2015-01-31 02:27:36 +01:00
|
|
|
// Copyright 2015 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.
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
package android
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
import (
|
2015-07-15 03:55:36 +02:00
|
|
|
"fmt"
|
2020-01-11 02:11:46 +01:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2015-06-17 01:38:10 +02:00
|
|
|
"path/filepath"
|
2015-09-24 00:26:20 +02:00
|
|
|
"reflect"
|
2021-07-30 22:25:42 +02:00
|
|
|
"regexp"
|
2017-11-03 23:20:35 +01:00
|
|
|
"sort"
|
2015-09-24 00:26:20 +02:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/google/blueprint"
|
2021-05-03 22:35:32 +02:00
|
|
|
"github.com/google/blueprint/bootstrap"
|
2015-09-24 00:26:20 +02:00
|
|
|
"github.com/google/blueprint/pathtools"
|
2015-01-31 02:27:36 +01:00
|
|
|
)
|
|
|
|
|
2020-01-11 02:11:46 +01:00
|
|
|
var absSrcDir string
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
// PathContext is the subset of a (Module|Singleton)Context required by the
|
|
|
|
// Path methods.
|
|
|
|
type PathContext interface {
|
2017-11-29 09:27:14 +01:00
|
|
|
Config() Config
|
2015-12-19 00:11:17 +01:00
|
|
|
AddNinjaFileDeps(deps ...string)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-11-01 19:10:25 +01:00
|
|
|
type PathGlobContext interface {
|
|
|
|
GlobWithDeps(globPattern string, excludes []string) ([]string, error)
|
|
|
|
}
|
|
|
|
|
2017-11-29 09:27:14 +01:00
|
|
|
var _ PathContext = SingletonContext(nil)
|
|
|
|
var _ PathContext = ModuleContext(nil)
|
2015-09-24 00:26:20 +02:00
|
|
|
|
2020-05-11 19:06:15 +02:00
|
|
|
// "Null" path context is a minimal path context for a given config.
|
|
|
|
type NullPathContext struct {
|
|
|
|
config Config
|
|
|
|
}
|
|
|
|
|
|
|
|
func (NullPathContext) AddNinjaFileDeps(...string) {}
|
|
|
|
func (ctx NullPathContext) Config() Config { return ctx.config }
|
|
|
|
|
2020-11-10 19:50:34 +01:00
|
|
|
// EarlyModulePathContext is a subset of EarlyModuleContext methods required by the
|
|
|
|
// Path methods. These path methods can be called before any mutators have run.
|
|
|
|
type EarlyModulePathContext interface {
|
|
|
|
PathContext
|
|
|
|
PathGlobContext
|
|
|
|
|
|
|
|
ModuleDir() string
|
|
|
|
ModuleErrorf(fmt string, args ...interface{})
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ EarlyModulePathContext = ModuleContext(nil)
|
|
|
|
|
|
|
|
// Glob globs files and directories matching globPattern relative to ModuleDir(),
|
|
|
|
// paths in the excludes parameter will be omitted.
|
|
|
|
func Glob(ctx EarlyModulePathContext, globPattern string, excludes []string) Paths {
|
|
|
|
ret, err := ctx.GlobWithDeps(globPattern, excludes)
|
|
|
|
if err != nil {
|
|
|
|
ctx.ModuleErrorf("glob: %s", err.Error())
|
|
|
|
}
|
|
|
|
return pathsForModuleSrcFromFullPath(ctx, ret, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GlobFiles globs *only* files (not directories) matching globPattern relative to ModuleDir().
|
|
|
|
// Paths in the excludes parameter will be omitted.
|
|
|
|
func GlobFiles(ctx EarlyModulePathContext, globPattern string, excludes []string) Paths {
|
|
|
|
ret, err := ctx.GlobWithDeps(globPattern, excludes)
|
|
|
|
if err != nil {
|
|
|
|
ctx.ModuleErrorf("glob: %s", err.Error())
|
|
|
|
}
|
|
|
|
return pathsForModuleSrcFromFullPath(ctx, ret, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ModuleWithDepsPathContext is a subset of *ModuleContext methods required by
|
|
|
|
// the Path methods that rely on module dependencies having been resolved.
|
|
|
|
type ModuleWithDepsPathContext interface {
|
|
|
|
EarlyModulePathContext
|
2021-07-09 18:10:35 +02:00
|
|
|
VisitDirectDepsBlueprint(visit func(blueprint.Module))
|
|
|
|
OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag
|
2020-11-10 19:50:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ModuleMissingDepsPathContext is a subset of *ModuleContext methods required by
|
|
|
|
// the Path methods that rely on module dependencies having been resolved and ability to report
|
|
|
|
// missing dependency errors.
|
|
|
|
type ModuleMissingDepsPathContext interface {
|
|
|
|
ModuleWithDepsPathContext
|
|
|
|
AddMissingDependencies(missingDeps []string)
|
|
|
|
}
|
|
|
|
|
2017-07-07 01:59:48 +02:00
|
|
|
type ModuleInstallPathContext interface {
|
2019-06-06 23:33:29 +02:00
|
|
|
BaseModuleContext
|
2017-07-07 01:59:48 +02:00
|
|
|
|
|
|
|
InstallInData() bool
|
2019-09-11 19:25:18 +02:00
|
|
|
InstallInTestcases() bool
|
2017-07-07 01:59:48 +02:00
|
|
|
InstallInSanitizerDir() bool
|
2020-01-22 00:53:22 +01:00
|
|
|
InstallInRamdisk() bool
|
2020-10-22 00:17:56 +02:00
|
|
|
InstallInVendorRamdisk() bool
|
2021-04-08 14:13:22 +02:00
|
|
|
InstallInDebugRamdisk() bool
|
2018-01-31 16:54:12 +01:00
|
|
|
InstallInRecovery() bool
|
2019-10-02 20:10:58 +02:00
|
|
|
InstallInRoot() bool
|
2020-09-01 05:37:45 +02:00
|
|
|
InstallForceOS() (*OsType, *ArchType)
|
2017-07-07 01:59:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ ModuleInstallPathContext = ModuleContext(nil)
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
// errorfContext is the interface containing the Errorf method matching the
|
|
|
|
// Errorf method in blueprint.SingletonContext.
|
|
|
|
type errorfContext interface {
|
|
|
|
Errorf(format string, args ...interface{})
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
var _ errorfContext = blueprint.SingletonContext(nil)
|
|
|
|
|
|
|
|
// moduleErrorf is the interface containing the ModuleErrorf method matching
|
|
|
|
// the ModuleErrorf method in blueprint.ModuleContext.
|
|
|
|
type moduleErrorf interface {
|
|
|
|
ModuleErrorf(format string, args ...interface{})
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ moduleErrorf = blueprint.ModuleContext(nil)
|
|
|
|
|
|
|
|
// reportPathError will register an error with the attached context. It
|
|
|
|
// attempts ctx.ModuleErrorf for a better error message first, then falls
|
|
|
|
// back to ctx.Errorf.
|
2018-02-22 22:54:26 +01:00
|
|
|
func reportPathError(ctx PathContext, err error) {
|
2020-08-25 13:45:15 +02:00
|
|
|
ReportPathErrorf(ctx, "%s", err.Error())
|
2018-02-22 22:54:26 +01:00
|
|
|
}
|
|
|
|
|
2020-08-25 13:45:15 +02:00
|
|
|
// ReportPathErrorf will register an error with the attached context. It
|
2018-02-22 22:54:26 +01:00
|
|
|
// attempts ctx.ModuleErrorf for a better error message first, then falls
|
|
|
|
// back to ctx.Errorf.
|
2020-08-25 13:45:15 +02:00
|
|
|
func ReportPathErrorf(ctx PathContext, format string, args ...interface{}) {
|
2015-09-24 00:26:20 +02:00
|
|
|
if mctx, ok := ctx.(moduleErrorf); ok {
|
|
|
|
mctx.ModuleErrorf(format, args...)
|
|
|
|
} else if ectx, ok := ctx.(errorfContext); ok {
|
|
|
|
ectx.Errorf(format, args...)
|
|
|
|
} else {
|
|
|
|
panic(fmt.Sprintf(format, args...))
|
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2019-08-06 22:59:50 +02:00
|
|
|
func pathContextName(ctx PathContext, module blueprint.Module) string {
|
|
|
|
if x, ok := ctx.(interface{ ModuleName(blueprint.Module) string }); ok {
|
|
|
|
return x.ModuleName(module)
|
|
|
|
} else if x, ok := ctx.(interface{ OtherModuleName(blueprint.Module) string }); ok {
|
|
|
|
return x.OtherModuleName(module)
|
|
|
|
}
|
|
|
|
return "unknown"
|
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
type Path interface {
|
|
|
|
// Returns the path in string form
|
|
|
|
String() string
|
|
|
|
|
2016-10-26 19:05:25 +02:00
|
|
|
// Ext returns the extension of the last element of the path
|
2015-09-24 00:26:20 +02:00
|
|
|
Ext() string
|
2016-10-26 19:05:25 +02:00
|
|
|
|
|
|
|
// Base returns the last element of the path
|
|
|
|
Base() string
|
2017-02-01 23:12:44 +01:00
|
|
|
|
|
|
|
// Rel returns the portion of the path relative to the directory it was created from. For
|
|
|
|
// example, Rel on a PathsForModuleSrc would return the path relative to the module source
|
2017-12-06 00:36:55 +01:00
|
|
|
// directory, and OutputPath.Join("foo").Rel() would return "foo".
|
2017-02-01 23:12:44 +01:00
|
|
|
Rel() string
|
2021-03-24 11:18:18 +01:00
|
|
|
|
|
|
|
// RelativeToTop returns a new path relative to the top, it is provided solely for use in tests.
|
|
|
|
//
|
|
|
|
// It is guaranteed to always return the same type as it is called on, e.g. if called on an
|
|
|
|
// InstallPath then the returned value can be converted to an InstallPath.
|
|
|
|
//
|
|
|
|
// A standard build has the following structure:
|
|
|
|
// ../top/
|
|
|
|
// out/ - make install files go here.
|
2021-08-26 15:07:24 +02:00
|
|
|
// out/soong - this is the soongOutDir passed to NewTestConfig()
|
2021-03-24 11:18:18 +01:00
|
|
|
// ... - the source files
|
|
|
|
//
|
|
|
|
// This function converts a path so that it appears relative to the ../top/ directory, i.e.
|
2021-08-26 15:07:24 +02:00
|
|
|
// * Make install paths, which have the pattern "soongOutDir/../<path>" are converted into the top
|
2021-03-24 11:18:18 +01:00
|
|
|
// relative path "out/<path>"
|
2021-08-26 15:07:24 +02:00
|
|
|
// * Soong install paths and other writable paths, which have the pattern "soongOutDir/<path>" are
|
2021-03-24 11:18:18 +01:00
|
|
|
// converted into the top relative path "out/soong/<path>".
|
|
|
|
// * Source paths are already relative to the top.
|
|
|
|
// * Phony paths are not relative to anything.
|
|
|
|
// * toolDepPath have an absolute but known value in so don't need making relative to anything in
|
|
|
|
// order to test.
|
|
|
|
RelativeToTop() Path
|
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
|
|
|
OutDir = "out"
|
|
|
|
OutSoongDir = OutDir + "/soong"
|
|
|
|
)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
// WritablePath is a type of path that can be used as an output for build rules.
|
|
|
|
type WritablePath interface {
|
|
|
|
Path
|
|
|
|
|
2019-12-10 14:41:51 +01:00
|
|
|
// return the path to the build directory.
|
2021-08-26 15:07:24 +02:00
|
|
|
getSoongOutDir() string
|
2019-12-10 14:41:51 +01:00
|
|
|
|
2017-04-11 00:47:24 +02:00
|
|
|
// the writablePath method doesn't directly do anything,
|
|
|
|
// but it allows a struct to distinguish between whether or not it implements the WritablePath interface
|
2015-09-24 00:26:20 +02:00
|
|
|
writablePath()
|
2020-11-27 12:37:28 +01:00
|
|
|
|
|
|
|
ReplaceExtension(ctx PathContext, ext string) OutputPath
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
type genPathProvider interface {
|
2020-11-10 19:50:34 +01:00
|
|
|
genPathWithExt(ctx ModuleOutPathContext, subdir, ext string) ModuleGenPath
|
2015-09-24 00:26:20 +02:00
|
|
|
}
|
|
|
|
type objPathProvider interface {
|
2020-11-10 19:50:34 +01:00
|
|
|
objPathWithExt(ctx ModuleOutPathContext, subdir, ext string) ModuleObjPath
|
2015-09-24 00:26:20 +02:00
|
|
|
}
|
|
|
|
type resPathProvider interface {
|
2020-11-10 19:50:34 +01:00
|
|
|
resPathWithName(ctx ModuleOutPathContext, name string) ModuleResPath
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
// GenPathWithExt derives a new file path in ctx's generated sources directory
|
|
|
|
// from the current path, but with the new extension.
|
2020-11-10 19:50:34 +01:00
|
|
|
func GenPathWithExt(ctx ModuleOutPathContext, subdir string, p Path, ext string) ModuleGenPath {
|
2015-09-24 00:26:20 +02:00
|
|
|
if path, ok := p.(genPathProvider); ok {
|
2016-11-03 04:43:13 +01:00
|
|
|
return path.genPathWithExt(ctx, subdir, ext)
|
2015-09-24 00:26:20 +02:00
|
|
|
}
|
2020-08-25 13:45:15 +02:00
|
|
|
ReportPathErrorf(ctx, "Tried to create generated file from unsupported path: %s(%s)", reflect.TypeOf(p).Name(), p)
|
2015-09-24 00:26:20 +02:00
|
|
|
return PathForModuleGen(ctx)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
// ObjPathWithExt derives a new file path in ctx's object directory from the
|
|
|
|
// current path, but with the new extension.
|
2020-11-10 19:50:34 +01:00
|
|
|
func ObjPathWithExt(ctx ModuleOutPathContext, subdir string, p Path, ext string) ModuleObjPath {
|
2015-09-24 00:26:20 +02:00
|
|
|
if path, ok := p.(objPathProvider); ok {
|
|
|
|
return path.objPathWithExt(ctx, subdir, ext)
|
|
|
|
}
|
2020-08-25 13:45:15 +02:00
|
|
|
ReportPathErrorf(ctx, "Tried to create object file from unsupported path: %s (%s)", reflect.TypeOf(p).Name(), p)
|
2015-09-24 00:26:20 +02:00
|
|
|
return PathForModuleObj(ctx)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
// ResPathWithName derives a new path in ctx's output resource directory, using
|
|
|
|
// the current path to create the directory name, and the `name` argument for
|
|
|
|
// the filename.
|
2020-11-10 19:50:34 +01:00
|
|
|
func ResPathWithName(ctx ModuleOutPathContext, p Path, name string) ModuleResPath {
|
2015-09-24 00:26:20 +02:00
|
|
|
if path, ok := p.(resPathProvider); ok {
|
|
|
|
return path.resPathWithName(ctx, name)
|
|
|
|
}
|
2020-08-25 13:45:15 +02:00
|
|
|
ReportPathErrorf(ctx, "Tried to create res file from unsupported path: %s (%s)", reflect.TypeOf(p).Name(), p)
|
2015-09-24 00:26:20 +02:00
|
|
|
return PathForModuleRes(ctx)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
// OptionalPath is a container that may or may not contain a valid Path.
|
|
|
|
type OptionalPath struct {
|
2021-09-15 03:39:00 +02:00
|
|
|
path Path // nil if invalid.
|
|
|
|
invalidReason string // Not applicable if path != nil. "" if the reason is unknown.
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
2015-05-12 20:36:53 +02:00
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
// OptionalPathForPath returns an OptionalPath containing the path.
|
|
|
|
func OptionalPathForPath(path Path) OptionalPath {
|
2021-09-16 15:11:12 +02:00
|
|
|
return OptionalPath{path: path}
|
2015-09-24 00:26:20 +02:00
|
|
|
}
|
|
|
|
|
2021-09-15 03:39:00 +02:00
|
|
|
// InvalidOptionalPath returns an OptionalPath that is invalid with the given reason.
|
|
|
|
func InvalidOptionalPath(reason string) OptionalPath {
|
|
|
|
|
|
|
|
return OptionalPath{invalidReason: reason}
|
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
// Valid returns whether there is a valid path
|
|
|
|
func (p OptionalPath) Valid() bool {
|
2021-09-16 15:11:12 +02:00
|
|
|
return p.path != nil
|
2015-09-24 00:26:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Path returns the Path embedded in this OptionalPath. You must be sure that
|
|
|
|
// there is a valid path, since this method will panic if there is not.
|
|
|
|
func (p OptionalPath) Path() Path {
|
2021-09-16 15:11:12 +02:00
|
|
|
if p.path == nil {
|
2021-09-15 03:39:00 +02:00
|
|
|
msg := "Requesting an invalid path"
|
|
|
|
if p.invalidReason != "" {
|
|
|
|
msg += ": " + p.invalidReason
|
|
|
|
}
|
|
|
|
panic(msg)
|
2015-09-24 00:26:20 +02:00
|
|
|
}
|
|
|
|
return p.path
|
|
|
|
}
|
|
|
|
|
2021-09-15 03:39:00 +02:00
|
|
|
// InvalidReason returns the reason that the optional path is invalid, or "" if it is valid.
|
|
|
|
func (p OptionalPath) InvalidReason() string {
|
|
|
|
if p.path != nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
if p.invalidReason == "" {
|
|
|
|
return "unknown"
|
|
|
|
}
|
|
|
|
return p.invalidReason
|
|
|
|
}
|
|
|
|
|
2021-05-13 12:11:15 +02:00
|
|
|
// AsPaths converts the OptionalPath into Paths.
|
|
|
|
//
|
|
|
|
// It returns nil if this is not valid, or a single length slice containing the Path embedded in
|
|
|
|
// this OptionalPath.
|
|
|
|
func (p OptionalPath) AsPaths() Paths {
|
2021-09-16 15:11:12 +02:00
|
|
|
if p.path == nil {
|
2021-05-13 12:11:15 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return Paths{p.path}
|
|
|
|
}
|
|
|
|
|
2021-03-30 20:44:07 +02:00
|
|
|
// RelativeToTop returns an OptionalPath with the path that was embedded having been replaced by the
|
|
|
|
// result of calling Path.RelativeToTop on it.
|
|
|
|
func (p OptionalPath) RelativeToTop() OptionalPath {
|
2021-09-16 15:11:12 +02:00
|
|
|
if p.path == nil {
|
2021-03-29 00:57:19 +02:00
|
|
|
return p
|
|
|
|
}
|
|
|
|
p.path = p.path.RelativeToTop()
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
// String returns the string version of the Path, or "" if it isn't valid.
|
|
|
|
func (p OptionalPath) String() string {
|
2021-09-16 15:11:12 +02:00
|
|
|
if p.path != nil {
|
2015-09-24 00:26:20 +02:00
|
|
|
return p.path.String()
|
|
|
|
} else {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Paths is a slice of Path objects, with helpers to operate on the collection.
|
|
|
|
type Paths []Path
|
|
|
|
|
2021-03-24 11:18:18 +01:00
|
|
|
// RelativeToTop creates a new Paths containing the result of calling Path.RelativeToTop on each
|
|
|
|
// item in this slice.
|
|
|
|
func (p Paths) RelativeToTop() Paths {
|
|
|
|
ensureTestOnly()
|
|
|
|
if p == nil {
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
ret := make(Paths, len(p))
|
|
|
|
for i, path := range p {
|
|
|
|
ret[i] = path.RelativeToTop()
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2020-06-15 07:24:19 +02:00
|
|
|
func (paths Paths) containsPath(path Path) bool {
|
|
|
|
for _, p := range paths {
|
|
|
|
if p == path {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-02-11 15:16:14 +01:00
|
|
|
// PathsForSource returns Paths rooted from SrcDir, *not* rooted from the module's local source
|
|
|
|
// directory
|
2015-09-24 00:26:20 +02:00
|
|
|
func PathsForSource(ctx PathContext, paths []string) Paths {
|
|
|
|
ret := make(Paths, len(paths))
|
|
|
|
for i, path := range paths {
|
|
|
|
ret[i] = PathForSource(ctx, path)
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2021-02-11 15:16:14 +01:00
|
|
|
// ExistentPathsForSources returns a list of Paths rooted from SrcDir, *not* rooted from the
|
|
|
|
// module's local source directory, that are found in the tree. If any are not found, they are
|
|
|
|
// omitted from the list, and dependencies are added so that we're re-run when they are added.
|
2018-02-22 20:47:25 +01:00
|
|
|
func ExistentPathsForSources(ctx PathContext, paths []string) Paths {
|
2015-12-19 00:11:17 +01:00
|
|
|
ret := make(Paths, 0, len(paths))
|
|
|
|
for _, path := range paths {
|
2018-02-22 20:47:25 +01:00
|
|
|
p := ExistentPathForSource(ctx, path)
|
2015-12-19 00:11:17 +01:00
|
|
|
if p.Valid() {
|
|
|
|
ret = append(ret, p.Path())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2021-04-14 23:36:10 +02:00
|
|
|
// PathsForModuleSrc returns a Paths{} containing the resolved references in paths:
|
|
|
|
// * filepath, relative to local module directory, resolves as a filepath relative to the local
|
|
|
|
// source directory
|
|
|
|
// * glob, relative to the local module directory, resolves as filepath(s), relative to the local
|
|
|
|
// source directory.
|
|
|
|
// * other modules using the ":name{.tag}" syntax. These modules must implement SourceFileProducer
|
|
|
|
// or OutputFileProducer. These resolve as a filepath to an output filepath or generated source
|
|
|
|
// filepath.
|
|
|
|
// Properties passed as the paths argument must have been annotated with struct tag
|
2019-05-29 23:40:35 +02:00
|
|
|
// `android:"path"` so that dependencies on SourceFileProducer modules will have already been handled by the
|
2021-04-14 23:36:10 +02:00
|
|
|
// path_deps mutator.
|
|
|
|
// If a requested module is not found as a dependency:
|
|
|
|
// * if ctx.Config().AllowMissingDependencies() is true, this module to be marked as having
|
|
|
|
// missing dependencies
|
|
|
|
// * otherwise, a ModuleError is thrown.
|
2020-11-10 19:50:34 +01:00
|
|
|
func PathsForModuleSrc(ctx ModuleMissingDepsPathContext, paths []string) Paths {
|
2019-03-06 07:25:09 +01:00
|
|
|
return PathsForModuleSrcExcludes(ctx, paths, nil)
|
|
|
|
}
|
|
|
|
|
2022-01-28 21:13:39 +01:00
|
|
|
type SourceInput struct {
|
|
|
|
Context ModuleMissingDepsPathContext
|
|
|
|
Paths []string
|
|
|
|
ExcludePaths []string
|
|
|
|
IncludeDirs bool
|
|
|
|
}
|
|
|
|
|
2021-04-14 23:36:10 +02:00
|
|
|
// PathsForModuleSrcExcludes returns a Paths{} containing the resolved references in paths, minus
|
|
|
|
// those listed in excludes. Elements of paths and excludes are resolved as:
|
|
|
|
// * filepath, relative to local module directory, resolves as a filepath relative to the local
|
|
|
|
// source directory
|
|
|
|
// * glob, relative to the local module directory, resolves as filepath(s), relative to the local
|
|
|
|
// source directory. Not valid in excludes.
|
|
|
|
// * other modules using the ":name{.tag}" syntax. These modules must implement SourceFileProducer
|
|
|
|
// or OutputFileProducer. These resolve as a filepath to an output filepath or generated source
|
|
|
|
// filepath.
|
|
|
|
// excluding the items (similarly resolved
|
|
|
|
// Properties passed as the paths argument must have been annotated with struct tag
|
|
|
|
// `android:"path"` so that dependencies on SourceFileProducer modules will have already been handled by the
|
|
|
|
// path_deps mutator.
|
|
|
|
// If a requested module is not found as a dependency:
|
|
|
|
// * if ctx.Config().AllowMissingDependencies() is true, this module to be marked as having
|
|
|
|
// missing dependencies
|
|
|
|
// * otherwise, a ModuleError is thrown.
|
2020-11-10 19:50:34 +01:00
|
|
|
func PathsForModuleSrcExcludes(ctx ModuleMissingDepsPathContext, paths, excludes []string) Paths {
|
2022-01-28 21:13:39 +01:00
|
|
|
return PathsRelativeToModuleSourceDir(SourceInput{
|
|
|
|
Context: ctx,
|
|
|
|
Paths: paths,
|
|
|
|
ExcludePaths: excludes,
|
|
|
|
IncludeDirs: true,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func PathsRelativeToModuleSourceDir(input SourceInput) Paths {
|
|
|
|
ret, missingDeps := PathsAndMissingDepsRelativeToModuleSourceDir(input)
|
|
|
|
if input.Context.Config().AllowMissingDependencies() {
|
|
|
|
input.Context.AddMissingDependencies(missingDeps)
|
2019-03-18 20:12:48 +01:00
|
|
|
} else {
|
|
|
|
for _, m := range missingDeps {
|
2022-01-28 21:13:39 +01:00
|
|
|
input.Context.ModuleErrorf(`missing dependency on %q, is the property annotated with android:"path"?`, m)
|
2019-03-18 20:12:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2019-11-08 11:54:21 +01:00
|
|
|
// OutputPaths is a slice of OutputPath objects, with helpers to operate on the collection.
|
|
|
|
type OutputPaths []OutputPath
|
|
|
|
|
|
|
|
// Paths returns the OutputPaths as a Paths
|
|
|
|
func (p OutputPaths) Paths() Paths {
|
|
|
|
if p == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
ret := make(Paths, len(p))
|
|
|
|
for i, path := range p {
|
|
|
|
ret[i] = path
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
// Strings returns the string forms of the writable paths.
|
|
|
|
func (p OutputPaths) Strings() []string {
|
|
|
|
if p == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
ret := make([]string, len(p))
|
|
|
|
for i, path := range p {
|
|
|
|
ret[i] = path.String()
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2021-10-26 00:36:21 +02:00
|
|
|
// PathForGoBinary returns the path to the installed location of a bootstrap_go_binary module.
|
|
|
|
func PathForGoBinary(ctx PathContext, goBinary bootstrap.GoBinaryTool) Path {
|
|
|
|
goBinaryInstallDir := pathForInstall(ctx, ctx.Config().BuildOS, ctx.Config().BuildArch, "bin", false)
|
|
|
|
rel := Rel(ctx, goBinaryInstallDir.String(), goBinary.InstallPath())
|
|
|
|
return goBinaryInstallDir.Join(ctx, rel)
|
|
|
|
}
|
|
|
|
|
2020-11-10 19:50:34 +01:00
|
|
|
// Expands Paths to a SourceFileProducer or OutputFileProducer module dependency referenced via ":name" or ":name{.tag}" syntax.
|
|
|
|
// If the dependency is not found, a missingErrorDependency is returned.
|
|
|
|
// If the module dependency is not a SourceFileProducer or OutputFileProducer, appropriate errors will be returned.
|
|
|
|
func getPathsFromModuleDep(ctx ModuleWithDepsPathContext, path, moduleName, tag string) (Paths, error) {
|
Support customizing behavior around sourceOrOutputDependencyTag
Previously, modules customized behavior around the handling of
sourceOrOutputDependencyTag by comparing them to android.SourceDepTag
and retrieving the module using something like this:
ctx.GetDirectDepWithTag(m, android.SourceDepTag)
The problem with that is it does not allow an output tag to be
specified and does not handle fully qualified names properly.
This adds the following:
* IsSourceDepTag and IsSourceDepTagWithOutputTag to check whether a
blueprint.DependencyTag is a sourceOrOutputDependencyTag. The latter
also checks that it has the correct output tag.
* GetModuleFromPathDep(ctx, moduleName, outputTag) as a replacement for
ctx.GetDirectDepWithTag(m, android.SourceDepTag).
Replaces usages of:
* t == SourceDepTag with IsSourceDepTagWithOutputTag(t, "")
* ctx.GetDirectDepWithTag(m, android.SourceDepTag) with
GetModuleFromPathDep(ctx, m, "")
It also deprecates the following:
* android.SourcDepTag - as a follow up change needs to modify the
sourceOrOutputDependencyTag will make this useless.
* ExpandSources, ExpandsSources - copies existing deprecated messages
from the implementation to the interface so that they can be seen
by users of that interface.
Bug: 193228441
Test: m nothing
Change-Id: I8c397232b8d7dc1f9702c04ad45ea7819d4631ae
2021-07-09 18:38:55 +02:00
|
|
|
module := GetModuleFromPathDep(ctx, moduleName, tag)
|
2020-11-10 19:50:34 +01:00
|
|
|
if module == nil {
|
|
|
|
return nil, missingDependencyError{[]string{moduleName}}
|
|
|
|
}
|
2021-03-23 01:05:59 +01:00
|
|
|
if aModule, ok := module.(Module); ok && !aModule.Enabled() {
|
|
|
|
return nil, missingDependencyError{[]string{moduleName}}
|
|
|
|
}
|
2020-11-10 19:50:34 +01:00
|
|
|
if outProducer, ok := module.(OutputFileProducer); ok {
|
|
|
|
outputFiles, err := outProducer.OutputFiles(tag)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("path dependency %q: %s", path, err)
|
|
|
|
}
|
|
|
|
return outputFiles, nil
|
|
|
|
} else if tag != "" {
|
|
|
|
return nil, fmt.Errorf("path dependency %q is not an output file producing module", path)
|
2021-05-03 22:35:32 +02:00
|
|
|
} else if goBinary, ok := module.(bootstrap.GoBinaryTool); ok {
|
2021-10-26 00:36:21 +02:00
|
|
|
goBinaryPath := PathForGoBinary(ctx, goBinary)
|
|
|
|
return Paths{goBinaryPath}, nil
|
2020-11-10 19:50:34 +01:00
|
|
|
} else if srcProducer, ok := module.(SourceFileProducer); ok {
|
|
|
|
return srcProducer.Srcs(), nil
|
|
|
|
} else {
|
|
|
|
return nil, fmt.Errorf("path dependency %q is not a source file producing module", path)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Support customizing behavior around sourceOrOutputDependencyTag
Previously, modules customized behavior around the handling of
sourceOrOutputDependencyTag by comparing them to android.SourceDepTag
and retrieving the module using something like this:
ctx.GetDirectDepWithTag(m, android.SourceDepTag)
The problem with that is it does not allow an output tag to be
specified and does not handle fully qualified names properly.
This adds the following:
* IsSourceDepTag and IsSourceDepTagWithOutputTag to check whether a
blueprint.DependencyTag is a sourceOrOutputDependencyTag. The latter
also checks that it has the correct output tag.
* GetModuleFromPathDep(ctx, moduleName, outputTag) as a replacement for
ctx.GetDirectDepWithTag(m, android.SourceDepTag).
Replaces usages of:
* t == SourceDepTag with IsSourceDepTagWithOutputTag(t, "")
* ctx.GetDirectDepWithTag(m, android.SourceDepTag) with
GetModuleFromPathDep(ctx, m, "")
It also deprecates the following:
* android.SourcDepTag - as a follow up change needs to modify the
sourceOrOutputDependencyTag will make this useless.
* ExpandSources, ExpandsSources - copies existing deprecated messages
from the implementation to the interface so that they can be seen
by users of that interface.
Bug: 193228441
Test: m nothing
Change-Id: I8c397232b8d7dc1f9702c04ad45ea7819d4631ae
2021-07-09 18:38:55 +02:00
|
|
|
// GetModuleFromPathDep will return the module that was added as a dependency automatically for
|
|
|
|
// properties tagged with `android:"path"` or manually using ExtractSourceDeps or
|
|
|
|
// ExtractSourcesDeps.
|
|
|
|
//
|
|
|
|
// The moduleName and tag supplied to this should be the values returned from SrcIsModuleWithTag.
|
|
|
|
// Or, if no tag is expected then the moduleName should be the value returned by SrcIsModule and
|
|
|
|
// the tag must be "".
|
|
|
|
//
|
|
|
|
// If tag is "" then the returned module will be the dependency that was added for ":moduleName".
|
|
|
|
// Otherwise, it is the dependency that was added for ":moduleName{tag}".
|
|
|
|
func GetModuleFromPathDep(ctx ModuleWithDepsPathContext, moduleName, tag string) blueprint.Module {
|
2021-07-09 18:10:35 +02:00
|
|
|
var found blueprint.Module
|
|
|
|
// The sourceOrOutputDepTag uniquely identifies the module dependency as it contains both the
|
|
|
|
// module name and the tag. Dependencies added automatically for properties tagged with
|
|
|
|
// `android:"path"` are deduped so are guaranteed to be unique. It is possible for duplicate
|
|
|
|
// dependencies to be added manually using ExtractSourcesDeps or ExtractSourceDeps but even then
|
|
|
|
// it will always be the case that the dependencies will be identical, i.e. the same tag and same
|
|
|
|
// moduleName referring to the same dependency module.
|
|
|
|
//
|
|
|
|
// It does not matter whether the moduleName is a fully qualified name or if the module
|
|
|
|
// dependency is a prebuilt module. All that matters is the same information is supplied to
|
|
|
|
// create the tag here as was supplied to create the tag when the dependency was added so that
|
|
|
|
// this finds the matching dependency module.
|
|
|
|
expectedTag := sourceOrOutputDepTag(moduleName, tag)
|
|
|
|
ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
|
|
|
|
depTag := ctx.OtherModuleDependencyTag(module)
|
|
|
|
if depTag == expectedTag {
|
|
|
|
found = module
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return found
|
Support customizing behavior around sourceOrOutputDependencyTag
Previously, modules customized behavior around the handling of
sourceOrOutputDependencyTag by comparing them to android.SourceDepTag
and retrieving the module using something like this:
ctx.GetDirectDepWithTag(m, android.SourceDepTag)
The problem with that is it does not allow an output tag to be
specified and does not handle fully qualified names properly.
This adds the following:
* IsSourceDepTag and IsSourceDepTagWithOutputTag to check whether a
blueprint.DependencyTag is a sourceOrOutputDependencyTag. The latter
also checks that it has the correct output tag.
* GetModuleFromPathDep(ctx, moduleName, outputTag) as a replacement for
ctx.GetDirectDepWithTag(m, android.SourceDepTag).
Replaces usages of:
* t == SourceDepTag with IsSourceDepTagWithOutputTag(t, "")
* ctx.GetDirectDepWithTag(m, android.SourceDepTag) with
GetModuleFromPathDep(ctx, m, "")
It also deprecates the following:
* android.SourcDepTag - as a follow up change needs to modify the
sourceOrOutputDependencyTag will make this useless.
* ExpandSources, ExpandsSources - copies existing deprecated messages
from the implementation to the interface so that they can be seen
by users of that interface.
Bug: 193228441
Test: m nothing
Change-Id: I8c397232b8d7dc1f9702c04ad45ea7819d4631ae
2021-07-09 18:38:55 +02:00
|
|
|
}
|
|
|
|
|
2021-04-14 23:36:10 +02:00
|
|
|
// PathsAndMissingDepsForModuleSrcExcludes returns a Paths{} containing the resolved references in
|
|
|
|
// paths, minus those listed in excludes. Elements of paths and excludes are resolved as:
|
|
|
|
// * filepath, relative to local module directory, resolves as a filepath relative to the local
|
|
|
|
// source directory
|
|
|
|
// * glob, relative to the local module directory, resolves as filepath(s), relative to the local
|
|
|
|
// source directory. Not valid in excludes.
|
|
|
|
// * other modules using the ":name{.tag}" syntax. These modules must implement SourceFileProducer
|
|
|
|
// or OutputFileProducer. These resolve as a filepath to an output filepath or generated source
|
|
|
|
// filepath.
|
|
|
|
// and a list of the module names of missing module dependencies are returned as the second return.
|
|
|
|
// Properties passed as the paths argument must have been annotated with struct tag
|
2019-05-29 23:40:35 +02:00
|
|
|
// `android:"path"` so that dependencies on SourceFileProducer modules will have already been handled by the
|
2021-04-14 23:36:10 +02:00
|
|
|
// path_deps mutator.
|
2022-01-28 21:13:39 +01:00
|
|
|
func PathsAndMissingDepsForModuleSrcExcludes(ctx ModuleMissingDepsPathContext, paths, excludes []string) (Paths, []string) {
|
|
|
|
return PathsAndMissingDepsRelativeToModuleSourceDir(SourceInput{
|
|
|
|
Context: ctx,
|
|
|
|
Paths: paths,
|
|
|
|
ExcludePaths: excludes,
|
|
|
|
IncludeDirs: true,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func PathsAndMissingDepsRelativeToModuleSourceDir(input SourceInput) (Paths, []string) {
|
|
|
|
prefix := pathForModuleSrc(input.Context).String()
|
2019-03-06 07:25:09 +01:00
|
|
|
|
|
|
|
var expandedExcludes []string
|
2022-01-28 21:13:39 +01:00
|
|
|
if input.ExcludePaths != nil {
|
|
|
|
expandedExcludes = make([]string, 0, len(input.ExcludePaths))
|
2019-03-06 07:25:09 +01:00
|
|
|
}
|
|
|
|
|
2019-03-18 20:12:48 +01:00
|
|
|
var missingExcludeDeps []string
|
2022-01-28 21:13:39 +01:00
|
|
|
for _, e := range input.ExcludePaths {
|
2019-05-29 23:40:35 +02:00
|
|
|
if m, t := SrcIsModuleWithTag(e); m != "" {
|
2022-01-28 21:13:39 +01:00
|
|
|
modulePaths, err := getPathsFromModuleDep(input.Context, e, m, t)
|
2020-11-10 19:50:34 +01:00
|
|
|
if m, ok := err.(missingDependencyError); ok {
|
|
|
|
missingExcludeDeps = append(missingExcludeDeps, m.missingDeps...)
|
|
|
|
} else if err != nil {
|
2022-01-28 21:13:39 +01:00
|
|
|
reportPathError(input.Context, err)
|
2019-03-06 07:25:09 +01:00
|
|
|
} else {
|
2020-11-10 19:50:34 +01:00
|
|
|
expandedExcludes = append(expandedExcludes, modulePaths.Strings()...)
|
2019-03-06 07:25:09 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
expandedExcludes = append(expandedExcludes, filepath.Join(prefix, e))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-28 21:13:39 +01:00
|
|
|
if input.Paths == nil {
|
2019-03-18 20:12:48 +01:00
|
|
|
return nil, missingExcludeDeps
|
2019-03-06 07:25:09 +01:00
|
|
|
}
|
|
|
|
|
2019-03-18 20:12:48 +01:00
|
|
|
var missingDeps []string
|
|
|
|
|
2022-01-28 21:13:39 +01:00
|
|
|
expandedSrcFiles := make(Paths, 0, len(input.Paths))
|
|
|
|
for _, s := range input.Paths {
|
|
|
|
srcFiles, err := expandOneSrcPath(sourcePathInput{
|
|
|
|
context: input.Context,
|
|
|
|
path: s,
|
|
|
|
expandedExcludes: expandedExcludes,
|
|
|
|
includeDirs: input.IncludeDirs,
|
|
|
|
})
|
2019-03-06 07:25:09 +01:00
|
|
|
if depErr, ok := err.(missingDependencyError); ok {
|
2019-03-18 20:12:48 +01:00
|
|
|
missingDeps = append(missingDeps, depErr.missingDeps...)
|
2019-03-06 07:25:09 +01:00
|
|
|
} else if err != nil {
|
2022-01-28 21:13:39 +01:00
|
|
|
reportPathError(input.Context, err)
|
2019-03-06 07:25:09 +01:00
|
|
|
}
|
|
|
|
expandedSrcFiles = append(expandedSrcFiles, srcFiles...)
|
|
|
|
}
|
2019-03-18 20:12:48 +01:00
|
|
|
|
|
|
|
return expandedSrcFiles, append(missingDeps, missingExcludeDeps...)
|
2019-03-06 07:25:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type missingDependencyError struct {
|
|
|
|
missingDeps []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e missingDependencyError) Error() string {
|
|
|
|
return "missing dependencies: " + strings.Join(e.missingDeps, ", ")
|
|
|
|
}
|
|
|
|
|
2022-01-28 21:13:39 +01:00
|
|
|
type sourcePathInput struct {
|
|
|
|
context ModuleWithDepsPathContext
|
|
|
|
path string
|
|
|
|
expandedExcludes []string
|
|
|
|
includeDirs bool
|
|
|
|
}
|
|
|
|
|
2020-11-10 19:50:34 +01:00
|
|
|
// Expands one path string to Paths rooted from the module's local source
|
|
|
|
// directory, excluding those listed in the expandedExcludes.
|
|
|
|
// Expands globs, references to SourceFileProducer or OutputFileProducer modules using the ":name" and ":name{.tag}" syntax.
|
2022-01-28 21:13:39 +01:00
|
|
|
func expandOneSrcPath(input sourcePathInput) (Paths, error) {
|
2020-07-05 03:23:14 +02:00
|
|
|
excludePaths := func(paths Paths) Paths {
|
2022-01-28 21:13:39 +01:00
|
|
|
if len(input.expandedExcludes) == 0 {
|
2020-07-05 03:23:14 +02:00
|
|
|
return paths
|
|
|
|
}
|
|
|
|
remainder := make(Paths, 0, len(paths))
|
|
|
|
for _, p := range paths {
|
2022-01-28 21:13:39 +01:00
|
|
|
if !InList(p.String(), input.expandedExcludes) {
|
2020-07-05 03:23:14 +02:00
|
|
|
remainder = append(remainder, p)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return remainder
|
|
|
|
}
|
2022-01-28 21:13:39 +01:00
|
|
|
if m, t := SrcIsModuleWithTag(input.path); m != "" {
|
|
|
|
modulePaths, err := getPathsFromModuleDep(input.context, input.path, m, t)
|
2020-11-10 19:50:34 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2019-03-06 07:25:09 +01:00
|
|
|
} else {
|
2020-11-10 19:50:34 +01:00
|
|
|
return excludePaths(modulePaths), nil
|
2019-03-06 07:25:09 +01:00
|
|
|
}
|
|
|
|
} else {
|
2022-01-28 21:13:39 +01:00
|
|
|
p := pathForModuleSrc(input.context, input.path)
|
|
|
|
if pathtools.IsGlob(input.path) {
|
|
|
|
paths := GlobFiles(input.context, p.String(), input.expandedExcludes)
|
|
|
|
return PathsWithModuleSrcSubDir(input.context, paths, ""), nil
|
|
|
|
} else {
|
|
|
|
if exists, _, err := input.context.Config().fs.Exists(p.String()); err != nil {
|
|
|
|
ReportPathErrorf(input.context, "%s: %s", p, err.Error())
|
|
|
|
} else if !exists && !input.context.Config().TestAllowNonExistentPaths {
|
|
|
|
ReportPathErrorf(input.context, "module source path %q does not exist", p)
|
|
|
|
} else if !input.includeDirs {
|
|
|
|
if isDir, err := input.context.Config().fs.IsDir(p.String()); exists && err != nil {
|
|
|
|
ReportPathErrorf(input.context, "%s: %s", p, err.Error())
|
|
|
|
} else if isDir {
|
|
|
|
ReportPathErrorf(input.context, "module source path %q is a directory", p)
|
|
|
|
}
|
|
|
|
}
|
2019-03-06 07:25:09 +01:00
|
|
|
|
2022-01-28 21:13:39 +01:00
|
|
|
if InList(p.String(), input.expandedExcludes) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
return Paths{p}, nil
|
2019-03-06 07:25:09 +01:00
|
|
|
}
|
2015-09-24 00:26:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// pathsForModuleSrcFromFullPath returns Paths rooted from the module's local
|
|
|
|
// source directory, but strip the local source directory from the beginning of
|
2018-02-27 06:50:08 +01:00
|
|
|
// each string. If incDirs is false, strip paths with a trailing '/' from the list.
|
2018-09-12 19:02:13 +02:00
|
|
|
// It intended for use in globs that only list files that exist, so it allows '$' in
|
|
|
|
// filenames.
|
2020-11-10 19:50:34 +01:00
|
|
|
func pathsForModuleSrcFromFullPath(ctx EarlyModulePathContext, paths []string, incDirs bool) Paths {
|
2021-08-16 17:05:09 +02:00
|
|
|
prefix := ctx.ModuleDir() + "/"
|
2017-09-28 02:42:05 +02:00
|
|
|
if prefix == "./" {
|
|
|
|
prefix = ""
|
|
|
|
}
|
2015-09-24 00:26:20 +02:00
|
|
|
ret := make(Paths, 0, len(paths))
|
|
|
|
for _, p := range paths {
|
2018-02-27 06:50:08 +01:00
|
|
|
if !incDirs && strings.HasSuffix(p, "/") {
|
|
|
|
continue
|
|
|
|
}
|
2015-09-24 00:26:20 +02:00
|
|
|
path := filepath.Clean(p)
|
|
|
|
if !strings.HasPrefix(path, prefix) {
|
2020-08-25 13:45:15 +02:00
|
|
|
ReportPathErrorf(ctx, "Path %q is not in module source directory %q", p, prefix)
|
2015-09-24 00:26:20 +02:00
|
|
|
continue
|
2015-05-12 20:36:53 +02:00
|
|
|
}
|
2018-08-16 05:18:53 +02:00
|
|
|
|
2018-09-12 19:02:13 +02:00
|
|
|
srcPath, err := safePathForSource(ctx, ctx.ModuleDir(), path[len(prefix):])
|
2018-08-16 05:18:53 +02:00
|
|
|
if err != nil {
|
|
|
|
reportPathError(ctx, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2019-03-05 21:46:40 +01:00
|
|
|
srcPath.basePath.rel = srcPath.path
|
2018-08-16 05:18:53 +02:00
|
|
|
|
2019-03-05 21:46:40 +01:00
|
|
|
ret = append(ret, srcPath)
|
2015-09-24 00:26:20 +02:00
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2020-11-10 19:50:34 +01:00
|
|
|
// PathsWithOptionalDefaultForModuleSrc returns Paths rooted from the module's local source
|
|
|
|
// directory. If input is nil, use the default if it exists. If input is empty, returns nil.
|
|
|
|
func PathsWithOptionalDefaultForModuleSrc(ctx ModuleMissingDepsPathContext, input []string, def string) Paths {
|
2019-02-08 00:30:01 +01:00
|
|
|
if input != nil {
|
2015-09-24 00:26:20 +02:00
|
|
|
return PathsForModuleSrc(ctx, input)
|
2015-05-12 20:36:53 +02:00
|
|
|
}
|
2015-09-24 00:26:20 +02:00
|
|
|
// Use Glob so that if the default doesn't exist, a dependency is added so that when it
|
|
|
|
// is created, we're run again.
|
2021-08-16 17:05:09 +02:00
|
|
|
path := filepath.Join(ctx.ModuleDir(), def)
|
2020-11-10 19:50:34 +01:00
|
|
|
return Glob(ctx, path, nil)
|
2015-05-12 20:36:53 +02:00
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
// Strings returns the Paths in string form
|
|
|
|
func (p Paths) Strings() []string {
|
|
|
|
if p == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
ret := make([]string, len(p))
|
|
|
|
for i, path := range p {
|
|
|
|
ret[i] = path.String()
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2020-07-03 20:56:24 +02:00
|
|
|
func CopyOfPaths(paths Paths) Paths {
|
|
|
|
return append(Paths(nil), paths...)
|
|
|
|
}
|
|
|
|
|
2017-10-24 20:13:31 +02:00
|
|
|
// FirstUniquePaths returns all unique elements of a Paths, keeping the first copy of each. It
|
|
|
|
// modifies the Paths slice contents in place, and returns a subslice of the original slice.
|
2017-08-29 21:28:37 +02:00
|
|
|
func FirstUniquePaths(list Paths) Paths {
|
2020-02-29 00:34:17 +01:00
|
|
|
// 128 was chosen based on BenchmarkFirstUniquePaths results.
|
|
|
|
if len(list) > 128 {
|
|
|
|
return firstUniquePathsMap(list)
|
|
|
|
}
|
|
|
|
return firstUniquePathsList(list)
|
|
|
|
}
|
|
|
|
|
2020-07-03 20:56:24 +02:00
|
|
|
// SortedUniquePaths returns all unique elements of a Paths in sorted order. It modifies the
|
|
|
|
// Paths slice contents in place, and returns a subslice of the original slice.
|
2020-05-29 15:00:16 +02:00
|
|
|
func SortedUniquePaths(list Paths) Paths {
|
|
|
|
unique := FirstUniquePaths(list)
|
|
|
|
sort.Slice(unique, func(i, j int) bool {
|
|
|
|
return unique[i].String() < unique[j].String()
|
|
|
|
})
|
|
|
|
return unique
|
|
|
|
}
|
|
|
|
|
2020-02-29 00:34:17 +01:00
|
|
|
func firstUniquePathsList(list Paths) Paths {
|
2017-08-29 21:28:37 +02:00
|
|
|
k := 0
|
|
|
|
outer:
|
|
|
|
for i := 0; i < len(list); i++ {
|
|
|
|
for j := 0; j < k; j++ {
|
|
|
|
if list[i] == list[j] {
|
|
|
|
continue outer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
list[k] = list[i]
|
|
|
|
k++
|
|
|
|
}
|
|
|
|
return list[:k]
|
|
|
|
}
|
|
|
|
|
2020-02-29 00:34:17 +01:00
|
|
|
func firstUniquePathsMap(list Paths) Paths {
|
|
|
|
k := 0
|
|
|
|
seen := make(map[Path]bool, len(list))
|
|
|
|
for i := 0; i < len(list); i++ {
|
|
|
|
if seen[list[i]] {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
seen[list[i]] = true
|
|
|
|
list[k] = list[i]
|
|
|
|
k++
|
|
|
|
}
|
|
|
|
return list[:k]
|
|
|
|
}
|
|
|
|
|
2020-11-25 01:21:24 +01:00
|
|
|
// FirstUniqueInstallPaths returns all unique elements of an InstallPaths, keeping the first copy of each. It
|
|
|
|
// modifies the InstallPaths slice contents in place, and returns a subslice of the original slice.
|
|
|
|
func FirstUniqueInstallPaths(list InstallPaths) InstallPaths {
|
|
|
|
// 128 was chosen based on BenchmarkFirstUniquePaths results.
|
|
|
|
if len(list) > 128 {
|
|
|
|
return firstUniqueInstallPathsMap(list)
|
|
|
|
}
|
|
|
|
return firstUniqueInstallPathsList(list)
|
|
|
|
}
|
|
|
|
|
|
|
|
func firstUniqueInstallPathsList(list InstallPaths) InstallPaths {
|
|
|
|
k := 0
|
|
|
|
outer:
|
|
|
|
for i := 0; i < len(list); i++ {
|
|
|
|
for j := 0; j < k; j++ {
|
|
|
|
if list[i] == list[j] {
|
|
|
|
continue outer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
list[k] = list[i]
|
|
|
|
k++
|
|
|
|
}
|
|
|
|
return list[:k]
|
|
|
|
}
|
|
|
|
|
|
|
|
func firstUniqueInstallPathsMap(list InstallPaths) InstallPaths {
|
|
|
|
k := 0
|
|
|
|
seen := make(map[InstallPath]bool, len(list))
|
|
|
|
for i := 0; i < len(list); i++ {
|
|
|
|
if seen[list[i]] {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
seen[list[i]] = true
|
|
|
|
list[k] = list[i]
|
|
|
|
k++
|
|
|
|
}
|
|
|
|
return list[:k]
|
|
|
|
}
|
|
|
|
|
2017-10-24 20:13:31 +02:00
|
|
|
// LastUniquePaths returns all unique elements of a Paths, keeping the last copy of each. It
|
|
|
|
// modifies the Paths slice contents in place, and returns a subslice of the original slice.
|
|
|
|
func LastUniquePaths(list Paths) Paths {
|
|
|
|
totalSkip := 0
|
|
|
|
for i := len(list) - 1; i >= totalSkip; i-- {
|
|
|
|
skip := 0
|
|
|
|
for j := i - 1; j >= totalSkip; j-- {
|
|
|
|
if list[i] == list[j] {
|
|
|
|
skip++
|
|
|
|
} else {
|
|
|
|
list[j+skip] = list[j]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
totalSkip += skip
|
|
|
|
}
|
|
|
|
return list[totalSkip:]
|
|
|
|
}
|
|
|
|
|
2018-04-17 19:52:26 +02:00
|
|
|
// ReversePaths returns a copy of a Paths in reverse order.
|
|
|
|
func ReversePaths(list Paths) Paths {
|
|
|
|
if list == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
ret := make(Paths, len(list))
|
|
|
|
for i := range list {
|
|
|
|
ret[i] = list[len(list)-1-i]
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2017-09-28 02:05:30 +02:00
|
|
|
func indexPathList(s Path, list []Path) int {
|
|
|
|
for i, l := range list {
|
|
|
|
if l == s {
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
|
|
|
func inPathList(p Path, list []Path) bool {
|
|
|
|
return indexPathList(p, list) != -1
|
|
|
|
}
|
|
|
|
|
|
|
|
func FilterPathList(list []Path, filter []Path) (remainder []Path, filtered []Path) {
|
2019-12-13 01:03:35 +01:00
|
|
|
return FilterPathListPredicate(list, func(p Path) bool { return inPathList(p, filter) })
|
|
|
|
}
|
|
|
|
|
|
|
|
func FilterPathListPredicate(list []Path, predicate func(Path) bool) (remainder []Path, filtered []Path) {
|
2017-09-28 02:05:30 +02:00
|
|
|
for _, l := range list {
|
2019-12-13 01:03:35 +01:00
|
|
|
if predicate(l) {
|
2017-09-28 02:05:30 +02:00
|
|
|
filtered = append(filtered, l)
|
|
|
|
} else {
|
|
|
|
remainder = append(remainder, l)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-08-15 22:34:18 +02:00
|
|
|
// HasExt returns true of any of the paths have extension ext, otherwise false
|
|
|
|
func (p Paths) HasExt(ext string) bool {
|
|
|
|
for _, path := range p {
|
|
|
|
if path.Ext() == ext {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// FilterByExt returns the subset of the paths that have extension ext
|
|
|
|
func (p Paths) FilterByExt(ext string) Paths {
|
|
|
|
ret := make(Paths, 0, len(p))
|
|
|
|
for _, path := range p {
|
|
|
|
if path.Ext() == ext {
|
|
|
|
ret = append(ret, path)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
// FilterOutByExt returns the subset of the paths that do not have extension ext
|
|
|
|
func (p Paths) FilterOutByExt(ext string) Paths {
|
|
|
|
ret := make(Paths, 0, len(p))
|
|
|
|
for _, path := range p {
|
|
|
|
if path.Ext() != ext {
|
|
|
|
ret = append(ret, path)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2017-11-03 23:20:35 +01:00
|
|
|
// DirectorySortedPaths is a slice of paths that are sorted such that all files in a directory
|
|
|
|
// (including subdirectories) are in a contiguous subslice of the list, and can be found in
|
|
|
|
// O(log(N)) time using a binary search on the directory prefix.
|
|
|
|
type DirectorySortedPaths Paths
|
|
|
|
|
|
|
|
func PathsToDirectorySortedPaths(paths Paths) DirectorySortedPaths {
|
|
|
|
ret := append(DirectorySortedPaths(nil), paths...)
|
|
|
|
sort.Slice(ret, func(i, j int) bool {
|
|
|
|
return ret[i].String() < ret[j].String()
|
|
|
|
})
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
// PathsInDirectory returns a subslice of the DirectorySortedPaths as a Paths that contains all entries
|
|
|
|
// that are in the specified directory and its subdirectories.
|
|
|
|
func (p DirectorySortedPaths) PathsInDirectory(dir string) Paths {
|
|
|
|
prefix := filepath.Clean(dir) + "/"
|
|
|
|
start := sort.Search(len(p), func(i int) bool {
|
|
|
|
return prefix < p[i].String()
|
|
|
|
})
|
|
|
|
|
|
|
|
ret := p[start:]
|
|
|
|
|
|
|
|
end := sort.Search(len(ret), func(i int) bool {
|
|
|
|
return !strings.HasPrefix(ret[i].String(), prefix)
|
|
|
|
})
|
|
|
|
|
|
|
|
ret = ret[:end]
|
|
|
|
|
|
|
|
return Paths(ret)
|
|
|
|
}
|
|
|
|
|
2020-11-21 03:30:13 +01:00
|
|
|
// WritablePaths is a slice of WritablePath, used for multiple outputs.
|
2015-09-24 00:26:20 +02:00
|
|
|
type WritablePaths []WritablePath
|
|
|
|
|
2021-03-24 11:18:18 +01:00
|
|
|
// RelativeToTop creates a new WritablePaths containing the result of calling Path.RelativeToTop on
|
|
|
|
// each item in this slice.
|
|
|
|
func (p WritablePaths) RelativeToTop() WritablePaths {
|
|
|
|
ensureTestOnly()
|
|
|
|
if p == nil {
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
ret := make(WritablePaths, len(p))
|
|
|
|
for i, path := range p {
|
|
|
|
ret[i] = path.RelativeToTop().(WritablePath)
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
// Strings returns the string forms of the writable paths.
|
|
|
|
func (p WritablePaths) Strings() []string {
|
|
|
|
if p == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
ret := make([]string, len(p))
|
|
|
|
for i, path := range p {
|
|
|
|
ret[i] = path.String()
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2017-11-23 01:19:37 +01:00
|
|
|
// Paths returns the WritablePaths as a Paths
|
|
|
|
func (p WritablePaths) Paths() Paths {
|
|
|
|
if p == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
ret := make(Paths, len(p))
|
|
|
|
for i, path := range p {
|
|
|
|
ret[i] = path
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
type basePath struct {
|
2021-03-24 10:24:59 +01:00
|
|
|
path string
|
|
|
|
rel string
|
2015-09-24 00:26:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p basePath) Ext() string {
|
|
|
|
return filepath.Ext(p.path)
|
|
|
|
}
|
|
|
|
|
2016-10-26 19:05:25 +02:00
|
|
|
func (p basePath) Base() string {
|
|
|
|
return filepath.Base(p.path)
|
|
|
|
}
|
|
|
|
|
2017-02-01 23:12:44 +01:00
|
|
|
func (p basePath) Rel() string {
|
|
|
|
if p.rel != "" {
|
|
|
|
return p.rel
|
|
|
|
}
|
|
|
|
return p.path
|
|
|
|
}
|
|
|
|
|
2017-11-29 02:34:01 +01:00
|
|
|
func (p basePath) String() string {
|
|
|
|
return p.path
|
|
|
|
}
|
|
|
|
|
2017-12-06 00:36:55 +01:00
|
|
|
func (p basePath) withRel(rel string) basePath {
|
|
|
|
p.path = filepath.Join(p.path, rel)
|
|
|
|
p.rel = rel
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
// SourcePath is a Path representing a file path rooted from SrcDir
|
|
|
|
type SourcePath struct {
|
|
|
|
basePath
|
2021-03-24 10:04:03 +01:00
|
|
|
|
|
|
|
// The sources root, i.e. Config.SrcDir()
|
|
|
|
srcDir string
|
2015-09-24 00:26:20 +02:00
|
|
|
}
|
|
|
|
|
2021-03-24 11:18:18 +01:00
|
|
|
func (p SourcePath) RelativeToTop() Path {
|
|
|
|
ensureTestOnly()
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
var _ Path = SourcePath{}
|
|
|
|
|
2017-12-06 00:36:55 +01:00
|
|
|
func (p SourcePath) withRel(rel string) SourcePath {
|
|
|
|
p.basePath = p.basePath.withRel(rel)
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
// safePathForSource is for paths that we expect are safe -- only for use by go
|
|
|
|
// code that is embedding ninja variables in paths
|
2018-09-12 19:02:13 +02:00
|
|
|
func safePathForSource(ctx PathContext, pathComponents ...string) (SourcePath, error) {
|
|
|
|
p, err := validateSafePath(pathComponents...)
|
2021-08-16 17:05:09 +02:00
|
|
|
ret := SourcePath{basePath{p, ""}, "."}
|
2018-02-22 22:54:26 +01:00
|
|
|
if err != nil {
|
2018-09-12 19:02:13 +02:00
|
|
|
return ret, err
|
2018-02-22 22:54:26 +01:00
|
|
|
}
|
2015-09-24 00:26:20 +02:00
|
|
|
|
2019-01-24 22:14:39 +01:00
|
|
|
// absolute path already checked by validateSafePath
|
2021-08-26 15:07:24 +02:00
|
|
|
if strings.HasPrefix(ret.String(), ctx.Config().soongOutDir) {
|
2019-02-08 22:17:55 +01:00
|
|
|
return ret, fmt.Errorf("source path %q is in output", ret.String())
|
2015-09-24 00:26:20 +02:00
|
|
|
}
|
|
|
|
|
2018-09-12 19:02:13 +02:00
|
|
|
return ret, err
|
2015-09-24 00:26:20 +02:00
|
|
|
}
|
|
|
|
|
2018-02-22 23:21:02 +01:00
|
|
|
// pathForSource creates a SourcePath from pathComponents, but does not check that it exists.
|
|
|
|
func pathForSource(ctx PathContext, pathComponents ...string) (SourcePath, error) {
|
2018-02-22 22:54:26 +01:00
|
|
|
p, err := validatePath(pathComponents...)
|
2021-08-16 17:05:09 +02:00
|
|
|
ret := SourcePath{basePath{p, ""}, "."}
|
2018-02-22 22:54:26 +01:00
|
|
|
if err != nil {
|
2018-02-22 23:21:02 +01:00
|
|
|
return ret, err
|
2018-02-22 22:54:26 +01:00
|
|
|
}
|
2015-09-24 00:26:20 +02:00
|
|
|
|
2019-01-24 22:14:39 +01:00
|
|
|
// absolute path already checked by validatePath
|
2021-08-26 15:07:24 +02:00
|
|
|
if strings.HasPrefix(ret.String(), ctx.Config().soongOutDir) {
|
2019-02-08 22:17:55 +01:00
|
|
|
return ret, fmt.Errorf("source path %q is in output", ret.String())
|
2018-02-22 23:21:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// existsWithDependencies returns true if the path exists, and adds appropriate dependencies to rerun if the
|
|
|
|
// path does not exist.
|
|
|
|
func existsWithDependencies(ctx PathContext, path SourcePath) (exists bool, err error) {
|
|
|
|
var files []string
|
|
|
|
|
|
|
|
if gctx, ok := ctx.(PathGlobContext); ok {
|
|
|
|
// Use glob to produce proper dependencies, even though we only want
|
|
|
|
// a single file.
|
|
|
|
files, err = gctx.GlobWithDeps(path.String(), nil)
|
|
|
|
} else {
|
2021-04-06 02:48:26 +02:00
|
|
|
var result pathtools.GlobResult
|
2018-02-22 23:21:02 +01:00
|
|
|
// We cannot add build statements in this context, so we fall back to
|
|
|
|
// AddNinjaFileDeps
|
2021-04-06 02:48:26 +02:00
|
|
|
result, err = ctx.Config().fs.Glob(path.String(), nil, pathtools.FollowSymlinks)
|
|
|
|
ctx.AddNinjaFileDeps(result.Deps...)
|
|
|
|
files = result.Matches
|
2015-09-24 00:26:20 +02:00
|
|
|
}
|
|
|
|
|
2018-02-22 23:21:02 +01:00
|
|
|
if err != nil {
|
|
|
|
return false, fmt.Errorf("glob: %s", err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
return len(files) > 0, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// PathForSource joins the provided path components and validates that the result
|
|
|
|
// neither escapes the source dir nor is in the out dir.
|
|
|
|
// On error, it will return a usable, but invalid SourcePath, and report a ModuleError.
|
|
|
|
func PathForSource(ctx PathContext, pathComponents ...string) SourcePath {
|
|
|
|
path, err := pathForSource(ctx, pathComponents...)
|
|
|
|
if err != nil {
|
|
|
|
reportPathError(ctx, err)
|
|
|
|
}
|
|
|
|
|
2018-08-16 05:18:53 +02:00
|
|
|
if pathtools.IsGlob(path.String()) {
|
2020-08-25 13:45:15 +02:00
|
|
|
ReportPathErrorf(ctx, "path may not contain a glob: %s", path.String())
|
2018-08-16 05:18:53 +02:00
|
|
|
}
|
|
|
|
|
2020-11-10 19:50:34 +01:00
|
|
|
if modCtx, ok := ctx.(ModuleMissingDepsPathContext); ok && ctx.Config().AllowMissingDependencies() {
|
2018-02-22 23:21:02 +01:00
|
|
|
exists, err := existsWithDependencies(ctx, path)
|
|
|
|
if err != nil {
|
|
|
|
reportPathError(ctx, err)
|
|
|
|
}
|
|
|
|
if !exists {
|
|
|
|
modCtx.AddMissingDependencies([]string{path.String()})
|
|
|
|
}
|
2020-01-11 02:11:46 +01:00
|
|
|
} else if exists, _, err := ctx.Config().fs.Exists(path.String()); err != nil {
|
2020-08-25 13:45:15 +02:00
|
|
|
ReportPathErrorf(ctx, "%s: %s", path, err.Error())
|
2021-02-15 16:41:33 +01:00
|
|
|
} else if !exists && !ctx.Config().TestAllowNonExistentPaths {
|
2020-08-25 13:45:15 +02:00
|
|
|
ReportPathErrorf(ctx, "source path %q does not exist", path)
|
2015-05-12 20:36:53 +02:00
|
|
|
}
|
2018-02-22 23:21:02 +01:00
|
|
|
return path
|
2015-09-24 00:26:20 +02:00
|
|
|
}
|
|
|
|
|
2021-02-11 15:16:14 +01:00
|
|
|
// ExistentPathForSource returns an OptionalPath with the SourcePath, rooted from SrcDir, *not*
|
|
|
|
// rooted from the module's local source directory, if the path exists, or an empty OptionalPath if
|
|
|
|
// it doesn't exist. Dependencies are added so that the ninja file will be regenerated if the state
|
|
|
|
// of the path changes.
|
2018-02-22 20:47:25 +01:00
|
|
|
func ExistentPathForSource(ctx PathContext, pathComponents ...string) OptionalPath {
|
2018-02-22 23:21:02 +01:00
|
|
|
path, err := pathForSource(ctx, pathComponents...)
|
2018-02-22 22:54:26 +01:00
|
|
|
if err != nil {
|
|
|
|
reportPathError(ctx, err)
|
2021-09-15 03:39:00 +02:00
|
|
|
// No need to put the error message into the returned path since it has been reported already.
|
2018-02-22 22:54:26 +01:00
|
|
|
return OptionalPath{}
|
|
|
|
}
|
2015-09-24 00:26:20 +02:00
|
|
|
|
2018-08-16 05:18:53 +02:00
|
|
|
if pathtools.IsGlob(path.String()) {
|
2020-08-25 13:45:15 +02:00
|
|
|
ReportPathErrorf(ctx, "path may not contain a glob: %s", path.String())
|
2018-08-16 05:18:53 +02:00
|
|
|
return OptionalPath{}
|
|
|
|
}
|
|
|
|
|
2018-02-22 23:21:02 +01:00
|
|
|
exists, err := existsWithDependencies(ctx, path)
|
2015-09-24 00:26:20 +02:00
|
|
|
if err != nil {
|
2018-02-22 22:54:26 +01:00
|
|
|
reportPathError(ctx, err)
|
2015-09-24 00:26:20 +02:00
|
|
|
return OptionalPath{}
|
|
|
|
}
|
2018-02-22 23:21:02 +01:00
|
|
|
if !exists {
|
2021-09-15 03:39:00 +02:00
|
|
|
return InvalidOptionalPath(path.String() + " does not exist")
|
2018-02-23 08:09:01 +01:00
|
|
|
}
|
2015-09-24 00:26:20 +02:00
|
|
|
return OptionalPathForPath(path)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p SourcePath) String() string {
|
2021-03-24 10:04:03 +01:00
|
|
|
return filepath.Join(p.srcDir, p.path)
|
2015-09-24 00:26:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Join creates a new SourcePath with paths... joined with the current path. The
|
|
|
|
// provided paths... may not use '..' to escape from the current path.
|
|
|
|
func (p SourcePath) Join(ctx PathContext, paths ...string) SourcePath {
|
2018-02-22 22:54:26 +01:00
|
|
|
path, err := validatePath(paths...)
|
|
|
|
if err != nil {
|
|
|
|
reportPathError(ctx, err)
|
|
|
|
}
|
2017-12-06 00:36:55 +01:00
|
|
|
return p.withRel(path)
|
2015-05-12 20:36:53 +02:00
|
|
|
}
|
2015-07-15 03:55:36 +02:00
|
|
|
|
2019-03-05 21:39:51 +01:00
|
|
|
// join is like Join but does less path validation.
|
|
|
|
func (p SourcePath) join(ctx PathContext, paths ...string) SourcePath {
|
|
|
|
path, err := validateSafePath(paths...)
|
|
|
|
if err != nil {
|
|
|
|
reportPathError(ctx, err)
|
|
|
|
}
|
|
|
|
return p.withRel(path)
|
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
// OverlayPath returns the overlay for `path' if it exists. This assumes that the
|
|
|
|
// SourcePath is the path to a resource overlay directory.
|
2020-11-10 19:50:34 +01:00
|
|
|
func (p SourcePath) OverlayPath(ctx ModuleMissingDepsPathContext, path Path) OptionalPath {
|
2015-09-24 00:26:20 +02:00
|
|
|
var relDir string
|
2019-03-05 21:46:40 +01:00
|
|
|
if srcPath, ok := path.(SourcePath); ok {
|
2015-09-24 00:26:20 +02:00
|
|
|
relDir = srcPath.path
|
|
|
|
} else {
|
2020-08-25 13:45:15 +02:00
|
|
|
ReportPathErrorf(ctx, "Cannot find relative path for %s(%s)", reflect.TypeOf(path).Name(), path)
|
2021-09-15 03:39:00 +02:00
|
|
|
// No need to put the error message into the returned path since it has been reported already.
|
2015-09-24 00:26:20 +02:00
|
|
|
return OptionalPath{}
|
|
|
|
}
|
2021-03-24 10:04:03 +01:00
|
|
|
dir := filepath.Join(p.srcDir, p.path, relDir)
|
2015-09-24 00:26:20 +02:00
|
|
|
// Use Glob so that we are run again if the directory is added.
|
2016-11-01 19:10:25 +01:00
|
|
|
if pathtools.IsGlob(dir) {
|
2020-08-25 13:45:15 +02:00
|
|
|
ReportPathErrorf(ctx, "Path may not contain a glob: %s", dir)
|
2015-12-19 00:11:17 +01:00
|
|
|
}
|
2018-02-23 18:22:42 +01:00
|
|
|
paths, err := ctx.GlobWithDeps(dir, nil)
|
2015-07-15 03:55:36 +02:00
|
|
|
if err != nil {
|
2020-08-25 13:45:15 +02:00
|
|
|
ReportPathErrorf(ctx, "glob: %s", err.Error())
|
2015-09-24 00:26:20 +02:00
|
|
|
return OptionalPath{}
|
|
|
|
}
|
|
|
|
if len(paths) == 0 {
|
2021-09-15 03:39:00 +02:00
|
|
|
return InvalidOptionalPath(dir + " does not exist")
|
2015-09-24 00:26:20 +02:00
|
|
|
}
|
2021-03-24 10:04:03 +01:00
|
|
|
relPath := Rel(ctx, p.srcDir, paths[0])
|
2015-09-24 00:26:20 +02:00
|
|
|
return OptionalPathForPath(PathForSource(ctx, relPath))
|
|
|
|
}
|
|
|
|
|
2019-10-02 07:05:35 +02:00
|
|
|
// OutputPath is a Path representing an intermediates file path rooted from the build directory
|
2015-09-24 00:26:20 +02:00
|
|
|
type OutputPath struct {
|
|
|
|
basePath
|
2021-03-24 10:22:07 +01:00
|
|
|
|
2021-08-31 10:42:08 +02:00
|
|
|
// The soong build directory, i.e. Config.SoongOutDir()
|
2021-08-26 15:07:24 +02:00
|
|
|
soongOutDir string
|
2021-03-24 10:22:07 +01:00
|
|
|
|
2020-01-30 01:52:50 +01:00
|
|
|
fullPath string
|
2015-09-24 00:26:20 +02:00
|
|
|
}
|
|
|
|
|
2017-10-19 02:27:54 +02:00
|
|
|
func (p OutputPath) withRel(rel string) OutputPath {
|
2017-12-06 00:36:55 +01:00
|
|
|
p.basePath = p.basePath.withRel(rel)
|
2020-01-30 01:52:50 +01:00
|
|
|
p.fullPath = filepath.Join(p.fullPath, rel)
|
2017-10-19 02:27:54 +02:00
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2018-08-15 20:19:12 +02:00
|
|
|
func (p OutputPath) WithoutRel() OutputPath {
|
|
|
|
p.basePath.rel = filepath.Base(p.basePath.path)
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2021-08-26 15:07:24 +02:00
|
|
|
func (p OutputPath) getSoongOutDir() string {
|
|
|
|
return p.soongOutDir
|
2019-12-10 14:41:51 +01:00
|
|
|
}
|
|
|
|
|
2021-03-24 11:18:18 +01:00
|
|
|
func (p OutputPath) RelativeToTop() Path {
|
|
|
|
return p.outputPathRelativeToTop()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p OutputPath) outputPathRelativeToTop() OutputPath {
|
2021-08-26 15:07:24 +02:00
|
|
|
p.fullPath = StringPathRelativeToTop(p.soongOutDir, p.fullPath)
|
|
|
|
p.soongOutDir = OutSoongDir
|
2021-03-24 11:18:18 +01:00
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2021-02-02 11:05:52 +01:00
|
|
|
func (p OutputPath) objPathWithExt(ctx ModuleOutPathContext, subdir, ext string) ModuleObjPath {
|
|
|
|
return PathForModuleObj(ctx, subdir, pathtools.ReplaceExtension(p.path, ext))
|
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
var _ Path = OutputPath{}
|
2019-12-10 14:41:51 +01:00
|
|
|
var _ WritablePath = OutputPath{}
|
2021-02-02 11:05:52 +01:00
|
|
|
var _ objPathProvider = OutputPath{}
|
2015-09-24 00:26:20 +02:00
|
|
|
|
2020-06-23 23:37:05 +02:00
|
|
|
// toolDepPath is a Path representing a dependency of the build tool.
|
|
|
|
type toolDepPath struct {
|
|
|
|
basePath
|
|
|
|
}
|
|
|
|
|
2021-03-24 11:18:18 +01:00
|
|
|
func (t toolDepPath) RelativeToTop() Path {
|
|
|
|
ensureTestOnly()
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
2020-06-23 23:37:05 +02:00
|
|
|
var _ Path = toolDepPath{}
|
|
|
|
|
|
|
|
// pathForBuildToolDep returns a toolDepPath representing the given path string.
|
|
|
|
// There is no validation for the path, as it is "trusted": It may fail
|
|
|
|
// normal validation checks. For example, it may be an absolute path.
|
|
|
|
// Only use this function to construct paths for dependencies of the build
|
|
|
|
// tool invocation.
|
|
|
|
func pathForBuildToolDep(ctx PathContext, path string) toolDepPath {
|
2021-03-24 10:24:59 +01:00
|
|
|
return toolDepPath{basePath{path, ""}}
|
2020-06-23 23:37:05 +02:00
|
|
|
}
|
|
|
|
|
2017-04-11 00:47:24 +02:00
|
|
|
// PathForOutput joins the provided paths and returns an OutputPath that is
|
|
|
|
// validated to not escape the build dir.
|
|
|
|
// On error, it will return a usable, but invalid OutputPath, and report a ModuleError.
|
|
|
|
func PathForOutput(ctx PathContext, pathComponents ...string) OutputPath {
|
2018-02-22 22:54:26 +01:00
|
|
|
path, err := validatePath(pathComponents...)
|
|
|
|
if err != nil {
|
|
|
|
reportPathError(ctx, err)
|
|
|
|
}
|
2021-08-26 15:07:24 +02:00
|
|
|
fullPath := filepath.Join(ctx.Config().soongOutDir, path)
|
2020-01-30 01:52:50 +01:00
|
|
|
path = fullPath[len(fullPath)-len(path):]
|
2021-08-26 15:07:24 +02:00
|
|
|
return OutputPath{basePath{path, ""}, ctx.Config().soongOutDir, fullPath}
|
2015-09-24 00:26:20 +02:00
|
|
|
}
|
|
|
|
|
2021-08-26 15:07:24 +02:00
|
|
|
// PathsForOutput returns Paths rooted from soongOutDir
|
2019-02-15 20:08:35 +01:00
|
|
|
func PathsForOutput(ctx PathContext, paths []string) WritablePaths {
|
|
|
|
ret := make(WritablePaths, len(paths))
|
|
|
|
for i, path := range paths {
|
|
|
|
ret[i] = PathForOutput(ctx, path)
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
func (p OutputPath) writablePath() {}
|
|
|
|
|
|
|
|
func (p OutputPath) String() string {
|
2020-01-30 01:52:50 +01:00
|
|
|
return p.fullPath
|
2015-09-24 00:26:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Join creates a new OutputPath with paths... joined with the current path. The
|
|
|
|
// provided paths... may not use '..' to escape from the current path.
|
|
|
|
func (p OutputPath) Join(ctx PathContext, paths ...string) OutputPath {
|
2018-02-22 22:54:26 +01:00
|
|
|
path, err := validatePath(paths...)
|
|
|
|
if err != nil {
|
|
|
|
reportPathError(ctx, err)
|
|
|
|
}
|
2017-12-06 00:36:55 +01:00
|
|
|
return p.withRel(path)
|
2015-09-24 00:26:20 +02:00
|
|
|
}
|
|
|
|
|
2019-02-11 23:14:16 +01:00
|
|
|
// ReplaceExtension creates a new OutputPath with the extension replaced with ext.
|
|
|
|
func (p OutputPath) ReplaceExtension(ctx PathContext, ext string) OutputPath {
|
|
|
|
if strings.Contains(ext, "/") {
|
2020-08-25 13:45:15 +02:00
|
|
|
ReportPathErrorf(ctx, "extension %q cannot contain /", ext)
|
2019-02-11 23:14:16 +01:00
|
|
|
}
|
|
|
|
ret := PathForOutput(ctx, pathtools.ReplaceExtension(p.path, ext))
|
2019-02-25 19:25:24 +01:00
|
|
|
ret.rel = pathtools.ReplaceExtension(p.rel, ext)
|
2019-02-11 23:14:16 +01:00
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2019-02-15 20:08:35 +01:00
|
|
|
// InSameDir creates a new OutputPath from the directory of the current OutputPath joined with the elements in paths.
|
|
|
|
func (p OutputPath) InSameDir(ctx PathContext, paths ...string) OutputPath {
|
|
|
|
path, err := validatePath(paths...)
|
|
|
|
if err != nil {
|
|
|
|
reportPathError(ctx, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
ret := PathForOutput(ctx, filepath.Dir(p.path), path)
|
2019-02-25 19:25:24 +01:00
|
|
|
ret.rel = filepath.Join(filepath.Dir(p.rel), path)
|
2019-02-15 20:08:35 +01:00
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
// PathForIntermediates returns an OutputPath representing the top-level
|
|
|
|
// intermediates directory.
|
|
|
|
func PathForIntermediates(ctx PathContext, paths ...string) OutputPath {
|
2018-02-22 22:54:26 +01:00
|
|
|
path, err := validatePath(paths...)
|
|
|
|
if err != nil {
|
|
|
|
reportPathError(ctx, err)
|
|
|
|
}
|
2015-09-24 00:26:20 +02:00
|
|
|
return PathForOutput(ctx, ".intermediates", path)
|
|
|
|
}
|
|
|
|
|
2019-03-05 21:46:40 +01:00
|
|
|
var _ genPathProvider = SourcePath{}
|
|
|
|
var _ objPathProvider = SourcePath{}
|
|
|
|
var _ resPathProvider = SourcePath{}
|
2015-09-24 00:26:20 +02:00
|
|
|
|
2019-03-05 21:46:40 +01:00
|
|
|
// PathForModuleSrc returns a Path representing the paths... under the
|
2015-09-24 00:26:20 +02:00
|
|
|
// module's local source directory.
|
2020-11-10 19:50:34 +01:00
|
|
|
func PathForModuleSrc(ctx ModuleMissingDepsPathContext, pathComponents ...string) Path {
|
2021-07-09 17:56:35 +02:00
|
|
|
// Just join the components textually just to make sure that it does not corrupt a fully qualified
|
|
|
|
// module reference, e.g. if the pathComponents is "://other:foo" then using filepath.Join() or
|
|
|
|
// validatePath() will corrupt it, e.g. replace "//" with "/". If the path is not a module
|
|
|
|
// reference then it will be validated by expandOneSrcPath anyway when it calls expandOneSrcPath.
|
|
|
|
p := strings.Join(pathComponents, string(filepath.Separator))
|
2022-01-28 21:13:39 +01:00
|
|
|
paths, err := expandOneSrcPath(sourcePathInput{context: ctx, path: p, includeDirs: true})
|
2019-03-06 07:25:09 +01:00
|
|
|
if err != nil {
|
|
|
|
if depErr, ok := err.(missingDependencyError); ok {
|
|
|
|
if ctx.Config().AllowMissingDependencies() {
|
|
|
|
ctx.AddMissingDependencies(depErr.missingDeps)
|
|
|
|
} else {
|
|
|
|
ctx.ModuleErrorf(`%s, is the property annotated with android:"path"?`, depErr.Error())
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
reportPathError(ctx, err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
} else if len(paths) == 0 {
|
2020-08-25 13:45:15 +02:00
|
|
|
ReportPathErrorf(ctx, "%q produced no files, expected exactly one", p)
|
2019-03-06 07:25:09 +01:00
|
|
|
return nil
|
|
|
|
} else if len(paths) > 1 {
|
2020-08-25 13:45:15 +02:00
|
|
|
ReportPathErrorf(ctx, "%q produced %d files, expected exactly one", p, len(paths))
|
2019-03-06 07:25:09 +01:00
|
|
|
}
|
|
|
|
return paths[0]
|
2019-03-05 21:46:40 +01:00
|
|
|
}
|
|
|
|
|
2020-11-10 19:50:34 +01:00
|
|
|
func pathForModuleSrc(ctx EarlyModulePathContext, paths ...string) SourcePath {
|
2018-02-22 22:54:26 +01:00
|
|
|
p, err := validatePath(paths...)
|
|
|
|
if err != nil {
|
|
|
|
reportPathError(ctx, err)
|
|
|
|
}
|
2018-02-22 23:21:02 +01:00
|
|
|
|
2019-03-05 21:46:40 +01:00
|
|
|
path, err := pathForSource(ctx, ctx.ModuleDir(), p)
|
2018-02-22 23:21:02 +01:00
|
|
|
if err != nil {
|
|
|
|
reportPathError(ctx, err)
|
|
|
|
}
|
|
|
|
|
2017-02-01 23:12:44 +01:00
|
|
|
path.basePath.rel = p
|
2018-02-22 23:21:02 +01:00
|
|
|
|
2017-02-01 23:12:44 +01:00
|
|
|
return path
|
2015-09-24 00:26:20 +02:00
|
|
|
}
|
|
|
|
|
2019-03-05 21:39:51 +01:00
|
|
|
// PathsWithModuleSrcSubDir takes a list of Paths and returns a new list of Paths where Rel() on each path
|
|
|
|
// will return the path relative to subDir in the module's source directory. If any input paths are not located
|
|
|
|
// inside subDir then a path error will be reported.
|
2020-11-10 19:50:34 +01:00
|
|
|
func PathsWithModuleSrcSubDir(ctx EarlyModulePathContext, paths Paths, subDir string) Paths {
|
2019-03-05 21:39:51 +01:00
|
|
|
paths = append(Paths(nil), paths...)
|
2019-03-05 21:46:40 +01:00
|
|
|
subDirFullPath := pathForModuleSrc(ctx, subDir)
|
2019-03-05 21:39:51 +01:00
|
|
|
for i, path := range paths {
|
|
|
|
rel := Rel(ctx, subDirFullPath.String(), path.String())
|
|
|
|
paths[i] = subDirFullPath.join(ctx, rel)
|
|
|
|
}
|
|
|
|
return paths
|
|
|
|
}
|
|
|
|
|
|
|
|
// PathWithModuleSrcSubDir takes a Path and returns a Path where Rel() will return the path relative to subDir in the
|
|
|
|
// module's source directory. If the input path is not located inside subDir then a path error will be reported.
|
2020-11-10 19:50:34 +01:00
|
|
|
func PathWithModuleSrcSubDir(ctx EarlyModulePathContext, path Path, subDir string) Path {
|
2019-03-05 21:46:40 +01:00
|
|
|
subDirFullPath := pathForModuleSrc(ctx, subDir)
|
2019-03-05 21:39:51 +01:00
|
|
|
rel := Rel(ctx, subDirFullPath.String(), path.String())
|
|
|
|
return subDirFullPath.Join(ctx, rel)
|
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
// OptionalPathForModuleSrc returns an OptionalPath. The OptionalPath contains a
|
|
|
|
// valid path if p is non-nil.
|
2020-11-10 19:50:34 +01:00
|
|
|
func OptionalPathForModuleSrc(ctx ModuleMissingDepsPathContext, p *string) OptionalPath {
|
2015-09-24 00:26:20 +02:00
|
|
|
if p == nil {
|
|
|
|
return OptionalPath{}
|
|
|
|
}
|
|
|
|
return OptionalPathForPath(PathForModuleSrc(ctx, *p))
|
|
|
|
}
|
|
|
|
|
2020-11-10 19:50:34 +01:00
|
|
|
func (p SourcePath) genPathWithExt(ctx ModuleOutPathContext, subdir, ext string) ModuleGenPath {
|
2017-02-01 23:07:55 +01:00
|
|
|
return PathForModuleGen(ctx, subdir, pathtools.ReplaceExtension(p.path, ext))
|
2015-09-24 00:26:20 +02:00
|
|
|
}
|
|
|
|
|
2020-11-10 19:50:34 +01:00
|
|
|
func (p SourcePath) objPathWithExt(ctx ModuleOutPathContext, subdir, ext string) ModuleObjPath {
|
2017-02-01 23:07:55 +01:00
|
|
|
return PathForModuleObj(ctx, subdir, pathtools.ReplaceExtension(p.path, ext))
|
2015-09-24 00:26:20 +02:00
|
|
|
}
|
|
|
|
|
2020-11-10 19:50:34 +01:00
|
|
|
func (p SourcePath) resPathWithName(ctx ModuleOutPathContext, name string) ModuleResPath {
|
2015-09-24 00:26:20 +02:00
|
|
|
// TODO: Use full directory if the new ctx is not the current ctx?
|
|
|
|
return PathForModuleRes(ctx, p.path, name)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ModuleOutPath is a Path representing a module's output directory.
|
|
|
|
type ModuleOutPath struct {
|
|
|
|
OutputPath
|
|
|
|
}
|
|
|
|
|
2021-03-24 11:18:18 +01:00
|
|
|
func (p ModuleOutPath) RelativeToTop() Path {
|
|
|
|
p.OutputPath = p.outputPathRelativeToTop()
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
var _ Path = ModuleOutPath{}
|
2021-03-24 11:18:18 +01:00
|
|
|
var _ WritablePath = ModuleOutPath{}
|
2015-09-24 00:26:20 +02:00
|
|
|
|
2020-11-10 19:50:34 +01:00
|
|
|
func (p ModuleOutPath) objPathWithExt(ctx ModuleOutPathContext, subdir, ext string) ModuleObjPath {
|
2019-08-16 21:14:32 +02:00
|
|
|
return PathForModuleObj(ctx, subdir, pathtools.ReplaceExtension(p.path, ext))
|
|
|
|
}
|
|
|
|
|
2020-11-10 19:50:34 +01:00
|
|
|
// ModuleOutPathContext Subset of ModuleContext functions necessary for output path methods.
|
|
|
|
type ModuleOutPathContext interface {
|
|
|
|
PathContext
|
|
|
|
|
|
|
|
ModuleName() string
|
|
|
|
ModuleDir() string
|
|
|
|
ModuleSubDir() string
|
|
|
|
}
|
|
|
|
|
|
|
|
func pathForModuleOut(ctx ModuleOutPathContext) OutputPath {
|
2017-10-19 02:27:54 +02:00
|
|
|
return PathForOutput(ctx, ".intermediates", ctx.ModuleDir(), ctx.ModuleName(), ctx.ModuleSubDir())
|
|
|
|
}
|
|
|
|
|
2018-07-11 12:10:41 +02:00
|
|
|
// PathForVndkRefAbiDump returns an OptionalPath representing the path of the
|
|
|
|
// reference abi dump for the given module. This is not guaranteed to be valid.
|
2020-11-10 19:50:34 +01:00
|
|
|
func PathForVndkRefAbiDump(ctx ModuleInstallPathContext, version, fileName string,
|
2019-07-31 11:10:45 +02:00
|
|
|
isNdk, isLlndkOrVndk, isGzip bool) OptionalPath {
|
2018-07-11 12:10:41 +02:00
|
|
|
|
2018-02-20 19:53:31 +01:00
|
|
|
arches := ctx.DeviceConfig().Arches()
|
2018-07-11 12:10:41 +02:00
|
|
|
if len(arches) == 0 {
|
|
|
|
panic("device build with no primary arch")
|
|
|
|
}
|
2018-02-20 19:53:31 +01:00
|
|
|
currentArch := ctx.Arch()
|
|
|
|
archNameAndVariant := currentArch.ArchType.String()
|
|
|
|
if currentArch.ArchVariant != "" {
|
|
|
|
archNameAndVariant += "_" + currentArch.ArchVariant
|
|
|
|
}
|
2018-07-11 11:15:57 +02:00
|
|
|
|
|
|
|
var dirName string
|
2019-07-31 11:10:45 +02:00
|
|
|
if isNdk {
|
2018-07-11 11:15:57 +02:00
|
|
|
dirName = "ndk"
|
2019-07-31 11:10:45 +02:00
|
|
|
} else if isLlndkOrVndk {
|
2018-07-11 11:15:57 +02:00
|
|
|
dirName = "vndk"
|
2019-04-10 07:33:58 +02:00
|
|
|
} else {
|
|
|
|
dirName = "platform" // opt-in libs
|
2017-02-08 22:45:53 +01:00
|
|
|
}
|
2018-07-11 11:15:57 +02:00
|
|
|
|
2018-03-08 20:00:50 +01:00
|
|
|
binderBitness := ctx.DeviceConfig().BinderBitness()
|
2018-07-11 12:10:41 +02:00
|
|
|
|
|
|
|
var ext string
|
|
|
|
if isGzip {
|
|
|
|
ext = ".lsdump.gz"
|
|
|
|
} else {
|
|
|
|
ext = ".lsdump"
|
|
|
|
}
|
|
|
|
|
|
|
|
return ExistentPathForSource(ctx, "prebuilts", "abi-dumps", dirName,
|
|
|
|
version, binderBitness, archNameAndVariant, "source-based",
|
|
|
|
fileName+ext)
|
2017-02-08 22:45:53 +01:00
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
// PathForModuleOut returns a Path representing the paths... under the module's
|
|
|
|
// output directory.
|
2020-11-10 19:50:34 +01:00
|
|
|
func PathForModuleOut(ctx ModuleOutPathContext, paths ...string) ModuleOutPath {
|
2018-02-22 22:54:26 +01:00
|
|
|
p, err := validatePath(paths...)
|
|
|
|
if err != nil {
|
|
|
|
reportPathError(ctx, err)
|
|
|
|
}
|
2017-10-19 02:27:54 +02:00
|
|
|
return ModuleOutPath{
|
2020-11-10 19:50:34 +01:00
|
|
|
OutputPath: pathForModuleOut(ctx).withRel(p),
|
2017-10-19 02:27:54 +02:00
|
|
|
}
|
2015-09-24 00:26:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ModuleGenPath is a Path representing the 'gen' directory in a module's output
|
|
|
|
// directory. Mainly used for generated sources.
|
|
|
|
type ModuleGenPath struct {
|
|
|
|
ModuleOutPath
|
|
|
|
}
|
|
|
|
|
2021-03-24 11:18:18 +01:00
|
|
|
func (p ModuleGenPath) RelativeToTop() Path {
|
|
|
|
p.OutputPath = p.outputPathRelativeToTop()
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
var _ Path = ModuleGenPath{}
|
2021-03-24 11:18:18 +01:00
|
|
|
var _ WritablePath = ModuleGenPath{}
|
2015-09-24 00:26:20 +02:00
|
|
|
var _ genPathProvider = ModuleGenPath{}
|
|
|
|
var _ objPathProvider = ModuleGenPath{}
|
|
|
|
|
|
|
|
// PathForModuleGen returns a Path representing the paths... under the module's
|
|
|
|
// `gen' directory.
|
2020-11-10 19:50:34 +01:00
|
|
|
func PathForModuleGen(ctx ModuleOutPathContext, paths ...string) ModuleGenPath {
|
2018-02-22 22:54:26 +01:00
|
|
|
p, err := validatePath(paths...)
|
|
|
|
if err != nil {
|
|
|
|
reportPathError(ctx, err)
|
|
|
|
}
|
2015-09-24 00:26:20 +02:00
|
|
|
return ModuleGenPath{
|
2017-10-19 02:27:54 +02:00
|
|
|
ModuleOutPath: ModuleOutPath{
|
2020-11-10 19:50:34 +01:00
|
|
|
OutputPath: pathForModuleOut(ctx).withRel("gen").withRel(p),
|
2017-10-19 02:27:54 +02:00
|
|
|
},
|
2015-07-15 03:55:36 +02:00
|
|
|
}
|
2015-09-24 00:26:20 +02:00
|
|
|
}
|
|
|
|
|
2020-11-10 19:50:34 +01:00
|
|
|
func (p ModuleGenPath) genPathWithExt(ctx ModuleOutPathContext, subdir, ext string) ModuleGenPath {
|
2015-09-24 00:26:20 +02:00
|
|
|
// TODO: make a different path for local vs remote generated files?
|
2016-11-03 04:43:13 +01:00
|
|
|
return PathForModuleGen(ctx, subdir, pathtools.ReplaceExtension(p.path, ext))
|
2015-09-24 00:26:20 +02:00
|
|
|
}
|
|
|
|
|
2020-11-10 19:50:34 +01:00
|
|
|
func (p ModuleGenPath) objPathWithExt(ctx ModuleOutPathContext, subdir, ext string) ModuleObjPath {
|
2015-09-24 00:26:20 +02:00
|
|
|
return PathForModuleObj(ctx, subdir, pathtools.ReplaceExtension(p.path, ext))
|
|
|
|
}
|
2015-07-15 03:55:36 +02:00
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
// ModuleObjPath is a Path representing the 'obj' directory in a module's output
|
|
|
|
// directory. Used for compiled objects.
|
|
|
|
type ModuleObjPath struct {
|
|
|
|
ModuleOutPath
|
|
|
|
}
|
|
|
|
|
2021-03-24 11:18:18 +01:00
|
|
|
func (p ModuleObjPath) RelativeToTop() Path {
|
|
|
|
p.OutputPath = p.outputPathRelativeToTop()
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
var _ Path = ModuleObjPath{}
|
2021-03-24 11:18:18 +01:00
|
|
|
var _ WritablePath = ModuleObjPath{}
|
2015-09-24 00:26:20 +02:00
|
|
|
|
|
|
|
// PathForModuleObj returns a Path representing the paths... under the module's
|
|
|
|
// 'obj' directory.
|
2020-11-10 19:50:34 +01:00
|
|
|
func PathForModuleObj(ctx ModuleOutPathContext, pathComponents ...string) ModuleObjPath {
|
2018-02-22 22:54:26 +01:00
|
|
|
p, err := validatePath(pathComponents...)
|
|
|
|
if err != nil {
|
|
|
|
reportPathError(ctx, err)
|
|
|
|
}
|
2015-09-24 00:26:20 +02:00
|
|
|
return ModuleObjPath{PathForModuleOut(ctx, "obj", p)}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ModuleResPath is a a Path representing the 'res' directory in a module's
|
|
|
|
// output directory.
|
|
|
|
type ModuleResPath struct {
|
|
|
|
ModuleOutPath
|
|
|
|
}
|
|
|
|
|
2021-03-24 11:18:18 +01:00
|
|
|
func (p ModuleResPath) RelativeToTop() Path {
|
|
|
|
p.OutputPath = p.outputPathRelativeToTop()
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
var _ Path = ModuleResPath{}
|
2021-03-24 11:18:18 +01:00
|
|
|
var _ WritablePath = ModuleResPath{}
|
2015-09-24 00:26:20 +02:00
|
|
|
|
|
|
|
// PathForModuleRes returns a Path representing the paths... under the module's
|
|
|
|
// 'res' directory.
|
2020-11-10 19:50:34 +01:00
|
|
|
func PathForModuleRes(ctx ModuleOutPathContext, pathComponents ...string) ModuleResPath {
|
2018-02-22 22:54:26 +01:00
|
|
|
p, err := validatePath(pathComponents...)
|
|
|
|
if err != nil {
|
|
|
|
reportPathError(ctx, err)
|
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
return ModuleResPath{PathForModuleOut(ctx, "res", p)}
|
|
|
|
}
|
|
|
|
|
2019-10-02 07:05:35 +02:00
|
|
|
// InstallPath is a Path representing a installed file path rooted from the build directory
|
|
|
|
type InstallPath struct {
|
|
|
|
basePath
|
2019-10-03 01:01:35 +02:00
|
|
|
|
2021-08-31 10:42:08 +02:00
|
|
|
// The soong build directory, i.e. Config.SoongOutDir()
|
2021-08-26 15:07:24 +02:00
|
|
|
soongOutDir string
|
2021-03-24 10:22:07 +01:00
|
|
|
|
InstallPath keeps its partition dir
This change introduces the concept of partition dir for InstallPaths.
It's the path to the partition where the InstallPath is rooted at. For
example, it's out/soong/target/product/<device>/<partitoon> for paths
created for device modules. For host modules, it is defined as
out/soong/host/<host_os>-<host_arch>.
The partition dir is obtained using the new PartitionDir() function.
Another change is that a freshly created InstallPath (usually via
PathForModuleInstall) is the result of joining PartitionDir() and the
remaining path elements. For example, PathForModuleInstall(ctx, "foo",
"bar").Rel() now returns "foo/bar". Previously, that call returned the
relative path from config.buildDir() ("out/soong"). This change is in
line with the behavior of other path-creating functions like
PathForModuleSrc where Rel() returns the path relative to the
contextually determined path like the module source directory.
Notice that the Join() call to InstallPath doesn't change
PartitionDir(), while does change the result of Rel().
p := PathForModuleInstall(ctx, "foo", "bar")
p.PartitionDir() is out/soong/host/linux-x86
p.Rel() is foo/bar
q := p.Join(ctx, "baz")
q.PartitionDir() is still out/soong/host/linux-x86
q.Rel() now returns baz
Bug: N/A
Test: m nothing
Change-Id: I916bb1c782a4bfe0fbd4854e349cd2a2a42f56b6
2020-10-20 11:23:33 +02:00
|
|
|
// partitionDir is the part of the InstallPath that is automatically determined according to the context.
|
|
|
|
// For example, it is host/<os>-<arch> for host modules, and target/product/<device>/<partition> for device modules.
|
|
|
|
partitionDir string
|
|
|
|
|
2021-10-26 00:39:01 +02:00
|
|
|
partition string
|
|
|
|
|
InstallPath keeps its partition dir
This change introduces the concept of partition dir for InstallPaths.
It's the path to the partition where the InstallPath is rooted at. For
example, it's out/soong/target/product/<device>/<partitoon> for paths
created for device modules. For host modules, it is defined as
out/soong/host/<host_os>-<host_arch>.
The partition dir is obtained using the new PartitionDir() function.
Another change is that a freshly created InstallPath (usually via
PathForModuleInstall) is the result of joining PartitionDir() and the
remaining path elements. For example, PathForModuleInstall(ctx, "foo",
"bar").Rel() now returns "foo/bar". Previously, that call returned the
relative path from config.buildDir() ("out/soong"). This change is in
line with the behavior of other path-creating functions like
PathForModuleSrc where Rel() returns the path relative to the
contextually determined path like the module source directory.
Notice that the Join() call to InstallPath doesn't change
PartitionDir(), while does change the result of Rel().
p := PathForModuleInstall(ctx, "foo", "bar")
p.PartitionDir() is out/soong/host/linux-x86
p.Rel() is foo/bar
q := p.Join(ctx, "baz")
q.PartitionDir() is still out/soong/host/linux-x86
q.Rel() now returns baz
Bug: N/A
Test: m nothing
Change-Id: I916bb1c782a4bfe0fbd4854e349cd2a2a42f56b6
2020-10-20 11:23:33 +02:00
|
|
|
// makePath indicates whether this path is for Soong (false) or Make (true).
|
|
|
|
makePath bool
|
2019-10-02 07:05:35 +02:00
|
|
|
}
|
|
|
|
|
2021-03-24 11:18:18 +01:00
|
|
|
// Will panic if called from outside a test environment.
|
|
|
|
func ensureTestOnly() {
|
2021-03-27 19:54:49 +01:00
|
|
|
if PrefixInList(os.Args, "-test.") {
|
2021-03-24 11:18:18 +01:00
|
|
|
return
|
|
|
|
}
|
2021-03-27 19:54:49 +01:00
|
|
|
panic(fmt.Errorf("Not in test. Command line:\n %s", strings.Join(os.Args, "\n ")))
|
2021-03-24 11:18:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p InstallPath) RelativeToTop() Path {
|
|
|
|
ensureTestOnly()
|
2021-08-26 15:07:24 +02:00
|
|
|
p.soongOutDir = OutSoongDir
|
2021-03-24 11:18:18 +01:00
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2021-08-26 15:07:24 +02:00
|
|
|
func (p InstallPath) getSoongOutDir() string {
|
|
|
|
return p.soongOutDir
|
2019-12-10 14:41:51 +01:00
|
|
|
}
|
|
|
|
|
2020-11-27 12:37:28 +01:00
|
|
|
func (p InstallPath) ReplaceExtension(ctx PathContext, ext string) OutputPath {
|
|
|
|
panic("Not implemented")
|
|
|
|
}
|
|
|
|
|
2019-12-10 14:41:51 +01:00
|
|
|
var _ Path = InstallPath{}
|
|
|
|
var _ WritablePath = InstallPath{}
|
|
|
|
|
2019-10-02 07:05:35 +02:00
|
|
|
func (p InstallPath) writablePath() {}
|
|
|
|
|
|
|
|
func (p InstallPath) String() string {
|
InstallPath keeps its partition dir
This change introduces the concept of partition dir for InstallPaths.
It's the path to the partition where the InstallPath is rooted at. For
example, it's out/soong/target/product/<device>/<partitoon> for paths
created for device modules. For host modules, it is defined as
out/soong/host/<host_os>-<host_arch>.
The partition dir is obtained using the new PartitionDir() function.
Another change is that a freshly created InstallPath (usually via
PathForModuleInstall) is the result of joining PartitionDir() and the
remaining path elements. For example, PathForModuleInstall(ctx, "foo",
"bar").Rel() now returns "foo/bar". Previously, that call returned the
relative path from config.buildDir() ("out/soong"). This change is in
line with the behavior of other path-creating functions like
PathForModuleSrc where Rel() returns the path relative to the
contextually determined path like the module source directory.
Notice that the Join() call to InstallPath doesn't change
PartitionDir(), while does change the result of Rel().
p := PathForModuleInstall(ctx, "foo", "bar")
p.PartitionDir() is out/soong/host/linux-x86
p.Rel() is foo/bar
q := p.Join(ctx, "baz")
q.PartitionDir() is still out/soong/host/linux-x86
q.Rel() now returns baz
Bug: N/A
Test: m nothing
Change-Id: I916bb1c782a4bfe0fbd4854e349cd2a2a42f56b6
2020-10-20 11:23:33 +02:00
|
|
|
if p.makePath {
|
|
|
|
// Make path starts with out/ instead of out/soong.
|
2021-08-26 15:07:24 +02:00
|
|
|
return filepath.Join(p.soongOutDir, "../", p.path)
|
InstallPath keeps its partition dir
This change introduces the concept of partition dir for InstallPaths.
It's the path to the partition where the InstallPath is rooted at. For
example, it's out/soong/target/product/<device>/<partitoon> for paths
created for device modules. For host modules, it is defined as
out/soong/host/<host_os>-<host_arch>.
The partition dir is obtained using the new PartitionDir() function.
Another change is that a freshly created InstallPath (usually via
PathForModuleInstall) is the result of joining PartitionDir() and the
remaining path elements. For example, PathForModuleInstall(ctx, "foo",
"bar").Rel() now returns "foo/bar". Previously, that call returned the
relative path from config.buildDir() ("out/soong"). This change is in
line with the behavior of other path-creating functions like
PathForModuleSrc where Rel() returns the path relative to the
contextually determined path like the module source directory.
Notice that the Join() call to InstallPath doesn't change
PartitionDir(), while does change the result of Rel().
p := PathForModuleInstall(ctx, "foo", "bar")
p.PartitionDir() is out/soong/host/linux-x86
p.Rel() is foo/bar
q := p.Join(ctx, "baz")
q.PartitionDir() is still out/soong/host/linux-x86
q.Rel() now returns baz
Bug: N/A
Test: m nothing
Change-Id: I916bb1c782a4bfe0fbd4854e349cd2a2a42f56b6
2020-10-20 11:23:33 +02:00
|
|
|
} else {
|
2021-08-26 15:07:24 +02:00
|
|
|
return filepath.Join(p.soongOutDir, p.path)
|
InstallPath keeps its partition dir
This change introduces the concept of partition dir for InstallPaths.
It's the path to the partition where the InstallPath is rooted at. For
example, it's out/soong/target/product/<device>/<partitoon> for paths
created for device modules. For host modules, it is defined as
out/soong/host/<host_os>-<host_arch>.
The partition dir is obtained using the new PartitionDir() function.
Another change is that a freshly created InstallPath (usually via
PathForModuleInstall) is the result of joining PartitionDir() and the
remaining path elements. For example, PathForModuleInstall(ctx, "foo",
"bar").Rel() now returns "foo/bar". Previously, that call returned the
relative path from config.buildDir() ("out/soong"). This change is in
line with the behavior of other path-creating functions like
PathForModuleSrc where Rel() returns the path relative to the
contextually determined path like the module source directory.
Notice that the Join() call to InstallPath doesn't change
PartitionDir(), while does change the result of Rel().
p := PathForModuleInstall(ctx, "foo", "bar")
p.PartitionDir() is out/soong/host/linux-x86
p.Rel() is foo/bar
q := p.Join(ctx, "baz")
q.PartitionDir() is still out/soong/host/linux-x86
q.Rel() now returns baz
Bug: N/A
Test: m nothing
Change-Id: I916bb1c782a4bfe0fbd4854e349cd2a2a42f56b6
2020-10-20 11:23:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// PartitionDir returns the path to the partition where the install path is rooted at. It is
|
|
|
|
// out/soong/target/product/<device>/<partition> for device modules, and out/soong/host/<os>-<arch> for host modules.
|
|
|
|
// The ./soong is dropped if the install path is for Make.
|
|
|
|
func (p InstallPath) PartitionDir() string {
|
|
|
|
if p.makePath {
|
2021-08-26 15:07:24 +02:00
|
|
|
return filepath.Join(p.soongOutDir, "../", p.partitionDir)
|
InstallPath keeps its partition dir
This change introduces the concept of partition dir for InstallPaths.
It's the path to the partition where the InstallPath is rooted at. For
example, it's out/soong/target/product/<device>/<partitoon> for paths
created for device modules. For host modules, it is defined as
out/soong/host/<host_os>-<host_arch>.
The partition dir is obtained using the new PartitionDir() function.
Another change is that a freshly created InstallPath (usually via
PathForModuleInstall) is the result of joining PartitionDir() and the
remaining path elements. For example, PathForModuleInstall(ctx, "foo",
"bar").Rel() now returns "foo/bar". Previously, that call returned the
relative path from config.buildDir() ("out/soong"). This change is in
line with the behavior of other path-creating functions like
PathForModuleSrc where Rel() returns the path relative to the
contextually determined path like the module source directory.
Notice that the Join() call to InstallPath doesn't change
PartitionDir(), while does change the result of Rel().
p := PathForModuleInstall(ctx, "foo", "bar")
p.PartitionDir() is out/soong/host/linux-x86
p.Rel() is foo/bar
q := p.Join(ctx, "baz")
q.PartitionDir() is still out/soong/host/linux-x86
q.Rel() now returns baz
Bug: N/A
Test: m nothing
Change-Id: I916bb1c782a4bfe0fbd4854e349cd2a2a42f56b6
2020-10-20 11:23:33 +02:00
|
|
|
} else {
|
2021-08-26 15:07:24 +02:00
|
|
|
return filepath.Join(p.soongOutDir, p.partitionDir)
|
InstallPath keeps its partition dir
This change introduces the concept of partition dir for InstallPaths.
It's the path to the partition where the InstallPath is rooted at. For
example, it's out/soong/target/product/<device>/<partitoon> for paths
created for device modules. For host modules, it is defined as
out/soong/host/<host_os>-<host_arch>.
The partition dir is obtained using the new PartitionDir() function.
Another change is that a freshly created InstallPath (usually via
PathForModuleInstall) is the result of joining PartitionDir() and the
remaining path elements. For example, PathForModuleInstall(ctx, "foo",
"bar").Rel() now returns "foo/bar". Previously, that call returned the
relative path from config.buildDir() ("out/soong"). This change is in
line with the behavior of other path-creating functions like
PathForModuleSrc where Rel() returns the path relative to the
contextually determined path like the module source directory.
Notice that the Join() call to InstallPath doesn't change
PartitionDir(), while does change the result of Rel().
p := PathForModuleInstall(ctx, "foo", "bar")
p.PartitionDir() is out/soong/host/linux-x86
p.Rel() is foo/bar
q := p.Join(ctx, "baz")
q.PartitionDir() is still out/soong/host/linux-x86
q.Rel() now returns baz
Bug: N/A
Test: m nothing
Change-Id: I916bb1c782a4bfe0fbd4854e349cd2a2a42f56b6
2020-10-20 11:23:33 +02:00
|
|
|
}
|
2019-10-02 07:05:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Join creates a new InstallPath with paths... joined with the current path. The
|
|
|
|
// provided paths... may not use '..' to escape from the current path.
|
|
|
|
func (p InstallPath) Join(ctx PathContext, paths ...string) InstallPath {
|
|
|
|
path, err := validatePath(paths...)
|
|
|
|
if err != nil {
|
|
|
|
reportPathError(ctx, err)
|
|
|
|
}
|
|
|
|
return p.withRel(path)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p InstallPath) withRel(rel string) InstallPath {
|
|
|
|
p.basePath = p.basePath.withRel(rel)
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2021-11-12 03:59:15 +01:00
|
|
|
// Deprecated: ToMakePath is a noop, PathForModuleInstall always returns Make paths when building
|
|
|
|
// embedded in Make.
|
2019-10-03 01:01:35 +02:00
|
|
|
func (p InstallPath) ToMakePath() InstallPath {
|
InstallPath keeps its partition dir
This change introduces the concept of partition dir for InstallPaths.
It's the path to the partition where the InstallPath is rooted at. For
example, it's out/soong/target/product/<device>/<partitoon> for paths
created for device modules. For host modules, it is defined as
out/soong/host/<host_os>-<host_arch>.
The partition dir is obtained using the new PartitionDir() function.
Another change is that a freshly created InstallPath (usually via
PathForModuleInstall) is the result of joining PartitionDir() and the
remaining path elements. For example, PathForModuleInstall(ctx, "foo",
"bar").Rel() now returns "foo/bar". Previously, that call returned the
relative path from config.buildDir() ("out/soong"). This change is in
line with the behavior of other path-creating functions like
PathForModuleSrc where Rel() returns the path relative to the
contextually determined path like the module source directory.
Notice that the Join() call to InstallPath doesn't change
PartitionDir(), while does change the result of Rel().
p := PathForModuleInstall(ctx, "foo", "bar")
p.PartitionDir() is out/soong/host/linux-x86
p.Rel() is foo/bar
q := p.Join(ctx, "baz")
q.PartitionDir() is still out/soong/host/linux-x86
q.Rel() now returns baz
Bug: N/A
Test: m nothing
Change-Id: I916bb1c782a4bfe0fbd4854e349cd2a2a42f56b6
2020-10-20 11:23:33 +02:00
|
|
|
p.makePath = true
|
2019-10-03 01:01:35 +02:00
|
|
|
return p
|
2019-10-02 07:05:35 +02:00
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
// PathForModuleInstall returns a Path representing the install path for the
|
|
|
|
// module appended with paths...
|
2019-10-02 07:05:35 +02:00
|
|
|
func PathForModuleInstall(ctx ModuleInstallPathContext, pathComponents ...string) InstallPath {
|
2021-06-03 21:36:41 +02:00
|
|
|
os, arch := osAndArch(ctx)
|
|
|
|
partition := modulePartition(ctx, os)
|
|
|
|
return makePathForInstall(ctx, os, arch, partition, ctx.Debug(), pathComponents...)
|
|
|
|
}
|
|
|
|
|
2021-11-03 22:08:20 +01:00
|
|
|
// PathForHostDexInstall returns an InstallPath representing the install path for the
|
|
|
|
// module appended with paths...
|
|
|
|
func PathForHostDexInstall(ctx ModuleInstallPathContext, pathComponents ...string) InstallPath {
|
|
|
|
return makePathForInstall(ctx, ctx.Config().BuildOS, ctx.Config().BuildArch, "", ctx.Debug(), pathComponents...)
|
|
|
|
}
|
|
|
|
|
2021-06-03 21:36:41 +02:00
|
|
|
// PathForModuleInPartitionInstall is similar to PathForModuleInstall but partition is provided by the caller
|
|
|
|
func PathForModuleInPartitionInstall(ctx ModuleInstallPathContext, partition string, pathComponents ...string) InstallPath {
|
|
|
|
os, arch := osAndArch(ctx)
|
|
|
|
return makePathForInstall(ctx, os, arch, partition, ctx.Debug(), pathComponents...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func osAndArch(ctx ModuleInstallPathContext) (OsType, ArchType) {
|
2020-02-11 00:29:54 +01:00
|
|
|
os := ctx.Os()
|
2020-09-01 05:37:45 +02:00
|
|
|
arch := ctx.Arch().ArchType
|
|
|
|
forceOS, forceArch := ctx.InstallForceOS()
|
|
|
|
if forceOS != nil {
|
2020-02-11 00:29:54 +01:00
|
|
|
os = *forceOS
|
|
|
|
}
|
2020-09-01 05:37:45 +02:00
|
|
|
if forceArch != nil {
|
|
|
|
arch = *forceArch
|
|
|
|
}
|
2021-06-03 21:36:41 +02:00
|
|
|
return os, arch
|
|
|
|
}
|
2020-02-13 22:20:11 +01:00
|
|
|
|
2021-06-03 21:36:41 +02:00
|
|
|
func makePathForInstall(ctx ModuleInstallPathContext, os OsType, arch ArchType, partition string, debug bool, pathComponents ...string) InstallPath {
|
|
|
|
ret := pathForInstall(ctx, os, arch, partition, debug, pathComponents...)
|
2020-02-13 22:20:11 +01:00
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2020-09-01 05:37:45 +02:00
|
|
|
func pathForInstall(ctx PathContext, os OsType, arch ArchType, partition string, debug bool,
|
2020-02-13 22:20:11 +01:00
|
|
|
pathComponents ...string) InstallPath {
|
|
|
|
|
InstallPath keeps its partition dir
This change introduces the concept of partition dir for InstallPaths.
It's the path to the partition where the InstallPath is rooted at. For
example, it's out/soong/target/product/<device>/<partitoon> for paths
created for device modules. For host modules, it is defined as
out/soong/host/<host_os>-<host_arch>.
The partition dir is obtained using the new PartitionDir() function.
Another change is that a freshly created InstallPath (usually via
PathForModuleInstall) is the result of joining PartitionDir() and the
remaining path elements. For example, PathForModuleInstall(ctx, "foo",
"bar").Rel() now returns "foo/bar". Previously, that call returned the
relative path from config.buildDir() ("out/soong"). This change is in
line with the behavior of other path-creating functions like
PathForModuleSrc where Rel() returns the path relative to the
contextually determined path like the module source directory.
Notice that the Join() call to InstallPath doesn't change
PartitionDir(), while does change the result of Rel().
p := PathForModuleInstall(ctx, "foo", "bar")
p.PartitionDir() is out/soong/host/linux-x86
p.Rel() is foo/bar
q := p.Join(ctx, "baz")
q.PartitionDir() is still out/soong/host/linux-x86
q.Rel() now returns baz
Bug: N/A
Test: m nothing
Change-Id: I916bb1c782a4bfe0fbd4854e349cd2a2a42f56b6
2020-10-20 11:23:33 +02:00
|
|
|
var partionPaths []string
|
2020-02-13 22:20:11 +01:00
|
|
|
|
2020-02-11 00:29:54 +01:00
|
|
|
if os.Class == Device {
|
InstallPath keeps its partition dir
This change introduces the concept of partition dir for InstallPaths.
It's the path to the partition where the InstallPath is rooted at. For
example, it's out/soong/target/product/<device>/<partitoon> for paths
created for device modules. For host modules, it is defined as
out/soong/host/<host_os>-<host_arch>.
The partition dir is obtained using the new PartitionDir() function.
Another change is that a freshly created InstallPath (usually via
PathForModuleInstall) is the result of joining PartitionDir() and the
remaining path elements. For example, PathForModuleInstall(ctx, "foo",
"bar").Rel() now returns "foo/bar". Previously, that call returned the
relative path from config.buildDir() ("out/soong"). This change is in
line with the behavior of other path-creating functions like
PathForModuleSrc where Rel() returns the path relative to the
contextually determined path like the module source directory.
Notice that the Join() call to InstallPath doesn't change
PartitionDir(), while does change the result of Rel().
p := PathForModuleInstall(ctx, "foo", "bar")
p.PartitionDir() is out/soong/host/linux-x86
p.Rel() is foo/bar
q := p.Join(ctx, "baz")
q.PartitionDir() is still out/soong/host/linux-x86
q.Rel() now returns baz
Bug: N/A
Test: m nothing
Change-Id: I916bb1c782a4bfe0fbd4854e349cd2a2a42f56b6
2020-10-20 11:23:33 +02:00
|
|
|
partionPaths = []string{"target", "product", ctx.Config().DeviceName(), partition}
|
2015-09-24 00:26:20 +02:00
|
|
|
} else {
|
2020-09-01 05:37:45 +02:00
|
|
|
osName := os.String()
|
2021-07-24 00:23:07 +02:00
|
|
|
if os == Linux || os == LinuxMusl {
|
2020-09-01 05:37:45 +02:00
|
|
|
// instead of linux_glibc
|
|
|
|
osName = "linux"
|
|
|
|
}
|
|
|
|
// SOONG_HOST_OUT is set to out/host/$(HOST_OS)-$(HOST_PREBUILT_ARCH)
|
|
|
|
// and HOST_PREBUILT_ARCH is forcibly set to x86 even on x86_64 hosts. We don't seem
|
|
|
|
// to have a plan to fix it (see the comment in build/make/core/envsetup.mk).
|
|
|
|
// Let's keep using x86 for the existing cases until we have a need to support
|
|
|
|
// other architectures.
|
|
|
|
archName := arch.String()
|
|
|
|
if os.Class == Host && (arch == X86_64 || arch == Common) {
|
|
|
|
archName = "x86"
|
2017-09-22 21:28:24 +02:00
|
|
|
}
|
InstallPath keeps its partition dir
This change introduces the concept of partition dir for InstallPaths.
It's the path to the partition where the InstallPath is rooted at. For
example, it's out/soong/target/product/<device>/<partitoon> for paths
created for device modules. For host modules, it is defined as
out/soong/host/<host_os>-<host_arch>.
The partition dir is obtained using the new PartitionDir() function.
Another change is that a freshly created InstallPath (usually via
PathForModuleInstall) is the result of joining PartitionDir() and the
remaining path elements. For example, PathForModuleInstall(ctx, "foo",
"bar").Rel() now returns "foo/bar". Previously, that call returned the
relative path from config.buildDir() ("out/soong"). This change is in
line with the behavior of other path-creating functions like
PathForModuleSrc where Rel() returns the path relative to the
contextually determined path like the module source directory.
Notice that the Join() call to InstallPath doesn't change
PartitionDir(), while does change the result of Rel().
p := PathForModuleInstall(ctx, "foo", "bar")
p.PartitionDir() is out/soong/host/linux-x86
p.Rel() is foo/bar
q := p.Join(ctx, "baz")
q.PartitionDir() is still out/soong/host/linux-x86
q.Rel() now returns baz
Bug: N/A
Test: m nothing
Change-Id: I916bb1c782a4bfe0fbd4854e349cd2a2a42f56b6
2020-10-20 11:23:33 +02:00
|
|
|
partionPaths = []string{"host", osName + "-" + archName, partition}
|
2015-09-24 00:26:20 +02:00
|
|
|
}
|
2020-02-13 22:20:11 +01:00
|
|
|
if debug {
|
InstallPath keeps its partition dir
This change introduces the concept of partition dir for InstallPaths.
It's the path to the partition where the InstallPath is rooted at. For
example, it's out/soong/target/product/<device>/<partitoon> for paths
created for device modules. For host modules, it is defined as
out/soong/host/<host_os>-<host_arch>.
The partition dir is obtained using the new PartitionDir() function.
Another change is that a freshly created InstallPath (usually via
PathForModuleInstall) is the result of joining PartitionDir() and the
remaining path elements. For example, PathForModuleInstall(ctx, "foo",
"bar").Rel() now returns "foo/bar". Previously, that call returned the
relative path from config.buildDir() ("out/soong"). This change is in
line with the behavior of other path-creating functions like
PathForModuleSrc where Rel() returns the path relative to the
contextually determined path like the module source directory.
Notice that the Join() call to InstallPath doesn't change
PartitionDir(), while does change the result of Rel().
p := PathForModuleInstall(ctx, "foo", "bar")
p.PartitionDir() is out/soong/host/linux-x86
p.Rel() is foo/bar
q := p.Join(ctx, "baz")
q.PartitionDir() is still out/soong/host/linux-x86
q.Rel() now returns baz
Bug: N/A
Test: m nothing
Change-Id: I916bb1c782a4bfe0fbd4854e349cd2a2a42f56b6
2020-10-20 11:23:33 +02:00
|
|
|
partionPaths = append([]string{"debug"}, partionPaths...)
|
2015-12-21 23:55:28 +01:00
|
|
|
}
|
2019-10-02 07:05:35 +02:00
|
|
|
|
InstallPath keeps its partition dir
This change introduces the concept of partition dir for InstallPaths.
It's the path to the partition where the InstallPath is rooted at. For
example, it's out/soong/target/product/<device>/<partitoon> for paths
created for device modules. For host modules, it is defined as
out/soong/host/<host_os>-<host_arch>.
The partition dir is obtained using the new PartitionDir() function.
Another change is that a freshly created InstallPath (usually via
PathForModuleInstall) is the result of joining PartitionDir() and the
remaining path elements. For example, PathForModuleInstall(ctx, "foo",
"bar").Rel() now returns "foo/bar". Previously, that call returned the
relative path from config.buildDir() ("out/soong"). This change is in
line with the behavior of other path-creating functions like
PathForModuleSrc where Rel() returns the path relative to the
contextually determined path like the module source directory.
Notice that the Join() call to InstallPath doesn't change
PartitionDir(), while does change the result of Rel().
p := PathForModuleInstall(ctx, "foo", "bar")
p.PartitionDir() is out/soong/host/linux-x86
p.Rel() is foo/bar
q := p.Join(ctx, "baz")
q.PartitionDir() is still out/soong/host/linux-x86
q.Rel() now returns baz
Bug: N/A
Test: m nothing
Change-Id: I916bb1c782a4bfe0fbd4854e349cd2a2a42f56b6
2020-10-20 11:23:33 +02:00
|
|
|
partionPath, err := validatePath(partionPaths...)
|
2019-10-02 07:05:35 +02:00
|
|
|
if err != nil {
|
|
|
|
reportPathError(ctx, err)
|
|
|
|
}
|
2019-10-03 01:01:35 +02:00
|
|
|
|
InstallPath keeps its partition dir
This change introduces the concept of partition dir for InstallPaths.
It's the path to the partition where the InstallPath is rooted at. For
example, it's out/soong/target/product/<device>/<partitoon> for paths
created for device modules. For host modules, it is defined as
out/soong/host/<host_os>-<host_arch>.
The partition dir is obtained using the new PartitionDir() function.
Another change is that a freshly created InstallPath (usually via
PathForModuleInstall) is the result of joining PartitionDir() and the
remaining path elements. For example, PathForModuleInstall(ctx, "foo",
"bar").Rel() now returns "foo/bar". Previously, that call returned the
relative path from config.buildDir() ("out/soong"). This change is in
line with the behavior of other path-creating functions like
PathForModuleSrc where Rel() returns the path relative to the
contextually determined path like the module source directory.
Notice that the Join() call to InstallPath doesn't change
PartitionDir(), while does change the result of Rel().
p := PathForModuleInstall(ctx, "foo", "bar")
p.PartitionDir() is out/soong/host/linux-x86
p.Rel() is foo/bar
q := p.Join(ctx, "baz")
q.PartitionDir() is still out/soong/host/linux-x86
q.Rel() now returns baz
Bug: N/A
Test: m nothing
Change-Id: I916bb1c782a4bfe0fbd4854e349cd2a2a42f56b6
2020-10-20 11:23:33 +02:00
|
|
|
base := InstallPath{
|
2021-03-24 10:24:59 +01:00
|
|
|
basePath: basePath{partionPath, ""},
|
2021-08-26 15:07:24 +02:00
|
|
|
soongOutDir: ctx.Config().soongOutDir,
|
InstallPath keeps its partition dir
This change introduces the concept of partition dir for InstallPaths.
It's the path to the partition where the InstallPath is rooted at. For
example, it's out/soong/target/product/<device>/<partitoon> for paths
created for device modules. For host modules, it is defined as
out/soong/host/<host_os>-<host_arch>.
The partition dir is obtained using the new PartitionDir() function.
Another change is that a freshly created InstallPath (usually via
PathForModuleInstall) is the result of joining PartitionDir() and the
remaining path elements. For example, PathForModuleInstall(ctx, "foo",
"bar").Rel() now returns "foo/bar". Previously, that call returned the
relative path from config.buildDir() ("out/soong"). This change is in
line with the behavior of other path-creating functions like
PathForModuleSrc where Rel() returns the path relative to the
contextually determined path like the module source directory.
Notice that the Join() call to InstallPath doesn't change
PartitionDir(), while does change the result of Rel().
p := PathForModuleInstall(ctx, "foo", "bar")
p.PartitionDir() is out/soong/host/linux-x86
p.Rel() is foo/bar
q := p.Join(ctx, "baz")
q.PartitionDir() is still out/soong/host/linux-x86
q.Rel() now returns baz
Bug: N/A
Test: m nothing
Change-Id: I916bb1c782a4bfe0fbd4854e349cd2a2a42f56b6
2020-10-20 11:23:33 +02:00
|
|
|
partitionDir: partionPath,
|
2021-10-26 00:39:01 +02:00
|
|
|
partition: partition,
|
2021-11-12 03:59:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ctx.Config().KatiEnabled() {
|
|
|
|
base.makePath = true
|
InstallPath keeps its partition dir
This change introduces the concept of partition dir for InstallPaths.
It's the path to the partition where the InstallPath is rooted at. For
example, it's out/soong/target/product/<device>/<partitoon> for paths
created for device modules. For host modules, it is defined as
out/soong/host/<host_os>-<host_arch>.
The partition dir is obtained using the new PartitionDir() function.
Another change is that a freshly created InstallPath (usually via
PathForModuleInstall) is the result of joining PartitionDir() and the
remaining path elements. For example, PathForModuleInstall(ctx, "foo",
"bar").Rel() now returns "foo/bar". Previously, that call returned the
relative path from config.buildDir() ("out/soong"). This change is in
line with the behavior of other path-creating functions like
PathForModuleSrc where Rel() returns the path relative to the
contextually determined path like the module source directory.
Notice that the Join() call to InstallPath doesn't change
PartitionDir(), while does change the result of Rel().
p := PathForModuleInstall(ctx, "foo", "bar")
p.PartitionDir() is out/soong/host/linux-x86
p.Rel() is foo/bar
q := p.Join(ctx, "baz")
q.PartitionDir() is still out/soong/host/linux-x86
q.Rel() now returns baz
Bug: N/A
Test: m nothing
Change-Id: I916bb1c782a4bfe0fbd4854e349cd2a2a42f56b6
2020-10-20 11:23:33 +02:00
|
|
|
}
|
2019-10-03 01:01:35 +02:00
|
|
|
|
InstallPath keeps its partition dir
This change introduces the concept of partition dir for InstallPaths.
It's the path to the partition where the InstallPath is rooted at. For
example, it's out/soong/target/product/<device>/<partitoon> for paths
created for device modules. For host modules, it is defined as
out/soong/host/<host_os>-<host_arch>.
The partition dir is obtained using the new PartitionDir() function.
Another change is that a freshly created InstallPath (usually via
PathForModuleInstall) is the result of joining PartitionDir() and the
remaining path elements. For example, PathForModuleInstall(ctx, "foo",
"bar").Rel() now returns "foo/bar". Previously, that call returned the
relative path from config.buildDir() ("out/soong"). This change is in
line with the behavior of other path-creating functions like
PathForModuleSrc where Rel() returns the path relative to the
contextually determined path like the module source directory.
Notice that the Join() call to InstallPath doesn't change
PartitionDir(), while does change the result of Rel().
p := PathForModuleInstall(ctx, "foo", "bar")
p.PartitionDir() is out/soong/host/linux-x86
p.Rel() is foo/bar
q := p.Join(ctx, "baz")
q.PartitionDir() is still out/soong/host/linux-x86
q.Rel() now returns baz
Bug: N/A
Test: m nothing
Change-Id: I916bb1c782a4bfe0fbd4854e349cd2a2a42f56b6
2020-10-20 11:23:33 +02:00
|
|
|
return base.Join(ctx, pathComponents...)
|
2019-10-02 07:05:35 +02:00
|
|
|
}
|
|
|
|
|
2020-02-27 14:45:35 +01:00
|
|
|
func pathForNdkOrSdkInstall(ctx PathContext, prefix string, paths []string) InstallPath {
|
InstallPath keeps its partition dir
This change introduces the concept of partition dir for InstallPaths.
It's the path to the partition where the InstallPath is rooted at. For
example, it's out/soong/target/product/<device>/<partitoon> for paths
created for device modules. For host modules, it is defined as
out/soong/host/<host_os>-<host_arch>.
The partition dir is obtained using the new PartitionDir() function.
Another change is that a freshly created InstallPath (usually via
PathForModuleInstall) is the result of joining PartitionDir() and the
remaining path elements. For example, PathForModuleInstall(ctx, "foo",
"bar").Rel() now returns "foo/bar". Previously, that call returned the
relative path from config.buildDir() ("out/soong"). This change is in
line with the behavior of other path-creating functions like
PathForModuleSrc where Rel() returns the path relative to the
contextually determined path like the module source directory.
Notice that the Join() call to InstallPath doesn't change
PartitionDir(), while does change the result of Rel().
p := PathForModuleInstall(ctx, "foo", "bar")
p.PartitionDir() is out/soong/host/linux-x86
p.Rel() is foo/bar
q := p.Join(ctx, "baz")
q.PartitionDir() is still out/soong/host/linux-x86
q.Rel() now returns baz
Bug: N/A
Test: m nothing
Change-Id: I916bb1c782a4bfe0fbd4854e349cd2a2a42f56b6
2020-10-20 11:23:33 +02:00
|
|
|
base := InstallPath{
|
2021-03-24 10:24:59 +01:00
|
|
|
basePath: basePath{prefix, ""},
|
2021-08-26 15:07:24 +02:00
|
|
|
soongOutDir: ctx.Config().soongOutDir,
|
InstallPath keeps its partition dir
This change introduces the concept of partition dir for InstallPaths.
It's the path to the partition where the InstallPath is rooted at. For
example, it's out/soong/target/product/<device>/<partitoon> for paths
created for device modules. For host modules, it is defined as
out/soong/host/<host_os>-<host_arch>.
The partition dir is obtained using the new PartitionDir() function.
Another change is that a freshly created InstallPath (usually via
PathForModuleInstall) is the result of joining PartitionDir() and the
remaining path elements. For example, PathForModuleInstall(ctx, "foo",
"bar").Rel() now returns "foo/bar". Previously, that call returned the
relative path from config.buildDir() ("out/soong"). This change is in
line with the behavior of other path-creating functions like
PathForModuleSrc where Rel() returns the path relative to the
contextually determined path like the module source directory.
Notice that the Join() call to InstallPath doesn't change
PartitionDir(), while does change the result of Rel().
p := PathForModuleInstall(ctx, "foo", "bar")
p.PartitionDir() is out/soong/host/linux-x86
p.Rel() is foo/bar
q := p.Join(ctx, "baz")
q.PartitionDir() is still out/soong/host/linux-x86
q.Rel() now returns baz
Bug: N/A
Test: m nothing
Change-Id: I916bb1c782a4bfe0fbd4854e349cd2a2a42f56b6
2020-10-20 11:23:33 +02:00
|
|
|
partitionDir: prefix,
|
|
|
|
makePath: false,
|
2019-10-02 07:05:35 +02:00
|
|
|
}
|
InstallPath keeps its partition dir
This change introduces the concept of partition dir for InstallPaths.
It's the path to the partition where the InstallPath is rooted at. For
example, it's out/soong/target/product/<device>/<partitoon> for paths
created for device modules. For host modules, it is defined as
out/soong/host/<host_os>-<host_arch>.
The partition dir is obtained using the new PartitionDir() function.
Another change is that a freshly created InstallPath (usually via
PathForModuleInstall) is the result of joining PartitionDir() and the
remaining path elements. For example, PathForModuleInstall(ctx, "foo",
"bar").Rel() now returns "foo/bar". Previously, that call returned the
relative path from config.buildDir() ("out/soong"). This change is in
line with the behavior of other path-creating functions like
PathForModuleSrc where Rel() returns the path relative to the
contextually determined path like the module source directory.
Notice that the Join() call to InstallPath doesn't change
PartitionDir(), while does change the result of Rel().
p := PathForModuleInstall(ctx, "foo", "bar")
p.PartitionDir() is out/soong/host/linux-x86
p.Rel() is foo/bar
q := p.Join(ctx, "baz")
q.PartitionDir() is still out/soong/host/linux-x86
q.Rel() now returns baz
Bug: N/A
Test: m nothing
Change-Id: I916bb1c782a4bfe0fbd4854e349cd2a2a42f56b6
2020-10-20 11:23:33 +02:00
|
|
|
return base.Join(ctx, paths...)
|
2015-09-24 00:26:20 +02:00
|
|
|
}
|
|
|
|
|
2020-02-27 14:45:35 +01:00
|
|
|
func PathForNdkInstall(ctx PathContext, paths ...string) InstallPath {
|
|
|
|
return pathForNdkOrSdkInstall(ctx, "ndk", paths)
|
|
|
|
}
|
|
|
|
|
|
|
|
func PathForMainlineSdksInstall(ctx PathContext, paths ...string) InstallPath {
|
|
|
|
return pathForNdkOrSdkInstall(ctx, "mainline-sdks", paths)
|
|
|
|
}
|
|
|
|
|
2019-10-02 07:05:35 +02:00
|
|
|
func InstallPathToOnDevicePath(ctx PathContext, path InstallPath) string {
|
2021-10-26 00:39:01 +02:00
|
|
|
rel := Rel(ctx, strings.TrimSuffix(path.PartitionDir(), path.partition), path.String())
|
2018-11-12 19:13:39 +01:00
|
|
|
return "/" + rel
|
|
|
|
}
|
|
|
|
|
2020-02-11 00:29:54 +01:00
|
|
|
func modulePartition(ctx ModuleInstallPathContext, os OsType) string {
|
2018-11-12 19:13:39 +01:00
|
|
|
var partition string
|
2020-02-11 00:29:54 +01:00
|
|
|
if ctx.InstallInTestcases() {
|
|
|
|
// "testcases" install directory can be used for host or device modules.
|
2019-09-11 19:25:18 +02:00
|
|
|
partition = "testcases"
|
2020-02-11 00:29:54 +01:00
|
|
|
} else if os.Class == Device {
|
|
|
|
if ctx.InstallInData() {
|
|
|
|
partition = "data"
|
|
|
|
} else if ctx.InstallInRamdisk() {
|
|
|
|
if ctx.DeviceConfig().BoardUsesRecoveryAsBoot() {
|
|
|
|
partition = "recovery/root/first_stage_ramdisk"
|
|
|
|
} else {
|
|
|
|
partition = "ramdisk"
|
|
|
|
}
|
|
|
|
if !ctx.InstallInRoot() {
|
|
|
|
partition += "/system"
|
|
|
|
}
|
2020-10-22 00:17:56 +02:00
|
|
|
} else if ctx.InstallInVendorRamdisk() {
|
2020-10-26 20:43:12 +01:00
|
|
|
// The module is only available after switching root into
|
|
|
|
// /first_stage_ramdisk. To expose the module before switching root
|
|
|
|
// on a device without a dedicated recovery partition, install the
|
|
|
|
// recovery variant.
|
2020-10-22 00:40:17 +02:00
|
|
|
if ctx.DeviceConfig().BoardMoveRecoveryResourcesToVendorBoot() {
|
2021-03-03 08:44:02 +01:00
|
|
|
partition = "vendor_ramdisk/first_stage_ramdisk"
|
2020-10-22 00:40:17 +02:00
|
|
|
} else {
|
2021-03-03 08:44:02 +01:00
|
|
|
partition = "vendor_ramdisk"
|
2020-10-22 00:40:17 +02:00
|
|
|
}
|
|
|
|
if !ctx.InstallInRoot() {
|
|
|
|
partition += "/system"
|
|
|
|
}
|
2021-04-08 14:13:22 +02:00
|
|
|
} else if ctx.InstallInDebugRamdisk() {
|
|
|
|
partition = "debug_ramdisk"
|
2020-02-11 00:29:54 +01:00
|
|
|
} else if ctx.InstallInRecovery() {
|
|
|
|
if ctx.InstallInRoot() {
|
|
|
|
partition = "recovery/root"
|
|
|
|
} else {
|
|
|
|
// the layout of recovery partion is the same as that of system partition
|
|
|
|
partition = "recovery/root/system"
|
|
|
|
}
|
|
|
|
} else if ctx.SocSpecific() {
|
|
|
|
partition = ctx.DeviceConfig().VendorPath()
|
|
|
|
} else if ctx.DeviceSpecific() {
|
|
|
|
partition = ctx.DeviceConfig().OdmPath()
|
|
|
|
} else if ctx.ProductSpecific() {
|
|
|
|
partition = ctx.DeviceConfig().ProductPath()
|
|
|
|
} else if ctx.SystemExtSpecific() {
|
|
|
|
partition = ctx.DeviceConfig().SystemExtPath()
|
|
|
|
} else if ctx.InstallInRoot() {
|
|
|
|
partition = "root"
|
2020-01-22 01:12:26 +01:00
|
|
|
} else {
|
2020-02-11 00:29:54 +01:00
|
|
|
partition = "system"
|
2020-01-22 01:12:26 +01:00
|
|
|
}
|
2020-02-11 00:29:54 +01:00
|
|
|
if ctx.InstallInSanitizerDir() {
|
|
|
|
partition = "data/asan/" + partition
|
2019-10-02 20:10:58 +02:00
|
|
|
}
|
2018-11-12 19:13:39 +01:00
|
|
|
}
|
|
|
|
return partition
|
|
|
|
}
|
|
|
|
|
2020-02-13 22:20:11 +01:00
|
|
|
type InstallPaths []InstallPath
|
|
|
|
|
|
|
|
// Paths returns the InstallPaths as a Paths
|
|
|
|
func (p InstallPaths) Paths() Paths {
|
|
|
|
if p == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
ret := make(Paths, len(p))
|
|
|
|
for i, path := range p {
|
|
|
|
ret[i] = path
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
// Strings returns the string forms of the install paths.
|
|
|
|
func (p InstallPaths) Strings() []string {
|
|
|
|
if p == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
ret := make([]string, len(p))
|
|
|
|
for i, path := range p {
|
|
|
|
ret[i] = path.String()
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
// validateSafePath validates a path that we trust (may contain ninja variables).
|
2015-12-21 23:57:11 +01:00
|
|
|
// Ensures that each path component does not attempt to leave its component.
|
2018-02-22 22:54:26 +01:00
|
|
|
func validateSafePath(pathComponents ...string) (string, error) {
|
2017-04-11 00:47:24 +02:00
|
|
|
for _, path := range pathComponents {
|
2015-12-21 23:57:11 +01:00
|
|
|
path := filepath.Clean(path)
|
|
|
|
if path == ".." || strings.HasPrefix(path, "../") || strings.HasPrefix(path, "/") {
|
2018-02-22 22:54:26 +01:00
|
|
|
return "", fmt.Errorf("Path is outside directory: %s", path)
|
2015-12-21 23:57:11 +01:00
|
|
|
}
|
|
|
|
}
|
2015-09-24 00:26:20 +02:00
|
|
|
// TODO: filepath.Join isn't necessarily correct with embedded ninja
|
|
|
|
// variables. '..' may remove the entire ninja variable, even if it
|
|
|
|
// will be expanded to multiple nested directories.
|
2018-02-22 22:54:26 +01:00
|
|
|
return filepath.Join(pathComponents...), nil
|
2015-09-24 00:26:20 +02:00
|
|
|
}
|
|
|
|
|
2015-12-21 23:57:11 +01:00
|
|
|
// validatePath validates that a path does not include ninja variables, and that
|
|
|
|
// each path component does not attempt to leave its component. Returns a joined
|
|
|
|
// version of each path component.
|
2018-02-22 22:54:26 +01:00
|
|
|
func validatePath(pathComponents ...string) (string, error) {
|
2017-04-11 00:47:24 +02:00
|
|
|
for _, path := range pathComponents {
|
2015-09-24 00:26:20 +02:00
|
|
|
if strings.Contains(path, "$") {
|
2018-02-22 22:54:26 +01:00
|
|
|
return "", fmt.Errorf("Path contains invalid character($): %s", path)
|
2015-09-24 00:26:20 +02:00
|
|
|
}
|
|
|
|
}
|
2018-02-22 22:54:26 +01:00
|
|
|
return validateSafePath(pathComponents...)
|
2015-07-15 03:55:36 +02:00
|
|
|
}
|
2017-05-09 22:34:34 +02:00
|
|
|
|
2017-11-29 02:34:01 +01:00
|
|
|
func PathForPhony(ctx PathContext, phony string) WritablePath {
|
|
|
|
if strings.ContainsAny(phony, "$/") {
|
2020-08-25 13:45:15 +02:00
|
|
|
ReportPathErrorf(ctx, "Phony target contains invalid character ($ or /): %s", phony)
|
2017-11-29 02:34:01 +01:00
|
|
|
}
|
2021-03-24 10:24:59 +01:00
|
|
|
return PhonyPath{basePath{phony, ""}}
|
2017-11-29 02:34:01 +01:00
|
|
|
}
|
|
|
|
|
2017-12-12 00:51:44 +01:00
|
|
|
type PhonyPath struct {
|
|
|
|
basePath
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p PhonyPath) writablePath() {}
|
|
|
|
|
2021-08-26 15:07:24 +02:00
|
|
|
func (p PhonyPath) getSoongOutDir() string {
|
2021-03-24 10:22:07 +01:00
|
|
|
// A phone path cannot contain any / so cannot be relative to the build directory.
|
|
|
|
return ""
|
2019-12-10 14:41:51 +01:00
|
|
|
}
|
|
|
|
|
2021-03-24 11:18:18 +01:00
|
|
|
func (p PhonyPath) RelativeToTop() Path {
|
|
|
|
ensureTestOnly()
|
|
|
|
// A phony path cannot contain any / so does not have a build directory so switching to a new
|
|
|
|
// build directory has no effect so just return this path.
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2020-11-27 12:37:28 +01:00
|
|
|
func (p PhonyPath) ReplaceExtension(ctx PathContext, ext string) OutputPath {
|
|
|
|
panic("Not implemented")
|
|
|
|
}
|
|
|
|
|
2017-12-12 00:51:44 +01:00
|
|
|
var _ Path = PhonyPath{}
|
|
|
|
var _ WritablePath = PhonyPath{}
|
|
|
|
|
2017-05-09 22:34:34 +02:00
|
|
|
type testPath struct {
|
|
|
|
basePath
|
|
|
|
}
|
|
|
|
|
2021-03-24 11:18:18 +01:00
|
|
|
func (p testPath) RelativeToTop() Path {
|
|
|
|
ensureTestOnly()
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2017-05-09 22:34:34 +02:00
|
|
|
func (p testPath) String() string {
|
|
|
|
return p.path
|
|
|
|
}
|
|
|
|
|
2021-03-24 11:18:18 +01:00
|
|
|
var _ Path = testPath{}
|
|
|
|
|
2019-02-15 20:08:35 +01:00
|
|
|
// PathForTesting returns a Path constructed from joining the elements of paths with '/'. It should only be used from
|
|
|
|
// within tests.
|
2017-05-09 22:34:34 +02:00
|
|
|
func PathForTesting(paths ...string) Path {
|
2018-02-22 22:54:26 +01:00
|
|
|
p, err := validateSafePath(paths...)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2017-05-09 22:34:34 +02:00
|
|
|
return testPath{basePath{path: p, rel: p}}
|
|
|
|
}
|
|
|
|
|
2019-02-15 20:08:35 +01:00
|
|
|
// PathsForTesting returns a Path constructed from each element in strs. It should only be used from within tests.
|
|
|
|
func PathsForTesting(strs ...string) Paths {
|
2017-05-09 22:34:34 +02:00
|
|
|
p := make(Paths, len(strs))
|
|
|
|
for i, s := range strs {
|
|
|
|
p[i] = PathForTesting(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
return p
|
|
|
|
}
|
2018-11-12 19:13:39 +01:00
|
|
|
|
2019-02-15 20:08:35 +01:00
|
|
|
type testPathContext struct {
|
|
|
|
config Config
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x *testPathContext) Config() Config { return x.config }
|
|
|
|
func (x *testPathContext) AddNinjaFileDeps(...string) {}
|
|
|
|
|
|
|
|
// PathContextForTesting returns a PathContext that can be used in tests, for example to create an OutputPath with
|
|
|
|
// PathForOutput.
|
2019-12-14 05:41:13 +01:00
|
|
|
func PathContextForTesting(config Config) PathContext {
|
2019-02-15 20:08:35 +01:00
|
|
|
return &testPathContext{
|
|
|
|
config: config,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-14 12:29:07 +02:00
|
|
|
type testModuleInstallPathContext struct {
|
|
|
|
baseModuleContext
|
|
|
|
|
|
|
|
inData bool
|
|
|
|
inTestcases bool
|
|
|
|
inSanitizerDir bool
|
|
|
|
inRamdisk bool
|
|
|
|
inVendorRamdisk bool
|
2021-04-08 14:13:22 +02:00
|
|
|
inDebugRamdisk bool
|
2020-10-14 12:29:07 +02:00
|
|
|
inRecovery bool
|
|
|
|
inRoot bool
|
|
|
|
forceOS *OsType
|
|
|
|
forceArch *ArchType
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m testModuleInstallPathContext) Config() Config {
|
|
|
|
return m.baseModuleContext.config
|
|
|
|
}
|
|
|
|
|
|
|
|
func (testModuleInstallPathContext) AddNinjaFileDeps(deps ...string) {}
|
|
|
|
|
|
|
|
func (m testModuleInstallPathContext) InstallInData() bool {
|
|
|
|
return m.inData
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m testModuleInstallPathContext) InstallInTestcases() bool {
|
|
|
|
return m.inTestcases
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m testModuleInstallPathContext) InstallInSanitizerDir() bool {
|
|
|
|
return m.inSanitizerDir
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m testModuleInstallPathContext) InstallInRamdisk() bool {
|
|
|
|
return m.inRamdisk
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m testModuleInstallPathContext) InstallInVendorRamdisk() bool {
|
|
|
|
return m.inVendorRamdisk
|
|
|
|
}
|
|
|
|
|
2021-04-08 14:13:22 +02:00
|
|
|
func (m testModuleInstallPathContext) InstallInDebugRamdisk() bool {
|
|
|
|
return m.inDebugRamdisk
|
|
|
|
}
|
|
|
|
|
2020-10-14 12:29:07 +02:00
|
|
|
func (m testModuleInstallPathContext) InstallInRecovery() bool {
|
|
|
|
return m.inRecovery
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m testModuleInstallPathContext) InstallInRoot() bool {
|
|
|
|
return m.inRoot
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m testModuleInstallPathContext) InstallForceOS() (*OsType, *ArchType) {
|
|
|
|
return m.forceOS, m.forceArch
|
|
|
|
}
|
|
|
|
|
|
|
|
// Construct a minimal ModuleInstallPathContext for testing. Note that baseModuleContext is
|
|
|
|
// default-initialized, which leaves blueprint.baseModuleContext set to nil, so methods that are
|
|
|
|
// delegated to it will panic.
|
|
|
|
func ModuleInstallPathContextForTesting(config Config) ModuleInstallPathContext {
|
|
|
|
ctx := &testModuleInstallPathContext{}
|
|
|
|
ctx.config = config
|
|
|
|
ctx.os = Android
|
|
|
|
return ctx
|
|
|
|
}
|
|
|
|
|
2018-11-12 19:13:39 +01:00
|
|
|
// Rel performs the same function as filepath.Rel, but reports errors to a PathContext, and reports an error if
|
|
|
|
// targetPath is not inside basePath.
|
|
|
|
func Rel(ctx PathContext, basePath string, targetPath string) string {
|
|
|
|
rel, isRel := MaybeRel(ctx, basePath, targetPath)
|
|
|
|
if !isRel {
|
2020-08-25 13:45:15 +02:00
|
|
|
ReportPathErrorf(ctx, "path %q is not under path %q", targetPath, basePath)
|
2018-11-12 19:13:39 +01:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return rel
|
|
|
|
}
|
|
|
|
|
|
|
|
// MaybeRel performs the same function as filepath.Rel, but reports errors to a PathContext, and returns false if
|
|
|
|
// targetPath is not inside basePath.
|
|
|
|
func MaybeRel(ctx PathContext, basePath string, targetPath string) (string, bool) {
|
2019-04-12 20:11:38 +02:00
|
|
|
rel, isRel, err := maybeRelErr(basePath, targetPath)
|
|
|
|
if err != nil {
|
|
|
|
reportPathError(ctx, err)
|
|
|
|
}
|
|
|
|
return rel, isRel
|
|
|
|
}
|
|
|
|
|
|
|
|
func maybeRelErr(basePath string, targetPath string) (string, bool, error) {
|
2018-11-12 19:13:39 +01:00
|
|
|
// filepath.Rel returns an error if one path is absolute and the other is not, handle that case first.
|
|
|
|
if filepath.IsAbs(basePath) != filepath.IsAbs(targetPath) {
|
2019-04-12 20:11:38 +02:00
|
|
|
return "", false, nil
|
2018-11-12 19:13:39 +01:00
|
|
|
}
|
|
|
|
rel, err := filepath.Rel(basePath, targetPath)
|
|
|
|
if err != nil {
|
2019-04-12 20:11:38 +02:00
|
|
|
return "", false, err
|
2018-11-12 19:13:39 +01:00
|
|
|
} else if rel == ".." || strings.HasPrefix(rel, "../") || strings.HasPrefix(rel, "/") {
|
2019-04-12 20:11:38 +02:00
|
|
|
return "", false, nil
|
2018-11-12 19:13:39 +01:00
|
|
|
}
|
2019-04-12 20:11:38 +02:00
|
|
|
return rel, true, nil
|
2018-11-12 19:13:39 +01:00
|
|
|
}
|
2020-01-11 02:11:46 +01:00
|
|
|
|
|
|
|
// Writes a file to the output directory. Attempting to write directly to the output directory
|
|
|
|
// will fail due to the sandbox of the soong_build process.
|
|
|
|
func WriteFileToOutputDir(path WritablePath, data []byte, perm os.FileMode) error {
|
2021-11-09 21:32:34 +01:00
|
|
|
absPath := absolutePath(path.String())
|
|
|
|
err := os.MkdirAll(filepath.Dir(absPath), 0777)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return ioutil.WriteFile(absPath, data, perm)
|
2020-01-11 02:11:46 +01:00
|
|
|
}
|
|
|
|
|
2020-11-26 01:06:39 +01:00
|
|
|
func RemoveAllOutputDir(path WritablePath) error {
|
|
|
|
return os.RemoveAll(absolutePath(path.String()))
|
|
|
|
}
|
|
|
|
|
|
|
|
func CreateOutputDirIfNonexistent(path WritablePath, perm os.FileMode) error {
|
|
|
|
dir := absolutePath(path.String())
|
2021-05-12 20:51:49 +02:00
|
|
|
return createDirIfNonexistent(dir, perm)
|
|
|
|
}
|
|
|
|
|
|
|
|
func createDirIfNonexistent(dir string, perm os.FileMode) error {
|
2020-11-26 01:06:39 +01:00
|
|
|
if _, err := os.Stat(dir); os.IsNotExist(err) {
|
|
|
|
return os.MkdirAll(dir, os.ModePerm)
|
|
|
|
} else {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-21 04:34:24 +02:00
|
|
|
// absolutePath is deliberately private so that Soong's Go plugins can't use it to find and
|
|
|
|
// read arbitrary files without going through the methods in the current package that track
|
|
|
|
// dependencies.
|
2020-01-11 02:11:46 +01:00
|
|
|
func absolutePath(path string) string {
|
|
|
|
if filepath.IsAbs(path) {
|
|
|
|
return path
|
|
|
|
}
|
|
|
|
return filepath.Join(absSrcDir, path)
|
|
|
|
}
|
2020-07-09 23:12:52 +02:00
|
|
|
|
|
|
|
// A DataPath represents the path of a file to be used as data, for example
|
|
|
|
// a test library to be installed alongside a test.
|
|
|
|
// The data file should be installed (copied from `<SrcPath>`) to
|
|
|
|
// `<install_root>/<RelativeInstallPath>/<filename>`, or
|
|
|
|
// `<install_root>/<filename>` if RelativeInstallPath is empty.
|
|
|
|
type DataPath struct {
|
|
|
|
// The path of the data file that should be copied into the data directory
|
|
|
|
SrcPath Path
|
|
|
|
// The install path of the data file, relative to the install root.
|
|
|
|
RelativeInstallPath string
|
|
|
|
}
|
2021-02-01 22:59:03 +01:00
|
|
|
|
|
|
|
// PathsIfNonNil returns a Paths containing only the non-nil input arguments.
|
|
|
|
func PathsIfNonNil(paths ...Path) Paths {
|
|
|
|
if len(paths) == 0 {
|
|
|
|
// Fast path for empty argument list
|
|
|
|
return nil
|
|
|
|
} else if len(paths) == 1 {
|
|
|
|
// Fast path for a single argument
|
|
|
|
if paths[0] != nil {
|
|
|
|
return paths
|
|
|
|
} else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ret := make(Paths, 0, len(paths))
|
|
|
|
for _, path := range paths {
|
|
|
|
if path != nil {
|
|
|
|
ret = append(ret, path)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(ret) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
2021-07-30 22:25:42 +02:00
|
|
|
|
|
|
|
var thirdPartyDirPrefixExceptions = []*regexp.Regexp{
|
|
|
|
regexp.MustCompile("^vendor/[^/]*google[^/]*/"),
|
|
|
|
regexp.MustCompile("^hardware/google/"),
|
|
|
|
regexp.MustCompile("^hardware/interfaces/"),
|
|
|
|
regexp.MustCompile("^hardware/libhardware[^/]*/"),
|
|
|
|
regexp.MustCompile("^hardware/ril/"),
|
|
|
|
}
|
|
|
|
|
|
|
|
func IsThirdPartyPath(path string) bool {
|
|
|
|
thirdPartyDirPrefixes := []string{"external/", "vendor/", "hardware/"}
|
|
|
|
|
|
|
|
if HasAnyPrefix(path, thirdPartyDirPrefixes) {
|
|
|
|
for _, prefix := range thirdPartyDirPrefixExceptions {
|
|
|
|
if prefix.MatchString(path) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2022-01-12 19:57:57 +01:00
|
|
|
|
|
|
|
// PathsDepSet is a thin type-safe wrapper around the generic depSet. It always uses
|
|
|
|
// topological order.
|
|
|
|
type PathsDepSet struct {
|
|
|
|
depSet
|
|
|
|
}
|
|
|
|
|
|
|
|
// newPathsDepSet returns an immutable PathsDepSet with the given direct and
|
|
|
|
// transitive contents.
|
|
|
|
func newPathsDepSet(direct Paths, transitive []*PathsDepSet) *PathsDepSet {
|
|
|
|
return &PathsDepSet{*newDepSet(TOPOLOGICAL, direct, transitive)}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToList returns the PathsDepSet flattened to a list in topological order.
|
|
|
|
func (d *PathsDepSet) ToList() Paths {
|
|
|
|
if d == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return d.depSet.ToList().(Paths)
|
|
|
|
}
|