From d428e2c9529fc4c62e7110d390b0886d62b10b63 Mon Sep 17 00:00:00 2001 From: Danna Kelmer Date: Mon, 6 May 2019 11:20:07 -0400 Subject: [PATCH] Add implementation to removed methods to address https://github.com/bazelbuild/bazel/issues/8226 --- .../java/com/google/devtools/build/lib/BUILD | 1 + .../lib/bazel/rules/cpp/BazelCcModule.java | 269 ++++++++-- .../skylarkbuildapi/cpp/BazelCcModuleApi.java | 493 ++++++------------ .../lib/skylarkbuildapi/cpp/CcBootstrap.java | 36 +- .../skydoc/fakebuildapi/cpp/FakeCcModule.java | 35 +- 5 files changed, 408 insertions(+), 426 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/BUILD b/src/main/java/com/google/devtools/build/lib/BUILD index 119de1bc687e0e..c9114debef9296 100644 --- a/src/main/java/com/google/devtools/build/lib/BUILD +++ b/src/main/java/com/google/devtools/build/lib/BUILD @@ -748,6 +748,7 @@ java_library( ":python-rules", ":testing-support-rules", ":util", + "//src/main/java/com/google/devtools/build/lib:skylarkinterface", "//src/main/java/com/google/devtools/build/lib/actions", "//src/main/java/com/google/devtools/build/lib/buildeventstream", "//src/main/java/com/google/devtools/build/lib/buildeventstream/proto:build_event_stream_java_proto", diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcModule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcModule.java index 520106596bbfee..9d8b779750291a 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcModule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcModule.java @@ -14,23 +14,54 @@ package com.google.devtools.build.lib.bazel.rules.cpp; +import com.google.common.base.Joiner; +import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.actions.Artifact; +import com.google.devtools.build.lib.analysis.RuleContext; +import com.google.devtools.build.lib.analysis.actions.ActionConstructionContext; +import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget.Mode; +import com.google.devtools.build.lib.analysis.skylark.BazelStarlarkContext; import com.google.devtools.build.lib.analysis.skylark.SkylarkActionFactory; import com.google.devtools.build.lib.analysis.skylark.SkylarkRuleContext; +import com.google.devtools.build.lib.cmdline.Label; +import com.google.devtools.build.lib.cmdline.LabelSyntaxException; +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.events.Location; +import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException; +import com.google.devtools.build.lib.rules.cpp.CcCommon; import com.google.devtools.build.lib.rules.cpp.CcCompilationContext; +import com.google.devtools.build.lib.rules.cpp.CcCompilationHelper; +import com.google.devtools.build.lib.rules.cpp.CcCompilationHelper.CompilationInfo; import com.google.devtools.build.lib.rules.cpp.CcCompilationOutputs; +import com.google.devtools.build.lib.rules.cpp.CcLinkingHelper; +import com.google.devtools.build.lib.rules.cpp.CcLinkingHelper.LinkingInfo; import com.google.devtools.build.lib.rules.cpp.CcLinkingOutputs; import com.google.devtools.build.lib.rules.cpp.CcModule; import com.google.devtools.build.lib.rules.cpp.CcToolchainConfigInfo; +import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration; import com.google.devtools.build.lib.rules.cpp.CcToolchainProvider; import com.google.devtools.build.lib.rules.cpp.CcToolchainVariables; +import com.google.devtools.build.lib.rules.cpp.CppConfiguration; +import com.google.devtools.build.lib.rules.cpp.CppFileTypes; +import com.google.devtools.build.lib.rules.cpp.FdoContext; import com.google.devtools.build.lib.rules.cpp.FeatureConfigurationForStarlark; import com.google.devtools.build.lib.rules.cpp.LibraryToLink; import com.google.devtools.build.lib.rules.cpp.LibraryToLink.CcLinkingContext; import com.google.devtools.build.lib.skylarkbuildapi.cpp.BazelCcModuleApi; +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; 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; +import com.google.devtools.build.lib.util.FileTypeSet; +import com.google.devtools.build.lib.util.Pair; +import com.google.devtools.build.lib.vfs.PathFragment; +import java.util.ArrayList; +import java.util.List; /** * A module that contains Skylark utilities for C++ support. @@ -40,70 +71,220 @@ */ public class BazelCcModule extends CcModule implements BazelCcModuleApi< - SkylarkActionFactory, - Artifact, - SkylarkRuleContext, - CcToolchainProvider, - FeatureConfigurationForStarlark, - CcCompilationContext, - CcCompilationOutputs, - CcLinkingOutputs, - CcLinkingContext, - LibraryToLink, - CcToolchainVariables, - CcToolchainConfigInfo> { + Artifact, + SkylarkRuleContext, + SkylarkActionFactory, + CcToolchainProvider, + FeatureConfigurationForStarlark, + CcCompilationContext, + CcCompilationOutputs, + CcLinkingContext, + LibraryToLink, + CcToolchainVariables, + CcToolchainConfigInfo> { + public static final FileTypeSet ALL_C_CLASS_SOURCE = + FileTypeSet.of( + CppFileTypes.CPP_SOURCE, + CppFileTypes.C_SOURCE, + CppFileTypes.OBJCPP_SOURCE, + CppFileTypes.OBJC_SOURCE); @Override public Tuple compile( - SkylarkActionFactory skylarkActionFactoryApi, + SkylarkActionFactory actions, FeatureConfigurationForStarlark skylarkFeatureConfiguration, CcToolchainProvider skylarkCcToolchainProvider, SkylarkList sources, SkylarkList publicHeaders, SkylarkList privateHeaders, - SkylarkList includes, - SkylarkList quoteIncludes, - SkylarkList systemIncludes, - SkylarkList userCompileFlags, + SkylarkList skylarkIncludes, + SkylarkList skylarkUserCompileFlags, SkylarkList ccCompilationContexts, String name, - boolean disallowPicOutputs, - boolean disallowNopicOutputs) + Location location) throws EvalException, InterruptedException { - return null; + CcToolchainProvider ccToolchainProvider = convertFromNoneable(skylarkCcToolchainProvider, null); + FeatureConfigurationForStarlark featureConfiguration = + convertFromNoneable(skylarkFeatureConfiguration, null); + Pair, List> separatedHeadersAndSources = + separateSourcesFromHeaders(sources); + FdoContext fdoContext = ccToolchainProvider.getFdoContext(); + // TODO(plf): Need to flatten the nested set to convert the Strings to PathFragment. This could + // be avoided if path fragments are ever added to Skylark or in the C++ code we take Strings + // instead of PathFragments. + List includeDirs = convertSkylarkListOrNestedSetToList(skylarkIncludes, String.class); + + validateExtensions( + location, + "srcs", + sources, + ALL_C_CLASS_SOURCE, + FileTypeSet.of(CppFileTypes.CPP_SOURCE, CppFileTypes.C_SOURCE)); + validateExtensions( + location, + "public_hdrs", + publicHeaders, + FileTypeSet.of(CppFileTypes.CPP_HEADER), + FileTypeSet.of(CppFileTypes.CPP_HEADER)); + validateExtensions( + location, + "private_hdrs", + privateHeaders, + FileTypeSet.of(CppFileTypes.CPP_HEADER), + FileTypeSet.of(CppFileTypes.CPP_HEADER)); + + Label label = getCallerLabel(location, actions, name); + CcCompilationHelper helper = + new CcCompilationHelper( + actions.asActionRegistry(location, actions), + actions.getActionConstructionContext(), + label, + /* grepIncludes= */ null, + BazelCppSemantics.INSTANCE, + featureConfiguration.getFeatureConfiguration(), + ccToolchainProvider, + fdoContext) + .addPublicHeaders(publicHeaders) + .addIncludeDirs( + includeDirs.stream() + .map(PathFragment::create) + .collect(ImmutableList.toImmutableList())) + .addPrivateHeaders(separatedHeadersAndSources.first) + .addSources(separatedHeadersAndSources.second) + .addCcCompilationContexts(ccCompilationContexts) + .setCopts(skylarkUserCompileFlags); + + try { + CompilationInfo compilationInfo = helper.compile(); + return Tuple.of( + compilationInfo.getCcCompilationContext(), compilationInfo.getCcCompilationOutputs()); + } catch (RuleErrorException e) { + throw new EvalException(location, e); + } } @Override - public CcLinkingContext createLinkingContextFromCompilationOutputs( - SkylarkActionFactory skylarkActionFactoryApi, + public Tuple createLinkingContextFromCompilationOutputs( + SkylarkActionFactory actions, FeatureConfigurationForStarlark skylarkFeatureConfiguration, CcToolchainProvider skylarkCcToolchainProvider, CcCompilationOutputs compilationOutputs, - SkylarkList userLinkFlags, + SkylarkList skylarkUserLinkFlags, + SkylarkList linkingContexts, String name, - String language, - boolean alwayslink, - SkylarkList nonCodeInputs, - boolean disallowStaticLibraries, - boolean disallowDynamicLibraries) + Location location, + StarlarkContext starlarkContext) throws InterruptedException, EvalException { - return null; + CcToolchainProvider ccToolchainProvider = convertFromNoneable(skylarkCcToolchainProvider, null); + FeatureConfigurationForStarlark featureConfiguration = + convertFromNoneable(skylarkFeatureConfiguration, null); + Label label = getCallerLabel(location, actions, name); + FdoContext fdoContext = ccToolchainProvider.getFdoContext(); + CcLinkingHelper helper = + new CcLinkingHelper( + actions.getActionConstructionContext().getRuleErrorConsumer(), + label, + actions.asActionRegistry(location, actions), + actions.getActionConstructionContext(), + BazelCppSemantics.INSTANCE, + featureConfiguration.getFeatureConfiguration(), + ccToolchainProvider, + fdoContext, + actions.getActionConstructionContext().getConfiguration(), + actions + .getActionConstructionContext() + .getConfiguration() + .getFragment(CppConfiguration.class), + ((BazelStarlarkContext) starlarkContext).getSymbolGenerator()) + .addLinkopts(skylarkUserLinkFlags) + .addCcLinkingContexts(linkingContexts); + try { + CcLinkingOutputs ccLinkingOutputs = CcLinkingOutputs.EMPTY; + ImmutableList libraryToLink = ImmutableList.of(); + if (!compilationOutputs.isEmpty()) { + ccLinkingOutputs = helper.link(compilationOutputs); + if (!ccLinkingOutputs.isEmpty()) { + libraryToLink = + ImmutableList.of(ccLinkingOutputs.getLibraryToLink()); + } + } + CcLinkingContext linkingContext = + helper.buildCcLinkingContextFromLibrariesToLink( + libraryToLink, CcCompilationContext.EMPTY); + return Tuple.of( + CcLinkingContext.merge( + ImmutableList.builder() + .add(linkingContext) + .addAll(linkingContexts) + .build()), + ccLinkingOutputs); + } catch (RuleErrorException e) { + throw new EvalException(location, e); + } } - @Override - public CcLinkingOutputs link( - SkylarkActionFactory skylarkActionFactoryApi, - FeatureConfigurationForStarlark skylarkFeatureConfiguration, - CcToolchainProvider skylarkCcToolchainProvider, - Object compilationOutputs, - SkylarkList userLinkFlags, - SkylarkList linkingContexts, - String name, - String language, - String outputType, - boolean linkDepsStatically, - SkylarkList nonCodeInputs) - throws InterruptedException, EvalException { - return null; + @SuppressWarnings("unchecked") + protected static List convertSkylarkListOrNestedSetToList(Object o, Class type) { + return o instanceof SkylarkNestedSet + ? ((SkylarkNestedSet) o).getSet(type).toList() + : ((SkylarkList) o).getImmutableList(); + } + + private static Pair, List> separateSourcesFromHeaders( + Iterable artifacts) { + List headers = new ArrayList<>(); + List sources = new ArrayList<>(); + for (Artifact artifact : artifacts) { + if (CppFileTypes.CPP_HEADER.matches(artifact.getExecPath())) { + headers.add(artifact); + } else { + sources.add(artifact); + } + } + return Pair.of(headers, sources); + } + + + @SuppressWarnings("unchecked") + protected static NestedSet convertSkylarkListOrNestedSetToNestedSet( + Object o, Class type) { + return o instanceof SkylarkNestedSet + ? ((SkylarkNestedSet) o).getSet(type) + : NestedSetBuilder.wrap(Order.COMPILE_ORDER, (SkylarkList) o); + } + + private void validateExtensions( + Location location, + String paramName, + List files, + FileTypeSet validFileTypeSet, + FileTypeSet fileTypeForErrorMessage) + throws EvalException { + for (Artifact file : files) { + if (!validFileTypeSet.matches(file.getFilename())) { + throw new EvalException( + location, + String.format( + "'%s' has wrong extension. The list of possible extensions for '" + + paramName + + "' are: %s", + file.getExecPathString(), + Joiner.on(",").join(fileTypeForErrorMessage.getExtensions()))); + } + } + } + + protected Label getCallerLabel(Location location, SkylarkActionFactory actions, String name) + throws EvalException { + Label label; + try { + label = + Label.create( + actions.getActionConstructionContext().getActionOwner().getLabel().getPackageName(), + name); + } catch (LabelSyntaxException e) { + throw new EvalException(location, e); + } + return label; } } diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/BazelCcModuleApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/BazelCcModuleApi.java index b01da22d2cbfbb..bda6b3e195a9a9 100644 --- a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/BazelCcModuleApi.java +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/BazelCcModuleApi.java @@ -14,6 +14,7 @@ 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; @@ -21,6 +22,8 @@ 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; @@ -31,365 +34,187 @@ @SkylarkModule( name = "cc_common", doc = "Utilities for C++ compilation, linking, and command line generation.") +// TODO(b/111365281): Add experimental field once it's available. public interface BazelCcModuleApi< - SkylarkActionFactoryT extends SkylarkActionFactoryApi, - FileT extends FileApi, - SkylarkRuleContextT extends SkylarkRuleContextApi, - CcToolchainProviderT extends CcToolchainProviderApi, - FeatureConfigurationT extends FeatureConfigurationApi, - CompilationContextT extends CcCompilationContextApi, - CompilationOutputsT extends CcCompilationOutputsApi, - LinkingOutputsT extends CcLinkingOutputsApi, - LinkingContextT extends CcLinkingContextApi, - LibraryToLinkT extends LibraryToLinkApi, - CcToolchainVariablesT extends CcToolchainVariablesApi, - CcToolchainConfigInfoT extends CcToolchainConfigInfoApi> + FileT extends FileApi, + SkylarkRuleContextT extends SkylarkRuleContextApi, + SkylarkActionFactoryT extends SkylarkActionFactoryApi, + CcToolchainProviderT extends CcToolchainProviderApi, + FeatureConfigurationT extends FeatureConfigurationApi, + CcCompilationContextT extends CcCompilationContextApi, + CcCompilationOutputsT extends CcCompilationOutputsApi, + LinkingContextT extends CcLinkingContextApi, + LibraryToLinkT extends LibraryToLinkApi, + CcToolchainVariablesT extends CcToolchainVariablesApi, + CcToolchainConfigInfoT extends CcToolchainConfigInfoApi> extends CcModuleApi< - FileT, - CcToolchainProviderT, - FeatureConfigurationT, - CompilationContextT, - LinkingContextT, - LibraryToLinkT, - CcToolchainVariablesT, - SkylarkRuleContextT, - CcToolchainConfigInfoT> { + FileT, + CcToolchainProviderT, + FeatureConfigurationT, + CcCompilationContextT, + LinkingContextT, + LibraryToLinkT, + CcToolchainVariablesT, + SkylarkRuleContextT, + CcToolchainConfigInfoT> { @SkylarkCallable( name = "compile", documented = false, + useLocation = true, parameters = { - @Param( - name = "actions", - type = SkylarkActionFactoryApi.class, - positional = false, - named = true, - doc = "actions object."), - @Param( - name = "feature_configuration", - doc = "feature_configuration to be queried.", - positional = false, - named = true, - type = FeatureConfigurationApi.class), - @Param( - name = "cc_toolchain", - doc = "CcToolchainInfo provider to be used.", - positional = false, - named = true, - type = CcToolchainProviderApi.class), - @Param( - name = "srcs", - doc = "The list of source files to be compiled.", - positional = false, - named = true, - defaultValue = "[]", - type = SkylarkList.class), - @Param( - name = "public_hdrs", - doc = - "List of headers needed for compilation of srcs and may be included by dependent " - + "rules transitively.", - positional = false, - named = true, - defaultValue = "[]", - type = SkylarkList.class), - @Param( - name = "private_hdrs", - doc = - "List of headers needed for compilation of srcs and NOT to be included by" - + " dependent rules.", - positional = false, - named = true, - defaultValue = "[]", - type = SkylarkList.class), - @Param( - name = "includes", - doc = - "Search paths for header files referenced both by angle bracket and quotes. " - + "Usually passed with -I. Propagated to dependents transitively.", - positional = false, - named = true, - noneable = true, - defaultValue = "[]", - type = SkylarkList.class), - @Param( - name = "quote_includes", - doc = - "Search paths for header files referenced by quotes, " - + "e.g. #include \"foo/bar/header.h\". They can be either relative to the exec " - + "root or absolute. Usually passed with -iquote. Propagated to dependents " - + "transitively.", - positional = false, - named = true, - noneable = true, - defaultValue = "[]", - type = SkylarkList.class), - @Param( - name = "system_includes", - doc = - "Search paths for header files referenced by angle brackets, e.g. #include" - + " . They can be either relative to the exec root or" - + " absolute. Usually passed with -isystem. Propagated to dependents " - + "transitively.", - positional = false, - named = true, - noneable = true, - defaultValue = "[]", - type = SkylarkList.class), - @Param( - name = "user_compile_flags", - doc = "Additional list of compilation options.", - positional = false, - named = true, - noneable = true, - defaultValue = "[]", - type = SkylarkList.class), - @Param( - name = "compilation_contexts", - doc = "Headers from dependencies used for compilation.", - positional = false, - named = true, - defaultValue = "[]", - type = SkylarkList.class), - @Param( - name = "name", - doc = - "This is used for naming the output artifacts of actions created by this " - + "method.", - positional = false, - named = true, - type = String.class), - @Param( - name = "disallow_pic_outputs", - doc = "Whether PIC outputs should be created.", - positional = false, - named = true, - defaultValue = "False", - type = Boolean.class), - @Param( - name = "disallow_nopic_outputs", - doc = "Whether NOPIC outputs should be created.", - positional = false, - named = true, - defaultValue = "False", - type = Boolean.class) + @Param( + name = "actions", + type = SkylarkActionFactoryApi.class, + positional = false, + named = true, + doc = "actions object."), + @Param( + name = "feature_configuration", + doc = "Feature configuration to be queried.", + positional = false, + named = true, + type = FeatureConfigurationApi.class), + @Param( + name = "cc_toolchain", + doc = "C++ toolchain provider to be used.", + positional = false, + named = true, + type = CcToolchainProviderApi.class), + @Param( + name = "srcs", + doc = "The list of source files to be compiled, see cc_library.srcs", + positional = false, + named = true, + defaultValue = "[]", + type = SkylarkList.class), + @Param( + name = "public_hdrs", + doc = "The list of public headers to be provided to dependents, see cc_library.hdrs", + positional = false, + named = true, + defaultValue = "[]", + type = SkylarkList.class), + @Param( + name = "private_hdrs", + doc = + "List of headers needed for compilation of srcs and NOT to be included by" + + " dependent rules.", + positional = false, + named = true, + defaultValue = "[]", + type = SkylarkList.class), + @Param( + name = "includes", + doc = + "Search paths for header files referenced both by angle bracket and quotes. " + + "Usually passed with -I. Propagated to dependents transitively.", + positional = false, + named = true, + noneable = true, + defaultValue = "[]", + type = SkylarkList.class), + @Param( + name = "user_compile_flags", + doc = "Additional list of compiler options.", + positional = false, + named = true, + defaultValue = "[]", + type = SkylarkList.class), + @Param( + name = "compilation_contexts", + doc = "compilation_context instances affecting compilation, e.g. from dependencies", + positional = false, + named = true, + defaultValue = "[]", + type = SkylarkList.class), + @Param( + name = "name", + doc = + "This is used for naming the output artifacts of actions created by this " + + "method.", + positional = false, + named = true, + type = String.class), }) Tuple compile( - SkylarkActionFactoryT skylarkActionFactoryApi, + SkylarkActionFactoryT skylarkActionFactory, FeatureConfigurationT skylarkFeatureConfiguration, CcToolchainProviderT skylarkCcToolchainProvider, SkylarkList sources, SkylarkList publicHeaders, SkylarkList privateHeaders, - SkylarkList includes, - SkylarkList quoteIncludes, - SkylarkList systemIncludes, - SkylarkList userCompileFlags, - SkylarkList ccCompilationContexts, + SkylarkList skylarkIncludes, + SkylarkList skylarkUserCompileFlags, + SkylarkList ccCompilationContexts, String name, - boolean disallowPicOutputs, - boolean disallowNopicOutputs) + Location location) throws EvalException, InterruptedException; - @SkylarkCallable( - name = "link", - documented = false, - parameters = { - @Param( - name = "actions", - type = SkylarkActionFactoryApi.class, - positional = false, - named = true, - doc = "actions object."), - @Param( - name = "feature_configuration", - doc = "feature_configuration to be queried.", - positional = false, - named = true, - type = FeatureConfigurationApi.class), - @Param( - name = "cc_toolchain", - doc = "CcToolchainInfo provider to be used.", - positional = false, - named = true, - type = CcToolchainProviderApi.class), - @Param( - name = "compilation_outputs", - doc = "Compilation outputs containing object files to link.", - positional = false, - named = true, - defaultValue = "None", - noneable = true, - allowedTypes = { - @ParamType(type = NoneType.class), - @ParamType(type = SkylarkList.class), - @ParamType(type = SkylarkNestedSet.class) - }), - @Param( - name = "user_link_flags", - doc = "Additional list of linker options.", - positional = false, - named = true, - 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 = - "This is used for naming the output artifacts of actions created by this " - + "method.", - positional = false, - named = true, - type = String.class), - @Param( - name = "language", - doc = "Can be one of C++, objc or objc++.", - positional = false, - named = true, - noneable = true, - defaultValue = "'C++'", - type = String.class), - @Param( - name = "output_type", - doc = "Can be either 'executable' or 'shared_library'.", - positional = false, - named = true, - noneable = true, - defaultValue = "'executable'", - type = String.class), - @Param( - name = "link_deps_statically", - doc = " True to link dependencies statically, False dynamically.", - positional = false, - named = true, - noneable = true, - defaultValue = "True", - type = Boolean.class), - @Param( - name = "non_code_inputs", - doc = "For additional inputs to the linking action, e.g.: linking scripts.", - positional = false, - named = true, - defaultValue = "[]", - type = SkylarkList.class), - }) - LinkingOutputsT link( - SkylarkActionFactoryT skylarkActionFactoryApi, - FeatureConfigurationT skylarkFeatureConfiguration, - CcToolchainProviderT skylarkCcToolchainProvider, - Object compilationOutputs, - SkylarkList userLinkFlags, - SkylarkList linkingContexts, - String name, - String language, - String outputType, - boolean linkDepsStatically, - SkylarkList nonCodeInputs) - throws InterruptedException, EvalException; - @SkylarkCallable( name = "create_linking_context_from_compilation_outputs", documented = false, + useLocation = true, + useContext = true, parameters = { - @Param( - name = "actions", - type = SkylarkActionFactoryApi.class, - positional = false, - named = true, - doc = "actions object."), - @Param( - name = "feature_configuration", - doc = "feature_configuration to be queried.", - positional = false, - named = true, - type = FeatureConfigurationApi.class), - @Param( - name = "cc_toolchain", - doc = "CcToolchainInfo provider to be used.", - positional = false, - named = true, - type = CcToolchainProviderApi.class), - @Param( - name = "compilation_outputs", - doc = "Compilation outputs containing object files to link.", - positional = false, - named = true, - type = CcCompilationOutputsApi.class), - @Param( - name = "user_link_flags", - doc = "Additional list of linking options.", - positional = false, - named = true, - defaultValue = "[]", - noneable = true, - type = SkylarkList.class), - @Param( - name = "name", - doc = - "This is used for naming the output artifacts of actions created by this " - + "method.", - positional = false, - named = true, - type = String.class), - @Param( - name = "language", - doc = "Can be one of C++, objc or objc++.", - positional = false, - named = true, - noneable = true, - defaultValue = "'C++'", - type = String.class), - @Param( - name = "alwayslink", - doc = "Whether this library should always be linked.", - positional = false, - named = true, - noneable = true, - defaultValue = "False", - type = Boolean.class), - @Param( - name = "non_code_inputs", - doc = "For additional inputs to the linking action, e.g.: linking scripts.", - positional = false, - named = true, - defaultValue = "[]", - type = SkylarkList.class), - @Param( - name = "disallow_static_libraries", - doc = "Whether static libraries should be created.", - positional = false, - named = true, - defaultValue = "False", - type = Boolean.class), - @Param( - name = "disallow_dynamic_libraries", - doc = "Whether dynamic libraries should be created.", - positional = false, - named = true, - defaultValue = "False", - type = Boolean.class) + @Param( + name = "actions", + type = SkylarkActionFactoryApi.class, + positional = false, + named = true, + doc = "actions object."), + @Param( + name = "feature_configuration", + doc = "Feature configuration to be queried.", + positional = false, + named = true, + type = FeatureConfigurationApi.class), + @Param( + name = "cc_toolchain", + doc = "C++ toolchain provider to be used.", + positional = false, + named = true, + type = CcToolchainProviderApi.class), + @Param( + name = "compilation_outputs", + doc = "Compilation outputs containing object files to link.", + positional = false, + named = true, + type = CcCompilationOutputsApi.class), + @Param( + name = "user_link_flags", + doc = "Additional list of linking options.", + positional = false, + named = true, + defaultValue = "[]", + noneable = true, + type = SkylarkList.class), + @Param( + name = "linking_contexts", + doc = "linking_context instances affecting linking, e.g. from dependencies", + positional = false, + named = true, + noneable = true, + defaultValue = "[]", + type = SkylarkList.class), + @Param( + name = "name", + doc = + "This is used for naming the output artifacts of actions created by this " + + "method.", + positional = false, + named = true, + type = String.class), }) - LinkingContextT createLinkingContextFromCompilationOutputs( - SkylarkActionFactoryT skylarkActionFactoryApi, + Tuple createLinkingContextFromCompilationOutputs( + SkylarkActionFactoryT skylarkActionFactory, FeatureConfigurationT skylarkFeatureConfiguration, CcToolchainProviderT skylarkCcToolchainProvider, - CompilationOutputsT compilationOutputs, + CcCompilationOutputsT ccCompilationOutputs, SkylarkList userLinkFlags, + SkylarkList skylarkCcLinkingContexts, String name, - String language, - boolean alwayslink, - SkylarkList nonCodeInputs, - boolean disallowStaticLibraries, - boolean disallowDynamicLibraries) + Location location, + StarlarkContext starlarkContext) throws InterruptedException, EvalException; } diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CcBootstrap.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CcBootstrap.java index 88c36c9021d555..96c18ca8b744f1 100644 --- a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CcBootstrap.java +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CcBootstrap.java @@ -25,34 +25,32 @@ */ public class CcBootstrap implements Bootstrap { private final BazelCcModuleApi< - ? extends SkylarkActionFactoryApi, + ? extends FileApi, + ? extends SkylarkRuleContextApi, + ? extends SkylarkActionFactoryApi, + ? extends CcToolchainProviderApi, + ? extends FeatureConfigurationApi, + ? extends CcCompilationContextApi, + ? extends CcCompilationOutputsApi, + ? extends CcLinkingContextApi, + ? extends LibraryToLinkApi, + ? extends CcToolchainVariablesApi, + ? extends CcToolchainConfigInfoApi> + ccModule; + + public CcBootstrap( + BazelCcModuleApi< ? extends FileApi, ? extends SkylarkRuleContextApi, + ? extends SkylarkActionFactoryApi, ? extends CcToolchainProviderApi, ? extends FeatureConfigurationApi, ? extends CcCompilationContextApi, - ? extends CcCompilationOutputsApi, - ? extends CcLinkingOutputsApi, + ? extends CcCompilationOutputsApi, ? extends CcLinkingContextApi, ? extends LibraryToLinkApi, ? extends CcToolchainVariablesApi, ? extends CcToolchainConfigInfoApi> - ccModule; - - public CcBootstrap( - BazelCcModuleApi< - ? extends SkylarkActionFactoryApi, - ? extends FileApi, - ? extends SkylarkRuleContextApi, - ? extends CcToolchainProviderApi, - ? extends FeatureConfigurationApi, - ? extends CcCompilationContextApi, - ? extends CcCompilationOutputsApi, - ? extends CcLinkingOutputsApi, - ? extends CcLinkingContextApi, - ? extends LibraryToLinkApi, - ? extends CcToolchainVariablesApi, - ? extends CcToolchainConfigInfoApi> ccModule) { this.ccModule = ccModule; } diff --git a/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/cpp/FakeCcModule.java b/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/cpp/FakeCcModule.java index 4e673203fd89f6..b4110ab874eb97 100644 --- a/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/cpp/FakeCcModule.java +++ b/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/cpp/FakeCcModule.java @@ -42,14 +42,13 @@ /** Fake implementation of {@link CcModuleApi}. */ public class FakeCcModule implements BazelCcModuleApi< - SkylarkActionFactoryApi, FileApi, SkylarkRuleContextApi, + SkylarkActionFactoryApi, CcToolchainProviderApi, FeatureConfigurationApi, CcCompilationContextApi, CcCompilationOutputsApi, - CcLinkingOutputsApi, CcLinkingContextApi, LibraryToLinkApi, CcToolchainVariablesApi, @@ -178,47 +177,25 @@ public Tuple compile( SkylarkList publicHeaders, SkylarkList privateHeaders, SkylarkList includes, - SkylarkList quoteIncludes, - SkylarkList systemIncludes, SkylarkList userCompileFlags, SkylarkList ccCompilationContexts, String name, - boolean disallowPicOutputs, - boolean disallowNopicOutputs) + Location location) throws EvalException, InterruptedException { return null; } @Override - public CcLinkingContextApi createLinkingContextFromCompilationOutputs( + public Tuple createLinkingContextFromCompilationOutputs( SkylarkActionFactoryApi skylarkActionFactoryApi, FeatureConfigurationApi skylarkFeatureConfiguration, CcToolchainProviderApi skylarkCcToolchainProvider, CcCompilationOutputsApi compilationOutputs, SkylarkList userLinkFlags, + SkylarkList ccCompilationContexts, String name, - String language, - boolean alwayslink, - SkylarkList nonCodeInputs, - boolean disallowStaticLibraries, - boolean disallowDynamicLibraries) - throws InterruptedException, EvalException { - return null; - } - - @Override - public CcLinkingOutputsApi link( - SkylarkActionFactoryApi skylarkActionFactoryApi, - FeatureConfigurationApi skylarkFeatureConfiguration, - CcToolchainProviderApi skylarkCcToolchainProvider, - Object compilationOutputs, - SkylarkList userLinkFlags, - SkylarkList linkingContexts, - String name, - String language, - String outputType, - boolean linkDepsStatically, - SkylarkList nonCodeInputs) + Location location, + StarlarkContext starlarkContext) throws InterruptedException, EvalException { return null; }