Merge "Change the global CFI flag to default to enabled."
diff --git a/Android.bp b/Android.bp
index 2ae993f..61ef41e 100644
--- a/Android.bp
+++ b/Android.bp
@@ -127,6 +127,7 @@
"cc/proto.go",
"cc/relocation_packer.go",
"cc/sanitize.go",
+ "cc/sabi.go",
"cc/stl.go",
"cc/strip.go",
"cc/tidy.go",
diff --git a/android/arch.go b/android/arch.go
index f9697bc..2d0515f 100644
--- a/android/arch.go
+++ b/android/arch.go
@@ -716,17 +716,19 @@
prefix := "target.android32"
a.appendProperties(ctx, genProps, targetProp, field, prefix)
}
- }
- if arch.ArchType == X86 && hasArmAbi(arch) {
- field := "Arm_on_x86"
- prefix := "target.arm_on_x86"
- a.appendProperties(ctx, genProps, targetProp, field, prefix)
- }
- if arch.ArchType == X86_64 && hasArmAbi(arch) {
- field := "Arm_on_x86_64"
- prefix := "target.arm_on_x86_64"
- a.appendProperties(ctx, genProps, targetProp, field, prefix)
+ if arch.ArchType == X86 && (hasArmAbi(arch) ||
+ hasArmAndroidArch(ctx.AConfig().Targets[Device])) {
+ field := "Arm_on_x86"
+ prefix := "target.arm_on_x86"
+ a.appendProperties(ctx, genProps, targetProp, field, prefix)
+ }
+ if arch.ArchType == X86_64 && (hasArmAbi(arch) ||
+ hasArmAndroidArch(ctx.AConfig().Targets[Device])) {
+ field := "Arm_on_x86_64"
+ prefix := "target.arm_on_x86_64"
+ a.appendProperties(ctx, genProps, targetProp, field, prefix)
+ }
}
}
}
@@ -835,6 +837,16 @@
return false
}
+// hasArmArch returns true if targets has at least arm Android arch
+func hasArmAndroidArch(targets []Target) bool {
+ for _, target := range targets {
+ if target.Os == Android && target.Arch.ArchType == Arm {
+ return true
+ }
+ }
+ return false
+}
+
type archConfig struct {
arch string
archVariant string
diff --git a/android/module.go b/android/module.go
index 963d611..2b93d8e 100644
--- a/android/module.go
+++ b/android/module.go
@@ -754,9 +754,16 @@
// modules listed in srcFiles using ":module" syntax
func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) {
var deps []string
+ set := make(map[string]bool)
+
for _, s := range srcFiles {
if m := SrcIsModule(s); m != "" {
- deps = append(deps, m)
+ if _, found := set[m]; found {
+ ctx.ModuleErrorf("found source dependency duplicate: %q!", m)
+ } else {
+ set[m] = true
+ deps = append(deps, m)
+ }
}
}
diff --git a/android/paths.go b/android/paths.go
index 969c753..75e5980 100644
--- a/android/paths.go
+++ b/android/paths.go
@@ -576,6 +576,30 @@
var _ Path = ModuleOutPath{}
+// PathForVndkRefDump returns an OptionalPath representing the path of the reference
+// abi dump for the given module. This is not guaranteed to be valid.
+func PathForVndkRefAbiDump(ctx ModuleContext, version, fileName string, vndkOrNdk, isSourceDump bool) OptionalPath {
+ archName := ctx.Arch().ArchType.Name
+ var sourceOrBinaryDir string
+ var vndkOrNdkDir string
+ var ext string
+ if isSourceDump {
+ ext = ".lsdump"
+ sourceOrBinaryDir = "source-based"
+ } else {
+ ext = ".bdump"
+ sourceOrBinaryDir = "binary-based"
+ }
+ if vndkOrNdk {
+ vndkOrNdkDir = "vndk"
+ } else {
+ vndkOrNdkDir = "ndk"
+ }
+ refDumpFileStr := "prebuilts/abi-dumps/" + vndkOrNdkDir + "/" + version + "/" +
+ archName + "/" + sourceOrBinaryDir + "/" + fileName + ext
+ return OptionalPathForSource(ctx, "", refDumpFileStr)
+}
+
// PathForModuleOut returns a Path representing the paths... under the module's
// output directory.
func PathForModuleOut(ctx ModuleContext, paths ...string) ModuleOutPath {
diff --git a/cc/androidmk.go b/cc/androidmk.go
index 59a1db8..481dbb4 100644
--- a/cc/androidmk.go
+++ b/cc/androidmk.go
@@ -141,6 +141,13 @@
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) error {
library.androidMkWriteExportedFlags(w)
+ fmt.Fprintln(w, "LOCAL_ADDITIONAL_DEPENDENCIES := ")
+ if library.sAbiOutputFile.Valid() {
+ fmt.Fprintln(w, "LOCAL_ADDITIONAL_DEPENDENCIES += ", library.sAbiOutputFile.String())
+ if library.sAbiDiff.Valid() && !library.static() {
+ fmt.Fprintln(w, "LOCAL_ADDITIONAL_DEPENDENCIES += ", library.sAbiDiff.String())
+ }
+ }
fmt.Fprintln(w, "LOCAL_BUILT_MODULE_STEM := $(LOCAL_MODULE)"+outputFile.Ext())
diff --git a/cc/binary.go b/cc/binary.go
index b4610ed..cd440ea 100644
--- a/cc/binary.go
+++ b/cc/binary.go
@@ -214,7 +214,7 @@
// all code is position independent, and then those warnings get promoted to
// errors.
if !ctx.Windows() {
- flags.CFlags = append(flags.CFlags, "-fpie")
+ flags.CFlags = append(flags.CFlags, "-fPIE")
}
if ctx.toolchain().Bionic() {
diff --git a/cc/builder.go b/cc/builder.go
index 0694cb7..81ecd73 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -168,6 +168,38 @@
Description: "yasm $out",
},
"asFlags")
+
+ _ = pctx.SourcePathVariable("sAbiDumper", "prebuilts/build-tools/${config.HostPrebuiltTag}/bin/header-abi-dumper")
+
+ sAbiDump = pctx.AndroidStaticRule("sAbiDump",
+ blueprint.RuleParams{
+ Command: "rm -f $out && $sAbiDumper -o ${out} $in $exportDirs -- $cFlags -Wno-packed -Qunused-arguments -isystem ${config.RSIncludePath}",
+ CommandDeps: []string{"$sAbiDumper"},
+ Description: "header-abi-dumper $in -o $out $exportDirs",
+ },
+ "cFlags", "exportDirs")
+
+ _ = pctx.SourcePathVariable("sAbiLinker", "prebuilts/build-tools/${config.HostPrebuiltTag}/bin/header-abi-linker")
+
+ sAbiLink = pctx.AndroidStaticRule("sAbiLink",
+ blueprint.RuleParams{
+ Command: "$sAbiLinker -o ${out} $symbolFile -arch $arch -api $api $exportedHeaderFlags @${out}.rsp ",
+ CommandDeps: []string{"$sAbiLinker"},
+ Description: "header-abi-linker $in -o $out",
+ Rspfile: "${out}.rsp",
+ RspfileContent: "${in}",
+ },
+ "symbolFile", "arch", "api", "exportedHeaderFlags")
+
+ _ = pctx.SourcePathVariable("sAbiDiffer", "prebuilts/build-tools/${config.HostPrebuiltTag}/bin/header-abi-diff")
+ // Abidiff check turned on in advice-only mode. Builds will not fail on abi incompatibilties / extensions.
+ sAbiDiff = pctx.AndroidStaticRule("sAbiDiff",
+ blueprint.RuleParams{
+ Command: "$sAbiDiffer -advice-only -o ${out} -new $in -old $referenceDump",
+ CommandDeps: []string{"$sAbiDiffer"},
+ Description: "header-abi-diff -o ${out} -new $in -old $referenceDump",
+ },
+ "referenceDump")
)
func init() {
@@ -194,12 +226,14 @@
yaccFlags string
protoFlags string
tidyFlags string
+ sAbiFlags string
yasmFlags string
aidlFlags string
toolchain config.Toolchain
clang bool
tidy bool
coverage bool
+ sAbiDump bool
systemIncludeFlags string
@@ -214,6 +248,7 @@
objFiles android.Paths
tidyFiles android.Paths
coverageFiles android.Paths
+ sAbiDumpFiles android.Paths
}
func (a Objects) Copy() Objects {
@@ -221,6 +256,7 @@
objFiles: append(android.Paths{}, a.objFiles...),
tidyFiles: append(android.Paths{}, a.tidyFiles...),
coverageFiles: append(android.Paths{}, a.coverageFiles...),
+ sAbiDumpFiles: append(android.Paths{}, a.sAbiDumpFiles...),
}
}
@@ -229,6 +265,7 @@
objFiles: append(a.objFiles, b.objFiles...),
tidyFiles: append(a.tidyFiles, b.tidyFiles...),
coverageFiles: append(a.coverageFiles, b.coverageFiles...),
+ sAbiDumpFiles: append(a.sAbiDumpFiles, b.sAbiDumpFiles...),
}
}
@@ -265,6 +302,10 @@
flags.systemIncludeFlags,
flags.asFlags,
}, " ")
+ var sAbiDumpFiles android.Paths
+ if flags.sAbiDump && flags.clang {
+ sAbiDumpFiles = make(android.Paths, 0, len(srcFiles))
+ }
if flags.clang {
cflags += " ${config.NoOverrideClangGlobalCflags}"
@@ -296,6 +337,7 @@
var ccCmd string
tidy := flags.tidy && flags.clang
coverage := flags.coverage
+ dump := flags.sAbiDump && flags.clang
switch srcFile.Ext() {
case ".S", ".s":
@@ -303,6 +345,7 @@
moduleCflags = asflags
tidy = false
coverage = false
+ dump = false
case ".c":
ccCmd = "gcc"
moduleCflags = cflags
@@ -366,12 +409,29 @@
})
}
+ if dump {
+ sAbiDumpFile := android.ObjPathWithExt(ctx, subdir, srcFile, "sdump")
+ sAbiDumpFiles = append(sAbiDumpFiles, sAbiDumpFile)
+
+ ctx.ModuleBuild(pctx, android.ModuleBuildParams{
+ Rule: sAbiDump,
+ Output: sAbiDumpFile,
+ Input: srcFile,
+ Implicit: objFile,
+ Args: map[string]string{
+ "cFlags": moduleCflags,
+ "exportDirs": flags.sAbiFlags,
+ },
+ })
+ }
+
}
return Objects{
objFiles: objFiles,
tidyFiles: tidyFiles,
coverageFiles: coverageFiles,
+ sAbiDumpFiles: sAbiDumpFiles,
}
}
@@ -554,6 +614,47 @@
})
}
+// Generate a rule to combine .dump sAbi dump files from multiple source files
+// into a single .ldump sAbi dump file
+func TransformDumpToLinkedDump(ctx android.ModuleContext, sAbiDumps android.Paths,
+ symbolFile android.OptionalPath, apiLevel, baseName, exportedHeaderFlags string) android.OptionalPath {
+ outputFile := android.PathForModuleOut(ctx, baseName+".lsdump")
+ var symbolFileStr string
+ var linkedDumpDep android.Path
+ if symbolFile.Valid() {
+ symbolFileStr = "-v " + symbolFile.Path().String()
+ linkedDumpDep = symbolFile.Path()
+ }
+ ctx.ModuleBuild(pctx, android.ModuleBuildParams{
+ Rule: sAbiLink,
+ Output: outputFile,
+ Inputs: sAbiDumps,
+ Implicit: linkedDumpDep,
+ Args: map[string]string{
+ "symbolFile": symbolFileStr,
+ "arch": ctx.Arch().ArchType.Name,
+ "api": apiLevel,
+ "exportedHeaderFlags": exportedHeaderFlags,
+ },
+ })
+ return android.OptionalPathForPath(outputFile)
+}
+
+func SourceAbiDiff(ctx android.ModuleContext, inputDump android.Path, referenceDump android.Path,
+ baseName string) android.OptionalPath {
+ outputFile := android.PathForModuleOut(ctx, baseName+".abidiff")
+ ctx.ModuleBuild(pctx, android.ModuleBuildParams{
+ Rule: sAbiDiff,
+ Output: outputFile,
+ Input: inputDump,
+ Implicit: referenceDump,
+ Args: map[string]string{
+ "referenceDump": referenceDump.String(),
+ },
+ })
+ return android.OptionalPathForPath(outputFile)
+}
+
// Generate a rule for extract a table of contents from a shared library (.so)
func TransformSharedObjectToToc(ctx android.ModuleContext, inputFile android.WritablePath,
outputFile android.WritablePath, flags builderFlags) {
diff --git a/cc/cc.go b/cc/cc.go
index 63caf3a..6e2f6a5 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -49,6 +49,7 @@
ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
ctx.BottomUp("coverage", coverageLinkingMutator).Parallel()
+ ctx.TopDown("vndk_deps", sabiDepsMutator)
})
pctx.Import("android/soong/cc/config")
@@ -108,6 +109,7 @@
LdFlags []string // Flags that apply to linker command lines
libFlags []string // Flags to add libraries early to the link order
TidyFlags []string // Flags that apply to clang-tidy
+ SAbiFlags []string // Flags that apply to header-abi-dumper
YasmFlags []string // Flags that apply to yasm assembly source files
// Global include flags that apply to C, C++, and assembly source files
@@ -118,6 +120,7 @@
Clang bool
Tidy bool
Coverage bool
+ SAbiDump bool
RequiredInstructionSet string
DynamicLinker string
@@ -177,6 +180,7 @@
sdk() bool
sdkVersion() string
vndk() bool
+ createVndkSourceAbiDump() bool
selectedStl() string
baseModuleName() string
}
@@ -283,6 +287,7 @@
stl *stl
sanitize *sanitize
coverage *coverage
+ sabi *sabi
androidMkSharedLibDeps []string
@@ -316,6 +321,9 @@
if c.coverage != nil {
props = append(props, c.coverage.props()...)
}
+ if c.sabi != nil {
+ props = append(props, c.sabi.props()...)
+ }
for _, feature := range c.features {
props = append(props, feature.props()...)
}
@@ -418,6 +426,12 @@
return ctx.mod.vndk()
}
+// Create source abi dumps if the module belongs to the list of VndkLibraries.
+func (ctx *moduleContextImpl) createVndkSourceAbiDump() bool {
+ return ctx.ctx.Device() && (inList(ctx.baseModuleName(), config.LLndkLibraries())) ||
+ (inList(ctx.baseModuleName(), config.VndkLibraries()))
+}
+
func (ctx *moduleContextImpl) selectedStl() string {
if stl := ctx.mod.stl; stl != nil {
return stl.Properties.SelectedStl
@@ -444,6 +458,7 @@
module.stl = &stl{}
module.sanitize = &sanitize{}
module.coverage = &coverage{}
+ module.sabi = &sabi{}
return module
}
@@ -492,6 +507,9 @@
if c.coverage != nil {
flags = c.coverage.flags(ctx, flags)
}
+ if c.sabi != nil {
+ flags = c.sabi.flags(ctx, flags)
+ }
for _, feature := range c.features {
flags = feature.flags(ctx, flags)
}
@@ -566,6 +584,9 @@
if c.coverage != nil {
c.coverage.begin(ctx)
}
+ if c.sabi != nil {
+ c.sabi.begin(ctx)
+ }
for _, feature := range c.features {
feature.begin(ctx)
}
@@ -596,6 +617,9 @@
if c.coverage != nil {
deps = c.coverage.deps(ctx, deps)
}
+ if c.sabi != nil {
+ deps = c.sabi.deps(ctx, deps)
+ }
for _, feature := range c.features {
deps = feature.deps(ctx, deps)
}
@@ -999,9 +1023,12 @@
}
// When combining coverage files for shared libraries and executables, coverage files
- // in static libraries act as if they were whole static libraries.
+ // in static libraries act as if they were whole static libraries. The same goes for
+ // source based Abi dump files.
depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
staticLib.objs().coverageFiles...)
+ depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
+ staticLib.objs().sAbiDumpFiles...)
}
if ptr != nil {
@@ -1085,6 +1112,7 @@
&InstallerProperties{},
&TidyProperties{},
&CoverageProperties{},
+ &SAbiProperties{},
)
return android.InitDefaultsModule(module, module, props...)
diff --git a/cc/library.go b/cc/library.go
index 0ba7088..e2ec584 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -21,6 +21,7 @@
"github.com/google/blueprint/pathtools"
"android/soong/android"
+ "android/soong/cc/config"
)
type LibraryProperties struct {
@@ -220,9 +221,17 @@
sanitize *sanitize
+ sabi *sabi
+
// Output archive of gcno coverage information files
coverageOutputFile android.OptionalPath
+ // linked Source Abi Dump
+ sAbiOutputFile android.OptionalPath
+
+ // Source Abi Diff
+ sAbiDiff android.OptionalPath
+
// Decorated interafaces
*baseCompiler
*baseLinker
@@ -316,7 +325,20 @@
}
return Objects{}
}
+ if ctx.createVndkSourceAbiDump() || (library.sabi.Properties.CreateSAbiDumps && ctx.Device()) {
+ exportIncludeDirs := android.PathsForModuleSrc(ctx, library.flagExporter.Properties.Export_include_dirs)
+ var SourceAbiFlags []string
+ for _, dir := range exportIncludeDirs.Strings() {
+ SourceAbiFlags = append(SourceAbiFlags, "-I "+dir)
+ }
+ flags.SAbiFlags = SourceAbiFlags
+ total_length := len(library.baseCompiler.Properties.Srcs) + len(deps.GeneratedSources) + len(library.Properties.Shared.Srcs) +
+ len(library.Properties.Static.Srcs)
+ if total_length > 0 {
+ flags.SAbiDump = true
+ }
+ }
objs := library.baseCompiler.compile(ctx, flags, deps)
library.reuseObjects = objs
buildFlags := flagsToBuilderFlags(flags)
@@ -534,11 +556,45 @@
objs.coverageFiles = append(objs.coverageFiles, deps.StaticLibObjs.coverageFiles...)
objs.coverageFiles = append(objs.coverageFiles, deps.WholeStaticLibObjs.coverageFiles...)
+
+ objs.sAbiDumpFiles = append(objs.sAbiDumpFiles, deps.StaticLibObjs.sAbiDumpFiles...)
+ objs.sAbiDumpFiles = append(objs.sAbiDumpFiles, deps.WholeStaticLibObjs.sAbiDumpFiles...)
+
library.coverageOutputFile = TransformCoverageFilesToLib(ctx, objs, builderFlags, library.getLibName(ctx))
+ library.linkSAbiDumpFiles(ctx, objs, fileName)
return ret
}
+func (library *libraryDecorator) linkSAbiDumpFiles(ctx ModuleContext, objs Objects, fileName string) {
+ //Also take into account object re-use.
+ if len(objs.sAbiDumpFiles) > 0 && ctx.createVndkSourceAbiDump() {
+ refSourceDumpFile := android.PathForVndkRefAbiDump(ctx, "current", fileName, vndkVsNdk(ctx), true)
+ versionScript := android.OptionalPathForModuleSrc(ctx, library.Properties.Version_script)
+ var symbolFile android.OptionalPath
+ if versionScript.Valid() {
+ symbolFile = versionScript
+ }
+ exportIncludeDirs := android.PathsForModuleSrc(ctx, library.flagExporter.Properties.Export_include_dirs)
+ var SourceAbiFlags []string
+ for _, dir := range exportIncludeDirs.Strings() {
+ SourceAbiFlags = append(SourceAbiFlags, "-I "+dir)
+ }
+ exportedHeaderFlags := strings.Join(SourceAbiFlags, " ")
+ library.sAbiOutputFile = TransformDumpToLinkedDump(ctx, objs.sAbiDumpFiles, symbolFile, "current", fileName, exportedHeaderFlags)
+ if refSourceDumpFile.Valid() {
+ library.sAbiDiff = SourceAbiDiff(ctx, library.sAbiOutputFile.Path(), refSourceDumpFile.Path(), fileName)
+ }
+ }
+}
+
+func vndkVsNdk(ctx ModuleContext) bool {
+ if inList(ctx.baseModuleName(), config.LLndkLibraries()) {
+ return false
+ }
+ return true
+}
+
func (library *libraryDecorator) link(ctx ModuleContext,
flags Flags, deps PathDeps, objs Objects) android.Path {
@@ -604,7 +660,7 @@
}
func (library *libraryDecorator) install(ctx ModuleContext, file android.Path) {
- if !ctx.static() {
+ if library.shared() {
library.baseInstaller.install(ctx, file)
}
}
@@ -656,6 +712,7 @@
baseLinker: NewBaseLinker(),
baseInstaller: NewBaseInstaller("lib", "lib64", InstallInSystem),
sanitize: module.sanitize,
+ sabi: module.sabi,
}
module.compiler = library
diff --git a/cc/ndk_library.go b/cc/ndk_library.go
index 8f424d8..d769fea 100644
--- a/cc/ndk_library.go
+++ b/cc/ndk_library.go
@@ -116,19 +116,18 @@
}
minVersion := 9 // Minimum version supported by the NDK.
- firstArchVersions := map[string]int{
- "arm": 9,
- "arm64": 21,
- "mips": 9,
- "mips64": 21,
- "x86": 9,
- "x86_64": 21,
+ firstArchVersions := map[android.ArchType]int{
+ android.Arm: 9,
+ android.Arm64: 21,
+ android.Mips: 9,
+ android.Mips64: 21,
+ android.X86: 9,
+ android.X86_64: 21,
}
- archStr := arch.ArchType.String()
- firstArchVersion, ok := firstArchVersions[archStr]
+ firstArchVersion, ok := firstArchVersions[arch.ArchType]
if !ok {
- panic(fmt.Errorf("Arch %q not found in firstArchVersions", archStr))
+ panic(fmt.Errorf("Arch %q not found in firstArchVersions", arch.ArchType))
}
if apiLevel == "minimum" {
diff --git a/cc/sabi.go b/cc/sabi.go
new file mode 100644
index 0000000..7ae31c9
--- /dev/null
+++ b/cc/sabi.go
@@ -0,0 +1,63 @@
+// Copyright 2017 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package cc
+
+import (
+ "android/soong/android"
+ "github.com/google/blueprint"
+
+ "android/soong/cc/config"
+)
+
+type SAbiProperties struct {
+ CreateSAbiDumps bool `blueprint:"mutated"`
+}
+
+type sabi struct {
+ Properties SAbiProperties
+}
+
+func (sabimod *sabi) props() []interface{} {
+ return []interface{}{&sabimod.Properties}
+}
+
+func (sabimod *sabi) begin(ctx BaseModuleContext) {}
+
+func (sabimod *sabi) deps(ctx BaseModuleContext, deps Deps) Deps {
+ return deps
+}
+
+func (sabimod *sabi) flags(ctx ModuleContext, flags Flags) Flags {
+ return flags
+}
+
+func sabiDepsMutator(mctx android.TopDownMutatorContext) {
+ if c, ok := mctx.Module().(*Module); ok &&
+ ((inList(c.Name(), config.VndkLibraries())) || (inList(c.Name(), config.LLndkLibraries())) ||
+ (c.sabi != nil && c.sabi.Properties.CreateSAbiDumps)) {
+ mctx.VisitDirectDeps(func(m blueprint.Module) {
+ tag := mctx.OtherModuleDependencyTag(m)
+ switch tag {
+ case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
+
+ cc, _ := m.(*Module)
+ if cc == nil {
+ return
+ }
+ cc.sabi.Properties.CreateSAbiDumps = true
+ }
+ })
+ }
+}
diff --git a/cc/util.go b/cc/util.go
index 36d8dd2..18ad8a6 100644
--- a/cc/util.go
+++ b/cc/util.go
@@ -99,11 +99,13 @@
ldFlags: strings.Join(in.LdFlags, " "),
libFlags: strings.Join(in.libFlags, " "),
tidyFlags: strings.Join(in.TidyFlags, " "),
+ sAbiFlags: strings.Join(in.SAbiFlags, " "),
yasmFlags: strings.Join(in.YasmFlags, " "),
toolchain: in.Toolchain,
clang: in.Clang,
coverage: in.Coverage,
tidy: in.Tidy,
+ sAbiDump: in.SAbiDump,
systemIncludeFlags: strings.Join(in.SystemIncludeFlags, " "),
diff --git a/cmd/javac_filter/javac_filter.go b/cmd/javac_filter/javac_filter.go
deleted file mode 100644
index a089acd..0000000
--- a/cmd/javac_filter/javac_filter.go
+++ /dev/null
@@ -1,109 +0,0 @@
-// Copyright 2017 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.
-
-// soong_javac_filter expects the output of javac on stdin, and produces
-// an ANSI colorized version of the output on stdout.
-//
-// It also hides the unhelpful and unhideable "warning there is a warning"
-// messages.
-package main
-
-import (
- "bufio"
- "fmt"
- "io"
- "os"
- "regexp"
-)
-
-// Regular expressions are based on
-// https://chromium.googlesource.com/chromium/src/+/master/build/android/gyp/javac.py
-// Colors are based on clang's output
-var (
- filelinePrefix = `^[-.\w/\\]+.java:[0-9]+:`
- warningRe = regexp.MustCompile(filelinePrefix + ` (warning:) .*$`)
- errorRe = regexp.MustCompile(filelinePrefix + ` (.*?:) .*$`)
- markerRe = regexp.MustCompile(`\s*(\^)\s*$`)
-
- escape = "\x1b"
- reset = escape + "[0m"
- bold = escape + "[1m"
- red = escape + "[31m"
- green = escape + "[32m"
- magenta = escape + "[35m"
-)
-
-func main() {
- err := process(bufio.NewReader(os.Stdin), os.Stdout)
- if err != nil {
- fmt.Fprintln(os.Stderr, "reading standard input:", err)
- os.Exit(-1)
- }
-}
-
-func process(r io.Reader, w io.Writer) error {
- scanner := bufio.NewScanner(r)
- // Some javac wrappers output the entire list of java files being
- // compiled on a single line, which can be very large, set the maximum
- // buffer size to 2MB.
- scanner.Buffer(nil, 2*1024*1024)
- for scanner.Scan() {
- processLine(w, scanner.Text())
- }
- return scanner.Err()
-}
-
-func processLine(w io.Writer, line string) {
- for _, f := range filters {
- if f.MatchString(line) {
- return
- }
- }
- for _, p := range colorPatterns {
- var matched bool
- if line, matched = applyColor(line, p.color, p.re); matched {
- break
- }
- }
- fmt.Fprintln(w, line)
-}
-
-// If line matches re, make it bold and apply color to the first submatch
-// Returns line, modified if it matched, and true if it matched.
-func applyColor(line, color string, re *regexp.Regexp) (string, bool) {
- if m := re.FindStringSubmatchIndex(line); m != nil {
- tagStart, tagEnd := m[2], m[3]
- line = bold + line[:tagStart] +
- color + line[tagStart:tagEnd] + reset + bold +
- line[tagEnd:] + reset
- return line, true
- }
- return line, false
-}
-
-var colorPatterns = []struct {
- re *regexp.Regexp
- color string
-}{
- {warningRe, magenta},
- {errorRe, red},
- {markerRe, green},
-}
-
-var filters = []*regexp.Regexp{
- regexp.MustCompile(`Note: (Some input files|.*\.java) uses? or overrides? a deprecated API.`),
- regexp.MustCompile(`Note: Recompile with -Xlint:deprecation for details.`),
- regexp.MustCompile(`Note: (Some input files|.*\.java) uses? unchecked or unsafe operations.`),
- regexp.MustCompile(`Note: Recompile with -Xlint:unchecked for details.`),
-}
diff --git a/cmd/javac_filter/Android.bp b/cmd/javac_wrapper/Android.bp
similarity index 87%
rename from cmd/javac_filter/Android.bp
rename to cmd/javac_wrapper/Android.bp
index cbdabb9..c00f4bd 100644
--- a/cmd/javac_filter/Android.bp
+++ b/cmd/javac_wrapper/Android.bp
@@ -13,11 +13,11 @@
// limitations under the License.
blueprint_go_binary {
- name: "soong_javac_filter",
+ name: "soong_javac_wrapper",
srcs: [
- "javac_filter.go",
+ "javac_wrapper.go",
],
testSrcs: [
- "javac_filter_test.go",
+ "javac_wrapper_test.go",
],
}
diff --git a/cmd/javac_wrapper/javac_wrapper.go b/cmd/javac_wrapper/javac_wrapper.go
new file mode 100644
index 0000000..a323473
--- /dev/null
+++ b/cmd/javac_wrapper/javac_wrapper.go
@@ -0,0 +1,173 @@
+// Copyright 2017 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.
+
+// soong_javac_wrapper expects a javac command line and argments, executes
+// it, and produces an ANSI colorized version of the output on stdout.
+//
+// It also hides the unhelpful and unhideable "warning there is a warning"
+// messages.
+package main
+
+import (
+ "bufio"
+ "fmt"
+ "io"
+ "os"
+ "os/exec"
+ "regexp"
+ "syscall"
+)
+
+// Regular expressions are based on
+// https://chromium.googlesource.com/chromium/src/+/master/build/android/gyp/javac.py
+// Colors are based on clang's output
+var (
+ filelinePrefix = `^([-.\w/\\]+.java:[0-9]+: )`
+ warningRe = regexp.MustCompile(filelinePrefix + `?(warning:) .*$`)
+ errorRe = regexp.MustCompile(filelinePrefix + `(.*?:) .*$`)
+ markerRe = regexp.MustCompile(`()\s*(\^)\s*$`)
+
+ escape = "\x1b"
+ reset = escape + "[0m"
+ bold = escape + "[1m"
+ red = escape + "[31m"
+ green = escape + "[32m"
+ magenta = escape + "[35m"
+)
+
+func main() {
+ exitCode, err := Main(os.Args[0], os.Args[1:])
+ if err != nil {
+ fmt.Fprintln(os.Stderr, err.Error())
+ }
+ os.Exit(exitCode)
+}
+
+func Main(name string, args []string) (int, error) {
+ if len(args) < 1 {
+ return 1, fmt.Errorf("usage: %s javac ...", name)
+ }
+
+ pr, pw, err := os.Pipe()
+ if err != nil {
+ return 1, fmt.Errorf("creating output pipe: %s", err)
+ }
+
+ cmd := exec.Command(args[0], args[1:]...)
+ cmd.Stdin = os.Stdin
+ cmd.Stdout = pw
+ cmd.Stderr = pw
+ err = cmd.Start()
+ if err != nil {
+ return 1, fmt.Errorf("starting subprocess: %s", err)
+ }
+
+ pw.Close()
+
+ // Process subprocess stdout asynchronously
+ errCh := make(chan error)
+ go func() {
+ errCh <- process(pr, os.Stdout)
+ }()
+
+ // Wait for subprocess to finish
+ cmdErr := cmd.Wait()
+
+ // Wait for asynchronous stdout processing to finish
+ err = <-errCh
+
+ // Check for subprocess exit code
+ if cmdErr != nil {
+ if exitErr, ok := cmdErr.(*exec.ExitError); ok {
+ if status, ok := exitErr.Sys().(syscall.WaitStatus); ok {
+ if status.Exited() {
+ return status.ExitStatus(), nil
+ } else if status.Signaled() {
+ exitCode := 128 + int(status.Signal())
+ return exitCode, nil
+ } else {
+ return 1, exitErr
+ }
+ } else {
+ return 1, nil
+ }
+ }
+ }
+
+ if err != nil {
+ return 1, err
+ }
+
+ return 0, nil
+}
+
+func process(r io.Reader, w io.Writer) error {
+ scanner := bufio.NewScanner(r)
+ // Some javac wrappers output the entire list of java files being
+ // compiled on a single line, which can be very large, set the maximum
+ // buffer size to 2MB.
+ scanner.Buffer(nil, 2*1024*1024)
+ for scanner.Scan() {
+ processLine(w, scanner.Text())
+ }
+ err := scanner.Err()
+ if err != nil {
+ return fmt.Errorf("scanning input: %s", err)
+ }
+ return nil
+}
+
+func processLine(w io.Writer, line string) {
+ for _, f := range filters {
+ if f.MatchString(line) {
+ return
+ }
+ }
+ for _, p := range colorPatterns {
+ var matched bool
+ if line, matched = applyColor(line, p.color, p.re); matched {
+ break
+ }
+ }
+ fmt.Fprintln(w, line)
+}
+
+// If line matches re, make it bold and apply color to the first submatch
+// Returns line, modified if it matched, and true if it matched.
+func applyColor(line, color string, re *regexp.Regexp) (string, bool) {
+ if m := re.FindStringSubmatchIndex(line); m != nil {
+ tagStart, tagEnd := m[4], m[5]
+ line = bold + line[:tagStart] +
+ color + line[tagStart:tagEnd] + reset + bold +
+ line[tagEnd:] + reset
+ return line, true
+ }
+ return line, false
+}
+
+var colorPatterns = []struct {
+ re *regexp.Regexp
+ color string
+}{
+ {warningRe, magenta},
+ {errorRe, red},
+ {markerRe, green},
+}
+
+var filters = []*regexp.Regexp{
+ regexp.MustCompile(`Note: (Some input files|.*\.java) uses? or overrides? a deprecated API.`),
+ regexp.MustCompile(`Note: Recompile with -Xlint:deprecation for details.`),
+ regexp.MustCompile(`Note: (Some input files|.*\.java) uses? unchecked or unsafe operations.`),
+ regexp.MustCompile(`Note: Recompile with -Xlint:unchecked for details.`),
+}
diff --git a/cmd/javac_filter/javac_filter_test.go b/cmd/javac_wrapper/javac_wrapper_test.go
similarity index 60%
rename from cmd/javac_filter/javac_filter_test.go
rename to cmd/javac_wrapper/javac_wrapper_test.go
index 43381ce..9f41078 100644
--- a/cmd/javac_filter/javac_filter_test.go
+++ b/cmd/javac_wrapper/javac_wrapper_test.go
@@ -16,6 +16,7 @@
import (
"bytes"
+ "strconv"
"testing"
)
@@ -39,6 +40,10 @@
out: "\x1b[1mFile.java:398: \x1b[35mwarning:\x1b[0m\x1b[1m [RectIntersectReturnValueIgnored] Return value of com.blah.function() must be checked\x1b[0m\n",
},
{
+ in: "warning: [options] bootstrap class path not set in conjunction with -source 1.7\n",
+ out: "\x1b[1m\x1b[35mwarning:\x1b[0m\x1b[1m [options] bootstrap class path not set in conjunction with -source 1.7\x1b[0m\n",
+ },
+ {
in: " (see http://go/errorprone/bugpattern/RectIntersectReturnValueIgnored.md)\n",
out: " (see http://go/errorprone/bugpattern/RectIntersectReturnValueIgnored.md)\n",
},
@@ -60,15 +65,50 @@
}
func TestJavacColorize(t *testing.T) {
- for _, test := range testCases {
- buf := new(bytes.Buffer)
- err := process(bytes.NewReader([]byte(test.in)), buf)
- if err != nil {
- t.Errorf("error: %q", err)
- }
- got := string(buf.Bytes())
- if got != test.out {
- t.Errorf("expected %q got %q", test.out, got)
- }
+ for i, test := range testCases {
+ t.Run(strconv.Itoa(i), func(t *testing.T) {
+ buf := new(bytes.Buffer)
+ err := process(bytes.NewReader([]byte(test.in)), buf)
+ if err != nil {
+ t.Errorf("error: %q", err)
+ }
+ got := string(buf.Bytes())
+ if got != test.out {
+ t.Errorf("expected %q got %q", test.out, got)
+ }
+ })
}
}
+
+func TestSubprocess(t *testing.T) {
+ t.Run("failure", func(t *testing.T) {
+ exitCode, err := Main("test", []string{"sh", "-c", "exit 9"})
+ if err != nil {
+ t.Fatal("unexpected error", err)
+ }
+ if exitCode != 9 {
+ t.Fatal("expected exit code 9, got", exitCode)
+ }
+ })
+
+ t.Run("signal", func(t *testing.T) {
+ exitCode, err := Main("test", []string{"sh", "-c", "kill -9 $$"})
+ if err != nil {
+ t.Fatal("unexpected error", err)
+ }
+ if exitCode != 137 {
+ t.Fatal("expected exit code 137, got", exitCode)
+ }
+ })
+
+ t.Run("success", func(t *testing.T) {
+ exitCode, err := Main("test", []string{"echo"})
+ if err != nil {
+ t.Fatal("unexpected error", err)
+ }
+ if exitCode != 0 {
+ t.Fatal("expected exit code 0, got", exitCode)
+ }
+ })
+
+}
diff --git a/genrule/genrule.go b/genrule/genrule.go
index ee4c503..cb741b3 100644
--- a/genrule/genrule.go
+++ b/genrule/genrule.go
@@ -198,6 +198,7 @@
if err != nil {
ctx.PropertyErrorf("cmd", "%s", err.Error())
+ return
}
ruleParams := blueprint.RuleParams{
diff --git a/root.bp b/root.bp
index f14b047..4f9775b 100644
--- a/root.bp
+++ b/root.bp
@@ -17,13 +17,9 @@
"development/*",
"device/*/*",
"external/*",
- "frameworks/av",
- "frameworks/base",
+ "frameworks/*",
"frameworks/compile/*",
"frameworks/hardware/interfaces",
- "frameworks/native",
- "frameworks/rs",
- "frameworks/wilhelm",
"hardware/*",
"libcore",
"libnativehelper",
diff --git a/scripts/strip.sh b/scripts/strip.sh
index 8224942..b9ff741 100755
--- a/scripts/strip.sh
+++ b/scripts/strip.sh
@@ -35,18 +35,20 @@
}
do_strip_keep_mini_debug_info() {
- "${CROSS_COMPILE}nm" -D "${infile}" --format=posix --defined-only | awk '{ print $$1 }' | sort >"${outfile}.dynsyms"
- "${CROSS_COMPILE}nm" "${infile}" --format=posix --defined-only | awk '{ if ($$2 == "T" || $$2 == "t" || $$2 == "D") print $$1 }' | sort > "${outfile}.funcsyms"
- comm -13 "${outfile}.dynsyms" "${outfile}.funcsyms" > "${outfile}.keep_symbols"
- "${CROSS_COMPILE}objcopy" --only-keep-debug "${infile}" "${outfile}.debug"
- "${CROSS_COMPILE}objcopy" --rename-section .debug_frame=saved_debug_frame "${outfile}.debug" "${outfile}.mini_debuginfo"
- "${CROSS_COMPILE}objcopy" -S --remove-section .gdb_index --remove-section .comment --keep-symbols="${outfile}.keep_symbols" "${outfile}.mini_debuginfo"
- "${CROSS_COMPILE}objcopy" --rename-section saved_debug_frame=.debug_frame "${outfile}.mini_debuginfo"
- "${CROSS_COMPILE}strip" --strip-all -R .comment "${infile}" -o "${outfile}.tmp"
- rm -f "${outfile}.mini_debuginfo.xz"
- xz "${outfile}.mini_debuginfo"
- "${CROSS_COMPILE}objcopy" --add-section .gnu_debugdata="${outfile}.mini_debuginfo.xz" "${outfile}.tmp"
- rm -f "${outfile}.dynsyms" "${outfile}.funcsyms" "${outfile}.keep_symbols" "${outfile}.debug" "${outfile}.mini_debuginfo.xz"
+ rm -f "${outfile}.dynsyms" "${outfile}.funcsyms" "${outfile}.keep_symbols" "${outfile}.debug" "${outfile}.mini_debuginfo" "${outfile}.mini_debuginfo.xz"
+ if "${CROSS_COMPILE}strip" --strip-all -R .comment "${infile}" -o "${outfile}.tmp"; then
+ "${CROSS_COMPILE}objcopy" --only-keep-debug "${infile}" "${outfile}.debug"
+ "${CROSS_COMPILE}nm" -D "${infile}" --format=posix --defined-only | awk '{ print $$1 }' | sort >"${outfile}.dynsyms"
+ "${CROSS_COMPILE}nm" "${infile}" --format=posix --defined-only | awk '{ if ($$2 == "T" || $$2 == "t" || $$2 == "D") print $$1 }' | sort > "${outfile}.funcsyms"
+ comm -13 "${outfile}.dynsyms" "${outfile}.funcsyms" > "${outfile}.keep_symbols"
+ "${CROSS_COMPILE}objcopy" --rename-section .debug_frame=saved_debug_frame "${outfile}.debug" "${outfile}.mini_debuginfo"
+ "${CROSS_COMPILE}objcopy" -S --remove-section .gdb_index --remove-section .comment --keep-symbols="${outfile}.keep_symbols" "${outfile}.mini_debuginfo"
+ "${CROSS_COMPILE}objcopy" --rename-section saved_debug_frame=.debug_frame "${outfile}.mini_debuginfo"
+ xz "${outfile}.mini_debuginfo"
+ "${CROSS_COMPILE}objcopy" --add-section .gnu_debugdata="${outfile}.mini_debuginfo.xz" "${outfile}.tmp"
+ else
+ cp -f "${infile}" "${outfile}.tmp"
+ fi
}
do_add_gnu_debuglink() {
diff --git a/ui/build/config.go b/ui/build/config.go
index 9a8a3fb..c01bf4c 100644
--- a/ui/build/config.go
+++ b/ui/build/config.go
@@ -83,6 +83,10 @@
// We handle this above
"OUT_DIR_COMMON_BASE",
+
+ // Variables that have caused problems in the past
+ "DISPLAY",
+ "GREP_OPTIONS",
)
// Tell python not to spam the source tree with .pyc files.