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

Commit 3be24727 authored by Sam Delmerico's avatar Sam Delmerico Committed by Gerrit Code Review
Browse files

Merge changes from topic "aidl_interface_bp2build"

* changes:
  add bp2build unit tests for aidl_interface
  AIDL source generation accounts for Bazel paths
  convert .aidl srcs for java_library
  add Partition method to LabelListAttribute
parents 5fa4e961 1fa2672b
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -157,6 +157,7 @@ var (
		"frameworks/av/media/liberror":                       Bp2BuildDefaultTrueRecursively,
		"frameworks/av/services/minijail":                    Bp2BuildDefaultTrueRecursively,
		"frameworks/base/media/tests/MediaDump":              Bp2BuildDefaultTrue,
		"frameworks/base/services/tests/servicestests/aidl":  Bp2BuildDefaultTrue,
		"frameworks/base/startop/apps/test":                  Bp2BuildDefaultTrue,
		"frameworks/base/tests/appwidgets/AppWidgetHostTest": Bp2BuildDefaultTrueRecursively,
		"frameworks/native/libs/adbd_auth":                   Bp2BuildDefaultTrueRecursively,
@@ -408,6 +409,7 @@ var (
		"linker_config",
		"java_import",
		"java_import_host",
		"aidl_interface_headers",
	}

	Bp2buildModuleDoNotConvertList = []string{
+42 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ package android

import (
	"path/filepath"
	"regexp"
	"strings"

	"android/soong/bazel"
@@ -37,6 +38,34 @@ func IsFilegroup(ctx bazel.OtherModuleContext, m blueprint.Module) bool {
	return ctx.OtherModuleType(m) == "filegroup"
}

var (
	// ignoring case, checks for proto or protos as an independent word in the name, whether at the
	// beginning, end, or middle. e.g. "proto.foo", "bar-protos", "baz_proto_srcs" would all match
	filegroupLikelyProtoPattern = regexp.MustCompile("(?i)(^|[^a-z])proto(s)?([^a-z]|$)")
	filegroupLikelyAidlPattern  = regexp.MustCompile("(?i)(^|[^a-z])aidl([^a-z]|$)")

	ProtoSrcLabelPartition = bazel.LabelPartition{
		Extensions:  []string{".proto"},
		LabelMapper: isFilegroupWithPattern(filegroupLikelyProtoPattern),
	}
	AidlSrcLabelPartition = bazel.LabelPartition{
		Extensions:  []string{".aidl"},
		LabelMapper: isFilegroupWithPattern(filegroupLikelyAidlPattern),
	}
)

func isFilegroupWithPattern(pattern *regexp.Regexp) bazel.LabelMapper {
	return func(ctx bazel.OtherModuleContext, label bazel.Label) (string, bool) {
		m, exists := ctx.ModuleFromName(label.OriginalModuleName)
		labelStr := label.Label
		if !exists || !IsFilegroup(ctx, m) {
			return labelStr, false
		}
		likelyMatched := pattern.MatchString(label.OriginalModuleName)
		return labelStr, likelyMatched
	}
}

// https://docs.bazel.build/versions/master/be/general.html#filegroup
type bazelFilegroupAttributes struct {
	Srcs bazel.LabelListAttribute
@@ -232,3 +261,16 @@ func (fg *fileGroup) GetAidlLibraryLabel(ctx BazelConversionPathContext) string
		return fg.GetBazelLabel(ctx, fg)
	}
}

// Given a name in srcs prop, check to see if the name references a filegroup
// and the filegroup is converted to aidl_library
func IsConvertedToAidlLibrary(ctx BazelConversionPathContext, name string) bool {
	if module, ok := ctx.ModuleFromName(name); ok {
		if IsFilegroup(ctx, module) {
			if fg, ok := module.(Bp2buildAidlLibrary); ok {
				return fg.ShouldConvertToAidlLibrary(ctx)
			}
		}
	}
	return false
}
+14 −0
Original line number Diff line number Diff line
@@ -642,6 +642,20 @@ type TestResult struct {
	NinjaDeps []string
}

type TestPathContext struct {
	*TestResult
}

var _ PathContext = &TestPathContext{}

func (t *TestPathContext) Config() Config {
	return t.TestResult.Config
}

func (t *TestPathContext) AddNinjaFileDeps(deps ...string) {
	panic("unimplemented")
}

func createFixture(t *testing.T, buildDir string, preparers []*simpleFixturePreparer) Fixture {
	config := TestConfig(buildDir, nil, "", nil)
	ctx := NewTestContext(config)
+12 −0
Original line number Diff line number Diff line
@@ -1978,6 +1978,18 @@ func PathForTesting(paths ...string) Path {
	return testPath{basePath{path: p, rel: p}}
}

func PathForTestingWithRel(path, rel string) Path {
	p, err := validateSafePath(path, rel)
	if err != nil {
		panic(err)
	}
	r, err := validatePath(rel)
	if err != nil {
		panic(err)
	}
	return testPath{basePath{path: p, rel: r}}
}

// PathsForTesting returns a Path constructed from each element in strs. It should only be used from within tests.
func PathsForTesting(strs ...string) Paths {
	p := make(Paths, len(strs))
+0 −19
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@ package android

import (
	"android/soong/bazel"
	"regexp"
	"strings"

	"github.com/google/blueprint"
@@ -27,14 +26,6 @@ const (
	canonicalPathFromRootDefault = true
)

var (
	// ignoring case, checks for proto or protos as an independent word in the name, whether at the
	// beginning, end, or middle. e.g. "proto.foo", "bar-protos", "baz_proto_srcs" would all match
	filegroupLikelyProtoPattern = regexp.MustCompile("(?i)(^|[^a-z])proto(s)?([^a-z]|$)")

	ProtoSrcLabelPartition = bazel.LabelPartition{Extensions: []string{".proto"}, LabelMapper: isProtoFilegroup}
)

// TODO(ccross): protos are often used to communicate between multiple modules.  If the only
// way to convert a proto to source is to reference it as a source file, and external modules cannot
// reference source files in other modules, then every module that owns a proto file will need to
@@ -213,13 +204,3 @@ func Bp2buildProtoProperties(ctx Bp2buildMutatorContext, m *ModuleBase, srcs baz

	return info, true
}

func isProtoFilegroup(ctx bazel.OtherModuleContext, label bazel.Label) (string, bool) {
	m, exists := ctx.ModuleFromName(label.OriginalModuleName)
	labelStr := label.Label
	if !exists || !IsFilegroup(ctx, m) {
		return labelStr, false
	}
	likelyProtos := filegroupLikelyProtoPattern.MatchString(label.OriginalModuleName)
	return labelStr, likelyProtos
}
Loading