Seperate asflags and cflags
This fixes a bug which was a misunderstanding of soong properties:
Soong's cflags pertain only to C and C++ language, whereas bazel's copts
pertain to all three languages. This change ensures that asflags are
added as specifically asflags, and the 'copts' for the static library
macro pertains only to C and C++ languages.
This requires a somewhat hacky workaround for asflags, however: Since
assembly sources also need includepath-related flags, this duplicates
these flags between copts and asflags. To reduce verbosity of
bp2build-generated targets, this also ensures that asflags are omitted
in cases where there are no assembly sources.
Test: Mixed build droid CI
Change-Id: Ic0babed1f90d6dc82e5788638681ce5b995043f8
diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go
index 285677a..4f720f5 100644
--- a/bp2build/cc_library_conversion_test.go
+++ b/bp2build/cc_library_conversion_test.go
@@ -674,6 +674,10 @@
blueprint: soongCcLibraryPreamble,
expectedBazelTargets: []string{`cc_library(
name = "a",
+ asflags = [
+ "-Ifoo/bar",
+ "-I$(BINDIR)/foo/bar",
+ ],
copts = [
"-Ifoo/bar",
"-I$(BINDIR)/foo/bar",
diff --git a/bp2build/cc_library_static_conversion_test.go b/bp2build/cc_library_static_conversion_test.go
index 40edec8..c33889f 100644
--- a/bp2build/cc_library_static_conversion_test.go
+++ b/bp2build/cc_library_static_conversion_test.go
@@ -1413,7 +1413,7 @@
func TestCcLibraryStaticProductVariableStringReplacement(t *testing.T) {
runCcLibraryStaticTestCase(t, bp2buildTestCase{
- description: "cc_library_static product variable selects",
+ description: "cc_library_static product variable string replacement",
moduleTypeUnderTest: "cc_library_static",
moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
@@ -1422,7 +1422,7 @@
blueprint: soongCcLibraryStaticPreamble + `
cc_library_static {
name: "foo_static",
- srcs: ["common.c"],
+ srcs: ["common.S"],
product_variables: {
platform_sdk_version: {
asflags: ["-DPLATFORM_SDK_VERSION=%d"],
@@ -1431,7 +1431,10 @@
} `,
expectedBazelTargets: []string{`cc_library_static(
name = "foo_static",
- asflags = select({
+ asflags = [
+ "-I.",
+ "-I$(BINDIR)/.",
+ ] + select({
"//build/bazel/product_variables:platform_sdk_version": ["-DPLATFORM_SDK_VERSION=$(Platform_sdk_version)"],
"//conditions:default": [],
}),
@@ -1440,7 +1443,7 @@
"-I$(BINDIR)/.",
],
linkstatic = True,
- srcs_c = ["common.c"],
+ srcs_as = ["common.S"],
)`},
})
}
diff --git a/bp2build/cc_object_conversion_test.go b/bp2build/cc_object_conversion_test.go
index 8ede226..df4924b 100644
--- a/bp2build/cc_object_conversion_test.go
+++ b/bp2build/cc_object_conversion_test.go
@@ -211,6 +211,7 @@
asflags: ["-DPLATFORM_SDK_VERSION=%d"],
},
},
+ srcs: ["src.S"],
}
`,
expectedBazelTargets: []string{`cc_object(
@@ -220,6 +221,7 @@
"//conditions:default": [],
}),
copts = ["-fno-addrsig"],
+ srcs_as = ["src.S"],
)`,
},
})
@@ -240,7 +242,7 @@
cflags: ["-fPIC"], // string list
},
arm: {
- srcs: ["arch/arm/file.S"], // label list
+ srcs: ["arch/arm/file.cpp"], // label list
},
},
}
@@ -257,7 +259,7 @@
"//conditions:default": [],
}),
srcs = ["a.cpp"] + select({
- "//build/bazel/platforms/arch:arm": ["arch/arm/file.S"],
+ "//build/bazel/platforms/arch:arm": ["arch/arm/file.cpp"],
"//conditions:default": [],
}),
)`,