Skip to content

Commit

Permalink
Fix incremental compilation when generated header is nested in a dire…
Browse files Browse the repository at this point in the history
…ctory (#945)
  • Loading branch information
brentleyjones authored Dec 1, 2022
1 parent 9eecf4b commit 569819b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ build --features treat_warnings_as_errors

# The default strategy is worker, which has sandboxing disabled by default,
# which can hide issues with non-hermetic bugs.
build --strategy=SwiftCompile=sandboxed
build --worker_sandboxing
1 change: 1 addition & 0 deletions examples/apple/objc_interop/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ objc_library(
swift_library(
name = "Printer",
srcs = ["Printer.swift"],
generated_header_name = "generated_header/Printer-Swift.h",
generates_header = True,
deps = [":PrintStream"],
)
Expand Down
2 changes: 1 addition & 1 deletion examples/apple/objc_interop/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// rules automatically add "bazel-genfiles" to the include path, the file should
// be imported using a workspace-relative path to access the Obj-C interface for
// the Swift code.
#import "examples/apple/objc_interop/Printer-Swift.h"
#import "examples/apple/objc_interop/generated_header/Printer-Swift.h"

int main(int argc, char **argv) {
@autoreleasepool {
Expand Down
19 changes: 19 additions & 0 deletions tools/worker/work_processor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <filesystem>
#include <fstream>
#include <map>
#include <set>
#include <sstream>
#include <string>

Expand Down Expand Up @@ -148,6 +149,20 @@ void WorkProcessor::ProcessWorkRequest(
std::ostringstream stderr_stream;

if (is_incremental) {
std::set<std::string> dir_paths;

for (const auto &expected_object_pair :
output_file_map.incremental_inputs()) {
// Bazel creates the intermediate directories for the files declared at
// analysis time, but not any any deeper directories, like one can have
// with -emit-objc-header-path, so we need to create those.
const std::string dir_path =
std::filesystem::path(expected_object_pair.second)
.parent_path()
.string();
dir_paths.insert(dir_path);
}

for (const auto &expected_object_pair :
output_file_map.incremental_outputs()) {
// Bazel creates the intermediate directories for the files declared at
Expand All @@ -157,6 +172,10 @@ void WorkProcessor::ProcessWorkRequest(
std::filesystem::path(expected_object_pair.second)
.parent_path()
.string();
dir_paths.insert(dir_path);
}

for (const auto &dir_path : dir_paths) {
std::error_code ec;
std::filesystem::create_directories(dir_path, ec);
if (ec) {
Expand Down

0 comments on commit 569819b

Please sign in to comment.