Merge "Split local/absolute include into attributes"

This commit is contained in:
Liz Kammer 2021-09-13 21:21:09 +00:00 committed by Gerrit Code Review
commit 04e0a1551d
8 changed files with 84 additions and 125 deletions

View file

@ -255,13 +255,11 @@ cc_library {
blueprint: soongCcLibraryPreamble, blueprint: soongCcLibraryPreamble,
expectedBazelTargets: []string{`cc_library( expectedBazelTargets: []string{`cc_library(
name = "fake-libarm-optimized-routines-math", name = "fake-libarm-optimized-routines-math",
copts = [ copts = select({
"-Iexternal",
"-I$(BINDIR)/external",
] + select({
"//build/bazel/platforms/arch:arm64": ["-DHAVE_FAST_FMA=1"], "//build/bazel/platforms/arch:arm64": ["-DHAVE_FAST_FMA=1"],
"//conditions:default": [], "//conditions:default": [],
}), }),
local_includes = ["."],
srcs_c = ["math/cosf.c"], srcs_c = ["math/cosf.c"],
)`}, )`},
}) })
@ -494,12 +492,9 @@ cc_library_static { name: "android_dep_for_shared" }
blueprint: soongCcLibraryPreamble, blueprint: soongCcLibraryPreamble,
expectedBazelTargets: []string{`cc_library( expectedBazelTargets: []string{`cc_library(
name = "a", name = "a",
copts = [ copts = ["bothflag"],
"bothflag",
"-Ifoo/bar",
"-I$(BINDIR)/foo/bar",
],
implementation_deps = [":static_dep_for_both"], implementation_deps = [":static_dep_for_both"],
local_includes = ["."],
shared = { shared = {
"copts": ["sharedflag"] + select({ "copts": ["sharedflag"] + select({
"//build/bazel/platforms/arch:arm": ["-DARM_SHARED"], "//build/bazel/platforms/arch:arm": ["-DARM_SHARED"],
@ -635,14 +630,7 @@ filegroup {
blueprint: soongCcLibraryPreamble, blueprint: soongCcLibraryPreamble,
expectedBazelTargets: []string{`cc_library( expectedBazelTargets: []string{`cc_library(
name = "a", name = "a",
asflags = [ local_includes = ["."],
"-Ifoo/bar",
"-I$(BINDIR)/foo/bar",
],
copts = [
"-Ifoo/bar",
"-I$(BINDIR)/foo/bar",
],
shared = { shared = {
"srcs": [ "srcs": [
":shared_filegroup_cpp_srcs", ":shared_filegroup_cpp_srcs",

View file

@ -130,10 +130,6 @@ cc_library_headers {
}`, }`,
expectedBazelTargets: []string{`cc_library_headers( expectedBazelTargets: []string{`cc_library_headers(
name = "foo_headers", name = "foo_headers",
copts = [
"-I.",
"-I$(BINDIR)/.",
],
export_includes = [ export_includes = [
"dir-1", "dir-1",
"dir-2", "dir-2",

View file

@ -184,19 +184,13 @@ cc_library_static {
}`, }`,
expectedBazelTargets: []string{`cc_library_static( expectedBazelTargets: []string{`cc_library_static(
name = "foo_static", name = "foo_static",
absolute_includes = [
"include_dir_1",
"include_dir_2",
],
copts = [ copts = [
"-Dflag1", "-Dflag1",
"-Dflag2", "-Dflag2",
"-Iinclude_dir_1",
"-I$(BINDIR)/include_dir_1",
"-Iinclude_dir_2",
"-I$(BINDIR)/include_dir_2",
"-Ilocal_include_dir_1",
"-I$(BINDIR)/local_include_dir_1",
"-Ilocal_include_dir_2",
"-I$(BINDIR)/local_include_dir_2",
"-I.",
"-I$(BINDIR)/.",
], ],
export_includes = [ export_includes = [
"export_include_dir_1", "export_include_dir_1",
@ -209,6 +203,11 @@ cc_library_static {
":static_lib_2", ":static_lib_2",
], ],
linkstatic = True, linkstatic = True,
local_includes = [
"local_include_dir_1",
"local_include_dir_2",
".",
],
srcs = [ srcs = [
"foo_static1.cc", "foo_static1.cc",
"foo_static2.cc", "foo_static2.cc",
@ -244,21 +243,16 @@ func TestCcLibraryStaticSubpackage(t *testing.T) {
blueprint: soongCcLibraryStaticPreamble + ` blueprint: soongCcLibraryStaticPreamble + `
cc_library_static { cc_library_static {
name: "foo_static", name: "foo_static",
srcs: [ srcs: [],
],
include_dirs: [ include_dirs: [
"subpackage", "subpackage",
], ],
}`, }`,
expectedBazelTargets: []string{`cc_library_static( expectedBazelTargets: []string{`cc_library_static(
name = "foo_static", name = "foo_static",
copts = [ absolute_includes = ["subpackage"],
"-Isubpackage",
"-I$(BINDIR)/subpackage",
"-I.",
"-I$(BINDIR)/.",
],
linkstatic = True, linkstatic = True,
local_includes = ["."],
)`}, )`},
}) })
} }
@ -347,20 +341,17 @@ cc_library_static {
blueprint: soongCcLibraryStaticPreamble, blueprint: soongCcLibraryStaticPreamble,
expectedBazelTargets: []string{`cc_library_static( expectedBazelTargets: []string{`cc_library_static(
name = "foo_static", name = "foo_static",
copts = [ absolute_includes = [
"-Isubpackage/subsubpackage", "subpackage/subsubpackage",
"-I$(BINDIR)/subpackage/subsubpackage", "subpackage2",
"-Isubpackage2", "subpackage3/subsubpackage",
"-I$(BINDIR)/subpackage2",
"-Isubpackage3/subsubpackage",
"-I$(BINDIR)/subpackage3/subsubpackage",
"-Isubpackage/subsubpackage2",
"-I$(BINDIR)/subpackage/subsubpackage2",
"-Isubpackage",
"-I$(BINDIR)/subpackage",
], ],
export_includes = ["./exported_subsubpackage"], export_includes = ["./exported_subsubpackage"],
linkstatic = True, linkstatic = True,
local_includes = [
"subsubpackage2",
".",
],
)`}, )`},
}) })
} }
@ -386,13 +377,9 @@ cc_library_static {
}`, }`,
expectedBazelTargets: []string{`cc_library_static( expectedBazelTargets: []string{`cc_library_static(
name = "foo_static", name = "foo_static",
copts = [ absolute_includes = ["subpackage"],
"-Isubpackage",
"-I$(BINDIR)/subpackage",
"-Isubpackage2",
"-I$(BINDIR)/subpackage2",
],
linkstatic = True, linkstatic = True,
local_includes = ["subpackage2"],
)`}, )`},
}) })
} }
@ -420,15 +407,12 @@ cc_library_static {
}`, }`,
expectedBazelTargets: []string{`cc_library_static( expectedBazelTargets: []string{`cc_library_static(
name = "foo_static", name = "foo_static",
copts = [ absolute_includes = ["subpackage"],
"-Isubpackage",
"-I$(BINDIR)/subpackage",
"-Isubpackage2",
"-I$(BINDIR)/subpackage2",
"-I.",
"-I$(BINDIR)/.",
],
linkstatic = True, linkstatic = True,
local_includes = [
"subpackage2",
".",
],
)`}, )`},
}) })
} }

View file

@ -65,10 +65,10 @@ func TestCcObjectSimple(t *testing.T) {
"-Wno-gcc-compat", "-Wno-gcc-compat",
"-Wall", "-Wall",
"-Werror", "-Werror",
"-Iinclude", ],
"-I$(BINDIR)/include", local_includes = [
"-I.", "include",
"-I$(BINDIR)/.", ".",
], ],
srcs = ["a/b/c.c"], srcs = ["a/b/c.c"],
)`, )`,
@ -113,9 +113,8 @@ cc_defaults {
"-Wall", "-Wall",
"-Werror", "-Werror",
"-fno-addrsig", "-fno-addrsig",
"-I.",
"-I$(BINDIR)/.",
], ],
local_includes = ["."],
srcs = ["a/b/c.c"], srcs = ["a/b/c.c"],
)`, )`,
}}) }})

View file

@ -216,6 +216,9 @@ type compilerAttributes struct {
srcs bazel.LabelListAttribute srcs bazel.LabelListAttribute
rtti bazel.BoolAttribute rtti bazel.BoolAttribute
localIncludes bazel.StringListAttribute
absoluteIncludes bazel.StringListAttribute
} }
// bp2BuildParseCompilerProps returns copts, srcs and hdrs and other attributes. // bp2BuildParseCompilerProps returns copts, srcs and hdrs and other attributes.
@ -226,28 +229,8 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul
var conlyFlags bazel.StringListAttribute var conlyFlags bazel.StringListAttribute
var cppFlags bazel.StringListAttribute var cppFlags bazel.StringListAttribute
var rtti bazel.BoolAttribute var rtti bazel.BoolAttribute
var localIncludes bazel.StringListAttribute
// Creates the -I flags for a directory, while making the directory relative var absoluteIncludes bazel.StringListAttribute
// to the exec root for Bazel to work.
includeFlags := func(dir string) []string {
// filepath.Join canonicalizes the path, i.e. it takes care of . or .. elements.
moduleDirRootedPath := filepath.Join(ctx.ModuleDir(), dir)
return []string{
"-I" + moduleDirRootedPath,
// Include the bindir-rooted path (using make variable substitution). This most
// closely matches Bazel's native include path handling, which allows for dependency
// on generated headers in these directories.
// TODO(b/188084383): Handle local include directories in Bazel.
"-I$(BINDIR)/" + moduleDirRootedPath,
}
}
// Parse the list of module-relative include directories (-I).
parseLocalIncludeDirs := func(baseCompilerProps *BaseCompilerProperties) []string {
// include_dirs are root-relative, not module-relative.
includeDirs := bp2BuildMakePathsRelativeToModule(ctx, baseCompilerProps.Include_dirs)
return append(includeDirs, baseCompilerProps.Local_include_dirs...)
}
parseCommandLineFlags := func(soongFlags []string) []string { parseCommandLineFlags := func(soongFlags []string) []string {
var result []string var result []string
@ -285,18 +268,14 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul
archVariantCopts := parseCommandLineFlags(baseCompilerProps.Cflags) archVariantCopts := parseCommandLineFlags(baseCompilerProps.Cflags)
archVariantAsflags := parseCommandLineFlags(baseCompilerProps.Asflags) archVariantAsflags := parseCommandLineFlags(baseCompilerProps.Asflags)
for _, dir := range parseLocalIncludeDirs(baseCompilerProps) {
archVariantCopts = append(archVariantCopts, includeFlags(dir)...) localIncludeDirs := baseCompilerProps.Local_include_dirs
archVariantAsflags = append(archVariantAsflags, includeFlags(dir)...) if axis == bazel.NoConfigAxis && includeBuildDirectory(baseCompilerProps.Include_build_directory) {
localIncludeDirs = append(localIncludeDirs, ".")
} }
if axis == bazel.NoConfigAxis { absoluteIncludes.SetSelectValue(axis, config, baseCompilerProps.Include_dirs)
if includeBuildDirectory(baseCompilerProps.Include_build_directory) { localIncludes.SetSelectValue(axis, config, localIncludeDirs)
flags := includeFlags(".")
archVariantCopts = append(archVariantCopts, flags...)
archVariantAsflags = append(archVariantAsflags, flags...)
}
}
copts.SetSelectValue(axis, config, archVariantCopts) copts.SetSelectValue(axis, config, archVariantCopts)
asFlags.SetSelectValue(axis, config, archVariantAsflags) asFlags.SetSelectValue(axis, config, archVariantAsflags)
@ -308,6 +287,8 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul
} }
srcs.ResolveExcludes() srcs.ResolveExcludes()
absoluteIncludes.DeduplicateAxesFromBase()
localIncludes.DeduplicateAxesFromBase()
productVarPropNameToAttribute := map[string]*bazel.StringListAttribute{ productVarPropNameToAttribute := map[string]*bazel.StringListAttribute{
"Cflags": &copts, "Cflags": &copts,
@ -331,14 +312,16 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul
srcs, cSrcs, asSrcs := groupSrcsByExtension(ctx, srcs) srcs, cSrcs, asSrcs := groupSrcsByExtension(ctx, srcs)
return compilerAttributes{ return compilerAttributes{
copts: copts, copts: copts,
srcs: srcs, srcs: srcs,
asFlags: asFlags, asFlags: asFlags,
asSrcs: asSrcs, asSrcs: asSrcs,
cSrcs: cSrcs, cSrcs: cSrcs,
conlyFlags: conlyFlags, conlyFlags: conlyFlags,
cppFlags: cppFlags, cppFlags: cppFlags,
rtti: rtti, rtti: rtti,
localIncludes: localIncludes,
absoluteIncludes: absoluteIncludes,
} }
} }

View file

@ -236,6 +236,8 @@ type bazelCcLibraryAttributes struct {
System_dynamic_deps bazel.LabelListAttribute System_dynamic_deps bazel.LabelListAttribute
Export_includes bazel.StringListAttribute Export_includes bazel.StringListAttribute
Export_system_includes bazel.StringListAttribute Export_system_includes bazel.StringListAttribute
Local_includes bazel.StringListAttribute
Absolute_includes bazel.StringListAttribute
Linkopts bazel.StringListAttribute Linkopts bazel.StringListAttribute
Use_libcrt bazel.BoolAttribute Use_libcrt bazel.BoolAttribute
Rtti bazel.BoolAttribute Rtti bazel.BoolAttribute
@ -307,6 +309,8 @@ func CcLibraryBp2Build(ctx android.TopDownMutatorContext) {
System_dynamic_deps: linkerAttrs.systemDynamicDeps, System_dynamic_deps: linkerAttrs.systemDynamicDeps,
Export_includes: exportedIncludes.Includes, Export_includes: exportedIncludes.Includes,
Export_system_includes: exportedIncludes.SystemIncludes, Export_system_includes: exportedIncludes.SystemIncludes,
Local_includes: compilerAttrs.localIncludes,
Absolute_includes: compilerAttrs.absoluteIncludes,
Linkopts: linkerAttrs.linkopts, Linkopts: linkerAttrs.linkopts,
Use_libcrt: linkerAttrs.useLibcrt, Use_libcrt: linkerAttrs.useLibcrt,
Rtti: compilerAttrs.rtti, Rtti: compilerAttrs.rtti,
@ -2333,6 +2337,8 @@ type bazelCcLibraryStaticAttributes struct {
Rtti bazel.BoolAttribute Rtti bazel.BoolAttribute
Export_includes bazel.StringListAttribute Export_includes bazel.StringListAttribute
Export_system_includes bazel.StringListAttribute Export_system_includes bazel.StringListAttribute
Local_includes bazel.StringListAttribute
Absolute_includes bazel.StringListAttribute
Hdrs bazel.LabelListAttribute Hdrs bazel.LabelListAttribute
Cppflags bazel.StringListAttribute Cppflags bazel.StringListAttribute
@ -2384,6 +2390,8 @@ func ccLibraryStaticBp2BuildInternal(ctx android.TopDownMutatorContext, module *
Rtti: compilerAttrs.rtti, Rtti: compilerAttrs.rtti,
Export_includes: exportedIncludes.Includes, Export_includes: exportedIncludes.Includes,
Export_system_includes: exportedIncludes.SystemIncludes, Export_system_includes: exportedIncludes.SystemIncludes,
Local_includes: compilerAttrs.localIncludes,
Absolute_includes: compilerAttrs.absoluteIncludes,
Cppflags: compilerAttrs.cppFlags, Cppflags: compilerAttrs.cppFlags,
Srcs_c: compilerAttrs.cSrcs, Srcs_c: compilerAttrs.cSrcs,

View file

@ -103,7 +103,6 @@ func prebuiltLibraryHeaderFactory() android.Module {
} }
type bazelCcLibraryHeadersAttributes struct { type bazelCcLibraryHeadersAttributes struct {
Copts bazel.StringListAttribute
Hdrs bazel.LabelListAttribute Hdrs bazel.LabelListAttribute
Export_includes bazel.StringListAttribute Export_includes bazel.StringListAttribute
Export_system_includes bazel.StringListAttribute Export_system_includes bazel.StringListAttribute
@ -128,11 +127,9 @@ func CcLibraryHeadersBp2Build(ctx android.TopDownMutatorContext) {
} }
exportedIncludes := bp2BuildParseExportedIncludes(ctx, module) exportedIncludes := bp2BuildParseExportedIncludes(ctx, module)
compilerAttrs := bp2BuildParseCompilerProps(ctx, module)
linkerAttrs := bp2BuildParseLinkerProps(ctx, module) linkerAttrs := bp2BuildParseLinkerProps(ctx, module)
attrs := &bazelCcLibraryHeadersAttributes{ attrs := &bazelCcLibraryHeadersAttributes{
Copts: compilerAttrs.copts,
Export_includes: exportedIncludes.Includes, Export_includes: exportedIncludes.Includes,
Export_system_includes: exportedIncludes.SystemIncludes, Export_system_includes: exportedIncludes.SystemIncludes,
Implementation_deps: linkerAttrs.deps, Implementation_deps: linkerAttrs.deps,

View file

@ -122,12 +122,14 @@ func ObjectFactory() android.Module {
// For bp2build conversion. // For bp2build conversion.
type bazelObjectAttributes struct { type bazelObjectAttributes struct {
Srcs bazel.LabelListAttribute Srcs bazel.LabelListAttribute
Srcs_as bazel.LabelListAttribute Srcs_as bazel.LabelListAttribute
Hdrs bazel.LabelListAttribute Hdrs bazel.LabelListAttribute
Deps bazel.LabelListAttribute Deps bazel.LabelListAttribute
Copts bazel.StringListAttribute Copts bazel.StringListAttribute
Asflags bazel.StringListAttribute Asflags bazel.StringListAttribute
Local_includes bazel.StringListAttribute
Absolute_includes bazel.StringListAttribute
} }
// ObjectBp2Build is the bp2build converter from cc_object modules to the // ObjectBp2Build is the bp2build converter from cc_object modules to the
@ -170,11 +172,13 @@ func ObjectBp2Build(ctx android.TopDownMutatorContext) {
} }
attrs := &bazelObjectAttributes{ attrs := &bazelObjectAttributes{
Srcs: srcs, Srcs: srcs,
Srcs_as: compilerAttrs.asSrcs, Srcs_as: compilerAttrs.asSrcs,
Deps: deps, Deps: deps,
Copts: compilerAttrs.copts, Copts: compilerAttrs.copts,
Asflags: asFlags, Asflags: asFlags,
Local_includes: compilerAttrs.localIncludes,
Absolute_includes: compilerAttrs.absoluteIncludes,
} }
props := bazel.BazelTargetModuleProperties{ props := bazel.BazelTargetModuleProperties{