diff options
author | Colin Cross | 2019-05-09 23:50:00 -0500 |
---|---|---|
committer | Colin Cross | 2019-05-10 09:07:21 -0500 |
commit | 2d00f0dcae6c843d4c98cebfe81a901adb0897c5 (patch) | |
tree | ae341de4dee5565f007338396355d3d5dced5b91 | |
parent | a1591ab08cdd8908e1d3d08c2f4f7be9b5b94957 (diff) | |
download | platform-build-soong-2d00f0dcae6c843d4c98cebfe81a901adb0897c5.tar.gz platform-build-soong-2d00f0dcae6c843d4c98cebfe81a901adb0897c5.tar.xz platform-build-soong-2d00f0dcae6c843d4c98cebfe81a901adb0897c5.zip |
Write dexpreopt.config again during the build
Writing $OUT/dexpreopt.config during build setup and then using
it during the build causes bad incremental builds if a cleanspec
removes $OUT/dexpreopt.config. Create a rule in Soong to write
out a copy so that it is a normal build artifact.
Bug: 132379813
Test: m checkbuild
Change-Id: I7755a7f8c1d6561fc83022a7f4cf7e4a64e989c9
-rw-r--r-- | dexpreopt/config.go | 20 | ||||
-rw-r--r-- | dexpreopt/dexpreopt_gen/dexpreopt_gen.go | 2 | ||||
-rw-r--r-- | java/dexpreopt_bootjars.go | 21 | ||||
-rw-r--r-- | java/dexpreopt_config.go | 26 |
4 files changed, 50 insertions, 19 deletions
diff --git a/dexpreopt/config.go b/dexpreopt/config.go index 3b77042b..1e0f862e 100644 --- a/dexpreopt/config.go +++ b/dexpreopt/config.go | |||
@@ -176,7 +176,7 @@ func constructWritablePath(ctx android.PathContext, path string) android.Writabl | |||
176 | 176 | ||
177 | // LoadGlobalConfig reads the global dexpreopt.config file into a GlobalConfig struct. It is used directly in Soong | 177 | // LoadGlobalConfig reads the global dexpreopt.config file into a GlobalConfig struct. It is used directly in Soong |
178 | // and in dexpreopt_gen called from Make to read the $OUT/dexpreopt.config written by Make. | 178 | // and in dexpreopt_gen called from Make to read the $OUT/dexpreopt.config written by Make. |
179 | func LoadGlobalConfig(ctx android.PathContext, path string) (GlobalConfig, error) { | 179 | func LoadGlobalConfig(ctx android.PathContext, path string) (GlobalConfig, []byte, error) { |
180 | type GlobalJSONConfig struct { | 180 | type GlobalJSONConfig struct { |
181 | GlobalConfig | 181 | GlobalConfig |
182 | 182 | ||
@@ -199,9 +199,9 @@ func LoadGlobalConfig(ctx android.PathContext, path string) (GlobalConfig, error | |||
199 | } | 199 | } |
200 | 200 | ||
201 | config := GlobalJSONConfig{} | 201 | config := GlobalJSONConfig{} |
202 | err := loadConfig(ctx, path, &config) | 202 | data, err := loadConfig(ctx, path, &config) |
203 | if err != nil { | 203 | if err != nil { |
204 | return config.GlobalConfig, err | 204 | return config.GlobalConfig, nil, err |
205 | } | 205 | } |
206 | 206 | ||
207 | // Construct paths that require a PathContext. | 207 | // Construct paths that require a PathContext. |
@@ -217,7 +217,7 @@ func LoadGlobalConfig(ctx android.PathContext, path string) (GlobalConfig, error | |||
217 | config.GlobalConfig.Tools.VerifyUsesLibraries = constructPath(ctx, config.Tools.VerifyUsesLibraries) | 217 | config.GlobalConfig.Tools.VerifyUsesLibraries = constructPath(ctx, config.Tools.VerifyUsesLibraries) |
218 | config.GlobalConfig.Tools.ConstructContext = constructPath(ctx, config.Tools.ConstructContext) | 218 | config.GlobalConfig.Tools.ConstructContext = constructPath(ctx, config.Tools.ConstructContext) |
219 | 219 | ||
220 | return config.GlobalConfig, nil | 220 | return config.GlobalConfig, data, nil |
221 | } | 221 | } |
222 | 222 | ||
223 | // LoadModuleConfig reads a per-module dexpreopt.config file into a ModuleConfig struct. It is not used in Soong, which | 223 | // LoadModuleConfig reads a per-module dexpreopt.config file into a ModuleConfig struct. It is not used in Soong, which |
@@ -241,7 +241,7 @@ func LoadModuleConfig(ctx android.PathContext, path string) (ModuleConfig, error | |||
241 | 241 | ||
242 | config := ModuleJSONConfig{} | 242 | config := ModuleJSONConfig{} |
243 | 243 | ||
244 | err := loadConfig(ctx, path, &config) | 244 | _, err := loadConfig(ctx, path, &config) |
245 | if err != nil { | 245 | if err != nil { |
246 | return config.ModuleConfig, err | 246 | return config.ModuleConfig, err |
247 | } | 247 | } |
@@ -259,24 +259,24 @@ func LoadModuleConfig(ctx android.PathContext, path string) (ModuleConfig, error | |||
259 | return config.ModuleConfig, nil | 259 | return config.ModuleConfig, nil |
260 | } | 260 | } |
261 | 261 | ||
262 | func loadConfig(ctx android.PathContext, path string, config interface{}) error { | 262 | func loadConfig(ctx android.PathContext, path string, config interface{}) ([]byte, error) { |
263 | r, err := ctx.Fs().Open(path) | 263 | r, err := ctx.Fs().Open(path) |
264 | if err != nil { | 264 | if err != nil { |
265 | return err | 265 | return nil, err |
266 | } | 266 | } |
267 | defer r.Close() | 267 | defer r.Close() |
268 | 268 | ||
269 | data, err := ioutil.ReadAll(r) | 269 | data, err := ioutil.ReadAll(r) |
270 | if err != nil { | 270 | if err != nil { |
271 | return err | 271 | return nil, err |
272 | } | 272 | } |
273 | 273 | ||
274 | err = json.Unmarshal(data, config) | 274 | err = json.Unmarshal(data, config) |
275 | if err != nil { | 275 | if err != nil { |
276 | return err | 276 | return nil, err |
277 | } | 277 | } |
278 | 278 | ||
279 | return nil | 279 | return data, nil |
280 | } | 280 | } |
281 | 281 | ||
282 | func GlobalConfigForTests(ctx android.PathContext) GlobalConfig { | 282 | func GlobalConfigForTests(ctx android.PathContext) GlobalConfig { |
diff --git a/dexpreopt/dexpreopt_gen/dexpreopt_gen.go b/dexpreopt/dexpreopt_gen/dexpreopt_gen.go index c72f6842..d54ddb1f 100644 --- a/dexpreopt/dexpreopt_gen/dexpreopt_gen.go +++ b/dexpreopt/dexpreopt_gen/dexpreopt_gen.go | |||
@@ -78,7 +78,7 @@ func main() { | |||
78 | 78 | ||
79 | ctx := &pathContext{android.TestConfig(*outDir, nil)} | 79 | ctx := &pathContext{android.TestConfig(*outDir, nil)} |
80 | 80 | ||
81 | globalConfig, err := dexpreopt.LoadGlobalConfig(ctx, *globalConfigPath) | 81 | globalConfig, _, err := dexpreopt.LoadGlobalConfig(ctx, *globalConfigPath) |
82 | if err != nil { | 82 | if err != nil { |
83 | fmt.Fprintf(os.Stderr, "error loading global config %q: %s\n", *globalConfigPath, err) | 83 | fmt.Fprintf(os.Stderr, "error loading global config %q: %s\n", *globalConfigPath, err) |
84 | os.Exit(2) | 84 | os.Exit(2) |
diff --git a/java/dexpreopt_bootjars.go b/java/dexpreopt_bootjars.go index f48428f4..2a1a901b 100644 --- a/java/dexpreopt_bootjars.go +++ b/java/dexpreopt_bootjars.go | |||
@@ -115,6 +115,8 @@ func skipDexpreoptBootJars(ctx android.PathContext) bool { | |||
115 | type dexpreoptBootJars struct { | 115 | type dexpreoptBootJars struct { |
116 | defaultBootImage *bootImage | 116 | defaultBootImage *bootImage |
117 | otherImages []*bootImage | 117 | otherImages []*bootImage |
118 | |||
119 | dexpreoptConfigForMake android.WritablePath | ||
118 | } | 120 | } |
119 | 121 | ||
120 | // dexpreoptBoot singleton rules | 122 | // dexpreoptBoot singleton rules |
@@ -123,6 +125,9 @@ func (d *dexpreoptBootJars) GenerateBuildActions(ctx android.SingletonContext) { | |||
123 | return | 125 | return |
124 | } | 126 | } |
125 | 127 | ||
128 | d.dexpreoptConfigForMake = android.PathForOutput(ctx, ctx.Config().DeviceName(), "dexpreopt.config") | ||
129 | writeGlobalConfigForMake(ctx, d.dexpreoptConfigForMake) | ||
130 | |||
126 | global := dexpreoptGlobalConfig(ctx) | 131 | global := dexpreoptGlobalConfig(ctx) |
127 | 132 | ||
128 | // Skip recompiling the boot image for the second sanitization phase. We'll get separate paths | 133 | // Skip recompiling the boot image for the second sanitization phase. We'll get separate paths |
@@ -453,8 +458,24 @@ func dumpOatRules(ctx android.SingletonContext, image *bootImage) { | |||
453 | 458 | ||
454 | } | 459 | } |
455 | 460 | ||
461 | func writeGlobalConfigForMake(ctx android.SingletonContext, path android.WritablePath) { | ||
462 | data := dexpreoptGlobalConfigRaw(ctx).data | ||
463 | |||
464 | ctx.Build(pctx, android.BuildParams{ | ||
465 | Rule: android.WriteFile, | ||
466 | Output: path, | ||
467 | Args: map[string]string{ | ||
468 | "content": string(data), | ||
469 | }, | ||
470 | }) | ||
471 | } | ||
472 | |||
456 | // Export paths for default boot image to Make | 473 | // Export paths for default boot image to Make |
457 | func (d *dexpreoptBootJars) MakeVars(ctx android.MakeVarsContext) { | 474 | func (d *dexpreoptBootJars) MakeVars(ctx android.MakeVarsContext) { |
475 | if d.dexpreoptConfigForMake != nil { | ||
476 | ctx.Strict("DEX_PREOPT_CONFIG_FOR_MAKE", d.dexpreoptConfigForMake.String()) | ||
477 | } | ||
478 | |||
458 | image := d.defaultBootImage | 479 | image := d.defaultBootImage |
459 | if image != nil { | 480 | if image != nil { |
460 | ctx.Strict("DEXPREOPT_IMAGE_PROFILE_BUILT_INSTALLED", image.profileInstalls.String()) | 481 | ctx.Strict("DEXPREOPT_IMAGE_PROFILE_BUILT_INSTALLED", image.profileInstalls.String()) |
diff --git a/java/dexpreopt_config.go b/java/dexpreopt_config.go index 270fcb47..d903f456 100644 --- a/java/dexpreopt_config.go +++ b/java/dexpreopt_config.go | |||
@@ -15,40 +15,50 @@ | |||
15 | package java | 15 | package java |
16 | 16 | ||
17 | import ( | 17 | import ( |
18 | "android/soong/android" | ||
19 | "android/soong/dexpreopt" | ||
20 | "path/filepath" | 18 | "path/filepath" |
21 | "strings" | 19 | "strings" |
20 | |||
21 | "android/soong/android" | ||
22 | "android/soong/dexpreopt" | ||
22 | ) | 23 | ) |
23 | 24 | ||
24 | // dexpreoptGlobalConfig returns the global dexpreopt.config. It is loaded once the first time it is called for any | 25 | // dexpreoptGlobalConfig returns the global dexpreopt.config. It is loaded once the first time it is called for any |
25 | // ctx.Config(), and returns the same data for all future calls with the same ctx.Config(). A value can be inserted | 26 | // ctx.Config(), and returns the same data for all future calls with the same ctx.Config(). A value can be inserted |
26 | // for tests using setDexpreoptTestGlobalConfig. | 27 | // for tests using setDexpreoptTestGlobalConfig. |
27 | func dexpreoptGlobalConfig(ctx android.PathContext) dexpreopt.GlobalConfig { | 28 | func dexpreoptGlobalConfig(ctx android.PathContext) dexpreopt.GlobalConfig { |
29 | return dexpreoptGlobalConfigRaw(ctx).global | ||
30 | } | ||
31 | |||
32 | type globalConfigAndRaw struct { | ||
33 | global dexpreopt.GlobalConfig | ||
34 | data []byte | ||
35 | } | ||
36 | |||
37 | func dexpreoptGlobalConfigRaw(ctx android.PathContext) globalConfigAndRaw { | ||
28 | return ctx.Config().Once(dexpreoptGlobalConfigKey, func() interface{} { | 38 | return ctx.Config().Once(dexpreoptGlobalConfigKey, func() interface{} { |
29 | if f := ctx.Config().DexpreoptGlobalConfig(); f != "" { | 39 | if f := ctx.Config().DexpreoptGlobalConfig(); f != "" { |
30 | ctx.AddNinjaFileDeps(f) | 40 | ctx.AddNinjaFileDeps(f) |
31 | globalConfig, err := dexpreopt.LoadGlobalConfig(ctx, f) | 41 | globalConfig, data, err := dexpreopt.LoadGlobalConfig(ctx, f) |
32 | if err != nil { | 42 | if err != nil { |
33 | panic(err) | 43 | panic(err) |
34 | } | 44 | } |
35 | return globalConfig | 45 | return globalConfigAndRaw{globalConfig, data} |
36 | } | 46 | } |
37 | 47 | ||
38 | // No global config filename set, see if there is a test config set | 48 | // No global config filename set, see if there is a test config set |
39 | return ctx.Config().Once(dexpreoptTestGlobalConfigKey, func() interface{} { | 49 | return ctx.Config().Once(dexpreoptTestGlobalConfigKey, func() interface{} { |
40 | // Nope, return a config with preopting disabled | 50 | // Nope, return a config with preopting disabled |
41 | return dexpreopt.GlobalConfig{ | 51 | return globalConfigAndRaw{dexpreopt.GlobalConfig{ |
42 | DisablePreopt: true, | 52 | DisablePreopt: true, |
43 | } | 53 | }, nil} |
44 | }) | 54 | }) |
45 | }).(dexpreopt.GlobalConfig) | 55 | }).(globalConfigAndRaw) |
46 | } | 56 | } |
47 | 57 | ||
48 | // setDexpreoptTestGlobalConfig sets a GlobalConfig that future calls to dexpreoptGlobalConfig will return. It must | 58 | // setDexpreoptTestGlobalConfig sets a GlobalConfig that future calls to dexpreoptGlobalConfig will return. It must |
49 | // be called before the first call to dexpreoptGlobalConfig for the config. | 59 | // be called before the first call to dexpreoptGlobalConfig for the config. |
50 | func setDexpreoptTestGlobalConfig(config android.Config, globalConfig dexpreopt.GlobalConfig) { | 60 | func setDexpreoptTestGlobalConfig(config android.Config, globalConfig dexpreopt.GlobalConfig) { |
51 | config.Once(dexpreoptTestGlobalConfigKey, func() interface{} { return globalConfig }) | 61 | config.Once(dexpreoptTestGlobalConfigKey, func() interface{} { return globalConfigAndRaw{globalConfig, nil} }) |
52 | } | 62 | } |
53 | 63 | ||
54 | var dexpreoptGlobalConfigKey = android.NewOnceKey("DexpreoptGlobalConfig") | 64 | var dexpreoptGlobalConfigKey = android.NewOnceKey("DexpreoptGlobalConfig") |