aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com
diff options
context:
space:
mode:
authorGravatar Ulf Adams <ulfjack@google.com>2016-10-18 08:26:13 +0000
committerGravatar Philipp Wollermann <philwo@google.com>2016-10-18 10:58:55 +0000
commitb392fc737978703d391d2fc9ba717a4b6bf694f9 (patch)
tree3e5d73d44b7f15ad67c67294fd93788c16c39ee3 /src/main/java/com
parent721785a9d898f9c0920391c9be2be2bf62763572 (diff)
Simplify the j2objc stuff.
-- MOS_MIGRATED_REVID=136446429
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java7
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/objc/BazelJ2ObjcLibraryRule.java85
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java97
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcLibraryRule.java85
4 files changed, 143 insertions, 131 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java
index 6c9548225d..0fae32d39c 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java
@@ -56,7 +56,6 @@ import com.google.devtools.build.lib.bazel.rules.java.proto.BazelJavaLiteProtoAs
import com.google.devtools.build.lib.bazel.rules.java.proto.BazelJavaLiteProtoLibraryRule;
import com.google.devtools.build.lib.bazel.rules.java.proto.BazelJavaProtoAspect;
import com.google.devtools.build.lib.bazel.rules.java.proto.BazelJavaProtoLibraryRule;
-import com.google.devtools.build.lib.bazel.rules.objc.BazelJ2ObjcLibraryRule;
import com.google.devtools.build.lib.bazel.rules.python.BazelPyBinaryRule;
import com.google.devtools.build.lib.bazel.rules.python.BazelPyLibraryRule;
import com.google.devtools.build.lib.bazel.rules.python.BazelPyRuleClasses;
@@ -131,6 +130,7 @@ import com.google.devtools.build.lib.rules.objc.J2ObjcAspect;
import com.google.devtools.build.lib.rules.objc.J2ObjcCommandLineOptions;
import com.google.devtools.build.lib.rules.objc.J2ObjcConfiguration;
import com.google.devtools.build.lib.rules.objc.J2ObjcLibraryBaseRule;
+import com.google.devtools.build.lib.rules.objc.J2ObjcLibraryRule;
import com.google.devtools.build.lib.rules.objc.ObjcBinaryRule;
import com.google.devtools.build.lib.rules.objc.ObjcBuildInfoFactory;
import com.google.devtools.build.lib.rules.objc.ObjcBundleLibraryRule;
@@ -612,11 +612,12 @@ public class BazelRuleClassProvider {
builder.addNativeAspectClass(bazelJ2ObjcProtoAspect);
builder.addNativeAspectClass(j2ObjcAspect);
builder.addRuleDefinition(new J2ObjcLibraryBaseRule());
- builder.addRuleDefinition(new BazelJ2ObjcLibraryRule(j2ObjcAspect));
+ builder.addRuleDefinition(new J2ObjcLibraryRule(j2ObjcAspect));
try {
builder.addWorkspaceFilePrefix(
- ResourceFileLoader.loadResource(BazelJ2ObjcLibraryRule.class, "j2objc.WORKSPACE"));
+ ResourceFileLoader.loadResource(
+ BazelRuleClassProvider.class, "objc/j2objc.WORKSPACE"));
} catch (IOException e) {
throw new IllegalStateException(e);
}
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/objc/BazelJ2ObjcLibraryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/objc/BazelJ2ObjcLibraryRule.java
deleted file mode 100644
index 551a4243e1..0000000000
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/objc/BazelJ2ObjcLibraryRule.java
+++ /dev/null
@@ -1,85 +0,0 @@
-// Copyright 2015 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.
-
-package com.google.devtools.build.lib.bazel.rules.objc;
-
-import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
-
-import com.google.devtools.build.lib.analysis.RuleDefinition;
-import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
-import com.google.devtools.build.lib.packages.RuleClass;
-import com.google.devtools.build.lib.packages.RuleClass.Builder;
-import com.google.devtools.build.lib.rules.apple.AppleConfiguration;
-import com.google.devtools.build.lib.rules.objc.J2ObjcAspect;
-import com.google.devtools.build.lib.rules.objc.J2ObjcConfiguration;
-import com.google.devtools.build.lib.rules.objc.J2ObjcLibrary;
-import com.google.devtools.build.lib.rules.objc.J2ObjcLibraryBaseRule;
-import com.google.devtools.build.lib.rules.objc.ObjcConfiguration;
-
-/**
- * Concrete implementation of J2ObjCLibraryBaseRule.
- */
-public class BazelJ2ObjcLibraryRule implements RuleDefinition {
- private final J2ObjcAspect j2ObjcAspect;
-
- public BazelJ2ObjcLibraryRule(J2ObjcAspect j2ObjcAspect) {
- this.j2ObjcAspect = j2ObjcAspect;
- }
-
- @Override
- public RuleClass build(Builder builder, RuleDefinitionEnvironment env) {
- return builder
- .requiresConfigurationFragments(J2ObjcConfiguration.class, ObjcConfiguration.class,
- AppleConfiguration.class)
- /* <!-- #BLAZE_RULE(j2objc_library).ATTRIBUTE(deps) -->
- A list of <code>j2objc_library</code>, <code>java_library</code>
- and <code>java_import</code> targets that contain
- Java files to be transpiled to Objective-C.
- <p>All <code>java_library</code> and <code>java_import</code> targets that can be reached
- transitively through <code>exports</code>, <code>deps</code> and <code>runtime_deps</code>
- will be translated and compiled. Currently there is no support for files generated by Java
- annotation processing or <code>java_import</code> targets with no <code>srcjar</code>
- specified.
- </p>
- <p>The J2ObjC translation works differently depending on the type of source Java source
- files included in the transitive closure. For each .java source files included in
- <code>srcs</code> of <code>java_library</code>, a corresponding .h and .m source file
- will be generated. For each source jar included in <code>srcs</code> of
- <code>java_library</code> or <code>srcjar</code> of <code>java_import</code>, a
- corresponding .h and .m source file will be generated with all the code for that jar.
- </p>
- <p>Users can import the J2ObjC-generated header files in their code. The import paths for
- these files are the root-relative path of the original Java artifacts. For example,
- <code>//some/package/foo.java</code> has an import path of <code>some/package/foo.h</code>
- and <code>//some/package/bar.srcjar</code> has <code>some/package/bar.h</code
- </p>
- <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
- .add(attr("deps", LABEL_LIST)
- .aspect(j2ObjcAspect)
- .direct_compile_time_input()
- .allowedRuleClasses("j2objc_library", "java_library", "java_import")
- .allowedFileTypes())
- .build();
- }
-
- @Override
- public Metadata getMetadata() {
- return RuleDefinition.Metadata.builder()
- .name("j2objc_library")
- .factoryClass(J2ObjcLibrary.class)
- .ancestors(J2ObjcLibraryBaseRule.class)
- .build();
- }
-}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java
index 60fc82c643..2c19d7bdf3 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java
@@ -67,14 +67,14 @@ import java.util.List;
public class J2ObjcAspect extends NativeAspectClass implements ConfiguredAspectFactory {
public static final String NAME = "J2ObjcAspect";
private final String toolsRepository;
- private final BazelJ2ObjcProtoAspect bazelJ2ObjcProtoAspect;
+ private final AbstractJ2ObjcProtoAspect j2ObjcProtoAspect;
private static final ExtraCompileArgs EXTRA_COMPILE_ARGS = new ExtraCompileArgs(
"-fno-strict-overflow");
- public J2ObjcAspect(String toolsRepository, BazelJ2ObjcProtoAspect bazelJ2ObjcProtoAspect) {
+ public J2ObjcAspect(String toolsRepository, AbstractJ2ObjcProtoAspect j2ObjcProtoAspect) {
this.toolsRepository = toolsRepository;
- this.bazelJ2ObjcProtoAspect = bazelJ2ObjcProtoAspect;
+ this.j2ObjcProtoAspect = j2ObjcProtoAspect;
}
private static final Iterable<Attribute> DEPENDENT_ATTRIBUTES = ImmutableList.of(
@@ -98,56 +98,67 @@ public class J2ObjcAspect extends NativeAspectClass implements ConfiguredAspectF
}
};
- /**
- * Adds additional attribute aspects and attributes to the given AspectDefinition.Builder.
- */
- protected AspectDefinition.Builder addAdditionalAttributes(
- AspectDefinition.Builder builder) {
- return builder.attributeAspect("deps", this, bazelJ2ObjcProtoAspect)
- .attributeAspect("exports", this, bazelJ2ObjcProtoAspect)
- .attributeAspect("runtime_deps", this, bazelJ2ObjcProtoAspect);
+ /** Adds additional attribute aspects and attributes to the given AspectDefinition.Builder. */
+ protected AspectDefinition.Builder addAdditionalAttributes(AspectDefinition.Builder builder) {
+ return builder;
}
@Override
public AspectDefinition getDefinition(AspectParameters aspectParameters) {
return addAdditionalAttributes(new AspectDefinition.Builder("J2ObjCAspect"))
+ .attributeAspect("deps", this, j2ObjcProtoAspect)
+ .attributeAspect("exports", this, j2ObjcProtoAspect)
+ .attributeAspect("runtime_deps", this, j2ObjcProtoAspect)
.requireProvider(JavaSourceInfoProvider.class)
.requireProvider(JavaCompilationArgsProvider.class)
.requiresConfigurationFragments(
- AppleConfiguration.class,
- J2ObjcConfiguration.class,
- ObjcConfiguration.class)
+ AppleConfiguration.class, J2ObjcConfiguration.class, ObjcConfiguration.class)
.requiresHostConfigurationFragments(Jvm.class)
- .add(attr("$j2objc", LABEL).cfg(HOST).exec()
- .value(Label.parseAbsoluteUnchecked(
- toolsRepository + "//tools/j2objc:j2objc_deploy.jar")))
- .add(attr("$j2objc_wrapper", LABEL)
- .allowedFileTypes(FileType.of(".py"))
- .cfg(HOST)
- .exec()
- .singleArtifact()
- .value(Label.parseAbsoluteUnchecked(
- toolsRepository + "//tools/j2objc:j2objc_wrapper")))
- .add(attr("$jre_emul_jar", LABEL).cfg(HOST)
- .value(Label.parseAbsoluteUnchecked(
- toolsRepository + "//third_party/java/j2objc:jre_emul.jar")))
+ .add(
+ attr("$j2objc", LABEL)
+ .cfg(HOST)
+ .exec()
+ .value(
+ Label.parseAbsoluteUnchecked(
+ toolsRepository + "//tools/j2objc:j2objc_deploy.jar")))
+ .add(
+ attr("$j2objc_wrapper", LABEL)
+ .allowedFileTypes(FileType.of(".py"))
+ .cfg(HOST)
+ .exec()
+ .singleArtifact()
+ .value(
+ Label.parseAbsoluteUnchecked(
+ toolsRepository + "//tools/j2objc:j2objc_wrapper")))
+ .add(
+ attr("$jre_emul_jar", LABEL)
+ .cfg(HOST)
+ .value(
+ Label.parseAbsoluteUnchecked(
+ toolsRepository + "//third_party/java/j2objc:jre_emul.jar")))
.add(attr(":jre_lib", LABEL).value(JRE_LIB))
- .add(attr("$xcrunwrapper", LABEL).cfg(HOST).exec()
- .value(Label.parseAbsoluteUnchecked(
- toolsRepository + "//tools/objc:xcrunwrapper")))
- .add(attr(ObjcRuleClasses.LIBTOOL_ATTRIBUTE, LABEL).cfg(HOST).exec()
- .value(Label.parseAbsoluteUnchecked(
- toolsRepository + "//tools/objc:libtool")))
- .add(attr(":xcode_config", LABEL)
- .allowedRuleClasses("xcode_config")
- .checkConstraints()
- .direct_compile_time_input()
- .cfg(HOST)
- .value(new AppleToolchain.XcodeConfigLabel(toolsRepository)))
- .add(attr("$zipper", LABEL)
- .cfg(HOST)
- .exec()
- .value(Label.parseAbsoluteUnchecked(toolsRepository + "//tools/zip:zipper")))
+ .add(
+ attr("$xcrunwrapper", LABEL)
+ .cfg(HOST)
+ .exec()
+ .value(Label.parseAbsoluteUnchecked(toolsRepository + "//tools/objc:xcrunwrapper")))
+ .add(
+ attr(ObjcRuleClasses.LIBTOOL_ATTRIBUTE, LABEL)
+ .cfg(HOST)
+ .exec()
+ .value(Label.parseAbsoluteUnchecked(toolsRepository + "//tools/objc:libtool")))
+ .add(
+ attr(":xcode_config", LABEL)
+ .allowedRuleClasses("xcode_config")
+ .checkConstraints()
+ .direct_compile_time_input()
+ .cfg(HOST)
+ .value(new AppleToolchain.XcodeConfigLabel(toolsRepository)))
+ .add(
+ attr("$zipper", LABEL)
+ .cfg(HOST)
+ .exec()
+ .value(Label.parseAbsoluteUnchecked(toolsRepository + "//tools/zip:zipper")))
.build();
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcLibraryRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcLibraryRule.java
new file mode 100644
index 0000000000..416e7143ec
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcLibraryRule.java
@@ -0,0 +1,85 @@
+// Copyright 2015 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.
+
+package com.google.devtools.build.lib.rules.objc;
+
+import static com.google.devtools.build.lib.packages.Attribute.attr;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
+
+import com.google.devtools.build.lib.analysis.RuleDefinition;
+import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
+import com.google.devtools.build.lib.packages.RuleClass;
+import com.google.devtools.build.lib.packages.RuleClass.Builder;
+import com.google.devtools.build.lib.rules.apple.AppleConfiguration;
+
+/** <code>j2objc_library</code> rule declaration. */
+public class J2ObjcLibraryRule implements RuleDefinition {
+ private final J2ObjcAspect j2ObjcAspect;
+
+ public J2ObjcLibraryRule(J2ObjcAspect j2ObjcAspect) {
+ this.j2ObjcAspect = j2ObjcAspect;
+ }
+
+ @Override
+ public RuleClass build(Builder builder, RuleDefinitionEnvironment env) {
+ return builder
+ .requiresConfigurationFragments(
+ J2ObjcConfiguration.class, ObjcConfiguration.class, AppleConfiguration.class)
+ /* <!-- #BLAZE_RULE(j2objc_library).ATTRIBUTE(deps) -->
+ A list of <code>j2objc_library</code>, <code>java_library</code>
+ and <code>java_import</code> targets that contain
+ Java files to be transpiled to Objective-C.
+ <p>All <code>java_library</code> and <code>java_import</code> targets that can be reached
+ transitively through <code>exports</code>, <code>deps</code> and <code>runtime_deps</code>
+ will be translated and compiled. Currently there is no support for files generated by Java
+ annotation processing or <code>java_import</code> targets with no <code>srcjar</code>
+ specified.
+ </p>
+ <p>The J2ObjC translation works differently depending on the type of source Java source
+ files included in the transitive closure. For each .java source files included in
+ <code>srcs</code> of <code>java_library</code>, a corresponding .h and .m source file
+ will be generated. For each source jar included in <code>srcs</code> of
+ <code>java_library</code> or <code>srcjar</code> of <code>java_import</code>, a
+ corresponding .h and .m source file will be generated with all the code for that jar.
+ </p>
+ <p>Users can import the J2ObjC-generated header files in their code. The import paths for
+ these files are the root-relative path of the original Java artifacts. For example,
+ <code>//some/package/foo.java</code> has an import path of <code>some/package/foo.h</code>
+ and <code>//some/package/bar.srcjar</code> has <code>some/package/bar.h</code
+ </p>
+ <p>
+ If proto_library rules are in the transitive closure of this rule, J2ObjC protos will also
+ be generated, compiled and linked-in at the binary level. For proto
+ <code>//some/proto/foo.proto</code>, users can reference the generated code using import
+ path <code>some/proto/foo.j2objc.pb.h</code>.
+ </p>
+ <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
+ .add(
+ attr("deps", LABEL_LIST)
+ .aspect(j2ObjcAspect)
+ .direct_compile_time_input()
+ .allowedRuleClasses("j2objc_library", "java_library", "java_import")
+ .allowedFileTypes())
+ .build();
+ }
+
+ @Override
+ public Metadata getMetadata() {
+ return RuleDefinition.Metadata.builder()
+ .name("j2objc_library")
+ .factoryClass(J2ObjcLibrary.class)
+ .ancestors(J2ObjcLibraryBaseRule.class)
+ .build();
+ }
+}