Skip to content

Commit

Permalink
C++: Add non_code_inputs to create_linking_context
Browse files Browse the repository at this point in the history
    RELNOTES:none
    PiperOrigin-RevId: 241527045
  • Loading branch information
Luca Di Grazia committed Sep 4, 2022
1 parent bbada98 commit 9a2e7b3
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ public static <FragmentT> Object resolveLateBoundDefault(
Attribute attribute,
BuildConfiguration ruleConfig,
BuildConfiguration hostConfig) {
Preconditions.checkState(!attribute.getTransitionFactory().isSplit());
Preconditions.checkState(!attribute.hasSplitConfigurationTransition());
@SuppressWarnings("unchecked")
LateBoundDefault<FragmentT, ?> lateBoundDefault =
(LateBoundDefault<FragmentT, ?>) attribute.getLateBoundDefault();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ public Map<String, TransitiveInfoCollection> getPrerequisiteMap(String attribute
public List<ConfiguredTargetAndData> getPrerequisiteConfiguredTargetAndTargets(
String attributeName, Mode mode) {
Attribute attributeDefinition = attributes().getAttributeDefinition(attributeName);
if ((mode == Mode.TARGET) && (attributeDefinition.getTransitionFactory().isSplit())) {
if ((mode == Mode.TARGET) && (attributeDefinition.hasSplitConfigurationTransition())) {
// TODO(bazel-team): If you request a split-configured attribute in the target configuration,
// we return only the list of configured targets for the first architecture; this is for
// backwards compatibility with existing code in cases where the call to getPrerequisites is
Expand All @@ -837,7 +837,7 @@ public List<ConfiguredTargetAndData> getPrerequisiteConfiguredTargetAndTargets(
getSplitPrerequisiteConfiguredTargetAndTargets(String attributeName) {
checkAttribute(attributeName, Mode.SPLIT);
Attribute attributeDefinition = attributes().getAttributeDefinition(attributeName);
Preconditions.checkState(attributeDefinition.getTransitionFactory().isSplit());
Preconditions.checkState(attributeDefinition.hasSplitConfigurationTransition());
SplitTransition transition =
(SplitTransition)
attributeDefinition
Expand Down Expand Up @@ -1192,7 +1192,7 @@ private void checkAttribute(String attributeName, Mode mode) {
+ getRuleClassNameForLogging() + " attribute " + attributeName
+ ": DATA transition no longer supported"); // See b/80157700.
} else if (mode == Mode.SPLIT) {
if (!(attributeDefinition.getTransitionFactory().isSplit())) {
if (!(attributeDefinition.hasSplitConfigurationTransition())) {
throw new IllegalStateException(getRule().getLocation() + ": "
+ getRuleClassNameForLogging() + " attribute " + attributeName
+ " is not configured for a split transition");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
import com.google.devtools.build.lib.packages.StructProvider;
import com.google.devtools.build.lib.skylarkbuildapi.SplitTransitionProviderApi;
import com.google.devtools.build.lib.skylarkinterface.SkylarkPrinter;
import com.google.devtools.build.lib.syntax.Environment;
import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.lib.syntax.Starlark;
import com.google.devtools.build.lib.syntax.Runtime;
import com.google.devtools.build.lib.syntax.SkylarkType;
import java.util.LinkedHashMap;
import java.util.List;

Expand Down Expand Up @@ -92,7 +94,9 @@ class FunctionSplitTransition extends StarlarkTransition implements SplitTransit
LinkedHashMap<String, Object> attributes = new LinkedHashMap<>();
for (String attribute : attributeMap.getAttributeNames()) {
Object val = attributeMap.get(attribute, attributeMap.getAttributeType(attribute));
attributes.put(Attribute.getSkylarkName(attribute), Starlark.fromJava(val, null));
attributes.put(
Attribute.getSkylarkName(attribute),
val == null ? Runtime.NONE : SkylarkType.convertToSkylark(val, (Environment) null));
}
attrObject = StructProvider.STRUCT.create(attributes, ERROR_MESSAGE_FOR_NO_ATTR);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2149,6 +2149,14 @@ public TransitionFactory<AttributeTransitionData> getTransitionFactory() {
return transitionFactory;
}

/**
* Returns true if this attribute transitions on a split transition. See {@link SplitTransition}.
*/
// TODO(https://github.com/bazelbuild/bazel/issues/7814) Remove this.
public boolean hasSplitConfigurationTransition() {
return transitionFactory.isSplit();
}

/**
* Returns true if this attribute transitions to the host configuration. See {@link
* com.google.devtools.build.lib.analysis.config.HostTransition}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ static FlagGroup flagGroupFromSkylark(SkylarkInfo flagGroupStruct) throws EvalEx
ImmutableList<String> flags = getStringListFromSkylarkProviderField(flagGroupStruct, "flags");
for (String flag : flags) {
StringValueParser parser = new StringValueParser(flag);
expandableBuilder.add(Flag.create(parser.getChunks()));
expandableBuilder.add(new Flag(parser.getChunks()));
}

ImmutableList<SkylarkInfo> flagGroups =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.skylarkbuildapi.cpp.CcLinkingContextApi;
import com.google.devtools.build.lib.skylarkbuildapi.cpp.LibraryToLinkApi;
import com.google.devtools.build.lib.syntax.Environment;
import com.google.devtools.build.lib.syntax.SkylarkList;
import com.google.devtools.build.lib.syntax.SkylarkNestedSet;
import com.google.devtools.build.lib.util.Fingerprint;
Expand Down Expand Up @@ -62,7 +61,7 @@ public Artifact getDynamicLibraryForRuntimeOrNull(boolean linkingStatically) {
}

/** Structure of CcLinkingContext. */
public static class CcLinkingContext implements CcLinkingContextApi<Artifact> {
public static class CcLinkingContext implements CcLinkingContextApi {
public static final CcLinkingContext EMPTY = builder().build();

/** A list of link options contributed by a single configured target/aspect. */
Expand Down Expand Up @@ -290,12 +289,8 @@ public SkylarkList<String> getSkylarkUserLinkFlags() {
}

@Override
public Object getSkylarkLibrariesToLink(Environment environment) {
if (environment.getSemantics().incompatibleDepsetForLibrariesToLinkGetter()) {
return SkylarkNestedSet.of(LibraryToLink.class, libraries);
} else {
return SkylarkList.createImmutable(libraries.toList());
}
public SkylarkList<LibraryToLinkApi> getSkylarkLibrariesToLink() {
return SkylarkList.createImmutable(libraries.toList());
}

@Override
Expand Down Expand Up @@ -448,15 +443,13 @@ public String toString() {
public abstract Artifact getDynamicLibrary();

@Nullable
@Override
public abstract Artifact getResolvedSymlinkDynamicLibrary();

@Nullable
@Override
public abstract Artifact getInterfaceLibrary();

@Nullable
@Override
public abstract Artifact getResolvedSymlinkInterfaceLibrary();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@

package com.google.devtools.build.lib.skylarkbuildapi.cpp;

import com.google.devtools.build.lib.events.Location;
import com.google.devtools.build.lib.skylarkbuildapi.FileApi;
import com.google.devtools.build.lib.skylarkbuildapi.SkylarkActionFactoryApi;
import com.google.devtools.build.lib.skylarkbuildapi.SkylarkRuleContextApi;
import com.google.devtools.build.lib.skylarkinterface.Param;
import com.google.devtools.build.lib.skylarkinterface.ParamType;
import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.skylarkinterface.StarlarkContext;
import com.google.devtools.build.lib.syntax.Environment;
import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.lib.syntax.Runtime.NoneType;
import com.google.devtools.build.lib.syntax.SkylarkList;
import com.google.devtools.build.lib.syntax.SkylarkList.Tuple;
import com.google.devtools.build.lib.syntax.SkylarkNestedSet;

/** Utilites related to C++ support. */
@SkylarkModule(
Expand All @@ -40,12 +40,11 @@ public interface BazelCcModuleApi<
CompilationContextT extends CcCompilationContextApi,
CompilationOutputsT extends CcCompilationOutputsApi<FileT>,
LinkingOutputsT extends CcLinkingOutputsApi<FileT>,
LibraryToLinkT extends LibraryToLinkApi<FileT>,
LinkingContextT extends CcLinkingContextApi<FileT, LibraryToLinkT>,
LinkingContextT extends CcLinkingContextApi,
LibraryToLinkT extends LibraryToLinkApi,
CcToolchainVariablesT extends CcToolchainVariablesApi,
CcToolchainConfigInfoT extends CcToolchainConfigInfoApi>
extends CcModuleApi<
SkylarkActionFactoryT,
FileT,
CcToolchainProviderT,
FeatureConfigurationT,
Expand All @@ -54,14 +53,11 @@ public interface BazelCcModuleApi<
LibraryToLinkT,
CcToolchainVariablesT,
SkylarkRuleContextT,
CcToolchainConfigInfoT,
CompilationOutputsT> {
CcToolchainConfigInfoT> {

@SkylarkCallable(
name = "compile",
doc = "Should be used for C++ compilation.",
useEnvironment = true,
useLocation = true,
documented = false,
parameters = {
@Param(
name = "actions",
Expand Down Expand Up @@ -140,13 +136,6 @@ public interface BazelCcModuleApi<
noneable = true,
defaultValue = "[]",
type = SkylarkList.class),
@Param(
name = "defines",
doc = "Set of defines needed to compile this target. Each define is a string.",
positional = false,
named = true,
defaultValue = "[]",
type = SkylarkList.class),
@Param(
name = "user_compile_flags",
doc = "Additional list of compilation options.",
Expand Down Expand Up @@ -195,22 +184,16 @@ Tuple<Object> compile(
SkylarkList<String> includes,
SkylarkList<String> quoteIncludes,
SkylarkList<String> systemIncludes,
SkylarkList<String> defines,
SkylarkList<String> userCompileFlags,
SkylarkList<CompilationContextT> ccCompilationContexts,
String name,
boolean disallowPicOutputs,
boolean disallowNopicOutputs,
Location location,
Environment environment)
boolean disallowNopicOutputs)
throws EvalException, InterruptedException;

@SkylarkCallable(
name = "link",
doc = "Should be used for C++ transitive linking.",
useEnvironment = true,
useLocation = true,
useContext = true,
documented = false,
parameters = {
@Param(
name = "actions",
Expand All @@ -237,7 +220,11 @@ Tuple<Object> compile(
named = true,
defaultValue = "None",
noneable = true,
type = CcCompilationOutputsApi.class),
allowedTypes = {
@ParamType(type = NoneType.class),
@ParamType(type = SkylarkList.class),
@ParamType(type = SkylarkNestedSet.class)
}),
@Param(
name = "user_link_flags",
doc = "Additional list of linker options.",
Expand All @@ -249,8 +236,8 @@ Tuple<Object> compile(
@Param(
name = "linking_contexts",
doc =
"Linking contexts from dependencies to be linked into the linking context "
+ "generated by this rule.",
"Libraries from dependencies. These libraries will be linked into the output "
+ "artifact of the link() call, be it a binary or a library.",
positional = false,
named = true,
noneable = true,
Expand All @@ -266,15 +253,15 @@ Tuple<Object> compile(
type = String.class),
@Param(
name = "language",
doc = "Can be one of c++, objc or objc++.",
doc = "Can be one of C++, objc or objc++.",
positional = false,
named = true,
noneable = true,
defaultValue = "'c++'",
defaultValue = "'C++'",
type = String.class),
@Param(
name = "output_type",
doc = "Can be either 'executable' or 'dynamic_library'.",
doc = "Can be either 'executable' or 'shared_library'.",
positional = false,
named = true,
noneable = true,
Expand All @@ -289,7 +276,7 @@ Tuple<Object> compile(
defaultValue = "True",
type = Boolean.class),
@Param(
name = "additional_inputs",
name = "non_code_inputs",
doc = "For additional inputs to the linking action, e.g.: linking scripts.",
positional = false,
named = true,
Expand All @@ -300,28 +287,19 @@ LinkingOutputsT link(
SkylarkActionFactoryT skylarkActionFactoryApi,
FeatureConfigurationT skylarkFeatureConfiguration,
CcToolchainProviderT skylarkCcToolchainProvider,
CompilationOutputsT compilationOutputs,
Object compilationOutputs,
SkylarkList<String> userLinkFlags,
SkylarkList<LinkingContextT> linkingContexts,
String name,
String language,
String outputType,
boolean linkDepsStatically,
SkylarkList<FileT> additionalInputs,
Location location,
Environment environment,
StarlarkContext starlarkContext)
SkylarkList<FileT> nonCodeInputs)
throws InterruptedException, EvalException;

@SkylarkCallable(
name = "create_linking_context_from_compilation_outputs",
doc =
"Should be used for creating library rules that can propagate information downstream in"
+ " order to be linked later by a top level rule that does transitive linking to"
+ " create an executable or dynamic library.",
useLocation = true,
useEnvironment = true,
useContext = true,
documented = false,
parameters = {
@Param(
name = "actions",
Expand Down Expand Up @@ -355,16 +333,6 @@ LinkingOutputsT link(
defaultValue = "[]",
noneable = true,
type = SkylarkList.class),
@Param(
name = "linking_contexts",
doc =
"Libraries from dependencies. These libraries will be linked into the output "
+ "artifact of the link() call, be it a binary or a library.",
positional = false,
named = true,
noneable = true,
defaultValue = "[]",
type = SkylarkList.class),
@Param(
name = "name",
doc =
Expand All @@ -375,11 +343,11 @@ LinkingOutputsT link(
type = String.class),
@Param(
name = "language",
doc = "Can be one of c++, objc or objc++.",
doc = "Can be one of C++, objc or objc++.",
positional = false,
named = true,
noneable = true,
defaultValue = "'c++'",
defaultValue = "'C++'",
type = String.class),
@Param(
name = "alwayslink",
Expand All @@ -390,7 +358,7 @@ LinkingOutputsT link(
defaultValue = "False",
type = Boolean.class),
@Param(
name = "additional_inputs",
name = "non_code_inputs",
doc = "For additional inputs to the linking action, e.g.: linking scripts.",
positional = false,
named = true,
Expand All @@ -404,28 +372,24 @@ LinkingOutputsT link(
defaultValue = "False",
type = Boolean.class),
@Param(
name = "disallow_dynamic_library",
doc = "Whether a dynamic library should be created.",
name = "disallow_dynamic_libraries",
doc = "Whether dynamic libraries should be created.",
positional = false,
named = true,
defaultValue = "False",
type = Boolean.class)
})
Tuple<Object> createLinkingContextFromCompilationOutputs(
LinkingContextT createLinkingContextFromCompilationOutputs(
SkylarkActionFactoryT skylarkActionFactoryApi,
FeatureConfigurationT skylarkFeatureConfiguration,
CcToolchainProviderT skylarkCcToolchainProvider,
CompilationOutputsT compilationOutputs,
SkylarkList<String> userLinkFlags,
SkylarkList<LinkingContextT> linkingContexts,
String name,
String language,
boolean alwayslink,
SkylarkList<FileT> additionalInputs,
SkylarkList<FileT> nonCodeInputs,
boolean disallowStaticLibraries,
boolean disallowDynamicLibraries,
Location location,
Environment environment,
StarlarkContext bazelStarlarkContext)
boolean disallowDynamicLibraries)
throws InterruptedException, EvalException;
}
Loading

0 comments on commit 9a2e7b3

Please sign in to comment.