Skip to content

Commit e8d1177

Browse files
damienmgvladmos
authored andcommitted
Correctly returns null if an environment variables is missing
The hard part is to test this one as we haven't even been able to reproduce. Maybe we should just fuzz Skyframe function for null values. Fixes bazelbuild#2621. To cherry-pick for 0.4.5 (bazelbuild#2472) -- Change-Id: Ida489fb8dbd659b42a8d2bebff58d49ffeaf72c3 Reviewed-on: https://cr.bazel.build/9213 PiperOrigin-RevId: 149316508 MOS_MIGRATED_REVID=149316508
1 parent ddcfc61 commit e8d1177

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidNdkRepositoryFunction.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,18 @@ public boolean verifyMarkerData(Rule rule, Map<String, String> markerData, Envir
9696
public RepositoryDirectoryValue.Builder fetch(Rule rule, Path outputDirectory,
9797
BlazeDirectories directories, Environment env, Map<String, String> markerData)
9898
throws InterruptedException, RepositoryFunctionException {
99-
declareEnvironmentDependencies(markerData, env, PATH_ENV_VAR_AS_LIST);
99+
Map<String, String> environ =
100+
declareEnvironmentDependencies(markerData, env, PATH_ENV_VAR_AS_LIST);
101+
if (environ == null) {
102+
return null;
103+
}
100104
prepareLocalRepositorySymlinkTree(rule, outputDirectory);
101105
WorkspaceAttributeMapper attributes = WorkspaceAttributeMapper.of(rule);
102106
PathFragment pathFragment;
103107
if (attributes.isAttributeValueExplicitlySpecified("path")) {
104108
pathFragment = getTargetPath(rule, directories.getWorkspace());
105-
} else if (clientEnvironment.containsKey(PATH_ENV_VAR)) {
106-
pathFragment = getAndroidNdkHomeEnvironmentVar(directories.getWorkspace(), clientEnvironment);
109+
} else if (environ.containsKey(PATH_ENV_VAR)) {
110+
pathFragment = getAndroidNdkHomeEnvironmentVar(directories.getWorkspace(), environ);
107111
} else {
108112
throw new RepositoryFunctionException(
109113
new EvalException(

src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryFunction.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,20 @@ public boolean verifyMarkerData(Rule rule, Map<String, String> markerData, Envir
8282
public RepositoryDirectoryValue.Builder fetch(Rule rule, Path outputDirectory,
8383
BlazeDirectories directories, Environment env, Map<String, String> markerData)
8484
throws SkyFunctionException, InterruptedException {
85-
declareEnvironmentDependencies(markerData, env, PATH_ENV_VAR_AS_LIST);
85+
Map<String, String> environ =
86+
declareEnvironmentDependencies(markerData, env, PATH_ENV_VAR_AS_LIST);
87+
if (environ == null) {
88+
return null;
89+
}
8690
prepareLocalRepositorySymlinkTree(rule, outputDirectory);
8791
WorkspaceAttributeMapper attributes = WorkspaceAttributeMapper.of(rule);
8892
FileSystem fs = directories.getOutputBase().getFileSystem();
8993
Path androidSdkPath;
9094
if (attributes.isAttributeValueExplicitlySpecified("path")) {
9195
androidSdkPath = fs.getPath(getTargetPath(rule, directories.getWorkspace()));
92-
} else if (clientEnvironment.containsKey(PATH_ENV_VAR)){
96+
} else if (environ.containsKey(PATH_ENV_VAR)){
9397
androidSdkPath =
94-
fs.getPath(getAndroidHomeEnvironmentVar(directories.getWorkspace(), clientEnvironment));
98+
fs.getPath(getAndroidHomeEnvironmentVar(directories.getWorkspace(), environ));
9599
} else {
96100
throw new RepositoryFunctionException(
97101
new EvalException(

0 commit comments

Comments
 (0)