Skip to content

Commit

Permalink
Fix middleman conflicts in external repositories by appending the pac…
Browse files Browse the repository at this point in the history
…kage path

Fixes #341.

--
MOS_MIGRATED_REVID=99390495
  • Loading branch information
damienmg committed Jul 30, 2015
1 parent 8ff5b3c commit d3a726c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,12 @@ private Pair<Artifact, Action> createMiddleman(
* <p>Note: there's no need to synchronize this method; the only use of a field is via a call to
* another synchronized method (getArtifact()).
*/
public Artifact createMiddlemanAllowMultiple(ActionRegistry registry,
ActionOwner owner, String purpose, Iterable<Artifact> inputs, Root middlemanDir) {
PathFragment stampName = new PathFragment("_middlemen/" + purpose);
public Artifact createMiddlemanAllowMultiple(ActionRegistry registry, ActionOwner owner,
PathFragment packageDirectory, String purpose, Iterable<Artifact> inputs, Root middlemanDir) {
String escapedPackageDirectory = Actions.escapedPath(packageDirectory.getPathString());
PathFragment stampName =
new PathFragment("_middlemen/" + (purpose.startsWith(escapedPackageDirectory)
? purpose : (escapedPackageDirectory + purpose)));
Artifact stampFile = artifactFactory.getDerivedArtifact(stampName, middlemanDir,
actionRegistry.getOwner());
MiddlemanAction.create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private static List<Artifact> getMiddlemanInternal(AnalysisEnvironment env,
}
MiddlemanFactory factory = env.getMiddlemanFactory();
return ImmutableList.of(factory.createMiddlemanAllowMultiple(
env, actionOwner, purpose, filesToBuild,
env, actionOwner, ruleContext.getPackageDirectory(), purpose, filesToBuild,
ruleContext.getConfiguration().getMiddlemanDirectory()));
}

Expand Down Expand Up @@ -85,8 +85,8 @@ private static List<Artifact> getMiddlemanInternal(AnalysisEnvironment env,
}
MiddlemanFactory factory = env.getMiddlemanFactory();
Iterable<Artifact> artifacts = dep.getProvider(FileProvider.class).getFilesToBuild();
return ImmutableList.of(factory.createMiddlemanAllowMultiple(
env, actionOwner, purpose, artifacts,
ruleContext.getConfiguration().getMiddlemanDirectory()));
return ImmutableList.of(
factory.createMiddlemanAllowMultiple(env, actionOwner, ruleContext.getPackageDirectory(),
purpose, artifacts, ruleContext.getConfiguration().getMiddlemanDirectory()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,9 @@ private static List<Artifact> getMiddlemanInternal(AnalysisEnvironment env,
artifacts = symlinkedArtifacts;
purpose += "_with_solib";
}
return ImmutableList.of(factory.createMiddlemanAllowMultiple(
env, actionOwner, purpose, artifacts, configuration.getMiddlemanDirectory()));
return ImmutableList.of(
factory.createMiddlemanAllowMultiple(env, actionOwner, ruleContext.getPackageDirectory(),
purpose, artifacts, configuration.getMiddlemanDirectory()));
}

/**
Expand Down
34 changes: 34 additions & 0 deletions src/test/shell/bazel/workspace_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,38 @@ function test_path_with_spaces() {
bazel help &> $TEST_log || fail "Help failed"
}

# Tests for middleman conflict when using workspace repository
function test_middleman_conflict() {
local test_repo1=$TEST_TMPDIR/repo1
local test_repo2=$TEST_TMPDIR/repo2

mkdir -p $test_repo1
mkdir -p $test_repo2
echo "1" >$test_repo1/test.in
echo "2" >$test_repo2/test.in
echo 'filegroup(name="test", srcs=["test.in"], visibility=["//visibility:public"])' \
>$test_repo1/BUILD
echo 'filegroup(name="test", srcs=["test.in"], visibility=["//visibility:public"])' \
>$test_repo2/BUILD
touch $test_repo1/WORKSPACE
touch $test_repo2/WORKSPACE

cat > WORKSPACE <<EOF
local_repository(name = 'repo1', path='$test_repo1')
local_repository(name = 'repo2', path='$test_repo2')
EOF

cat > BUILD <<'EOF'
genrule(
name = "test",
srcs = ["@repo1//:test", "@repo2//:test"],
outs = ["test.out"],
cmd = "cat $(SRCS) >$@"
)
EOF
bazel fetch //:test || fail "Fetch failed"
bazel build //:test || echo "Expected build to succeed"
check_eq "12" "$(cat bazel-genfiles/test.out | tr -d '[[:space:]]')"
}

run_suite "workspace tests"

0 comments on commit d3a726c

Please sign in to comment.