From c958e00f6f4c09411b4482c2e5b8cfc61d5e17bf Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 5 Mar 2024 05:55:00 -0800 Subject: [PATCH 1/2] Move compile StarlarkMethod back to CcModuleAPI This way the documentation is again generated. Fixes: https://github.com/bazelbuild/bazel/issues/20922 PiperOrigin-RevId: 612810046 Change-Id: I38f3ab01d1f4951eeb9045bbf214057824be6fd4 --- .../build/lib/rules/cpp/CcModule.java | 290 +--------------- .../lib/starlarkbuildapi/cpp/CcModuleApi.java | 327 ++++++++++++++++++ 2 files changed, 328 insertions(+), 289 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java index 98d57d0e4f9a6c..a9b29aaf3aa0ef 100755 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java @@ -73,10 +73,7 @@ import com.google.devtools.build.lib.rules.cpp.CppActionConfigs.CppPlatform; import com.google.devtools.build.lib.rules.cpp.Link.LinkTargetType; import com.google.devtools.build.lib.rules.cpp.Link.LinkingMode; -import com.google.devtools.build.lib.starlarkbuildapi.FileApi; -import com.google.devtools.build.lib.starlarkbuildapi.cpp.CcCompilationContextApi; import com.google.devtools.build.lib.starlarkbuildapi.cpp.CcModuleApi; -import com.google.devtools.build.lib.starlarkbuildapi.cpp.CppModuleMapApi; import com.google.devtools.build.lib.starlarkbuildapi.cpp.ExtraLinkTimeLibraryApi; import com.google.devtools.build.lib.util.FileTypeSet; import com.google.devtools.build.lib.util.Pair; @@ -2142,292 +2139,7 @@ private static boolean checkObjectsBound(Object... objects) { return false; } - @StarlarkMethod( - name = "compile", - doc = - "Should be used for C++ compilation. Returns tuple of " - + "(CompilationContext, CcCompilationOutputs).", - useStarlarkThread = true, - parameters = { - @Param( - name = "actions", - positional = false, - named = true, - doc = "actions object."), - @Param( - name = "feature_configuration", - doc = "feature_configuration to be queried.", - positional = false, - named = true), - @Param( - name = "cc_toolchain", - doc = "CcToolchainInfo provider to be used.", - positional = false, - named = true), - @Param( - name = "srcs", - doc = "The list of source files to be compiled.", - positional = false, - named = true, - defaultValue = "[]"), - @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 = "[]"), - @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 = "[]"), - @Param( - name = "textual_hdrs", - positional = false, - named = true, - allowedTypes = { - @ParamType(type = Sequence.class, generic1 = FileApi.class), - @ParamType(type = Depset.class) - }, - documented = false, - defaultValue = "[]"), - @Param( - name = "additional_exported_hdrs", - positional = false, - named = true, - documented = false, - allowedTypes = {@ParamType(type = Sequence.class, generic1 = String.class)}, - defaultValue = "unbound"), - @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, - defaultValue = "[]", - allowedTypes = {@ParamType(type = Sequence.class), @ParamType(type = Depset.class)}), - @Param( - name = "loose_includes", - documented = false, - positional = false, - named = true, - defaultValue = "unbound", - allowedTypes = {@ParamType(type = Sequence.class), @ParamType(type = NoneType.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, - defaultValue = "[]"), - @Param( - name = "system_includes", - doc = - "Search paths for header files referenced by angle brackets, e.g. #include" - + " <foo/bar/header.h>. They can be either relative to the exec root or" - + " absolute. Usually passed with -isystem. Propagated to dependents " - + "transitively.", - positional = false, - named = true, - defaultValue = "[]"), - @Param( - name = "framework_includes", - doc = - "Search paths for header files from Apple frameworks. They can be either relative " - + "to the exec root or absolute. Usually passed with -F. Propagated to " - + "dependents transitively.", - positional = false, - named = true, - defaultValue = "[]"), - @Param( - name = "defines", - doc = - "Set of defines needed to compile this target. Each define is a string. Propagated" - + " to dependents transitively.", - positional = false, - named = true, - defaultValue = "[]"), - @Param( - name = "local_defines", - doc = - "Set of defines needed to compile this target. Each define is a string. Not" - + " propagated to dependents transitively.", - positional = false, - named = true, - defaultValue = "[]"), - @Param( - name = "include_prefix", - doc = - "The prefix to add to the paths of the headers of this rule. When set, the " - + "headers in the hdrs attribute of this rule are accessible at is the " - + "value of this attribute prepended to their repository-relative path. " - + "The prefix in the strip_include_prefix attribute is removed before this " - + "prefix is added.", - positional = false, - named = true, - defaultValue = "''"), - @Param( - name = "strip_include_prefix", - doc = - "The prefix to strip from the paths of the headers of this rule. When set, the" - + " headers in the hdrs attribute of this rule are accessible at their path" - + " with this prefix cut off. If it's a relative path, it's taken as a" - + " package-relative one. If it's an absolute one, it's understood as a" - + " repository-relative path. The prefix in the include_prefix attribute is" - + " added after this prefix is stripped.", - positional = false, - named = true, - defaultValue = "''"), - @Param( - name = "user_compile_flags", - doc = "Additional list of compilation options.", - positional = false, - named = true, - defaultValue = "[]"), - @Param( - name = "compilation_contexts", - doc = "Headers from dependencies used for compilation.", - positional = false, - named = true, - defaultValue = "[]"), - @Param( - name = "implementation_compilation_contexts", - documented = false, - positional = false, - defaultValue = "unbound", - allowedTypes = { - @ParamType(type = Sequence.class, generic1 = CcCompilationContextApi.class), - @ParamType(type = NoneType.class) - }, - named = true), - @Param( - name = "name", - doc = - "This is used for naming the output artifacts of actions created by this " - + "method. See also the `main_output` arg.", - positional = false, - named = true), - @Param( - name = "disallow_pic_outputs", - doc = "Whether PIC outputs should be created.", - positional = false, - named = true, - defaultValue = "False"), - @Param( - name = "disallow_nopic_outputs", - doc = "Whether NOPIC outputs should be created.", - positional = false, - named = true, - defaultValue = "False"), - @Param( - name = "additional_include_scanning_roots", - documented = false, - positional = false, - named = true, - defaultValue = "[]"), - @Param( - name = "additional_inputs", - doc = "List of additional files needed for compilation of srcs", - positional = false, - named = true, - defaultValue = "[]"), - @Param( - name = "module_map", - positional = false, - documented = false, - defaultValue = "unbound", - allowedTypes = { - @ParamType(type = CppModuleMapApi.class), - @ParamType(type = NoneType.class) - }, - named = true), - @Param( - name = "additional_module_maps", - positional = false, - documented = false, - defaultValue = "unbound", - allowedTypes = {@ParamType(type = Sequence.class, generic1 = CppModuleMapApi.class)}, - named = true), - @Param( - name = "propagate_module_map_to_compile_action", - positional = false, - named = true, - documented = false, - allowedTypes = {@ParamType(type = Boolean.class)}, - defaultValue = "unbound"), - @Param( - name = "do_not_generate_module_map", - positional = false, - named = true, - documented = false, - allowedTypes = {@ParamType(type = Boolean.class)}, - defaultValue = "unbound"), - @Param( - name = "code_coverage_enabled", - positional = false, - named = true, - documented = false, - allowedTypes = {@ParamType(type = Boolean.class)}, - defaultValue = "unbound"), - @Param( - name = "hdrs_checking_mode", - positional = false, - named = true, - documented = false, - allowedTypes = {@ParamType(type = String.class), @ParamType(type = NoneType.class)}, - defaultValue = "unbound"), - @Param( - name = "variables_extension", - positional = false, - named = true, - documented = false, - allowedTypes = {@ParamType(type = Dict.class)}, - defaultValue = "unbound"), - @Param( - name = "language", - positional = false, - named = true, - documented = false, - allowedTypes = {@ParamType(type = String.class), @ParamType(type = NoneType.class)}, - defaultValue = "unbound"), - @Param( - name = "purpose", - documented = false, - positional = false, - named = true, - allowedTypes = {@ParamType(type = String.class), @ParamType(type = NoneType.class)}, - defaultValue = "unbound"), - @Param( - name = "copts_filter", - documented = false, - positional = false, - named = true, - allowedTypes = {@ParamType(type = String.class), @ParamType(type = NoneType.class)}, - defaultValue = "unbound"), - @Param( - name = "separate_module_headers", - documented = false, - positional = false, - named = true, - allowedTypes = {@ParamType(type = Sequence.class)}, - defaultValue = "unbound"), - @Param( - name = "non_compilation_additional_inputs", - positional = false, - named = true, - allowedTypes = {@ParamType(type = Sequence.class, generic1 = Artifact.class)}, - documented = false, - defaultValue = "unbound"), - }) + @Override @SuppressWarnings("unchecked") public Tuple compile( StarlarkActionFactory starlarkActionFactoryApi, diff --git a/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/cpp/CcModuleApi.java b/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/cpp/CcModuleApi.java index 64f7ff78be110a..b2451ca1293515 100755 --- a/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/cpp/CcModuleApi.java +++ b/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/cpp/CcModuleApi.java @@ -91,6 +91,333 @@ public interface CcModuleApi< structField = true) default void compilerFlagExists() {} + @StarlarkMethod( + name = "compile", + doc = + "Should be used for C++ compilation. Returns tuple of " + + "(CompilationContext, CcCompilationOutputs).", + useStarlarkThread = true, + parameters = { + @Param( + name = "actions", + positional = false, + named = true, + doc = "actions object."), + @Param( + name = "feature_configuration", + doc = "feature_configuration to be queried.", + positional = false, + named = true), + @Param( + name = "cc_toolchain", + doc = "CcToolchainInfo provider to be used.", + positional = false, + named = true), + @Param( + name = "srcs", + doc = "The list of source files to be compiled.", + positional = false, + named = true, + defaultValue = "[]"), + @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 = "[]"), + @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 = "[]"), + @Param( + name = "textual_hdrs", + positional = false, + named = true, + allowedTypes = { + @ParamType(type = Sequence.class, generic1 = FileApi.class), + @ParamType(type = Depset.class) + }, + documented = false, + defaultValue = "[]"), + @Param( + name = "additional_exported_hdrs", + positional = false, + named = true, + documented = false, + allowedTypes = {@ParamType(type = Sequence.class, generic1 = String.class)}, + defaultValue = "unbound"), + @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, + defaultValue = "[]", + allowedTypes = {@ParamType(type = Sequence.class), @ParamType(type = Depset.class)}), + @Param( + name = "loose_includes", + documented = false, + positional = false, + named = true, + defaultValue = "unbound", + allowedTypes = {@ParamType(type = Sequence.class), @ParamType(type = NoneType.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, + defaultValue = "[]"), + @Param( + name = "system_includes", + doc = + "Search paths for header files referenced by angle brackets, e.g. #include" + + " <foo/bar/header.h>. They can be either relative to the exec root or" + + " absolute. Usually passed with -isystem. Propagated to dependents " + + "transitively.", + positional = false, + named = true, + defaultValue = "[]"), + @Param( + name = "framework_includes", + doc = + "Search paths for header files from Apple frameworks. They can be either relative " + + "to the exec root or absolute. Usually passed with -F. Propagated to " + + "dependents transitively.", + positional = false, + named = true, + defaultValue = "[]"), + @Param( + name = "defines", + doc = + "Set of defines needed to compile this target. Each define is a string. Propagated" + + " to dependents transitively.", + positional = false, + named = true, + defaultValue = "[]"), + @Param( + name = "local_defines", + doc = + "Set of defines needed to compile this target. Each define is a string. Not" + + " propagated to dependents transitively.", + positional = false, + named = true, + defaultValue = "[]"), + @Param( + name = "include_prefix", + doc = + "The prefix to add to the paths of the headers of this rule. When set, the " + + "headers in the hdrs attribute of this rule are accessible at is the " + + "value of this attribute prepended to their repository-relative path. " + + "The prefix in the strip_include_prefix attribute is removed before this " + + "prefix is added.", + positional = false, + named = true, + defaultValue = "''"), + @Param( + name = "strip_include_prefix", + doc = + "The prefix to strip from the paths of the headers of this rule. When set, the" + + " headers in the hdrs attribute of this rule are accessible at their path" + + " with this prefix cut off. If it's a relative path, it's taken as a" + + " package-relative one. If it's an absolute one, it's understood as a" + + " repository-relative path. The prefix in the include_prefix attribute is" + + " added after this prefix is stripped.", + positional = false, + named = true, + defaultValue = "''"), + @Param( + name = "user_compile_flags", + doc = "Additional list of compilation options.", + positional = false, + named = true, + defaultValue = "[]"), + @Param( + name = "compilation_contexts", + doc = "Headers from dependencies used for compilation.", + positional = false, + named = true, + defaultValue = "[]"), + @Param( + name = "implementation_compilation_contexts", + documented = false, + positional = false, + defaultValue = "unbound", + allowedTypes = { + @ParamType(type = Sequence.class, generic1 = CcCompilationContextApi.class), + @ParamType(type = NoneType.class) + }, + named = true), + @Param( + name = "name", + doc = + "This is used for naming the output artifacts of actions created by this " + + "method. See also the `main_output` arg.", + positional = false, + named = true), + @Param( + name = "disallow_pic_outputs", + doc = "Whether PIC outputs should be created.", + positional = false, + named = true, + defaultValue = "False"), + @Param( + name = "disallow_nopic_outputs", + doc = "Whether NOPIC outputs should be created.", + positional = false, + named = true, + defaultValue = "False"), + @Param( + name = "additional_include_scanning_roots", + documented = false, + positional = false, + named = true, + defaultValue = "[]"), + @Param( + name = "additional_inputs", + doc = "List of additional files needed for compilation of srcs", + positional = false, + named = true, + defaultValue = "[]"), + @Param( + name = "module_map", + positional = false, + documented = false, + defaultValue = "unbound", + allowedTypes = { + @ParamType(type = CppModuleMapApi.class), + @ParamType(type = NoneType.class) + }, + named = true), + @Param( + name = "additional_module_maps", + positional = false, + documented = false, + defaultValue = "unbound", + allowedTypes = {@ParamType(type = Sequence.class, generic1 = CppModuleMapApi.class)}, + named = true), + @Param( + name = "propagate_module_map_to_compile_action", + positional = false, + named = true, + documented = false, + allowedTypes = {@ParamType(type = Boolean.class)}, + defaultValue = "unbound"), + @Param( + name = "do_not_generate_module_map", + positional = false, + named = true, + documented = false, + allowedTypes = {@ParamType(type = Boolean.class)}, + defaultValue = "unbound"), + @Param( + name = "code_coverage_enabled", + positional = false, + named = true, + documented = false, + allowedTypes = {@ParamType(type = Boolean.class)}, + defaultValue = "unbound"), + @Param( + name = "hdrs_checking_mode", + positional = false, + named = true, + documented = false, + allowedTypes = {@ParamType(type = String.class), @ParamType(type = NoneType.class)}, + defaultValue = "unbound"), + @Param( + name = "variables_extension", + positional = false, + named = true, + documented = false, + allowedTypes = {@ParamType(type = Dict.class)}, + defaultValue = "unbound"), + @Param( + name = "language", + positional = false, + named = true, + documented = false, + allowedTypes = {@ParamType(type = String.class), @ParamType(type = NoneType.class)}, + defaultValue = "unbound"), + @Param( + name = "purpose", + documented = false, + positional = false, + named = true, + allowedTypes = {@ParamType(type = String.class), @ParamType(type = NoneType.class)}, + defaultValue = "unbound"), + @Param( + name = "copts_filter", + documented = false, + positional = false, + named = true, + allowedTypes = {@ParamType(type = String.class), @ParamType(type = NoneType.class)}, + defaultValue = "unbound"), + @Param( + name = "separate_module_headers", + documented = false, + positional = false, + named = true, + allowedTypes = {@ParamType(type = Sequence.class)}, + defaultValue = "unbound"), + @Param( + name = "non_compilation_additional_inputs", + positional = false, + named = true, + allowedTypes = {@ParamType(type = Sequence.class, generic1 = FileApi.class)}, + documented = false, + defaultValue = "unbound"), + }) + Tuple compile( + StarlarkActionFactoryT starlarkActionFactoryApi, + FeatureConfigurationT starlarkFeatureConfiguration, + Info starlarkCcToolchainProvider, + Sequence sourcesUnchecked, // expected + Sequence publicHeadersUnchecked, // expected + Sequence privateHeadersUnchecked, // expected + Object textualHeadersStarlarkObject, + Object additionalExportedHeadersObject, + Object starlarkIncludes, + Object starlarkLooseIncludes, + Sequence quoteIncludes, // expected + Sequence systemIncludes, // expected + Sequence frameworkIncludes, // expected + Sequence defines, // expected + Sequence localDefines, // expected + String includePrefix, + String stripIncludePrefix, + Sequence userCompileFlags, // expected + Sequence ccCompilationContexts, // expected + Object implementationCcCompilationContextsObject, + String name, + boolean disallowPicOutputs, + boolean disallowNopicOutputs, + Sequence additionalIncludeScanningRoots, // expected + Sequence additionalInputs, // expected + Object moduleMapNoneable, + Object additionalModuleMapsNoneable, + Object propagateModuleMapToCompileActionObject, + Object doNotGenerateModuleMapObject, + Object codeCoverageEnabledObject, + Object hdrsCheckingModeObject, + Object variablesExtension, + Object languageObject, + Object purposeObject, + Object coptsFilterObject, + Object separateModuleHeadersObject, + Object nonCompilationAdditionalInputsObject, + StarlarkThread thread) + throws EvalException, InterruptedException; + @StarlarkMethod( name = "link", doc = "Should be used for C++ transitive linking.", From d89f9a9f5be0bd866c7b10a930a45bd9dd4a8474 Mon Sep 17 00:00:00 2001 From: Ivo List Date: Thu, 7 Mar 2024 15:41:01 +0100 Subject: [PATCH 2/2] Change Info to CcToolchainProvider --- .../devtools/build/lib/starlarkbuildapi/cpp/CcModuleApi.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/cpp/CcModuleApi.java b/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/cpp/CcModuleApi.java index b2451ca1293515..6174591c125bf1 100755 --- a/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/cpp/CcModuleApi.java +++ b/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/cpp/CcModuleApi.java @@ -380,7 +380,7 @@ default void compilerFlagExists() {} Tuple compile( StarlarkActionFactoryT starlarkActionFactoryApi, FeatureConfigurationT starlarkFeatureConfiguration, - Info starlarkCcToolchainProvider, + CcToolchainProviderT starlarkCcToolchainProvider, Sequence sourcesUnchecked, // expected Sequence publicHeadersUnchecked, // expected Sequence privateHeadersUnchecked, // expected