Merge "bp2build implementation for c_std" am: 93c3cb69bc am: cd37948bf8 am: 640ecbcd91 am: c604da7467

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

Change-Id: Ifda5afbaaad8b8ac49c8bb61c3d9bacaa7c7da10
This commit is contained in:
Christopher Parsons
2021-11-30 16:52:47 +00:00
committed by Automerger Merge Worker
5 changed files with 82 additions and 52 deletions

View File

@@ -252,6 +252,7 @@ type compilerAttributes struct {
// Not affected by arch variants
stl *string
cStd *string
cppStd *string
localIncludes bazel.StringListAttribute
@@ -278,8 +279,7 @@ func (ca *compilerAttributes) bp2buildForAxisAndConfig(ctx android.BazelConversi
localIncludeDirs := props.Local_include_dirs
if axis == bazel.NoConfigAxis {
ca.cppStd = bp2buildResolveCppStdValue(props.Cpp_std, props.Gnu_extensions)
ca.cStd, ca.cppStd = bp2buildResolveCppStdValue(props.C_std, props.Cpp_std, props.Gnu_extensions)
if includeBuildDirectory(props.Include_build_directory) {
localIncludeDirs = append(localIncludeDirs, ".")
}
@@ -371,24 +371,24 @@ func parseSrcs(ctx android.BazelConversionPathContext, props *BaseCompilerProper
return bazel.AppendBazelLabelLists(allSrcsLabelList, generatedSrcsLabelList), anySrcs
}
func bp2buildResolveCppStdValue(cpp_std *string, gnu_extensions *bool) *string {
var cppStd *string
// 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.
func bp2buildResolveCppStdValue(c_std *string, cpp_std *string, gnu_extensions *bool) (*string, *string) {
var cStdVal, cppStdVal string
// 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 {
// TODO(b/202491296): Handle C_std.
// These transformations are shared with compiler.go.
cppStdVal := parseCppStd(cpp_std)
_, cppStdVal = maybeReplaceGnuToC(gnu_extensions, "", cppStdVal)
cppStd = &cppStdVal
cppStdVal = parseCppStd(cpp_std)
} else if gnu_extensions != nil && !*gnu_extensions {
cppStdVal := "c++17"
cppStd = &cppStdVal
cppStdVal = "c++17"
}
return cppStd
if c_std != nil {
cStdVal = parseCStd(c_std)
} else if gnu_extensions != nil && !*gnu_extensions {
cStdVal = "c99"
}
cStdVal, cppStdVal = maybeReplaceGnuToC(gnu_extensions, cStdVal, cppStdVal)
return &cStdVal, &cppStdVal
}
// bp2BuildParseCompilerProps returns copts, srcs and hdrs and other attributes.

View File

@@ -304,11 +304,24 @@ func parseCppStd(cppStdPtr *string) string {
cppStd := String(cppStdPtr)
switch cppStd {
case "":
cppStd = config.CppStdVersion
return config.CppStdVersion
case "experimental":
cppStd = config.ExperimentalCppStdVersion
return config.ExperimentalCppStdVersion
default:
return cppStd
}
}
func parseCStd(cStdPtr *string) string {
cStd := String(cStdPtr)
switch cStd {
case "":
return config.CStdVersion
case "experimental":
return config.ExperimentalCStdVersion
default:
return cStd
}
return cppStd
}
// Create a Flags struct that collects the compile flags from global values,
@@ -479,13 +492,7 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
flags.Global.CommonFlags = append(flags.Global.CommonFlags, tc.ToolchainCflags())
cStd := config.CStdVersion
if String(compiler.Properties.C_std) == "experimental" {
cStd = config.ExperimentalCStdVersion
} else if String(compiler.Properties.C_std) != "" {
cStd = String(compiler.Properties.C_std)
}
cStd := parseCStd(compiler.Properties.C_std)
cppStd := parseCppStd(compiler.Properties.Cpp_std)
cStd, cppStd = maybeReplaceGnuToC(compiler.Properties.Gnu_extensions, cStd, cppStd)

View File

@@ -253,6 +253,7 @@ type bazelCcLibraryAttributes struct {
Stl *string
Cpp_std *string
C_std *string
// This is shared only.
Link_crt bazel.BoolAttribute
@@ -335,6 +336,7 @@ func CcLibraryBp2Build(ctx android.TopDownMutatorContext) {
Rtti: compilerAttrs.rtti,
Stl: compilerAttrs.stl,
Cpp_std: compilerAttrs.cppStd,
C_std: compilerAttrs.cStd,
Additional_linker_inputs: linkerAttrs.additionalLinkerInputs,
@@ -2420,6 +2422,7 @@ func ccSharedOrStaticBp2BuildMutatorInternal(ctx android.TopDownMutatorContext,
Rtti: compilerAttrs.rtti,
Stl: compilerAttrs.stl,
Cpp_std: compilerAttrs.cppStd,
C_std: compilerAttrs.cStd,
Export_includes: exportedIncludes.Includes,
Export_system_includes: exportedIncludes.SystemIncludes,
Local_includes: compilerAttrs.localIncludes,
@@ -2445,6 +2448,7 @@ func ccSharedOrStaticBp2BuildMutatorInternal(ctx android.TopDownMutatorContext,
Rtti: compilerAttrs.rtti,
Stl: compilerAttrs.stl,
Cpp_std: compilerAttrs.cppStd,
C_std: compilerAttrs.cStd,
Export_includes: exportedIncludes.Includes,
Export_system_includes: exportedIncludes.SystemIncludes,
@@ -2480,6 +2484,7 @@ type bazelCcLibraryStaticAttributes struct {
Rtti bazel.BoolAttribute
Stl *string
Cpp_std *string
C_std *string
Export_includes bazel.StringListAttribute
Export_system_includes bazel.StringListAttribute
@@ -2516,6 +2521,7 @@ type bazelCcLibrarySharedAttributes struct {
Rtti bazel.BoolAttribute
Stl *string
Cpp_std *string
C_std *string
Export_includes bazel.StringListAttribute
Export_system_includes bazel.StringListAttribute