Merge remote-tracking branch 'aosp/master-soong'
Change-Id: Ie4d13a216466b2a8c193b6df05f360b7a59830e9
diff --git a/Android.bp b/Android.bp
new file mode 100644
index 0000000..f001246
--- /dev/null
+++ b/Android.bp
@@ -0,0 +1,253 @@
+//
+// WARNING: Modifying this file will NOT automatically regenerate build.ninja.in!
+//
+// Before modifying this file make sure minibp is up to date:
+// 1) "repo sync build/soong" to make sure you have the latest build.ninja.in
+// 2) build minibp, which builds automicatically through the normal build steps. For example:
+//
+// After modifying this file regenerate build.ninja.in and build your changes:
+// 1) In your build directory, execute "../bootstrap.bash -r" to regenerate build.ninja.in
+// 2) Build again
+//
+
+bootstrap_go_binary {
+ name: "soong_build",
+ deps: [
+ "blueprint",
+ "blueprint-bootstrap",
+ "soong",
+ "soong-art",
+ "soong-cc",
+ "soong-common",
+ "soong-env",
+ "soong-genrule",
+ "soong-java",
+ ],
+ srcs: [
+ "cmd/soong_build/main.go",
+ ],
+ primaryBuilder: true,
+}
+
+bootstrap_go_binary {
+ name: "soong_env",
+ deps: [
+ "soong-env",
+ ],
+ srcs: [
+ "cmd/soong_env/soong_env.go",
+ ],
+}
+
+bootstrap_go_package {
+ name: "soong-env",
+ pkgPath: "android/soong/env",
+ srcs: [
+ "env/env.go",
+ ],
+}
+
+
+bootstrap_go_binary {
+ name: "soong_glob",
+ deps: [
+ "soong-glob",
+ ],
+ srcs: [
+ "cmd/soong_glob/soong_glob.go",
+ ],
+}
+
+bootstrap_go_package {
+ name: "soong-glob",
+ pkgPath: "android/soong/glob",
+ deps: [
+ "blueprint-deptools",
+ "blueprint-pathtools",
+ ],
+ srcs: [
+ "glob/glob.go",
+ ],
+}
+
+bootstrap_go_package {
+ name: "soong",
+ pkgPath: "android/soong",
+ deps: [
+ "blueprint",
+ ],
+ srcs: [
+ "doc.go",
+ "register.go",
+ ],
+}
+
+bootstrap_go_package {
+ name: "soong-common",
+ pkgPath: "android/soong/common",
+ deps: [
+ "blueprint",
+ "blueprint-bootstrap",
+ "soong",
+ "soong-env",
+ "soong-glob",
+ ],
+ srcs: [
+ "common/arch.go",
+ "common/config.go",
+ "common/defs.go",
+ "common/env.go",
+ "common/glob.go",
+ "common/module.go",
+ "common/paths.go",
+ "common/util.go",
+ ],
+}
+
+bootstrap_go_package {
+ name: "soong-cc",
+ pkgPath: "android/soong/cc",
+ deps: [
+ "blueprint",
+ "blueprint-pathtools",
+ "soong",
+ "soong-common",
+ "soong-genrule",
+ ],
+ srcs: [
+ "cc/builder.go",
+ "cc/cc.go",
+ "cc/clang.go",
+ "cc/gen.go",
+ "cc/toolchain.go",
+ "cc/util.go",
+
+ "cc/arm_device.go",
+ "cc/arm64_device.go",
+
+ "cc/x86_darwin_host.go",
+ "cc/x86_linux_host.go",
+ ],
+ testSrcs: [
+ "cc/cc_test.go",
+ ],
+}
+
+bootstrap_go_package {
+ name: "soong-genrule",
+ pkgPath: "android/soong/genrule",
+ deps: [
+ "blueprint",
+ "blueprint-pathtools",
+ "soong",
+ "soong-common",
+ ],
+ srcs: [
+ "genrule/genrule.go",
+ ],
+}
+
+bootstrap_go_binary {
+ name: "soong_jar",
+ srcs: [
+ "cmd/soong_jar/soong_jar.go",
+ ],
+}
+
+bootstrap_go_package {
+ name: "soong-java",
+ pkgPath: "android/soong/java",
+ deps: [
+ "blueprint",
+ "blueprint-pathtools",
+ "soong",
+ "soong-common",
+ "soong-genrule",
+ ],
+ srcs: [
+ "java/app_builder.go",
+ "java/app.go",
+ "java/builder.go",
+ "java/gen.go",
+ "java/java.go",
+ "java/resources.go",
+ ],
+}
+
+//
+// androidmk Android.mk to Blueprints translator
+//
+
+bootstrap_go_binary {
+ name: "androidmk",
+ srcs: [
+ "androidmk/cmd/androidmk/android.go",
+ "androidmk/cmd/androidmk/androidmk.go",
+ "androidmk/cmd/androidmk/values.go",
+ ],
+ deps: [
+ "androidmk-parser",
+ "blueprint-parser",
+ ],
+}
+
+bootstrap_go_package {
+ name: "androidmk-parser",
+ pkgPath: "android/soong/androidmk/parser",
+ srcs: [
+ "androidmk/parser/make_strings.go",
+ "androidmk/parser/makething.go",
+ "androidmk/parser/parser.go",
+ "androidmk/parser/scope.go",
+ ],
+ testSrcs: [
+ "androidmk/parser/make_strings_test.go",
+ ],
+}
+
+bootstrap_go_binary {
+ name: "androidbp",
+ srcs: [
+ "androidbp/cmd/androidbp.go",
+ "androidbp/cmd/soong.go",
+ "androidbp/cmd/module.go",
+ ],
+ testSrcs: [
+ "androidbp/cmd/androidbp_test.go",
+ ],
+ deps: [
+ "blueprint",
+ "blueprint-parser",
+ ],
+}
+
+//
+// C static libraries extracted from the gcc toolchain
+//
+
+toolchain_library {
+ name: "libatomic",
+ arch: {
+ arm: {
+ instruction_set: "arm",
+ },
+ },
+}
+
+toolchain_library {
+ name: "libgcc",
+ arch: {
+ arm: {
+ instruction_set: "arm",
+ },
+ },
+}
+
+toolchain_library {
+ name: "libgcov",
+ arch: {
+ arm: {
+ instruction_set: "arm",
+ },
+ },
+}
diff --git a/androidbp/cmd/androidbp.go b/androidbp/cmd/androidbp.go
new file mode 100644
index 0000000..b1e364c
--- /dev/null
+++ b/androidbp/cmd/androidbp.go
@@ -0,0 +1,655 @@
+package main
+
+import (
+ "bytes"
+ "errors"
+ "fmt"
+ "io"
+ "os"
+ "path"
+ "path/filepath"
+ "regexp"
+ "strings"
+ "text/scanner"
+
+ "github.com/google/blueprint"
+ bpparser "github.com/google/blueprint/parser"
+)
+
+var recursiveSubdirRegex *regexp.Regexp = regexp.MustCompile("(.+)/\\*\\*/(.+)")
+
+type androidMkWriter struct {
+ io.Writer
+
+ blueprint *bpparser.File
+ path string
+}
+
+type propAssignment struct {
+ name, assigner, value string
+}
+
+func (a propAssignment) assignmentWithSuffix(suffix string) string {
+ if suffix != "" {
+ a.name = a.name + "_" + suffix
+ }
+ return a.name + " " + a.assigner + " " + a.value
+}
+
+func (a propAssignment) assignment() string {
+ return a.assignmentWithSuffix("")
+}
+
+func (w *androidMkWriter) WriteString(s string) (int, error) {
+ return io.WriteString(w.Writer, s)
+}
+
+func valueToString(value bpparser.Value) (string, error) {
+ switch value.Type {
+ case bpparser.Bool:
+ return fmt.Sprintf("%t", value.BoolValue), nil
+ case bpparser.String:
+ return fmt.Sprintf("%s", processWildcards(value.StringValue)), nil
+ case bpparser.List:
+ val, err := listToMkString(value.ListValue)
+ if err != nil {
+ return "", err
+ }
+ return fmt.Sprintf("\\\n%s", val), nil
+ case bpparser.Map:
+ return "", fmt.Errorf("Can't convert map to string")
+ default:
+ return "", fmt.Errorf("ERROR: unsupported type %d", value.Type)
+ }
+}
+
+func appendValueToValue(dest bpparser.Value, src bpparser.Value) (bpparser.Value, error) {
+ if src.Type != dest.Type {
+ return bpparser.Value{}, fmt.Errorf("ERROR: source and destination types don't match")
+ }
+ switch dest.Type {
+ case bpparser.List:
+ dest.ListValue = append(dest.ListValue, src.ListValue...)
+ return dest, nil
+ case bpparser.String:
+ dest.StringValue += src.StringValue
+ return dest, nil
+ default:
+ return bpparser.Value{}, fmt.Errorf("ERROR: unsupported append with type %s", dest.Type.String())
+ }
+}
+
+func getTopOfAndroidTree(wd string) (string, error) {
+ if !filepath.IsAbs(wd) {
+ return "", errors.New("path must be absolute: " + wd)
+ }
+
+ topfile := "build/soong/bootstrap.bash"
+
+ for "/" != wd {
+ expected := filepath.Join(wd, topfile)
+
+ if _, err := os.Stat(expected); err == nil {
+ // Found the top
+ return wd, nil
+ }
+
+ wd = filepath.Join(wd, "..")
+ }
+
+ return "", errors.New("couldn't find top of tree from " + wd)
+}
+
+// TODO: handle non-recursive wildcards?
+func processWildcards(s string) string {
+ submatches := recursiveSubdirRegex.FindStringSubmatch(s)
+ if len(submatches) > 2 {
+ // Found a wildcard rule
+ return fmt.Sprintf("$(call find-files-in-subdirs, $(LOCAL_PATH), %s, %s)",
+ submatches[2], submatches[1])
+ }
+
+ return s
+}
+
+func listToMkString(list []bpparser.Value) (string, error) {
+ lines := make([]string, 0, len(list))
+ for _, tok := range list {
+ val, err := valueToString(tok)
+ if err != nil {
+ return "", err
+ }
+ lines = append(lines, fmt.Sprintf(" %s", val))
+ }
+
+ return strings.Join(lines, " \\\n"), nil
+}
+
+func translateTargetConditionals(props []*bpparser.Property,
+ disabledBuilds map[string]bool, isHostRule bool) (computedProps []string, err error) {
+ for _, target := range props {
+ conditionals := targetScopedPropertyConditionals
+ altConditionals := hostScopedPropertyConditionals
+ if isHostRule {
+ conditionals, altConditionals = altConditionals, conditionals
+ }
+
+ conditional, ok := conditionals[target.Name.Name]
+ if !ok {
+ if _, ok := altConditionals[target.Name.Name]; ok {
+ // This is only for the other build type
+ continue
+ } else {
+ return nil, fmt.Errorf("Unsupported conditional %q", target.Name.Name)
+ }
+ }
+
+ var scopedProps []string
+ for _, targetScopedProp := range target.Value.MapValue {
+ if assignment, ok, err := translateSingleProperty(targetScopedProp); err != nil {
+ return nil, err
+ } else if ok {
+ scopedProps = append(scopedProps, assignment.assignment())
+ } else if "disabled" == targetScopedProp.Name.Name {
+ if targetScopedProp.Value.BoolValue {
+ disabledBuilds[target.Name.Name] = true
+ } else {
+ delete(disabledBuilds, target.Name.Name)
+ }
+ } else {
+ return nil, fmt.Errorf("Unsupported target property %q", targetScopedProp.Name.Name)
+ }
+ }
+
+ if len(scopedProps) > 0 {
+ if conditional != "" {
+ computedProps = append(computedProps, conditional)
+ computedProps = append(computedProps, scopedProps...)
+ computedProps = append(computedProps, "endif")
+ } else {
+ computedProps = append(computedProps, scopedProps...)
+ }
+ }
+ }
+
+ return
+}
+
+var secondTargetReplacer = strings.NewReplacer("TARGET_", "TARGET_2ND_")
+
+func translateSuffixProperties(suffixProps []*bpparser.Property,
+ suffixMap map[string]string) (computedProps []string, err error) {
+ for _, suffixProp := range suffixProps {
+ if suffix, ok := suffixMap[suffixProp.Name.Name]; ok {
+ for _, stdProp := range suffixProp.Value.MapValue {
+ if assignment, ok, err := translateSingleProperty(stdProp); err != nil {
+ return nil, err
+ } else if ok {
+ computedProps = append(computedProps, assignment.assignmentWithSuffix(suffix))
+ } else {
+ return nil, fmt.Errorf("Unsupported property %q", stdProp.Name.Name)
+ }
+ }
+ } else if variant, ok := cpuVariantConditionals[suffixProp.Name.Name]; ok {
+ var conditionalProps []propAssignment
+ for _, stdProp := range suffixProp.Value.MapValue {
+ if assignment, ok, err := translateSingleProperty(stdProp); err != nil {
+ return nil, err
+ } else if ok {
+ conditionalProps = append(conditionalProps, assignment)
+ } else {
+ return nil, fmt.Errorf("Unsupported property %q", stdProp.Name.Name)
+ }
+ }
+
+ appendComputedProps := func() {
+ computedProps = append(computedProps, variant.conditional)
+ for _, prop := range conditionalProps {
+ prop.assigner = "+="
+ computedProps = append(computedProps, prop.assignmentWithSuffix(variant.suffix))
+ }
+ computedProps = append(computedProps, "endif")
+ }
+
+ appendComputedProps()
+ if variant.secondArch {
+ variant.conditional = secondTargetReplacer.Replace(variant.conditional)
+ variant.suffix = secondTargetReplacer.Replace(variant.suffix)
+ appendComputedProps()
+ }
+ } else {
+ return nil, fmt.Errorf("Unsupported suffix property %q", suffixProp.Name.Name)
+ }
+ }
+ return
+}
+
+func translateSingleProperty(prop *bpparser.Property) (propAssignment, bool, error) {
+ var assignment propAssignment
+ if mkProp, ok := standardProperties[prop.Name.Name]; ok {
+ name := mkProp.string
+ val, err := valueToString(prop.Value)
+ if err != nil {
+ return propAssignment{}, false, err
+ }
+ assignment = propAssignment{name, ":=", val}
+ } else if rwProp, ok := rewriteProperties[prop.Name.Name]; ok {
+ val, err := valueToString(prop.Value)
+ if err != nil {
+ return propAssignment{}, false, err
+ }
+ assignment, err = rwProp.f(rwProp.string, prop, val)
+ if err != nil {
+ return propAssignment{}, false, err
+ }
+ } else {
+ // Unhandled, return false with no error to tell the caller to handle it
+ return propAssignment{}, false, nil
+ }
+ return assignment, true, nil
+}
+
+func appendAssign(name string, prop *bpparser.Property, val string) (propAssignment, error) {
+ return propAssignment{name, "+=", val}, nil
+}
+
+func prependLocalPath(name string, prop *bpparser.Property, val string) (propAssignment, error) {
+ return propAssignment{name, "+=", fmt.Sprintf("$(addprefix $(LOCAL_PATH)/,%s)", val)}, nil
+}
+
+func prependLocalModule(name string, prop *bpparser.Property, val string) (propAssignment, error) {
+ return propAssignment{name, ":=", "$(LOCAL_MODULE)" + val}, nil
+}
+
+func versionScript(name string, prop *bpparser.Property, val string) (propAssignment, error) {
+ return propAssignment{name, "+=", "-Wl,--version-script,$(LOCAL_PATH)/" + val}, nil
+}
+
+func (w *androidMkWriter) writeModule(moduleRule string, props []string,
+ disabledBuilds map[string]bool, isHostRule bool) {
+ disabledConditionals := disabledTargetConditionals
+ if isHostRule {
+ disabledConditionals = disabledHostConditionals
+ }
+ for build, _ := range disabledBuilds {
+ if conditional, ok := disabledConditionals[build]; ok {
+ fmt.Fprintf(w, "%s\n", conditional)
+ defer fmt.Fprintf(w, "endif\n")
+ }
+ }
+
+ fmt.Fprintf(w, "include $(CLEAR_VARS)\n")
+ fmt.Fprintf(w, "%s\n", strings.Join(props, "\n"))
+ fmt.Fprintf(w, "include $(%s)\n\n", moduleRule)
+}
+
+func (w *androidMkWriter) parsePropsAndWriteModule(module *Module) error {
+ standardProps := make([]string, 0, len(module.bpmod.Properties))
+ disabledBuilds := make(map[string]bool)
+ for _, prop := range module.bpmod.Properties {
+ if assignment, ok, err := translateSingleProperty(prop); err != nil {
+ return err
+ } else if ok {
+ standardProps = append(standardProps, assignment.assignment())
+ } else if suffixMap, ok := suffixProperties[prop.Name.Name]; ok {
+ props, err := translateSuffixProperties(prop.Value.MapValue, suffixMap)
+ if err != nil {
+ return err
+ }
+ standardProps = append(standardProps, props...)
+ } else if "target" == prop.Name.Name {
+ props, err := translateTargetConditionals(prop.Value.MapValue, disabledBuilds, module.isHostRule)
+ if err != nil {
+ return err
+ }
+ standardProps = append(standardProps, props...)
+ } else if _, ok := ignoredProperties[prop.Name.Name]; ok {
+ } else {
+ return fmt.Errorf("Unsupported property %q", prop.Name.Name)
+ }
+ }
+
+ w.writeModule(module.mkname, standardProps, disabledBuilds, module.isHostRule)
+
+ return nil
+}
+
+func canUseWholeStaticLibrary(m *Module) (bool, error) {
+ ret := true
+
+ isCompatible := func(props Properties, prop *bpparser.Property) error {
+ for _, p := range prop.Value.MapValue {
+ if p.Name.Name == "cflags" {
+ ret = false
+ return nil
+ }
+ if prop.Name.Name == "static" {
+ if p.Name.Name == "srcs" {
+ ret = false
+ return nil
+ }
+ }
+ }
+ return nil
+ }
+
+ err := m.IterateArchPropertiesWithName("shared", isCompatible)
+ if err != nil {
+ return false, err
+ }
+ err = m.IterateArchPropertiesWithName("static", isCompatible)
+ if err != nil {
+ return false, err
+ }
+
+ return ret, nil
+}
+
+func (w *androidMkWriter) mutateModule(module *Module) (modules []*Module, err error) {
+ modules = []*Module{module}
+
+ if module.bpname == "cc_library" {
+ modules = []*Module{
+ newModule(module.bpmod),
+ newModule(module.bpmod),
+ }
+
+ ccLinkageCopy := func(props Properties, prop *bpparser.Property) error {
+ for _, p := range prop.Value.MapValue {
+ err := props.AppendToProp(p.Name.Name, p)
+ if err != nil {
+ return err
+ }
+ }
+ props.DeleteProp(prop.Name.Name)
+ return nil
+ }
+ deleteProp := func(props Properties, prop *bpparser.Property) error {
+ props.DeleteProp(prop.Name.Name)
+ return nil
+ }
+
+ if ok, err := canUseWholeStaticLibrary(module); err != nil {
+ return nil, err
+ } else if ok {
+ err = modules[0].IterateArchPropertiesWithName("srcs", deleteProp)
+ if err != nil {
+ return nil, err
+ }
+
+ if nameProp, ok := modules[0].Properties().Prop("name"); !ok {
+ return nil, fmt.Errorf("Can't find name property")
+ } else {
+ modules[0].Properties().AppendToProp("whole_static_libs", &bpparser.Property{
+ Value: bpparser.Value{
+ Type: bpparser.List,
+ ListValue: []bpparser.Value{
+ nameProp.Value.Copy(),
+ },
+ },
+ })
+ }
+ }
+
+ modules[0].bpname = "cc_library_shared"
+ err := modules[0].IterateArchPropertiesWithName("shared", ccLinkageCopy)
+ if err != nil {
+ return nil, err
+ }
+ err = modules[0].IterateArchPropertiesWithName("static", deleteProp)
+ if err != nil {
+ return nil, err
+ }
+
+ modules[1].bpname = "cc_library_static"
+ err = modules[1].IterateArchPropertiesWithName("shared", deleteProp)
+ if err != nil {
+ return nil, err
+ }
+ err = modules[1].IterateArchPropertiesWithName("static", ccLinkageCopy)
+ if err != nil {
+ return nil, err
+ }
+ }
+
+ for _, mod := range modules {
+ err := mod.translateRuleName()
+ if err != nil {
+ return nil, err
+ }
+ if mod.isHostRule || !mod.PropBool("host_supported") {
+ continue
+ }
+
+ m := &Module{
+ bpmod: mod.bpmod,
+ bpname: mod.bpname,
+ isHostRule: true,
+ }
+ err = m.translateRuleName()
+ if err != nil {
+ return nil, err
+ }
+ modules = append(modules, m)
+ }
+
+ return
+}
+
+func (w *androidMkWriter) handleModule(inputModule *bpparser.Module) error {
+ comment := w.getCommentBlock(inputModule.Type.Pos)
+ if translation, translated, err := getCommentTranslation(comment); err != nil {
+ return err
+ } else if translated {
+ w.WriteString(translation)
+ return nil
+ }
+
+ if ignoredModuleType[inputModule.Type.Name] {
+ return nil
+ }
+
+ modules, err := w.mutateModule(newModule(inputModule))
+ if err != nil {
+ return err
+ }
+
+ for _, module := range modules {
+ err := w.parsePropsAndWriteModule(module)
+ if err != nil {
+ return err
+ }
+ }
+
+ return nil
+}
+
+func (w *androidMkWriter) handleSubdirs(value bpparser.Value) {
+ subdirs := make([]string, 0, len(value.ListValue))
+ for _, tok := range value.ListValue {
+ subdirs = append(subdirs, tok.StringValue)
+ }
+ // The current makefile may be generated to outside the source tree (such as the out directory), with a different structure.
+ fmt.Fprintf(w, "# Uncomment the following line if you really want to include subdir Android.mks.\n")
+ fmt.Fprintf(w, "# include $(wildcard $(addsuffix $(LOCAL_PATH)/%s/, Android.mk))\n", strings.Join(subdirs, " "))
+}
+
+func (w *androidMkWriter) handleLocalPath() error {
+ w.WriteString("LOCAL_PATH := " + w.path + "\n")
+ w.WriteString("LOCAL_MODULE_MAKEFILE := $(lastword $(MAKEFILE_LIST))\n\n")
+ return nil
+}
+
+// Returns any block comment on the line preceding pos as a string
+func (w *androidMkWriter) getCommentBlock(pos scanner.Position) string {
+ var buf []byte
+
+ comments := w.blueprint.Comments
+ for i, c := range comments {
+ if c.EndLine() == pos.Line-1 {
+ line := pos.Line
+ for j := i; j >= 0; j-- {
+ c = comments[j]
+ if c.EndLine() == line-1 {
+ buf = append([]byte(c.Text()), buf...)
+ line = c.Pos.Line
+ } else {
+ break
+ }
+ }
+ }
+ }
+
+ return string(buf)
+}
+
+func getCommentTranslation(comment string) (string, bool, error) {
+ lines := strings.Split(comment, "\n")
+
+ if directive, i, err := getCommentDirective(lines); err != nil {
+ return "", false, err
+ } else if directive != "" {
+ switch directive {
+ case "ignore":
+ return "", true, nil
+ case "start":
+ return getCommentTranslationBlock(lines[i+1:])
+ case "end":
+ return "", false, fmt.Errorf("Unexpected Android.mk:end translation directive")
+ default:
+ return "", false, fmt.Errorf("Unknown Android.mk module translation directive %q", directive)
+ }
+ }
+
+ return "", false, nil
+}
+
+func getCommentTranslationBlock(lines []string) (string, bool, error) {
+ var buf []byte
+
+ for _, line := range lines {
+ if directive := getLineCommentDirective(line); directive != "" {
+ switch directive {
+ case "end":
+ return string(buf), true, nil
+ default:
+ return "", false, fmt.Errorf("Unexpected Android.mk translation directive %q inside start", directive)
+ }
+ } else {
+ buf = append(buf, line...)
+ buf = append(buf, '\n')
+ }
+ }
+
+ return "", false, fmt.Errorf("Missing Android.mk:end translation directive")
+}
+
+func getCommentDirective(lines []string) (directive string, n int, err error) {
+ for i, line := range lines {
+ if directive := getLineCommentDirective(line); directive != "" {
+ return strings.ToLower(directive), i, nil
+ }
+ }
+
+ return "", -1, nil
+}
+
+func getLineCommentDirective(line string) string {
+ line = strings.TrimSpace(line)
+ if strings.HasPrefix(line, "Android.mk:") {
+ line = strings.TrimPrefix(line, "Android.mk:")
+ line = strings.TrimSpace(line)
+ return line
+ }
+
+ return ""
+}
+
+func (w *androidMkWriter) write(writer io.Writer) (err error) {
+ w.Writer = writer
+
+ if err = w.handleLocalPath(); err != nil {
+ return err
+ }
+
+ for _, block := range w.blueprint.Defs {
+ switch block := block.(type) {
+ case *bpparser.Module:
+ err = w.handleModule(block)
+ case *bpparser.Assignment:
+ // Nothing
+ default:
+ return fmt.Errorf("Unhandled def %v", block)
+ }
+ if err != nil {
+ return err
+ }
+ }
+
+ return nil
+}
+
+func translate(rootFile, androidBp, androidMk string) error {
+
+ ctx := blueprint.NewContext()
+
+ var blueprintFile *bpparser.File
+
+ _, errs := ctx.WalkBlueprintsFiles(rootFile, func(file *bpparser.File) {
+ if file.Name == androidBp {
+ blueprintFile = file
+ }
+ })
+ if len(errs) > 0 {
+ return errs[0]
+ }
+
+ if blueprintFile == nil {
+ return fmt.Errorf("File %q wasn't parsed from %q", androidBp, rootFile)
+ }
+
+ writer := &androidMkWriter{
+ blueprint: blueprintFile,
+ path: path.Dir(androidBp),
+ }
+
+ buf := &bytes.Buffer{}
+
+ err := writer.write(buf)
+ if err != nil {
+ os.Remove(androidMk)
+ return err
+ }
+
+ f, err := os.Create(androidMk)
+ if err != nil {
+ return err
+ }
+ defer f.Close()
+
+ _, err = f.Write(buf.Bytes())
+
+ return err
+}
+
+func main() {
+ if len(os.Args) < 4 {
+ fmt.Fprintln(os.Stderr, "Expected root Android.bp, input and output filename arguments")
+ os.Exit(1)
+ }
+
+ rootFile := os.Args[1]
+ androidBp, err := filepath.Rel(filepath.Dir(rootFile), os.Args[2])
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "Android.bp file %q is not relative to %q: %s\n",
+ os.Args[2], rootFile, err.Error())
+ os.Exit(1)
+ }
+ androidMk := os.Args[3]
+
+ err = translate(rootFile, androidBp, androidMk)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "Error translating %s: %s\n", androidBp, err.Error())
+ os.Exit(1)
+ }
+}
diff --git a/androidbp/cmd/androidbp_test.go b/androidbp/cmd/androidbp_test.go
new file mode 100644
index 0000000..081a1ca
--- /dev/null
+++ b/androidbp/cmd/androidbp_test.go
@@ -0,0 +1,227 @@
+package main
+
+import (
+ "bytes"
+ "strings"
+ "testing"
+ "unicode"
+
+ bpparser "github.com/google/blueprint/parser"
+)
+
+var valueTestCases = []struct {
+ blueprint string
+ expected string
+}{
+ {
+ blueprint: `test = false`,
+ expected: `false`,
+ },
+ {
+ blueprint: `test = "string"`,
+ expected: `string`,
+ },
+ {
+ blueprint: `test = ["a", "b"]`,
+ expected: `\
+ a \
+ b
+ `,
+ },
+}
+
+func TestValueToString(t *testing.T) {
+ for _, testCase := range valueTestCases {
+ blueprint, errs := bpparser.Parse("", strings.NewReader(testCase.blueprint), nil)
+ if len(errs) > 0 {
+ t.Errorf("Failed to read blueprint: %q", errs)
+ }
+
+ str, err := valueToString(blueprint.Defs[0].(*bpparser.Assignment).Value)
+ if err != nil {
+ t.Error(err.Error())
+ }
+ expect(t, testCase.blueprint, testCase.expected, str)
+ }
+}
+
+var moduleTestCases = []struct {
+ blueprint string
+ androidmk string
+}{
+ // Target-only
+ {
+ blueprint: `cc_library_shared { name: "test", }`,
+ androidmk: `include $(CLEAR_VARS)
+ LOCAL_MODULE := test
+ include $(BUILD_SHARED_LIBRARY)`,
+ },
+ // Host-only
+ {
+ blueprint: `cc_library_host_shared { name: "test", }`,
+ androidmk: `include $(CLEAR_VARS)
+ LOCAL_MODULE := test
+ include $(BUILD_HOST_SHARED_LIBRARY)`,
+ },
+ // Target and Host
+ {
+ blueprint: `cc_library_shared { name: "test", host_supported: true, }`,
+ androidmk: `include $(CLEAR_VARS)
+ LOCAL_MODULE := test
+ include $(BUILD_SHARED_LIBRARY)
+
+ include $(CLEAR_VARS)
+ LOCAL_MODULE := test
+ include $(BUILD_HOST_SHARED_LIBRARY)`,
+ },
+ // Static and Shared
+ {
+ blueprint: `cc_library { name: "test", srcs: ["a"], }`,
+ androidmk: `include $(CLEAR_VARS)
+ LOCAL_MODULE := test
+ LOCAL_WHOLE_STATIC_LIBRARIES := \
+ test
+ include $(BUILD_SHARED_LIBRARY)
+
+ include $(CLEAR_VARS)
+ LOCAL_MODULE := test
+ LOCAL_SRC_FILES := \
+ a
+ include $(BUILD_STATIC_LIBRARY)`,
+ },
+ // Static and Shared / Target and Host
+ {
+ blueprint: `cc_library { name: "test", host_supported: true, }`,
+ androidmk: `include $(CLEAR_VARS)
+ LOCAL_MODULE := test
+ LOCAL_WHOLE_STATIC_LIBRARIES := \
+ test
+ include $(BUILD_SHARED_LIBRARY)
+
+ include $(CLEAR_VARS)
+ LOCAL_MODULE := test
+ include $(BUILD_STATIC_LIBRARY)
+
+ include $(CLEAR_VARS)
+ LOCAL_MODULE := test
+ LOCAL_WHOLE_STATIC_LIBRARIES := \
+ test
+ include $(BUILD_HOST_SHARED_LIBRARY)
+
+ include $(CLEAR_VARS)
+ LOCAL_MODULE := test
+ include $(BUILD_HOST_STATIC_LIBRARY)`,
+ },
+ // Static and Shared properties
+ {
+ blueprint: `cc_library {
+ name: "test",
+ srcs: ["a"],
+ static: { srcs: ["c"], static_libs: ["l"], },
+ shared: { srcs: ["b"], },
+ multilib: { lib32: { shared: { cflags: ["f"], }, }, },
+ }`,
+ androidmk: `include $(CLEAR_VARS)
+ LOCAL_MODULE := test
+ LOCAL_SRC_FILES := \
+ a \
+ b
+ LOCAL_CFLAGS_32 := \
+ f
+ include $(BUILD_SHARED_LIBRARY)
+
+ include $(CLEAR_VARS)
+ LOCAL_MODULE := test
+ LOCAL_SRC_FILES := \
+ a \
+ c
+ LOCAL_STATIC_LIBRARIES := \
+ l
+ include $(BUILD_STATIC_LIBRARY)`,
+ },
+ // Static and Shared properties, use whole static lib, but add extra shared srcs
+ {
+ blueprint: `cc_library {
+ name: "test",
+ srcs: ["a"],
+ shared: { srcs: ["b"], },
+ }`,
+ androidmk: `include $(CLEAR_VARS)
+ LOCAL_MODULE := test
+ LOCAL_WHOLE_STATIC_LIBRARIES := \
+ test
+ LOCAL_SRC_FILES := \
+ b
+ include $(BUILD_SHARED_LIBRARY)
+
+ include $(CLEAR_VARS)
+ LOCAL_MODULE := test
+ LOCAL_SRC_FILES := \
+ a
+ include $(BUILD_STATIC_LIBRARY)`,
+ },
+ // Manual translation
+ {
+ blueprint: `/* Android.mk:start
+ # Manual translation
+ Android.mk:end */
+ cc_library { name: "test", host_supported: true, }`,
+ androidmk: `# Manual translation`,
+ },
+ // Ignored translation
+ {
+ blueprint: `/* Android.mk:ignore */
+ cc_library { name: "test", host_supported: true, }`,
+ androidmk: ``,
+ },
+}
+
+func TestModules(t *testing.T) {
+ for _, testCase := range moduleTestCases {
+ blueprint, errs := bpparser.Parse("", strings.NewReader(testCase.blueprint), nil)
+ if len(errs) > 0 {
+ t.Errorf("Failed to read blueprint: %q", errs)
+ }
+
+ buf := &bytes.Buffer{}
+ writer := &androidMkWriter{
+ blueprint: blueprint,
+ path: "",
+ Writer: buf,
+ }
+
+ module := blueprint.Defs[0].(*bpparser.Module)
+ err := writer.handleModule(module)
+ if err != nil {
+ t.Errorf("Unexpected error %s", err.Error())
+ }
+
+ expect(t, testCase.blueprint, testCase.androidmk, buf.String())
+ }
+}
+
+// Trim left whitespace, and any trailing newlines. Leave inner blank lines and
+// right whitespace so that we can still check line continuations are correct
+func trim(str string) string {
+ var list []string
+ for _, s := range strings.Split(str, "\n") {
+ list = append(list, strings.TrimLeftFunc(s, unicode.IsSpace))
+ }
+ return strings.TrimRight(strings.Join(list, "\n"), "\n")
+}
+
+func expect(t *testing.T, testCase string, expected string, out string) {
+ expected = trim(expected)
+ out = trim(out)
+ if expected != out {
+ sep := " "
+ if strings.Index(expected, "\n") != -1 || strings.Index(out, "\n") != -1 {
+ sep = "\n"
+ }
+
+ t.Errorf("test case: %s", testCase)
+ t.Errorf("unexpected difference:")
+ t.Errorf(" expected:%s%s", sep, expected)
+ t.Errorf(" got:%s%s", sep, out)
+ }
+}
diff --git a/androidbp/cmd/module.go b/androidbp/cmd/module.go
new file mode 100644
index 0000000..648ff88
--- /dev/null
+++ b/androidbp/cmd/module.go
@@ -0,0 +1,121 @@
+package main
+
+import (
+ "fmt"
+ "strings"
+
+ bpparser "github.com/google/blueprint/parser"
+)
+
+type Module struct {
+ bpmod *bpparser.Module
+ bpname string
+ mkname string
+ isHostRule bool
+}
+
+func newModule(mod *bpparser.Module) *Module {
+ return &Module{
+ bpmod: mod.Copy(),
+ bpname: mod.Type.Name,
+ }
+}
+
+func (m *Module) translateRuleName() error {
+ var name string
+ if translation, ok := moduleTypeToRule[m.bpname]; ok {
+ name = translation
+ } else {
+ return fmt.Errorf("Unknown module type %q", m.bpname)
+ }
+
+ if m.isHostRule {
+ if trans, ok := targetToHostModuleRule[name]; ok {
+ name = trans
+ } else {
+ return fmt.Errorf("No corresponding host rule for %q", name)
+ }
+ } else {
+ m.isHostRule = strings.Contains(name, "HOST")
+ }
+
+ m.mkname = name
+
+ return nil
+}
+
+func (m *Module) Properties() Properties {
+ return Properties{&m.bpmod.Properties}
+}
+
+func (m *Module) PropBool(name string) bool {
+ if prop, ok := m.Properties().Prop(name); ok {
+ return prop.Value.BoolValue
+ }
+ return false
+}
+
+func (m *Module) IterateArchPropertiesWithName(name string, f func(Properties, *bpparser.Property) error) error {
+ if p, ok := m.Properties().Prop(name); ok {
+ err := f(m.Properties(), p)
+ if err != nil {
+ return err
+ }
+ }
+
+ for _, prop := range m.bpmod.Properties {
+ switch prop.Name.Name {
+ case "arch", "multilib", "target":
+ for _, sub := range prop.Value.MapValue {
+ props := Properties{&sub.Value.MapValue}
+ if p, ok := props.Prop(name); ok {
+ err := f(props, p)
+ if err != nil {
+ return err
+ }
+ }
+ }
+ }
+ }
+
+ return nil
+}
+
+type Properties struct {
+ props *[]*bpparser.Property
+}
+
+func (p Properties) Prop(name string) (*bpparser.Property, bool) {
+ for _, prop := range *p.props {
+ if name == prop.Name.Name {
+ return prop, true
+ }
+ }
+ return nil, false
+}
+
+func (p Properties) AppendToProp(name string, src *bpparser.Property) error {
+ if d, ok := p.Prop(name); ok {
+ val, err := appendValueToValue(d.Value, src.Value)
+ if err != nil {
+ return err
+ }
+
+ d.Value = val
+ } else {
+ prop := src.Copy()
+ prop.Name.Name = name
+ *p.props = append(*p.props, prop)
+ }
+
+ return nil
+}
+
+func (p Properties) DeleteProp(name string) {
+ for i, prop := range *p.props {
+ if prop.Name.Name == name {
+ *p.props = append((*p.props)[0:i], (*p.props)[i+1:]...)
+ return
+ }
+ }
+}
diff --git a/androidbp/cmd/soong.go b/androidbp/cmd/soong.go
new file mode 100644
index 0000000..7bd0463
--- /dev/null
+++ b/androidbp/cmd/soong.go
@@ -0,0 +1,174 @@
+package main
+
+import bpparser "github.com/google/blueprint/parser"
+
+var standardProperties = map[string]struct {
+ string
+ bpparser.ValueType
+}{
+ // ==== STRING PROPERTIES ====
+ "name": {"LOCAL_MODULE", bpparser.String},
+ "stem": {"LOCAL_MODULE_STEM", bpparser.String},
+ "class": {"LOCAL_MODULE_CLASS", bpparser.String},
+ "stl": {"LOCAL_CXX_STL", bpparser.String},
+ "strip": {"LOCAL_STRIP_MODULE", bpparser.String},
+ "compile_multilib": {"LOCAL_MULTILIB", bpparser.String},
+ "instruction_set": {"LOCAL_ARM_MODE_HACK", bpparser.String},
+ "sdk_version": {"LOCAL_SDK_VERSION", bpparser.String},
+ //"stl": "LOCAL_NDK_STL_VARIANT", TODO
+ "manifest": {"LOCAL_JAR_MANIFEST", bpparser.String},
+ "jarjar_rules": {"LOCAL_JARJAR_RULES", bpparser.String},
+ "certificate": {"LOCAL_CERTIFICATE", bpparser.String},
+ //"name": "LOCAL_PACKAGE_NAME", TODO
+
+ // ==== LIST PROPERTIES ====
+ "srcs": {"LOCAL_SRC_FILES", bpparser.List},
+ "exclude_srcs": {"LOCAL_SRC_FILES_EXCLUDE", bpparser.List},
+ "shared_libs": {"LOCAL_SHARED_LIBRARIES", bpparser.List},
+ "static_libs": {"LOCAL_STATIC_LIBRARIES", bpparser.List},
+ "whole_static_libs": {"LOCAL_WHOLE_STATIC_LIBRARIES", bpparser.List},
+ "system_shared_libs": {"LOCAL_SYSTEM_SHARED_LIBRARIES", bpparser.List},
+ "asflags": {"LOCAL_ASFLAGS", bpparser.List},
+ "clang_asflags": {"LOCAL_CLANG_ASFLAGS", bpparser.List},
+ "cflags": {"LOCAL_CFLAGS", bpparser.List},
+ "conlyflags": {"LOCAL_CONLYFLAGS", bpparser.List},
+ "cppflags": {"LOCAL_CPPFLAGS", bpparser.List},
+ "ldflags": {"LOCAL_LDFLAGS", bpparser.List},
+ "required": {"LOCAL_REQUIRED_MODULES", bpparser.List},
+ "tags": {"LOCAL_MODULE_TAGS", bpparser.List},
+ "host_ldlibs": {"LOCAL_LDLIBS", bpparser.List},
+ "clang_cflags": {"LOCAL_CLANG_CFLAGS", bpparser.List},
+ "yaccflags": {"LOCAL_YACCFLAGS", bpparser.List},
+ "java_resource_dirs": {"LOCAL_JAVA_RESOURCE_DIRS", bpparser.List},
+ "javacflags": {"LOCAL_JAVACFLAGS", bpparser.List},
+ "dxflags": {"LOCAL_DX_FLAGS", bpparser.List},
+ "java_libs": {"LOCAL_JAVA_LIBRARIES", bpparser.List},
+ "java_static_libs": {"LOCAL_STATIC_JAVA_LIBRARIES", bpparser.List},
+ "aidl_includes": {"LOCAL_AIDL_INCLUDES", bpparser.List},
+ "aaptflags": {"LOCAL_AAPT_FLAGS", bpparser.List},
+ "package_splits": {"LOCAL_PACKAGE_SPLITS", bpparser.List},
+
+ // ==== BOOL PROPERTIES ====
+ "host": {"LOCAL_IS_HOST_MODULE", bpparser.Bool},
+ "clang": {"LOCAL_CLANG", bpparser.Bool},
+ "static_executable": {"LOCAL_FORCE_STATIC_EXECUTABLE", bpparser.Bool},
+ "asan": {"LOCAL_ADDRESS_SANITIZER", bpparser.Bool},
+ "native_coverage": {"LOCAL_NATIVE_COVERAGE", bpparser.Bool},
+ "nocrt": {"LOCAL_NO_CRT", bpparser.Bool},
+ "allow_undefined_symbols": {"LOCAL_ALLOW_UNDEFINED_SYMBOLS", bpparser.Bool},
+ "rtti": {"LOCAL_RTTI_FLAG", bpparser.Bool},
+ "no_standard_libraries": {"LOCAL_NO_STANDARD_LIBRARIES", bpparser.Bool},
+ "export_package_resources": {"LOCAL_EXPORT_PACKAGE_RESOURCES", bpparser.Bool},
+ "no_default_compiler_flags": {"LOCAL_NO_DEFAULT_COMPILER_FLAGS", bpparser.Bool},
+}
+
+var rewriteProperties = map[string]struct {
+ string
+ f func(name string, prop *bpparser.Property, val string) (propAssignment, error)
+}{
+ "include_dirs": {"LOCAL_C_INCLUDES", appendAssign},
+ "local_include_dirs": {"LOCAL_C_INCLUDES", prependLocalPath},
+ "export_include_dirs": {"LOCAL_EXPORT_C_INCLUDE_DIRS", prependLocalPath},
+ "suffix": {"LOCAL_MODULE_STEM", prependLocalModule},
+ "version_script": {"LOCAL_LDFLAGS", versionScript},
+}
+
+var ignoredProperties = map[string]bool{
+ "host_supported": true,
+}
+
+var moduleTypeToRule = map[string]string{
+ "cc_library_shared": "BUILD_SHARED_LIBRARY",
+ "cc_library_static": "BUILD_STATIC_LIBRARY",
+ "cc_library_host_shared": "BUILD_HOST_SHARED_LIBRARY",
+ "cc_library_host_static": "BUILD_HOST_STATIC_LIBRARY",
+ "cc_binary": "BUILD_EXECUTABLE",
+ "cc_binary_host": "BUILD_HOST_EXECUTABLE",
+ "cc_test": "BUILD_NATIVE_TEST",
+ "cc_test_host": "BUILD_HOST_NATIVE_TEST",
+ "cc_benchmark": "BUILD_NATIVE_BENCHMARK",
+ "cc_benchmark_host": "BUILD_HOST_NATIVE_BENCHMARK",
+ "java_library": "BUILD_JAVA_LIBRARY",
+ "java_library_static": "BUILD_STATIC_JAVA_LIBRARY",
+ "java_library_host": "BUILD_HOST_JAVA_LIBRARY",
+ "java_library_host_dalvik": "BUILD_HOST_DALVIK_JAVA_LIBRARY",
+ "android_app": "BUILD_PACKAGE",
+ "prebuilt": "BUILD_PREBUILT",
+}
+
+var ignoredModuleType = map[string]bool{
+ "bootstrap_go_binary": true,
+ "bootstrap_go_package": true,
+ "toolchain_library": true,
+}
+
+var suffixProperties = map[string]map[string]string{
+ "multilib": {"lib32": "32", "lib64": "64"},
+ "arch": {"arm": "arm", "arm64": "arm64", "mips": "mips", "mips64": "mips64",
+ "x86": "x86", "x86_64": "x86_64"},
+}
+
+var cpuVariantConditionals = map[string]struct {
+ conditional string
+ suffix string
+ secondArch bool
+}{
+ "armv5te": {"ifeq ($(TARGET_ARCH_VARIANT),armv5te)", "$(TARGET_ARCH)", true},
+ "armv7_a": {"ifeq ($(TARGET_ARCH_VARIANT),armv7-a)", "$(TARGET_ARCH)", true},
+ "armv7_a_neon": {"ifeq ($(TARGET_ARCH_VARIANT),armv7-a-neon)", "$(TARGET_ARCH)", true},
+ "cortex_a7": {"ifeq ($(TARGET_CPU_VARIANT),cortex-a7)", "$(TARGET_ARCH)", true},
+ "cortex_a8": {"ifeq ($(TARGET_CPU_VARIANT),cortex-a8)", "$(TARGET_ARCH)", true},
+ "cortex_a9": {"ifeq ($(TARGET_CPU_VARIANT),cortex-a9)", "$(TARGET_ARCH)", true},
+ "cortex_a15": {"ifeq ($(TARGET_CPU_VARIANT),cortex-a15)", "$(TARGET_ARCH)", true},
+ "krait": {"ifeq ($(TARGET_CPU_VARIANT),krait)", "$(TARGET_ARCH)", true},
+ "denver": {"ifeq ($(TARGET_CPU_VARIANT),denver)", "$(TARGET_ARCH)", true},
+ "denver64": {"ifeq ($(TARGET_CPU_VARIANT),denver64)", "$(TARGET_ARCH)", true},
+ "mips_rev6": {"ifdef ARCH_MIPS_REV6", "mips", false},
+ "atom": {"ifeq ($(TARGET_ARCH_VARIANT),atom)", "$(TARGET_ARCH)", true},
+ "silvermont": {"ifeq ($(TARGET_ARCH_VARIANT),silvermont)", "$(TARGET_ARCH)", true},
+ "x86_sse3": {"ifeq ($(ARCH_X86_HAVE_SSE3),true)", "x86", true},
+ "x86_sse4": {"ifeq ($(ARCH_X86_HAVE_SSE4),true)", "x86", true},
+}
+
+var hostScopedPropertyConditionals = map[string]string{
+ "host": "",
+ "darwin": "ifeq ($(HOST_OS), darwin)",
+ "not_darwin": "ifneq ($(HOST_OS), darwin)",
+ "windows": "ifeq ($(HOST_OS), windows)",
+ "not_windows": "ifneq ($(HOST_OS), windows)",
+ "linux": "ifeq ($(HOST_OS), linux)",
+ "not_linux": "ifneq ($(HOST_OS), linux)",
+}
+
+// TODO: host target?
+var targetScopedPropertyConditionals = map[string]string{
+ "android": "",
+ "android32": "ifneq ($(TARGET_IS_64_BIT), true)",
+ "not_android32": "ifeq ($(TARGET_IS_64_BIT), true)",
+ "android64": "ifeq ($(TARGET_IS_64_BIT), true)",
+ "not_android64": "ifneq ($(TARGET_IS_64_BIT), true)",
+}
+
+var disabledHostConditionals = map[string]string{
+ "darwin": "ifneq ($(HOST_OS), darwin)",
+ "not_darwin": "ifeq ($(HOST_OS), darwin)",
+ "windows": "ifneq ($(HOST_OS), windows)",
+ "not_windows": "ifeq ($(HOST_OS), windows)",
+ "linux": "ifneq ($(HOST_OS), linux)",
+ "not_linux": "ifeq ($(HOST_OS), linux)",
+}
+
+var disabledTargetConditionals = map[string]string{
+ "android32": "ifeq ($(TARGET_IS_64_BIT), true)",
+ "not_android32": "ifeq ($(TARGET_IS_64_BIT), false)",
+ "android64": "ifeq ($(TARGET_IS_64_BIT), false)",
+ "not_android64": "ifeq ($(TARGET_IS_64_BIT), true)",
+}
+
+var targetToHostModuleRule = map[string]string{
+ "BUILD_SHARED_LIBRARY": "BUILD_HOST_SHARED_LIBRARY",
+ "BUILD_STATIC_LIBRARY": "BUILD_HOST_STATIC_LIBRARY",
+ "BUILD_EXECUTABLE": "BUILD_HOST_EXECUTABLE",
+ "BUILD_NATIVE_TEST": "BUILD_HOST_NATIVE_TEST",
+ "BUILD_JAVA_LIBRARY": "BUILD_HOST_JAVA_LIBRARY",
+}
diff --git a/androidmk/cmd/androidmk/android.go b/androidmk/cmd/androidmk/android.go
new file mode 100644
index 0000000..8d7025c
--- /dev/null
+++ b/androidmk/cmd/androidmk/android.go
@@ -0,0 +1,373 @@
+package main
+
+import (
+ mkparser "android/soong/androidmk/parser"
+ "fmt"
+ "strings"
+
+ bpparser "github.com/google/blueprint/parser"
+)
+
+const (
+ clear_vars = "__android_mk_clear_vars"
+)
+
+var standardProperties = map[string]struct {
+ string
+ bpparser.ValueType
+}{
+ // String properties
+ "LOCAL_MODULE": {"name", bpparser.String},
+ "LOCAL_MODULE_CLASS": {"class", bpparser.String},
+ "LOCAL_CXX_STL": {"stl", bpparser.String},
+ "LOCAL_STRIP_MODULE": {"strip", bpparser.String},
+ "LOCAL_MULTILIB": {"compile_multilib", bpparser.String},
+ "LOCAL_ARM_MODE_HACK": {"instruction_set", bpparser.String},
+ "LOCAL_SDK_VERSION": {"sdk_version", bpparser.String},
+ "LOCAL_NDK_STL_VARIANT": {"stl", bpparser.String},
+ "LOCAL_JAR_MANIFEST": {"manifest", bpparser.String},
+ "LOCAL_JARJAR_RULES": {"jarjar_rules", bpparser.String},
+ "LOCAL_CERTIFICATE": {"certificate", bpparser.String},
+ "LOCAL_PACKAGE_NAME": {"name", bpparser.String},
+ "LOCAL_MODULE_RELATIVE_PATH": {"relative_install_path", bpparser.String},
+
+ // List properties
+ "LOCAL_SRC_FILES": {"srcs", bpparser.List},
+ "LOCAL_SHARED_LIBRARIES": {"shared_libs", bpparser.List},
+ "LOCAL_STATIC_LIBRARIES": {"static_libs", bpparser.List},
+ "LOCAL_WHOLE_STATIC_LIBRARIES": {"whole_static_libs", bpparser.List},
+ "LOCAL_SYSTEM_SHARED_LIBRARIES": {"system_shared_libs", bpparser.List},
+ "LOCAL_ASFLAGS": {"asflags", bpparser.List},
+ "LOCAL_CLANG_ASFLAGS": {"clang_asflags", bpparser.List},
+ "LOCAL_CFLAGS": {"cflags", bpparser.List},
+ "LOCAL_CONLYFLAGS": {"conlyflags", bpparser.List},
+ "LOCAL_CPPFLAGS": {"cppflags", bpparser.List},
+ "LOCAL_LDFLAGS": {"ldflags", bpparser.List},
+ "LOCAL_REQUIRED_MODULES": {"required", bpparser.List},
+ "LOCAL_MODULE_TAGS": {"tags", bpparser.List},
+ "LOCAL_LDLIBS": {"host_ldlibs", bpparser.List},
+ "LOCAL_CLANG_CFLAGS": {"clang_cflags", bpparser.List},
+ "LOCAL_YACCFLAGS": {"yaccflags", bpparser.List},
+
+ "LOCAL_JAVA_RESOURCE_DIRS": {"java_resource_dirs", bpparser.List},
+ "LOCAL_JAVACFLAGS": {"javacflags", bpparser.List},
+ "LOCAL_DX_FLAGS": {"dxflags", bpparser.List},
+ "LOCAL_JAVA_LIBRARIES": {"java_libs", bpparser.List},
+ "LOCAL_STATIC_JAVA_LIBRARIES": {"java_static_libs", bpparser.List},
+ "LOCAL_AIDL_INCLUDES": {"aidl_includes", bpparser.List},
+ "LOCAL_AAPT_FLAGS": {"aaptflags", bpparser.List},
+ "LOCAL_PACKAGE_SPLITS": {"package_splits", bpparser.List},
+
+ // Bool properties
+ "LOCAL_IS_HOST_MODULE": {"host", bpparser.Bool},
+ "LOCAL_CLANG": {"clang", bpparser.Bool},
+ "LOCAL_FORCE_STATIC_EXECUTABLE": {"static", bpparser.Bool},
+ "LOCAL_ADDRESS_SANITIZER": {"asan", bpparser.Bool},
+ "LOCAL_NATIVE_COVERAGE": {"native_coverage", bpparser.Bool},
+ "LOCAL_NO_CRT": {"nocrt", bpparser.Bool},
+ "LOCAL_ALLOW_UNDEFINED_SYMBOLS": {"allow_undefined_symbols", bpparser.Bool},
+ "LOCAL_RTTI_FLAG": {"rtti", bpparser.Bool},
+
+ "LOCAL_NO_STANDARD_LIBRARIES": {"no_standard_libraries", bpparser.Bool},
+
+ "LOCAL_EXPORT_PACKAGE_RESOURCES": {"export_package_resources", bpparser.Bool},
+}
+
+var rewriteProperties = map[string]struct {
+ f func(file *bpFile, prefix string, value *mkparser.MakeString, append bool) error
+}{
+ "LOCAL_C_INCLUDES": {localIncludeDirs},
+ "LOCAL_EXPORT_C_INCLUDE_DIRS": {exportIncludeDirs},
+ "LOCAL_MODULE_STEM": {stem},
+}
+
+func localAbsPath(value bpparser.Value) (*bpparser.Value, error) {
+ if value.Type != bpparser.String {
+ return nil, fmt.Errorf("isLocalAbsPath expected a string, got %d", value.Type)
+ }
+
+ if value.Expression == nil {
+ if value.Variable == "LOCAL_PATH" {
+ return &bpparser.Value{
+ Type: bpparser.String,
+ StringValue: ".",
+ }, nil
+ }
+ return nil, nil
+ }
+
+ if value.Expression.Operator != '+' {
+ return nil, nil
+ }
+
+ firstOperand := value.Expression.Args[0]
+ secondOperand := value.Expression.Args[1]
+ if firstOperand.Type != bpparser.String {
+ return nil, nil
+ }
+
+ if firstOperand.Expression != nil {
+ return nil, nil
+ }
+
+ if firstOperand.Variable != "LOCAL_PATH" {
+ return nil, nil
+ }
+
+ if secondOperand.Expression == nil && secondOperand.Variable == "" {
+ if strings.HasPrefix(secondOperand.StringValue, "/") {
+ secondOperand.StringValue = secondOperand.StringValue[1:]
+ }
+ }
+ return &secondOperand, nil
+}
+
+func emptyList(value *bpparser.Value) bool {
+ return value.Type == bpparser.List && value.Expression == nil && value.Variable == "" &&
+ len(value.ListValue) == 0
+}
+
+func splitLocalGlobal(file *bpFile, val *bpparser.Value) (local, global *bpparser.Value, err error) {
+ local = &bpparser.Value{
+ Type: bpparser.List,
+ }
+ global = &bpparser.Value{
+ Type: bpparser.List,
+ }
+
+ if val.Expression != nil {
+ localA, globalA, err := splitLocalGlobal(file, &val.Expression.Args[0])
+ if err != nil {
+ return nil, nil, err
+ }
+
+ localB, globalB, err := splitLocalGlobal(file, &val.Expression.Args[1])
+ if err != nil {
+ return nil, nil, err
+ }
+
+ if emptyList(localA) {
+ local = localB
+ } else if emptyList(localB) {
+ local = localA
+ } else {
+ localExpression := *val.Expression
+ local.Expression = &localExpression
+ local.Expression.Args = [2]bpparser.Value{*localA, *localB}
+ }
+
+ if emptyList(globalA) {
+ global = globalB
+ } else if emptyList(globalB) {
+ global = globalA
+ } else {
+ globalExpression := *val.Expression
+ global.Expression = &globalExpression
+ global.Expression.Args = [2]bpparser.Value{*globalA, *globalB}
+ }
+ } else if val.Variable != "" {
+ if val.Variable == "LOCAL_PATH" {
+ local.ListValue = append(local.ListValue, bpparser.Value{
+ Type: bpparser.String,
+ StringValue: ".",
+ })
+ } else {
+ global.Variable = val.Variable
+ }
+ } else {
+ for _, v := range val.ListValue {
+ localPath, err := localAbsPath(v)
+ if err != nil {
+ return nil, nil, err
+ }
+ if localPath != nil {
+ local.ListValue = append(local.ListValue, *localPath)
+ } else {
+ global.ListValue = append(global.ListValue, v)
+ }
+ }
+ }
+
+ return local, global, nil
+}
+
+func localIncludeDirs(file *bpFile, prefix string, value *mkparser.MakeString, appendVariable bool) error {
+ val, err := makeVariableToBlueprint(file, value, bpparser.List)
+ if err != nil {
+ return err
+ }
+
+ local, global, err := splitLocalGlobal(file, val)
+ if err != nil {
+ return err
+ }
+
+ if len(global.ListValue) > 0 || global.Expression != nil || global.Variable != "" {
+ err = setVariable(file, appendVariable, prefix, "include_dirs", global, true)
+ if err != nil {
+ return err
+ }
+ }
+
+ if len(local.ListValue) > 0 || local.Expression != nil || local.Variable != "" {
+ err = setVariable(file, appendVariable, prefix, "local_include_dirs", local, true)
+ if err != nil {
+ return err
+ }
+ }
+
+ return nil
+}
+
+func exportIncludeDirs(file *bpFile, prefix string, value *mkparser.MakeString, appendVariable bool) error {
+ val, err := makeVariableToBlueprint(file, value, bpparser.List)
+ if err != nil {
+ return err
+ }
+
+ local, global, err := splitLocalGlobal(file, val)
+ if err != nil {
+ return err
+ }
+
+ if len(local.ListValue) > 0 || local.Expression != nil || local.Variable != "" {
+ err = setVariable(file, appendVariable, prefix, "export_include_dirs", local, true)
+ if err != nil {
+ return err
+ }
+ appendVariable = true
+ }
+
+ // Add any paths that could not be converted to local relative paths to export_include_dirs
+ // anyways, they will cause an error if they don't exist and can be fixed manually.
+ if len(global.ListValue) > 0 || global.Expression != nil || global.Variable != "" {
+ err = setVariable(file, appendVariable, prefix, "export_include_dirs", global, true)
+ if err != nil {
+ return err
+ }
+ }
+
+ return nil
+}
+
+func stem(file *bpFile, prefix string, value *mkparser.MakeString, appendVariable bool) error {
+ val, err := makeVariableToBlueprint(file, value, bpparser.String)
+ if err != nil {
+ return err
+ }
+ varName := "stem"
+
+ if val.Expression != nil && val.Expression.Operator == '+' &&
+ val.Expression.Args[0].Variable == "LOCAL_MODULE" {
+ varName = "suffix"
+ val = &val.Expression.Args[1]
+ }
+
+ return setVariable(file, appendVariable, prefix, varName, val, true)
+}
+
+var deleteProperties = map[string]struct{}{
+ "LOCAL_CPP_EXTENSION": struct{}{},
+}
+
+var propertyPrefixes = map[string]string{
+ "arm": "arch.arm",
+ "arm64": "arm.arm64",
+ "mips": "arch.mips",
+ "mips64": "arch.mips64",
+ "x86": "arch.x86",
+ "x86_64": "arch.x86_64",
+ "32": "multilib.lib32",
+ "64": "multilib.lib64",
+}
+
+var conditionalTranslations = map[string]map[bool]string{
+ "($(HOST_OS),darwin)": {
+ true: "target.darwin",
+ false: "target.not_darwin"},
+ "($(HOST_OS), darwin)": {
+ true: "target.darwin",
+ false: "target.not_darwin"},
+ "($(HOST_OS),windows)": {
+ true: "target.windows",
+ false: "target.not_windows"},
+ "($(HOST_OS), windows)": {
+ true: "target.windows",
+ false: "target.not_windows"},
+ "($(HOST_OS),linux)": {
+ true: "target.linux",
+ false: "target.not_linux"},
+ "($(HOST_OS), linux)": {
+ true: "target.linux",
+ false: "target.not_linux"},
+ "($(BUILD_OS),darwin)": {
+ true: "target.darwin",
+ false: "target.not_darwin"},
+ "($(BUILD_OS), darwin)": {
+ true: "target.darwin",
+ false: "target.not_darwin"},
+ "($(BUILD_OS),linux)": {
+ true: "target.linux",
+ false: "target.not_linux"},
+ "($(BUILD_OS), linux)": {
+ true: "target.linux",
+ false: "target.not_linux"},
+ "USE_MINGW": {
+ true: "target.windows",
+ false: "target.not_windows"},
+}
+
+func mydir(args []string) string {
+ return "."
+}
+
+func allJavaFilesUnder(args []string) string {
+ dir := ""
+ if len(args) > 0 {
+ dir = strings.TrimSpace(args[0])
+ }
+
+ return fmt.Sprintf("%s/**/*.java", dir)
+}
+
+func allSubdirJavaFiles(args []string) string {
+ return "**/*.java"
+}
+
+var moduleTypes = map[string]string{
+ "BUILD_SHARED_LIBRARY": "cc_library_shared",
+ "BUILD_STATIC_LIBRARY": "cc_library_static",
+ "BUILD_HOST_SHARED_LIBRARY": "cc_library_host_shared",
+ "BUILD_HOST_STATIC_LIBRARY": "cc_library_host_static",
+ "BUILD_EXECUTABLE": "cc_binary",
+ "BUILD_HOST_EXECUTABLE": "cc_binary_host",
+ "BUILD_NATIVE_TEST": "cc_test",
+ "BUILD_HOST_NATIVE_TEST": "cc_test_host",
+ "BUILD_NATIVE_BENCHMARK": "cc_benchmark",
+ "BUILD_HOST_NATIVE_BENCHMARK": "cc_benchmark_host",
+
+ "BUILD_JAVA_LIBRARY": "java_library",
+ "BUILD_STATIC_JAVA_LIBRARY": "java_library_static",
+ "BUILD_HOST_JAVA_LIBRARY": "java_library_host",
+ "BUILD_HOST_DALVIK_JAVA_LIBRARY": "java_library_host_dalvik",
+ "BUILD_PACKAGE": "android_app",
+
+ "BUILD_PREBUILT": "prebuilt",
+}
+
+var soongModuleTypes = map[string]bool{}
+
+func androidScope() mkparser.Scope {
+ globalScope := mkparser.NewScope(nil)
+ globalScope.Set("CLEAR_VARS", clear_vars)
+ globalScope.SetFunc("my-dir", mydir)
+ globalScope.SetFunc("all-java-files-under", allJavaFilesUnder)
+ globalScope.SetFunc("all-subdir-java-files", allSubdirJavaFiles)
+
+ for k, v := range moduleTypes {
+ globalScope.Set(k, v)
+ soongModuleTypes[v] = true
+ }
+
+ return globalScope
+}
diff --git a/androidmk/cmd/androidmk/androidmk.go b/androidmk/cmd/androidmk/androidmk.go
new file mode 100644
index 0000000..735a240
--- /dev/null
+++ b/androidmk/cmd/androidmk/androidmk.go
@@ -0,0 +1,425 @@
+package main
+
+import (
+ "bytes"
+ "fmt"
+ "io/ioutil"
+ "os"
+ "strings"
+ "text/scanner"
+
+ mkparser "android/soong/androidmk/parser"
+
+ bpparser "github.com/google/blueprint/parser"
+)
+
+// TODO: non-expanded variables with expressions
+
+type bpFile struct {
+ comments []bpparser.Comment
+ defs []bpparser.Definition
+ localAssignments map[string]*bpparser.Property
+ globalAssignments map[string]*bpparser.Value
+ scope mkparser.Scope
+ module *bpparser.Module
+
+ pos scanner.Position
+ prevLine, line int
+}
+
+func (f *bpFile) errorf(thing mkparser.MakeThing, s string, args ...interface{}) {
+ orig := thing.Dump()
+ s = fmt.Sprintf(s, args...)
+ f.comments = append(f.comments, bpparser.Comment{
+ Comment: []string{fmt.Sprintf("// ANDROIDMK TRANSLATION ERROR: %s", s)},
+ Pos: f.pos,
+ })
+ lines := strings.Split(orig, "\n")
+ for _, l := range lines {
+ f.incPos()
+ f.comments = append(f.comments, bpparser.Comment{
+ Comment: []string{"// " + l},
+ Pos: f.pos,
+ })
+ }
+}
+
+func (f *bpFile) setPos(pos, endPos scanner.Position) {
+ f.pos = pos
+
+ f.line++
+ if f.pos.Line > f.prevLine+1 {
+ f.line++
+ }
+
+ f.pos.Line = f.line
+ f.prevLine = endPos.Line
+}
+
+func (f *bpFile) incPos() {
+ f.pos.Line++
+ f.line++
+ f.prevLine++
+}
+
+type conditional struct {
+ cond string
+ eq bool
+}
+
+func main() {
+ b, err := ioutil.ReadFile(os.Args[1])
+ if err != nil {
+ fmt.Println(err.Error())
+ return
+ }
+
+ p := mkparser.NewParser(os.Args[1], bytes.NewBuffer(b))
+
+ things, errs := p.Parse()
+ if len(errs) > 0 {
+ for _, err := range errs {
+ fmt.Println("ERROR: ", err)
+ }
+ return
+ }
+
+ file := &bpFile{
+ scope: androidScope(),
+ localAssignments: make(map[string]*bpparser.Property),
+ globalAssignments: make(map[string]*bpparser.Value),
+ }
+
+ var conds []*conditional
+ var cond *conditional
+
+ for _, t := range things {
+ file.setPos(t.Pos(), t.EndPos())
+
+ if comment, ok := t.AsComment(); ok {
+ file.comments = append(file.comments, bpparser.Comment{
+ Pos: file.pos,
+ Comment: []string{"//" + comment.Comment},
+ })
+ } else if assignment, ok := t.AsAssignment(); ok {
+ handleAssignment(file, assignment, cond)
+ } else if directive, ok := t.AsDirective(); ok {
+ switch directive.Name {
+ case "include":
+ val := directive.Args.Value(file.scope)
+ switch {
+ case soongModuleTypes[val]:
+ handleModuleConditionals(file, directive, cond)
+ makeModule(file, val)
+ case val == clear_vars:
+ resetModule(file)
+ default:
+ file.errorf(directive, "unsupported include")
+ continue
+ }
+ case "ifeq", "ifneq", "ifdef", "ifndef":
+ args := directive.Args.Dump()
+ eq := directive.Name == "ifeq" || directive.Name == "ifdef"
+ if _, ok := conditionalTranslations[args]; ok {
+ newCond := conditional{args, eq}
+ conds = append(conds, &newCond)
+ if cond == nil {
+ cond = &newCond
+ } else {
+ file.errorf(directive, "unsupported nested conditional")
+ }
+ } else {
+ file.errorf(directive, "unsupported conditional")
+ conds = append(conds, nil)
+ continue
+ }
+ case "else":
+ if len(conds) == 0 {
+ file.errorf(directive, "missing if before else")
+ continue
+ } else if conds[len(conds)-1] == nil {
+ file.errorf(directive, "else from unsupported contitional")
+ continue
+ }
+ cond.eq = !cond.eq
+ case "endif":
+ if len(conds) == 0 {
+ file.errorf(directive, "missing if before endif")
+ continue
+ } else if conds[len(conds)-1] == nil {
+ file.errorf(directive, "endif from unsupported contitional")
+ conds = conds[:len(conds)-1]
+ } else {
+ if cond == conds[len(conds)-1] {
+ cond = nil
+ }
+ conds = conds[:len(conds)-1]
+ }
+ default:
+ file.errorf(directive, "unsupported directive")
+ continue
+ }
+ } else {
+ file.errorf(t, "unsupported line")
+ }
+ }
+
+ out, err := bpparser.Print(&bpparser.File{
+ Defs: file.defs,
+ Comments: file.comments,
+ })
+ if err != nil {
+ fmt.Println(err)
+ return
+ }
+
+ fmt.Print(string(out))
+}
+
+func handleAssignment(file *bpFile, assignment mkparser.Assignment, c *conditional) {
+ if !assignment.Name.Const() {
+ file.errorf(assignment, "unsupported non-const variable name")
+ return
+ }
+
+ if assignment.Target != nil {
+ file.errorf(assignment, "unsupported target assignment")
+ return
+ }
+
+ name := assignment.Name.Value(nil)
+ prefix := ""
+
+ if strings.HasPrefix(name, "LOCAL_") {
+ for k, v := range propertyPrefixes {
+ if strings.HasSuffix(name, "_"+k) {
+ name = strings.TrimSuffix(name, "_"+k)
+ prefix = v
+ break
+ }
+ }
+
+ if c != nil {
+ if prefix != "" {
+ file.errorf(assignment, "prefix assignment inside conditional, skipping conditional")
+ } else {
+ var ok bool
+ if prefix, ok = conditionalTranslations[c.cond][c.eq]; !ok {
+ panic("unknown conditional")
+ }
+ }
+ }
+ } else {
+ if c != nil {
+ eq := "eq"
+ if !c.eq {
+ eq = "neq"
+ }
+ file.errorf(assignment, "conditional %s %s on global assignment", eq, c.cond)
+ }
+ }
+
+ appendVariable := assignment.Type == "+="
+
+ var err error
+ if prop, ok := standardProperties[name]; ok {
+ var val *bpparser.Value
+ val, err = makeVariableToBlueprint(file, assignment.Value, prop.ValueType)
+ if err == nil {
+ err = setVariable(file, appendVariable, prefix, prop.string, val, true)
+ }
+ } else if prop, ok := rewriteProperties[name]; ok {
+ err = prop.f(file, prefix, assignment.Value, appendVariable)
+ } else if _, ok := deleteProperties[name]; ok {
+ return
+ } else {
+ switch {
+ case name == "LOCAL_PATH":
+ // Nothing to do, except maybe avoid the "./" in paths?
+ case name == "LOCAL_ARM_MODE":
+ // This is a hack to get the LOCAL_ARM_MODE value inside
+ // of an arch: { arm: {} } block.
+ armModeAssign := assignment
+ armModeAssign.Name = mkparser.SimpleMakeString("LOCAL_ARM_MODE_HACK_arm", assignment.Name.Pos)
+ handleAssignment(file, armModeAssign, c)
+ case name == "LOCAL_ADDITIONAL_DEPENDENCIES":
+ // TODO: check for only .mk files?
+ case strings.HasPrefix(name, "LOCAL_"):
+ file.errorf(assignment, "unsupported assignment to %s", name)
+ return
+ default:
+ var val *bpparser.Value
+ val, err = makeVariableToBlueprint(file, assignment.Value, bpparser.List)
+ err = setVariable(file, appendVariable, prefix, name, val, false)
+ }
+ }
+ if err != nil {
+ file.errorf(assignment, err.Error())
+ }
+}
+
+func handleModuleConditionals(file *bpFile, directive mkparser.Directive, c *conditional) {
+ if c == nil {
+ return
+ }
+
+ if _, ok := conditionalTranslations[c.cond]; !ok {
+ panic("unknown conditional " + c.cond)
+ }
+
+ prefix := conditionalTranslations[c.cond][c.eq]
+ disabledPrefix := conditionalTranslations[c.cond][!c.eq]
+
+ names := strings.Split(prefix, ".")
+ if len(names) != 2 {
+ panic("expected class.type")
+ }
+ class := names[0]
+ typ := names[1]
+ classProp := file.localAssignments[class]
+
+ // Hoist all properties inside the condtional up to the top level
+ file.module.Properties = file.localAssignments[prefix].Value.MapValue
+ file.module.Properties = append(file.module.Properties, classProp)
+ file.localAssignments[prefix].Value.MapValue = nil
+ for i := range classProp.Value.MapValue {
+ if classProp.Value.MapValue[i].Name.Name == typ {
+ classProp.Value.MapValue = append(classProp.Value.MapValue[:i], classProp.Value.MapValue[i+1:]...)
+ }
+ }
+
+ // Create a fake assignment with enabled = false
+ val, err := makeVariableToBlueprint(file, mkparser.SimpleMakeString("true", file.pos), bpparser.Bool)
+ if err == nil {
+ err = setVariable(file, false, disabledPrefix, "disabled", val, true)
+ }
+ if err != nil {
+ file.errorf(directive, err.Error())
+ }
+}
+
+func makeModule(file *bpFile, t string) {
+ file.module.Type = bpparser.Ident{
+ Name: t,
+ Pos: file.module.LbracePos,
+ }
+ file.module.RbracePos = file.pos
+ file.defs = append(file.defs, file.module)
+}
+
+func resetModule(file *bpFile) {
+ file.module = &bpparser.Module{}
+ file.module.LbracePos = file.pos
+ file.localAssignments = make(map[string]*bpparser.Property)
+}
+
+func makeVariableToBlueprint(file *bpFile, val *mkparser.MakeString,
+ typ bpparser.ValueType) (*bpparser.Value, error) {
+
+ var exp *bpparser.Value
+ var err error
+ switch typ {
+ case bpparser.List:
+ exp, err = makeToListExpression(val, file.scope)
+ case bpparser.String:
+ exp, err = makeToStringExpression(val, file.scope)
+ case bpparser.Bool:
+ exp, err = makeToBoolExpression(val)
+ default:
+ panic("unknown type")
+ }
+
+ if err != nil {
+ return nil, err
+ }
+
+ return exp, nil
+}
+
+func setVariable(file *bpFile, plusequals bool, prefix, name string, value *bpparser.Value, local bool) error {
+
+ if prefix != "" {
+ name = prefix + "." + name
+ }
+
+ pos := file.pos
+
+ var oldValue *bpparser.Value
+ if local {
+ oldProp := file.localAssignments[name]
+ if oldProp != nil {
+ oldValue = &oldProp.Value
+ }
+ } else {
+ oldValue = file.globalAssignments[name]
+ }
+
+ if local {
+ if oldValue != nil && plusequals {
+ val, err := addValues(oldValue, value)
+ if err != nil {
+ return fmt.Errorf("unsupported addition: %s", err.Error())
+ }
+ val.Expression.Pos = pos
+ *oldValue = *val
+ } else {
+ names := strings.Split(name, ".")
+ container := &file.module.Properties
+
+ for i, n := range names[:len(names)-1] {
+ fqn := strings.Join(names[0:i+1], ".")
+ prop := file.localAssignments[fqn]
+ if prop == nil {
+ prop = &bpparser.Property{
+ Name: bpparser.Ident{Name: n, Pos: pos},
+ Pos: pos,
+ Value: bpparser.Value{
+ Type: bpparser.Map,
+ MapValue: []*bpparser.Property{},
+ },
+ }
+ file.localAssignments[fqn] = prop
+ *container = append(*container, prop)
+ }
+ container = &prop.Value.MapValue
+ }
+
+ prop := &bpparser.Property{
+ Name: bpparser.Ident{Name: names[len(names)-1], Pos: pos},
+ Pos: pos,
+ Value: *value,
+ }
+ file.localAssignments[name] = prop
+ *container = append(*container, prop)
+ }
+ } else {
+ if oldValue != nil && plusequals {
+ a := &bpparser.Assignment{
+ Name: bpparser.Ident{
+ Name: name,
+ Pos: pos,
+ },
+ Value: *value,
+ OrigValue: *value,
+ Pos: pos,
+ Assigner: "+=",
+ }
+ file.defs = append(file.defs, a)
+ } else {
+ a := &bpparser.Assignment{
+ Name: bpparser.Ident{
+ Name: name,
+ Pos: pos,
+ },
+ Value: *value,
+ OrigValue: *value,
+ Pos: pos,
+ Assigner: "=",
+ }
+ file.globalAssignments[name] = &a.Value
+ file.defs = append(file.defs, a)
+ }
+ }
+
+ return nil
+}
diff --git a/androidmk/cmd/androidmk/values.go b/androidmk/cmd/androidmk/values.go
new file mode 100644
index 0000000..ce2f279
--- /dev/null
+++ b/androidmk/cmd/androidmk/values.go
@@ -0,0 +1,203 @@
+package main
+
+import (
+ "fmt"
+ "strings"
+
+ mkparser "android/soong/androidmk/parser"
+
+ bpparser "github.com/google/blueprint/parser"
+)
+
+func stringToStringValue(s string) *bpparser.Value {
+ return &bpparser.Value{
+ Type: bpparser.String,
+ StringValue: s,
+ }
+}
+
+func addValues(val1, val2 *bpparser.Value) (*bpparser.Value, error) {
+ if val1 == nil {
+ return val2, nil
+ }
+
+ if val1.Type == bpparser.String && val2.Type == bpparser.List {
+ val1 = &bpparser.Value{
+ Type: bpparser.List,
+ ListValue: []bpparser.Value{*val1},
+ }
+ } else if val2.Type == bpparser.String && val1.Type == bpparser.List {
+ val2 = &bpparser.Value{
+ Type: bpparser.List,
+ ListValue: []bpparser.Value{*val1},
+ }
+ } else if val1.Type != val2.Type {
+ return nil, fmt.Errorf("cannot add mismatched types")
+ }
+
+ return &bpparser.Value{
+ Type: val1.Type,
+ Expression: &bpparser.Expression{
+ Operator: '+',
+ Args: [2]bpparser.Value{*val1, *val2},
+ },
+ }, nil
+}
+
+func makeToStringExpression(ms *mkparser.MakeString, scope mkparser.Scope) (*bpparser.Value, error) {
+ var val *bpparser.Value
+ var err error
+
+ if ms.Strings[0] != "" {
+ val = stringToStringValue(ms.Strings[0])
+ }
+
+ for i, s := range ms.Strings[1:] {
+ if ret, ok := ms.Variables[i].EvalFunction(scope); ok {
+ val, err = addValues(val, stringToStringValue(ret))
+ } else {
+ name := ms.Variables[i].Name
+ if !name.Const() {
+ return nil, fmt.Errorf("Unsupported non-const variable name %s", name.Dump())
+ }
+ tmp := &bpparser.Value{
+ Type: bpparser.String,
+ Variable: name.Value(nil),
+ }
+
+ val, err = addValues(val, tmp)
+ if err != nil {
+ return nil, err
+ }
+ }
+
+ if s != "" {
+ tmp := stringToStringValue(s)
+ val, err = addValues(val, tmp)
+ if err != nil {
+ return nil, err
+ }
+ }
+ }
+
+ return val, nil
+}
+
+func stringToListValue(s string) *bpparser.Value {
+ list := strings.Fields(s)
+ valList := make([]bpparser.Value, len(list))
+ for i, l := range list {
+ valList[i] = bpparser.Value{
+ Type: bpparser.String,
+ StringValue: l,
+ }
+ }
+ return &bpparser.Value{
+ Type: bpparser.List,
+ ListValue: valList,
+ }
+
+}
+
+func makeToListExpression(ms *mkparser.MakeString, scope mkparser.Scope) (*bpparser.Value, error) {
+ fields := ms.Split(" \t")
+
+ var listOfListValues []*bpparser.Value
+
+ listValue := &bpparser.Value{
+ Type: bpparser.List,
+ }
+
+ for _, f := range fields {
+ if len(f.Variables) == 1 && f.Strings[0] == "" && f.Strings[1] == "" {
+ if ret, ok := f.Variables[0].EvalFunction(scope); ok {
+ listValue.ListValue = append(listValue.ListValue, bpparser.Value{
+ Type: bpparser.String,
+ StringValue: ret,
+ })
+ } else {
+ // Variable by itself, variable is probably a list
+ if !f.Variables[0].Name.Const() {
+ return nil, fmt.Errorf("unsupported non-const variable name")
+ }
+ if len(listValue.ListValue) > 0 {
+ listOfListValues = append(listOfListValues, listValue)
+ }
+ listOfListValues = append(listOfListValues, &bpparser.Value{
+ Type: bpparser.List,
+ Variable: f.Variables[0].Name.Value(nil),
+ })
+ listValue = &bpparser.Value{
+ Type: bpparser.List,
+ }
+ }
+ } else {
+ s, err := makeToStringExpression(f, scope)
+ if err != nil {
+ return nil, err
+ }
+ if s == nil {
+ continue
+ }
+
+ listValue.ListValue = append(listValue.ListValue, *s)
+ }
+ }
+
+ if len(listValue.ListValue) > 0 {
+ listOfListValues = append(listOfListValues, listValue)
+ }
+
+ if len(listOfListValues) == 0 {
+ return listValue, nil
+ }
+
+ val := listOfListValues[0]
+ for _, tmp := range listOfListValues[1:] {
+ var err error
+ val, err = addValues(val, tmp)
+ if err != nil {
+ return nil, err
+ }
+ }
+
+ return val, nil
+}
+
+func stringToBoolValue(s string) (*bpparser.Value, error) {
+ var b bool
+ s = strings.TrimSpace(s)
+ switch s {
+ case "true":
+ b = true
+ case "false", "":
+ b = false
+ case "-frtti": // HACK for LOCAL_RTTI_VALUE
+ b = true
+ default:
+ return nil, fmt.Errorf("unexpected bool value %s", s)
+ }
+ return &bpparser.Value{
+ Type: bpparser.Bool,
+ BoolValue: b,
+ }, nil
+}
+
+func makeToBoolExpression(ms *mkparser.MakeString) (*bpparser.Value, error) {
+ if !ms.Const() {
+ if len(ms.Variables) == 1 && ms.Strings[0] == "" && ms.Strings[1] == "" {
+ name := ms.Variables[0].Name
+ if !name.Const() {
+ return nil, fmt.Errorf("unsupported non-const variable name")
+ }
+ return &bpparser.Value{
+ Type: bpparser.Bool,
+ Variable: name.Value(nil),
+ }, nil
+ } else {
+ return nil, fmt.Errorf("non-const bool expression %s", ms.Dump())
+ }
+ }
+
+ return stringToBoolValue(ms.Value(nil))
+}
diff --git a/androidmk/parser/make_strings.go b/androidmk/parser/make_strings.go
new file mode 100644
index 0000000..558853f
--- /dev/null
+++ b/androidmk/parser/make_strings.go
@@ -0,0 +1,170 @@
+package parser
+
+import (
+ "strings"
+ "text/scanner"
+ "unicode"
+)
+
+// A MakeString is a string that may contain variable substitutions in it.
+// It can be considered as an alternating list of raw Strings and variable
+// substitutions, where the first and last entries in the list must be raw
+// Strings (possibly empty). A MakeString that starts with a variable
+// will have an empty first raw string, and a MakeString that ends with a
+// variable will have an empty last raw string. Two sequential Variables
+// will have an empty raw string between them.
+//
+// The MakeString is stored as two lists, a list of raw Strings and a list
+// of Variables. The raw string list is always one longer than the variable
+// list.
+type MakeString struct {
+ Pos scanner.Position
+ Strings []string
+ Variables []Variable
+}
+
+func SimpleMakeString(s string, pos scanner.Position) *MakeString {
+ return &MakeString{
+ Pos: pos,
+ Strings: []string{s},
+ }
+}
+
+func (ms *MakeString) appendString(s string) {
+ if len(ms.Strings) == 0 {
+ ms.Strings = []string{s}
+ return
+ } else {
+ ms.Strings[len(ms.Strings)-1] += s
+ }
+}
+
+func (ms *MakeString) appendVariable(v Variable) {
+ if len(ms.Strings) == 0 {
+ ms.Strings = []string{"", ""}
+ ms.Variables = []Variable{v}
+ } else {
+ ms.Strings = append(ms.Strings, "")
+ ms.Variables = append(ms.Variables, v)
+ }
+}
+
+func (ms *MakeString) appendMakeString(other *MakeString) {
+ last := len(ms.Strings) - 1
+ ms.Strings[last] += other.Strings[0]
+ ms.Strings = append(ms.Strings, other.Strings[1:]...)
+ ms.Variables = append(ms.Variables, other.Variables...)
+}
+
+func (ms *MakeString) Value(scope Scope) string {
+ if len(ms.Strings) == 0 {
+ return ""
+ } else {
+ ret := ms.Strings[0]
+ for i := range ms.Strings[1:] {
+ ret += ms.Variables[i].Value(scope)
+ ret += ms.Strings[i+1]
+ }
+ return ret
+ }
+}
+
+func (ms *MakeString) Dump() string {
+ if len(ms.Strings) == 0 {
+ return ""
+ } else {
+ ret := ms.Strings[0]
+ for i := range ms.Strings[1:] {
+ ret += ms.Variables[i].Dump()
+ ret += ms.Strings[i+1]
+ }
+ return ret
+ }
+}
+
+func (ms *MakeString) Const() bool {
+ return len(ms.Strings) <= 1
+}
+
+func (ms *MakeString) Empty() bool {
+ return len(ms.Strings) == 0 || (len(ms.Strings) == 1 && ms.Strings[0] == "")
+}
+
+func (ms *MakeString) Split(sep string) []*MakeString {
+ return ms.SplitN(sep, -1)
+}
+
+func (ms *MakeString) SplitN(sep string, n int) []*MakeString {
+ ret := []*MakeString{}
+
+ curMs := SimpleMakeString("", ms.Pos)
+
+ var i int
+ var s string
+ for i, s = range ms.Strings {
+ if n != 0 {
+ split := splitAnyN(s, sep, n)
+ if n != -1 {
+ if len(split) > n {
+ panic("oops!")
+ } else {
+ n -= len(split)
+ }
+ }
+ curMs.appendString(split[0])
+
+ for _, r := range split[1:] {
+ ret = append(ret, curMs)
+ curMs = SimpleMakeString(r, ms.Pos)
+ }
+ } else {
+ curMs.appendString(s)
+ }
+
+ if i < len(ms.Strings)-1 {
+ curMs.appendVariable(ms.Variables[i])
+ }
+ }
+
+ ret = append(ret, curMs)
+ return ret
+}
+
+func (ms *MakeString) TrimLeftSpaces() {
+ ms.Strings[0] = strings.TrimLeftFunc(ms.Strings[0], unicode.IsSpace)
+}
+
+func (ms *MakeString) TrimRightSpaces() {
+ last := len(ms.Strings) - 1
+ ms.Strings[last] = strings.TrimRightFunc(ms.Strings[last], unicode.IsSpace)
+}
+
+func (ms *MakeString) TrimRightOne() {
+ last := len(ms.Strings) - 1
+ if len(ms.Strings[last]) > 1 {
+ ms.Strings[last] = ms.Strings[last][0 : len(ms.Strings[last])-1]
+ }
+}
+
+func (ms *MakeString) EndsWith(ch rune) bool {
+ s := ms.Strings[len(ms.Strings)-1]
+ return s[len(s)-1] == uint8(ch)
+}
+
+func splitAnyN(s, sep string, n int) []string {
+ ret := []string{}
+ for n == -1 || n > 1 {
+ index := strings.IndexAny(s, sep)
+ if index >= 0 {
+ ret = append(ret, s[0:index])
+ s = s[index+1:]
+ if n > 0 {
+ n--
+ }
+ } else {
+ break
+ }
+ }
+ ret = append(ret, s)
+ return ret
+}
diff --git a/androidmk/parser/make_strings_test.go b/androidmk/parser/make_strings_test.go
new file mode 100644
index 0000000..cc3fd0a
--- /dev/null
+++ b/androidmk/parser/make_strings_test.go
@@ -0,0 +1,97 @@
+package parser
+
+import (
+ "strings"
+ "testing"
+ "text/scanner"
+)
+
+var splitNTestCases = []struct {
+ in *MakeString
+ expected []*MakeString
+ sep string
+ n int
+}{
+ {
+ in: &MakeString{
+ Strings: []string{
+ "a b c",
+ "d e f",
+ " h i j",
+ },
+ Variables: []Variable{
+ Variable{Name: SimpleMakeString("var1", scanner.Position{})},
+ Variable{Name: SimpleMakeString("var2", scanner.Position{})},
+ },
+ },
+ sep: " ",
+ n: -1,
+ expected: []*MakeString{
+ SimpleMakeString("a", scanner.Position{}),
+ SimpleMakeString("b", scanner.Position{}),
+ &MakeString{
+ Strings: []string{"c", "d"},
+ Variables: []Variable{
+ Variable{Name: SimpleMakeString("var1", scanner.Position{})},
+ },
+ },
+ SimpleMakeString("e", scanner.Position{}),
+ &MakeString{
+ Strings: []string{"f", ""},
+ Variables: []Variable{
+ Variable{Name: SimpleMakeString("var2", scanner.Position{})},
+ },
+ },
+ SimpleMakeString("h", scanner.Position{}),
+ SimpleMakeString("i", scanner.Position{}),
+ SimpleMakeString("j", scanner.Position{}),
+ },
+ },
+ {
+ in: &MakeString{
+ Strings: []string{
+ "a b c",
+ "d e f",
+ " h i j",
+ },
+ Variables: []Variable{
+ Variable{Name: SimpleMakeString("var1", scanner.Position{})},
+ Variable{Name: SimpleMakeString("var2", scanner.Position{})},
+ },
+ },
+ sep: " ",
+ n: 3,
+ expected: []*MakeString{
+ SimpleMakeString("a", scanner.Position{}),
+ SimpleMakeString("b", scanner.Position{}),
+ &MakeString{
+ Strings: []string{"c", "d e f", " h i j"},
+ Variables: []Variable{
+ Variable{Name: SimpleMakeString("var1", scanner.Position{})},
+ Variable{Name: SimpleMakeString("var2", scanner.Position{})},
+ },
+ },
+ },
+ },
+}
+
+func TestMakeStringSplitN(t *testing.T) {
+ for _, test := range splitNTestCases {
+ got := test.in.SplitN(test.sep, test.n)
+ gotString := dumpArray(got)
+ expectedString := dumpArray(test.expected)
+ if gotString != expectedString {
+ t.Errorf("expected:\n%s\ngot:\n%s", expectedString, gotString)
+ }
+ }
+}
+
+func dumpArray(a []*MakeString) string {
+ ret := make([]string, len(a))
+
+ for i, s := range a {
+ ret[i] = s.Dump()
+ }
+
+ return strings.Join(ret, "|||")
+}
diff --git a/androidmk/parser/makething.go b/androidmk/parser/makething.go
new file mode 100644
index 0000000..7d60a77
--- /dev/null
+++ b/androidmk/parser/makething.go
@@ -0,0 +1,142 @@
+package parser
+
+import (
+ "text/scanner"
+)
+
+type MakeThing interface {
+ AsAssignment() (Assignment, bool)
+ AsComment() (Comment, bool)
+ AsDirective() (Directive, bool)
+ AsRule() (Rule, bool)
+ AsVariable() (Variable, bool)
+ Dump() string
+ Pos() scanner.Position
+ EndPos() scanner.Position
+}
+
+type Assignment struct {
+ makeThing
+ Name *MakeString
+ Value *MakeString
+ Target *MakeString
+ Type string
+}
+
+type Comment struct {
+ makeThing
+ Comment string
+}
+
+type Directive struct {
+ makeThing
+ Name string
+ Args *MakeString
+}
+
+type Rule struct {
+ makeThing
+ Target *MakeString
+ Prerequisites *MakeString
+ Recipe string
+}
+
+type Variable struct {
+ makeThing
+ Name *MakeString
+}
+
+type makeThing struct {
+ pos scanner.Position
+ endPos scanner.Position
+}
+
+func (m makeThing) Pos() scanner.Position {
+ return m.pos
+}
+
+func (m makeThing) EndPos() scanner.Position {
+ return m.endPos
+}
+
+func (makeThing) AsAssignment() (a Assignment, ok bool) {
+ return
+}
+
+func (a Assignment) AsAssignment() (Assignment, bool) {
+ return a, true
+}
+
+func (a Assignment) Dump() string {
+ target := ""
+ if a.Target != nil {
+ target = a.Target.Dump() + ": "
+ }
+ return target + a.Name.Dump() + a.Type + a.Value.Dump()
+}
+
+func (makeThing) AsComment() (c Comment, ok bool) {
+ return
+}
+
+func (c Comment) AsComment() (Comment, bool) {
+ return c, true
+}
+
+func (c Comment) Dump() string {
+ return "#" + c.Comment
+}
+
+func (makeThing) AsDirective() (d Directive, ok bool) {
+ return
+}
+
+func (d Directive) AsDirective() (Directive, bool) {
+ return d, true
+}
+
+func (d Directive) Dump() string {
+ return d.Name + " " + d.Args.Dump()
+}
+
+func (makeThing) AsRule() (r Rule, ok bool) {
+ return
+}
+
+func (r Rule) AsRule() (Rule, bool) {
+ return r, true
+}
+
+func (r Rule) Dump() string {
+ recipe := ""
+ if r.Recipe != "" {
+ recipe = "\n" + r.Recipe
+ }
+ return "rule: " + r.Target.Dump() + ": " + r.Prerequisites.Dump() + recipe
+}
+
+func (makeThing) AsVariable() (v Variable, ok bool) {
+ return
+}
+
+func (v Variable) AsVariable() (Variable, bool) {
+ return v, true
+}
+
+func (v Variable) Dump() string {
+ return "$(" + v.Name.Dump() + ")"
+}
+
+type byPosition []MakeThing
+
+func (s byPosition) Len() int {
+ return len(s)
+}
+
+func (s byPosition) Swap(i, j int) {
+ s[i], s[j] = s[j], s[i]
+}
+
+func (s byPosition) Less(i, j int) bool {
+ return s[i].Pos().Offset < s[j].Pos().Offset
+}
diff --git a/androidmk/parser/parser.go b/androidmk/parser/parser.go
new file mode 100644
index 0000000..58e612e
--- /dev/null
+++ b/androidmk/parser/parser.go
@@ -0,0 +1,633 @@
+package parser
+
+import (
+ "errors"
+ "fmt"
+ "io"
+ "sort"
+ "text/scanner"
+)
+
+var errTooManyErrors = errors.New("too many errors")
+
+const maxErrors = 100
+
+type ParseError struct {
+ Err error
+ Pos scanner.Position
+}
+
+func (e *ParseError) Error() string {
+ return fmt.Sprintf("%s: %s", e.Pos, e.Err)
+}
+
+func (p *parser) Parse() ([]MakeThing, []error) {
+ defer func() {
+ if r := recover(); r != nil {
+ if r == errTooManyErrors {
+ return
+ }
+ panic(r)
+ }
+ }()
+
+ p.parseLines()
+ p.accept(scanner.EOF)
+ p.things = append(p.things, p.comments...)
+ sort.Sort(byPosition(p.things))
+
+ return p.things, p.errors
+}
+
+type parser struct {
+ scanner scanner.Scanner
+ tok rune
+ errors []error
+ comments []MakeThing
+ things []MakeThing
+}
+
+func NewParser(filename string, r io.Reader) *parser {
+ p := &parser{}
+ p.scanner.Init(r)
+ p.scanner.Error = func(sc *scanner.Scanner, msg string) {
+ p.errorf(msg)
+ }
+ p.scanner.Whitespace = 0
+ p.scanner.IsIdentRune = func(ch rune, i int) bool {
+ return ch > 0 && ch != ':' && ch != '#' && ch != '=' && ch != '+' && ch != '$' &&
+ ch != '\\' && ch != '(' && ch != ')' && ch != '{' && ch != '}' && ch != ';' &&
+ ch != '|' && ch != '?' && ch != '\r' && !isWhitespace(ch)
+ }
+ p.scanner.Mode = scanner.ScanIdents
+ p.scanner.Filename = filename
+ p.next()
+ return p
+}
+
+func (p *parser) errorf(format string, args ...interface{}) {
+ pos := p.scanner.Position
+ if !pos.IsValid() {
+ pos = p.scanner.Pos()
+ }
+ err := &ParseError{
+ Err: fmt.Errorf(format, args...),
+ Pos: pos,
+ }
+ p.errors = append(p.errors, err)
+ if len(p.errors) >= maxErrors {
+ panic(errTooManyErrors)
+ }
+}
+
+func (p *parser) accept(toks ...rune) bool {
+ for _, tok := range toks {
+ if p.tok != tok {
+ p.errorf("expected %s, found %s", scanner.TokenString(tok),
+ scanner.TokenString(p.tok))
+ return false
+ }
+ p.next()
+ }
+ return true
+}
+
+func (p *parser) next() {
+ if p.tok != scanner.EOF {
+ p.tok = p.scanner.Scan()
+ for p.tok == '\r' {
+ p.tok = p.scanner.Scan()
+ }
+ }
+ return
+}
+
+func (p *parser) parseLines() {
+ for {
+ p.ignoreWhitespace()
+
+ if p.parseDirective() {
+ continue
+ }
+
+ ident, _ := p.parseExpression('=', '?', ':', '#', '\n')
+
+ p.ignoreSpaces()
+
+ switch p.tok {
+ case '?':
+ p.accept('?')
+ if p.tok == '=' {
+ p.parseAssignment("?=", nil, ident)
+ } else {
+ p.errorf("expected = after ?")
+ }
+ case '+':
+ p.accept('+')
+ if p.tok == '=' {
+ p.parseAssignment("+=", nil, ident)
+ } else {
+ p.errorf("expected = after +")
+ }
+ case ':':
+ p.accept(':')
+ switch p.tok {
+ case '=':
+ p.parseAssignment(":=", nil, ident)
+ default:
+ p.parseRule(ident)
+ }
+ case '=':
+ p.parseAssignment("=", nil, ident)
+ case '#', '\n', scanner.EOF:
+ ident.TrimRightSpaces()
+ if v, ok := toVariable(ident); ok {
+ p.things = append(p.things, v)
+ } else if !ident.Empty() {
+ p.errorf("expected directive, rule, or assignment after ident " + ident.Dump())
+ }
+ switch p.tok {
+ case scanner.EOF:
+ return
+ case '\n':
+ p.accept('\n')
+ case '#':
+ p.parseComment()
+ }
+ default:
+ p.errorf("expected assignment or rule definition, found %s\n",
+ p.scanner.TokenText())
+ return
+ }
+ }
+}
+
+func (p *parser) parseDirective() bool {
+ if p.tok != scanner.Ident || !isDirective(p.scanner.TokenText()) {
+ return false
+ }
+
+ d := p.scanner.TokenText()
+ pos := p.scanner.Position
+ endPos := pos
+ p.accept(scanner.Ident)
+
+ expression := SimpleMakeString("", pos)
+
+ switch d {
+ case "endif", "endef", "else":
+ // Nothing
+ case "define":
+ expression = p.parseDefine()
+ default:
+ p.ignoreSpaces()
+ expression, endPos = p.parseExpression()
+ }
+
+ p.things = append(p.things, Directive{
+ makeThing: makeThing{
+ pos: pos,
+ endPos: endPos,
+ },
+ Name: d,
+ Args: expression,
+ })
+ return true
+}
+
+func (p *parser) parseDefine() *MakeString {
+ value := SimpleMakeString("", p.scanner.Position)
+
+loop:
+ for {
+ switch p.tok {
+ case scanner.Ident:
+ if p.scanner.TokenText() == "endef" {
+ p.accept(scanner.Ident)
+ break loop
+ }
+ value.appendString(p.scanner.TokenText())
+ p.accept(scanner.Ident)
+ case '\\':
+ p.parseEscape()
+ switch p.tok {
+ case '\n':
+ value.appendString(" ")
+ case scanner.EOF:
+ p.errorf("expected escaped character, found %s",
+ scanner.TokenString(p.tok))
+ break loop
+ default:
+ value.appendString(`\` + string(p.tok))
+ }
+ p.accept(p.tok)
+ //TODO: handle variables inside defines? result depends if
+ //define is used in make or rule context
+ //case '$':
+ // variable := p.parseVariable()
+ // value.appendVariable(variable)
+ case scanner.EOF:
+ p.errorf("unexpected EOF while looking for endef")
+ break loop
+ default:
+ value.appendString(p.scanner.TokenText())
+ p.accept(p.tok)
+ }
+ }
+
+ return value
+}
+
+func (p *parser) parseEscape() {
+ p.scanner.Mode = 0
+ p.accept('\\')
+ p.scanner.Mode = scanner.ScanIdents
+}
+
+func (p *parser) parseExpression(end ...rune) (*MakeString, scanner.Position) {
+ value := SimpleMakeString("", p.scanner.Position)
+
+ endParen := false
+ for _, r := range end {
+ if r == ')' {
+ endParen = true
+ }
+ }
+ parens := 0
+
+ endPos := p.scanner.Position
+
+loop:
+ for {
+ if endParen && parens > 0 && p.tok == ')' {
+ parens--
+ value.appendString(")")
+ endPos = p.scanner.Position
+ p.accept(')')
+ continue
+ }
+
+ for _, r := range end {
+ if p.tok == r {
+ break loop
+ }
+ }
+
+ switch p.tok {
+ case '\n':
+ break loop
+ case scanner.Ident:
+ value.appendString(p.scanner.TokenText())
+ endPos = p.scanner.Position
+ p.accept(scanner.Ident)
+ case '\\':
+ p.parseEscape()
+ switch p.tok {
+ case '\n':
+ value.appendString(" ")
+ case scanner.EOF:
+ p.errorf("expected escaped character, found %s",
+ scanner.TokenString(p.tok))
+ return value, endPos
+ default:
+ value.appendString(`\` + string(p.tok))
+ }
+ endPos = p.scanner.Position
+ p.accept(p.tok)
+ case '#':
+ p.parseComment()
+ break loop
+ case '$':
+ var variable Variable
+ variable, endPos = p.parseVariable()
+ value.appendVariable(variable)
+ case scanner.EOF:
+ break loop
+ case '(':
+ if endParen {
+ parens++
+ }
+ value.appendString("(")
+ endPos = p.scanner.Position
+ p.accept('(')
+ default:
+ value.appendString(p.scanner.TokenText())
+ endPos = p.scanner.Position
+ p.accept(p.tok)
+ }
+ }
+
+ if parens > 0 {
+ p.errorf("expected closing paren %s", value.Dump())
+ }
+ return value, endPos
+}
+
+func (p *parser) parseVariable() (Variable, scanner.Position) {
+ pos := p.scanner.Position
+ endPos := pos
+ p.accept('$')
+ var name *MakeString
+ switch p.tok {
+ case '(':
+ return p.parseBracketedVariable('(', ')', pos)
+ case '{':
+ return p.parseBracketedVariable('{', '}', pos)
+ case '$':
+ name = SimpleMakeString("__builtin_dollar", scanner.Position{})
+ case scanner.EOF:
+ p.errorf("expected variable name, found %s",
+ scanner.TokenString(p.tok))
+ default:
+ name, endPos = p.parseExpression(variableNameEndRunes...)
+ }
+
+ return p.nameToVariable(name, pos, endPos), endPos
+}
+
+func (p *parser) parseBracketedVariable(start, end rune, pos scanner.Position) (Variable, scanner.Position) {
+ p.accept(start)
+ name, endPos := p.parseExpression(end)
+ p.accept(end)
+ return p.nameToVariable(name, pos, endPos), endPos
+}
+
+func (p *parser) nameToVariable(name *MakeString, pos, endPos scanner.Position) Variable {
+ return Variable{
+ makeThing: makeThing{
+ pos: pos,
+ endPos: endPos,
+ },
+ Name: name,
+ }
+}
+
+func (p *parser) parseRule(target *MakeString) {
+ prerequisites, newLine := p.parseRulePrerequisites(target)
+
+ recipe := ""
+ endPos := p.scanner.Position
+loop:
+ for {
+ if newLine {
+ if p.tok == '\t' {
+ endPos = p.scanner.Position
+ p.accept('\t')
+ newLine = false
+ continue loop
+ } else if p.parseDirective() {
+ newLine = false
+ continue
+ } else {
+ break loop
+ }
+ }
+
+ newLine = false
+ switch p.tok {
+ case '\\':
+ p.parseEscape()
+ recipe += string(p.tok)
+ endPos = p.scanner.Position
+ p.accept(p.tok)
+ case '\n':
+ newLine = true
+ recipe += "\n"
+ endPos = p.scanner.Position
+ p.accept('\n')
+ case scanner.EOF:
+ break loop
+ default:
+ recipe += p.scanner.TokenText()
+ endPos = p.scanner.Position
+ p.accept(p.tok)
+ }
+ }
+
+ if prerequisites != nil {
+ p.things = append(p.things, Rule{
+ makeThing: makeThing{
+ pos: target.Pos,
+ endPos: endPos,
+ },
+ Target: target,
+ Prerequisites: prerequisites,
+ Recipe: recipe,
+ })
+ }
+}
+
+func (p *parser) parseRulePrerequisites(target *MakeString) (*MakeString, bool) {
+ newLine := false
+
+ p.ignoreSpaces()
+
+ prerequisites, _ := p.parseExpression('#', '\n', ';', ':', '=')
+
+ switch p.tok {
+ case '\n':
+ p.accept('\n')
+ newLine = true
+ case '#':
+ p.parseComment()
+ newLine = true
+ case ';':
+ p.accept(';')
+ case ':':
+ p.accept(':')
+ if p.tok == '=' {
+ p.parseAssignment(":=", target, prerequisites)
+ return nil, true
+ } else {
+ more, _ := p.parseExpression('#', '\n', ';')
+ prerequisites.appendMakeString(more)
+ }
+ case '=':
+ p.parseAssignment("=", target, prerequisites)
+ return nil, true
+ default:
+ p.errorf("unexpected token %s after rule prerequisites", scanner.TokenString(p.tok))
+ }
+
+ return prerequisites, newLine
+}
+
+func (p *parser) parseComment() {
+ pos := p.scanner.Position
+ p.accept('#')
+ comment := ""
+ endPos := pos
+loop:
+ for {
+ switch p.tok {
+ case '\\':
+ p.parseEscape()
+ if p.tok == '\n' {
+ comment += "\n"
+ } else {
+ comment += "\\" + p.scanner.TokenText()
+ }
+ endPos = p.scanner.Position
+ p.accept(p.tok)
+ case '\n':
+ endPos = p.scanner.Position
+ p.accept('\n')
+ break loop
+ case scanner.EOF:
+ break loop
+ default:
+ comment += p.scanner.TokenText()
+ endPos = p.scanner.Position
+ p.accept(p.tok)
+ }
+ }
+
+ p.comments = append(p.comments, Comment{
+ makeThing: makeThing{
+ pos: pos,
+ endPos: endPos,
+ },
+ Comment: comment,
+ })
+}
+
+func (p *parser) parseAssignment(t string, target *MakeString, ident *MakeString) {
+ // The value of an assignment is everything including and after the first
+ // non-whitespace character after the = until the end of the logical line,
+ // which may included escaped newlines
+ p.accept('=')
+ value, endPos := p.parseExpression()
+ value.TrimLeftSpaces()
+ if ident.EndsWith('+') && t == "=" {
+ ident.TrimRightOne()
+ t = "+="
+ }
+
+ ident.TrimRightSpaces()
+
+ p.things = append(p.things, Assignment{
+ makeThing: makeThing{
+ pos: ident.Pos,
+ endPos: endPos,
+ },
+ Name: ident,
+ Value: value,
+ Target: target,
+ Type: t,
+ })
+}
+
+type androidMkModule struct {
+ assignments map[string]string
+}
+
+type androidMkFile struct {
+ assignments map[string]string
+ modules []androidMkModule
+ includes []string
+}
+
+var directives = [...]string{
+ "define",
+ "else",
+ "endef",
+ "endif",
+ "ifdef",
+ "ifeq",
+ "ifndef",
+ "ifneq",
+ "include",
+ "-include",
+}
+
+var functions = [...]string{
+ "abspath",
+ "addprefix",
+ "addsuffix",
+ "basename",
+ "dir",
+ "notdir",
+ "subst",
+ "suffix",
+ "filter",
+ "filter-out",
+ "findstring",
+ "firstword",
+ "flavor",
+ "join",
+ "lastword",
+ "patsubst",
+ "realpath",
+ "shell",
+ "sort",
+ "strip",
+ "wildcard",
+ "word",
+ "wordlist",
+ "words",
+ "origin",
+ "foreach",
+ "call",
+ "info",
+ "error",
+ "warning",
+ "if",
+ "or",
+ "and",
+ "value",
+ "eval",
+ "file",
+}
+
+func init() {
+ sort.Strings(directives[:])
+ sort.Strings(functions[:])
+}
+
+func isDirective(s string) bool {
+ for _, d := range directives {
+ if s == d {
+ return true
+ } else if s < d {
+ return false
+ }
+ }
+ return false
+}
+
+func isFunctionName(s string) bool {
+ for _, f := range functions {
+ if s == f {
+ return true
+ } else if s < f {
+ return false
+ }
+ }
+ return false
+}
+
+func isWhitespace(ch rune) bool {
+ return ch == ' ' || ch == '\t' || ch == '\n'
+}
+
+func isValidVariableRune(ch rune) bool {
+ return ch != scanner.Ident && ch != ':' && ch != '=' && ch != '#'
+}
+
+var whitespaceRunes = []rune{' ', '\t', '\n'}
+var variableNameEndRunes = append([]rune{':', '=', '#', ')', '}'}, whitespaceRunes...)
+
+func (p *parser) ignoreSpaces() int {
+ skipped := 0
+ for p.tok == ' ' || p.tok == '\t' {
+ p.accept(p.tok)
+ skipped++
+ }
+ return skipped
+}
+
+func (p *parser) ignoreWhitespace() {
+ for isWhitespace(p.tok) {
+ p.accept(p.tok)
+ }
+}
diff --git a/androidmk/parser/scope.go b/androidmk/parser/scope.go
new file mode 100644
index 0000000..5e94ea5
--- /dev/null
+++ b/androidmk/parser/scope.go
@@ -0,0 +1,95 @@
+package parser
+
+import "strings"
+
+type Scope interface {
+ Get(name string) string
+ Set(name, value string)
+ Call(name string, args []string) string
+ SetFunc(name string, f func([]string) string)
+}
+
+type scope struct {
+ variables map[string]string
+ functions map[string]func([]string) string
+ parent Scope
+}
+
+func (s *scope) Get(name string) string {
+ if val, ok := s.variables[name]; ok {
+ return val
+ } else if s.parent != nil {
+ return s.parent.Get(name)
+ } else if val, ok := builtinScope[name]; ok {
+ return val
+ } else {
+ return "<'" + name + "' unset>"
+ }
+}
+
+func (s *scope) Set(name, value string) {
+ s.variables[name] = value
+}
+
+func (s *scope) Call(name string, args []string) string {
+ if f, ok := s.functions[name]; ok {
+ return f(args)
+ }
+
+ return "<func:'" + name + "' unset>"
+}
+
+func (s *scope) SetFunc(name string, f func([]string) string) {
+ s.functions[name] = f
+}
+
+func NewScope(parent Scope) Scope {
+ return &scope{
+ variables: make(map[string]string),
+ functions: make(map[string]func([]string) string),
+ parent: parent,
+ }
+}
+
+var builtinScope map[string]string
+
+func init() {
+ builtinScope := make(map[string]string)
+ builtinScope["__builtin_dollar"] = "$"
+}
+
+func (v Variable) EvalFunction(scope Scope) (string, bool) {
+ f := v.Name.SplitN(" \t", 2)
+ if len(f) > 1 && f[0].Const() {
+ fname := f[0].Value(nil)
+ if isFunctionName(fname) {
+ args := f[1].Split(",")
+ argVals := make([]string, len(args))
+ for i, a := range args {
+ argVals[i] = a.Value(scope)
+ }
+
+ if fname == "call" {
+ return scope.Call(argVals[0], argVals[1:]), true
+ } else {
+ return "__builtin_func:" + fname + " " + strings.Join(argVals, " "), true
+ }
+ }
+ }
+
+ return "", false
+}
+
+func (v Variable) Value(scope Scope) string {
+ if ret, ok := v.EvalFunction(scope); ok {
+ return ret
+ }
+ return scope.Get(v.Name.Value(scope))
+}
+
+func toVariable(ms *MakeString) (Variable, bool) {
+ if len(ms.Variables) == 1 && ms.Strings[0] == "" && ms.Strings[1] == "" {
+ return ms.Variables[0], true
+ }
+ return Variable{}, false
+}
diff --git a/bootstrap.bash b/bootstrap.bash
new file mode 100755
index 0000000..f6056d6
--- /dev/null
+++ b/bootstrap.bash
@@ -0,0 +1,36 @@
+#!/bin/bash
+
+export BOOTSTRAP="${BASH_SOURCE[0]}"
+export SRCDIR=$(dirname "${BASH_SOURCE[0]}")
+export TOPNAME="Android.bp"
+export BOOTSTRAP_MANIFEST="${SRCDIR}/build/soong/build.ninja.in"
+export RUN_TESTS="-t"
+
+case $(uname) in
+ Linux)
+ export GOOS="linux"
+ export PREBUILTOS="linux-x86"
+ ;;
+ Darwin)
+ export GOOS="darwin"
+ export PREBUILTOS="darwin-x86"
+ ;;
+ *) echo "unknown OS:" $(uname) && exit 1;;
+esac
+export GOROOT="${SRCDIR}/prebuilts/go/$PREBUILTOS/"
+export GOARCH="amd64"
+export GOCHAR="6"
+
+if [[ $(find . -maxdepth 1 -name $(basename "${BOOTSTRAP}")) ]]; then
+ echo "FAILED: Tried to run "$(basename "${BOOTSTRAP}")" from "$(pwd)""
+ exit 1
+fi
+
+if [[ $# -eq 0 ]]; then
+ sed -e "s|@@SrcDir@@|${SRCDIR}|" \
+ -e "s|@@PrebuiltOS@@|${PREBUILTOS}|" \
+ "${SRCDIR}/build/soong/soong.bootstrap.in" > .soong.bootstrap
+ ln -sf "${SRCDIR}/build/soong/soong.bash" soong
+fi
+
+"${SRCDIR}/build/blueprint/bootstrap.bash" "$@"
diff --git a/build.ninja.in b/build.ninja.in
new file mode 100644
index 0000000..3bb9559
--- /dev/null
+++ b/build.ninja.in
@@ -0,0 +1,958 @@
+# ******************************************************************************
+# *** This file is generated and should not be edited ***
+# ******************************************************************************
+#
+# This file contains variables, rules, and pools with name prefixes indicating
+# they were generated by the following Go packages:
+#
+# bootstrap [from Go package github.com/google/blueprint/bootstrap]
+#
+ninja_required_version = 1.1.0
+
+g.bootstrap.bootstrapCmd = @@Bootstrap@@
+
+g.bootstrap.bootstrapManifest = @@BootstrapManifest@@
+
+g.bootstrap.goRoot = @@GoRoot@@
+
+g.bootstrap.goOS = @@GoOS@@
+
+g.bootstrap.goArch = @@GoArch@@
+
+g.bootstrap.goToolDir = ${g.bootstrap.goRoot}/pkg/tool/${g.bootstrap.goOS}_${g.bootstrap.goArch}
+
+g.bootstrap.goChar = @@GoChar@@
+
+g.bootstrap.gcCmd = ${g.bootstrap.goToolDir}/${g.bootstrap.goChar}g
+
+g.bootstrap.goTestMainCmd = .bootstrap/bin/gotestmain
+
+g.bootstrap.linkCmd = ${g.bootstrap.goToolDir}/${g.bootstrap.goChar}l
+
+g.bootstrap.srcDir = @@SrcDir@@
+
+builddir = .bootstrap
+
+rule g.bootstrap.bootstrap
+ command = ${g.bootstrap.bootstrapCmd} -i ${in}
+ description = bootstrap ${in}
+ generator = true
+
+rule g.bootstrap.cp
+ command = cp ${in} ${out}
+ description = cp ${out}
+
+rule g.bootstrap.gc
+ command = GOROOT='${g.bootstrap.goRoot}' ${g.bootstrap.gcCmd} -o ${out} -p ${pkgPath} -complete ${incFlags} -pack ${in}
+ description = ${g.bootstrap.goChar}g ${out}
+
+rule g.bootstrap.gotestmain
+ command = ${g.bootstrap.goTestMainCmd} -o ${out} -pkg ${pkg} ${in}
+ description = gotestmain ${out}
+
+rule g.bootstrap.link
+ command = GOROOT='${g.bootstrap.goRoot}' ${g.bootstrap.linkCmd} -o ${out} ${libDirFlags} ${in}
+ description = ${g.bootstrap.goChar}l ${out}
+
+rule g.bootstrap.test
+ command = (cd ${pkgSrcDir} && $$OLDPWD/${in} -test.short) && touch ${out}
+ description = test ${pkg}
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# Module: androidbp
+# Variant:
+# Type: bootstrap_go_binary
+# Factory: github.com/google/blueprint/bootstrap.func·003
+# Defined: build/soong/Android.bp:208:1
+
+build .bootstrap/androidbp/test/androidbp.a: g.bootstrap.gc $
+ ${g.bootstrap.srcDir}/build/soong/androidbp/cmd/androidbp.go $
+ ${g.bootstrap.srcDir}/build/soong/androidbp/cmd/soong.go $
+ ${g.bootstrap.srcDir}/build/soong/androidbp/cmd/module.go $
+ ${g.bootstrap.srcDir}/build/soong/androidbp/cmd/androidbp_test.go | $
+ ${g.bootstrap.gcCmd} $
+ .bootstrap/blueprint-parser/pkg/github.com/google/blueprint/parser.a $
+ .bootstrap/blueprint-pathtools/pkg/github.com/google/blueprint/pathtools.a $
+ .bootstrap/blueprint-proptools/pkg/github.com/google/blueprint/proptools.a $
+ .bootstrap/blueprint/pkg/github.com/google/blueprint.a
+ incFlags = -I .bootstrap/blueprint-parser/pkg -I .bootstrap/blueprint-pathtools/pkg -I .bootstrap/blueprint-proptools/pkg -I .bootstrap/blueprint/pkg
+ pkgPath = androidbp
+default .bootstrap/androidbp/test/androidbp.a
+
+build .bootstrap/androidbp/test/test.go: g.bootstrap.gotestmain $
+ ${g.bootstrap.srcDir}/build/soong/androidbp/cmd/androidbp_test.go | $
+ ${g.bootstrap.goTestMainCmd}
+ pkg = androidbp
+default .bootstrap/androidbp/test/test.go
+
+build .bootstrap/androidbp/test/test.a: g.bootstrap.gc $
+ .bootstrap/androidbp/test/test.go | $
+ .bootstrap/androidbp/test/androidbp.a
+ incFlags = -I .bootstrap/androidbp/test
+ pkgPath = main
+default .bootstrap/androidbp/test/test.a
+
+build .bootstrap/androidbp/test/test: g.bootstrap.link $
+ .bootstrap/androidbp/test/test.a | ${g.bootstrap.linkCmd}
+ libDirFlags = -L .bootstrap/androidbp/test -L .bootstrap/blueprint-parser/pkg -L .bootstrap/blueprint-pathtools/pkg -L .bootstrap/blueprint-proptools/pkg -L .bootstrap/blueprint/pkg
+default .bootstrap/androidbp/test/test
+
+build .bootstrap/androidbp/test/test.passed: g.bootstrap.test $
+ .bootstrap/androidbp/test/test
+ pkg = androidbp
+ pkgSrcDir = ${g.bootstrap.srcDir}/build/soong/androidbp/cmd
+default .bootstrap/androidbp/test/test.passed
+
+build .bootstrap/androidbp/obj/androidbp.a: g.bootstrap.gc $
+ ${g.bootstrap.srcDir}/build/soong/androidbp/cmd/androidbp.go $
+ ${g.bootstrap.srcDir}/build/soong/androidbp/cmd/soong.go $
+ ${g.bootstrap.srcDir}/build/soong/androidbp/cmd/module.go | $
+ ${g.bootstrap.gcCmd} $
+ .bootstrap/blueprint-parser/pkg/github.com/google/blueprint/parser.a $
+ .bootstrap/blueprint-pathtools/pkg/github.com/google/blueprint/pathtools.a $
+ .bootstrap/blueprint-proptools/pkg/github.com/google/blueprint/proptools.a $
+ .bootstrap/blueprint/pkg/github.com/google/blueprint.a || $
+ .bootstrap/androidbp/test/test.passed
+ incFlags = -I .bootstrap/blueprint-parser/pkg -I .bootstrap/blueprint-pathtools/pkg -I .bootstrap/blueprint-proptools/pkg -I .bootstrap/blueprint/pkg
+ pkgPath = androidbp
+default .bootstrap/androidbp/obj/androidbp.a
+
+build .bootstrap/androidbp/obj/a.out: g.bootstrap.link $
+ .bootstrap/androidbp/obj/androidbp.a | ${g.bootstrap.linkCmd}
+ libDirFlags = -L .bootstrap/blueprint-parser/pkg -L .bootstrap/blueprint-pathtools/pkg -L .bootstrap/blueprint-proptools/pkg -L .bootstrap/blueprint/pkg
+default .bootstrap/androidbp/obj/a.out
+
+build .bootstrap/bin/androidbp: g.bootstrap.cp .bootstrap/androidbp/obj/a.out
+default .bootstrap/bin/androidbp
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# Module: androidmk
+# Variant:
+# Type: bootstrap_go_binary
+# Factory: github.com/google/blueprint/bootstrap.func·003
+# Defined: build/soong/Android.bp:181:1
+
+build .bootstrap/androidmk/obj/androidmk.a: g.bootstrap.gc $
+ ${g.bootstrap.srcDir}/build/soong/androidmk/cmd/androidmk/android.go $
+ ${g.bootstrap.srcDir}/build/soong/androidmk/cmd/androidmk/androidmk.go $
+ ${g.bootstrap.srcDir}/build/soong/androidmk/cmd/androidmk/values.go | $
+ ${g.bootstrap.gcCmd} $
+ .bootstrap/androidmk-parser/pkg/android/soong/androidmk/parser.a $
+ .bootstrap/blueprint-parser/pkg/github.com/google/blueprint/parser.a
+ incFlags = -I .bootstrap/androidmk-parser/pkg -I .bootstrap/blueprint-parser/pkg
+ pkgPath = androidmk
+default .bootstrap/androidmk/obj/androidmk.a
+
+build .bootstrap/androidmk/obj/a.out: g.bootstrap.link $
+ .bootstrap/androidmk/obj/androidmk.a | ${g.bootstrap.linkCmd}
+ libDirFlags = -L .bootstrap/androidmk-parser/pkg -L .bootstrap/blueprint-parser/pkg
+default .bootstrap/androidmk/obj/a.out
+
+build .bootstrap/bin/androidmk: g.bootstrap.cp .bootstrap/androidmk/obj/a.out
+default .bootstrap/bin/androidmk
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# Module: androidmk-parser
+# Variant:
+# Type: bootstrap_go_package
+# Factory: github.com/google/blueprint/bootstrap.func·002
+# Defined: build/soong/Android.bp:194:1
+
+build .bootstrap/androidmk-parser/test/android/soong/androidmk/parser.a: $
+ g.bootstrap.gc $
+ ${g.bootstrap.srcDir}/build/soong/androidmk/parser/make_strings.go $
+ ${g.bootstrap.srcDir}/build/soong/androidmk/parser/makething.go $
+ ${g.bootstrap.srcDir}/build/soong/androidmk/parser/parser.go $
+ ${g.bootstrap.srcDir}/build/soong/androidmk/parser/scope.go $
+ ${g.bootstrap.srcDir}/build/soong/androidmk/parser/make_strings_test.go $
+ | ${g.bootstrap.gcCmd}
+ pkgPath = android/soong/androidmk/parser
+default .bootstrap/androidmk-parser/test/android/soong/androidmk/parser.a
+
+build .bootstrap/androidmk-parser/test/test.go: g.bootstrap.gotestmain $
+ ${g.bootstrap.srcDir}/build/soong/androidmk/parser/make_strings_test.go $
+ | ${g.bootstrap.goTestMainCmd}
+ pkg = android/soong/androidmk/parser
+default .bootstrap/androidmk-parser/test/test.go
+
+build .bootstrap/androidmk-parser/test/test.a: g.bootstrap.gc $
+ .bootstrap/androidmk-parser/test/test.go | $
+ .bootstrap/androidmk-parser/test/android/soong/androidmk/parser.a
+ incFlags = -I .bootstrap/androidmk-parser/test
+ pkgPath = main
+default .bootstrap/androidmk-parser/test/test.a
+
+build .bootstrap/androidmk-parser/test/test: g.bootstrap.link $
+ .bootstrap/androidmk-parser/test/test.a | ${g.bootstrap.linkCmd}
+ libDirFlags = -L .bootstrap/androidmk-parser/test
+default .bootstrap/androidmk-parser/test/test
+
+build .bootstrap/androidmk-parser/test/test.passed: g.bootstrap.test $
+ .bootstrap/androidmk-parser/test/test
+ pkg = android/soong/androidmk/parser
+ pkgSrcDir = ${g.bootstrap.srcDir}/build/soong/androidmk/parser
+default .bootstrap/androidmk-parser/test/test.passed
+
+build .bootstrap/androidmk-parser/pkg/android/soong/androidmk/parser.a: $
+ g.bootstrap.gc $
+ ${g.bootstrap.srcDir}/build/soong/androidmk/parser/make_strings.go $
+ ${g.bootstrap.srcDir}/build/soong/androidmk/parser/makething.go $
+ ${g.bootstrap.srcDir}/build/soong/androidmk/parser/parser.go $
+ ${g.bootstrap.srcDir}/build/soong/androidmk/parser/scope.go | $
+ ${g.bootstrap.gcCmd} || .bootstrap/androidmk-parser/test/test.passed
+ pkgPath = android/soong/androidmk/parser
+default .bootstrap/androidmk-parser/pkg/android/soong/androidmk/parser.a
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# Module: blueprint
+# Variant:
+# Type: bootstrap_go_package
+# Factory: github.com/google/blueprint/bootstrap.func·002
+# Defined: build/blueprint/Blueprints:1:1
+
+build .bootstrap/blueprint/test/github.com/google/blueprint.a: g.bootstrap.gc $
+ ${g.bootstrap.srcDir}/build/blueprint/context.go $
+ ${g.bootstrap.srcDir}/build/blueprint/live_tracker.go $
+ ${g.bootstrap.srcDir}/build/blueprint/mangle.go $
+ ${g.bootstrap.srcDir}/build/blueprint/module_ctx.go $
+ ${g.bootstrap.srcDir}/build/blueprint/ninja_defs.go $
+ ${g.bootstrap.srcDir}/build/blueprint/ninja_strings.go $
+ ${g.bootstrap.srcDir}/build/blueprint/ninja_writer.go $
+ ${g.bootstrap.srcDir}/build/blueprint/package_ctx.go $
+ ${g.bootstrap.srcDir}/build/blueprint/scope.go $
+ ${g.bootstrap.srcDir}/build/blueprint/singleton_ctx.go $
+ ${g.bootstrap.srcDir}/build/blueprint/unpack.go $
+ ${g.bootstrap.srcDir}/build/blueprint/context_test.go $
+ ${g.bootstrap.srcDir}/build/blueprint/ninja_strings_test.go $
+ ${g.bootstrap.srcDir}/build/blueprint/ninja_writer_test.go $
+ ${g.bootstrap.srcDir}/build/blueprint/splice_modules_test.go $
+ ${g.bootstrap.srcDir}/build/blueprint/unpack_test.go | $
+ ${g.bootstrap.gcCmd} $
+ .bootstrap/blueprint-parser/pkg/github.com/google/blueprint/parser.a $
+ .bootstrap/blueprint-pathtools/pkg/github.com/google/blueprint/pathtools.a $
+ .bootstrap/blueprint-proptools/pkg/github.com/google/blueprint/proptools.a
+ incFlags = -I .bootstrap/blueprint-parser/pkg -I .bootstrap/blueprint-pathtools/pkg -I .bootstrap/blueprint-proptools/pkg
+ pkgPath = github.com/google/blueprint
+default .bootstrap/blueprint/test/github.com/google/blueprint.a
+
+build .bootstrap/blueprint/test/test.go: g.bootstrap.gotestmain $
+ ${g.bootstrap.srcDir}/build/blueprint/context_test.go $
+ ${g.bootstrap.srcDir}/build/blueprint/ninja_strings_test.go $
+ ${g.bootstrap.srcDir}/build/blueprint/ninja_writer_test.go $
+ ${g.bootstrap.srcDir}/build/blueprint/splice_modules_test.go $
+ ${g.bootstrap.srcDir}/build/blueprint/unpack_test.go | $
+ ${g.bootstrap.goTestMainCmd}
+ pkg = github.com/google/blueprint
+default .bootstrap/blueprint/test/test.go
+
+build .bootstrap/blueprint/test/test.a: g.bootstrap.gc $
+ .bootstrap/blueprint/test/test.go | $
+ .bootstrap/blueprint/test/github.com/google/blueprint.a
+ incFlags = -I .bootstrap/blueprint/test
+ pkgPath = main
+default .bootstrap/blueprint/test/test.a
+
+build .bootstrap/blueprint/test/test: g.bootstrap.link $
+ .bootstrap/blueprint/test/test.a | ${g.bootstrap.linkCmd}
+ libDirFlags = -L .bootstrap/blueprint/test -L .bootstrap/blueprint-parser/pkg -L .bootstrap/blueprint-pathtools/pkg -L .bootstrap/blueprint-proptools/pkg
+default .bootstrap/blueprint/test/test
+
+build .bootstrap/blueprint/test/test.passed: g.bootstrap.test $
+ .bootstrap/blueprint/test/test
+ pkg = github.com/google/blueprint
+ pkgSrcDir = ${g.bootstrap.srcDir}/build/blueprint
+default .bootstrap/blueprint/test/test.passed
+
+build .bootstrap/blueprint/pkg/github.com/google/blueprint.a: g.bootstrap.gc $
+ ${g.bootstrap.srcDir}/build/blueprint/context.go $
+ ${g.bootstrap.srcDir}/build/blueprint/live_tracker.go $
+ ${g.bootstrap.srcDir}/build/blueprint/mangle.go $
+ ${g.bootstrap.srcDir}/build/blueprint/module_ctx.go $
+ ${g.bootstrap.srcDir}/build/blueprint/ninja_defs.go $
+ ${g.bootstrap.srcDir}/build/blueprint/ninja_strings.go $
+ ${g.bootstrap.srcDir}/build/blueprint/ninja_writer.go $
+ ${g.bootstrap.srcDir}/build/blueprint/package_ctx.go $
+ ${g.bootstrap.srcDir}/build/blueprint/scope.go $
+ ${g.bootstrap.srcDir}/build/blueprint/singleton_ctx.go $
+ ${g.bootstrap.srcDir}/build/blueprint/unpack.go | ${g.bootstrap.gcCmd} $
+ .bootstrap/blueprint-parser/pkg/github.com/google/blueprint/parser.a $
+ .bootstrap/blueprint-pathtools/pkg/github.com/google/blueprint/pathtools.a $
+ .bootstrap/blueprint-proptools/pkg/github.com/google/blueprint/proptools.a $
+ || .bootstrap/blueprint/test/test.passed
+ incFlags = -I .bootstrap/blueprint-parser/pkg -I .bootstrap/blueprint-pathtools/pkg -I .bootstrap/blueprint-proptools/pkg
+ pkgPath = github.com/google/blueprint
+default .bootstrap/blueprint/pkg/github.com/google/blueprint.a
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# Module: blueprint-bootstrap
+# Variant:
+# Type: bootstrap_go_package
+# Factory: github.com/google/blueprint/bootstrap.func·002
+# Defined: build/blueprint/Blueprints:70:1
+
+build $
+ .bootstrap/blueprint-bootstrap/pkg/github.com/google/blueprint/bootstrap.a $
+ : g.bootstrap.gc $
+ ${g.bootstrap.srcDir}/build/blueprint/bootstrap/bootstrap.go $
+ ${g.bootstrap.srcDir}/build/blueprint/bootstrap/cleanup.go $
+ ${g.bootstrap.srcDir}/build/blueprint/bootstrap/command.go $
+ ${g.bootstrap.srcDir}/build/blueprint/bootstrap/config.go $
+ ${g.bootstrap.srcDir}/build/blueprint/bootstrap/doc.go $
+ ${g.bootstrap.srcDir}/build/blueprint/bootstrap/writedocs.go | $
+ ${g.bootstrap.gcCmd} $
+ .bootstrap/blueprint-parser/pkg/github.com/google/blueprint/parser.a $
+ .bootstrap/blueprint-pathtools/pkg/github.com/google/blueprint/pathtools.a $
+ .bootstrap/blueprint-proptools/pkg/github.com/google/blueprint/proptools.a $
+ .bootstrap/blueprint/pkg/github.com/google/blueprint.a $
+ .bootstrap/blueprint-deptools/pkg/github.com/google/blueprint/deptools.a $
+ .bootstrap/blueprint-bootstrap-bpdoc/pkg/github.com/google/blueprint/bootstrap/bpdoc.a
+ incFlags = -I .bootstrap/blueprint-parser/pkg -I .bootstrap/blueprint-pathtools/pkg -I .bootstrap/blueprint-proptools/pkg -I .bootstrap/blueprint/pkg -I .bootstrap/blueprint-deptools/pkg -I .bootstrap/blueprint-bootstrap-bpdoc/pkg
+ pkgPath = github.com/google/blueprint/bootstrap
+default $
+ .bootstrap/blueprint-bootstrap/pkg/github.com/google/blueprint/bootstrap.a
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# Module: blueprint-bootstrap-bpdoc
+# Variant:
+# Type: bootstrap_go_package
+# Factory: github.com/google/blueprint/bootstrap.func·002
+# Defined: build/blueprint/Blueprints:89:1
+
+build $
+ .bootstrap/blueprint-bootstrap-bpdoc/pkg/github.com/google/blueprint/bootstrap/bpdoc.a $
+ : g.bootstrap.gc $
+ ${g.bootstrap.srcDir}/build/blueprint/bootstrap/bpdoc/bpdoc.go | $
+ ${g.bootstrap.gcCmd} $
+ .bootstrap/blueprint-parser/pkg/github.com/google/blueprint/parser.a $
+ .bootstrap/blueprint-pathtools/pkg/github.com/google/blueprint/pathtools.a $
+ .bootstrap/blueprint-proptools/pkg/github.com/google/blueprint/proptools.a $
+ .bootstrap/blueprint/pkg/github.com/google/blueprint.a
+ incFlags = -I .bootstrap/blueprint-parser/pkg -I .bootstrap/blueprint-pathtools/pkg -I .bootstrap/blueprint-proptools/pkg -I .bootstrap/blueprint/pkg
+ pkgPath = github.com/google/blueprint/bootstrap/bpdoc
+default $
+ .bootstrap/blueprint-bootstrap-bpdoc/pkg/github.com/google/blueprint/bootstrap/bpdoc.a
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# Module: blueprint-deptools
+# Variant:
+# Type: bootstrap_go_package
+# Factory: github.com/google/blueprint/bootstrap.func·002
+# Defined: build/blueprint/Blueprints:46:1
+
+build .bootstrap/blueprint-deptools/pkg/github.com/google/blueprint/deptools.a $
+ : g.bootstrap.gc $
+ ${g.bootstrap.srcDir}/build/blueprint/deptools/depfile.go | $
+ ${g.bootstrap.gcCmd}
+ pkgPath = github.com/google/blueprint/deptools
+default $
+ .bootstrap/blueprint-deptools/pkg/github.com/google/blueprint/deptools.a
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# Module: blueprint-parser
+# Variant:
+# Type: bootstrap_go_package
+# Factory: github.com/google/blueprint/bootstrap.func·002
+# Defined: build/blueprint/Blueprints:31:1
+
+build .bootstrap/blueprint-parser/test/github.com/google/blueprint/parser.a: $
+ g.bootstrap.gc ${g.bootstrap.srcDir}/build/blueprint/parser/modify.go $
+ ${g.bootstrap.srcDir}/build/blueprint/parser/parser.go $
+ ${g.bootstrap.srcDir}/build/blueprint/parser/printer.go $
+ ${g.bootstrap.srcDir}/build/blueprint/parser/sort.go $
+ ${g.bootstrap.srcDir}/build/blueprint/parser/parser_test.go $
+ ${g.bootstrap.srcDir}/build/blueprint/parser/printer_test.go | $
+ ${g.bootstrap.gcCmd}
+ pkgPath = github.com/google/blueprint/parser
+default .bootstrap/blueprint-parser/test/github.com/google/blueprint/parser.a
+
+build .bootstrap/blueprint-parser/test/test.go: g.bootstrap.gotestmain $
+ ${g.bootstrap.srcDir}/build/blueprint/parser/parser_test.go $
+ ${g.bootstrap.srcDir}/build/blueprint/parser/printer_test.go | $
+ ${g.bootstrap.goTestMainCmd}
+ pkg = github.com/google/blueprint/parser
+default .bootstrap/blueprint-parser/test/test.go
+
+build .bootstrap/blueprint-parser/test/test.a: g.bootstrap.gc $
+ .bootstrap/blueprint-parser/test/test.go | $
+ .bootstrap/blueprint-parser/test/github.com/google/blueprint/parser.a
+ incFlags = -I .bootstrap/blueprint-parser/test
+ pkgPath = main
+default .bootstrap/blueprint-parser/test/test.a
+
+build .bootstrap/blueprint-parser/test/test: g.bootstrap.link $
+ .bootstrap/blueprint-parser/test/test.a | ${g.bootstrap.linkCmd}
+ libDirFlags = -L .bootstrap/blueprint-parser/test
+default .bootstrap/blueprint-parser/test/test
+
+build .bootstrap/blueprint-parser/test/test.passed: g.bootstrap.test $
+ .bootstrap/blueprint-parser/test/test
+ pkg = github.com/google/blueprint/parser
+ pkgSrcDir = ${g.bootstrap.srcDir}/build/blueprint/parser
+default .bootstrap/blueprint-parser/test/test.passed
+
+build .bootstrap/blueprint-parser/pkg/github.com/google/blueprint/parser.a: $
+ g.bootstrap.gc ${g.bootstrap.srcDir}/build/blueprint/parser/modify.go $
+ ${g.bootstrap.srcDir}/build/blueprint/parser/parser.go $
+ ${g.bootstrap.srcDir}/build/blueprint/parser/printer.go $
+ ${g.bootstrap.srcDir}/build/blueprint/parser/sort.go | $
+ ${g.bootstrap.gcCmd} || .bootstrap/blueprint-parser/test/test.passed
+ pkgPath = github.com/google/blueprint/parser
+default .bootstrap/blueprint-parser/pkg/github.com/google/blueprint/parser.a
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# Module: blueprint-pathtools
+# Variant:
+# Type: bootstrap_go_package
+# Factory: github.com/google/blueprint/bootstrap.func·002
+# Defined: build/blueprint/Blueprints:52:1
+
+build $
+ .bootstrap/blueprint-pathtools/test/github.com/google/blueprint/pathtools.a $
+ : g.bootstrap.gc $
+ ${g.bootstrap.srcDir}/build/blueprint/pathtools/lists.go $
+ ${g.bootstrap.srcDir}/build/blueprint/pathtools/glob.go $
+ ${g.bootstrap.srcDir}/build/blueprint/pathtools/glob_test.go | $
+ ${g.bootstrap.gcCmd}
+ pkgPath = github.com/google/blueprint/pathtools
+default $
+ .bootstrap/blueprint-pathtools/test/github.com/google/blueprint/pathtools.a
+
+build .bootstrap/blueprint-pathtools/test/test.go: g.bootstrap.gotestmain $
+ ${g.bootstrap.srcDir}/build/blueprint/pathtools/glob_test.go | $
+ ${g.bootstrap.goTestMainCmd}
+ pkg = github.com/google/blueprint/pathtools
+default .bootstrap/blueprint-pathtools/test/test.go
+
+build .bootstrap/blueprint-pathtools/test/test.a: g.bootstrap.gc $
+ .bootstrap/blueprint-pathtools/test/test.go | $
+ .bootstrap/blueprint-pathtools/test/github.com/google/blueprint/pathtools.a
+ incFlags = -I .bootstrap/blueprint-pathtools/test
+ pkgPath = main
+default .bootstrap/blueprint-pathtools/test/test.a
+
+build .bootstrap/blueprint-pathtools/test/test: g.bootstrap.link $
+ .bootstrap/blueprint-pathtools/test/test.a | ${g.bootstrap.linkCmd}
+ libDirFlags = -L .bootstrap/blueprint-pathtools/test
+default .bootstrap/blueprint-pathtools/test/test
+
+build .bootstrap/blueprint-pathtools/test/test.passed: g.bootstrap.test $
+ .bootstrap/blueprint-pathtools/test/test
+ pkg = github.com/google/blueprint/pathtools
+ pkgSrcDir = ${g.bootstrap.srcDir}/build/blueprint/pathtools
+default .bootstrap/blueprint-pathtools/test/test.passed
+
+build $
+ .bootstrap/blueprint-pathtools/pkg/github.com/google/blueprint/pathtools.a $
+ : g.bootstrap.gc $
+ ${g.bootstrap.srcDir}/build/blueprint/pathtools/lists.go $
+ ${g.bootstrap.srcDir}/build/blueprint/pathtools/glob.go | $
+ ${g.bootstrap.gcCmd} || $
+ .bootstrap/blueprint-pathtools/test/test.passed
+ pkgPath = github.com/google/blueprint/pathtools
+default $
+ .bootstrap/blueprint-pathtools/pkg/github.com/google/blueprint/pathtools.a
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# Module: blueprint-proptools
+# Variant:
+# Type: bootstrap_go_package
+# Factory: github.com/google/blueprint/bootstrap.func·002
+# Defined: build/blueprint/Blueprints:64:1
+
+build $
+ .bootstrap/blueprint-proptools/pkg/github.com/google/blueprint/proptools.a $
+ : g.bootstrap.gc $
+ ${g.bootstrap.srcDir}/build/blueprint/proptools/proptools.go | $
+ ${g.bootstrap.gcCmd}
+ pkgPath = github.com/google/blueprint/proptools
+default $
+ .bootstrap/blueprint-proptools/pkg/github.com/google/blueprint/proptools.a
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# Module: bpfmt
+# Variant:
+# Type: bootstrap_go_binary
+# Factory: github.com/google/blueprint/bootstrap.func·003
+# Defined: build/blueprint/Blueprints:110:1
+
+build .bootstrap/bpfmt/obj/bpfmt.a: g.bootstrap.gc $
+ ${g.bootstrap.srcDir}/build/blueprint/bpfmt/bpfmt.go | $
+ ${g.bootstrap.gcCmd} $
+ .bootstrap/blueprint-parser/pkg/github.com/google/blueprint/parser.a
+ incFlags = -I .bootstrap/blueprint-parser/pkg
+ pkgPath = bpfmt
+default .bootstrap/bpfmt/obj/bpfmt.a
+
+build .bootstrap/bpfmt/obj/a.out: g.bootstrap.link $
+ .bootstrap/bpfmt/obj/bpfmt.a | ${g.bootstrap.linkCmd}
+ libDirFlags = -L .bootstrap/blueprint-parser/pkg
+default .bootstrap/bpfmt/obj/a.out
+
+build .bootstrap/bin/bpfmt: g.bootstrap.cp .bootstrap/bpfmt/obj/a.out
+default .bootstrap/bin/bpfmt
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# Module: bpmodify
+# Variant:
+# Type: bootstrap_go_binary
+# Factory: github.com/google/blueprint/bootstrap.func·003
+# Defined: build/blueprint/Blueprints:116:1
+
+build .bootstrap/bpmodify/obj/bpmodify.a: g.bootstrap.gc $
+ ${g.bootstrap.srcDir}/build/blueprint/bpmodify/bpmodify.go | $
+ ${g.bootstrap.gcCmd} $
+ .bootstrap/blueprint-parser/pkg/github.com/google/blueprint/parser.a
+ incFlags = -I .bootstrap/blueprint-parser/pkg
+ pkgPath = bpmodify
+default .bootstrap/bpmodify/obj/bpmodify.a
+
+build .bootstrap/bpmodify/obj/a.out: g.bootstrap.link $
+ .bootstrap/bpmodify/obj/bpmodify.a | ${g.bootstrap.linkCmd}
+ libDirFlags = -L .bootstrap/blueprint-parser/pkg
+default .bootstrap/bpmodify/obj/a.out
+
+build .bootstrap/bin/bpmodify: g.bootstrap.cp .bootstrap/bpmodify/obj/a.out
+default .bootstrap/bin/bpmodify
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# Module: gotestmain
+# Variant:
+# Type: bootstrap_go_binary
+# Factory: github.com/google/blueprint/bootstrap.func·003
+# Defined: build/blueprint/Blueprints:122:1
+
+build .bootstrap/gotestmain/obj/gotestmain.a: g.bootstrap.gc $
+ ${g.bootstrap.srcDir}/build/blueprint/gotestmain/gotestmain.go | $
+ ${g.bootstrap.gcCmd}
+ pkgPath = gotestmain
+default .bootstrap/gotestmain/obj/gotestmain.a
+
+build .bootstrap/gotestmain/obj/a.out: g.bootstrap.link $
+ .bootstrap/gotestmain/obj/gotestmain.a | ${g.bootstrap.linkCmd}
+default .bootstrap/gotestmain/obj/a.out
+build .bootstrap/bin/gotestmain: g.bootstrap.cp $
+ .bootstrap/gotestmain/obj/a.out
+default .bootstrap/bin/gotestmain
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# Module: minibp
+# Variant:
+# Type: bootstrap_go_binary
+# Factory: github.com/google/blueprint/bootstrap.func·003
+# Defined: build/blueprint/Blueprints:101:1
+
+build .bootstrap/minibp/obj/minibp.a: g.bootstrap.gc $
+ ${g.bootstrap.srcDir}/build/blueprint/bootstrap/minibp/main.go | $
+ ${g.bootstrap.gcCmd} $
+ .bootstrap/blueprint-parser/pkg/github.com/google/blueprint/parser.a $
+ .bootstrap/blueprint-pathtools/pkg/github.com/google/blueprint/pathtools.a $
+ .bootstrap/blueprint-proptools/pkg/github.com/google/blueprint/proptools.a $
+ .bootstrap/blueprint/pkg/github.com/google/blueprint.a $
+ .bootstrap/blueprint-deptools/pkg/github.com/google/blueprint/deptools.a $
+ .bootstrap/blueprint-bootstrap-bpdoc/pkg/github.com/google/blueprint/bootstrap/bpdoc.a $
+ .bootstrap/blueprint-bootstrap/pkg/github.com/google/blueprint/bootstrap.a
+ incFlags = -I .bootstrap/blueprint-parser/pkg -I .bootstrap/blueprint-pathtools/pkg -I .bootstrap/blueprint-proptools/pkg -I .bootstrap/blueprint/pkg -I .bootstrap/blueprint-deptools/pkg -I .bootstrap/blueprint-bootstrap-bpdoc/pkg -I .bootstrap/blueprint-bootstrap/pkg
+ pkgPath = minibp
+default .bootstrap/minibp/obj/minibp.a
+
+build .bootstrap/minibp/obj/a.out: g.bootstrap.link $
+ .bootstrap/minibp/obj/minibp.a | ${g.bootstrap.linkCmd}
+ libDirFlags = -L .bootstrap/blueprint-parser/pkg -L .bootstrap/blueprint-pathtools/pkg -L .bootstrap/blueprint-proptools/pkg -L .bootstrap/blueprint/pkg -L .bootstrap/blueprint-deptools/pkg -L .bootstrap/blueprint-bootstrap-bpdoc/pkg -L .bootstrap/blueprint-bootstrap/pkg
+default .bootstrap/minibp/obj/a.out
+
+build .bootstrap/bin/minibp: g.bootstrap.cp .bootstrap/minibp/obj/a.out
+default .bootstrap/bin/minibp
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# Module: soong
+# Variant:
+# Type: bootstrap_go_package
+# Factory: github.com/google/blueprint/bootstrap.func·002
+# Defined: build/soong/Android.bp:73:1
+
+build .bootstrap/soong/pkg/android/soong.a: g.bootstrap.gc $
+ ${g.bootstrap.srcDir}/build/soong/doc.go $
+ ${g.bootstrap.srcDir}/build/soong/register.go | ${g.bootstrap.gcCmd} $
+ .bootstrap/blueprint-parser/pkg/github.com/google/blueprint/parser.a $
+ .bootstrap/blueprint-pathtools/pkg/github.com/google/blueprint/pathtools.a $
+ .bootstrap/blueprint-proptools/pkg/github.com/google/blueprint/proptools.a $
+ .bootstrap/blueprint/pkg/github.com/google/blueprint.a
+ incFlags = -I .bootstrap/blueprint-parser/pkg -I .bootstrap/blueprint-pathtools/pkg -I .bootstrap/blueprint-proptools/pkg -I .bootstrap/blueprint/pkg
+ pkgPath = android/soong
+default .bootstrap/soong/pkg/android/soong.a
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# Module: soong-art
+# Variant:
+# Type: bootstrap_go_package
+# Factory: github.com/google/blueprint/bootstrap.func·002
+# Defined: art/build/Android.bp:13:1
+
+build .bootstrap/soong-art/pkg/android/soong/art.a: g.bootstrap.gc $
+ ${g.bootstrap.srcDir}/art/build/art.go | ${g.bootstrap.gcCmd} $
+ .bootstrap/blueprint-parser/pkg/github.com/google/blueprint/parser.a $
+ .bootstrap/blueprint-pathtools/pkg/github.com/google/blueprint/pathtools.a $
+ .bootstrap/blueprint-proptools/pkg/github.com/google/blueprint/proptools.a $
+ .bootstrap/blueprint/pkg/github.com/google/blueprint.a $
+ .bootstrap/soong/pkg/android/soong.a $
+ .bootstrap/blueprint-deptools/pkg/github.com/google/blueprint/deptools.a $
+ .bootstrap/blueprint-bootstrap-bpdoc/pkg/github.com/google/blueprint/bootstrap/bpdoc.a $
+ .bootstrap/blueprint-bootstrap/pkg/github.com/google/blueprint/bootstrap.a $
+ .bootstrap/soong-env/pkg/android/soong/env.a $
+ .bootstrap/soong-glob/pkg/android/soong/glob.a $
+ .bootstrap/soong-common/pkg/android/soong/common.a $
+ .bootstrap/soong-genrule/pkg/android/soong/genrule.a $
+ .bootstrap/soong-cc/pkg/android/soong/cc.a
+ incFlags = -I .bootstrap/blueprint-parser/pkg -I .bootstrap/blueprint-pathtools/pkg -I .bootstrap/blueprint-proptools/pkg -I .bootstrap/blueprint/pkg -I .bootstrap/soong/pkg -I .bootstrap/blueprint-deptools/pkg -I .bootstrap/blueprint-bootstrap-bpdoc/pkg -I .bootstrap/blueprint-bootstrap/pkg -I .bootstrap/soong-env/pkg -I .bootstrap/soong-glob/pkg -I .bootstrap/soong-common/pkg -I .bootstrap/soong-genrule/pkg -I .bootstrap/soong-cc/pkg
+ pkgPath = android/soong/art
+default .bootstrap/soong-art/pkg/android/soong/art.a
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# Module: soong-cc
+# Variant:
+# Type: bootstrap_go_package
+# Factory: github.com/google/blueprint/bootstrap.func·002
+# Defined: build/soong/Android.bp:107:1
+
+build .bootstrap/soong-cc/test/android/soong/cc.a: g.bootstrap.gc $
+ ${g.bootstrap.srcDir}/build/soong/cc/builder.go $
+ ${g.bootstrap.srcDir}/build/soong/cc/cc.go $
+ ${g.bootstrap.srcDir}/build/soong/cc/clang.go $
+ ${g.bootstrap.srcDir}/build/soong/cc/gen.go $
+ ${g.bootstrap.srcDir}/build/soong/cc/toolchain.go $
+ ${g.bootstrap.srcDir}/build/soong/cc/util.go $
+ ${g.bootstrap.srcDir}/build/soong/cc/arm_device.go $
+ ${g.bootstrap.srcDir}/build/soong/cc/arm64_device.go $
+ ${g.bootstrap.srcDir}/build/soong/cc/x86_darwin_host.go $
+ ${g.bootstrap.srcDir}/build/soong/cc/x86_linux_host.go $
+ ${g.bootstrap.srcDir}/build/soong/cc/cc_test.go | ${g.bootstrap.gcCmd} $
+ .bootstrap/blueprint-parser/pkg/github.com/google/blueprint/parser.a $
+ .bootstrap/blueprint-pathtools/pkg/github.com/google/blueprint/pathtools.a $
+ .bootstrap/blueprint-proptools/pkg/github.com/google/blueprint/proptools.a $
+ .bootstrap/blueprint/pkg/github.com/google/blueprint.a $
+ .bootstrap/soong/pkg/android/soong.a $
+ .bootstrap/blueprint-deptools/pkg/github.com/google/blueprint/deptools.a $
+ .bootstrap/blueprint-bootstrap-bpdoc/pkg/github.com/google/blueprint/bootstrap/bpdoc.a $
+ .bootstrap/blueprint-bootstrap/pkg/github.com/google/blueprint/bootstrap.a $
+ .bootstrap/soong-env/pkg/android/soong/env.a $
+ .bootstrap/soong-glob/pkg/android/soong/glob.a $
+ .bootstrap/soong-common/pkg/android/soong/common.a $
+ .bootstrap/soong-genrule/pkg/android/soong/genrule.a
+ incFlags = -I .bootstrap/blueprint-parser/pkg -I .bootstrap/blueprint-pathtools/pkg -I .bootstrap/blueprint-proptools/pkg -I .bootstrap/blueprint/pkg -I .bootstrap/soong/pkg -I .bootstrap/blueprint-deptools/pkg -I .bootstrap/blueprint-bootstrap-bpdoc/pkg -I .bootstrap/blueprint-bootstrap/pkg -I .bootstrap/soong-env/pkg -I .bootstrap/soong-glob/pkg -I .bootstrap/soong-common/pkg -I .bootstrap/soong-genrule/pkg
+ pkgPath = android/soong/cc
+default .bootstrap/soong-cc/test/android/soong/cc.a
+
+build .bootstrap/soong-cc/test/test.go: g.bootstrap.gotestmain $
+ ${g.bootstrap.srcDir}/build/soong/cc/cc_test.go | $
+ ${g.bootstrap.goTestMainCmd}
+ pkg = android/soong/cc
+default .bootstrap/soong-cc/test/test.go
+
+build .bootstrap/soong-cc/test/test.a: g.bootstrap.gc $
+ .bootstrap/soong-cc/test/test.go | $
+ .bootstrap/soong-cc/test/android/soong/cc.a
+ incFlags = -I .bootstrap/soong-cc/test
+ pkgPath = main
+default .bootstrap/soong-cc/test/test.a
+
+build .bootstrap/soong-cc/test/test: g.bootstrap.link $
+ .bootstrap/soong-cc/test/test.a | ${g.bootstrap.linkCmd}
+ libDirFlags = -L .bootstrap/soong-cc/test -L .bootstrap/blueprint-parser/pkg -L .bootstrap/blueprint-pathtools/pkg -L .bootstrap/blueprint-proptools/pkg -L .bootstrap/blueprint/pkg -L .bootstrap/soong/pkg -L .bootstrap/blueprint-deptools/pkg -L .bootstrap/blueprint-bootstrap-bpdoc/pkg -L .bootstrap/blueprint-bootstrap/pkg -L .bootstrap/soong-env/pkg -L .bootstrap/soong-glob/pkg -L .bootstrap/soong-common/pkg -L .bootstrap/soong-genrule/pkg
+default .bootstrap/soong-cc/test/test
+
+build .bootstrap/soong-cc/test/test.passed: g.bootstrap.test $
+ .bootstrap/soong-cc/test/test
+ pkg = android/soong/cc
+ pkgSrcDir = ${g.bootstrap.srcDir}/build/soong/cc
+default .bootstrap/soong-cc/test/test.passed
+
+build .bootstrap/soong-cc/pkg/android/soong/cc.a: g.bootstrap.gc $
+ ${g.bootstrap.srcDir}/build/soong/cc/builder.go $
+ ${g.bootstrap.srcDir}/build/soong/cc/cc.go $
+ ${g.bootstrap.srcDir}/build/soong/cc/clang.go $
+ ${g.bootstrap.srcDir}/build/soong/cc/gen.go $
+ ${g.bootstrap.srcDir}/build/soong/cc/toolchain.go $
+ ${g.bootstrap.srcDir}/build/soong/cc/util.go $
+ ${g.bootstrap.srcDir}/build/soong/cc/arm_device.go $
+ ${g.bootstrap.srcDir}/build/soong/cc/arm64_device.go $
+ ${g.bootstrap.srcDir}/build/soong/cc/x86_darwin_host.go $
+ ${g.bootstrap.srcDir}/build/soong/cc/x86_linux_host.go | $
+ ${g.bootstrap.gcCmd} $
+ .bootstrap/blueprint-parser/pkg/github.com/google/blueprint/parser.a $
+ .bootstrap/blueprint-pathtools/pkg/github.com/google/blueprint/pathtools.a $
+ .bootstrap/blueprint-proptools/pkg/github.com/google/blueprint/proptools.a $
+ .bootstrap/blueprint/pkg/github.com/google/blueprint.a $
+ .bootstrap/soong/pkg/android/soong.a $
+ .bootstrap/blueprint-deptools/pkg/github.com/google/blueprint/deptools.a $
+ .bootstrap/blueprint-bootstrap-bpdoc/pkg/github.com/google/blueprint/bootstrap/bpdoc.a $
+ .bootstrap/blueprint-bootstrap/pkg/github.com/google/blueprint/bootstrap.a $
+ .bootstrap/soong-env/pkg/android/soong/env.a $
+ .bootstrap/soong-glob/pkg/android/soong/glob.a $
+ .bootstrap/soong-common/pkg/android/soong/common.a $
+ .bootstrap/soong-genrule/pkg/android/soong/genrule.a || $
+ .bootstrap/soong-cc/test/test.passed
+ incFlags = -I .bootstrap/blueprint-parser/pkg -I .bootstrap/blueprint-pathtools/pkg -I .bootstrap/blueprint-proptools/pkg -I .bootstrap/blueprint/pkg -I .bootstrap/soong/pkg -I .bootstrap/blueprint-deptools/pkg -I .bootstrap/blueprint-bootstrap-bpdoc/pkg -I .bootstrap/blueprint-bootstrap/pkg -I .bootstrap/soong-env/pkg -I .bootstrap/soong-glob/pkg -I .bootstrap/soong-common/pkg -I .bootstrap/soong-genrule/pkg
+ pkgPath = android/soong/cc
+default .bootstrap/soong-cc/pkg/android/soong/cc.a
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# Module: soong-common
+# Variant:
+# Type: bootstrap_go_package
+# Factory: github.com/google/blueprint/bootstrap.func·002
+# Defined: build/soong/Android.bp:85:1
+
+build .bootstrap/soong-common/pkg/android/soong/common.a: g.bootstrap.gc $
+ ${g.bootstrap.srcDir}/build/soong/common/arch.go $
+ ${g.bootstrap.srcDir}/build/soong/common/config.go $
+ ${g.bootstrap.srcDir}/build/soong/common/defs.go $
+ ${g.bootstrap.srcDir}/build/soong/common/env.go $
+ ${g.bootstrap.srcDir}/build/soong/common/glob.go $
+ ${g.bootstrap.srcDir}/build/soong/common/module.go $
+ ${g.bootstrap.srcDir}/build/soong/common/paths.go $
+ ${g.bootstrap.srcDir}/build/soong/common/util.go | $
+ ${g.bootstrap.gcCmd} $
+ .bootstrap/blueprint-parser/pkg/github.com/google/blueprint/parser.a $
+ .bootstrap/blueprint-pathtools/pkg/github.com/google/blueprint/pathtools.a $
+ .bootstrap/blueprint-proptools/pkg/github.com/google/blueprint/proptools.a $
+ .bootstrap/blueprint/pkg/github.com/google/blueprint.a $
+ .bootstrap/blueprint-deptools/pkg/github.com/google/blueprint/deptools.a $
+ .bootstrap/blueprint-bootstrap-bpdoc/pkg/github.com/google/blueprint/bootstrap/bpdoc.a $
+ .bootstrap/blueprint-bootstrap/pkg/github.com/google/blueprint/bootstrap.a $
+ .bootstrap/soong/pkg/android/soong.a $
+ .bootstrap/soong-env/pkg/android/soong/env.a $
+ .bootstrap/soong-glob/pkg/android/soong/glob.a
+ incFlags = -I .bootstrap/blueprint-parser/pkg -I .bootstrap/blueprint-pathtools/pkg -I .bootstrap/blueprint-proptools/pkg -I .bootstrap/blueprint/pkg -I .bootstrap/blueprint-deptools/pkg -I .bootstrap/blueprint-bootstrap-bpdoc/pkg -I .bootstrap/blueprint-bootstrap/pkg -I .bootstrap/soong/pkg -I .bootstrap/soong-env/pkg -I .bootstrap/soong-glob/pkg
+ pkgPath = android/soong/common
+default .bootstrap/soong-common/pkg/android/soong/common.a
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# Module: soong-env
+# Variant:
+# Type: bootstrap_go_package
+# Factory: github.com/google/blueprint/bootstrap.func·002
+# Defined: build/soong/Android.bp:42:1
+
+build .bootstrap/soong-env/pkg/android/soong/env.a: g.bootstrap.gc $
+ ${g.bootstrap.srcDir}/build/soong/env/env.go | ${g.bootstrap.gcCmd}
+ pkgPath = android/soong/env
+default .bootstrap/soong-env/pkg/android/soong/env.a
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# Module: soong-genrule
+# Variant:
+# Type: bootstrap_go_package
+# Factory: github.com/google/blueprint/bootstrap.func·002
+# Defined: build/soong/Android.bp:136:1
+
+build .bootstrap/soong-genrule/pkg/android/soong/genrule.a: g.bootstrap.gc $
+ ${g.bootstrap.srcDir}/build/soong/genrule/genrule.go | $
+ ${g.bootstrap.gcCmd} $
+ .bootstrap/blueprint-parser/pkg/github.com/google/blueprint/parser.a $
+ .bootstrap/blueprint-pathtools/pkg/github.com/google/blueprint/pathtools.a $
+ .bootstrap/blueprint-proptools/pkg/github.com/google/blueprint/proptools.a $
+ .bootstrap/blueprint/pkg/github.com/google/blueprint.a $
+ .bootstrap/soong/pkg/android/soong.a $
+ .bootstrap/blueprint-deptools/pkg/github.com/google/blueprint/deptools.a $
+ .bootstrap/blueprint-bootstrap-bpdoc/pkg/github.com/google/blueprint/bootstrap/bpdoc.a $
+ .bootstrap/blueprint-bootstrap/pkg/github.com/google/blueprint/bootstrap.a $
+ .bootstrap/soong-env/pkg/android/soong/env.a $
+ .bootstrap/soong-glob/pkg/android/soong/glob.a $
+ .bootstrap/soong-common/pkg/android/soong/common.a
+ incFlags = -I .bootstrap/blueprint-parser/pkg -I .bootstrap/blueprint-pathtools/pkg -I .bootstrap/blueprint-proptools/pkg -I .bootstrap/blueprint/pkg -I .bootstrap/soong/pkg -I .bootstrap/blueprint-deptools/pkg -I .bootstrap/blueprint-bootstrap-bpdoc/pkg -I .bootstrap/blueprint-bootstrap/pkg -I .bootstrap/soong-env/pkg -I .bootstrap/soong-glob/pkg -I .bootstrap/soong-common/pkg
+ pkgPath = android/soong/genrule
+default .bootstrap/soong-genrule/pkg/android/soong/genrule.a
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# Module: soong-glob
+# Variant:
+# Type: bootstrap_go_package
+# Factory: github.com/google/blueprint/bootstrap.func·002
+# Defined: build/soong/Android.bp:61:1
+
+build .bootstrap/soong-glob/pkg/android/soong/glob.a: g.bootstrap.gc $
+ ${g.bootstrap.srcDir}/build/soong/glob/glob.go | ${g.bootstrap.gcCmd} $
+ .bootstrap/blueprint-deptools/pkg/github.com/google/blueprint/deptools.a $
+ .bootstrap/blueprint-pathtools/pkg/github.com/google/blueprint/pathtools.a
+ incFlags = -I .bootstrap/blueprint-deptools/pkg -I .bootstrap/blueprint-pathtools/pkg
+ pkgPath = android/soong/glob
+default .bootstrap/soong-glob/pkg/android/soong/glob.a
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# Module: soong-java
+# Variant:
+# Type: bootstrap_go_package
+# Factory: github.com/google/blueprint/bootstrap.func·002
+# Defined: build/soong/Android.bp:157:1
+
+build .bootstrap/soong-java/pkg/android/soong/java.a: g.bootstrap.gc $
+ ${g.bootstrap.srcDir}/build/soong/java/app_builder.go $
+ ${g.bootstrap.srcDir}/build/soong/java/app.go $
+ ${g.bootstrap.srcDir}/build/soong/java/builder.go $
+ ${g.bootstrap.srcDir}/build/soong/java/gen.go $
+ ${g.bootstrap.srcDir}/build/soong/java/java.go $
+ ${g.bootstrap.srcDir}/build/soong/java/resources.go | $
+ ${g.bootstrap.gcCmd} $
+ .bootstrap/blueprint-parser/pkg/github.com/google/blueprint/parser.a $
+ .bootstrap/blueprint-pathtools/pkg/github.com/google/blueprint/pathtools.a $
+ .bootstrap/blueprint-proptools/pkg/github.com/google/blueprint/proptools.a $
+ .bootstrap/blueprint/pkg/github.com/google/blueprint.a $
+ .bootstrap/soong/pkg/android/soong.a $
+ .bootstrap/blueprint-deptools/pkg/github.com/google/blueprint/deptools.a $
+ .bootstrap/blueprint-bootstrap-bpdoc/pkg/github.com/google/blueprint/bootstrap/bpdoc.a $
+ .bootstrap/blueprint-bootstrap/pkg/github.com/google/blueprint/bootstrap.a $
+ .bootstrap/soong-env/pkg/android/soong/env.a $
+ .bootstrap/soong-glob/pkg/android/soong/glob.a $
+ .bootstrap/soong-common/pkg/android/soong/common.a $
+ .bootstrap/soong-genrule/pkg/android/soong/genrule.a
+ incFlags = -I .bootstrap/blueprint-parser/pkg -I .bootstrap/blueprint-pathtools/pkg -I .bootstrap/blueprint-proptools/pkg -I .bootstrap/blueprint/pkg -I .bootstrap/soong/pkg -I .bootstrap/blueprint-deptools/pkg -I .bootstrap/blueprint-bootstrap-bpdoc/pkg -I .bootstrap/blueprint-bootstrap/pkg -I .bootstrap/soong-env/pkg -I .bootstrap/soong-glob/pkg -I .bootstrap/soong-common/pkg -I .bootstrap/soong-genrule/pkg
+ pkgPath = android/soong/java
+default .bootstrap/soong-java/pkg/android/soong/java.a
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# Module: soong_build
+# Variant:
+# Type: bootstrap_go_binary
+# Factory: github.com/google/blueprint/bootstrap.func·003
+# Defined: build/soong/Android.bp:13:1
+
+build .bootstrap/soong_build/obj/soong_build.a: g.bootstrap.gc $
+ ${g.bootstrap.srcDir}/build/soong/cmd/soong_build/main.go | $
+ ${g.bootstrap.gcCmd} $
+ .bootstrap/blueprint-parser/pkg/github.com/google/blueprint/parser.a $
+ .bootstrap/blueprint-pathtools/pkg/github.com/google/blueprint/pathtools.a $
+ .bootstrap/blueprint-proptools/pkg/github.com/google/blueprint/proptools.a $
+ .bootstrap/blueprint/pkg/github.com/google/blueprint.a $
+ .bootstrap/blueprint-deptools/pkg/github.com/google/blueprint/deptools.a $
+ .bootstrap/blueprint-bootstrap-bpdoc/pkg/github.com/google/blueprint/bootstrap/bpdoc.a $
+ .bootstrap/blueprint-bootstrap/pkg/github.com/google/blueprint/bootstrap.a $
+ .bootstrap/soong/pkg/android/soong.a $
+ .bootstrap/soong-env/pkg/android/soong/env.a $
+ .bootstrap/soong-glob/pkg/android/soong/glob.a $
+ .bootstrap/soong-common/pkg/android/soong/common.a $
+ .bootstrap/soong-genrule/pkg/android/soong/genrule.a $
+ .bootstrap/soong-cc/pkg/android/soong/cc.a $
+ .bootstrap/soong-art/pkg/android/soong/art.a $
+ .bootstrap/soong-java/pkg/android/soong/java.a
+ incFlags = -I .bootstrap/blueprint-parser/pkg -I .bootstrap/blueprint-pathtools/pkg -I .bootstrap/blueprint-proptools/pkg -I .bootstrap/blueprint/pkg -I .bootstrap/blueprint-deptools/pkg -I .bootstrap/blueprint-bootstrap-bpdoc/pkg -I .bootstrap/blueprint-bootstrap/pkg -I .bootstrap/soong/pkg -I .bootstrap/soong-env/pkg -I .bootstrap/soong-glob/pkg -I .bootstrap/soong-common/pkg -I .bootstrap/soong-genrule/pkg -I .bootstrap/soong-cc/pkg -I .bootstrap/soong-art/pkg -I .bootstrap/soong-java/pkg
+ pkgPath = soong_build
+default .bootstrap/soong_build/obj/soong_build.a
+
+build .bootstrap/soong_build/obj/a.out: g.bootstrap.link $
+ .bootstrap/soong_build/obj/soong_build.a | ${g.bootstrap.linkCmd}
+ libDirFlags = -L .bootstrap/blueprint-parser/pkg -L .bootstrap/blueprint-pathtools/pkg -L .bootstrap/blueprint-proptools/pkg -L .bootstrap/blueprint/pkg -L .bootstrap/blueprint-deptools/pkg -L .bootstrap/blueprint-bootstrap-bpdoc/pkg -L .bootstrap/blueprint-bootstrap/pkg -L .bootstrap/soong/pkg -L .bootstrap/soong-env/pkg -L .bootstrap/soong-glob/pkg -L .bootstrap/soong-common/pkg -L .bootstrap/soong-genrule/pkg -L .bootstrap/soong-cc/pkg -L .bootstrap/soong-art/pkg -L .bootstrap/soong-java/pkg
+default .bootstrap/soong_build/obj/a.out
+
+build .bootstrap/bin/soong_build: g.bootstrap.cp $
+ .bootstrap/soong_build/obj/a.out
+default .bootstrap/bin/soong_build
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# Module: soong_env
+# Variant:
+# Type: bootstrap_go_binary
+# Factory: github.com/google/blueprint/bootstrap.func·003
+# Defined: build/soong/Android.bp:32:1
+
+build .bootstrap/soong_env/obj/soong_env.a: g.bootstrap.gc $
+ ${g.bootstrap.srcDir}/build/soong/cmd/soong_env/soong_env.go | $
+ ${g.bootstrap.gcCmd} .bootstrap/soong-env/pkg/android/soong/env.a
+ incFlags = -I .bootstrap/soong-env/pkg
+ pkgPath = soong_env
+default .bootstrap/soong_env/obj/soong_env.a
+
+build .bootstrap/soong_env/obj/a.out: g.bootstrap.link $
+ .bootstrap/soong_env/obj/soong_env.a | ${g.bootstrap.linkCmd}
+ libDirFlags = -L .bootstrap/soong-env/pkg
+default .bootstrap/soong_env/obj/a.out
+
+build .bootstrap/bin/soong_env: g.bootstrap.cp .bootstrap/soong_env/obj/a.out
+default .bootstrap/bin/soong_env
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# Module: soong_glob
+# Variant:
+# Type: bootstrap_go_binary
+# Factory: github.com/google/blueprint/bootstrap.func·003
+# Defined: build/soong/Android.bp:51:1
+
+build .bootstrap/soong_glob/obj/soong_glob.a: g.bootstrap.gc $
+ ${g.bootstrap.srcDir}/build/soong/cmd/soong_glob/soong_glob.go | $
+ ${g.bootstrap.gcCmd} $
+ .bootstrap/blueprint-deptools/pkg/github.com/google/blueprint/deptools.a $
+ .bootstrap/blueprint-pathtools/pkg/github.com/google/blueprint/pathtools.a $
+ .bootstrap/soong-glob/pkg/android/soong/glob.a
+ incFlags = -I .bootstrap/blueprint-deptools/pkg -I .bootstrap/blueprint-pathtools/pkg -I .bootstrap/soong-glob/pkg
+ pkgPath = soong_glob
+default .bootstrap/soong_glob/obj/soong_glob.a
+
+build .bootstrap/soong_glob/obj/a.out: g.bootstrap.link $
+ .bootstrap/soong_glob/obj/soong_glob.a | ${g.bootstrap.linkCmd}
+ libDirFlags = -L .bootstrap/blueprint-deptools/pkg -L .bootstrap/blueprint-pathtools/pkg -L .bootstrap/soong-glob/pkg
+default .bootstrap/soong_glob/obj/a.out
+
+build .bootstrap/bin/soong_glob: g.bootstrap.cp $
+ .bootstrap/soong_glob/obj/a.out
+default .bootstrap/bin/soong_glob
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# Module: soong_jar
+# Variant:
+# Type: bootstrap_go_binary
+# Factory: github.com/google/blueprint/bootstrap.func·003
+# Defined: build/soong/Android.bp:150:1
+
+build .bootstrap/soong_jar/obj/soong_jar.a: g.bootstrap.gc $
+ ${g.bootstrap.srcDir}/build/soong/cmd/soong_jar/soong_jar.go | $
+ ${g.bootstrap.gcCmd}
+ pkgPath = soong_jar
+default .bootstrap/soong_jar/obj/soong_jar.a
+
+build .bootstrap/soong_jar/obj/a.out: g.bootstrap.link $
+ .bootstrap/soong_jar/obj/soong_jar.a | ${g.bootstrap.linkCmd}
+default .bootstrap/soong_jar/obj/a.out
+build .bootstrap/bin/soong_jar: g.bootstrap.cp .bootstrap/soong_jar/obj/a.out
+default .bootstrap/bin/soong_jar
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# Singleton: bootstrap
+# Factory: github.com/google/blueprint/bootstrap.func·008
+
+rule s.bootstrap.bigbpDocs
+ command = .bootstrap/bin/soong_build -t --docs ${out} ${g.bootstrap.srcDir}/Android.bp
+ description = soong_build docs ${out}
+
+rule s.bootstrap.bigbp
+ command = .bootstrap/bin/soong_build -t -d .bootstrap/main.ninja.in.d -m ${g.bootstrap.bootstrapManifest} -o ${out} ${in}
+ depfile = .bootstrap/main.ninja.in.d
+ description = soong_build ${out}
+
+rule s.bootstrap.minibp
+ command = .bootstrap/bin/minibp ${runTests} -c ${checkFile} -m ${g.bootstrap.bootstrapManifest} -d ${out}.d -o ${out} ${in}
+ depfile = ${out}.d
+ description = minibp ${out}
+ generator = true
+
+build .bootstrap/docs/soong_build.html: s.bootstrap.bigbpDocs | $
+ .bootstrap/bin/soong_build
+default .bootstrap/docs/soong_build.html
+build .bootstrap/main.ninja.in: s.bootstrap.bigbp $
+ ${g.bootstrap.srcDir}/Android.bp | .bootstrap/bin/androidbp $
+ .bootstrap/bin/androidmk .bootstrap/bin/bpfmt .bootstrap/bin/bpmodify $
+ .bootstrap/bin/gotestmain .bootstrap/bin/minibp $
+ .bootstrap/bin/soong_build .bootstrap/bin/soong_env $
+ .bootstrap/bin/soong_glob .bootstrap/bin/soong_jar $
+ .bootstrap/docs/soong_build.html
+default .bootstrap/main.ninja.in
+build .bootstrap/notAFile: phony
+default .bootstrap/notAFile
+build build.ninja: g.bootstrap.bootstrap .bootstrap/main.ninja.in | $
+ ${g.bootstrap.bootstrapCmd} .bootstrap/notAFile $
+ .bootstrap/bootstrap.ninja.in
+default build.ninja
+build .bootstrap/bootstrap.ninja.in: s.bootstrap.minibp $
+ ${g.bootstrap.srcDir}/Android.bp | .bootstrap/bin/minibp
+ checkFile = ${g.bootstrap.bootstrapManifest}
+ runTests = -t
+default .bootstrap/bootstrap.ninja.in
+
diff --git a/cc/arm64_device.go b/cc/arm64_device.go
new file mode 100644
index 0000000..201c0f2
--- /dev/null
+++ b/cc/arm64_device.go
@@ -0,0 +1,145 @@
+package cc
+
+import (
+ "strings"
+
+ "android/soong/common"
+)
+
+var (
+ arm64Cflags = []string{
+ "-fno-exceptions", // from build/core/combo/select.mk
+ "-Wno-multichar", // from build/core/combo/select.mk
+ "-fno-strict-aliasing",
+ "-fstack-protector",
+ "-ffunction-sections",
+ "-fdata-sections",
+ "-funwind-tables",
+ "-Wa,--noexecstack",
+ "-Werror=format-security",
+ "-D_FORTIFY_SOURCE=2",
+ "-fno-short-enums",
+ "-no-canonical-prefixes",
+ "-fno-canonical-system-headers",
+ "-include ${SrcDir}/build/core/combo/include/arch/linux-arm64/AndroidConfig.h",
+
+ // Help catch common 32/64-bit errors.
+ "-Werror=pointer-to-int-cast",
+ "-Werror=int-to-pointer-cast",
+
+ "-fno-strict-volatile-bitfields",
+
+ // TARGET_RELEASE_CFLAGS
+ "-DNDEBUG",
+ "-O2 -g",
+ "-Wstrict-aliasing=2",
+ "-fgcse-after-reload",
+ "-frerun-cse-after-loop",
+ "-frename-registers",
+ }
+
+ arm64Ldflags = []string{
+ "-Wl,-z,noexecstack",
+ "-Wl,-z,relro",
+ "-Wl,-z,now",
+ "-Wl,--build-id=md5",
+ "-Wl,--warn-shared-textrel",
+ "-Wl,--fatal-warnings",
+ "-Wl,-maarch64linux",
+ "-Wl,--hash-style=gnu",
+
+ // Disable transitive dependency library symbol resolving.
+ "-Wl,--allow-shlib-undefined",
+ }
+
+ arm64Cppflags = []string{
+ "-fvisibility-inlines-hidden",
+ }
+)
+
+func init() {
+ pctx.StaticVariable("arm64GccVersion", "4.9")
+
+ pctx.StaticVariable("arm64GccRoot",
+ "${SrcDir}/prebuilts/gcc/${HostPrebuiltTag}/aarch64/aarch64-linux-android-${arm64GccVersion}")
+
+ pctx.StaticVariable("arm64GccTriple", "aarch64-linux-android")
+
+ pctx.StaticVariable("arm64Cflags", strings.Join(arm64Cflags, " "))
+ pctx.StaticVariable("arm64Ldflags", strings.Join(arm64Ldflags, " "))
+ pctx.StaticVariable("arm64Cppflags", strings.Join(arm64Cppflags, " "))
+ pctx.StaticVariable("arm64IncludeFlags", strings.Join([]string{
+ "-isystem ${LibcRoot}/arch-arm64/include",
+ "-isystem ${LibcRoot}/include",
+ "-isystem ${LibcRoot}/kernel/uapi",
+ "-isystem ${LibcRoot}/kernel/uapi/asm-arm64",
+ "-isystem ${LibmRoot}/include",
+ "-isystem ${LibmRoot}/include/arm64",
+ }, " "))
+
+ pctx.StaticVariable("arm64ClangCflags", strings.Join(clangFilterUnknownCflags(arm64Cflags), " "))
+ pctx.StaticVariable("arm64ClangLdflags", strings.Join(clangFilterUnknownCflags(arm64Ldflags), " "))
+ pctx.StaticVariable("arm64ClangCppflags", strings.Join(clangFilterUnknownCflags(arm64Cppflags), " "))
+}
+
+type toolchainArm64 struct {
+ toolchain64Bit
+}
+
+var toolchainArm64Singleton = &toolchainArm64{}
+
+func (t *toolchainArm64) Name() string {
+ return "arm64"
+}
+
+func (t *toolchainArm64) GccRoot() string {
+ return "${arm64GccRoot}"
+}
+
+func (t *toolchainArm64) GccTriple() string {
+ return "${arm64GccTriple}"
+}
+
+func (t *toolchainArm64) GccVersion() string {
+ return "${arm64GccVersion}"
+}
+
+func (t *toolchainArm64) Cflags() string {
+ return "${arm64Cflags}"
+}
+
+func (t *toolchainArm64) Cppflags() string {
+ return "${arm64Cppflags}"
+}
+
+func (t *toolchainArm64) Ldflags() string {
+ return "${arm64Ldflags}"
+}
+
+func (t *toolchainArm64) IncludeFlags() string {
+ return "${arm64IncludeFlags}"
+}
+
+func (t *toolchainArm64) ClangTriple() string {
+ return "${arm64GccTriple}"
+}
+
+func (t *toolchainArm64) ClangCflags() string {
+ return "${arm64ClangCflags}"
+}
+
+func (t *toolchainArm64) ClangCppflags() string {
+ return "${arm64ClangCppflags}"
+}
+
+func (t *toolchainArm64) ClangLdflags() string {
+ return "${arm64Ldflags}"
+}
+
+func arm64ToolchainFactory(archVariant string, cpuVariant string) Toolchain {
+ return toolchainArm64Singleton
+}
+
+func init() {
+ registerToolchainFactory(common.Device, common.Arm64, arm64ToolchainFactory)
+}
diff --git a/cc/arm_device.go b/cc/arm_device.go
new file mode 100644
index 0000000..b935348
--- /dev/null
+++ b/cc/arm_device.go
@@ -0,0 +1,320 @@
+package cc
+
+import (
+ "fmt"
+ "strings"
+
+ "android/soong/common"
+)
+
+var (
+ armCflags = []string{
+ "-fno-exceptions", // from build/core/combo/select.mk
+ "-Wno-multichar", // from build/core/combo/select.mk
+ "-msoft-float",
+ "-ffunction-sections",
+ "-fdata-sections",
+ "-funwind-tables",
+ "-fstack-protector",
+ "-Wa,--noexecstack",
+ "-Werror=format-security",
+ "-D_FORTIFY_SOURCE=2",
+ "-fno-short-enums",
+ "-no-canonical-prefixes",
+ "-fno-canonical-system-headers",
+ "-include ${SrcDir}/build/core/combo/include/arch/linux-arm/AndroidConfig.h",
+
+ "-fno-builtin-sin",
+ "-fno-strict-volatile-bitfields",
+
+ "-mthumb-interwork",
+
+ // TARGET_RELEASE_CFLAGS
+ "-DNDEBUG",
+ "-g",
+ "-Wstrict-aliasing=2",
+ "-fgcse-after-reload",
+ "-frerun-cse-after-loop",
+ "-frename-registers",
+ }
+
+ armCppflags = []string{
+ "-fvisibility-inlines-hidden",
+ }
+
+ armLdflags = []string{
+ "-Wl,-z,noexecstack",
+ "-Wl,-z,relro",
+ "-Wl,-z,now",
+ "-Wl,--build-id=md5",
+ "-Wl,--warn-shared-textrel",
+ "-Wl,--fatal-warnings",
+ "-Wl,--icf=safe",
+ "-Wl,--hash-style=gnu",
+ }
+
+ armArmCflags = []string{
+ "-O2",
+ "-fomit-frame-pointer",
+ "-fstrict-aliasing",
+ "-funswitch-loops",
+ }
+
+ armThumbCflags = []string{
+ "-mthumb",
+ "-Os",
+ "-fomit-frame-pointer",
+ "-fno-strict-aliasing",
+ }
+
+ armArchVariantCflags = map[string][]string{
+ "armv5te": []string{
+ "-march=armv5te",
+ "-mtune=xscale",
+ "-D__ARM_ARCH_5__",
+ "-D__ARM_ARCH_5T__",
+ "-D__ARM_ARCH_5E__",
+ "-D__ARM_ARCH_5TE__",
+ },
+ "armv7-a": []string{
+ "-march=armv7-a",
+ "-mfloat-abi=softfp",
+ "-mfpu=vfpv3-d16",
+ },
+ "armv7-a-neon": []string{
+ "-mfloat-abi=softfp",
+ "-mfpu=neon",
+ },
+ }
+
+ armCpuVariantCflags = map[string][]string{
+ "cortex-a7": []string{
+ "-mcpu=cortex-a7",
+ },
+ "cortex-a8": []string{
+ "-mcpu=cortex-a8",
+ },
+ "cortex-a15": []string{
+ "-mcpu=cortex-a15",
+ // Fake an ARM compiler flag as these processors support LPAE which GCC/clang
+ // don't advertise.
+ "-D__ARM_FEATURE_LPAE=1",
+ },
+ }
+
+ armClangCpuVariantCflags = copyVariantFlags(armCpuVariantCflags)
+ armClangArchVariantCflags = copyVariantFlags(armArchVariantCflags)
+)
+
+func copyVariantFlags(m map[string][]string) map[string][]string {
+ ret := make(map[string][]string, len(m))
+ for k, v := range m {
+ l := make([]string, len(m[k]))
+ for i := range m[k] {
+ l[i] = v[i]
+ }
+ ret[k] = l
+ }
+ return ret
+}
+
+func init() {
+ replaceFirst := func(slice []string, from, to string) {
+ if slice[0] != from {
+ panic(fmt.Errorf("Expected %q, found %q", from, to))
+ }
+
+ slice[0] = to
+ }
+
+ replaceFirst(armClangArchVariantCflags["armv5te"], "-march=armv5te", "-march=armv5t")
+ armClangCpuVariantCflags["krait"] = []string{
+ "-mcpu=krait",
+ }
+
+ pctx.StaticVariable("armGccVersion", "4.9")
+
+ pctx.StaticVariable("armGccRoot",
+ "${SrcDir}/prebuilts/gcc/${HostPrebuiltTag}/arm/arm-linux-androideabi-${armGccVersion}")
+
+ pctx.StaticVariable("armGccTriple", "arm-linux-androideabi")
+
+ pctx.StaticVariable("armCflags", strings.Join(armCflags, " "))
+ pctx.StaticVariable("armLdflags", strings.Join(armLdflags, " "))
+ pctx.StaticVariable("armCppflags", strings.Join(armCppflags, " "))
+ pctx.StaticVariable("armIncludeFlags", strings.Join([]string{
+ "-isystem ${LibcRoot}/arch-arm/include",
+ "-isystem ${LibcRoot}/include",
+ "-isystem ${LibcRoot}/kernel/uapi",
+ "-isystem ${LibcRoot}/kernel/uapi/asm-arm",
+ "-isystem ${LibmRoot}/include",
+ "-isystem ${LibmRoot}/include/arm",
+ }, " "))
+
+ // Extended cflags
+
+ // ARM vs. Thumb instruction set flags
+ pctx.StaticVariable("armArmCflags", strings.Join(armArmCflags, " "))
+ pctx.StaticVariable("armThumbCflags", strings.Join(armThumbCflags, " "))
+
+ // Architecture variant cflags
+ pctx.StaticVariable("armArmv5TECflags", strings.Join(armArchVariantCflags["armv5te"], " "))
+ pctx.StaticVariable("armArmv7ACflags", strings.Join(armArchVariantCflags["armv7-a"], " "))
+ pctx.StaticVariable("armArmv7ANeonCflags", strings.Join(armArchVariantCflags["armv7-a-neon"], " "))
+
+ // Cpu variant cflags
+ pctx.StaticVariable("armCortexA7Cflags", strings.Join(armCpuVariantCflags["cortex-a7"], " "))
+ pctx.StaticVariable("armCortexA8Cflags", strings.Join(armCpuVariantCflags["cortex-a8"], " "))
+ pctx.StaticVariable("armCortexA15Cflags", strings.Join(armCpuVariantCflags["cortex-a15"], " "))
+
+ // Clang cflags
+ pctx.StaticVariable("armClangCflags", strings.Join(clangFilterUnknownCflags(armCflags), " "))
+ pctx.StaticVariable("armClangLdflags", strings.Join(clangFilterUnknownCflags(armLdflags), " "))
+ pctx.StaticVariable("armClangCppflags", strings.Join(clangFilterUnknownCflags(armCppflags), " "))
+
+ // Clang cpu variant cflags
+ pctx.StaticVariable("armClangArmv5TECflags",
+ strings.Join(armClangArchVariantCflags["armv5te"], " "))
+ pctx.StaticVariable("armClangArmv7ACflags",
+ strings.Join(armClangArchVariantCflags["armv7-a"], " "))
+ pctx.StaticVariable("armClangArmv7ANeonCflags",
+ strings.Join(armClangArchVariantCflags["armv7-a-neon"], " "))
+
+ // Clang cpu variant cflags
+ pctx.StaticVariable("armClangCortexA7Cflags",
+ strings.Join(armClangCpuVariantCflags["cortex-a7"], " "))
+ pctx.StaticVariable("armClangCortexA8Cflags",
+ strings.Join(armClangCpuVariantCflags["cortex-a8"], " "))
+ pctx.StaticVariable("armClangCortexA15Cflags",
+ strings.Join(armClangCpuVariantCflags["cortex-a15"], " "))
+ pctx.StaticVariable("armClangKraitCflags",
+ strings.Join(armClangCpuVariantCflags["krait"], " "))
+}
+
+var (
+ armArchVariantCflagsVar = map[string]string{
+ "armv5te": "${armArmv5TECflags}",
+ "armv7-a": "${armArmv7ACflags}",
+ "armv7-a-neon": "${armArmv7ANeonCflags}",
+ }
+
+ armCpuVariantCflagsVar = map[string]string{
+ "": "",
+ "cortex-a7": "${armCortexA7Cflags}",
+ "cortex-a8": "${armCortexA8Cflags}",
+ "cortex-a15": "${armCortexA15Cflags}",
+ "krait": "${armCortexA15Cflags}",
+ "denver": "${armCortexA15Cflags}",
+ }
+
+ armClangArchVariantCflagsVar = map[string]string{
+ "armv5te": "${armClangArmv5TECflags}",
+ "armv7-a": "${armClangArmv7ACflags}",
+ "armv7-a-neon": "${armClangArmv7ANeonCflags}",
+ }
+
+ armClangCpuVariantCflagsVar = map[string]string{
+ "": "",
+ "cortex-a7": "${armClangCortexA7Cflags}",
+ "cortex-a8": "${armClangCortexA8Cflags}",
+ "cortex-a15": "${armClangCortexA15Cflags}",
+ "krait": "${armClangKraitCflags}",
+ "denver": "${armClangCortexA15Cflags}",
+ }
+)
+
+type toolchainArm struct {
+ toolchain32Bit
+ cflags, ldflags, clangCflags string
+}
+
+func (t *toolchainArm) Name() string {
+ return "arm"
+}
+
+func (t *toolchainArm) GccRoot() string {
+ return "${armGccRoot}"
+}
+
+func (t *toolchainArm) GccTriple() string {
+ return "${armGccTriple}"
+}
+
+func (t *toolchainArm) GccVersion() string {
+ return "${armGccVersion}"
+}
+
+func (t *toolchainArm) Cflags() string {
+ return t.cflags
+}
+
+func (t *toolchainArm) Cppflags() string {
+ return "${armCppflags}"
+}
+
+func (t *toolchainArm) Ldflags() string {
+ return t.ldflags
+}
+
+func (t *toolchainArm) IncludeFlags() string {
+ return "${armIncludeFlags}"
+}
+
+func (t *toolchainArm) InstructionSetFlags(isa string) (string, error) {
+ switch isa {
+ case "arm":
+ return "${armArmCflags}", nil
+ case "thumb", "":
+ return "${armThumbCflags}", nil
+ default:
+ return t.toolchainBase.InstructionSetFlags(isa)
+ }
+}
+
+func (t *toolchainArm) ClangTriple() string {
+ return "${armGccTriple}"
+}
+
+func (t *toolchainArm) ClangCflags() string {
+ return t.clangCflags
+}
+
+func (t *toolchainArm) ClangCppflags() string {
+ return "${armClangCppflags}"
+}
+
+func (t *toolchainArm) ClangLdflags() string {
+ return t.ldflags
+}
+
+func armToolchainFactory(archVariant string, cpuVariant string) Toolchain {
+ var fixCortexA8 string
+ switch cpuVariant {
+ case "cortex-a8", "":
+ // Generic ARM might be a Cortex A8 -- better safe than sorry
+ fixCortexA8 = "-Wl,--fix-cortex-a8"
+ default:
+ fixCortexA8 = "-Wl,--no-fix-cortex-a8"
+ }
+
+ return &toolchainArm{
+ cflags: strings.Join([]string{
+ "${armCflags}",
+ armArchVariantCflagsVar[archVariant],
+ armCpuVariantCflagsVar[cpuVariant],
+ }, " "),
+ ldflags: strings.Join([]string{
+ "${armLdflags}",
+ fixCortexA8,
+ }, " "),
+ clangCflags: strings.Join([]string{
+ "${armClangCflags}",
+ armClangArchVariantCflagsVar[archVariant],
+ armClangCpuVariantCflagsVar[cpuVariant],
+ }, " "),
+ }
+}
+
+func init() {
+ registerToolchainFactory(common.Device, common.Arm, armToolchainFactory)
+}
diff --git a/cc/builder.go b/cc/builder.go
new file mode 100644
index 0000000..d6d1a02
--- /dev/null
+++ b/cc/builder.go
@@ -0,0 +1,438 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package cc
+
+// This file generates the final rules for compiling all C/C++. All properties related to
+// compiling should have been translated into builderFlags or another argument to the Transform*
+// functions.
+
+import (
+ "android/soong/common"
+ "fmt"
+ "runtime"
+ "strconv"
+
+ "path/filepath"
+ "strings"
+
+ "github.com/google/blueprint"
+ "github.com/google/blueprint/pathtools"
+)
+
+const (
+ objectExtension = ".o"
+ sharedLibraryExtension = ".so"
+ staticLibraryExtension = ".a"
+)
+
+var (
+ pctx = blueprint.NewPackageContext("android/soong/cc")
+
+ cc = pctx.StaticRule("cc",
+ blueprint.RuleParams{
+ Depfile: "${out}.d",
+ Deps: blueprint.DepsGCC,
+ Command: "$ccCmd -c $cFlags -MD -MF ${out}.d -o $out $in",
+ Description: "cc $out",
+ },
+ "ccCmd", "cFlags")
+
+ ld = pctx.StaticRule("ld",
+ blueprint.RuleParams{
+ Command: "$ldCmd ${ldDirFlags} ${crtBegin} @${out}.rsp " +
+ "${libFlags} ${crtEnd} -o ${out} ${ldFlags}",
+ Description: "ld $out",
+ Rspfile: "${out}.rsp",
+ RspfileContent: "${in}",
+ },
+ "ldCmd", "ldDirFlags", "crtBegin", "libFlags", "crtEnd", "ldFlags")
+
+ partialLd = pctx.StaticRule("partialLd",
+ blueprint.RuleParams{
+ Command: "$ldCmd -r ${in} -o ${out}",
+ Description: "partialLd $out",
+ },
+ "ldCmd")
+
+ ar = pctx.StaticRule("ar",
+ blueprint.RuleParams{
+ Command: "rm -f ${out} && $arCmd $arFlags $out @${out}.rsp",
+ Description: "ar $out",
+ Rspfile: "${out}.rsp",
+ RspfileContent: "${in}",
+ },
+ "arCmd", "arFlags")
+
+ darwinAr = pctx.StaticRule("darwinAr",
+ blueprint.RuleParams{
+ Command: "rm -f ${out} && $arCmd $arFlags $out $in",
+ Description: "ar $out",
+ },
+ "arCmd", "arFlags")
+
+ darwinAppendAr = pctx.StaticRule("darwinAppendAr",
+ blueprint.RuleParams{
+ Command: "cp -f ${inAr} ${out}.tmp && $arCmd $arFlags ${out}.tmp $in && mv ${out}.tmp ${out}",
+ Description: "ar $out",
+ },
+ "arCmd", "arFlags", "inAr")
+
+ prefixSymbols = pctx.StaticRule("prefixSymbols",
+ blueprint.RuleParams{
+ Command: "$objcopyCmd --prefix-symbols=${prefix} ${in} ${out}",
+ Description: "prefixSymbols $out",
+ },
+ "objcopyCmd", "prefix")
+
+ copyGccLibPath = pctx.StaticVariable("copyGccLibPath", "${SrcDir}/build/soong/copygcclib.sh")
+
+ copyGccLib = pctx.StaticRule("copyGccLib",
+ blueprint.RuleParams{
+ Depfile: "${out}.d",
+ Deps: blueprint.DepsGCC,
+ Command: "$copyGccLibPath $out $ccCmd $cFlags -print-file-name=${libName}",
+ Description: "copy gcc $out",
+ },
+ "ccCmd", "cFlags", "libName")
+)
+
+type builderFlags struct {
+ globalFlags string
+ asFlags string
+ cFlags string
+ conlyFlags string
+ cppFlags string
+ ldFlags string
+ yaccFlags string
+ nocrt bool
+ toolchain Toolchain
+ clang bool
+}
+
+// Generate rules for compiling multiple .c, .cpp, or .S files to individual .o files
+func TransformSourceToObj(ctx common.AndroidModuleContext, subdir string, srcFiles []string,
+ flags builderFlags, deps []string) (objFiles []string) {
+
+ srcRoot := ctx.AConfig().SrcDir()
+ intermediatesRoot := ctx.AConfig().IntermediatesDir()
+
+ objFiles = make([]string, len(srcFiles))
+ objDir := common.ModuleObjDir(ctx)
+ if subdir != "" {
+ objDir = filepath.Join(objDir, subdir)
+ }
+
+ cflags := flags.globalFlags + " " + flags.cFlags + " " + flags.conlyFlags
+ cppflags := flags.globalFlags + " " + flags.cFlags + " " + flags.cppFlags
+ asflags := flags.globalFlags + " " + flags.asFlags
+
+ for i, srcFile := range srcFiles {
+ var objFile string
+ if strings.HasPrefix(srcFile, srcRoot) {
+ objFile = strings.TrimPrefix(srcFile, srcRoot)
+ objFile = filepath.Join(objDir, objFile)
+ } else if strings.HasPrefix(srcFile, intermediatesRoot) {
+ objFile = strings.TrimPrefix(srcFile, intermediatesRoot)
+ objFile = filepath.Join(objDir, "gen", objFile)
+ } else {
+ ctx.ModuleErrorf("source file %q is not in source directory %q", srcFile, srcRoot)
+ continue
+ }
+
+ objFile = pathtools.ReplaceExtension(objFile, "o")
+
+ objFiles[i] = objFile
+
+ var moduleCflags string
+ var ccCmd string
+
+ switch filepath.Ext(srcFile) {
+ case ".S", ".s":
+ ccCmd = "gcc"
+ moduleCflags = asflags
+ case ".c":
+ ccCmd = "gcc"
+ moduleCflags = cflags
+ case ".cpp", ".cc":
+ ccCmd = "g++"
+ moduleCflags = cppflags
+ default:
+ ctx.ModuleErrorf("File %s has unknown extension", srcFile)
+ continue
+ }
+
+ if flags.clang {
+ switch ccCmd {
+ case "gcc":
+ ccCmd = "clang"
+ case "g++":
+ ccCmd = "clang++"
+ default:
+ panic("unrecoginzied ccCmd")
+ }
+
+ ccCmd = "${clangPath}" + ccCmd
+ } else {
+ ccCmd = gccCmd(flags.toolchain, ccCmd)
+ }
+
+ objDeps := append([]string{ccCmd}, deps...)
+
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: cc,
+ Outputs: []string{objFile},
+ Inputs: []string{srcFile},
+ Implicits: objDeps,
+ Args: map[string]string{
+ "cFlags": moduleCflags,
+ "ccCmd": ccCmd,
+ },
+ })
+ }
+
+ return objFiles
+}
+
+// Generate a rule for compiling multiple .o files to a static library (.a)
+func TransformObjToStaticLib(ctx common.AndroidModuleContext, objFiles []string,
+ flags builderFlags, outputFile string) {
+
+ arCmd := gccCmd(flags.toolchain, "ar")
+ arFlags := "crsPD"
+
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: ar,
+ Outputs: []string{outputFile},
+ Inputs: objFiles,
+ Implicits: []string{arCmd},
+ Args: map[string]string{
+ "arFlags": arFlags,
+ "arCmd": arCmd,
+ },
+ })
+}
+
+// Generate a rule for compiling multiple .o files to a static library (.a) on
+// darwin. The darwin ar tool doesn't support @file for list files, and has a
+// very small command line length limit, so we have to split the ar into multiple
+// steps, each appending to the previous one.
+func TransformDarwinObjToStaticLib(ctx common.AndroidModuleContext, objFiles []string,
+ flags builderFlags, outputFile string) {
+
+ arCmd := "ar"
+ arFlags := "cqs"
+
+ // ARG_MAX on darwin is 262144, use half that to be safe
+ objFilesLists, err := splitListForSize(objFiles, 131072)
+ if err != nil {
+ ctx.ModuleErrorf("%s", err.Error())
+ }
+
+ var in, out string
+ for i, l := range objFilesLists {
+ in = out
+ out = outputFile
+ if i != len(objFilesLists)-1 {
+ out += "." + strconv.Itoa(i)
+ }
+
+ if in == "" {
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: darwinAr,
+ Outputs: []string{out},
+ Inputs: l,
+ Args: map[string]string{
+ "arFlags": arFlags,
+ "arCmd": arCmd,
+ },
+ })
+ } else {
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: darwinAppendAr,
+ Outputs: []string{out},
+ Inputs: l,
+ Implicits: []string{in},
+ Args: map[string]string{
+ "arFlags": arFlags,
+ "arCmd": arCmd,
+ "inAr": in,
+ },
+ })
+ }
+ }
+}
+
+// Generate a rule for compiling multiple .o files, plus static libraries, whole static libraries,
+// and shared libraires, to a shared library (.so) or dynamic executable
+func TransformObjToDynamicBinary(ctx common.AndroidModuleContext,
+ objFiles, sharedLibs, staticLibs, lateStaticLibs, wholeStaticLibs, deps []string,
+ crtBegin, crtEnd string, groupLate bool, flags builderFlags, outputFile string) {
+
+ var ldCmd string
+ if flags.clang {
+ ldCmd = "${clangPath}clang++"
+ } else {
+ ldCmd = gccCmd(flags.toolchain, "g++")
+ }
+
+ var ldDirs []string
+ var libFlagsList []string
+
+ if len(wholeStaticLibs) > 0 {
+ if ctx.Host() && runtime.GOOS == "darwin" {
+ libFlagsList = append(libFlagsList, common.JoinWithPrefix(wholeStaticLibs, "-force_load "))
+ } else {
+ libFlagsList = append(libFlagsList, "-Wl,--whole-archive ")
+ libFlagsList = append(libFlagsList, wholeStaticLibs...)
+ libFlagsList = append(libFlagsList, "-Wl,--no-whole-archive ")
+ }
+ }
+
+ libFlagsList = append(libFlagsList, staticLibs...)
+
+ if groupLate && len(lateStaticLibs) > 0 {
+ libFlagsList = append(libFlagsList, "-Wl,--start-group")
+ }
+ libFlagsList = append(libFlagsList, lateStaticLibs...)
+ if groupLate && len(lateStaticLibs) > 0 {
+ libFlagsList = append(libFlagsList, "-Wl,--end-group")
+ }
+
+ for _, lib := range sharedLibs {
+ dir, file := filepath.Split(lib)
+ if !strings.HasPrefix(file, "lib") {
+ panic("shared library " + lib + " does not start with lib")
+ }
+ if !strings.HasSuffix(file, sharedLibraryExtension) {
+ panic("shared library " + lib + " does not end with " + sharedLibraryExtension)
+ }
+ libFlagsList = append(libFlagsList,
+ "-l"+strings.TrimSuffix(strings.TrimPrefix(file, "lib"), sharedLibraryExtension))
+ ldDirs = append(ldDirs, dir)
+ }
+
+ deps = append(deps, ldCmd)
+ deps = append(deps, sharedLibs...)
+ deps = append(deps, staticLibs...)
+ deps = append(deps, lateStaticLibs...)
+ deps = append(deps, wholeStaticLibs...)
+ if crtBegin != "" {
+ deps = append(deps, crtBegin, crtEnd)
+ }
+
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: ld,
+ Outputs: []string{outputFile},
+ Inputs: objFiles,
+ Implicits: deps,
+ Args: map[string]string{
+ "ldCmd": ldCmd,
+ "ldDirFlags": ldDirsToFlags(ldDirs),
+ "crtBegin": crtBegin,
+ "libFlags": strings.Join(libFlagsList, " "),
+ "ldFlags": flags.ldFlags,
+ "crtEnd": crtEnd,
+ },
+ })
+}
+
+// Generate a rule for compiling multiple .o files to a .o using ld partial linking
+func TransformObjsToObj(ctx common.AndroidModuleContext, objFiles []string,
+ flags builderFlags, outputFile string) {
+
+ ldCmd := gccCmd(flags.toolchain, "ld")
+
+ deps := []string{ldCmd}
+
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: partialLd,
+ Outputs: []string{outputFile},
+ Inputs: objFiles,
+ Implicits: deps,
+ Args: map[string]string{
+ "ldCmd": ldCmd,
+ },
+ })
+}
+
+// Generate a rule for runing objcopy --prefix-symbols on a binary
+func TransformBinaryPrefixSymbols(ctx common.AndroidModuleContext, prefix string, inputFile string,
+ flags builderFlags, outputFile string) {
+
+ objcopyCmd := gccCmd(flags.toolchain, "objcopy")
+
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: prefixSymbols,
+ Outputs: []string{outputFile},
+ Inputs: []string{inputFile},
+ Implicits: []string{objcopyCmd},
+ Args: map[string]string{
+ "objcopyCmd": objcopyCmd,
+ "prefix": prefix,
+ },
+ })
+}
+
+func CopyGccLib(ctx common.AndroidModuleContext, libName string,
+ flags builderFlags, outputFile string) {
+
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: copyGccLib,
+ Outputs: []string{outputFile},
+ Implicits: []string{
+ "$copyGccLibPath",
+ gccCmd(flags.toolchain, "gcc"),
+ },
+ Args: map[string]string{
+ "ccCmd": gccCmd(flags.toolchain, "gcc"),
+ "cFlags": flags.globalFlags,
+ "libName": libName,
+ },
+ })
+}
+
+func gccCmd(toolchain Toolchain, cmd string) string {
+ return filepath.Join(toolchain.GccRoot(), "bin", toolchain.GccTriple()+"-"+cmd)
+}
+
+func splitListForSize(list []string, limit int) (lists [][]string, err error) {
+ var i int
+
+ start := 0
+ bytes := 0
+ for i = range list {
+ l := len(list[i])
+ if l > limit {
+ return nil, fmt.Errorf("list element greater than size limit (%d)", limit)
+ }
+ if bytes+l > limit {
+ lists = append(lists, list[start:i])
+ start = i
+ bytes = 0
+ }
+ bytes += l + 1 // count a space between each list element
+ }
+
+ lists = append(lists, list[start:])
+
+ totalLen := 0
+ for _, l := range lists {
+ totalLen += len(l)
+ }
+ if totalLen != len(list) {
+ panic(fmt.Errorf("Failed breaking up list, %d != %d", len(list), totalLen))
+ }
+ return lists, nil
+}
diff --git a/cc/cc.go b/cc/cc.go
new file mode 100644
index 0000000..e9d3884
--- /dev/null
+++ b/cc/cc.go
@@ -0,0 +1,1904 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package cc
+
+// This file contains the module types for compiling C/C++ for Android, and converts the properties
+// into the flags and filenames necessary to pass to the compiler. The final creation of the rules
+// is handled in builder.go
+
+import (
+ "fmt"
+ "path/filepath"
+ "runtime"
+ "strings"
+
+ "github.com/google/blueprint"
+ "github.com/google/blueprint/pathtools"
+
+ "android/soong"
+ "android/soong/common"
+ "android/soong/genrule"
+)
+
+func init() {
+ soong.RegisterModuleType("cc_library_static", CCLibraryStaticFactory)
+ soong.RegisterModuleType("cc_library_shared", CCLibrarySharedFactory)
+ soong.RegisterModuleType("cc_library", CCLibraryFactory)
+ soong.RegisterModuleType("cc_object", CCObjectFactory)
+ soong.RegisterModuleType("cc_binary", CCBinaryFactory)
+ soong.RegisterModuleType("cc_test", CCTestFactory)
+ soong.RegisterModuleType("cc_benchmark", CCBenchmarkFactory)
+
+ soong.RegisterModuleType("toolchain_library", ToolchainLibraryFactory)
+ soong.RegisterModuleType("ndk_prebuilt_library", NdkPrebuiltLibraryFactory)
+ soong.RegisterModuleType("ndk_prebuilt_object", NdkPrebuiltObjectFactory)
+ soong.RegisterModuleType("ndk_prebuilt_static_stl", NdkPrebuiltStaticStlFactory)
+ soong.RegisterModuleType("ndk_prebuilt_shared_stl", NdkPrebuiltSharedStlFactory)
+
+ soong.RegisterModuleType("cc_library_host_static", CCLibraryHostStaticFactory)
+ soong.RegisterModuleType("cc_library_host_shared", CCLibraryHostSharedFactory)
+ soong.RegisterModuleType("cc_binary_host", CCBinaryHostFactory)
+ soong.RegisterModuleType("cc_test_host", CCTestHostFactory)
+ soong.RegisterModuleType("cc_benchmark_host", CCBenchmarkHostFactory)
+
+ // LinkageMutator must be registered after common.ArchMutator, but that is guaranteed by
+ // the Go initialization order because this package depends on common, so common's init
+ // functions will run first.
+ soong.RegisterEarlyMutator("link", LinkageMutator)
+ soong.RegisterEarlyMutator("test_per_src", TestPerSrcMutator)
+}
+
+var (
+ HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", common.Config.PrebuiltOS)
+ SrcDir = pctx.VariableConfigMethod("SrcDir", common.Config.SrcDir)
+
+ LibcRoot = pctx.StaticVariable("LibcRoot", "${SrcDir}/bionic/libc")
+ LibmRoot = pctx.StaticVariable("LibmRoot", "${SrcDir}/bionic/libm")
+)
+
+// Flags used by lots of devices. Putting them in package static variables will save bytes in
+// build.ninja so they aren't repeated for every file
+var (
+ commonGlobalCflags = []string{
+ "-DANDROID",
+ "-fmessage-length=0",
+ "-W",
+ "-Wall",
+ "-Wno-unused",
+ "-Winit-self",
+ "-Wpointer-arith",
+
+ // COMMON_RELEASE_CFLAGS
+ "-DNDEBUG",
+ "-UDEBUG",
+ }
+
+ deviceGlobalCflags = []string{
+ // TARGET_ERROR_FLAGS
+ "-Werror=return-type",
+ "-Werror=non-virtual-dtor",
+ "-Werror=address",
+ "-Werror=sequence-point",
+ }
+
+ hostGlobalCflags = []string{}
+
+ commonGlobalCppflags = []string{
+ "-Wsign-promo",
+ "-std=gnu++11",
+ }
+)
+
+func init() {
+ pctx.StaticVariable("commonGlobalCflags", strings.Join(commonGlobalCflags, " "))
+ pctx.StaticVariable("deviceGlobalCflags", strings.Join(deviceGlobalCflags, " "))
+ pctx.StaticVariable("hostGlobalCflags", strings.Join(hostGlobalCflags, " "))
+
+ pctx.StaticVariable("commonGlobalCppflags", strings.Join(commonGlobalCppflags, " "))
+
+ pctx.StaticVariable("commonClangGlobalCflags",
+ strings.Join(clangFilterUnknownCflags(commonGlobalCflags), " "))
+ pctx.StaticVariable("deviceClangGlobalCflags",
+ strings.Join(clangFilterUnknownCflags(deviceGlobalCflags), " "))
+ pctx.StaticVariable("hostClangGlobalCflags",
+ strings.Join(clangFilterUnknownCflags(hostGlobalCflags), " "))
+ pctx.StaticVariable("commonClangGlobalCppflags",
+ strings.Join(clangFilterUnknownCflags(commonGlobalCppflags), " "))
+
+ // Everything in this list is a crime against abstraction and dependency tracking.
+ // Do not add anything to this list.
+ pctx.StaticVariable("commonGlobalIncludes", strings.Join([]string{
+ "-isystem ${SrcDir}/system/core/include",
+ "-isystem ${SrcDir}/hardware/libhardware/include",
+ "-isystem ${SrcDir}/hardware/libhardware_legacy/include",
+ "-isystem ${SrcDir}/hardware/ril/include",
+ "-isystem ${SrcDir}/libnativehelper/include",
+ "-isystem ${SrcDir}/frameworks/native/include",
+ "-isystem ${SrcDir}/frameworks/native/opengl/include",
+ "-isystem ${SrcDir}/frameworks/av/include",
+ "-isystem ${SrcDir}/frameworks/base/include",
+ }, " "))
+
+ pctx.StaticVariable("clangPath", "${SrcDir}/prebuilts/clang/${HostPrebuiltTag}/host/3.6/bin/")
+}
+
+// Building C/C++ code is handled by objects that satisfy this interface via composition
+type CCModuleType interface {
+ common.AndroidModule
+
+ // Modify property values after parsing Blueprints file but before starting dependency
+ // resolution or build rule generation
+ ModifyProperties(common.AndroidBaseContext)
+
+ // Modify the ccFlags
+ flags(common.AndroidModuleContext, CCFlags) CCFlags
+
+ // Return list of dependency names for use in AndroidDynamicDependencies and in depsToPaths
+ depNames(common.AndroidBaseContext, CCDeps) CCDeps
+
+ // Compile objects into final module
+ compileModule(common.AndroidModuleContext, CCFlags, CCDeps, []string)
+
+ // Install the built module.
+ installModule(common.AndroidModuleContext, CCFlags)
+
+ // Return the output file (.o, .a or .so) for use by other modules
+ outputFile() string
+}
+
+type CCDeps struct {
+ StaticLibs, SharedLibs, LateStaticLibs, WholeStaticLibs, ObjFiles, Cflags []string
+
+ WholeStaticLibObjFiles []string
+
+ CrtBegin, CrtEnd string
+}
+
+type CCFlags struct {
+ GlobalFlags []string // Flags that apply to C, C++, and assembly source files
+ AsFlags []string // Flags that apply to assembly source files
+ CFlags []string // Flags that apply to C and C++ source files
+ ConlyFlags []string // Flags that apply to C source files
+ CppFlags []string // Flags that apply to C++ source files
+ YaccFlags []string // Flags that apply to Yacc source files
+ LdFlags []string // Flags that apply to linker command lines
+
+ Nocrt bool
+ Toolchain Toolchain
+ Clang bool
+}
+
+// Properties used to compile all C or C++ modules
+type CCBaseProperties struct {
+ // list of source files used to compile the C/C++ module. May be .c, .cpp, or .S files.
+ Srcs []string `android:"arch_variant"`
+
+ // list of source files that should not be used to build the C/C++ module.
+ // This is most useful in the arch/multilib variants to remove non-common files
+ Exclude_srcs []string `android:"arch_variant"`
+
+ // list of module-specific flags that will be used for C and C++ compiles.
+ Cflags []string `android:"arch_variant"`
+
+ // list of module-specific flags that will be used for C++ compiles
+ Cppflags []string `android:"arch_variant"`
+
+ // list of module-specific flags that will be used for C compiles
+ Conlyflags []string `android:"arch_variant"`
+
+ // list of module-specific flags that will be used for .S compiles
+ Asflags []string `android:"arch_variant"`
+
+ // list of module-specific flags that will be used for .y and .yy compiles
+ Yaccflags []string
+
+ // list of module-specific flags that will be used for all link steps
+ Ldflags []string `android:"arch_variant"`
+
+ // the instruction set architecture to use to compile the C/C++
+ // module.
+ Instruction_set string `android:"arch_variant"`
+
+ // list of directories relative to the root of the source tree that will
+ // be added to the include path using -I.
+ // If possible, don't use this. If adding paths from the current directory use
+ // local_include_dirs, if adding paths from other modules use export_include_dirs in
+ // that module.
+ Include_dirs []string `android:"arch_variant"`
+
+ // list of directories relative to the Blueprints file that will
+ // be added to the include path using -I
+ Local_include_dirs []string `android:"arch_variant"`
+
+ // list of directories relative to the Blueprints file that will
+ // be added to the include path using -I for any module that links against this module
+ Export_include_dirs []string `android:"arch_variant"`
+
+ // list of module-specific flags that will be used for C and C++ compiles when
+ // compiling with clang
+ Clang_cflags []string `android:"arch_variant"`
+
+ // list of module-specific flags that will be used for .S compiles when
+ // compiling with clang
+ Clang_asflags []string `android:"arch_variant"`
+
+ // list of system libraries that will be dynamically linked to
+ // shared library and executable modules. If unset, generally defaults to libc
+ // and libm. Set to [] to prevent linking against libc and libm.
+ System_shared_libs []string
+
+ // list of modules whose object files should be linked into this module
+ // in their entirety. For static library modules, all of the .o files from the intermediate
+ // directory of the dependency will be linked into this modules .a file. For a shared library,
+ // the dependency's .a file will be linked into this module using -Wl,--whole-archive.
+ Whole_static_libs []string `android:"arch_variant"`
+
+ // list of modules that should be statically linked into this module.
+ Static_libs []string `android:"arch_variant"`
+
+ // list of modules that should be dynamically linked into this module.
+ Shared_libs []string `android:"arch_variant"`
+
+ // allow the module to contain undefined symbols. By default,
+ // modules cannot contain undefined symbols that are not satisified by their immediate
+ // dependencies. Set this flag to true to remove --no-undefined from the linker flags.
+ // This flag should only be necessary for compiling low-level libraries like libc.
+ Allow_undefined_symbols bool
+
+ // don't link in crt_begin and crt_end. This flag should only be necessary for
+ // compiling crt or libc.
+ Nocrt bool `android:"arch_variant"`
+
+ // don't insert default compiler flags into asflags, cflags,
+ // cppflags, conlyflags, ldflags, or include_dirs
+ No_default_compiler_flags bool
+
+ // compile module with clang instead of gcc
+ Clang bool `android:"arch_variant"`
+
+ // pass -frtti instead of -fno-rtti
+ Rtti bool
+
+ // -l arguments to pass to linker for host-provided shared libraries
+ Host_ldlibs []string `android:"arch_variant"`
+
+ // select the STL library to use. Possible values are "libc++", "libc++_static",
+ // "stlport", "stlport_static", "ndk", "libstdc++", or "none". Leave blank to select the
+ // default
+ Stl string
+
+ // Set for combined shared/static libraries to prevent compiling object files a second time
+ SkipCompileObjs bool `blueprint:"mutated"`
+
+ Debug, Release struct {
+ // list of module-specific flags that will be used for C and C++ compiles in debug or
+ // release builds
+ Cflags []string `android:"arch_variant"`
+ } `android:"arch_variant"`
+
+ // Minimum sdk version supported when compiling against the ndk
+ Sdk_version string
+
+ // install to a subdirectory of the default install path for the module
+ Relative_install_path string
+}
+
+// CCBase contains the properties and members used by all C/C++ module types, and implements
+// the blueprint.Module interface. It expects to be embedded into an outer specialization struct,
+// and uses a ccModuleType interface to that struct to create the build steps.
+type CCBase struct {
+ common.AndroidModuleBase
+ module CCModuleType
+
+ Properties CCBaseProperties
+
+ unused struct {
+ Asan bool
+ Native_coverage bool
+ Strip string
+ Tags []string
+ Required []string
+ }
+
+ installPath string
+
+ savedDepNames CCDeps
+}
+
+func newCCBase(base *CCBase, module CCModuleType, hod common.HostOrDeviceSupported,
+ multilib common.Multilib, props ...interface{}) (blueprint.Module, []interface{}) {
+
+ base.module = module
+
+ props = append(props, &base.Properties, &base.unused)
+
+ return common.InitAndroidArchModule(module, hod, multilib, props...)
+}
+
+func (c *CCBase) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) {
+ toolchain := c.findToolchain(ctx)
+ if ctx.Failed() {
+ return
+ }
+
+ flags := c.collectFlags(ctx, toolchain)
+ if ctx.Failed() {
+ return
+ }
+
+ deps := c.depsToPaths(ctx, c.savedDepNames)
+ if ctx.Failed() {
+ return
+ }
+
+ flags.CFlags = append(flags.CFlags, deps.Cflags...)
+
+ objFiles := c.compileObjs(ctx, flags)
+ if ctx.Failed() {
+ return
+ }
+
+ generatedObjFiles := c.compileGeneratedObjs(ctx, flags)
+ if ctx.Failed() {
+ return
+ }
+
+ objFiles = append(objFiles, generatedObjFiles...)
+
+ c.ccModuleType().compileModule(ctx, flags, deps, objFiles)
+ if ctx.Failed() {
+ return
+ }
+
+ c.ccModuleType().installModule(ctx, flags)
+ if ctx.Failed() {
+ return
+ }
+}
+
+func (c *CCBase) ccModuleType() CCModuleType {
+ return c.module
+}
+
+var _ common.AndroidDynamicDepender = (*CCBase)(nil)
+
+func (c *CCBase) findToolchain(ctx common.AndroidModuleContext) Toolchain {
+ arch := ctx.Arch()
+ hod := ctx.HostOrDevice()
+ factory := toolchainFactories[hod][arch.ArchType]
+ if factory == nil {
+ panic(fmt.Sprintf("Toolchain not found for %s arch %q",
+ hod.String(), arch.String()))
+ }
+ return factory(arch.ArchVariant, arch.CpuVariant)
+}
+
+func (c *CCBase) ModifyProperties(ctx common.AndroidBaseContext) {
+}
+
+func (c *CCBase) depNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps {
+ depNames.WholeStaticLibs = append(depNames.WholeStaticLibs, c.Properties.Whole_static_libs...)
+ depNames.StaticLibs = append(depNames.StaticLibs, c.Properties.Static_libs...)
+ depNames.SharedLibs = append(depNames.SharedLibs, c.Properties.Shared_libs...)
+
+ return depNames
+}
+
+func (c *CCBase) AndroidDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string {
+ c.module.ModifyProperties(ctx)
+
+ c.savedDepNames = c.module.depNames(ctx, CCDeps{})
+ c.savedDepNames.WholeStaticLibs = lastUniqueElements(c.savedDepNames.WholeStaticLibs)
+ c.savedDepNames.StaticLibs = lastUniqueElements(c.savedDepNames.StaticLibs)
+ c.savedDepNames.SharedLibs = lastUniqueElements(c.savedDepNames.SharedLibs)
+
+ staticLibs := c.savedDepNames.WholeStaticLibs
+ staticLibs = append(staticLibs, c.savedDepNames.StaticLibs...)
+ staticLibs = append(staticLibs, c.savedDepNames.LateStaticLibs...)
+ ctx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, staticLibs...)
+
+ ctx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, c.savedDepNames.SharedLibs...)
+
+ ret := append([]string(nil), c.savedDepNames.ObjFiles...)
+ if c.savedDepNames.CrtBegin != "" {
+ ret = append(ret, c.savedDepNames.CrtBegin)
+ }
+ if c.savedDepNames.CrtEnd != "" {
+ ret = append(ret, c.savedDepNames.CrtEnd)
+ }
+
+ return ret
+}
+
+// Create a ccFlags struct that collects the compile flags from global values,
+// per-target values, module type values, and per-module Blueprints properties
+func (c *CCBase) collectFlags(ctx common.AndroidModuleContext, toolchain Toolchain) CCFlags {
+ flags := CCFlags{
+ CFlags: c.Properties.Cflags,
+ CppFlags: c.Properties.Cppflags,
+ ConlyFlags: c.Properties.Conlyflags,
+ LdFlags: c.Properties.Ldflags,
+ AsFlags: c.Properties.Asflags,
+ YaccFlags: c.Properties.Yaccflags,
+ Nocrt: c.Properties.Nocrt,
+ Toolchain: toolchain,
+ Clang: c.Properties.Clang,
+ }
+
+ // Include dir cflags
+ common.CheckSrcDirsExist(ctx, c.Properties.Include_dirs, "include_dirs")
+ common.CheckModuleSrcDirsExist(ctx, c.Properties.Local_include_dirs, "local_include_dirs")
+
+ rootIncludeDirs := pathtools.PrefixPaths(c.Properties.Include_dirs, ctx.AConfig().SrcDir())
+ localIncludeDirs := pathtools.PrefixPaths(c.Properties.Local_include_dirs, common.ModuleSrcDir(ctx))
+ flags.GlobalFlags = append(flags.GlobalFlags,
+ includeDirsToFlags(rootIncludeDirs),
+ includeDirsToFlags(localIncludeDirs))
+
+ if !c.Properties.No_default_compiler_flags {
+ if c.Properties.Sdk_version == "" || ctx.Host() {
+ flags.GlobalFlags = append(flags.GlobalFlags,
+ "${commonGlobalIncludes}",
+ toolchain.IncludeFlags(),
+ "-I${SrcDir}/libnativehelper/include/nativehelper")
+ }
+
+ flags.GlobalFlags = append(flags.GlobalFlags, []string{
+ "-I" + common.ModuleSrcDir(ctx),
+ "-I" + common.ModuleOutDir(ctx),
+ "-I" + common.ModuleGenDir(ctx),
+ }...)
+ }
+
+ instructionSet := c.Properties.Instruction_set
+ instructionSetFlags, err := toolchain.InstructionSetFlags(instructionSet)
+ if err != nil {
+ ctx.ModuleErrorf("%s", err)
+ }
+
+ // TODO: debug
+ flags.CFlags = append(flags.CFlags, c.Properties.Release.Cflags...)
+
+ if ctx.Host() && !ctx.ContainsProperty("clang") {
+ flags.Clang = true
+ }
+
+ if flags.Clang {
+ flags.CFlags = clangFilterUnknownCflags(flags.CFlags)
+ flags.CFlags = append(flags.CFlags, c.Properties.Clang_cflags...)
+ flags.AsFlags = append(flags.AsFlags, c.Properties.Clang_asflags...)
+ flags.CppFlags = clangFilterUnknownCflags(flags.CppFlags)
+ flags.ConlyFlags = clangFilterUnknownCflags(flags.ConlyFlags)
+ flags.LdFlags = clangFilterUnknownCflags(flags.LdFlags)
+
+ flags.CFlags = append(flags.CFlags, "${clangExtraCflags}")
+ flags.ConlyFlags = append(flags.ConlyFlags, "${clangExtraConlyflags}")
+ if ctx.Device() {
+ flags.CFlags = append(flags.CFlags, "${clangExtraTargetCflags}")
+ }
+
+ target := "-target " + toolchain.ClangTriple()
+ gccPrefix := "-B" + filepath.Join(toolchain.GccRoot(), toolchain.GccTriple(), "bin")
+
+ flags.CFlags = append(flags.CFlags, target, gccPrefix)
+ flags.AsFlags = append(flags.AsFlags, target, gccPrefix)
+ flags.LdFlags = append(flags.LdFlags, target, gccPrefix)
+ }
+
+ if !c.Properties.No_default_compiler_flags {
+ if ctx.Device() && !c.Properties.Allow_undefined_symbols {
+ flags.LdFlags = append(flags.LdFlags, "-Wl,--no-undefined")
+ }
+
+ flags.GlobalFlags = append(flags.GlobalFlags, instructionSetFlags)
+
+ if flags.Clang {
+ flags.CppFlags = append(flags.CppFlags, "${commonClangGlobalCppflags}")
+ flags.GlobalFlags = append(flags.GlobalFlags,
+ toolchain.ClangCflags(),
+ "${commonClangGlobalCflags}",
+ fmt.Sprintf("${%sClangGlobalCflags}", ctx.HostOrDevice()))
+ } else {
+ flags.CppFlags = append(flags.CppFlags, "${commonGlobalCppflags}")
+ flags.GlobalFlags = append(flags.GlobalFlags,
+ toolchain.Cflags(),
+ "${commonGlobalCflags}",
+ fmt.Sprintf("${%sGlobalCflags}", ctx.HostOrDevice()))
+ }
+
+ if ctx.Device() {
+ if c.Properties.Rtti {
+ flags.CppFlags = append(flags.CppFlags, "-frtti")
+ } else {
+ flags.CppFlags = append(flags.CppFlags, "-fno-rtti")
+ }
+ }
+
+ flags.AsFlags = append(flags.AsFlags, "-D__ASSEMBLY__")
+
+ if flags.Clang {
+ flags.CppFlags = append(flags.CppFlags, toolchain.ClangCppflags())
+ flags.LdFlags = append(flags.LdFlags, toolchain.ClangLdflags())
+ } else {
+ flags.CppFlags = append(flags.CppFlags, toolchain.Cppflags())
+ flags.LdFlags = append(flags.LdFlags, toolchain.Ldflags())
+ }
+
+ if ctx.Host() {
+ flags.LdFlags = append(flags.LdFlags, c.Properties.Host_ldlibs...)
+ }
+ }
+
+ flags = c.ccModuleType().flags(ctx, flags)
+
+ // Optimization to reduce size of build.ninja
+ // Replace the long list of flags for each file with a module-local variable
+ ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
+ ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
+ ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
+ flags.CFlags = []string{"$cflags"}
+ flags.CppFlags = []string{"$cppflags"}
+ flags.AsFlags = []string{"$asflags"}
+
+ return flags
+}
+
+func (c *CCBase) flags(ctx common.AndroidModuleContext, flags CCFlags) CCFlags {
+ return flags
+}
+
+// Compile a list of source files into objects a specified subdirectory
+func (c *CCBase) customCompileObjs(ctx common.AndroidModuleContext, flags CCFlags,
+ subdir string, srcFiles, excludes []string) []string {
+
+ buildFlags := ccFlagsToBuilderFlags(flags)
+
+ srcFiles = ctx.ExpandSources(srcFiles, excludes)
+ srcFiles, deps := genSources(ctx, srcFiles, buildFlags)
+
+ return TransformSourceToObj(ctx, subdir, srcFiles, buildFlags, deps)
+}
+
+// Compile files listed in c.Properties.Srcs into objects
+func (c *CCBase) compileObjs(ctx common.AndroidModuleContext, flags CCFlags) []string {
+
+ if c.Properties.SkipCompileObjs {
+ return nil
+ }
+
+ return c.customCompileObjs(ctx, flags, "", c.Properties.Srcs, c.Properties.Exclude_srcs)
+}
+
+// Compile generated source files from dependencies
+func (c *CCBase) compileGeneratedObjs(ctx common.AndroidModuleContext, flags CCFlags) []string {
+ var srcs []string
+
+ if c.Properties.SkipCompileObjs {
+ return nil
+ }
+
+ ctx.VisitDirectDeps(func(module blueprint.Module) {
+ if gen, ok := module.(genrule.SourceFileGenerator); ok {
+ srcs = append(srcs, gen.GeneratedSourceFiles()...)
+ }
+ })
+
+ if len(srcs) == 0 {
+ return nil
+ }
+
+ return TransformSourceToObj(ctx, "", srcs, ccFlagsToBuilderFlags(flags), nil)
+}
+
+func (c *CCBase) outputFile() string {
+ return ""
+}
+
+func (c *CCBase) depsToPathsFromList(ctx common.AndroidModuleContext,
+ names []string) (modules []common.AndroidModule,
+ outputFiles []string, exportedFlags []string) {
+
+ for _, n := range names {
+ found := false
+ ctx.VisitDirectDeps(func(m blueprint.Module) {
+ otherName := ctx.OtherModuleName(m)
+ if otherName != n {
+ return
+ }
+
+ if a, ok := m.(CCModuleType); ok {
+ if a.Disabled() {
+ // If a cc_library host+device module depends on a library that exists as both
+ // cc_library_shared and cc_library_host_shared, it will end up with two
+ // dependencies with the same name, one of which is marked disabled for each
+ // of host and device. Ignore the disabled one.
+ return
+ }
+ if a.HostOrDevice() != ctx.HostOrDevice() {
+ ctx.ModuleErrorf("host/device mismatch between %q and %q", ctx.ModuleName(),
+ otherName)
+ return
+ }
+
+ if outputFile := a.outputFile(); outputFile != "" {
+ if found {
+ ctx.ModuleErrorf("multiple modules satisified dependency on %q", otherName)
+ return
+ }
+ outputFiles = append(outputFiles, outputFile)
+ modules = append(modules, a)
+ if i, ok := a.(ccExportedFlagsProducer); ok {
+ exportedFlags = append(exportedFlags, i.exportedFlags()...)
+ }
+ found = true
+ } else {
+ ctx.ModuleErrorf("module %q missing output file", otherName)
+ return
+ }
+ } else {
+ ctx.ModuleErrorf("module %q not an android module", otherName)
+ return
+ }
+ })
+ if !found {
+ ctx.ModuleErrorf("unsatisified dependency on %q", n)
+ }
+ }
+
+ return modules, outputFiles, exportedFlags
+}
+
+// Convert depenedency names to paths. Takes a CCDeps containing names and returns a CCDeps
+// containing paths
+func (c *CCBase) depsToPaths(ctx common.AndroidModuleContext, depNames CCDeps) CCDeps {
+ var depPaths CCDeps
+ var newCflags []string
+
+ var wholeStaticLibModules []common.AndroidModule
+
+ wholeStaticLibModules, depPaths.WholeStaticLibs, newCflags =
+ c.depsToPathsFromList(ctx, depNames.WholeStaticLibs)
+ depPaths.Cflags = append(depPaths.Cflags, newCflags...)
+
+ for _, m := range wholeStaticLibModules {
+ if staticLib, ok := m.(ccLibraryInterface); ok && staticLib.static() {
+ depPaths.WholeStaticLibObjFiles =
+ append(depPaths.WholeStaticLibObjFiles, staticLib.allObjFiles()...)
+ } else {
+ ctx.ModuleErrorf("module %q not a static library", ctx.OtherModuleName(m))
+ }
+ }
+
+ _, depPaths.StaticLibs, newCflags = c.depsToPathsFromList(ctx, depNames.StaticLibs)
+ depPaths.Cflags = append(depPaths.Cflags, newCflags...)
+
+ _, depPaths.LateStaticLibs, newCflags = c.depsToPathsFromList(ctx, depNames.LateStaticLibs)
+ depPaths.Cflags = append(depPaths.Cflags, newCflags...)
+
+ _, depPaths.SharedLibs, newCflags = c.depsToPathsFromList(ctx, depNames.SharedLibs)
+ depPaths.Cflags = append(depPaths.Cflags, newCflags...)
+
+ ctx.VisitDirectDeps(func(m blueprint.Module) {
+ if obj, ok := m.(ccObjectProvider); ok {
+ otherName := ctx.OtherModuleName(m)
+ if otherName == depNames.CrtBegin {
+ if !c.Properties.Nocrt {
+ depPaths.CrtBegin = obj.object().outputFile()
+ }
+ } else if otherName == depNames.CrtEnd {
+ if !c.Properties.Nocrt {
+ depPaths.CrtEnd = obj.object().outputFile()
+ }
+ } else {
+ depPaths.ObjFiles = append(depPaths.ObjFiles, obj.object().outputFile())
+ }
+ }
+ })
+
+ return depPaths
+}
+
+type ccLinkedProperties struct {
+ VariantIsShared bool `blueprint:"mutated"`
+ VariantIsStatic bool `blueprint:"mutated"`
+ VariantIsStaticBinary bool `blueprint:"mutated"`
+}
+
+// CCLinked contains the properties and members used by libraries and executables
+type CCLinked struct {
+ CCBase
+ dynamicProperties ccLinkedProperties
+}
+
+func newCCDynamic(dynamic *CCLinked, module CCModuleType, hod common.HostOrDeviceSupported,
+ multilib common.Multilib, props ...interface{}) (blueprint.Module, []interface{}) {
+
+ props = append(props, &dynamic.dynamicProperties)
+
+ return newCCBase(&dynamic.CCBase, module, hod, multilib, props...)
+}
+
+func (c *CCLinked) systemSharedLibs(ctx common.AndroidBaseContext) []string {
+ if ctx.ContainsProperty("system_shared_libs") {
+ return c.Properties.System_shared_libs
+ } else if ctx.Device() && c.Properties.Sdk_version == "" {
+ return []string{"libc", "libm"}
+ } else {
+ return nil
+ }
+}
+
+func (c *CCLinked) stl(ctx common.AndroidBaseContext) string {
+ if c.Properties.Sdk_version != "" && ctx.Device() {
+ switch c.Properties.Stl {
+ case "":
+ return "ndk_system"
+ case "c++_shared", "c++_static",
+ "stlport_shared", "stlport_static",
+ "gnustl_static":
+ return "ndk_lib" + c.Properties.Stl
+ default:
+ ctx.ModuleErrorf("stl: %q is not a supported STL with sdk_version set", c.Properties.Stl)
+ return ""
+ }
+ }
+
+ switch c.Properties.Stl {
+ case "libc++", "libc++_static",
+ "stlport", "stlport_static",
+ "libstdc++":
+ return c.Properties.Stl
+ case "none":
+ return ""
+ case "":
+ if c.static() {
+ return "libc++_static"
+ } else {
+ return "libc++" // TODO: mingw needs libstdc++
+ }
+ default:
+ ctx.ModuleErrorf("stl: %q is not a supported STL", c.Properties.Stl)
+ return ""
+ }
+}
+
+var hostDynamicGccLibs, hostStaticGccLibs []string
+
+func init() {
+ if runtime.GOOS == "darwin" {
+ hostDynamicGccLibs = []string{"-lc", "-lSystem"}
+ hostStaticGccLibs = []string{"NO_STATIC_HOST_BINARIES_ON_DARWIN"}
+ } else {
+ hostDynamicGccLibs = []string{"-lgcc_s", "-lgcc", "-lc", "-lgcc_s", "-lgcc"}
+ hostStaticGccLibs = []string{"-Wl,--start-group", "-lgcc", "-lgcc_eh", "-lc", "-Wl,--end-group"}
+ }
+}
+
+func (c *CCLinked) flags(ctx common.AndroidModuleContext, flags CCFlags) CCFlags {
+ stl := c.stl(ctx)
+ if ctx.Failed() {
+ return flags
+ }
+
+ switch stl {
+ case "libc++", "libc++_static":
+ flags.CFlags = append(flags.CFlags, "-D_USING_LIBCXX")
+ flags.CFlags = append(flags.CFlags, "-I${SrcDir}/external/libcxx/include")
+ if ctx.Host() {
+ flags.CppFlags = append(flags.CppFlags, "-nostdinc++")
+ flags.LdFlags = append(flags.LdFlags, "-nodefaultlibs")
+ flags.LdFlags = append(flags.LdFlags, "-lm", "-lpthread")
+ if c.staticBinary() {
+ flags.LdFlags = append(flags.LdFlags, hostStaticGccLibs...)
+ } else {
+ flags.LdFlags = append(flags.LdFlags, hostDynamicGccLibs...)
+ }
+ }
+ case "stlport", "stlport_static":
+ if ctx.Device() {
+ flags.CFlags = append(flags.CFlags,
+ "-I${SrcDir}/external/stlport/stlport",
+ "-I${SrcDir}/bionic/libstdc++/include",
+ "-I${SrcDir}/bionic")
+ }
+ case "libstdc++":
+ // Using bionic's basic libstdc++. Not actually an STL. Only around until the
+ // tree is in good enough shape to not need it.
+ // Host builds will use GNU libstdc++.
+ if ctx.Device() {
+ flags.CFlags = append(flags.CFlags, "-I${SrcDir}/bionic/libstdc++/include")
+ }
+ case "ndk_system":
+ ndkSrcRoot := ctx.AConfig().SrcDir() + "/prebuilts/ndk/current/sources/"
+ flags.CFlags = append(flags.CFlags, "-isystem "+ndkSrcRoot+"cxx-stl/system/include")
+ case "ndk_libc++_shared", "ndk_libc++_static":
+ // TODO(danalbert): This really shouldn't be here...
+ flags.CppFlags = append(flags.CppFlags, "-std=c++11")
+ case "ndk_libstlport_shared", "ndk_libstlport_static", "ndk_libgnustl_static":
+ // Nothing
+ case "":
+ // None or error.
+ if ctx.Host() {
+ flags.CppFlags = append(flags.CppFlags, "-nostdinc++")
+ flags.LdFlags = append(flags.LdFlags, "-nodefaultlibs")
+ if c.staticBinary() {
+ flags.LdFlags = append(flags.LdFlags, hostStaticGccLibs...)
+ } else {
+ flags.LdFlags = append(flags.LdFlags, hostDynamicGccLibs...)
+ }
+ }
+ default:
+ panic(fmt.Errorf("Unknown stl in CCLinked.Flags: %q", stl))
+ }
+
+ return flags
+}
+
+func (c *CCLinked) depNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps {
+ depNames = c.CCBase.depNames(ctx, depNames)
+
+ stl := c.stl(ctx)
+ if ctx.Failed() {
+ return depNames
+ }
+
+ switch stl {
+ case "libstdc++":
+ if ctx.Device() {
+ depNames.SharedLibs = append(depNames.SharedLibs, stl)
+ }
+ case "libc++", "libc++_static":
+ if stl == "libc++" {
+ depNames.SharedLibs = append(depNames.SharedLibs, stl)
+ } else {
+ depNames.StaticLibs = append(depNames.StaticLibs, stl)
+ }
+ if ctx.Device() {
+ if ctx.Arch().ArchType == common.Arm {
+ depNames.StaticLibs = append(depNames.StaticLibs, "libunwind_llvm")
+ }
+ if c.staticBinary() {
+ depNames.StaticLibs = append(depNames.StaticLibs, "libdl")
+ } else {
+ depNames.SharedLibs = append(depNames.SharedLibs, "libdl")
+ }
+ }
+ case "stlport":
+ depNames.SharedLibs = append(depNames.SharedLibs, "libstdc++", "libstlport")
+ case "stlport_static":
+ depNames.StaticLibs = append(depNames.StaticLibs, "libstdc++", "libstlport_static")
+ case "":
+ // None or error.
+ case "ndk_system":
+ // TODO: Make a system STL prebuilt for the NDK.
+ // The system STL doesn't have a prebuilt (it uses the system's libstdc++), but it does have
+ // its own includes. The includes are handled in CCBase.Flags().
+ depNames.SharedLibs = append([]string{"libstdc++"}, depNames.SharedLibs...)
+ case "ndk_libc++_shared", "ndk_libstlport_shared":
+ depNames.SharedLibs = append(depNames.SharedLibs, stl)
+ case "ndk_libc++_static", "ndk_libstlport_static", "ndk_libgnustl_static":
+ depNames.StaticLibs = append(depNames.StaticLibs, stl)
+ default:
+ panic(fmt.Errorf("Unknown stl in CCLinked.depNames: %q", stl))
+ }
+
+ if ctx.ModuleName() != "libcompiler_rt-extras" {
+ depNames.StaticLibs = append(depNames.StaticLibs, "libcompiler_rt-extras")
+ }
+
+ if ctx.Device() {
+ // libgcc and libatomic have to be last on the command line
+ depNames.LateStaticLibs = append(depNames.LateStaticLibs, "libgcov", "libatomic", "libgcc")
+
+ if !c.static() {
+ depNames.SharedLibs = append(depNames.SharedLibs, c.systemSharedLibs(ctx)...)
+ }
+
+ if c.Properties.Sdk_version != "" {
+ version := c.Properties.Sdk_version
+ depNames.SharedLibs = append(depNames.SharedLibs,
+ "ndk_libc."+version,
+ "ndk_libm."+version,
+ )
+ }
+ }
+
+ return depNames
+}
+
+// ccLinkedInterface interface is used on ccLinked to deal with static or shared variants
+type ccLinkedInterface interface {
+ // Returns true if the build options for the module have selected a static or shared build
+ buildStatic() bool
+ buildShared() bool
+
+ // Sets whether a specific variant is static or shared
+ setStatic(bool)
+
+ // Returns whether a specific variant is a static library or binary
+ static() bool
+
+ // Returns whether a module is a static binary
+ staticBinary() bool
+}
+
+var _ ccLinkedInterface = (*CCLibrary)(nil)
+var _ ccLinkedInterface = (*CCBinary)(nil)
+
+func (c *CCLinked) static() bool {
+ return c.dynamicProperties.VariantIsStatic
+}
+
+func (c *CCLinked) staticBinary() bool {
+ return c.dynamicProperties.VariantIsStaticBinary
+}
+
+func (c *CCLinked) setStatic(static bool) {
+ c.dynamicProperties.VariantIsStatic = static
+}
+
+type ccExportedFlagsProducer interface {
+ exportedFlags() []string
+}
+
+//
+// Combined static+shared libraries
+//
+
+type CCLibraryProperties struct {
+ BuildStatic bool `blueprint:"mutated"`
+ BuildShared bool `blueprint:"mutated"`
+ Static struct {
+ Srcs []string `android:"arch_variant"`
+ Exclude_srcs []string `android:"arch_variant"`
+ Cflags []string `android:"arch_variant"`
+ Whole_static_libs []string `android:"arch_variant"`
+ Static_libs []string `android:"arch_variant"`
+ Shared_libs []string `android:"arch_variant"`
+ } `android:"arch_variant"`
+ Shared struct {
+ Srcs []string `android:"arch_variant"`
+ Exclude_srcs []string `android:"arch_variant"`
+ Cflags []string `android:"arch_variant"`
+ Whole_static_libs []string `android:"arch_variant"`
+ Static_libs []string `android:"arch_variant"`
+ Shared_libs []string `android:"arch_variant"`
+ } `android:"arch_variant"`
+
+ // local file name to pass to the linker as --version_script
+ Version_script string `android:"arch_variant"`
+}
+
+type CCLibrary struct {
+ CCLinked
+
+ reuseFrom ccLibraryInterface
+ reuseObjFiles []string
+ objFiles []string
+ exportFlags []string
+ out string
+
+ LibraryProperties CCLibraryProperties
+}
+
+func (c *CCLibrary) buildStatic() bool {
+ return c.LibraryProperties.BuildStatic
+}
+
+func (c *CCLibrary) buildShared() bool {
+ return c.LibraryProperties.BuildShared
+}
+
+type ccLibraryInterface interface {
+ ccLinkedInterface
+ ccLibrary() *CCLibrary
+ setReuseFrom(ccLibraryInterface)
+ getReuseFrom() ccLibraryInterface
+ getReuseObjFiles() []string
+ allObjFiles() []string
+}
+
+var _ ccLibraryInterface = (*CCLibrary)(nil)
+
+func (c *CCLibrary) ccLibrary() *CCLibrary {
+ return c
+}
+
+func NewCCLibrary(library *CCLibrary, module CCModuleType,
+ hod common.HostOrDeviceSupported) (blueprint.Module, []interface{}) {
+
+ return newCCDynamic(&library.CCLinked, module, hod, common.MultilibBoth,
+ &library.LibraryProperties)
+}
+
+func CCLibraryFactory() (blueprint.Module, []interface{}) {
+ module := &CCLibrary{}
+
+ module.LibraryProperties.BuildShared = true
+ module.LibraryProperties.BuildStatic = true
+
+ return NewCCLibrary(module, module, common.HostAndDeviceSupported)
+}
+
+func (c *CCLibrary) depNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps {
+ depNames = c.CCLinked.depNames(ctx, depNames)
+ if c.static() {
+ depNames.WholeStaticLibs = append(depNames.WholeStaticLibs, c.LibraryProperties.Static.Whole_static_libs...)
+ depNames.StaticLibs = append(depNames.StaticLibs, c.LibraryProperties.Static.Static_libs...)
+ depNames.SharedLibs = append(depNames.SharedLibs, c.LibraryProperties.Static.Shared_libs...)
+ } else {
+ if ctx.Device() {
+ if c.Properties.Sdk_version == "" {
+ depNames.CrtBegin = "crtbegin_so"
+ depNames.CrtEnd = "crtend_so"
+ } else {
+ depNames.CrtBegin = "ndk_crtbegin_so." + c.Properties.Sdk_version
+ depNames.CrtEnd = "ndk_crtend_so." + c.Properties.Sdk_version
+ }
+ }
+ depNames.WholeStaticLibs = append(depNames.WholeStaticLibs, c.LibraryProperties.Shared.Whole_static_libs...)
+ depNames.StaticLibs = append(depNames.StaticLibs, c.LibraryProperties.Shared.Static_libs...)
+ depNames.SharedLibs = append(depNames.SharedLibs, c.LibraryProperties.Shared.Shared_libs...)
+ }
+
+ return depNames
+}
+
+func (c *CCLibrary) outputFile() string {
+ return c.out
+}
+
+func (c *CCLibrary) getReuseObjFiles() []string {
+ return c.reuseObjFiles
+}
+
+func (c *CCLibrary) setReuseFrom(reuseFrom ccLibraryInterface) {
+ c.reuseFrom = reuseFrom
+}
+
+func (c *CCLibrary) getReuseFrom() ccLibraryInterface {
+ return c.reuseFrom
+}
+
+func (c *CCLibrary) allObjFiles() []string {
+ return c.objFiles
+}
+
+func (c *CCLibrary) exportedFlags() []string {
+ return c.exportFlags
+}
+
+func (c *CCLibrary) flags(ctx common.AndroidModuleContext, flags CCFlags) CCFlags {
+ flags = c.CCLinked.flags(ctx, flags)
+
+ flags.CFlags = append(flags.CFlags, "-fPIC")
+
+ if c.static() {
+ flags.CFlags = append(flags.CFlags, c.LibraryProperties.Static.Cflags...)
+ } else {
+ flags.CFlags = append(flags.CFlags, c.LibraryProperties.Shared.Cflags...)
+ }
+
+ if !c.static() {
+ libName := ctx.ModuleName()
+ // GCC for Android assumes that -shared means -Bsymbolic, use -Wl,-shared instead
+ sharedFlag := "-Wl,-shared"
+ if c.Properties.Clang || ctx.Host() {
+ sharedFlag = "-shared"
+ }
+ if ctx.Device() {
+ flags.LdFlags = append(flags.LdFlags, "-nostdlib")
+ }
+
+ if ctx.Darwin() {
+ flags.LdFlags = append(flags.LdFlags,
+ "-dynamiclib",
+ "-single_module",
+ //"-read_only_relocs suppress",
+ "-install_name @rpath/"+libName+sharedLibraryExtension,
+ )
+ } else {
+ flags.LdFlags = append(flags.LdFlags,
+ "-Wl,--gc-sections",
+ sharedFlag,
+ "-Wl,-soname,"+libName+sharedLibraryExtension,
+ )
+ }
+ }
+
+ return flags
+}
+
+func (c *CCLibrary) compileStaticLibrary(ctx common.AndroidModuleContext,
+ flags CCFlags, deps CCDeps, objFiles []string) {
+
+ staticFlags := flags
+ objFilesStatic := c.customCompileObjs(ctx, staticFlags, common.DeviceStaticLibrary,
+ c.LibraryProperties.Static.Srcs, c.LibraryProperties.Static.Exclude_srcs)
+
+ objFiles = append(objFiles, objFilesStatic...)
+ objFiles = append(objFiles, deps.WholeStaticLibObjFiles...)
+
+ outputFile := filepath.Join(common.ModuleOutDir(ctx), ctx.ModuleName()+staticLibraryExtension)
+
+ if ctx.Darwin() {
+ TransformDarwinObjToStaticLib(ctx, objFiles, ccFlagsToBuilderFlags(flags), outputFile)
+ } else {
+ TransformObjToStaticLib(ctx, objFiles, ccFlagsToBuilderFlags(flags), outputFile)
+ }
+
+ c.objFiles = objFiles
+ c.out = outputFile
+
+ common.CheckModuleSrcDirsExist(ctx, c.Properties.Export_include_dirs, "export_include_dirs")
+ includeDirs := pathtools.PrefixPaths(c.Properties.Export_include_dirs, common.ModuleSrcDir(ctx))
+ c.exportFlags = []string{includeDirsToFlags(includeDirs)}
+
+ ctx.CheckbuildFile(outputFile)
+}
+
+func (c *CCLibrary) compileSharedLibrary(ctx common.AndroidModuleContext,
+ flags CCFlags, deps CCDeps, objFiles []string) {
+
+ sharedFlags := flags
+ objFilesShared := c.customCompileObjs(ctx, sharedFlags, common.DeviceSharedLibrary,
+ c.LibraryProperties.Shared.Srcs, c.LibraryProperties.Shared.Exclude_srcs)
+
+ objFiles = append(objFiles, objFilesShared...)
+
+ outputFile := filepath.Join(common.ModuleOutDir(ctx), ctx.ModuleName()+sharedLibraryExtension)
+
+ var linkerDeps []string
+
+ if c.LibraryProperties.Version_script != "" {
+ versionScript := filepath.Join(common.ModuleSrcDir(ctx), c.LibraryProperties.Version_script)
+ sharedFlags.LdFlags = append(sharedFlags.LdFlags, "-Wl,--version-script,"+versionScript)
+ linkerDeps = append(linkerDeps, versionScript)
+ }
+
+ TransformObjToDynamicBinary(ctx, objFiles, deps.SharedLibs, deps.StaticLibs,
+ deps.LateStaticLibs, deps.WholeStaticLibs, linkerDeps, deps.CrtBegin, deps.CrtEnd, false,
+ ccFlagsToBuilderFlags(flags), outputFile)
+
+ c.out = outputFile
+ includeDirs := pathtools.PrefixPaths(c.Properties.Export_include_dirs, common.ModuleSrcDir(ctx))
+ c.exportFlags = []string{includeDirsToFlags(includeDirs)}
+}
+
+func (c *CCLibrary) compileModule(ctx common.AndroidModuleContext,
+ flags CCFlags, deps CCDeps, objFiles []string) {
+
+ // Reuse the object files from the matching static library if it exists
+ if c.getReuseFrom().ccLibrary() == c {
+ c.reuseObjFiles = objFiles
+ } else {
+ if c.getReuseFrom().ccLibrary().LibraryProperties.Static.Cflags == nil &&
+ c.LibraryProperties.Shared.Cflags == nil {
+ objFiles = append([]string(nil), c.getReuseFrom().getReuseObjFiles()...)
+ }
+ }
+
+ if c.static() {
+ c.compileStaticLibrary(ctx, flags, deps, objFiles)
+ } else {
+ c.compileSharedLibrary(ctx, flags, deps, objFiles)
+ }
+}
+
+func (c *CCLibrary) installStaticLibrary(ctx common.AndroidModuleContext, flags CCFlags) {
+ // Static libraries do not get installed.
+}
+
+func (c *CCLibrary) installSharedLibrary(ctx common.AndroidModuleContext, flags CCFlags) {
+ installDir := "lib"
+ if flags.Toolchain.Is64Bit() {
+ installDir = "lib64"
+ }
+
+ ctx.InstallFile(filepath.Join(installDir, c.Properties.Relative_install_path), c.out)
+}
+
+func (c *CCLibrary) installModule(ctx common.AndroidModuleContext, flags CCFlags) {
+ if c.static() {
+ c.installStaticLibrary(ctx, flags)
+ } else {
+ c.installSharedLibrary(ctx, flags)
+ }
+}
+
+//
+// Objects (for crt*.o)
+//
+
+type ccObjectProvider interface {
+ object() *ccObject
+}
+
+type ccObject struct {
+ CCBase
+ out string
+}
+
+func (c *ccObject) object() *ccObject {
+ return c
+}
+
+func CCObjectFactory() (blueprint.Module, []interface{}) {
+ module := &ccObject{}
+
+ return newCCBase(&module.CCBase, module, common.DeviceSupported, common.MultilibBoth)
+}
+
+func (*ccObject) AndroidDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string {
+ // object files can't have any dynamic dependencies
+ return nil
+}
+
+func (*ccObject) depNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps {
+ // object files can't have any dynamic dependencies
+ return CCDeps{}
+}
+
+func (c *ccObject) compileModule(ctx common.AndroidModuleContext,
+ flags CCFlags, deps CCDeps, objFiles []string) {
+
+ objFiles = append(objFiles, deps.ObjFiles...)
+
+ var outputFile string
+ if len(objFiles) == 1 {
+ outputFile = objFiles[0]
+ } else {
+ outputFile = filepath.Join(common.ModuleOutDir(ctx), ctx.ModuleName()+objectExtension)
+ TransformObjsToObj(ctx, objFiles, ccFlagsToBuilderFlags(flags), outputFile)
+ }
+
+ c.out = outputFile
+
+ ctx.CheckbuildFile(outputFile)
+}
+
+func (c *ccObject) installModule(ctx common.AndroidModuleContext, flags CCFlags) {
+ // Object files do not get installed.
+}
+
+func (c *ccObject) outputFile() string {
+ return c.out
+}
+
+var _ ccObjectProvider = (*ccObject)(nil)
+
+//
+// Executables
+//
+
+type CCBinaryProperties struct {
+ // compile executable with -static
+ Static_executable bool
+
+ // set the name of the output
+ Stem string `android:"arch_variant"`
+
+ // append to the name of the output
+ Suffix string `android:"arch_variant"`
+
+ // if set, add an extra objcopy --prefix-symbols= step
+ Prefix_symbols string
+}
+
+type CCBinary struct {
+ CCLinked
+ out string
+ installFile string
+ BinaryProperties CCBinaryProperties
+}
+
+func (c *CCBinary) buildStatic() bool {
+ return c.BinaryProperties.Static_executable
+}
+
+func (c *CCBinary) buildShared() bool {
+ return !c.BinaryProperties.Static_executable
+}
+
+func (c *CCBinary) getStem(ctx common.AndroidModuleContext) string {
+ stem := ctx.ModuleName()
+ if c.BinaryProperties.Stem != "" {
+ stem = c.BinaryProperties.Stem
+ }
+
+ return stem + c.BinaryProperties.Suffix
+}
+
+func (c *CCBinary) depNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps {
+ depNames = c.CCLinked.depNames(ctx, depNames)
+ if ctx.Device() {
+ if c.Properties.Sdk_version == "" {
+ if c.BinaryProperties.Static_executable {
+ depNames.CrtBegin = "crtbegin_static"
+ } else {
+ depNames.CrtBegin = "crtbegin_dynamic"
+ }
+ depNames.CrtEnd = "crtend_android"
+ } else {
+ if c.BinaryProperties.Static_executable {
+ depNames.CrtBegin = "ndk_crtbegin_static." + c.Properties.Sdk_version
+ } else {
+ depNames.CrtBegin = "ndk_crtbegin_dynamic." + c.Properties.Sdk_version
+ }
+ depNames.CrtEnd = "ndk_crtend_android." + c.Properties.Sdk_version
+ }
+
+ if c.BinaryProperties.Static_executable {
+ if c.stl(ctx) == "libc++_static" {
+ depNames.StaticLibs = append(depNames.StaticLibs, "libm", "libc", "libdl")
+ }
+ // static libraries libcompiler_rt, libc and libc_nomalloc need to be linked with
+ // --start-group/--end-group along with libgcc. If they are in deps.StaticLibs,
+ // move them to the beginning of deps.LateStaticLibs
+ var groupLibs []string
+ depNames.StaticLibs, groupLibs = filterList(depNames.StaticLibs,
+ []string{"libc", "libc_nomalloc", "libcompiler_rt"})
+ depNames.LateStaticLibs = append(groupLibs, depNames.LateStaticLibs...)
+ }
+ }
+ return depNames
+}
+
+func NewCCBinary(binary *CCBinary, module CCModuleType,
+ hod common.HostOrDeviceSupported, props ...interface{}) (blueprint.Module, []interface{}) {
+
+ props = append(props, &binary.BinaryProperties)
+
+ return newCCDynamic(&binary.CCLinked, module, hod, common.MultilibFirst, props...)
+}
+
+func CCBinaryFactory() (blueprint.Module, []interface{}) {
+ module := &CCBinary{}
+
+ return NewCCBinary(module, module, common.HostAndDeviceSupported)
+}
+
+func (c *CCBinary) ModifyProperties(ctx common.AndroidBaseContext) {
+ if ctx.Darwin() {
+ c.BinaryProperties.Static_executable = false
+ }
+ if c.BinaryProperties.Static_executable {
+ c.dynamicProperties.VariantIsStaticBinary = true
+ }
+}
+
+func (c *CCBinary) flags(ctx common.AndroidModuleContext, flags CCFlags) CCFlags {
+ flags = c.CCLinked.flags(ctx, flags)
+
+ flags.CFlags = append(flags.CFlags, "-fpie")
+
+ if ctx.Device() {
+ if c.BinaryProperties.Static_executable {
+ // Clang driver needs -static to create static executable.
+ // However, bionic/linker uses -shared to overwrite.
+ // Linker for x86 targets does not allow coexistance of -static and -shared,
+ // so we add -static only if -shared is not used.
+ if !inList("-shared", flags.LdFlags) {
+ flags.LdFlags = append(flags.LdFlags, "-static")
+ }
+
+ flags.LdFlags = append(flags.LdFlags,
+ "-nostdlib",
+ "-Bstatic",
+ "-Wl,--gc-sections",
+ )
+
+ } else {
+ linker := "/system/bin/linker"
+ if flags.Toolchain.Is64Bit() {
+ linker = "/system/bin/linker64"
+ }
+
+ flags.LdFlags = append(flags.LdFlags,
+ "-nostdlib",
+ "-Bdynamic",
+ fmt.Sprintf("-Wl,-dynamic-linker,%s", linker),
+ "-Wl,--gc-sections",
+ "-Wl,-z,nocopyreloc",
+ )
+ }
+ } else if ctx.Darwin() {
+ flags.LdFlags = append(flags.LdFlags, "-Wl,-headerpad_max_install_names")
+ }
+
+ return flags
+}
+
+func (c *CCBinary) compileModule(ctx common.AndroidModuleContext,
+ flags CCFlags, deps CCDeps, objFiles []string) {
+
+ if !c.BinaryProperties.Static_executable && inList("libc", c.Properties.Static_libs) {
+ ctx.ModuleErrorf("statically linking libc to dynamic executable, please remove libc\n" +
+ "from static libs or set static_executable: true")
+ }
+
+ outputFile := filepath.Join(common.ModuleOutDir(ctx), c.getStem(ctx))
+ c.out = outputFile
+ if c.BinaryProperties.Prefix_symbols != "" {
+ afterPrefixSymbols := outputFile
+ outputFile = outputFile + ".intermediate"
+ TransformBinaryPrefixSymbols(ctx, c.BinaryProperties.Prefix_symbols, outputFile,
+ ccFlagsToBuilderFlags(flags), afterPrefixSymbols)
+ }
+
+ var linkerDeps []string
+
+ TransformObjToDynamicBinary(ctx, objFiles, deps.SharedLibs, deps.StaticLibs,
+ deps.LateStaticLibs, deps.WholeStaticLibs, linkerDeps, deps.CrtBegin, deps.CrtEnd, true,
+ ccFlagsToBuilderFlags(flags), outputFile)
+}
+
+func (c *CCBinary) installModule(ctx common.AndroidModuleContext, flags CCFlags) {
+ c.installFile = ctx.InstallFile(filepath.Join("bin", c.Properties.Relative_install_path), c.out)
+}
+
+func (c *CCBinary) HostToolPath() string {
+ if c.HostOrDevice().Host() {
+ return c.installFile
+ }
+ return ""
+}
+
+type CCTestProperties struct {
+ // Create a separate test for each source file. Useful when there is
+ // global state that can not be torn down and reset between each test suite.
+ Test_per_src bool
+}
+
+type CCTest struct {
+ CCBinary
+
+ TestProperties CCTestProperties
+}
+
+func (c *CCTest) flags(ctx common.AndroidModuleContext, flags CCFlags) CCFlags {
+ flags = c.CCBinary.flags(ctx, flags)
+
+ flags.CFlags = append(flags.CFlags, "-DGTEST_HAS_STD_STRING")
+ if ctx.Host() {
+ flags.CFlags = append(flags.CFlags, "-O0", "-g")
+ flags.LdFlags = append(flags.LdFlags, "-lpthread")
+ }
+
+ // TODO(danalbert): Make gtest export its dependencies.
+ flags.CFlags = append(flags.CFlags,
+ "-I"+filepath.Join(ctx.AConfig().SrcDir(), "external/gtest/include"))
+
+ return flags
+}
+
+func (c *CCTest) depNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps {
+ depNames.StaticLibs = append(depNames.StaticLibs, "libgtest", "libgtest_main")
+ depNames = c.CCBinary.depNames(ctx, depNames)
+ return depNames
+}
+
+func (c *CCTest) installModule(ctx common.AndroidModuleContext, flags CCFlags) {
+ if ctx.Device() {
+ ctx.InstallFile("../data/nativetest"+ctx.Arch().ArchType.Multilib[3:]+"/"+ctx.ModuleName(), c.out)
+ } else {
+ c.CCBinary.installModule(ctx, flags)
+ }
+}
+
+func (c *CCTest) testPerSrc() bool {
+ return c.TestProperties.Test_per_src
+}
+
+func (c *CCTest) test() *CCTest {
+ return c
+}
+
+func NewCCTest(test *CCTest, module CCModuleType,
+ hod common.HostOrDeviceSupported, props ...interface{}) (blueprint.Module, []interface{}) {
+
+ props = append(props, &test.TestProperties)
+
+ return NewCCBinary(&test.CCBinary, module, hod, props...)
+}
+
+func CCTestFactory() (blueprint.Module, []interface{}) {
+ module := &CCTest{}
+
+ return NewCCTest(module, module, common.HostAndDeviceSupported)
+}
+
+type testPerSrc interface {
+ test() *CCTest
+ testPerSrc() bool
+}
+
+var _ testPerSrc = (*CCTest)(nil)
+
+func TestPerSrcMutator(mctx blueprint.EarlyMutatorContext) {
+ if test, ok := mctx.Module().(testPerSrc); ok {
+ if test.testPerSrc() {
+ testNames := make([]string, len(test.test().Properties.Srcs))
+ for i, src := range test.test().Properties.Srcs {
+ testNames[i] = strings.TrimSuffix(src, filepath.Ext(src))
+ }
+ tests := mctx.CreateLocalVariations(testNames...)
+ for i, src := range test.test().Properties.Srcs {
+ tests[i].(testPerSrc).test().Properties.Srcs = []string{src}
+ tests[i].(testPerSrc).test().BinaryProperties.Stem = testNames[i]
+ }
+ }
+ }
+}
+
+type CCBenchmark struct {
+ CCBinary
+}
+
+func (c *CCBenchmark) depNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps {
+ depNames = c.CCBinary.depNames(ctx, depNames)
+ depNames.StaticLibs = append(depNames.StaticLibs, "libbenchmark")
+ return depNames
+}
+
+func (c *CCBenchmark) installModule(ctx common.AndroidModuleContext, flags CCFlags) {
+ if ctx.Device() {
+ ctx.InstallFile("../data/nativetest"+ctx.Arch().ArchType.Multilib[3:]+"/"+ctx.ModuleName(), c.out)
+ } else {
+ c.CCBinary.installModule(ctx, flags)
+ }
+}
+
+func NewCCBenchmark(test *CCBenchmark, module CCModuleType,
+ hod common.HostOrDeviceSupported, props ...interface{}) (blueprint.Module, []interface{}) {
+
+ return NewCCBinary(&test.CCBinary, module, hod, props...)
+}
+
+func CCBenchmarkFactory() (blueprint.Module, []interface{}) {
+ module := &CCBenchmark{}
+
+ return NewCCBenchmark(module, module, common.HostAndDeviceSupported)
+}
+
+//
+// Static library
+//
+
+func CCLibraryStaticFactory() (blueprint.Module, []interface{}) {
+ module := &CCLibrary{}
+ module.LibraryProperties.BuildStatic = true
+
+ return NewCCLibrary(module, module, common.HostAndDeviceSupported)
+}
+
+//
+// Shared libraries
+//
+
+func CCLibrarySharedFactory() (blueprint.Module, []interface{}) {
+ module := &CCLibrary{}
+ module.LibraryProperties.BuildShared = true
+
+ return NewCCLibrary(module, module, common.HostAndDeviceSupported)
+}
+
+//
+// Host static library
+//
+
+func CCLibraryHostStaticFactory() (blueprint.Module, []interface{}) {
+ module := &CCLibrary{}
+ module.LibraryProperties.BuildStatic = true
+
+ return NewCCLibrary(module, module, common.HostSupported)
+}
+
+//
+// Host Shared libraries
+//
+
+func CCLibraryHostSharedFactory() (blueprint.Module, []interface{}) {
+ module := &CCLibrary{}
+ module.LibraryProperties.BuildShared = true
+
+ return NewCCLibrary(module, module, common.HostSupported)
+}
+
+//
+// Host Binaries
+//
+
+func CCBinaryHostFactory() (blueprint.Module, []interface{}) {
+ module := &CCBinary{}
+
+ return NewCCBinary(module, module, common.HostSupported)
+}
+
+//
+// Host Tests
+//
+
+func CCTestHostFactory() (blueprint.Module, []interface{}) {
+ module := &CCTest{}
+ return NewCCBinary(&module.CCBinary, module, common.HostSupported,
+ &module.TestProperties)
+}
+
+//
+// Host Benchmarks
+//
+
+func CCBenchmarkHostFactory() (blueprint.Module, []interface{}) {
+ module := &CCBenchmark{}
+ return NewCCBinary(&module.CCBinary, module, common.HostSupported)
+}
+
+//
+// Device libraries shipped with gcc
+//
+
+type toolchainLibrary struct {
+ CCLibrary
+}
+
+func (*toolchainLibrary) AndroidDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string {
+ // toolchain libraries can't have any dependencies
+ return nil
+}
+
+func (*toolchainLibrary) depNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps {
+ // toolchain libraries can't have any dependencies
+ return CCDeps{}
+}
+
+func ToolchainLibraryFactory() (blueprint.Module, []interface{}) {
+ module := &toolchainLibrary{}
+
+ module.LibraryProperties.BuildStatic = true
+
+ return newCCBase(&module.CCBase, module, common.DeviceSupported, common.MultilibBoth,
+ &module.LibraryProperties)
+}
+
+func (c *toolchainLibrary) compileModule(ctx common.AndroidModuleContext,
+ flags CCFlags, deps CCDeps, objFiles []string) {
+
+ libName := ctx.ModuleName() + staticLibraryExtension
+ outputFile := filepath.Join(common.ModuleOutDir(ctx), libName)
+
+ CopyGccLib(ctx, libName, ccFlagsToBuilderFlags(flags), outputFile)
+
+ c.out = outputFile
+
+ ctx.CheckbuildFile(outputFile)
+}
+
+func (c *toolchainLibrary) installModule(ctx common.AndroidModuleContext, flags CCFlags) {
+ // Toolchain libraries do not get installed.
+}
+
+// NDK prebuilt libraries.
+//
+// These differ from regular prebuilts in that they aren't stripped and usually aren't installed
+// either (with the exception of the shared STLs, which are installed to the app's directory rather
+// than to the system image).
+
+func getNdkLibDir(ctx common.AndroidModuleContext, toolchain Toolchain, version string) string {
+ return fmt.Sprintf("%s/prebuilts/ndk/current/platforms/android-%s/arch-%s/usr/lib",
+ ctx.AConfig().SrcDir(), version, toolchain.Name())
+}
+
+func ndkPrebuiltModuleToPath(ctx common.AndroidModuleContext, toolchain Toolchain,
+ ext string, version string) string {
+
+ // NDK prebuilts are named like: ndk_NAME.EXT.SDK_VERSION.
+ // We want to translate to just NAME.EXT
+ name := strings.Split(strings.TrimPrefix(ctx.ModuleName(), "ndk_"), ".")[0]
+ dir := getNdkLibDir(ctx, toolchain, version)
+ return filepath.Join(dir, name+ext)
+}
+
+type ndkPrebuiltObject struct {
+ ccObject
+}
+
+func (*ndkPrebuiltObject) AndroidDynamicDependencies(
+ ctx common.AndroidDynamicDependerModuleContext) []string {
+
+ // NDK objects can't have any dependencies
+ return nil
+}
+
+func (*ndkPrebuiltObject) depNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps {
+ // NDK objects can't have any dependencies
+ return CCDeps{}
+}
+
+func NdkPrebuiltObjectFactory() (blueprint.Module, []interface{}) {
+ module := &ndkPrebuiltObject{}
+ return newCCBase(&module.CCBase, module, common.DeviceSupported, common.MultilibBoth)
+}
+
+func (c *ndkPrebuiltObject) compileModule(ctx common.AndroidModuleContext, flags CCFlags,
+ deps CCDeps, objFiles []string) {
+ // A null build step, but it sets up the output path.
+ if !strings.HasPrefix(ctx.ModuleName(), "ndk_crt") {
+ ctx.ModuleErrorf("NDK prebuilts must have an ndk_crt prefixed name")
+ }
+
+ c.out = ndkPrebuiltModuleToPath(ctx, flags.Toolchain, objectExtension, c.Properties.Sdk_version)
+}
+
+func (c *ndkPrebuiltObject) installModule(ctx common.AndroidModuleContext, flags CCFlags) {
+ // Objects do not get installed.
+}
+
+var _ ccObjectProvider = (*ndkPrebuiltObject)(nil)
+
+type ndkPrebuiltLibrary struct {
+ CCLibrary
+}
+
+func (*ndkPrebuiltLibrary) AndroidDynamicDependencies(
+ ctx common.AndroidDynamicDependerModuleContext) []string {
+
+ // NDK libraries can't have any dependencies
+ return nil
+}
+
+func (*ndkPrebuiltLibrary) depNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps {
+ // NDK libraries can't have any dependencies
+ return CCDeps{}
+}
+
+func NdkPrebuiltLibraryFactory() (blueprint.Module, []interface{}) {
+ module := &ndkPrebuiltLibrary{}
+ module.LibraryProperties.BuildShared = true
+ return NewCCLibrary(&module.CCLibrary, module, common.DeviceSupported)
+}
+
+func (c *ndkPrebuiltLibrary) compileModule(ctx common.AndroidModuleContext, flags CCFlags,
+ deps CCDeps, objFiles []string) {
+ // A null build step, but it sets up the output path.
+ if !strings.HasPrefix(ctx.ModuleName(), "ndk_lib") {
+ ctx.ModuleErrorf("NDK prebuilts must have an ndk_lib prefixed name")
+ }
+
+ includeDirs := pathtools.PrefixPaths(c.Properties.Export_include_dirs, common.ModuleSrcDir(ctx))
+ c.exportFlags = []string{common.JoinWithPrefix(includeDirs, "-isystem ")}
+
+ c.out = ndkPrebuiltModuleToPath(ctx, flags.Toolchain, sharedLibraryExtension,
+ c.Properties.Sdk_version)
+}
+
+func (c *ndkPrebuiltLibrary) installModule(ctx common.AndroidModuleContext, flags CCFlags) {
+ // NDK prebuilt libraries do not get installed.
+}
+
+// The NDK STLs are slightly different from the prebuilt system libraries:
+// * Are not specific to each platform version.
+// * The libraries are not in a predictable location for each STL.
+
+type ndkPrebuiltStl struct {
+ ndkPrebuiltLibrary
+}
+
+type ndkPrebuiltStaticStl struct {
+ ndkPrebuiltStl
+}
+
+type ndkPrebuiltSharedStl struct {
+ ndkPrebuiltStl
+}
+
+func NdkPrebuiltSharedStlFactory() (blueprint.Module, []interface{}) {
+ module := &ndkPrebuiltSharedStl{}
+ module.LibraryProperties.BuildShared = true
+ return NewCCLibrary(&module.CCLibrary, module, common.DeviceSupported)
+}
+
+func NdkPrebuiltStaticStlFactory() (blueprint.Module, []interface{}) {
+ module := &ndkPrebuiltStaticStl{}
+ module.LibraryProperties.BuildStatic = true
+ return NewCCLibrary(&module.CCLibrary, module, common.DeviceSupported)
+}
+
+func getNdkStlLibDir(ctx common.AndroidModuleContext, toolchain Toolchain, stl string) string {
+ gccVersion := toolchain.GccVersion()
+ var libDir string
+ switch stl {
+ case "libstlport":
+ libDir = "cxx-stl/stlport/libs"
+ case "libc++":
+ libDir = "cxx-stl/llvm-libc++/libs"
+ case "libgnustl":
+ libDir = fmt.Sprintf("cxx-stl/gnu-libstdc++/%s/libs", gccVersion)
+ }
+
+ if libDir != "" {
+ ndkSrcRoot := ctx.AConfig().SrcDir() + "/prebuilts/ndk/current/sources"
+ return fmt.Sprintf("%s/%s/%s", ndkSrcRoot, libDir, ctx.Arch().Abi)
+ }
+
+ ctx.ModuleErrorf("Unknown NDK STL: %s", stl)
+ return ""
+}
+
+func (c *ndkPrebuiltStl) compileModule(ctx common.AndroidModuleContext, flags CCFlags,
+ deps CCDeps, objFiles []string) {
+ // A null build step, but it sets up the output path.
+ if !strings.HasPrefix(ctx.ModuleName(), "ndk_lib") {
+ ctx.ModuleErrorf("NDK prebuilts must have an ndk_lib prefixed name")
+ }
+
+ includeDirs := pathtools.PrefixPaths(c.Properties.Export_include_dirs, common.ModuleSrcDir(ctx))
+ c.exportFlags = []string{includeDirsToFlags(includeDirs)}
+
+ libName := strings.TrimPrefix(ctx.ModuleName(), "ndk_")
+ libExt := sharedLibraryExtension
+ if c.LibraryProperties.BuildStatic {
+ libExt = staticLibraryExtension
+ }
+
+ stlName := strings.TrimSuffix(libName, "_shared")
+ stlName = strings.TrimSuffix(stlName, "_static")
+ libDir := getNdkStlLibDir(ctx, flags.Toolchain, stlName)
+ c.out = libDir + "/" + libName + libExt
+}
+
+func LinkageMutator(mctx blueprint.EarlyMutatorContext) {
+ if c, ok := mctx.Module().(ccLinkedInterface); ok {
+ var modules []blueprint.Module
+ if c.buildStatic() && c.buildShared() {
+ modules = mctx.CreateLocalVariations("static", "shared")
+ modules[0].(ccLinkedInterface).setStatic(true)
+ modules[1].(ccLinkedInterface).setStatic(false)
+ } else if c.buildStatic() {
+ modules = mctx.CreateLocalVariations("static")
+ modules[0].(ccLinkedInterface).setStatic(true)
+ } else if c.buildShared() {
+ modules = mctx.CreateLocalVariations("shared")
+ modules[0].(ccLinkedInterface).setStatic(false)
+ } else {
+ panic(fmt.Errorf("ccLibrary %q not static or shared", mctx.ModuleName()))
+ }
+
+ if _, ok := c.(ccLibraryInterface); ok {
+ reuseFrom := modules[0].(ccLibraryInterface)
+ for _, m := range modules {
+ m.(ccLibraryInterface).setReuseFrom(reuseFrom)
+ }
+ }
+ }
+}
+
+// lastUniqueElements returns all unique elements of a slice, keeping the last copy of each
+// modifies the slice contents in place, and returns a subslice of the original slice
+func lastUniqueElements(list []string) []string {
+ totalSkip := 0
+ for i := len(list) - 1; i >= totalSkip; i-- {
+ skip := 0
+ for j := i - 1; j >= totalSkip; j-- {
+ if list[i] == list[j] {
+ skip++
+ } else {
+ list[j+skip] = list[j]
+ }
+ }
+ totalSkip += skip
+ }
+ return list[totalSkip:]
+}
diff --git a/cc/cc_test.go b/cc/cc_test.go
new file mode 100644
index 0000000..ec7da90
--- /dev/null
+++ b/cc/cc_test.go
@@ -0,0 +1,154 @@
+package cc
+
+import (
+ "reflect"
+ "testing"
+)
+
+var lastUniqueElementsTestCases = []struct {
+ in []string
+ out []string
+}{
+ {
+ in: []string{"a"},
+ out: []string{"a"},
+ },
+ {
+ in: []string{"a", "b"},
+ out: []string{"a", "b"},
+ },
+ {
+ in: []string{"a", "a"},
+ out: []string{"a"},
+ },
+ {
+ in: []string{"a", "b", "a"},
+ out: []string{"b", "a"},
+ },
+ {
+ in: []string{"b", "a", "a"},
+ out: []string{"b", "a"},
+ },
+ {
+ in: []string{"a", "a", "b"},
+ out: []string{"a", "b"},
+ },
+ {
+ in: []string{"a", "b", "a", "b"},
+ out: []string{"a", "b"},
+ },
+ {
+ in: []string{"liblog", "libdl", "libc++", "libdl", "libc", "libm"},
+ out: []string{"liblog", "libc++", "libdl", "libc", "libm"},
+ },
+}
+
+func TestLastUniqueElements(t *testing.T) {
+ for _, testCase := range lastUniqueElementsTestCases {
+ out := lastUniqueElements(testCase.in)
+ if !reflect.DeepEqual(out, testCase.out) {
+ t.Errorf("incorrect output:")
+ t.Errorf(" input: %#v", testCase.in)
+ t.Errorf(" expected: %#v", testCase.out)
+ t.Errorf(" got: %#v", out)
+ }
+ }
+}
+
+var (
+ str11 = "01234567891"
+ str10 = str11[:10]
+ str9 = str11[:9]
+ str5 = str11[:5]
+ str4 = str11[:4]
+)
+
+var splitListForSizeTestCases = []struct {
+ in []string
+ out [][]string
+ size int
+}{
+ {
+ in: []string{str10},
+ out: [][]string{{str10}},
+ size: 10,
+ },
+ {
+ in: []string{str9},
+ out: [][]string{{str9}},
+ size: 10,
+ },
+ {
+ in: []string{str5},
+ out: [][]string{{str5}},
+ size: 10,
+ },
+ {
+ in: []string{str11},
+ out: nil,
+ size: 10,
+ },
+ {
+ in: []string{str10, str10},
+ out: [][]string{{str10}, {str10}},
+ size: 10,
+ },
+ {
+ in: []string{str9, str10},
+ out: [][]string{{str9}, {str10}},
+ size: 10,
+ },
+ {
+ in: []string{str10, str9},
+ out: [][]string{{str10}, {str9}},
+ size: 10,
+ },
+ {
+ in: []string{str5, str4},
+ out: [][]string{{str5, str4}},
+ size: 10,
+ },
+ {
+ in: []string{str5, str4, str5},
+ out: [][]string{{str5, str4}, {str5}},
+ size: 10,
+ },
+ {
+ in: []string{str5, str4, str5, str4},
+ out: [][]string{{str5, str4}, {str5, str4}},
+ size: 10,
+ },
+ {
+ in: []string{str5, str4, str5, str5},
+ out: [][]string{{str5, str4}, {str5}, {str5}},
+ size: 10,
+ },
+ {
+ in: []string{str5, str5, str5, str4},
+ out: [][]string{{str5}, {str5}, {str5, str4}},
+ size: 10,
+ },
+ {
+ in: []string{str9, str11},
+ out: nil,
+ size: 10,
+ },
+ {
+ in: []string{str11, str9},
+ out: nil,
+ size: 10,
+ },
+}
+
+func TestSplitListForSize(t *testing.T) {
+ for _, testCase := range splitListForSizeTestCases {
+ out, _ := splitListForSize(testCase.in, testCase.size)
+ if !reflect.DeepEqual(out, testCase.out) {
+ t.Errorf("incorrect output:")
+ t.Errorf(" input: %#v", testCase.in)
+ t.Errorf(" size: %d", testCase.size)
+ t.Errorf(" expected: %#v", testCase.out)
+ t.Errorf(" got: %#v", out)
+ }
+ }
+}
diff --git a/cc/clang.go b/cc/clang.go
new file mode 100644
index 0000000..347efbe
--- /dev/null
+++ b/cc/clang.go
@@ -0,0 +1,117 @@
+package cc
+
+import (
+ "sort"
+ "strings"
+)
+
+// Cflags that should be filtered out when compiling with clang
+var clangUnknownCflags = []string{
+ "-finline-functions",
+ "-finline-limit=64",
+ "-fno-canonical-system-headers",
+ "-fno-tree-sra",
+ "-fprefetch-loop-arrays",
+ "-funswitch-loops",
+ "-Wmaybe-uninitialized",
+ "-Wno-error=maybe-uninitialized",
+ "-Wno-error=unused-but-set-parameter",
+ "-Wno-error=unused-but-set-variable",
+ "-Wno-free-nonheap-object",
+ "-Wno-literal-suffix",
+ "-Wno-maybe-uninitialized",
+ "-Wno-old-style-declaration",
+ "-Wno-psabi",
+ "-Wno-unused-but-set-parameter",
+ "-Wno-unused-but-set-variable",
+ "-Wno-unused-local-typedefs",
+ "-Wunused-but-set-parameter",
+ "-Wunused-but-set-variable",
+
+ // arm + arm64 + mips + mips64
+ "-fgcse-after-reload",
+ "-frerun-cse-after-loop",
+ "-frename-registers",
+ "-fno-strict-volatile-bitfields",
+
+ // arm + arm64
+ "-fno-align-jumps",
+ "-Wa,--noexecstack",
+
+ // arm
+ "-mthumb-interwork",
+ "-fno-builtin-sin",
+ "-fno-caller-saves",
+ "-fno-early-inlining",
+ "-fno-move-loop-invariants",
+ "-fno-partial-inlining",
+ "-fno-tree-copy-prop",
+ "-fno-tree-loop-optimize",
+
+ // mips + mips64
+ "-msynci",
+ "-mno-fused-madd",
+
+ // x86 + x86_64
+ "-finline-limit=300",
+ "-fno-inline-functions-called-once",
+ "-mfpmath=sse",
+ "-mbionic",
+}
+
+func init() {
+ sort.Strings(clangUnknownCflags)
+
+ pctx.StaticVariable("clangExtraCflags", strings.Join([]string{
+ "-D__compiler_offsetof=__builtin_offsetof",
+
+ // Help catch common 32/64-bit errors.
+ "-Werror=int-conversion",
+
+ // Disable overly aggressive warning for macros defined with a leading underscore
+ // This happens in AndroidConfig.h, which is included nearly everywhere.
+ "-Wno-reserved-id-macro",
+
+ // Disable overly aggressive warning for format strings.
+ // Bug: 20148343
+ "-Wno-format-pedantic",
+
+ // Workaround for ccache with clang.
+ // See http://petereisentraut.blogspot.com/2011/05/ccache-and-clang.html.
+ "-Wno-unused-command-line-argument",
+
+ // Disable -Winconsistent-missing-override until we can clean up the existing
+ // codebase for it.
+ "-Wno-inconsistent-missing-override",
+ }, " "))
+
+ pctx.StaticVariable("clangExtraConlyflags", strings.Join([]string{
+ "-std=gnu99",
+ }, " "))
+
+ pctx.StaticVariable("clangExtraTargetCflags", strings.Join([]string{
+ "-nostdlibinc",
+ }, " "))
+}
+
+func clangFilterUnknownCflags(cflags []string) []string {
+ ret := make([]string, 0, len(cflags))
+ for _, f := range cflags {
+ if !inListSorted(f, clangUnknownCflags) {
+ ret = append(ret, f)
+ }
+ }
+
+ return ret
+}
+
+func inListSorted(s string, list []string) bool {
+ for _, l := range list {
+ if s == l {
+ return true
+ } else if s < l {
+ return false
+ }
+ }
+ return false
+}
diff --git a/cc/gen.go b/cc/gen.go
new file mode 100644
index 0000000..bd91d64
--- /dev/null
+++ b/cc/gen.go
@@ -0,0 +1,109 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package cc
+
+// This file generates the final rules for compiling all C/C++. All properties related to
+// compiling should have been translated into builderFlags or another argument to the Transform*
+// functions.
+
+import (
+ "path/filepath"
+ "strings"
+
+ "github.com/google/blueprint"
+ "github.com/google/blueprint/pathtools"
+
+ "android/soong/common"
+)
+
+func init() {
+ pctx.StaticVariable("lexCmd", "${SrcDir}/prebuilts/misc/${HostPrebuiltTag}/flex/flex-2.5.39")
+ pctx.StaticVariable("yaccCmd", "${SrcDir}/prebuilts/misc/${HostPrebuiltTag}/bison/bison")
+ pctx.StaticVariable("yaccDataDir", "${SrcDir}/external/bison/data")
+}
+
+var (
+ yacc = pctx.StaticRule("yacc",
+ blueprint.RuleParams{
+ Command: "BISON_PKGDATADIR=$yaccDataDir $yaccCmd -d $yaccFlags -o $cppFile $in && " +
+ "cp -f $hppFile $hFile",
+ Description: "yacc $out",
+ },
+ "yaccFlags", "cppFile", "hppFile", "hFile")
+
+ lex = pctx.StaticRule("lex",
+ blueprint.RuleParams{
+ Command: "$lexCmd -o$out $in",
+ Description: "lex $out",
+ })
+)
+
+func genYacc(ctx common.AndroidModuleContext, yaccFile, yaccFlags string) (cppFile, headerFile string) {
+ cppFile = strings.TrimPrefix(yaccFile, common.ModuleSrcDir(ctx))
+ cppFile = filepath.Join(common.ModuleGenDir(ctx), cppFile)
+ cppFile = pathtools.ReplaceExtension(cppFile, "cpp")
+ hppFile := pathtools.ReplaceExtension(cppFile, "hpp")
+ headerFile = pathtools.ReplaceExtension(cppFile, "h")
+
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: yacc,
+ Outputs: []string{cppFile, headerFile},
+ Inputs: []string{yaccFile},
+ Implicits: []string{"$yaccCmd"},
+ Args: map[string]string{
+ "yaccFlags": yaccFlags,
+ "cppFile": cppFile,
+ "hppFile": hppFile,
+ "hFile": headerFile,
+ },
+ })
+
+ return cppFile, headerFile
+}
+
+func genLex(ctx common.AndroidModuleContext, lexFile string) (cppFile string) {
+ cppFile = strings.TrimPrefix(lexFile, common.ModuleSrcDir(ctx))
+ cppFile = filepath.Join(common.ModuleGenDir(ctx), cppFile)
+ cppFile = pathtools.ReplaceExtension(cppFile, "cpp")
+
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: lex,
+ Outputs: []string{cppFile},
+ Inputs: []string{lexFile},
+ Implicits: []string{"$lexCmd"},
+ })
+
+ return cppFile
+}
+
+func genSources(ctx common.AndroidModuleContext, srcFiles []string,
+ buildFlags builderFlags) ([]string, []string) {
+
+ var deps []string
+
+ for i, srcFile := range srcFiles {
+ switch filepath.Ext(srcFile) {
+ case ".y", ".yy":
+ cppFile, headerFile := genYacc(ctx, srcFile, buildFlags.yaccFlags)
+ srcFiles[i] = cppFile
+ deps = append(deps, headerFile)
+ case ".l", ".ll":
+ cppFile := genLex(ctx, srcFile)
+ srcFiles[i] = cppFile
+ }
+ }
+
+ return srcFiles, deps
+}
diff --git a/cc/toolchain.go b/cc/toolchain.go
new file mode 100644
index 0000000..d188845
--- /dev/null
+++ b/cc/toolchain.go
@@ -0,0 +1,80 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package cc
+
+import (
+ "fmt"
+
+ "android/soong/common"
+)
+
+type toolchainFactory func(archVariant string, cpuVariant string) Toolchain
+
+var toolchainFactories = map[common.HostOrDevice]map[common.ArchType]toolchainFactory{
+ common.Host: make(map[common.ArchType]toolchainFactory),
+ common.Device: make(map[common.ArchType]toolchainFactory),
+}
+
+func registerToolchainFactory(hod common.HostOrDevice, arch common.ArchType,
+ factory toolchainFactory) {
+
+ toolchainFactories[hod][arch] = factory
+}
+
+type Toolchain interface {
+ Name() string
+
+ GccRoot() string
+ GccTriple() string
+ GccVersion() string
+ Cflags() string
+ Cppflags() string
+ Ldflags() string
+ IncludeFlags() string
+ InstructionSetFlags(string) (string, error)
+
+ ClangTriple() string
+ ClangCflags() string
+ ClangCppflags() string
+ ClangLdflags() string
+
+ Is64Bit() bool
+}
+
+type toolchainBase struct {
+}
+
+func (toolchainBase) InstructionSetFlags(s string) (string, error) {
+ if s != "" {
+ return "", fmt.Errorf("instruction_set: %s is not a supported instruction set", s)
+ }
+ return "", nil
+}
+
+type toolchain64Bit struct {
+ toolchainBase
+}
+
+func (toolchain64Bit) Is64Bit() bool {
+ return true
+}
+
+type toolchain32Bit struct {
+ toolchainBase
+}
+
+func (toolchain32Bit) Is64Bit() bool {
+ return false
+}
diff --git a/cc/util.go b/cc/util.go
new file mode 100644
index 0000000..9ce84ee
--- /dev/null
+++ b/cc/util.go
@@ -0,0 +1,84 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package cc
+
+import (
+ "fmt"
+ "regexp"
+ "strings"
+
+ "android/soong/common"
+)
+
+// Efficiently converts a list of include directories to a single string
+// of cflags with -I prepended to each directory.
+func includeDirsToFlags(dirs []string) string {
+ return common.JoinWithPrefix(dirs, "-I")
+}
+
+func ldDirsToFlags(dirs []string) string {
+ return common.JoinWithPrefix(dirs, "-L")
+}
+
+func libNamesToFlags(names []string) string {
+ return common.JoinWithPrefix(names, "-l")
+}
+
+func inList(s string, list []string) bool {
+ for _, l := range list {
+ if l == s {
+ return true
+ }
+ }
+
+ return false
+}
+
+func filterList(list []string, filter []string) (remainder []string, filtered []string) {
+ for _, l := range list {
+ if inList(l, filter) {
+ filtered = append(filtered, l)
+ } else {
+ remainder = append(remainder, l)
+ }
+ }
+
+ return
+}
+
+var libNameRegexp = regexp.MustCompile(`^lib(.*)$`)
+
+func moduleToLibName(module string) (string, error) {
+ matches := libNameRegexp.FindStringSubmatch(module)
+ if matches == nil {
+ return "", fmt.Errorf("Library module name %s does not start with lib", module)
+ }
+ return matches[1], nil
+}
+
+func ccFlagsToBuilderFlags(in CCFlags) builderFlags {
+ return builderFlags{
+ globalFlags: strings.Join(in.GlobalFlags, " "),
+ asFlags: strings.Join(in.AsFlags, " "),
+ cFlags: strings.Join(in.CFlags, " "),
+ conlyFlags: strings.Join(in.ConlyFlags, " "),
+ cppFlags: strings.Join(in.CppFlags, " "),
+ yaccFlags: strings.Join(in.YaccFlags, " "),
+ ldFlags: strings.Join(in.LdFlags, " "),
+ nocrt: in.Nocrt,
+ toolchain: in.Toolchain,
+ clang: in.Clang,
+ }
+}
diff --git a/cc/x86_darwin_host.go b/cc/x86_darwin_host.go
new file mode 100644
index 0000000..bed977d
--- /dev/null
+++ b/cc/x86_darwin_host.go
@@ -0,0 +1,213 @@
+package cc
+
+import (
+ "runtime"
+ "strings"
+
+ "android/soong/common"
+)
+
+var (
+ darwinCflags = []string{
+ "-fno-exceptions", // from build/core/combo/select.mk
+ "-Wno-multichar", // from build/core/combo/select.mk
+
+ "-fPIC",
+ "-funwind-tables",
+ "-include ${SrcDir}/build/core/combo/include/arch/darwin-x86/AndroidConfig.h",
+
+ // Workaround differences in inttypes.h between host and target.
+ //See bug 12708004.
+ "-D__STDC_FORMAT_MACROS",
+ "-D__STDC_CONSTANT_MACROS",
+
+ // HOST_RELEASE_CFLAGS
+ "-O2", // from build/core/combo/select.mk
+ "-g", // from build/core/combo/select.mk
+ "-fno-strict-aliasing", // from build/core/combo/select.mk
+ "-isysroot ${macSdkRoot}",
+ "-mmacosx-version-min=10.9",
+ "-DMACOSX_DEPLOYMENT_TARGET=10.9",
+ }
+
+ darwinCppflags = []string{
+ "-isystem ${macSdkPath}/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1",
+ }
+
+ darwinLdflags = []string{
+ "-isysroot ${macSdkRoot}",
+ "-Wl,-syslibroot,${macSdkRoot}",
+ "-mmacosx-version-min=10.9",
+ }
+
+ // Extended cflags
+ darwinX86Cflags = []string{
+ "-m32",
+ }
+
+ darwinX8664Cflags = []string{
+ "-m64",
+ }
+
+ darwinX86Ldflags = []string{
+ "-m32",
+ "-Wl,-rpath,@loader_path/../lib",
+ }
+
+ darwinX8664Ldflags = []string{
+ "-m64",
+ "-Wl,-rpath,@loader_path/../lib64",
+ }
+
+ darwinClangCflags = append([]string{
+ "-integrated-as",
+ }, clangFilterUnknownCflags(darwinCflags)...)
+
+ darwinClangLdflags = clangFilterUnknownCflags(darwinLdflags)
+
+ darwinX86ClangLdflags = clangFilterUnknownCflags(darwinX86Ldflags)
+
+ darwinX8664ClangLdflags = clangFilterUnknownCflags(darwinX8664Ldflags)
+
+ darwinClangCppflags = clangFilterUnknownCflags(darwinCppflags)
+)
+
+func init() {
+ pctx.StaticVariable("macSdkPath", "/Applications/Xcode.app/Contents/Developer")
+ pctx.StaticVariable("macSdkRoot", "${macSdkPath}/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk")
+
+ pctx.StaticVariable("darwinGccVersion", "4.2.1")
+ pctx.StaticVariable("darwinGccRoot",
+ "${SrcDir}/prebuilts/gcc/${HostPrebuiltTag}/host/i686-apple-darwin-${darwinGccVersion}")
+
+ pctx.StaticVariable("darwinGccTriple", "i686-apple-darwin11")
+
+ pctx.StaticVariable("darwinCflags", strings.Join(darwinCflags, " "))
+ pctx.StaticVariable("darwinLdflags", strings.Join(darwinLdflags, " "))
+ pctx.StaticVariable("darwinCppflags", strings.Join(darwinCppflags, " "))
+
+ pctx.StaticVariable("darwinClangCflags", strings.Join(darwinClangCflags, " "))
+ pctx.StaticVariable("darwinClangLdflags", strings.Join(darwinClangLdflags, " "))
+ pctx.StaticVariable("darwinClangCppflags", strings.Join(darwinClangCppflags, " "))
+
+ // Extended cflags
+ pctx.StaticVariable("darwinX86Cflags", strings.Join(darwinX86Cflags, " "))
+ pctx.StaticVariable("darwinX8664Cflags", strings.Join(darwinX8664Cflags, " "))
+ pctx.StaticVariable("darwinX86Ldflags", strings.Join(darwinX86Ldflags, " "))
+ pctx.StaticVariable("darwinX8664Ldflags", strings.Join(darwinX8664Ldflags, " "))
+
+ pctx.StaticVariable("darwinX86ClangCflags",
+ strings.Join(clangFilterUnknownCflags(darwinX86Cflags), " "))
+ pctx.StaticVariable("darwinX8664ClangCflags",
+ strings.Join(clangFilterUnknownCflags(darwinX8664Cflags), " "))
+ pctx.StaticVariable("darwinX86ClangLdflags", strings.Join(darwinX86ClangLdflags, " "))
+ pctx.StaticVariable("darwinX8664ClangLdflags", strings.Join(darwinX8664ClangLdflags, " "))
+}
+
+type toolchainDarwin struct {
+ cFlags, ldFlags string
+}
+
+type toolchainDarwinX86 struct {
+ toolchain32Bit
+ toolchainDarwin
+}
+
+type toolchainDarwinX8664 struct {
+ toolchain64Bit
+ toolchainDarwin
+}
+
+func (t *toolchainDarwinX86) Name() string {
+ return "x86"
+}
+
+func (t *toolchainDarwinX8664) Name() string {
+ return "x86_64"
+}
+
+func (t *toolchainDarwin) GccRoot() string {
+ return "${darwinGccRoot}"
+}
+
+func (t *toolchainDarwin) GccTriple() string {
+ return "${darwinGccTriple}"
+}
+
+func (t *toolchainDarwin) GccVersion() string {
+ return "${darwinGccVersion}"
+}
+
+func (t *toolchainDarwin) Cflags() string {
+ return "${darwinCflags} ${darwinX86Cflags}"
+}
+
+func (t *toolchainDarwinX8664) Cflags() string {
+ return "${darwinCflags} ${darwinX8664Cflags}"
+}
+
+func (t *toolchainDarwin) Cppflags() string {
+ return "${darwinCppflags}"
+}
+
+func (t *toolchainDarwinX86) Ldflags() string {
+ return "${darwinLdflags} ${darwinX86Ldflags}"
+}
+
+func (t *toolchainDarwinX8664) Ldflags() string {
+ return "${darwinLdflags} ${darwinX8664Ldflags}"
+}
+
+func (t *toolchainDarwin) IncludeFlags() string {
+ return ""
+}
+
+func (t *toolchainDarwinX86) ClangTriple() string {
+ return "i686-darwin-gnu"
+}
+
+func (t *toolchainDarwinX86) ClangCflags() string {
+ return "${darwinClangCflags} ${darwinX86ClangCflags}"
+}
+
+func (t *toolchainDarwinX86) ClangCppflags() string {
+ return "${darwinClangCppflags}"
+}
+
+func (t *toolchainDarwinX8664) ClangTriple() string {
+ return "x86_64-darwin-gnu"
+}
+
+func (t *toolchainDarwinX8664) ClangCflags() string {
+ return "${darwinClangCflags} ${darwinX8664ClangCflags}"
+}
+
+func (t *toolchainDarwinX8664) ClangCppflags() string {
+ return "${darwinClangCppflags}"
+}
+
+func (t *toolchainDarwinX86) ClangLdflags() string {
+ return "${darwinClangLdflags} ${darwinX86ClangLdflags}"
+}
+
+func (t *toolchainDarwinX8664) ClangLdflags() string {
+ return "${darwinClangLdflags} ${darwinX8664ClangLdflags}"
+}
+
+var toolchainDarwinX86Singleton Toolchain = &toolchainDarwinX86{}
+var toolchainDarwinX8664Singleton Toolchain = &toolchainDarwinX8664{}
+
+func darwinX86ToolchainFactory(archVariant string, cpuVariant string) Toolchain {
+ return toolchainDarwinX86Singleton
+}
+
+func darwinX8664ToolchainFactory(archVariant string, cpuVariant string) Toolchain {
+ return toolchainDarwinX8664Singleton
+}
+
+func init() {
+ if runtime.GOOS == "darwin" {
+ registerToolchainFactory(common.Host, common.X86, darwinX86ToolchainFactory)
+ registerToolchainFactory(common.Host, common.X86_64, darwinX8664ToolchainFactory)
+ }
+}
diff --git a/cc/x86_linux_host.go b/cc/x86_linux_host.go
new file mode 100644
index 0000000..b39c0b4
--- /dev/null
+++ b/cc/x86_linux_host.go
@@ -0,0 +1,238 @@
+package cc
+
+import (
+ "runtime"
+ "strings"
+
+ "android/soong/common"
+)
+
+var (
+ linuxCflags = []string{
+ "-fno-exceptions", // from build/core/combo/select.mk
+ "-Wno-multichar", // from build/core/combo/select.mk
+
+ "-Wa,--noexecstack",
+
+ "-fPIC",
+ "-no-canonical-prefixes",
+ "-include ${SrcDir}/build/core/combo/include/arch/linux-x86/AndroidConfig.h",
+
+ // TODO: Set _FORTIFY_SOURCE=2. Bug 20558757.
+ "-U_FORTIFY_SOURCE",
+ "-D_FORTIFY_SOURCE=0",
+ "-fstack-protector",
+
+ // Workaround differences in inttypes.h between host and target.
+ //See bug 12708004.
+ "-D__STDC_FORMAT_MACROS",
+ "-D__STDC_CONSTANT_MACROS",
+
+ // HOST_RELEASE_CFLAGS
+ "-O2", // from build/core/combo/select.mk
+ "-g", // from build/core/combo/select.mk
+ "-fno-strict-aliasing", // from build/core/combo/select.mk
+ }
+
+ linuxLdflags = []string{
+ "-Wl,-z,noexecstack",
+ "-Wl,-z,relro",
+ "-Wl,-z,now",
+ }
+
+ // Extended cflags
+ linuxX86Cflags = []string{
+ "-msse3",
+ "-mfpmath=sse",
+ "-m32",
+ "-march=prescott",
+ }
+
+ linuxX8664Cflags = []string{
+ "-m64",
+ }
+
+ linuxX86Ldflags = []string{
+ "-m32",
+ `-Wl,-rpath,\$$ORIGIN/../lib`,
+ }
+
+ linuxX8664Ldflags = []string{
+ "-m64",
+ `-Wl,-rpath,\$$ORIGIN/../lib64`,
+ }
+
+ linuxClangCflags = append([]string{
+ "--gcc-toolchain=${linuxGccRoot}",
+ "--sysroot=${linuxGccRoot}/sysroot",
+ }, clangFilterUnknownCflags(linuxCflags)...)
+
+ linuxClangLdflags = append([]string{
+ "--gcc-toolchain=${linuxGccRoot}",
+ "--sysroot=${linuxGccRoot}/sysroot",
+ }, clangFilterUnknownCflags(linuxLdflags)...)
+
+ linuxX86ClangLdflags = append([]string{
+ "-B${linuxGccRoot}/lib/gcc/${linuxGccTriple}/${linuxGccVersion}/32",
+ "-L${linuxGccRoot}/lib/gcc/${linuxGccTriple}/${linuxGccVersion}/32",
+ "-L${linuxGccRoot}/${linuxGccTriple}/lib32",
+ }, clangFilterUnknownCflags(linuxX86Ldflags)...)
+
+ linuxX8664ClangLdflags = append([]string{
+ "-B${linuxGccRoot}/lib/gcc/${linuxGccTriple}/${linuxGccVersion}",
+ "-L${linuxGccRoot}/lib/gcc/${linuxGccTriple}/${linuxGccVersion}",
+ "-L${linuxGccRoot}/${linuxGccTriple}/lib64",
+ }, clangFilterUnknownCflags(linuxX8664Ldflags)...)
+
+ linuxClangCppflags = []string{
+ "-isystem ${linuxGccRoot}/${linuxGccTriple}/include/c++/${linuxGccVersion}",
+ "-isystem ${linuxGccRoot}/${linuxGccTriple}/include/c++/${linuxGccVersion}/backward",
+ }
+
+ linuxX86ClangCppflags = []string{
+ "-isystem ${linuxGccRoot}/${linuxGccTriple}/include/c++/${linuxGccVersion}/${linuxGccTriple}/32",
+ }
+
+ linuxX8664ClangCppflags = []string{
+ "-isystem ${linuxGccRoot}/${linuxGccTriple}/include/c++/${linuxGccVersion}/${linuxGccTriple}",
+ }
+)
+
+func init() {
+ pctx.StaticVariable("linuxGccVersion", "4.8")
+
+ pctx.StaticVariable("linuxGccRoot",
+ "${SrcDir}/prebuilts/gcc/${HostPrebuiltTag}/host/x86_64-linux-glibc2.15-${linuxGccVersion}")
+
+ pctx.StaticVariable("linuxGccTriple", "x86_64-linux")
+
+ pctx.StaticVariable("linuxCflags", strings.Join(linuxCflags, " "))
+ pctx.StaticVariable("linuxLdflags", strings.Join(linuxLdflags, " "))
+
+ pctx.StaticVariable("linuxClangCflags", strings.Join(linuxClangCflags, " "))
+ pctx.StaticVariable("linuxClangLdflags", strings.Join(linuxClangLdflags, " "))
+ pctx.StaticVariable("linuxClangCppflags", strings.Join(linuxClangCppflags, " "))
+
+ // Extended cflags
+ pctx.StaticVariable("linuxX86Cflags", strings.Join(linuxX86Cflags, " "))
+ pctx.StaticVariable("linuxX8664Cflags", strings.Join(linuxX8664Cflags, " "))
+ pctx.StaticVariable("linuxX86Ldflags", strings.Join(linuxX86Ldflags, " "))
+ pctx.StaticVariable("linuxX8664Ldflags", strings.Join(linuxX8664Ldflags, " "))
+
+ pctx.StaticVariable("linuxX86ClangCflags",
+ strings.Join(clangFilterUnknownCflags(linuxX86Cflags), " "))
+ pctx.StaticVariable("linuxX8664ClangCflags",
+ strings.Join(clangFilterUnknownCflags(linuxX8664Cflags), " "))
+ pctx.StaticVariable("linuxX86ClangLdflags", strings.Join(linuxX86ClangLdflags, " "))
+ pctx.StaticVariable("linuxX8664ClangLdflags", strings.Join(linuxX8664ClangLdflags, " "))
+ pctx.StaticVariable("linuxX86ClangCppflags", strings.Join(linuxX86ClangCppflags, " "))
+ pctx.StaticVariable("linuxX8664ClangCppflags", strings.Join(linuxX8664ClangCppflags, " "))
+}
+
+type toolchainLinux struct {
+ cFlags, ldFlags string
+}
+
+type toolchainLinuxX86 struct {
+ toolchain32Bit
+ toolchainLinux
+}
+
+type toolchainLinuxX8664 struct {
+ toolchain64Bit
+ toolchainLinux
+}
+
+func (t *toolchainLinuxX86) Name() string {
+ return "x86"
+}
+
+func (t *toolchainLinuxX8664) Name() string {
+ return "x86_64"
+}
+
+func (t *toolchainLinux) GccRoot() string {
+ return "${linuxGccRoot}"
+}
+
+func (t *toolchainLinux) GccTriple() string {
+ return "${linuxGccTriple}"
+}
+
+func (t *toolchainLinux) GccVersion() string {
+ return "${linuxGccVersion}"
+}
+
+func (t *toolchainLinuxX86) Cflags() string {
+ return "${linuxCflags} ${linuxX86Cflags}"
+}
+
+func (t *toolchainLinuxX8664) Cflags() string {
+ return "${linuxCflags} ${linuxX8664Cflags}"
+}
+
+func (t *toolchainLinux) Cppflags() string {
+ return ""
+}
+
+func (t *toolchainLinuxX86) Ldflags() string {
+ return "${linuxLdflags} ${linuxX86Ldflags}"
+}
+
+func (t *toolchainLinuxX8664) Ldflags() string {
+ return "${linuxLdflags} ${linuxX8664Ldflags}"
+}
+
+func (t *toolchainLinux) IncludeFlags() string {
+ return ""
+}
+
+func (t *toolchainLinuxX86) ClangTriple() string {
+ return "i686-linux-gnu"
+}
+
+func (t *toolchainLinuxX86) ClangCflags() string {
+ return "${linuxClangCflags} ${linuxX86ClangCflags}"
+}
+
+func (t *toolchainLinuxX86) ClangCppflags() string {
+ return "${linuxClangCppflags} ${linuxX86ClangCppflags}"
+}
+
+func (t *toolchainLinuxX8664) ClangTriple() string {
+ return "x86_64-linux-gnu"
+}
+
+func (t *toolchainLinuxX8664) ClangCflags() string {
+ return "${linuxClangCflags} ${linuxX8664ClangCflags}"
+}
+
+func (t *toolchainLinuxX8664) ClangCppflags() string {
+ return "${linuxClangCppflags} ${linuxX8664ClangCppflags}"
+}
+
+func (t *toolchainLinuxX86) ClangLdflags() string {
+ return "${linuxClangLdflags} ${linuxX86ClangLdflags}"
+}
+
+func (t *toolchainLinuxX8664) ClangLdflags() string {
+ return "${linuxClangLdflags} ${linuxX8664ClangLdflags}"
+}
+
+var toolchainLinuxX86Singleton Toolchain = &toolchainLinuxX86{}
+var toolchainLinuxX8664Singleton Toolchain = &toolchainLinuxX8664{}
+
+func linuxX86ToolchainFactory(archVariant string, cpuVariant string) Toolchain {
+ return toolchainLinuxX86Singleton
+}
+
+func linuxX8664ToolchainFactory(archVariant string, cpuVariant string) Toolchain {
+ return toolchainLinuxX8664Singleton
+}
+
+func init() {
+ if runtime.GOOS == "linux" {
+ registerToolchainFactory(common.Host, common.X86, linuxX86ToolchainFactory)
+ registerToolchainFactory(common.Host, common.X86_64, linuxX8664ToolchainFactory)
+ }
+}
diff --git a/cmd/soong_build/main.go b/cmd/soong_build/main.go
new file mode 100644
index 0000000..94fb6e7
--- /dev/null
+++ b/cmd/soong_build/main.go
@@ -0,0 +1,53 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package main
+
+import (
+ "flag"
+ "fmt"
+ "os"
+ "path/filepath"
+
+ "github.com/google/blueprint/bootstrap"
+
+ "android/soong"
+
+ // These imports cause the modules to register their ModuleTypes, etc. with the soong package
+ _ "android/soong/art"
+ _ "android/soong/cc"
+ "android/soong/common"
+ _ "android/soong/genrule"
+ _ "android/soong/java"
+)
+
+func main() {
+ flag.Parse()
+
+ // The top-level Blueprints file is passed as the first argument.
+ srcDir := filepath.Dir(flag.Arg(0))
+
+ ctx := soong.NewContext()
+
+ configuration, err := common.NewConfig(srcDir)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "%s", err)
+ os.Exit(1)
+ }
+
+ // Temporary hack
+ //ctx.SetIgnoreUnknownModuleTypes(true)
+
+ bootstrap.Main(ctx, configuration, common.ConfigFileName)
+}
diff --git a/cmd/soong_env/soong_env.go b/cmd/soong_env/soong_env.go
new file mode 100644
index 0000000..933e525
--- /dev/null
+++ b/cmd/soong_env/soong_env.go
@@ -0,0 +1,55 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// soong_glob is the command line tool that checks if the list of files matching a glob has
+// changed, and only updates the output file list if it has changed. It is used to optimize
+// out build.ninja regenerations when non-matching files are added. See
+// android/soong/common/glob.go for a longer description.
+package main
+
+import (
+ "flag"
+ "fmt"
+ "os"
+
+ "android/soong/env"
+)
+
+func usage() {
+ fmt.Fprintf(os.Stderr, "usage: soong_env env_file\n")
+ fmt.Fprintf(os.Stderr, "exits with success if the environment varibles in env_file match\n")
+ fmt.Fprintf(os.Stderr, "the current environment\n")
+ flag.PrintDefaults()
+ os.Exit(2)
+}
+
+func main() {
+ flag.Parse()
+
+ if flag.NArg() != 1 {
+ usage()
+ }
+
+ stale, err := env.StaleEnvFile(flag.Arg(0))
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "error: %s\n", err.Error())
+ os.Exit(1)
+ }
+
+ if stale {
+ os.Exit(1)
+ }
+
+ os.Exit(0)
+}
diff --git a/cmd/soong_glob/soong_glob.go b/cmd/soong_glob/soong_glob.go
new file mode 100644
index 0000000..6f56bb9
--- /dev/null
+++ b/cmd/soong_glob/soong_glob.go
@@ -0,0 +1,77 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// soong_glob is the command line tool that checks if the list of files matching a glob has
+// changed, and only updates the output file list if it has changed. It is used to optimize
+// out build.ninja regenerations when non-matching files are added. See
+// android/soong/common/glob.go for a longer description.
+package main
+
+import (
+ "flag"
+ "fmt"
+ "os"
+
+ "android/soong/glob"
+)
+
+var (
+ out = flag.String("o", "", "file to write list of files that match glob")
+
+ excludes multiArg
+)
+
+func init() {
+ flag.Var(&excludes, "e", "pattern to exclude from results")
+}
+
+type multiArg []string
+
+func (m *multiArg) String() string {
+ return `""`
+}
+
+func (m *multiArg) Set(s string) error {
+ *m = append(*m, s)
+ return nil
+}
+
+func (m *multiArg) Get() interface{} {
+ return m
+}
+
+func usage() {
+ fmt.Fprintf(os.Stderr, "usage: soong_glob -o out glob\n")
+ flag.PrintDefaults()
+ os.Exit(2)
+}
+
+func main() {
+ flag.Parse()
+
+ if *out == "" {
+ fmt.Fprintln(os.Stderr, "error: -o is required\n")
+ usage()
+ }
+
+ if flag.NArg() != 1 {
+ usage()
+ }
+
+ _, err := glob.GlobWithDepFile(flag.Arg(0), *out, *out+".d", excludes)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "error: %s\n", err.Error())
+ os.Exit(1)
+ }
+}
diff --git a/cmd/soong_jar/soong_jar.go b/cmd/soong_jar/soong_jar.go
new file mode 100644
index 0000000..4a4a3ab
--- /dev/null
+++ b/cmd/soong_jar/soong_jar.go
@@ -0,0 +1,238 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package main
+
+import (
+ "archive/zip"
+ "flag"
+ "fmt"
+ "io"
+ "io/ioutil"
+ "os"
+ "path/filepath"
+ "strings"
+ "time"
+)
+
+type fileArg struct {
+ relativeRoot, file string
+}
+
+type fileArgs []fileArg
+
+func (l *fileArgs) String() string {
+ return `""`
+}
+
+func (l *fileArgs) Set(s string) error {
+ if *relativeRoot == "" {
+ return fmt.Errorf("must pass -C before -f")
+ }
+
+ *l = append(*l, fileArg{*relativeRoot, s})
+ return nil
+}
+
+func (l *fileArgs) Get() interface{} {
+ return l
+}
+
+var (
+ out = flag.String("o", "", "file to write jar file to")
+ manifest = flag.String("m", "", "input manifest file name")
+ directories = flag.Bool("d", false, "include directories in jar")
+ relativeRoot = flag.String("C", "", "path to use as relative root of files in next -f or -l argument")
+ listFiles fileArgs
+ files fileArgs
+)
+
+func init() {
+ flag.Var(&listFiles, "l", "file containing list of .class files")
+ flag.Var(&files, "f", "file to include in jar")
+}
+
+func usage() {
+ fmt.Fprintf(os.Stderr, "usage: soong_jar -o jarfile [-m manifest] -C dir [-f|-l file]...\n")
+ flag.PrintDefaults()
+ os.Exit(2)
+}
+
+type zipWriter struct {
+ time time.Time
+ createdDirs map[string]bool
+ directories bool
+
+ w *zip.Writer
+}
+
+func main() {
+ flag.Parse()
+
+ if *out == "" {
+ fmt.Fprintf(os.Stderr, "error: -o is required\n")
+ usage()
+ }
+
+ w := &zipWriter{
+ time: time.Now(),
+ createdDirs: make(map[string]bool),
+ directories: *directories,
+ }
+
+ // TODO: Go's zip implementation doesn't support increasing the compression level yet
+ err := w.write(*out, listFiles, *manifest)
+ if err != nil {
+ fmt.Fprintln(os.Stderr, err.Error())
+ os.Exit(1)
+ }
+}
+
+func (z *zipWriter) write(out string, listFiles fileArgs, manifest string) error {
+ f, err := os.Create(out)
+ if err != nil {
+ return err
+ }
+
+ defer f.Close()
+ defer func() {
+ if err != nil {
+ os.Remove(out)
+ }
+ }()
+
+ z.w = zip.NewWriter(f)
+ defer z.w.Close()
+
+ for _, listFile := range listFiles {
+ err = z.writeListFile(listFile)
+ if err != nil {
+ return err
+ }
+ }
+
+ for _, file := range files {
+ err = z.writeRelFile(file.relativeRoot, file.file)
+ if err != nil {
+ return err
+ }
+ }
+
+ if manifest != "" {
+ err = z.writeFile("META-INF/MANIFEST.MF", manifest)
+ if err != nil {
+ return err
+ }
+ }
+
+ return nil
+}
+
+func (z *zipWriter) writeListFile(listFile fileArg) error {
+ list, err := ioutil.ReadFile(listFile.file)
+ if err != nil {
+ return err
+ }
+
+ files := strings.Split(string(list), "\n")
+
+ for _, file := range files {
+ file = strings.TrimSpace(file)
+ if file == "" {
+ continue
+ }
+ err = z.writeRelFile(listFile.relativeRoot, file)
+ if err != nil {
+ return err
+ }
+ }
+
+ return nil
+}
+
+func (z *zipWriter) writeRelFile(root, file string) error {
+ rel, err := filepath.Rel(root, file)
+ if err != nil {
+ return err
+ }
+
+ err = z.writeFile(rel, file)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
+func (z *zipWriter) writeFile(rel, file string) error {
+ if s, _ := os.Stat(file); s.IsDir() {
+ if z.directories {
+ return z.writeDirectory(file)
+ }
+ return nil
+ }
+
+ if z.directories {
+ dir, _ := filepath.Split(rel)
+ err := z.writeDirectory(dir)
+ if err != nil {
+ return err
+ }
+ }
+
+ fileHeader := &zip.FileHeader{
+ Name: rel,
+ Method: zip.Deflate,
+ }
+ fileHeader.SetModTime(z.time)
+
+ out, err := z.w.CreateHeader(fileHeader)
+ if err != nil {
+ return err
+ }
+
+ in, err := os.Open(file)
+ if err != nil {
+ return err
+ }
+ defer in.Close()
+
+ _, err = io.Copy(out, in)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
+func (z *zipWriter) writeDirectory(dir string) error {
+ for dir != "" && !z.createdDirs[dir] {
+ z.createdDirs[dir] = true
+
+ dirHeader := &zip.FileHeader{
+ Name: dir,
+ }
+ dirHeader.SetMode(os.ModeDir)
+ dirHeader.SetModTime(z.time)
+
+ _, err := z.w.CreateHeader(dirHeader)
+ if err != nil {
+ return err
+ }
+
+ dir, _ = filepath.Split(dir)
+ }
+
+ return nil
+}
diff --git a/common/arch.go b/common/arch.go
new file mode 100644
index 0000000..3d685e5
--- /dev/null
+++ b/common/arch.go
@@ -0,0 +1,699 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package common
+
+import (
+ "fmt"
+ "reflect"
+ "runtime"
+ "strings"
+
+ "android/soong"
+
+ "github.com/google/blueprint"
+ "github.com/google/blueprint/proptools"
+)
+
+func init() {
+ soong.RegisterEarlyMutator("host_or_device", HostOrDeviceMutator)
+ soong.RegisterEarlyMutator("arch", ArchMutator)
+}
+
+var (
+ Arm = newArch("arm", "lib32")
+ Arm64 = newArch("arm64", "lib64")
+ Mips = newArch("mips", "lib32")
+ Mips64 = newArch("mips64", "lib64")
+ X86 = newArch("x86", "lib32")
+ X86_64 = newArch("x86_64", "lib64")
+
+ Common = ArchType{
+ Name: "common",
+ }
+)
+
+/*
+Example blueprints file containing all variant property groups, with comment listing what type
+of variants get properties in that group:
+
+module {
+ arch: {
+ arm: {
+ // Host or device variants with arm architecture
+ },
+ arm64: {
+ // Host or device variants with arm64 architecture
+ },
+ mips: {
+ // Host or device variants with mips architecture
+ },
+ mips64: {
+ // Host or device variants with mips64 architecture
+ },
+ x86: {
+ // Host or device variants with x86 architecture
+ },
+ x86_64: {
+ // Host or device variants with x86_64 architecture
+ },
+ },
+ multilib: {
+ lib32: {
+ // Host or device variants for 32-bit architectures
+ },
+ lib64: {
+ // Host or device variants for 64-bit architectures
+ },
+ },
+ target: {
+ android: {
+ // Device variants
+ },
+ host: {
+ // Host variants
+ },
+ linux: {
+ // Linux host variants
+ },
+ darwin: {
+ // Darwin host variants
+ },
+ windows: {
+ // Windows host variants
+ },
+ not_windows: {
+ // Non-windows host variants
+ },
+ },
+}
+*/
+
+type archProperties struct {
+ // Properties to vary by target architecture
+ Arch struct {
+ // Properties for module variants being built to run on arm (host or device)
+ Arm interface{} `blueprint:"filter(android:\"arch_variant\")"`
+ // Properties for module variants being built to run on arm64 (host or device)
+ Arm64 interface{} `blueprint:"filter(android:\"arch_variant\")"`
+ // Properties for module variants being built to run on mips (host or device)
+ Mips interface{} `blueprint:"filter(android:\"arch_variant\")"`
+ // Properties for module variants being built to run on mips64 (host or device)
+ Mips64 interface{} `blueprint:"filter(android:\"arch_variant\")"`
+ // Properties for module variants being built to run on x86 (host or device)
+ X86 interface{} `blueprint:"filter(android:\"arch_variant\")"`
+ // Properties for module variants being built to run on x86_64 (host or device)
+ X86_64 interface{} `blueprint:"filter(android:\"arch_variant\")"`
+
+ // Arm arch variants
+ Armv5te interface{} `blueprint:"filter(android:\"arch_variant\")"`
+ Armv7_a interface{} `blueprint:"filter(android:\"arch_variant\")"`
+ Armv7_a_neon interface{} `blueprint:"filter(android:\"arch_variant\")"`
+
+ // Arm cpu variants
+ Cortex_a7 interface{} `blueprint:"filter(android:\"arch_variant\")"`
+ Cortex_a8 interface{} `blueprint:"filter(android:\"arch_variant\")"`
+ Cortex_a9 interface{} `blueprint:"filter(android:\"arch_variant\")"`
+ Cortex_a15 interface{} `blueprint:"filter(android:\"arch_variant\")"`
+ Krait interface{} `blueprint:"filter(android:\"arch_variant\")"`
+ Denver interface{} `blueprint:"filter(android:\"arch_variant\")"`
+
+ // Arm64 cpu variants
+ Denver64 interface{} `blueprint:"filter(android:\"arch_variant\")"`
+
+ // Mips arch variants
+ Mips_rev6 interface{} `blueprint:"filter(android:\"arch_variant\")"`
+
+ // X86 arch variants
+ X86_sse3 interface{} `blueprint:"filter(android:\"arch_variant\")"`
+ X86_sse4 interface{} `blueprint:"filter(android:\"arch_variant\")"`
+
+ // X86 cpu variants
+ Atom interface{} `blueprint:"filter(android:\"arch_variant\")"`
+ Silvermont interface{} `blueprint:"filter(android:\"arch_variant\")"`
+ }
+
+ // Properties to vary by 32-bit or 64-bit
+ Multilib struct {
+ // Properties for module variants being built to run on 32-bit devices
+ Lib32 interface{} `blueprint:"filter(android:\"arch_variant\")"`
+ // Properties for module variants being built to run on 64-bit devices
+ Lib64 interface{} `blueprint:"filter(android:\"arch_variant\")"`
+ }
+ // Properties to vary by build target (host or device, os, os+archictecture)
+ Target struct {
+ // Properties for module variants being built to run on the host
+ Host interface{} `blueprint:"filter(android:\"arch_variant\")"`
+ // Properties for module variants being built to run on the device
+ Android interface{} `blueprint:"filter(android:\"arch_variant\")"`
+ // Properties for module variants being built to run on arm devices
+ Android_arm interface{} `blueprint:"filter(android:\"arch_variant\")"`
+ // Properties for module variants being built to run on arm64 devices
+ Android_arm64 interface{} `blueprint:"filter(android:\"arch_variant\")"`
+ // Properties for module variants being built to run on mips devices
+ Android_mips interface{} `blueprint:"filter(android:\"arch_variant\")"`
+ // Properties for module variants being built to run on mips64 devices
+ Android_mips64 interface{} `blueprint:"filter(android:\"arch_variant\")"`
+ // Properties for module variants being built to run on x86 devices
+ Android_x86 interface{} `blueprint:"filter(android:\"arch_variant\")"`
+ // Properties for module variants being built to run on x86_64 devices
+ Android_x86_64 interface{} `blueprint:"filter(android:\"arch_variant\")"`
+ // Properties for module variants being built to run on devices that support 64-bit
+ Android64 interface{} `blueprint:"filter(android:\"arch_variant\")"`
+ // Properties for module variants being built to run on devices that do not support 64-bit
+ Android32 interface{} `blueprint:"filter(android:\"arch_variant\")"`
+ // Properties for module variants being built to run on linux hosts
+ Linux interface{} `blueprint:"filter(android:\"arch_variant\")"`
+ // Properties for module variants being built to run on linux x86 hosts
+ Linux_x86 interface{} `blueprint:"filter(android:\"arch_variant\")"`
+ // Properties for module variants being built to run on linux x86_64 hosts
+ Linux_x86_64 interface{} `blueprint:"filter(android:\"arch_variant\")"`
+ // Properties for module variants being built to run on darwin hosts
+ Darwin interface{} `blueprint:"filter(android:\"arch_variant\")"`
+ // Properties for module variants being built to run on darwin x86 hosts
+ Darwin_x86 interface{} `blueprint:"filter(android:\"arch_variant\")"`
+ // Properties for module variants being built to run on darwin x86_64 hosts
+ Darwin_x86_64 interface{} `blueprint:"filter(android:\"arch_variant\")"`
+ // Properties for module variants being built to run on windows hosts
+ Windows interface{} `blueprint:"filter(android:\"arch_variant\")"`
+ // Properties for module variants being built to run on linux or darwin hosts
+ Not_windows interface{} `blueprint:"filter(android:\"arch_variant\")"`
+ }
+}
+
+// An Arch indicates a single CPU architecture.
+type Arch struct {
+ ArchType ArchType
+ ArchVariant string
+ CpuVariant string
+ Abi string
+}
+
+func (a Arch) String() string {
+ s := a.ArchType.String()
+ if a.ArchVariant != "" {
+ s += "_" + a.ArchVariant
+ }
+ if a.CpuVariant != "" {
+ s += "_" + a.CpuVariant
+ }
+ return s
+}
+
+type ArchType struct {
+ Name string
+ Multilib string
+}
+
+func newArch(name, multilib string) ArchType {
+ return ArchType{
+ Name: name,
+ Multilib: multilib,
+ }
+}
+
+func (a ArchType) String() string {
+ return a.Name
+}
+
+type HostOrDeviceSupported int
+
+const (
+ _ HostOrDeviceSupported = iota
+ HostSupported
+ DeviceSupported
+ HostAndDeviceSupported
+)
+
+type HostOrDevice int
+
+const (
+ _ HostOrDevice = iota
+ Host
+ Device
+)
+
+func (hod HostOrDevice) String() string {
+ switch hod {
+ case Device:
+ return "device"
+ case Host:
+ return "host"
+ default:
+ panic(fmt.Sprintf("unexpected HostOrDevice value %d", hod))
+ }
+}
+
+func (hod HostOrDevice) Property() string {
+ switch hod {
+ case Device:
+ return "android"
+ case Host:
+ return "host"
+ default:
+ panic(fmt.Sprintf("unexpected HostOrDevice value %d", hod))
+ }
+}
+
+func (hod HostOrDevice) Host() bool {
+ if hod == 0 {
+ panic("HostOrDevice unset")
+ }
+ return hod == Host
+}
+
+func (hod HostOrDevice) Device() bool {
+ if hod == 0 {
+ panic("HostOrDevice unset")
+ }
+ return hod == Device
+}
+
+var hostOrDeviceName = map[HostOrDevice]string{
+ Device: "device",
+ Host: "host",
+}
+
+var (
+ armArch = Arch{
+ ArchType: Arm,
+ ArchVariant: "armv7-a-neon",
+ CpuVariant: "cortex-a15",
+ Abi: "armeabi-v7a",
+ }
+ arm64Arch = Arch{
+ ArchType: Arm64,
+ CpuVariant: "denver64",
+ Abi: "arm64-v8a",
+ }
+ x86Arch = Arch{
+ ArchType: X86,
+ }
+ x8664Arch = Arch{
+ ArchType: X86_64,
+ }
+ commonArch = Arch{
+ ArchType: Common,
+ }
+)
+
+func HostOrDeviceMutator(mctx blueprint.EarlyMutatorContext) {
+ var module AndroidModule
+ var ok bool
+ if module, ok = mctx.Module().(AndroidModule); !ok {
+ return
+ }
+
+ hods := []HostOrDevice{}
+
+ if module.base().HostSupported() {
+ hods = append(hods, Host)
+ }
+
+ if module.base().DeviceSupported() {
+ hods = append(hods, Device)
+ }
+
+ if len(hods) == 0 {
+ return
+ }
+
+ hodNames := []string{}
+ for _, hod := range hods {
+ hodNames = append(hodNames, hod.String())
+ }
+
+ modules := mctx.CreateVariations(hodNames...)
+ for i, m := range modules {
+ m.(AndroidModule).base().SetHostOrDevice(hods[i])
+ }
+}
+
+func ArchMutator(mctx blueprint.EarlyMutatorContext) {
+ var module AndroidModule
+ var ok bool
+ if module, ok = mctx.Module().(AndroidModule); !ok {
+ return
+ }
+
+ // TODO: this is all hardcoded for arm64 primary, arm secondary for now
+ // Replace with a configuration file written by lunch or bootstrap
+
+ arches := []Arch{}
+
+ if module.base().HostSupported() && module.base().HostOrDevice().Host() {
+ switch module.base().commonProperties.Compile_multilib {
+ case "common":
+ arches = append(arches, commonArch)
+ case "both":
+ arches = append(arches, x8664Arch, x86Arch)
+ case "first", "64":
+ arches = append(arches, x8664Arch)
+ case "32":
+ arches = append(arches, x86Arch)
+ default:
+ arches = append(arches, x8664Arch)
+ }
+ }
+
+ if module.base().DeviceSupported() && module.base().HostOrDevice().Device() {
+ switch module.base().commonProperties.Compile_multilib {
+ case "common":
+ arches = append(arches, commonArch)
+ case "both":
+ arches = append(arches, arm64Arch, armArch)
+ case "first", "64":
+ arches = append(arches, arm64Arch)
+ case "32":
+ arches = append(arches, armArch)
+ default:
+ mctx.ModuleErrorf(`compile_multilib must be "both", "first", "32", or "64", found %q`,
+ module.base().commonProperties.Compile_multilib)
+ }
+ }
+
+ if len(arches) == 0 {
+ return
+ }
+
+ archNames := []string{}
+ for _, arch := range arches {
+ archNames = append(archNames, arch.String())
+ }
+
+ modules := mctx.CreateVariations(archNames...)
+
+ for i, m := range modules {
+ m.(AndroidModule).base().SetArch(arches[i])
+ m.(AndroidModule).base().setArchProperties(mctx)
+ }
+}
+
+func InitArchModule(m AndroidModule, defaultMultilib Multilib,
+ propertyStructs ...interface{}) (blueprint.Module, []interface{}) {
+
+ base := m.base()
+
+ base.commonProperties.Compile_multilib = string(defaultMultilib)
+
+ base.generalProperties = append(base.generalProperties,
+ propertyStructs...)
+
+ for _, properties := range base.generalProperties {
+ propertiesValue := reflect.ValueOf(properties)
+ if propertiesValue.Kind() != reflect.Ptr {
+ panic("properties must be a pointer to a struct")
+ }
+
+ propertiesValue = propertiesValue.Elem()
+ if propertiesValue.Kind() != reflect.Struct {
+ panic("properties must be a pointer to a struct")
+ }
+
+ archProperties := &archProperties{}
+ forEachInterface(reflect.ValueOf(archProperties), func(v reflect.Value) {
+ newValue := proptools.CloneEmptyProperties(propertiesValue)
+ v.Set(newValue)
+ })
+
+ base.archProperties = append(base.archProperties, archProperties)
+ }
+
+ var allProperties []interface{}
+ allProperties = append(allProperties, base.generalProperties...)
+ for _, asp := range base.archProperties {
+ allProperties = append(allProperties, asp)
+ }
+
+ return m, allProperties
+}
+
+var dashToUnderscoreReplacer = strings.NewReplacer("-", "_")
+
+// Rewrite the module's properties structs to contain arch-specific values.
+func (a *AndroidModuleBase) setArchProperties(ctx blueprint.EarlyMutatorContext) {
+ arch := a.commonProperties.CompileArch
+ hod := a.commonProperties.CompileHostOrDevice
+
+ if arch.ArchType == Common {
+ return
+ }
+
+ for i := range a.generalProperties {
+ generalPropsValue := reflect.ValueOf(a.generalProperties[i]).Elem()
+
+ // Handle arch-specific properties in the form:
+ // arch: {
+ // arm64: {
+ // key: value,
+ // },
+ // },
+ t := arch.ArchType
+ field := proptools.FieldNameForProperty(t.Name)
+ a.extendProperties(ctx, "arch", t.Name, generalPropsValue,
+ reflect.ValueOf(a.archProperties[i].Arch).FieldByName(field).Elem().Elem())
+
+ // Handle arch-variant-specific properties in the form:
+ // arch: {
+ // variant: {
+ // key: value,
+ // },
+ // },
+ v := dashToUnderscoreReplacer.Replace(arch.ArchVariant)
+ if v != "" {
+ field := proptools.FieldNameForProperty(v)
+ a.extendProperties(ctx, "arch", v, generalPropsValue,
+ reflect.ValueOf(a.archProperties[i].Arch).FieldByName(field).Elem().Elem())
+ }
+
+ // Handle cpu-variant-specific properties in the form:
+ // arch: {
+ // variant: {
+ // key: value,
+ // },
+ // },
+ c := dashToUnderscoreReplacer.Replace(arch.CpuVariant)
+ if c != "" {
+ field := proptools.FieldNameForProperty(c)
+ a.extendProperties(ctx, "arch", c, generalPropsValue,
+ reflect.ValueOf(a.archProperties[i].Arch).FieldByName(field).Elem().Elem())
+ }
+
+ // Handle multilib-specific properties in the form:
+ // multilib: {
+ // lib32: {
+ // key: value,
+ // },
+ // },
+ multilibField := proptools.FieldNameForProperty(t.Multilib)
+ a.extendProperties(ctx, "multilib", t.Multilib, generalPropsValue,
+ reflect.ValueOf(a.archProperties[i].Multilib).FieldByName(multilibField).Elem().Elem())
+
+ // Handle host-or-device-specific properties in the form:
+ // target: {
+ // host: {
+ // key: value,
+ // },
+ // },
+ hodProperty := hod.Property()
+ hodField := proptools.FieldNameForProperty(hodProperty)
+ a.extendProperties(ctx, "target", hodProperty, generalPropsValue,
+ reflect.ValueOf(a.archProperties[i].Target).FieldByName(hodField).Elem().Elem())
+
+ // Handle host target properties in the form:
+ // target: {
+ // linux: {
+ // key: value,
+ // },
+ // not_windows: {
+ // key: value,
+ // },
+ // linux_x86: {
+ // key: value,
+ // },
+ // linux_arm: {
+ // key: value,
+ // },
+ // },
+ var osList = []struct {
+ goos string
+ field string
+ }{
+ {"darwin", "Darwin"},
+ {"linux", "Linux"},
+ {"windows", "Windows"},
+ }
+
+ if hod.Host() {
+ for _, v := range osList {
+ if v.goos == runtime.GOOS {
+ a.extendProperties(ctx, "target", v.goos, generalPropsValue,
+ reflect.ValueOf(a.archProperties[i].Target).FieldByName(v.field).Elem().Elem())
+ t := arch.ArchType
+ a.extendProperties(ctx, "target", v.goos+"_"+t.Name, generalPropsValue,
+ reflect.ValueOf(a.archProperties[i].Target).FieldByName(v.field+"_"+t.Name).Elem().Elem())
+ }
+ }
+ a.extendProperties(ctx, "target", "not_windows", generalPropsValue,
+ reflect.ValueOf(a.archProperties[i].Target).FieldByName("Not_windows").Elem().Elem())
+ }
+
+ // Handle 64-bit device properties in the form:
+ // target {
+ // android64 {
+ // key: value,
+ // },
+ // android32 {
+ // key: value,
+ // },
+ // },
+ // WARNING: this is probably not what you want to use in your blueprints file, it selects
+ // options for all targets on a device that supports 64-bit binaries, not just the targets
+ // that are being compiled for 64-bit. Its expected use case is binaries like linker and
+ // debuggerd that need to know when they are a 32-bit process running on a 64-bit device
+ if hod.Device() {
+ if true /* && target_is_64_bit */ {
+ a.extendProperties(ctx, "target", "android64", generalPropsValue,
+ reflect.ValueOf(a.archProperties[i].Target).FieldByName("Android64").Elem().Elem())
+ } else {
+ a.extendProperties(ctx, "target", "android32", generalPropsValue,
+ reflect.ValueOf(a.archProperties[i].Target).FieldByName("Android32").Elem().Elem())
+ }
+ }
+
+ // Handle device architecture properties in the form:
+ // target {
+ // android_arm {
+ // key: value,
+ // },
+ // android_x86 {
+ // key: value,
+ // },
+ // },
+ if hod.Device() {
+ t := arch.ArchType
+ a.extendProperties(ctx, "target", "android_"+t.Name, generalPropsValue,
+ reflect.ValueOf(a.archProperties[i].Target).FieldByName("Android_"+t.Name).Elem().Elem())
+ }
+
+ if ctx.Failed() {
+ return
+ }
+ }
+}
+
+func forEachInterface(v reflect.Value, f func(reflect.Value)) {
+ switch v.Kind() {
+ case reflect.Interface:
+ f(v)
+ case reflect.Struct:
+ for i := 0; i < v.NumField(); i++ {
+ forEachInterface(v.Field(i), f)
+ }
+ case reflect.Ptr:
+ forEachInterface(v.Elem(), f)
+ default:
+ panic(fmt.Errorf("Unsupported kind %s", v.Kind()))
+ }
+}
+
+// TODO: move this to proptools
+func (a *AndroidModuleBase) extendProperties(ctx blueprint.EarlyMutatorContext, variationType, variationName string,
+ dstValue, srcValue reflect.Value) {
+ a.extendPropertiesRecursive(ctx, variationType, variationName, dstValue, srcValue, "")
+}
+
+func (a *AndroidModuleBase) extendPropertiesRecursive(ctx blueprint.EarlyMutatorContext, variationType, variationName string,
+ dstValue, srcValue reflect.Value, recursePrefix string) {
+
+ typ := dstValue.Type()
+ if srcValue.Type() != typ {
+ panic(fmt.Errorf("can't extend mismatching types (%s <- %s)",
+ dstValue.Kind(), srcValue.Kind()))
+ }
+
+ for i := 0; i < srcValue.NumField(); i++ {
+ field := typ.Field(i)
+ if field.PkgPath != "" {
+ // The field is not exported so just skip it.
+ continue
+ }
+
+ srcFieldValue := srcValue.Field(i)
+ dstFieldValue := dstValue.Field(i)
+
+ localPropertyName := proptools.PropertyNameForField(field.Name)
+ propertyName := fmt.Sprintf("%s.%s.%s%s", variationType, variationName,
+ recursePrefix, localPropertyName)
+ propertyPresentInVariation := ctx.ContainsProperty(propertyName)
+
+ if !propertyPresentInVariation {
+ continue
+ }
+
+ tag := field.Tag.Get("android")
+ tags := map[string]bool{}
+ for _, entry := range strings.Split(tag, ",") {
+ if entry != "" {
+ tags[entry] = true
+ }
+ }
+
+ if !tags["arch_variant"] {
+ ctx.PropertyErrorf(propertyName, "property %q can't be specific to a build variant",
+ recursePrefix+proptools.PropertyNameForField(field.Name))
+ continue
+ }
+
+ if !ctx.ContainsProperty(propertyName) {
+ continue
+ }
+ a.extendedProperties[localPropertyName] = struct{}{}
+
+ switch srcFieldValue.Kind() {
+ case reflect.Bool:
+ // Replace the original value.
+ dstFieldValue.Set(srcFieldValue)
+ case reflect.String:
+ // Append the extension string.
+ dstFieldValue.SetString(dstFieldValue.String() +
+ srcFieldValue.String())
+ case reflect.Struct:
+ // Recursively extend the struct's fields.
+ newRecursePrefix := fmt.Sprintf("%s%s.", recursePrefix, strings.ToLower(field.Name))
+ a.extendPropertiesRecursive(ctx, variationType, variationName,
+ dstFieldValue, srcFieldValue,
+ newRecursePrefix)
+ case reflect.Slice:
+ dstFieldValue.Set(reflect.AppendSlice(dstFieldValue, srcFieldValue))
+ case reflect.Ptr, reflect.Interface:
+ // Recursively extend the pointed-to struct's fields.
+ if dstFieldValue.IsNil() != srcFieldValue.IsNil() {
+ panic(fmt.Errorf("can't extend field %q: nilitude mismatch"))
+ }
+ if dstFieldValue.Type() != srcFieldValue.Type() {
+ panic(fmt.Errorf("can't extend field %q: type mismatch"))
+ }
+ if !dstFieldValue.IsNil() {
+ newRecursePrefix := fmt.Sprintf("%s.%s", recursePrefix, field.Name)
+ a.extendPropertiesRecursive(ctx, variationType, variationName,
+ dstFieldValue.Elem(), srcFieldValue.Elem(),
+ newRecursePrefix)
+ }
+ default:
+ panic(fmt.Errorf("unexpected kind for property struct field %q: %s",
+ field.Name, srcFieldValue.Kind()))
+ }
+ }
+}
diff --git a/common/config.go b/common/config.go
new file mode 100644
index 0000000..10ed4f0
--- /dev/null
+++ b/common/config.go
@@ -0,0 +1,255 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package common
+
+import (
+ "encoding/json"
+ "fmt"
+ "os"
+ "path/filepath"
+ "runtime"
+ "sync"
+)
+
+// The configuration file name
+const ConfigFileName = "soong.config"
+
+// A FileConfigurableOptions contains options which can be configured by the
+// config file. These will be included in the config struct.
+type FileConfigurableOptions struct {
+}
+
+func NewFileConfigurableOptions() FileConfigurableOptions {
+ f := FileConfigurableOptions{}
+ return f
+}
+
+type Config struct {
+ *config
+}
+
+// A config object represents the entire build configuration for Blue.
+type config struct {
+ FileConfigurableOptions
+
+ srcDir string // the path of the root source directory
+
+ envLock sync.Mutex
+ envDeps map[string]string
+}
+
+// loads configuration options from a JSON file in the cwd.
+func loadFromConfigFile(config *config) error {
+ // Make a proxy config
+ var configProxy FileConfigurableOptions
+
+ // Try to open the file
+ configFileReader, err := os.Open(ConfigFileName)
+ defer configFileReader.Close()
+ if os.IsNotExist(err) {
+ // Need to create a file, so that blueprint & ninja don't get in
+ // a dependency tracking loop.
+ // Make a file-configurable-options with defaults, write it out using
+ // a json writer.
+ configProxy = NewFileConfigurableOptions()
+ err = saveToConfigFile(configProxy)
+ if err != nil {
+ return err
+ }
+ } else {
+ // Make a decoder for it
+ jsonDecoder := json.NewDecoder(configFileReader)
+ err = jsonDecoder.Decode(&configProxy)
+ if err != nil {
+ return fmt.Errorf("config file: %s did not parse correctly: "+err.Error(), ConfigFileName)
+ }
+ }
+
+ // Copy the configurable options out of the config_proxy into the config,
+ // and we're done!
+ config.FileConfigurableOptions = configProxy
+
+ // No error
+ return nil
+}
+
+func saveToConfigFile(config FileConfigurableOptions) error {
+ data, err := json.MarshalIndent(&config, "", " ")
+ if err != nil {
+ return fmt.Errorf("cannot marshal config data: %s", err.Error())
+ }
+
+ configFileWriter, err := os.Create(ConfigFileName)
+ if err != nil {
+ return fmt.Errorf("cannot create empty config file %s: %s\n", ConfigFileName, err.Error())
+ }
+ defer configFileWriter.Close()
+
+ _, err = configFileWriter.Write(data)
+ if err != nil {
+ return fmt.Errorf("default config file: %s could not be written: %s", ConfigFileName, err.Error())
+ }
+
+ return nil
+}
+
+// New creates a new Config object. The srcDir argument specifies the path to
+// the root source directory. It also loads the config file, if found.
+func NewConfig(srcDir string) (Config, error) {
+ // Make a config with default options
+ config := Config{
+ config: &config{
+ srcDir: srcDir,
+ envDeps: make(map[string]string),
+ },
+ }
+
+ // Load any configurable options from the configuration file
+ err := loadFromConfigFile(config.config)
+ if err != nil {
+ return Config{}, err
+ }
+
+ return config, nil
+}
+
+func (c *config) SrcDir() string {
+ return c.srcDir
+}
+
+func (c *config) IntermediatesDir() string {
+ return ".intermediates"
+}
+
+// HostGoOS returns the OS of the system that the Go toolchain is being run on.
+func (c *config) HostGoOS() string {
+ return runtime.GOOS
+}
+
+// PrebuiltOS returns the name of the host OS used in prebuilts directories
+func (c *config) PrebuiltOS() string {
+ switch runtime.GOOS {
+ case "linux":
+ return "linux-x86"
+ case "darwin":
+ return "darwin-x86"
+ default:
+ panic("Unknown GOOS")
+ }
+}
+
+// GoRoot returns the path to the root directory of the Go toolchain.
+func (c *config) GoRoot() string {
+ return fmt.Sprintf("%s/prebuilts/go/%s", c.srcDir, c.PrebuiltOS())
+}
+
+func (c *config) CpPreserveSymlinksFlags() string {
+ switch c.HostGoOS() {
+ case "darwin":
+ return "-R"
+ case "linux":
+ return "-d"
+ default:
+ return ""
+ }
+}
+
+func (c *config) Getenv(key string) string {
+ var val string
+ var exists bool
+ c.envLock.Lock()
+ if val, exists = c.envDeps[key]; !exists {
+ val = os.Getenv(key)
+ c.envDeps[key] = val
+ }
+ c.envLock.Unlock()
+ return val
+}
+
+func (c *config) EnvDeps() map[string]string {
+ return c.envDeps
+}
+
+// DeviceName returns the name of the current device target
+// TODO: take an AndroidModuleContext to select the device name for multi-device builds
+func (c *config) DeviceName() string {
+ return "unset"
+}
+
+// DeviceOut returns the path to out directory for device targets
+func (c *config) DeviceOut() string {
+ return filepath.Join("target/product", c.DeviceName())
+}
+
+// HostOut returns the path to out directory for host targets
+func (c *config) HostOut() string {
+ return filepath.Join("host", c.PrebuiltOS())
+}
+
+// HostBin returns the path to bin directory for host targets
+func (c *config) HostBin() string {
+ return filepath.Join(c.HostOut(), "bin")
+}
+
+// HostBinTool returns the path to a host tool in the bin directory for host targets
+func (c *config) HostBinTool(tool string) (string, error) {
+ return filepath.Join(c.HostBin(), tool), nil
+}
+
+// HostJavaDir returns the path to framework directory for host targets
+func (c *config) HostJavaDir() string {
+ return filepath.Join(c.HostOut(), "framework")
+}
+
+// HostJavaTool returns the path to a host tool in the frameworks directory for host targets
+func (c *config) HostJavaTool(tool string) (string, error) {
+ return filepath.Join(c.HostJavaDir(), tool), nil
+}
+
+func (c *config) ResourceOverlays() []string {
+ return nil
+}
+
+func (c *config) PlatformVersion() string {
+ return "M"
+}
+
+func (c *config) PlatformSdkVersion() string {
+ return "22"
+}
+
+func (c *config) BuildNumber() string {
+ return "000000"
+}
+
+func (c *config) ProductAaptConfig() []string {
+ return []string{"normal", "large", "xlarge", "hdpi", "xhdpi", "xxhdpi"}
+}
+
+func (c *config) ProductAaptPreferredConfig() string {
+ return "xhdpi"
+}
+
+func (c *config) ProductAaptCharacteristics() string {
+ return "nosdcard"
+}
+
+func (c *config) DefaultAppCertificateDir() string {
+ return filepath.Join(c.SrcDir(), "build/target/product/security")
+}
+
+func (c *config) DefaultAppCertificate() string {
+ return filepath.Join(c.DefaultAppCertificateDir(), "testkey")
+}
diff --git a/common/defs.go b/common/defs.go
new file mode 100644
index 0000000..f5b02fe
--- /dev/null
+++ b/common/defs.go
@@ -0,0 +1,73 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package common
+
+import (
+ "path/filepath"
+
+ "github.com/google/blueprint"
+ "github.com/google/blueprint/bootstrap"
+)
+
+var (
+ pctx = blueprint.NewPackageContext("android/soong/common")
+
+ cpPreserveSymlinks = pctx.VariableConfigMethod("cpPreserveSymlinks",
+ Config.CpPreserveSymlinksFlags)
+
+ srcDir = pctx.VariableConfigMethod("srcDir", Config.SrcDir)
+
+ androidbpCmd = filepath.Join(bootstrap.BinDir, "androidbp")
+ androidbp = pctx.StaticRule("androidbp",
+ blueprint.RuleParams{
+ Command: androidbpCmd + " ${srcDir}/Android.bp $in $out",
+ Description: "androidbp $out",
+ })
+
+ // A phony rule that is not the built-in Ninja phony rule. The built-in
+ // phony rule has special behavior that is sometimes not desired. See the
+ // Ninja docs for more details.
+ Phony = pctx.StaticRule("Phony",
+ blueprint.RuleParams{
+ Command: "# phony $out",
+ Description: "phony $out",
+ })
+
+ // GeneratedFile is a rule for indicating that a given file was generated
+ // while running soong. This allows the file to be cleaned up if it ever
+ // stops being generated by soong.
+ GeneratedFile = pctx.StaticRule("GeneratedFile",
+ blueprint.RuleParams{
+ Command: "# generated $out",
+ Description: "generated $out",
+ Generator: true,
+ })
+
+ // A copy rule.
+ Cp = pctx.StaticRule("Cp",
+ blueprint.RuleParams{
+ Command: "cp $cpPreserveSymlinks $cpFlags $in $out",
+ Description: "cp $out",
+ },
+ "cpFlags")
+
+ // A symlink rule.
+ Symlink = pctx.StaticRule("Symlink",
+ blueprint.RuleParams{
+ Command: "ln -f -s $fromPath $out",
+ Description: "symlink $out",
+ },
+ "fromPath")
+)
diff --git a/common/env.go b/common/env.go
new file mode 100644
index 0000000..3214baa
--- /dev/null
+++ b/common/env.go
@@ -0,0 +1,52 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package common
+
+import (
+ "android/soong"
+ "android/soong/env"
+
+ "github.com/google/blueprint"
+)
+
+// This file supports dependencies on environment variables. During build manifest generation,
+// any dependency on an environment variable is added to a list. During the singleton phase
+// a JSON file is written containing the current value of all used environment variables.
+// The next time the top-level build script is run, it uses the soong_env executable to
+// compare the contents of the environment variables, rewriting the file if necessary to cause
+// a manifest regeneration.
+
+func init() {
+ soong.RegisterSingletonType("env", EnvSingleton)
+}
+
+func EnvSingleton() blueprint.Singleton {
+ return &envSingleton{}
+}
+
+type envSingleton struct{}
+
+func (c *envSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
+ envDeps := ctx.Config().(Config).EnvDeps()
+
+ envFile := ".soong.environment"
+
+ err := env.WriteEnvFile(envFile, envDeps)
+ if err != nil {
+ ctx.Errorf(err.Error())
+ }
+
+ ctx.AddNinjaFileDeps(envFile)
+}
diff --git a/common/glob.go b/common/glob.go
new file mode 100644
index 0000000..5a01cf5
--- /dev/null
+++ b/common/glob.go
@@ -0,0 +1,121 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package common
+
+import (
+ "fmt"
+ "path/filepath"
+
+ "github.com/google/blueprint"
+ "github.com/google/blueprint/bootstrap"
+
+ "android/soong/glob"
+)
+
+// This file supports globbing source files in Blueprints files.
+//
+// The build.ninja file needs to be regenerated any time a file matching the glob is added
+// or removed. The naive solution is to have the build.ninja file depend on all the
+// traversed directories, but this will cause the regeneration step to run every time a
+// non-matching file is added to a traversed directory, including backup files created by
+// editors.
+//
+// The solution implemented here optimizes out regenerations when the directory modifications
+// don't match the glob by having the build.ninja file depend on an intermedate file that
+// is only updated when a file matching the glob is added or removed. The intermediate file
+// depends on the traversed directories via a depfile. The depfile is used to avoid build
+// errors if a directory is deleted - a direct dependency on the deleted directory would result
+// in a build failure with a "missing and no known rule to make it" error.
+
+var (
+ globCmd = filepath.Join(bootstrap.BinDir, "soong_glob")
+
+ // globRule rule traverses directories to produce a list of files that match $glob
+ // and writes it to $out if it has changed, and writes the directories to $out.d
+ globRule = pctx.StaticRule("globRule",
+ blueprint.RuleParams{
+ Command: fmt.Sprintf(`%s -o $out $excludes "$glob"`, globCmd),
+ Description: "glob $glob",
+
+ Restat: true,
+ Deps: blueprint.DepsGCC,
+ Depfile: "$out.d",
+ },
+ "glob", "excludes")
+)
+
+func hasGlob(in []string) bool {
+ for _, s := range in {
+ if glob.IsGlob(s) {
+ return true
+ }
+ }
+
+ return false
+}
+
+// The subset of ModuleContext and SingletonContext needed by Glob
+type globContext interface {
+ Build(pctx *blueprint.PackageContext, params blueprint.BuildParams)
+ AddNinjaFileDeps(deps ...string)
+}
+
+func Glob(ctx globContext, outDir string, globPattern string, excludes []string) ([]string, error) {
+ fileListFile := filepath.Join(outDir, "glob", globToString(globPattern))
+ depFile := fileListFile + ".d"
+
+ // Get a globbed file list, and write out fileListFile and depFile
+ files, err := glob.GlobWithDepFile(globPattern, fileListFile, depFile, excludes)
+ if err != nil {
+ return nil, err
+ }
+
+ GlobRule(ctx, globPattern, excludes, fileListFile, depFile)
+
+ // Make build.ninja depend on the fileListFile
+ ctx.AddNinjaFileDeps(fileListFile)
+
+ return files, nil
+}
+
+func GlobRule(ctx globContext, globPattern string, excludes []string,
+ fileListFile, depFile string) {
+
+ // Create a rule to rebuild fileListFile if a directory in depFile changes. fileListFile
+ // will only be rewritten if it has changed, preventing unnecesary build.ninja regenerations.
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: globRule,
+ Outputs: []string{fileListFile},
+ Implicits: []string{globCmd},
+ Args: map[string]string{
+ "glob": globPattern,
+ "excludes": JoinWithPrefixAndQuote(excludes, "-e "),
+ },
+ })
+}
+
+func globToString(glob string) string {
+ ret := ""
+ for _, c := range glob {
+ if c >= 'a' && c <= 'z' ||
+ c >= 'A' && c <= 'Z' ||
+ c >= '0' && c <= '9' ||
+ c == '_' || c == '-' || c == '/' {
+ ret += string(c)
+ }
+ }
+
+ return ret
+}
diff --git a/common/module.go b/common/module.go
new file mode 100644
index 0000000..e8c4a87
--- /dev/null
+++ b/common/module.go
@@ -0,0 +1,625 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package common
+
+import (
+ "android/soong"
+ "path/filepath"
+ "runtime"
+ "sort"
+ "strings"
+
+ "android/soong/glob"
+
+ "github.com/google/blueprint"
+)
+
+var (
+ DeviceSharedLibrary = "shared_library"
+ DeviceStaticLibrary = "static_library"
+ DeviceExecutable = "executable"
+ HostSharedLibrary = "host_shared_library"
+ HostStaticLibrary = "host_static_library"
+ HostExecutable = "host_executable"
+)
+
+type androidBaseContext interface {
+ Arch() Arch
+ HostOrDevice() HostOrDevice
+ Host() bool
+ Device() bool
+ Darwin() bool
+ Debug() bool
+ AConfig() Config
+}
+
+type AndroidBaseContext interface {
+ blueprint.BaseModuleContext
+ androidBaseContext
+}
+
+type AndroidModuleContext interface {
+ blueprint.ModuleContext
+ androidBaseContext
+
+ ExpandSources(srcFiles, excludes []string) []string
+ Glob(outDir, globPattern string, excludes []string) []string
+
+ InstallFile(installPath, srcPath string, deps ...string) string
+ InstallFileName(installPath, name, srcPath string, deps ...string) string
+ CheckbuildFile(srcPath string)
+}
+
+type AndroidModule interface {
+ blueprint.Module
+
+ GenerateAndroidBuildActions(AndroidModuleContext)
+
+ base() *AndroidModuleBase
+ Disabled() bool
+ HostOrDevice() HostOrDevice
+}
+
+type AndroidDynamicDepender interface {
+ AndroidDynamicDependencies(ctx AndroidDynamicDependerModuleContext) []string
+}
+
+type AndroidDynamicDependerModuleContext interface {
+ blueprint.DynamicDependerModuleContext
+ androidBaseContext
+}
+
+type commonProperties struct {
+ Name string
+ Deps []string
+ Tags []string
+
+ // don't emit any build rules for this module
+ Disabled bool `android:"arch_variant"`
+
+ // control whether this module compiles for 32-bit, 64-bit, or both. Possible values
+ // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both
+ // architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit
+ // platform
+ Compile_multilib string
+
+ // Set by HostOrDeviceMutator
+ CompileHostOrDevice HostOrDevice `blueprint:"mutated"`
+
+ // Set by ArchMutator
+ CompileArch Arch `blueprint:"mutated"`
+
+ // Set by InitAndroidModule
+ HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
+}
+
+type hostAndDeviceProperties struct {
+ Host_supported bool
+ Device_supported bool
+}
+
+type Multilib string
+
+const (
+ MultilibBoth Multilib = "both"
+ MultilibFirst Multilib = "first"
+ MultilibCommon Multilib = "common"
+)
+
+func InitAndroidModule(m AndroidModule,
+ propertyStructs ...interface{}) (blueprint.Module, []interface{}) {
+
+ base := m.base()
+ base.module = m
+ base.extendedProperties = make(map[string]struct{})
+
+ propertyStructs = append(propertyStructs, &base.commonProperties)
+
+ return m, propertyStructs
+}
+
+func InitAndroidArchModule(m AndroidModule, hod HostOrDeviceSupported, defaultMultilib Multilib,
+ propertyStructs ...interface{}) (blueprint.Module, []interface{}) {
+
+ _, propertyStructs = InitAndroidModule(m, propertyStructs...)
+
+ base := m.base()
+ base.commonProperties.HostOrDeviceSupported = hod
+
+ if hod == HostAndDeviceSupported {
+ // Default to module to device supported, host not supported, can override in module
+ // properties
+ base.hostAndDeviceProperties.Device_supported = true
+ propertyStructs = append(propertyStructs, &base.hostAndDeviceProperties)
+ }
+
+ return InitArchModule(m, defaultMultilib, propertyStructs...)
+}
+
+// A AndroidModuleBase object contains the properties that are common to all Android
+// modules. It should be included as an anonymous field in every module
+// struct definition. InitAndroidModule should then be called from the module's
+// factory function, and the return values from InitAndroidModule should be
+// returned from the factory function.
+//
+// The AndroidModuleBase type is responsible for implementing the
+// GenerateBuildActions method to support the blueprint.Module interface. This
+// method will then call the module's GenerateAndroidBuildActions method once
+// for each build variant that is to be built. GenerateAndroidBuildActions is
+// passed a AndroidModuleContext rather than the usual blueprint.ModuleContext.
+// AndroidModuleContext exposes extra functionality specific to the Android build
+// system including details about the particular build variant that is to be
+// generated.
+//
+// For example:
+//
+// import (
+// "android/soong/common"
+// "github.com/google/blueprint"
+// )
+//
+// type myModule struct {
+// common.AndroidModuleBase
+// properties struct {
+// MyProperty string
+// }
+// }
+//
+// func NewMyModule() (blueprint.Module, []interface{}) {
+// m := &myModule{}
+// return common.InitAndroidModule(m, &m.properties)
+// }
+//
+// func (m *myModule) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) {
+// // Get the CPU architecture for the current build variant.
+// variantArch := ctx.Arch()
+//
+// // ...
+// }
+type AndroidModuleBase struct {
+ // Putting the curiously recurring thing pointing to the thing that contains
+ // the thing pattern to good use.
+ module AndroidModule
+
+ commonProperties commonProperties
+ hostAndDeviceProperties hostAndDeviceProperties
+ generalProperties []interface{}
+ archProperties []*archProperties
+ extendedProperties map[string]struct{}
+
+ noAddressSanitizer bool
+ installFiles []string
+ checkbuildFiles []string
+
+ // Used by buildTargetSingleton to create checkbuild and per-directory build targets
+ // Only set on the final variant of each module
+ installTarget string
+ checkbuildTarget string
+ blueprintDir string
+}
+
+func (a *AndroidModuleBase) base() *AndroidModuleBase {
+ return a
+}
+
+func (a *AndroidModuleBase) SetHostOrDevice(hod HostOrDevice) {
+ a.commonProperties.CompileHostOrDevice = hod
+}
+
+func (a *AndroidModuleBase) SetArch(arch Arch) {
+ a.commonProperties.CompileArch = arch
+}
+
+func (a *AndroidModuleBase) HostOrDevice() HostOrDevice {
+ return a.commonProperties.CompileHostOrDevice
+}
+
+func (a *AndroidModuleBase) HostSupported() bool {
+ return a.commonProperties.HostOrDeviceSupported == HostSupported ||
+ a.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
+ a.hostAndDeviceProperties.Host_supported
+}
+
+func (a *AndroidModuleBase) DeviceSupported() bool {
+ return a.commonProperties.HostOrDeviceSupported == DeviceSupported ||
+ a.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
+ a.hostAndDeviceProperties.Device_supported
+}
+
+func (a *AndroidModuleBase) Disabled() bool {
+ return a.commonProperties.Disabled
+}
+
+func (a *AndroidModuleBase) computeInstallDeps(
+ ctx blueprint.ModuleContext) []string {
+
+ result := []string{}
+ ctx.VisitDepsDepthFirstIf(isFileInstaller,
+ func(m blueprint.Module) {
+ fileInstaller := m.(fileInstaller)
+ files := fileInstaller.filesToInstall()
+ result = append(result, files...)
+ })
+
+ return result
+}
+
+func (a *AndroidModuleBase) filesToInstall() []string {
+ return a.installFiles
+}
+
+func (p *AndroidModuleBase) NoAddressSanitizer() bool {
+ return p.noAddressSanitizer
+}
+
+func (a *AndroidModuleBase) generateModuleTarget(ctx blueprint.ModuleContext) {
+ if a != ctx.FinalModule().(AndroidModule).base() {
+ return
+ }
+
+ allInstalledFiles := []string{}
+ allCheckbuildFiles := []string{}
+ ctx.VisitAllModuleVariants(func(module blueprint.Module) {
+ a := module.(AndroidModule).base()
+ allInstalledFiles = append(allInstalledFiles, a.installFiles...)
+ allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...)
+ })
+
+ deps := []string{}
+
+ if len(allInstalledFiles) > 0 {
+ name := ctx.ModuleName() + "-install"
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: blueprint.Phony,
+ Outputs: []string{name},
+ Implicits: allInstalledFiles,
+ })
+ deps = append(deps, name)
+ a.installTarget = name
+ }
+
+ if len(allCheckbuildFiles) > 0 {
+ name := ctx.ModuleName() + "-checkbuild"
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: blueprint.Phony,
+ Outputs: []string{name},
+ Implicits: allCheckbuildFiles,
+ Optional: true,
+ })
+ deps = append(deps, name)
+ a.checkbuildTarget = name
+ }
+
+ if len(deps) > 0 {
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: blueprint.Phony,
+ Outputs: []string{ctx.ModuleName()},
+ Implicits: deps,
+ Optional: true,
+ })
+
+ a.blueprintDir = ctx.ModuleDir()
+ }
+}
+
+func (a *AndroidModuleBase) DynamicDependencies(ctx blueprint.DynamicDependerModuleContext) []string {
+ actx := &androidDynamicDependerContext{
+ DynamicDependerModuleContext: ctx,
+ androidBaseContextImpl: androidBaseContextImpl{
+ arch: a.commonProperties.CompileArch,
+ hod: a.commonProperties.CompileHostOrDevice,
+ config: ctx.Config().(Config),
+ },
+ }
+
+ if dynamic, ok := a.module.(AndroidDynamicDepender); ok {
+ return dynamic.AndroidDynamicDependencies(actx)
+ }
+
+ return nil
+}
+
+func (a *AndroidModuleBase) GenerateBuildActions(ctx blueprint.ModuleContext) {
+ androidCtx := &androidModuleContext{
+ ModuleContext: ctx,
+ androidBaseContextImpl: androidBaseContextImpl{
+ arch: a.commonProperties.CompileArch,
+ hod: a.commonProperties.CompileHostOrDevice,
+ config: ctx.Config().(Config),
+ },
+ installDeps: a.computeInstallDeps(ctx),
+ installFiles: a.installFiles,
+ extendedProperties: a.extendedProperties,
+ }
+
+ if a.commonProperties.Disabled {
+ return
+ }
+
+ a.module.GenerateAndroidBuildActions(androidCtx)
+ if ctx.Failed() {
+ return
+ }
+
+ a.installFiles = append(a.installFiles, androidCtx.installFiles...)
+ a.checkbuildFiles = append(a.checkbuildFiles, androidCtx.checkbuildFiles...)
+
+ a.generateModuleTarget(ctx)
+ if ctx.Failed() {
+ return
+ }
+}
+
+type androidBaseContextImpl struct {
+ arch Arch
+ hod HostOrDevice
+ debug bool
+ config Config
+}
+
+type androidModuleContext struct {
+ blueprint.ModuleContext
+ androidBaseContextImpl
+ installDeps []string
+ installFiles []string
+ checkbuildFiles []string
+ extendedProperties map[string]struct{}
+}
+
+func (a *androidModuleContext) Build(pctx *blueprint.PackageContext, params blueprint.BuildParams) {
+ params.Optional = true
+ a.ModuleContext.Build(pctx, params)
+}
+
+func (a *androidModuleContext) ContainsProperty(property string) bool {
+ if a.ModuleContext.ContainsProperty(property) {
+ return true
+ }
+ _, ok := a.extendedProperties[property]
+ return ok
+}
+
+func (a *androidBaseContextImpl) Arch() Arch {
+ return a.arch
+}
+
+func (a *androidBaseContextImpl) HostOrDevice() HostOrDevice {
+ return a.hod
+}
+
+func (a *androidBaseContextImpl) Host() bool {
+ return a.hod.Host()
+}
+
+func (a *androidBaseContextImpl) Device() bool {
+ return a.hod.Device()
+}
+
+func (a *androidBaseContextImpl) Darwin() bool {
+ return a.hod.Host() && runtime.GOOS == "darwin"
+}
+
+func (a *androidBaseContextImpl) Debug() bool {
+ return a.debug
+}
+
+func (a *androidBaseContextImpl) AConfig() Config {
+ return a.config
+}
+
+func (a *androidModuleContext) InstallFileName(installPath, name, srcPath string,
+ deps ...string) string {
+
+ config := a.AConfig()
+ var fullInstallPath string
+ if a.hod.Device() {
+ // TODO: replace unset with a device name once we have device targeting
+ fullInstallPath = filepath.Join(config.DeviceOut(), "system",
+ installPath, name)
+ } else {
+ fullInstallPath = filepath.Join(config.HostOut(), installPath, name)
+ }
+
+ deps = append(deps, a.installDeps...)
+
+ a.ModuleContext.Build(pctx, blueprint.BuildParams{
+ Rule: Cp,
+ Outputs: []string{fullInstallPath},
+ Inputs: []string{srcPath},
+ OrderOnly: deps,
+ })
+
+ a.installFiles = append(a.installFiles, fullInstallPath)
+ a.checkbuildFiles = append(a.checkbuildFiles, srcPath)
+ return fullInstallPath
+}
+
+func (a *androidModuleContext) InstallFile(installPath, srcPath string, deps ...string) string {
+ return a.InstallFileName(installPath, filepath.Base(srcPath), srcPath, deps...)
+}
+
+func (a *androidModuleContext) CheckbuildFile(srcPath string) {
+ a.checkbuildFiles = append(a.checkbuildFiles, srcPath)
+}
+
+type androidDynamicDependerContext struct {
+ blueprint.DynamicDependerModuleContext
+ androidBaseContextImpl
+}
+
+type fileInstaller interface {
+ filesToInstall() []string
+}
+
+func isFileInstaller(m blueprint.Module) bool {
+ _, ok := m.(fileInstaller)
+ return ok
+}
+
+func isAndroidModule(m blueprint.Module) bool {
+ _, ok := m.(AndroidModule)
+ return ok
+}
+
+func findStringInSlice(str string, slice []string) int {
+ for i, s := range slice {
+ if s == str {
+ return i
+ }
+ }
+ return -1
+}
+
+func (ctx *androidModuleContext) ExpandSources(srcFiles, excludes []string) []string {
+ prefix := ModuleSrcDir(ctx)
+ for i, e := range excludes {
+ j := findStringInSlice(e, srcFiles)
+ if j != -1 {
+ srcFiles = append(srcFiles[:j], srcFiles[j+1:]...)
+ }
+
+ excludes[i] = filepath.Join(prefix, e)
+ }
+
+ for i, srcFile := range srcFiles {
+ srcFiles[i] = filepath.Join(prefix, srcFile)
+ }
+
+ if !hasGlob(srcFiles) {
+ return srcFiles
+ }
+
+ globbedSrcFiles := make([]string, 0, len(srcFiles))
+ for _, s := range srcFiles {
+ if glob.IsGlob(s) {
+ globbedSrcFiles = append(globbedSrcFiles, ctx.Glob("src_glob", s, excludes)...)
+ } else {
+ globbedSrcFiles = append(globbedSrcFiles, s)
+ }
+ }
+
+ return globbedSrcFiles
+}
+
+func (ctx *androidModuleContext) Glob(outDir, globPattern string, excludes []string) []string {
+ ret, err := Glob(ctx, filepath.Join(ModuleOutDir(ctx), outDir), globPattern, excludes)
+ if err != nil {
+ ctx.ModuleErrorf("glob: %s", err.Error())
+ }
+ return ret
+}
+
+func init() {
+ soong.RegisterSingletonType("buildtarget", BuildTargetSingleton)
+}
+
+func BuildTargetSingleton() blueprint.Singleton {
+ return &buildTargetSingleton{}
+}
+
+type buildTargetSingleton struct{}
+
+func (c *buildTargetSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
+ checkbuildDeps := []string{}
+
+ dirModules := make(map[string][]string)
+ hasBPFile := make(map[string]bool)
+ bpFiles := []string{}
+
+ ctx.VisitAllModules(func(module blueprint.Module) {
+ if a, ok := module.(AndroidModule); ok {
+ blueprintDir := a.base().blueprintDir
+ installTarget := a.base().installTarget
+ checkbuildTarget := a.base().checkbuildTarget
+ bpFile := ctx.BlueprintFile(module)
+
+ if checkbuildTarget != "" {
+ checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
+ dirModules[blueprintDir] = append(dirModules[blueprintDir], checkbuildTarget)
+ }
+
+ if installTarget != "" {
+ dirModules[blueprintDir] = append(dirModules[blueprintDir], installTarget)
+ }
+
+ if !hasBPFile[bpFile] {
+ hasBPFile[bpFile] = true
+ bpFiles = append(bpFiles, bpFile)
+ }
+ }
+ })
+
+ // Create a top-level checkbuild target that depends on all modules
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: blueprint.Phony,
+ Outputs: []string{"checkbuild"},
+ Implicits: checkbuildDeps,
+ // HACK: checkbuild should be an optional build, but force it enabled for now
+ //Optional: true,
+ })
+
+ // Create a mm/<directory> target that depends on all modules in a directory
+ dirs := sortedKeys(dirModules)
+ for _, dir := range dirs {
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: blueprint.Phony,
+ Outputs: []string{filepath.Join("mm", dir)},
+ Implicits: dirModules[dir],
+ Optional: true,
+ })
+ }
+
+ // Create Android.bp->mk translation rules
+ androidMks := []string{}
+ srcDir := ctx.Config().(Config).SrcDir()
+ intermediatesDir := filepath.Join(ctx.Config().(Config).IntermediatesDir(), "androidmk")
+ sort.Strings(bpFiles)
+ for _, origBp := range bpFiles {
+ bpFile := filepath.Join(srcDir, origBp)
+ mkFile := filepath.Join(srcDir, filepath.Dir(origBp), "Android.mk")
+
+ files, err := Glob(ctx, intermediatesDir, mkFile, nil)
+ if err != nil {
+ ctx.Errorf("glob: %s", err.Error())
+ continue
+ }
+
+ // Existing Android.mk file, use that instead
+ if len(files) > 0 {
+ for _, file := range files {
+ ctx.AddNinjaFileDeps(file)
+ }
+ continue
+ }
+
+ transMk := filepath.Join("androidmk", "Android_"+strings.Replace(filepath.Dir(origBp), "/", "_", -1)+".mk")
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: androidbp,
+ Outputs: []string{transMk},
+ Inputs: []string{bpFile},
+ Implicits: []string{androidbpCmd},
+ Optional: true,
+ })
+
+ androidMks = append(androidMks, transMk)
+ }
+
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: blueprint.Phony,
+ Outputs: []string{"androidmk"},
+ Implicits: androidMks,
+ Optional: true,
+ })
+}
diff --git a/common/paths.go b/common/paths.go
new file mode 100644
index 0000000..c4bdfc7
--- /dev/null
+++ b/common/paths.go
@@ -0,0 +1,107 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package common
+
+import (
+ "os"
+ "path/filepath"
+)
+
+// ModuleOutDir returns the path to the module-specific output directory.
+func ModuleOutDir(ctx AndroidModuleContext) string {
+ return filepath.Join(ctx.AConfig().IntermediatesDir(),
+ ctx.ModuleDir(), ctx.ModuleName(), ctx.ModuleSubDir())
+}
+
+// ModuleSrcDir returns the path of the directory that all source file paths are
+// specified relative to.
+func ModuleSrcDir(ctx AndroidModuleContext) string {
+ return filepath.Join(ctx.AConfig().SrcDir(), ctx.ModuleDir())
+}
+
+// ModuleBinDir returns the path to the module- and architecture-specific binary
+// output directory.
+func ModuleBinDir(ctx AndroidModuleContext) string {
+ return filepath.Join(ModuleOutDir(ctx), "bin")
+}
+
+// ModuleLibDir returns the path to the module- and architecture-specific
+// library output directory.
+func ModuleLibDir(ctx AndroidModuleContext) string {
+ return filepath.Join(ModuleOutDir(ctx), "lib")
+}
+
+// ModuleGenDir returns the module directory for generated files
+// path.
+func ModuleGenDir(ctx AndroidModuleContext) string {
+ return filepath.Join(ModuleOutDir(ctx), "gen")
+}
+
+// ModuleObjDir returns the module- and architecture-specific object directory
+// path.
+func ModuleObjDir(ctx AndroidModuleContext) string {
+ return filepath.Join(ModuleOutDir(ctx), "obj")
+}
+
+// ModuleGoPackageDir returns the module-specific package root directory path.
+// This directory is where the final package .a files are output and where
+// dependent modules search for this package via -I arguments.
+func ModuleGoPackageDir(ctx AndroidModuleContext) string {
+ return filepath.Join(ModuleOutDir(ctx), "pkg")
+}
+
+// ModuleIncludeDir returns the module-specific public include directory path.
+func ModuleIncludeDir(ctx AndroidModuleContext) string {
+ return filepath.Join(ModuleOutDir(ctx), "include")
+}
+
+// ModuleProtoDir returns the module-specific public proto include directory path.
+func ModuleProtoDir(ctx AndroidModuleContext) string {
+ return filepath.Join(ModuleOutDir(ctx), "proto")
+}
+
+func ModuleJSCompiledDir(ctx AndroidModuleContext) string {
+ return filepath.Join(ModuleOutDir(ctx), "js")
+}
+
+// CheckModuleSrcDirsExist logs an error on a property if any of the directories relative to the
+// Blueprints file don't exist.
+func CheckModuleSrcDirsExist(ctx AndroidModuleContext, dirs []string, prop string) {
+ for _, dir := range dirs {
+ fullDir := filepath.Join(ModuleSrcDir(ctx), dir)
+ if _, err := os.Stat(fullDir); err != nil {
+ if os.IsNotExist(err) {
+ ctx.PropertyErrorf(prop, "module source directory %q does not exist", dir)
+ } else {
+ ctx.PropertyErrorf(prop, "%s", err.Error())
+ }
+ }
+ }
+}
+
+// CheckModuleSrcDirsExist logs an error on a property if any of the directories relative to the
+// top of the source tree don't exist.
+func CheckSrcDirsExist(ctx AndroidModuleContext, dirs []string, prop string) {
+ for _, dir := range dirs {
+ fullDir := filepath.Join(ctx.AConfig().SrcDir(), dir)
+ if _, err := os.Stat(fullDir); err != nil {
+ if os.IsNotExist(err) {
+ ctx.PropertyErrorf(prop, "top-level source directory %q does not exist", dir)
+ } else {
+ ctx.PropertyErrorf(prop, "%s", err.Error())
+ }
+ }
+ }
+}
diff --git a/common/util.go b/common/util.go
new file mode 100644
index 0000000..0a0ed13
--- /dev/null
+++ b/common/util.go
@@ -0,0 +1,78 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package common
+
+import "sort"
+
+func JoinWithPrefix(strs []string, prefix string) string {
+ if len(strs) == 0 {
+ return ""
+ }
+
+ if len(strs) == 1 {
+ return prefix + strs[0]
+ }
+
+ n := len(" ") * (len(strs) - 1)
+ for _, s := range strs {
+ n += len(prefix) + len(s)
+ }
+
+ ret := make([]byte, 0, n)
+ for i, s := range strs {
+ if i != 0 {
+ ret = append(ret, ' ')
+ }
+ ret = append(ret, prefix...)
+ ret = append(ret, s...)
+ }
+ return string(ret)
+}
+
+func JoinWithPrefixAndQuote(strs []string, prefix string) string {
+ if len(strs) == 0 {
+ return ""
+ }
+
+ if len(strs) == 1 {
+ return prefix + `"` + strs[0] + `"`
+ }
+
+ n := len(" ") * (len(strs) - 1)
+ for _, s := range strs {
+ n += len(prefix) + len(s) + len(`""`)
+ }
+
+ ret := make([]byte, 0, n)
+ for i, s := range strs {
+ if i != 0 {
+ ret = append(ret, ' ')
+ }
+ ret = append(ret, prefix...)
+ ret = append(ret, '"')
+ ret = append(ret, s...)
+ ret = append(ret, '"')
+ }
+ return string(ret)
+}
+
+func sortedKeys(m map[string][]string) []string {
+ s := make([]string, 0, len(m))
+ for k := range m {
+ s = append(s, k)
+ }
+ sort.Strings(s)
+ return s
+}
diff --git a/copygcclib.sh b/copygcclib.sh
new file mode 100755
index 0000000..93c52cc
--- /dev/null
+++ b/copygcclib.sh
@@ -0,0 +1,7 @@
+#!/bin/bash -e
+
+OUT=$1
+shift
+LIBPATH=$($@)
+cp -f $LIBPATH $OUT
+echo "$OUT: $LIBPATH" > ${OUT}.d
diff --git a/doc.go b/doc.go
new file mode 100644
index 0000000..543c460
--- /dev/null
+++ b/doc.go
@@ -0,0 +1,56 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// Soong is a builder for Android that uses Blueprint to parse Blueprints
+// files and Ninja to do the dependency tracking and subprocess management.
+// Soong itself is responsible for converting the modules read by Blueprint
+// into build rules, which will be written to a build.ninja file by Blueprint.
+//
+// Android build concepts:
+//
+// Device
+// A device is a piece of hardware that will be running Android. It may specify
+// global settings like architecture, filesystem configuration, initialization
+// scripts, and device drivers. A device may support all variants of a single
+// piece of hardware, or multiple devices may be used for different variants.
+// A build is never targeted directly at a device, it is always targeted at a
+// "product".
+//
+// Product
+// A product is a configuration of a device, often for a specific market or
+// use case. It is sometimes referred to as a "SKU". A product defines
+// global settings like supported languages, supported use cases, preinstalled
+// modules, and user-visible behavior choices. A product selects one and only
+// one device.
+//
+// Module
+// A module is a definition of something to be built. It may be a C library or
+// binary, a java library, an Android app, etc. A module may be built for multiple
+// targets, even in a single build, for example host and device, or 32-bit device
+// and 64-bit device.
+//
+// Installed module
+// An installed module is one that has been requested by the selected product,
+// or a dependency of an installed module.
+//
+// Target architecture
+// The target architecture is the preferred architecture supported by the selected
+// device. It is most commonly 32-bit arm, but may also be 64-bit arm, 32-bit or
+// 64-bit x86, or mips.
+//
+// Secondary architecture
+// The secondary architecture specifies the architecture to compile a second copy
+// of some modules for devices that support multiple architectures, for example
+// 64-bit devices that also support 32-bit binaries.
+package soong
diff --git a/env/env.go b/env/env.go
new file mode 100644
index 0000000..bf58a99
--- /dev/null
+++ b/env/env.go
@@ -0,0 +1,97 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// env implements the environment JSON file handling for the soong_env command line tool run before
+// the builder and for the env writer in the builder.
+package env
+
+import (
+ "encoding/json"
+ "fmt"
+ "io/ioutil"
+ "os"
+ "sort"
+)
+
+type envFileEntry struct{ Key, Value string }
+type envFileData []envFileEntry
+
+func WriteEnvFile(filename string, envDeps map[string]string) error {
+ contents := make(envFileData, 0, len(envDeps))
+ for key, value := range envDeps {
+ contents = append(contents, envFileEntry{key, value})
+ }
+
+ sort.Sort(contents)
+
+ data, err := json.MarshalIndent(contents, "", " ")
+ if err != nil {
+ return err
+ }
+
+ data = append(data, '\n')
+
+ err = ioutil.WriteFile(filename, data, 0664)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
+func StaleEnvFile(filename string) (bool, error) {
+ data, err := ioutil.ReadFile(filename)
+ if err != nil {
+ return true, err
+ }
+
+ var contents envFileData
+
+ err = json.Unmarshal(data, &contents)
+ if err != nil {
+ return true, err
+ }
+
+ var changed []string
+ for _, entry := range contents {
+ key := entry.Key
+ old := entry.Value
+ cur := os.Getenv(key)
+ if old != cur {
+ changed = append(changed, fmt.Sprintf("%s (%q -> %q)", key, old, cur))
+ }
+ }
+
+ if len(changed) > 0 {
+ fmt.Printf("environment variables changed value:\n")
+ for _, s := range changed {
+ fmt.Printf(" %s\n", s)
+ }
+ return true, nil
+ }
+
+ return false, nil
+}
+
+func (e envFileData) Len() int {
+ return len(e)
+}
+
+func (e envFileData) Less(i, j int) bool {
+ return e[i].Key < e[j].Key
+}
+
+func (e envFileData) Swap(i, j int) {
+ e[i], e[j] = e[j], e[i]
+}
diff --git a/genrule/genrule.go b/genrule/genrule.go
new file mode 100644
index 0000000..a5a4c71
--- /dev/null
+++ b/genrule/genrule.go
@@ -0,0 +1,185 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package genrule
+
+import (
+ "path/filepath"
+
+ "github.com/google/blueprint"
+ "github.com/google/blueprint/pathtools"
+
+ "android/soong"
+ "android/soong/common"
+)
+
+func init() {
+ soong.RegisterModuleType("gensrcs", GenSrcsFactory)
+ soong.RegisterModuleType("genrule", GenRuleFactory)
+}
+
+var (
+ pctx = blueprint.NewPackageContext("android/soong/genrule")
+)
+
+func init() {
+ pctx.VariableConfigMethod("srcDir", common.Config.SrcDir)
+ pctx.VariableConfigMethod("hostBin", common.Config.HostBin)
+}
+
+type SourceFileGenerator interface {
+ GeneratedSourceFiles() []string
+}
+
+type HostToolProvider interface {
+ HostToolPath() string
+}
+
+type generatorProperties struct {
+ // command to run on one or more input files. Available variables for substitution:
+ // $in: one or more input files
+ // $out: a single output file
+ // $srcDir: the root directory of the source tree
+ // The host bin directory will be in the path
+ Cmd string
+
+ // name of the module (if any) that produces the host executable. Leave empty for
+ // prebuilts or scripts that do not need a module to build them.
+ Tool string
+}
+
+type generator struct {
+ common.AndroidModuleBase
+
+ properties generatorProperties
+
+ tasks taskFunc
+
+ deps []string
+ rule blueprint.Rule
+
+ outputFiles []string
+}
+
+type taskFunc func(ctx common.AndroidModuleContext) []generateTask
+
+type generateTask struct {
+ in []string
+ out string
+}
+
+func (g *generator) GeneratedSourceFiles() []string {
+ return g.outputFiles
+}
+
+func (g *generator) AndroidDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string {
+ if g.properties.Tool != "" {
+ ctx.AddFarVariationDependencies([]blueprint.Variation{{"hostordevice", common.Host.String()}},
+ g.properties.Tool)
+ }
+ return nil
+}
+
+func (g *generator) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) {
+ g.rule = ctx.Rule(pctx, "generator", blueprint.RuleParams{
+ Command: "PATH=$$PATH:$hostBin " + g.properties.Cmd,
+ })
+
+ ctx.VisitDirectDeps(func(module blueprint.Module) {
+ if t, ok := module.(HostToolProvider); ok {
+ p := t.HostToolPath()
+ if p != "" {
+ g.deps = append(g.deps, p)
+ } else {
+ ctx.ModuleErrorf("host tool %q missing output file", ctx.OtherModuleName(module))
+ }
+ } else {
+ ctx.ModuleErrorf("unknown dependency %q", ctx.OtherModuleName(module))
+ }
+ })
+
+ for _, task := range g.tasks(ctx) {
+ g.generateSourceFile(ctx, task)
+ }
+}
+
+func (g *generator) generateSourceFile(ctx common.AndroidModuleContext, task generateTask) {
+
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: g.rule,
+ Inputs: task.in,
+ Implicits: g.deps,
+ Outputs: []string{task.out},
+ })
+
+ g.outputFiles = append(g.outputFiles, task.out)
+}
+
+func generatorFactory(tasks taskFunc, props ...interface{}) (blueprint.Module, []interface{}) {
+ module := &generator{
+ tasks: tasks,
+ }
+
+ props = append(props, &module.properties)
+
+ return common.InitAndroidModule(module, props...)
+}
+
+func GenSrcsFactory() (blueprint.Module, []interface{}) {
+ properties := &genSrcsProperties{}
+
+ tasks := func(ctx common.AndroidModuleContext) []generateTask {
+ srcFiles := ctx.ExpandSources(properties.Srcs, nil)
+ tasks := make([]generateTask, 0, len(srcFiles))
+ for _, in := range srcFiles {
+ out := pathtools.ReplaceExtension(in, properties.Output_extension)
+ out = filepath.Join(common.ModuleGenDir(ctx), out)
+ tasks = append(tasks, generateTask{[]string{in}, out})
+ }
+ return tasks
+ }
+
+ return generatorFactory(tasks, properties)
+}
+
+type genSrcsProperties struct {
+ // list of input files
+ Srcs []string
+
+ // extension that will be substituted for each output file
+ Output_extension string
+}
+
+func GenRuleFactory() (blueprint.Module, []interface{}) {
+ properties := &genRuleProperties{}
+
+ tasks := func(ctx common.AndroidModuleContext) []generateTask {
+ return []generateTask{
+ {
+ in: ctx.ExpandSources(properties.Srcs, nil),
+ out: filepath.Join(common.ModuleGenDir(ctx), properties.Out),
+ },
+ }
+ }
+
+ return generatorFactory(tasks, properties)
+}
+
+type genRuleProperties struct {
+ // list of input files
+ Srcs []string
+
+ // name of the output file that will be generated
+ Out string
+}
diff --git a/glob/glob.go b/glob/glob.go
new file mode 100644
index 0000000..060c9dd
--- /dev/null
+++ b/glob/glob.go
@@ -0,0 +1,100 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package glob
+
+import (
+ "io/ioutil"
+ "os"
+ "path/filepath"
+ "strings"
+
+ "github.com/google/blueprint/deptools"
+ "github.com/google/blueprint/pathtools"
+)
+
+func IsGlob(glob string) bool {
+ return strings.IndexAny(glob, "*?[") >= 0
+}
+
+// GlobWithDepFile finds all files that match glob. It compares the list of files
+// against the contents of fileListFile, and rewrites fileListFile if it has changed. It also
+// writes all of the the directories it traversed as a depenencies on fileListFile to depFile.
+//
+// The format of glob is either path/*.ext for a single directory glob, or path/**/*.ext
+// for a recursive glob.
+//
+// Returns a list of file paths, and an error.
+func GlobWithDepFile(glob, fileListFile, depFile string, excludes []string) (files []string, err error) {
+ files, dirs, err := pathtools.GlobWithExcludes(glob, excludes)
+ if err != nil {
+ return nil, err
+ }
+
+ fileList := strings.Join(files, "\n") + "\n"
+
+ writeFileIfChanged(fileListFile, []byte(fileList), 0666)
+ deptools.WriteDepFile(depFile, fileListFile, dirs)
+
+ return
+}
+
+func writeFileIfChanged(filename string, data []byte, perm os.FileMode) error {
+ var isChanged bool
+
+ dir := filepath.Dir(filename)
+ err := os.MkdirAll(dir, 0777)
+ if err != nil {
+ return err
+ }
+
+ info, err := os.Stat(filename)
+ if err != nil {
+ if os.IsNotExist(err) {
+ // The file does not exist yet.
+ isChanged = true
+ } else {
+ return err
+ }
+ } else {
+ if info.Size() != int64(len(data)) {
+ isChanged = true
+ } else {
+ oldData, err := ioutil.ReadFile(filename)
+ if err != nil {
+ return err
+ }
+
+ if len(oldData) != len(data) {
+ isChanged = true
+ } else {
+ for i := range data {
+ if oldData[i] != data[i] {
+ isChanged = true
+ break
+ }
+ }
+ }
+ }
+ }
+
+ if isChanged {
+ err = ioutil.WriteFile(filename, data, perm)
+ if err != nil {
+ return err
+ }
+ }
+
+ return nil
+}
diff --git a/java/app.go b/java/app.go
new file mode 100644
index 0000000..a6e651d
--- /dev/null
+++ b/java/app.go
@@ -0,0 +1,319 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package java
+
+// This file contains the module types for compiling Android apps.
+
+import (
+ "os"
+ "path/filepath"
+ "strings"
+
+ "github.com/google/blueprint"
+ "github.com/google/blueprint/pathtools"
+
+ "android/soong/common"
+)
+
+// AAR prebuilts
+// AndroidManifest.xml merging
+// package splits
+
+type androidAppProperties struct {
+ // path to a certificate, or the name of a certificate in the default
+ // certificate directory, or blank to use the default product certificate
+ Certificate string
+
+ // paths to extra certificates to sign the apk with
+ Additional_certificates []string
+
+ // If set, create package-export.apk, which other packages can
+ // use to get PRODUCT-agnostic resource data like IDs and type definitions.
+ Export_package_resources bool
+
+ // flags passed to aapt when creating the apk
+ Aaptflags []string
+
+ // list of resource labels to generate individual resource packages
+ Package_splits []string
+
+ // list of directories relative to the Blueprints file containing assets.
+ // Defaults to "assets"
+ Asset_dirs []string
+
+ // list of directories relative to the Blueprints file containing
+ // Java resources
+ Android_resource_dirs []string
+}
+
+type AndroidApp struct {
+ javaBase
+
+ appProperties androidAppProperties
+
+ aaptJavaFileList string
+ exportPackage string
+}
+
+func (a *AndroidApp) JavaDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string {
+ deps := a.javaBase.JavaDynamicDependencies(ctx)
+
+ if !a.properties.No_standard_libraries {
+ switch a.properties.Sdk_version { // TODO: Res_sdk_version?
+ case "current", "system_current", "":
+ deps = append(deps, "framework-res")
+ default:
+ // We'll already have a dependency on an sdk prebuilt android.jar
+ }
+ }
+
+ return deps
+}
+
+func (a *AndroidApp) GenerateJavaBuildActions(ctx common.AndroidModuleContext) {
+ aaptFlags, aaptDeps, hasResources := a.aaptFlags(ctx)
+
+ if hasResources {
+ // First generate R.java so we can build the .class files
+ aaptRJavaFlags := append([]string(nil), aaptFlags...)
+
+ publicResourcesFile, proguardOptionsFile, aaptJavaFileList :=
+ CreateResourceJavaFiles(ctx, aaptRJavaFlags, aaptDeps)
+ a.aaptJavaFileList = aaptJavaFileList
+ a.ExtraSrcLists = append(a.ExtraSrcLists, aaptJavaFileList)
+
+ if a.appProperties.Export_package_resources {
+ aaptPackageFlags := append([]string(nil), aaptFlags...)
+ var hasProduct bool
+ for _, f := range aaptPackageFlags {
+ if strings.HasPrefix(f, "--product") {
+ hasProduct = true
+ break
+ }
+ }
+
+ if !hasProduct {
+ aaptPackageFlags = append(aaptPackageFlags,
+ "--product "+ctx.AConfig().ProductAaptCharacteristics())
+ }
+ a.exportPackage = CreateExportPackage(ctx, aaptPackageFlags, aaptDeps)
+ ctx.CheckbuildFile(a.exportPackage)
+ }
+ ctx.CheckbuildFile(publicResourcesFile)
+ ctx.CheckbuildFile(proguardOptionsFile)
+ ctx.CheckbuildFile(aaptJavaFileList)
+ }
+
+ // apps manifests are handled by aapt, don't let javaBase see them
+ a.properties.Manifest = ""
+
+ //if !ctx.ContainsProperty("proguard.enabled") {
+ // a.properties.Proguard.Enabled = true
+ //}
+
+ a.javaBase.GenerateJavaBuildActions(ctx)
+
+ aaptPackageFlags := append([]string(nil), aaptFlags...)
+ var hasProduct bool
+ for _, f := range aaptPackageFlags {
+ if strings.HasPrefix(f, "--product") {
+ hasProduct = true
+ break
+ }
+ }
+
+ if !hasProduct {
+ aaptPackageFlags = append(aaptPackageFlags,
+ "--product "+ctx.AConfig().ProductAaptCharacteristics())
+ }
+
+ certificate := a.appProperties.Certificate
+ if certificate == "" {
+ certificate = ctx.AConfig().DefaultAppCertificate()
+ } else if dir, _ := filepath.Split(certificate); dir == "" {
+ certificate = filepath.Join(ctx.AConfig().DefaultAppCertificateDir(), certificate)
+ } else {
+ certificate = filepath.Join(ctx.AConfig().SrcDir(), certificate)
+ }
+
+ certificates := []string{certificate}
+ for _, c := range a.appProperties.Additional_certificates {
+ certificates = append(certificates, filepath.Join(ctx.AConfig().SrcDir(), c))
+ }
+
+ a.outputFile = CreateAppPackage(ctx, aaptPackageFlags, a.outputFile, certificates)
+ ctx.InstallFileName("app", ctx.ModuleName()+".apk", a.outputFile)
+}
+
+var aaptIgnoreFilenames = []string{
+ ".svn",
+ ".git",
+ ".ds_store",
+ "*.scc",
+ ".*",
+ "CVS",
+ "thumbs.db",
+ "picasa.ini",
+ "*~",
+}
+
+func (a *AndroidApp) aaptFlags(ctx common.AndroidModuleContext) ([]string, []string, bool) {
+ aaptFlags := a.appProperties.Aaptflags
+ hasVersionCode := false
+ hasVersionName := false
+ for _, f := range aaptFlags {
+ if strings.HasPrefix(f, "--version-code") {
+ hasVersionCode = true
+ } else if strings.HasPrefix(f, "--version-name") {
+ hasVersionName = true
+ }
+ }
+
+ if true /* is not a test */ {
+ aaptFlags = append(aaptFlags, "-z")
+ }
+
+ assetDirs := a.appProperties.Asset_dirs
+ if len(assetDirs) == 0 {
+ defaultAssetDir := filepath.Join(common.ModuleSrcDir(ctx), "assets")
+ if _, err := os.Stat(defaultAssetDir); err == nil {
+ assetDirs = []string{defaultAssetDir}
+ } else {
+ // Default asset directory doesn't exist, add a dep on the parent directory to
+ // regenerate the manifest if it is created later
+ // TODO: use glob to avoid rerunning whole regenerate if a different file is created?
+ ctx.AddNinjaFileDeps(common.ModuleSrcDir(ctx))
+ }
+ } else {
+ assetDirs = pathtools.PrefixPaths(assetDirs, common.ModuleSrcDir(ctx))
+ }
+
+ resourceDirs := a.appProperties.Android_resource_dirs
+ if len(resourceDirs) == 0 {
+ defaultResourceDir := filepath.Join(common.ModuleSrcDir(ctx), "res")
+ if _, err := os.Stat(defaultResourceDir); err == nil {
+ resourceDirs = []string{defaultResourceDir}
+ } else {
+ // Default resource directory doesn't exist, add a dep on the parent directory to
+ // regenerate the manifest if it is created later
+ // TODO: use glob to avoid rerunning whole regenerate if a different file is created?
+ ctx.AddNinjaFileDeps(common.ModuleSrcDir(ctx))
+ }
+ } else {
+ resourceDirs = pathtools.PrefixPaths(resourceDirs, common.ModuleSrcDir(ctx))
+ }
+
+ rootSrcDir := ctx.AConfig().SrcDir()
+ var overlayResourceDirs []string
+ // For every resource directory, check if there is an overlay directory with the same path.
+ // If found, it will be prepended to the list of resource directories.
+ for _, overlayDir := range ctx.AConfig().ResourceOverlays() {
+ for _, resourceDir := range resourceDirs {
+ relResourceDir, err := filepath.Rel(rootSrcDir, resourceDir)
+ if err != nil {
+ ctx.ModuleErrorf("resource directory %q is not in source tree", resourceDir)
+ continue
+ }
+ overlayResourceDir := filepath.Join(overlayDir, relResourceDir)
+ if _, err := os.Stat(overlayResourceDir); err == nil {
+ overlayResourceDirs = append(overlayResourceDirs, overlayResourceDir)
+ } else {
+ // Overlay resource directory doesn't exist, add a dep to regenerate the manifest if
+ // it is created later
+ ctx.AddNinjaFileDeps(overlayResourceDir)
+ }
+ }
+ }
+
+ if len(overlayResourceDirs) > 0 {
+ resourceDirs = append(overlayResourceDirs, resourceDirs...)
+ }
+
+ // aapt needs to rerun if any files are added or modified in the assets or resource directories,
+ // use glob to create a filelist.
+ var aaptDeps []string
+ var hasResources bool
+ for _, d := range resourceDirs {
+ newDeps := ctx.Glob("app_resources", filepath.Join(d, "**/*"), aaptIgnoreFilenames)
+ aaptDeps = append(aaptDeps, newDeps...)
+ if len(newDeps) > 0 {
+ hasResources = true
+ }
+ }
+ for _, d := range assetDirs {
+ newDeps := ctx.Glob("app_assets", filepath.Join(d, "**/*"), aaptIgnoreFilenames)
+ aaptDeps = append(aaptDeps, newDeps...)
+ }
+
+ manifestFile := a.properties.Manifest
+ if manifestFile == "" {
+ manifestFile = "AndroidManifest.xml"
+ }
+
+ manifestFile = filepath.Join(common.ModuleSrcDir(ctx), manifestFile)
+ aaptDeps = append(aaptDeps, manifestFile)
+
+ aaptFlags = append(aaptFlags, "-M "+manifestFile)
+ aaptFlags = append(aaptFlags, common.JoinWithPrefix(assetDirs, "-A "))
+ aaptFlags = append(aaptFlags, common.JoinWithPrefix(resourceDirs, "-S "))
+
+ ctx.VisitDirectDeps(func(module blueprint.Module) {
+ var depFile string
+ if sdkDep, ok := module.(sdkDependency); ok {
+ depFile = sdkDep.ClasspathFile()
+ } else if javaDep, ok := module.(JavaDependency); ok {
+ if ctx.OtherModuleName(module) == "framework-res" {
+ depFile = javaDep.(*javaBase).module.(*AndroidApp).exportPackage
+ }
+ }
+ if depFile != "" {
+ aaptFlags = append(aaptFlags, "-I "+depFile)
+ aaptDeps = append(aaptDeps, depFile)
+ }
+ })
+
+ sdkVersion := a.properties.Sdk_version
+ if sdkVersion == "" {
+ sdkVersion = ctx.AConfig().PlatformSdkVersion()
+ }
+
+ aaptFlags = append(aaptFlags, "--min-sdk-version "+sdkVersion)
+ aaptFlags = append(aaptFlags, "--target-sdk-version "+sdkVersion)
+
+ if !hasVersionCode {
+ aaptFlags = append(aaptFlags, "--version-code "+ctx.AConfig().PlatformSdkVersion())
+ }
+
+ if !hasVersionName {
+ aaptFlags = append(aaptFlags,
+ "--version-name "+ctx.AConfig().PlatformVersion()+"-"+ctx.AConfig().BuildNumber())
+ }
+
+ // TODO: LOCAL_PACKAGE_OVERRIDES
+ // $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \
+
+ // TODO: LOCAL_INSTRUMENTATION_FOR
+ // $(addprefix --rename-instrumentation-target-package , $(PRIVATE_MANIFEST_INSTRUMENTATION_FOR))
+
+ return aaptFlags, aaptDeps, hasResources
+}
+
+func AndroidAppFactory() (blueprint.Module, []interface{}) {
+ module := &AndroidApp{}
+
+ module.properties.Dex = true
+
+ return NewJavaBase(&module.javaBase, module, common.DeviceSupported, &module.appProperties)
+}
diff --git a/java/app_builder.go b/java/app_builder.go
new file mode 100644
index 0000000..8e907d2
--- /dev/null
+++ b/java/app_builder.go
@@ -0,0 +1,179 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package java
+
+// This file generates the final rules for compiling all Java. All properties related to
+// compiling should have been translated into javaBuilderFlags or another argument to the Transform*
+// functions.
+
+import (
+ "path/filepath"
+ "strings"
+
+ "github.com/google/blueprint"
+
+ "android/soong/common"
+)
+
+var (
+ aaptCreateResourceJavaFile = pctx.StaticRule("aaptCreateResourceJavaFile",
+ blueprint.RuleParams{
+ Command: `rm -rf "$javaDir" && mkdir -p "$javaDir" && ` +
+ `$aaptCmd package -m $aaptFlags -P $publicResourcesFile -G $proguardOptionsFile ` +
+ `-J $javaDir || ( rm -rf "$javaDir/*"; exit 41 ) && ` +
+ `find $javaDir -name "*.java" > $javaFileList`,
+ Description: "aapt create R.java $out",
+ },
+ "aaptFlags", "publicResourcesFile", "proguardOptionsFile", "javaDir", "javaFileList")
+
+ aaptCreateAssetsPackage = pctx.StaticRule("aaptCreateAssetsPackage",
+ blueprint.RuleParams{
+ Command: `rm -f $out && $aaptCmd package $aaptFlags -F $out`,
+ Description: "aapt export package $out",
+ },
+ "aaptFlags", "publicResourcesFile", "proguardOptionsFile", "javaDir", "javaFileList")
+
+ aaptAddResources = pctx.StaticRule("aaptAddResources",
+ blueprint.RuleParams{
+ // TODO: add-jni-shared-libs-to-package
+ Command: `cp -f $in $out.tmp && $aaptCmd package -u $aaptFlags -F $out.tmp && mv $out.tmp $out`,
+ Description: "aapt package $out",
+ },
+ "aaptFlags")
+
+ zipalign = pctx.StaticRule("zipalign",
+ blueprint.RuleParams{
+ Command: `$zipalignCmd -f $zipalignFlags 4 $in $out`,
+ Description: "zipalign $out",
+ },
+ "zipalignFlags")
+
+ signapk = pctx.StaticRule("signapk",
+ blueprint.RuleParams{
+ Command: `java -jar $signapkCmd $certificates $in $out`,
+ Description: "signapk $out",
+ },
+ "certificates")
+
+ androidManifestMerger = pctx.StaticRule("androidManifestMerger",
+ blueprint.RuleParams{
+ Command: "java -classpath $androidManifestMergerCmd com.android.manifmerger.Main merge " +
+ "--main $in --libs $libsManifests --out $out",
+ Description: "merge manifest files $out",
+ },
+ "libsManifests")
+)
+
+func init() {
+ pctx.StaticVariable("androidManifestMergerCmd", "${srcDir}/prebuilts/devtools/tools/lib/manifest-merger.jar")
+ pctx.VariableFunc("aaptCmd", func(c interface{}) (string, error) {
+ return c.(common.Config).HostBinTool("aapt")
+ })
+ pctx.VariableFunc("zipalignCmd", func(c interface{}) (string, error) {
+ return c.(common.Config).HostBinTool("zipalign")
+ })
+ pctx.VariableFunc("signapkCmd", func(c interface{}) (string, error) {
+ return c.(common.Config).HostJavaTool("signapk.jar")
+ })
+}
+
+func CreateResourceJavaFiles(ctx common.AndroidModuleContext, flags []string,
+ deps []string) (string, string, string) {
+ javaDir := filepath.Join(common.ModuleGenDir(ctx), "R")
+ javaFileList := filepath.Join(common.ModuleOutDir(ctx), "R.filelist")
+ publicResourcesFile := filepath.Join(common.ModuleOutDir(ctx), "public_resources.xml")
+ proguardOptionsFile := filepath.Join(common.ModuleOutDir(ctx), "proguard.options")
+
+ deps = append([]string{"$aaptCmd"}, deps...)
+
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: aaptCreateResourceJavaFile,
+ Outputs: []string{publicResourcesFile, proguardOptionsFile, javaFileList},
+ Implicits: deps,
+ Args: map[string]string{
+ "aaptFlags": strings.Join(flags, " "),
+ "publicResourcesFile": publicResourcesFile,
+ "proguardOptionsFile": proguardOptionsFile,
+ "javaDir": javaDir,
+ "javaFileList": javaFileList,
+ },
+ })
+
+ return publicResourcesFile, proguardOptionsFile, javaFileList
+}
+
+func CreateExportPackage(ctx common.AndroidModuleContext, flags []string, deps []string) string {
+ outputFile := filepath.Join(common.ModuleOutDir(ctx), "package-export.apk")
+
+ deps = append([]string{"$aaptCmd"}, deps...)
+
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: aaptCreateAssetsPackage,
+ Outputs: []string{outputFile},
+ Implicits: deps,
+ Args: map[string]string{
+ "aaptFlags": strings.Join(flags, " "),
+ },
+ })
+
+ return outputFile
+}
+
+func CreateAppPackage(ctx common.AndroidModuleContext, flags []string, jarFile string,
+ certificates []string) string {
+
+ resourceApk := filepath.Join(common.ModuleOutDir(ctx), "resources.apk")
+
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: aaptAddResources,
+ Outputs: []string{resourceApk},
+ Inputs: []string{jarFile},
+ Implicits: []string{"$aaptCmd"},
+ Args: map[string]string{
+ "aaptFlags": strings.Join(flags, " "),
+ },
+ })
+
+ signedApk := filepath.Join(common.ModuleOutDir(ctx), "signed.apk")
+
+ var certificateArgs []string
+ for _, c := range certificates {
+ certificateArgs = append(certificateArgs, c+".x509.pem", c+".pk8")
+ }
+
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: signapk,
+ Outputs: []string{signedApk},
+ Inputs: []string{resourceApk},
+ Implicits: []string{"$signapkCmd"},
+ Args: map[string]string{
+ "certificates": strings.Join(certificateArgs, " "),
+ },
+ })
+
+ outputFile := filepath.Join(common.ModuleOutDir(ctx), "package.apk")
+
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: zipalign,
+ Outputs: []string{outputFile},
+ Inputs: []string{signedApk},
+ Implicits: []string{"$zipalignCmd"},
+ Args: map[string]string{
+ "zipalignFlags": "",
+ },
+ })
+
+ return outputFile
+}
diff --git a/java/builder.go b/java/builder.go
new file mode 100644
index 0000000..d4b900d
--- /dev/null
+++ b/java/builder.go
@@ -0,0 +1,256 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package java
+
+// This file generates the final rules for compiling all Java. All properties related to
+// compiling should have been translated into javaBuilderFlags or another argument to the Transform*
+// functions.
+
+import (
+ "path/filepath"
+ "strings"
+
+ "android/soong/common"
+
+ "github.com/google/blueprint"
+ "github.com/google/blueprint/bootstrap"
+)
+
+var (
+ pctx = blueprint.NewPackageContext("android/soong/java")
+
+ // Compiling java is not conducive to proper dependency tracking. The path-matches-class-name
+ // requirement leads to unpredictable generated source file names, and a single .java file
+ // will get compiled into multiple .class files if it contains inner classes. To work around
+ // this, all java rules write into separate directories and then a post-processing step lists
+ // the files in the the directory into a list file that later rules depend on (and sometimes
+ // read from directly using @<listfile>)
+ javac = pctx.StaticRule("javac",
+ blueprint.RuleParams{
+ Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
+ `$javacCmd -encoding UTF-8 $javacFlags $bootClasspath $classpath ` +
+ `-extdirs "" -d $outDir @$out.rsp || ( rm -rf "$outDir"; exit 41 ) && ` +
+ `find $outDir -name "*.class" > $out`,
+ Rspfile: "$out.rsp",
+ RspfileContent: "$in",
+ Description: "javac $outDir",
+ },
+ "javacCmd", "javacFlags", "bootClasspath", "classpath", "outDir")
+
+ jar = pctx.StaticRule("jar",
+ blueprint.RuleParams{
+ Command: `$jarCmd -o $out $jarArgs`,
+ Description: "jar $out",
+ },
+ "jarCmd", "jarArgs")
+
+ dx = pctx.StaticRule("dx",
+ blueprint.RuleParams{
+ Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
+ `$dxCmd --dex --output=$outDir $dxFlags $in || ( rm -rf "$outDir"; exit 41 ) && ` +
+ `find "$outDir" -name "classes*.dex" > $out`,
+ Description: "dex $out",
+ },
+ "outDir", "dxFlags")
+
+ jarjar = pctx.StaticRule("jarjar",
+ blueprint.RuleParams{
+ Command: "java -jar $jarjarCmd process $rulesFile $in $out",
+ Description: "jarjar $out",
+ },
+ "rulesFile")
+
+ extractPrebuilt = pctx.StaticRule("extractPrebuilt",
+ blueprint.RuleParams{
+ Command: `rm -rf $outDir && unzip -qo $in -d $outDir && ` +
+ `find $outDir -name "*.class" > $classFile && ` +
+ `find $outDir -type f -a \! -name "*.class" -a \! -name "MANIFEST.MF" > $resourceFile || ` +
+ `(rm -rf $outDir; exit 42)`,
+ Description: "extract java prebuilt $outDir",
+ },
+ "outDir", "classFile", "resourceFile")
+)
+
+func init() {
+ pctx.StaticVariable("commonJdkFlags", "-source 1.7 -target 1.7 -Xmaxerrs 9999999")
+ pctx.StaticVariable("javacCmd", "javac -J-Xmx1024M $commonJdkFlags")
+ pctx.StaticVariable("jarCmd", filepath.Join(bootstrap.BinDir, "soong_jar"))
+ pctx.VariableFunc("dxCmd", func(c interface{}) (string, error) {
+ return c.(common.Config).HostBinTool("dx")
+ })
+ pctx.VariableFunc("jarjarCmd", func(c interface{}) (string, error) {
+ return c.(common.Config).HostJavaTool("jarjar.jar")
+ })
+}
+
+type javaBuilderFlags struct {
+ javacFlags string
+ dxFlags string
+ bootClasspath string
+ classpath string
+ aidlFlags string
+}
+
+type jarSpec struct {
+ fileList, dir string
+}
+
+func (j jarSpec) soongJarArgs() string {
+ return "-C " + j.dir + " -l " + j.fileList
+}
+
+func TransformJavaToClasses(ctx common.AndroidModuleContext, srcFiles []string, srcFileLists []string,
+ flags javaBuilderFlags, deps []string) jarSpec {
+
+ classDir := filepath.Join(common.ModuleOutDir(ctx), "classes")
+ classFileList := filepath.Join(common.ModuleOutDir(ctx), "classes.list")
+
+ javacFlags := flags.javacFlags + common.JoinWithPrefix(srcFileLists, "@")
+
+ deps = append(deps, srcFileLists...)
+
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: javac,
+ Outputs: []string{classFileList},
+ Inputs: srcFiles,
+ Implicits: deps,
+ Args: map[string]string{
+ "javacFlags": javacFlags,
+ "bootClasspath": flags.bootClasspath,
+ "classpath": flags.classpath,
+ "outDir": classDir,
+ },
+ })
+
+ return jarSpec{classFileList, classDir}
+}
+
+func TransformClassesToJar(ctx common.AndroidModuleContext, classes []jarSpec,
+ manifest string) string {
+
+ outputFile := filepath.Join(common.ModuleOutDir(ctx), "classes-full-debug.jar")
+
+ deps := []string{}
+ jarArgs := []string{}
+
+ for _, j := range classes {
+ deps = append(deps, j.fileList)
+ jarArgs = append(jarArgs, j.soongJarArgs())
+ }
+
+ if manifest != "" {
+ deps = append(deps, manifest)
+ jarArgs = append(jarArgs, "-m "+manifest)
+ }
+
+ deps = append(deps, "$jarCmd")
+
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: jar,
+ Outputs: []string{outputFile},
+ Implicits: deps,
+ Args: map[string]string{
+ "jarArgs": strings.Join(jarArgs, " "),
+ },
+ })
+
+ return outputFile
+}
+
+func TransformClassesJarToDex(ctx common.AndroidModuleContext, classesJar string,
+ flags javaBuilderFlags) jarSpec {
+
+ outDir := filepath.Join(common.ModuleOutDir(ctx), "dex")
+ outputFile := filepath.Join(common.ModuleOutDir(ctx), "dex.filelist")
+
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: dx,
+ Outputs: []string{outputFile},
+ Inputs: []string{classesJar},
+ Implicits: []string{"$dxCmd"},
+ Args: map[string]string{
+ "dxFlags": flags.dxFlags,
+ "outDir": outDir,
+ },
+ })
+
+ return jarSpec{outputFile, outDir}
+}
+
+func TransformDexToJavaLib(ctx common.AndroidModuleContext, resources []jarSpec,
+ dexJarSpec jarSpec) string {
+
+ outputFile := filepath.Join(common.ModuleOutDir(ctx), "javalib.jar")
+ var deps []string
+ var jarArgs []string
+
+ for _, j := range resources {
+ deps = append(deps, j.fileList)
+ jarArgs = append(jarArgs, j.soongJarArgs())
+ }
+
+ deps = append(deps, dexJarSpec.fileList)
+ jarArgs = append(jarArgs, dexJarSpec.soongJarArgs())
+
+ deps = append(deps, "$jarCmd")
+
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: jar,
+ Outputs: []string{outputFile},
+ Implicits: deps,
+ Args: map[string]string{
+ "jarArgs": strings.Join(jarArgs, " "),
+ },
+ })
+
+ return outputFile
+}
+
+func TransformJarJar(ctx common.AndroidModuleContext, classesJar string, rulesFile string) string {
+ outputFile := filepath.Join(common.ModuleOutDir(ctx), "classes-jarjar.jar")
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: jarjar,
+ Outputs: []string{outputFile},
+ Inputs: []string{classesJar},
+ Implicits: []string{"$jarjarCmd"},
+ Args: map[string]string{
+ "rulesFile": rulesFile,
+ },
+ })
+
+ return outputFile
+}
+
+func TransformPrebuiltJarToClasses(ctx common.AndroidModuleContext,
+ prebuilt string) (classJarSpec, resourceJarSpec jarSpec) {
+
+ extractedDir := filepath.Join(common.ModuleOutDir(ctx), "extracted")
+ classDir := filepath.Join(extractedDir, "classes")
+ classFileList := filepath.Join(extractedDir, "classes.list")
+ resourceFileList := filepath.Join(extractedDir, "resources.list")
+
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: extractPrebuilt,
+ Outputs: []string{classFileList, resourceFileList},
+ Inputs: []string{prebuilt},
+ Args: map[string]string{
+ "outDir": classDir,
+ "classFile": classFileList,
+ "resourceFile": resourceFileList,
+ },
+ })
+
+ return jarSpec{classFileList, classDir}, jarSpec{resourceFileList, classDir}
+}
diff --git a/java/gen.go b/java/gen.go
new file mode 100644
index 0000000..dd86f66
--- /dev/null
+++ b/java/gen.go
@@ -0,0 +1,141 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package java
+
+// This file generates the final rules for compiling all C/C++. All properties related to
+// compiling should have been translated into builderFlags or another argument to the Transform*
+// functions.
+
+import (
+ "path/filepath"
+ "strings"
+
+ "github.com/google/blueprint"
+ "github.com/google/blueprint/pathtools"
+
+ "android/soong/common"
+)
+
+func init() {
+ pctx.VariableFunc("aidlCmd", func(c interface{}) (string, error) {
+ return c.(common.Config).HostBinTool("aidl")
+ })
+ pctx.StaticVariable("logtagsCmd", "${srcDir}/build/tools/java-event-log-tags.py")
+ pctx.StaticVariable("mergeLogtagsCmd", "${srcDir}/build/tools/merge-event-log-tags.py")
+ pctx.VariableConfigMethod("srcDir", common.Config.SrcDir)
+
+ pctx.VariableFunc("allLogtagsFile", func(c interface{}) (string, error) {
+ return filepath.Join(c.(common.Config).IntermediatesDir(), "all-event-log-tags.txt"), nil
+ })
+}
+
+var (
+ aidl = pctx.StaticRule("aidl",
+ blueprint.RuleParams{
+ Command: "$aidlCmd -d$depFile $aidlFlags $in $out",
+ Description: "aidl $out",
+ },
+ "depFile", "aidlFlags")
+
+ logtags = pctx.StaticRule("logtags",
+ blueprint.RuleParams{
+ Command: "$logtagsCmd -o $out $in $allLogtagsFile",
+ Description: "logtags $out",
+ })
+
+ mergeLogtags = pctx.StaticRule("mergeLogtags",
+ blueprint.RuleParams{
+ Command: "$mergeLogtagsCmd -o $out $in",
+ Description: "merge logtags $out",
+ })
+)
+
+func genAidl(ctx common.AndroidModuleContext, aidlFile, aidlFlags string) string {
+ javaFile := strings.TrimPrefix(aidlFile, common.ModuleSrcDir(ctx))
+ javaFile = filepath.Join(common.ModuleGenDir(ctx), javaFile)
+ javaFile = pathtools.ReplaceExtension(javaFile, "java")
+ depFile := javaFile + ".d"
+
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: aidl,
+ Outputs: []string{javaFile},
+ Inputs: []string{aidlFile},
+ Implicits: []string{"$aidlCmd"},
+ Args: map[string]string{
+ "depFile": depFile,
+ "aidlFlags": aidlFlags,
+ },
+ })
+
+ return javaFile
+}
+
+func genLogtags(ctx common.AndroidModuleContext, logtagsFile string) string {
+ javaFile := strings.TrimPrefix(logtagsFile, common.ModuleSrcDir(ctx))
+ javaFile = filepath.Join(common.ModuleGenDir(ctx), javaFile)
+ javaFile = pathtools.ReplaceExtension(javaFile, "java")
+
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: logtags,
+ Outputs: []string{javaFile},
+ Inputs: []string{logtagsFile},
+ Implicits: []string{"$logtagsCmd"},
+ })
+
+ return javaFile
+}
+
+func (j *javaBase) genSources(ctx common.AndroidModuleContext, srcFiles []string,
+ flags javaBuilderFlags) []string {
+
+ for i, srcFile := range srcFiles {
+ switch filepath.Ext(srcFile) {
+ case ".aidl":
+ javaFile := genAidl(ctx, srcFile, flags.aidlFlags)
+ srcFiles[i] = javaFile
+ case ".logtags":
+ j.logtagsSrcs = append(j.logtagsSrcs, srcFile)
+ javaFile := genLogtags(ctx, srcFile)
+ srcFiles[i] = javaFile
+ }
+ }
+
+ return srcFiles
+}
+
+func LogtagsSingleton() blueprint.Singleton {
+ return &logtagsSingleton{}
+}
+
+type logtagsProducer interface {
+ logtags() []string
+}
+
+type logtagsSingleton struct{}
+
+func (l *logtagsSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
+ var allLogtags []string
+ ctx.VisitAllModules(func(module blueprint.Module) {
+ if logtags, ok := module.(logtagsProducer); ok {
+ allLogtags = append(allLogtags, logtags.logtags()...)
+ }
+ })
+
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: mergeLogtags,
+ Outputs: []string{"$allLogtagsFile"},
+ Inputs: allLogtags,
+ })
+}
diff --git a/java/java.go b/java/java.go
new file mode 100644
index 0000000..8b50eff
--- /dev/null
+++ b/java/java.go
@@ -0,0 +1,608 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package java
+
+// This file contains the module types for compiling Java for Android, and converts the properties
+// into the flags and filenames necessary to pass to the compiler. The final creation of the rules
+// is handled in builder.go
+
+import (
+ "fmt"
+ "path/filepath"
+ "strings"
+
+ "github.com/google/blueprint"
+ "github.com/google/blueprint/pathtools"
+
+ "android/soong"
+ "android/soong/common"
+ "android/soong/genrule"
+)
+
+func init() {
+ soong.RegisterModuleType("java_library", JavaLibraryFactory)
+ soong.RegisterModuleType("java_library_static", JavaLibraryFactory)
+ soong.RegisterModuleType("java_library_host", JavaLibraryHostFactory)
+ soong.RegisterModuleType("java_binary", JavaBinaryFactory)
+ soong.RegisterModuleType("java_binary_host", JavaBinaryHostFactory)
+ soong.RegisterModuleType("prebuilt_java_library", JavaPrebuiltFactory)
+ soong.RegisterModuleType("prebuilt_sdk", SdkPrebuiltFactory)
+ soong.RegisterModuleType("android_app", AndroidAppFactory)
+
+ soong.RegisterSingletonType("logtags", LogtagsSingleton)
+}
+
+// TODO:
+// Autogenerated files:
+// Proto
+// Renderscript
+// Post-jar passes:
+// Proguard
+// Emma
+// Jarjar
+// Dex
+// Rmtypedefs
+// Jack
+// DroidDoc
+// Findbugs
+
+type javaBaseProperties struct {
+ // list of source files used to compile the Java module. May be .java, .logtags, .proto,
+ // or .aidl files.
+ Srcs []string `android:"arch_variant"`
+
+ // list of source files that should not be used to build the Java module.
+ // This is most useful in the arch/multilib variants to remove non-common files
+ Exclude_srcs []string `android:"arch_variant"`
+
+ // list of directories containing Java resources
+ Java_resource_dirs []string `android:"arch_variant"`
+
+ // list of directories that should be excluded from java_resource_dirs
+ Exclude_java_resource_dirs []string `android:"arch_variant"`
+
+ // don't build against the default libraries (core-libart, core-junit,
+ // ext, and framework for device targets)
+ No_standard_libraries bool
+
+ // list of module-specific flags that will be used for javac compiles
+ Javacflags []string `android:"arch_variant"`
+
+ // list of module-specific flags that will be used for jack compiles
+ Jack_flags []string `android:"arch_variant"`
+
+ // list of module-specific flags that will be used for dex compiles
+ Dxflags []string `android:"arch_variant"`
+
+ // list of of java libraries that will be in the classpath
+ Java_libs []string `android:"arch_variant"`
+
+ // list of java libraries that will be compiled into the resulting jar
+ Java_static_libs []string `android:"arch_variant"`
+
+ // manifest file to be included in resulting jar
+ Manifest string
+
+ // if not blank, set to the version of the sdk to compile against
+ Sdk_version string
+
+ // Set for device java libraries, and for host versions of device java libraries
+ // built for testing
+ Dex bool `blueprint:"mutated"`
+
+ // if not blank, run jarjar using the specified rules file
+ Jarjar_rules string
+
+ // directories to pass to aidl tool
+ Aidl_includes []string
+
+ // directories that should be added as include directories
+ // for any aidl sources of modules that depend on this module
+ Export_aidl_include_dirs []string
+}
+
+// javaBase contains the properties and members used by all java module types, and implements
+// the blueprint.Module interface.
+type javaBase struct {
+ common.AndroidModuleBase
+ module JavaModuleType
+
+ properties javaBaseProperties
+
+ // output file suitable for inserting into the classpath of another compile
+ classpathFile string
+
+ // output file suitable for installing or running
+ outputFile string
+
+ // jarSpecs suitable for inserting classes from a static library into another jar
+ classJarSpecs []jarSpec
+
+ // jarSpecs suitable for inserting resources from a static library into another jar
+ resourceJarSpecs []jarSpec
+
+ exportAidlIncludeDirs []string
+
+ logtagsSrcs []string
+
+ // filelists of extra source files that should be included in the javac command line,
+ // for example R.java generated by aapt for android apps
+ ExtraSrcLists []string
+
+ // installed file for binary dependency
+ installFile string
+}
+
+type JavaModuleType interface {
+ GenerateJavaBuildActions(ctx common.AndroidModuleContext)
+ JavaDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string
+}
+
+type JavaDependency interface {
+ ClasspathFile() string
+ ClassJarSpecs() []jarSpec
+ ResourceJarSpecs() []jarSpec
+ AidlIncludeDirs() []string
+}
+
+func NewJavaBase(base *javaBase, module JavaModuleType, hod common.HostOrDeviceSupported,
+ props ...interface{}) (blueprint.Module, []interface{}) {
+
+ base.module = module
+
+ props = append(props, &base.properties)
+
+ return common.InitAndroidArchModule(base, hod, common.MultilibCommon, props...)
+}
+
+func (j *javaBase) BootClasspath(ctx common.AndroidBaseContext) string {
+ if ctx.Device() {
+ if j.properties.Sdk_version == "" {
+ return "core-libart"
+ } else if j.properties.Sdk_version == "current" {
+ // TODO: !TARGET_BUILD_APPS
+ // TODO: export preprocessed framework.aidl from android_stubs_current
+ return "android_stubs_current"
+ } else if j.properties.Sdk_version == "system_current" {
+ return "android_system_stubs_current"
+ } else {
+ return "sdk_v" + j.properties.Sdk_version
+ }
+ } else {
+ if j.properties.Dex {
+ return "core-libart"
+ } else {
+ return ""
+ }
+ }
+}
+
+var defaultJavaLibraries = []string{"core-libart", "core-junit", "ext", "framework"}
+
+func (j *javaBase) AndroidDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string {
+ return j.module.JavaDynamicDependencies(ctx)
+}
+
+func (j *javaBase) JavaDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string {
+ var deps []string
+
+ if !j.properties.No_standard_libraries {
+ bootClasspath := j.BootClasspath(ctx)
+ if bootClasspath != "" {
+ deps = append(deps, bootClasspath)
+ }
+ if ctx.Device() && j.properties.Sdk_version == "" {
+ deps = append(deps, defaultJavaLibraries...)
+ }
+ }
+ deps = append(deps, j.properties.Java_libs...)
+ deps = append(deps, j.properties.Java_static_libs...)
+
+ return deps
+}
+
+func (j *javaBase) aidlFlags(ctx common.AndroidModuleContext, aidlPreprocess string,
+ aidlIncludeDirs []string) []string {
+
+ localAidlIncludes := pathtools.PrefixPaths(j.properties.Aidl_includes, common.ModuleSrcDir(ctx))
+
+ var flags []string
+ if aidlPreprocess != "" {
+ flags = append(flags, "-p"+aidlPreprocess)
+ } else {
+ flags = append(flags, common.JoinWithPrefix(aidlIncludeDirs, "-I"))
+ }
+
+ flags = append(flags, common.JoinWithPrefix(j.exportAidlIncludeDirs, "-I"))
+ flags = append(flags, common.JoinWithPrefix(localAidlIncludes, "-I"))
+ flags = append(flags, "-I"+common.ModuleSrcDir(ctx))
+ flags = append(flags, "-I"+filepath.Join(common.ModuleSrcDir(ctx), "src"))
+
+ return flags
+}
+
+func (j *javaBase) collectDeps(ctx common.AndroidModuleContext) (classpath []string,
+ bootClasspath string, classJarSpecs, resourceJarSpecs []jarSpec, aidlPreprocess string,
+ aidlIncludeDirs []string, srcFileLists []string) {
+
+ ctx.VisitDirectDeps(func(module blueprint.Module) {
+ otherName := ctx.OtherModuleName(module)
+ if javaDep, ok := module.(JavaDependency); ok {
+ if otherName == j.BootClasspath(ctx) {
+ bootClasspath = javaDep.ClasspathFile()
+ } else if inList(otherName, defaultJavaLibraries) {
+ classpath = append(classpath, javaDep.ClasspathFile())
+ } else if inList(otherName, j.properties.Java_libs) {
+ classpath = append(classpath, javaDep.ClasspathFile())
+ } else if inList(otherName, j.properties.Java_static_libs) {
+ classpath = append(classpath, javaDep.ClasspathFile())
+ classJarSpecs = append(classJarSpecs, javaDep.ClassJarSpecs()...)
+ resourceJarSpecs = append(resourceJarSpecs, javaDep.ResourceJarSpecs()...)
+ } else if otherName == "framework-res" {
+ if ctx.ModuleName() == "framework" {
+ // framework.jar has a one-off dependency on the R.java and Manifest.java files
+ // generated by framework-res.apk
+ srcFileLists = append(srcFileLists, module.(*javaBase).module.(*AndroidApp).aaptJavaFileList)
+ }
+ } else {
+ panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
+ }
+ aidlIncludeDirs = append(aidlIncludeDirs, javaDep.AidlIncludeDirs()...)
+ if sdkDep, ok := module.(sdkDependency); ok {
+ if sdkDep.AidlPreprocessed() != "" {
+ if aidlPreprocess != "" {
+ ctx.ModuleErrorf("multiple dependencies with preprocessed aidls:\n %q\n %q",
+ aidlPreprocess, sdkDep.AidlPreprocessed())
+ } else {
+ aidlPreprocess = sdkDep.AidlPreprocessed()
+ }
+ }
+ }
+ }
+ })
+
+ return classpath, bootClasspath, classJarSpecs, resourceJarSpecs, aidlPreprocess,
+ aidlIncludeDirs, srcFileLists
+}
+
+func (j *javaBase) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) {
+ j.module.GenerateJavaBuildActions(ctx)
+}
+
+func (j *javaBase) GenerateJavaBuildActions(ctx common.AndroidModuleContext) {
+
+ j.exportAidlIncludeDirs = pathtools.PrefixPaths(j.properties.Export_aidl_include_dirs,
+ common.ModuleSrcDir(ctx))
+
+ classpath, bootClasspath, classJarSpecs, resourceJarSpecs, aidlPreprocess,
+ aidlIncludeDirs, srcFileLists := j.collectDeps(ctx)
+
+ var flags javaBuilderFlags
+
+ javacFlags := j.properties.Javacflags
+ if len(javacFlags) > 0 {
+ ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
+ flags.javacFlags = "$javacFlags"
+ }
+
+ aidlFlags := j.aidlFlags(ctx, aidlPreprocess, aidlIncludeDirs)
+ if len(aidlFlags) > 0 {
+ ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
+ flags.aidlFlags = "$aidlFlags"
+ }
+
+ var javacDeps []string
+
+ if bootClasspath != "" {
+ flags.bootClasspath = "-bootclasspath " + bootClasspath
+ javacDeps = append(javacDeps, bootClasspath)
+ }
+
+ if len(classpath) > 0 {
+ flags.classpath = "-classpath " + strings.Join(classpath, ":")
+ javacDeps = append(javacDeps, classpath...)
+ }
+
+ srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
+
+ srcFiles = j.genSources(ctx, srcFiles, flags)
+
+ ctx.VisitDirectDeps(func(module blueprint.Module) {
+ if gen, ok := module.(genrule.SourceFileGenerator); ok {
+ srcFiles = append(srcFiles, gen.GeneratedSourceFiles()...)
+ }
+ })
+
+ srcFileLists = append(srcFileLists, j.ExtraSrcLists...)
+
+ if len(srcFiles) > 0 {
+ // Compile java sources into .class files
+ classes := TransformJavaToClasses(ctx, srcFiles, srcFileLists, flags, javacDeps)
+ if ctx.Failed() {
+ return
+ }
+
+ classJarSpecs = append([]jarSpec{classes}, classJarSpecs...)
+ }
+
+ resourceJarSpecs = append(ResourceDirsToJarSpecs(ctx, j.properties.Java_resource_dirs, j.properties.Exclude_java_resource_dirs),
+ resourceJarSpecs...)
+
+ manifest := j.properties.Manifest
+ if manifest != "" {
+ manifest = filepath.Join(common.ModuleSrcDir(ctx), manifest)
+ }
+
+ allJarSpecs := append([]jarSpec(nil), classJarSpecs...)
+ allJarSpecs = append(allJarSpecs, resourceJarSpecs...)
+
+ // Combine classes + resources into classes-full-debug.jar
+ outputFile := TransformClassesToJar(ctx, allJarSpecs, manifest)
+ if ctx.Failed() {
+ return
+ }
+
+ if j.properties.Jarjar_rules != "" {
+ jarjar_rules := filepath.Join(common.ModuleSrcDir(ctx), j.properties.Jarjar_rules)
+ // Transform classes-full-debug.jar into classes-jarjar.jar
+ outputFile = TransformJarJar(ctx, outputFile, jarjar_rules)
+ if ctx.Failed() {
+ return
+ }
+
+ classes, _ := TransformPrebuiltJarToClasses(ctx, outputFile)
+ classJarSpecs = []jarSpec{classes}
+ }
+
+ j.resourceJarSpecs = resourceJarSpecs
+ j.classJarSpecs = classJarSpecs
+ j.classpathFile = outputFile
+
+ if j.properties.Dex && len(srcFiles) > 0 {
+ dxFlags := j.properties.Dxflags
+ if false /* emma enabled */ {
+ // If you instrument class files that have local variable debug information in
+ // them emma does not correctly maintain the local variable table.
+ // This will cause an error when you try to convert the class files for Android.
+ // The workaround here is to build different dex file here based on emma switch
+ // then later copy into classes.dex. When emma is on, dx is run with --no-locals
+ // option to remove local variable information
+ dxFlags = append(dxFlags, "--no-locals")
+ }
+
+ if ctx.AConfig().Getenv("NO_OPTIMIZE_DX") != "" {
+ dxFlags = append(dxFlags, "--no-optimize")
+ }
+
+ if ctx.AConfig().Getenv("GENERATE_DEX_DEBUG") != "" {
+ dxFlags = append(dxFlags,
+ "--debug",
+ "--verbose",
+ "--dump-to="+filepath.Join(common.ModuleOutDir(ctx), "classes.lst"),
+ "--dump-width=1000")
+ }
+
+ flags.dxFlags = strings.Join(dxFlags, " ")
+
+ // Compile classes.jar into classes.dex
+ dexJarSpec := TransformClassesJarToDex(ctx, outputFile, flags)
+ if ctx.Failed() {
+ return
+ }
+
+ // Combine classes.dex + resources into javalib.jar
+ outputFile = TransformDexToJavaLib(ctx, resourceJarSpecs, dexJarSpec)
+ }
+ ctx.CheckbuildFile(outputFile)
+ j.outputFile = outputFile
+}
+
+var _ JavaDependency = (*JavaLibrary)(nil)
+
+func (j *javaBase) ClasspathFile() string {
+ return j.classpathFile
+}
+
+func (j *javaBase) ClassJarSpecs() []jarSpec {
+ return j.classJarSpecs
+}
+
+func (j *javaBase) ResourceJarSpecs() []jarSpec {
+ return j.resourceJarSpecs
+}
+
+func (j *javaBase) AidlIncludeDirs() []string {
+ return j.exportAidlIncludeDirs
+}
+
+var _ logtagsProducer = (*javaBase)(nil)
+
+func (j *javaBase) logtags() []string {
+ return j.logtagsSrcs
+}
+
+//
+// Java libraries (.jar file)
+//
+
+type JavaLibrary struct {
+ javaBase
+}
+
+func (j *JavaLibrary) GenerateJavaBuildActions(ctx common.AndroidModuleContext) {
+ j.javaBase.GenerateJavaBuildActions(ctx)
+
+ j.installFile = ctx.InstallFileName("framework", ctx.ModuleName()+".jar", j.outputFile)
+}
+
+func JavaLibraryFactory() (blueprint.Module, []interface{}) {
+ module := &JavaLibrary{}
+
+ module.properties.Dex = true
+
+ return NewJavaBase(&module.javaBase, module, common.HostAndDeviceSupported)
+}
+
+func JavaLibraryHostFactory() (blueprint.Module, []interface{}) {
+ module := &JavaLibrary{}
+
+ return NewJavaBase(&module.javaBase, module, common.HostSupported)
+}
+
+//
+// Java Binaries (.jar file plus wrapper script)
+//
+
+type javaBinaryProperties struct {
+ // installable script to execute the resulting jar
+ Wrapper string
+}
+
+type JavaBinary struct {
+ JavaLibrary
+
+ binaryProperties javaBinaryProperties
+}
+
+func (j *JavaBinary) GenerateJavaBuildActions(ctx common.AndroidModuleContext) {
+ j.JavaLibrary.GenerateJavaBuildActions(ctx)
+
+ // Depend on the installed jar (j.installFile) so that the wrapper doesn't get executed by
+ // another build rule before the jar has been installed.
+ ctx.InstallFile("bin", filepath.Join(common.ModuleSrcDir(ctx), j.binaryProperties.Wrapper),
+ j.installFile)
+}
+
+func JavaBinaryFactory() (blueprint.Module, []interface{}) {
+ module := &JavaBinary{}
+
+ module.properties.Dex = true
+
+ return NewJavaBase(&module.javaBase, module, common.HostAndDeviceSupported, &module.binaryProperties)
+}
+
+func JavaBinaryHostFactory() (blueprint.Module, []interface{}) {
+ module := &JavaBinary{}
+
+ return NewJavaBase(&module.javaBase, module, common.HostSupported, &module.binaryProperties)
+}
+
+//
+// Java prebuilts
+//
+
+type javaPrebuiltProperties struct {
+ Srcs []string
+}
+
+type JavaPrebuilt struct {
+ common.AndroidModuleBase
+
+ properties javaPrebuiltProperties
+
+ classpathFile string
+ classJarSpecs, resourceJarSpecs []jarSpec
+}
+
+func (j *JavaPrebuilt) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) {
+ if len(j.properties.Srcs) != 1 {
+ ctx.ModuleErrorf("expected exactly one jar in srcs")
+ return
+ }
+ prebuilt := filepath.Join(common.ModuleSrcDir(ctx), j.properties.Srcs[0])
+
+ classJarSpec, resourceJarSpec := TransformPrebuiltJarToClasses(ctx, prebuilt)
+
+ j.classpathFile = prebuilt
+ j.classJarSpecs = []jarSpec{classJarSpec}
+ j.resourceJarSpecs = []jarSpec{resourceJarSpec}
+ ctx.InstallFileName("framework", ctx.ModuleName()+".jar", j.classpathFile)
+}
+
+var _ JavaDependency = (*JavaPrebuilt)(nil)
+
+func (j *JavaPrebuilt) ClasspathFile() string {
+ return j.classpathFile
+}
+
+func (j *JavaPrebuilt) ClassJarSpecs() []jarSpec {
+ return j.classJarSpecs
+}
+
+func (j *JavaPrebuilt) ResourceJarSpecs() []jarSpec {
+ return j.resourceJarSpecs
+}
+
+func (j *JavaPrebuilt) AidlIncludeDirs() []string {
+ return nil
+}
+
+func JavaPrebuiltFactory() (blueprint.Module, []interface{}) {
+ module := &JavaPrebuilt{}
+
+ return common.InitAndroidArchModule(module, common.HostAndDeviceSupported,
+ common.MultilibCommon, &module.properties)
+}
+
+//
+// SDK java prebuilts (.jar containing resources plus framework.aidl)
+//
+
+type sdkDependency interface {
+ JavaDependency
+ AidlPreprocessed() string
+}
+
+var _ sdkDependency = (*sdkPrebuilt)(nil)
+
+type sdkPrebuiltProperties struct {
+ Aidl_preprocessed string
+}
+
+type sdkPrebuilt struct {
+ JavaPrebuilt
+
+ sdkProperties sdkPrebuiltProperties
+
+ aidlPreprocessed string
+}
+
+func (j *sdkPrebuilt) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) {
+ j.JavaPrebuilt.GenerateAndroidBuildActions(ctx)
+
+ if j.sdkProperties.Aidl_preprocessed != "" {
+ j.aidlPreprocessed = filepath.Join(common.ModuleSrcDir(ctx), j.sdkProperties.Aidl_preprocessed)
+ }
+}
+
+func (j *sdkPrebuilt) AidlPreprocessed() string {
+ return j.aidlPreprocessed
+}
+
+func SdkPrebuiltFactory() (blueprint.Module, []interface{}) {
+ module := &sdkPrebuilt{}
+
+ return common.InitAndroidArchModule(module, common.HostAndDeviceSupported,
+ common.MultilibCommon, &module.properties, &module.sdkProperties)
+}
+
+func inList(s string, l []string) bool {
+ for _, e := range l {
+ if e == s {
+ return true
+ }
+ }
+ return false
+}
diff --git a/java/resources.go b/java/resources.go
new file mode 100644
index 0000000..995e60d
--- /dev/null
+++ b/java/resources.go
@@ -0,0 +1,69 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package java
+
+import (
+ "path/filepath"
+
+ "android/soong/common"
+)
+
+var resourceExcludes = []string{
+ "**/*.java",
+ "**/package.html",
+ "**/overview.html",
+ "**/.*.swp",
+ "**/.DS_Store",
+ "**/*~",
+}
+
+func isStringInSlice(str string, slice []string) bool {
+ for _, s := range slice {
+ if s == str {
+ return true
+ }
+ }
+ return false
+}
+
+func ResourceDirsToJarSpecs(ctx common.AndroidModuleContext, resourceDirs, excludeDirs []string) []jarSpec {
+ var excludes []string
+
+ for _, exclude := range excludeDirs {
+ excludes = append(excludes, filepath.Join(common.ModuleSrcDir(ctx), exclude, "**/*"))
+ }
+
+ excludes = append(excludes, resourceExcludes...)
+
+ var jarSpecs []jarSpec
+
+ for _, resourceDir := range resourceDirs {
+ if isStringInSlice(resourceDir, excludeDirs) {
+ continue
+ }
+ resourceDir := filepath.Join(common.ModuleSrcDir(ctx), resourceDir)
+ dirs := ctx.Glob("java_resources", resourceDir, nil)
+ for _, dir := range dirs {
+ fileListFile := filepath.Join(common.ModuleOutDir(ctx), "res", dir, "resources.list")
+ depFile := fileListFile + ".d"
+
+ glob := filepath.Join(dir, "**/*")
+ common.GlobRule(ctx, glob, excludes, fileListFile, depFile)
+ jarSpecs = append(jarSpecs, jarSpec{fileListFile, dir})
+ }
+ }
+
+ return jarSpecs
+}
diff --git a/register.go b/register.go
new file mode 100644
index 0000000..c35beae
--- /dev/null
+++ b/register.go
@@ -0,0 +1,68 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package soong
+
+import "github.com/google/blueprint"
+
+type moduleType struct {
+ name string
+ factory blueprint.ModuleFactory
+}
+
+var moduleTypes []moduleType
+
+type singleton struct {
+ name string
+ factory blueprint.SingletonFactory
+}
+
+var singletons []singleton
+
+type earlyMutator struct {
+ name string
+ mutator blueprint.EarlyMutator
+}
+
+var earlyMutators []earlyMutator
+
+func RegisterModuleType(name string, factory blueprint.ModuleFactory) {
+ moduleTypes = append(moduleTypes, moduleType{name, factory})
+}
+
+func RegisterSingletonType(name string, factory blueprint.SingletonFactory) {
+ singletons = append(singletons, singleton{name, factory})
+}
+
+func RegisterEarlyMutator(name string, mutator blueprint.EarlyMutator) {
+ earlyMutators = append(earlyMutators, earlyMutator{name, mutator})
+}
+
+func NewContext() *blueprint.Context {
+ ctx := blueprint.NewContext()
+
+ for _, t := range moduleTypes {
+ ctx.RegisterModuleType(t.name, t.factory)
+ }
+
+ for _, t := range singletons {
+ ctx.RegisterSingletonType(t.name, t.factory)
+ }
+
+ for _, t := range earlyMutators {
+ ctx.RegisterEarlyMutator(t.name, t.mutator)
+ }
+
+ return ctx
+}
diff --git a/root.bp b/root.bp
new file mode 100644
index 0000000..ea17db3
--- /dev/null
+++ b/root.bp
@@ -0,0 +1,22 @@
+subname = "Android.bp"
+
+subdirs = [
+ "art",
+ "build/blueprint",
+ "build/soong",
+ "bionic",
+ "dalvik",
+ "external/*",
+ "frameworks/base",
+ "frameworks/native/libs/*",
+ "hardware/*",
+ "libcore",
+ "libnativehelper",
+ "prebuilts/ndk",
+ "prebuilts/sdk",
+ "system/core/*",
+ "packages/apps/HTMLViewer",
+ "build/tools/*",
+ "system/security/*",
+ "system/keymaster",
+]
diff --git a/soong.bash b/soong.bash
new file mode 100755
index 0000000..778f5e0
--- /dev/null
+++ b/soong.bash
@@ -0,0 +1,47 @@
+#!/bin/bash
+
+# Determine the build directory location based on the location of this script.
+BPBUILD="${BASH_SOURCE[0]}"
+BUILDDIR=`dirname "${BASH_SOURCE[0]}"`
+BOOTSTRAP="${BUILDDIR}/.soong.bootstrap"
+
+# The source directory path and operating system will get written to
+# .soong.bootstrap by the bootstrap script.
+
+if [ ! -f "${BOOTSTRAP}" ]; then
+ echo "Error: soong script must be located in a directory created by bootstrap.bash"
+ exit 1
+fi
+
+source "${BOOTSTRAP}"
+
+if [[ ${SRCDIR_IN:0:1} == '/' ]]; then
+ # SRCDIR_IN is an absolute path
+ SRCDIR="${SRCDIR_IN}"
+else
+ # SRCDIR_IN is a relative path
+ SRCDIR="${BUILDDIR}/${SRCDIR_IN}"
+fi
+
+# Let Blueprint know that the Ninja we're using performs multiple passes that
+# can regenerate the build manifest.
+export BLUEPRINT_NINJA_HAS_MULTIPASS=1
+
+# Ninja can't depend on environment variables, so do a manual comparison
+# of the relevant environment variables from the last build using the
+# soong_env tool and trigger a build manifest regeneration if necessary
+ENVFILE="${BUILDDIR}/.soong.environment"
+ENVTOOL="${BUILDDIR}/.bootstrap/bin/soong_env"
+if [ -f "${ENVFILE}" ]; then
+ if [ -x "${ENVTOOL}" ]; then
+ if ! "${ENVTOOL}" "${ENVFILE}"; then
+ echo "forcing build manifest regeneration"
+ rm -f "${ENVFILE}"
+ fi
+ else
+ echo "Missing soong_env tool, forcing build manifest regeneration"
+ rm -f "${ENVFILE}"
+ fi
+fi
+
+"${SRCDIR}/prebuilts/ninja/${PREBUILTOS}/ninja" -C "${BUILDDIR}" "$@"
diff --git a/soong.bootstrap.in b/soong.bootstrap.in
new file mode 100644
index 0000000..79e4a65
--- /dev/null
+++ b/soong.bootstrap.in
@@ -0,0 +1,2 @@
+SRCDIR_IN="@@SrcDir@@"
+PREBUILTOS="@@PrebuiltOS@@"