From d3c1513df94c1494aa84f3c4cdfb29bb6b9d8252 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Wed, 21 Apr 2021 22:12:35 +0100 Subject: [PATCH] Add tempPathForRestat to improve consistency Previously, there were two approaches used to construct the temporary path needed by the commitChangeForRestat method and neither was suitable for general use. One was: android.PathForOutput(ctx, outputPath.Rel()+".tmp") The other was: combinedAidl.ReplaceExtension(ctx, "aidl.tmp") The first approach would not work if the supplied path had been created by PathForModuleOut() or similar as it would drop the module directory. That could lead to the same path being used for multiple rules. The second approach would not work for files with a different extension. The tempPathForRestat combines the two approaches so it can be used generally with any WritablePath. Bug: 179354495 Test: verified that the ninja rules that used these files were not changed by these changes. Change-Id: I4439dea0a823512c281eeb1366522fb49dceb4e3 --- java/hiddenapi_modular.go | 2 +- java/hiddenapi_singleton.go | 14 +++++++++++++- java/sdk.go | 6 +++--- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/java/hiddenapi_modular.go b/java/hiddenapi_modular.go index ebf541d25..747b29207 100644 --- a/java/hiddenapi_modular.go +++ b/java/hiddenapi_modular.go @@ -206,7 +206,7 @@ var hiddenAPIFlagFileInfoProvider = blueprint.NewProvider(hiddenAPIFlagFileInfo{ // augmentationInfo is a struct containing paths to files that augment the information provided by // the moduleSpecificFlagsPaths. func ruleToGenerateHiddenApiFlags(ctx android.BuilderContext, outputPath android.WritablePath, baseFlagsPath android.Path, moduleSpecificFlagsPaths android.Paths, augmentationInfo hiddenAPIFlagFileInfo) { - tempPath := android.PathForOutput(ctx, outputPath.Rel()+".tmp") + tempPath := tempPathForRestat(ctx, outputPath) rule := android.NewRuleBuilder(pctx, ctx) command := rule.Command(). BuiltTool("generate_hiddenapi_lists"). diff --git a/java/hiddenapi_singleton.go b/java/hiddenapi_singleton.go index ed0b72250..0149609f5 100644 --- a/java/hiddenapi_singleton.go +++ b/java/hiddenapi_singleton.go @@ -15,6 +15,8 @@ package java import ( + "strings" + "android/soong/android" ) @@ -242,7 +244,7 @@ func stubFlagsRule(ctx android.SingletonContext) { rule := android.NewRuleBuilder(pctx, ctx) outputPath := hiddenAPISingletonPaths(ctx).stubFlags - tempPath := android.PathForOutput(ctx, outputPath.Rel()+".tmp") + tempPath := tempPathForRestat(ctx, outputPath) rule.MissingDeps(missingDeps) @@ -348,6 +350,16 @@ func emptyFlagsRule(ctx android.SingletonContext) android.Path { return outputPath } +// tempPathForRestat creates a path of the same type as the supplied type but with a name of +// .tmp. +// +// e.g. If path is an OutputPath for out/soong/hiddenapi/hiddenapi-flags.csv then this will return +// an OutputPath for out/soong/hiddenapi/hiddenapi-flags.csv.tmp +func tempPathForRestat(ctx android.PathContext, path android.WritablePath) android.WritablePath { + extWithoutLeadingDot := strings.TrimPrefix(path.Ext(), ".") + return path.ReplaceExtension(ctx, extWithoutLeadingDot+".tmp") +} + // commitChangeForRestat adds a command to a rule that updates outputPath from tempPath if they are different. It // also marks the rule as restat and marks the tempPath as a temporary file that should not be considered an output of // the rule. diff --git a/java/sdk.go b/java/sdk.go index d6e20a78f..1c097d5b7 100644 --- a/java/sdk.go +++ b/java/sdk.go @@ -247,7 +247,7 @@ func createSdkFrameworkAidl(ctx android.SingletonContext) { } combinedAidl := sdkFrameworkAidlPath(ctx) - tempPath := combinedAidl.ReplaceExtension(ctx, "aidl.tmp") + tempPath := tempPathForRestat(ctx, combinedAidl) rule := createFrameworkAidl(stubsModules, tempPath, ctx) @@ -261,7 +261,7 @@ func createNonUpdatableFrameworkAidl(ctx android.SingletonContext) { stubsModules := []string{"android_module_lib_stubs_current"} combinedAidl := nonUpdatableFrameworkAidlPath(ctx) - tempPath := combinedAidl.ReplaceExtension(ctx, "aidl.tmp") + tempPath := tempPathForRestat(ctx, combinedAidl) rule := createFrameworkAidl(stubsModules, tempPath, ctx) @@ -270,7 +270,7 @@ func createNonUpdatableFrameworkAidl(ctx android.SingletonContext) { rule.Build("framework_non_updatable_aidl", "generate framework_non_updatable.aidl") } -func createFrameworkAidl(stubsModules []string, path android.OutputPath, ctx android.SingletonContext) *android.RuleBuilder { +func createFrameworkAidl(stubsModules []string, path android.WritablePath, ctx android.SingletonContext) *android.RuleBuilder { stubsJars := make([]android.Paths, len(stubsModules)) ctx.VisitAllModules(func(module android.Module) {