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-03-12 10:37:20 +01: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")
|
|
|
|
pctx.Import("android/soong/java")
|
|
|
|
pctx.HostBinToolVariable("apexer", "apexer")
|
|
|
|
// ART minimal builds (using the master-art manifest) do not have the "frameworks/base"
|
|
|
|
// projects, and hence cannot built 'aapt2'. Use the SDK prebuilt instead.
|
|
|
|
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")
|
2019-11-18 03:16:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
// Create a canned fs config file where all files and directories are
|
|
|
|
// by default set to (uid/gid/mode) = (1000/1000/0644)
|
|
|
|
// TODO(b/113082813) make this configurable using config.fs syntax
|
|
|
|
generateFsConfig = pctx.StaticRule("generateFsConfig", blueprint.RuleParams{
|
2020-05-28 01:36:07 +02:00
|
|
|
Command: `( echo '/ 1000 1000 0755' ` +
|
|
|
|
`&& for i in ${ro_paths}; do echo "/$$i 1000 1000 0644"; done ` +
|
|
|
|
`&& for i in ${exec_paths}; do echo "/$$i 0 2000 0755"; done ` +
|
|
|
|
`&& ( tr ' ' '\n' <${out}.apklist | for i in ${apk_paths}; do read apk; echo "/$$i 0 2000 0755"; zipinfo -1 $$apk | sed "s:\(.*\):/$$i/\1 1000 1000 0644:"; done ) ) > ${out}`,
|
|
|
|
Description: "fs_config ${out}",
|
|
|
|
Rspfile: "$out.apklist",
|
|
|
|
RspfileContent: "$in",
|
|
|
|
}, "ro_paths", "exec_paths", "apk_paths")
|
2019-11-18 03:16:27 +01:00
|
|
|
|
|
|
|
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}",
|
|
|
|
})
|
|
|
|
|
|
|
|
// TODO(b/113233103): make sure that file_contexts is sane, i.e., validate
|
|
|
|
// 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 ` +
|
|
|
|
`--key ${key} ${opt_flags} ${image_dir} ${out} `,
|
|
|
|
CommandDeps: []string{"${apexer}", "${avbtool}", "${e2fsdroid}", "${merge_zips}",
|
|
|
|
"${mke2fs}", "${resize2fs}", "${sefcontext_compile}",
|
|
|
|
"${soong_zip}", "${zipalign}", "${aapt2}", "prebuilts/sdk/current/public/android.jar"},
|
|
|
|
Rspfile: "${out}.copy_commands",
|
|
|
|
RspfileContent: "${copy_commands}",
|
|
|
|
Description: "APEX ${image_dir} => ${out}",
|
2019-11-12 05:03:50 +01:00
|
|
|
}, "tool_path", "image_dir", "copy_commands", "file_contexts", "canned_fs_config", "key", "opt_flags", "manifest")
|
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}",
|
2019-11-12 05:03:50 +01: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")
|
2019-11-18 03:16:27 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func (a *apexBundle) buildManifest(ctx android.ModuleContext, provideNativeLibs, requireNativeLibs []string) {
|
|
|
|
manifestSrc := android.PathForModuleSrc(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json"))
|
|
|
|
|
2019-11-12 05:03:50 +01:00
|
|
|
manifestJsonFullOut := android.PathForModuleOut(ctx, "apex_manifest_full.json")
|
2019-11-18 03:16:27 +01:00
|
|
|
|
|
|
|
// put dependency({provide|require}NativeLibs) in apex_manifest.json
|
|
|
|
provideNativeLibs = android.SortedUniqueStrings(provideNativeLibs)
|
|
|
|
requireNativeLibs = android.SortedUniqueStrings(android.RemoveListFromList(requireNativeLibs, provideNativeLibs))
|
|
|
|
|
|
|
|
// apex name can be overridden
|
|
|
|
optCommands := []string{}
|
|
|
|
if a.properties.Apex_name != nil {
|
|
|
|
optCommands = append(optCommands, "-v name "+*a.properties.Apex_name)
|
|
|
|
}
|
|
|
|
|
2020-02-27 05:50:06 +01:00
|
|
|
// collect jniLibs. Notice that a.filesInfo is already sorted
|
|
|
|
var jniLibs []string
|
|
|
|
for _, fi := range a.filesInfo {
|
|
|
|
if fi.isJniLib {
|
2020-05-29 14:29:20 +02:00
|
|
|
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, " "))
|
|
|
|
}
|
|
|
|
|
2019-11-18 03:16:27 +01:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: apexManifestRule,
|
|
|
|
Input: manifestSrc,
|
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-03-12 10:37:20 +01:00
|
|
|
if a.minSdkVersion(ctx) == android.SdkVersion_Android10 {
|
2019-11-12 05:03:50 +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
|
|
|
|
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
|
|
|
|
|
|
|
// from R+, protobuf binary format (.pb) is the standard format for apex_manifest
|
|
|
|
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-01-28 12:05:29 +01:00
|
|
|
func (a *apexBundle) buildNoticeFiles(ctx android.ModuleContext, apexFileName string) android.NoticeOutputs {
|
2020-03-17 11:16:40 +01:00
|
|
|
var noticeFiles android.Paths
|
|
|
|
|
2020-03-30 16:54:08 +02:00
|
|
|
a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
|
2020-03-17 11:16:40 +01:00
|
|
|
if externalDep {
|
2020-03-30 16:54:08 +02:00
|
|
|
// As soon as the dependency graph crosses the APEX boundary, don't go further.
|
|
|
|
return false
|
2019-11-18 03:16:27 +01:00
|
|
|
}
|
2020-03-30 16:54:08 +02:00
|
|
|
|
2020-03-17 11:16:40 +01:00
|
|
|
notices := to.NoticeFiles()
|
|
|
|
noticeFiles = append(noticeFiles, notices...)
|
2020-03-30 16:54:08 +02:00
|
|
|
|
|
|
|
return true
|
2020-03-17 11:16:40 +01:00
|
|
|
})
|
2019-11-18 03:16:27 +01:00
|
|
|
|
|
|
|
if len(noticeFiles) == 0 {
|
2020-01-28 12:05:29 +01:00
|
|
|
return android.NoticeOutputs{}
|
2019-11-18 03:16:27 +01:00
|
|
|
}
|
|
|
|
|
2020-05-29 15:00:16 +02:00
|
|
|
return android.BuildNoticeOutput(ctx, a.installDir, apexFileName, android.SortedUniquePaths(noticeFiles))
|
2019-11-18 03:16:27 +01:00
|
|
|
}
|
|
|
|
|
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")
|
|
|
|
rule := android.NewRuleBuilder()
|
|
|
|
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)
|
|
|
|
rule.Build(pctx, ctx, "installed-files."+a.Name(), "Installed files")
|
|
|
|
return output.OutputPath
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
// collect the manifest names and paths of android apps
|
|
|
|
// if their manifest names are overridden
|
|
|
|
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,
|
|
|
|
Apk_path: fi.Path(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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))
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: android.WriteFile,
|
|
|
|
Output: output,
|
|
|
|
Description: "Bundle Config " + output.String(),
|
|
|
|
Args: map[string]string{
|
|
|
|
"content": string(j),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
return output.OutputPath
|
|
|
|
}
|
|
|
|
|
2019-11-18 03:16:27 +01:00
|
|
|
func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) {
|
|
|
|
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)
|
|
|
|
|
|
|
|
apexType := a.properties.ApexType
|
|
|
|
suffix := apexType.suffix()
|
2020-01-14 01:22:18 +01:00
|
|
|
var implicitInputs []android.Path
|
2019-11-22 23:50:42 +01:00
|
|
|
unsignedOutputFile := android.PathForModuleOut(ctx, a.Name()+suffix+".unsigned")
|
2019-11-18 03:16:27 +01:00
|
|
|
|
2020-01-14 01:22:18 +01:00
|
|
|
// TODO(jiyong): construct the copy rules using RuleBuilder
|
|
|
|
var copyCommands []string
|
|
|
|
for _, fi := range a.filesInfo {
|
|
|
|
destPath := android.PathForModuleOut(ctx, "image"+suffix, fi.Path()).String()
|
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-01-14 01:22:18 +01:00
|
|
|
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())
|
|
|
|
copyCommands = append(copyCommands, "ln -sfn "+pathOnDevice+" "+destPath)
|
|
|
|
} else {
|
2020-05-28 01:36:07 +02:00
|
|
|
if fi.class == appSet {
|
|
|
|
copyCommands = append(copyCommands,
|
|
|
|
fmt.Sprintf("unzip -q -d %s %s", destPathDir, fi.builtFile.String()))
|
|
|
|
} else {
|
|
|
|
copyCommands = append(copyCommands, "cp -f "+fi.builtFile.String()+" "+destPath)
|
|
|
|
}
|
2020-01-14 01:22:18 +01:00
|
|
|
implicitInputs = append(implicitInputs, fi.builtFile)
|
|
|
|
}
|
|
|
|
// create additional symlinks pointing the file inside the APEX
|
|
|
|
for _, symlinkPath := range fi.SymlinkPaths() {
|
|
|
|
symlinkDest := android.PathForModuleOut(ctx, "image"+suffix, symlinkPath).String()
|
2020-03-18 19:00:41 +01:00
|
|
|
copyCommands = append(copyCommands, "ln -sfn "+filepath.Base(destPath)+" "+symlinkDest)
|
2020-01-14 01:22:18 +01:00
|
|
|
}
|
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
|
|
|
|
relPath := d.Rel()
|
|
|
|
dataPath := d.String()
|
|
|
|
if !strings.HasSuffix(dataPath, relPath) {
|
|
|
|
panic(fmt.Errorf("path %q does not end with %q", dataPath, relPath))
|
|
|
|
}
|
|
|
|
|
|
|
|
dataDest := android.PathForModuleOut(ctx, "image"+suffix, fi.apexRelativePath(relPath)).String()
|
|
|
|
|
|
|
|
copyCommands = append(copyCommands, "cp -f "+d.String()+" "+dataDest)
|
|
|
|
implicitInputs = append(implicitInputs, d)
|
|
|
|
}
|
2019-11-18 03:16:27 +01:00
|
|
|
}
|
|
|
|
|
2020-01-14 01:22:18 +01:00
|
|
|
// TODO(jiyong): use RuleBuilder
|
|
|
|
var emitCommands []string
|
|
|
|
imageContentFile := android.PathForModuleOut(ctx, "content.txt")
|
2019-11-12 05:03:50 +01:00
|
|
|
emitCommands = append(emitCommands, "echo ./apex_manifest.pb >> "+imageContentFile.String())
|
2020-03-12 10:37:20 +01:00
|
|
|
if a.minSdkVersion(ctx) == android.SdkVersion_Android10 {
|
2019-11-12 05:03:50 +01:00
|
|
|
emitCommands = append(emitCommands, "echo ./apex_manifest.json >> "+imageContentFile.String())
|
|
|
|
}
|
2020-01-14 01:22:18 +01:00
|
|
|
for _, fi := range a.filesInfo {
|
|
|
|
emitCommands = append(emitCommands, "echo './"+fi.Path()+"' >> "+imageContentFile.String())
|
2019-11-18 03:16:27 +01:00
|
|
|
}
|
|
|
|
emitCommands = append(emitCommands, "sort -o "+imageContentFile.String()+" "+imageContentFile.String())
|
2019-11-12 05:03:50 +01:00
|
|
|
implicitInputs = append(implicitInputs, a.manifestPbOut)
|
2019-11-18 03:16:27 +01:00
|
|
|
|
2020-06-20 05:47:47 +02:00
|
|
|
if a.overridableProperties.Allowed_files != nil {
|
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-06-20 05:47:47 +02:00
|
|
|
allowedFilesFile := android.PathForModuleSrc(ctx, proptools.String(a.overridableProperties.Allowed_files))
|
2019-11-18 03:16:27 +01:00
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
outHostBinDir := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "bin").String()
|
|
|
|
prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin")
|
|
|
|
|
2020-01-14 06:39:19 +01:00
|
|
|
imageDir := android.PathForModuleOut(ctx, "image"+suffix)
|
2019-11-18 03:16:27 +01:00
|
|
|
if apexType == imageApex {
|
|
|
|
// files and dirs that will be created in APEX
|
|
|
|
var readOnlyPaths = []string{"apex_manifest.json", "apex_manifest.pb"}
|
|
|
|
var executablePaths []string // this also includes dirs
|
2020-05-28 01:36:07 +02:00
|
|
|
var extractedAppSetPaths android.Paths
|
|
|
|
var extractedAppSetDirs []string
|
2019-11-18 03:16:27 +01:00
|
|
|
for _, f := range a.filesInfo {
|
2020-05-29 14:29:20 +02:00
|
|
|
pathInApex := f.Path()
|
2019-11-18 03:16:27 +01:00
|
|
|
if f.installDir == "bin" || strings.HasPrefix(f.installDir, "bin/") {
|
|
|
|
executablePaths = append(executablePaths, pathInApex)
|
2020-05-13 00:26:55 +02:00
|
|
|
for _, d := range f.dataPaths {
|
|
|
|
readOnlyPaths = append(readOnlyPaths, filepath.Join(f.installDir, d.Rel()))
|
|
|
|
}
|
2019-11-18 03:16:27 +01:00
|
|
|
for _, s := range f.symlinks {
|
|
|
|
executablePaths = append(executablePaths, filepath.Join(f.installDir, s))
|
|
|
|
}
|
2020-05-28 01:36:07 +02:00
|
|
|
} else if f.class == appSet {
|
|
|
|
extractedAppSetPaths = append(extractedAppSetPaths, f.builtFile)
|
|
|
|
extractedAppSetDirs = append(extractedAppSetDirs, f.installDir)
|
2019-11-18 03:16:27 +01:00
|
|
|
} 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)
|
|
|
|
cannedFsConfig := android.PathForModuleOut(ctx, "canned_fs_config")
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: generateFsConfig,
|
|
|
|
Output: cannedFsConfig,
|
|
|
|
Description: "generate fs config",
|
2020-05-28 01:36:07 +02:00
|
|
|
Inputs: extractedAppSetPaths,
|
2019-11-18 03:16:27 +01:00
|
|
|
Args: map[string]string{
|
|
|
|
"ro_paths": strings.Join(readOnlyPaths, " "),
|
|
|
|
"exec_paths": strings.Join(executablePaths, " "),
|
2020-05-28 01:36:07 +02:00
|
|
|
"apk_paths": strings.Join(extractedAppSetDirs, " "),
|
2019-11-18 03:16:27 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
optFlags := []string{}
|
|
|
|
|
|
|
|
// Additional implicit inputs.
|
2019-11-19 18:26:02 +01:00
|
|
|
implicitInputs = append(implicitInputs, cannedFsConfig, a.fileContexts, a.private_key_file, a.public_key_file)
|
2019-11-18 03:16:27 +01:00
|
|
|
optFlags = append(optFlags, "--pubkey "+a.public_key_file.String())
|
|
|
|
|
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))
|
|
|
|
implicitInputs = append(implicitInputs, androidManifestFile)
|
|
|
|
optFlags = append(optFlags, "--android_manifest "+androidManifestFile.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
targetSdkVersion := ctx.Config().DefaultAppTargetSdk()
|
2020-05-20 01:16:27 +02:00
|
|
|
// TODO(b/157078772): propagate min_sdk_version to apexer.
|
2020-01-25 00:15:44 +01:00
|
|
|
minSdkVersion := ctx.Config().DefaultAppTargetSdk()
|
2020-02-20 01:43:27 +01:00
|
|
|
|
2020-03-12 10:37:20 +01:00
|
|
|
if a.minSdkVersion(ctx) == android.SdkVersion_Android10 {
|
|
|
|
minSdkVersion = strconv.Itoa(a.minSdkVersion(ctx))
|
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))
|
|
|
|
}
|
2020-03-02 17:58:11 +01:00
|
|
|
if java.UseApiFingerprint(ctx) {
|
|
|
|
minSdkVersion = 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)
|
|
|
|
}
|
|
|
|
|
2020-01-28 12:05:29 +01:00
|
|
|
a.mergedNotices = a.buildNoticeFiles(ctx, a.Name()+suffix)
|
|
|
|
if a.mergedNotices.HtmlGzOutput.Valid() {
|
2019-11-18 03:16:27 +01:00
|
|
|
// If there's a NOTICE file, embed it as an asset file in the APEX.
|
2020-01-28 12:05:29 +01:00
|
|
|
implicitInputs = append(implicitInputs, a.mergedNotices.HtmlGzOutput.Path())
|
|
|
|
optFlags = append(optFlags, "--assets_dir "+filepath.Dir(a.mergedNotices.HtmlGzOutput.String()))
|
2019-11-18 03:16:27 +01:00
|
|
|
}
|
|
|
|
|
2020-01-03 00:01:39 +01:00
|
|
|
if ctx.ModuleDir() != "system/apex/apexd/apexd_testdata" && ctx.ModuleDir() != "system/apex/shim/build" && a.testOnlyShouldSkipHashtreeGeneration() {
|
2019-12-07 18:30:22 +01:00
|
|
|
ctx.PropertyErrorf("test_only_no_hashtree", "not available")
|
|
|
|
return
|
|
|
|
}
|
2020-03-12 10:37:20 +01:00
|
|
|
if a.minSdkVersion(ctx) > android.SdkVersion_Android10 || a.testOnlyShouldSkipHashtreeGeneration() {
|
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 {
|
|
|
|
// If apex_name is set, apexer can skip checking if key name matches with apex name.
|
|
|
|
// Note that apex_manifest is also mended.
|
|
|
|
optFlags = append(optFlags, "--do_not_check_keyname")
|
|
|
|
}
|
|
|
|
|
2020-03-12 10:37:20 +01:00
|
|
|
if a.minSdkVersion(ctx) == android.SdkVersion_Android10 {
|
2019-11-12 05:03:50 +01:00
|
|
|
implicitInputs = append(implicitInputs, a.manifestJsonOut)
|
|
|
|
optFlags = append(optFlags, "--manifest_json "+a.manifestJsonOut.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{
|
2019-11-12 05:03:50 +01:00
|
|
|
"tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
|
2020-01-14 06:39:19 +01:00
|
|
|
"image_dir": imageDir.String(),
|
2019-11-12 05:03:50 +01:00
|
|
|
"copy_commands": strings.Join(copyCommands, " && "),
|
|
|
|
"manifest": a.manifestPbOut.String(),
|
|
|
|
"file_contexts": a.fileContexts.String(),
|
|
|
|
"canned_fs_config": cannedFsConfig.String(),
|
|
|
|
"key": a.private_key_file.String(),
|
|
|
|
"opt_flags": strings.Join(optFlags, " "),
|
2019-11-18 03:16:27 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
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-02-28 07:22:21 +01:00
|
|
|
bundleConfig := a.buildBundleConfig(ctx)
|
|
|
|
|
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
|
|
|
},
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: zipApexRule,
|
|
|
|
Implicits: implicitInputs,
|
|
|
|
Output: unsignedOutputFile,
|
|
|
|
Description: "apex (" + apexType.name() + ")",
|
|
|
|
Args: map[string]string{
|
2019-11-12 05:03:50 +01:00
|
|
|
"tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
|
2020-01-14 06:39:19 +01:00
|
|
|
"image_dir": imageDir.String(),
|
2019-11-12 05:03:50 +01:00
|
|
|
"copy_commands": strings.Join(copyCommands, " && "),
|
|
|
|
"manifest": a.manifestPbOut.String(),
|
2019-11-18 03:16:27 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-11-22 23:50:42 +01:00
|
|
|
a.outputFile = android.PathForModuleOut(ctx, a.Name()+suffix)
|
2020-05-28 15:13:33 +02:00
|
|
|
rule := java.Signapk
|
|
|
|
args := map[string]string{
|
|
|
|
"certificates": a.container_certificate_file.String() + " " + a.container_private_key_file.String(),
|
|
|
|
"flags": "-a 4096", //alignment
|
|
|
|
}
|
|
|
|
implicits := android.Paths{
|
|
|
|
a.container_certificate_file,
|
|
|
|
a.container_private_key_file,
|
|
|
|
}
|
|
|
|
if ctx.Config().IsEnvTrue("RBE_SIGNAPK") {
|
|
|
|
rule = java.SignapkRE
|
|
|
|
args["implicits"] = strings.Join(implicits.Strings(), ",")
|
|
|
|
args["outCommaList"] = a.outputFile.String()
|
|
|
|
}
|
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",
|
|
|
|
Output: a.outputFile,
|
|
|
|
Input: unsignedOutputFile,
|
2020-05-28 15:13:33 +02:00
|
|
|
Implicits: implicits,
|
|
|
|
Args: args,
|
2019-11-18 03:16:27 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
// Install to $OUT/soong/{target,host}/.../apex
|
|
|
|
if a.installable() {
|
2019-11-22 23:50:42 +01:00
|
|
|
ctx.InstallFile(a.installDir, a.Name()+suffix, a.outputFile)
|
2019-11-18 03:16:27 +01:00
|
|
|
}
|
|
|
|
a.buildFilesInfo(ctx)
|
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
|
|
|
}
|
|
|
|
|
|
|
|
func (a *apexBundle) buildFlattenedApex(ctx android.ModuleContext) {
|
|
|
|
// Temporarily wrap the original `ctx` into a `flattenedApexContext` to have it
|
|
|
|
// reply true to `InstallBypassMake()` (thus making the call
|
|
|
|
// `android.PathForModuleInstall` below use `android.pathForInstallInMakeDir`
|
|
|
|
// instead of `android.PathForOutput`) to return the correct path to the flattened
|
|
|
|
// APEX (as its contents is installed by Make, not Soong).
|
|
|
|
factx := flattenedApexContext{ctx}
|
2020-02-07 02:15:14 +01:00
|
|
|
apexBundleName := a.Name()
|
|
|
|
a.outputFile = android.PathForModuleInstall(&factx, "apex", apexBundleName)
|
2019-11-18 03:16:27 +01:00
|
|
|
|
2019-12-05 05:20:58 +01:00
|
|
|
if a.installable() && a.GetOverriddenBy() == "" {
|
2020-02-07 02:15:14 +01:00
|
|
|
installPath := android.PathForModuleInstall(ctx, "apex", apexBundleName)
|
2019-11-19 18:26:02 +01:00
|
|
|
devicePath := android.InstallPathToOnDevicePath(ctx, installPath)
|
2020-02-07 02:15:14 +01:00
|
|
|
addFlattenedFileContextsInfos(ctx, apexBundleName+":"+devicePath+":"+a.fileContexts.String())
|
2019-11-19 18:26:02 +01:00
|
|
|
}
|
2019-11-18 03:16:27 +01:00
|
|
|
a.buildFilesInfo(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *apexBundle) setCertificateAndPrivateKey(ctx android.ModuleContext) {
|
2019-12-17 06:30:11 +01:00
|
|
|
if a.container_certificate_file == nil {
|
|
|
|
cert := String(a.properties.Certificate)
|
|
|
|
if cert == "" {
|
|
|
|
pem, key := ctx.Config().DefaultAppCertificate(ctx)
|
|
|
|
a.container_certificate_file = pem
|
|
|
|
a.container_private_key_file = key
|
|
|
|
} else {
|
|
|
|
defaultDir := ctx.Config().DefaultAppCertificateDir(ctx)
|
|
|
|
a.container_certificate_file = defaultDir.Join(ctx, cert+".x509.pem")
|
|
|
|
a.container_private_key_file = defaultDir.Join(ctx, cert+".pk8")
|
|
|
|
}
|
2019-11-18 03:16:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *apexBundle) buildFilesInfo(ctx android.ModuleContext) {
|
|
|
|
if a.installable() {
|
2019-11-12 05:03:50 +01:00
|
|
|
// For flattened APEX, do nothing but make sure that APEX manifest and apex_pubkey are also copied along
|
2019-11-18 03:16:27 +01:00
|
|
|
// with other ordinary files.
|
2020-01-14 01:22:18 +01:00
|
|
|
a.filesInfo = append(a.filesInfo, newApexFile(ctx, a.manifestPbOut, "apex_manifest.pb", ".", etc, nil))
|
2019-11-18 03:16:27 +01:00
|
|
|
|
|
|
|
// rename to apex_pubkey
|
|
|
|
copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: android.Cp,
|
|
|
|
Input: a.public_key_file,
|
|
|
|
Output: copiedPubkey,
|
|
|
|
})
|
2020-01-14 01:22:18 +01:00
|
|
|
a.filesInfo = append(a.filesInfo, newApexFile(ctx, copiedPubkey, "apex_pubkey", ".", etc, nil))
|
2019-11-18 03:16:27 +01:00
|
|
|
|
|
|
|
if a.properties.ApexType == flattenedApex {
|
2020-02-07 02:15:14 +01:00
|
|
|
apexBundleName := a.Name()
|
2019-11-18 03:16:27 +01:00
|
|
|
for _, fi := range a.filesInfo {
|
2020-02-07 02:15:14 +01:00
|
|
|
dir := filepath.Join("apex", apexBundleName, fi.installDir)
|
2020-05-29 14:29:20 +02:00
|
|
|
target := ctx.InstallFile(android.PathForModuleInstall(ctx, dir), fi.Stem(), fi.builtFile)
|
2019-11-18 03:16:27 +01:00
|
|
|
for _, sym := range fi.symlinks {
|
|
|
|
ctx.InstallSymlink(android.PathForModuleInstall(ctx, dir), sym, target)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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{}
|
|
|
|
a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
|
|
|
|
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
|
|
|
|
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)"
|
|
|
|
if m, ok := to.(interface{ MinSdkVersion() string }); ok {
|
|
|
|
if v := m.MinSdkVersion(); v != "" {
|
|
|
|
toMinSdkVersion = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
})
|
|
|
|
|
2020-04-27 19:53:18 +02:00
|
|
|
a.ApexBundleDepsInfo.BuildDepsInfoLists(ctx, proptools.String(a.properties.Min_sdk_version), 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
|
|
|
})
|
|
|
|
}
|