Delete some Objc dead code
RELNOTES:none
PiperOrigin-RevId: 388712502
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java b/src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java
index e804edb..92f95a9 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java
@@ -520,4 +520,17 @@
.build();
}
}
+
+ /**
+ * Factory used by rules' definitions that exist for the sole purpose of providing documentation.
+ * For most of these rules, the actual rule is implemented in Starlark but the documentation
+ * generation mechanism does not work yet for Starlark rules. TODO(bazel-team): Delete once
+ * documentation tools work for Starlark.
+ */
+ public static class EmptyRuleConfiguredTargetFactory implements RuleConfiguredTargetFactory {
+ @Override
+ public ConfiguredTarget create(RuleContext ruleContext) {
+ return null;
+ }
+ }
}
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/objc/BazelObjcImport.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/objc/BazelObjcImport.java
deleted file mode 100644
index c5d73107..0000000
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/objc/BazelObjcImport.java
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright 2021 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 com.google.devtools.build.lib.bazel.rules.cpp.BazelCppSemantics;
-import com.google.devtools.build.lib.rules.objc.ObjcImport;
-
-/** Factory class for the {@code objc_import} rule. */
-public class BazelObjcImport extends ObjcImport {
- public BazelObjcImport() {
- super(BazelCppSemantics.OBJC);
- }
-}
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/objc/BazelObjcImportRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/objc/BazelObjcImportRule.java
index 4f90f57..b6f5c33 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/objc/BazelObjcImportRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/objc/BazelObjcImportRule.java
@@ -14,6 +14,7 @@
package com.google.devtools.build.lib.bazel.rules.objc;
+import com.google.devtools.build.lib.analysis.BaseRuleClasses;
import com.google.devtools.build.lib.analysis.RuleDefinition;
import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
import com.google.devtools.build.lib.packages.RuleClass;
@@ -30,7 +31,7 @@
public Metadata getMetadata() {
return RuleDefinition.Metadata.builder()
.name("objc_import")
- .factoryClass(BazelObjcImport.class)
+ .factoryClass(BaseRuleClasses.EmptyRuleConfiguredTargetFactory.class)
.ancestors(ObjcImportBaseRule.class)
.build();
}
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/objc/BazelObjcLibrary.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/objc/BazelObjcLibrary.java
deleted file mode 100644
index ed1a0f3..0000000
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/objc/BazelObjcLibrary.java
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright 2021 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 com.google.devtools.build.lib.bazel.rules.cpp.BazelCppSemantics;
-import com.google.devtools.build.lib.rules.objc.ObjcLibrary;
-
-/** Factory class for the {@code objc_library} rule. */
-public class BazelObjcLibrary extends ObjcLibrary {
- public BazelObjcLibrary() {
- super(BazelCppSemantics.OBJC);
- }
-}
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/objc/BazelObjcLibraryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/objc/BazelObjcLibraryRule.java
index d4de989..0350327 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/objc/BazelObjcLibraryRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/objc/BazelObjcLibraryRule.java
@@ -14,6 +14,7 @@
package com.google.devtools.build.lib.bazel.rules.objc;
+import com.google.devtools.build.lib.analysis.BaseRuleClasses;
import com.google.devtools.build.lib.analysis.RuleDefinition;
import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
import com.google.devtools.build.lib.packages.RuleClass;
@@ -34,7 +35,7 @@
public Metadata getMetadata() {
return RuleDefinition.Metadata.builder()
.name("objc_library")
- .factoryClass(BazelObjcLibrary.class)
+ .factoryClass(BaseRuleClasses.EmptyRuleConfiguredTargetFactory.class)
.ancestors(ObjcLibraryBaseRule.class)
.build();
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java
index 9ebce70..a82fe44 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java
@@ -115,9 +115,7 @@
import java.util.Set;
import java.util.TreeMap;
import java.util.stream.Stream;
-import net.starlark.java.annot.Param;
import net.starlark.java.annot.StarlarkMethod;
-import net.starlark.java.eval.EvalException;
import net.starlark.java.eval.StarlarkValue;
/**
@@ -958,29 +956,6 @@
return this;
}
- @StarlarkMethod(name = "validate_attributes", documented = false)
- public void validateAttributesForStarlark() throws EvalException {
- try {
- validateAttributes();
- } catch (RuleErrorException ruleErrorException) {
- throw new EvalException(ruleErrorException);
- }
- }
-
- @StarlarkMethod(
- name = "register_compile_and_archive_actions",
- documented = false,
- parameters = {@Param(name = "common", positional = false, named = true)})
- public void registerCompileAndArchiveActionsForStarlark(ObjcCommon common)
- throws EvalException, InterruptedException {
- try {
- registerCompileAndArchiveActions(
- common, ExtraCompileArgs.NONE, ImmutableList.<PathFragment>of());
- } catch (RuleErrorException ruleErrorException) {
- throw new EvalException(ruleErrorException);
- }
- }
-
/**
* Registers all actions necessary to compile this rule's sources and archive them.
*
@@ -1002,33 +977,6 @@
/**
* Registers all actions necessary to compile this rule's sources and archive them.
*
- * @param common common information about this rule and its dependencies
- * @return this compilation support
- * @throws RuleErrorException for invalid crosstool files
- */
- CompilationSupport registerCompileAndArchiveActions(ObjcCommon common)
- throws RuleErrorException, InterruptedException {
- return registerCompileAndArchiveActions(
- common, ExtraCompileArgs.NONE, ImmutableList.<PathFragment>of());
- }
-
- /**
- * Registers all actions necessary to compile this rule's sources and archive them.
- *
- * @param common common information about this rule and its dependencies
- * @param priorityHeaders priority headers to be included before the dependency headers
- * @return this compilation support
- * @throws RuleErrorException for invalid crosstool files
- */
- CompilationSupport registerCompileAndArchiveActions(
- ObjcCommon common, List<PathFragment> priorityHeaders)
- throws RuleErrorException, InterruptedException {
- return registerCompileAndArchiveActions(common, ExtraCompileArgs.NONE, priorityHeaders);
- }
-
- /**
- * Registers all actions necessary to compile this rule's sources and archive them.
- *
* @param compilationArtifacts collection of artifacts required for the compilation
* @param objcCompilationContext provides the compiling information to register these actions
* @param extraCompileArgs args to be added to compile actions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java
index 8f033ae..a1a4214 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java
@@ -31,7 +31,6 @@
import static com.google.devtools.build.lib.rules.objc.ObjcProvider.UMBRELLA_HEADER;
import static com.google.devtools.build.lib.rules.objc.ObjcProvider.WEAK_SDK_FRAMEWORK;
-import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
@@ -53,13 +52,9 @@
import com.google.devtools.build.lib.rules.cpp.CcLinkingContext;
import com.google.devtools.build.lib.rules.cpp.CppModuleMap;
import com.google.devtools.build.lib.rules.cpp.LibraryToLink;
-import com.google.devtools.build.lib.util.FileType;
import com.google.devtools.build.lib.vfs.PathFragment;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
-import java.util.Set;
-import net.starlark.java.annot.StarlarkMethod;
import net.starlark.java.eval.StarlarkSemantics;
import net.starlark.java.eval.StarlarkValue;
@@ -222,24 +217,6 @@
return this;
}
- /**
- * Adds providers for runtime frameworks included in the final app bundle but not linked with at
- * build time.
- */
- Builder addRuntimeDeps(List<? extends TransitiveInfoCollection> runtimeDeps) {
- ImmutableList.Builder<ObjcProvider> objcProviders = ImmutableList.builder();
- ImmutableList.Builder<CcInfo> ccInfos = ImmutableList.builder();
-
- for (TransitiveInfoCollection dep : runtimeDeps) {
- addAnyProviders(objcProviders, dep, ObjcProvider.STARLARK_CONSTRUCTOR);
- addAnyProviders(ccInfos, dep, CcInfo.PROVIDER);
- }
- this.runtimeObjcProviders =
- Iterables.concat(this.runtimeObjcProviders, objcProviders.build());
- addCcCompilationContexts(ccInfos.build());
- return this;
- }
-
private <T extends Info> ImmutableList.Builder<T> addAnyProviders(
ImmutableList.Builder<T> listBuilder,
TransitiveInfoCollection collection,
@@ -296,11 +273,6 @@
return this;
}
- Builder addLinkopts(Iterable<String> linkopts) {
- this.linkopts = Iterables.concat(this.linkopts, linkopts);
- return this;
- }
-
/**
* Specifies that this target has a clang module map. This should be called if this target
* compiles sources or exposes headers for other targets to use. Note that this does not add
@@ -312,14 +284,6 @@
return this;
}
- /**
- * Adds additional static libraries to be linked into the final ObjC application bundle.
- */
- Builder addExtraImportLibraries(Iterable<Artifact> extraImportLibraries) {
- this.extraImportLibraries = Iterables.concat(this.extraImportLibraries, extraImportLibraries);
- return this;
- }
-
ObjcCommon build() {
ObjcCompilationContext.Builder objcCompilationContextBuilder =
@@ -481,12 +445,10 @@
return purpose;
}
- @StarlarkMethod(name = "objc_provider", documented = false, structField = true)
public ObjcProvider getObjcProvider() {
return objcProvider;
}
- @StarlarkMethod(name = "objc_compilation_context", documented = false, structField = true)
public ObjcCompilationContext getObjcCompilationContext() {
return objcCompilationContext;
}
@@ -510,64 +472,4 @@
}
return Optional.absent();
}
-
- /**
- * Returns effective compilation options that do not arise from the crosstool.
- */
- static Iterable<String> getNonCrosstoolCopts(RuleContext ruleContext) {
- return Iterables.concat(
- ruleContext.getFragment(ObjcConfiguration.class).getCopts(),
- ruleContext.getExpander().withDataLocations().tokenized("copts"));
- }
-
- /**
- * Returns the first directory in the sequence of parents of the exec path of the given artifact
- * that matches {@code type}. For instance, if {@code type} is FileType.of(".foo") and the exec
- * path of {@code artifact} is {@code a/b/c/bar.foo/d/e}, then the return value is
- * {@code a/b/c/bar.foo}.
- */
- static Optional<PathFragment> nearestContainerMatching(FileType type, Artifact artifact) {
- PathFragment container = artifact.getExecPath();
- do {
- if (type.matches(container)) {
- return Optional.of(container);
- }
- container = container.getParentDirectory();
- } while (container != null);
- return Optional.absent();
- }
-
- /**
- * Similar to {@link #nearestContainerMatching(FileType, Artifact)}, but tries matching several
- * file types in {@code types}, and returns a path for the first match in the sequence.
- */
- static Optional<PathFragment> nearestContainerMatching(
- Iterable<FileType> types, Artifact artifact) {
- for (FileType type : types) {
- for (PathFragment container : nearestContainerMatching(type, artifact).asSet()) {
- return Optional.of(container);
- }
- }
- return Optional.absent();
- }
-
- static Iterable<String> notInContainerErrors(
- Iterable<Artifact> artifacts, Iterable<FileType> containerTypes) {
- Set<String> errors = new HashSet<>();
- for (Artifact artifact : artifacts) {
- boolean inContainer = nearestContainerMatching(containerTypes, artifact).isPresent();
- if (!inContainer) {
- errors.add(
- String.format(
- NOT_IN_CONTAINER_ERROR_FORMAT,
- artifact.getExecPath(),
- Iterables.toString(containerTypes)));
- }
- }
- return errors;
- }
-
- @VisibleForTesting
- static final String NOT_IN_CONTAINER_ERROR_FORMAT =
- "File '%s' is not in a directory of one of these type(s): %s";
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcImport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcImport.java
deleted file mode 100644
index 37a686f..0000000
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcImport.java
+++ /dev/null
@@ -1,84 +0,0 @@
-// Copyright 2014 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 com.google.common.collect.ImmutableList;
-import com.google.devtools.build.lib.actions.Artifact;
-import com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException;
-import com.google.devtools.build.lib.analysis.ConfiguredTarget;
-import com.google.devtools.build.lib.analysis.RuleConfiguredTargetFactory;
-import com.google.devtools.build.lib.analysis.RuleContext;
-import com.google.devtools.build.lib.collect.nestedset.NestedSet;
-import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
-import com.google.devtools.build.lib.packages.Type;
-import com.google.devtools.build.lib.rules.cpp.CcInfo;
-import com.google.devtools.build.lib.rules.cpp.CppSemantics;
-import java.util.Map;
-import java.util.TreeMap;
-
-/**
- * Implementation for {@code objc_import}.
- */
-public class ObjcImport implements RuleConfiguredTargetFactory {
- private final CppSemantics cppSemantics;
-
- protected ObjcImport(CppSemantics cppSemantics) {
- this.cppSemantics = cppSemantics;
- }
-
- @Override
- public ConfiguredTarget create(RuleContext ruleContext)
- throws InterruptedException, RuleErrorException, ActionConflictException {
-
- CompilationAttributes compilationAttributes =
- CompilationAttributes.Builder.fromRuleContext(ruleContext).build();
- IntermediateArtifacts intermediateArtifacts =
- ObjcRuleClasses.intermediateArtifacts(ruleContext);
- CompilationArtifacts compilationArtifacts = new CompilationArtifacts.Builder().build();
-
- ObjcCommon common =
- new ObjcCommon.Builder(ObjcCommon.Purpose.COMPILE_AND_LINK, ruleContext)
- .setCompilationArtifacts(compilationArtifacts)
- .setCompilationAttributes(compilationAttributes)
- .addDeps(ruleContext.getPrerequisites("deps"))
- .setIntermediateArtifacts(intermediateArtifacts)
- .setAlwayslink(ruleContext.attributes().get("alwayslink", Type.BOOLEAN))
- .setHasModuleMap()
- .addExtraImportLibraries(ruleContext.getPrerequisiteArtifacts("archives").list())
- .build();
-
- NestedSetBuilder<Artifact> filesToBuild = NestedSetBuilder.stableOrder();
-
- Map<String, NestedSet<Artifact>> outputGroupCollector = new TreeMap<>();
- ImmutableList.Builder<Artifact> objectFilesCollector = ImmutableList.builder();
-
- CompilationSupport compilationSupport =
- new CompilationSupport.Builder(ruleContext, cppSemantics)
- .setOutputGroupCollector(outputGroupCollector)
- .setObjectFilesCollector(objectFilesCollector)
- .build();
-
- compilationSupport.registerCompileAndArchiveActions(common).validateAttributes();
-
- return ObjcRuleClasses.ruleConfiguredTarget(ruleContext, filesToBuild.build())
- .addNativeDeclaredProvider(common.getObjcProvider())
- .addNativeDeclaredProvider(
- CcInfo.builder()
- .setCcCompilationContext(compilationSupport.getCcCompilationContext())
- .build())
- .addStarlarkTransitiveInfo(ObjcProvider.STARLARK_NAME, common.getObjcProvider())
- .build();
- }
-}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcLibrary.java
deleted file mode 100644
index e593a3e..0000000
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcLibrary.java
+++ /dev/null
@@ -1,189 +0,0 @@
-// Copyright 2014 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 com.google.common.collect.ImmutableList;
-import com.google.devtools.build.lib.actions.Artifact;
-import com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException;
-import com.google.devtools.build.lib.analysis.ConfiguredTarget;
-import com.google.devtools.build.lib.analysis.RuleConfiguredTargetFactory;
-import com.google.devtools.build.lib.analysis.RuleContext;
-import com.google.devtools.build.lib.cmdline.Label;
-import com.google.devtools.build.lib.collect.compacthashset.CompactHashSet;
-import com.google.devtools.build.lib.collect.nestedset.NestedSet;
-import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
-import com.google.devtools.build.lib.collect.nestedset.Order;
-import com.google.devtools.build.lib.packages.SymbolGenerator;
-import com.google.devtools.build.lib.packages.Type;
-import com.google.devtools.build.lib.rules.cpp.CcCompilationContext;
-import com.google.devtools.build.lib.rules.cpp.CcInfo;
-import com.google.devtools.build.lib.rules.cpp.CcLinkingContext;
-import com.google.devtools.build.lib.rules.cpp.CcLinkingContext.LinkOptions;
-import com.google.devtools.build.lib.rules.cpp.CcLinkingContext.LinkerInput;
-import com.google.devtools.build.lib.rules.cpp.CppSemantics;
-import com.google.devtools.build.lib.rules.cpp.LibraryToLink;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-
-/**
- * Implementation for {@code objc_library}.
- */
-public class ObjcLibrary implements RuleConfiguredTargetFactory {
- private final CppSemantics cppSemantics;
-
- protected ObjcLibrary(CppSemantics cppSemantics) {
- this.cppSemantics = cppSemantics;
- }
-
- /**
- * Constructs an {@link ObjcCommon} instance based on the attributes of the given rule context.
- */
- private static ObjcCommon common(RuleContext ruleContext) throws InterruptedException {
- return new ObjcCommon.Builder(ObjcCommon.Purpose.COMPILE_AND_LINK, ruleContext)
- .setCompilationAttributes(
- CompilationAttributes.Builder.fromRuleContext(ruleContext).build())
- .setCompilationArtifacts(CompilationSupport.compilationArtifacts(ruleContext))
- .addDeps(ruleContext.getPrerequisites("deps"))
- .addRuntimeDeps(ruleContext.getPrerequisites("runtime_deps"))
- .setIntermediateArtifacts(ObjcRuleClasses.intermediateArtifacts(ruleContext))
- .setAlwayslink(ruleContext.attributes().get("alwayslink", Type.BOOLEAN))
- .addLinkopts(ruleContext.getExpander().withDataLocations().tokenized("linkopts"))
- .setHasModuleMap()
- .build();
- }
-
- @Override
- public ConfiguredTarget create(RuleContext ruleContext)
- throws InterruptedException, RuleErrorException, ActionConflictException {
- validateAttributes(ruleContext);
-
- ObjcCommon common = common(ruleContext);
-
- NestedSetBuilder<Artifact> filesToBuild = NestedSetBuilder.<Artifact>stableOrder()
- .addAll(common.getCompiledArchive().asSet());
-
- Map<String, NestedSet<Artifact>> outputGroupCollector = new TreeMap<>();
- ImmutableList.Builder<Artifact> objectFilesCollector = ImmutableList.builder();
- CompilationSupport compilationSupport =
- new CompilationSupport.Builder(ruleContext, cppSemantics)
- .setOutputGroupCollector(outputGroupCollector)
- .setObjectFilesCollector(objectFilesCollector)
- .build();
-
- compilationSupport
- .registerCompileAndArchiveActions(common)
- .validateAttributes();
-
- J2ObjcMappingFileProvider j2ObjcMappingFileProvider =
- J2ObjcMappingFileProvider.union(
- ruleContext.getPrerequisites("deps", J2ObjcMappingFileProvider.PROVIDER));
- J2ObjcEntryClassProvider j2ObjcEntryClassProvider =
- new J2ObjcEntryClassProvider.Builder()
- .addTransitive(ruleContext.getPrerequisites("deps", J2ObjcEntryClassProvider.PROVIDER))
- .build();
- ObjcProvider objcProvider = common.getObjcProvider();
- CcCompilationContext ccCompilationContext = compilationSupport.getCcCompilationContext();
- CcLinkingContext ccLinkingContext =
- buildCcLinkingContext(
- ruleContext.getLabel(), objcProvider, ruleContext.getSymbolGenerator());
-
- return ObjcRuleClasses.ruleConfiguredTarget(ruleContext, filesToBuild.build())
- .addNativeDeclaredProvider(objcProvider)
- .addStarlarkTransitiveInfo(ObjcProvider.STARLARK_NAME, objcProvider)
- .addNativeDeclaredProvider(j2ObjcEntryClassProvider)
- .addNativeDeclaredProvider(j2ObjcMappingFileProvider)
- .addNativeDeclaredProvider(
- compilationSupport.getInstrumentedFilesProvider(objectFilesCollector.build()))
- .addNativeDeclaredProvider(
- CcInfo.builder()
- .setCcCompilationContext(ccCompilationContext)
- .setCcLinkingContext(ccLinkingContext)
- .build())
- .addOutputGroups(outputGroupCollector)
- .build();
- }
-
- private static CcLinkingContext buildCcLinkingContext(
- Label label, ObjcProvider objcProvider, SymbolGenerator<?> symbolGenerator) {
- List<Artifact> libraries = objcProvider.get(ObjcProvider.LIBRARY).toList();
- List<LibraryToLink> ccLibraries = objcProvider.get(ObjcProvider.CC_LIBRARY).toList();
-
- Set<LibraryToLink> librariesToLink =
- CompactHashSet.createWithExpectedSize(libraries.size() + ccLibraries.size());
- for (Artifact library : libraries) {
- librariesToLink.add(LibraryToLink.staticOnly(library));
- }
-
- for (LibraryToLink library : ccLibraries) {
- librariesToLink.add(convertToStaticLibrary(library));
- }
-
- List<SdkFramework> sdkFrameworks = objcProvider.get(ObjcProvider.SDK_FRAMEWORK).toList();
- ImmutableList.Builder<LinkOptions> userLinkFlags =
- ImmutableList.builderWithExpectedSize(sdkFrameworks.size());
- for (SdkFramework sdkFramework : sdkFrameworks) {
- userLinkFlags.add(
- LinkOptions.of(ImmutableList.of("-framework", sdkFramework.getName()), symbolGenerator));
- }
-
- LinkerInput linkerInput =
- new LinkerInput(
- label,
- ImmutableList.copyOf(librariesToLink),
- userLinkFlags.build(),
- /*nonCodeInputs=*/ ImmutableList.of(),
- objcProvider.get(ObjcProvider.LINKSTAMP).toList());
-
- return new CcLinkingContext(
- NestedSetBuilder.create(Order.LINK_ORDER, linkerInput), /*extraLinkTimeLibraries=*/ null);
- }
-
- /**
- * Removes dynamic libraries from {@link LibraryToLink} objects coming from C++ dependencies. The
- * reason for this is that objective-C rules do not support linking the dynamic version of the
- * libraries.
- *
- * <p>Returns the same object if nothing would be changed.
- */
- private static LibraryToLink convertToStaticLibrary(LibraryToLink library) {
- if ((library.getPicStaticLibrary() == null && library.getStaticLibrary() == null)
- || (library.getDynamicLibrary() == null && library.getInterfaceLibrary() == null)) {
- return library;
- }
-
- return library.toBuilder()
- .setDynamicLibrary(null)
- .setResolvedSymlinkDynamicLibrary(null)
- .setInterfaceLibrary(null)
- .setResolvedSymlinkInterfaceLibrary(null)
- .build();
- }
-
- /** Throws errors or warnings for bad attribute state. */
- private static void validateAttributes(RuleContext ruleContext) {
- // TODO(b/129469095): objc_library cannot handle target names with slashes. Rather than
- // crashing bazel, we emit a useful error message.
- if (ruleContext.getTarget().getName().indexOf('/') != -1) {
- ruleContext.attributeError("name", "this attribute has unsupported character '/'");
- }
- for (String copt : ObjcCommon.getNonCrosstoolCopts(ruleContext)) {
- if (copt.contains("-fmodules-cache-path")) {
- ruleContext.ruleWarning(CompilationSupport.MODULES_CACHE_PATH_WARNING);
- }
- }
- }
-}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcStarlarkInternal.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcStarlarkInternal.java
index 1f58091..69262ca 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcStarlarkInternal.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcStarlarkInternal.java
@@ -21,14 +21,11 @@
import com.google.devtools.build.docgen.annot.DocCategory;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.analysis.TemplateVariableInfo;
-import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
import com.google.devtools.build.lib.analysis.starlark.StarlarkRuleContext;
import com.google.devtools.build.lib.analysis.test.InstrumentedFilesInfo;
import com.google.devtools.build.lib.packages.NativeInfo;
-import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException;
import com.google.devtools.build.lib.packages.Type;
import com.google.devtools.build.lib.rules.cpp.CcCompilationContext;
-import com.google.devtools.build.lib.rules.cpp.CppSemantics;
import com.google.devtools.build.lib.shell.ShellUtils;
import com.google.devtools.build.lib.shell.ShellUtils.TokenizationException;
import com.google.devtools.build.lib.vfs.PathFragment;
@@ -207,84 +204,6 @@
}
@StarlarkMethod(
- name = "create_common",
- documented = false,
- parameters = {
- @Param(name = "ctx", positional = false, named = true),
- @Param(name = "purpose", positional = false, named = true),
- @Param(name = "compilation_attributes", positional = false, named = true),
- @Param(name = "deps", positional = false, named = true),
- @Param(name = "runtime_deps", positional = false, named = true, defaultValue = "[]"),
- @Param(name = "intermediate_artifacts", positional = false, named = true),
- @Param(name = "alwayslink", positional = false, named = true),
- @Param(name = "has_module_map", positional = false, named = true),
- @Param(
- name = "extra_import_libraries",
- positional = false,
- defaultValue = "[]",
- named = true),
- @Param(name = "compilation_artifacts", positional = false, named = true),
- @Param(name = "linkopts", positional = false, named = true, defaultValue = "[]")
- })
- public ObjcCommon createObjcCommon(
- StarlarkRuleContext starlarkRuleContext,
- String purpose,
- CompilationAttributes compilationAttributes,
- Sequence<?> deps,
- Sequence<?> runtimeDeps,
- IntermediateArtifacts intermediateArtifacts,
- boolean alwayslink,
- boolean hasModuleMap,
- Sequence<?> extraImportLibraries,
- CompilationArtifacts compilationArtifacts,
- Sequence<?> linkopts)
- throws InterruptedException, EvalException {
- ObjcCommon.Builder builder =
- new ObjcCommon.Builder(
- ObjcCommon.Purpose.valueOf(purpose), starlarkRuleContext.getRuleContext())
- .setCompilationAttributes(compilationAttributes)
- .addDeps(Sequence.cast(deps, TransitiveInfoCollection.class, "deps"))
- .addRuntimeDeps(
- Sequence.cast(runtimeDeps, TransitiveInfoCollection.class, "runtime_deps"))
- .setIntermediateArtifacts(intermediateArtifacts)
- .setAlwayslink(alwayslink)
- .addExtraImportLibraries(
- Sequence.cast(extraImportLibraries, Artifact.class, "archives"))
- .setCompilationArtifacts(compilationArtifacts)
- .addLinkopts(
- expandToolchainAndRuleContextVariables(
- starlarkRuleContext, Sequence.cast(linkopts, String.class, "linkopts")));
-
- if (hasModuleMap) {
- builder.setHasModuleMap();
- }
-
- return builder.build();
- }
-
- @StarlarkMethod(
- name = "create_compilation_support",
- documented = false,
- parameters = {
- @Param(name = "ctx", positional = false, named = true),
- @Param(name = "semantics", positional = false, named = true),
- @Param(name = "compilation_attributes", positional = false, named = true),
- })
- public CompilationSupport createCompilationSupport(
- StarlarkRuleContext starlarkRuleContext,
- CppSemantics cppSemantics,
- CompilationAttributes compilationAttributes)
- throws InterruptedException, EvalException {
- try {
- return new CompilationSupport.Builder(starlarkRuleContext.getRuleContext(), cppSemantics)
- .setCompilationAttributes(compilationAttributes)
- .build();
- } catch (RuleErrorException e) {
- throw new EvalException(e);
- }
- }
-
- @StarlarkMethod(
name = "instrumented_files_info",
documented = false,
parameters = {
diff --git a/src/main/starlark/builtins_bzl/common/exports.bzl b/src/main/starlark/builtins_bzl/common/exports.bzl
index 5da87c2..6af77e5 100644
--- a/src/main/starlark/builtins_bzl/common/exports.bzl
+++ b/src/main/starlark/builtins_bzl/common/exports.bzl
@@ -27,8 +27,8 @@
}
exported_rules = {
"+cc_import": cc_import,
- "+objc_import": objc_import,
- "+objc_library": objc_library,
+ "objc_import": objc_import,
+ "objc_library": objc_library,
"+apple_static_library": apple_static_library,
}
exported_to_java = {}