Skip to content

Commit

Permalink
Create rule to generate the exportable api files when checkapi is dis…
Browse files Browse the repository at this point in the history
…abled

WITHOUT_CHECK_API environment variable enables the checkapi to be
removed from the critical path. The variable is rarely used within AOSP,
but the downstream vendors may depend on it, in order to improve the
build performance given that the api signature file through metalava is
a resource costly task.

Currently, the exportable api files / removed api files are not
generated when checkapi is disabled, but a module may depend on the
exportable api files when a checkapi is disabled. In order to prevent
the missing build rules error in this case, generate the rule to copy
the checked in api file / removed api file to the exportable api file /
removed api file to prevent build errors.

This change also fixes the error message when the OutputFiles(string)
api file is null, to correctly inform the user the error.

Test: m BUILD_FROM_SOURCE_STUB=true WITHOUT_CHECK_API=true && inspect ninja path and verify that "non-updatable-exportable-current.txt" depends on the generated exportable api file.
Bug: 329374072
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:2d4074a022c0d836c712a6606b5c6e2cb376e07a)
Merged-In: I24f88d450fb46b6ea9d5920d83617d8228edd34b
Change-Id: I24f88d450fb46b6ea9d5920d83617d8228edd34b
  • Loading branch information
jihoonkang0829 authored and Android Build Coastguard Worker committed Mar 20, 2024
1 parent 025dee5 commit 58d100f
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions java/droidstubs.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ func (d *Droidstubs) ApiFilePath(stubsType StubsType) (ret android.Path, err err
ret, err = nil, fmt.Errorf("api file path not supported for the stub type %s", stubsType.String())
}
if ret == nil && err == nil {
err = fmt.Errorf("stubs srcjar is null for the stub type %s", stubsType.String())
err = fmt.Errorf("api file is null for the stub type %s", stubsType.String())
}
return ret, err
}
Expand Down Expand Up @@ -478,34 +478,41 @@ func (d *Droidstubs) sdkValuesFlags(ctx android.ModuleContext, cmd *android.Rule
}

func (d *Droidstubs) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.OptionalPath, stubsType StubsType, checkApi bool) {
if checkApi || String(d.properties.Api_filename) != "" {
filename := proptools.StringDefault(d.properties.Api_filename, ctx.ModuleName()+"_api.txt")
uncheckedApiFile := android.PathForModuleOut(ctx, stubsType.String(), filename)
cmd.FlagWithOutput("--api ", uncheckedApiFile)

apiFileName := proptools.StringDefault(d.properties.Api_filename, ctx.ModuleName()+"_api.txt")
uncheckedApiFile := android.PathForModuleOut(ctx, stubsType.String(), apiFileName)
cmd.FlagWithOutput("--api ", uncheckedApiFile)
if checkApi || String(d.properties.Api_filename) != "" {
if stubsType == Everything {
d.apiFile = uncheckedApiFile
} else if stubsType == Exportable {
d.exportableApiFile = uncheckedApiFile
}
} else if sourceApiFile := proptools.String(d.properties.Check_api.Current.Api_file); sourceApiFile != "" {
// If check api is disabled then make the source file available for export.
d.apiFile = android.PathForModuleSrc(ctx, sourceApiFile)
if stubsType == Everything {
// If check api is disabled then make the source file available for export.
d.apiFile = android.PathForModuleSrc(ctx, sourceApiFile)
} else if stubsType == Exportable {
d.exportableApiFile = uncheckedApiFile
}
}

removedApiFileName := proptools.StringDefault(d.properties.Removed_api_filename, ctx.ModuleName()+"_removed.txt")
uncheckedRemovedFile := android.PathForModuleOut(ctx, stubsType.String(), removedApiFileName)
cmd.FlagWithOutput("--removed-api ", uncheckedRemovedFile)
if checkApi || String(d.properties.Removed_api_filename) != "" {
filename := proptools.StringDefault(d.properties.Removed_api_filename, ctx.ModuleName()+"_removed.txt")
uncheckedRemovedFile := android.PathForModuleOut(ctx, stubsType.String(), filename)
cmd.FlagWithOutput("--removed-api ", uncheckedRemovedFile)

if stubsType == Everything {
d.removedApiFile = uncheckedRemovedFile
} else if stubsType == Exportable {
d.exportableRemovedApiFile = uncheckedRemovedFile
}
} else if sourceRemovedApiFile := proptools.String(d.properties.Check_api.Current.Removed_api_file); sourceRemovedApiFile != "" {
// If check api is disabled then make the source removed api file available for export.
d.removedApiFile = android.PathForModuleSrc(ctx, sourceRemovedApiFile)
if stubsType == Everything {
// If check api is disabled then make the source removed api file available for export.
d.removedApiFile = android.PathForModuleSrc(ctx, sourceRemovedApiFile)
} else if stubsType == Exportable {
d.exportableRemovedApiFile = uncheckedRemovedFile
}
}

if stubsDir.Valid() {
Expand Down

0 comments on commit 58d100f

Please sign in to comment.