Build native libraries used by layoutlib.
Bug: 303904212
Test: m layoutlib dist; CIs
Change-Id: Id77cba97b2f66997431beb78ecc9d9b74b64b803
diff --git a/cc/binary.go b/cc/binary.go
index ebe672b..61541ad 100644
--- a/cc/binary.go
+++ b/cc/binary.go
@@ -445,6 +445,10 @@
return binary.unstrippedOutputFile
}
+func (binary *binaryDecorator) strippedAllOutputFilePath() android.Path {
+ panic("Not implemented.")
+}
+
func (binary *binaryDecorator) setSymlinkList(ctx ModuleContext) {
for _, symlink := range binary.Properties.Symlinks {
binary.symlinks = append(binary.symlinks,
diff --git a/cc/builder.go b/cc/builder.go
index 69cf75b..e4d5be2 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -1052,6 +1052,9 @@
if flags.StripKeepSymbolsAndDebugFrame {
args += " --keep-symbols-and-debug-frame"
}
+ if ctx.Windows() {
+ args += " --windows"
+ }
ctx.Build(pctx, android.BuildParams{
Rule: strip,
diff --git a/cc/cc.go b/cc/cc.go
index 12db797..7a06128 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -617,6 +617,7 @@
link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
appendLdflags([]string)
unstrippedOutputFilePath() android.Path
+ strippedAllOutputFilePath() android.Path
nativeCoverage() bool
coverageOutputFilePath() android.OptionalPath
@@ -3634,6 +3635,11 @@
return android.PathsIfNonNil(c.linker.unstrippedOutputFilePath()), nil
}
return nil, nil
+ case "stripped_all":
+ if c.linker != nil {
+ return android.PathsIfNonNil(c.linker.strippedAllOutputFilePath()), nil
+ }
+ return nil, nil
default:
return nil, fmt.Errorf("unsupported module reference tag %q", tag)
}
diff --git a/cc/cc_test.go b/cc/cc_test.go
index a1842d7..3631f19 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -4758,3 +4758,29 @@
})
}
}
+
+func TestStrippedAllOutputFile(t *testing.T) {
+ t.Parallel()
+ bp := `
+ cc_library {
+ name: "test_lib",
+ srcs: ["test_lib.cpp"],
+ dist: {
+ targets: [ "dist_target" ],
+ tag: "stripped_all",
+ }
+ }
+ `
+ config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
+ ctx := testCcWithConfig(t, config)
+ module := ctx.ModuleForTests("test_lib", "android_arm_armv7-a-neon_shared").Module()
+ outputFile, err := module.(android.OutputFileProducer).OutputFiles("stripped_all")
+ if err != nil {
+ t.Errorf("Expected cc_library to produce output files, error: %s", err)
+ return
+ }
+ if !strings.HasSuffix(outputFile.Strings()[0], "/stripped_all/test_lib.so") {
+ t.Errorf("Unexpected output file: %s", outputFile.Strings()[0])
+ return
+ }
+}
diff --git a/cc/library.go b/cc/library.go
index 2aa0b1b..4d5a254 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -400,6 +400,8 @@
// Location of the linked, unstripped library for shared libraries
unstrippedOutputFile android.Path
+ // Location of the linked, stripped library for shared libraries, strip: "all"
+ strippedAllOutputFile android.Path
// Location of the file that should be copied to dist dir when requested
distFile android.Path
@@ -1201,6 +1203,17 @@
}
}
+ // Generate an output file for dist as if strip: "all" is set on the module.
+ // Currently this is for layoutlib release process only.
+ for _, dist := range ctx.Module().(*Module).Dists() {
+ if dist.Tag != nil && *dist.Tag == "stripped_all" {
+ strippedAllOutputFile := android.PathForModuleOut(ctx, "stripped_all", fileName)
+ transformStrip(ctx, outputFile, strippedAllOutputFile, StripFlags{Toolchain: flags.Toolchain})
+ library.strippedAllOutputFile = strippedAllOutputFile
+ break
+ }
+ }
+
sharedLibs := deps.EarlySharedLibs
sharedLibs = append(sharedLibs, deps.SharedLibs...)
sharedLibs = append(sharedLibs, deps.LateSharedLibs...)
@@ -1262,6 +1275,10 @@
return library.unstrippedOutputFile
}
+func (library *libraryDecorator) strippedAllOutputFilePath() android.Path {
+ return library.strippedAllOutputFile
+}
+
func (library *libraryDecorator) disableStripping() {
library.stripper.StripProperties.Strip.None = BoolPtr(true)
}
diff --git a/cc/object.go b/cc/object.go
index b9c40d8..0dba99f 100644
--- a/cc/object.go
+++ b/cc/object.go
@@ -219,6 +219,10 @@
return nil
}
+func (object *objectLinker) strippedAllOutputFilePath() android.Path {
+ panic("Not implemented.")
+}
+
func (object *objectLinker) nativeCoverage() bool {
return true
}