Skip to content

Commit

Permalink
Create new key for ObjcProvider
Browse files Browse the repository at this point in the history
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: 381031117
  • Loading branch information
oquenchil authored and copybara-github committed Jun 23, 2021
1 parent 2ace97f commit 1d738de
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
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;
Expand Down Expand Up @@ -1449,7 +1448,7 @@ CompilationSupport registerFullyLinkAction(ObjcProvider objcProvider, Artifact o
*/
private Set<String> frameworkNames(ObjcProvider provider) {
Set<String> names = new LinkedHashSet<>();
names.addAll(SdkFramework.names(provider.get(SDK_FRAMEWORK)));
names.addAll(SdkFramework.names(provider.getFrameworks()));
names.addAll(provider.staticFrameworkNames().toList());
names.addAll(provider.dynamicFrameworkNames().toList());
return names;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@

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;
import static com.google.devtools.build.lib.rules.objc.ObjcProvider.HEADER;
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;
Expand All @@ -36,24 +33,20 @@
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;
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.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;
Expand Down Expand Up @@ -340,32 +333,12 @@ ObjcCommon build() {
}

for (CcLinkingContext linkProvider : ccLinkingContexts) {
ImmutableList<String> linkOpts = linkProvider.getFlattenedUserLinkFlags();
ImmutableSet.Builder<SdkFramework> frameworkLinkOpts = new ImmutableSet.Builder<>();
ImmutableList.Builder<String> nonFrameworkLinkOpts = new ImmutableList.Builder<>();
// Add any framework flags as frameworks directly, rather than as linkopts.
for (UnmodifiableIterator<String> 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.<LibraryToLink>linkOrder()
.addTransitive(linkProvider.getLibraries())
.build());
objcProvider.addAll(ObjcProvider.CC_LINKER_INPUTS, linkProvider.getLinkerInputs());
}

for (CcLinkingContext ccLinkStampContext : ccLinkStampContexts) {
objcProvider.addAll(LINKSTAMP, ccLinkStampContext.getLinkstamps());
objcProvider.addAll(
ObjcProvider.LINKSTAMP_LINKER_INPUTS, ccLinkStampContext.getLinkerInputs());
}

if (compilationAttributes.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public ConfiguredTarget create(RuleContext ruleContext)
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();
List<LibraryToLink> ccLibraries = objcProvider.getTransitiveCcLibraries().toList();

Set<LibraryToLink> librariesToLink =
CompactHashSet.createWithExpectedSize(libraries.size() + ccLibraries.size());
Expand All @@ -131,7 +131,7 @@ private static CcLinkingContext buildCcLinkingContext(
librariesToLink.add(convertToStaticLibrary(library));
}

List<SdkFramework> sdkFrameworks = objcProvider.get(ObjcProvider.SDK_FRAMEWORK).toList();
List<SdkFramework> sdkFrameworks = objcProvider.getFrameworks().toList();
ImmutableList.Builder<LinkOptions> userLinkFlags =
ImmutableList.builderWithExpectedSize(sdkFrameworks.size());
for (SdkFramework sdkFramework : sdkFrameworks) {
Expand All @@ -145,7 +145,7 @@ private static CcLinkingContext buildCcLinkingContext(
ImmutableList.copyOf(librariesToLink),
userLinkFlags.build(),
/*nonCodeInputs=*/ ImmutableList.of(),
objcProvider.get(ObjcProvider.LINKSTAMP).toList());
objcProvider.getLinkstamps().toList());

return new CcLinkingContext(
NestedSetBuilder.create(Order.LINK_ORDER, linkerInput), /*extraLinkTimeLibraries=*/ null);
Expand Down
Loading

0 comments on commit 1d738de

Please sign in to comment.