Skip to content

Commit

Permalink
Reset platform on cpu transitions.
Browse files Browse the repository at this point in the history
With platform mappings about to be enabled we need to make sure that platforms are reset in any configuration transitions that write flags which may impact the platform. Otherwise a platform may be set before the transition that matches the old flags but platform mapping would not be triggered for the new flag values (because platform mapping only happens if no platform is set).

Step 6/N towards the platforms mapping functionality for #6426

RELNOTES: None.
PiperOrigin-RevId: 244696779
  • Loading branch information
aragos authored and copybara-github committed Apr 22, 2019
1 parent 5ba7cf6 commit 8396c2f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Lists;
import com.google.devtools.build.lib.analysis.BaseRuleClasses;
import com.google.devtools.build.lib.analysis.PlatformOptions;
import com.google.devtools.build.lib.analysis.RuleDefinition;
import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
Expand Down Expand Up @@ -212,22 +213,19 @@ public static LabelLateBoundDefault<?> getAndroidSdkLabel(Label androidSdk) {
/** Android Split configuration transition for properly handling native dependencies */
public static final class AndroidSplitTransition
implements SplitTransition, AndroidSplitTransititionApi {
private static void setCrosstoolToAndroid(BuildOptions output, BuildOptions input) {
AndroidConfiguration.Options inputAndroidOptions =
input.get(AndroidConfiguration.Options.class);
AndroidConfiguration.Options outputAndroidOptions =
output.get(AndroidConfiguration.Options.class);

CppOptions cppOptions = output.get(CppOptions.class);
if (inputAndroidOptions.androidCrosstoolTop != null
&& !cppOptions.crosstoolTop.equals(inputAndroidOptions.androidCrosstoolTop)) {
private static void setCrosstoolToAndroid(BuildOptions options) {
AndroidConfiguration.Options androidOptions = options.get(AndroidConfiguration.Options.class);

CppOptions cppOptions = options.get(CppOptions.class);
if (androidOptions.androidCrosstoolTop != null
&& !cppOptions.crosstoolTop.equals(androidOptions.androidCrosstoolTop)) {
if (cppOptions.hostCrosstoolTop == null) {
cppOptions.hostCrosstoolTop = cppOptions.crosstoolTop;
}
cppOptions.crosstoolTop = inputAndroidOptions.androidCrosstoolTop;
cppOptions.crosstoolTop = androidOptions.androidCrosstoolTop;
}

outputAndroidOptions.configurationDistinguisher = ConfigurationDistinguisher.ANDROID;
androidOptions.configurationDistinguisher = ConfigurationDistinguisher.ANDROID;
}

@Override
Expand All @@ -248,11 +246,8 @@ public List<BuildOptions> split(BuildOptions buildOptions) {
} else {

BuildOptions splitOptions = buildOptions.clone();
splitOptions.get(CppOptions.class).cppCompiler = androidOptions.cppCompiler;
splitOptions.get(CppOptions.class).libcTopLabel = androidOptions.androidLibcTopLabel;
splitOptions.get(BuildConfiguration.Options.class).cpu = androidOptions.cpu;
splitOptions.get(CppOptions.class).dynamicMode = androidOptions.dynamicMode;
setCrosstoolToAndroid(splitOptions, buildOptions);
setCommonAndroidOptions(androidOptions, splitOptions);
return ImmutableList.of(splitOptions);
}

Expand All @@ -268,16 +263,24 @@ public List<BuildOptions> split(BuildOptions buildOptions) {
// TODO(bazel-team): --android_cpu doesn't follow --cpu right now; it should.
splitOptions.get(AndroidConfiguration.Options.class).cpu = cpu;
splitOptions.get(BuildConfiguration.Options.class).cpu = cpu;
splitOptions.get(CppOptions.class).cppCompiler = androidOptions.cppCompiler;
splitOptions.get(CppOptions.class).libcTopLabel = androidOptions.androidLibcTopLabel;
splitOptions.get(CppOptions.class).dynamicMode = androidOptions.dynamicMode;
setCrosstoolToAndroid(splitOptions, buildOptions);
setCommonAndroidOptions(androidOptions, splitOptions);
result.add(splitOptions);
}
return result.build();
}
}

private void setCommonAndroidOptions(
AndroidConfiguration.Options androidOptions, BuildOptions newOptions) {
newOptions.get(CppOptions.class).cppCompiler = androidOptions.cppCompiler;
newOptions.get(CppOptions.class).libcTopLabel = androidOptions.androidLibcTopLabel;
newOptions.get(CppOptions.class).dynamicMode = androidOptions.dynamicMode;
setCrosstoolToAndroid(newOptions);

// Ensure platforms aren't set so that platform mapping can take place.
newOptions.get(PlatformOptions.class).platforms = ImmutableList.of();
}

@Override
public boolean isImmutable() {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.analysis.PlatformOptions;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
import com.google.devtools.build.lib.analysis.config.BuildOptions;
import com.google.devtools.build.lib.analysis.config.transitions.PatchTransition;
Expand Down Expand Up @@ -96,6 +97,9 @@ public static void setAppleCrosstoolTransitionConfiguration(BuildOptions from,

// OSX toolchains do not support fission.
to.get(CppOptions.class).fissionModes = ImmutableList.of();

// Ensure platforms aren't set so that platform mapping can take place.
to.get(PlatformOptions.class).platforms = ImmutableList.of();
}

/**
Expand Down

0 comments on commit 8396c2f

Please sign in to comment.