summaryrefslogtreecommitdiff
path: root/rust/prebuilt.go
diff options
context:
space:
mode:
author Matthew Maurer <mmaurer@google.com> 2023-11-22 20:37:27 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2023-11-22 20:37:27 +0000
commitb103659c0b9e883401d482168731d194b2c6657c (patch)
tree9561013968ca2af25b30e9bf8dd1e4de5416912d /rust/prebuilt.go
parentf7474880a152b8423231b70d597c8a949ae2ab01 (diff)
parentdb72f7ed803df370951f7a03bd6f6fcad1b357e2 (diff)
Merge changes I0caddbf6,Iee20b060,I6c92580b,I45028945,Ia7dd5220, ... into main
* changes: rust: Resolve crate roots outside rust-project rust: Cache crateRootPath to avoid ctx rust: internalize srcPathFromModuleSrcs rust: move crateRootPath to compiler rust: Privatize Cargo* methods on compiler rust: Move compiler interface to compiler.go
Diffstat (limited to 'rust/prebuilt.go')
-rw-r--r--rust/prebuilt.go23
1 files changed, 13 insertions, 10 deletions
diff --git a/rust/prebuilt.go b/rust/prebuilt.go
index fe9d0b5dd..e35e510da 100644
--- a/rust/prebuilt.go
+++ b/rust/prebuilt.go
@@ -76,6 +76,17 @@ var _ compiler = (*prebuiltProcMacroDecorator)(nil)
var _ exportedFlagsProducer = (*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 {
module, _ := NewPrebuiltLibrary(android.HostAndDeviceSupported)
return module.Init()
@@ -148,11 +159,7 @@ func (prebuilt *prebuiltLibraryDecorator) compilerProps() []interface{} {
func (prebuilt *prebuiltLibraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) buildOutput {
prebuilt.flagExporter.exportLinkDirs(android.PathsForModuleSrc(ctx, prebuilt.Properties.Link_dirs).Strings()...)
prebuilt.flagExporter.setProvider(ctx)
-
- 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)")
- }
+ srcPath := prebuiltPath(ctx, prebuilt)
prebuilt.baseCompiler.unstrippedOutputFile = 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 {
prebuilt.flagExporter.exportLinkDirs(android.PathsForModuleSrc(ctx, prebuilt.Properties.Link_dirs).Strings()...)
prebuilt.flagExporter.setProvider(ctx)
-
- 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)")
- }
+ srcPath := prebuiltPath(ctx, prebuilt)
prebuilt.baseCompiler.unstrippedOutputFile = srcPath
return buildOutput{outputFile: srcPath}
}