Support tailoring clang --target flag based on min sdk version.
Bug: 215748260 Test: Tested using aquery to verify the --target flag; add added unit Change-Id: Ifb13509db7d1e110316aa44d55ec9cccaa4b83d1
This commit is contained in:
@@ -18,6 +18,8 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"android/soong/starlark_fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -380,3 +382,21 @@ func (a *apiLevelsSingleton) GenerateBuildActions(ctx SingletonContext) {
|
|||||||
apiLevelsJson := GetApiLevelsJson(ctx)
|
apiLevelsJson := GetApiLevelsJson(ctx)
|
||||||
createApiLevelsJson(ctx, apiLevelsJson, apiLevelsMap)
|
createApiLevelsJson(ctx, apiLevelsJson, apiLevelsMap)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func printApiLevelsStarlarkDict(config Config) string {
|
||||||
|
apiLevelsMap := GetApiLevelsMap(config)
|
||||||
|
valDict := make(map[string]string, len(apiLevelsMap))
|
||||||
|
for k, v := range apiLevelsMap {
|
||||||
|
valDict[k] = strconv.Itoa(v)
|
||||||
|
}
|
||||||
|
return starlark_fmt.PrintDict(valDict, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func StarlarkApiLevelConfigs(config Config) string {
|
||||||
|
return fmt.Sprintf(`# GENERATED FOR BAZEL FROM SOONG. DO NOT EDIT.
|
||||||
|
_api_levels = %s
|
||||||
|
|
||||||
|
api_levels = _api_levels
|
||||||
|
`, printApiLevelsStarlarkDict(config),
|
||||||
|
)
|
||||||
|
}
|
@@ -15,12 +15,13 @@
|
|||||||
package bp2build
|
package bp2build
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"android/soong/android"
|
|
||||||
"android/soong/cc"
|
|
||||||
"android/soong/genrule"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"android/soong/android"
|
||||||
|
"android/soong/cc"
|
||||||
|
"android/soong/genrule"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -127,6 +128,8 @@ func TestBasicCcBinary(t *testing.T) {
|
|||||||
keep_symbols_list: ["symbol"],
|
keep_symbols_list: ["symbol"],
|
||||||
none: true,
|
none: true,
|
||||||
},
|
},
|
||||||
|
sdk_version: "current",
|
||||||
|
min_sdk_version: "29",
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
targets: []testBazelTarget{
|
targets: []testBazelTarget{
|
||||||
@@ -150,6 +153,8 @@ func TestBasicCcBinary(t *testing.T) {
|
|||||||
"keep_symbols_list": ["symbol"],
|
"keep_symbols_list": ["symbol"],
|
||||||
"none": True,
|
"none": True,
|
||||||
}`,
|
}`,
|
||||||
|
"sdk_version": `"current"`,
|
||||||
|
"min_sdk_version": `"29"`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@@ -115,6 +115,8 @@ cc_library {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
include_build_directory: false,
|
include_build_directory: false,
|
||||||
|
sdk_version: "current",
|
||||||
|
min_sdk_version: "29",
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
expectedBazelTargets: makeCcLibraryTargets("foo-lib", attrNameToString{
|
expectedBazelTargets: makeCcLibraryTargets("foo-lib", attrNameToString{
|
||||||
@@ -140,6 +142,8 @@ cc_library {
|
|||||||
"//build/bazel/platforms/os:linux_bionic": ["bionic.cpp"],
|
"//build/bazel/platforms/os:linux_bionic": ["bionic.cpp"],
|
||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
})`,
|
})`,
|
||||||
|
"sdk_version": `"current"`,
|
||||||
|
"min_sdk_version": `"29"`,
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@@ -112,6 +112,8 @@ cc_library_headers {
|
|||||||
export_include_dirs: ["arch_x86_64_exported_include_dir"],
|
export_include_dirs: ["arch_x86_64_exported_include_dir"],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
sdk_version: "current",
|
||||||
|
min_sdk_version: "29",
|
||||||
|
|
||||||
// TODO: Also support export_header_lib_headers
|
// TODO: Also support export_header_lib_headers
|
||||||
}`,
|
}`,
|
||||||
@@ -130,6 +132,8 @@ cc_library_headers {
|
|||||||
":lib-1",
|
":lib-1",
|
||||||
":lib-2",
|
":lib-2",
|
||||||
]`,
|
]`,
|
||||||
|
"sdk_version": `"current"`,
|
||||||
|
"min_sdk_version": `"29"`,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@@ -136,6 +136,8 @@ cc_library_shared {
|
|||||||
"header_lib_1",
|
"header_lib_1",
|
||||||
"header_lib_2"
|
"header_lib_2"
|
||||||
],
|
],
|
||||||
|
sdk_version: "current",
|
||||||
|
min_sdk_version: "29",
|
||||||
|
|
||||||
// TODO: Also support export_header_lib_headers
|
// TODO: Also support export_header_lib_headers
|
||||||
}`,
|
}`,
|
||||||
@@ -174,6 +176,8 @@ cc_library_shared {
|
|||||||
":whole_static_lib_1",
|
":whole_static_lib_1",
|
||||||
":whole_static_lib_2",
|
":whole_static_lib_2",
|
||||||
]`,
|
]`,
|
||||||
|
"sdk_version": `"current"`,
|
||||||
|
"min_sdk_version": `"29"`,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@@ -166,6 +166,8 @@ cc_library_static {
|
|||||||
"header_lib_1",
|
"header_lib_1",
|
||||||
"header_lib_2"
|
"header_lib_2"
|
||||||
],
|
],
|
||||||
|
sdk_version: "current",
|
||||||
|
min_sdk_version: "29",
|
||||||
|
|
||||||
// TODO: Also support export_header_lib_headers
|
// TODO: Also support export_header_lib_headers
|
||||||
}`,
|
}`,
|
||||||
@@ -202,6 +204,8 @@ cc_library_static {
|
|||||||
":whole_static_lib_1",
|
":whole_static_lib_1",
|
||||||
":whole_static_lib_2",
|
":whole_static_lib_2",
|
||||||
]`,
|
]`,
|
||||||
|
"sdk_version": `"current"`,
|
||||||
|
"min_sdk_version": `"29"`,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@@ -55,6 +55,8 @@ func TestCcObjectSimple(t *testing.T) {
|
|||||||
"a/b/*.c"
|
"a/b/*.c"
|
||||||
],
|
],
|
||||||
exclude_srcs: ["a/b/exclude.c"],
|
exclude_srcs: ["a/b/exclude.c"],
|
||||||
|
sdk_version: "current",
|
||||||
|
min_sdk_version: "29",
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
expectedBazelTargets: []string{
|
expectedBazelTargets: []string{
|
||||||
@@ -71,6 +73,8 @@ func TestCcObjectSimple(t *testing.T) {
|
|||||||
]`,
|
]`,
|
||||||
"srcs": `["a/b/c.c"]`,
|
"srcs": `["a/b/c.c"]`,
|
||||||
"system_dynamic_deps": `[]`,
|
"system_dynamic_deps": `[]`,
|
||||||
|
"sdk_version": `"current"`,
|
||||||
|
"min_sdk_version": `"29"`,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@@ -36,6 +36,7 @@ func CreateSoongInjectionFiles(cfg android.Config, metrics CodegenMetrics) []Baz
|
|||||||
}
|
}
|
||||||
files = append(files, newFile("api_levels", GeneratedBuildFileName, `exports_files(["api_levels.json"])`))
|
files = append(files, newFile("api_levels", GeneratedBuildFileName, `exports_files(["api_levels.json"])`))
|
||||||
files = append(files, newFile("api_levels", "api_levels.json", string(apiLevelsContent)))
|
files = append(files, newFile("api_levels", "api_levels.json", string(apiLevelsContent)))
|
||||||
|
files = append(files, newFile("api_levels", "api_levels.bzl", android.StarlarkApiLevelConfigs(cfg)))
|
||||||
|
|
||||||
return files
|
return files
|
||||||
}
|
}
|
||||||
|
@@ -114,6 +114,10 @@ func TestCreateBazelFiles_Bp2Build_CreatesDefaultFiles(t *testing.T) {
|
|||||||
dir: "api_levels",
|
dir: "api_levels",
|
||||||
basename: "api_levels.json",
|
basename: "api_levels.json",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
dir: "api_levels",
|
||||||
|
basename: "api_levels.bzl",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(files) != len(expectedFilePaths) {
|
if len(files) != len(expectedFilePaths) {
|
||||||
|
@@ -630,6 +630,8 @@ func binaryBp2build(ctx android.TopDownMutatorContext, m *Module, typ string) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
Features: baseAttrs.features,
|
Features: baseAttrs.features,
|
||||||
|
|
||||||
|
sdkAttributes: bp2BuildParseSdkAttributes(m),
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.CreateBazelTargetModule(bazel.BazelTargetModuleProperties{
|
ctx.CreateBazelTargetModule(bazel.BazelTargetModuleProperties{
|
||||||
@@ -673,4 +675,6 @@ type binaryAttributes struct {
|
|||||||
Strip stripAttributes
|
Strip stripAttributes
|
||||||
|
|
||||||
Features bazel.StringListAttribute
|
Features bazel.StringListAttribute
|
||||||
|
|
||||||
|
sdkAttributes
|
||||||
}
|
}
|
||||||
|
@@ -52,6 +52,8 @@ type staticOrSharedAttributes struct {
|
|||||||
System_dynamic_deps bazel.LabelListAttribute
|
System_dynamic_deps bazel.LabelListAttribute
|
||||||
|
|
||||||
Enabled bazel.BoolAttribute
|
Enabled bazel.BoolAttribute
|
||||||
|
|
||||||
|
sdkAttributes
|
||||||
}
|
}
|
||||||
|
|
||||||
// groupSrcsByExtension partitions `srcs` into groups based on file extension.
|
// groupSrcsByExtension partitions `srcs` into groups based on file extension.
|
||||||
@@ -539,6 +541,18 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func bp2BuildParseSdkAttributes(module *Module) sdkAttributes {
|
||||||
|
return sdkAttributes {
|
||||||
|
Sdk_version: module.Properties.Sdk_version,
|
||||||
|
Min_sdk_version: module.Properties.Min_sdk_version,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type sdkAttributes struct {
|
||||||
|
Sdk_version *string
|
||||||
|
Min_sdk_version *string
|
||||||
|
}
|
||||||
|
|
||||||
// Convenience struct to hold all attributes parsed from linker properties.
|
// Convenience struct to hold all attributes parsed from linker properties.
|
||||||
type linkerAttributes struct {
|
type linkerAttributes struct {
|
||||||
deps bazel.LabelListAttribute
|
deps bazel.LabelListAttribute
|
||||||
|
@@ -316,6 +316,7 @@ func libraryBp2Build(ctx android.TopDownMutatorContext, m *Module) {
|
|||||||
Implementation_whole_archive_deps: linkerAttrs.implementationWholeArchiveDeps,
|
Implementation_whole_archive_deps: linkerAttrs.implementationWholeArchiveDeps,
|
||||||
Whole_archive_deps: *linkerAttrs.wholeArchiveDeps.Clone().Append(staticAttrs.Whole_archive_deps),
|
Whole_archive_deps: *linkerAttrs.wholeArchiveDeps.Clone().Append(staticAttrs.Whole_archive_deps),
|
||||||
System_dynamic_deps: *linkerAttrs.systemDynamicDeps.Clone().Append(staticAttrs.System_dynamic_deps),
|
System_dynamic_deps: *linkerAttrs.systemDynamicDeps.Clone().Append(staticAttrs.System_dynamic_deps),
|
||||||
|
sdkAttributes: bp2BuildParseSdkAttributes(m),
|
||||||
}
|
}
|
||||||
|
|
||||||
sharedCommonAttrs := staticOrSharedAttributes{
|
sharedCommonAttrs := staticOrSharedAttributes{
|
||||||
@@ -331,6 +332,7 @@ func libraryBp2Build(ctx android.TopDownMutatorContext, m *Module) {
|
|||||||
Implementation_dynamic_deps: *linkerAttrs.implementationDynamicDeps.Clone().Append(sharedAttrs.Implementation_dynamic_deps),
|
Implementation_dynamic_deps: *linkerAttrs.implementationDynamicDeps.Clone().Append(sharedAttrs.Implementation_dynamic_deps),
|
||||||
Whole_archive_deps: *linkerAttrs.wholeArchiveDeps.Clone().Append(sharedAttrs.Whole_archive_deps),
|
Whole_archive_deps: *linkerAttrs.wholeArchiveDeps.Clone().Append(sharedAttrs.Whole_archive_deps),
|
||||||
System_dynamic_deps: *linkerAttrs.systemDynamicDeps.Clone().Append(sharedAttrs.System_dynamic_deps),
|
System_dynamic_deps: *linkerAttrs.systemDynamicDeps.Clone().Append(sharedAttrs.System_dynamic_deps),
|
||||||
|
sdkAttributes: bp2BuildParseSdkAttributes(m),
|
||||||
}
|
}
|
||||||
|
|
||||||
staticTargetAttrs := &bazelCcLibraryStaticAttributes{
|
staticTargetAttrs := &bazelCcLibraryStaticAttributes{
|
||||||
@@ -2481,6 +2483,7 @@ func sharedOrStaticLibraryBp2Build(ctx android.TopDownMutatorContext, module *Mo
|
|||||||
Whole_archive_deps: linkerAttrs.wholeArchiveDeps,
|
Whole_archive_deps: linkerAttrs.wholeArchiveDeps,
|
||||||
Implementation_whole_archive_deps: linkerAttrs.implementationWholeArchiveDeps,
|
Implementation_whole_archive_deps: linkerAttrs.implementationWholeArchiveDeps,
|
||||||
System_dynamic_deps: linkerAttrs.systemDynamicDeps,
|
System_dynamic_deps: linkerAttrs.systemDynamicDeps,
|
||||||
|
sdkAttributes: bp2BuildParseSdkAttributes(module),
|
||||||
}
|
}
|
||||||
|
|
||||||
var attrs interface{}
|
var attrs interface{}
|
||||||
|
@@ -117,6 +117,7 @@ type bazelCcLibraryHeadersAttributes struct {
|
|||||||
Deps bazel.LabelListAttribute
|
Deps bazel.LabelListAttribute
|
||||||
Implementation_deps bazel.LabelListAttribute
|
Implementation_deps bazel.LabelListAttribute
|
||||||
System_dynamic_deps bazel.LabelListAttribute
|
System_dynamic_deps bazel.LabelListAttribute
|
||||||
|
sdkAttributes
|
||||||
}
|
}
|
||||||
|
|
||||||
func libraryHeadersBp2Build(ctx android.TopDownMutatorContext, module *Module) {
|
func libraryHeadersBp2Build(ctx android.TopDownMutatorContext, module *Module) {
|
||||||
@@ -132,6 +133,7 @@ func libraryHeadersBp2Build(ctx android.TopDownMutatorContext, module *Module) {
|
|||||||
Deps: linkerAttrs.deps,
|
Deps: linkerAttrs.deps,
|
||||||
System_dynamic_deps: linkerAttrs.systemDynamicDeps,
|
System_dynamic_deps: linkerAttrs.systemDynamicDeps,
|
||||||
Hdrs: baseAttributes.hdrs,
|
Hdrs: baseAttributes.hdrs,
|
||||||
|
sdkAttributes: bp2BuildParseSdkAttributes(module),
|
||||||
}
|
}
|
||||||
|
|
||||||
props := bazel.BazelTargetModuleProperties{
|
props := bazel.BazelTargetModuleProperties{
|
||||||
|
@@ -133,6 +133,7 @@ type bazelObjectAttributes struct {
|
|||||||
Absolute_includes bazel.StringListAttribute
|
Absolute_includes bazel.StringListAttribute
|
||||||
Stl *string
|
Stl *string
|
||||||
Linker_script bazel.LabelAttribute
|
Linker_script bazel.LabelAttribute
|
||||||
|
sdkAttributes
|
||||||
}
|
}
|
||||||
|
|
||||||
// objectBp2Build is the bp2build converter from cc_object modules to the
|
// objectBp2Build is the bp2build converter from cc_object modules to the
|
||||||
@@ -191,6 +192,7 @@ func objectBp2Build(ctx android.TopDownMutatorContext, m *Module) {
|
|||||||
Absolute_includes: compilerAttrs.absoluteIncludes,
|
Absolute_includes: compilerAttrs.absoluteIncludes,
|
||||||
Stl: compilerAttrs.stl,
|
Stl: compilerAttrs.stl,
|
||||||
Linker_script: linkerScript,
|
Linker_script: linkerScript,
|
||||||
|
sdkAttributes: bp2BuildParseSdkAttributes(m),
|
||||||
}
|
}
|
||||||
|
|
||||||
props := bazel.BazelTargetModuleProperties{
|
props := bazel.BazelTargetModuleProperties{
|
||||||
|
Reference in New Issue
Block a user