Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions swift/internal/feature_names.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ SWIFT_FEATURE_EMIT_PRIVATE_SWIFTINTERFACE = "swift.emit_private_swiftinterface"
# any of the existing compiler flags. Only enable this feature if such
# non-determinism does not negatively impact you.
#
# Note: If opted out of this feature, .swiftsourceinfo are generated by the
# compiler but excluded from Bazel's tracking.
# If opted out of this feature, the compiler is instructed not to generate a
# `.swiftsourceinfo` file.
SWIFT_FEATURE_DECLARE_SWIFTSOURCEINFO = "swift.emit_swiftsourceinfo"

# If enabled, the .swiftmodule file for the affected target will not be
Expand Down
18 changes: 3 additions & 15 deletions swift/toolchains/config/compile_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -580,22 +580,10 @@ def compile_action_configs(
],
not_features = [SWIFT_FEATURE_COVERAGE_PREFIX_MAP, SWIFT_FEATURE_FILE_PREFIX_MAP],
),

# Ensure that .swiftsourceinfo files are tracked and not deleted by the worker
ActionConfigInfo(
actions = [
SWIFT_ACTION_COMPILE,
],
configurators = [add_arg("-Xwrapped-swift=-emit-swiftsourceinfo")],
features = [SWIFT_FEATURE_DECLARE_SWIFTSOURCEINFO],
not_features = [SWIFT_FEATURE_SPLIT_DERIVED_FILES_GENERATION],
),
ActionConfigInfo(
actions = [
SWIFT_ACTION_DERIVE_FILES,
],
configurators = [add_arg("-Xwrapped-swift=-emit-swiftsourceinfo")],
features = [SWIFT_FEATURE_DECLARE_SWIFTSOURCEINFO],
actions = all_compile_action_names(),
configurators = [add_arg("-avoid-emit-module-source-info")],
not_features = [SWIFT_FEATURE_DECLARE_SWIFTSOURCEINFO],
),
]

Expand Down
50 changes: 50 additions & 0 deletions test/split_derived_files_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ default_no_split_emit_swiftsourceinfo_provider_test = make_provider_test_rule(
},
)

default_no_split_emit_swiftsourceinfo_test = make_action_command_line_test_rule(
config_settings = {
"//command_line_option:features": [
"swift.emit_swiftsourceinfo",
],
},
)

split_swiftmodule_test = make_action_command_line_test_rule(
config_settings = {
"//command_line_option:features": [
Expand Down Expand Up @@ -61,6 +69,15 @@ split_emit_swiftsourceinfo_provider_test = make_provider_test_rule(
},
)

split_emit_swiftsourceinfo_test = make_action_command_line_test_rule(
config_settings = {
"//command_line_option:features": [
"swift.emit_swiftsourceinfo",
"swift.split_derived_files_generation",
],
},
)

split_no_emit_swiftdoc_provider_test = make_provider_test_rule(
config_settings = {
"//command_line_option:features": [
Expand Down Expand Up @@ -135,6 +152,7 @@ def split_derived_files_test_suite(name, tags = []):
default_no_split_test(
name = "{}_default_no_split_args".format(name),
expected_argv = [
"-avoid-emit-module-source-info",
"-emit-module-path",
"-emit-object",
"-enable-batch-mode",
Expand All @@ -148,6 +166,16 @@ def split_derived_files_test_suite(name, tags = []):
target_under_test = "//test/fixtures/debug_settings:simple",
)

default_no_split_emit_swiftsourceinfo_test(
name = "{}_default_no_split_emit_swiftsourceinfo_args".format(name),
mnemonic = "SwiftCompile",
not_expected_argv = [
"-avoid-emit-module-source-info",
],
tags = all_tags,
target_under_test = "//test/fixtures/debug_settings:simple",
)

default_no_split_provider_test(
name = "{}_default_no_split_provider_swiftmodule".format(name),
expected_files = [
Expand Down Expand Up @@ -274,6 +302,7 @@ def split_derived_files_test_suite(name, tags = []):
split_swiftmodule_test(
name = "{}_object_only".format(name),
expected_argv = [
"-avoid-emit-module-source-info",
"-emit-object",
"-enable-batch-mode",
"simple.output_file_map.json",
Expand All @@ -290,6 +319,7 @@ def split_derived_files_test_suite(name, tags = []):
split_swiftmodule_test(
name = "{}_swiftmodule_only".format(name),
expected_argv = [
"-avoid-emit-module-source-info",
"-emit-module-path",
"-enable-batch-mode",
"simple.derived_output_file_map.json",
Expand All @@ -303,6 +333,26 @@ def split_derived_files_test_suite(name, tags = []):
target_under_test = "//test/fixtures/debug_settings:simple",
)

split_emit_swiftsourceinfo_test(
name = "{}_object_only_emit_swiftsourceinfo".format(name),
mnemonic = "SwiftCompile",
not_expected_argv = [
"-avoid-emit-module-source-info",
],
tags = all_tags,
target_under_test = "//test/fixtures/debug_settings:simple",
)

split_emit_swiftsourceinfo_test(
name = "{}_swiftmodule_only_emit_swiftsourceinfo".format(name),
mnemonic = "SwiftDeriveFiles",
not_expected_argv = [
"-avoid-emit-module-source-info",
],
tags = all_tags,
target_under_test = "//test/fixtures/debug_settings:simple",
)

split_swiftmodule_provider_test(
name = "{}_split_provider".format(name),
expected_files = [
Expand Down
8 changes: 0 additions & 8 deletions tools/worker/output_file_map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,6 @@ void OutputFileMap::UpdateForIncremental(
auto copied_swiftdoc_path =
MakeIncrementalOutputPath(swiftdoc_path, derived);
incremental_inputs[swiftdoc_path] = copied_swiftdoc_path;

std::string swiftsourceinfo_path =
std::filesystem::path(swiftmodule_path)
.replace_extension(".swiftsourceinfo")
.string();
auto copied_swiftsourceinfo_path =
MakeIncrementalOutputPath(swiftsourceinfo_path, derived);
incremental_inputs[swiftsourceinfo_path] = copied_swiftsourceinfo_path;
}

if (!emit_objc_header_path.empty()) {
Expand Down
16 changes: 0 additions & 16 deletions tools/worker/swift_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -472,17 +472,6 @@ SwiftRunner::SwiftRunner(const std::vector<std::string>& args,
}

int SwiftRunner::Run(std::ostream* stderr_stream, bool stdout_to_stderr) {
// In rules_swift < 3.x the .swiftsourceinfo files are unconditionally written
// to the module path. In rules_swift >= 3.x these same files are no longer
// tracked by Bazel unless explicitly requested. When using non-sandboxed
// mode, previous builds will contain these files and cause build failures
// when Swift tries to use them, in order to work around this compatibility
// issue, we check the module path for the presence of .swiftsourceinfo files
// and if they are present but not requested, we remove them.
if (swift_source_info_path_ != "" && !emit_swift_source_info_) {
std::filesystem::remove(swift_source_info_path_);
}

int exit_code = 0;

// Do the layering check before compilation. This gives a better error
Expand Down Expand Up @@ -759,8 +748,6 @@ std::vector<std::string> SwiftRunner::ParseArguments(Iterator itr) {
target_label_ = std::string(value);
} else if (absl::ConsumePrefix(&value, "-layering-check-deps-modules=")) {
deps_modules_path_ = std::string(value);
} else if (value == "-emit-swiftsourceinfo") {
emit_swift_source_info_ = true;
} else if (value == "-hermetic-pcm") {
hermetic_pcm_ = true;
} else if (absl::ConsumePrefix(
Expand All @@ -779,9 +766,6 @@ std::vector<std::string> SwiftRunner::ParseArguments(Iterator itr) {
} else if (arg == "-emit-module-path") {
++it;
emit_module_path_ = *it;
std::filesystem::path module_path(*it);
swift_source_info_path_ =
module_path.replace_extension(".swiftsourceinfo").string();
out_args.push_back(*it);
} else if (arg == "-module-name") {
++it;
Expand Down
6 changes: 0 additions & 6 deletions tools/worker/swift_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,6 @@ class SwiftRunner {
// index outputs into the `index_store_path` to integrate outputs with Bazel.
std::string global_index_store_import_path_;

// The path where the module files will be written
std::string swift_source_info_path_;

// Whether `.swiftsourceinfo` files are being generated.
bool emit_swift_source_info_;

// Whether `-Xwrapped-swift=-hermetic-pcm` was passed
bool hermetic_pcm_;

Expand Down
15 changes: 0 additions & 15 deletions tools/worker/work_processor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ void WorkProcessor::ProcessWorkRequest(
std::string emit_objc_header_path;
bool is_wmo = false;
bool is_dump_ast = false;
bool emit_swift_source_info = false;

std::string prev_arg;
for (std::string arg : request.arguments) {
Expand All @@ -114,8 +113,6 @@ void WorkProcessor::ProcessWorkRequest(
emit_objc_header_path = arg;
} else if (ArgumentEnablesWMO(arg)) {
is_wmo = true;
} else if (prev_arg == "-Xwrapped-swift=-emit-swiftsourceinfo") {
emit_swift_source_info = true;
}

if (!arg.empty()) {
Expand Down Expand Up @@ -167,18 +164,6 @@ void WorkProcessor::ProcessWorkRequest(
const auto expected_object_path =
std::filesystem::path(expected_object_pair.second);

// In rules_swift < 3.x the .swiftsourceinfo files are unconditionally
// written to the module path. In rules_swift >= 3.x these same files are
// no longer tracked by Bazel unless explicitly requested. When using
// non-sandboxed mode, previous builds will contain these files and cause
// build failures when Swift tries to use them, in order to work around
// this compatibility issue, we remove them if they are present but not
// requested.
if (!emit_swift_source_info &&
expected_object_path.extension() == ".swiftsourceinfo") {
std::filesystem::remove(LongPath(expected_object_path));
}

// 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.
Expand Down
Loading