blob: 89df5b521fb3f44d280a44ad5164803d6ef3d71b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
// Copyright 2017 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.devtools.build.lib.rules.objc;
import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.analysis.config.BuildOptions;
import com.google.devtools.build.lib.packages.Attribute.SplitTransition;
import com.google.devtools.build.lib.rules.apple.AppleCommandLineOptions;
import com.google.devtools.build.lib.rules.apple.AppleConfiguration.ConfigurationDistinguisher;
import java.util.List;
/**
* Transition that produces a configuration that causes c++ toolchain selection to use the
* CROSSTOOL given in apple_crosstool_top.
*
* <p>Duplicates {@link AppleCrosstoolTransition} as a {@link SplitTransition}. This is necessary
* for the top level configuration hook, until the top level configuration hook is supported for
* dynamic configurations.
*
* <p>TODO(b/34241319): Use AppleCrosstoolTransition at the top level, and retire this class.
*/
public class AppleCrosstoolSplitTransition implements SplitTransition<BuildOptions> {
/**
* A singleton instance of {@link AppleCrosstoolSplitTransition}, since the class must be
* stateless. Use in BuildConfigurationCollection.Transitions#topLevelConfigurationHook.
*/
public static final AppleCrosstoolSplitTransition APPLE_CROSSTOOL_SPLIT_TRANSITION =
new AppleCrosstoolSplitTransition();
@Override
public boolean defaultsToSelf() {
return true;
}
@Override
public List<BuildOptions> split(BuildOptions buildOptions) {
BuildOptions result = buildOptions.clone();
if (!AppleCrosstoolTransition.appleCrosstoolTransitionIsAppliedForAllObjc(buildOptions)) {
// If the apple crosstool is not applied universally, the apple crosstool distinguisher
// is required to prevent artifact collisions. Since AppleCrosstoolTransition is only applied
// when the crosstool is applied universally, the distinguisher only needs to be set here.
result.get(AppleCommandLineOptions.class).configurationDistinguisher =
ConfigurationDistinguisher.APPLE_CROSSTOOL;
}
// TODO(b/29355778): Once ios_cpu is retired, introduce another top-level flag (perhaps
// --apple_cpu) for toolchain selection in top-level consuming rules.
String cpu = "ios_" + buildOptions.get(AppleCommandLineOptions.class).iosCpu;
AppleCrosstoolTransition.setAppleCrosstoolTransitionConfiguration(buildOptions, result, cpu);
return ImmutableList.of(result);
}
}
|