Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 02ce1e78 authored by Colin Cross's avatar Colin Cross Committed by Gerrit Code Review
Browse files

Merge changes Ib3f4ee14,Iac22c9fd,Ibd78758c,I40d8696c,I2a2b10e4, ...

* changes:
  Fix InstallBypassMake symlink dependencies
  Add tests for ctx.InstallFile
  Fix OutDir vs SoongOutDir in tests
  Fix go vet error
  Add missing os.MkdirAll to WriteFileToOutputDir
  Use pathtools.WriteFileIfChanged in translateAndroidMk
parents 3d3aa703 64002afc
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -19,6 +19,9 @@ bootstrap_go_package {
        "soong-ui-metrics_proto",
        "golang-protobuf-proto",
        "golang-protobuf-encoding-prototext",

        // Only used for tests.
        "androidmk-parser",
    ],
    srcs: [
        "androidmk.go",
+4 −24
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import (
	"bytes"
	"fmt"
	"io"
	"io/ioutil"
	"os"
	"path/filepath"
	"reflect"
@@ -35,6 +34,7 @@ import (

	"github.com/google/blueprint"
	"github.com/google/blueprint/bootstrap"
	"github.com/google/blueprint/pathtools"
)

func init() {
@@ -690,7 +690,7 @@ func (c *androidMkSingleton) GenerateBuildActions(ctx SingletonContext) {
	})
}

func translateAndroidMk(ctx SingletonContext, mkFile string, mods []blueprint.Module) error {
func translateAndroidMk(ctx SingletonContext, absMkFile string, mods []blueprint.Module) error {
	buf := &bytes.Buffer{}

	fmt.Fprintln(buf, "LOCAL_MODULE_MAKEFILE := $(lastword $(MAKEFILE_LIST))")
@@ -699,7 +699,7 @@ func translateAndroidMk(ctx SingletonContext, mkFile string, mods []blueprint.Mo
	for _, mod := range mods {
		err := translateAndroidMkModule(ctx, buf, mod)
		if err != nil {
			os.Remove(mkFile)
			os.Remove(absMkFile)
			return err
		}

@@ -719,27 +719,7 @@ func translateAndroidMk(ctx SingletonContext, mkFile string, mods []blueprint.Mo
		fmt.Fprintf(buf, "STATS.SOONG_MODULE_TYPE.%s := %d\n", mod_type, typeStats[mod_type])
	}

	// Don't write to the file if it hasn't changed
	if _, err := os.Stat(absolutePath(mkFile)); !os.IsNotExist(err) {
		if data, err := ioutil.ReadFile(absolutePath(mkFile)); err == nil {
			matches := buf.Len() == len(data)

			if matches {
				for i, value := range buf.Bytes() {
					if value != data[i] {
						matches = false
						break
					}
				}
			}

			if matches {
				return nil
			}
		}
	}

	return ioutil.WriteFile(absolutePath(mkFile), buf.Bytes(), 0666)
	return pathtools.WriteFileIfChanged(absMkFile, buf.Bytes(), 0666)
}

func translateAndroidMkModule(ctx SingletonContext, w io.Writer, mod blueprint.Module) error {
+2 −4
Original line number Diff line number Diff line
@@ -335,9 +335,7 @@ func TestConfig(buildDir string, env map[string]string, bp string, fs map[string
		},

		outDir:       buildDir,
		// soongOutDir is inconsistent with production (it should be buildDir + "/soong")
		// but a lot of tests assume this :(
		soongOutDir:  buildDir,
		soongOutDir:  filepath.Join(buildDir, "soong"),
		captureBuild: true,
		env:          envCopy,

+21 −9
Original line number Diff line number Diff line
@@ -142,15 +142,19 @@ type SingletonMakeVarsProvider interface {

var singletonMakeVarsProvidersKey = NewOnceKey("singletonMakeVarsProvidersKey")

func getSingletonMakevarsProviders(config Config) *[]makeVarsProvider {
	return config.Once(singletonMakeVarsProvidersKey, func() interface{} {
		return &[]makeVarsProvider{}
	}).(*[]makeVarsProvider)
}

// registerSingletonMakeVarsProvider adds a singleton that implements SingletonMakeVarsProvider to
// the list of MakeVarsProviders to run.
func registerSingletonMakeVarsProvider(config Config, singleton SingletonMakeVarsProvider) {
	// Singletons are registered on the Context and may be different between different Contexts,
	// for example when running multiple tests.  Store the SingletonMakeVarsProviders in the
	// Config so they are attached to the Context.
	singletonMakeVarsProviders := config.Once(singletonMakeVarsProvidersKey, func() interface{} {
		return &[]makeVarsProvider{}
	}).(*[]makeVarsProvider)
	singletonMakeVarsProviders := getSingletonMakevarsProviders(config)

	*singletonMakeVarsProviders = append(*singletonMakeVarsProviders,
		makeVarsProvider{pctx, singletonMakeVarsProviderAdapter(singleton)})
@@ -175,7 +179,9 @@ func makeVarsSingletonFunc() Singleton {
	return &makeVarsSingleton{}
}

type makeVarsSingleton struct{}
type makeVarsSingleton struct {
	installsForTesting []byte
}

type makeVarsProvider struct {
	pctx PackageContext
@@ -238,7 +244,7 @@ func (s *makeVarsSingleton) GenerateBuildActions(ctx SingletonContext) {
	var katiSymlinks []katiInstall

	providers := append([]makeVarsProvider(nil), makeVarsInitProviders...)
	providers = append(providers, *ctx.Config().Get(singletonMakeVarsProvidersKey).(*[]makeVarsProvider)...)
	providers = append(providers, *getSingletonMakevarsProviders(ctx.Config())...)

	for _, provider := range providers {
		mctx := &makeVarsContext{
@@ -313,6 +319,8 @@ func (s *makeVarsSingleton) GenerateBuildActions(ctx SingletonContext) {
	if err := pathtools.WriteFileIfChanged(installsFile, installsBytes, 0666); err != nil {
		ctx.Errorf(err.Error())
	}

	s.installsForTesting = installsBytes
}

func (s *makeVarsSingleton) writeVars(vars []makeVarsVariable) []byte {
@@ -465,15 +473,19 @@ func (s *makeVarsSingleton) writeInstalls(installs, symlinks []katiInstall) []by

	for _, symlink := range symlinks {
		fmt.Fprintf(buf, "%s:", symlink.to.String())
		if symlink.from != nil {
			// The symlink doesn't need updating when the target is modified, but we sometimes
			// have a dependency on a symlink to a binary instead of to the binary directly, and
			// the mtime of the symlink must be updated when the binary is modified, so use a
			// normal dependency here instead of an order-only dependency.
			fmt.Fprintf(buf, " %s", symlink.from.String())
		}
		for _, dep := range symlink.implicitDeps {
			fmt.Fprintf(buf, " %s", dep.String())
		}
		if symlink.from != nil || len(symlink.orderOnlyDeps) > 0 {
		if len(symlink.orderOnlyDeps) > 0 {
			fmt.Fprintf(buf, " |")
		}
		if symlink.from != nil {
			fmt.Fprintf(buf, " %s", symlink.from.String())
		}
		for _, dep := range symlink.orderOnlyDeps {
			fmt.Fprintf(buf, " %s", dep.String())
		}
+4 −0
Original line number Diff line number Diff line
@@ -2953,6 +2953,10 @@ func (m *moduleContext) InstallSymlink(installPath InstallPath, name string, src
				to:   fullInstallPath,
			})
		} else {
			// The symlink doesn't need updating when the target is modified, but we sometimes
			// have a dependency on a symlink to a binary instead of to the binary directly, and
			// the mtime of the symlink must be updated when the binary is modified, so use a
			// normal dependency here instead of an order-only dependency.
			m.Build(pctx, BuildParams{
				Rule:        Symlink,
				Description: "install symlink " + fullInstallPath.Base(),
Loading