diff options
author | 2023-07-12 16:51:48 +0100 | |
---|---|---|
committer | 2023-07-14 12:13:30 +0100 | |
commit | 4d90da29a887f8919a0ad931d2045814e9e5ac65 (patch) | |
tree | 0710e38e7ecadb233c8a3e0940c0667969224c32 /android/configured_jars.go | |
parent | cb13b5d1bde9a45316271c61fd23a22c35ebf609 (diff) |
Add a Make variable that overrides configured jar locations.
We had hardcoded logic to override "framework-minus-apex", but we need
to override more jars, so this CL adds a general solution for this.
Bug: 290583827
Test: m nothing
Change-Id: I211ebda7aa2803886ab6e6d081d26327665e49a6
Diffstat (limited to 'android/configured_jars.go')
-rw-r--r-- | android/configured_jars.go | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/android/configured_jars.go b/android/configured_jars.go index 1281bae87..c7b808f3d 100644 --- a/android/configured_jars.go +++ b/android/configured_jars.go @@ -178,7 +178,7 @@ func (l *ConfiguredJarList) CopyOfApexJarPairs() []string { func (l *ConfiguredJarList) BuildPaths(ctx PathContext, dir OutputPath) WritablePaths { paths := make(WritablePaths, l.Len()) for i, jar := range l.jars { - paths[i] = dir.Join(ctx, ModuleStem(jar)+".jar") + paths[i] = dir.Join(ctx, ModuleStem(ctx.Config(), l.Apex(i), jar)+".jar") } return paths } @@ -187,8 +187,8 @@ func (l *ConfiguredJarList) BuildPaths(ctx PathContext, dir OutputPath) Writable // prefix. func (l *ConfiguredJarList) BuildPathsByModule(ctx PathContext, dir OutputPath) map[string]WritablePath { paths := map[string]WritablePath{} - for _, jar := range l.jars { - paths[jar] = dir.Join(ctx, ModuleStem(jar)+".jar") + for i, jar := range l.jars { + paths[jar] = dir.Join(ctx, ModuleStem(ctx.Config(), l.Apex(i), jar)+".jar") } return paths } @@ -228,24 +228,32 @@ func (l *ConfiguredJarList) MarshalJSON() ([]byte, error) { return json.Marshal(list) } -// ModuleStem hardcodes the stem of framework-minus-apex to return "framework". -// -// TODO(b/139391334): hard coded until we find a good way to query the stem of a -// module before any other mutators are run. -func ModuleStem(module string) string { - if module == "framework-minus-apex" { - return "framework" +func OverrideConfiguredJarLocationFor(cfg Config, apex string, jar string) (newApex string, newJar string) { + for _, entry := range cfg.productVariables.ConfiguredJarLocationOverrides { + tuple := strings.Split(entry, ":") + if len(tuple) != 4 { + panic("malformed configured jar location override '%s', expected format: <old_apex>:<old_jar>:<new_apex>:<new_jar>") + } + if apex == tuple[0] && jar == tuple[1] { + return tuple[2], tuple[3] + } } - return module + return apex, jar +} + +// ModuleStem returns the overridden jar name. +func ModuleStem(cfg Config, apex string, jar string) string { + _, newJar := OverrideConfiguredJarLocationFor(cfg, apex, jar) + return newJar } // DevicePaths computes the on-device paths for the list of (apex, jar) pairs, // based on the operating system. func (l *ConfiguredJarList) DevicePaths(cfg Config, ostype OsType) []string { paths := make([]string, l.Len()) - for i, jar := range l.jars { - apex := l.apexes[i] - name := ModuleStem(jar) + ".jar" + for i := 0; i < l.Len(); i++ { + apex, jar := OverrideConfiguredJarLocationFor(cfg, l.Apex(i), l.Jar(i)) + name := jar + ".jar" var subdir string if apex == "platform" { |