2019-11-18 03:16:27 +01:00
|
|
|
// Copyright (C) 2019 The Android Open Source Project
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package apex
|
|
|
|
|
|
|
|
import (
|
2020-02-28 07:22:21 +01:00
|
|
|
"encoding/json"
|
2019-11-18 03:16:27 +01:00
|
|
|
"fmt"
|
|
|
|
"path/filepath"
|
|
|
|
"runtime"
|
|
|
|
"sort"
|
2020-10-20 01:02:15 +02:00
|
|
|
"strconv"
|
2019-11-18 03:16:27 +01:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/java"
|
|
|
|
|
|
|
|
"github.com/google/blueprint"
|
|
|
|
"github.com/google/blueprint/proptools"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
pctx = android.NewPackageContext("android/apex")
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
pctx.Import("android/soong/android")
|
2020-11-12 17:39:19 +01:00
|
|
|
pctx.Import("android/soong/cc/config")
|
2019-11-18 03:16:27 +01:00
|
|
|
pctx.Import("android/soong/java")
|
|
|
|
pctx.HostBinToolVariable("apexer", "apexer")
|
|
|
|
// ART minimal builds (using the master-art manifest) do not have the "frameworks/base"
|
2020-11-24 11:51:18 +01:00
|
|
|
// projects, and hence cannot build 'aapt2'. Use the SDK prebuilt instead.
|
2019-11-18 03:16:27 +01:00
|
|
|
hostBinToolVariableWithPrebuilt := func(name, prebuiltDir, tool string) {
|
|
|
|
pctx.VariableFunc(name, func(ctx android.PackageVarContext) string {
|
|
|
|
if !ctx.Config().FrameworksBaseDirExists(ctx) {
|
|
|
|
return filepath.Join(prebuiltDir, runtime.GOOS, "bin", tool)
|
|
|
|
} else {
|
2019-12-09 22:47:14 +01:00
|
|
|
return ctx.Config().HostToolPath(ctx, tool).String()
|
2019-11-18 03:16:27 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
hostBinToolVariableWithPrebuilt("aapt2", "prebuilts/sdk/tools", "aapt2")
|
|
|
|
pctx.HostBinToolVariable("avbtool", "avbtool")
|
|
|
|
pctx.HostBinToolVariable("e2fsdroid", "e2fsdroid")
|
|
|
|
pctx.HostBinToolVariable("merge_zips", "merge_zips")
|
|
|
|
pctx.HostBinToolVariable("mke2fs", "mke2fs")
|
|
|
|
pctx.HostBinToolVariable("resize2fs", "resize2fs")
|
|
|
|
pctx.HostBinToolVariable("sefcontext_compile", "sefcontext_compile")
|
|
|
|
pctx.HostBinToolVariable("soong_zip", "soong_zip")
|
|
|
|
pctx.HostBinToolVariable("zip2zip", "zip2zip")
|
|
|
|
pctx.HostBinToolVariable("zipalign", "zipalign")
|
|
|
|
pctx.HostBinToolVariable("jsonmodify", "jsonmodify")
|
|
|
|
pctx.HostBinToolVariable("conv_apex_manifest", "conv_apex_manifest")
|
2020-05-14 23:15:24 +02:00
|
|
|
pctx.HostBinToolVariable("extract_apks", "extract_apks")
|
2020-06-12 14:46:59 +02:00
|
|
|
pctx.HostBinToolVariable("make_f2fs", "make_f2fs")
|
|
|
|
pctx.HostBinToolVariable("sload_f2fs", "sload_f2fs")
|
2021-08-02 09:02:17 +02:00
|
|
|
pctx.HostBinToolVariable("make_erofs", "make_erofs")
|
2020-11-26 14:32:26 +01:00
|
|
|
pctx.HostBinToolVariable("apex_compression_tool", "apex_compression_tool")
|
2021-11-03 01:58:02 +01:00
|
|
|
pctx.HostBinToolVariable("dexdeps", "dexdeps")
|
2020-11-12 17:39:19 +01:00
|
|
|
pctx.SourcePathVariable("genNdkUsedbyApexPath", "build/soong/scripts/gen_ndk_usedby_apex.sh")
|
2019-11-18 03:16:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
apexManifestRule = pctx.StaticRule("apexManifestRule", blueprint.RuleParams{
|
|
|
|
Command: `rm -f $out && ${jsonmodify} $in ` +
|
|
|
|
`-a provideNativeLibs ${provideNativeLibs} ` +
|
|
|
|
`-a requireNativeLibs ${requireNativeLibs} ` +
|
|
|
|
`${opt} ` +
|
|
|
|
`-o $out`,
|
|
|
|
CommandDeps: []string{"${jsonmodify}"},
|
|
|
|
Description: "prepare ${out}",
|
|
|
|
}, "provideNativeLibs", "requireNativeLibs", "opt")
|
|
|
|
|
|
|
|
stripApexManifestRule = pctx.StaticRule("stripApexManifestRule", blueprint.RuleParams{
|
|
|
|
Command: `rm -f $out && ${conv_apex_manifest} strip $in -o $out`,
|
|
|
|
CommandDeps: []string{"${conv_apex_manifest}"},
|
|
|
|
Description: "strip ${in}=>${out}",
|
|
|
|
})
|
|
|
|
|
|
|
|
pbApexManifestRule = pctx.StaticRule("pbApexManifestRule", blueprint.RuleParams{
|
|
|
|
Command: `rm -f $out && ${conv_apex_manifest} proto $in -o $out`,
|
|
|
|
CommandDeps: []string{"${conv_apex_manifest}"},
|
|
|
|
Description: "convert ${in}=>${out}",
|
|
|
|
})
|
|
|
|
|
2021-10-28 00:47:06 +02:00
|
|
|
// TODO(b/113233103): make sure that file_contexts is as expected, i.e., validate
|
2019-11-18 03:16:27 +01:00
|
|
|
// against the binary policy using sefcontext_compiler -p <policy>.
|
|
|
|
|
|
|
|
// TODO(b/114327326): automate the generation of file_contexts
|
|
|
|
apexRule = pctx.StaticRule("apexRule", blueprint.RuleParams{
|
|
|
|
Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` +
|
|
|
|
`(. ${out}.copy_commands) && ` +
|
|
|
|
`APEXER_TOOL_PATH=${tool_path} ` +
|
|
|
|
`${apexer} --force --manifest ${manifest} ` +
|
|
|
|
`--file_contexts ${file_contexts} ` +
|
|
|
|
`--canned_fs_config ${canned_fs_config} ` +
|
2020-01-02 16:24:12 +01:00
|
|
|
`--include_build_info ` +
|
2019-11-18 03:16:27 +01:00
|
|
|
`--payload_type image ` +
|
2022-05-05 15:52:25 +02:00
|
|
|
`--key ${key} ${opt_flags} ${image_dir} ${out} `,
|
2019-11-18 03:16:27 +01:00
|
|
|
CommandDeps: []string{"${apexer}", "${avbtool}", "${e2fsdroid}", "${merge_zips}",
|
2021-08-02 09:02:17 +02:00
|
|
|
"${mke2fs}", "${resize2fs}", "${sefcontext_compile}", "${make_f2fs}", "${sload_f2fs}", "${make_erofs}",
|
2019-11-18 03:16:27 +01:00
|
|
|
"${soong_zip}", "${zipalign}", "${aapt2}", "prebuilts/sdk/current/public/android.jar"},
|
|
|
|
Rspfile: "${out}.copy_commands",
|
|
|
|
RspfileContent: "${copy_commands}",
|
|
|
|
Description: "APEX ${image_dir} => ${out}",
|
2022-05-05 15:52:25 +02:00
|
|
|
}, "tool_path", "image_dir", "copy_commands", "file_contexts", "canned_fs_config", "key", "opt_flags", "manifest", "payload_fs_type")
|
2019-11-18 03:16:27 +01:00
|
|
|
|
|
|
|
zipApexRule = pctx.StaticRule("zipApexRule", blueprint.RuleParams{
|
|
|
|
Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` +
|
|
|
|
`(. ${out}.copy_commands) && ` +
|
|
|
|
`APEXER_TOOL_PATH=${tool_path} ` +
|
2019-11-12 05:03:50 +01:00
|
|
|
`${apexer} --force --manifest ${manifest} ` +
|
2019-11-18 03:16:27 +01:00
|
|
|
`--payload_type zip ` +
|
|
|
|
`${image_dir} ${out} `,
|
|
|
|
CommandDeps: []string{"${apexer}", "${merge_zips}", "${soong_zip}", "${zipalign}", "${aapt2}"},
|
|
|
|
Rspfile: "${out}.copy_commands",
|
|
|
|
RspfileContent: "${copy_commands}",
|
|
|
|
Description: "ZipAPEX ${image_dir} => ${out}",
|
2022-05-05 15:52:25 +02:00
|
|
|
}, "tool_path", "image_dir", "copy_commands", "manifest")
|
2019-11-18 03:16:27 +01:00
|
|
|
|
|
|
|
apexProtoConvertRule = pctx.AndroidStaticRule("apexProtoConvertRule",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: `${aapt2} convert --output-format proto $in -o $out`,
|
|
|
|
CommandDeps: []string{"${aapt2}"},
|
|
|
|
})
|
|
|
|
|
|
|
|
apexBundleRule = pctx.StaticRule("apexBundleRule", blueprint.RuleParams{
|
2020-02-28 07:22:21 +01:00
|
|
|
Command: `${zip2zip} -i $in -o $out.base ` +
|
2019-11-18 03:16:27 +01:00
|
|
|
`apex_payload.img:apex/${abi}.img ` +
|
2020-03-02 22:47:09 +01:00
|
|
|
`apex_build_info.pb:apex/${abi}.build_info.pb ` +
|
2019-11-18 03:16:27 +01:00
|
|
|
`apex_manifest.json:root/apex_manifest.json ` +
|
2019-12-07 18:06:24 +01:00
|
|
|
`apex_manifest.pb:root/apex_manifest.pb ` +
|
2019-11-18 03:16:27 +01:00
|
|
|
`AndroidManifest.xml:manifest/AndroidManifest.xml ` +
|
2020-02-28 07:22:21 +01:00
|
|
|
`assets/NOTICE.html.gz:assets/NOTICE.html.gz &&` +
|
|
|
|
`${soong_zip} -o $out.config -C $$(dirname ${config}) -f ${config} && ` +
|
|
|
|
`${merge_zips} $out $out.base $out.config`,
|
|
|
|
CommandDeps: []string{"${zip2zip}", "${soong_zip}", "${merge_zips}"},
|
2019-11-18 03:16:27 +01:00
|
|
|
Description: "app bundle",
|
2020-02-28 07:22:21 +01:00
|
|
|
}, "abi", "config")
|
2019-11-18 03:16:27 +01:00
|
|
|
|
|
|
|
emitApexContentRule = pctx.StaticRule("emitApexContentRule", blueprint.RuleParams{
|
|
|
|
Command: `rm -f ${out} && touch ${out} && (. ${out}.emit_commands)`,
|
|
|
|
Rspfile: "${out}.emit_commands",
|
|
|
|
RspfileContent: "${emit_commands}",
|
|
|
|
Description: "Emit APEX image content",
|
|
|
|
}, "emit_commands")
|
|
|
|
|
|
|
|
diffApexContentRule = pctx.StaticRule("diffApexContentRule", blueprint.RuleParams{
|
|
|
|
Command: `diff --unchanged-group-format='' \` +
|
|
|
|
`--changed-group-format='%<' \` +
|
2020-06-11 20:32:11 +02:00
|
|
|
`${image_content_file} ${allowed_files_file} || (` +
|
2019-11-18 03:16:27 +01:00
|
|
|
`echo -e "New unexpected files were added to ${apex_module_name}." ` +
|
|
|
|
` "To fix the build run following command:" && ` +
|
2020-06-11 20:32:11 +02:00
|
|
|
`echo "system/apex/tools/update_allowed_list.sh ${allowed_files_file} ${image_content_file}" && ` +
|
2020-01-29 00:40:19 +01:00
|
|
|
`exit 1); touch ${out}`,
|
2020-06-11 20:32:11 +02:00
|
|
|
Description: "Diff ${image_content_file} and ${allowed_files_file}",
|
|
|
|
}, "image_content_file", "allowed_files_file", "apex_module_name")
|
2020-11-24 11:51:18 +01:00
|
|
|
|
2020-11-12 17:39:19 +01:00
|
|
|
generateAPIsUsedbyApexRule = pctx.StaticRule("generateAPIsUsedbyApexRule", blueprint.RuleParams{
|
|
|
|
Command: "$genNdkUsedbyApexPath ${image_dir} ${readelf} ${out}",
|
|
|
|
CommandDeps: []string{"${genNdkUsedbyApexPath}"},
|
|
|
|
Description: "Generate symbol list used by Apex",
|
|
|
|
}, "image_dir", "readelf")
|
|
|
|
|
2020-11-24 11:51:18 +01:00
|
|
|
// Don't add more rules here. Consider using android.NewRuleBuilder instead.
|
2019-11-18 03:16:27 +01:00
|
|
|
)
|
|
|
|
|
2020-11-24 11:51:18 +01:00
|
|
|
// buildManifest creates buile rules to modify the input apex_manifest.json to add information
|
|
|
|
// gathered by the build system such as provided/required native libraries. Two output files having
|
|
|
|
// different formats are generated. a.manifestJsonOut is JSON format for Q devices, and
|
|
|
|
// a.manifest.PbOut is protobuf format for R+ devices.
|
|
|
|
// TODO(jiyong): make this to return paths instead of directly storing the paths to apexBundle
|
2019-11-18 03:16:27 +01:00
|
|
|
func (a *apexBundle) buildManifest(ctx android.ModuleContext, provideNativeLibs, requireNativeLibs []string) {
|
2020-11-24 11:51:18 +01:00
|
|
|
src := android.PathForModuleSrc(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json"))
|
2019-11-18 03:16:27 +01:00
|
|
|
|
2020-11-24 11:51:18 +01:00
|
|
|
// Put dependency({provide|require}NativeLibs) in apex_manifest.json
|
2019-11-18 03:16:27 +01:00
|
|
|
provideNativeLibs = android.SortedUniqueStrings(provideNativeLibs)
|
|
|
|
requireNativeLibs = android.SortedUniqueStrings(android.RemoveListFromList(requireNativeLibs, provideNativeLibs))
|
|
|
|
|
2020-11-24 11:51:18 +01:00
|
|
|
// APEX name can be overridden
|
2019-11-18 03:16:27 +01:00
|
|
|
optCommands := []string{}
|
|
|
|
if a.properties.Apex_name != nil {
|
|
|
|
optCommands = append(optCommands, "-v name "+*a.properties.Apex_name)
|
|
|
|
}
|
|
|
|
|
2020-11-24 11:51:18 +01:00
|
|
|
// Collect jniLibs. Notice that a.filesInfo is already sorted
|
2020-02-27 05:50:06 +01:00
|
|
|
var jniLibs []string
|
|
|
|
for _, fi := range a.filesInfo {
|
2020-11-19 15:00:52 +01:00
|
|
|
if fi.isJniLib && !android.InList(fi.stem(), jniLibs) {
|
|
|
|
jniLibs = append(jniLibs, fi.stem())
|
2020-02-27 05:50:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(jniLibs) > 0 {
|
|
|
|
optCommands = append(optCommands, "-a jniLibs "+strings.Join(jniLibs, " "))
|
|
|
|
}
|
|
|
|
|
2020-11-24 11:51:18 +01:00
|
|
|
manifestJsonFullOut := android.PathForModuleOut(ctx, "apex_manifest_full.json")
|
2019-11-18 03:16:27 +01:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: apexManifestRule,
|
2020-11-24 11:51:18 +01:00
|
|
|
Input: src,
|
2019-11-12 05:03:50 +01:00
|
|
|
Output: manifestJsonFullOut,
|
2019-11-18 03:16:27 +01:00
|
|
|
Args: map[string]string{
|
|
|
|
"provideNativeLibs": strings.Join(provideNativeLibs, " "),
|
|
|
|
"requireNativeLibs": strings.Join(requireNativeLibs, " "),
|
|
|
|
"opt": strings.Join(optCommands, " "),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2020-11-24 11:51:18 +01:00
|
|
|
// b/143654022 Q apexd can't understand newly added keys in apex_manifest.json prepare
|
|
|
|
// stripped-down version so that APEX modules built from R+ can be installed to Q
|
2020-07-23 07:32:17 +02:00
|
|
|
minSdkVersion := a.minSdkVersion(ctx)
|
|
|
|
if minSdkVersion.EqualTo(android.SdkVersion_Android10) {
|
2019-11-12 05:03:50 +01:00
|
|
|
a.manifestJsonOut = android.PathForModuleOut(ctx, "apex_manifest.json")
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: stripApexManifestRule,
|
|
|
|
Input: manifestJsonFullOut,
|
|
|
|
Output: a.manifestJsonOut,
|
|
|
|
})
|
|
|
|
}
|
2019-11-18 03:16:27 +01:00
|
|
|
|
2020-11-24 11:51:18 +01:00
|
|
|
// From R+, protobuf binary format (.pb) is the standard format for apex_manifest
|
2019-11-18 03:16:27 +01:00
|
|
|
a.manifestPbOut = android.PathForModuleOut(ctx, "apex_manifest.pb")
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: pbApexManifestRule,
|
2019-11-12 05:03:50 +01:00
|
|
|
Input: manifestJsonFullOut,
|
2019-11-18 03:16:27 +01:00
|
|
|
Output: a.manifestPbOut,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-11-24 11:51:18 +01:00
|
|
|
// buildFileContexts create build rules to append an entry for apex_manifest.pb to the file_contexts
|
|
|
|
// file for this APEX which is either from /systme/sepolicy/apex/<apexname>-file_contexts or from
|
|
|
|
// the file_contexts property of this APEX. This is to make sure that the manifest file is correctly
|
|
|
|
// labeled as system_file.
|
|
|
|
func (a *apexBundle) buildFileContexts(ctx android.ModuleContext) android.OutputPath {
|
2020-06-24 12:33:06 +02:00
|
|
|
var fileContexts android.Path
|
2021-09-14 23:53:38 +02:00
|
|
|
var fileContextsDir string
|
2020-06-24 12:33:06 +02:00
|
|
|
if a.properties.File_contexts == nil {
|
|
|
|
fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
|
|
|
|
} else {
|
2021-09-14 23:53:38 +02:00
|
|
|
if m, t := android.SrcIsModuleWithTag(*a.properties.File_contexts); m != "" {
|
|
|
|
otherModule := android.GetModuleFromPathDep(ctx, m, t)
|
|
|
|
fileContextsDir = ctx.OtherModuleDir(otherModule)
|
|
|
|
}
|
2020-06-24 12:33:06 +02:00
|
|
|
fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
|
|
|
|
}
|
2021-09-14 23:53:38 +02:00
|
|
|
if fileContextsDir == "" {
|
|
|
|
fileContextsDir = filepath.Dir(fileContexts.String())
|
|
|
|
}
|
|
|
|
fileContextsDir += string(filepath.Separator)
|
|
|
|
|
2020-06-24 12:33:06 +02:00
|
|
|
if a.Platform() {
|
2021-09-14 23:53:38 +02:00
|
|
|
if !strings.HasPrefix(fileContextsDir, "system/sepolicy/") {
|
|
|
|
ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but found in %q", fileContextsDir)
|
2020-06-24 12:33:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if !android.ExistentPathForSource(ctx, fileContexts.String()).Valid() {
|
2020-11-24 11:51:18 +01:00
|
|
|
ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", fileContexts.String())
|
2020-06-24 12:33:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
output := android.PathForModuleOut(ctx, "file_contexts")
|
2020-11-17 02:32:30 +01:00
|
|
|
rule := android.NewRuleBuilder(pctx, ctx)
|
2020-09-23 12:15:55 +02:00
|
|
|
|
2020-11-24 11:51:18 +01:00
|
|
|
switch a.properties.ApexType {
|
|
|
|
case imageApex:
|
2020-09-23 12:15:55 +02:00
|
|
|
// remove old file
|
|
|
|
rule.Command().Text("rm").FlagWithOutput("-f ", output)
|
|
|
|
// copy file_contexts
|
|
|
|
rule.Command().Text("cat").Input(fileContexts).Text(">>").Output(output)
|
|
|
|
// new line
|
|
|
|
rule.Command().Text("echo").Text(">>").Output(output)
|
|
|
|
// force-label /apex_manifest.pb and / as system_file so that apexd can read them
|
|
|
|
rule.Command().Text("echo").Flag("/apex_manifest\\\\.pb u:object_r:system_file:s0").Text(">>").Output(output)
|
|
|
|
rule.Command().Text("echo").Flag("/ u:object_r:system_file:s0").Text(">>").Output(output)
|
2020-11-24 11:51:18 +01:00
|
|
|
case flattenedApex:
|
2020-09-23 12:15:55 +02:00
|
|
|
// For flattened apexes, install path should be prepended.
|
|
|
|
// File_contexts file should be emiited to make via LOCAL_FILE_CONTEXTS
|
|
|
|
// so that it can be merged into file_contexts.bin
|
|
|
|
apexPath := android.InstallPathToOnDevicePath(ctx, a.installDir.Join(ctx, a.Name()))
|
|
|
|
apexPath = strings.ReplaceAll(apexPath, ".", `\\.`)
|
|
|
|
// remove old file
|
|
|
|
rule.Command().Text("rm").FlagWithOutput("-f ", output)
|
|
|
|
// copy file_contexts
|
|
|
|
rule.Command().Text("awk").Text(`'/object_r/{printf("` + apexPath + `%s\n", $0)}'`).Input(fileContexts).Text(">").Output(output)
|
|
|
|
// new line
|
|
|
|
rule.Command().Text("echo").Text(">>").Output(output)
|
|
|
|
// force-label /apex_manifest.pb and / as system_file so that apexd can read them
|
|
|
|
rule.Command().Text("echo").Flag(apexPath + `/apex_manifest\\.pb u:object_r:system_file:s0`).Text(">>").Output(output)
|
|
|
|
rule.Command().Text("echo").Flag(apexPath + "/ u:object_r:system_file:s0").Text(">>").Output(output)
|
2020-11-24 11:51:18 +01:00
|
|
|
default:
|
|
|
|
panic(fmt.Errorf("unsupported type %v", a.properties.ApexType))
|
2020-09-23 12:15:55 +02:00
|
|
|
}
|
|
|
|
|
2020-11-17 02:32:30 +01:00
|
|
|
rule.Build("file_contexts."+a.Name(), "Generate file_contexts")
|
2020-11-24 11:51:18 +01:00
|
|
|
return output.OutputPath
|
2020-06-24 12:33:06 +02:00
|
|
|
}
|
|
|
|
|
2020-11-24 11:51:18 +01:00
|
|
|
// buildInstalledFilesFile creates a build rule for the installed-files.txt file where the list of
|
|
|
|
// files included in this APEX is shown. The text file is dist'ed so that people can see what's
|
|
|
|
// included in the APEX without actually downloading and extracting it.
|
2020-01-14 06:39:19 +01:00
|
|
|
func (a *apexBundle) buildInstalledFilesFile(ctx android.ModuleContext, builtApex android.Path, imageDir android.Path) android.OutputPath {
|
|
|
|
output := android.PathForModuleOut(ctx, "installed-files.txt")
|
2020-11-17 02:32:30 +01:00
|
|
|
rule := android.NewRuleBuilder(pctx, ctx)
|
2020-01-14 06:39:19 +01:00
|
|
|
rule.Command().
|
|
|
|
Implicit(builtApex).
|
|
|
|
Text("(cd " + imageDir.String() + " ; ").
|
2020-02-08 04:40:05 +01:00
|
|
|
Text("find . \\( -type f -o -type l \\) -printf \"%s %p\\n\") ").
|
2020-01-14 06:39:19 +01:00
|
|
|
Text(" | sort -nr > ").
|
|
|
|
Output(output)
|
2020-11-17 02:32:30 +01:00
|
|
|
rule.Build("installed-files."+a.Name(), "Installed files")
|
2020-01-14 06:39:19 +01:00
|
|
|
return output.OutputPath
|
|
|
|
}
|
|
|
|
|
2020-11-24 11:51:18 +01:00
|
|
|
// buildBundleConfig creates a build rule for the bundle config file that will control the bundle
|
|
|
|
// creation process.
|
2020-02-28 07:22:21 +01:00
|
|
|
func (a *apexBundle) buildBundleConfig(ctx android.ModuleContext) android.OutputPath {
|
|
|
|
output := android.PathForModuleOut(ctx, "bundle_config.json")
|
|
|
|
|
2020-02-28 08:51:07 +01:00
|
|
|
type ApkConfig struct {
|
|
|
|
Package_name string `json:"package_name"`
|
|
|
|
Apk_path string `json:"path"`
|
|
|
|
}
|
2020-02-28 07:22:21 +01:00
|
|
|
config := struct {
|
|
|
|
Compression struct {
|
|
|
|
Uncompressed_glob []string `json:"uncompressed_glob"`
|
|
|
|
} `json:"compression"`
|
2020-02-28 08:51:07 +01:00
|
|
|
Apex_config struct {
|
|
|
|
Apex_embedded_apk_config []ApkConfig `json:"apex_embedded_apk_config,omitempty"`
|
|
|
|
} `json:"apex_config,omitempty"`
|
2020-02-28 07:22:21 +01:00
|
|
|
}{}
|
|
|
|
|
|
|
|
config.Compression.Uncompressed_glob = []string{
|
|
|
|
"apex_payload.img",
|
|
|
|
"apex_manifest.*",
|
|
|
|
}
|
2020-02-28 08:51:07 +01:00
|
|
|
|
2020-11-24 11:51:18 +01:00
|
|
|
// Collect the manifest names and paths of android apps if their manifest names are
|
|
|
|
// overridden.
|
2020-02-28 08:51:07 +01:00
|
|
|
for _, fi := range a.filesInfo {
|
2020-05-28 01:36:07 +02:00
|
|
|
if fi.class != app && fi.class != appSet {
|
2020-02-28 08:51:07 +01:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
packageName := fi.overriddenPackageName
|
|
|
|
if packageName != "" {
|
|
|
|
config.Apex_config.Apex_embedded_apk_config = append(
|
|
|
|
config.Apex_config.Apex_embedded_apk_config,
|
|
|
|
ApkConfig{
|
|
|
|
Package_name: packageName,
|
2020-11-19 15:00:52 +01:00
|
|
|
Apk_path: fi.path(),
|
2020-02-28 08:51:07 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-28 07:22:21 +01:00
|
|
|
j, err := json.Marshal(config)
|
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Errorf("error while marshalling to %q: %#v", output, err))
|
|
|
|
}
|
|
|
|
|
2020-11-13 20:48:42 +01:00
|
|
|
android.WriteFileRule(ctx, output, string(j))
|
2020-02-28 07:22:21 +01:00
|
|
|
|
|
|
|
return output.OutputPath
|
|
|
|
}
|
|
|
|
|
2022-01-24 18:44:05 +01:00
|
|
|
func markManifestTestOnly(ctx android.ModuleContext, androidManifestFile android.Path) android.Path {
|
2022-02-10 14:28:35 +01:00
|
|
|
return java.ManifestFixer(ctx, androidManifestFile, java.ManifestFixerParams{
|
|
|
|
TestOnly: true,
|
2022-01-24 18:44:05 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-11-24 11:51:18 +01:00
|
|
|
// buildUnflattendApex creates build rules to build an APEX using apexer.
|
2019-11-18 03:16:27 +01:00
|
|
|
func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) {
|
|
|
|
apexType := a.properties.ApexType
|
|
|
|
suffix := apexType.suffix()
|
2021-11-04 20:01:18 +01:00
|
|
|
apexName := proptools.StringDefault(a.properties.Apex_name, a.BaseModuleName())
|
2019-11-18 03:16:27 +01:00
|
|
|
|
2020-11-24 11:51:18 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Step 1: copy built files to appropriate directories under the image directory
|
|
|
|
|
|
|
|
imageDir := android.PathForModuleOut(ctx, "image"+suffix)
|
|
|
|
|
2022-04-19 02:42:27 +02:00
|
|
|
installSymbolFiles := (!ctx.Config().KatiEnabled() || a.ExportedToMake()) && a.installable()
|
2021-11-04 20:01:18 +01:00
|
|
|
|
|
|
|
// b/140136207. When there are overriding APEXes for a VNDK APEX, the symbols file for the overridden
|
|
|
|
// APEX and the overriding APEX will have the same installation paths at /apex/com.android.vndk.v<ver>
|
|
|
|
// as their apexName will be the same. To avoid the path conflicts, skip installing the symbol files
|
|
|
|
// for the overriding VNDK APEXes.
|
|
|
|
if a.vndkApex && len(a.overridableProperties.Overrides) > 0 {
|
|
|
|
installSymbolFiles = false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Avoid creating duplicate build rules for multi-installed APEXes.
|
|
|
|
if proptools.BoolDefault(a.properties.Multi_install_skip_symbol_files, false) {
|
|
|
|
installSymbolFiles = false
|
2021-12-11 00:05:02 +01:00
|
|
|
|
2021-11-04 20:01:18 +01:00
|
|
|
}
|
2021-12-11 00:05:02 +01:00
|
|
|
// set of dependency module:location mappings
|
|
|
|
installMapSet := make(map[string]bool)
|
2021-11-04 20:01:18 +01:00
|
|
|
|
2020-11-24 11:51:18 +01:00
|
|
|
// TODO(jiyong): use the RuleBuilder
|
2020-01-14 01:22:18 +01:00
|
|
|
var copyCommands []string
|
2020-11-24 11:51:18 +01:00
|
|
|
var implicitInputs []android.Path
|
2021-11-04 20:01:18 +01:00
|
|
|
pathWhenActivated := android.PathForModuleInPartitionInstall(ctx, "apex", apexName)
|
2020-01-14 01:22:18 +01:00
|
|
|
for _, fi := range a.filesInfo {
|
2020-11-24 11:51:18 +01:00
|
|
|
destPath := imageDir.Join(ctx, fi.path()).String()
|
|
|
|
// Prepare the destination path
|
2020-05-28 01:36:07 +02:00
|
|
|
destPathDir := filepath.Dir(destPath)
|
|
|
|
if fi.class == appSet {
|
|
|
|
copyCommands = append(copyCommands, "rm -rf "+destPathDir)
|
|
|
|
}
|
|
|
|
copyCommands = append(copyCommands, "mkdir -p "+destPathDir)
|
2020-11-24 11:51:18 +01:00
|
|
|
|
2021-12-11 00:05:02 +01:00
|
|
|
installMapPath := fi.builtFile
|
|
|
|
|
2020-11-24 11:51:18 +01:00
|
|
|
// Copy the built file to the directory. But if the symlink optimization is turned
|
|
|
|
// on, place a symlink to the corresponding file in /system partition instead.
|
2020-11-19 15:00:52 +01:00
|
|
|
if a.linkToSystemLib && fi.transitiveDep && fi.availableToPlatform() {
|
2020-01-14 01:22:18 +01:00
|
|
|
// TODO(jiyong): pathOnDevice should come from fi.module, not being calculated here
|
2020-11-19 15:00:52 +01:00
|
|
|
pathOnDevice := filepath.Join("/system", fi.path())
|
2020-01-14 01:22:18 +01:00
|
|
|
copyCommands = append(copyCommands, "ln -sfn "+pathOnDevice+" "+destPath)
|
|
|
|
} else {
|
2021-12-11 00:05:02 +01:00
|
|
|
var installedPath android.InstallPath
|
2020-05-28 01:36:07 +02:00
|
|
|
if fi.class == appSet {
|
|
|
|
copyCommands = append(copyCommands,
|
2021-11-12 21:19:42 +01:00
|
|
|
fmt.Sprintf("unzip -qDD -d %s %s", destPathDir,
|
|
|
|
fi.module.(*java.AndroidAppSet).PackedAdditionalOutputs().String()))
|
2021-11-04 20:01:18 +01:00
|
|
|
if installSymbolFiles {
|
|
|
|
installedPath = ctx.InstallFileWithExtraFilesZip(pathWhenActivated.Join(ctx, fi.installDir),
|
|
|
|
fi.stem(), fi.builtFile, fi.module.(*java.AndroidAppSet).PackedAdditionalOutputs())
|
|
|
|
}
|
2020-05-28 01:36:07 +02:00
|
|
|
} else {
|
|
|
|
copyCommands = append(copyCommands, "cp -f "+fi.builtFile.String()+" "+destPath)
|
2021-11-04 20:01:18 +01:00
|
|
|
if installSymbolFiles {
|
|
|
|
installedPath = ctx.InstallFile(pathWhenActivated.Join(ctx, fi.installDir), fi.stem(), fi.builtFile)
|
|
|
|
}
|
2020-05-28 01:36:07 +02:00
|
|
|
}
|
2020-01-14 01:22:18 +01:00
|
|
|
implicitInputs = append(implicitInputs, fi.builtFile)
|
2021-11-04 20:01:18 +01:00
|
|
|
if installSymbolFiles {
|
|
|
|
implicitInputs = append(implicitInputs, installedPath)
|
|
|
|
}
|
2020-11-24 11:51:18 +01:00
|
|
|
|
2021-12-11 00:05:02 +01:00
|
|
|
// Create additional symlinks pointing the file inside the APEX (if any). Note that
|
|
|
|
// this is independent from the symlink optimization.
|
|
|
|
for _, symlinkPath := range fi.symlinkPaths() {
|
|
|
|
symlinkDest := imageDir.Join(ctx, symlinkPath).String()
|
|
|
|
copyCommands = append(copyCommands, "ln -sfn "+filepath.Base(destPath)+" "+symlinkDest)
|
|
|
|
if installSymbolFiles {
|
|
|
|
installedSymlink := ctx.InstallSymlink(pathWhenActivated.Join(ctx, filepath.Dir(symlinkPath)), filepath.Base(symlinkPath), installedPath)
|
|
|
|
implicitInputs = append(implicitInputs, installedSymlink)
|
|
|
|
}
|
2021-11-04 20:01:18 +01:00
|
|
|
}
|
2021-12-11 00:05:02 +01:00
|
|
|
|
|
|
|
installMapPath = installedPath
|
2020-01-14 01:22:18 +01:00
|
|
|
}
|
2020-11-24 11:51:18 +01:00
|
|
|
|
|
|
|
// Copy the test files (if any)
|
2020-05-13 00:26:55 +02:00
|
|
|
for _, d := range fi.dataPaths {
|
|
|
|
// TODO(eakammer): This is now the third repetition of ~this logic for test paths, refactoring should be possible
|
2020-07-09 23:12:52 +02:00
|
|
|
relPath := d.SrcPath.Rel()
|
|
|
|
dataPath := d.SrcPath.String()
|
2020-05-13 00:26:55 +02:00
|
|
|
if !strings.HasSuffix(dataPath, relPath) {
|
|
|
|
panic(fmt.Errorf("path %q does not end with %q", dataPath, relPath))
|
|
|
|
}
|
|
|
|
|
2020-11-24 11:51:18 +01:00
|
|
|
dataDest := imageDir.Join(ctx, fi.apexRelativePath(relPath), d.RelativeInstallPath).String()
|
2020-05-13 00:26:55 +02:00
|
|
|
|
2020-07-09 23:12:52 +02:00
|
|
|
copyCommands = append(copyCommands, "cp -f "+d.SrcPath.String()+" "+dataDest)
|
|
|
|
implicitInputs = append(implicitInputs, d.SrcPath)
|
2020-05-13 00:26:55 +02:00
|
|
|
}
|
2021-12-11 00:05:02 +01:00
|
|
|
|
|
|
|
installMapSet[installMapPath.String()+":"+fi.installDir+"/"+fi.builtFile.Base()] = true
|
2019-11-18 03:16:27 +01:00
|
|
|
}
|
2019-11-12 05:03:50 +01:00
|
|
|
implicitInputs = append(implicitInputs, a.manifestPbOut)
|
2021-11-04 20:01:18 +01:00
|
|
|
if installSymbolFiles {
|
|
|
|
installedManifest := ctx.InstallFile(pathWhenActivated, "apex_manifest.pb", a.manifestPbOut)
|
|
|
|
installedKey := ctx.InstallFile(pathWhenActivated, "apex_pubkey", a.publicKeyFile)
|
|
|
|
implicitInputs = append(implicitInputs, installedManifest, installedKey)
|
|
|
|
}
|
2019-11-18 03:16:27 +01:00
|
|
|
|
2021-12-11 00:05:02 +01:00
|
|
|
if len(installMapSet) > 0 {
|
|
|
|
var installs []string
|
|
|
|
installs = append(installs, android.SortedStringKeys(installMapSet)...)
|
|
|
|
a.SetLicenseInstallMap(installs)
|
|
|
|
}
|
|
|
|
|
2020-11-24 11:51:18 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Step 1.a: Write the list of files in this APEX to a txt file and compare it against
|
|
|
|
// the allowed list given via the allowed_files property. Build fails when the two lists
|
|
|
|
// differ.
|
|
|
|
//
|
|
|
|
// TODO(jiyong): consider removing this. Nobody other than com.android.apex.cts.shim.* seems
|
|
|
|
// to be using this at this moment. Furthermore, this looks very similar to what
|
|
|
|
// buildInstalledFilesFile does. At least, move this to somewhere else so that this doesn't
|
|
|
|
// hurt readability.
|
|
|
|
// TODO(jiyong): use RuleBuilder
|
2020-06-20 05:47:47 +02:00
|
|
|
if a.overridableProperties.Allowed_files != nil {
|
2020-11-24 11:51:18 +01:00
|
|
|
// Build content.txt
|
|
|
|
var emitCommands []string
|
|
|
|
imageContentFile := android.PathForModuleOut(ctx, "content.txt")
|
|
|
|
emitCommands = append(emitCommands, "echo ./apex_manifest.pb >> "+imageContentFile.String())
|
|
|
|
minSdkVersion := a.minSdkVersion(ctx)
|
|
|
|
if minSdkVersion.EqualTo(android.SdkVersion_Android10) {
|
|
|
|
emitCommands = append(emitCommands, "echo ./apex_manifest.json >> "+imageContentFile.String())
|
|
|
|
}
|
|
|
|
for _, fi := range a.filesInfo {
|
|
|
|
emitCommands = append(emitCommands, "echo './"+fi.path()+"' >> "+imageContentFile.String())
|
|
|
|
}
|
|
|
|
emitCommands = append(emitCommands, "sort -o "+imageContentFile.String()+" "+imageContentFile.String())
|
2019-11-18 03:16:27 +01:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: emitApexContentRule,
|
|
|
|
Implicits: implicitInputs,
|
|
|
|
Output: imageContentFile,
|
|
|
|
Description: "emit apex image content",
|
|
|
|
Args: map[string]string{
|
|
|
|
"emit_commands": strings.Join(emitCommands, " && "),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
implicitInputs = append(implicitInputs, imageContentFile)
|
|
|
|
|
2020-11-24 11:51:18 +01:00
|
|
|
// Compare content.txt against allowed_files.
|
|
|
|
allowedFilesFile := android.PathForModuleSrc(ctx, proptools.String(a.overridableProperties.Allowed_files))
|
2019-11-22 23:50:42 +01:00
|
|
|
phonyOutput := android.PathForModuleOut(ctx, a.Name()+"-diff-phony-output")
|
2019-11-18 03:16:27 +01:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: diffApexContentRule,
|
|
|
|
Implicits: implicitInputs,
|
|
|
|
Output: phonyOutput,
|
|
|
|
Description: "diff apex image content",
|
|
|
|
Args: map[string]string{
|
2020-06-11 20:32:11 +02:00
|
|
|
"allowed_files_file": allowedFilesFile.String(),
|
|
|
|
"image_content_file": imageContentFile.String(),
|
|
|
|
"apex_module_name": a.Name(),
|
2019-11-18 03:16:27 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
implicitInputs = append(implicitInputs, phonyOutput)
|
|
|
|
}
|
|
|
|
|
2020-11-24 11:51:18 +01:00
|
|
|
unsignedOutputFile := android.PathForModuleOut(ctx, a.Name()+suffix+".unsigned")
|
2021-10-26 04:15:55 +02:00
|
|
|
outHostBinDir := ctx.Config().HostToolPath(ctx, "").String()
|
2019-11-18 03:16:27 +01:00
|
|
|
prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin")
|
|
|
|
|
2021-10-14 21:33:41 +02:00
|
|
|
// Figure out if we need to compress the apex.
|
|
|
|
compressionEnabled := ctx.Config().CompressedApex() && proptools.BoolDefault(a.overridableProperties.Compressible, false) && !a.testApex && !ctx.Config().UnbundledBuildApps()
|
2019-11-18 03:16:27 +01:00
|
|
|
if apexType == imageApex {
|
2021-12-13 15:40:17 +01:00
|
|
|
|
2020-11-24 11:51:18 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Step 2: create canned_fs_config which encodes filemode,uid,gid of each files
|
|
|
|
// in this APEX. The file will be used by apexer in later steps.
|
2021-12-13 15:40:17 +01:00
|
|
|
cannedFsConfig := a.buildCannedFsConfig(ctx)
|
2020-11-24 11:51:18 +01:00
|
|
|
implicitInputs = append(implicitInputs, cannedFsConfig)
|
2019-11-18 03:16:27 +01:00
|
|
|
|
2020-11-24 11:51:18 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Step 3: Prepare option flags for apexer and invoke it to create an unsigned APEX.
|
|
|
|
// TODO(jiyong): use the RuleBuilder
|
2019-11-18 03:16:27 +01:00
|
|
|
optFlags := []string{}
|
|
|
|
|
2020-11-24 11:51:18 +01:00
|
|
|
fileContexts := a.buildFileContexts(ctx)
|
|
|
|
implicitInputs = append(implicitInputs, fileContexts)
|
|
|
|
|
2020-12-21 18:11:10 +01:00
|
|
|
implicitInputs = append(implicitInputs, a.privateKeyFile, a.publicKeyFile)
|
|
|
|
optFlags = append(optFlags, "--pubkey "+a.publicKeyFile.String())
|
2019-11-18 03:16:27 +01:00
|
|
|
|
2019-12-16 09:45:32 +01:00
|
|
|
manifestPackageName := a.getOverrideManifestPackageName(ctx)
|
|
|
|
if manifestPackageName != "" {
|
2019-11-18 03:16:27 +01:00
|
|
|
optFlags = append(optFlags, "--override_apk_package_name "+manifestPackageName)
|
|
|
|
}
|
|
|
|
|
|
|
|
if a.properties.AndroidManifest != nil {
|
|
|
|
androidManifestFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.AndroidManifest))
|
2022-01-24 18:44:05 +01:00
|
|
|
|
|
|
|
if a.testApex {
|
|
|
|
androidManifestFile = markManifestTestOnly(ctx, androidManifestFile)
|
|
|
|
}
|
|
|
|
|
2019-11-18 03:16:27 +01:00
|
|
|
implicitInputs = append(implicitInputs, androidManifestFile)
|
|
|
|
optFlags = append(optFlags, "--android_manifest "+androidManifestFile.String())
|
2022-02-03 22:01:51 +01:00
|
|
|
} else if a.testApex {
|
|
|
|
optFlags = append(optFlags, "--test_only")
|
2019-11-18 03:16:27 +01:00
|
|
|
}
|
|
|
|
|
2020-11-24 11:51:18 +01:00
|
|
|
// Determine target/min sdk version from the context
|
|
|
|
// TODO(jiyong): make this as a function
|
2020-07-23 07:32:17 +02:00
|
|
|
moduleMinSdkVersion := a.minSdkVersion(ctx)
|
2020-10-20 01:02:15 +02:00
|
|
|
minSdkVersion := moduleMinSdkVersion.String()
|
|
|
|
|
2020-11-24 11:51:18 +01:00
|
|
|
// bundletool doesn't understand what "current" is. We need to transform it to
|
|
|
|
// codename
|
2021-01-26 03:43:46 +01:00
|
|
|
if moduleMinSdkVersion.IsCurrent() || moduleMinSdkVersion.IsNone() {
|
2020-10-20 01:02:15 +02:00
|
|
|
minSdkVersion = ctx.Config().DefaultAppTargetSdk(ctx).String()
|
2021-05-27 20:28:27 +02:00
|
|
|
|
|
|
|
if java.UseApiFingerprint(ctx) {
|
|
|
|
minSdkVersion = ctx.Config().PlatformSdkCodename() + fmt.Sprintf(".$$(cat %s)", java.ApiFingerprintPath(ctx).String())
|
|
|
|
implicitInputs = append(implicitInputs, java.ApiFingerprintPath(ctx))
|
|
|
|
}
|
2020-02-20 01:43:27 +01:00
|
|
|
}
|
2020-11-24 11:51:18 +01:00
|
|
|
// apex module doesn't have a concept of target_sdk_version, hence for the time
|
|
|
|
// being targetSdkVersion == default targetSdkVersion of the branch.
|
2020-10-20 01:02:15 +02:00
|
|
|
targetSdkVersion := strconv.Itoa(ctx.Config().DefaultAppTargetSdk(ctx).FinalOrFutureInt())
|
2020-02-20 01:43:27 +01:00
|
|
|
|
2020-03-02 17:58:11 +01:00
|
|
|
if java.UseApiFingerprint(ctx) {
|
|
|
|
targetSdkVersion = ctx.Config().PlatformSdkCodename() + fmt.Sprintf(".$$(cat %s)", java.ApiFingerprintPath(ctx).String())
|
2020-01-25 00:15:44 +01:00
|
|
|
implicitInputs = append(implicitInputs, java.ApiFingerprintPath(ctx))
|
|
|
|
}
|
2019-11-18 03:16:27 +01:00
|
|
|
optFlags = append(optFlags, "--target_sdk_version "+targetSdkVersion)
|
2020-01-25 00:15:44 +01:00
|
|
|
optFlags = append(optFlags, "--min_sdk_version "+minSdkVersion)
|
2019-11-18 03:16:27 +01:00
|
|
|
|
2020-02-20 06:29:28 +01:00
|
|
|
if a.overridableProperties.Logging_parent != "" {
|
|
|
|
optFlags = append(optFlags, "--logging_parent ", a.overridableProperties.Logging_parent)
|
|
|
|
}
|
|
|
|
|
2022-04-01 20:00:00 +02:00
|
|
|
// Create a NOTICE file, and embed it as an asset file in the APEX.
|
2022-04-05 01:12:21 +02:00
|
|
|
a.htmlGzNotice = android.PathForModuleOut(ctx, "NOTICE.html.gz")
|
2022-05-16 21:20:04 +02:00
|
|
|
android.BuildNoticeHtmlOutputFromLicenseMetadata(ctx, a.htmlGzNotice, "", unsignedOutputFile.String())
|
2022-04-05 01:12:21 +02:00
|
|
|
noticeAssetPath := android.PathForModuleOut(ctx, "NOTICE", "NOTICE.html.gz")
|
|
|
|
builder := android.NewRuleBuilder(pctx, ctx)
|
|
|
|
builder.Command().Text("cp").
|
|
|
|
Input(a.htmlGzNotice).
|
|
|
|
Output(noticeAssetPath)
|
|
|
|
builder.Build("notice_dir", "Building notice dir")
|
|
|
|
implicitInputs = append(implicitInputs, noticeAssetPath)
|
|
|
|
optFlags = append(optFlags, "--assets_dir "+filepath.Dir(noticeAssetPath.String()))
|
2019-11-18 03:16:27 +01:00
|
|
|
|
2021-06-09 20:43:46 +02:00
|
|
|
if (moduleMinSdkVersion.GreaterThan(android.SdkVersion_Android10) && !a.shouldGenerateHashtree()) && !compressionEnabled {
|
2019-11-18 03:16:27 +01:00
|
|
|
// Apexes which are supposed to be installed in builtin dirs(/system, etc)
|
|
|
|
// don't need hashtree for activation. Therefore, by removing hashtree from
|
|
|
|
// apex bundle (filesystem image in it, to be specific), we can save storage.
|
|
|
|
optFlags = append(optFlags, "--no_hashtree")
|
|
|
|
}
|
|
|
|
|
2020-04-27 19:21:11 +02:00
|
|
|
if a.testOnlyShouldSkipPayloadSign() {
|
|
|
|
optFlags = append(optFlags, "--unsigned_payload")
|
|
|
|
}
|
|
|
|
|
2019-11-18 03:16:27 +01:00
|
|
|
if a.properties.Apex_name != nil {
|
2020-11-24 11:51:18 +01:00
|
|
|
// If apex_name is set, apexer can skip checking if key name matches with
|
|
|
|
// apex name. Note that apex_manifest is also mended.
|
2019-11-18 03:16:27 +01:00
|
|
|
optFlags = append(optFlags, "--do_not_check_keyname")
|
|
|
|
}
|
|
|
|
|
2020-07-23 07:32:17 +02:00
|
|
|
if moduleMinSdkVersion == android.SdkVersion_Android10 {
|
2019-11-12 05:03:50 +01:00
|
|
|
implicitInputs = append(implicitInputs, a.manifestJsonOut)
|
|
|
|
optFlags = append(optFlags, "--manifest_json "+a.manifestJsonOut.String())
|
|
|
|
}
|
|
|
|
|
2020-06-12 14:46:59 +02:00
|
|
|
optFlags = append(optFlags, "--payload_fs_type "+a.payloadFsType.string())
|
|
|
|
|
2019-11-18 03:16:27 +01:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: apexRule,
|
|
|
|
Implicits: implicitInputs,
|
|
|
|
Output: unsignedOutputFile,
|
|
|
|
Description: "apex (" + apexType.name() + ")",
|
|
|
|
Args: map[string]string{
|
2022-05-05 15:52:25 +02:00
|
|
|
"tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
|
|
|
|
"image_dir": imageDir.String(),
|
|
|
|
"copy_commands": strings.Join(copyCommands, " && "),
|
|
|
|
"manifest": a.manifestPbOut.String(),
|
|
|
|
"file_contexts": fileContexts.String(),
|
|
|
|
"canned_fs_config": cannedFsConfig.String(),
|
|
|
|
"key": a.privateKeyFile.String(),
|
|
|
|
"opt_flags": strings.Join(optFlags, " "),
|
2019-11-18 03:16:27 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2020-11-24 11:51:18 +01:00
|
|
|
// TODO(jiyong): make the two rules below as separate functions
|
2019-11-22 23:50:42 +01:00
|
|
|
apexProtoFile := android.PathForModuleOut(ctx, a.Name()+".pb"+suffix)
|
|
|
|
bundleModuleFile := android.PathForModuleOut(ctx, a.Name()+suffix+"-base.zip")
|
2019-11-18 03:16:27 +01:00
|
|
|
a.bundleModuleFile = bundleModuleFile
|
|
|
|
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: apexProtoConvertRule,
|
|
|
|
Input: unsignedOutputFile,
|
|
|
|
Output: apexProtoFile,
|
|
|
|
Description: "apex proto convert",
|
|
|
|
})
|
|
|
|
|
2020-11-12 17:39:19 +01:00
|
|
|
implicitInputs = append(implicitInputs, unsignedOutputFile)
|
|
|
|
|
|
|
|
// Run coverage analysis
|
2021-01-09 02:03:42 +01:00
|
|
|
apisUsedbyOutputFile := android.PathForModuleOut(ctx, a.Name()+"_using.txt")
|
2020-11-12 17:39:19 +01:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: generateAPIsUsedbyApexRule,
|
|
|
|
Implicits: implicitInputs,
|
|
|
|
Description: "coverage",
|
|
|
|
Output: apisUsedbyOutputFile,
|
|
|
|
Args: map[string]string{
|
|
|
|
"image_dir": imageDir.String(),
|
|
|
|
"readelf": "${config.ClangBin}/llvm-readelf",
|
|
|
|
},
|
|
|
|
})
|
2021-11-03 01:58:02 +01:00
|
|
|
a.nativeApisUsedByModuleFile = apisUsedbyOutputFile
|
2021-01-09 02:03:42 +01:00
|
|
|
|
2021-11-03 01:58:02 +01:00
|
|
|
var nativeLibNames []string
|
2021-02-09 01:49:57 +01:00
|
|
|
for _, f := range a.filesInfo {
|
|
|
|
if f.class == nativeSharedLib {
|
2021-11-03 01:58:02 +01:00
|
|
|
nativeLibNames = append(nativeLibNames, f.stem())
|
2021-02-09 01:49:57 +01:00
|
|
|
}
|
|
|
|
}
|
2021-01-09 02:03:42 +01:00
|
|
|
apisBackedbyOutputFile := android.PathForModuleOut(ctx, a.Name()+"_backing.txt")
|
|
|
|
rule := android.NewRuleBuilder(pctx, ctx)
|
|
|
|
rule.Command().
|
|
|
|
Tool(android.PathForSource(ctx, "build/soong/scripts/gen_ndk_backedby_apex.sh")).
|
|
|
|
Output(apisBackedbyOutputFile).
|
2021-11-03 01:58:02 +01:00
|
|
|
Flags(nativeLibNames)
|
2021-01-09 02:03:42 +01:00
|
|
|
rule.Build("ndk_backedby_list", "Generate API libraries backed by Apex")
|
2021-11-03 01:58:02 +01:00
|
|
|
a.nativeApisBackedByModuleFile = apisBackedbyOutputFile
|
|
|
|
|
|
|
|
var javaLibOrApkPath []android.Path
|
|
|
|
for _, f := range a.filesInfo {
|
|
|
|
if f.class == javaSharedLib || f.class == app {
|
|
|
|
javaLibOrApkPath = append(javaLibOrApkPath, f.builtFile)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
javaApiUsedbyOutputFile := android.PathForModuleOut(ctx, a.Name()+"_using.xml")
|
|
|
|
javaUsedByRule := android.NewRuleBuilder(pctx, ctx)
|
|
|
|
javaUsedByRule.Command().
|
|
|
|
Tool(android.PathForSource(ctx, "build/soong/scripts/gen_java_usedby_apex.sh")).
|
|
|
|
BuiltTool("dexdeps").
|
|
|
|
Output(javaApiUsedbyOutputFile).
|
|
|
|
Inputs(javaLibOrApkPath)
|
|
|
|
javaUsedByRule.Build("java_usedby_list", "Generate Java APIs used by Apex")
|
|
|
|
a.javaApisUsedByModuleFile = javaApiUsedbyOutputFile
|
2020-11-12 17:39:19 +01:00
|
|
|
|
2020-02-28 07:22:21 +01:00
|
|
|
bundleConfig := a.buildBundleConfig(ctx)
|
|
|
|
|
2020-11-24 11:51:18 +01:00
|
|
|
var abis []string
|
|
|
|
for _, target := range ctx.MultiTargets() {
|
|
|
|
if len(target.Arch.Abi) > 0 {
|
|
|
|
abis = append(abis, target.Arch.Abi[0])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
abis = android.FirstUniqueStrings(abis)
|
|
|
|
|
2019-11-18 03:16:27 +01:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: apexBundleRule,
|
|
|
|
Input: apexProtoFile,
|
2020-02-28 07:22:21 +01:00
|
|
|
Implicit: bundleConfig,
|
2019-11-18 03:16:27 +01:00
|
|
|
Output: a.bundleModuleFile,
|
|
|
|
Description: "apex bundle module",
|
|
|
|
Args: map[string]string{
|
2020-02-28 07:22:21 +01:00
|
|
|
"abi": strings.Join(abis, "."),
|
|
|
|
"config": bundleConfig.String(),
|
2019-11-18 03:16:27 +01:00
|
|
|
},
|
|
|
|
})
|
2020-11-24 11:51:18 +01:00
|
|
|
} else { // zipApex
|
2019-11-18 03:16:27 +01:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: zipApexRule,
|
|
|
|
Implicits: implicitInputs,
|
|
|
|
Output: unsignedOutputFile,
|
|
|
|
Description: "apex (" + apexType.name() + ")",
|
|
|
|
Args: map[string]string{
|
2022-05-05 15:52:25 +02:00
|
|
|
"tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
|
|
|
|
"image_dir": imageDir.String(),
|
|
|
|
"copy_commands": strings.Join(copyCommands, " && "),
|
|
|
|
"manifest": a.manifestPbOut.String(),
|
2019-11-18 03:16:27 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-11-24 11:51:18 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Step 4: Sign the APEX using signapk
|
2020-11-26 14:32:26 +01:00
|
|
|
signedOutputFile := android.PathForModuleOut(ctx, a.Name()+suffix)
|
2020-11-24 11:51:18 +01:00
|
|
|
|
|
|
|
pem, key := a.getCertificateAndPrivateKey(ctx)
|
2020-05-28 15:13:33 +02:00
|
|
|
rule := java.Signapk
|
|
|
|
args := map[string]string{
|
2020-11-24 11:51:18 +01:00
|
|
|
"certificates": pem.String() + " " + key.String(),
|
2021-07-11 00:26:22 +02:00
|
|
|
"flags": "-a 4096 --align-file-size", //alignment
|
2020-05-28 15:13:33 +02:00
|
|
|
}
|
2020-11-24 11:51:18 +01:00
|
|
|
implicits := android.Paths{pem, key}
|
2020-09-03 07:29:49 +02:00
|
|
|
if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_SIGNAPK") {
|
2020-05-28 15:13:33 +02:00
|
|
|
rule = java.SignapkRE
|
|
|
|
args["implicits"] = strings.Join(implicits.Strings(), ",")
|
2020-11-26 14:32:26 +01:00
|
|
|
args["outCommaList"] = signedOutputFile.String()
|
2020-05-28 15:13:33 +02:00
|
|
|
}
|
2019-11-18 03:16:27 +01:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2020-05-28 15:13:33 +02:00
|
|
|
Rule: rule,
|
2019-11-18 03:16:27 +01:00
|
|
|
Description: "signapk",
|
2020-11-26 14:32:26 +01:00
|
|
|
Output: signedOutputFile,
|
2019-11-18 03:16:27 +01:00
|
|
|
Input: unsignedOutputFile,
|
2020-05-28 15:13:33 +02:00
|
|
|
Implicits: implicits,
|
|
|
|
Args: args,
|
2019-11-18 03:16:27 +01:00
|
|
|
})
|
2022-02-24 05:58:07 +01:00
|
|
|
if suffix == imageApexSuffix {
|
|
|
|
a.outputApexFile = signedOutputFile
|
|
|
|
}
|
2020-11-26 14:32:26 +01:00
|
|
|
a.outputFile = signedOutputFile
|
|
|
|
|
2020-12-22 11:47:50 +01:00
|
|
|
if ctx.ModuleDir() != "system/apex/apexd/apexd_testdata" && a.testOnlyShouldForceCompression() {
|
|
|
|
ctx.PropertyErrorf("test_only_force_compression", "not available")
|
|
|
|
return
|
|
|
|
}
|
2021-04-14 22:35:24 +02:00
|
|
|
|
2020-12-22 11:47:50 +01:00
|
|
|
if apexType == imageApex && (compressionEnabled || a.testOnlyShouldForceCompression()) {
|
2020-11-26 14:32:26 +01:00
|
|
|
a.isCompressed = true
|
2021-09-08 18:48:28 +02:00
|
|
|
unsignedCompressedOutputFile := android.PathForModuleOut(ctx, a.Name()+imageCapexSuffix+".unsigned")
|
2020-11-26 14:32:26 +01:00
|
|
|
|
|
|
|
compressRule := android.NewRuleBuilder(pctx, ctx)
|
|
|
|
compressRule.Command().
|
|
|
|
Text("rm").
|
|
|
|
FlagWithOutput("-f ", unsignedCompressedOutputFile)
|
|
|
|
compressRule.Command().
|
|
|
|
BuiltTool("apex_compression_tool").
|
|
|
|
Flag("compress").
|
|
|
|
FlagWithArg("--apex_compression_tool ", outHostBinDir+":"+prebuiltSdkToolsBinDir).
|
|
|
|
FlagWithInput("--input ", signedOutputFile).
|
|
|
|
FlagWithOutput("--output ", unsignedCompressedOutputFile)
|
|
|
|
compressRule.Build("compressRule", "Generate unsigned compressed APEX file")
|
|
|
|
|
2021-09-08 18:48:28 +02:00
|
|
|
signedCompressedOutputFile := android.PathForModuleOut(ctx, a.Name()+imageCapexSuffix)
|
2021-01-19 12:32:29 +01:00
|
|
|
if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_SIGNAPK") {
|
|
|
|
args["outCommaList"] = signedCompressedOutputFile.String()
|
|
|
|
}
|
2020-11-26 14:32:26 +01:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: rule,
|
|
|
|
Description: "sign compressedApex",
|
|
|
|
Output: signedCompressedOutputFile,
|
|
|
|
Input: unsignedCompressedOutputFile,
|
|
|
|
Implicits: implicits,
|
|
|
|
Args: args,
|
|
|
|
})
|
|
|
|
a.outputFile = signedCompressedOutputFile
|
|
|
|
}
|
2019-11-18 03:16:27 +01:00
|
|
|
|
2021-11-04 20:01:18 +01:00
|
|
|
installSuffix := suffix
|
|
|
|
if a.isCompressed {
|
|
|
|
installSuffix = imageCapexSuffix
|
|
|
|
}
|
|
|
|
|
2022-03-08 03:38:34 +01:00
|
|
|
if !a.installable() {
|
|
|
|
a.SkipInstall()
|
|
|
|
}
|
|
|
|
|
2021-09-27 05:50:30 +02:00
|
|
|
// Install to $OUT/soong/{target,host}/.../apex.
|
2021-11-04 20:01:18 +01:00
|
|
|
a.installedFile = ctx.InstallFile(a.installDir, a.Name()+installSuffix, a.outputFile,
|
|
|
|
a.compatSymlinks.Paths()...)
|
2020-01-14 06:39:19 +01:00
|
|
|
|
|
|
|
// installed-files.txt is dist'ed
|
|
|
|
a.installedFilesFile = a.buildInstalledFilesFile(ctx, a.outputFile, imageDir)
|
2019-11-18 03:16:27 +01:00
|
|
|
}
|
|
|
|
|
2020-11-24 11:51:18 +01:00
|
|
|
// buildFlattenedApex creates rules for a flattened APEX. Flattened APEX actually doesn't have a
|
|
|
|
// single output file. It is a phony target for all the files under /system/apex/<name> directory.
|
|
|
|
// This function creates the installation rules for the files.
|
2019-11-18 03:16:27 +01:00
|
|
|
func (a *apexBundle) buildFlattenedApex(ctx android.ModuleContext) {
|
2020-11-24 11:51:18 +01:00
|
|
|
bundleName := a.Name()
|
2021-11-04 20:01:18 +01:00
|
|
|
installedSymlinks := append(android.InstallPaths(nil), a.compatSymlinks...)
|
2020-11-24 11:51:18 +01:00
|
|
|
if a.installable() {
|
|
|
|
for _, fi := range a.filesInfo {
|
|
|
|
dir := filepath.Join("apex", bundleName, fi.installDir)
|
2021-11-04 20:01:18 +01:00
|
|
|
installDir := android.PathForModuleInstall(ctx, dir)
|
|
|
|
if a.linkToSystemLib && fi.transitiveDep && fi.availableToPlatform() {
|
|
|
|
// TODO(jiyong): pathOnDevice should come from fi.module, not being calculated here
|
|
|
|
pathOnDevice := filepath.Join("/system", fi.path())
|
|
|
|
installedSymlinks = append(installedSymlinks,
|
|
|
|
ctx.InstallAbsoluteSymlink(installDir, fi.stem(), pathOnDevice))
|
|
|
|
} else {
|
|
|
|
target := ctx.InstallFile(installDir, fi.stem(), fi.builtFile)
|
|
|
|
for _, sym := range fi.symlinks {
|
|
|
|
installedSymlinks = append(installedSymlinks,
|
|
|
|
ctx.InstallSymlink(installDir, sym, target))
|
|
|
|
}
|
2020-11-24 11:51:18 +01:00
|
|
|
}
|
2019-12-17 06:30:11 +01:00
|
|
|
}
|
2021-11-04 20:01:18 +01:00
|
|
|
|
|
|
|
// Create install rules for the files added in GenerateAndroidBuildActions after
|
|
|
|
// buildFlattenedApex is called. Add the links to system libs (if any) as dependencies
|
|
|
|
// of the apex_manifest.pb file since it is always present.
|
|
|
|
dir := filepath.Join("apex", bundleName)
|
|
|
|
installDir := android.PathForModuleInstall(ctx, dir)
|
|
|
|
ctx.InstallFile(installDir, "apex_manifest.pb", a.manifestPbOut, installedSymlinks.Paths()...)
|
|
|
|
ctx.InstallFile(installDir, "apex_pubkey", a.publicKeyFile)
|
2019-11-18 03:16:27 +01:00
|
|
|
}
|
2020-11-24 11:51:18 +01:00
|
|
|
|
|
|
|
a.fileContexts = a.buildFileContexts(ctx)
|
|
|
|
|
2021-11-04 20:01:18 +01:00
|
|
|
a.outputFile = android.PathForModuleInstall(ctx, "apex", bundleName)
|
2019-11-18 03:16:27 +01:00
|
|
|
}
|
|
|
|
|
2020-11-24 11:51:18 +01:00
|
|
|
// getCertificateAndPrivateKey retrieves the cert and the private key that will be used to sign
|
|
|
|
// the zip container of this APEX. See the description of the 'certificate' property for how
|
|
|
|
// the cert and the private key are found.
|
|
|
|
func (a *apexBundle) getCertificateAndPrivateKey(ctx android.PathContext) (pem, key android.Path) {
|
2020-12-21 18:11:10 +01:00
|
|
|
if a.containerCertificateFile != nil {
|
|
|
|
return a.containerCertificateFile, a.containerPrivateKeyFile
|
2020-11-24 11:51:18 +01:00
|
|
|
}
|
2019-11-18 03:16:27 +01:00
|
|
|
|
2021-04-21 01:21:24 +02:00
|
|
|
cert := String(a.overridableProperties.Certificate)
|
2020-11-24 11:51:18 +01:00
|
|
|
if cert == "" {
|
|
|
|
return ctx.Config().DefaultAppCertificate(ctx)
|
2019-11-18 03:16:27 +01:00
|
|
|
}
|
2020-11-24 11:51:18 +01:00
|
|
|
|
|
|
|
defaultDir := ctx.Config().DefaultAppCertificateDir(ctx)
|
|
|
|
pem = defaultDir.Join(ctx, cert+".x509.pem")
|
|
|
|
key = defaultDir.Join(ctx, cert+".pk8")
|
|
|
|
return pem, key
|
2019-11-18 03:16:27 +01:00
|
|
|
}
|
2019-12-16 09:45:32 +01:00
|
|
|
|
|
|
|
func (a *apexBundle) getOverrideManifestPackageName(ctx android.ModuleContext) string {
|
|
|
|
// For VNDK APEXes, check "com.android.vndk" in PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES
|
|
|
|
// to see if it should be overridden because their <apex name> is dynamically generated
|
|
|
|
// according to its VNDK version.
|
|
|
|
if a.vndkApex {
|
|
|
|
overrideName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(vndkApexName)
|
|
|
|
if overridden {
|
|
|
|
return strings.Replace(*a.properties.Apex_name, vndkApexName, overrideName, 1)
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
2020-03-15 21:01:05 +01:00
|
|
|
if a.overridableProperties.Package_name != "" {
|
|
|
|
return a.overridableProperties.Package_name
|
|
|
|
}
|
2020-03-03 03:45:41 +01:00
|
|
|
manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName())
|
2019-12-16 09:45:32 +01:00
|
|
|
if overridden {
|
|
|
|
return manifestPackageName
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
2020-01-14 10:38:44 +01:00
|
|
|
|
|
|
|
func (a *apexBundle) buildApexDependencyInfo(ctx android.ModuleContext) {
|
|
|
|
if !a.primaryApexType {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if a.properties.IsCoverageVariant {
|
|
|
|
// Otherwise, we will have duplicated rules for coverage and
|
|
|
|
// non-coverage variants of the same APEX
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if ctx.Host() {
|
|
|
|
// No need to generate dependency info for host variant
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-04-27 18:08:37 +02:00
|
|
|
depInfos := android.DepNameToDepInfoMap{}
|
2020-04-15 04:03:39 +02:00
|
|
|
a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
|
2020-04-27 18:08:37 +02:00
|
|
|
if from.Name() == to.Name() {
|
|
|
|
// This can happen for cc.reuseObjTag. We are not interested in tracking this.
|
|
|
|
// As soon as the dependency graph crosses the APEX boundary, don't go further.
|
|
|
|
return !externalDep
|
2020-02-07 09:25:49 +01:00
|
|
|
}
|
2020-01-14 10:38:44 +01:00
|
|
|
|
2021-03-11 19:03:42 +01:00
|
|
|
// Skip dependencies that are only available to APEXes; they are developed with updatability
|
|
|
|
// in mind and don't need manual approval.
|
|
|
|
if to.(android.ApexModule).NotAvailableForPlatform() {
|
|
|
|
return !externalDep
|
|
|
|
}
|
|
|
|
|
2020-12-10 16:12:38 +01:00
|
|
|
depTag := ctx.OtherModuleDependencyTag(to)
|
2021-03-11 19:03:42 +01:00
|
|
|
// Check to see if dependency been marked to skip the dependency check
|
2020-12-10 16:12:38 +01:00
|
|
|
if skipDepCheck, ok := depTag.(android.SkipApexAllowedDependenciesCheck); ok && skipDepCheck.SkipApexAllowedDependenciesCheck() {
|
|
|
|
return !externalDep
|
|
|
|
}
|
|
|
|
|
2020-04-27 18:08:37 +02:00
|
|
|
if info, exists := depInfos[to.Name()]; exists {
|
|
|
|
if !android.InList(from.Name(), info.From) {
|
|
|
|
info.From = append(info.From, from.Name())
|
|
|
|
}
|
|
|
|
info.IsExternal = info.IsExternal && externalDep
|
|
|
|
depInfos[to.Name()] = info
|
|
|
|
} else {
|
2020-04-27 19:53:18 +02:00
|
|
|
toMinSdkVersion := "(no version)"
|
2021-04-02 01:45:46 +02:00
|
|
|
if m, ok := to.(interface {
|
|
|
|
MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec
|
|
|
|
}); ok {
|
|
|
|
if v := m.MinSdkVersion(ctx); !v.ApiLevel.IsNone() {
|
|
|
|
toMinSdkVersion = v.ApiLevel.String()
|
2020-04-27 19:53:18 +02:00
|
|
|
}
|
2021-04-02 01:45:46 +02:00
|
|
|
} else if m, ok := to.(interface{ MinSdkVersion() string }); ok {
|
|
|
|
// TODO(b/175678607) eliminate the use of MinSdkVersion returning
|
|
|
|
// string
|
|
|
|
if v := m.MinSdkVersion(); v != "" {
|
2021-03-29 13:11:58 +02:00
|
|
|
toMinSdkVersion = v
|
|
|
|
}
|
2020-04-27 19:53:18 +02:00
|
|
|
}
|
2020-04-27 18:08:37 +02:00
|
|
|
depInfos[to.Name()] = android.ApexModuleDepInfo{
|
2020-04-27 19:53:18 +02:00
|
|
|
To: to.Name(),
|
|
|
|
From: []string{from.Name()},
|
|
|
|
IsExternal: externalDep,
|
|
|
|
MinSdkVersion: toMinSdkVersion,
|
2020-04-27 18:08:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// As soon as the dependency graph crosses the APEX boundary, don't go further.
|
|
|
|
return !externalDep
|
2020-01-14 10:38:44 +01:00
|
|
|
})
|
|
|
|
|
2022-03-21 21:11:16 +01:00
|
|
|
a.ApexBundleDepsInfo.BuildDepsInfoLists(ctx, a.MinSdkVersion(ctx).Raw, depInfos)
|
2020-04-27 18:08:37 +02:00
|
|
|
|
2020-01-14 10:38:44 +01:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: android.Phony,
|
|
|
|
Output: android.PathForPhony(ctx, a.Name()+"-deps-info"),
|
2020-04-27 19:07:06 +02:00
|
|
|
Inputs: []android.Path{
|
|
|
|
a.ApexBundleDepsInfo.FullListPath(),
|
|
|
|
a.ApexBundleDepsInfo.FlatListPath(),
|
|
|
|
},
|
2020-01-14 10:38:44 +01:00
|
|
|
})
|
|
|
|
}
|
2020-07-22 05:31:17 +02:00
|
|
|
|
|
|
|
func (a *apexBundle) buildLintReports(ctx android.ModuleContext) {
|
|
|
|
depSetsBuilder := java.NewLintDepSetBuilder()
|
|
|
|
for _, fi := range a.filesInfo {
|
|
|
|
depSetsBuilder.Transitive(fi.lintDepSets)
|
|
|
|
}
|
|
|
|
|
|
|
|
a.lintReports = java.BuildModuleLintReportZips(ctx, depSetsBuilder.Build())
|
|
|
|
}
|
2021-12-13 15:40:17 +01:00
|
|
|
|
|
|
|
func (a *apexBundle) buildCannedFsConfig(ctx android.ModuleContext) android.OutputPath {
|
|
|
|
var readOnlyPaths = []string{"apex_manifest.json", "apex_manifest.pb"}
|
|
|
|
var executablePaths []string // this also includes dirs
|
|
|
|
var appSetDirs []string
|
|
|
|
appSetFiles := make(map[string]android.Path)
|
|
|
|
for _, f := range a.filesInfo {
|
|
|
|
pathInApex := f.path()
|
|
|
|
if f.installDir == "bin" || strings.HasPrefix(f.installDir, "bin/") {
|
|
|
|
executablePaths = append(executablePaths, pathInApex)
|
|
|
|
for _, d := range f.dataPaths {
|
|
|
|
readOnlyPaths = append(readOnlyPaths, filepath.Join(f.installDir, d.RelativeInstallPath, d.SrcPath.Rel()))
|
|
|
|
}
|
|
|
|
for _, s := range f.symlinks {
|
|
|
|
executablePaths = append(executablePaths, filepath.Join(f.installDir, s))
|
|
|
|
}
|
|
|
|
} else if f.class == appSet {
|
|
|
|
appSetDirs = append(appSetDirs, f.installDir)
|
|
|
|
appSetFiles[f.installDir] = f.builtFile
|
|
|
|
} else {
|
|
|
|
readOnlyPaths = append(readOnlyPaths, pathInApex)
|
|
|
|
}
|
|
|
|
dir := f.installDir
|
|
|
|
for !android.InList(dir, executablePaths) && dir != "" {
|
|
|
|
executablePaths = append(executablePaths, dir)
|
|
|
|
dir, _ = filepath.Split(dir) // move up to the parent
|
|
|
|
if len(dir) > 0 {
|
|
|
|
// remove trailing slash
|
|
|
|
dir = dir[:len(dir)-1]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sort.Strings(readOnlyPaths)
|
|
|
|
sort.Strings(executablePaths)
|
|
|
|
sort.Strings(appSetDirs)
|
|
|
|
|
|
|
|
cannedFsConfig := android.PathForModuleOut(ctx, "canned_fs_config")
|
|
|
|
builder := android.NewRuleBuilder(pctx, ctx)
|
|
|
|
cmd := builder.Command()
|
|
|
|
cmd.Text("(")
|
|
|
|
cmd.Text("echo '/ 1000 1000 0755';")
|
|
|
|
for _, p := range readOnlyPaths {
|
|
|
|
cmd.Textf("echo '/%s 1000 1000 0644';", p)
|
|
|
|
}
|
|
|
|
for _, p := range executablePaths {
|
|
|
|
cmd.Textf("echo '/%s 0 2000 0755';", p)
|
|
|
|
}
|
|
|
|
for _, dir := range appSetDirs {
|
|
|
|
cmd.Textf("echo '/%s 0 2000 0755';", dir)
|
|
|
|
file := appSetFiles[dir]
|
|
|
|
cmd.Text("zipinfo -1").Input(file).Textf(`| sed "s:\(.*\):/%s/\1 1000 1000 0644:";`, dir)
|
|
|
|
}
|
2021-12-13 15:56:35 +01:00
|
|
|
// Custom fs_config is "appended" to the last so that entries from the file are preferred
|
|
|
|
// over default ones set above.
|
|
|
|
if a.properties.Canned_fs_config != nil {
|
|
|
|
cmd.Text("cat").Input(android.PathForModuleSrc(ctx, *a.properties.Canned_fs_config))
|
|
|
|
}
|
2021-12-13 15:40:17 +01:00
|
|
|
cmd.Text(")").FlagWithOutput("> ", cannedFsConfig)
|
|
|
|
builder.Build("generateFsConfig", fmt.Sprintf("Generating canned fs config for %s", a.BaseModuleName()))
|
|
|
|
|
|
|
|
return cannedFsConfig.OutputPath
|
|
|
|
}
|