summaryrefslogtreecommitdiff
path: root/snapshot
diff options
context:
space:
mode:
author Ivan Lozano <ivanlozano@google.com> 2022-03-23 17:31:39 -0400
committer Ivan Lozano <ivanlozano@google.com> 2022-03-25 09:25:07 -0400
commit872d579a22cd8e2d34a9baf8d892346e4ac71d27 (patch)
tree82273711859c3094e83a80de9ee34a6d36e60e8d /snapshot
parent057beb21468ec738d6d9325a46d6e8ca77fef00b (diff)
rust: rust_proc_macro host snapshot support.
Adds support for capturing rust_proc_macros as part of the host snapshot. Proc macros target the host and can be thought of as compiler plugins. Because of this, they don't have vendor image variants and can't be easily captured as part of the vendor snapshot. Instead we capture them as part of the host snapshot. This adds a rust_prebuilt_proc_macro module type. Bug: 204304380 Test: m HOST_FAKE_SNAPSHOT_ENABLE=true host-fake-snapshot dist Test: python3 development/vendor_snapshot/update.py --image=host --install-dir=vendor/vendor_name/ 31 --local out/dist Test: Checked Android.bp for rust_prebuilt_proc_macro modules. Change-Id: I4a8c4d9c41b7ca361b5b97d3f74973918c2a5fe3
Diffstat (limited to 'snapshot')
-rw-r--r--snapshot/host_fake_snapshot.go4
-rw-r--r--snapshot/host_snapshot.go32
-rw-r--r--snapshot/snapshot_base.go2
3 files changed, 29 insertions, 9 deletions
diff --git a/snapshot/host_fake_snapshot.go b/snapshot/host_fake_snapshot.go
index 6b4e12b05..1a75f3a65 100644
--- a/snapshot/host_fake_snapshot.go
+++ b/snapshot/host_fake_snapshot.go
@@ -114,13 +114,13 @@ func (c *hostFakeSingleton) GenerateBuildActions(ctx android.SingletonContext) {
if !apexInfo.IsForPlatform() {
return
}
- path := hostBinToolPath(module)
+ path := hostToolPath(module)
if path.Valid() && path.String() != "" {
outFile := filepath.Join(c.snapshotDir, path.String())
if !seen[outFile] {
seen[outFile] = true
outputs = append(outputs, WriteStringToFileRule(ctx, "", outFile))
- jsonData = append(jsonData, *hostBinJsonDesc(module))
+ jsonData = append(jsonData, *hostJsonDesc(module))
}
}
})
diff --git a/snapshot/host_snapshot.go b/snapshot/host_snapshot.go
index 09a382e6e..75b5e889f 100644
--- a/snapshot/host_snapshot.go
+++ b/snapshot/host_snapshot.go
@@ -19,6 +19,7 @@ import (
"fmt"
"path/filepath"
"sort"
+ "strings"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
@@ -62,6 +63,11 @@ type hostSnapshot struct {
installDir android.InstallPath
}
+type ProcMacro interface {
+ ProcMacro() bool
+ CrateName() string
+}
+
func hostSnapshotFactory() android.Module {
module := &hostSnapshot{}
initHostToolsModule(module)
@@ -94,7 +100,7 @@ func (f *hostSnapshot) CreateMetaData(ctx android.ModuleContext, fileName string
// Create JSON file based on the direct dependencies
ctx.VisitDirectDeps(func(dep android.Module) {
- desc := hostBinJsonDesc(dep)
+ desc := hostJsonDesc(dep)
if desc != nil {
jsonData = append(jsonData, *desc)
}
@@ -183,7 +189,7 @@ func (f *hostSnapshot) AndroidMkEntries() []android.AndroidMkEntries {
}
// Get host tools path and relative install string helpers
-func hostBinToolPath(m android.Module) android.OptionalPath {
+func hostToolPath(m android.Module) android.OptionalPath {
if provider, ok := m.(android.HostToolProvider); ok {
return provider.HostToolPath()
}
@@ -198,18 +204,30 @@ func hostRelativePathString(m android.Module) string {
return outString
}
-// Create JSON description for given module, only create descriptions for binary modueles which
-// provide a valid HostToolPath
-func hostBinJsonDesc(m android.Module) *SnapshotJsonFlags {
- path := hostBinToolPath(m)
+// Create JSON description for given module, only create descriptions for binary modules
+// and rust_proc_macro modules which provide a valid HostToolPath
+func hostJsonDesc(m android.Module) *SnapshotJsonFlags {
+ path := hostToolPath(m)
relPath := hostRelativePathString(m)
+ procMacro := false
+ moduleStem := filepath.Base(path.String())
+ crateName := ""
+
+ if pm, ok := m.(ProcMacro); ok && pm.ProcMacro() {
+ procMacro = pm.ProcMacro()
+ moduleStem = strings.TrimSuffix(moduleStem, filepath.Ext(moduleStem))
+ crateName = pm.CrateName()
+ }
+
if path.Valid() && path.String() != "" {
return &SnapshotJsonFlags{
ModuleName: m.Name(),
- ModuleStemName: filepath.Base(path.String()),
+ ModuleStemName: moduleStem,
Filename: path.String(),
Required: append(m.HostRequiredModuleNames(), m.RequiredModuleNames()...),
RelativeInstallPath: relPath,
+ RustProcMacro: procMacro,
+ CrateName: crateName,
}
}
return nil
diff --git a/snapshot/snapshot_base.go b/snapshot/snapshot_base.go
index 79d3cf6f3..4a14f2e03 100644
--- a/snapshot/snapshot_base.go
+++ b/snapshot/snapshot_base.go
@@ -114,6 +114,8 @@ type SnapshotJsonFlags struct {
RelativeInstallPath string `json:",omitempty"`
Filename string `json:",omitempty"`
ModuleStemName string `json:",omitempty"`
+ RustProcMacro bool `json:",omitempty"`
+ CrateName string `json:",omitempty"`
// dependencies
Required []string `json:",omitempty"`