Skip to content

Commit

Permalink
Remove conditionals for Xcode versions pre Xcode 13 (#1029)
Browse files Browse the repository at this point in the history
  • Loading branch information
keith authored Mar 22, 2023
1 parent d577f38 commit af526d3
Showing 1 changed file with 10 additions and 44 deletions.
54 changes: 10 additions & 44 deletions swift/internal/xcode_swift_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -137,28 +137,17 @@ def _command_line_objc_copts(compilation_mode, cpp_fragment, objc_fragment):

def _platform_developer_framework_dir(
apple_toolchain,
target_triple,
xcode_config):
target_triple):
"""Returns the Developer framework directory for the platform.
Args:
apple_toolchain: The `apple_common.apple_toolchain()` object.
target_triple: The triple of the platform being targeted.
xcode_config: The Xcode configuration.
Returns:
The path to the Developer framework directory for the platform if one
exists, otherwise `None`.
"""

# All platforms have a `Developer/Library/Frameworks` directory in their
# platform root, except for watchOS prior to Xcode 12.5.
if (
target_triples.unversioned_os(target_triple) == "watchos" and
not _is_xcode_at_least_version(xcode_config, "12.5")
):
return None

return paths.join(
apple_toolchain.developer_dir(),
"Platforms",
Expand All @@ -168,26 +157,22 @@ def _platform_developer_framework_dir(
"Developer/Library/Frameworks",
)

def _sdk_developer_framework_dir(apple_toolchain, target_triple, xcode_config):
def _sdk_developer_framework_dir(apple_toolchain, target_triple):
"""Returns the Developer framework directory for the SDK.
Args:
apple_toolchain: The `apple_common.apple_toolchain()` object.
target_triple: The triple of the platform being targeted.
xcode_config: The Xcode configuration.
Returns:
The path to the Developer framework directory for the SDK if one
exists, otherwise `None`.
"""

# All platforms have a `Developer/Library/Frameworks` directory in their SDK
# root except for macOS (all versions of Xcode so far), and watchOS (prior
# to Xcode 12.5).
# root except for macOS (all versions of Xcode so far)
os = target_triples.unversioned_os(target_triple)
if (os == "macos" or
(os == "watchos" and
not _is_xcode_at_least_version(xcode_config, "12.5"))):
if os == "macos":
return None

return paths.join(apple_toolchain.sdk_dir(), "Developer/Library/Frameworks")
Expand Down Expand Up @@ -467,8 +452,7 @@ def _all_tool_configs(
execution_requirements,
generated_header_rewriter,
swift_executable,
toolchain_root,
xcode_config):
toolchain_root):
"""Returns the tool configurations for the Swift toolchain.
Args:
Expand All @@ -482,7 +466,6 @@ def _all_tool_configs(
swift_executable: A custom Swift driver executable to be used during the
build, if provided.
toolchain_root: The root directory of the toolchain, if provided.
xcode_config: The `apple_common.XcodeVersionConfig` provider.
Returns:
A dictionary mapping action name to tool configuration.
Expand Down Expand Up @@ -513,11 +496,7 @@ def _all_tool_configs(
swift_action_names.COMPILE: tool_config,
swift_action_names.DERIVE_FILES: tool_config,
swift_action_names.DUMP_AST: tool_config,
}

# Xcode 12.0 implies Swift 5.3.
if _is_xcode_at_least_version(xcode_config, "12.0"):
tool_configs[swift_action_names.PRECOMPILE_C_MODULE] = (
swift_action_names.PRECOMPILE_C_MODULE: (
swift_toolchain_config.driver_tool_config(
driver_mode = "swiftc",
env = env,
Expand All @@ -527,7 +506,8 @@ def _all_tool_configs(
use_param_file = True,
worker_mode = "wrap",
)
)
),
}

return tool_configs

Expand Down Expand Up @@ -632,28 +612,17 @@ def _xcode_swift_toolchain_impl(ctx):
SWIFT_FEATURE_COVERAGE_PREFIX_MAP,
SWIFT_FEATURE_DEBUG_PREFIX_MAP,
SWIFT_FEATURE_ENABLE_BATCH_MODE,
SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES,
SWIFT_FEATURE_OBJC_LINK_FLAGS,
SWIFT_FEATURE_OPT_USES_WMO,
SWIFT_FEATURE_REMAP_XCODE_PATH,
SWIFT_FEATURE_SUPPORTS_LIBRARY_EVOLUTION,
SWIFT_FEATURE_SUPPORTS_PRIVATE_DEPS,
SWIFT_FEATURE_SUPPORTS_SYSTEM_MODULE_FLAG,
SWIFT_FEATURE_USE_GLOBAL_MODULE_CACHE,
SWIFT_FEATURE_USE_RESPONSE_FILES,
])

# Xcode 11.0 implies Swift 5.1.
if _is_xcode_at_least_version(xcode_config, "11.0"):
requested_features.append(SWIFT_FEATURE_SUPPORTS_LIBRARY_EVOLUTION)
requested_features.append(SWIFT_FEATURE_SUPPORTS_PRIVATE_DEPS)

# Xcode 11.4 implies Swift 5.2.
if _is_xcode_at_least_version(xcode_config, "11.4"):
requested_features.append(SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES)

# Xcode 12.5 implies Swift 5.4.
if _is_xcode_at_least_version(xcode_config, "12.5"):
requested_features.append(SWIFT_FEATURE_SUPPORTS_SYSTEM_MODULE_FLAG)

# Xcode 14 implies Swift 5.7.
if _is_xcode_at_least_version(xcode_config, "14.0"):
requested_features.append(SWIFT_FEATURE_FILE_PREFIX_MAP)
Expand All @@ -673,7 +642,6 @@ def _xcode_swift_toolchain_impl(ctx):
generated_header_rewriter = generated_header_rewriter,
swift_executable = swift_executable,
toolchain_root = toolchain_root,
xcode_config = xcode_config,
)
all_action_configs = _all_action_configs(
additional_objc_copts = _command_line_objc_copts(
Expand All @@ -691,7 +659,6 @@ def _xcode_swift_toolchain_impl(ctx):
platform_developer_framework_dir = _platform_developer_framework_dir(
apple_toolchain,
target_triple,
xcode_config,
)
if platform_developer_framework_dir:
swift_toolchain_developer_paths.append(
Expand All @@ -703,7 +670,6 @@ def _xcode_swift_toolchain_impl(ctx):
sdk_developer_framework_dir = _sdk_developer_framework_dir(
apple_toolchain,
target_triple,
xcode_config,
)
if sdk_developer_framework_dir:
swift_toolchain_developer_paths.append(
Expand Down

0 comments on commit af526d3

Please sign in to comment.