Merge "Add assets
property for Android apps." into main am: c82e844121
am: ab202d1aa2
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2786252 Change-Id: I5289eaac6ff9d7e8667f3a345ed0ba70a2e25568 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
30
java/aar.go
30
java/aar.go
@@ -66,6 +66,9 @@ type aaptProperties struct {
|
|||||||
// ones.
|
// ones.
|
||||||
Aapt_include_all_resources *bool
|
Aapt_include_all_resources *bool
|
||||||
|
|
||||||
|
// list of files to use as assets.
|
||||||
|
Assets []string `android:"path"`
|
||||||
|
|
||||||
// list of directories relative to the Blueprints file containing assets.
|
// list of directories relative to the Blueprints file containing assets.
|
||||||
// Defaults to ["assets"] if a directory called assets exists. Set to []
|
// Defaults to ["assets"] if a directory called assets exists. Set to []
|
||||||
// to disable the default.
|
// to disable the default.
|
||||||
@@ -192,6 +195,11 @@ func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext android.SdkConte
|
|||||||
linkFlags = append(linkFlags, a.aaptProperties.Aaptflags...)
|
linkFlags = append(linkFlags, a.aaptProperties.Aaptflags...)
|
||||||
|
|
||||||
// Find implicit or explicit asset and resource dirs
|
// Find implicit or explicit asset and resource dirs
|
||||||
|
assets := android.PathsRelativeToModuleSourceDir(android.SourceInput{
|
||||||
|
Context: ctx,
|
||||||
|
Paths: a.aaptProperties.Assets,
|
||||||
|
IncludeDirs: false,
|
||||||
|
})
|
||||||
assetDirs := android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Asset_dirs, "assets")
|
assetDirs := android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Asset_dirs, "assets")
|
||||||
resourceDirs := android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Resource_dirs, "res")
|
resourceDirs := android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Resource_dirs, "res")
|
||||||
resourceZips := android.PathsForModuleSrc(ctx, a.aaptProperties.Resource_zips)
|
resourceZips := android.PathsForModuleSrc(ctx, a.aaptProperties.Resource_zips)
|
||||||
@@ -226,6 +234,28 @@ func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext android.SdkConte
|
|||||||
assetDirStrings = append(assetDirStrings, filepath.Dir(a.noticeFile.Path().String()))
|
assetDirStrings = append(assetDirStrings, filepath.Dir(a.noticeFile.Path().String()))
|
||||||
assetDeps = append(assetDeps, a.noticeFile.Path())
|
assetDeps = append(assetDeps, a.noticeFile.Path())
|
||||||
}
|
}
|
||||||
|
if len(assets) > 0 {
|
||||||
|
// aapt2 doesn't support adding individual asset files. Create a temp directory to hold asset
|
||||||
|
// files and pass it to aapt2.
|
||||||
|
tmpAssetDir := android.PathForModuleOut(ctx, "tmp_asset_dir")
|
||||||
|
|
||||||
|
rule := android.NewRuleBuilder(pctx, ctx)
|
||||||
|
rule.Command().
|
||||||
|
Text("rm -rf").Text(tmpAssetDir.String()).
|
||||||
|
Text("&&").
|
||||||
|
Text("mkdir -p").Text(tmpAssetDir.String())
|
||||||
|
|
||||||
|
for _, asset := range assets {
|
||||||
|
output := tmpAssetDir.Join(ctx, asset.Rel())
|
||||||
|
assetDeps = append(assetDeps, output)
|
||||||
|
rule.Command().Text("mkdir -p").Text(filepath.Dir(output.String()))
|
||||||
|
rule.Command().Text("cp").Input(asset).Output(output)
|
||||||
|
}
|
||||||
|
|
||||||
|
rule.Build("tmp_asset_dir", "tmp_asset_dir")
|
||||||
|
|
||||||
|
assetDirStrings = append(assetDirStrings, tmpAssetDir.String())
|
||||||
|
}
|
||||||
|
|
||||||
linkFlags = append(linkFlags, "--manifest "+manifestPath.String())
|
linkFlags = append(linkFlags, "--manifest "+manifestPath.String())
|
||||||
linkDeps = append(linkDeps, manifestPath)
|
linkDeps = append(linkDeps, manifestPath)
|
||||||
|
@@ -608,6 +608,15 @@ func TestLibraryAssets(t *testing.T) {
|
|||||||
asset_dirs: ["assets_b"],
|
asset_dirs: ["assets_b"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
android_library {
|
||||||
|
name: "lib5",
|
||||||
|
sdk_version: "current",
|
||||||
|
assets: [
|
||||||
|
"path/to/asset_file_1",
|
||||||
|
"path/to/asset_file_2",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
android_library_import {
|
android_library_import {
|
||||||
name: "import",
|
name: "import",
|
||||||
sdk_version: "current",
|
sdk_version: "current",
|
||||||
@@ -619,6 +628,8 @@ func TestLibraryAssets(t *testing.T) {
|
|||||||
name string
|
name string
|
||||||
assetFlag string
|
assetFlag string
|
||||||
assetPackages []string
|
assetPackages []string
|
||||||
|
tmpAssetDirInputs []string
|
||||||
|
tmpAssetDirOutputs []string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "foo",
|
name: "foo",
|
||||||
@@ -644,6 +655,18 @@ func TestLibraryAssets(t *testing.T) {
|
|||||||
name: "lib4",
|
name: "lib4",
|
||||||
assetFlag: "-A assets_b",
|
assetFlag: "-A assets_b",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "lib5",
|
||||||
|
assetFlag: "-A out/soong/.intermediates/lib5/android_common/tmp_asset_dir",
|
||||||
|
tmpAssetDirInputs: []string{
|
||||||
|
"path/to/asset_file_1",
|
||||||
|
"path/to/asset_file_2",
|
||||||
|
},
|
||||||
|
tmpAssetDirOutputs: []string{
|
||||||
|
"out/soong/.intermediates/lib5/android_common/tmp_asset_dir/path/to/asset_file_1",
|
||||||
|
"out/soong/.intermediates/lib5/android_common/tmp_asset_dir/path/to/asset_file_2",
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
ctx := testApp(t, bp)
|
ctx := testApp(t, bp)
|
||||||
|
|
||||||
@@ -671,6 +694,14 @@ func TestLibraryAssets(t *testing.T) {
|
|||||||
mergeAssets := m.Output("package-res.apk")
|
mergeAssets := m.Output("package-res.apk")
|
||||||
android.AssertPathsRelativeToTopEquals(t, "mergeAssets inputs", test.assetPackages, mergeAssets.Inputs)
|
android.AssertPathsRelativeToTopEquals(t, "mergeAssets inputs", test.assetPackages, mergeAssets.Inputs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(test.tmpAssetDirInputs) > 0 {
|
||||||
|
rule := m.Rule("tmp_asset_dir")
|
||||||
|
inputs := rule.Implicits
|
||||||
|
outputs := append(android.WritablePaths{rule.Output}, rule.ImplicitOutputs...).Paths()
|
||||||
|
android.AssertPathsRelativeToTopEquals(t, "tmp_asset_dir inputs", test.tmpAssetDirInputs, inputs)
|
||||||
|
android.AssertPathsRelativeToTopEquals(t, "tmp_asset_dir outputs", test.tmpAssetDirOutputs, outputs)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user