From 3f80c72b6744abe9d4139c90e475a6123b1a38e2 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 16 Feb 2016 15:25:28 +0000 Subject: Roll forward of commit 500175fcfb37953f50cf0869df164902755807f2: Don't include absolute paths in blaze IDE artifacts NEW: Fixed bazel java_test rules Rollback of commit a4ba24e286b7e9a7a09e333d8eb64a8cf7e81895. *** Reason for rollback *** Rollforward, fixing bazel java_test rules *** Original change description *** Automated [] rollback of commit 500175fcfb37953f50cf0869df164902755807f2. *** Reason for rollback *** Breaks Bazel Build http://ci.bazel.io/job/Bazel/JAVA_VERSION=1.7,PLATFORM_NAME=linux-x86_64/356/console *** Original change description *** Don't include absolute paths in blaze IDE artifacts RELNOTES: Don't include absolute paths in blaze IDE artifacts -- MOS_MIGRATED_REVID=114751236 --- .../build/lib/ideinfo/AndroidStudioInfoAspect.java | 46 ++++++++++++++++-- .../lib/rules/android/AndroidIdeInfoProvider.java | 55 ++++++++++++++++------ 2 files changed, 81 insertions(+), 20 deletions(-) (limited to 'src/main/java/com/google') diff --git a/src/main/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspect.java b/src/main/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspect.java index f6d4856374..472bef60f9 100644 --- a/src/main/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspect.java +++ b/src/main/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspect.java @@ -20,8 +20,10 @@ import static com.google.devtools.build.lib.packages.Attribute.attr; import static com.google.devtools.build.lib.packages.BuildType.LABEL; import com.google.common.base.Function; +import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.common.io.ByteSource; import com.google.devtools.build.lib.Constants; @@ -56,6 +58,7 @@ import com.google.devtools.build.lib.ideinfo.androidstudio.AndroidStudioIdeInfo. import com.google.devtools.build.lib.packages.AspectDefinition; import com.google.devtools.build.lib.packages.AspectParameters; import com.google.devtools.build.lib.packages.BuildType; +import com.google.devtools.build.lib.packages.Package; import com.google.devtools.build.lib.packages.Rule; import com.google.devtools.build.lib.rules.android.AndroidCommon; import com.google.devtools.build.lib.rules.android.AndroidIdeInfoProvider; @@ -303,6 +306,9 @@ public class AndroidStudioInfoAspect implements ConfiguredNativeAspectFactory { .getPath() .toString()); + outputBuilder.setBuildFileArtifactLocation( + makeArtifactLocation(ruleContext.getRule().getPackage())); + outputBuilder.setKind(ruleKind); if (ruleKind == Kind.JAVA_LIBRARY @@ -373,8 +379,7 @@ public class AndroidStudioInfoAspect implements ConfiguredNativeAspectFactory { .setExecutable(ruleContext.getExecutablePrerequisite("$packageParser", Mode.HOST)) .setCommandLine(CustomCommandLine.builder() .addExecPath("--output_manifest", packageManifest) - .addJoinStrings("--sources_absolute_paths", ":", Artifact.toAbsolutePaths(sourceFiles)) - .addJoinExecPaths("--sources_execution_paths", ":", sourceFiles) + .addJoinStrings("--sources", ":", toSerializedArtifactLocations(sourceFiles)) .build()) .useParameterFile(ParameterFileType.SHELL_QUOTED) .setProgressMessage("Parsing java package strings for " + ruleContext.getRule()) @@ -382,6 +387,25 @@ public class AndroidStudioInfoAspect implements ConfiguredNativeAspectFactory { .build(ruleContext); } + private static Iterable toSerializedArtifactLocations(Iterable artifacts) { + return Iterables.transform( + Iterables.filter(artifacts, Artifact.MIDDLEMAN_FILTER), + PACKAGE_PARSER_SERIALIZER); + } + + private static final Function PACKAGE_PARSER_SERIALIZER = + new Function() { + @Override + public String apply(Artifact artifact) { + ArtifactLocation location = makeArtifactLocation(artifact); + return Joiner.on(",").join( + location.getRootExecutionPathFragment(), + location.getRelativePath(), + location.getRootPath() + ); + } + }; + private static Artifact derivedArtifact(ConfiguredTarget base, RuleContext ruleContext, String suffix) { BuildConfiguration configuration = ruleContext.getConfiguration(); @@ -471,16 +495,28 @@ public class AndroidStudioInfoAspect implements ConfiguredNativeAspectFactory { } private static ArtifactLocation makeArtifactLocation(Artifact artifact) { + return makeArtifactLocation(artifact.getRoot(), artifact.getRootRelativePath()); + } + + private static ArtifactLocation makeArtifactLocation(Package pkg) { + Root root = Root.asSourceRoot(pkg.getSourceRoot()); + PathFragment relativePath = pkg.getBuildFile().getPath().relativeTo(root.getPath()); + return makeArtifactLocation(root, relativePath); + } + + private static ArtifactLocation makeArtifactLocation(Root root, PathFragment relativePath) { return ArtifactLocation.newBuilder() - .setRootPath(artifact.getRoot().getPath().toString()) - .setRelativePath(artifact.getRootRelativePathString()) - .setIsSource(artifact.isSourceArtifact()) + .setRootPath(root.getPath().toString()) + .setRootExecutionPathFragment(root.getExecPath().toString()) + .setRelativePath(relativePath.toString()) + .setIsSource(root.isSourceRoot()) .build(); } private static ArtifactLocation makeArtifactLocation(SourceDirectory resourceDir) { return ArtifactLocation.newBuilder() .setRootPath(resourceDir.getRootPath().toString()) + .setRootExecutionPathFragment(resourceDir.getRootExecutionPathFragment().toString()) .setRelativePath(resourceDir.getRelativePath().toString()) .setIsSource(resourceDir.isSource()) .build(); diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidIdeInfoProvider.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidIdeInfoProvider.java index 7028a45eca..0cd44ad59d 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidIdeInfoProvider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidIdeInfoProvider.java @@ -13,6 +13,7 @@ // limitations under the License. package com.google.devtools.build.lib.rules.android; +import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableCollection; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; @@ -39,11 +40,29 @@ public final class AndroidIdeInfoProvider implements TransitiveInfoProvider { @Immutable public static class SourceDirectory { final PathFragment relativePath; + final PathFragment rootExecutionPathFragment; final PathFragment rootPath; final boolean isSource; - public SourceDirectory(PathFragment rootPath, PathFragment relativePath, boolean isSource) { + @VisibleForTesting + public static SourceDirectory fromSourceRoot( + PathFragment rootPath, + PathFragment relativePath) { + return new SourceDirectory(rootPath, PathFragment.EMPTY_FRAGMENT, relativePath, true); + } + + public static SourceDirectory fromRoot(Root root, PathFragment relativePath) { + return new SourceDirectory( + root.getPath().asFragment(), root.getExecPath(), relativePath, root.isSourceRoot()); + } + + private SourceDirectory( + PathFragment rootPath, + PathFragment rootExecutionPathFragment, + PathFragment relativePath, + boolean isSource) { this.rootPath = rootPath; + this.rootExecutionPathFragment = rootExecutionPathFragment; this.relativePath = relativePath; this.isSource = isSource; } @@ -62,6 +81,14 @@ public final class AndroidIdeInfoProvider implements TransitiveInfoProvider { return rootPath; } + /** + * The path from the execution root to the actual root. For source roots, this returns + * the empty fragment, {@link Root#getExecPath()}. + */ + public PathFragment getRootExecutionPathFragment() { + return rootExecutionPathFragment; + } + /** Indicates if the directory is in the gen files tree. */ public boolean isSource() { return isSource; @@ -69,7 +96,7 @@ public final class AndroidIdeInfoProvider implements TransitiveInfoProvider { @Override public int hashCode() { - return Objects.hash(relativePath, rootPath, isSource); + return Objects.hash(relativePath, rootPath, rootExecutionPathFragment, isSource); } @Override @@ -77,6 +104,7 @@ public final class AndroidIdeInfoProvider implements TransitiveInfoProvider { if (other instanceof SourceDirectory) { SourceDirectory otherDir = (SourceDirectory) other; return Objects.equals(rootPath, otherDir.rootPath) + && Objects.equals(rootExecutionPathFragment, otherDir.rootExecutionPathFragment) && Objects.equals(relativePath, otherDir.relativePath) && Objects.equals(isSource, otherDir.isSource); } @@ -86,7 +114,7 @@ public final class AndroidIdeInfoProvider implements TransitiveInfoProvider { @Override public String toString() { return "SourceDirectory [relativePath=" + relativePath + ", rootPath=" + rootPath - + ", isSource=" + isSource + "]"; + + ", executionRootPrefix=" + rootExecutionPathFragment + ", isSource=" + isSource + "]"; } } @@ -179,10 +207,9 @@ public final class AndroidIdeInfoProvider implements TransitiveInfoProvider { private void addIdlDirs(Collection idlArtifacts) { for (Artifact idl : idlArtifacts) { this.idlDirs.add( - new SourceDirectory( - idl.getRoot().getPath().asFragment(), - idl.getRootRelativePath().getParentDirectory(), - idl.isSourceArtifact())); + SourceDirectory.fromRoot( + idl.getRoot(), + idl.getRootRelativePath().getParentDirectory())); } } @@ -199,10 +226,9 @@ public final class AndroidIdeInfoProvider implements TransitiveInfoProvider { public Builder addResourceSource(Artifact resource) { PathFragment resourceDir = LocalResourceContainer.Builder.findResourceDir(resource); resourceDirs.add( - new SourceDirectory( - resource.getRoot().getPath().asFragment(), - trimTo(resource.getRootRelativePath(), resourceDir), - resource.isSourceArtifact())); + SourceDirectory.fromRoot( + resource.getRoot(), + trimTo(resource.getRootRelativePath(), resourceDir))); return this; } @@ -222,10 +248,9 @@ public final class AndroidIdeInfoProvider implements TransitiveInfoProvider { public Builder addAssetSource(Artifact asset, PathFragment assetDir) { assetDirs.add( - new SourceDirectory( - asset.getRoot().getPath().asFragment(), - trimTo(asset.getRootRelativePath(), assetDir), - asset.isSourceArtifact())); + SourceDirectory.fromRoot( + asset.getRoot(), + trimTo(asset.getRootRelativePath(), assetDir))); return this; } -- cgit v1.2.3