Skip to content

Commit

Permalink
Add platform and toolchain related flags to the BuildConfiguration.
Browse files Browse the repository at this point in the history
Part of bazelbuild#2219.

Change-Id: Ifd8aacef04bfbe2aa25eec7551803dc6e6a59ce5
  • Loading branch information
katre committed Apr 28, 2017
1 parent 413cf46 commit 434a797
Showing 1 changed file with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,35 @@ public DynamicConfigsConverter() {
)
public TriState buildPythonZip;

@Option(
name = "experimental_target_platform",
defaultValue = "@bazel_tools//platforms:host_platform",
converter = LabelConverter.class,
optionUsageRestrictions = OptionUsageRestrictions.HIDDEN,
help = "Declare the platform targeted by the current build action"
)
public Label targetPlatform;

@Option(
name = "experimental_host_platform",
defaultValue = "@bazel_tools//platforms:host_platform",
converter = LabelConverter.class,
optionUsageRestrictions = OptionUsageRestrictions.HIDDEN,
help = "Declare the platform the build is started from"
)
public Label hostPlatform;

// TODO(katre): Add available execution platforms.

@Option(
name = "experimental_toolchains",
defaultValue = "",
converter = LabelListConverter.class,
optionUsageRestrictions = OptionUsageRestrictions.HIDDEN,
help = "Declares which toolchains to consider during toolchain resolution"
)
public List<Label> toolchains;

@Override
public FragmentOptions getHost(boolean fallback) {
Options host = (Options) getDefault();
Expand Down Expand Up @@ -1092,6 +1121,13 @@ public FragmentOptions getHost(boolean fallback) {
// === Pass on C++ compiler features.
host.defaultFeatures = ImmutableList.copyOf(defaultFeatures);

// == Set the target platform.
host.targetPlatform = hostPlatform;
host.hostPlatform = hostPlatform;

// == Pass on all toolchains.
host.toolchains = ImmutableList.copyOf(toolchains);

return host;
}

Expand All @@ -1102,7 +1138,11 @@ public void addAllLabels(Multimap<String, Label> labelMap) {
if ((runUnder != null) && (runUnder.getLabel() != null)) {
labelMap.put("RunUnder", runUnder.getLabel());
}
labelMap.put("target_platform", targetPlatform);
labelMap.put("host_platform", hostPlatform);
labelMap.putAll("toolchains", toolchains);
}

@Override
public Map<String, Set<Label>> getDefaultsLabels(BuildConfiguration.Options commonOptions) {
return ImmutableMap.<String, Set<Label>>of(
Expand Down Expand Up @@ -2216,7 +2256,7 @@ public ImmutableMap<String, String> getLocalShellEnvironment() {
* client's own environment, and are returned by this function.
*
* <p>The values of the "variable" variables are tracked in Skyframe via the {@link
* com.google.devtools.build.lib.skyframe.SkyFunctions.CLIENT_ENVIRONMENT_VARIABLE} skyfunction.
* com.google.devtools.build.lib.skyframe.SkyFunctions#CLIENT_ENVIRONMENT_VARIABLE} skyfunction.
* This method only returns the names of those variables to be inherited, if set in the client's
* environment. (Variables where the name is not returned in this set should not be taken from the
* client environment.)
Expand Down Expand Up @@ -2594,4 +2634,16 @@ public Class<? extends Fragment> getSkylarkFragmentByName(String name) {
public ImmutableCollection<String> getSkylarkFragmentNames() {
return skylarkVisibleFragments.keySet();
}

public Label getTargetPlatform() {
return options.targetPlatform;
}

public Label getHostPlatform() {
return options.hostPlatform;
}

public ImmutableList<Label> getToolchains() {
return ImmutableList.copyOf(options.toolchains);
}
}

0 comments on commit 434a797

Please sign in to comment.