Build native libraries used by layoutlib.

Bug: 303904212
Test: m layoutlib dist; CIs
Change-Id: Id77cba97b2f66997431beb78ecc9d9b74b64b803
This commit is contained in:
Wei Li 2023-12-11 15:40:29 -08:00
parent 4e8a7e9974
commit 5f5d271fc3
7 changed files with 68 additions and 1 deletions

View file

@ -445,6 +445,10 @@ func (binary *binaryDecorator) unstrippedOutputFilePath() android.Path {
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,

View file

@ -1052,6 +1052,9 @@ func transformStrip(ctx android.ModuleContext, inputFile android.Path,
if flags.StripKeepSymbolsAndDebugFrame {
args += " --keep-symbols-and-debug-frame"
}
if ctx.Windows() {
args += " --windows"
}
ctx.Build(pctx, android.BuildParams{
Rule: strip,

View file

@ -617,6 +617,7 @@ type linker interface {
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 @@ func (c *Module) OutputFiles(tag string) (android.Paths, error) {
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)
}

View file

@ -4758,3 +4758,29 @@ func TestCcBuildBrokenClangCFlags(t *testing.T) {
})
}
}
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
}
}

View file

@ -400,6 +400,8 @@ type libraryDecorator struct {
// 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 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext,
}
}
// 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 @@ func (library *libraryDecorator) unstrippedOutputFilePath() android.Path {
return library.unstrippedOutputFile
}
func (library *libraryDecorator) strippedAllOutputFilePath() android.Path {
return library.strippedAllOutputFile
}
func (library *libraryDecorator) disableStripping() {
library.stripper.StripProperties.Strip.None = BoolPtr(true)
}

View file

@ -219,6 +219,10 @@ func (object *objectLinker) unstrippedOutputFilePath() android.Path {
return nil
}
func (object *objectLinker) strippedAllOutputFilePath() android.Path {
panic("Not implemented.")
}
func (object *objectLinker) nativeCoverage() bool {
return true
}

View file

@ -29,6 +29,7 @@
# --keep-symbols
# --keep-symbols-and-debug-frame
# --remove-build-id
# --windows
set -o pipefail
@ -43,6 +44,7 @@ Options:
--keep-symbols Keep symbols in out-file
--keep-symbols-and-debug-frame Keep symbols and .debug_frame in out-file
--remove-build-id Remove the gnu build-id section in out-file
--windows Input file is Windows DLL or executable
EOF
exit 1
}
@ -50,7 +52,11 @@ EOF
do_strip() {
# GNU strip --strip-all does not strip .ARM.attributes,
# so we tell llvm-strip to keep it too.
"${CLANG_BIN}/llvm-strip" --strip-all --keep-section=.ARM.attributes "${infile}" -o "${outfile}.tmp"
local keep_section=--keep-section=.ARM.attributes
if [ -n "${windows}" ]; then
keep_section=
fi
"${CLANG_BIN}/llvm-strip" --strip-all ${keep_section} "${infile}" -o "${outfile}.tmp"
}
do_strip_keep_symbols_and_debug_frame() {
@ -149,6 +155,7 @@ while getopts $OPTSTRING opt; do
keep-symbols) keep_symbols=true ;;
keep-symbols-and-debug-frame) keep_symbols_and_debug_frame=true ;;
remove-build-id) remove_build_id=true ;;
windows) windows=true ;;
*) echo "Unknown option --${OPTARG}"; usage ;;
esac;;
?) usage ;;