diff options
author | Jingwen Chen <jingwen@google.com> | 2021-03-24 10:04:33 -0400 |
---|---|---|
committer | Jingwen Chen <jingwen@google.com> | 2021-04-09 09:42:53 +0000 |
commit | 6393098ecfd94c08e4e6f405227bda792413a7c2 (patch) | |
tree | 992247188b4ad67da859dcdbab5f2390146173bd /bazel | |
parent | 190ba3ea820f7a4500d6fb4fb70553a6667868a0 (diff) | |
download | soong-6393098ecfd94c08e4e6f405227bda792413a7c2.tar.gz |
bp2build: cc_library converter for //bionic/libdl:libdl_android
This CL contains the converter for libdl_android, a cc_library that
expands into a cc_shared_library and a regular cc_library.
Test: TH
Test: bp2build; bazel test //build/bazel/tests/...
Change-Id: If70641a538211b0d6b2aac0e4d0d06912318304d
Diffstat (limited to 'bazel')
-rw-r--r-- | bazel/properties.go | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/bazel/properties.go b/bazel/properties.go index 148386f6a..4bb239101 100644 --- a/bazel/properties.go +++ b/bazel/properties.go @@ -16,6 +16,7 @@ package bazel import ( "fmt" + "path/filepath" "regexp" "sort" ) @@ -47,6 +48,57 @@ type LabelList struct { Excludes []Label } +// GlobsInDir returns a list of glob expressions for a list of extensions +// (optionally recursive) within a directory. +func GlobsInDir(dir string, recursive bool, extensions []string) []string { + globs := []string{} + + globInfix := "" + if dir == "." { + if recursive { + // e.g "**/*.h" + globInfix = "**/" + } // else e.g. "*.h" + for _, ext := range extensions { + globs = append(globs, globInfix+"*"+ext) + } + } else { + if recursive { + // e.g. "foo/bar/**/*.h" + dir += "/**" + } // else e.g. "foo/bar/*.h" + for _, ext := range extensions { + globs = append(globs, dir+"/*"+ext) + } + } + return globs +} + +// LooseHdrsGlobs returns the list of non-recursive header globs for each parent directory of +// each source file in this LabelList's Includes. +func (ll *LabelList) LooseHdrsGlobs(exts []string) []string { + var globs []string + for _, parentDir := range ll.uniqueParentDirectories() { + globs = append(globs, + GlobsInDir(parentDir, false, exts)...) + } + return globs +} + +// uniqueParentDirectories returns a list of the unique parent directories for +// all files in ll.Includes. +func (ll *LabelList) uniqueParentDirectories() []string { + dirMap := map[string]bool{} + for _, label := range ll.Includes { + dirMap[filepath.Dir(label.Label)] = true + } + dirs := []string{} + for dir := range dirMap { + dirs = append(dirs, dir) + } + return dirs +} + // Append appends the fields of other labelList to the corresponding fields of ll. func (ll *LabelList) Append(other LabelList) { if len(ll.Includes) > 0 || len(other.Includes) > 0 { @@ -224,6 +276,26 @@ func MakeLabelListAttribute(value LabelList) LabelListAttribute { return LabelListAttribute{Value: UniqueBazelLabelList(value)} } +// Append appends all values, including os and arch specific ones, from another +// LabelListAttribute to this LabelListAttribute. +func (attrs *LabelListAttribute) Append(other LabelListAttribute) { + for arch := range PlatformArchMap { + this := attrs.GetValueForArch(arch) + that := other.GetValueForArch(arch) + this.Append(that) + attrs.SetValueForArch(arch, this) + } + + for os := range PlatformOsMap { + this := attrs.GetValueForOS(os) + that := other.GetValueForOS(os) + this.Append(that) + attrs.SetValueForOS(os, this) + } + + attrs.Value.Append(other.Value) +} + // HasArchSpecificValues returns true if the attribute contains // architecture-specific label_list values. func (attrs LabelListAttribute) HasConfigurableValues() bool { |