Merge "Use static build rules in snapshot generation"
am: 7467a714b0
Change-Id: I2ee0d433e3ac586103c931295fea5d807156617f
This commit is contained in:
@@ -31,6 +31,8 @@ import (
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
pctx.Import("android/soong/android")
|
pctx.Import("android/soong/android")
|
||||||
|
pctx.Import("android/soong/java/config")
|
||||||
|
|
||||||
android.RegisterModuleType("sdk", ModuleFactory)
|
android.RegisterModuleType("sdk", ModuleFactory)
|
||||||
android.RegisterModuleType("sdk_snapshot", SnapshotModuleFactory)
|
android.RegisterModuleType("sdk_snapshot", SnapshotModuleFactory)
|
||||||
android.PreDepsMutators(RegisterPreDepsMutators)
|
android.PreDepsMutators(RegisterPreDepsMutators)
|
||||||
|
@@ -27,7 +27,7 @@ import (
|
|||||||
"android/soong/java"
|
"android/soong/java"
|
||||||
)
|
)
|
||||||
|
|
||||||
func testSdkContext(t *testing.T, bp string) (*android.TestContext, android.Config) {
|
func testSdkContext(bp string) (*android.TestContext, android.Config) {
|
||||||
config := android.TestArchConfig(buildDir, nil)
|
config := android.TestArchConfig(buildDir, nil)
|
||||||
ctx := android.NewTestArchContext()
|
ctx := android.NewTestArchContext()
|
||||||
|
|
||||||
@@ -114,7 +114,7 @@ func testSdkContext(t *testing.T, bp string) (*android.TestContext, android.Conf
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testSdk(t *testing.T, bp string) (*android.TestContext, android.Config) {
|
func testSdk(t *testing.T, bp string) (*android.TestContext, android.Config) {
|
||||||
ctx, config := testSdkContext(t, bp)
|
ctx, config := testSdkContext(bp)
|
||||||
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
||||||
android.FailIfErrored(t, errs)
|
android.FailIfErrored(t, errs)
|
||||||
_, errs = ctx.PrepareBuildActions(config)
|
_, errs = ctx.PrepareBuildActions(config)
|
||||||
@@ -124,7 +124,7 @@ func testSdk(t *testing.T, bp string) (*android.TestContext, android.Config) {
|
|||||||
|
|
||||||
func testSdkError(t *testing.T, pattern, bp string) {
|
func testSdkError(t *testing.T, pattern, bp string) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
ctx, config := testSdkContext(t, bp)
|
ctx, config := testSdkContext(bp)
|
||||||
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
||||||
if len(errs) > 0 {
|
if len(errs) > 0 {
|
||||||
android.FailIfNoMatchingErrors(t, pattern, errs)
|
android.FailIfNoMatchingErrors(t, pattern, errs)
|
||||||
@@ -147,7 +147,7 @@ func ensureListContains(t *testing.T, result []string, expected string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func pathsToStrings(paths android.Paths) []string {
|
func pathsToStrings(paths android.Paths) []string {
|
||||||
ret := []string{}
|
var ret []string
|
||||||
for _, p := range paths {
|
for _, p := range paths {
|
||||||
ret = append(ret, p.String())
|
ret = append(ret, p.String())
|
||||||
}
|
}
|
||||||
@@ -554,14 +554,23 @@ sdk_snapshot {
|
|||||||
var copySrcs []string
|
var copySrcs []string
|
||||||
var copyDests []string
|
var copyDests []string
|
||||||
buildParams := sdk.BuildParamsForTests()
|
buildParams := sdk.BuildParamsForTests()
|
||||||
var zipBp android.BuildParams
|
var mergeZipInputs []string
|
||||||
|
var intermediateZip string
|
||||||
|
var outputZip string
|
||||||
for _, bp := range buildParams {
|
for _, bp := range buildParams {
|
||||||
ruleString := bp.Rule.String()
|
ruleString := bp.Rule.String()
|
||||||
if ruleString == "android/soong/android.Cp" {
|
if ruleString == android.Cp.String() {
|
||||||
copySrcs = append(copySrcs, bp.Input.String())
|
copySrcs = append(copySrcs, bp.Input.String())
|
||||||
copyDests = append(copyDests, bp.Output.Rel()) // rooted at the snapshot root
|
copyDests = append(copyDests, bp.Output.Rel()) // rooted at the snapshot root
|
||||||
} else if ruleString == "<local rule>:m.mysdk_android_common.snapshot" {
|
} else if ruleString == zipFiles.String() {
|
||||||
zipBp = bp
|
intermediateZip = bp.Output.String()
|
||||||
|
} else if ruleString == mergeZips.String() {
|
||||||
|
input := bp.Input.String()
|
||||||
|
if intermediateZip != input {
|
||||||
|
t.Errorf("Intermediate zip %s is not an input to merge_zips, %s is used instead", intermediateZip, input)
|
||||||
|
}
|
||||||
|
mergeZipInputs = bp.Inputs.Strings()
|
||||||
|
outputZip = bp.Output.String()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -582,17 +591,14 @@ sdk_snapshot {
|
|||||||
ensureListContains(t, copyDests, "java/myjavalib.jar")
|
ensureListContains(t, copyDests, "java/myjavalib.jar")
|
||||||
ensureListContains(t, copyDests, "arm64/lib/mynativelib.so")
|
ensureListContains(t, copyDests, "arm64/lib/mynativelib.so")
|
||||||
|
|
||||||
|
expectedOutputZip := filepath.Join(buildDir, ".intermediates/mysdk/android_common/mysdk-current.zip")
|
||||||
|
expectedRepackagedZip := filepath.Join(buildDir, ".intermediates/mysdk/android_common/tmp/java/myjavaapistubs_stubs_sources.zip")
|
||||||
|
|
||||||
// Ensure that the droidstubs .srcjar as repackaged into a temporary zip file
|
// Ensure that the droidstubs .srcjar as repackaged into a temporary zip file
|
||||||
// and then merged together with the intermediate snapshot zip.
|
// and then merged together with the intermediate snapshot zip.
|
||||||
snapshotCreationInputs := zipBp.Implicits.Strings()
|
ensureListContains(t, mergeZipInputs, expectedRepackagedZip)
|
||||||
ensureListContains(t, snapshotCreationInputs,
|
if outputZip != expectedOutputZip {
|
||||||
filepath.Join(buildDir, ".intermediates/mysdk/android_common/tmp/java/myjavaapistubs_stubs_sources.zip"))
|
t.Errorf("Expected snapshot output to be %q but was %q", expectedOutputZip, outputZip)
|
||||||
ensureListContains(t, snapshotCreationInputs,
|
|
||||||
filepath.Join(buildDir, ".intermediates/mysdk/android_common/mysdk-current.unmerged.zip"))
|
|
||||||
actual := zipBp.Output.String()
|
|
||||||
expected := filepath.Join(buildDir, ".intermediates/mysdk/android_common/mysdk-current.zip")
|
|
||||||
if actual != expected {
|
|
||||||
t.Errorf("Expected snapshot output to be %q but was %q", expected, actual)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -749,14 +755,23 @@ sdk_snapshot {
|
|||||||
var copySrcs []string
|
var copySrcs []string
|
||||||
var copyDests []string
|
var copyDests []string
|
||||||
buildParams := sdk.BuildParamsForTests()
|
buildParams := sdk.BuildParamsForTests()
|
||||||
var zipBp android.BuildParams
|
var mergeZipInputs []string
|
||||||
|
var intermediateZip string
|
||||||
|
var outputZip string
|
||||||
for _, bp := range buildParams {
|
for _, bp := range buildParams {
|
||||||
ruleString := bp.Rule.String()
|
ruleString := bp.Rule.String()
|
||||||
if ruleString == "android/soong/android.Cp" {
|
if ruleString == android.Cp.String() {
|
||||||
copySrcs = append(copySrcs, bp.Input.String())
|
copySrcs = append(copySrcs, bp.Input.String())
|
||||||
copyDests = append(copyDests, bp.Output.Rel()) // rooted at the snapshot root
|
copyDests = append(copyDests, bp.Output.Rel()) // rooted at the snapshot root
|
||||||
} else if ruleString == "<local rule>:m.mysdk_linux_glibc_common.snapshot" {
|
} else if ruleString == zipFiles.String() {
|
||||||
zipBp = bp
|
intermediateZip = bp.Output.String()
|
||||||
|
} else if ruleString == mergeZips.String() {
|
||||||
|
input := bp.Input.String()
|
||||||
|
if intermediateZip != input {
|
||||||
|
t.Errorf("Intermediate zip %s is not an input to merge_zips, %s is used instead", intermediateZip, input)
|
||||||
|
}
|
||||||
|
mergeZipInputs = bp.Inputs.Strings()
|
||||||
|
outputZip = bp.Output.String()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -777,17 +792,14 @@ sdk_snapshot {
|
|||||||
ensureListContains(t, copyDests, "java/myjavalib.jar")
|
ensureListContains(t, copyDests, "java/myjavalib.jar")
|
||||||
ensureListContains(t, copyDests, "x86_64/lib/mynativelib.so")
|
ensureListContains(t, copyDests, "x86_64/lib/mynativelib.so")
|
||||||
|
|
||||||
|
expectedOutputZip := filepath.Join(buildDir, ".intermediates/mysdk/linux_glibc_common/mysdk-current.zip")
|
||||||
|
expectedRepackagedZip := filepath.Join(buildDir, ".intermediates/mysdk/linux_glibc_common/tmp/java/myjavaapistubs_stubs_sources.zip")
|
||||||
|
|
||||||
// Ensure that the droidstubs .srcjar as repackaged into a temporary zip file
|
// Ensure that the droidstubs .srcjar as repackaged into a temporary zip file
|
||||||
// and then merged together with the intermediate snapshot zip.
|
// and then merged together with the intermediate snapshot zip.
|
||||||
snapshotCreationInputs := zipBp.Implicits.Strings()
|
ensureListContains(t, mergeZipInputs, expectedRepackagedZip)
|
||||||
ensureListContains(t, snapshotCreationInputs,
|
if outputZip != expectedOutputZip {
|
||||||
filepath.Join(buildDir, ".intermediates/mysdk/linux_glibc_common/tmp/java/myjavaapistubs_stubs_sources.zip"))
|
t.Errorf("Expected snapshot output to be %q but was %q", expectedOutputZip, outputZip)
|
||||||
ensureListContains(t, snapshotCreationInputs,
|
|
||||||
filepath.Join(buildDir, ".intermediates/mysdk/linux_glibc_common/mysdk-current.unmerged.zip"))
|
|
||||||
actual := zipBp.Output.String()
|
|
||||||
expected := filepath.Join(buildDir, ".intermediates/mysdk/linux_glibc_common/mysdk-current.zip")
|
|
||||||
if actual != expected {
|
|
||||||
t.Errorf("Expected snapshot output to be %q but was %q", expected, actual)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -810,7 +822,7 @@ func setUp() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func tearDown() {
|
func tearDown() {
|
||||||
os.RemoveAll(buildDir)
|
_ = os.RemoveAll(buildDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
|
@@ -20,6 +20,7 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/google/blueprint"
|
||||||
"github.com/google/blueprint/proptools"
|
"github.com/google/blueprint/proptools"
|
||||||
|
|
||||||
"android/soong/android"
|
"android/soong/android"
|
||||||
@@ -29,6 +30,36 @@ import (
|
|||||||
|
|
||||||
var pctx = android.NewPackageContext("android/soong/sdk")
|
var pctx = android.NewPackageContext("android/soong/sdk")
|
||||||
|
|
||||||
|
var (
|
||||||
|
repackageZip = pctx.AndroidStaticRule("SnapshotRepackageZip",
|
||||||
|
blueprint.RuleParams{
|
||||||
|
Command: `${config.Zip2ZipCmd} -i $in -o $out "**/*:$destdir"`,
|
||||||
|
CommandDeps: []string{
|
||||||
|
"${config.Zip2ZipCmd}",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"destdir")
|
||||||
|
|
||||||
|
zipFiles = pctx.AndroidStaticRule("SnapshotZipFiles",
|
||||||
|
blueprint.RuleParams{
|
||||||
|
Command: `${config.SoongZipCmd} -C $basedir -l $out.rsp -o $out`,
|
||||||
|
CommandDeps: []string{
|
||||||
|
"${config.SoongZipCmd}",
|
||||||
|
},
|
||||||
|
Rspfile: "$out.rsp",
|
||||||
|
RspfileContent: "$in",
|
||||||
|
},
|
||||||
|
"basedir")
|
||||||
|
|
||||||
|
mergeZips = pctx.AndroidStaticRule("SnapshotMergeZips",
|
||||||
|
blueprint.RuleParams{
|
||||||
|
Command: `${config.MergeZipsCmd} $out $in`,
|
||||||
|
CommandDeps: []string{
|
||||||
|
"${config.MergeZipsCmd}",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
type generatedContents struct {
|
type generatedContents struct {
|
||||||
content strings.Builder
|
content strings.Builder
|
||||||
indentLevel int
|
indentLevel int
|
||||||
@@ -316,41 +347,39 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext) android.OutputPath {
|
|||||||
|
|
||||||
// zip them all
|
// zip them all
|
||||||
outputZipFile := android.PathForModuleOut(ctx, ctx.ModuleName()+"-current.zip").OutputPath
|
outputZipFile := android.PathForModuleOut(ctx, ctx.ModuleName()+"-current.zip").OutputPath
|
||||||
outputRuleName := "snapshot"
|
|
||||||
outputDesc := "Building snapshot for " + ctx.ModuleName()
|
outputDesc := "Building snapshot for " + ctx.ModuleName()
|
||||||
|
|
||||||
// If there are no zips to merge then generate the output zip directly.
|
// If there are no zips to merge then generate the output zip directly.
|
||||||
// Otherwise, generate an intermediate zip file into which other zips can be
|
// Otherwise, generate an intermediate zip file into which other zips can be
|
||||||
// merged.
|
// merged.
|
||||||
var zipFile android.OutputPath
|
var zipFile android.OutputPath
|
||||||
var ruleName string
|
|
||||||
var desc string
|
var desc string
|
||||||
if len(builder.zipsToMerge) == 0 {
|
if len(builder.zipsToMerge) == 0 {
|
||||||
zipFile = outputZipFile
|
zipFile = outputZipFile
|
||||||
ruleName = outputRuleName
|
|
||||||
desc = outputDesc
|
desc = outputDesc
|
||||||
} else {
|
} else {
|
||||||
zipFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"-current.unmerged.zip").OutputPath
|
zipFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"-current.unmerged.zip").OutputPath
|
||||||
ruleName = "intermediate snapshot"
|
|
||||||
desc = "Building intermediate snapshot for " + ctx.ModuleName()
|
desc = "Building intermediate snapshot for " + ctx.ModuleName()
|
||||||
}
|
}
|
||||||
|
|
||||||
rb := android.NewRuleBuilder()
|
ctx.Build(pctx, android.BuildParams{
|
||||||
rb.Command().
|
Description: desc,
|
||||||
BuiltTool(ctx, "soong_zip").
|
Rule: zipFiles,
|
||||||
FlagWithArg("-C ", builder.snapshotDir.String()).
|
Inputs: filesToZip,
|
||||||
FlagWithRspFileInputList("-l ", filesToZip).
|
Output: zipFile,
|
||||||
FlagWithOutput("-o ", zipFile)
|
Args: map[string]string{
|
||||||
rb.Build(pctx, ctx, ruleName, desc)
|
"basedir": builder.snapshotDir.String(),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
if len(builder.zipsToMerge) != 0 {
|
if len(builder.zipsToMerge) != 0 {
|
||||||
rb := android.NewRuleBuilder()
|
ctx.Build(pctx, android.BuildParams{
|
||||||
rb.Command().
|
Description: outputDesc,
|
||||||
BuiltTool(ctx, "merge_zips").
|
Rule: mergeZips,
|
||||||
Output(outputZipFile).
|
Input: zipFile,
|
||||||
Input(zipFile).
|
Inputs: builder.zipsToMerge,
|
||||||
Inputs(builder.zipsToMerge)
|
Output: outputZipFile,
|
||||||
rb.Build(pctx, ctx, outputRuleName, outputDesc)
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return outputZipFile
|
return outputZipFile
|
||||||
@@ -534,14 +563,16 @@ func (s *snapshotBuilder) UnzipToSnapshot(zipPath android.Path, destDir string)
|
|||||||
// Repackage the zip file so that the entries are in the destDir directory.
|
// Repackage the zip file so that the entries are in the destDir directory.
|
||||||
// This will allow the zip file to be merged into the snapshot.
|
// This will allow the zip file to be merged into the snapshot.
|
||||||
tmpZipPath := android.PathForModuleOut(ctx, "tmp", destDir+".zip").OutputPath
|
tmpZipPath := android.PathForModuleOut(ctx, "tmp", destDir+".zip").OutputPath
|
||||||
rb := android.NewRuleBuilder()
|
|
||||||
rb.Command().
|
ctx.Build(pctx, android.BuildParams{
|
||||||
BuiltTool(ctx, "zip2zip").
|
Description: "Repackaging zip file " + destDir + " for snapshot " + ctx.ModuleName(),
|
||||||
FlagWithInput("-i ", zipPath).
|
Rule: repackageZip,
|
||||||
FlagWithOutput("-o ", tmpZipPath).
|
Input: zipPath,
|
||||||
Flag("**/*:" + destDir)
|
Output: tmpZipPath,
|
||||||
rb.Build(pctx, ctx, "repackaging "+destDir,
|
Args: map[string]string{
|
||||||
"Repackaging zip file "+destDir+" for snapshot "+ctx.ModuleName())
|
"destdir": destDir,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
// Add the repackaged zip file to the files to merge.
|
// Add the repackaged zip file to the files to merge.
|
||||||
s.zipsToMerge = append(s.zipsToMerge, tmpZipPath)
|
s.zipsToMerge = append(s.zipsToMerge, tmpZipPath)
|
||||||
|
Reference in New Issue
Block a user