Skip to content

Commit

Permalink
C++: Wrap CcLinkParamsInfo with CcLinkingInfo.
Browse files Browse the repository at this point in the history
CcLinkingInfo will eventually wrap all C++ linking providers. CcLinkParamsInfo is no longer a provider and will be renamed in a later CL.

RELNOTES:none
PiperOrigin-RevId: 193011702
  • Loading branch information
oquenchil authored and Copybara-Service committed Apr 16, 2018
1 parent 0c17f0c commit fa135cf
Show file tree
Hide file tree
Showing 17 changed files with 221 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import com.google.devtools.build.lib.packages.RuleClass.PackageNameConstraint;
import com.google.devtools.build.lib.packages.SkylarkProviderIdentifier;
import com.google.devtools.build.lib.packages.TriState;
import com.google.devtools.build.lib.rules.cpp.CcLinkParamsInfo;
import com.google.devtools.build.lib.rules.cpp.CcLinkingInfo;
import com.google.devtools.build.lib.rules.java.JavaInfo;
import com.google.devtools.build.lib.rules.java.JavaRuleClasses.IjarBaseRule;
import com.google.devtools.build.lib.rules.java.JavaRuntimeInfo;
Expand Down Expand Up @@ -77,8 +77,7 @@ public class BazelJavaRuleClasses {
JavaSemantics.JAVA_LIBRARY_SOURCE_JAR);

public static final ImmutableList<SkylarkProviderIdentifier> CONTAINS_CC_LINK_PARAMS =
ImmutableList.of(
SkylarkProviderIdentifier.forKey(CcLinkParamsInfo.PROVIDER.getKey()));
ImmutableList.of(SkylarkProviderIdentifier.forKey(CcLinkingInfo.PROVIDER.getKey()));

/**
* Meant to be the value of {@code mandatoryProvidersLists} in order for the rule to provide only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import com.google.devtools.build.lib.rules.cpp.CcLinkParams;
import com.google.devtools.build.lib.rules.cpp.CcLinkParamsInfo;
import com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore;
import com.google.devtools.build.lib.rules.cpp.CcLinkingInfo;
import com.google.devtools.build.lib.rules.java.DeployArchiveBuilder;
import com.google.devtools.build.lib.rules.java.DeployArchiveBuilder.Compression;
import com.google.devtools.build.lib.rules.java.JavaCcLinkParamsProvider;
Expand Down Expand Up @@ -577,7 +578,8 @@ public void addProviders(
RuleConfiguredTargetBuilder ruleBuilder) {
if (!isJavaBinaryOrJavaTest(ruleContext)) {
// TODO(plf): Figure out whether we can remove support for C++ dependencies in Bazel.
ruleBuilder.addNativeDeclaredProvider(
CcLinkingInfo.Builder ccLinkingInfoBuilder = CcLinkingInfo.Builder.create();
ccLinkingInfoBuilder.setCcLinkParamsInfo(
new CcLinkParamsInfo(
new CcLinkParamsStore() {
@Override
Expand All @@ -589,6 +591,7 @@ protected void collect(
CcLinkParamsInfo.TO_LINK_PARAMS);
}
}));
ruleBuilder.addNativeDeclaredProvider(ccLinkingInfoBuilder.build());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,10 @@ public Builder addTransitiveTargets(Iterable<? extends TransitiveInfoCollection>
* the method does not do anything.
*/
public Builder addTransitiveTarget(TransitiveInfoCollection target) {
return addTransitiveProvider(target.get(CcLinkParamsInfo.PROVIDER));
CcLinkingInfo ccLinkingInfo = target.get(CcLinkingInfo.PROVIDER);
CcLinkParamsInfo ccLinkParamsInfo =
ccLinkingInfo == null ? null : ccLinkingInfo.getCcLinkParamsInfo();
return addTransitiveProvider(ccLinkParamsInfo);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,23 @@
import com.google.common.base.Function;
import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.packages.NativeInfo;
import com.google.devtools.build.lib.packages.NativeProvider;
import com.google.devtools.build.lib.rules.cpp.CcLinkParams.Builder;
import com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore.CcLinkParamsStoreImpl;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;

/** A target that provides C linker parameters. */
@Immutable
@AutoCodec
@SkylarkModule(
name = "cc_link_params_info",
title = "cc_link_params_info",
documented = false,
category = SkylarkModuleCategory.PROVIDER,
doc = "Link params provider"
)
public final class CcLinkParamsInfo extends NativeInfo {
public static final NativeProvider<CcLinkParamsInfo> PROVIDER =
new NativeProvider<CcLinkParamsInfo>(CcLinkParamsInfo.class, "link_params") {};
public final class CcLinkParamsInfo {
public static final Function<TransitiveInfoCollection, CcLinkParamsStore> TO_LINK_PARAMS =
input -> {
// ... then try Skylark.
CcLinkParamsInfo provider = input.get(PROVIDER);
if (provider != null) {
return provider.getCcLinkParamsStore();
CcLinkingInfo provider = input.get(CcLinkingInfo.PROVIDER);
CcLinkParamsInfo ccLinkParamsInfo =
provider == null ? null : provider.getCcLinkParamsInfo();
if (ccLinkParamsInfo != null) {
return ccLinkParamsInfo.getCcLinkParamsStore();
}
return null;
};
Expand All @@ -53,7 +42,6 @@ public final class CcLinkParamsInfo extends NativeInfo {

@AutoCodec.Instantiator
public CcLinkParamsInfo(CcLinkParamsStore store) {
super(PROVIDER);
this.store = new CcLinkParamsStoreImpl(store);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ public TransitiveInfoProviderMap getProviders() {
return providers;
}

@SkylarkCallable(name = "cc_link_params_info", documented = false)
public CcLinkParamsInfo getCcLinkParamsInfo() {
return (CcLinkParamsInfo) providers.getProvider(CcLinkParamsInfo.PROVIDER.getKey());
@SkylarkCallable(name = "cc_linking_info", documented = false)
public CcLinkingInfo getCcLinkParamsInfo() {
return (CcLinkingInfo) providers.getProvider(CcLinkingInfo.PROVIDER.getKey());
}

public Map<String, NestedSet<Artifact>> getOutputGroups() {
Expand Down Expand Up @@ -551,9 +551,11 @@ public LinkingInfo link(
new CcSpecificLinkParamsProvider(
createCcLinkParamsStore(ccLinkingOutputs, ccCompilationContextInfo, forcePic)));
} else {
providers.put(
CcLinkingInfo.Builder ccLinkingInfoBuilder = CcLinkingInfo.Builder.create();
ccLinkingInfoBuilder.setCcLinkParamsInfo(
new CcLinkParamsInfo(
createCcLinkParamsStore(ccLinkingOutputs, ccCompilationContextInfo, forcePic)));
providers.put(ccLinkingInfoBuilder.build());
}
return new LinkingInfo(
providers.build(), outputGroups, ccLinkingOutputs, originalLinkingOutputs);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// 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.cpp;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.analysis.AnalysisUtils;
import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.packages.NativeInfo;
import com.google.devtools.build.lib.packages.NativeProvider;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;

/** Wrapper for every C++ linking provider. */
@Immutable
@AutoCodec
@SkylarkModule(
name = "cc_linking_info",
documented = false,
category = SkylarkModuleCategory.PROVIDER,
doc = "Wrapper for every C++ linking provider"
)
public final class CcLinkingInfo extends NativeInfo {
public static final NativeProvider<CcLinkingInfo> PROVIDER =
new NativeProvider<CcLinkingInfo>(CcLinkingInfo.class, "CcLinkingInfo") {};

private final CcLinkParamsInfo ccLinkParamsInfo;

@AutoCodec.Instantiator
@VisibleForSerialization
CcLinkingInfo(CcLinkParamsInfo ccLinkParamsInfo) {
super(PROVIDER);
this.ccLinkParamsInfo = ccLinkParamsInfo;
}

public CcLinkParamsInfo getCcLinkParamsInfo() {
return ccLinkParamsInfo;
}

/** A Builder for {@link CcLinkingInfo}. */
public static class Builder {
CcLinkParamsInfo ccLinkParamsInfo;

public static CcLinkingInfo.Builder create() {
return new CcLinkingInfo.Builder();
}

public Builder setCcLinkParamsInfo(CcLinkParamsInfo ccLinkParamsInfo) {
Preconditions.checkState(this.ccLinkParamsInfo == null);
this.ccLinkParamsInfo = ccLinkParamsInfo;
return this;
}

public CcLinkingInfo build() {
return new CcLinkingInfo(ccLinkParamsInfo);
}
}

public static ImmutableList<CcLinkParamsInfo> getCcLinkParamsInfos(
Iterable<? extends TransitiveInfoCollection> deps) {
ImmutableList.Builder<CcLinkParamsInfo> ccLinkParamsInfosBuilder = ImmutableList.builder();
for (CcLinkingInfo ccLinkingInfo : AnalysisUtils.getProviders(deps, CcLinkingInfo.PROVIDER)) {
CcLinkParamsInfo ccLinkParamsInfo = ccLinkingInfo.getCcLinkParamsInfo();
if (ccLinkParamsInfo != null) {
ccLinkParamsInfosBuilder.add(ccLinkParamsInfo);
}
}
return ccLinkParamsInfosBuilder.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ public NestedSet<Artifact> getTransitiveHeaders() {
+ "(possibly empty but never <code>None</code>)")
public NestedSet<Artifact> getLibraries() {
NestedSetBuilder<Artifact> libs = NestedSetBuilder.linkOrder();
CcLinkParamsInfo ccLinkParams = getInfo().get(CcLinkParamsInfo.PROVIDER);
CcLinkingInfo ccLinkingInfo = getInfo().get(CcLinkingInfo.PROVIDER);
CcLinkParamsInfo ccLinkParams =
ccLinkingInfo == null ? null : ccLinkingInfo.getCcLinkParamsInfo();
if (ccLinkParams == null) {
return libs.build();
}
Expand All @@ -84,7 +86,9 @@ public NestedSet<Artifact> getLibraries() {
+ "<code>MOSTLY STATIC</code> mode (<code>linkstatic=1</code>) "
+ "(possibly empty but never <code>None</code>)")
public ImmutableList<String> getLinkopts() {
CcLinkParamsInfo ccLinkParams = getInfo().get(CcLinkParamsInfo.PROVIDER);
CcLinkingInfo ccLinkingInfo = getInfo().get(CcLinkingInfo.PROVIDER);
CcLinkParamsInfo ccLinkParams =
ccLinkingInfo == null ? null : ccLinkingInfo.getCcLinkParamsInfo();
if (ccLinkParams == null) {
return ImmutableList.of();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.google.devtools.build.lib.rules.cpp.CcLinkParams;
import com.google.devtools.build.lib.rules.cpp.CcLinkParamsInfo;
import com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore;
import com.google.devtools.build.lib.rules.cpp.CcLinkingInfo;
import com.google.devtools.build.lib.rules.cpp.LinkerInput;
import com.google.devtools.build.lib.rules.java.JavaCompilationArgs.ClasspathType;
import java.util.LinkedHashSet;
Expand Down Expand Up @@ -161,13 +162,17 @@ protected void collect(CcLinkParams.Builder builder, boolean linkingStatically,
.setRuntimeJars(javaArtifacts.getRuntimeJars())
.setNeverlink(neverLink)
.build();

CcLinkingInfo.Builder ccLinkingInfoBuilder = CcLinkingInfo.Builder.create();
ccLinkingInfoBuilder.setCcLinkParamsInfo(new CcLinkParamsInfo(ccLinkParamsStore));

return ruleBuilder
.setFilesToBuild(filesToBuild)
.addSkylarkTransitiveInfo(
JavaSkylarkApiProvider.NAME, JavaSkylarkApiProvider.fromRuleContext())
.addNativeDeclaredProvider(javaInfo)
.add(RunfilesProvider.class, RunfilesProvider.simple(runfiles))
.addNativeDeclaredProvider(new CcLinkParamsInfo(ccLinkParamsStore))
.addNativeDeclaredProvider(ccLinkingInfoBuilder.build())
.add(
JavaNativeLibraryProvider.class,
new JavaNativeLibraryProvider(transitiveJavaNativeLibraries))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.rules.apple.AppleConfiguration;
import com.google.devtools.build.lib.rules.apple.ApplePlatform.PlatformType;
import com.google.devtools.build.lib.rules.cpp.CcLinkParamsInfo;
import com.google.devtools.build.lib.rules.cpp.CcLinkingInfo;
import com.google.devtools.build.lib.rules.cpp.CcToolchainProvider;
import com.google.devtools.build.lib.rules.cpp.CppHelper;
import com.google.devtools.build.lib.rules.objc.ObjcProvider.Key;
Expand Down Expand Up @@ -82,9 +82,9 @@ public final ConfiguredTarget create(RuleContext ruleContext)
ImmutableListMultimap<BuildConfiguration, ObjcProvider> configToObjcAvoidDepsMap =
ruleContext.getPrerequisitesByConfiguration(AppleStaticLibraryRule.AVOID_DEPS_ATTR_NAME,
Mode.SPLIT, ObjcProvider.SKYLARK_CONSTRUCTOR);
ImmutableListMultimap<BuildConfiguration, CcLinkParamsInfo> configToCcAvoidDepsMap =
ruleContext.getPrerequisitesByConfiguration(AppleStaticLibraryRule.AVOID_DEPS_ATTR_NAME,
Mode.SPLIT, CcLinkParamsInfo.PROVIDER);
ImmutableListMultimap<BuildConfiguration, CcLinkingInfo> configToCcAvoidDepsMap =
ruleContext.getPrerequisitesByConfiguration(
AppleStaticLibraryRule.AVOID_DEPS_ATTR_NAME, Mode.SPLIT, CcLinkingInfo.PROVIDER);
Iterable<ObjcProtoProvider> avoidProtoProviders =
ruleContext.getPrerequisites(AppleStaticLibraryRule.AVOID_DEPS_ATTR_NAME, Mode.TARGET,
ObjcProtoProvider.SKYLARK_CONSTRUCTOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import com.google.devtools.build.lib.packages.NativeProvider;
import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException;
import com.google.devtools.build.lib.rules.apple.ApplePlatform;
import com.google.devtools.build.lib.rules.cpp.CcLinkParamsInfo;
import com.google.devtools.build.lib.rules.cpp.CcLinkingInfo;
import com.google.devtools.build.lib.rules.cpp.CcToolchainProvider;
import com.google.devtools.build.lib.rules.objc.CompilationSupport.ExtraLinkArgs;
import com.google.devtools.build.lib.rules.proto.ProtoSourcesProvider;
Expand Down Expand Up @@ -262,8 +262,9 @@ public ImmutableSet<DependencySpecificConfiguration> getDependencySpecificConfig
nullToEmptyList(configurationToNonPropagatedObjcMap.get(childConfig)),
additionalDepProviders);
ObjcProvider objcProviderWithDylibSymbols = common.getObjcProvider();
ObjcProvider objcProvider = objcProviderWithDylibSymbols.subtractSubtrees(dylibObjcProviders,
ImmutableList.<CcLinkParamsInfo>of());
ObjcProvider objcProvider =
objcProviderWithDylibSymbols.subtractSubtrees(
dylibObjcProviders, ImmutableList.<CcLinkingInfo>of());

childInfoBuilder.add(
DependencySpecificConfiguration.create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import com.google.devtools.build.lib.rules.cpp.CcCompilationInfo;
import com.google.devtools.build.lib.rules.cpp.CcLinkParams;
import com.google.devtools.build.lib.rules.cpp.CcLinkParamsInfo;
import com.google.devtools.build.lib.rules.cpp.CcLinkingInfo;
import com.google.devtools.build.lib.rules.cpp.CppFileTypes;
import com.google.devtools.build.lib.rules.cpp.CppModuleMap;
import com.google.devtools.build.lib.skyframe.ConfiguredTargetAndData;
Expand Down Expand Up @@ -267,7 +268,7 @@ Builder addDeps(List<ConfiguredTargetAndData> deps) {
addAnyProviders(propagatedObjcDeps, depCT, ObjcProvider.SKYLARK_CONSTRUCTOR);
addAnyProviders(cppDeps, depCT, CcCompilationInfo.PROVIDER);
if (isCcLibrary(dep)) {
cppDepLinkParams.add(depCT.get(CcLinkParamsInfo.PROVIDER));
cppDepLinkParams.add(depCT.get(CcLinkingInfo.PROVIDER).getCcLinkParamsInfo());
CcCompilationContextInfo ccCompilationContextInfo =
depCT.get(CcCompilationInfo.PROVIDER).getCcCompilationContextInfo();
addDefines(ccCompilationContextInfo.getDefines());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.devtools.build.lib.rules.cpp.CcCompilationContextInfo;
import com.google.devtools.build.lib.rules.cpp.CcCompilationInfo;
import com.google.devtools.build.lib.rules.cpp.CcLinkParamsInfo;
import com.google.devtools.build.lib.rules.cpp.CcLinkingInfo;
import com.google.devtools.build.lib.rules.objc.ObjcCommon.ResourceAttributes;
import com.google.devtools.build.lib.syntax.Type;
import java.util.Map;
Expand Down Expand Up @@ -105,6 +106,10 @@ public ConfiguredTarget create(RuleContext ruleContext)
CcCompilationInfo.Builder ccCompilationInfoBuilder = CcCompilationInfo.Builder.create();
ccCompilationInfoBuilder.setCcCompilationContextInfo(ccCompilationContextInfo);

CcLinkingInfo.Builder ccLinkingInfoBuilder = CcLinkingInfo.Builder.create();
ccLinkingInfoBuilder.setCcLinkParamsInfo(
new CcLinkParamsInfo(new ObjcLibraryCcLinkParamsStore(common)));

return ObjcRuleClasses.ruleConfiguredTarget(ruleContext, filesToBuild.build())
.addNativeDeclaredProvider(common.getObjcProvider())
.addNativeDeclaredProvider(ccCompilationInfoBuilder.build())
Expand All @@ -113,7 +118,7 @@ public ConfiguredTarget create(RuleContext ruleContext)
.addProvider(
InstrumentedFilesProvider.class,
compilationSupport.getInstrumentedFilesProvider(objectFilesCollector.build()))
.addNativeDeclaredProvider(new CcLinkParamsInfo(new ObjcLibraryCcLinkParamsStore(common)))
.addNativeDeclaredProvider(ccLinkingInfoBuilder.build())
.addOutputGroups(outputGroupCollector)
.build();
}
Expand Down
Loading

0 comments on commit fa135cf

Please sign in to comment.