rust: Refactor stripped output file path
Rust installed files reside in "$MODULE_OUT/stripped/" when they are stripped, otherwise they reside in "$MODULE_OUT". However, other parts of Soong assume that installed files are always in $MODULE_OUT (cc_modules place *unstripped* files in $MODULE_OUT/unstripped). This notably causes problems when adding Rust modules as test data in AndroidMkDataPaths. When Rust modules are parsed by AndroidMkDataPaths, if they are stripped then they incorrectly get installed as test data with the path: <install_root>/<relative_install_path>/stripped/file. This CL refactors how we handle Rust stripped output such that the installed file always resides in $MODULE_OUT. Bug: 171710847 Test: Installed files now always reside in $MODULE_OUT Change-Id: I53a6ff57a0a5a55cd95ea78ae592ce22abfa20c9
This commit is contained in:
@@ -469,7 +469,7 @@ func (library *libraryDecorator) compilerFlags(ctx ModuleContext, flags Flags) F
|
||||
}
|
||||
|
||||
func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path {
|
||||
var outputFile android.ModuleOutPath
|
||||
var outputFile, ret android.ModuleOutPath
|
||||
var fileName string
|
||||
srcPath := library.srcPath(ctx, deps)
|
||||
|
||||
@@ -477,6 +477,34 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa
|
||||
deps.srcProviderFiles = append(deps.srcProviderFiles, library.sourceProvider.Srcs()...)
|
||||
}
|
||||
|
||||
// Calculate output filename
|
||||
if library.rlib() {
|
||||
fileName = library.getStem(ctx) + ctx.toolchain().RlibSuffix()
|
||||
outputFile = android.PathForModuleOut(ctx, fileName)
|
||||
ret = outputFile
|
||||
} else if library.dylib() {
|
||||
fileName = library.getStem(ctx) + ctx.toolchain().DylibSuffix()
|
||||
outputFile = android.PathForModuleOut(ctx, fileName)
|
||||
ret = outputFile
|
||||
} else if library.static() {
|
||||
fileName = library.getStem(ctx) + ctx.toolchain().StaticLibSuffix()
|
||||
outputFile = android.PathForModuleOut(ctx, fileName)
|
||||
ret = outputFile
|
||||
} else if library.shared() {
|
||||
fileName = library.sharedLibFilename(ctx)
|
||||
outputFile = android.PathForModuleOut(ctx, fileName)
|
||||
ret = outputFile
|
||||
}
|
||||
|
||||
if !library.rlib() && !library.static() && library.stripper.NeedsStrip(ctx) {
|
||||
strippedOutputFile := outputFile
|
||||
outputFile = android.PathForModuleOut(ctx, "unstripped", fileName)
|
||||
library.stripper.StripExecutableOrSharedLib(ctx, outputFile, strippedOutputFile)
|
||||
|
||||
library.baseCompiler.strippedOutputFile = android.OptionalPathForPath(strippedOutputFile)
|
||||
}
|
||||
library.baseCompiler.unstrippedOutputFile = outputFile
|
||||
|
||||
flags.RustFlags = append(flags.RustFlags, deps.depFlags...)
|
||||
flags.LinkFlags = append(flags.LinkFlags, deps.depLinkFlags...)
|
||||
flags.LinkFlags = append(flags.LinkFlags, deps.linkObjects...)
|
||||
@@ -488,34 +516,17 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa
|
||||
flags.RustFlags = append(flags.RustFlags, "-C prefer-dynamic")
|
||||
}
|
||||
|
||||
// Call the appropriate builder for this library type
|
||||
if library.rlib() {
|
||||
fileName = library.getStem(ctx) + ctx.toolchain().RlibSuffix()
|
||||
outputFile = android.PathForModuleOut(ctx, fileName)
|
||||
|
||||
TransformSrctoRlib(ctx, srcPath, deps, flags, outputFile)
|
||||
} else if library.dylib() {
|
||||
fileName = library.getStem(ctx) + ctx.toolchain().DylibSuffix()
|
||||
outputFile = android.PathForModuleOut(ctx, fileName)
|
||||
|
||||
TransformSrctoDylib(ctx, srcPath, deps, flags, outputFile)
|
||||
} else if library.static() {
|
||||
fileName = library.getStem(ctx) + ctx.toolchain().StaticLibSuffix()
|
||||
outputFile = android.PathForModuleOut(ctx, fileName)
|
||||
|
||||
TransformSrctoStatic(ctx, srcPath, deps, flags, outputFile)
|
||||
} else if library.shared() {
|
||||
fileName = library.sharedLibFilename(ctx)
|
||||
outputFile = android.PathForModuleOut(ctx, fileName)
|
||||
|
||||
TransformSrctoShared(ctx, srcPath, deps, flags, outputFile)
|
||||
}
|
||||
|
||||
if !library.rlib() && !library.static() && library.stripper.NeedsStrip(ctx) {
|
||||
strippedOutputFile := android.PathForModuleOut(ctx, "stripped", fileName)
|
||||
library.stripper.StripExecutableOrSharedLib(ctx, outputFile, strippedOutputFile)
|
||||
library.strippedOutputFile = android.OptionalPathForPath(strippedOutputFile)
|
||||
}
|
||||
|
||||
if library.rlib() || library.dylib() {
|
||||
library.flagExporter.exportLinkDirs(deps.linkDirs...)
|
||||
library.flagExporter.exportLinkObjects(deps.linkObjects...)
|
||||
@@ -552,7 +563,7 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa
|
||||
|
||||
library.flagExporter.setProvider(ctx)
|
||||
|
||||
return outputFile
|
||||
return ret
|
||||
}
|
||||
|
||||
func (library *libraryDecorator) srcPath(ctx ModuleContext, deps PathDeps) android.Path {
|
||||
|
Reference in New Issue
Block a user