diff options
4 files changed, 47 insertions, 19 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/AbstractJ2ObjcProtoAspect.java b/src/main/java/com/google/devtools/build/lib/rules/objc/AbstractJ2ObjcProtoAspect.java index 83735730a9..bfa0aec72d 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/AbstractJ2ObjcProtoAspect.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/AbstractJ2ObjcProtoAspect.java @@ -36,6 +36,7 @@ import com.google.devtools.build.lib.rules.apple.AppleToolchain; import com.google.devtools.build.lib.rules.objc.J2ObjcSource.SourceType; import com.google.devtools.build.lib.rules.proto.ProtoCommon; import com.google.devtools.build.lib.rules.proto.ProtoConfiguration; +import com.google.devtools.build.lib.rules.proto.ProtoSourceFileBlacklist; import com.google.devtools.build.lib.rules.proto.ProtoSourcesProvider; import com.google.devtools.build.lib.vfs.PathFragment; @@ -62,6 +63,8 @@ public abstract class AbstractJ2ObjcProtoAspect extends NativeAspectClass new Attribute("$protobuf_lib", Mode.TARGET), new Attribute("deps", Mode.TARGET)); + private static final String PROTO_SOURCE_FILE_BLACKLIST_ATTR = "$j2objc_proto_blacklist"; + /** Flags passed to J2ObjC proto compiler plugin. */ protected static final Iterable<String> J2OBJC_PLUGIN_PARAMS = ImmutableList.of("file_dir_mapping", "generate_class_mappings"); @@ -97,7 +100,11 @@ public abstract class AbstractJ2ObjcProtoAspect extends NativeAspectClass .checkConstraints() .direct_compile_time_input() .cfg(HOST) - .value(new AppleToolchain.XcodeConfigLabel(toolsRepository))); + .value(new AppleToolchain.XcodeConfigLabel(toolsRepository))) + .add(ProtoSourceFileBlacklist.blacklistFilegroupAttribute( + PROTO_SOURCE_FILE_BLACKLIST_ATTR, + ImmutableList.of(Label.parseAbsoluteUnchecked( + toolsRepository + "//tools/j2objc:j2objc_proto_blacklist")))); return addAdditionalAttributes(builder).build(); } @@ -118,12 +125,18 @@ public abstract class AbstractJ2ObjcProtoAspect extends NativeAspectClass ImmutableList<Artifact> protoSources = protoSourcesProvider.getDirectProtoSources(); NestedSet<Artifact> transitiveImports = protoSourcesProvider.getTransitiveImports(); + // Avoid pulling in any generated files from blacklisted protos. + ProtoSourceFileBlacklist protoBlacklist = + new ProtoSourceFileBlacklist(ruleContext, PROTO_SOURCE_FILE_BLACKLIST_ATTR); + ImmutableList<Artifact> filteredProtoSources = ImmutableList.copyOf( + protoBlacklist.filter(protoSources)); + XcodeProvider xcodeProvider; Iterable<Artifact> headerMappingFiles; Iterable<Artifact> classMappingFiles; ObjcCommon common; - if (protoSources.isEmpty()) { + if (filteredProtoSources.isEmpty()) { headerMappingFiles = ImmutableList.of(); classMappingFiles = ImmutableList.of(); common = J2ObjcAspect.common( @@ -139,11 +152,11 @@ public abstract class AbstractJ2ObjcProtoAspect extends NativeAspectClass ImmutableList.<PathFragment>of(), DEPENDENT_ATTRIBUTES); } else { - J2ObjcSource j2ObjcSource = j2ObjcSource(ruleContext, protoSources); - headerMappingFiles = headerMappingFiles(ruleContext, protoSources); - classMappingFiles = classMappingFiles(ruleContext, protoSources); + J2ObjcSource j2ObjcSource = j2ObjcSource(ruleContext, filteredProtoSources); + headerMappingFiles = headerMappingFiles(ruleContext, filteredProtoSources); + classMappingFiles = classMappingFiles(ruleContext, filteredProtoSources); - createActions(base, ruleContext, protoSources, transitiveImports, + createActions(base, ruleContext, filteredProtoSources, transitiveImports, headerMappingFiles, classMappingFiles, j2ObjcSource); common = J2ObjcAspect.common( ruleContext, @@ -185,13 +198,7 @@ public abstract class AbstractJ2ObjcProtoAspect extends NativeAspectClass Iterable<Artifact> headerMappingFiles, Iterable<Artifact> classMappingFiles, J2ObjcSource j2ObjcSource); - protected abstract boolean checkShouldCreateSources(RuleContext ruleContext); - - private J2ObjcSource j2ObjcSource(RuleContext ruleContext, - ImmutableList<Artifact> protoSources) { - Iterable<Artifact> generatedSourceFiles = checkShouldCreateSources(ruleContext) - ? ProtoCommon.getGeneratedOutputs(ruleContext, protoSources, ".j2objc.pb.m") - : ImmutableList.<Artifact>of(); + private J2ObjcSource j2ObjcSource(RuleContext ruleContext, ImmutableList<Artifact> protoSources) { PathFragment objcFileRootExecPath = ruleContext.getConfiguration() .getGenfilesDirectory(ruleContext.getRule().getRepository()) .getExecPath(); @@ -200,7 +207,7 @@ public abstract class AbstractJ2ObjcProtoAspect extends NativeAspectClass return new J2ObjcSource( ruleContext.getTarget().getLabel(), - generatedSourceFiles, + ProtoCommon.getGeneratedOutputs(ruleContext, protoSources, ".j2objc.pb.m"), ProtoCommon.getGeneratedOutputs(ruleContext, protoSources, ".j2objc.pb.h"), objcFileRootExecPath, SourceType.PROTO, diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/BazelJ2ObjcProtoAspect.java b/src/main/java/com/google/devtools/build/lib/rules/objc/BazelJ2ObjcProtoAspect.java index 98e05011e5..24fbb7419e 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/BazelJ2ObjcProtoAspect.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/BazelJ2ObjcProtoAspect.java @@ -97,9 +97,4 @@ public class BazelJ2ObjcProtoAspect extends AbstractJ2ObjcProtoAspect { .addOutputs(classMappingFiles) .build(ruleContext)); } - - @Override - protected boolean checkShouldCreateSources(RuleContext ruleContext) { - return true; - } } diff --git a/tools/j2objc/BUILD b/tools/j2objc/BUILD index 3334dfe35e..705b377310 100644 --- a/tools/j2objc/BUILD +++ b/tools/j2objc/BUILD @@ -17,3 +17,8 @@ filegroup( name = "j2objc_wrapper", srcs = ["j2objc_wrapper.py"], ) + +filegroup( + name = "j2objc_proto_blacklist", + srcs = ["dummy.proto"], +) diff --git a/tools/j2objc/dummy.proto b/tools/j2objc/dummy.proto new file mode 100644 index 0000000000..9d90b3dcdb --- /dev/null +++ b/tools/j2objc/dummy.proto @@ -0,0 +1,21 @@ +// Copyright 2016 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto2"; + +package third_party.bazel.tools.j2objc; + +message Dummy { + optional string dummy = 1; +} |