Add bp2build support for cpp_std. am: 97b8531492 am: aff7f12f5a am: ffa51d929e am: 6ac44b93dc am: 4350025d8f

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1850354

Change-Id: Ie6279620041da5d656ca8f0e520191f7705cd1fa
This commit is contained in:
Jingwen Chen
2021-10-08 17:40:25 +00:00
committed by Automerger Merge Worker
3 changed files with 123 additions and 12 deletions

View File

@@ -277,7 +277,24 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul
srcs.SetSelectValue(axis, config, srcsList)
}
archVariantCopts := parseCommandLineFlags(baseCompilerProps.Cflags)
var archVariantCopts []string
if axis == bazel.NoConfigAxis {
// If cpp_std is not specified, don't generate it in the
// BUILD file. For readability purposes, cpp_std and gnu_extensions are
// combined into a single -std=<version> copt, except in the
// default case where cpp_std is nil and gnu_extensions is true or unspecified,
// then the toolchain's default "gnu++17" will be used.
if baseCompilerProps.Cpp_std != nil {
// TODO(b/202491296): Handle C_std.
// These transformations are shared with compiler.go.
cppStdVal := parseCppStd(baseCompilerProps.Cpp_std)
_, cppStdVal = maybeReplaceGnuToC(baseCompilerProps.Gnu_extensions, "", cppStdVal)
archVariantCopts = append(archVariantCopts, "-std="+cppStdVal)
} else if baseCompilerProps.Gnu_extensions != nil && !*baseCompilerProps.Gnu_extensions {
archVariantCopts = append(archVariantCopts, "-std=c++17")
}
}
archVariantCopts = append(archVariantCopts, parseCommandLineFlags(baseCompilerProps.Cflags)...)
archVariantAsflags := parseCommandLineFlags(baseCompilerProps.Asflags)
localIncludeDirs := baseCompilerProps.Local_include_dirs

View File

@@ -305,6 +305,25 @@ func addToModuleList(ctx ModuleContext, key android.OnceKey, module string) {
getNamedMapForConfig(ctx.Config(), key).Store(module, true)
}
func maybeReplaceGnuToC(gnuExtensions *bool, cStd string, cppStd string) (string, string) {
if gnuExtensions != nil && *gnuExtensions == false {
cStd = gnuToCReplacer.Replace(cStd)
cppStd = gnuToCReplacer.Replace(cppStd)
}
return cStd, cppStd
}
func parseCppStd(cppStdPtr *string) string {
cppStd := String(cppStdPtr)
switch cppStd {
case "":
cppStd = config.CppStdVersion
case "experimental":
cppStd = config.ExperimentalCppStdVersion
}
return cppStd
}
// Create a Flags struct that collects the compile flags from global values,
// per-target values, module type values, and per-module Blueprints properties
func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags {
@@ -484,18 +503,9 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
cStd = String(compiler.Properties.C_std)
}
cppStd := String(compiler.Properties.Cpp_std)
switch String(compiler.Properties.Cpp_std) {
case "":
cppStd = config.CppStdVersion
case "experimental":
cppStd = config.ExperimentalCppStdVersion
}
cppStd := parseCppStd(compiler.Properties.Cpp_std)
if compiler.Properties.Gnu_extensions != nil && *compiler.Properties.Gnu_extensions == false {
cStd = gnuToCReplacer.Replace(cStd)
cppStd = gnuToCReplacer.Replace(cppStd)
}
cStd, cppStd = maybeReplaceGnuToC(compiler.Properties.Gnu_extensions, cStd, cppStd)
flags.Local.ConlyFlags = append([]string{"-std=" + cStd}, flags.Local.ConlyFlags...)
flags.Local.CppFlags = append([]string{"-std=" + cppStd}, flags.Local.CppFlags...)