summaryrefslogtreecommitdiff
path: root/snapshot
diff options
context:
space:
mode:
author Justin Yun <justinyun@google.com> 2023-04-11 18:20:07 +0900
committer Justin Yun <justinyun@google.com> 2023-04-25 18:03:32 +0900
commit1db9748805147a69792b2a1a556689253c5b82f6 (patch)
tree91e03b649dff99a37f43f59060ea51a93895db22 /snapshot
parent28cbb75a09c313956ac356d006106bc0c58d94ac (diff)
Include license information for vendor and host snapshots
In addition to the license text files, include license kinds information to json file. Also, use the original paths of license text files that are copied to NOTICE_FILES directory. This will be used when generating snapshots from the snapshot build. Bug: 271539873 Test: m vendor-snapshot Change-Id: I0c0427bb66f2c1fca322d5554aa66220a3b62fb3
Diffstat (limited to 'snapshot')
-rw-r--r--snapshot/host_snapshot.go18
-rw-r--r--snapshot/snapshot.go28
-rw-r--r--snapshot/snapshot_base.go15
-rw-r--r--snapshot/util.go16
4 files changed, 64 insertions, 13 deletions
diff --git a/snapshot/host_snapshot.go b/snapshot/host_snapshot.go
index 9793218a3..edcc16348 100644
--- a/snapshot/host_snapshot.go
+++ b/snapshot/host_snapshot.go
@@ -96,6 +96,7 @@ func (f *hostSnapshot) CreateMetaData(ctx android.ModuleContext, fileName string
var jsonData []SnapshotJsonFlags
var metaPaths android.Paths
+ installedNotices := make(map[string]bool)
metaZipFile := android.PathForModuleOut(ctx, fileName).OutputPath
// Create JSON file based on the direct dependencies
@@ -104,12 +105,14 @@ func (f *hostSnapshot) CreateMetaData(ctx android.ModuleContext, fileName string
if desc != nil {
jsonData = append(jsonData, *desc)
}
- if len(dep.EffectiveLicenseFiles()) > 0 {
- noticeFile := android.PathForModuleOut(ctx, "NOTICE_FILES", dep.Name()+".txt").OutputPath
- android.CatFileRule(ctx, dep.EffectiveLicenseFiles(), noticeFile)
- metaPaths = append(metaPaths, noticeFile)
+ for _, notice := range dep.EffectiveLicenseFiles() {
+ if _, ok := installedNotices[notice.String()]; !ok {
+ installedNotices[notice.String()] = true
+ noticeOut := android.PathForModuleOut(ctx, "NOTICE_FILES", notice.String()).OutputPath
+ CopyFileToOutputPathRule(pctx, ctx, notice, noticeOut)
+ metaPaths = append(metaPaths, noticeOut)
+ }
}
-
})
// Sort notice paths and json data for repeatble build
sort.Slice(jsonData, func(i, j int) bool {
@@ -220,8 +223,7 @@ func hostJsonDesc(m android.Module) *SnapshotJsonFlags {
}
if path.Valid() && path.String() != "" {
- return &SnapshotJsonFlags{
- ModuleName: m.Name(),
+ props := &SnapshotJsonFlags{
ModuleStemName: moduleStem,
Filename: path.String(),
Required: append(m.HostRequiredModuleNames(), m.RequiredModuleNames()...),
@@ -229,6 +231,8 @@ func hostJsonDesc(m android.Module) *SnapshotJsonFlags {
RustProcMacro: procMacro,
CrateName: crateName,
}
+ props.InitBaseSnapshotProps(m)
+ return props
}
return nil
}
diff --git a/snapshot/snapshot.go b/snapshot/snapshot.go
index 206ecc947..c95a53774 100644
--- a/snapshot/snapshot.go
+++ b/snapshot/snapshot.go
@@ -26,6 +26,10 @@ import (
var pctx = android.NewPackageContext("android/soong/snapshot")
+func init() {
+ pctx.Import("android/soong/android")
+}
+
type SnapshotSingleton struct {
// Name, e.g., "vendor", "recovery", "ramdisk".
name string
@@ -48,8 +52,18 @@ type SnapshotSingleton struct {
Fake bool
}
+// The output files to be included in the snapshot.
+type SnapshotPaths struct {
+ // All files to be included in the snapshot
+ OutputFiles android.Paths
+
+ // Notice files of the snapshot output files
+ NoticeFiles android.Paths
+}
+
// Interface of function to capture snapshot from each module
-type GenerateSnapshotAction func(snapshot SnapshotSingleton, ctx android.SingletonContext, snapshotArchDir string) android.Paths
+// Returns snapshot ouputs and notice files.
+type GenerateSnapshotAction func(snapshot SnapshotSingleton, ctx android.SingletonContext, snapshotArchDir string) SnapshotPaths
var snapshotActionList []GenerateSnapshotAction
@@ -74,9 +88,19 @@ func (c *SnapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) {
snapshotDir = filepath.Join("fake", snapshotDir)
}
snapshotArchDir := filepath.Join(snapshotDir, ctx.DeviceConfig().DeviceArch())
+ noticeDir := filepath.Join(snapshotArchDir, "NOTICE_FILES")
+ installedNotices := make(map[string]bool)
for _, f := range snapshotActionList {
- snapshotOutputs = append(snapshotOutputs, f(*c, ctx, snapshotArchDir)...)
+ snapshotPaths := f(*c, ctx, snapshotArchDir)
+ snapshotOutputs = append(snapshotOutputs, snapshotPaths.OutputFiles...)
+ for _, notice := range snapshotPaths.NoticeFiles {
+ if _, ok := installedNotices[notice.String()]; !ok {
+ installedNotices[notice.String()] = true
+ snapshotOutputs = append(snapshotOutputs, CopyFileRule(
+ pctx, ctx, notice, filepath.Join(noticeDir, notice.String())))
+ }
+ }
}
// All artifacts are ready. Sort them to normalize ninja and then zip.
diff --git a/snapshot/snapshot_base.go b/snapshot/snapshot_base.go
index 809ca3d11..fb4ee0c83 100644
--- a/snapshot/snapshot_base.go
+++ b/snapshot/snapshot_base.go
@@ -120,4 +120,19 @@ type SnapshotJsonFlags struct {
// dependencies
Required []string `json:",omitempty"`
Overrides []string `json:",omitempty"`
+
+ // license information
+ LicenseKinds []string `json:",omitempty"`
+ LicenseTexts []string `json:",omitempty"`
+}
+
+func (prop *SnapshotJsonFlags) InitBaseSnapshotPropsWithName(m android.Module, name string) {
+ prop.ModuleName = name
+
+ prop.LicenseKinds = m.EffectiveLicenseKinds()
+ prop.LicenseTexts = m.EffectiveLicenseFiles().Strings()
+}
+
+func (prop *SnapshotJsonFlags) InitBaseSnapshotProps(m android.Module) {
+ prop.InitBaseSnapshotPropsWithName(m, m.Name())
}
diff --git a/snapshot/util.go b/snapshot/util.go
index 806ac90fa..c87c508e6 100644
--- a/snapshot/util.go
+++ b/snapshot/util.go
@@ -21,17 +21,25 @@ func WriteStringToFileRule(ctx android.SingletonContext, content, out string) an
return outPath
}
-func CopyFileRule(pctx android.PackageContext, ctx android.SingletonContext, path android.Path, out string) android.OutputPath {
- outPath := android.PathForOutput(ctx, out)
+type buildContext interface {
+ Build(pctx android.PackageContext, params android.BuildParams)
+}
+
+func CopyFileToOutputPathRule(pctx android.PackageContext, ctx buildContext, path android.Path, outPath android.OutputPath) {
ctx.Build(pctx, android.BuildParams{
Rule: android.Cp,
Input: path,
Output: outPath,
- Description: "copy " + path.String() + " -> " + out,
+ Description: "copy " + path.String() + " -> " + outPath.String(),
Args: map[string]string{
- "cpFlags": "-f -L",
+ "cpFlags": "-L",
},
})
+}
+
+func CopyFileRule(pctx android.PackageContext, ctx android.SingletonContext, path android.Path, out string) android.OutputPath {
+ outPath := android.PathForOutput(ctx, out)
+ CopyFileToOutputPathRule(pctx, ctx, path, outPath)
return outPath
}