From a8bd113a695dfb77695cdff7f72719a08869fc23 Mon Sep 17 00:00:00 2001 From: Artur Satayev Date: Mon, 27 Apr 2020 18:07:06 +0100 Subject: [PATCH 1/2] Introduce flat deps info list. Compared to full list, flat list drops dependency edges and simply lists all transitive dependencies for a top-level apex bundle. Bug: 149622332 Test: m, manually build flatlist Change-Id: Ibd521c96b7aeab90b95965c1b524e0a0152aaf5a --- android/apex.go | 29 ++++++++++++++++++++++++++--- apex/apex_test.go | 31 +++++++++++++++++++++---------- apex/builder.go | 5 ++++- 3 files changed, 51 insertions(+), 14 deletions(-) diff --git a/android/apex.go b/android/apex.go index 5910ba064..1c2feb9c4 100644 --- a/android/apex.go +++ b/android/apex.go @@ -419,28 +419,41 @@ type ApexModuleDepInfo struct { type DepNameToDepInfoMap map[string]ApexModuleDepInfo type ApexBundleDepsInfo struct { + flatListPath OutputPath fullListPath OutputPath } type ApexDepsInfoIntf interface { + FlatListPath() Path FullListPath() Path } +func (d *ApexBundleDepsInfo) FlatListPath() Path { + return d.flatListPath +} + func (d *ApexBundleDepsInfo) FullListPath() Path { return d.fullListPath } var _ ApexDepsInfoIntf = (*ApexBundleDepsInfo)(nil) +// Generate two module out files: +// 1. FullList with transitive deps and their parents in the dep graph +// 2. FlatList with a flat list of transitive deps func (d *ApexBundleDepsInfo) BuildDepsInfoLists(ctx ModuleContext, depInfos DepNameToDepInfoMap) { - var content strings.Builder + var fullContent strings.Builder + var flatContent strings.Builder + + fmt.Fprintf(&flatContent, "%s:\\n", ctx.ModuleName()) for _, key := range FirstUniqueStrings(SortedStringKeys(depInfos)) { info := depInfos[key] toName := info.To if info.IsExternal { toName = toName + " (external)" } - fmt.Fprintf(&content, "%s <- %s\\n", toName, strings.Join(SortedUniqueStrings(info.From), ", ")) + fmt.Fprintf(&fullContent, "%s <- %s\\n", toName, strings.Join(SortedUniqueStrings(info.From), ", ")) + fmt.Fprintf(&flatContent, " %s\\n", toName) } d.fullListPath = PathForModuleOut(ctx, "depsinfo", "fulllist.txt").OutputPath @@ -449,7 +462,17 @@ func (d *ApexBundleDepsInfo) BuildDepsInfoLists(ctx ModuleContext, depInfos DepN Description: "Full Dependency Info", Output: d.fullListPath, Args: map[string]string{ - "content": content.String(), + "content": fullContent.String(), + }, + }) + + d.flatListPath = PathForModuleOut(ctx, "depsinfo", "flatlist.txt").OutputPath + ctx.Build(pctx, BuildParams{ + Rule: WriteFile, + Description: "Flat Dependency Info", + Output: d.flatListPath, + Args: map[string]string{ + "content": flatContent.String(), }, }) } diff --git a/apex/apex_test.go b/apex/apex_test.go index d52054479..de04dce2f 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -504,12 +504,19 @@ func TestBasicApex(t *testing.T) { ensureListContains(t, noticeInputs, "custom_notice") ensureListContains(t, noticeInputs, "custom_notice_for_static_lib") - depsInfo := strings.Split(ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("depsinfo/fulllist.txt").Args["content"], "\\n") - ensureListContains(t, depsInfo, "myjar <- myapex") - ensureListContains(t, depsInfo, "mylib <- myapex") - ensureListContains(t, depsInfo, "mylib2 <- mylib") - ensureListContains(t, depsInfo, "myotherjar <- myjar") - ensureListContains(t, depsInfo, "mysharedjar (external) <- myjar") + fullDepsInfo := strings.Split(ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("depsinfo/fulllist.txt").Args["content"], "\\n") + ensureListContains(t, fullDepsInfo, "myjar <- myapex") + ensureListContains(t, fullDepsInfo, "mylib <- myapex") + ensureListContains(t, fullDepsInfo, "mylib2 <- mylib") + ensureListContains(t, fullDepsInfo, "myotherjar <- myjar") + ensureListContains(t, fullDepsInfo, "mysharedjar (external) <- myjar") + + flatDepsInfo := strings.Split(ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("depsinfo/flatlist.txt").Args["content"], "\\n") + ensureListContains(t, flatDepsInfo, " myjar") + ensureListContains(t, flatDepsInfo, " mylib") + ensureListContains(t, flatDepsInfo, " mylib2") + ensureListContains(t, flatDepsInfo, " myotherjar") + ensureListContains(t, flatDepsInfo, " mysharedjar (external)") } func TestDefaults(t *testing.T) { @@ -818,11 +825,15 @@ func TestApexWithExplicitStubsDependency(t *testing.T) { // Ensure that libfoo stubs is not linking to libbar (since it is a stubs) ensureNotContains(t, libFooStubsLdFlags, "libbar.so") - depsInfo := strings.Split(ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Output("depsinfo/fulllist.txt").Args["content"], "\\n") + fullDepsInfo := strings.Split(ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Output("depsinfo/fulllist.txt").Args["content"], "\\n") + ensureListContains(t, fullDepsInfo, "mylib <- myapex2") + ensureListContains(t, fullDepsInfo, "libbaz <- mylib") + ensureListContains(t, fullDepsInfo, "libfoo (external) <- mylib") - ensureListContains(t, depsInfo, "mylib <- myapex2") - ensureListContains(t, depsInfo, "libbaz <- mylib") - ensureListContains(t, depsInfo, "libfoo (external) <- mylib") + flatDepsInfo := strings.Split(ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Output("depsinfo/flatlist.txt").Args["content"], "\\n") + ensureListContains(t, flatDepsInfo, " mylib") + ensureListContains(t, flatDepsInfo, " libbaz") + ensureListContains(t, flatDepsInfo, " libfoo (external)") } func TestApexWithRuntimeLibsDependency(t *testing.T) { diff --git a/apex/builder.go b/apex/builder.go index c6650c36d..2e1cbfc1f 100644 --- a/apex/builder.go +++ b/apex/builder.go @@ -719,6 +719,9 @@ func (a *apexBundle) buildApexDependencyInfo(ctx android.ModuleContext) { ctx.Build(pctx, android.BuildParams{ Rule: android.Phony, Output: android.PathForPhony(ctx, a.Name()+"-deps-info"), - Inputs: []android.Path{a.ApexBundleDepsInfo.FullListPath()}, + Inputs: []android.Path{ + a.ApexBundleDepsInfo.FullListPath(), + a.ApexBundleDepsInfo.FlatListPath(), + }, }) } From 480e25b74f9e7101ff3083bd4517f15ac0a6a1b9 Mon Sep 17 00:00:00 2001 From: Artur Satayev Date: Mon, 27 Apr 2020 18:53:18 +0100 Subject: [PATCH 2/2] Introduce min_sdk_version to deps info. Bug: 149622332 Test: m Change-Id: Ie6568cb8a82d5cca9a3dc91b5a068abf4b0632dc --- android/apex.go | 20 +++++++++++++++----- apex/apex_test.go | 32 ++++++++++++++++---------------- apex/builder.go | 16 ++++++++++++---- cc/cc.go | 4 ++++ java/java.go | 8 ++++++++ 5 files changed, 55 insertions(+), 25 deletions(-) diff --git a/android/apex.go b/android/apex.go index 1c2feb9c4..9056c3de7 100644 --- a/android/apex.go +++ b/android/apex.go @@ -413,21 +413,29 @@ type ApexModuleDepInfo struct { From []string // Whether the dependency belongs to the final compiled APEX. IsExternal bool + // min_sdk_version of the ApexModule + MinSdkVersion string } // A map of a dependency name to its ApexModuleDepInfo type DepNameToDepInfoMap map[string]ApexModuleDepInfo type ApexBundleDepsInfo struct { - flatListPath OutputPath - fullListPath OutputPath + minSdkVersion string + flatListPath OutputPath + fullListPath OutputPath } type ApexDepsInfoIntf interface { + MinSdkVersion() string FlatListPath() Path FullListPath() Path } +func (d *ApexBundleDepsInfo) MinSdkVersion() string { + return d.minSdkVersion +} + func (d *ApexBundleDepsInfo) FlatListPath() Path { return d.flatListPath } @@ -441,14 +449,16 @@ var _ ApexDepsInfoIntf = (*ApexBundleDepsInfo)(nil) // Generate two module out files: // 1. FullList with transitive deps and their parents in the dep graph // 2. FlatList with a flat list of transitive deps -func (d *ApexBundleDepsInfo) BuildDepsInfoLists(ctx ModuleContext, depInfos DepNameToDepInfoMap) { +func (d *ApexBundleDepsInfo) BuildDepsInfoLists(ctx ModuleContext, minSdkVersion string, depInfos DepNameToDepInfoMap) { + d.minSdkVersion = minSdkVersion + var fullContent strings.Builder var flatContent strings.Builder - fmt.Fprintf(&flatContent, "%s:\\n", ctx.ModuleName()) + fmt.Fprintf(&flatContent, "%s(minSdkVersion:%s):\\n", ctx.ModuleName(), minSdkVersion) for _, key := range FirstUniqueStrings(SortedStringKeys(depInfos)) { info := depInfos[key] - toName := info.To + toName := fmt.Sprintf("%s(minSdkVersion:%s)", info.To, info.MinSdkVersion) if info.IsExternal { toName = toName + " (external)" } diff --git a/apex/apex_test.go b/apex/apex_test.go index de04dce2f..ce39b39e4 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -505,18 +505,18 @@ func TestBasicApex(t *testing.T) { ensureListContains(t, noticeInputs, "custom_notice_for_static_lib") fullDepsInfo := strings.Split(ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("depsinfo/fulllist.txt").Args["content"], "\\n") - ensureListContains(t, fullDepsInfo, "myjar <- myapex") - ensureListContains(t, fullDepsInfo, "mylib <- myapex") - ensureListContains(t, fullDepsInfo, "mylib2 <- mylib") - ensureListContains(t, fullDepsInfo, "myotherjar <- myjar") - ensureListContains(t, fullDepsInfo, "mysharedjar (external) <- myjar") + ensureListContains(t, fullDepsInfo, "myjar(minSdkVersion:(no version)) <- myapex") + ensureListContains(t, fullDepsInfo, "mylib(minSdkVersion:(no version)) <- myapex") + ensureListContains(t, fullDepsInfo, "mylib2(minSdkVersion:(no version)) <- mylib") + ensureListContains(t, fullDepsInfo, "myotherjar(minSdkVersion:(no version)) <- myjar") + ensureListContains(t, fullDepsInfo, "mysharedjar(minSdkVersion:(no version)) (external) <- myjar") flatDepsInfo := strings.Split(ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("depsinfo/flatlist.txt").Args["content"], "\\n") - ensureListContains(t, flatDepsInfo, " myjar") - ensureListContains(t, flatDepsInfo, " mylib") - ensureListContains(t, flatDepsInfo, " mylib2") - ensureListContains(t, flatDepsInfo, " myotherjar") - ensureListContains(t, flatDepsInfo, " mysharedjar (external)") + ensureListContains(t, flatDepsInfo, " myjar(minSdkVersion:(no version))") + ensureListContains(t, flatDepsInfo, " mylib(minSdkVersion:(no version))") + ensureListContains(t, flatDepsInfo, " mylib2(minSdkVersion:(no version))") + ensureListContains(t, flatDepsInfo, " myotherjar(minSdkVersion:(no version))") + ensureListContains(t, flatDepsInfo, " mysharedjar(minSdkVersion:(no version)) (external)") } func TestDefaults(t *testing.T) { @@ -826,14 +826,14 @@ func TestApexWithExplicitStubsDependency(t *testing.T) { ensureNotContains(t, libFooStubsLdFlags, "libbar.so") fullDepsInfo := strings.Split(ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Output("depsinfo/fulllist.txt").Args["content"], "\\n") - ensureListContains(t, fullDepsInfo, "mylib <- myapex2") - ensureListContains(t, fullDepsInfo, "libbaz <- mylib") - ensureListContains(t, fullDepsInfo, "libfoo (external) <- mylib") + ensureListContains(t, fullDepsInfo, "mylib(minSdkVersion:(no version)) <- myapex2") + ensureListContains(t, fullDepsInfo, "libbaz(minSdkVersion:(no version)) <- mylib") + ensureListContains(t, fullDepsInfo, "libfoo(minSdkVersion:(no version)) (external) <- mylib") flatDepsInfo := strings.Split(ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Output("depsinfo/flatlist.txt").Args["content"], "\\n") - ensureListContains(t, flatDepsInfo, " mylib") - ensureListContains(t, flatDepsInfo, " libbaz") - ensureListContains(t, flatDepsInfo, " libfoo (external)") + ensureListContains(t, flatDepsInfo, " mylib(minSdkVersion:(no version))") + ensureListContains(t, flatDepsInfo, " libbaz(minSdkVersion:(no version))") + ensureListContains(t, flatDepsInfo, " libfoo(minSdkVersion:(no version)) (external)") } func TestApexWithRuntimeLibsDependency(t *testing.T) { diff --git a/apex/builder.go b/apex/builder.go index 2e1cbfc1f..ca24f2cff 100644 --- a/apex/builder.go +++ b/apex/builder.go @@ -703,10 +703,18 @@ func (a *apexBundle) buildApexDependencyInfo(ctx android.ModuleContext) { info.IsExternal = info.IsExternal && externalDep depInfos[to.Name()] = info } else { + toMinSdkVersion := "(no version)" + if m, ok := to.(interface{ MinSdkVersion() string }); ok { + if v := m.MinSdkVersion(); v != "" { + toMinSdkVersion = v + } + } + depInfos[to.Name()] = android.ApexModuleDepInfo{ - To: to.Name(), - From: []string{from.Name()}, - IsExternal: externalDep, + To: to.Name(), + From: []string{from.Name()}, + IsExternal: externalDep, + MinSdkVersion: toMinSdkVersion, } } @@ -714,7 +722,7 @@ func (a *apexBundle) buildApexDependencyInfo(ctx android.ModuleContext) { return !externalDep }) - a.ApexBundleDepsInfo.BuildDepsInfoLists(ctx, depInfos) + a.ApexBundleDepsInfo.BuildDepsInfoLists(ctx, proptools.String(a.properties.Min_sdk_version), depInfos) ctx.Build(pctx, android.BuildParams{ Rule: android.Phony, diff --git a/cc/cc.go b/cc/cc.go index 082816ef2..49605ccb3 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -581,6 +581,10 @@ func (c *Module) SdkVersion() string { return String(c.Properties.Sdk_version) } +func (c *Module) MinSdkVersion() string { + return String(c.Properties.Min_sdk_version) +} + func (c *Module) AlwaysSdk() bool { return c.Properties.AlwaysSdk || Bool(c.Properties.Sdk_variant_only) } diff --git a/java/java.go b/java/java.go index f339a1a7b..472d3dac4 100644 --- a/java/java.go +++ b/java/java.go @@ -600,6 +600,10 @@ func (j *Module) targetSdkVersion() sdkSpec { return j.sdkVersion() } +func (j *Module) MinSdkVersion() string { + return j.minSdkVersion().version.String() +} + func (j *Module) AvailableFor(what string) bool { if what == android.AvailableToPlatform && Bool(j.deviceProperties.Hostdex) { // Exception: for hostdex: true libraries, the platform variant is created @@ -2398,6 +2402,10 @@ func (j *Import) minSdkVersion() sdkSpec { return j.sdkVersion() } +func (j *Import) MinSdkVersion() string { + return j.minSdkVersion().version.String() +} + func (j *Import) Prebuilt() *android.Prebuilt { return &j.prebuilt }