rust: internalize srcPathFromModuleSrcs
This was frequently misused (for example, in the prebuilts module, it was used as a complex "assert(len(srcs))==1"), and can be superceded by getCrateRoot anywhere it was used. It's now only called from compiler.go, and can drop the second return parameter, as it was only actually used by the prebuilt assert misuse. Bug: 309943184 Test: m nothing Change-Id: I6c92580bc8f0ecb7586c544056b5409e6dd280e7
This commit is contained in:
parent
d221d31534
commit
1d8e20d744
5 changed files with 20 additions and 21 deletions
|
@ -137,12 +137,7 @@ func (binary *binaryDecorator) compile(ctx ModuleContext, flags Flags, deps Path
|
||||||
fileName := binary.getStem(ctx) + ctx.toolchain().ExecutableSuffix()
|
fileName := binary.getStem(ctx) + ctx.toolchain().ExecutableSuffix()
|
||||||
outputFile := android.PathForModuleOut(ctx, fileName)
|
outputFile := android.PathForModuleOut(ctx, fileName)
|
||||||
ret := buildOutput{outputFile: outputFile}
|
ret := buildOutput{outputFile: outputFile}
|
||||||
var crateRootPath android.Path
|
crateRootPath := binary.crateRootPath(ctx)
|
||||||
if binary.baseCompiler.Properties.Crate_root == nil {
|
|
||||||
crateRootPath, _ = srcPathFromModuleSrcs(ctx, binary.baseCompiler.Properties.Srcs)
|
|
||||||
} else {
|
|
||||||
crateRootPath = android.PathForModuleSrc(ctx, *binary.baseCompiler.Properties.Crate_root)
|
|
||||||
}
|
|
||||||
|
|
||||||
flags.RustFlags = append(flags.RustFlags, deps.depFlags...)
|
flags.RustFlags = append(flags.RustFlags, deps.depFlags...)
|
||||||
flags.LinkFlags = append(flags.LinkFlags, deps.depLinkFlags...)
|
flags.LinkFlags = append(flags.LinkFlags, deps.depLinkFlags...)
|
||||||
|
|
|
@ -541,7 +541,7 @@ func (compiler *baseCompiler) relativeInstallPath() string {
|
||||||
|
|
||||||
func (compiler *baseCompiler) crateRootPath(ctx ModuleContext) android.Path {
|
func (compiler *baseCompiler) crateRootPath(ctx ModuleContext) android.Path {
|
||||||
if compiler.Properties.Crate_root == nil {
|
if compiler.Properties.Crate_root == nil {
|
||||||
path, _ := srcPathFromModuleSrcs(ctx, compiler.Properties.Srcs)
|
path := srcPathFromModuleSrcs(ctx, compiler.Properties.Srcs)
|
||||||
return path
|
return path
|
||||||
} else {
|
} else {
|
||||||
return android.PathForModuleSrc(ctx, *compiler.Properties.Crate_root)
|
return android.PathForModuleSrc(ctx, *compiler.Properties.Crate_root)
|
||||||
|
@ -549,7 +549,7 @@ func (compiler *baseCompiler) crateRootPath(ctx ModuleContext) android.Path {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the Path for the main source file along with Paths for generated source files from modules listed in srcs.
|
// Returns the Path for the main source file along with Paths for generated source files from modules listed in srcs.
|
||||||
func srcPathFromModuleSrcs(ctx ModuleContext, srcs []string) (android.Path, android.Paths) {
|
func srcPathFromModuleSrcs(ctx ModuleContext, srcs []string) android.Path {
|
||||||
if len(srcs) == 0 {
|
if len(srcs) == 0 {
|
||||||
ctx.PropertyErrorf("srcs", "srcs must not be empty")
|
ctx.PropertyErrorf("srcs", "srcs must not be empty")
|
||||||
}
|
}
|
||||||
|
@ -580,5 +580,5 @@ func srcPathFromModuleSrcs(ctx ModuleContext, srcs []string) (android.Path, andr
|
||||||
// TODO: b/297264540 - once all modules are sandboxed, we need to select the proper
|
// TODO: b/297264540 - once all modules are sandboxed, we need to select the proper
|
||||||
// entry point file from Srcs rather than taking the first one
|
// entry point file from Srcs rather than taking the first one
|
||||||
paths := android.PathsForModuleSrc(ctx, srcs)
|
paths := android.PathsForModuleSrc(ctx, srcs)
|
||||||
return paths[srcIndex], paths[1:]
|
return paths[srcIndex]
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,6 +67,7 @@ func TestCfgsToFlags(t *testing.T) {
|
||||||
func TestEnforceSingleSourceFile(t *testing.T) {
|
func TestEnforceSingleSourceFile(t *testing.T) {
|
||||||
|
|
||||||
singleSrcError := "srcs can only contain one path for a rust file and source providers prefixed by \":\""
|
singleSrcError := "srcs can only contain one path for a rust file and source providers prefixed by \":\""
|
||||||
|
prebuiltSingleSrcError := "prebuilt libraries can only have one entry in srcs"
|
||||||
|
|
||||||
// Test libraries
|
// Test libraries
|
||||||
testRustError(t, singleSrcError, `
|
testRustError(t, singleSrcError, `
|
||||||
|
@ -90,7 +91,7 @@ func TestEnforceSingleSourceFile(t *testing.T) {
|
||||||
}`)
|
}`)
|
||||||
|
|
||||||
// Test prebuilts
|
// Test prebuilts
|
||||||
testRustError(t, singleSrcError, `
|
testRustError(t, prebuiltSingleSrcError, `
|
||||||
rust_prebuilt_dylib {
|
rust_prebuilt_dylib {
|
||||||
name: "foo-bar-prebuilt",
|
name: "foo-bar-prebuilt",
|
||||||
srcs: ["liby.so", "libz.so"],
|
srcs: ["liby.so", "libz.so"],
|
||||||
|
|
|
@ -76,6 +76,17 @@ var _ compiler = (*prebuiltProcMacroDecorator)(nil)
|
||||||
var _ exportedFlagsProducer = (*prebuiltProcMacroDecorator)(nil)
|
var _ exportedFlagsProducer = (*prebuiltProcMacroDecorator)(nil)
|
||||||
var _ rustPrebuilt = (*prebuiltProcMacroDecorator)(nil)
|
var _ rustPrebuilt = (*prebuiltProcMacroDecorator)(nil)
|
||||||
|
|
||||||
|
func prebuiltPath(ctx ModuleContext, prebuilt rustPrebuilt) android.Path {
|
||||||
|
srcs := android.PathsForModuleSrc(ctx, prebuilt.prebuiltSrcs())
|
||||||
|
if len(srcs) == 0 {
|
||||||
|
ctx.PropertyErrorf("srcs", "srcs must not be empty")
|
||||||
|
}
|
||||||
|
if len(srcs) > 1 {
|
||||||
|
ctx.PropertyErrorf("srcs", "prebuilt libraries can only have one entry in srcs (the prebuilt path)")
|
||||||
|
}
|
||||||
|
return srcs[0]
|
||||||
|
}
|
||||||
|
|
||||||
func PrebuiltLibraryFactory() android.Module {
|
func PrebuiltLibraryFactory() android.Module {
|
||||||
module, _ := NewPrebuiltLibrary(android.HostAndDeviceSupported)
|
module, _ := NewPrebuiltLibrary(android.HostAndDeviceSupported)
|
||||||
return module.Init()
|
return module.Init()
|
||||||
|
@ -148,11 +159,7 @@ func (prebuilt *prebuiltLibraryDecorator) compilerProps() []interface{} {
|
||||||
func (prebuilt *prebuiltLibraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) buildOutput {
|
func (prebuilt *prebuiltLibraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) buildOutput {
|
||||||
prebuilt.flagExporter.exportLinkDirs(android.PathsForModuleSrc(ctx, prebuilt.Properties.Link_dirs).Strings()...)
|
prebuilt.flagExporter.exportLinkDirs(android.PathsForModuleSrc(ctx, prebuilt.Properties.Link_dirs).Strings()...)
|
||||||
prebuilt.flagExporter.setProvider(ctx)
|
prebuilt.flagExporter.setProvider(ctx)
|
||||||
|
srcPath := prebuiltPath(ctx, prebuilt)
|
||||||
srcPath, paths := srcPathFromModuleSrcs(ctx, prebuilt.prebuiltSrcs())
|
|
||||||
if len(paths) > 0 {
|
|
||||||
ctx.PropertyErrorf("srcs", "prebuilt libraries can only have one entry in srcs (the prebuilt path)")
|
|
||||||
}
|
|
||||||
prebuilt.baseCompiler.unstrippedOutputFile = srcPath
|
prebuilt.baseCompiler.unstrippedOutputFile = srcPath
|
||||||
return buildOutput{outputFile: srcPath}
|
return buildOutput{outputFile: srcPath}
|
||||||
}
|
}
|
||||||
|
@ -205,11 +212,7 @@ func (prebuilt *prebuiltProcMacroDecorator) compilerProps() []interface{} {
|
||||||
func (prebuilt *prebuiltProcMacroDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) buildOutput {
|
func (prebuilt *prebuiltProcMacroDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) buildOutput {
|
||||||
prebuilt.flagExporter.exportLinkDirs(android.PathsForModuleSrc(ctx, prebuilt.Properties.Link_dirs).Strings()...)
|
prebuilt.flagExporter.exportLinkDirs(android.PathsForModuleSrc(ctx, prebuilt.Properties.Link_dirs).Strings()...)
|
||||||
prebuilt.flagExporter.setProvider(ctx)
|
prebuilt.flagExporter.setProvider(ctx)
|
||||||
|
srcPath := prebuiltPath(ctx, prebuilt)
|
||||||
srcPath, paths := srcPathFromModuleSrcs(ctx, prebuilt.prebuiltSrcs())
|
|
||||||
if len(paths) > 0 {
|
|
||||||
ctx.PropertyErrorf("srcs", "prebuilt libraries can only have one entry in srcs (the prebuilt path)")
|
|
||||||
}
|
|
||||||
prebuilt.baseCompiler.unstrippedOutputFile = srcPath
|
prebuilt.baseCompiler.unstrippedOutputFile = srcPath
|
||||||
return buildOutput{outputFile: srcPath}
|
return buildOutput{outputFile: srcPath}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ func (procMacro *procMacroDecorator) compile(ctx ModuleContext, flags Flags, dep
|
||||||
fileName := procMacro.getStem(ctx) + ctx.toolchain().ProcMacroSuffix()
|
fileName := procMacro.getStem(ctx) + ctx.toolchain().ProcMacroSuffix()
|
||||||
outputFile := android.PathForModuleOut(ctx, fileName)
|
outputFile := android.PathForModuleOut(ctx, fileName)
|
||||||
|
|
||||||
srcPath, _ := srcPathFromModuleSrcs(ctx, procMacro.baseCompiler.Properties.Srcs)
|
srcPath := procMacro.crateRootPath(ctx)
|
||||||
ret := TransformSrctoProcMacro(ctx, srcPath, deps, flags, outputFile)
|
ret := TransformSrctoProcMacro(ctx, srcPath, deps, flags, outputFile)
|
||||||
procMacro.baseCompiler.unstrippedOutputFile = outputFile
|
procMacro.baseCompiler.unstrippedOutputFile = outputFile
|
||||||
return ret
|
return ret
|
||||||
|
|
Loading…
Reference in a new issue