Express no{,_lib}crt via features vs attrs
Given that we can map them directly to disabling the
corresponding Bazel features: `-{link_,use_lib}crt`
Test: Existing (adapted) Unit Tests
Test: bp2build.sh
Change-Id: Ib502f6fb929ace8e86a1001e3cc21f399317500c
diff --git a/cc/linker.go b/cc/linker.go
index 371d78d..e49b97d 100644
--- a/cc/linker.go
+++ b/cc/linker.go
@@ -237,29 +237,14 @@
Exclude_shared_libs []string `android:"arch_variant"`
}
-func invertBoolPtr(value *bool) *bool {
- if value == nil {
- return nil
- }
- ret := !(*value)
- return &ret
+func (blp *BaseLinkerProperties) crt() bool {
+ // Since crt is enabled for almost every module compiling against the Bionic runtime,
+ // we interpret `nil` as enabled.
+ return blp.Nocrt == nil || !*blp.Nocrt
}
-func (blp *BaseLinkerProperties) crt() *bool {
- val := invertBoolPtr(blp.Nocrt)
- if val != nil && *val {
- // == True
- //
- // Since crt is enabled for almost every module compiling against the Bionic runtime,
- // use `nil` when it's enabled, and rely on the Starlark macro to set it to True by default.
- // This keeps the BUILD files clean.
- return nil
- }
- return val // can be False or nil
-}
-
-func (blp *BaseLinkerProperties) libCrt() *bool {
- return invertBoolPtr(blp.No_libcrt)
+func (blp *BaseLinkerProperties) libCrt() bool {
+ return blp.No_libcrt == nil || !*blp.No_libcrt
}
func NewBaseLinker(sanitize *sanitize) *baseLinker {
@@ -392,7 +377,7 @@
if ctx.toolchain().Bionic() {
// libclang_rt.builtins has to be last on the command line
- if !Bool(linker.Properties.No_libcrt) && !ctx.header() {
+ if linker.Properties.libCrt() && !ctx.header() {
deps.UnexportedStaticLibs = append(deps.UnexportedStaticLibs, config.BuiltinsRuntimeLibrary(ctx.toolchain()))
}
@@ -415,7 +400,7 @@
ctx.PropertyErrorf("system_shared_libs", "libdl must be after libc")
}
} else if ctx.toolchain().Musl() {
- if !Bool(linker.Properties.No_libcrt) && !ctx.header() {
+ if linker.Properties.libCrt() && !ctx.header() {
deps.UnexportedStaticLibs = append(deps.UnexportedStaticLibs, config.BuiltinsRuntimeLibrary(ctx.toolchain()))
}
}