Merge changes from topics "dist-for-goals", "soong-dist", "tests-PathForSource"

* changes:
  Add DistForGoal to MakeVarsContext
  Define Soong phony rules in Make
  Remove paths from cc.TestConfig
  Remove most paths from java.TestConfig
  Allow tests to bypass PathForSource existence checks
This commit is contained in:
Colin Cross
2020-06-11 18:36:18 +00:00
committed by Gerrit Code Review
16 changed files with 290 additions and 185 deletions

View File

@@ -36,6 +36,7 @@ bootstrap_go_package {
"package_ctx.go", "package_ctx.go",
"path_properties.go", "path_properties.go",
"paths.go", "paths.go",
"phony.go",
"prebuilt.go", "prebuilt.go",
"proto.go", "proto.go",
"register.go", "register.go",

View File

@@ -111,6 +111,10 @@ type config struct {
fs pathtools.FileSystem fs pathtools.FileSystem
mockBpList string mockBpList string
// If testAllowNonExistentPaths is true then PathForSource and PathForModuleSrc won't error
// in tests when a path doesn't exist.
testAllowNonExistentPaths bool
OncePer OncePer
} }
@@ -230,6 +234,10 @@ func TestConfig(buildDir string, env map[string]string, bp string, fs map[string
buildDir: buildDir, buildDir: buildDir,
captureBuild: true, captureBuild: true,
env: envCopy, env: envCopy,
// Set testAllowNonExistentPaths so that test contexts don't need to specify every path
// passed to PathForSource or PathForModuleSrc.
testAllowNonExistentPaths: true,
} }
config.deviceConfig = &deviceConfig{ config.deviceConfig = &deviceConfig{
config: config, config: config,

View File

@@ -17,12 +17,11 @@ package android
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io/ioutil"
"os"
"strconv" "strconv"
"strings" "strings"
"github.com/google/blueprint" "github.com/google/blueprint"
"github.com/google/blueprint/pathtools"
"github.com/google/blueprint/proptools" "github.com/google/blueprint/proptools"
) )
@@ -84,6 +83,29 @@ type MakeVarsContext interface {
// builder whenever a file matching the pattern as added or removed, without rerunning if a // builder whenever a file matching the pattern as added or removed, without rerunning if a
// file that does not match the pattern is added to a searched directory. // file that does not match the pattern is added to a searched directory.
GlobWithDeps(pattern string, excludes []string) ([]string, error) GlobWithDeps(pattern string, excludes []string) ([]string, error)
// Phony creates a phony rule in Make, which will allow additional DistForGoal
// dependencies to be added to it. Phony can be called on the same name multiple
// times to add additional dependencies.
Phony(names string, deps ...Path)
// DistForGoal creates a rule to copy one or more Paths to the artifacts
// directory on the build server when the specified goal is built.
DistForGoal(goal string, paths ...Path)
// DistForGoalWithFilename creates a rule to copy a Path to the artifacts
// directory on the build server with the given filename when the specified
// goal is built.
DistForGoalWithFilename(goal string, path Path, filename string)
// DistForGoals creates a rule to copy one or more Paths to the artifacts
// directory on the build server when any of the specified goals are built.
DistForGoals(goals []string, paths ...Path)
// DistForGoalsWithFilename creates a rule to copy a Path to the artifacts
// directory on the build server with the given filename when any of the
// specified goals are built.
DistForGoalsWithFilename(goals []string, path Path, filename string)
} }
var _ PathContext = MakeVarsContext(nil) var _ PathContext = MakeVarsContext(nil)
@@ -133,6 +155,8 @@ type makeVarsContext struct {
config Config config Config
pctx PackageContext pctx PackageContext
vars []makeVarsVariable vars []makeVarsVariable
phonies []phony
dists []dist
} }
var _ MakeVarsContext = &makeVarsContext{} var _ MakeVarsContext = &makeVarsContext{}
@@ -144,6 +168,16 @@ type makeVarsVariable struct {
strict bool strict bool
} }
type phony struct {
name string
deps []string
}
type dist struct {
goals []string
paths []string
}
func (s *makeVarsSingleton) GenerateBuildActions(ctx SingletonContext) { func (s *makeVarsSingleton) GenerateBuildActions(ctx SingletonContext) {
if !ctx.Config().EmbeddedInMake() { if !ctx.Config().EmbeddedInMake() {
return return
@@ -152,11 +186,16 @@ func (s *makeVarsSingleton) GenerateBuildActions(ctx SingletonContext) {
outFile := absolutePath(PathForOutput(ctx, outFile := absolutePath(PathForOutput(ctx,
"make_vars"+proptools.String(ctx.Config().productVariables.Make_suffix)+".mk").String()) "make_vars"+proptools.String(ctx.Config().productVariables.Make_suffix)+".mk").String())
lateOutFile := absolutePath(PathForOutput(ctx,
"late"+proptools.String(ctx.Config().productVariables.Make_suffix)+".mk").String())
if ctx.Failed() { if ctx.Failed() {
return return
} }
vars := []makeVarsVariable{} var vars []makeVarsVariable
var dists []dist
var phonies []phony
for _, provider := range makeVarsProviders { for _, provider := range makeVarsProviders {
mctx := &makeVarsContext{ mctx := &makeVarsContext{
SingletonContext: ctx, SingletonContext: ctx,
@@ -166,6 +205,8 @@ func (s *makeVarsSingleton) GenerateBuildActions(ctx SingletonContext) {
provider.call(mctx) provider.call(mctx)
vars = append(vars, mctx.vars...) vars = append(vars, mctx.vars...)
phonies = append(phonies, mctx.phonies...)
dists = append(dists, mctx.dists...)
} }
if ctx.Failed() { if ctx.Failed() {
@@ -174,17 +215,16 @@ func (s *makeVarsSingleton) GenerateBuildActions(ctx SingletonContext) {
outBytes := s.writeVars(vars) outBytes := s.writeVars(vars)
if _, err := os.Stat(absolutePath(outFile)); err == nil { if err := pathtools.WriteFileIfChanged(outFile, outBytes, 0666); err != nil {
if data, err := ioutil.ReadFile(absolutePath(outFile)); err == nil {
if bytes.Equal(data, outBytes) {
return
}
}
}
if err := ioutil.WriteFile(absolutePath(outFile), outBytes, 0666); err != nil {
ctx.Errorf(err.Error()) ctx.Errorf(err.Error())
} }
lateOutBytes := s.writeLate(phonies, dists)
if err := pathtools.WriteFileIfChanged(lateOutFile, lateOutBytes, 0666); err != nil {
ctx.Errorf(err.Error())
}
} }
func (s *makeVarsSingleton) writeVars(vars []makeVarsVariable) []byte { func (s *makeVarsSingleton) writeVars(vars []makeVarsVariable) []byte {
@@ -263,6 +303,33 @@ my_check_failed :=
fmt.Fprintln(buf, "\nsoong-compare-var :=") fmt.Fprintln(buf, "\nsoong-compare-var :=")
fmt.Fprintln(buf)
return buf.Bytes()
}
func (s *makeVarsSingleton) writeLate(phonies []phony, dists []dist) []byte {
buf := &bytes.Buffer{}
fmt.Fprint(buf, `# Autogenerated file
# Values written by Soong read after parsing all Android.mk files.
`)
for _, phony := range phonies {
fmt.Fprintf(buf, ".PHONY: %s\n", phony.name)
fmt.Fprintf(buf, "%s: %s\n", phony.name, strings.Join(phony.deps, "\\\n "))
}
fmt.Fprintln(buf)
for _, dist := range dists {
fmt.Fprintf(buf, "$(call dist-for-goals,%s,%s)\n",
strings.Join(dist.goals, " "), strings.Join(dist.paths, " "))
}
return buf.Bytes() return buf.Bytes()
} }
@@ -299,6 +366,17 @@ func (c *makeVarsContext) addVariable(name, ninjaStr string, strict, sort bool)
c.addVariableRaw(name, value, strict, sort) c.addVariableRaw(name, value, strict, sort)
} }
func (c *makeVarsContext) addPhony(name string, deps []string) {
c.phonies = append(c.phonies, phony{name, deps})
}
func (c *makeVarsContext) addDist(goals []string, paths []string) {
c.dists = append(c.dists, dist{
goals: goals,
paths: paths,
})
}
func (c *makeVarsContext) Strict(name, ninjaStr string) { func (c *makeVarsContext) Strict(name, ninjaStr string) {
c.addVariable(name, ninjaStr, true, false) c.addVariable(name, ninjaStr, true, false)
} }
@@ -318,3 +396,23 @@ func (c *makeVarsContext) CheckSorted(name, ninjaStr string) {
func (c *makeVarsContext) CheckRaw(name, value string) { func (c *makeVarsContext) CheckRaw(name, value string) {
c.addVariableRaw(name, value, false, false) c.addVariableRaw(name, value, false, false)
} }
func (c *makeVarsContext) Phony(name string, deps ...Path) {
c.addPhony(name, Paths(deps).Strings())
}
func (c *makeVarsContext) DistForGoal(goal string, paths ...Path) {
c.DistForGoals([]string{goal}, paths...)
}
func (c *makeVarsContext) DistForGoalWithFilename(goal string, path Path, filename string) {
c.DistForGoalsWithFilename([]string{goal}, path, filename)
}
func (c *makeVarsContext) DistForGoals(goals []string, paths ...Path) {
c.addDist(goals, Paths(paths).Strings())
}
func (c *makeVarsContext) DistForGoalsWithFilename(goals []string, path Path, filename string) {
c.addDist(goals, []string{path.String() + ":" + filename})
}

View File

@@ -207,6 +207,10 @@ type ModuleContext interface {
// Similar to blueprint.ModuleContext.Build, but takes Paths instead of []string, // Similar to blueprint.ModuleContext.Build, but takes Paths instead of []string,
// and performs more verification. // and performs more verification.
Build(pctx PackageContext, params BuildParams) Build(pctx PackageContext, params BuildParams)
// Phony creates a Make-style phony rule, a rule with no commands that can depend on other
// phony rules or real files. Phony can be called on the same name multiple times to add
// additional dependencies.
Phony(phony string, deps ...Path)
PrimaryModule() Module PrimaryModule() Module
FinalModule() Module FinalModule() Module
@@ -722,6 +726,7 @@ type ModuleBase struct {
installFiles InstallPaths installFiles InstallPaths
checkbuildFiles Paths checkbuildFiles Paths
noticeFiles Paths noticeFiles Paths
phonies map[string]Paths
// Used by buildTargetSingleton to create checkbuild and per-directory build targets // Used by buildTargetSingleton to create checkbuild and per-directory build targets
// Only set on the final variant of each module // Only set on the final variant of each module
@@ -1093,26 +1098,17 @@ func (m *ModuleBase) generateModuleTarget(ctx ModuleContext) {
} }
if len(allInstalledFiles) > 0 { if len(allInstalledFiles) > 0 {
name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-install") name := namespacePrefix + ctx.ModuleName() + "-install"
ctx.Build(pctx, BuildParams{ ctx.Phony(name, allInstalledFiles.Paths()...)
Rule: blueprint.Phony, m.installTarget = PathForPhony(ctx, name)
Output: name, deps = append(deps, m.installTarget)
Implicits: allInstalledFiles.Paths(),
Default: !ctx.Config().EmbeddedInMake(),
})
deps = append(deps, name)
m.installTarget = name
} }
if len(allCheckbuildFiles) > 0 { if len(allCheckbuildFiles) > 0 {
name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-checkbuild") name := namespacePrefix + ctx.ModuleName() + "-checkbuild"
ctx.Build(pctx, BuildParams{ ctx.Phony(name, allCheckbuildFiles...)
Rule: blueprint.Phony, m.checkbuildTarget = PathForPhony(ctx, name)
Output: name, deps = append(deps, m.checkbuildTarget)
Implicits: allCheckbuildFiles,
})
deps = append(deps, name)
m.checkbuildTarget = name
} }
if len(deps) > 0 { if len(deps) > 0 {
@@ -1121,12 +1117,7 @@ func (m *ModuleBase) generateModuleTarget(ctx ModuleContext) {
suffix = "-soong" suffix = "-soong"
} }
name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+suffix) ctx.Phony(namespacePrefix+ctx.ModuleName()+suffix, deps...)
ctx.Build(pctx, BuildParams{
Rule: blueprint.Phony,
Outputs: []WritablePath{name},
Implicits: deps,
})
m.blueprintDir = ctx.ModuleDir() m.blueprintDir = ctx.ModuleDir()
} }
@@ -1313,6 +1304,9 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext)
m.checkbuildFiles = append(m.checkbuildFiles, ctx.checkbuildFiles...) m.checkbuildFiles = append(m.checkbuildFiles, ctx.checkbuildFiles...)
m.initRcPaths = PathsForModuleSrc(ctx, m.commonProperties.Init_rc) m.initRcPaths = PathsForModuleSrc(ctx, m.commonProperties.Init_rc)
m.vintfFragmentsPaths = PathsForModuleSrc(ctx, m.commonProperties.Vintf_fragments) m.vintfFragmentsPaths = PathsForModuleSrc(ctx, m.commonProperties.Vintf_fragments)
for k, v := range ctx.phonies {
m.phonies[k] = append(m.phonies[k], v...)
}
} else if ctx.Config().AllowMissingDependencies() { } else if ctx.Config().AllowMissingDependencies() {
// If the module is not enabled it will not create any build rules, nothing will call // If the module is not enabled it will not create any build rules, nothing will call
// ctx.GetMissingDependencies(), and blueprint will consider the missing dependencies to be unhandled // ctx.GetMissingDependencies(), and blueprint will consider the missing dependencies to be unhandled
@@ -1460,6 +1454,7 @@ type moduleContext struct {
installFiles InstallPaths installFiles InstallPaths
checkbuildFiles Paths checkbuildFiles Paths
module Module module Module
phonies map[string]Paths
// For tests // For tests
buildParams []BuildParams buildParams []BuildParams
@@ -1574,6 +1569,11 @@ func (m *moduleContext) Build(pctx PackageContext, params BuildParams) {
m.bp.Build(pctx.PackageContext, convertBuildParams(params)) m.bp.Build(pctx.PackageContext, convertBuildParams(params))
} }
func (m *moduleContext) Phony(name string, deps ...Path) {
addPhony(m.config, name, deps...)
}
func (m *moduleContext) GetMissingDependencies() []string { func (m *moduleContext) GetMissingDependencies() []string {
var missingDeps []string var missingDeps []string
missingDeps = append(missingDeps, m.Module().base().commonProperties.MissingDeps...) missingDeps = append(missingDeps, m.Module().base().commonProperties.MissingDeps...)
@@ -2233,9 +2233,8 @@ type buildTargetSingleton struct{}
func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) { func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
var checkbuildDeps Paths var checkbuildDeps Paths
mmTarget := func(dir string) WritablePath { mmTarget := func(dir string) string {
return PathForPhony(ctx, return "MODULES-IN-" + strings.Replace(filepath.Clean(dir), "/", "-", -1)
"MODULES-IN-"+strings.Replace(filepath.Clean(dir), "/", "-", -1))
} }
modulesInDir := make(map[string]Paths) modulesInDir := make(map[string]Paths)
@@ -2261,11 +2260,7 @@ func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
} }
// Create a top-level checkbuild target that depends on all modules // Create a top-level checkbuild target that depends on all modules
ctx.Build(pctx, BuildParams{ ctx.Phony("checkbuild"+suffix, checkbuildDeps...)
Rule: blueprint.Phony,
Output: PathForPhony(ctx, "checkbuild"+suffix),
Implicits: checkbuildDeps,
})
// Make will generate the MODULES-IN-* targets // Make will generate the MODULES-IN-* targets
if ctx.Config().EmbeddedInMake() { if ctx.Config().EmbeddedInMake() {
@@ -2289,7 +2284,7 @@ func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
for _, dir := range dirs { for _, dir := range dirs {
p := parentDir(dir) p := parentDir(dir)
if p != "." && p != "/" { if p != "." && p != "/" {
modulesInDir[p] = append(modulesInDir[p], mmTarget(dir)) modulesInDir[p] = append(modulesInDir[p], PathForPhony(ctx, mmTarget(dir)))
} }
} }
@@ -2297,14 +2292,7 @@ func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
// depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp
// files. // files.
for _, dir := range dirs { for _, dir := range dirs {
ctx.Build(pctx, BuildParams{ ctx.Phony(mmTarget(dir), modulesInDir[dir]...)
Rule: blueprint.Phony,
Output: mmTarget(dir),
Implicits: modulesInDir[dir],
// HACK: checkbuild should be an optional build, but force it
// enabled for now in standalone builds
Default: !ctx.Config().EmbeddedInMake(),
})
} }
// Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild. // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild.
@@ -2331,23 +2319,15 @@ func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
continue continue
} }
name := PathForPhony(ctx, className+"-"+os.Name) name := className + "-" + os.Name
osClass[className] = append(osClass[className], name) osClass[className] = append(osClass[className], PathForPhony(ctx, name))
ctx.Build(pctx, BuildParams{ ctx.Phony(name, deps...)
Rule: blueprint.Phony,
Output: name,
Implicits: deps,
})
} }
// Wrap those into host|host-cross|target phony rules // Wrap those into host|host-cross|target phony rules
for _, class := range SortedStringKeys(osClass) { for _, class := range SortedStringKeys(osClass) {
ctx.Build(pctx, BuildParams{ ctx.Phony(class, osClass[class]...)
Rule: blueprint.Phony,
Output: PathForPhony(ctx, class),
Implicits: osClass[class],
})
} }
} }

View File

@@ -405,7 +405,7 @@ func expandOneSrcPath(ctx ModuleContext, s string, expandedExcludes []string) (P
p := pathForModuleSrc(ctx, s) p := pathForModuleSrc(ctx, s)
if exists, _, err := ctx.Config().fs.Exists(p.String()); err != nil { if exists, _, err := ctx.Config().fs.Exists(p.String()); err != nil {
reportPathErrorf(ctx, "%s: %s", p, err.Error()) reportPathErrorf(ctx, "%s: %s", p, err.Error())
} else if !exists { } else if !exists && !ctx.Config().testAllowNonExistentPaths {
reportPathErrorf(ctx, "module source path %q does not exist", p) reportPathErrorf(ctx, "module source path %q does not exist", p)
} }
@@ -798,7 +798,7 @@ func PathForSource(ctx PathContext, pathComponents ...string) SourcePath {
} }
} else if exists, _, err := ctx.Config().fs.Exists(path.String()); err != nil { } else if exists, _, err := ctx.Config().fs.Exists(path.String()); err != nil {
reportPathErrorf(ctx, "%s: %s", path, err.Error()) reportPathErrorf(ctx, "%s: %s", path, err.Error())
} else if !exists { } else if !exists && !ctx.Config().testAllowNonExistentPaths {
reportPathErrorf(ctx, "source path %q does not exist", path) reportPathErrorf(ctx, "source path %q does not exist", path)
} }
return path return path

75
android/phony.go Normal file
View File

@@ -0,0 +1,75 @@
// Copyright 2020 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package android
import (
"sync"
"github.com/google/blueprint"
)
var phonyMapOnceKey = NewOnceKey("phony")
type phonyMap map[string]Paths
var phonyMapLock sync.Mutex
func getPhonyMap(config Config) phonyMap {
return config.Once(phonyMapOnceKey, func() interface{} {
return make(phonyMap)
}).(phonyMap)
}
func addPhony(config Config, name string, deps ...Path) {
phonyMap := getPhonyMap(config)
phonyMapLock.Lock()
defer phonyMapLock.Unlock()
phonyMap[name] = append(phonyMap[name], deps...)
}
type phonySingleton struct {
phonyMap phonyMap
phonyList []string
}
var _ SingletonMakeVarsProvider = (*phonySingleton)(nil)
func (p *phonySingleton) GenerateBuildActions(ctx SingletonContext) {
p.phonyMap = getPhonyMap(ctx.Config())
p.phonyList = SortedStringKeys(p.phonyMap)
for _, phony := range p.phonyList {
p.phonyMap[phony] = SortedUniquePaths(p.phonyMap[phony])
}
if !ctx.Config().EmbeddedInMake() {
for _, phony := range p.phonyList {
ctx.Build(pctx, BuildParams{
Rule: blueprint.Phony,
Outputs: []WritablePath{PathForPhony(ctx, phony)},
Implicits: p.phonyMap[phony],
})
}
}
}
func (p phonySingleton) MakeVars(ctx MakeVarsContext) {
for _, phony := range p.phonyList {
ctx.Phony(phony, p.phonyMap[phony]...)
}
}
func phonySingletonFactory() Singleton {
return &phonySingleton{}
}

View File

@@ -104,6 +104,9 @@ func (ctx *Context) Register() {
registerMutators(ctx.Context, preArch, preDeps, postDeps, finalDeps) registerMutators(ctx.Context, preArch, preDeps, postDeps, finalDeps)
// Register phony just before makevars so it can write out its phony rules as Make rules
ctx.RegisterSingletonType("phony", SingletonFactoryAdaptor(phonySingletonFactory))
// Register makevars after other singletons so they can export values through makevars // Register makevars after other singletons so they can export values through makevars
ctx.RegisterSingletonType("makevars", SingletonFactoryAdaptor(makeVarsSingletonFunc)) ctx.RegisterSingletonType("makevars", SingletonFactoryAdaptor(makeVarsSingletonFunc))

View File

@@ -36,6 +36,12 @@ type SingletonContext interface {
Variable(pctx PackageContext, name, value string) Variable(pctx PackageContext, name, value string)
Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule
Build(pctx PackageContext, params BuildParams) Build(pctx PackageContext, params BuildParams)
// Phony creates a Make-style phony rule, a rule with no commands that can depend on other
// phony rules or real files. Phony can be called on the same name multiple times to add
// additional dependencies.
Phony(name string, deps ...Path)
RequireNinjaVersion(major, minor, micro int) RequireNinjaVersion(major, minor, micro int)
// SetNinjaBuildDir sets the value of the top-level "builddir" Ninja variable // SetNinjaBuildDir sets the value of the top-level "builddir" Ninja variable
@@ -156,6 +162,10 @@ func (s *singletonContextAdaptor) Build(pctx PackageContext, params BuildParams)
} }
func (s *singletonContextAdaptor) Phony(name string, deps ...Path) {
addPhony(s.Config(), name, deps...)
}
func (s *singletonContextAdaptor) SetNinjaBuildDir(pctx PackageContext, value string) { func (s *singletonContextAdaptor) SetNinjaBuildDir(pctx PackageContext, value string) {
s.SingletonContext.SetNinjaBuildDir(pctx.PackageContext, value) s.SingletonContext.SetNinjaBuildDir(pctx.PackageContext, value)
} }

View File

@@ -69,9 +69,5 @@ func (c *docsSingleton) GenerateBuildActions(ctx SingletonContext) {
}) })
// Add a phony target for building the documentation // Add a phony target for building the documentation
ctx.Build(pctx, BuildParams{ ctx.Phony("soong_docs", docsFile)
Rule: blueprint.Phony,
Output: PathForPhony(ctx, "soong_docs"),
Input: docsFile,
})
} }

View File

@@ -3223,12 +3223,7 @@ func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonCo
}) })
// TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
if len(xrefTargets) > 0 { if len(xrefTargets) > 0 {
ctx.Build(pctx, android.BuildParams{ ctx.Phony("xref_cxx", xrefTargets...)
Rule: blueprint.Phony,
Output: android.PathForPhony(ctx, "xref_cxx"),
Inputs: xrefTargets,
//Default: true,
})
} }
} }

View File

@@ -467,15 +467,6 @@ func GatherRequiredDepsForTest(oses ...android.OsType) string {
} }
func GatherRequiredFilesForTest(fs map[string][]byte) { func GatherRequiredFilesForTest(fs map[string][]byte) {
fs["prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libc++_shared.so"] = nil
fs["prebuilts/ndk/current/platforms/android-27/arch-arm/usr/lib/crtbegin_so.o"] = nil
fs["prebuilts/ndk/current/platforms/android-27/arch-arm/usr/lib/crtend_so.o"] = nil
fs["prebuilts/ndk/current/platforms/android-27/arch-arm64/usr/lib/crtbegin_so.o"] = nil
fs["prebuilts/ndk/current/platforms/android-27/arch-arm64/usr/lib/crtend_so.o"] = nil
fs["prebuilts/ndk/current/platforms/android-27/arch-x86/usr/lib/crtbegin_so.o"] = nil
fs["prebuilts/ndk/current/platforms/android-27/arch-x86/usr/lib/crtend_so.o"] = nil
fs["prebuilts/ndk/current/platforms/android-27/arch-x86_64/usr/lib64/crtbegin_so.o"] = nil
fs["prebuilts/ndk/current/platforms/android-27/arch-x86_64/usr/lib64/crtend_so.o"] = nil
} }
func TestConfig(buildDir string, os android.OsType, env map[string]string, func TestConfig(buildDir string, os android.OsType, env map[string]string,
@@ -484,20 +475,7 @@ func TestConfig(buildDir string, os android.OsType, env map[string]string,
// add some modules that are required by the compiler and/or linker // add some modules that are required by the compiler and/or linker
bp = bp + GatherRequiredDepsForTest(os) bp = bp + GatherRequiredDepsForTest(os)
mockFS := map[string][]byte{ mockFS := map[string][]byte{}
"foo.c": nil,
"foo.lds": nil,
"bar.c": nil,
"baz.c": nil,
"baz.o": nil,
"a.proto": nil,
"b.aidl": nil,
"sub/c.aidl": nil,
"my_include": nil,
"foo.map.txt": nil,
"liba.so": nil,
"libb.a": nil,
}
GatherRequiredFilesForTest(mockFS) GatherRequiredFilesForTest(mockFS)

View File

@@ -2657,7 +2657,7 @@ func TestCodelessApp(t *testing.T) {
} }
func TestEmbedNotice(t *testing.T) { func TestEmbedNotice(t *testing.T) {
ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+` ctx, _ := testJavaWithFS(t, cc.GatherRequiredDepsForTest(android.Android)+`
android_app { android_app {
name: "foo", name: "foo",
srcs: ["a.java"], srcs: ["a.java"],
@@ -2713,7 +2713,12 @@ func TestEmbedNotice(t *testing.T) {
srcs: ["b.java"], srcs: ["b.java"],
notice: "TOOL_NOTICE", notice: "TOOL_NOTICE",
} }
`) `, map[string][]byte{
"APP_NOTICE": nil,
"GENRULE_NOTICE": nil,
"LIB_NOTICE": nil,
"TOOL_NOTICE": nil,
})
// foo has NOTICE files to process, and embed_notices is true. // foo has NOTICE files to process, and embed_notices is true.
foo := ctx.ModuleForTests("foo", "android_common") foo := ctx.ModuleForTests("foo", "android_common")

View File

@@ -1470,7 +1470,7 @@ func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersi
FlagWithInput("@", srcJarList). FlagWithInput("@", srcJarList).
FlagWithOutput("--strict-input-files:warn ", android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"violations.txt")) FlagWithOutput("--strict-input-files:warn ", android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"violations.txt"))
if implicitsRsp.String() != "" { if implicitsRsp != nil {
cmd.FlagWithArg("--strict-input-files-exempt ", "@"+implicitsRsp.String()) cmd.FlagWithArg("--strict-input-files-exempt ", "@"+implicitsRsp.String())
} }

View File

@@ -2874,11 +2874,7 @@ func (ks *kytheExtractJavaSingleton) GenerateBuildActions(ctx android.SingletonC
}) })
// TODO(asmundak): perhaps emit a rule to output a warning if there were no xrefTargets // TODO(asmundak): perhaps emit a rule to output a warning if there were no xrefTargets
if len(xrefTargets) > 0 { if len(xrefTargets) > 0 {
ctx.Build(pctx, android.BuildParams{ ctx.Phony("xref_java", xrefTargets...)
Rule: blueprint.Phony,
Output: android.PathForPhony(ctx, "xref_java"),
Inputs: xrefTargets,
})
} }
} }

View File

@@ -142,9 +142,14 @@ func testJavaErrorWithConfig(t *testing.T, pattern string, config android.Config
return ctx, config return ctx, config
} }
func testJavaWithFS(t *testing.T, bp string, fs map[string][]byte) (*android.TestContext, android.Config) {
t.Helper()
return testJavaWithConfig(t, testConfig(nil, bp, fs))
}
func testJava(t *testing.T, bp string) (*android.TestContext, android.Config) { func testJava(t *testing.T, bp string) (*android.TestContext, android.Config) {
t.Helper() t.Helper()
return testJavaWithConfig(t, testConfig(nil, bp, nil)) return testJavaWithFS(t, bp, nil)
} }
func testJavaWithConfig(t *testing.T, config android.Config) (*android.TestContext, android.Config) { func testJavaWithConfig(t *testing.T, config android.Config) (*android.TestContext, android.Config) {
@@ -740,7 +745,7 @@ func TestResources(t *testing.T) {
for _, test := range table { for _, test := range table {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
ctx, _ := testJava(t, ` ctx, _ := testJavaWithFS(t, `
java_library { java_library {
name: "foo", name: "foo",
srcs: [ srcs: [
@@ -750,7 +755,13 @@ func TestResources(t *testing.T) {
], ],
`+test.prop+`, `+test.prop+`,
} }
`+test.extra) `+test.extra,
map[string][]byte{
"java-res/a/a": nil,
"java-res/b/b": nil,
"java-res2/a": nil,
},
)
foo := ctx.ModuleForTests("foo", "android_common").Output("withres/foo.jar") foo := ctx.ModuleForTests("foo", "android_common").Output("withres/foo.jar")
fooRes := ctx.ModuleForTests("foo", "android_common").Output("res/foo.jar") fooRes := ctx.ModuleForTests("foo", "android_common").Output("res/foo.jar")
@@ -769,7 +780,7 @@ func TestResources(t *testing.T) {
} }
func TestIncludeSrcs(t *testing.T) { func TestIncludeSrcs(t *testing.T) {
ctx, _ := testJava(t, ` ctx, _ := testJavaWithFS(t, `
java_library { java_library {
name: "foo", name: "foo",
srcs: [ srcs: [
@@ -790,7 +801,11 @@ func TestIncludeSrcs(t *testing.T) {
java_resource_dirs: ["java-res"], java_resource_dirs: ["java-res"],
include_srcs: true, include_srcs: true,
} }
`) `, map[string][]byte{
"java-res/a/a": nil,
"java-res/b/b": nil,
"java-res2/a": nil,
})
// Test a library with include_srcs: true // Test a library with include_srcs: true
foo := ctx.ModuleForTests("foo", "android_common").Output("withres/foo.jar") foo := ctx.ModuleForTests("foo", "android_common").Output("withres/foo.jar")
@@ -832,7 +847,7 @@ func TestIncludeSrcs(t *testing.T) {
} }
func TestGeneratedSources(t *testing.T) { func TestGeneratedSources(t *testing.T) {
ctx, _ := testJava(t, ` ctx, _ := testJavaWithFS(t, `
java_library { java_library {
name: "foo", name: "foo",
srcs: [ srcs: [
@@ -847,7 +862,10 @@ func TestGeneratedSources(t *testing.T) {
tool_files: ["java-res/a"], tool_files: ["java-res/a"],
out: ["gen.java"], out: ["gen.java"],
} }
`) `, map[string][]byte{
"a.java": nil,
"b.java": nil,
})
javac := ctx.ModuleForTests("foo", "android_common").Rule("javac") javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
genrule := ctx.ModuleForTests("gen", "").Rule("generator") genrule := ctx.ModuleForTests("gen", "").Rule("generator")
@@ -932,7 +950,7 @@ func TestSharding(t *testing.T) {
} }
func TestDroiddoc(t *testing.T) { func TestDroiddoc(t *testing.T) {
ctx, _ := testJava(t, ` ctx, _ := testJavaWithFS(t, `
droiddoc_exported_dir { droiddoc_exported_dir {
name: "droiddoc-templates-sdk", name: "droiddoc-templates-sdk",
path: ".", path: ".",
@@ -945,7 +963,7 @@ func TestDroiddoc(t *testing.T) {
droiddoc { droiddoc {
name: "bar-doc", name: "bar-doc",
srcs: [ srcs: [
"bar-doc/*.java", "bar-doc/a.java",
"bar-doc/IFoo.aidl", "bar-doc/IFoo.aidl",
":bar-doc-aidl-srcs", ":bar-doc-aidl-srcs",
], ],
@@ -963,7 +981,11 @@ func TestDroiddoc(t *testing.T) {
todo_file: "libcore-docs-todo.html", todo_file: "libcore-docs-todo.html",
args: "-offlinemode -title \"libcore\"", args: "-offlinemode -title \"libcore\"",
} }
`) `,
map[string][]byte{
"bar-doc/a.java": nil,
"bar-doc/b.java": nil,
})
barDoc := ctx.ModuleForTests("bar-doc", "android_common").Rule("javadoc") barDoc := ctx.ModuleForTests("bar-doc", "android_common").Rule("javadoc")
var javaSrcs []string var javaSrcs []string
@@ -989,7 +1011,7 @@ func TestDroidstubsWithSystemModules(t *testing.T) {
droidstubs { droidstubs {
name: "stubs-source-system-modules", name: "stubs-source-system-modules",
srcs: [ srcs: [
"bar-doc/*.java", "bar-doc/a.java",
], ],
sdk_version: "none", sdk_version: "none",
system_modules: "source-system-modules", system_modules: "source-system-modules",
@@ -1010,7 +1032,7 @@ func TestDroidstubsWithSystemModules(t *testing.T) {
droidstubs { droidstubs {
name: "stubs-prebuilt-system-modules", name: "stubs-prebuilt-system-modules",
srcs: [ srcs: [
"bar-doc/*.java", "bar-doc/a.java",
], ],
sdk_version: "none", sdk_version: "none",
system_modules: "prebuilt-system-modules", system_modules: "prebuilt-system-modules",

View File

@@ -25,35 +25,12 @@ func TestConfig(buildDir string, env map[string]string, bp string, fs map[string
bp += GatherRequiredDepsForTest() bp += GatherRequiredDepsForTest()
mockFS := map[string][]byte{ mockFS := map[string][]byte{
"a.java": nil,
"b.java": nil,
"c.java": nil,
"b.kt": nil,
"a.jar": nil,
"b.jar": nil,
"c.jar": nil,
"APP_NOTICE": nil,
"GENRULE_NOTICE": nil,
"LIB_NOTICE": nil,
"TOOL_NOTICE": nil,
"AndroidTest.xml": nil,
"java-res/a/a": nil,
"java-res/b/b": nil,
"java-res2/a": nil,
"java-fg/a.java": nil,
"java-fg/b.java": nil,
"java-fg/c.java": nil,
"api/current.txt": nil, "api/current.txt": nil,
"api/removed.txt": nil, "api/removed.txt": nil,
"api/system-current.txt": nil, "api/system-current.txt": nil,
"api/system-removed.txt": nil, "api/system-removed.txt": nil,
"api/test-current.txt": nil, "api/test-current.txt": nil,
"api/test-removed.txt": nil, "api/test-removed.txt": nil,
"framework/aidl/a.aidl": nil,
"aidl/foo/IFoo.aidl": nil,
"aidl/bar/IBar.aidl": nil,
"assets_a/a": nil,
"assets_b/b": nil,
"prebuilts/sdk/14/public/android.jar": nil, "prebuilts/sdk/14/public/android.jar": nil,
"prebuilts/sdk/14/public/framework.aidl": nil, "prebuilts/sdk/14/public/framework.aidl": nil,
@@ -103,45 +80,6 @@ func TestConfig(buildDir string, env map[string]string, bp string, fs map[string
"prebuilts/sdk/30/test/api/bar-removed.txt": nil, "prebuilts/sdk/30/test/api/bar-removed.txt": nil,
"prebuilts/sdk/tools/core-lambda-stubs.jar": nil, "prebuilts/sdk/tools/core-lambda-stubs.jar": nil,
"prebuilts/sdk/Android.bp": []byte(`prebuilt_apis { name: "sdk", api_dirs: ["14", "28", "30", "current"],}`), "prebuilts/sdk/Android.bp": []byte(`prebuilt_apis { name: "sdk", api_dirs: ["14", "28", "30", "current"],}`),
"prebuilts/apk/app.apk": nil,
"prebuilts/apk/app_arm.apk": nil,
"prebuilts/apk/app_arm64.apk": nil,
"prebuilts/apk/app_xhdpi.apk": nil,
"prebuilts/apk/app_xxhdpi.apk": nil,
"prebuilts/apks/app.apks": nil,
// For framework-res, which is an implicit dependency for framework
"AndroidManifest.xml": nil,
"build/make/target/product/security/testkey": nil,
"build/soong/scripts/jar-wrapper.sh": nil,
"build/make/core/verify_uses_libraries.sh": nil,
"build/make/core/proguard.flags": nil,
"build/make/core/proguard_basic_keeps.flags": nil,
"jdk8/jre/lib/jce.jar": nil,
"jdk8/jre/lib/rt.jar": nil,
"jdk8/lib/tools.jar": nil,
"bar-doc/a.java": nil,
"bar-doc/b.java": nil,
"bar-doc/IFoo.aidl": nil,
"bar-doc/IBar.aidl": nil,
"bar-doc/known_oj_tags.txt": nil,
"external/doclava/templates-sdk": nil,
"cert/new_cert.x509.pem": nil,
"cert/new_cert.pk8": nil,
"lineage.bin": nil,
"testdata/data": nil,
"stubs-sources/foo/Foo.java": nil,
"stubs/sources/foo/Foo.java": nil,
} }
cc.GatherRequiredFilesForTest(mockFS) cc.GatherRequiredFilesForTest(mockFS)