Merge changes from topic "soong_build_number_file"
* changes: Add an order-only dependency on the build number file Add support for order-only dependencies to RuleBuilder
This commit is contained in:
@@ -570,8 +570,8 @@ func (c *config) BuildId() string {
|
|||||||
return String(c.productVariables.BuildId)
|
return String(c.productVariables.BuildId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *config) BuildNumberFromFile() string {
|
func (c *config) BuildNumberFile(ctx PathContext) Path {
|
||||||
return String(c.productVariables.BuildNumberFromFile)
|
return PathForOutput(ctx, String(c.productVariables.BuildNumberFile))
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeviceName returns the name of the current device target
|
// DeviceName returns the name of the current device target
|
||||||
|
@@ -162,9 +162,10 @@ func (r *RuleBuilder) DeleteTemporaryFiles() {
|
|||||||
r.Command().Text("rm").Flag("-f").Outputs(temporariesList)
|
r.Command().Text("rm").Flag("-f").Outputs(temporariesList)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inputs returns the list of paths that were passed to the RuleBuilderCommand methods that take input paths, such
|
// Inputs returns the list of paths that were passed to the RuleBuilderCommand methods that take
|
||||||
// as RuleBuilderCommand.Input, RuleBuilderComand.Implicit, or RuleBuilderCommand.FlagWithInput. Inputs to a command
|
// input paths, such as RuleBuilderCommand.Input, RuleBuilderComand.Implicit, or
|
||||||
// that are also outputs of another command in the same RuleBuilder are filtered out.
|
// RuleBuilderCommand.FlagWithInput. Inputs to a command that are also outputs of another command
|
||||||
|
// in the same RuleBuilder are filtered out. The list is sorted and duplicates removed.
|
||||||
func (r *RuleBuilder) Inputs() Paths {
|
func (r *RuleBuilder) Inputs() Paths {
|
||||||
outputs := r.outputSet()
|
outputs := r.outputSet()
|
||||||
depFiles := r.depFileSet()
|
depFiles := r.depFileSet()
|
||||||
@@ -193,6 +194,28 @@ func (r *RuleBuilder) Inputs() Paths {
|
|||||||
return inputList
|
return inputList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OrderOnlys returns the list of paths that were passed to the RuleBuilderCommand.OrderOnly or
|
||||||
|
// RuleBuilderCommand.OrderOnlys. The list is sorted and duplicates removed.
|
||||||
|
func (r *RuleBuilder) OrderOnlys() Paths {
|
||||||
|
orderOnlys := make(map[string]Path)
|
||||||
|
for _, c := range r.commands {
|
||||||
|
for _, orderOnly := range c.orderOnlys {
|
||||||
|
orderOnlys[orderOnly.String()] = orderOnly
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var orderOnlyList Paths
|
||||||
|
for _, orderOnly := range orderOnlys {
|
||||||
|
orderOnlyList = append(orderOnlyList, orderOnly)
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Slice(orderOnlyList, func(i, j int) bool {
|
||||||
|
return orderOnlyList[i].String() < orderOnlyList[j].String()
|
||||||
|
})
|
||||||
|
|
||||||
|
return orderOnlyList
|
||||||
|
}
|
||||||
|
|
||||||
func (r *RuleBuilder) outputSet() map[string]WritablePath {
|
func (r *RuleBuilder) outputSet() map[string]WritablePath {
|
||||||
outputs := make(map[string]WritablePath)
|
outputs := make(map[string]WritablePath)
|
||||||
for _, c := range r.commands {
|
for _, c := range r.commands {
|
||||||
@@ -203,8 +226,9 @@ func (r *RuleBuilder) outputSet() map[string]WritablePath {
|
|||||||
return outputs
|
return outputs
|
||||||
}
|
}
|
||||||
|
|
||||||
// Outputs returns the list of paths that were passed to the RuleBuilderCommand methods that take output paths, such
|
// Outputs returns the list of paths that were passed to the RuleBuilderCommand methods that take
|
||||||
// as RuleBuilderCommand.Output, RuleBuilderCommand.ImplicitOutput, or RuleBuilderCommand.FlagWithInput.
|
// output paths, such as RuleBuilderCommand.Output, RuleBuilderCommand.ImplicitOutput, or
|
||||||
|
// RuleBuilderCommand.FlagWithInput. The list is sorted and duplicates removed.
|
||||||
func (r *RuleBuilder) Outputs() WritablePaths {
|
func (r *RuleBuilder) Outputs() WritablePaths {
|
||||||
outputs := r.outputSet()
|
outputs := r.outputSet()
|
||||||
|
|
||||||
@@ -262,7 +286,8 @@ func (r *RuleBuilder) toolsSet() map[string]Path {
|
|||||||
return tools
|
return tools
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tools returns the list of paths that were passed to the RuleBuilderCommand.Tool method.
|
// Tools returns the list of paths that were passed to the RuleBuilderCommand.Tool method. The
|
||||||
|
// list is sorted and duplicates removed.
|
||||||
func (r *RuleBuilder) Tools() Paths {
|
func (r *RuleBuilder) Tools() Paths {
|
||||||
toolsSet := r.toolsSet()
|
toolsSet := r.toolsSet()
|
||||||
|
|
||||||
@@ -337,6 +362,7 @@ func (r *RuleBuilder) Build(pctx PackageContext, ctx BuilderContext, name string
|
|||||||
ctx.Build(pctx, BuildParams{
|
ctx.Build(pctx, BuildParams{
|
||||||
Rule: ErrorRule,
|
Rule: ErrorRule,
|
||||||
Outputs: r.Outputs(),
|
Outputs: r.Outputs(),
|
||||||
|
OrderOnly: r.OrderOnlys(),
|
||||||
Description: desc,
|
Description: desc,
|
||||||
Args: map[string]string{
|
Args: map[string]string{
|
||||||
"error": "missing dependencies: " + strings.Join(r.missingDeps, ", "),
|
"error": "missing dependencies: " + strings.Join(r.missingDeps, ", "),
|
||||||
@@ -453,6 +479,7 @@ func (r *RuleBuilder) Build(pctx PackageContext, ctx BuilderContext, name string
|
|||||||
type RuleBuilderCommand struct {
|
type RuleBuilderCommand struct {
|
||||||
buf strings.Builder
|
buf strings.Builder
|
||||||
inputs Paths
|
inputs Paths
|
||||||
|
orderOnlys Paths
|
||||||
outputs WritablePaths
|
outputs WritablePaths
|
||||||
depFiles WritablePaths
|
depFiles WritablePaths
|
||||||
tools Paths
|
tools Paths
|
||||||
@@ -475,6 +502,10 @@ func (c *RuleBuilderCommand) addInput(path Path) string {
|
|||||||
return path.String()
|
return path.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *RuleBuilderCommand) addOrderOnly(path Path) {
|
||||||
|
c.orderOnlys = append(c.orderOnlys, path)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *RuleBuilderCommand) outputStr(path Path) string {
|
func (c *RuleBuilderCommand) outputStr(path Path) string {
|
||||||
if c.sbox {
|
if c.sbox {
|
||||||
// Errors will be handled in RuleBuilder.Build where we have a context to report them
|
// Errors will be handled in RuleBuilder.Build where we have a context to report them
|
||||||
@@ -604,6 +635,22 @@ func (c *RuleBuilderCommand) Implicits(paths Paths) *RuleBuilderCommand {
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OrderOnly adds the specified input path to the dependencies returned by RuleBuilder.OrderOnlys
|
||||||
|
// without modifying the command line.
|
||||||
|
func (c *RuleBuilderCommand) OrderOnly(path Path) *RuleBuilderCommand {
|
||||||
|
c.addOrderOnly(path)
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// OrderOnlys adds the specified input paths to the dependencies returned by RuleBuilder.OrderOnlys
|
||||||
|
// without modifying the command line.
|
||||||
|
func (c *RuleBuilderCommand) OrderOnlys(paths Paths) *RuleBuilderCommand {
|
||||||
|
for _, path := range paths {
|
||||||
|
c.addOrderOnly(path)
|
||||||
|
}
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
// Output adds the specified output path to the command line. The path will also be added to the outputs returned by
|
// Output adds the specified output path to the command line. The path will also be added to the outputs returned by
|
||||||
// RuleBuilder.Outputs.
|
// RuleBuilder.Outputs.
|
||||||
func (c *RuleBuilderCommand) Output(path WritablePath) *RuleBuilderCommand {
|
func (c *RuleBuilderCommand) Output(path WritablePath) *RuleBuilderCommand {
|
||||||
|
@@ -265,14 +265,16 @@ func ExampleRuleBuilderCommand_NinjaEscapedString() {
|
|||||||
|
|
||||||
func TestRuleBuilder(t *testing.T) {
|
func TestRuleBuilder(t *testing.T) {
|
||||||
fs := map[string][]byte{
|
fs := map[string][]byte{
|
||||||
"dep_fixer": nil,
|
"dep_fixer": nil,
|
||||||
"input": nil,
|
"input": nil,
|
||||||
"Implicit": nil,
|
"Implicit": nil,
|
||||||
"Input": nil,
|
"Input": nil,
|
||||||
"Tool": nil,
|
"OrderOnly": nil,
|
||||||
"input2": nil,
|
"OrderOnlys": nil,
|
||||||
"tool2": nil,
|
"Tool": nil,
|
||||||
"input3": nil,
|
"input2": nil,
|
||||||
|
"tool2": nil,
|
||||||
|
"input3": nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := PathContextForTesting(TestConfig("out", nil, "", fs))
|
ctx := PathContextForTesting(TestConfig("out", nil, "", fs))
|
||||||
@@ -290,6 +292,7 @@ func TestRuleBuilder(t *testing.T) {
|
|||||||
ImplicitOutput(PathForOutput(ctx, "ImplicitOutput")).
|
ImplicitOutput(PathForOutput(ctx, "ImplicitOutput")).
|
||||||
Input(PathForSource(ctx, "Input")).
|
Input(PathForSource(ctx, "Input")).
|
||||||
Output(PathForOutput(ctx, "Output")).
|
Output(PathForOutput(ctx, "Output")).
|
||||||
|
OrderOnly(PathForSource(ctx, "OrderOnly")).
|
||||||
Text("Text").
|
Text("Text").
|
||||||
Tool(PathForSource(ctx, "Tool"))
|
Tool(PathForSource(ctx, "Tool"))
|
||||||
|
|
||||||
@@ -298,6 +301,7 @@ func TestRuleBuilder(t *testing.T) {
|
|||||||
DepFile(PathForOutput(ctx, "depfile2")).
|
DepFile(PathForOutput(ctx, "depfile2")).
|
||||||
Input(PathForSource(ctx, "input2")).
|
Input(PathForSource(ctx, "input2")).
|
||||||
Output(PathForOutput(ctx, "output2")).
|
Output(PathForOutput(ctx, "output2")).
|
||||||
|
OrderOnlys(PathsForSource(ctx, []string{"OrderOnlys"})).
|
||||||
Tool(PathForSource(ctx, "tool2"))
|
Tool(PathForSource(ctx, "tool2"))
|
||||||
|
|
||||||
// Test updates to the first command after the second command has been started
|
// Test updates to the first command after the second command has been started
|
||||||
@@ -317,6 +321,7 @@ func TestRuleBuilder(t *testing.T) {
|
|||||||
wantOutputs := PathsForOutput(ctx, []string{"ImplicitOutput", "Output", "output", "output2", "output3"})
|
wantOutputs := PathsForOutput(ctx, []string{"ImplicitOutput", "Output", "output", "output2", "output3"})
|
||||||
wantDepFiles := PathsForOutput(ctx, []string{"DepFile", "depfile", "ImplicitDepFile", "depfile2"})
|
wantDepFiles := PathsForOutput(ctx, []string{"DepFile", "depfile", "ImplicitDepFile", "depfile2"})
|
||||||
wantTools := PathsForSource(ctx, []string{"Tool", "tool2"})
|
wantTools := PathsForSource(ctx, []string{"Tool", "tool2"})
|
||||||
|
wantOrderOnlys := PathsForSource(ctx, []string{"OrderOnly", "OrderOnlys"})
|
||||||
|
|
||||||
t.Run("normal", func(t *testing.T) {
|
t.Run("normal", func(t *testing.T) {
|
||||||
rule := NewRuleBuilder()
|
rule := NewRuleBuilder()
|
||||||
@@ -346,6 +351,9 @@ func TestRuleBuilder(t *testing.T) {
|
|||||||
if g, w := rule.Tools(), wantTools; !reflect.DeepEqual(w, g) {
|
if g, w := rule.Tools(), wantTools; !reflect.DeepEqual(w, g) {
|
||||||
t.Errorf("\nwant rule.Tools() = %#v\n got %#v", w, g)
|
t.Errorf("\nwant rule.Tools() = %#v\n got %#v", w, g)
|
||||||
}
|
}
|
||||||
|
if g, w := rule.OrderOnlys(), wantOrderOnlys; !reflect.DeepEqual(w, g) {
|
||||||
|
t.Errorf("\nwant rule.OrderOnlys() = %#v\n got %#v", w, g)
|
||||||
|
}
|
||||||
|
|
||||||
if g, w := rule.depFileMergerCmd(ctx, rule.DepFiles()).String(), wantDepMergerCommand; g != w {
|
if g, w := rule.depFileMergerCmd(ctx, rule.DepFiles()).String(), wantDepMergerCommand; g != w {
|
||||||
t.Errorf("\nwant rule.depFileMergerCmd() = %#v\n got %#v", w, g)
|
t.Errorf("\nwant rule.depFileMergerCmd() = %#v\n got %#v", w, g)
|
||||||
@@ -380,6 +388,9 @@ func TestRuleBuilder(t *testing.T) {
|
|||||||
if g, w := rule.Tools(), wantTools; !reflect.DeepEqual(w, g) {
|
if g, w := rule.Tools(), wantTools; !reflect.DeepEqual(w, g) {
|
||||||
t.Errorf("\nwant rule.Tools() = %#v\n got %#v", w, g)
|
t.Errorf("\nwant rule.Tools() = %#v\n got %#v", w, g)
|
||||||
}
|
}
|
||||||
|
if g, w := rule.OrderOnlys(), wantOrderOnlys; !reflect.DeepEqual(w, g) {
|
||||||
|
t.Errorf("\nwant rule.OrderOnlys() = %#v\n got %#v", w, g)
|
||||||
|
}
|
||||||
|
|
||||||
if g, w := rule.depFileMergerCmd(ctx, rule.DepFiles()).String(), wantDepMergerCommand; g != w {
|
if g, w := rule.depFileMergerCmd(ctx, rule.DepFiles()).String(), wantDepMergerCommand; g != w {
|
||||||
t.Errorf("\nwant rule.depFileMergerCmd() = %#v\n got %#v", w, g)
|
t.Errorf("\nwant rule.depFileMergerCmd() = %#v\n got %#v", w, g)
|
||||||
|
@@ -140,9 +140,8 @@ type productVariables struct {
|
|||||||
// Suffix to add to generated Makefiles
|
// Suffix to add to generated Makefiles
|
||||||
Make_suffix *string `json:",omitempty"`
|
Make_suffix *string `json:",omitempty"`
|
||||||
|
|
||||||
BuildId *string `json:",omitempty"`
|
BuildId *string `json:",omitempty"`
|
||||||
BuildNumberFromFile *string `json:",omitempty"`
|
BuildNumberFile *string `json:",omitempty"`
|
||||||
DateFromFile *string `json:",omitempty"`
|
|
||||||
|
|
||||||
Platform_version_name *string `json:",omitempty"`
|
Platform_version_name *string `json:",omitempty"`
|
||||||
Platform_sdk_version *int `json:",omitempty"`
|
Platform_sdk_version *int `json:",omitempty"`
|
||||||
@@ -345,7 +344,7 @@ func stringPtr(v string) *string {
|
|||||||
|
|
||||||
func (v *productVariables) SetDefaultConfig() {
|
func (v *productVariables) SetDefaultConfig() {
|
||||||
*v = productVariables{
|
*v = productVariables{
|
||||||
BuildNumberFromFile: stringPtr("123456789"),
|
BuildNumberFile: stringPtr("build_number.txt"),
|
||||||
|
|
||||||
Platform_version_name: stringPtr("Q"),
|
Platform_version_name: stringPtr("Q"),
|
||||||
Platform_sdk_version: intPtr(28),
|
Platform_sdk_version: intPtr(28),
|
||||||
|
@@ -501,19 +501,21 @@ func init() {
|
|||||||
var injectVersionSymbol = pctx.AndroidStaticRule("injectVersionSymbol",
|
var injectVersionSymbol = pctx.AndroidStaticRule("injectVersionSymbol",
|
||||||
blueprint.RuleParams{
|
blueprint.RuleParams{
|
||||||
Command: "$symbolInjectCmd -i $in -o $out -s soong_build_number " +
|
Command: "$symbolInjectCmd -i $in -o $out -s soong_build_number " +
|
||||||
"-from 'SOONG BUILD NUMBER PLACEHOLDER' -v $buildNumberFromFile",
|
"-from 'SOONG BUILD NUMBER PLACEHOLDER' -v $$(cat $buildNumberFile)",
|
||||||
CommandDeps: []string{"$symbolInjectCmd"},
|
CommandDeps: []string{"$symbolInjectCmd"},
|
||||||
},
|
},
|
||||||
"buildNumberFromFile")
|
"buildNumberFile")
|
||||||
|
|
||||||
func (linker *baseLinker) injectVersionSymbol(ctx ModuleContext, in android.Path, out android.WritablePath) {
|
func (linker *baseLinker) injectVersionSymbol(ctx ModuleContext, in android.Path, out android.WritablePath) {
|
||||||
|
buildNumberFile := ctx.Config().BuildNumberFile(ctx)
|
||||||
ctx.Build(pctx, android.BuildParams{
|
ctx.Build(pctx, android.BuildParams{
|
||||||
Rule: injectVersionSymbol,
|
Rule: injectVersionSymbol,
|
||||||
Description: "inject version symbol",
|
Description: "inject version symbol",
|
||||||
Input: in,
|
Input: in,
|
||||||
Output: out,
|
Output: out,
|
||||||
|
OrderOnly: android.Paths{buildNumberFile},
|
||||||
Args: map[string]string{
|
Args: map[string]string{
|
||||||
"buildNumberFromFile": proptools.NinjaEscape(ctx.Config().BuildNumberFromFile()),
|
"buildNumberFile": buildNumberFile.String(),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@@ -773,6 +773,7 @@ func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Droiddoc) doclavaDocsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, docletPath classpath) {
|
func (d *Droiddoc) doclavaDocsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, docletPath classpath) {
|
||||||
|
buildNumberFile := ctx.Config().BuildNumberFile(ctx)
|
||||||
// Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
|
// Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
|
||||||
// sources, droiddoc will get sources produced by metalava which will have already stripped out the
|
// sources, droiddoc will get sources produced by metalava which will have already stripped out the
|
||||||
// 1.9 language features.
|
// 1.9 language features.
|
||||||
@@ -782,7 +783,7 @@ func (d *Droiddoc) doclavaDocsFlags(ctx android.ModuleContext, cmd *android.Rule
|
|||||||
Flag("-XDignore.symbol.file").
|
Flag("-XDignore.symbol.file").
|
||||||
FlagWithArg("-doclet ", "com.google.doclava.Doclava").
|
FlagWithArg("-doclet ", "com.google.doclava.Doclava").
|
||||||
FlagWithInputList("-docletpath ", docletPath.Paths(), ":").
|
FlagWithInputList("-docletpath ", docletPath.Paths(), ":").
|
||||||
FlagWithArg("-hdf page.build ", ctx.Config().BuildId()+"-"+ctx.Config().BuildNumberFromFile()).
|
FlagWithArg("-hdf page.build ", ctx.Config().BuildId()+"-$(cat "+buildNumberFile.String()+")").OrderOnly(buildNumberFile).
|
||||||
FlagWithArg("-hdf page.now ", `"$(date -d @$(cat `+ctx.Config().Getenv("BUILD_DATETIME_FILE")+`) "+%d %b %Y %k:%M")" `)
|
FlagWithArg("-hdf page.now ", `"$(date -d @$(cat `+ctx.Config().Getenv("BUILD_DATETIME_FILE")+`) "+%d %b %Y %k:%M")" `)
|
||||||
|
|
||||||
if String(d.properties.Custom_template) == "" {
|
if String(d.properties.Custom_template) == "" {
|
||||||
|
Reference in New Issue
Block a user