Switch BootJars/UpdatableBootJars to ConfiguredJarList

This change:
* Switches BootJars/UpdatableBootJars fields of config.productVariables
  from []string to ConfiguredJarList.
* Updates BootJars() method to simply concatenate the jars list from
  the BootJars/UpdatableBootJars fields.
* Adds an UnmarshalJSON(..) method to ConfiguredJarList to support
  unmarshalling from a single string array to avoid having to change the
  format of the JSON file from which the configuration is loaded.
* Adds some additional calls to ConfiguredJarList(..) in tests to
  convert from []string to ConfiguredJarList. They pass nil as the
  ctx argument as there is no suitable PathContext which will cause any
  errors to be thrown using panic. That is reasonable for hard coded
  values in tests. A follow up change will clean up the calls to
  ConfiguredJarList(..).

Bug: 171479578
Test: m nothing
Change-Id: I59b94dafb479ccd8f0471ed802be175af57be271
This commit is contained in:
Paul Duffin
2020-10-23 21:14:20 +01:00
parent 0141660c63
commit 69d1fb1e39
4 changed files with 27 additions and 8 deletions

View File

@@ -1415,6 +1415,26 @@ func (l *ConfiguredJarList) BuildPaths(ctx PathContext, dir OutputPath) Writable
return paths
}
// Called when loading configuration from JSON into a configuration structure.
func (l *ConfiguredJarList) UnmarshalJSON(b []byte) error {
// Try and unmarshal into a []string each item of which contains a pair
// <apex>:<jar>.
var list []string
err := json.Unmarshal(b, &list)
if err != nil {
// Did not work so return
return err
}
apexes, jars, err := splitListOfPairsIntoPairOfLists(list)
if err != nil {
return err
}
l.apexes = apexes
l.jars = jars
return nil
}
func ModuleStem(module string) string {
// b/139391334: the stem of framework-minus-apex is framework. This is hard coded here until we
// find a good way to query the stem of a module before any other mutators are run.
@@ -1494,9 +1514,8 @@ var earlyBootJarsKey = NewOnceKey("earlyBootJars")
func (c *config) BootJars() []string {
return c.Once(earlyBootJarsKey, func() interface{} {
ctx := NullPathContext{Config{c}}
list := CreateConfiguredJarList(ctx,
append(CopyOf(c.productVariables.BootJars), c.productVariables.UpdatableBootJars...))
return list.CopyOfJars()
list := c.productVariables.BootJars.CopyOfJars()
list = append(list, c.productVariables.UpdatableBootJars.CopyOfJars()...)
return list
}).([]string)
}

View File

@@ -249,8 +249,8 @@ type productVariables struct {
UncompressPrivAppDex *bool `json:",omitempty"`
ModulesLoadedByPrivilegedModules []string `json:",omitempty"`
BootJars []string `json:",omitempty"`
UpdatableBootJars []string `json:",omitempty"`
BootJars ConfiguredJarList `json:",omitempty"`
UpdatableBootJars ConfiguredJarList `json:",omitempty"`
IntegerOverflowExcludePaths []string `json:",omitempty"`

View File

@@ -5905,7 +5905,7 @@ func testApexPermittedPackagesRules(t *testing.T, errmsg, bp string, apexBootJar
for _, apexBootJar := range apexBootJars {
updatableBootJars = append(updatableBootJars, "myapex:"+apexBootJar)
}
config.TestProductVariables.UpdatableBootJars = updatableBootJars
config.TestProductVariables.UpdatableBootJars = android.CreateConfiguredJarList(nil, updatableBootJars)
ctx.Register(config)

View File

@@ -25,7 +25,7 @@ import (
func testConfigWithBootJars(bp string, bootJars []string) android.Config {
config := testConfig(nil, bp, nil)
config.TestProductVariables.BootJars = bootJars
config.TestProductVariables.BootJars = android.CreateConfiguredJarList(nil, bootJars)
return config
}