From 5e875317ab13b35d89f7e13f099e0a8044ec9ef3 Mon Sep 17 00:00:00 2001 From: John Flanagan Date: Thu, 19 Feb 2026 13:33:56 -0600 Subject: [PATCH 1/2] Delete unused files Signed-off-by: John Flanagan --- test/BUILD | 1 - test/internal/opts/BUILD | 15 - .../opts/process_compiler_opts_tests.bzl | 1051 ----------------- tools/params_processors/BUILD | 54 - .../cc_compiler_params_processor.py | 1 + .../swift_compiler_params_processor.py | 218 ---- .../swift_compiler_params_processor_tests.py | 367 ------ .../swift_debug_settings_processor.py | 432 ------- .../swift_debug_settings_processor_tests.py | 314 ----- xcodeproj/internal/opts.bzl | 648 ---------- 10 files changed, 1 insertion(+), 3100 deletions(-) delete mode 100644 test/internal/opts/BUILD delete mode 100644 test/internal/opts/process_compiler_opts_tests.bzl delete mode 100755 tools/params_processors/swift_compiler_params_processor.py delete mode 100644 tools/params_processors/swift_compiler_params_processor_tests.py delete mode 100755 tools/params_processors/swift_debug_settings_processor.py delete mode 100644 tools/params_processors/swift_debug_settings_processor_tests.py delete mode 100644 xcodeproj/internal/opts.bzl diff --git a/test/BUILD b/test/BUILD index d4b8b8181a..a82a284563 100644 --- a/test/BUILD +++ b/test/BUILD @@ -7,7 +7,6 @@ test_suite( "//test/internal/build_settings", "//test/internal/flattened_key_values", "//test/internal/info_plists", - "//test/internal/opts", "//test/internal/pbxproj_partials", "//test/internal/platforms", "//test/internal/target", diff --git a/test/internal/opts/BUILD b/test/internal/opts/BUILD deleted file mode 100644 index 813052cbb2..0000000000 --- a/test/internal/opts/BUILD +++ /dev/null @@ -1,15 +0,0 @@ -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") -load( - ":process_compiler_opts_tests.bzl", - "process_compiler_opts_test_suite", -) - -process_compiler_opts_test_suite(name = "process_compiler_opts") - -test_suite(name = "opts") - -bzl_library( - name = "bzls", - srcs = glob(["*.bzl"]), - visibility = ["//test:__pkg__"], -) diff --git a/test/internal/opts/process_compiler_opts_tests.bzl b/test/internal/opts/process_compiler_opts_tests.bzl deleted file mode 100644 index e42b35f5f0..0000000000 --- a/test/internal/opts/process_compiler_opts_tests.bzl +++ /dev/null @@ -1,1051 +0,0 @@ -"""Tests for compiler options processing functions.""" - -load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest") -load("//test:utils.bzl", "stringify_dict") - -# buildifier: disable=bzl-visibility -load("//xcodeproj/internal:opts.bzl", "testable") - -process_compiler_opts = testable.process_compiler_opts - -def _process_compiler_opts_test_impl(ctx): - env = unittest.begin(ctx) - - conlyopts = ctx.attr.conlyopts - cxxopts = ctx.attr.cxxopts - swiftcopts = ctx.attr.swiftcopts - - build_settings = {} - ( - _, - _, - _, - _, - c_has_fortify_source, - cxx_has_fortify_source, - ) = process_compiler_opts( - actions = None, - name = "process_compiler_opts_tests", - conlyopts = conlyopts, - conly_args = [], - cxxopts = cxxopts, - cxx_args = [], - swiftcopts = swiftcopts, - swift_args = [], - cpp_fragment = _cpp_fragment_stub(ctx.attr.cpp_fragment), - package_bin_dir = ctx.attr.package_bin_dir, - build_settings = build_settings, - cc_compiler_params_processor = None, - swift_compiler_params_processor = None, - ) - string_build_settings = stringify_dict(build_settings) - - expected_build_settings = {} - if conlyopts or cxxopts or swiftcopts: - expected_build_settings["DEBUG_INFORMATION_FORMAT"] = "" - - expected_build_settings.update(ctx.attr.expected_build_settings) - - if (ctx.attr.expected_build_settings.get("DEBUG_INFORMATION_FORMAT", "") == - "None"): - expected_build_settings.pop("DEBUG_INFORMATION_FORMAT") - - asserts.equals( - env, - expected_build_settings, - string_build_settings, - "build_settings", - ) - - asserts.equals( - env, - ctx.attr.expected_c_has_fortify_source, - c_has_fortify_source, - "c_has_fortify_source", - ) - - asserts.equals( - env, - ctx.attr.expected_cxx_has_fortify_source, - cxx_has_fortify_source, - "cxx_has_fortify_source", - ) - - return unittest.end(env) - -process_compiler_opts_test = unittest.make( - impl = _process_compiler_opts_test_impl, - attrs = { - "conlyopts": attr.string_list(mandatory = True), - "cpp_fragment": attr.string_dict(mandatory = False), - "cxxopts": attr.string_list(mandatory = True), - "expected_build_settings": attr.string_dict(mandatory = True), - "expected_c_has_fortify_source": attr.bool(mandatory = True), - "expected_cxx_has_fortify_source": attr.bool(mandatory = True), - "package_bin_dir": attr.string(mandatory = True), - "swiftcopts": attr.string_list(mandatory = True), - }, -) - -def _cpp_fragment(*, apple_generate_dsym): - return { - "apple_generate_dsym": json.encode(apple_generate_dsym), - } - -def _cpp_fragment_stub(dict): - if not dict: - return struct( - apple_generate_dsym = False, - ) - return struct( - apple_generate_dsym = json.decode(dict["apple_generate_dsym"]), - ) - -def process_compiler_opts_test_suite(name): - """Test suite for `process_compiler_opts`. - - Args: - name: The base name to be used in things created by this macro. Also the - name of the test suite. - """ - test_names = [] - - def _add_test( - *, - name, - expected_build_settings = {}, - expected_c_has_fortify_source = False, - expected_cxx_has_fortify_source = False, - conlyopts = [], - cxxopts = [], - swiftcopts = [], - cpp_fragment = None, - package_bin_dir = ""): - test_names.append(name) - process_compiler_opts_test( - name = name, - conlyopts = conlyopts, - cxxopts = cxxopts, - swiftcopts = swiftcopts, - cpp_fragment = cpp_fragment, - package_bin_dir = package_bin_dir, - expected_build_settings = stringify_dict(expected_build_settings), - expected_c_has_fortify_source = expected_c_has_fortify_source, - expected_cxx_has_fortify_source = expected_cxx_has_fortify_source, - timeout = "short", - ) - - # Base - - _add_test( - name = "{}_swift_integration".format(name), - swiftcopts = [ - "-target", - "arm64-apple-ios15.0-simulator", - "-sdk", - "__BAZEL_XCODE_SDKROOT__", - "-emit-object", - "-output-file-map", - "bazel-out/ios-sim_arm64-min15.0-applebin_ios-ios_sim_arm64-fastbuild-ST-4e6c2a19403f/bin/examples/ExampleUITests/ExampleUITests.library.output_file_map.json", - "-Xfrontend", - "-no-clang-module-breadcrumbs", - "-emit-module-path", - "bazel-out/ios-sim_arm64-min15.0-applebin_ios-ios_sim_arm64-fastbuild-ST-4e6c2a19403f/bin/examples/ExampleUITests/ExampleUITests.swiftmodule", - "-DDEBUG", - "-Onone", - "-Xfrontend", - "-serialize-debugging-options", - "-enable-testing", - "-application-extension", - "weird", - "-gline-tables-only", - "-Xwrapped-swift=-debug-prefix-pwd-is-dot", - "-Xwrapped-swift=-ephemeral-module-cache", - "-Xfrontend", - "-color-diagnostics", - "-enable-batch-mode", - "-unhandled", - "-module-name", - "ExampleUITests", - "-parse-as-library", - "examples/xcode_like/ExampleUITests/ExampleUITests.swift", - "examples/xcode_like/ExampleUITests/ExampleUITestsLaunchTests.swift", - ], - ) - - _add_test( - name = "{}_empty".format(name), - conlyopts = [], - cxxopts = [], - swiftcopts = [], - expected_build_settings = {}, - ) - - # Skips - - _add_test( - name = "{}_skips".format(name), - conlyopts = [ - "-mtvos-simulator-version-min=8.0", - "-passthrough", - "-isysroot", - "other", - "-mios-simulator-version-min=11.2", - "-miphoneos-version-min=9.0", - "-passthrough", - "-mtvos-version-min=12.1", - "-mwatchos-simulator-version-min=10.1", - "-passthrough", - "-mwatchos-version-min=9.2", - "-target", - "ios", - "-mmacosx-version-min=12.0", - "-passthrough", - "-index-store-path", - "bazel-out/_global_index_store", - "-index-ignore-system-symbols", - "--config", - "relative/Path.yaml", - ], - cxxopts = [ - "-isysroot", - "something", - "-miphoneos-version-min=9.4", - "-mmacosx-version-min=10.9", - "-passthrough", - "-mtvos-version-min=12.2", - "-mwatchos-simulator-version-min=9.3", - "-passthrough", - "-mtvos-simulator-version-min=12.1", - "-mwatchos-version-min=10.2", - "-I__BAZEL_XCODE_BOSS_", - "-target", - "macos", - "-passthrough", - "-mios-simulator-version-min=14.0", - "-index-store-path", - "bazel-out/_global_index_store", - "-index-ignore-system-symbols", - "--config", - "relative/Path.yaml", - ], - swiftcopts = [ - "-output-file-map", - "path", - "-passthrough", - "-debug-prefix-map", - "__BAZEL_XCODE_DEVELOPER_DIR__=DEVELOPER_DIR", - "-file-prefix-map", - "__BAZEL_XCODE_DEVELOPER_DIR__=DEVELOPER_DIR", - "-emit-module-path", - "path", - "-passthrough", - "-Xfrontend", - "-color-diagnostics", - "-Xfrontend", - "-import-underlying-module", - "-emit-object", - "-enable-batch-mode", - "-passthrough", - "-gline-tables-only", - "-sdk", - "something", - "-module-name", - "name", - "-passthrough", - "-num-threads", - "6", - "-passthrough", - "-parse-as-library", - "-passthrough", - "-parse-as-library", - "-keep-me=something.swift", - "reject-me.swift", - "-target", - "ios", - "-Xwrapped-swift", - "-passthrough", - ], - ) - - # -Xcc - - _add_test( - name = "{}_swift_xcc".format(name), - swiftcopts = [ - # -fmodule-map-file - "-Xcc", - "-fmodule-map-file=/absolute/path", - "-Xcc", - "-fmodule-map-file=relative/path", - "-Xcc", - "-fmodule-map-file=bazel-out/relative/path", - "-Xcc", - "-fmodule-map-file=external/relative/path", - - # -iquote - "-Xcc", - "-iquote/absolute/path", - "-Xcc", - "-iquote", - "-Xcc", - "/absolute/path", - "-Xcc", - "-iquote", - "-Xcc", - "/absolute/path", - "-Xcc", - "-iquoterelative/path", - "-Xcc", - "-iquote", - "-Xcc", - "relative/path", - "-Xcc", - "-iquotebazel-out/relative/path", - "-Xcc", - "-iquote", - "-Xcc", - "bazel-out/relative/path", - "-Xcc", - "-iquoteexternal/relative/path", - "-Xcc", - "-iquote", - "-Xcc", - "external/relative/path", - "-Xcc", - "-iquote.", - "-Xcc", - "-iquote", - "-Xcc", - ".", - - # -I - "-Xcc", - "-I/absolute/path", - "-Xcc", - "-I", - "-Xcc", - "/absolute/path", - "-Xcc", - "-Irelative/path", - "-Xcc", - "-I", - "-Xcc", - "relative/path", - "-Xcc", - "-Ibazel-out/relative/path", - "-Xcc", - "-I", - "-Xcc", - "bazel-out/relative/path", - "-Xcc", - "-Iexternal/relative/path", - "-Xcc", - "-I", - "-Xcc", - "external/relative/path", - "-Xcc", - "-I.", - "-Xcc", - "-I", - "-Xcc", - ".", - - # -isystem - "-Xcc", - "-isystem/absolute/path", - "-Xcc", - "-isystem", - "-Xcc", - "/absolute/path", - "-Xcc", - "-isystemrelative/path", - "-Xcc", - "-isystem", - "-Xcc", - "relative/path", - "-Xcc", - "-isystembazel-out/relative/path", - "-Xcc", - "-isystem", - "-Xcc", - "bazel-out/relative/path", - "-Xcc", - "-isystemexternal/relative/path", - "-Xcc", - "-isystem", - "-Xcc", - "external/relative/path", - "-Xcc", - "-isystem.", - "-Xcc", - "-isystem", - "-Xcc", - ".", - - # -ivfsoverlay - "-Xcc", - "-ivfsoverlay", - "-Xcc", - "/Some/Path.yaml", - "-Xcc", - "-ivfsoverlay", - "-Xcc", - "relative/Path.yaml", - "-Xcc", - "-ivfsoverlay", - "-Xcc", - "bazel-out/relative/Path.yaml", - "-Xcc", - "-ivfsoverlay", - "-Xcc", - "external/relative/Path.yaml", - "-Xcc", - "-ivfsoverlay/Some/Path.yaml", - "-Xcc", - "-ivfsoverlayrelative/Path.yaml", - "-Xcc", - "-ivfsoverlaybazel-out/relative/Path.yaml", - "-Xcc", - "-ivfsoverlayexternal/relative/Path.yaml", - "-Xcc", - "-ivfsoverlay=/Some/Path.yaml", - "-Xcc", - "-ivfsoverlay=relative/Path.yaml", - "-Xcc", - "-ivfsoverlay=bazel-out/relative/Path.yaml", - "-Xcc", - "-ivfsoverlay=external/relative/Path.yaml", - - # Other - "-Xcc", - "-O0", - "-Xcc", - "-DDEBUG=1", - "-Xcc", - "-DNEEDS_QUOTES=Two words", - ], - expected_build_settings = { - "OTHER_SWIFT_FLAGS": """\ --Xcc -fmodule-map-file=/absolute/path \ --Xcc -fmodule-map-file=$(SRCROOT)/relative/path \ --Xcc -fmodule-map-file=$(BAZEL_OUT)/relative/path \ --Xcc -fmodule-map-file=$(BAZEL_EXTERNAL)/relative/path \ --Xcc -iquote -Xcc /absolute/path \ --Xcc -iquote -Xcc /absolute/path \ --Xcc -iquote -Xcc /absolute/path \ --Xcc -iquote -Xcc $(SRCROOT)/relative/path \ --Xcc -iquote -Xcc $(SRCROOT)/relative/path \ --Xcc -iquote -Xcc $(BAZEL_OUT)/relative/path \ --Xcc -iquote -Xcc $(BAZEL_OUT)/relative/path \ --Xcc -iquote -Xcc $(BAZEL_EXTERNAL)/relative/path \ --Xcc -iquote -Xcc $(BAZEL_EXTERNAL)/relative/path \ --Xcc -iquote -Xcc $(PROJECT_DIR) \ --Xcc -iquote -Xcc $(PROJECT_DIR) \ --Xcc -I -Xcc /absolute/path \ --Xcc -I -Xcc /absolute/path \ --Xcc -I -Xcc $(SRCROOT)/relative/path \ --Xcc -I -Xcc $(SRCROOT)/relative/path \ --Xcc -I -Xcc $(BAZEL_OUT)/relative/path \ --Xcc -I -Xcc $(BAZEL_OUT)/relative/path \ --Xcc -I -Xcc $(BAZEL_EXTERNAL)/relative/path \ --Xcc -I -Xcc $(BAZEL_EXTERNAL)/relative/path \ --Xcc -I -Xcc $(PROJECT_DIR) \ --Xcc -I -Xcc $(PROJECT_DIR) \ --Xcc -isystem -Xcc /absolute/path \ --Xcc -isystem -Xcc /absolute/path \ --Xcc -isystem -Xcc $(SRCROOT)/relative/path \ --Xcc -isystem -Xcc $(SRCROOT)/relative/path \ --Xcc -isystem -Xcc $(BAZEL_OUT)/relative/path \ --Xcc -isystem -Xcc $(BAZEL_OUT)/relative/path \ --Xcc -isystem -Xcc $(BAZEL_EXTERNAL)/relative/path \ --Xcc -isystem -Xcc $(BAZEL_EXTERNAL)/relative/path \ --Xcc -isystem -Xcc $(PROJECT_DIR) \ --Xcc -isystem -Xcc $(PROJECT_DIR) \ --Xcc -ivfsoverlay -Xcc /Some/Path.yaml \ --Xcc -ivfsoverlay -Xcc $(PROJECT_DIR)/relative/Path.yaml \ --Xcc -ivfsoverlay -Xcc $(PROJECT_DIR)/bazel-out/relative/Path.yaml \ --Xcc -ivfsoverlay -Xcc $(PROJECT_DIR)/external/relative/Path.yaml \ --Xcc -ivfsoverlay/Some/Path.yaml \ --Xcc -ivfsoverlay$(PROJECT_DIR)/relative/Path.yaml \ --Xcc -ivfsoverlay$(PROJECT_DIR)/bazel-out/relative/Path.yaml \ --Xcc -ivfsoverlay$(PROJECT_DIR)/external/relative/Path.yaml \ --Xcc -ivfsoverlay=/Some/Path.yaml \ --Xcc -ivfsoverlay$(PROJECT_DIR)/relative/Path.yaml \ --Xcc -ivfsoverlay$(PROJECT_DIR)/bazel-out/relative/Path.yaml \ --Xcc -ivfsoverlay$(PROJECT_DIR)/external/relative/Path.yaml \ --Xcc -O0 \ --Xcc -DDEBUG=1 \ --Xcc "-DNEEDS_QUOTES=Two words"\ -""", - }, - ) - - # -I - - _add_test( - name = "{}_swift_I_paths".format(name), - swiftcopts = [ - # -I - "-I__BAZEL_XCODE_SOMETHING_/path", - "-I__BAZEL_XCODE_DEVELOPER_DIR__/Platforms/iPhoneSimulator.platform/Developer/usr/lib", - "-I", - "__BAZEL_XCODE_DEVELOPER_DIR__/Platforms/iPhoneSimulator.platform/Developer/usr/lib", - "-Irelative/path", - "-Ibazel-out/relative/path", - "-Iexternal/relative/path", - "-I/absolute/path", - "-I.", - "-I", - "relative/path", - "-I", - "bazel-out/relative/path", - "-I", - "external/relative/path", - "-I", - "/absolute/path", - "-I", - ".", - ], - expected_build_settings = { - "OTHER_SWIFT_FLAGS": """\ --I__BAZEL_XCODE_SOMETHING_/path \ --I$(DEVELOPER_DIR)/Platforms/iPhoneSimulator.platform/Developer/usr/lib \ --I \ -$(DEVELOPER_DIR)/Platforms/iPhoneSimulator.platform/Developer/usr/lib \ --I$(SRCROOT)/relative/path \ --I$(BAZEL_OUT)/relative/path \ --I$(BAZEL_EXTERNAL)/relative/path \ --I/absolute/path \ --I$(PROJECT_DIR) \ --I \ -$(SRCROOT)/relative/path \ --I \ -$(BAZEL_OUT)/relative/path \ --I \ -$(BAZEL_EXTERNAL)/relative/path \ --I \ -/absolute/path \ --I \ -$(PROJECT_DIR)\ -""", - }, - ) - - # -F, -explicit-swift-module-map-file, -load-plugin-executable, - # -load-plugin-library, and -vfsoverlay - - _add_test( - name = "{}_swift_other_paths".format(name), - swiftcopts = [ - # -explicit-swift-module-map-file - "-explicit-swift-module-map-file", - "/Some/Path.json", - "-explicit-swift-module-map-file", - "relative/Path.json", - "-explicit-swift-module-map-file", - "bazel-out/relative/Path.json", - "-explicit-swift-module-map-file", - "external/relative/Path.json", - "-Xfrontend", - "-explicit-swift-module-map-file", - "-Xfrontend", - "/Some/Path.json", - "-Xfrontend", - "-explicit-swift-module-map-file", - "-Xfrontend", - "relative/Path.json", - "-Xfrontend", - "-explicit-swift-module-map-file", - "-Xfrontend", - "bazel-out/relative/Path.json", - "-Xfrontend", - "-explicit-swift-module-map-file", - "-Xfrontend", - "external/relative/Path.json", - - # -load-plugin-executable - "-load-plugin-executable", - "/Some/MacroPlugin#MacroPlugin", - "-load-plugin-executable", - "relative/MacroPlugin#MacroPlugin", - "-load-plugin-executable", - "bazel-out/relative/MacroPlugin#MacroPlugin", - "-load-plugin-executable", - "external/relative/MacroPlugin#MacroPlugin", - "-Xfrontend", - "-load-plugin-executable", - "-Xfrontend", - "/Some/MacroPlugin#MacroPlugin", - "-Xfrontend", - "-load-plugin-executable", - "-Xfrontend", - "relative/MacroPlugin#MacroPlugin", - "-Xfrontend", - "-load-plugin-executable", - "-Xfrontend", - "bazel-out/relative/MacroPlugin#MacroPlugin", - "-Xfrontend", - "-load-plugin-executable", - "-Xfrontend", - "external/relative/MacroPlugin#MacroPlugin", - - # -load-plugin-library - "-load-plugin-library", - "/Some/MacroPlugin#MacroPlugin", - "-load-plugin-library", - "relative/MacroPlugin#MacroPlugin", - "-load-plugin-library", - "bazel-out/relative/MacroPlugin#MacroPlugin", - "-load-plugin-library", - "external/relative/MacroPlugin#MacroPlugin", - "-Xfrontend", - "-load-plugin-library", - "-Xfrontend", - "/Some/MacroPlugin#MacroPlugin", - "-Xfrontend", - "-load-plugin-library", - "-Xfrontend", - "relative/MacroPlugin#MacroPlugin", - "-Xfrontend", - "-load-plugin-library", - "-Xfrontend", - "bazel-out/relative/MacroPlugin#MacroPlugin", - "-Xfrontend", - "-load-plugin-library", - "-Xfrontend", - "external/relative/MacroPlugin#MacroPlugin", - - # -vfsoverlay - "-vfsoverlay", - "/Some/Path.yaml", - "-vfsoverlay", - "relative/Path.yaml", - "-vfsoverlay", - "bazel-out/relative/Path.yaml", - "-vfsoverlay", - "external/relative/Path.yaml", - "-Xfrontend", - "-vfsoverlay", - "-Xfrontend", - "/Some/Path.yaml", - "-Xfrontend", - "-vfsoverlay", - "-Xfrontend", - "relative/Path.yaml", - "-Xfrontend", - "-vfsoverlay", - "-Xfrontend", - "bazel-out/relative/Path.yaml", - "-Xfrontend", - "-vfsoverlay", - "-Xfrontend", - "external/relative/Path.yaml", - "-Xfrontend", - "-vfsoverlay/Some/Path.yaml", - "-Xfrontend", - "-vfsoverlayrelative/Path.yaml", - "-Xfrontend", - "-vfsoverlaybazel-out/relative/Path.yaml", - "-Xfrontend", - "-vfsoverlayexternal/relative/Path.yaml", - "-Xfrontend", - "-vfsoverlay=/Some/Path.yaml", - "-Xfrontend", - "-vfsoverlay=relative/Path.yaml", - "-Xfrontend", - "-vfsoverlay=bazel-out/relative/Path.yaml", - "-Xfrontend", - "-vfsoverlay=external/relative/Path.yaml", - - # -F - "-F__BAZEL_XCODE_SOMETHING_/path", - "-F__BAZEL_XCODE_DEVELOPER_DIR__/Platforms/iPhoneSimulator.platform/Developer/usr/lib", - "-F", - "__BAZEL_XCODE_DEVELOPER_DIR__/Platforms/iPhoneSimulator.platform/Developer/usr/lib", - "-Frelative/path", - "-Fbazel-out/relative/path", - "-Fexternal/relative/path", - "-F/absolute/path", - "-F.", - "-F", - "relative/path", - "-F", - "bazel-out/relative/path", - "-F", - "external/relative/path", - "-F", - "/absolute/path", - "-F", - ".", - ], - expected_build_settings = { - "OTHER_SWIFT_FLAGS": """\ --explicit-swift-module-map-file \ -/Some/Path.json \ --explicit-swift-module-map-file \ -$(SRCROOT)/relative/Path.json \ --explicit-swift-module-map-file \ -$(BAZEL_OUT)/relative/Path.json \ --explicit-swift-module-map-file \ -$(BAZEL_EXTERNAL)/relative/Path.json \ --Xfrontend \ --explicit-swift-module-map-file \ --Xfrontend \ -/Some/Path.json \ --Xfrontend \ --explicit-swift-module-map-file \ --Xfrontend \ -$(SRCROOT)/relative/Path.json \ --Xfrontend \ --explicit-swift-module-map-file \ --Xfrontend \ -$(BAZEL_OUT)/relative/Path.json \ --Xfrontend \ --explicit-swift-module-map-file \ --Xfrontend \ -$(BAZEL_EXTERNAL)/relative/Path.json \ --load-plugin-executable \ -/Some/MacroPlugin#MacroPlugin \ --load-plugin-executable \ -$(SRCROOT)/relative/MacroPlugin#MacroPlugin \ --load-plugin-executable \ -$(BAZEL_OUT)/relative/MacroPlugin#MacroPlugin \ --load-plugin-executable \ -$(BAZEL_EXTERNAL)/relative/MacroPlugin#MacroPlugin \ --Xfrontend \ --load-plugin-executable \ --Xfrontend \ -/Some/MacroPlugin#MacroPlugin \ --Xfrontend \ --load-plugin-executable \ --Xfrontend \ -$(SRCROOT)/relative/MacroPlugin#MacroPlugin \ --Xfrontend \ --load-plugin-executable \ --Xfrontend \ -$(BAZEL_OUT)/relative/MacroPlugin#MacroPlugin \ --Xfrontend \ --load-plugin-executable \ --Xfrontend \ -$(BAZEL_EXTERNAL)/relative/MacroPlugin#MacroPlugin \ --load-plugin-library \ -/Some/MacroPlugin#MacroPlugin \ --load-plugin-library \ -$(SRCROOT)/relative/MacroPlugin#MacroPlugin \ --load-plugin-library \ -$(BAZEL_OUT)/relative/MacroPlugin#MacroPlugin \ --load-plugin-library \ -$(BAZEL_EXTERNAL)/relative/MacroPlugin#MacroPlugin \ --Xfrontend \ --load-plugin-library \ --Xfrontend \ -/Some/MacroPlugin#MacroPlugin \ --Xfrontend \ --load-plugin-library \ --Xfrontend \ -$(SRCROOT)/relative/MacroPlugin#MacroPlugin \ --Xfrontend \ --load-plugin-library \ --Xfrontend \ -$(BAZEL_OUT)/relative/MacroPlugin#MacroPlugin \ --Xfrontend \ --load-plugin-library \ --Xfrontend \ -$(BAZEL_EXTERNAL)/relative/MacroPlugin#MacroPlugin \ --vfsoverlay \ -/Some/Path.yaml \ --vfsoverlay \ -$(SRCROOT)/relative/Path.yaml \ --vfsoverlay \ -$(BAZEL_OUT)/relative/Path.yaml \ --vfsoverlay \ -$(BAZEL_EXTERNAL)/relative/Path.yaml \ --Xfrontend \ --vfsoverlay \ --Xfrontend \ -/Some/Path.yaml \ --Xfrontend \ --vfsoverlay \ --Xfrontend \ -$(SRCROOT)/relative/Path.yaml \ --Xfrontend \ --vfsoverlay \ --Xfrontend \ -$(BAZEL_OUT)/relative/Path.yaml \ --Xfrontend \ --vfsoverlay \ --Xfrontend \ -$(BAZEL_EXTERNAL)/relative/Path.yaml \ --Xfrontend \ --vfsoverlay/Some/Path.yaml \ --Xfrontend \ --vfsoverlay$(SRCROOT)/relative/Path.yaml \ --Xfrontend \ --vfsoverlay$(BAZEL_OUT)/relative/Path.yaml \ --Xfrontend \ --vfsoverlay$(BAZEL_EXTERNAL)/relative/Path.yaml \ --Xfrontend \ --vfsoverlay/Some/Path.yaml \ --Xfrontend \ --vfsoverlay$(SRCROOT)/relative/Path.yaml \ --Xfrontend \ --vfsoverlay$(BAZEL_OUT)/relative/Path.yaml \ --Xfrontend \ --vfsoverlay$(BAZEL_EXTERNAL)/relative/Path.yaml \ --F__BAZEL_XCODE_SOMETHING_/path \ --F$(DEVELOPER_DIR)/Platforms/iPhoneSimulator.platform/Developer/usr/lib \ --F \ -$(DEVELOPER_DIR)/Platforms/iPhoneSimulator.platform/Developer/usr/lib \ --F$(SRCROOT)/relative/path \ --F$(BAZEL_OUT)/relative/path \ --F$(BAZEL_EXTERNAL)/relative/path \ --F/absolute/path \ --F$(PROJECT_DIR) \ --F \ -$(SRCROOT)/relative/path \ --F \ -$(BAZEL_OUT)/relative/path \ --F \ -$(BAZEL_EXTERNAL)/relative/path \ --F \ -/absolute/path \ --F \ -$(PROJECT_DIR)\ -""", - }, - ) - - # -D_FORTIFY_SOURCE=1 - - _add_test( - name = "{}_has_fortify_source".format(name), - conlyopts = [ - "-D_FORTIFY_SOURCE=1", - ], - cxxopts = [ - "-D_FORTIFY_SOURCE=1", - ], - expected_c_has_fortify_source = True, - expected_cxx_has_fortify_source = True, - ) - - # Specific Xcode build settings - - ## DEBUG_INFORMATION_FORMAT - - _add_test( - name = "{}_all-debug-dsym".format(name), - conlyopts = ["-g"], - cxxopts = ["-g"], - swiftcopts = ["-g"], - cpp_fragment = _cpp_fragment(apple_generate_dsym = True), - expected_build_settings = { - "DEBUG_INFORMATION_FORMAT": None, - }, - ) - - _add_test( - name = "{}_all-debug-no-dsym".format(name), - conlyopts = ["-g"], - cxxopts = ["-g"], - swiftcopts = ["-g"], - cpp_fragment = _cpp_fragment(apple_generate_dsym = False), - expected_build_settings = { - "DEBUG_INFORMATION_FORMAT": None, - }, - ) - - _add_test( - name = "{}_no-debug-no-dsym".format(name), - conlyopts = ["-a"], - cxxopts = ["-b"], - swiftcopts = ["-c"], - cpp_fragment = _cpp_fragment(apple_generate_dsym = False), - expected_build_settings = { - "DEBUG_INFORMATION_FORMAT": "", - }, - ) - - _add_test( - name = "{}_c-debug-dsym".format(name), - conlyopts = ["-g"], - cxxopts = ["-g"], - swiftcopts = [], - cpp_fragment = _cpp_fragment(apple_generate_dsym = True), - expected_build_settings = { - "DEBUG_INFORMATION_FORMAT": None, - }, - ) - - _add_test( - name = "{}_c-debug-no-dsym".format(name), - conlyopts = ["-g"], - cxxopts = ["-g"], - swiftcopts = [], - cpp_fragment = _cpp_fragment(apple_generate_dsym = False), - expected_build_settings = { - "DEBUG_INFORMATION_FORMAT": None, - }, - ) - - _add_test( - name = "{}_conly-debug".format(name), - conlyopts = ["-g"], - cxxopts = [], - swiftcopts = [], - cpp_fragment = _cpp_fragment(apple_generate_dsym = False), - expected_build_settings = { - "DEBUG_INFORMATION_FORMAT": None, - }, - ) - - _add_test( - name = "{}_cxx-debug".format(name), - conlyopts = [], - cxxopts = ["-g"], - swiftcopts = [], - cpp_fragment = _cpp_fragment(apple_generate_dsym = False), - expected_build_settings = { - "DEBUG_INFORMATION_FORMAT": None, - }, - ) - - _add_test( - name = "{}_swift-debug-dsym".format(name), - conlyopts = [], - cxxopts = [], - swiftcopts = ["-g"], - cpp_fragment = _cpp_fragment(apple_generate_dsym = True), - expected_build_settings = { - "DEBUG_INFORMATION_FORMAT": None, - }, - ) - - _add_test( - name = "{}_swift-debug-no-dsym".format(name), - conlyopts = [], - cxxopts = [], - swiftcopts = ["-g"], - cpp_fragment = _cpp_fragment(apple_generate_dsym = False), - expected_build_settings = { - "DEBUG_INFORMATION_FORMAT": None, - }, - ) - - _add_test( - name = "{}_swift-and-c-debug".format(name), - conlyopts = ["-g"], - cxxopts = [], - swiftcopts = ["-g"], - cpp_fragment = _cpp_fragment(apple_generate_dsym = False), - expected_build_settings = { - "DEBUG_INFORMATION_FORMAT": None, - }, - ) - - ## SWIFT_COMPILATION_MODE - - _add_test( - name = "{}_multiple_swift_compilation_modes".format(name), - swiftcopts = [ - "-wmo", - "-no-whole-module-optimization", - ], - expected_build_settings = { - "SWIFT_COMPILATION_MODE": "singlefile", - }, - ) - - _add_test( - name = "{}_swift_option-incremental".format(name), - swiftcopts = ["-incremental"], - expected_build_settings = { - "SWIFT_COMPILATION_MODE": "singlefile", - }, - ) - - _add_test( - name = "{}_swift_option-whole-module-optimization".format(name), - swiftcopts = ["-whole-module-optimization"], - expected_build_settings = { - "SWIFT_COMPILATION_MODE": "wholemodule", - }, - ) - - _add_test( - name = "{}_swift_option-wmo".format(name), - swiftcopts = ["-wmo"], - expected_build_settings = { - "SWIFT_COMPILATION_MODE": "wholemodule", - }, - ) - - _add_test( - name = "{}_swift_option-no-whole-module-optimization".format(name), - swiftcopts = ["-no-whole-module-optimization"], - expected_build_settings = { - "SWIFT_COMPILATION_MODE": "singlefile", - }, - ) - - ## SWIFT_OBJC_INTERFACE_HEADER_NAME - - _add_test( - name = "{}_generated_header".format(name), - swiftcopts = [ - "-emit-objc-header-path", - "a/b/c/TestingUtils-Custom.h", - ], - package_bin_dir = "a/b", - expected_build_settings = { - "SWIFT_OBJC_INTERFACE_HEADER_NAME": "c/TestingUtils-Custom.h", - }, - ) - - ## SWIFT_VERSION - - _add_test( - name = "{}_swift_option-swift-version".format(name), - swiftcopts = ["-swift-version=42"], - expected_build_settings = { - "SWIFT_VERSION": "42", - }, - ) - - # Search Paths - - _add_test( - name = "{}_search_paths".format(name), - conlyopts = [ - "-iquote", - "a/b/c", - "-iquotea/b/c/d", - "-Ix/y/z", - "-I", - "1/2/3", - "-iquote", - "0/9", - "-isystem", - "s1/s2", - "-isystems1/s2/s3", - ], - cxxopts = [ - "-iquote", - "y/z", - "-iquotey/z/1", - "-Ix/y/z", - "-I", - "aa/bb", - "-isystem", - "s3/s4", - "-isystems3/s4/s5", - ], - ) - - # Test suite - - native.test_suite( - name = name, - tests = test_names, - ) diff --git a/tools/params_processors/BUILD b/tools/params_processors/BUILD index 3afc72eee5..2466499c9d 100644 --- a/tools/params_processors/BUILD +++ b/tools/params_processors/BUILD @@ -36,60 +36,6 @@ py_binary( visibility = ["//visibility:public"], ) -py_library( - name = "swift_debug_settings_processor_library", - srcs = ["swift_debug_settings_processor.py"], - srcs_version = "PY3", - # TODO: Restrict visibility - visibility = ["//visibility:public"], -) - -py_binary( - name = "swift_debug_settings_processor", - srcs = ["swift_debug_settings_processor.py"], - python_version = "PY3", - srcs_version = "PY3", - # TODO: Restrict visibility - visibility = ["//visibility:public"], - deps = [":swift_debug_settings_processor_library"], -) - -py_test( - name = "swift_debug_settings_processor_tests", - srcs = ["swift_debug_settings_processor_tests.py"], - deps = [ - ":swift_debug_settings_processor_library", - "//:py_init_shim", - ], -) - -py_library( - name = "swift_compiler_params_processor_library", - srcs = ["swift_compiler_params_processor.py"], - srcs_version = "PY3", - # TODO: Restrict visibility - visibility = ["//visibility:public"], -) - -py_binary( - name = "swift_compiler_params_processor", - srcs = ["swift_compiler_params_processor.py"], - python_version = "PY3", - srcs_version = "PY3", - # TODO: Restrict visibility - visibility = ["//visibility:public"], - deps = [":swift_compiler_params_processor_library"], -) - -py_test( - name = "swift_compiler_params_processor_tests", - srcs = ["swift_compiler_params_processor_tests.py"], - deps = [ - ":swift_compiler_params_processor_library", - "//:py_init_shim", - ], -) - # Release filegroup( diff --git a/tools/params_processors/cc_compiler_params_processor.py b/tools/params_processors/cc_compiler_params_processor.py index 1e4165eec9..e9acfaef23 100755 --- a/tools/params_processors/cc_compiler_params_processor.py +++ b/tools/params_processors/cc_compiler_params_processor.py @@ -23,6 +23,7 @@ "-c": 2, "-o": 2, + # TODO: This comment should be updated to not reference opts.bzl # Debug info is handled in `opts.bzl` "-g": 1, diff --git a/tools/params_processors/swift_compiler_params_processor.py b/tools/params_processors/swift_compiler_params_processor.py deleted file mode 100755 index bd554428f9..0000000000 --- a/tools/params_processors/swift_compiler_params_processor.py +++ /dev/null @@ -1,218 +0,0 @@ -#!/usr/bin/python3 - -import sys -from typing import Iterator, List, Optional - - -# Swift compiler flags that we don't want to propagate to Xcode. -# The values are the number of flags to skip, 1 being the flag itself, 2 being -# another flag right after it, etc. -_SWIFTC_SKIP_OPTS = { - # Xcode sets output paths - "-emit-module-path": 2, - "-emit-object": 1, - "-output-file-map": 2, - - # Xcode sets these, and no way to unset them - "-enable-bare-slash-regex": 1, - "-module-name": 2, - "-num-threads": 2, - "-parse-as-library": 1, - "-sdk": 2, - "-target": 2, - - # We want to use Xcode's normal PCM handling - "-module-cache-path": 2, - - # We want Xcode's normal debug handling - "-debug-prefix-map": 2, - "-file-prefix-map": 2, - "-gline-tables-only": 1, - - # We want to use Xcode's normal indexing handling - "-index-ignore-system-modules": 1, - "-index-store-path": 2, - - # We set Xcode build settings to control these - "-enable-batch-mode": 1, - - # We don't want to translate this for BwX - "-emit-symbol-graph-dir": 2, - - # These are handled in `opts.bzl` - "-emit-objc-header-path": 2, - "-explicit-swift-module-map-file": 2, - "-g": 1, - "-incremental": 1, - "-no-whole-module-optimization": 1, - "-swift-version": 2, - "-vfsoverlay": 2, - "-whole-module-optimization": 1, - "-wmo": 1, - "-Xcc": 2, - - # We filter out `-Xfrontend`, then add it back only if the current opt - # wasn't filtered out - "-Xfrontend": 1, - - # This is rules_swift specific, and we don't want to translate it for BwX - "-Xwrapped-swift": 1, -} - -_SWIFTC_SKIP_COMPOUND_OPTS = { - "-Xfrontend": { - # We want Xcode to control coloring - "-color-diagnostics": 1, - - # We want Xcode's normal debug handling - "-no-clang-module-breadcrumbs": 1, - "-no-serialize-debugging-options": 1, - "-serialize-debugging-options": 1, - - # We don't want to translate this for BwX - "-emit-symbol-graph": 1, - - # Handled in `opts.bzl` (skip 3 because of the extra `-Xfrontend` flag) - "-explicit-swift-module-map-file": 3, - "-load-plugin-executable": 3, - "-load-plugin-library": 3, - "-vfsoverlay": 3, - }, -} - - -def _inner_process_swiftcopts(*, opt: str, previous_opt: str) -> Optional[str]: - if (previous_opt == "-I" or opt.startswith("-I") or - previous_opt == "-F" or opt.startswith("-F")): - # BwX Swift include paths are set in `xcode_targets.bzl` - # `_set_swift_include_paths`, and BwB include paths are set in - # `opts.bzl` - return None - - if opt.startswith("-vfsoverlay"): - # Handled in opts.bzl - return None - - if opt[0] != "-" and opt.endswith(".swift"): - # These are the files to compile, not options. They are seen here - # because of the way we collect Swift compiler options. Ideally in - # the future we could collect Swift compiler options similar to how - # we collect C and C++ compiler options. - return None - - return opt - - -def process_args(params_paths: List[str], parse_args) -> List[str]: - # First two lines are "swift_worker" and "swiftc" - skip_next = 2 - - processed_opts = [] - next_previous_opt = None - for params_path in params_paths: - opts_iter = parse_args(params_path) - - next_opt = None - while True: - if next_opt: - opt = next_opt - next_opt = None - else: - opt = next(opts_iter, None) - if opt == None: - break - - # Remove trailing newline - opt = opt[:-1] - - previous_opt = next_previous_opt - next_previous_opt = opt - - if skip_next: - skip_next -= 1 - continue - - # Change "compile.params" from `shell` to `multiline` format - # https://bazel.build/versions/6.1.0/rules/lib/Args#set_param_file_format.format - if opt.startswith("'") and opt.endswith("'"): - opt = opt[1:-1] - - root_opt = opt.split("=")[0] - - compound_skip_next = _SWIFTC_SKIP_COMPOUND_OPTS.get(root_opt) - if compound_skip_next: - next_opt = next(opts_iter, None) - if next_opt: - # Remove trailing newline - next_opt = next_opt[:-1] - skip_next = compound_skip_next.get(next_opt, 0) - if skip_next: - # No need to decrement 1, since we need to skip the - # first opt - continue - - skip_next = _SWIFTC_SKIP_OPTS.get(root_opt, 0) - if skip_next: - skip_next -= 1 - continue - - is_frontend_opt = previous_opt == "-Xfrontend" - - if is_frontend_opt and opt.startswith("-vfsoverlay"): - # Handled in opts.bzl - continue - - processed_opt = _inner_process_swiftcopts( - opt = opt, - previous_opt = previous_opt, - ) - - if processed_opt and is_frontend_opt: - # We filter out `-Xfrontend`, then add it back only if the - # current opt wasn't filtered out - processed_opts.append(previous_opt) - - opt = processed_opt - if not opt: - continue - - # Use Xcode set `DEVELOPER_DIR` - opt = opt.replace( - "__BAZEL_XCODE_DEVELOPER_DIR__", - "$(DEVELOPER_DIR)", - ) - - # Use Xcode set `SDKROOT` - opt = opt.replace("__BAZEL_XCODE_SDKROOT__", "$(SDKROOT)") - - # Quote the option if it contains spaces or build setting variables - if " " in opt or ("$(" in opt and ")" in opt): - opt = f"'{opt}'" - - processed_opts.append(opt) - - return processed_opts - - -def _parse_args(params_path: str) -> Iterator[str]: - return open(params_path, encoding = "utf-8") - - -def _main(output_path: str, params_paths: List[str]) -> None: - processed_opts = process_args(params_paths, _parse_args) - - with open(output_path, encoding = "utf-8", mode = "w") as fp: - result = "\n".join(processed_opts) - fp.write(f'{result}\n') - - -if __name__ == "__main__": - if len(sys.argv) < 3: - print( - f""" -Usage: {sys.argv[0]} output_path [params_file, ...]""", - file = sys.stderr, - ) - exit(1) - - _main(sys.argv[1], sys.argv[2:]) diff --git a/tools/params_processors/swift_compiler_params_processor_tests.py b/tools/params_processors/swift_compiler_params_processor_tests.py deleted file mode 100644 index 3f201bbd1a..0000000000 --- a/tools/params_processors/swift_compiler_params_processor_tests.py +++ /dev/null @@ -1,367 +0,0 @@ -"""Tests for swift_compiler_params_processor.""" - -import unittest - -from tools.params_processors import swift_compiler_params_processor - -class swift_compiler_params_processor_test(unittest.TestCase): - def test_paths(self): - def _parse_args(args): - return iter([f"{arg}\n" for arg in args]) - - self.assertEqual( - swift_compiler_params_processor.process_args( - [[ - "swift_worker", - "swiftc", - - # -fmodule-map-file - "-Xcc", - "-fmodule-map-file=/absolute/path", - "-Xcc", - "-fmodule-map-file=relative/path", - "-Xcc", - "-fmodule-map-file=bazel-out/relative/path", - "-Xcc", - "-fmodule-map-file=external/relative/path", - - # -iquote - "-Xcc", - "-iquote/absolute/path", - "-Xcc", - "-iquote", - "-Xcc", - "/absolute/path", - "-Xcc", - "-iquote", - "-Xcc", - "/absolute/path", - "-Xcc", - "-iquoterelative/path", - "-Xcc", - "-iquote", - "-Xcc", - "relative/path", - "-Xcc", - "-iquotebazel-out/relative/path", - "-Xcc", - "-iquote", - "-Xcc", - "bazel-out/relative/path", - "-Xcc", - "-iquoteexternal/relative/path", - "-Xcc", - "-iquote", - "-Xcc", - "external/relative/path", - "-Xcc", - "-iquote.", - "-Xcc", - "-iquote", - "-Xcc", - ".", - - # -I - "-I/absolute/path", - "-I", - "/absolute/path", - "-Irelative/path", - "-I", - "relative/path", - "-Ibazel-out/relative/path", - "-I", - "bazel-out/relative/path", - "-Iexternal/relative/path", - "-I", - "external/relative/path", - "-I.", - "-I", - ".", - - "-Xcc", - "-I/absolute/path", - "-Xcc", - "-I", - "-Xcc", - "/absolute/path", - "-Xcc", - "-Irelative/path", - "-Xcc", - "-I", - "-Xcc", - "relative/path", - "-Xcc", - "-Ibazel-out/relative/path", - "-Xcc", - "-I", - "-Xcc", - "bazel-out/relative/path", - "-Xcc", - "-Iexternal/relative/path", - "-Xcc", - "-I", - "-Xcc", - "external/relative/path", - "-Xcc", - "-I.", - "-Xcc", - "-I", - "-Xcc", - ".", - - # -isystem - "-Xcc", - "-isystem/absolute/path", - "-Xcc", - "-isystem", - "-Xcc", - "/absolute/path", - "-Xcc", - "-isystemrelative/path", - "-Xcc", - "-isystem", - "-Xcc", - "relative/path", - "-Xcc", - "-isystembazel-out/relative/path", - "-Xcc", - "-isystem", - "-Xcc", - "bazel-out/relative/path", - "-Xcc", - "-isystemexternal/relative/path", - "-Xcc", - "-isystem", - "-Xcc", - "external/relative/path", - "-Xcc", - "-isystem.", - "-Xcc", - "-isystem", - "-Xcc", - ".", - - # -ivfsoverlay - "-Xcc", - "-ivfsoverlay", - "-Xcc", - "/Some/Path.yaml", - "-Xcc", - "-ivfsoverlay", - "-Xcc", - "relative/Path.yaml", - "-Xcc", - "-ivfsoverlay", - "-Xcc", - "bazel-out/relative/Path.yaml", - "-Xcc", - "-ivfsoverlay", - "-Xcc", - "external/relative/Path.yaml", - - "-Xcc", - "-ivfsoverlay/Some/Path.yaml", - "-Xcc", - "-ivfsoverlayrelative/Path.yaml", - "-Xcc", - "-ivfsoverlaybazel-out/relative/Path.yaml", - "-Xcc", - "-ivfsoverlayexternal/relative/Path.yaml", - - "-Xcc", - "-ivfsoverlay=/Some/Path.yaml", - "-Xcc", - "-ivfsoverlay=relative/Path.yaml", - "-Xcc", - "-ivfsoverlay=bazel-out/relative/Path.yaml", - "-Xcc", - "-ivfsoverlay=external/relative/Path.yaml", - ]], - parse_args = _parse_args, - ), - [], - ) - - def test_replacements(self): - def _parse_args(args): - return iter([f"{arg}\n" for arg in args]) - - self.assertEqual( - swift_compiler_params_processor.process_args( - [[ - "swift_worker", - "swiftc", - "-something", - "__BAZEL_XCODE_DEVELOPER_DIR__/hi", - "-another-thing", - "__BAZEL_XCODE_SDKROOT__/path", - "-one-more", - "__BAZEL_XCODE_SOMETHING_/path", - ]], - parse_args = _parse_args, - ), - [ - "-something", - "'$(DEVELOPER_DIR)/hi'", - "-another-thing", - "'$(SDKROOT)/path'", - "-one-more", - '__BAZEL_XCODE_SOMETHING_/path', - ], - ) - - def test_skips(self): - def _parse_args(args): - return iter([f"{arg}\n" for arg in args]) - - self.assertEqual( - swift_compiler_params_processor.process_args( - [[ - "swift_worker", - "swiftc", - "-output-file-map", - "path", - "-passthrough", - "-debug-prefix-map", - "__BAZEL_XCODE_DEVELOPER_DIR__=DEVELOPER_DIR", - "-file-prefix-map", - "__BAZEL_XCODE_DEVELOPER_DIR__=DEVELOPER_DIR", - "-emit-module-path", - "path", - "-passthrough", - "-Xfrontend", - "-color-diagnostics", - "-Xfrontend", - "-import-underlying-module", - "-emit-object", - "-enable-batch-mode", - "-passthrough", - "-gline-tables-only", - "-sdk", - "something", - "-module-name", - "name", - "-passthrough", - "-I__BAZEL_XCODE_SOMETHING_/path", - "-num-threads", - "6", - "-passthrough", - "-Ibazel-out/...", - "-parse-as-library", - "-passthrough", - "-parse-as-library", - "-keep-me=something.swift", - "reject-me.swift", - "-target", - "ios", - "-Xcc", - "-weird", - "-Xcc", - "-a=bazel-out/hi", - "-Xwrapped-swift", - "-passthrough", - ]], - parse_args = _parse_args, - ), - [ - "-passthrough", - "-passthrough", - "-Xfrontend", - "-import-underlying-module", - "-passthrough", - "-passthrough", - "-passthrough", - "-passthrough", - "-keep-me=something.swift", - "-passthrough", - ], - ) - - def test_explicit_swift_module_map_file(self): - def _parse_args(args): - return iter([f"{arg}\n" for arg in args]) - - self.assertEqual( - swift_compiler_params_processor.process_args( - [[ - "swift_worker", - "swiftc", - "-explicit-swift-module-map-file", - "/Some/Path.json", - "-explicit-swift-module-map-file", - "relative/Path.json", - "-Xfrontend", - "-explicit-swift-module-map-file", - "-Xfrontend", - "/Some/Path.json", - "-Xfrontend", - "-explicit-swift-module-map-file", - "-Xfrontend", - "relative/Path.json", - ]], - parse_args = _parse_args, - ), - [], - ) - - def test_vfsoverlay(self): - def _parse_args(args): - return iter([f"{arg}\n" for arg in args]) - - self.assertEqual( - swift_compiler_params_processor.process_args( - [[ - "swift_worker", - "swiftc", - "-vfsoverlay", - "/Some/Path.yaml", - "-vfsoverlay", - "relative/Path.yaml", - "-Xfrontend", - "-vfsoverlay", - "-Xfrontend", - "/Some/Path.yaml", - "-Xfrontend", - "-vfsoverlay", - "-Xfrontend", - "relative/Path.yaml", - "-Xfrontend", - "-vfsoverlay/Some/Path.yaml", - "-Xfrontend", - "-vfsoverlayrelative/Path.yaml", - "-Xfrontend", - "-vfsoverlay=/Some/Path.yaml", - "-Xfrontend", - "-vfsoverlay=relative/Path.yaml", - ]], - parse_args = _parse_args, - ), - [], - ) - - def test_quoting(self): - def _parse_args(args): - return iter([f"{arg}\n" for arg in args]) - - self.assertEqual( - swift_compiler_params_processor.process_args( - [[ - "swift_worker", - "swiftc", - "-something", - "no_spaces", - "-another-thing", - "some spaces", - ]], - parse_args = _parse_args, - ), - [ - "-something", - "no_spaces", - "-another-thing", - "'some spaces'", - ], - ) - -if __name__ == '__main__': - unittest.main() diff --git a/tools/params_processors/swift_debug_settings_processor.py b/tools/params_processors/swift_debug_settings_processor.py deleted file mode 100755 index 36d8c757a4..0000000000 --- a/tools/params_processors/swift_debug_settings_processor.py +++ /dev/null @@ -1,432 +0,0 @@ -#!/usr/bin/python3 - -import json -import os -import sys -from typing import Iterator, List, Optional - - -def _build_setting_path(path): - if path.startswith("bazel-out/"): - return f'$(BAZEL_OUT)/{path[10:]}' - if path.startswith("external/"): - return f'$(BAZEL_EXTERNAL)/{path[9:]}' - return path - -def _is_pre_processed_relative_path(path: str) -> bool: - if path.startswith("/"): - return False - for prefix in _PRE_PROCESSED_REPLACEMENT_PREFIXES: - if path.startswith(prefix): - return False - return True - - -def _is_post_processed_relative_path(path: str) -> bool: - if path.startswith("/"): - return False - for prefix in _POST_PROCESSED_REPLACEMENT_PREFIXES: - if path.startswith(prefix): - return False - return True - - -_PRE_PROCESSED_REPLACEMENT_PREFIXES = [ - "__BAZEL_XCODE_DEVELOPER_DIR__", - "__BAZEL_XCODE_SDKROOT__", -] - -_POST_PROCESSED_REPLACEMENT_PREFIXES = [ - "$(DEVELOPER_DIR)", - "$(SDKROOT)", -] - -_CLANG_PATH_PREFIXES = [ - "-F", - "-fmodule-map-file=", - "-iquote", - "-isystem", - "-I", -] - -_CLANG_SEARCH_PATHS = { - "-iquote": None, - "-isystem": None, - "-I": None, -} - -_ONCE_FLAGS = { - "-D": None, - "-F": None, - "-I": None, -} - - -def _process_clang_opt( - *, - opt: str, - previous_clang_opt: Optional[str]) -> Optional[str]: - if opt == "-Xcc": - return None - - for path_prefix in _CLANG_PATH_PREFIXES: - if opt.startswith(path_prefix): - path = opt[len(path_prefix):] - if not path: - return opt - if path == ".": - return f"{path_prefix}$(PROJECT_DIR)" - if _is_pre_processed_relative_path(path): - return f"{path_prefix}$(PROJECT_DIR)/{path}" - return opt - - if previous_clang_opt in _CLANG_SEARCH_PATHS: - if opt == ".": - return "$(PROJECT_DIR)" - if _is_pre_processed_relative_path(opt): - return "$(PROJECT_DIR)/" + opt - return opt - if previous_clang_opt == "-ivfsoverlay": - # -vfsoverlay doesn't apply `-working_directory=`, so we need to - # prefix it ourselves - if opt[0] != "/": - return "$(PROJECT_DIR)/" + opt - return opt - if opt.startswith("-ivfsoverlay"): - # Remove `-ivfsoverlay` prefix - value = opt[12:] - if not value: - return opt - if not value.startswith("/"): - return "-ivfsoverlay$(PROJECT_DIR)/" + value - return opt - - return opt - - -def _process_swift_opt( - *, - opt: str, - previous_opt: Optional[str], - framework_includes: List[str], - swift_includes: List[str]) -> Optional[str]: - if opt.startswith("-I"): - path = opt[2:] - if not path: - return opt - if path == ".": - path = "$(PROJECT_DIR)" - elif _is_post_processed_relative_path(path): - path = f"$(PROJECT_DIR)/{path}" - swift_includes.append(path) - return None - if previous_opt == "-I": - path = opt - if path == ".": - path = "$(PROJECT_DIR)" - elif _is_post_processed_relative_path(path): - path = f"$(PROJECT_DIR)/{path}" - swift_includes.append(path) - return None - if opt.startswith("-F"): - path = opt[2:] - if not path: - return opt - if path == ".": - path = "$(PROJECT_DIR)" - elif _is_post_processed_relative_path(path): - path = f"$(PROJECT_DIR)/{path}" - framework_includes.append(path) - return None - if previous_opt == "-F": - path = opt - if path == ".": - path = "$(PROJECT_DIR)" - elif _is_post_processed_relative_path(path): - path = f"$(PROJECT_DIR)/{path}" - framework_includes.append(path) - return None - - return None - - -def process_swift_params(params_paths: List[str], parse_args): - clang_opts = [] - framework_includes = [] - swift_includes = [] - next_previous_opt = None - previous_clang_opt = None - for params_path in params_paths: - for opt in parse_args(params_path): - # Remove trailing newline - opt = opt[:-1] - - # Change "compile.params" from `shell` to `multiline` format - # https://bazel.build/versions/6.1.0/rules/lib/Args#set_param_file_format.format - if opt.startswith("'") and opt.endswith("'"): - opt = opt[1:-1] - - previous_opt = next_previous_opt - next_previous_opt = opt - - is_clang_opt = opt == "-Xcc" or previous_opt == "-Xcc" - - if is_clang_opt: - processed_opt = _process_clang_opt( - opt = opt, - previous_clang_opt = previous_clang_opt, - ) - - if previous_opt == "-Xcc": - previous_clang_opt = opt - elif opt != "-Xcc": - previous_clang_opt = None - - if is_clang_opt: - opt = processed_opt - - if opt: - # Use Xcode set `DEVELOPER_DIR` - opt = opt.replace( - "__BAZEL_XCODE_DEVELOPER_DIR__", - "$(DEVELOPER_DIR)", - ) - - # Use Xcode set `SDKROOT` - opt = opt.replace("__BAZEL_XCODE_SDKROOT__", "$(SDKROOT)") - - if is_clang_opt: - if opt: - clang_opts.append(opt) - else: - _process_swift_opt( - opt = opt, - previous_opt = previous_opt, - framework_includes = framework_includes, - swift_includes = swift_includes, - ) - - return framework_includes, swift_includes, clang_opts - - -def _main(args: Iterator[str]) -> None: - output_path = next(args)[:-1] - xcode_generated_paths_path = next(args)[:-1] - - with open(xcode_generated_paths_path, encoding = "utf-8") as fp: - xcode_generated_paths = json.load(fp) - - if xcode_generated_paths: - def _handle_swiftmodule_path(path: str) -> str: - bs_path = xcode_generated_paths.get(path) - if not bs_path: - bs_path = _build_setting_path(path) - return os.path.dirname(bs_path) - else: - def _handle_swiftmodule_path(path: str) -> str: - return os.path.dirname(_build_setting_path(path)) - - contexts = {} - while True: - key = next(args, "\n")[:-1] - if key == "": - break - - swiftmodule_includes = {} - while True: - path = next(args)[:-1] - if path == "": - break - # In BwX mode swiftmodule paths are passed since we might need to - # remap them. We process them first, so that remapped paths are - # searched first. Any missed paths, such as for testing frameworks - # will be added to the end by the params processing. - swiftmodule_includes[_handle_swiftmodule_path(path)] = None - - once_flags = {} - clang_opts = [] - framework_includes = {} - parse_cache = {} - while True: - swift_sub_params_list = [] - while True: - swift_params = next(args)[:-1] - if swift_params == "": - # Groups of swift params files are separated by a blank line - break - swift_sub_params_list.append(swift_params) - if not swift_sub_params_list: - # If we didn't get any swift params files, we're done with - # processing clang opts - break - - parse_cache_key = " ".join(swift_sub_params_list) - - parse = parse_cache.get(parse_cache_key, None) - if not parse: - parse = process_swift_params( - params_paths = swift_sub_params_list, - parse_args = _parse_args, - ) - parse_cache[parse_cache_key] = parse - ( - raw_framework_includes, - raw_swift_includes, - raw_clang_opts, - ) = parse - - for path in raw_framework_includes: - framework_includes[path] = None - for path in raw_swift_includes: - swiftmodule_includes[path] = None - - for opt in raw_clang_opts: - if opt in once_flags: - continue - if ((opt[0:2] in _ONCE_FLAGS) or - opt.startswith("-fmodule-map-file=")): - # This can lead to correctness issues if the value of a - # define is specified multiple times, and different on - # different targets, but it's how lldb currently handles it. - # Ideally it should use a dictionary for the key of the - # define and only filter ones that have the same value as - # the last time the key was used. - once_flags[opt] = None - # Escape spaces in paths, since these opts are whitespace - # separated - clang_opts.append(opt.replace(' ', '\\ ')) - - dto = {} - - if clang_opts: - dto["c"] = " ".join(clang_opts) - if framework_includes: - dto["f"] = list(framework_includes.keys()) - if swiftmodule_includes: - dto["s"] = list(swiftmodule_includes.keys()) - - if dto: - contexts[key] = dto - - with open(output_path, encoding = "utf-8", mode = "w") as fp: - settings_content = json.dumps(contexts, indent = '\t', sort_keys = True) - result = f'''\ -#!/usr/bin/python3 - -"""An lldb module that registers a stop hook to set swift settings.""" - -import lldb -import re - -# Order matters, it needs to be from the most nested to the least -_BUNDLE_EXTENSIONS = [ - ".framework", - ".xctest", - ".appex", - ".bundle", - ".app", -] - -_TRIPLE_MATCH = re.compile(r"([^-]+-[^-]+)(-\D+)[^-]*(-.*)?") - -_SETTINGS = {settings_content} - -def __lldb_init_module(debugger, _internal_dict): - # Register the stop hook when this module is loaded in lldb - ci = debugger.GetCommandInterpreter() - res = lldb.SBCommandReturnObject() - ci.HandleCommand( - "target stop-hook add -P swift_debug_settings.StopHook", - res, - ) - if not res.Succeeded(): - print(f"""\\ -Failed to register Swift debug options stop hook: - -{{res.GetError()}} -Please file a bug report here: \\ -https://github.com/MobileNativeFoundation/rules_xcodeproj/issues/new?template=bug.md -""") - return - -def _get_relative_executable_path(module): - for extension in _BUNDLE_EXTENSIONS: - prefix, _, suffix = module.rpartition(extension) - if prefix: - return prefix.split("/")[-1] + extension + suffix - return module.split("/")[-1] - -class StopHook: - "An lldb stop hook class, that sets swift settings for the current module." - - def __init__(self, _target, _extra_args, _internal_dict): - pass - - def handle_stop(self, exe_ctx, _stream): - "Method that is called when the user stops in lldb." - module = exe_ctx.frame.module - if not module: - return - - module_name = module.file.GetDirectory() + "/" + module.file.GetFilename() - versionless_triple = _TRIPLE_MATCH.sub(r"\\1\\2\\3", module.GetTriple()) - executable_path = _get_relative_executable_path(module_name) - key = f"{{versionless_triple}} {{executable_path}}" - - settings = _SETTINGS.get(key) - - if settings: - frameworks = " ".join([ - f'"{{path}}"' - for path in settings.get("f", []) - ]) - if frameworks: - lldb.debugger.HandleCommand( - f"settings set -- target.swift-framework-search-paths {{frameworks}}", - ) - else: - lldb.debugger.HandleCommand( - "settings clear target.swift-framework-search-paths", - ) - - includes = " ".join([ - f'"{{path}}"' - for path in settings.get("s", []) - ]) - if includes: - lldb.debugger.HandleCommand( - f"settings set -- target.swift-module-search-paths {{includes}}", - ) - else: - lldb.debugger.HandleCommand( - "settings clear target.swift-module-search-paths", - ) - - clang = settings.get("c") - if clang: - lldb.debugger.HandleCommand( - f"settings set -- target.swift-extra-clang-flags '{{clang}}'", - ) - else: - lldb.debugger.HandleCommand( - "settings clear target.swift-extra-clang-flags", - ) - - return True''' - fp.write(f'{result}\n') - - -def _parse_args(params_path: str) -> Iterator[str]: - return open(params_path, encoding = "utf-8") - - -if __name__ == "__main__": - if len(sys.argv) != 2: - print( - f""" -Usage: {sys.argv[0]} @params_file""", - file = sys.stderr, - ) - exit(1) - - _main(_parse_args(sys.argv[1][1:])) diff --git a/tools/params_processors/swift_debug_settings_processor_tests.py b/tools/params_processors/swift_debug_settings_processor_tests.py deleted file mode 100644 index 21e788b24d..0000000000 --- a/tools/params_processors/swift_debug_settings_processor_tests.py +++ /dev/null @@ -1,314 +0,0 @@ -"""Tests for swift_debug_settings_processor.""" - -import unittest - -from tools.params_processors import swift_debug_settings_processor - - -def _before_each(seq, element): - return [ - y - for x in seq - for y in (element, x) - ] - - -class swift_debug_settings_processor_test(unittest.TestCase): - - def test_paths(self): - def _parse_args(args): - return iter([f"{arg}\n" for arg in args]) - - ( - framework_includes, - swift_includes, - clang_opts, - ) = swift_debug_settings_processor.process_swift_params( - [[ - "swiftc", - - # -fmodule-map-file - *_before_each( - [ - "-fmodule-map-file=/absolute/path", - "-fmodule-map-file=relative/path", - "-fmodule-map-file=.", - ], - "-Xcc", - ), - - # -iquote - "-iquote/absolute/path", - "-iquote", - "/absolute/path", - "-iquote", - "/absolute/path", - "-iquoterelative/path", - "-iquote", - "relative/path", - "-iquote.", - "-iquote", - ".", - - *_before_each( - [ - "-iquote/absolute/path", - "-iquote", - "/absolute/path", - "-iquote", - "/absolute/path", - "-iquoterelative/path", - "-iquote", - "relative/path", - "-iquote.", - "-iquote", - ".", - ], - "-Xcc", - ), - - # -F - "-F/absolute/fpath", - "-F", - "/absolute/fpath2", - "-Frelative/fpath", - "-F", - "relative/fpath2", - "-F.", - "-F", - ".", - - # -I - "-I/absolute/ipath", - "-I", - "/absolute/ipath2", - "-Irelative/ipath", - "-I", - "relative/ipath2", - "-I.", - "-I", - ".", - - *_before_each( - [ - "-I/absolute/path", - "-I", - "/absolute/path", - "-Irelative/path", - "-I", - "relative/path", - "-I.", - "-I", - ".", - ], - "-Xcc", - ), - - # -isystem - "-isystem/absolute/path", - "-isystem", - "/absolute/path", - "-isystemrelative/path", - "-isystem", - "relative/path", - "-isystem.", - "-isystem", - ".", - - *_before_each( - [ - "-isystem/absolute/path", - "-isystem", - "/absolute/path", - "-isystemrelative/path", - "-isystem", - "relative/path", - "-isystem.", - "-isystem", - ".", - ], - "-Xcc", - ), - ]], - parse_args = _parse_args, - ) - - self.assertEqual( - framework_includes, - [ - "/absolute/fpath", - "/absolute/fpath2", - "$(PROJECT_DIR)/relative/fpath", - "$(PROJECT_DIR)/relative/fpath2", - "$(PROJECT_DIR)", - "$(PROJECT_DIR)", - ], - ) - - self.assertEqual( - swift_includes, - [ - "/absolute/ipath", - "/absolute/ipath2", - "$(PROJECT_DIR)/relative/ipath", - "$(PROJECT_DIR)/relative/ipath2", - "$(PROJECT_DIR)", - "$(PROJECT_DIR)", - ], - ) - - self.assertEqual( - clang_opts, - [ - # -fmodule-map-file - "-fmodule-map-file=/absolute/path", - "-fmodule-map-file=$(PROJECT_DIR)/relative/path", - "-fmodule-map-file=$(PROJECT_DIR)", - - # -iquote - "-iquote/absolute/path", - "-iquote", - "/absolute/path", - "-iquote", - "/absolute/path", - "-iquote$(PROJECT_DIR)/relative/path", - "-iquote", - "$(PROJECT_DIR)/relative/path", - "-iquote$(PROJECT_DIR)", - "-iquote", - "$(PROJECT_DIR)", - - # -I - "-I/absolute/path", - "-I", - "/absolute/path", - "-I$(PROJECT_DIR)/relative/path", - "-I", - "$(PROJECT_DIR)/relative/path", - "-I$(PROJECT_DIR)", - "-I", - "$(PROJECT_DIR)", - - # -isystem - "-isystem/absolute/path", - "-isystem", - "/absolute/path", - "-isystem$(PROJECT_DIR)/relative/path", - "-isystem", - "$(PROJECT_DIR)/relative/path", - "-isystem$(PROJECT_DIR)", - "-isystem", - "$(PROJECT_DIR)", - ], - ) - - def test_replacements(self): - def _parse_args(args): - return iter([f"{arg}\n" for arg in args]) - - ( - framework_includes, - swift_includes, - clang_opts, - ) = swift_debug_settings_processor.process_swift_params( - [[ - "swiftc", - - "-F__BAZEL_XCODE_DEVELOPER_DIR__/Hi", - "-F__BAZEL_XCODE_SOMETHING_/path", - - *_before_each( - [ - "-F__BAZEL_XCODE_DEVELOPER_DIR__/Hi", - "-I__BAZEL_XCODE_SDKROOT__/Yo", - "-I__BAZEL_XCODE_SOMETHING_/path", - ], - "-Xcc", - ) - ]], - parse_args = _parse_args, - ) - - self.assertEqual( - framework_includes, - [ - "$(DEVELOPER_DIR)/Hi", - "$(PROJECT_DIR)/__BAZEL_XCODE_SOMETHING_/path", - ], - ) - - self.assertEqual( - clang_opts, - [ - "-F$(DEVELOPER_DIR)/Hi", - "-I$(SDKROOT)/Yo", - "-I$(PROJECT_DIR)/__BAZEL_XCODE_SOMETHING_/path", - ], - ) - - def test_vfsoverlay(self): - def _parse_args(args): - return iter([f"{arg}\n" for arg in args]) - - ( - _, - _, - clang_opts, - ) = swift_debug_settings_processor.process_swift_params( - [[ - "swiftc", - - "-vfsoverlay", - "/skipped/Some/Path.yaml", - "-vfsoverlay", - "skipped/relative/Path.yaml", - "-Xfrontend", - "-vfsoverlay", - "-Xfrontend", - "/skipped/Some/Path.yaml", - "-Xfrontend", - "-vfsoverlay", - "-Xfrontend", - "skipped/relative/Path.yaml", - "-Xfrontend", - "-vfsoverlay/skipped/Some/Path.yaml", - "-Xfrontend", - "-vfsoverlayskipped/relative/Path.yaml", - - *_before_each( - [ - "-ivfsoverlay", - "/Some/Path.yaml", - "-ivfsoverlay", - "relative/Path.yaml", - "-ivfsoverlay", - "/Some/Path.yaml", - "-ivfsoverlay", - "relative/Path.yaml", - "-ivfsoverlay/Some/Path.yaml", - "-ivfsoverlayrelative/Path.yaml", - ], - "-Xcc", - ) - ]], - parse_args = _parse_args, - ) - - self.assertEqual( - clang_opts, - [ - "-ivfsoverlay", - "/Some/Path.yaml", - "-ivfsoverlay", - "$(PROJECT_DIR)/relative/Path.yaml", - "-ivfsoverlay", - "/Some/Path.yaml", - "-ivfsoverlay", - "$(PROJECT_DIR)/relative/Path.yaml", - "-ivfsoverlay/Some/Path.yaml", - "-ivfsoverlay$(PROJECT_DIR)/relative/Path.yaml", - ], - ) - -if __name__ == '__main__': - unittest.main() diff --git a/xcodeproj/internal/opts.bzl b/xcodeproj/internal/opts.bzl deleted file mode 100644 index 030b970ea8..0000000000 --- a/xcodeproj/internal/opts.bzl +++ /dev/null @@ -1,648 +0,0 @@ -"""Functions for processing compiler and linker options.""" - -load("//xcodeproj/internal/files:files.bzl", "build_setting_path", "is_relative_path", "quote_if_needed") -load(":collections.bzl", "set_if_true") -load(":memory_efficiency.bzl", "EMPTY_LIST") - -# Maps Swift compliation mode compiler flags to the corresponding Xcode values -_SWIFT_COMPILATION_MODE_OPTS = { - "-incremental": "singlefile", - "-no-whole-module-optimization": "singlefile", - "-whole-module-optimization": "wholemodule", - "-wmo": "wholemodule", -} - -# Compiler option processing - -_CC_COMPILE_ACTIONS = { - "CppCompile": None, - "ObjcCompile": None, -} - -def _get_unprocessed_cc_compiler_opts( - *, - # buildifier: disable=unused-variable - ctx, - c_sources, - cxx_sources, - # buildifier: disable=unused-variable - has_swift_opts, - target, - # buildifier: disable=unused-variable - implementation_compilation_context): - conlyopts = EMPTY_LIST - conly_args = EMPTY_LIST - cxxopts = EMPTY_LIST - cxx_args = EMPTY_LIST - - if not c_sources and not cxx_sources: - return (conlyopts, conly_args, cxxopts, cxx_args) - - for action in target.actions: - if action.mnemonic not in _CC_COMPILE_ACTIONS: - continue - - previous_arg = None - for arg in action.argv: - if previous_arg == "-c": - if not conly_args and arg in c_sources: - # First argument is "wrapped_clang" - conlyopts = action.argv[1:] - conly_args = action.args - elif not cxx_args and arg in cxx_sources: - # First argument is "wrapped_clang_pp" - cxxopts = action.argv[1:] - cxx_args = action.args - break - previous_arg = arg - - if ((not c_sources or conly_args) and - (not cxx_sources or cxx_args)): - # We've found all the args we are looking for - break - - return conlyopts, conly_args, cxxopts, cxx_args - -_LOAD_PLUGIN_OPTS = { - "-load-plugin-executable": None, - "-load-plugin-library": None, -} - -_OVERLAY_OPTS = { - "-explicit-swift-module-map-file": None, - "-vfsoverlay": None, -} - -def _get_unprocessed_compiler_opts( - *, - ctx, - c_sources, - cxx_sources, - target, - implementation_compilation_context): - """Returns the unprocessed compiler options for the given target. - - Args: - ctx: The aspect context. - c_sources: A `dict` of C source paths. - cxx_sources: A `dict` of C++ source paths. - target: The `Target` that the compiler options will be retrieved from. - implementation_compilation_context: The implementation deps aware - `CcCompilationContext` for `target`. - - Returns: - A `tuple` containing three elements: - - * A `list` of C compiler options. - * A `list` of C++ compiler options. - * A `list` of Swift compiler options. - """ - - swiftcopts = EMPTY_LIST - swift_args = EMPTY_LIST - for action in target.actions: - if action.mnemonic == "SwiftCompile": - # First two arguments are "worker" and "swiftc" - swiftcopts = action.argv[2:] - swift_args = action.args - break - - ( - conlyopts, - conly_args, - cxxopts, - cxx_args, - ) = _get_unprocessed_cc_compiler_opts( - ctx = ctx, - c_sources = c_sources, - cxx_sources = cxx_sources, - has_swift_opts = bool(swiftcopts), - target = target, - implementation_compilation_context = implementation_compilation_context, - ) - - return ( - conlyopts, - conly_args, - cxxopts, - cxx_args, - swiftcopts, - swift_args, - ) - -_CLANG_SEARCH_PATH_OPTS = { - "-F": None, - "-I": None, - "-iquote": None, - "-isystem": None, -} - -def _process_swiftcopts( - opts, - *, - package_bin_dir, - build_settings): - """Processes the full Swift compiler options (including Bazel ones). - - Args: - opts: A `list` of Swift compiler options. - package_bin_dir: The package directory for the target within - `ctx.bin_dir`. - build_settings: A mutable `dict` that will be updated with build - settings that are parsed from `opts`. - - Returns: - A `bool` indicting if the target has debug info enabled. - """ - has_debug_info = False - next_previous_opt = None - next_previous_clang_opt = None - next_previous_frontend_opt = None - project_set_opts = [] - for opt in opts: - previous_opt = next_previous_opt - next_previous_opt = opt - - if opt == "-Xfrontend": - # Skipped to simplify the checks below - continue - - previous_frontend_opt = next_previous_frontend_opt - if previous_opt == "-Xfrontend": - next_previous_frontend_opt = opt - else: - next_previous_frontend_opt = None - - if opt == "-Xcc": - project_set_opts.append(opt) - continue - - is_clang_opt = previous_opt == "-Xcc" - - previous_clang_opt = next_previous_clang_opt - if is_clang_opt: - next_previous_clang_opt = opt - else: - next_previous_clang_opt = None - - if opt == "-g": - if is_clang_opt: - project_set_opts.pop() - else: - has_debug_info = True - continue - - compilation_mode = _SWIFT_COMPILATION_MODE_OPTS.get(opt, "") - if compilation_mode: - build_settings["SWIFT_COMPILATION_MODE"] = compilation_mode - continue - - if opt.startswith("-swift-version="): - version = opt[15:] - if version != "5.0": - build_settings["SWIFT_VERSION"] = version - continue - - if previous_opt == "-emit-objc-header-path": - if not opt.startswith(package_bin_dir): - fail("""\ --emit-objc-header-path must be in bin dir of the target. {} is not \ -under {}""".format(opt, package_bin_dir)) - header_name = opt[len(package_bin_dir) + 1:] - build_settings["SWIFT_OBJC_INTERFACE_HEADER_NAME"] = header_name - continue - - if is_clang_opt: - if opt.startswith("-fmodule-map-file="): - path = opt[18:] - absolute_opt = "-fmodule-map-file=" + build_setting_path(path) - project_set_opts.append(absolute_opt) - continue - - if (previous_clang_opt in _CLANG_SEARCH_PATH_OPTS): - absolute_opt = build_setting_path(opt) - project_set_opts.append(absolute_opt) - continue - - handled_seach_opt = False - for search_opt in _CLANG_SEARCH_PATH_OPTS: - if opt.startswith(search_opt): - path = opt[len(search_opt):] - if not path: - absolute_opt = opt - else: - project_set_opts.append(search_opt) - project_set_opts.append("-Xcc") - absolute_opt = build_setting_path(path) - project_set_opts.append(absolute_opt) - handled_seach_opt = True - break - if handled_seach_opt: - continue - - # -ivfsoverlay doesn't apply `-working_directory=`, so we need to - # prefix it ourselves - if previous_clang_opt == "-ivfsoverlay": - path = opt - if is_relative_path(path): - absolute_opt = "$(PROJECT_DIR)/" + path - else: - absolute_opt = opt - project_set_opts.append(absolute_opt) - continue - - if opt.startswith("-ivfsoverlay"): - path = opt[12:] - if path.startswith("="): - path = path[1:] - if not path: - absolute_opt = opt - elif is_relative_path(path): - absolute_opt = ( - "-ivfsoverlay$(PROJECT_DIR)/" + path - ) - else: - absolute_opt = opt - project_set_opts.append(absolute_opt) - continue - - project_set_opts.append(opt) - continue - else: - if previous_opt == "-I": - path = opt - - # We include non-relative paths in BwX mode to account for - # `/Applications/Xcode.app/Contents/Developer/Platforms/PLATFORM/Developer/usr/lib` - absolute_opt = build_setting_path(opt) - project_set_opts.append(previous_opt) - project_set_opts.append(absolute_opt) - continue - - if opt.startswith("-I"): - path = opt[2:] - - # We include non-relative paths in BwX mode to account for - # `/Applications/Xcode.app/Contents/Developer/Platforms/PLATFORM/Developer/usr/lib` - if not path: - # We will add the opt back above - continue - absolute_opt = "-I" + build_setting_path(path) - project_set_opts.append(absolute_opt) - continue - - if previous_opt == "-F": - path = opt - absolute_opt = build_setting_path(opt) - project_set_opts.append(absolute_opt) - continue - - if opt.startswith("-F"): - path = opt[2:] - if not path: - absolute_opt = opt - else: - absolute_opt = "-F" + build_setting_path(path) - project_set_opts.append(absolute_opt) - continue - - if previous_opt == "-Xfrontend": - previous_opt_to_check = previous_frontend_opt - append_previous_opt = True - else: - previous_opt_to_check = previous_opt - append_previous_opt = False - - if previous_opt_to_check in _OVERLAY_OPTS: - path = opt - absolute_opt = build_setting_path(path) - if append_previous_opt: - project_set_opts.append(previous_opt) - project_set_opts.append(absolute_opt) - continue - - if opt == "-explicit-swift-module-map-file": - if append_previous_opt: - project_set_opts.append(previous_opt) - project_set_opts.append(opt) - continue - - if opt in _LOAD_PLUGIN_OPTS: - if append_previous_opt: - project_set_opts.append(previous_opt) - project_set_opts.append(opt) - continue - - if previous_opt_to_check in _LOAD_PLUGIN_OPTS: - path = opt - absolute_opt = build_setting_path(path) - if append_previous_opt: - project_set_opts.append(previous_opt) - project_set_opts.append(absolute_opt) - continue - - if opt.startswith("-vfsoverlay"): - path = opt[11:] - if path.startswith("="): - path = path[1:] - if not path: - absolute_opt = opt - else: - absolute_opt = "-vfsoverlay" + build_setting_path(path) - if append_previous_opt: - project_set_opts.append(previous_opt) - project_set_opts.append(absolute_opt) - continue - - # Xcode's SourceKit `source.request.editor.open.interface` request filters a - # lot of arguments, and the params file in particular. In order to fix this - # request we need to include `-I` and `-vfsoverlay` arguments in the - # `OTHER_SWIFT_FLAGS` build setting. Above we set `project_set_opts` to - # include those arguments. We also filter these same arguments in - # `swift_compiler_params_processor.py` to prevent duplication. - # - # Since `-working-directory` is also filtered for the request, we ensure - # that relative paths use `$(PROJECT_DIR)`. - set_if_true( - build_settings, - "OTHER_SWIFT_FLAGS", - " ".join([quote_if_needed(opt) for opt in project_set_opts]), - ) - - return has_debug_info - -def _create_compile_params( - *, - actions, - name, - args, - opt_type, - params_processor): - if not args or not actions: - return None, None - - def _create_compiler_sub_params(idx, sub_args): - sub_output = actions.declare_file( - "{}.rules_xcodeproj.{}.compile.sub-{}.params".format( - name, - opt_type, - idx, - ), - ) - actions.write( - output = sub_output, - content = sub_args, - ) - return sub_output - - sub_params = [ - _create_compiler_sub_params(idx, sub_args) - for idx, sub_args in enumerate(args) - ] - - params = actions.declare_file( - "{}.rules_xcodeproj.{}.compile.params".format(name, opt_type.lower()), - ) - - params_args = actions.args() - params_args.add(params) - params_args.add_all(sub_params) - - actions.run( - executable = params_processor, - arguments = [params_args], - mnemonic = "Process{}CompileParams".format(opt_type), - progress_message = "Generating %{output}", - inputs = sub_params, - outputs = [params], - ) - - return params, sub_params - -def _process_compiler_opts( - *, - actions, - build_settings, - cc_compiler_params_processor, - conly_args, - conlyopts, - cpp_fragment, - cxx_args, - cxxopts, - name, - package_bin_dir, - swift_args, - swift_compiler_params_processor, - swiftcopts): - """Processes compiler options. - - Args: - actions: `ctx.actions`. - build_settings: A mutable `dict` that will be updated with build - settings that are parsed the `conlyopts`, `cxxopts`, and - `swiftcopts` lists. - cc_compiler_params_processor: The `cc_compiler_params_processor` - executable. - conly_args: An `Args` object for C compiler options. - conlyopts: A `list` of C compiler options. - cpp_fragment: The `cpp` configuration fragment. - cxx_args: An `Args` object for C compiler options. - cxxopts: A `list` of C++ compiler options. - name: The name of the target. - package_bin_dir: The package directory for the target within - `ctx.bin_dir`. - swift_args: An `Args` object for Swift compiler options. - swift_compiler_params_processor: The `swift_compiler_params_processor` - executable. - swiftcopts: A `list` of Swift compiler options. - - Returns: - A `tuple` containing six elements: - - * A C compiler params `File`. - * A C++ compiler params `File`. - * A Swift compiler params `File`. - * A `list` of Swift compiler sub-params `File`s. - * A `bool` that is `True` if C compiler options contain - "-D_FORTIFY_SOURCE=1". - * A `bool` that is `True` if C++ compiler options contain - "-D_FORTIFY_SOURCE=1". - """ - has_swiftcopts = bool(swiftcopts) - - c_has_debug_info = "-g" in conlyopts - cxx_has_debug_info = "-g" in cxxopts - swift_has_debug_info = _process_swiftcopts( - opts = swiftcopts, - package_bin_dir = package_bin_dir, - build_settings = build_settings, - ) - - if conlyopts or cxxopts or has_swiftcopts: - if cpp_fragment.apple_generate_dsym: - # Set to dwarf, because Bazel will generate the dSYMs - # We don't set "DEBUG_INFORMATION_FORMAT" to "dwarf", as we set - # that at the project level - pass - elif c_has_debug_info or cxx_has_debug_info or swift_has_debug_info: - # We don't set "DEBUG_INFORMATION_FORMAT" to "dwarf", as we set that - # at the project level - pass - else: - build_settings["DEBUG_INFORMATION_FORMAT"] = "" - - c_params, _ = _create_compile_params( - actions = actions, - name = name, - args = conly_args, - opt_type = "C", - params_processor = cc_compiler_params_processor, - ) - cxx_params, _ = _create_compile_params( - actions = actions, - name = name, - args = cxx_args, - opt_type = "CXX", - params_processor = cc_compiler_params_processor, - ) - swift_params, swift_sub_params = _create_compile_params( - actions = actions, - name = name, - args = swift_args, - opt_type = "Swift", - params_processor = swift_compiler_params_processor, - ) - - c_has_fortify_source = "-D_FORTIFY_SOURCE=1" in conlyopts - cxx_has_fortify_source = "-D_FORTIFY_SOURCE=1" in cxxopts - - return ( - c_params, - cxx_params, - swift_params, - swift_sub_params, - c_has_fortify_source, - cxx_has_fortify_source, - ) - -def _process_target_compiler_opts( - *, - ctx, - c_sources, - cxx_sources, - target, - implementation_compilation_context, - package_bin_dir, - build_settings): - """Processes the compiler options for a target. - - Args: - ctx: The aspect context. - c_sources: A `dict` of C source paths. - cxx_sources: A `dict` of C++ source paths. - target: The `Target` that the compiler options will be retrieved from. - implementation_compilation_context: The implementation deps aware - `CcCompilationContext` for `target`. - package_bin_dir: The package directory for `target` within - `ctx.bin_dir`. - build_settings: A mutable `dict` that will be updated with build - settings that are parsed from the target's compiler options. - - Returns: - A `tuple` containing six elements: - - * A C compiler params `File`. - * A C++ compiler params `File`. - * A Swift compiler params `File`. - * A `bool` that is `True` if C compiler options contain - "-D_FORTIFY_SOURCE=1". - * A `bool` that is `True` if C++ compiler options contain - "-D_FORTIFY_SOURCE=1". - * A `list` of Swift PCM (clang) compiler options. - """ - ( - conlyopts, - conly_args, - cxxopts, - cxx_args, - swiftcopts, - swift_args, - ) = _get_unprocessed_compiler_opts( - ctx = ctx, - c_sources = c_sources, - cxx_sources = cxx_sources, - target = target, - implementation_compilation_context = implementation_compilation_context, - ) - return _process_compiler_opts( - actions = ctx.actions, - name = ctx.rule.attr.name, - conlyopts = conlyopts, - conly_args = conly_args, - cxxopts = cxxopts, - cxx_args = cxx_args, - swiftcopts = swiftcopts, - swift_args = swift_args, - cpp_fragment = ctx.fragments.cpp, - package_bin_dir = package_bin_dir, - build_settings = build_settings, - cc_compiler_params_processor = ( - ctx.executable._cc_compiler_params_processor - ), - swift_compiler_params_processor = ( - ctx.executable._swift_compiler_params_processor - ), - ) - -# API - -def process_opts( - *, - ctx, - c_sources, - cxx_sources, - target, - implementation_compilation_context, - package_bin_dir, - build_settings): - """Processes the compiler options for a target. - - Args: - ctx: The aspect context. - c_sources: A `dict` of C source paths. - cxx_sources: A `dict` of C++ source paths. - target: The `Target` that the compiler and linker options will be - retrieved from. - implementation_compilation_context: The implementation deps aware - `CcCompilationContext` for `target`. - package_bin_dir: The package directory for `target` within - `ctx.bin_dir`. - build_settings: A mutable `dict` that will be updated with build - settings that are parsed from the compiler and linker options. - - Returns: - A `tuple` containing six elements: - - * A C compiler params `File`. - * A C++ compiler params `File`. - * A Swift compiler params `File`. - * A `bool` that is `True` if C compiler options contain - "-D_FORTIFY_SOURCE=1". - * A `bool` that is `True` if C++ compiler options contain - "-D_FORTIFY_SOURCE=1". - * A `list` of Swift PCM (clang) compiler options. - """ - return _process_target_compiler_opts( - ctx = ctx, - c_sources = c_sources, - cxx_sources = cxx_sources, - target = target, - implementation_compilation_context = implementation_compilation_context, - package_bin_dir = package_bin_dir, - build_settings = build_settings, - ) - -# These functions are exposed only for access in unit tests. -testable = struct( - process_compiler_opts = _process_compiler_opts, -) From 95e79c1c452f1a0a454ffcb7815befb6b4e2e599 Mon Sep 17 00:00:00 2001 From: John Flanagan Date: Thu, 19 Feb 2026 13:47:45 -0600 Subject: [PATCH 2/2] Add missed comment Signed-off-by: John Flanagan --- xcodeproj/internal/compilation_providers.bzl | 1 + 1 file changed, 1 insertion(+) diff --git a/xcodeproj/internal/compilation_providers.bzl b/xcodeproj/internal/compilation_providers.bzl index 9fd1e31d0d..9ed30b4832 100644 --- a/xcodeproj/internal/compilation_providers.bzl +++ b/xcodeproj/internal/compilation_providers.bzl @@ -25,6 +25,7 @@ def _legacy_merge_cc_compilation_context( return direct_compilation_context compilation_context = cc_common.create_compilation_context( + # TODO: This comment should be updated to not reference opts.bzl # Maybe not correct, but we don't use this value in `opts.bzl`, so not # worth the computation to merge it headers = direct_compilation_context.headers,