Merge "Do not hardcode default/experimental c{pp}std" am: ace70d857e
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2106991 Change-Id: Id32f103367512c5b7a1a22eaac933d67d91f01a3 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
72627266b9
4 changed files with 93 additions and 80 deletions
|
@ -1879,49 +1879,51 @@ func TestCcLibraryCppStdWithGnuExtensions_ConvertsToFeatureAttr(t *testing.T) {
|
|||
// not set, only emit if gnu_extensions is disabled. the default (gnu+17
|
||||
// is set in the toolchain.)
|
||||
{cpp_std: "", gnu_extensions: "", bazel_cpp_std: ""},
|
||||
{cpp_std: "", gnu_extensions: "false", bazel_cpp_std: "c++17", bazel_c_std: "c99"},
|
||||
{cpp_std: "", gnu_extensions: "false", bazel_cpp_std: "cpp_std_default_no_gnu", bazel_c_std: "c_std_default_no_gnu"},
|
||||
{cpp_std: "", gnu_extensions: "true", bazel_cpp_std: ""},
|
||||
// experimental defaults to gnu++2a
|
||||
{cpp_std: "experimental", gnu_extensions: "", bazel_cpp_std: "gnu++2a"},
|
||||
{cpp_std: "experimental", gnu_extensions: "false", bazel_cpp_std: "c++2a", bazel_c_std: "c99"},
|
||||
{cpp_std: "experimental", gnu_extensions: "true", bazel_cpp_std: "gnu++2a"},
|
||||
{cpp_std: "experimental", gnu_extensions: "", bazel_cpp_std: "cpp_std_experimental"},
|
||||
{cpp_std: "experimental", gnu_extensions: "false", bazel_cpp_std: "cpp_std_experimental_no_gnu", bazel_c_std: "c_std_default_no_gnu"},
|
||||
{cpp_std: "experimental", gnu_extensions: "true", bazel_cpp_std: "cpp_std_experimental"},
|
||||
// Explicitly setting a c++ std does not use replace gnu++ std even if
|
||||
// gnu_extensions is true.
|
||||
// "c++11",
|
||||
{cpp_std: "c++11", gnu_extensions: "", bazel_cpp_std: "c++11"},
|
||||
{cpp_std: "c++11", gnu_extensions: "false", bazel_cpp_std: "c++11", bazel_c_std: "c99"},
|
||||
{cpp_std: "c++11", gnu_extensions: "false", bazel_cpp_std: "c++11", bazel_c_std: "c_std_default_no_gnu"},
|
||||
{cpp_std: "c++11", gnu_extensions: "true", bazel_cpp_std: "c++11"},
|
||||
// "c++17",
|
||||
{cpp_std: "c++17", gnu_extensions: "", bazel_cpp_std: "c++17"},
|
||||
{cpp_std: "c++17", gnu_extensions: "false", bazel_cpp_std: "c++17", bazel_c_std: "c99"},
|
||||
{cpp_std: "c++17", gnu_extensions: "false", bazel_cpp_std: "c++17", bazel_c_std: "c_std_default_no_gnu"},
|
||||
{cpp_std: "c++17", gnu_extensions: "true", bazel_cpp_std: "c++17"},
|
||||
// "c++2a",
|
||||
{cpp_std: "c++2a", gnu_extensions: "", bazel_cpp_std: "c++2a"},
|
||||
{cpp_std: "c++2a", gnu_extensions: "false", bazel_cpp_std: "c++2a", bazel_c_std: "c99"},
|
||||
{cpp_std: "c++2a", gnu_extensions: "false", bazel_cpp_std: "c++2a", bazel_c_std: "c_std_default_no_gnu"},
|
||||
{cpp_std: "c++2a", gnu_extensions: "true", bazel_cpp_std: "c++2a"},
|
||||
// "c++98",
|
||||
{cpp_std: "c++98", gnu_extensions: "", bazel_cpp_std: "c++98"},
|
||||
{cpp_std: "c++98", gnu_extensions: "false", bazel_cpp_std: "c++98", bazel_c_std: "c99"},
|
||||
{cpp_std: "c++98", gnu_extensions: "false", bazel_cpp_std: "c++98", bazel_c_std: "c_std_default_no_gnu"},
|
||||
{cpp_std: "c++98", gnu_extensions: "true", bazel_cpp_std: "c++98"},
|
||||
// gnu++ is replaced with c++ if gnu_extensions is explicitly false.
|
||||
// "gnu++11",
|
||||
{cpp_std: "gnu++11", gnu_extensions: "", bazel_cpp_std: "gnu++11"},
|
||||
{cpp_std: "gnu++11", gnu_extensions: "false", bazel_cpp_std: "c++11", bazel_c_std: "c99"},
|
||||
{cpp_std: "gnu++11", gnu_extensions: "false", bazel_cpp_std: "c++11", bazel_c_std: "c_std_default_no_gnu"},
|
||||
{cpp_std: "gnu++11", gnu_extensions: "true", bazel_cpp_std: "gnu++11"},
|
||||
// "gnu++17",
|
||||
{cpp_std: "gnu++17", gnu_extensions: "", bazel_cpp_std: "gnu++17"},
|
||||
{cpp_std: "gnu++17", gnu_extensions: "false", bazel_cpp_std: "c++17", bazel_c_std: "c99"},
|
||||
{cpp_std: "gnu++17", gnu_extensions: "false", bazel_cpp_std: "c++17", bazel_c_std: "c_std_default_no_gnu"},
|
||||
{cpp_std: "gnu++17", gnu_extensions: "true", bazel_cpp_std: "gnu++17"},
|
||||
|
||||
// some c_std test cases
|
||||
{c_std: "experimental", gnu_extensions: "", bazel_c_std: "gnu17"},
|
||||
{c_std: "experimental", gnu_extensions: "false", bazel_cpp_std: "c++17", bazel_c_std: "c17"},
|
||||
{c_std: "experimental", gnu_extensions: "true", bazel_c_std: "gnu17"},
|
||||
{c_std: "experimental", gnu_extensions: "", bazel_c_std: "c_std_experimental"},
|
||||
{c_std: "experimental", gnu_extensions: "false", bazel_cpp_std: "cpp_std_default_no_gnu", bazel_c_std: "c_std_experimental_no_gnu"},
|
||||
{c_std: "experimental", gnu_extensions: "true", bazel_c_std: "c_std_experimental"},
|
||||
{c_std: "gnu11", cpp_std: "gnu++17", gnu_extensions: "", bazel_cpp_std: "gnu++17", bazel_c_std: "gnu11"},
|
||||
{c_std: "gnu11", cpp_std: "gnu++17", gnu_extensions: "false", bazel_cpp_std: "c++17", bazel_c_std: "c11"},
|
||||
{c_std: "gnu11", cpp_std: "gnu++17", gnu_extensions: "true", bazel_cpp_std: "gnu++17", bazel_c_std: "gnu11"},
|
||||
}
|
||||
for i, tc := range testCases {
|
||||
name := fmt.Sprintf("cpp std: %q, c std: %q, gnu_extensions: %q", tc.cpp_std, tc.c_std, tc.gnu_extensions)
|
||||
t.Run(name, func(t *testing.T) {
|
||||
name_prefix := fmt.Sprintf("a_%v", i)
|
||||
cppStdProp := ""
|
||||
if tc.cpp_std != "" {
|
||||
|
@ -1997,6 +1999,7 @@ cc_library_shared {
|
|||
makeBazelTarget("cc_library_shared", name_prefix+"_shared", attrs),
|
||||
},
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -444,32 +444,33 @@ func parseSrcs(ctx android.BazelConversionPathContext, props *BaseCompilerProper
|
|||
return bazel.AppendBazelLabelLists(allSrcsLabelList, generatedSrcsLabelList), anySrcs
|
||||
}
|
||||
|
||||
func bp2buildResolveCppStdValue(c_std *string, cpp_std *string, gnu_extensions *bool) (*string, *string) {
|
||||
var cStdVal, cppStdVal string
|
||||
func bp2buildStdVal(std *string, prefix string, useGnu bool) *string {
|
||||
defaultVal := prefix + "_std_default"
|
||||
// If c{,pp}std properties are not specified, don't generate them in the BUILD file.
|
||||
// Defaults are handled by the toolchain definition.
|
||||
// However, if gnu_extensions is false, then the default gnu-to-c version must be specified.
|
||||
if cpp_std != nil {
|
||||
cppStdVal = parseCppStd(cpp_std)
|
||||
} else if gnu_extensions != nil && !*gnu_extensions {
|
||||
cppStdVal = "c++17"
|
||||
stdVal := proptools.StringDefault(std, defaultVal)
|
||||
if stdVal == "experimental" || stdVal == defaultVal {
|
||||
if stdVal == "experimental" {
|
||||
stdVal = prefix + "_std_experimental"
|
||||
}
|
||||
if c_std != nil {
|
||||
cStdVal = parseCStd(c_std)
|
||||
} else if gnu_extensions != nil && !*gnu_extensions {
|
||||
cStdVal = "c99"
|
||||
if !useGnu {
|
||||
stdVal += "_no_gnu"
|
||||
}
|
||||
} else if !useGnu {
|
||||
stdVal = gnuToCReplacer.Replace(stdVal)
|
||||
}
|
||||
|
||||
cStdVal, cppStdVal = maybeReplaceGnuToC(gnu_extensions, cStdVal, cppStdVal)
|
||||
var c_std_prop, cpp_std_prop *string
|
||||
if cStdVal != "" {
|
||||
c_std_prop = &cStdVal
|
||||
if stdVal == defaultVal {
|
||||
return nil
|
||||
}
|
||||
if cppStdVal != "" {
|
||||
cpp_std_prop = &cppStdVal
|
||||
return &stdVal
|
||||
}
|
||||
|
||||
return c_std_prop, cpp_std_prop
|
||||
func bp2buildResolveCppStdValue(c_std *string, cpp_std *string, gnu_extensions *bool) (*string, *string) {
|
||||
useGnu := useGnuExtensions(gnu_extensions)
|
||||
|
||||
return bp2buildStdVal(c_std, "c", useGnu), bp2buildStdVal(cpp_std, "cpp", useGnu)
|
||||
}
|
||||
|
||||
// packageFromLabel extracts package from a fully-qualified or relative Label and whether the label
|
||||
|
|
|
@ -295,8 +295,12 @@ func addToModuleList(ctx ModuleContext, key android.OnceKey, module string) {
|
|||
getNamedMapForConfig(ctx.Config(), key).Store(module, true)
|
||||
}
|
||||
|
||||
func useGnuExtensions(gnuExtensions *bool) bool {
|
||||
return proptools.BoolDefault(gnuExtensions, true)
|
||||
}
|
||||
|
||||
func maybeReplaceGnuToC(gnuExtensions *bool, cStd string, cppStd string) (string, string) {
|
||||
if gnuExtensions != nil && *gnuExtensions == false {
|
||||
if !useGnuExtensions(gnuExtensions) {
|
||||
cStd = gnuToCReplacer.Replace(cStd)
|
||||
cppStd = gnuToCReplacer.Replace(cppStd)
|
||||
}
|
||||
|
|
|
@ -370,6 +370,11 @@ func init() {
|
|||
exportedVars.ExportStringListStaticVariable("CommonGlobalCppflags", commonGlobalCppflags)
|
||||
exportedVars.ExportStringListStaticVariable("ExternalCflags", extraExternalCflags)
|
||||
|
||||
exportedVars.ExportString("CStdVersion", CStdVersion)
|
||||
exportedVars.ExportString("CppStdVersion", CppStdVersion)
|
||||
exportedVars.ExportString("ExperimentalCStdVersion", ExperimentalCStdVersion)
|
||||
exportedVars.ExportString("ExperimentalCppStdVersion", ExperimentalCppStdVersion)
|
||||
|
||||
// Everything in these lists is a crime against abstraction and dependency tracking.
|
||||
// Do not add anything to this list.
|
||||
commonGlobalIncludes := []string{
|
||||
|
|
Loading…
Reference in a new issue