diff --git a/src/main/java/com/google/devtools/build/lib/sandbox/SpawnHelpers.java b/src/main/java/com/google/devtools/build/lib/sandbox/SpawnHelpers.java index 34ddd9e7823d64..1bfa16b19792dd 100644 --- a/src/main/java/com/google/devtools/build/lib/sandbox/SpawnHelpers.java +++ b/src/main/java/com/google/devtools/build/lib/sandbox/SpawnHelpers.java @@ -187,6 +187,17 @@ void mountInputs( } } + // ActionInputHelper#expandArtifacts above expands empty TreeArtifacts into an empty list. + // However, actions that accept TreeArtifacts as inputs generally expect that the empty + // directory is created. So here we explicitly mount the directories of the TreeArtifacts as + // inputs. + for (ActionInput input : spawn.getInputFiles()) { + if (input instanceof Artifact && ((Artifact) input).isTreeArtifact()) { + PathFragment mount = new PathFragment(input.getExecPathString()); + mounts.put(mount, execRoot.getRelative(mount)); + } + } + for (ActionInput input : inputs) { if (input.getExecPathString().contains("internal/_middlemen/")) { continue; diff --git a/src/test/shell/bazel/android/android_integration_test.sh b/src/test/shell/bazel/android/android_integration_test.sh index 466f78776adde1..00d215757ae9de 100755 --- a/src/test/shell/bazel/android/android_integration_test.sh +++ b/src/test/shell/bazel/android/android_integration_test.sh @@ -234,6 +234,29 @@ function test_android_binary_clang() { check_soname } +# Regression test for https://github.com/bazelbuild/bazel/issues/1928. +function test_empty_tree_artifact_action_inputs_mount_empty_directories() { + create_new_workspace + setup_android_support + cat > AndroidManifest.xml < +EOF + mkdir res + zip test.aar AndroidManifest.xml res/ + cat > BUILD <