-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use FeatureConfiguration to compute value of CC_FLAGS make variable
This cl introduces new action_config type for Crosstool named 'generic'. This can be used to set the value of CC_FLAGS make variable using much more expressive mechanism (action_configs + features) than previous make_variable Crosstool messages. This has been requested by the C++ LPT. However, as FeatureConfiguration needs RuleContext, CC_FLAGS cannot be computed using configuration only anymore. Also, FeatureConfiguration is C++ rules specific class, and Bazel build-base cannot depend on it. Therefore we cannot use FeatureConfiguration for ExtraActions, for example. Because it cannot be made perfect, this cl is not updating all the possible places that expand make variables but limits the scope to: * genrule (the only widely used rule that often expands make variables) * *_test (CC_FLAGS is used by Tensorflow in the 'args' attribute) * cc_rules (people sometimes set 'copts' to something like: "-DCC_STRING=\\\"$(CC)\\\" -DCC_FLAGS_STRING=\"$(CC_FLAGS)\"" The long term plan is to use Skylark C++ API to get C++ command lines, so CC_FLAGS together with this inconsistent solution will be removed. RELNOTES: CC_FLAGS can be defined using 'generic' action_config in CROSSTOOL PiperOrigin-RevId: 157202883
- Loading branch information
Showing
16 changed files
with
447 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/main/java/com/google/devtools/build/lib/analysis/MakeVariableSupplier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright 2014 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.analysis; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.google.devtools.build.lib.packages.Package; | ||
import com.google.devtools.build.lib.util.Preconditions; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Instances of {@link MakeVariableSupplier} passed to {@link ConfigurationMakeVariableContext} will | ||
* be called before getting value from {@link ConfigurationMakeVariableContext} itself. | ||
*/ | ||
public interface MakeVariableSupplier { | ||
|
||
/** Returns Make variable value or null if value is not supplied. */ | ||
@Nullable | ||
String getMakeVariable(String variableName); | ||
|
||
/** Returns all Make variables that it supplies */ | ||
ImmutableMap<String, String> getAllMakeVariables(); | ||
|
||
/** {@link MakeVariableSupplier} that reads variables it supplies from a map. */ | ||
class MapBackedMakeVariableSupplier implements MakeVariableSupplier { | ||
|
||
private final ImmutableMap<String, String> makeVariables; | ||
|
||
public MapBackedMakeVariableSupplier(ImmutableMap<String, String> makeVariables) { | ||
this.makeVariables = Preconditions.checkNotNull(makeVariables); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public String getMakeVariable(String variableName) { | ||
return makeVariables.get(variableName); | ||
} | ||
|
||
@Override | ||
public ImmutableMap<String, String> getAllMakeVariables() { | ||
return makeVariables; | ||
} | ||
} | ||
|
||
/** {@link MakeVariableSupplier} that reads variables it supplies from a {@link Package} */ | ||
class PackageBackedMakeVariableSupplier implements MakeVariableSupplier { | ||
|
||
private final String platform; | ||
private final Package pkg; | ||
|
||
public PackageBackedMakeVariableSupplier(Package pkg, String platform) { | ||
this.pkg = pkg; | ||
this.platform = platform; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public String getMakeVariable(String variableName) { | ||
return pkg.lookupMakeVariable(variableName, platform); | ||
} | ||
|
||
@Override | ||
public ImmutableMap<String, String> getAllMakeVariables() { | ||
return pkg.getAllMakeVariables(platform); | ||
} | ||
} | ||
} |
Oops, something went wrong.