Merge "Add Factory methods, WriteFormattedMessage" into main
diff --git a/android/packaging.go b/android/packaging.go
index a2b8755..ae412e1 100644
--- a/android/packaging.go
+++ b/android/packaging.go
@@ -155,11 +155,12 @@
}
type packagingMultilibProperties struct {
- First depsProperty `android:"arch_variant"`
- Common depsProperty `android:"arch_variant"`
- Lib32 depsProperty `android:"arch_variant"`
- Lib64 depsProperty `android:"arch_variant"`
- Both depsProperty `android:"arch_variant"`
+ First depsProperty `android:"arch_variant"`
+ Common depsProperty `android:"arch_variant"`
+ Lib32 depsProperty `android:"arch_variant"`
+ Lib64 depsProperty `android:"arch_variant"`
+ Both depsProperty `android:"arch_variant"`
+ Prefer32 depsProperty `android:"arch_variant"`
}
type packagingArchProperties struct {
@@ -198,8 +199,20 @@
ret = append(ret, get(p.properties.Deps)...)
} else if arch.Multilib == "lib32" {
ret = append(ret, get(p.properties.Multilib.Lib32.Deps)...)
+ // multilib.prefer32.deps are added for lib32 only when they support 32-bit arch
+ for _, dep := range get(p.properties.Multilib.Prefer32.Deps) {
+ if checkIfOtherModuleSupportsLib32(ctx, dep) {
+ ret = append(ret, dep)
+ }
+ }
} else if arch.Multilib == "lib64" {
ret = append(ret, get(p.properties.Multilib.Lib64.Deps)...)
+ // multilib.prefer32.deps are added for lib64 only when they don't support 32-bit arch
+ for _, dep := range get(p.properties.Multilib.Prefer32.Deps) {
+ if !checkIfOtherModuleSupportsLib32(ctx, dep) {
+ ret = append(ret, dep)
+ }
+ }
} else if arch == Common {
ret = append(ret, get(p.properties.Multilib.Common.Deps)...)
}
@@ -246,7 +259,7 @@
return FirstUniqueStrings(ret)
}
-func (p *PackagingBase) getSupportedTargets(ctx BaseModuleContext) []Target {
+func getSupportedTargets(ctx BaseModuleContext) []Target {
var ret []Target
// The current and the common OS targets are always supported
ret = append(ret, ctx.Target())
@@ -258,6 +271,28 @@
return ret
}
+// getLib32Target returns the 32-bit target from the list of targets this module supports. If this
+// module doesn't support 32-bit target, nil is returned.
+func getLib32Target(ctx BaseModuleContext) *Target {
+ for _, t := range getSupportedTargets(ctx) {
+ if t.Arch.ArchType.Multilib == "lib32" {
+ return &t
+ }
+ }
+ return nil
+}
+
+// checkIfOtherModuleSUpportsLib32 returns true if 32-bit variant of dep exists.
+func checkIfOtherModuleSupportsLib32(ctx BaseModuleContext, dep string) bool {
+ t := getLib32Target(ctx)
+ if t == nil {
+ // This packaging module doesn't support 32bit. No point of checking if dep supports 32-bit
+ // or not.
+ return false
+ }
+ return ctx.OtherModuleFarDependencyVariantExists(t.Variations(), dep)
+}
+
// PackagingItem is a marker interface for dependency tags.
// Direct dependencies with a tag implementing PackagingItem are packaged in CopyDepsToZip().
type PackagingItem interface {
@@ -278,7 +313,7 @@
// See PackageModule.AddDeps
func (p *PackagingBase) AddDeps(ctx BottomUpMutatorContext, depTag blueprint.DependencyTag) {
- for _, t := range p.getSupportedTargets(ctx) {
+ for _, t := range getSupportedTargets(ctx) {
for _, dep := range p.getDepsForArch(ctx, t.Arch.ArchType) {
if p.IgnoreMissingDependencies && !ctx.OtherModuleExists(dep) {
continue
@@ -292,7 +327,7 @@
m := make(map[string]PackagingSpec)
var arches []ArchType
- for _, target := range p.getSupportedTargets(ctx) {
+ for _, target := range getSupportedTargets(ctx) {
arches = append(arches, target.Arch.ArchType)
}
diff --git a/android/packaging_test.go b/android/packaging_test.go
index 0570ec5..89df8ef 100644
--- a/android/packaging_test.go
+++ b/android/packaging_test.go
@@ -15,6 +15,8 @@
package android
import (
+ "fmt"
+ "strings"
"testing"
"github.com/google/blueprint"
@@ -584,3 +586,69 @@
runPackagingTest(t, config, bp, tc.expected)
}
}
+
+func TestPrefer32Deps(t *testing.T) {
+ bpTemplate := `
+ component {
+ name: "foo",
+ compile_multilib: "both", // not needed but for clarity
+ }
+
+ component {
+ name: "foo_32only",
+ compile_multilib: "prefer32",
+ }
+
+ component {
+ name: "foo_64only",
+ compile_multilib: "64",
+ }
+
+ package_module {
+ name: "package",
+ compile_multilib: "%COMPILE_MULTILIB%",
+ multilib: {
+ prefer32: {
+ deps: %DEPS%,
+ },
+ },
+ }
+ `
+
+ testcases := []struct {
+ compileMultilib string
+ deps []string
+ expected []string
+ }{
+ {
+ compileMultilib: "first",
+ deps: []string{"foo", "foo_64only"},
+ expected: []string{"lib64/foo", "lib64/foo_64only"},
+ },
+ {
+ compileMultilib: "64",
+ deps: []string{"foo", "foo_64only"},
+ expected: []string{"lib64/foo", "lib64/foo_64only"},
+ },
+ {
+ compileMultilib: "32",
+ deps: []string{"foo", "foo_32only"},
+ expected: []string{"lib32/foo", "lib32/foo_32only"},
+ },
+ {
+ compileMultilib: "both",
+ deps: []string{"foo", "foo_32only", "foo_64only"},
+ expected: []string{"lib32/foo", "lib32/foo_32only", "lib64/foo_64only"},
+ },
+ }
+ for _, tc := range testcases {
+ config := testConfig{
+ multiTarget: true,
+ depsCollectFirstTargetOnly: true,
+ }
+ bp := strings.Replace(bpTemplate, "%COMPILE_MULTILIB%", tc.compileMultilib, -1)
+ bp = strings.Replace(bp, "%DEPS%", `["`+strings.Join(tc.deps, `", "`)+`"]`, -1)
+ fmt.Printf("bp = %s\n", bp)
+ runPackagingTest(t, config, bp, tc.expected)
+ }
+}
diff --git a/android/util.go b/android/util.go
index de4ca4d..e21e66b 100644
--- a/android/util.go
+++ b/android/util.go
@@ -24,6 +24,8 @@
"sort"
"strings"
"sync"
+
+ "github.com/google/blueprint/proptools"
)
// CopyOf returns a new slice that has the same contents as s.
@@ -542,25 +544,9 @@
return root, suffix, ext
}
-func shard[T ~[]E, E any](toShard T, shardSize int) []T {
- if len(toShard) == 0 {
- return nil
- }
-
- ret := make([]T, 0, (len(toShard)+shardSize-1)/shardSize)
- for len(toShard) > shardSize {
- ret = append(ret, toShard[0:shardSize])
- toShard = toShard[shardSize:]
- }
- if len(toShard) > 0 {
- ret = append(ret, toShard)
- }
- return ret
-}
-
// ShardPaths takes a Paths, and returns a slice of Paths where each one has at most shardSize paths.
func ShardPaths(paths Paths, shardSize int) []Paths {
- return shard(paths, shardSize)
+ return proptools.ShardBySize(paths, shardSize)
}
// ShardString takes a string and returns a slice of strings where the length of each one is
@@ -583,7 +569,7 @@
// ShardStrings takes a slice of strings, and returns a slice of slices of strings where each one has at most shardSize
// elements.
func ShardStrings(s []string, shardSize int) [][]string {
- return shard(s, shardSize)
+ return proptools.ShardBySize(s, shardSize)
}
// CheckDuplicate checks if there are duplicates in given string list.
diff --git a/apex/apex_test.go b/apex/apex_test.go
index a2c8896..965b4be 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -5922,6 +5922,7 @@
srcs: ["foo/bar/MyClass.java"],
sdk_version: "current",
system_modules: "none",
+ use_embedded_native_libs: true,
jni_libs: ["libjni"],
stl: "none",
apex_available: [ "myapex" ],
diff --git a/bin/cgrep b/bin/cgrep
new file mode 100755
index 0000000..6c9130c
--- /dev/null
+++ b/bin/cgrep
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+# Copyright (C) 2022 The Android Open Source Project
+#
+# 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.
+
+find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f \( \
+ -name '*.c' \
+ -o -name '*.cc' \
+ -o -name '*.cpp' \
+ -o -name '*.h' \
+ -o -name '*.hpp' \
+ \) -exec grep --color -n "$@" {} +
+exit $?
diff --git a/bin/ggrep b/bin/ggrep
new file mode 100755
index 0000000..fce8c84
--- /dev/null
+++ b/bin/ggrep
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+# Copyright (C) 2022 The Android Open Source Project
+#
+# 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.
+
+find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f \( \
+ -name '*.gradle' \
+ \) -exec grep --color -n "$@" {} +
+exit $?
diff --git a/bin/gogrep b/bin/gogrep
new file mode 100755
index 0000000..0265ccf
--- /dev/null
+++ b/bin/gogrep
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+# Copyright (C) 2022 The Android Open Source Project
+#
+# 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.
+
+find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f \( \
+ -name '*.go' \
+ \) -exec grep --color -n "$@" {} +
+exit $?
diff --git a/bin/hmm b/bin/hmm
new file mode 100755
index 0000000..c3d60fa
--- /dev/null
+++ b/bin/hmm
@@ -0,0 +1,79 @@
+#!/bin/bash
+
+# Copyright (C) 2022 The Android Open Source Project
+#
+# 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.
+
+cat <<EOF
+
+Run "m help" for help with the build system itself.
+
+Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
+- lunch: lunch <product_name>-<release_type>-<build_variant>
+ Selects <product_name> as the product to build, and <build_variant> as the variant to
+ build, and stores those selections in the environment to be read by subsequent
+ invocations of 'm' etc.
+- tapas: tapas [<App1> <App2> ...] [arm|x86|arm64|x86_64] [eng|userdebug|user]
+ Sets up the build environment for building unbundled apps (APKs).
+- banchan: banchan <module1> [<module2> ...] \\
+ [arm|x86|arm64|riscv64|x86_64|arm64_only|x86_64only] [eng|userdebug|user]
+ Sets up the build environment for building unbundled modules (APEXes).
+- croot: Changes directory to the top of the tree, or a subdirectory thereof.
+- m: Makes from the top of the tree.
+- mm: Builds and installs all of the modules in the current directory, and their
+ dependencies.
+- mmm: Builds and installs all of the modules in the supplied directories, and their
+ dependencies.
+ To limit the modules being built use the syntax: mmm dir/:target1,target2.
+- mma: Same as 'mm'
+- mmma: Same as 'mmm'
+- provision: Flash device with all required partitions. Options will be passed on to fastboot.
+- cgrep: Greps on all local C/C++ files.
+- ggrep: Greps on all local Gradle files.
+- gogrep: Greps on all local Go files.
+- jgrep: Greps on all local Java files.
+- jsongrep: Greps on all local Json files.
+- ktgrep: Greps on all local Kotlin files.
+- resgrep: Greps on all local res/*.xml files.
+- mangrep: Greps on all local AndroidManifest.xml files.
+- mgrep: Greps on all local Makefiles and *.bp files.
+- owngrep: Greps on all local OWNERS files.
+- rsgrep: Greps on all local Rust files.
+- sepgrep: Greps on all local sepolicy files.
+- sgrep: Greps on all local source files.
+- tomlgrep: Greps on all local Toml files.
+- pygrep: Greps on all local Python files.
+- godir: Go to the directory containing a file.
+- allmod: List all modules.
+- gomod: Go to the directory containing a module.
+- bmod: Get the Bazel label of a Soong module if it is converted with bp2build.
+- pathmod: Get the directory containing a module.
+- outmod: Gets the location of a module's installed outputs with a certain extension.
+- dirmods: Gets the modules defined in a given directory.
+- installmod: Adb installs a module's built APK.
+- refreshmod: Refresh list of modules for allmod/gomod/pathmod/outmod/installmod.
+- syswrite: Remount partitions (e.g. system.img) as writable, rebooting if necessary.
+
+Environment options:
+- SANITIZE_HOST: Set to 'address' to use ASAN for all host modules.
+- ANDROID_QUIET_BUILD: set to 'true' to display only the essential messages.
+
+Look at build/make/envsetup for more functions:
+EOF
+ local T=$(gettop)
+ local A=""
+ local i
+ for i in `(cat $T/build/envsetup.sh | sed -n "/^[[:blank:]]*function /s/function \([a-z]*\).*/\1/p" | sort | uniq`; do
+ A="$A $i"
+ done
+ echo $A
diff --git a/bin/jgrep b/bin/jgrep
new file mode 100755
index 0000000..afe70db
--- /dev/null
+++ b/bin/jgrep
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+# Copyright (C) 2022 The Android Open Source Project
+#
+# 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.
+
+find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f \( \
+ -name '*.java' \
+ -o -name '*.kt' \
+ \) -exec grep --color -n "$@" {} +
+exit $?
diff --git a/bin/jsongrep b/bin/jsongrep
new file mode 100755
index 0000000..6e14d0c
--- /dev/null
+++ b/bin/jsongrep
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+# Copyright (C) 2022 The Android Open Source Project
+#
+# 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.
+
+find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f \( \
+ -name '*.json' \
+ \) -exec grep --color -n "$@" {} +
+exit $?
diff --git a/bin/ktgrep b/bin/ktgrep
new file mode 120000
index 0000000..9b51491
--- /dev/null
+++ b/bin/ktgrep
@@ -0,0 +1 @@
+jgrep
\ No newline at end of file
diff --git a/bin/m b/bin/m
new file mode 100755
index 0000000..edcfce5
--- /dev/null
+++ b/bin/m
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+# Copyright (C) 2024 The Android Open Source Project
+#
+# 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.
+
+# Common script utilities
+source $(cd $(dirname $BASH_SOURCE) &> /dev/null && pwd)/../../make/shell_utils.sh
+
+require_top
+
+_wrap_build "$TOP/build/soong/soong_ui.bash" --build-mode --all-modules --dir="$(pwd)" "$@"
+
+exit $?
diff --git a/bin/mangrep b/bin/mangrep
new file mode 100755
index 0000000..a343000
--- /dev/null
+++ b/bin/mangrep
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+# Copyright (C) 2022 The Android Open Source Project
+#
+# 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.
+
+find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f \( \
+ -name 'AndroidManifest.xml' \
+ \) -exec grep --color -n "$@" {} +
+exit $?
diff --git a/bin/mgrep b/bin/mgrep
new file mode 100755
index 0000000..793730d
--- /dev/null
+++ b/bin/mgrep
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+# Copyright (C) 2022 The Android Open Source Project
+#
+# 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.
+
+find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f \( \
+ -name 'Makefile' \
+ -o -name 'Makefile.*' \
+ -o -name '*.make' \
+ -o -name '*.mak' \
+ -o -name '*.mk' \
+ -o -name '*.bp' \
+ \) -exec grep --color -n "$@" {} +
+exit $?
diff --git a/bin/mm b/bin/mm
new file mode 100755
index 0000000..6461b1e
--- /dev/null
+++ b/bin/mm
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+# Copyright (C) 2024 The Android Open Source Project
+#
+# 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.
+
+# Common script utilities
+source $(cd $(dirname $BASH_SOURCE) &> /dev/null && pwd)/../../make/shell_utils.sh
+
+require_top
+
+_wrap_build "$TOP/build/soong/soong_ui.bash" --build-mode --modules-in-a-dir-no-deps --dir="$(pwd)" "$@"
+
+exit $?
diff --git a/bin/mma b/bin/mma
new file mode 100755
index 0000000..6f1c934
--- /dev/null
+++ b/bin/mma
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+# Copyright (C) 2024 The Android Open Source Project
+#
+# 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.
+
+# Common script utilities
+source $(cd $(dirname $BASH_SOURCE) &> /dev/null && pwd)/../../make/shell_utils.sh
+
+require_top
+
+_wrap_build "$TOP/build/soong/soong_ui.bash" --build-mode --modules-in-a-dir --dir="$(pwd)" "$@"
+
+exit $?
diff --git a/bin/mmm b/bin/mmm
new file mode 100755
index 0000000..ab3a632
--- /dev/null
+++ b/bin/mmm
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+# Copyright (C) 2024 The Android Open Source Project
+#
+# 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.
+
+# Common script utilities
+source $(cd $(dirname $BASH_SOURCE) &> /dev/null && pwd)/../../make/shell_utils.sh
+
+require_top
+
+_wrap_build "$TOP/build/soong/soong_ui.bash" --build-mode --modules-in-dirs-no-deps --dir="$(pwd)" "$@"
+
+exit $?
diff --git a/bin/mmma b/bin/mmma
new file mode 100755
index 0000000..d9190e5
--- /dev/null
+++ b/bin/mmma
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+# Copyright (C) 2024 The Android Open Source Project
+#
+# 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.
+
+# Common script utilities
+source $(cd $(dirname $BASH_SOURCE) &> /dev/null && pwd)/../../make/shell_utils.sh
+
+require_top
+
+_wrap_build "$TOP/build/soong/soong_ui.bash" --build-mode --modules-in-dirs --dir="$(pwd)" "$@"
+
+exit $?
diff --git a/bin/owngrep b/bin/owngrep
new file mode 100755
index 0000000..26ce6e8
--- /dev/null
+++ b/bin/owngrep
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+# Copyright (C) 2022 The Android Open Source Project
+#
+# 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.
+
+find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f \( \
+ -name 'OWNERS' \
+ \) -exec grep --color -n "$@" {} +
+exit $?
diff --git a/bin/pygrep b/bin/pygrep
new file mode 100755
index 0000000..e072289
--- /dev/null
+++ b/bin/pygrep
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+# Copyright (C) 2022 The Android Open Source Project
+#
+# 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.
+
+find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f \( \
+ -name '*.py' \
+ \) -exec grep --color -n "$@" {} +
+exit $?
diff --git a/bin/rcgrep b/bin/rcgrep
new file mode 100755
index 0000000..ff93e51
--- /dev/null
+++ b/bin/rcgrep
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+# Copyright (C) 2022 The Android Open Source Project
+#
+# 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.
+
+find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f \( \
+ -name '*.rc' \
+ \) -exec grep --color -n "$@" {} +
+exit $?
diff --git a/bin/refreshmod b/bin/refreshmod
new file mode 100755
index 0000000..f511846
--- /dev/null
+++ b/bin/refreshmod
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+# Copyright (C) 2024 The Android Open Source Project
+#
+# 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.
+
+# Update module-info.json in out.
+
+# Common script utilities
+source $(cd $(dirname $BASH_SOURCE) &> /dev/null && pwd)/../../make/shell_utils.sh
+
+require_top
+
+if [ ! "$ANDROID_PRODUCT_OUT" ]; then
+ echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
+ return 1
+fi
+
+echo "Refreshing modules (building module-info.json)" >&2
+
+_wrap_build $TOP/build/soong/soong_ui.bash --build-mode --all-modules --dir="$(pwd)" module-info
diff --git a/bin/resgrep b/bin/resgrep
new file mode 100755
index 0000000..600091f
--- /dev/null
+++ b/bin/resgrep
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+# Copyright (C) 2022 The Android Open Source Project
+#
+# 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.
+
+for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do
+ find $dir -type f -name '*\.xml' -exec grep --color -n "$@" {} +
+done
diff --git a/bin/rsgrep b/bin/rsgrep
new file mode 100755
index 0000000..8c24151
--- /dev/null
+++ b/bin/rsgrep
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+# Copyright (C) 2022 The Android Open Source Project
+#
+# 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.
+
+find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f \( \
+ -name '*.rs' \
+ \) -exec grep --color -n "$@" {} +
+exit $?
diff --git a/bin/sepgrep b/bin/sepgrep
new file mode 100755
index 0000000..0e0d1ba
--- /dev/null
+++ b/bin/sepgrep
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+# Copyright (C) 2022 The Android Open Source Project
+#
+# 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.
+
+find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d \
+ -exec grep --color -n -r --exclude-dir=\.git "$@" {} +
+exit $?
diff --git a/bin/sgrep b/bin/sgrep
new file mode 100755
index 0000000..f186553
--- /dev/null
+++ b/bin/sgrep
@@ -0,0 +1,36 @@
+#!/bin/bash
+
+# Copyright (C) 2022 The Android Open Source Project
+#
+# 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.
+
+find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f \( \
+ -name '*.c' \
+ -o -name '*.cc' \
+ -o -name '*.cpp' \
+ -o -name '*.h' \
+ -o -name '*.hpp' \
+ -o -name '*.S' \
+ -o -name '*.java' \
+ -o -name '*.kt' \
+ -o -name '*.xml' \
+ -o -name '*.sh' \
+ -o -name '*.mk' \
+ -o -name '*.bp' \
+ -o -name '*.aidl' \
+ -o -name '*.vts' \
+ -o -name '*.proto' \
+ -o -name '*.rs' \
+ -o -name '*.go' \
+ \) -exec grep --color -n "$@" {} +
+exit $?
diff --git a/bin/syswrite b/bin/syswrite
new file mode 100755
index 0000000..46201e3
--- /dev/null
+++ b/bin/syswrite
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+# Copyright (C) 2024 The Android Open Source Project
+#
+# 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.
+
+# syswrite - disable verity, reboot if needed, and remount image
+# Easy way to make system.img/etc writable
+
+adb wait-for-device && adb root && adb wait-for-device || exit 1
+if [[ $(adb disable-verity | grep -i "reboot") ]]; then
+ echo "rebooting"
+ adb reboot && adb wait-for-device && adb root && adb wait-for-device || exit 1
+fi
+adb remount || exit 1
diff --git a/bin/tomlgrep b/bin/tomlgrep
new file mode 100755
index 0000000..636ef22
--- /dev/null
+++ b/bin/tomlgrep
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+# Copyright (C) 2022 The Android Open Source Project
+#
+# 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.
+
+find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f \( \
+ -name '*.toml' \
+ \) -exec grep --color -n "$@" {} +
+exit $?
diff --git a/bin/treegrep b/bin/treegrep
new file mode 100755
index 0000000..b83d419
--- /dev/null
+++ b/bin/treegrep
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+# Copyright (C) 2022 The Android Open Source Project
+#
+# 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.
+
+find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f \( \
+ -name '*.c' \
+ -o -name '*.cc' \
+ -o -name '*.cpp' \
+ -o -name '*.h' \
+ -o -name '*.hpp' \
+ -o -name '*.S' \
+ -o -name '*.java' \
+ -o -name '*.kt' \
+ -o -name '*.xml' \
+ \) -exec grep --color -n "$@" {} +
+exit $?
diff --git a/cc/builder.go b/cc/builder.go
index 42aa4b6..d817d82 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -46,18 +46,18 @@
blueprint.RuleParams{
Depfile: "${out}.d",
Deps: blueprint.DepsGCC,
- Command: "$relPwd ${config.CcWrapper}$ccCmd -c $cFlags -MD -MF ${out}.d -o $out $in",
+ Command: "$relPwd ${config.CcWrapper}$ccCmd -c $cFlags -MD -MF ${out}.d -o $out $in$postCmd",
CommandDeps: []string{"$ccCmd"},
},
- "ccCmd", "cFlags")
+ "ccCmd", "cFlags", "postCmd")
// Rule to invoke gcc with given command and flags, but no dependencies.
ccNoDeps = pctx.AndroidStaticRule("ccNoDeps",
blueprint.RuleParams{
- Command: "$relPwd $ccCmd -c $cFlags -o $out $in",
+ Command: "$relPwd $ccCmd -c $cFlags -o $out $in$postCmd",
CommandDeps: []string{"$ccCmd"},
},
- "ccCmd", "cFlags")
+ "ccCmd", "cFlags", "postCmd")
// Rules to invoke ld to link binaries. Uses a .rsp file to list dependencies, as there may
// be many.
@@ -400,6 +400,7 @@
gcovCoverage bool
sAbiDump bool
emitXrefs bool
+ clangVerify bool
assemblerWithCpp bool // True if .s files should be processed with the c preprocessor.
@@ -591,6 +592,7 @@
var moduleToolingFlags string
var ccCmd string
+ var postCmd string
tidy := flags.tidy
coverage := flags.gcovCoverage
dump := flags.sAbiDump
@@ -635,6 +637,10 @@
ccCmd = "${config.ClangBin}/" + ccCmd
+ if flags.clangVerify {
+ postCmd = " && touch $$out"
+ }
+
var implicitOutputs android.WritablePaths
if coverage {
gcnoFile := android.ObjPathWithExt(ctx, subdir, srcFile, "gcno")
@@ -651,8 +657,9 @@
Implicits: cFlagsDeps,
OrderOnly: pathDeps,
Args: map[string]string{
- "cFlags": shareFlags("cFlags", moduleFlags),
- "ccCmd": ccCmd, // short and not shared
+ "cFlags": shareFlags("cFlags", moduleFlags),
+ "ccCmd": ccCmd, // short and not shared
+ "postCmd": postCmd,
},
})
diff --git a/cc/cc.go b/cc/cc.go
index 89cf093..a64775d 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -260,6 +260,7 @@
GcovCoverage bool // True if coverage files should be generated.
SAbiDump bool // True if header abi dumps should be generated.
EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
+ ClangVerify bool // If true, append cflags "-Xclang -verify" and append "&& touch $out" to the clang command line.
// The instruction set required for clang ("arm" or "thumb").
RequiredInstructionSet string
diff --git a/cc/cc_test.go b/cc/cc_test.go
index 3d75bf5..026d291 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -3218,3 +3218,32 @@
testSdkVersionFlag("libfoo", "30")
testSdkVersionFlag("libbar", "29")
}
+
+func TestClangVerify(t *testing.T) {
+ t.Parallel()
+
+ ctx := testCc(t, `
+ cc_library {
+ name: "lib_no_clang_verify",
+ srcs: ["libnocv.cc"],
+ }
+
+ cc_library {
+ name: "lib_clang_verify",
+ srcs: ["libcv.cc"],
+ clang_verify: true,
+ }
+ `)
+
+ module := ctx.ModuleForTests("lib_no_clang_verify", "android_arm64_armv8-a_shared")
+
+ cFlags_no_cv := module.Rule("cc").Args["cFlags"]
+ if strings.Contains(cFlags_no_cv, "-Xclang") || strings.Contains(cFlags_no_cv, "-verify") {
+ t.Errorf("expected %q not in cflags, got %q", "-Xclang -verify", cFlags_no_cv)
+ }
+
+ cFlags_cv := ctx.ModuleForTests("lib_clang_verify", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"]
+ if strings.Contains(cFlags_cv, "-Xclang") && strings.Contains(cFlags_cv, "-verify") {
+ t.Errorf("expected %q in cflags, got %q", "-Xclang -verify", cFlags_cv)
+ }
+}
diff --git a/cc/compiler.go b/cc/compiler.go
index 21b8f2e..34d98c0 100644
--- a/cc/compiler.go
+++ b/cc/compiler.go
@@ -120,6 +120,10 @@
// ban targeting bpf in cc rules instead use bpf_rules. (b/323415017)
Bpf_target *bool
+ // Add "-Xclang -verify" to the cflags and appends "touch $out" to
+ // the clang command line.
+ Clang_verify bool
+
Yacc *YaccProperties
Lex *LexProperties
@@ -390,6 +394,11 @@
flags.Yacc = compiler.Properties.Yacc
flags.Lex = compiler.Properties.Lex
+ flags.ClangVerify = compiler.Properties.Clang_verify
+ if compiler.Properties.Clang_verify {
+ flags.Local.CFlags = append(flags.Local.CFlags, "-Xclang", "-verify")
+ }
+
// Include dir cflags
localIncludeDirs := android.PathsForModuleSrc(ctx, compiler.Properties.Local_include_dirs)
if len(localIncludeDirs) > 0 {
diff --git a/cc/library.go b/cc/library.go
index cc8fafe..b9018a7 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -1362,20 +1362,25 @@
func (library *libraryDecorator) crossVersionAbiDiff(ctx android.ModuleContext,
sourceDump, referenceDump android.Path,
- baseName string, isLlndk bool, sourceVersion, prevVersion string) {
+ baseName, nameExt string, isLlndk bool, sourceVersion, prevDumpDir string) {
- errorMessage := "error: Please follow https://android.googlesource.com/platform/development/+/main/vndk/tools/header-checker/README.md#configure-cross_version-abi-check to resolve the ABI difference between your source code and version " + prevVersion + "."
+ errorMessage := "error: Please follow https://android.googlesource.com/platform/development/+/main/vndk/tools/header-checker/README.md#configure-cross_version-abi-check to resolve the difference between your source code and the ABI dumps in " + prevDumpDir
- library.sourceAbiDiff(ctx, sourceDump, referenceDump, baseName, prevVersion,
+ library.sourceAbiDiff(ctx, sourceDump, referenceDump, baseName, nameExt,
isLlndk, true /* allowExtensions */, sourceVersion, errorMessage)
}
func (library *libraryDecorator) sameVersionAbiDiff(ctx android.ModuleContext,
sourceDump, referenceDump android.Path,
- baseName, nameExt string, isLlndk bool) {
+ baseName, nameExt string, isLlndk bool, lsdumpTagName string) {
libName := strings.TrimSuffix(baseName, filepath.Ext(baseName))
- errorMessage := "error: Please update ABI references with: $$ANDROID_BUILD_TOP/development/vndk/tools/header-checker/utils/create_reference_dumps.py -l " + libName
+ errorMessage := "error: Please update ABI references with: $$ANDROID_BUILD_TOP/development/vndk/tools/header-checker/utils/create_reference_dumps.py --lib " + libName + " --lib-variant " + lsdumpTagName
+
+ targetRelease := ctx.Config().Getenv("TARGET_RELEASE")
+ if targetRelease != "" {
+ errorMessage += " --release " + targetRelease
+ }
library.sourceAbiDiff(ctx, sourceDump, referenceDump, baseName, nameExt,
isLlndk, false /* allowExtensions */, "current", errorMessage)
@@ -1383,13 +1388,19 @@
func (library *libraryDecorator) optInAbiDiff(ctx android.ModuleContext,
sourceDump, referenceDump android.Path,
- baseName, nameExt string, refDumpDir string) {
+ baseName, nameExt string, refDumpDir string, lsdumpTagName string) {
libName := strings.TrimSuffix(baseName, filepath.Ext(baseName))
- errorMessage := "error: Please update ABI references with: $$ANDROID_BUILD_TOP/development/vndk/tools/header-checker/utils/create_reference_dumps.py -l " + libName + " -ref-dump-dir $$ANDROID_BUILD_TOP/" + refDumpDir
+ errorMessage := "error: Please update ABI references with: $$ANDROID_BUILD_TOP/development/vndk/tools/header-checker/utils/create_reference_dumps.py --lib " + libName + " --lib-variant " + lsdumpTagName + " --ref-dump-dir $$ANDROID_BUILD_TOP/" + refDumpDir
+
+ targetRelease := ctx.Config().Getenv("TARGET_RELEASE")
+ if targetRelease != "" {
+ errorMessage += " --release " + targetRelease
+ }
+
// Most opt-in libraries do not have dumps for all default architectures.
if ctx.Config().HasDeviceProduct() {
- errorMessage += " -products " + ctx.Config().DeviceProduct()
+ errorMessage += " --product " + ctx.Config().DeviceProduct()
}
library.sourceAbiDiff(ctx, sourceDump, referenceDump, baseName, nameExt,
@@ -1414,6 +1425,7 @@
var llndkDump, apexVariantDump android.Path
tags := classifySourceAbiDump(ctx)
+ optInTags := []lsdumpTag{}
for _, tag := range tags {
if tag == llndkLsdumpTag && currVendorVersion != "" {
if llndkDump == nil {
@@ -1435,6 +1447,9 @@
}
addLsdumpPath(string(tag) + ":" + apexVariantDump.String())
} else {
+ if tag.dirName() == "" {
+ optInTags = append(optInTags, tag)
+ }
addLsdumpPath(string(tag) + ":" + implDump.String())
}
}
@@ -1479,7 +1494,7 @@
prevDumpFile := getRefAbiDumpFile(ctx, prevDumpDir, fileName)
if prevDumpFile.Valid() {
library.crossVersionAbiDiff(ctx, sourceDump, prevDumpFile.Path(),
- fileName, isLlndk, currVersion, nameExt+prevVersion)
+ fileName, nameExt+prevVersion, isLlndk, currVersion, prevDumpDir)
}
// Check against the current version.
sourceDump = implDump
@@ -1499,9 +1514,15 @@
currDumpFile := getRefAbiDumpFile(ctx, currDumpDir, fileName)
if currDumpFile.Valid() {
library.sameVersionAbiDiff(ctx, sourceDump, currDumpFile.Path(),
- fileName, nameExt, isLlndk)
+ fileName, nameExt, isLlndk, string(tag))
}
}
+
+ // Assert that a module is tagged with at most one of platformLsdumpTag, productLsdumpTag, or vendorLsdumpTag.
+ if len(headerAbiChecker.Ref_dump_dirs) > 0 && len(optInTags) != 1 {
+ ctx.ModuleErrorf("Expect exactly one opt-in lsdump tag when ref_dump_dirs are specified: %s", optInTags)
+ return
+ }
// Ensure that a module tagged with only platformLsdumpTag has ref_dump_dirs.
// Android.bp in vendor projects should be cleaned up before this is enforced for vendorLsdumpTag and productLsdumpTag.
if len(headerAbiChecker.Ref_dump_dirs) == 0 && len(tags) == 1 && tags[0] == platformLsdumpTag {
@@ -1518,7 +1539,7 @@
}
library.optInAbiDiff(ctx,
implDump, optInDumpFile.Path(),
- fileName, "opt"+strconv.Itoa(i), optInDumpDirPath.String())
+ fileName, "opt"+strconv.Itoa(i), optInDumpDirPath.String(), string(optInTags[0]))
}
}
}
diff --git a/cc/util.go b/cc/util.go
index 3ede8ff..8ffacae 100644
--- a/cc/util.go
+++ b/cc/util.go
@@ -68,6 +68,7 @@
needTidyFiles: in.NeedTidyFiles,
sAbiDump: in.SAbiDump,
emitXrefs: in.EmitXrefs,
+ clangVerify: in.ClangVerify,
systemIncludeFlags: strings.Join(in.SystemIncludeFlags, " "),
diff --git a/java/androidmk.go b/java/androidmk.go
index 4f740b2..a1bc904 100644
--- a/java/androidmk.go
+++ b/java/androidmk.go
@@ -17,7 +17,6 @@
import (
"fmt"
"io"
- "strings"
"android/soong/android"
@@ -414,22 +413,11 @@
jniSymbols := app.JNISymbolsInstalls(app.installPathForJNISymbols.String())
entries.SetString("LOCAL_SOONG_JNI_LIBS_SYMBOLS", jniSymbols.String())
} else {
+ var names []string
for _, jniLib := range app.jniLibs {
- entries.AddStrings("LOCAL_SOONG_JNI_LIBS_"+jniLib.target.Arch.ArchType.String(), jniLib.name)
- var partitionTag string
-
- // Mimic the creation of partition_tag in build/make,
- // which defaults to an empty string when the partition is system.
- // Otherwise, capitalize with a leading _
- if jniLib.partition == "system" {
- partitionTag = ""
- } else {
- split := strings.Split(jniLib.partition, "/")
- partitionTag = "_" + strings.ToUpper(split[len(split)-1])
- }
- entries.AddStrings("LOCAL_SOONG_JNI_LIBS_PARTITION_"+jniLib.target.Arch.ArchType.String(),
- jniLib.name+":"+partitionTag)
+ names = append(names, jniLib.name)
}
+ entries.AddStrings("LOCAL_REQUIRED_MODULES", names...)
}
if len(app.jniCoverageOutputs) > 0 {
diff --git a/java/androidmk_test.go b/java/androidmk_test.go
index 2978a40..243a279 100644
--- a/java/androidmk_test.go
+++ b/java/androidmk_test.go
@@ -20,8 +20,6 @@
"android/soong/android"
"android/soong/cc"
-
- "github.com/google/blueprint/proptools"
)
func TestRequired(t *testing.T) {
@@ -256,148 +254,50 @@
}
}
-func TestJniPartition(t *testing.T) {
- bp := `
- cc_library {
- name: "libjni_system",
- system_shared_libs: [],
- sdk_version: "current",
- stl: "none",
- }
-
- cc_library {
- name: "libjni_system_ext",
- system_shared_libs: [],
- sdk_version: "current",
- stl: "none",
- system_ext_specific: true,
- }
-
- cc_library {
- name: "libjni_odm",
- system_shared_libs: [],
- sdk_version: "current",
- stl: "none",
- device_specific: true,
- }
-
- cc_library {
- name: "libjni_product",
- system_shared_libs: [],
- sdk_version: "current",
- stl: "none",
- product_specific: true,
- }
-
- cc_library {
- name: "libjni_vendor",
- system_shared_libs: [],
- sdk_version: "current",
- stl: "none",
- soc_specific: true,
- }
-
- android_app {
- name: "test_app_system_jni_system",
- privileged: true,
- platform_apis: true,
- certificate: "platform",
- jni_libs: ["libjni_system"],
- }
-
- android_app {
- name: "test_app_system_jni_system_ext",
- privileged: true,
- platform_apis: true,
- certificate: "platform",
- jni_libs: ["libjni_system_ext"],
- }
-
- android_app {
- name: "test_app_system_ext_jni_system",
- privileged: true,
- platform_apis: true,
- certificate: "platform",
- jni_libs: ["libjni_system"],
- system_ext_specific: true
- }
-
- android_app {
- name: "test_app_system_ext_jni_system_ext",
- sdk_version: "core_platform",
- jni_libs: ["libjni_system_ext"],
- system_ext_specific: true
- }
-
- android_app {
- name: "test_app_product_jni_product",
- sdk_version: "core_platform",
- jni_libs: ["libjni_product"],
- product_specific: true
- }
-
- android_app {
- name: "test_app_vendor_jni_odm",
- sdk_version: "core_platform",
- jni_libs: ["libjni_odm"],
- soc_specific: true
- }
-
- android_app {
- name: "test_app_odm_jni_vendor",
- sdk_version: "core_platform",
- jni_libs: ["libjni_vendor"],
- device_specific: true
- }
- android_app {
- name: "test_app_system_jni_multiple",
- privileged: true,
- platform_apis: true,
- certificate: "platform",
- jni_libs: ["libjni_system", "libjni_system_ext"],
- }
- android_app {
- name: "test_app_vendor_jni_multiple",
- sdk_version: "core_platform",
- jni_libs: ["libjni_odm", "libjni_vendor"],
- soc_specific: true
- }
- `
- arch := "arm64"
+func TestJniAsRequiredDeps(t *testing.T) {
ctx := android.GroupFixturePreparers(
PrepareForTestWithJavaDefaultModules,
cc.PrepareForTestWithCcDefaultModules,
android.PrepareForTestWithAndroidMk,
- android.FixtureModifyConfig(func(config android.Config) {
- config.TestProductVariables.DeviceArch = proptools.StringPtr(arch)
- }),
- ).
- RunTestWithBp(t, bp)
- testCases := []struct {
- name string
- partitionNames []string
- partitionTags []string
+ ).RunTestWithBp(t, `
+ android_app {
+ name: "app",
+ jni_libs: ["libjni"],
+ platform_apis: true,
+ }
+
+ android_app {
+ name: "app_embedded",
+ jni_libs: ["libjni"],
+ platform_apis: true,
+ use_embedded_native_libs: true,
+ }
+
+ cc_library {
+ name: "libjni",
+ system_shared_libs: [],
+ stl: "none",
+ }
+ `)
+
+ testcases := []struct {
+ name string
+ expected []string
}{
- {"test_app_system_jni_system", []string{"libjni_system"}, []string{""}},
- {"test_app_system_jni_system_ext", []string{"libjni_system_ext"}, []string{"_SYSTEM_EXT"}},
- {"test_app_system_ext_jni_system", []string{"libjni_system"}, []string{""}},
- {"test_app_system_ext_jni_system_ext", []string{"libjni_system_ext"}, []string{"_SYSTEM_EXT"}},
- {"test_app_product_jni_product", []string{"libjni_product"}, []string{"_PRODUCT"}},
- {"test_app_vendor_jni_odm", []string{"libjni_odm"}, []string{"_ODM"}},
- {"test_app_odm_jni_vendor", []string{"libjni_vendor"}, []string{"_VENDOR"}},
- {"test_app_system_jni_multiple", []string{"libjni_system", "libjni_system_ext"}, []string{"", "_SYSTEM_EXT"}},
- {"test_app_vendor_jni_multiple", []string{"libjni_odm", "libjni_vendor"}, []string{"_ODM", "_VENDOR"}},
+ {
+ name: "app",
+ expected: []string{"libjni"},
+ },
+ {
+ name: "app_embedded",
+ expected: nil,
+ },
}
- for _, test := range testCases {
- t.Run(test.name, func(t *testing.T) {
- mod := ctx.ModuleForTests(test.name, "android_common").Module()
- entry := android.AndroidMkEntriesForTest(t, ctx.TestContext, mod)[0]
- for i := range test.partitionNames {
- actual := entry.EntryMap["LOCAL_SOONG_JNI_LIBS_PARTITION_"+arch][i]
- expected := test.partitionNames[i] + ":" + test.partitionTags[i]
- android.AssertStringEquals(t, "Expected and actual differ", expected, actual)
- }
- })
+ for _, tc := range testcases {
+ mod := ctx.ModuleForTests(tc.name, "android_common").Module()
+ entries := android.AndroidMkEntriesForTest(t, ctx.TestContext, mod)[0]
+ required := entries.EntryMap["LOCAL_REQUIRED_MODULES"]
+ android.AssertDeepEquals(t, "unexpected required deps", tc.expected, required)
}
}
diff --git a/java/app.go b/java/app.go
index bab4130..ea72157 100644
--- a/java/app.go
+++ b/java/app.go
@@ -274,16 +274,37 @@
variation := append(jniTarget.Variations(),
blueprint.Variation{Mutator: "link", Variation: "shared"})
- // If the app builds against an Android SDK use the SDK variant of JNI dependencies
- // unless jni_uses_platform_apis is set.
- // Don't require the SDK variant for apps that are shipped on vendor, etc., as they already
- // have stable APIs through the VNDK.
- if (usesSDK && !a.RequiresStableAPIs(ctx) &&
- !Bool(a.appProperties.Jni_uses_platform_apis)) ||
- Bool(a.appProperties.Jni_uses_sdk_apis) {
+ // Test whether to use the SDK variant or the non-SDK variant of JNI dependencies.
+ // Many factors are considered here.
+ // 1. Basically, the selection follows whether the app has sdk_version set or not.
+ jniUsesSdkVariant := usesSDK
+ // 2. However, jni_uses_platform_apis and jni_uses_sdk_apis can override it
+ if Bool(a.appProperties.Jni_uses_sdk_apis) {
+ jniUsesSdkVariant = true
+ }
+ if Bool(a.appProperties.Jni_uses_platform_apis) {
+ jniUsesSdkVariant = false
+ }
+ // 3. Then the use of SDK variant is again prohibited for the following cases:
+ // 3.1. the app is shipped on unbundled partitions like vendor. Since the entire
+ // partition (not only the app) is considered unbudled, there's no need to use the
+ // SDK variant.
+ // 3.2. the app doesn't support embedding the JNI libs
+ if a.RequiresStableAPIs(ctx) || !a.shouldEmbedJnis(ctx) {
+ jniUsesSdkVariant = false
+ }
+ if jniUsesSdkVariant {
variation = append(variation, blueprint.Variation{Mutator: "sdk", Variation: "sdk"})
}
- ctx.AddFarVariationDependencies(variation, jniLibTag, a.appProperties.Jni_libs...)
+
+ // Use the installable dep tag when the JNIs are not embedded
+ var tag dependencyTag
+ if a.shouldEmbedJnis(ctx) {
+ tag = jniLibTag
+ } else {
+ tag = jniInstallTag
+ }
+ ctx.AddFarVariationDependencies(variation, tag, a.appProperties.Jni_libs...)
}
for _, aconfig_declaration := range a.aaptProperties.Flags_packages {
ctx.AddDependency(ctx.Module(), aconfigDeclarationTag, aconfig_declaration)
@@ -334,6 +355,7 @@
func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
a.checkAppSdkVersions(ctx)
+ a.checkEmbedJnis(ctx)
a.generateAndroidBuildActions(ctx)
a.generateJavaUsedByApex(ctx)
}
@@ -367,6 +389,17 @@
a.checkSdkVersions(ctx)
}
+// Ensures that use_embedded_native_libs are set for apk-in-apex
+func (a *AndroidApp) checkEmbedJnis(ctx android.BaseModuleContext) {
+ apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider)
+ apkInApex := !apexInfo.IsForPlatform()
+ hasJnis := len(a.appProperties.Jni_libs) > 0
+
+ if apkInApex && hasJnis && !Bool(a.appProperties.Use_embedded_native_libs) {
+ ctx.ModuleErrorf("APK in APEX should have use_embedded_native_libs: true")
+ }
+}
+
// If an updatable APK sets min_sdk_version, min_sdk_vesion of JNI libs should match with it.
// This check is enforced for "updatable" APKs (including APK-in-APEX).
func (a *AndroidApp) checkJniLibsSdkVersion(ctx android.ModuleContext, minSdkVersion android.ApiLevel) {
@@ -422,9 +455,9 @@
}
func (a *AndroidApp) shouldEmbedJnis(ctx android.BaseModuleContext) bool {
- apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider)
return ctx.Config().UnbundledBuild() || Bool(a.appProperties.Use_embedded_native_libs) ||
- !apexInfo.IsForPlatform() || a.appProperties.AlwaysPackageNativeLibs
+ Bool(a.appProperties.Updatable) ||
+ a.appProperties.AlwaysPackageNativeLibs
}
func generateAaptRenamePackageFlags(packageName string, renameResourcesPackage bool) []string {
@@ -818,7 +851,9 @@
dexJarFile, packageResources := a.dexBuildActions(ctx)
- jniLibs, prebuiltJniPackages, certificates := collectAppDeps(ctx, a, a.shouldEmbedJnis(ctx), !Bool(a.appProperties.Jni_uses_platform_apis))
+ // No need to check the SDK version of the JNI deps unless we embed them
+ checkNativeSdkVersion := a.shouldEmbedJnis(ctx) && !Bool(a.appProperties.Jni_uses_platform_apis)
+ jniLibs, prebuiltJniPackages, certificates := collectAppDeps(ctx, a, a.shouldEmbedJnis(ctx), checkNativeSdkVersion)
jniJarFile := a.jniBuildActions(jniLibs, prebuiltJniPackages, ctx)
if ctx.Failed() {
@@ -900,6 +935,22 @@
installed := ctx.InstallFile(a.installDir, extra.Base(), extra)
extraInstalledPaths = append(extraInstalledPaths, installed)
}
+ // If we don't embed jni libs, make sure that those are installed along with the
+ // app, and also place symlinks to the installed paths under the lib/<arch>
+ // directory of the app installation directory. ex:
+ // /system/app/MyApp/lib/arm64/libfoo.so -> /system/lib64/libfoo.so
+ if !a.embeddedJniLibs {
+ for _, jniLib := range jniLibs {
+ archStr := jniLib.target.Arch.ArchType.String()
+ symlinkDir := a.installDir.Join(ctx, "lib", archStr)
+ for _, installedLib := range jniLib.installPaths {
+ // install the symlink itself
+ symlinkName := installedLib.Base()
+ symlinkTarget := android.InstallPathToOnDevicePath(ctx, installedLib)
+ ctx.InstallAbsoluteSymlink(symlinkDir, symlinkName, symlinkTarget)
+ }
+ }
+ }
ctx.InstallFile(a.installDir, a.outputFile.Base(), a.outputFile, extraInstalledPaths...)
}
@@ -987,6 +1038,7 @@
coverageFile: dep.CoverageOutputFile(),
unstrippedFile: dep.UnstrippedOutputFile(),
partition: dep.Partition(),
+ installPaths: dep.FilesToInstall(),
})
} else if ctx.Config().AllowMissingDependencies() {
ctx.AddMissingDependencies([]string{otherName})
diff --git a/java/java.go b/java/java.go
index f038f63..e3f4824 100644
--- a/java/java.go
+++ b/java/java.go
@@ -366,14 +366,14 @@
toolchain bool
static bool
+
+ installable bool
}
-// installDependencyTag is a dependency tag that is annotated to cause the installed files of the
-// dependency to be installed when the parent module is installed.
-type installDependencyTag struct {
- blueprint.BaseDependencyTag
- android.InstallAlwaysNeededDependencyTag
- name string
+var _ android.InstallNeededDependencyTag = (*dependencyTag)(nil)
+
+func (d dependencyTag) InstallDepNeeded() bool {
+ return d.installable
}
func (d dependencyTag) LicenseAnnotations() []android.LicenseAnnotation {
@@ -405,7 +405,7 @@
}
func IsJniDepTag(depTag blueprint.DependencyTag) bool {
- return depTag == jniLibTag
+ return depTag == jniLibTag || depTag == jniInstallTag
}
var (
@@ -434,8 +434,8 @@
javaApiContributionTag = dependencyTag{name: "java-api-contribution"}
depApiSrcsTag = dependencyTag{name: "dep-api-srcs"}
aconfigDeclarationTag = dependencyTag{name: "aconfig-declaration"}
- jniInstallTag = installDependencyTag{name: "jni install"}
- binaryInstallTag = installDependencyTag{name: "binary install"}
+ jniInstallTag = dependencyTag{name: "jni install", runtimeLinked: true, installable: true}
+ binaryInstallTag = dependencyTag{name: "binary install", runtimeLinked: true, installable: true}
usesLibReqTag = makeUsesLibraryDependencyTag(dexpreopt.AnySdkVersion, false)
usesLibOptTag = makeUsesLibraryDependencyTag(dexpreopt.AnySdkVersion, true)
usesLibCompat28OptTag = makeUsesLibraryDependencyTag(28, true)
@@ -491,6 +491,7 @@
coverageFile android.OptionalPath
unstrippedFile android.Path
partition string
+ installPaths android.InstallPaths
}
func sdkDeps(ctx android.BottomUpMutatorContext, sdkContext android.SdkContext, d dexer) {
diff --git a/java/platform_bootclasspath.go b/java/platform_bootclasspath.go
index 0f87b27..8d4cf68 100644
--- a/java/platform_bootclasspath.go
+++ b/java/platform_bootclasspath.go
@@ -294,6 +294,15 @@
// generateHiddenAPIBuildActions generates all the hidden API related build rules.
func (b *platformBootclasspathModule) generateHiddenAPIBuildActions(ctx android.ModuleContext, modules []android.Module, fragments []android.Module) bootDexJarByModule {
+ createEmptyHiddenApiFiles := func() {
+ paths := android.OutputPaths{b.hiddenAPIFlagsCSV, b.hiddenAPIIndexCSV, b.hiddenAPIMetadataCSV}
+ for _, path := range paths {
+ ctx.Build(pctx, android.BuildParams{
+ Rule: android.Touch,
+ Output: path,
+ })
+ }
+ }
// Save the paths to the monolithic files for retrieval via OutputFiles().
b.hiddenAPIFlagsCSV = hiddenAPISingletonPaths(ctx).flags
@@ -306,13 +315,7 @@
// optimization that can be used to reduce the incremental build time but as its name suggests it
// can be unsafe to use, e.g. when the changes affect anything that goes on the bootclasspath.
if ctx.Config().DisableHiddenApiChecks() {
- paths := android.OutputPaths{b.hiddenAPIFlagsCSV, b.hiddenAPIIndexCSV, b.hiddenAPIMetadataCSV}
- for _, path := range paths {
- ctx.Build(pctx, android.BuildParams{
- Rule: android.Touch,
- Output: path,
- })
- }
+ createEmptyHiddenApiFiles()
return bootDexJarByModule
}
@@ -327,6 +330,8 @@
if len(classesJars) == 0 {
// This product does not include any monolithic jars. Monolithic hiddenapi flag generation is not required.
+ // However, generate an empty file so that the dist tags in f/b/boot/Android.bp can be resolved, and `m dist` works.
+ createEmptyHiddenApiFiles()
return bootDexJarByModule
}
diff --git a/java/sdk_library.go b/java/sdk_library.go
index 2d7ea63..645f513 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -1650,6 +1650,14 @@
module.dexpreopter.configPath = module.implLibraryModule.dexpreopter.configPath
module.dexpreopter.outputProfilePathOnHost = module.implLibraryModule.dexpreopter.outputProfilePathOnHost
+ // Properties required for Library.AndroidMkEntries
+ module.logtagsSrcs = module.implLibraryModule.logtagsSrcs
+ module.dexpreopter.builtInstalled = module.implLibraryModule.dexpreopter.builtInstalled
+ module.jacocoReportClassesFile = module.implLibraryModule.jacocoReportClassesFile
+ module.dexer.proguardDictionary = module.implLibraryModule.dexer.proguardDictionary
+ module.dexer.proguardUsageZip = module.implLibraryModule.dexer.proguardUsageZip
+ module.linter.reports = module.implLibraryModule.linter.reports
+
if !module.Host() {
module.hostdexInstallFile = module.implLibraryModule.hostdexInstallFile
}
@@ -1814,7 +1822,6 @@
props := struct {
Name *string
Visibility []string
- Instrument bool
Libs []string
Static_libs []string
Apex_available []string
@@ -1822,8 +1829,6 @@
}{
Name: proptools.StringPtr(module.implLibraryModuleName()),
Visibility: visibility,
- // Set the instrument property to ensure it is instrumented when instrumentation is required.
- Instrument: true,
Libs: append(module.properties.Libs, module.sdkLibraryProperties.Impl_only_libs...),
diff --git a/ui/build/soong.go b/ui/build/soong.go
index 79584c6..9955b1f 100644
--- a/ui/build/soong.go
+++ b/ui/build/soong.go
@@ -15,7 +15,6 @@
package build
import (
- "android/soong/ui/tracer"
"fmt"
"io/fs"
"os"
@@ -26,6 +25,8 @@
"sync/atomic"
"time"
+ "android/soong/ui/tracer"
+
"android/soong/bazel"
"android/soong/ui/metrics"
"android/soong/ui/metrics/metrics_proto"
@@ -270,7 +271,13 @@
} else if !exists {
// The tree is out of date for the current epoch, delete files used by bootstrap
// and force the primary builder to rerun.
- os.Remove(config.SoongNinjaFile())
+ soongNinjaFile := config.SoongNinjaFile()
+ os.Remove(soongNinjaFile)
+ for _, file := range blueprint.GetNinjaShardFiles(soongNinjaFile) {
+ if ok, _ := fileExists(file); ok {
+ os.Remove(file)
+ }
+ }
for _, globFile := range bootstrapGlobFileList(config) {
os.Remove(globFile)
}
@@ -680,7 +687,13 @@
loadSoongBuildMetrics(ctx, config, beforeSoongTimestamp)
- distGzipFile(ctx, config, config.SoongNinjaFile(), "soong")
+ soongNinjaFile := config.SoongNinjaFile()
+ distGzipFile(ctx, config, soongNinjaFile, "soong")
+ for _, file := range blueprint.GetNinjaShardFiles(soongNinjaFile) {
+ if ok, _ := fileExists(file); ok {
+ distGzipFile(ctx, config, file, "soong")
+ }
+ }
distFile(ctx, config, config.SoongVarsFile(), "soong")
if !config.SkipKati() {