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

Commit dabeb50e authored by Wei Li's avatar Wei Li Committed by Android (Google) Code Review
Browse files

Merge changes from topic "cherrypicker-L80700000960770298:N69600001370607907" into udc-dev

* changes:
  Change bp2build converter of module "package".
  Export some make variables to Bazel through product variables.
parents 16ef197d dff65b01
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -76,6 +76,7 @@ func isFilegroupWithPattern(pattern *regexp.Regexp) bazel.LabelMapper {
// https://docs.bazel.build/versions/master/be/general.html#filegroup
type bazelFilegroupAttributes struct {
	Srcs                bazel.LabelListAttribute
	Applicable_licenses bazel.LabelListAttribute
}

type bazelAidlLibraryAttributes struct {
+24 −3
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@
package android

import (
	"path/filepath"

	"android/soong/bazel"
	"github.com/google/blueprint"
	"github.com/google/blueprint/proptools"
@@ -40,7 +42,7 @@ type packageProperties struct {

type bazelPackageAttributes struct {
	Default_visibility       []string
	Default_applicable_licenses bazel.LabelListAttribute
	Default_package_metadata bazel.LabelListAttribute
}

type packageModule struct {
@@ -53,13 +55,32 @@ type packageModule struct {
var _ Bazelable = &packageModule{}

func (p *packageModule) ConvertWithBp2build(ctx TopDownMutatorContext) {
	defaultPackageMetadata := bazel.MakeLabelListAttribute(BazelLabelForModuleDeps(ctx, p.properties.Default_applicable_licenses))
	// If METADATA file exists in the package, add it to package(default_package_metadata=) using a
	// filegroup(name="default_metadata_file") which can be accessed later on each module in Bazel
	// using attribute "applicable_licenses".
	// Attribute applicable_licenses of filegroup "default_metadata_file" has to be set to [],
	// otherwise Bazel reports cyclic reference error.
	if existed, _, _ := ctx.Config().fs.Exists(filepath.Join(ctx.ModuleDir(), "METADATA")); existed {
		ctx.CreateBazelTargetModule(
			bazel.BazelTargetModuleProperties{
				Rule_class: "filegroup",
			},
			CommonAttributes{Name: "default_metadata_file"},
			&bazelFilegroupAttributes{
				Srcs:                bazel.MakeLabelListAttribute(BazelLabelForModuleSrc(ctx, []string{"METADATA"})),
				Applicable_licenses: bazel.LabelListAttribute{Value: bazel.LabelList{Includes: []bazel.Label{}}, EmitEmptyList: true},
			})
		defaultPackageMetadata.Value.Add(&bazel.Label{Label: ":default_metadata_file"})
	}

	ctx.CreateBazelTargetModule(
		bazel.BazelTargetModuleProperties{
			Rule_class: "package",
		},
		CommonAttributes{},
		&bazelPackageAttributes{
			Default_applicable_licenses: bazel.MakeLabelListAttribute(BazelLabelForModuleDeps(ctx, p.properties.Default_applicable_licenses)),
			Default_package_metadata: defaultPackageMetadata,
			// FIXME(asmundak): once b/221436821 is resolved
			Default_visibility: []string{"//visibility:public"},
		})
+4 −0
Original line number Diff line number Diff line
@@ -469,6 +469,10 @@ type productVariables struct {
	SourceRootDirs []string `json:",omitempty"`

	AfdoProfiles []string `json:",omitempty"`

	ProductManufacturer string   `json:",omitempty"`
	ProductBrand        string   `json:",omitempty"`
	BuildVersionTags    []string `json:",omitempty"`
}

func boolPtr(v bool) *bool {
+57 −3
Original line number Diff line number Diff line
@@ -15,9 +15,10 @@
package bp2build

import (
	"testing"

	"android/soong/android"
	"android/soong/genrule"
	"testing"
)

func registerDependentModules(ctx android.RegistrationContext) {
@@ -29,6 +30,7 @@ func TestPackage(t *testing.T) {
	tests := []struct {
		description string
		modules     string
		fs          map[string]string
		expected    []ExpectedRuleTarget
	}{
		{
@@ -50,7 +52,7 @@ package {
					"package",
					"",
					AttrNameToString{
						"default_applicable_licenses": `[":my_license"]`,
						"default_package_metadata": `[":my_license"]`,
						"default_visibility":       `["//visibility:public"]`,
					},
					android.HostAndDeviceDefault,
@@ -67,6 +69,57 @@ package {
				},
			},
		},
		{
			description: "package has METADATA file",
			fs: map[string]string{
				"METADATA": ``,
			},
			modules: `
license {
  name: "my_license",
  visibility: [":__subpackages__"],
  license_kinds: ["SPDX-license-identifier-Apache-2.0"],
  license_text: ["NOTICE"],
}

package {
  default_applicable_licenses: ["my_license"],
}
`,
			expected: []ExpectedRuleTarget{
				{
					"package",
					"",
					AttrNameToString{
						"default_package_metadata": `[
        ":my_license",
        ":default_metadata_file",
    ]`,
						"default_visibility": `["//visibility:public"]`,
					},
					android.HostAndDeviceDefault,
				},
				{
					"android_license",
					"my_license",
					AttrNameToString{
						"license_kinds": `["SPDX-license-identifier-Apache-2.0"]`,
						"license_text":  `"NOTICE"`,
						"visibility":    `[":__subpackages__"]`,
					},
					android.HostAndDeviceDefault,
				},
				{
					"filegroup",
					"default_metadata_file",
					AttrNameToString{
						"applicable_licenses": `[]`,
						"srcs":                `["METADATA"]`,
					},
					android.HostAndDeviceDefault,
				},
			},
		},
	}
	for _, test := range tests {
		expected := make([]string, 0, len(test.expected))
@@ -80,6 +133,7 @@ package {
				ModuleTypeUnderTestFactory: android.PackageFactory,
				Blueprint:                  test.modules,
				ExpectedBazelTargets:       expected,
				Filesystem:                 test.fs,
			})
	}
}
+9 −0
Original line number Diff line number Diff line
@@ -87,6 +87,8 @@ func NewSourceFinder(ctx Context, config Config) (f *finder.Finder) {
			"TEST_MAPPING",
			// Bazel top-level file to mark a directory as a Bazel workspace.
			"WORKSPACE",
			// METADATA file of packages
			"METADATA",
		},
		// Bazel Starlark configuration files and all .mk files for product/board configuration.
		IncludeSuffixes: []string{".bzl", ".mk"},
@@ -189,6 +191,13 @@ func FindSources(ctx Context, config Config, f *finder.Finder) {
		ctx.Fatalf("Could not find OWNERS: %v", err)
	}

	// Recursively look for all METADATA files.
	metadataFiles := f.FindNamedAt(".", "METADATA")
	err = dumpListToFile(ctx, config, metadataFiles, filepath.Join(dumpDir, "METADATA.list"))
	if err != nil {
		ctx.Fatalf("Could not find METADATA: %v", err)
	}

	// Recursively look for all TEST_MAPPING files.
	testMappings := f.FindNamedAt(".", "TEST_MAPPING")
	err = dumpListToFile(ctx, config, testMappings, filepath.Join(dumpDir, "TEST_MAPPING.list"))
Loading