diff options
author | 2018-02-21 15:48:03 -0800 | |
---|---|---|
committer | 2018-02-21 15:50:10 -0800 | |
commit | cfb8a74908459d839c755abcc1c68bfa2ed25f2a (patch) | |
tree | eb086f1c09d4a5d41d8d851e034a8c2229a7a0ec /src/main/java/com/google/devtools/build/lib/rules/proto | |
parent | ae24bfef708540b0e34744f98528d8e485052714 (diff) |
PiperOrigin-RevId: 186532302
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/proto')
5 files changed, 19 insertions, 107 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibrary.java index a4fd57525b..d1cd914016 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibrary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibrary.java @@ -44,13 +44,9 @@ public class BazelProtoLibrary implements RuleConfiguredTargetFactory { NestedSet<Artifact> transitiveImports = ProtoCommon.collectTransitiveImports(ruleContext, protoSources); - NestedSet<Artifact> protosInDirectDeps = ProtoCommon.computeProtosInDirectDeps(ruleContext); + NestedSet<String> protoPathFlags = ProtoCommon.collectTransitiveProtoPathFlags(ruleContext); - String protoSourceRoot = ProtoCommon.getProtoSourceRoot(ruleContext); - NestedSet<String> directProtoSourceRoots = - ProtoCommon.getProtoSourceRootsOfDirectDependencies(ruleContext, protoSourceRoot); - NestedSet<String> protoPathFlags = - ProtoCommon.collectTransitiveProtoPathFlags(ruleContext, protoSourceRoot); + NestedSet<Artifact> protosInDirectDeps = ProtoCommon.computeProtosInDirectDeps(ruleContext); final SupportData supportData = SupportData.create( @@ -59,7 +55,6 @@ public class BazelProtoLibrary implements RuleConfiguredTargetFactory { protosInDirectDeps, transitiveImports, protoPathFlags, - directProtoSourceRoots, !protoSources.isEmpty()); Artifact descriptorSetOutput = @@ -79,8 +74,7 @@ public class BazelProtoLibrary implements RuleConfiguredTargetFactory { descriptorSetOutput, true /* allowServices */, dependenciesDescriptorSets, - protoPathFlags, - directProtoSourceRoots); + protoPathFlags); Runfiles dataRunfiles = ProtoCommon.createDataRunfilesProvider(transitiveImports, ruleContext) @@ -96,8 +90,7 @@ public class BazelProtoLibrary implements RuleConfiguredTargetFactory { checkDepsProtoSources, descriptorSetOutput, transitiveDescriptorSetOutput, - protoPathFlags, - protoSourceRoot); + protoPathFlags); return new RuleConfiguredTargetBuilder(ruleContext) .setFilesToBuild(NestedSetBuilder.create(STABLE_ORDER, descriptorSetOutput)) diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCommon.java b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCommon.java index 2b6f88e2e6..374b534cd9 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCommon.java @@ -100,66 +100,29 @@ public class ProtoCommon { } /** - * Returns all proto source roots in this lib ({@code currentProtoSourceRoot}) and in its - * transitive dependencies, each prefixed by {@code --proto_path}. + * Returns all proto source roots in this lib and in its transitive dependencies, each prefixed + * by {@code --proto_path}. * - * Assumes {@code currentProtoSourceRoot} is the same as the package name. + * Build will fail if the {@code proto_source_root} of the current lib is different than the + * package name. */ - public static NestedSet<String> collectTransitiveProtoPathFlags( - RuleContext ruleContext, String currentProtoSourceRoot) { + public static NestedSet<String> collectTransitiveProtoPathFlags(RuleContext ruleContext) { NestedSetBuilder<String> protoPathFlags = NestedSetBuilder.stableOrder(); // first add the protoSourceRoot of the current target, if any - if (currentProtoSourceRoot != null && !currentProtoSourceRoot.isEmpty()) { - protoPathFlags.add("--proto_path=" + currentProtoSourceRoot); - } - - for (ProtoSourcesProvider provider : ruleContext.getPrerequisites( - "deps", Mode.TARGET, ProtoSourcesProvider.class)) { - protoPathFlags.addTransitive(provider.getTransitiveProtoPathFlags()); - } - - return protoPathFlags.build(); - } - - /** - * Returns the {@code proto_source_root} of the current library or null if none is specified. - * - * Build will fail if the {@code proto_source_root} of the current library is different than the - * package name. - */ - @Nullable - public static String getProtoSourceRoot(RuleContext ruleContext) { String protoSourceRoot = ruleContext.attributes().get("proto_source_root", Type.STRING); if (protoSourceRoot != null && !protoSourceRoot.isEmpty()) { checkProtoSourceRootIsTheSameAsPackage(protoSourceRoot, ruleContext); - } - return protoSourceRoot; - } - - /** - * Returns a set of the {@code proto_source_root} collected from the current library and the - * direct dependencies. - * - * Assumes {@code currentProtoSourceRoot} is the same as the package name. - */ - public static NestedSet<String> getProtoSourceRootsOfDirectDependencies( - RuleContext ruleContext, String currentProtoSourceRoot) { - NestedSetBuilder<String> protoSourceRoots = NestedSetBuilder.stableOrder(); - if (currentProtoSourceRoot != null && !currentProtoSourceRoot.isEmpty()) { - protoSourceRoots.add(currentProtoSourceRoot); + protoPathFlags.add("--proto_path=" + protoSourceRoot); } for (ProtoSourcesProvider provider : ruleContext.getPrerequisites( - "deps", Mode.TARGET, ProtoSourcesProvider.class)) { - String protoSourceRoot = provider.getProtoSourceRoot(); - if (protoSourceRoot != null && !protoSourceRoot.isEmpty()) { - protoSourceRoots.add(provider.getProtoSourceRoot()); - } + "deps", Mode.TARGET, ProtoSourcesProvider.class)) { + protoPathFlags.addTransitive(provider.getTransitiveProtoPathFlags()); } - return protoSourceRoots.build(); + return protoPathFlags.build(); } private static void checkProtoSourceRootIsTheSameAsPackage( diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java index 015c02c3f0..374bf9b9fe 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java @@ -322,7 +322,6 @@ public class ProtoCompileActionBuilder { addIncludeMapArguments( result, areDepsStrict ? supportData.getProtosInDirectDeps() : null, - supportData.getDirectProtoSourceRoots(), supportData.getTransitiveImports()); if (areDepsStrict) { @@ -361,8 +360,7 @@ public class ProtoCompileActionBuilder { Artifact output, boolean allowServices, NestedSet<Artifact> transitiveDescriptorSets, - NestedSet<String> protoSourceRoots, - NestedSet<String> directProtoSourceRoots) { + NestedSet<String> protoSourceRoots) { if (protosToCompile.isEmpty()) { ruleContext.registerAction( FileWriteAction.createEmptyWithInputs( @@ -378,7 +376,6 @@ public class ProtoCompileActionBuilder { transitiveSources, protosInDirectDeps, protoSourceRoots, - directProtoSourceRoots, ruleContext.getLabel(), ImmutableList.of(output), "Descriptor Set", @@ -426,7 +423,6 @@ public class ProtoCompileActionBuilder { NestedSet<Artifact> transitiveSources, NestedSet<Artifact> protosInDirectDeps, NestedSet<String> protoSourceRoots, - NestedSet<String> directProtoSourceRoots, Label ruleLabel, Iterable<Artifact> outputs, String flavorName, @@ -439,7 +435,6 @@ public class ProtoCompileActionBuilder { transitiveSources, protosInDirectDeps, protoSourceRoots, - directProtoSourceRoots, ruleLabel, outputs, flavorName, @@ -457,7 +452,6 @@ public class ProtoCompileActionBuilder { NestedSet<Artifact> transitiveSources, @Nullable NestedSet<Artifact> protosInDirectDeps, NestedSet<String> protoSourceRoots, - NestedSet<String> directProtoSourceRoots, Label ruleLabel, Iterable<Artifact> outputs, String flavorName, @@ -493,7 +487,6 @@ public class ProtoCompileActionBuilder { protosToCompile, transitiveSources, protoSourceRoots, - directProtoSourceRoots, areDepsStrict(ruleContext) ? protosInDirectDeps : null, ruleLabel, allowServices, @@ -531,13 +524,11 @@ public class ProtoCompileActionBuilder { Iterable<Artifact> protosToCompile, NestedSet<Artifact> transitiveSources, NestedSet<String> transitiveProtoPathFlags, - NestedSet<String> directProtoSourceRoots, @Nullable NestedSet<Artifact> protosInDirectDeps, Label ruleLabel, boolean allowServices, ImmutableList<String> protocOpts) { CustomCommandLine.Builder cmdLine = CustomCommandLine.builder(); - cmdLine.addAll(transitiveProtoPathFlags); cmdLine.addAll(transitiveProtoPathFlags); @@ -574,7 +565,7 @@ public class ProtoCompileActionBuilder { cmdLine.addAll(protocOpts); // Add include maps - addIncludeMapArguments(cmdLine, protosInDirectDeps, directProtoSourceRoots, transitiveSources); + addIncludeMapArguments(cmdLine, protosInDirectDeps, transitiveSources); if (protosInDirectDeps != null) { cmdLine.addFormatted(STRICT_DEPS_FLAG_TEMPLATE, ruleLabel); @@ -595,7 +586,6 @@ public class ProtoCompileActionBuilder { static void addIncludeMapArguments( CustomCommandLine.Builder commandLine, @Nullable NestedSet<Artifact> protosInDirectDependencies, - NestedSet<String> directProtoSourceRoots, NestedSet<Artifact> transitiveImports) { commandLine.addAll( VectorArg.of(transitiveImports) @@ -606,14 +596,7 @@ public class ProtoCompileActionBuilder { "--direct_dependencies", VectorArg.join(":") .each(protosInDirectDependencies) - .mapped((Artifact proto, Consumer<String> args) -> { - for (String directProtoSourceRoot : directProtoSourceRoots) { - expandToPathIgnoringSourceRoot(proto, directProtoSourceRoot, args); - } - expandToPathIgnoringRepository(proto, args); - }) - ); - + .mapped(ProtoCompileActionBuilder::expandToPathIgnoringRepository)); } else { // The proto compiler requires an empty list to turn on strict deps checking commandLine.add("--direct_dependencies="); @@ -644,20 +627,6 @@ public class ProtoCompileActionBuilder { .toString(); } - private static void expandToPathIgnoringSourceRoot( - Artifact artifact, String directProtoSourceRoot, Consumer<String> args) { - try { - String relativePath = artifact.getRootRelativePath() - .relativeTo( - artifact.getOwnerLabel().getPackageIdentifier().getRepository().getPathUnderExecRoot()) - .relativeTo(directProtoSourceRoot) - .toString(); - args.accept(relativePath); - } catch (IllegalArgumentException exception) { - // do nothing - } - } - /** * Describes a toolchain and the value to replace for a $(OUT) that might appear in its * commandLine() (e.g., "bazel-out/foo.srcjar"). diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoSourcesProvider.java b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoSourcesProvider.java index 25ea43b090..bf2ed12b3b 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoSourcesProvider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoSourcesProvider.java @@ -42,8 +42,7 @@ public abstract class ProtoSourcesProvider implements TransitiveInfoProvider { NestedSet<Artifact> checkDepsProtoSources, Artifact directDescriptorSet, NestedSet<Artifact> transitiveDescriptorSets, - NestedSet<String> protoPathFlags, - String protoSourceRoot) { + NestedSet<String> protoPathFlags) { return new AutoValue_ProtoSourcesProvider( transitiveImports, transitiveProtoSources, @@ -51,8 +50,7 @@ public abstract class ProtoSourcesProvider implements TransitiveInfoProvider { checkDepsProtoSources, directDescriptorSet, transitiveDescriptorSets, - protoPathFlags, - protoSourceRoot); + protoPathFlags); } /** @@ -137,10 +135,5 @@ public abstract class ProtoSourcesProvider implements TransitiveInfoProvider { */ public abstract NestedSet<String> getTransitiveProtoPathFlags(); - /** - * The {@code proto_source_root} of the current library. - */ - public abstract String getProtoSourceRoot(); - ProtoSourcesProvider() {} } diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/SupportData.java b/src/main/java/com/google/devtools/build/lib/rules/proto/SupportData.java index ad2c09c3ee..9e02d190d5 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/proto/SupportData.java +++ b/src/main/java/com/google/devtools/build/lib/rules/proto/SupportData.java @@ -34,11 +34,10 @@ public abstract class SupportData { NestedSet<Artifact> protosInDirectDeps, NestedSet<Artifact> transitiveImports, NestedSet<String> transitiveProtoPathFlags, - NestedSet<String> directProtoSourceRoots, boolean hasProtoSources) { return new AutoValue_SupportData( nonWeakDepsPredicate, protoSources, transitiveImports, protosInDirectDeps, - transitiveProtoPathFlags, directProtoSourceRoots, hasProtoSources); + transitiveProtoPathFlags, hasProtoSources); } public abstract Predicate<TransitiveInfoCollection> getNonWeakDepsPredicate(); @@ -58,11 +57,6 @@ public abstract class SupportData { */ public abstract NestedSet<String> getTransitiveProtoPathFlags(); - /** - * The {@code proto_source_root}'s collected from the current library and the direct dependencies. - */ - public abstract NestedSet<String> getDirectProtoSourceRoots(); - public abstract boolean hasProtoSources(); SupportData() {} |