From 7b548ed476095d491688b5104f3785abfe963ebf Mon Sep 17 00:00:00 2001 From: twerth Date: Thu, 24 Jun 2021 23:55:11 -0700 Subject: [PATCH] Automated rollback of commit 1d738dea93ca967aa9dd738b14b9dbd79e8ce493. *** Reason for rollback *** Breaks some targets per[] *** Original change description *** Create new key for ObjcProvider This key uses linker inputs from CcLinkingContext instead of its components. This will help avoiding nested set flattening in the Starlark implementation. RELNOTES:none PiperOrigin-RevId: 381411285 --- .../lib/rules/objc/CompilationSupport.java | 3 +- .../build/lib/rules/objc/ObjcCommon.java | 33 +++- .../build/lib/rules/objc/ObjcLibrary.java | 6 +- .../build/lib/rules/objc/ObjcProvider.java | 184 +++--------------- .../rules/objc/ObjcVariablesExtension.java | 3 +- .../build/lib/rules/objc/ObjcLibraryTest.java | 10 +- .../lib/rules/objc/ObjcStarlarkTest.java | 6 +- .../lib/starlark/StarlarkIntegrationTest.java | 20 +- 8 files changed, 84 insertions(+), 181 deletions(-) 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 a75422cda25e16..523d7ad83b29ae 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 @@ -24,6 +24,7 @@ import static com.google.devtools.build.lib.rules.objc.ObjcProvider.LIBRARY; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.LINK_INPUTS; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.SDK_DYLIB; +import static com.google.devtools.build.lib.rules.objc.ObjcProvider.SDK_FRAMEWORK; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.STATIC_FRAMEWORK_FILE; import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.COMPILABLE_SRCS_TYPE; import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.HEADERS; @@ -1448,7 +1449,7 @@ CompilationSupport registerFullyLinkAction(ObjcProvider objcProvider, Artifact o */ private Set frameworkNames(ObjcProvider provider) { Set names = new LinkedHashSet<>(); - names.addAll(SdkFramework.names(provider.getFrameworks())); + names.addAll(SdkFramework.names(provider.get(SDK_FRAMEWORK))); names.addAll(provider.staticFrameworkNames().toList()); names.addAll(provider.dynamicFrameworkNames().toList()); return names; 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 ae56004245e0f0..16e521bd97b850 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 @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.rules.objc; +import static com.google.devtools.build.lib.rules.objc.ObjcProvider.CC_LIBRARY; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.FLAG; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.FORCE_LOAD_LIBRARY; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.Flag.USES_CPP; @@ -21,6 +22,8 @@ import static com.google.devtools.build.lib.rules.objc.ObjcProvider.IMPORTED_LIBRARY; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.J2OBJC_LIBRARY; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.LIBRARY; +import static com.google.devtools.build.lib.rules.objc.ObjcProvider.LINKOPT; +import static com.google.devtools.build.lib.rules.objc.ObjcProvider.LINKSTAMP; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.MODULE_MAP; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.SDK_DYLIB; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.SDK_FRAMEWORK; @@ -33,13 +36,16 @@ import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.collect.Streams; +import com.google.common.collect.UnmodifiableIterator; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; 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.BuiltinProvider; import com.google.devtools.build.lib.packages.Info; import com.google.devtools.build.lib.rules.apple.AppleToolchain; @@ -47,6 +53,7 @@ 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.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; @@ -333,12 +340,32 @@ ObjcCommon build() { } for (CcLinkingContext linkProvider : ccLinkingContexts) { - objcProvider.addAll(ObjcProvider.CC_LINKER_INPUTS, linkProvider.getLinkerInputs()); + ImmutableList linkOpts = linkProvider.getFlattenedUserLinkFlags(); + ImmutableSet.Builder frameworkLinkOpts = new ImmutableSet.Builder<>(); + ImmutableList.Builder nonFrameworkLinkOpts = new ImmutableList.Builder<>(); + // Add any framework flags as frameworks directly, rather than as linkopts. + for (UnmodifiableIterator iterator = linkOpts.iterator(); iterator.hasNext(); ) { + String arg = iterator.next(); + if (arg.equals("-framework") && iterator.hasNext()) { + String framework = iterator.next(); + frameworkLinkOpts.add(new SdkFramework(framework)); + } else { + nonFrameworkLinkOpts.add(arg); + } + } + + objcProvider + .addAll(SDK_FRAMEWORK, frameworkLinkOpts.build()) + .addAll(LINKOPT, nonFrameworkLinkOpts.build()) + .addTransitiveAndPropagate( + CC_LIBRARY, + NestedSetBuilder.linkOrder() + .addTransitive(linkProvider.getLibraries()) + .build()); } for (CcLinkingContext ccLinkStampContext : ccLinkStampContexts) { - objcProvider.addAll( - ObjcProvider.LINKSTAMP_LINKER_INPUTS, ccLinkStampContext.getLinkerInputs()); + objcProvider.addAll(LINKSTAMP, ccLinkStampContext.getLinkstamps()); } if (compilationAttributes.isPresent()) { 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 index 59d007655885a1..6b23dce51c03e6 100644 --- 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 @@ -119,7 +119,7 @@ public ConfiguredTarget create(RuleContext ruleContext) private static CcLinkingContext buildCcLinkingContext( Label label, ObjcProvider objcProvider, SymbolGenerator symbolGenerator) { List libraries = objcProvider.get(ObjcProvider.LIBRARY).toList(); - List ccLibraries = objcProvider.getTransitiveCcLibraries().toList(); + List ccLibraries = objcProvider.get(ObjcProvider.CC_LIBRARY).toList(); Set librariesToLink = CompactHashSet.createWithExpectedSize(libraries.size() + ccLibraries.size()); @@ -131,7 +131,7 @@ private static CcLinkingContext buildCcLinkingContext( librariesToLink.add(convertToStaticLibrary(library)); } - List sdkFrameworks = objcProvider.getFrameworks().toList(); + List sdkFrameworks = objcProvider.get(ObjcProvider.SDK_FRAMEWORK).toList(); ImmutableList.Builder userLinkFlags = ImmutableList.builderWithExpectedSize(sdkFrameworks.size()); for (SdkFramework sdkFramework : sdkFrameworks) { @@ -145,7 +145,7 @@ private static CcLinkingContext buildCcLinkingContext( ImmutableList.copyOf(librariesToLink), userLinkFlags.build(), /*nonCodeInputs=*/ ImmutableList.of(), - objcProvider.getLinkstamps().toList()); + objcProvider.get(ObjcProvider.LINKSTAMP).toList()); return new CcLinkingContext( NestedSetBuilder.create(Order.LINK_ORDER, linkerInput), /*extraLinkTimeLibraries=*/ null); diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProvider.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProvider.java index d8f85b6c79cc7a..489200f7f5c86e 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProvider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProvider.java @@ -26,21 +26,16 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; -import com.google.common.collect.UnmodifiableIterator; import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.collect.nestedset.Depset; 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.concurrent.ThreadSafety.Immutable; -import com.google.devtools.build.lib.packages.BazelModuleContext; import com.google.devtools.build.lib.packages.BuiltinProvider; import com.google.devtools.build.lib.packages.BuiltinProvider.WithLegacyStarlarkName; import com.google.devtools.build.lib.packages.Info; 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.CcLinkingContext.Linkstamp; import com.google.devtools.build.lib.rules.cpp.LibraryToLink; import com.google.devtools.build.lib.starlarkbuildapi.apple.ObjcProviderApi; @@ -50,14 +45,11 @@ import java.util.HashSet; import java.util.List; import java.util.Map; -import net.starlark.java.annot.StarlarkMethod; import net.starlark.java.eval.EvalException; -import net.starlark.java.eval.Module; import net.starlark.java.eval.Sequence; import net.starlark.java.eval.Starlark; import net.starlark.java.eval.StarlarkList; import net.starlark.java.eval.StarlarkSemantics; -import net.starlark.java.eval.StarlarkThread; /** * A provider that provides all linking and miscellaneous information in the transitive closure of @@ -193,17 +185,11 @@ public Class getType() { static final Key LINKSTAMP = new Key<>(STABLE_ORDER, "linkstamp", CcLinkingContext.Linkstamp.class); - static final Key LINKSTAMP_LINKER_INPUTS = - new Key<>(STABLE_ORDER, "linkstamp_linker_inputs", LinkerInput.class); - /** * Linking options from dependencies. */ public static final Key LINKOPT = new Key<>(LINK_ORDER, "linkopt", String.class); - public static final Key CC_LINKER_INPUTS = - new Key<>(LINK_ORDER, "cc_linker_inputs", LinkerInput.class); - /** * Link time artifacts from dependencies. These do not fall into any other category such as * libraries or archives, rather provide a way to add arbitrary data (e.g. Swift AST files) @@ -346,7 +332,7 @@ public Sequence directHeaders() { @Override public Depset /**/ linkopt() { - return Depset.of(Depset.ElementType.STRING, getLinkopt()); + return Depset.of(Depset.ElementType.STRING, get(LINKOPT)); } @Override @@ -367,7 +353,7 @@ public Sequence directModuleMaps() { @Override public Depset sdkFramework() { return (Depset) - ObjcProviderStarlarkConverters.convertToStarlark(SDK_FRAMEWORK, getFrameworks()); + ObjcProviderStarlarkConverters.convertToStarlark(SDK_FRAMEWORK, get(SDK_FRAMEWORK)); } @Override @@ -421,10 +407,7 @@ public Depset weakSdkFramework() { // Linkstamp is not exposed to Starlark. See commentary at its definition. LINKSTAMP, // Strict include is handled specially. - STRICT_INCLUDE, - // Linker inputs avoid unnecessarily flattening nested sets - CC_LINKER_INPUTS, - LINKSTAMP_LINKER_INPUTS); + STRICT_INCLUDE); /** * Set of {@link ObjcProvider} whose values are not subtracted via {@link #subtractSubtrees}. @@ -489,10 +472,6 @@ public BuiltinProvider getProvider() { @SuppressWarnings("unchecked") public NestedSet get(Key key) { Preconditions.checkNotNull(key); - Preconditions.checkArgument(!key.equals(CC_LIBRARY)); - Preconditions.checkArgument(!key.equals(LINKOPT)); - Preconditions.checkArgument(!key.equals(LINKSTAMP)); - Preconditions.checkArgument(!key.equals(SDK_FRAMEWORK)); if (items.containsKey(key)) { return (NestedSet) items.get(key); } else { @@ -509,110 +488,6 @@ public Sequence getDirect(Key key) { return StarlarkList.empty(); } - @StarlarkMethod(name = "linker_inputs", documented = false, useStarlarkThread = true) - public Depset linkerInputsForStarlark(StarlarkThread thread) throws EvalException { - if (!isBuiltIn(thread)) { - throw Starlark.errorf("Cannot use builtin API"); - } - return Depset.of(LinkerInput.TYPE, get(ObjcProvider.CC_LINKER_INPUTS)); - } - - @StarlarkMethod(name = "linkstamp_linker_inputs", documented = false, useStarlarkThread = true) - public Depset linkstampLinkerInputsForStarlark(StarlarkThread thread) throws EvalException { - if (!isBuiltIn(thread)) { - throw Starlark.errorf("Cannot use builtin API"); - } - return Depset.of(LinkerInput.TYPE, get(ObjcProvider.LINKSTAMP_LINKER_INPUTS)); - } - - private static boolean isBuiltIn(StarlarkThread thread) { - Label label = - ((BazelModuleContext) Module.ofInnermostEnclosingStarlarkFunction(thread).getClientData()) - .label(); - return label.getPackageIdentifier().getRepository().toString().equals("@_builtins"); - } - - @SuppressWarnings("unchecked") - public NestedSet getTransitiveCcLibraries() { - NestedSetBuilder builder = NestedSetBuilder.linkOrder(); - if (items.containsKey(CC_LINKER_INPUTS)) { - for (LinkerInput linkerInput : - ((NestedSet) items.get(CC_LINKER_INPUTS)).toList()) { - builder.addAll(linkerInput.getLibraries()); - } - return builder.build(); - } else { - return NestedSetBuilder.emptySet(LINK_ORDER); - } - } - - @SuppressWarnings("unchecked") - public NestedSet getLinkopt() { - NestedSetBuilder builder = NestedSetBuilder.linkOrder(); - if (items.containsKey(LINKOPT)) { - builder.addTransitive((NestedSet) items.get(LINKOPT)); - } - - if (items.containsKey(CC_LINKER_INPUTS)) { - for (LinkerInput linkerInput : - ((NestedSet) items.get(CC_LINKER_INPUTS)).toList()) { - for (LinkOptions linkOptions : linkerInput.getUserLinkFlags()) { - ImmutableList linkOpts = linkOptions.get(); - ImmutableList.Builder nonFrameworkLinkOpts = ImmutableList.builder(); - for (UnmodifiableIterator iterator = linkOpts.iterator(); iterator.hasNext(); ) { - String arg = iterator.next(); - if (arg.equals("-framework") && iterator.hasNext()) { - iterator.next(); - } else { - nonFrameworkLinkOpts.add(arg); - } - } - builder.addAll(nonFrameworkLinkOpts.build()); - } - } - } - return builder.build(); - } - - @SuppressWarnings("unchecked") - public NestedSet getFrameworks() { - NestedSetBuilder builder = NestedSetBuilder.linkOrder(); - if (items.containsKey(SDK_FRAMEWORK)) { - builder.addTransitive((NestedSet) items.get(SDK_FRAMEWORK)); - } - if (items.containsKey(CC_LINKER_INPUTS)) { - for (LinkerInput linkerInput : - ((NestedSet) items.get(CC_LINKER_INPUTS)).toList()) { - for (LinkOptions linkOptions : linkerInput.getUserLinkFlags()) { - ImmutableList linkOpts = linkOptions.get(); - ImmutableList.Builder frameworkLinkOpts = ImmutableList.builder(); - for (UnmodifiableIterator iterator = linkOpts.iterator(); iterator.hasNext(); ) { - String arg = iterator.next(); - if (arg.equals("-framework") && iterator.hasNext()) { - String framework = iterator.next(); - frameworkLinkOpts.add(new SdkFramework(framework)); - } - } - builder.addAll(frameworkLinkOpts.build()); - } - } - } - - return builder.build(); - } - - @SuppressWarnings("unchecked") - public NestedSet getLinkstamps() { - NestedSetBuilder builder = NestedSetBuilder.linkOrder(); - if (items.containsKey(LINKSTAMP_LINKER_INPUTS)) { - for (LinkerInput linkerInput : - ((NestedSet) items.get(LINKSTAMP_LINKER_INPUTS)).toList()) { - builder.addAll(linkerInput.getLinkstamps()); - } - } - return builder.build(); - } - /** * All artifacts, bundleable files, etc, that should be propagated to transitive dependers, of * the type specified by {@code key}. @@ -648,7 +523,7 @@ ImmutableList getObjcLibraries() { /** Returns the list of .a files required for linking that arise from cc libraries. */ List getCcLibraries() { CcLinkingContext ccLinkingContext = - CcLinkingContext.builder().addLibraries(getTransitiveCcLibraries().toList()).build(); + CcLinkingContext.builder().addLibraries(get(CC_LIBRARY).toList()).build(); return ccLinkingContext.getStaticModeParamsForExecutableLibraries(); } @@ -691,9 +566,9 @@ public ObjcProvider subtractSubtrees( } ObjcProvider.Builder objcProviderBuilder = new ObjcProvider.Builder(semantics); for (Key key : items.keySet()) { - if (key == CC_LINKER_INPUTS) { - addTransitiveAndFilter( - objcProviderBuilder, CC_LINKER_INPUTS, ccLibraryNotYetLinked(avoidLibrariesSet)); + if (key == CC_LIBRARY) { + addTransitiveAndFilter(objcProviderBuilder, CC_LIBRARY, + ccLibraryNotYetLinked(avoidLibrariesSet)); } else if (key == LIBRARY) { addTransitiveAndFilter(objcProviderBuilder, LIBRARY, notContainedIn(avoidLibrariesSet)); } else if (NON_SUBTRACTABLE_KEYS.contains(key)) { @@ -728,35 +603,32 @@ private static Predicate notContainedIn( * @param runfilesPaths if a given library has runfiles path present in this set, the predicate * will return false */ - private static Predicate ccLibraryNotYetLinked( + private static Predicate ccLibraryNotYetLinked( final HashSet runfilesPaths) { - return linkerInput -> !checkIfLibraryIsInPaths(linkerInput, runfilesPaths); + return libraryToLink -> !checkIfLibraryIsInPaths(libraryToLink, runfilesPaths); } private static boolean checkIfLibraryIsInPaths( - LinkerInput linkerInput, HashSet runfilesPaths) { + LibraryToLink libraryToLink, HashSet runfilesPaths) { ImmutableList.Builder libraryRunfilesPaths = ImmutableList.builder(); - for (LibraryToLink libraryToLink : linkerInput.getLibraries()) { - if (libraryToLink.getStaticLibrary() != null) { - libraryRunfilesPaths.add(libraryToLink.getStaticLibrary().getRunfilesPath()); - } - if (libraryToLink.getPicStaticLibrary() != null) { - libraryRunfilesPaths.add(libraryToLink.getPicStaticLibrary().getRunfilesPath()); - } - if (libraryToLink.getDynamicLibrary() != null) { - libraryRunfilesPaths.add(libraryToLink.getDynamicLibrary().getRunfilesPath()); - } - if (libraryToLink.getResolvedSymlinkDynamicLibrary() != null) { - libraryRunfilesPaths.add( - libraryToLink.getResolvedSymlinkDynamicLibrary().getRunfilesPath()); - } - if (libraryToLink.getInterfaceLibrary() != null) { - libraryRunfilesPaths.add(libraryToLink.getInterfaceLibrary().getRunfilesPath()); - } - if (libraryToLink.getResolvedSymlinkInterfaceLibrary() != null) { - libraryRunfilesPaths.add( - libraryToLink.getResolvedSymlinkInterfaceLibrary().getRunfilesPath()); - } + if (libraryToLink.getStaticLibrary() != null) { + libraryRunfilesPaths.add(libraryToLink.getStaticLibrary().getRunfilesPath()); + } + if (libraryToLink.getPicStaticLibrary() != null) { + libraryRunfilesPaths.add(libraryToLink.getPicStaticLibrary().getRunfilesPath()); + } + if (libraryToLink.getDynamicLibrary() != null) { + libraryRunfilesPaths.add(libraryToLink.getDynamicLibrary().getRunfilesPath()); + } + if (libraryToLink.getResolvedSymlinkDynamicLibrary() != null) { + libraryRunfilesPaths.add(libraryToLink.getResolvedSymlinkDynamicLibrary().getRunfilesPath()); + } + if (libraryToLink.getInterfaceLibrary() != null) { + libraryRunfilesPaths.add(libraryToLink.getInterfaceLibrary().getRunfilesPath()); + } + if (libraryToLink.getResolvedSymlinkInterfaceLibrary() != null) { + libraryRunfilesPaths.add( + libraryToLink.getResolvedSymlinkInterfaceLibrary().getRunfilesPath()); } return !Collections.disjoint(libraryRunfilesPaths.build(), runfilesPaths); diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcVariablesExtension.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcVariablesExtension.java index 8373d5e55c0417..25745cfed1dc16 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcVariablesExtension.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcVariablesExtension.java @@ -16,6 +16,7 @@ import static com.google.common.collect.ImmutableList.toImmutableList; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.IMPORTED_LIBRARY; +import static com.google.devtools.build.lib.rules.objc.ObjcProvider.LINKOPT; import com.google.common.base.Preconditions; import com.google.common.base.Predicate; @@ -224,7 +225,7 @@ private void addExecutableLinkVariables(CcToolchainVariables.Builder builder) { builder.addStringSequenceVariable( FORCE_LOAD_EXEC_PATHS_VARIABLE_NAME, Artifact.toExecPaths(forceLoadArtifacts)); - builder.addStringSequenceVariable(DEP_LINKOPTS_VARIABLE_NAME, objcProvider.getLinkopt()); + builder.addStringSequenceVariable(DEP_LINKOPTS_VARIABLE_NAME, objcProvider.get(LINKOPT)); builder.addStringSequenceVariable(ATTR_LINKOPTS_VARIABLE_NAME, attributeLinkopts); } diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryTest.java index 7124f20d7f54e9..a629e637673bde 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryTest.java @@ -21,8 +21,10 @@ import static com.google.devtools.build.lib.rules.objc.CompilationSupport.ABSOLUTE_INCLUDES_PATH_FORMAT; import static com.google.devtools.build.lib.rules.objc.CompilationSupport.BOTH_MODULE_NAME_AND_MODULE_MAP_SPECIFIED; import static com.google.devtools.build.lib.rules.objc.CompilationSupport.FILE_IN_SRCS_AND_HDRS_WARNING_FORMAT; +import static com.google.devtools.build.lib.rules.objc.ObjcProvider.CC_LIBRARY; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.LIBRARY; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.SDK_DYLIB; +import static com.google.devtools.build.lib.rules.objc.ObjcProvider.SDK_FRAMEWORK; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.WEAK_SDK_FRAMEWORK; import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.NON_ARC_SRCS_TYPE; import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.SRCS_TYPE; @@ -917,7 +919,7 @@ public void checkDoesNotStoreObjcLibsAsCC() throws Exception { .setList("deps", "//objc:lib_dep") .write(); ObjcProvider objcProvider = providerForTarget("//objc2:lib"); - assertThat(objcProvider.getTransitiveCcLibraries().toList()).isEmpty(); + assertThat(objcProvider.get(CC_LIBRARY).toList()).isEmpty(); } @Test @@ -1405,7 +1407,7 @@ public void checkStoresCcLibsAsCc() throws Exception { Iterable linkerInputArtifacts = Iterables.transform( - objcProvider.getTransitiveCcLibraries().toList(), + objcProvider.get(CC_LIBRARY).toList(), (library) -> removeConfigFragment(library.getStaticLibrary().getExecPathString())); assertThat(linkerInputArtifacts) @@ -1436,8 +1438,8 @@ public void testCollectsSdkFrameworksTransitively() throws Exception { Set baseFrameworks = ImmutableSet.of(new SdkFramework("foo")); Set dependerFrameworks = ImmutableSet.of(new SdkFramework("foo"), new SdkFramework("bar")); - assertThat(baseProvider.getFrameworks().toList()).containsExactlyElementsIn(baseFrameworks); - assertThat(dependerProvider.getFrameworks().toList()) + assertThat(baseProvider.get(SDK_FRAMEWORK).toList()).containsExactlyElementsIn(baseFrameworks); + assertThat(dependerProvider.get(SDK_FRAMEWORK).toList()) .containsExactlyElementsIn(dependerFrameworks); // Make sure that the archive action does not actually include the frameworks. This is needed diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcStarlarkTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcStarlarkTest.java index c7459011c4dcd5..1884ea07c7a7ab 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcStarlarkTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcStarlarkTest.java @@ -333,7 +333,7 @@ public void testObjcRuleCanDependOnArbitraryStarlarkRuleThatProvidesObjc() throw ConfiguredTarget libTarget = getConfiguredTarget("//examples/apple_starlark:lib"); ObjcProvider libObjcProvider = libTarget.get(ObjcProvider.STARLARK_CONSTRUCTOR); - assertThat(libObjcProvider.getLinkopt().toList()).contains("mock_linkopt"); + assertThat(libObjcProvider.get(ObjcProvider.LINKOPT).toList()).contains("mock_linkopt"); } @Test @@ -909,7 +909,7 @@ public void testStarlarkCanCreateObjcProviderFromScratch() throws Exception { " return [created_provider]"); Iterable foundLinkopts = - starlarkTarget.get(ObjcProvider.STARLARK_CONSTRUCTOR).getLinkopt().toList(); + starlarkTarget.get(ObjcProvider.STARLARK_CONSTRUCTOR).get(ObjcProvider.LINKOPT).toList(); assertThat(foundLinkopts).containsExactly("somelinkopt"); } @@ -940,7 +940,7 @@ public void testStarlarkCanCreateObjcProviderWithLinkopts() throws Exception { " return [created_provider]"); Iterable foundLinkopts = - starlarkTarget.get(ObjcProvider.STARLARK_CONSTRUCTOR).getLinkopt().toList(); + starlarkTarget.get(ObjcProvider.STARLARK_CONSTRUCTOR).get(ObjcProvider.LINKOPT).toList(); assertThat(foundLinkopts).containsExactly("opt1", "opt2", "opt3"); } diff --git a/src/test/java/com/google/devtools/build/lib/starlark/StarlarkIntegrationTest.java b/src/test/java/com/google/devtools/build/lib/starlark/StarlarkIntegrationTest.java index 16c848c9e18a0b..de178ce59be863 100644 --- a/src/test/java/com/google/devtools/build/lib/starlark/StarlarkIntegrationTest.java +++ b/src/test/java/com/google/devtools/build/lib/starlark/StarlarkIntegrationTest.java @@ -3526,9 +3526,9 @@ public void testLegacyProvider_addCanonicalLegacyKeyAndModernKey() throws Except ObjcProvider providerFromFoo = (ObjcProvider) target.get("foo"); // The modern key and the canonical legacy key "objc" are set to the one available ObjcProvider. - assertThat(providerFromModernKey.getLinkopt().toList()).containsExactly("foo"); - assertThat(providerFromObjc.getLinkopt().toList()).containsExactly("foo"); - assertThat(providerFromFoo.getLinkopt().toList()).containsExactly("foo"); + assertThat(providerFromModernKey.get(ObjcProvider.LINKOPT).toList()).containsExactly("foo"); + assertThat(providerFromObjc.get(ObjcProvider.LINKOPT).toList()).containsExactly("foo"); + assertThat(providerFromFoo.get(ObjcProvider.LINKOPT).toList()).containsExactly("foo"); } @Test @@ -3555,9 +3555,9 @@ public void testLegacyProvider_dontAutomaticallyAddKeysAlreadyPresent() throws E ObjcProvider providerFromObjc = (ObjcProvider) target.get("objc"); ObjcProvider providerFromBah = (ObjcProvider) target.get("bah"); - assertThat(providerFromModernKey.getLinkopt().toList()).containsExactly("prov"); - assertThat(providerFromObjc.getLinkopt().toList()).containsExactly("objc"); - assertThat(providerFromBah.getLinkopt().toList()).containsExactly("bah"); + assertThat(providerFromModernKey.get(ObjcProvider.LINKOPT).toList()).containsExactly("prov"); + assertThat(providerFromObjc.get(ObjcProvider.LINKOPT).toList()).containsExactly("objc"); + assertThat(providerFromBah.get(ObjcProvider.LINKOPT).toList()).containsExactly("bah"); } @Test @@ -3585,11 +3585,11 @@ public void testLegacyProvider_firstNoncanonicalKeyBecomesCanonical() throws Exc ObjcProvider providerFromFoo = (ObjcProvider) target.get("foo"); ObjcProvider providerFromBar = (ObjcProvider) target.get("bar"); - assertThat(providerFromModernKey.getLinkopt().toList()).containsExactly("prov"); + assertThat(providerFromModernKey.get(ObjcProvider.LINKOPT).toList()).containsExactly("prov"); // The first defined provider is set to the legacy "objc" key. - assertThat(providerFromObjc.getLinkopt().toList()).containsExactly("foo"); - assertThat(providerFromFoo.getLinkopt().toList()).containsExactly("foo"); - assertThat(providerFromBar.getLinkopt().toList()).containsExactly("bar"); + assertThat(providerFromObjc.get(ObjcProvider.LINKOPT).toList()).containsExactly("foo"); + assertThat(providerFromFoo.get(ObjcProvider.LINKOPT).toList()).containsExactly("foo"); + assertThat(providerFromBar.get(ObjcProvider.LINKOPT).toList()).containsExactly("bar"); } @Test