Skip to content

Commit

Permalink
Add --host_swiftcopt
Browse files Browse the repository at this point in the history
This allows you to pass arguments to swiftc host targets.

Closes #6921.

PiperOrigin-RevId: 228162636
  • Loading branch information
keith authored and Copybara-Service committed Jan 7, 2019
1 parent 62199ea commit c72aa8c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,20 @@ public class SwiftCommandLineOptions extends FragmentOptions {
help = "Additional options to pass to Swift compilation."
)
public List<String> copts;

@Option(
name = "host_swiftcopt",
allowMultiple = true,
defaultValue = "",
documentationCategory = OptionDocumentationCategory.OUTPUT_PARAMETERS,
effectTags = {OptionEffectTag.ACTION_COMMAND_LINES, OptionEffectTag.AFFECTS_OUTPUTS},
help = "Additional options to pass to swiftc for host tools.")
public List<String> hostSwiftcoptList;

@Override
public FragmentOptions getHost() {
SwiftCommandLineOptions host = (SwiftCommandLineOptions) super.getHost();
host.copts = this.hostSwiftcoptList;
return host;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,37 @@ public void testSkylarkApi() throws Exception {

assertThat(copts).containsAllOf("foo", "bar");
}

@Test
public void testHostSwiftcopt() throws Exception {
scratch.file("examples/rule/BUILD");
scratch.file(
"examples/rule/apple_rules.bzl",
"def swift_binary_impl(ctx):",
" copts = ctx.fragments.swift.copts()",
" return struct(",
" copts=copts,",
" )",
"swift_binary = rule(",
" implementation = swift_binary_impl,",
" fragments = ['swift']",
")");

scratch.file(
"examples/swift_skylark/BUILD",
"load('//examples/rule:apple_rules.bzl', 'swift_binary')",
"swift_binary(",
" name='my_target',",
")");

useConfiguration("--swiftcopt=foo", "--host_swiftcopt=bar", "--host_swiftcopt=baz");
ConfiguredTarget target =
getConfiguredTarget("//examples/swift_skylark:my_target", getHostConfiguration());

@SuppressWarnings("unchecked")
List<String> copts = (List<String>) target.get("copts");

assertThat(copts).doesNotContain("foo");
assertThat(copts).containsAllOf("bar", "baz");
}
}

0 comments on commit c72aa8c

Please sign in to comment.