diff options
author | 2016-11-05 16:02:18 +0000 | |
---|---|---|
committer | 2016-11-07 09:53:05 +0000 | |
commit | 349e478687a00e28f8a68a2b90e85de4b5c2eb02 (patch) | |
tree | d17cb70222a18edf42c9c71dc22d4163b563d92e /tools/build_defs/apple/swift.bzl | |
parent | 6e8e9c081ed9d0fbbc77b3da5248d49ca034e5e8 (diff) |
Allow swiftc to correctly recognize main.swift as script target.
* This change removes forced -parse-as-library mode in favor of the driver figuring out how to parse each source. This means that main.swift will be parsed as a script and can contain top-level expressions.
--
MOS_MIGRATED_REVID=138285669
Diffstat (limited to 'tools/build_defs/apple/swift.bzl')
-rw-r--r-- | tools/build_defs/apple/swift.bzl | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/tools/build_defs/apple/swift.bzl b/tools/build_defs/apple/swift.bzl index 336329f537..447134377e 100644 --- a/tools/build_defs/apple/swift.bzl +++ b/tools/build_defs/apple/swift.bzl @@ -116,6 +116,21 @@ def _swift_xcrun_args(ctx): return [] +def _swift_parsing_flags(ctx): + """Returns additional parsing flags for swiftc.""" + srcs = ctx.files.srcs + + # swiftc has two different parsing modes: script and library. + # The difference is that in script mode top-level expressions are allowed. + # This mode is triggered when the file compiled is called main.swift. + # Additionally, script mode is used when there's just one file in the + # compilation. we would like to avoid that and therefore force library mode + # when there's only one source and it's not called main. + if len(srcs) == 1 and srcs[0].basename != "main.swift": + return ["-parse-as-library"] + return [] + + def _is_valid_swift_module_name(string): """Returns True if the string is a valid Swift module name.""" if not string: @@ -288,7 +303,6 @@ def _swift_library_impl(ctx): module_name, "-emit-objc-header-path", output_header.path, - "-parse-as-library", "-target", target, "-sdk", @@ -297,11 +311,14 @@ def _swift_library_impl(ctx): module_cache_path(ctx), "-output-file-map", swiftc_output_map_file.path, - ] + _swift_compilation_mode_flags(ctx) + _swift_bitcode_flags(ctx) + ] if ctx.configuration.coverage_enabled: args.extend(["-profile-generate", "-profile-coverage-mapping"]) + args.extend(_swift_compilation_mode_flags(ctx)) + args.extend(_swift_bitcode_flags(ctx)) + args.extend(_swift_parsing_flags(ctx)) args.extend(srcs_args) args.extend(include_args) args.extend(framework_args) |