Merge "Include license information for vendor and host snapshots"
This commit is contained in:
11
cc/util.go
11
cc/util.go
@@ -100,17 +100,6 @@ func makeSymlinkCmd(linkDirOnDevice string, linkName string, target string) stri
|
|||||||
"ln -sf " + target + " " + filepath.Join(dir, linkName)
|
"ln -sf " + target + " " + filepath.Join(dir, linkName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func combineNoticesRule(ctx android.SingletonContext, paths android.Paths, out string) android.OutputPath {
|
|
||||||
outPath := android.PathForOutput(ctx, out)
|
|
||||||
ctx.Build(pctx, android.BuildParams{
|
|
||||||
Rule: android.Cat,
|
|
||||||
Inputs: paths,
|
|
||||||
Output: outPath,
|
|
||||||
Description: "combine notices for " + out,
|
|
||||||
})
|
|
||||||
return outPath
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dump a map to a list file as:
|
// Dump a map to a list file as:
|
||||||
//
|
//
|
||||||
// {key1} {value1}
|
// {key1} {value1}
|
||||||
|
@@ -160,7 +160,7 @@ type snapshotJsonFlags struct {
|
|||||||
MinSdkVersion string `json:",omitempty"`
|
MinSdkVersion string `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var ccSnapshotAction snapshot.GenerateSnapshotAction = func(s snapshot.SnapshotSingleton, ctx android.SingletonContext, snapshotArchDir string) android.Paths {
|
var ccSnapshotAction snapshot.GenerateSnapshotAction = func(s snapshot.SnapshotSingleton, ctx android.SingletonContext, snapshotArchDir string) snapshot.SnapshotPaths {
|
||||||
/*
|
/*
|
||||||
Vendor snapshot zipped artifacts directory structure for cc modules:
|
Vendor snapshot zipped artifacts directory structure for cc modules:
|
||||||
{SNAPSHOT_ARCH}/
|
{SNAPSHOT_ARCH}/
|
||||||
@@ -195,10 +195,10 @@ var ccSnapshotAction snapshot.GenerateSnapshotAction = func(s snapshot.SnapshotS
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
var snapshotOutputs android.Paths
|
var snapshotOutputs android.Paths
|
||||||
|
var snapshotNotices android.Paths
|
||||||
|
|
||||||
includeDir := filepath.Join(snapshotArchDir, "include")
|
includeDir := filepath.Join(snapshotArchDir, "include")
|
||||||
configsDir := filepath.Join(snapshotArchDir, "configs")
|
configsDir := filepath.Join(snapshotArchDir, "configs")
|
||||||
noticeDir := filepath.Join(snapshotArchDir, "NOTICE_FILES")
|
|
||||||
|
|
||||||
installedNotices := make(map[string]bool)
|
installedNotices := make(map[string]bool)
|
||||||
installedConfigs := make(map[string]bool)
|
installedConfigs := make(map[string]bool)
|
||||||
@@ -228,7 +228,7 @@ var ccSnapshotAction snapshot.GenerateSnapshotAction = func(s snapshot.SnapshotS
|
|||||||
prop := snapshotJsonFlags{}
|
prop := snapshotJsonFlags{}
|
||||||
|
|
||||||
// Common properties among snapshots.
|
// Common properties among snapshots.
|
||||||
prop.ModuleName = ctx.ModuleName(m)
|
prop.InitBaseSnapshotPropsWithName(m, ctx.ModuleName(m))
|
||||||
if supportsVndkExt(s.Image) && m.IsVndkExt() {
|
if supportsVndkExt(s.Image) && m.IsVndkExt() {
|
||||||
// vndk exts are installed to /vendor/lib(64)?/vndk(-sp)?
|
// vndk exts are installed to /vendor/lib(64)?/vndk(-sp)?
|
||||||
if m.IsVndkSp() {
|
if m.IsVndkSp() {
|
||||||
@@ -406,13 +406,10 @@ var ccSnapshotAction snapshot.GenerateSnapshotAction = func(s snapshot.SnapshotS
|
|||||||
headers = append(headers, m.SnapshotHeaders()...)
|
headers = append(headers, m.SnapshotHeaders()...)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(m.EffectiveLicenseFiles()) > 0 {
|
for _, notice := range m.EffectiveLicenseFiles() {
|
||||||
noticeName := ctx.ModuleName(m) + ".txt"
|
if _, ok := installedNotices[notice.String()]; !ok {
|
||||||
noticeOut := filepath.Join(noticeDir, noticeName)
|
installedNotices[notice.String()] = true
|
||||||
// skip already copied notice file
|
snapshotNotices = append(snapshotNotices, notice)
|
||||||
if !installedNotices[noticeOut] {
|
|
||||||
installedNotices[noticeOut] = true
|
|
||||||
snapshotOutputs = append(snapshotOutputs, combineNoticesRule(ctx, m.EffectiveLicenseFiles(), noticeOut))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -422,7 +419,7 @@ var ccSnapshotAction snapshot.GenerateSnapshotAction = func(s snapshot.SnapshotS
|
|||||||
snapshotOutputs = append(snapshotOutputs, copyFile(ctx, header, filepath.Join(includeDir, header.String()), s.Fake))
|
snapshotOutputs = append(snapshotOutputs, copyFile(ctx, header, filepath.Join(includeDir, header.String()), s.Fake))
|
||||||
}
|
}
|
||||||
|
|
||||||
return snapshotOutputs
|
return snapshot.SnapshotPaths{OutputFiles: snapshotOutputs, NoticeFiles: snapshotNotices}
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@@ -617,7 +617,7 @@ func isSnapshotAware(ctx android.SingletonContext, m *PrebuiltEtc, image snapsho
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func generatePrebuiltSnapshot(s snapshot.SnapshotSingleton, ctx android.SingletonContext, snapshotArchDir string) android.Paths {
|
func generatePrebuiltSnapshot(s snapshot.SnapshotSingleton, ctx android.SingletonContext, snapshotArchDir string) snapshot.SnapshotPaths {
|
||||||
/*
|
/*
|
||||||
Snapshot zipped artifacts directory structure for etc modules:
|
Snapshot zipped artifacts directory structure for etc modules:
|
||||||
{SNAPSHOT_ARCH}/
|
{SNAPSHOT_ARCH}/
|
||||||
@@ -631,7 +631,7 @@ func generatePrebuiltSnapshot(s snapshot.SnapshotSingleton, ctx android.Singleto
|
|||||||
(notice files)
|
(notice files)
|
||||||
*/
|
*/
|
||||||
var snapshotOutputs android.Paths
|
var snapshotOutputs android.Paths
|
||||||
noticeDir := filepath.Join(snapshotArchDir, "NOTICE_FILES")
|
var snapshotNotices android.Paths
|
||||||
installedNotices := make(map[string]bool)
|
installedNotices := make(map[string]bool)
|
||||||
|
|
||||||
ctx.VisitAllModules(func(module android.Module) {
|
ctx.VisitAllModules(func(module android.Module) {
|
||||||
@@ -651,7 +651,7 @@ func generatePrebuiltSnapshot(s snapshot.SnapshotSingleton, ctx android.Singleto
|
|||||||
|
|
||||||
prop := snapshot.SnapshotJsonFlags{}
|
prop := snapshot.SnapshotJsonFlags{}
|
||||||
propOut := snapshotLibOut + ".json"
|
propOut := snapshotLibOut + ".json"
|
||||||
prop.ModuleName = m.BaseModuleName()
|
prop.InitBaseSnapshotProps(m)
|
||||||
if m.subdirProperties.Relative_install_path != nil {
|
if m.subdirProperties.Relative_install_path != nil {
|
||||||
prop.RelativeInstallPath = *m.subdirProperties.Relative_install_path
|
prop.RelativeInstallPath = *m.subdirProperties.Relative_install_path
|
||||||
}
|
}
|
||||||
@@ -667,27 +667,16 @@ func generatePrebuiltSnapshot(s snapshot.SnapshotSingleton, ctx android.Singleto
|
|||||||
}
|
}
|
||||||
snapshotOutputs = append(snapshotOutputs, snapshot.WriteStringToFileRule(ctx, string(j), propOut))
|
snapshotOutputs = append(snapshotOutputs, snapshot.WriteStringToFileRule(ctx, string(j), propOut))
|
||||||
|
|
||||||
if len(m.EffectiveLicenseFiles()) > 0 {
|
for _, notice := range m.EffectiveLicenseFiles() {
|
||||||
noticeName := ctx.ModuleName(m) + ".txt"
|
if _, ok := installedNotices[notice.String()]; !ok {
|
||||||
noticeOut := filepath.Join(noticeDir, noticeName)
|
installedNotices[notice.String()] = true
|
||||||
// skip already copied notice file
|
snapshotNotices = append(snapshotNotices, notice)
|
||||||
if !installedNotices[noticeOut] {
|
|
||||||
installedNotices[noticeOut] = true
|
|
||||||
|
|
||||||
noticeOutPath := android.PathForOutput(ctx, noticeOut)
|
|
||||||
ctx.Build(pctx, android.BuildParams{
|
|
||||||
Rule: android.Cat,
|
|
||||||
Inputs: m.EffectiveLicenseFiles(),
|
|
||||||
Output: noticeOutPath,
|
|
||||||
Description: "combine notices for " + noticeOut,
|
|
||||||
})
|
|
||||||
snapshotOutputs = append(snapshotOutputs, noticeOutPath)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return snapshotOutputs
|
return snapshot.SnapshotPaths{OutputFiles: snapshotOutputs, NoticeFiles: snapshotNotices}
|
||||||
}
|
}
|
||||||
|
|
||||||
// For Bazel / bp2build
|
// For Bazel / bp2build
|
||||||
|
@@ -96,6 +96,7 @@ func (f *hostSnapshot) CreateMetaData(ctx android.ModuleContext, fileName string
|
|||||||
var jsonData []SnapshotJsonFlags
|
var jsonData []SnapshotJsonFlags
|
||||||
var metaPaths android.Paths
|
var metaPaths android.Paths
|
||||||
|
|
||||||
|
installedNotices := make(map[string]bool)
|
||||||
metaZipFile := android.PathForModuleOut(ctx, fileName).OutputPath
|
metaZipFile := android.PathForModuleOut(ctx, fileName).OutputPath
|
||||||
|
|
||||||
// Create JSON file based on the direct dependencies
|
// Create JSON file based on the direct dependencies
|
||||||
@@ -104,12 +105,14 @@ func (f *hostSnapshot) CreateMetaData(ctx android.ModuleContext, fileName string
|
|||||||
if desc != nil {
|
if desc != nil {
|
||||||
jsonData = append(jsonData, *desc)
|
jsonData = append(jsonData, *desc)
|
||||||
}
|
}
|
||||||
if len(dep.EffectiveLicenseFiles()) > 0 {
|
for _, notice := range dep.EffectiveLicenseFiles() {
|
||||||
noticeFile := android.PathForModuleOut(ctx, "NOTICE_FILES", dep.Name()+".txt").OutputPath
|
if _, ok := installedNotices[notice.String()]; !ok {
|
||||||
android.CatFileRule(ctx, dep.EffectiveLicenseFiles(), noticeFile)
|
installedNotices[notice.String()] = true
|
||||||
metaPaths = append(metaPaths, noticeFile)
|
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 notice paths and json data for repeatble build
|
||||||
sort.Slice(jsonData, func(i, j int) bool {
|
sort.Slice(jsonData, func(i, j int) bool {
|
||||||
@@ -220,8 +223,7 @@ func hostJsonDesc(m android.Module) *SnapshotJsonFlags {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if path.Valid() && path.String() != "" {
|
if path.Valid() && path.String() != "" {
|
||||||
return &SnapshotJsonFlags{
|
props := &SnapshotJsonFlags{
|
||||||
ModuleName: m.Name(),
|
|
||||||
ModuleStemName: moduleStem,
|
ModuleStemName: moduleStem,
|
||||||
Filename: path.String(),
|
Filename: path.String(),
|
||||||
Required: append(m.HostRequiredModuleNames(), m.RequiredModuleNames()...),
|
Required: append(m.HostRequiredModuleNames(), m.RequiredModuleNames()...),
|
||||||
@@ -229,6 +231,8 @@ func hostJsonDesc(m android.Module) *SnapshotJsonFlags {
|
|||||||
RustProcMacro: procMacro,
|
RustProcMacro: procMacro,
|
||||||
CrateName: crateName,
|
CrateName: crateName,
|
||||||
}
|
}
|
||||||
|
props.InitBaseSnapshotProps(m)
|
||||||
|
return props
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,10 @@ import (
|
|||||||
|
|
||||||
var pctx = android.NewPackageContext("android/soong/snapshot")
|
var pctx = android.NewPackageContext("android/soong/snapshot")
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
pctx.Import("android/soong/android")
|
||||||
|
}
|
||||||
|
|
||||||
type SnapshotSingleton struct {
|
type SnapshotSingleton struct {
|
||||||
// Name, e.g., "vendor", "recovery", "ramdisk".
|
// Name, e.g., "vendor", "recovery", "ramdisk".
|
||||||
name string
|
name string
|
||||||
@@ -48,8 +52,18 @@ type SnapshotSingleton struct {
|
|||||||
Fake bool
|
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
|
// 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
|
var snapshotActionList []GenerateSnapshotAction
|
||||||
|
|
||||||
@@ -74,9 +88,19 @@ func (c *SnapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) {
|
|||||||
snapshotDir = filepath.Join("fake", snapshotDir)
|
snapshotDir = filepath.Join("fake", snapshotDir)
|
||||||
}
|
}
|
||||||
snapshotArchDir := filepath.Join(snapshotDir, ctx.DeviceConfig().DeviceArch())
|
snapshotArchDir := filepath.Join(snapshotDir, ctx.DeviceConfig().DeviceArch())
|
||||||
|
noticeDir := filepath.Join(snapshotArchDir, "NOTICE_FILES")
|
||||||
|
installedNotices := make(map[string]bool)
|
||||||
|
|
||||||
for _, f := range snapshotActionList {
|
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.
|
// All artifacts are ready. Sort them to normalize ninja and then zip.
|
||||||
|
@@ -120,4 +120,19 @@ type SnapshotJsonFlags struct {
|
|||||||
// dependencies
|
// dependencies
|
||||||
Required []string `json:",omitempty"`
|
Required []string `json:",omitempty"`
|
||||||
Overrides []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())
|
||||||
}
|
}
|
||||||
|
@@ -21,17 +21,25 @@ func WriteStringToFileRule(ctx android.SingletonContext, content, out string) an
|
|||||||
return outPath
|
return outPath
|
||||||
}
|
}
|
||||||
|
|
||||||
func CopyFileRule(pctx android.PackageContext, ctx android.SingletonContext, path android.Path, out string) android.OutputPath {
|
type buildContext interface {
|
||||||
outPath := android.PathForOutput(ctx, out)
|
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{
|
ctx.Build(pctx, android.BuildParams{
|
||||||
Rule: android.Cp,
|
Rule: android.Cp,
|
||||||
Input: path,
|
Input: path,
|
||||||
Output: outPath,
|
Output: outPath,
|
||||||
Description: "copy " + path.String() + " -> " + out,
|
Description: "copy " + path.String() + " -> " + outPath.String(),
|
||||||
Args: map[string]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
|
return outPath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user