Skip to content

Commit

Permalink
Automated rollback of commit 1d738de.
Browse files Browse the repository at this point in the history
*** 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
  • Loading branch information
meisterT authored and copybara-github committed Jun 25, 2021
1 parent 6d603b7 commit 7b548ed
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 181 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1448,7 +1449,7 @@ CompilationSupport registerFullyLinkAction(ObjcProvider objcProvider, Artifact o
*/
private Set<String> frameworkNames(ObjcProvider provider) {
Set<String> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@

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 @@ -33,20 +36,24 @@
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 @@ -333,12 +340,32 @@ ObjcCommon build() {
}

for (CcLinkingContext linkProvider : ccLinkingContexts) {
objcProvider.addAll(ObjcProvider.CC_LINKER_INPUTS, linkProvider.getLinkerInputs());
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());
}

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

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.getTransitiveCcLibraries().toList();
List<LibraryToLink> ccLibraries = objcProvider.get(ObjcProvider.CC_LIBRARY).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.getFrameworks().toList();
List<SdkFramework> sdkFrameworks = objcProvider.get(ObjcProvider.SDK_FRAMEWORK).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.getLinkstamps().toList());
objcProvider.get(ObjcProvider.LINKSTAMP).toList());

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

0 comments on commit 7b548ed

Please sign in to comment.