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

Commit 4eb6ad09 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Revert "Revert "Convert hardware/interfaces/compatibility_matric..."" into main

parents 6e26bafe b7995ac8
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ ignore_merged_commits = true
bpfmt = true
clang_format = true
aidl_format = true
gofmt = true

[Hook Scripts]
aosp_hook_confirmationui = ${REPO_ROOT}/frameworks/base/tools/aosp/aosp_sha.sh ${PREUPLOAD_COMMIT} confirmationui
+31 −0
Original line number Diff line number Diff line
@@ -93,6 +93,14 @@ vintf_compatibility_matrix {

}

// Device framework compatibility matrix (common to all FCM versions)
// Reference: https://source.android.com/docs/core/architecture/vintf/comp-matrices
vintf_compatibility_matrix {
    name: "framework_compatibility_matrix.device.xml",
    stem: "compatibility_matrix.device.xml",
    type: "device_fcm",
}

// Phony target that installs all system compatibility matrix files
SYSTEM_MATRIX_DEPS = [
    "framework_compatibility_matrix.5.xml",
@@ -114,3 +122,26 @@ phony {
        },
    },
}

// Product Compatibility Matrix
vintf_compatibility_matrix {
    name: "product_compatibility_matrix.xml",
    stem: "compatibility_matrix.xml",
    product_specific: true,
    type: "product_fcm",
}

// Phony target that installs all framework compatibility matrix files (system + product)
FRAMEWORK_MATRIX_DEPS = SYSTEM_MATRIX_DEPS + ["product_compatibility_matrix.xml"]

phony {
    name: "framework_compatibility_matrix.xml",
    required: FRAMEWORK_MATRIX_DEPS,
    product_variables: {
        release_aidl_use_unfrozen: {
            required: [
                "framework_compatibility_matrix.202504.xml",
            ],
        },
    },
}

compatibility_matrices/Android.mk

deleted100644 → 0
+0 −134
Original line number Diff line number Diff line
#
# Copyright (C) 2017 The Android Open Source Project
#
# 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.
#

LOCAL_PATH := $(call my-dir)

BUILD_FRAMEWORK_COMPATIBILITY_MATRIX := $(LOCAL_PATH)/compatibility_matrix.mk
my_empty_manifest := $(LOCAL_PATH)/manifest.empty.xml

# System Compatibility Matrix (common to all FCM versions)

include $(CLEAR_VARS)
include $(LOCAL_PATH)/clear_vars.mk
LOCAL_MODULE := framework_compatibility_matrix.device.xml
LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0
LOCAL_LICENSE_CONDITIONS := notice
LOCAL_NOTICE_FILE := $(LOCAL_PATH)/../NOTICE
LOCAL_MODULE_STEM := compatibility_matrix.device.xml
# define LOCAL_MODULE_CLASS for local-generated-sources-dir.
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_RELATIVE_PATH := vintf

ifndef DEVICE_FRAMEWORK_COMPATIBILITY_MATRIX_FILE
LOCAL_SRC_FILES := compatibility_matrix.empty.xml
else

# DEVICE_FRAMEWORK_COMPATIBILITY_MATRIX_FILE specifies absolute paths
LOCAL_GENERATED_SOURCES := $(DEVICE_FRAMEWORK_COMPATIBILITY_MATRIX_FILE)

# Enforce that DEVICE_FRAMEWORK_COMPATIBILITY_MATRIX_FILE does not specify required HALs
# by checking it against an empty manifest. But the empty manifest needs to contain
# BOARD_SEPOLICY_VERS to be compatible with DEVICE_FRAMEWORK_COMPATIBILITY_MATRIX_FILE.
my_gen_check_manifest := $(local-generated-sources-dir)/manifest.check.xml
$(my_gen_check_manifest): PRIVATE_SRC_FILE := $(my_empty_manifest)
$(my_gen_check_manifest): $(my_empty_manifest) $(HOST_OUT_EXECUTABLES)/assemble_vintf
	BOARD_SEPOLICY_VERS=$(BOARD_SEPOLICY_VERS) \
	VINTF_IGNORE_TARGET_FCM_VERSION=true \
		$(HOST_OUT_EXECUTABLES)/assemble_vintf -i $(PRIVATE_SRC_FILE) -o $@

LOCAL_GEN_FILE_DEPENDENCIES += $(my_gen_check_manifest)
LOCAL_ASSEMBLE_VINTF_FLAGS += -c "$(my_gen_check_manifest)"

my_gen_check_manifest :=

endif # DEVICE_FRAMEWORK_COMPATIBILITY_MATRIX_FILE

# TODO(b/296875906): use POLICYVERS from Soong
POLICYVERS ?= 30

LOCAL_ADD_VBMETA_VERSION := true
LOCAL_ASSEMBLE_VINTF_ENV_VARS := \
    POLICYVERS \
    PLATFORM_SEPOLICY_VERSION \
    PLATFORM_SEPOLICY_COMPAT_VERSIONS

include $(BUILD_FRAMEWORK_COMPATIBILITY_MATRIX)

# Product Compatibility Matrix

include $(CLEAR_VARS)
include $(LOCAL_PATH)/clear_vars.mk
LOCAL_MODULE := product_compatibility_matrix.xml
LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0
LOCAL_LICENSE_CONDITIONS := notice
LOCAL_NOTICE_FILE := $(LOCAL_PATH)/../NOTICE

ifndef DEVICE_PRODUCT_COMPATIBILITY_MATRIX_FILE
my_framework_matrix_deps :=
include $(BUILD_PHONY_PACKAGE)
else # DEVICE_PRODUCT_COMPATIBILITY_MATRIX_FILE

LOCAL_MODULE_STEM := compatibility_matrix.xml
LOCAL_PRODUCT_MODULE := true
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_RELATIVE_PATH := vintf

# DEVICE_PRODUCT_COMPATIBILITY_MATRIX_FILE specifies absolute paths
LOCAL_GENERATED_SOURCES := $(DEVICE_PRODUCT_COMPATIBILITY_MATRIX_FILE)

# Enforce that DEVICE_PRODUCT_COMPATIBILITY_MATRIX_FILE does not specify required HALs
# by checking it against an empty manifest.
LOCAL_GEN_FILE_DEPENDENCIES += $(my_empty_manifest)
LOCAL_ASSEMBLE_VINTF_FLAGS += -c "$(my_empty_manifest)"

my_framework_matrix_deps := $(LOCAL_MODULE)

include $(BUILD_FRAMEWORK_COMPATIBILITY_MATRIX)

endif # DEVICE_PRODUCT_COMPATIBILITY_MATRIX_FILE

my_system_matrix_deps := \
    framework_compatibility_matrix.5.xml \
    framework_compatibility_matrix.6.xml \
    framework_compatibility_matrix.7.xml \
    framework_compatibility_matrix.8.xml \
    framework_compatibility_matrix.202404.xml \
    framework_compatibility_matrix.device.xml \

# Only allow the use of the unreleased compatibility matrix when we can use unfrozen
# interfaces (in the `next` release configuration).
ifeq ($(RELEASE_AIDL_USE_UNFROZEN),true)
my_system_matrix_deps += \
    framework_compatibility_matrix.202504.xml \

endif

my_framework_matrix_deps += \
    $(my_system_matrix_deps)

# Phony target that installs all framework compatibility matrix files (system + product)
include $(CLEAR_VARS)
LOCAL_MODULE := framework_compatibility_matrix.xml
LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0
LOCAL_LICENSE_CONDITIONS := notice
LOCAL_NOTICE_FILE := $(LOCAL_PATH)/../NOTICE
LOCAL_REQUIRED_MODULES := $(my_framework_matrix_deps)
include $(BUILD_PHONY_PACKAGE)

my_system_matrix_deps :=
my_framework_matrix_deps :=
my_empty_manifest :=
BUILD_FRAMEWORK_COMPATIBILITY_MATRIX :=
+1 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ bootstrap_go_package {
        "kernel-config-soong-rules",
        "soong",
        "soong-android",
        "soong-selinux",
    ],
    srcs: [
        "vintf_compatibility_matrix.go",
+119 −6
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import (

	"android/soong/android"
	"android/soong/kernel/configs"
	"android/soong/selinux"
)

type dependencyTag struct {
@@ -35,10 +36,10 @@ var (
	pctx = android.NewPackageContext("android/vintf")

	assembleVintfRule = pctx.AndroidStaticRule("assemble_vintf", blueprint.RuleParams{
		Command:     `${assembleVintfCmd} -i ${inputs} -o ${out}`,
		CommandDeps: []string{"${assembleVintfCmd}"},
		Command:     `${assembleVintfEnv} ${assembleVintfCmd} -i ${inputs} -o ${out} ${extraArgs}`,
		CommandDeps: []string{"${assembleVintfCmd}", "${AvbToolCmd}"},
		Description: "assemble_vintf -i ${inputs}",
	}, "inputs")
	}, "inputs", "extraArgs", "assembleVintfEnv")

	xmllintXsd = pctx.AndroidStaticRule("xmllint-xsd", blueprint.RuleParams{
		Command:     `$XmlLintCmd --quiet --schema $xsd $in > /dev/null && touch -a $out`,
@@ -53,6 +54,10 @@ var (

const (
	relpath                  = "vintf"
	emptyManifest            = "hardware/interfaces/compatibility_matrices/manifest.empty.xml"
	compatibilityEmptyMatrix = "hardware/interfaces/compatibility_matrices/compatibility_matrix.empty.xml"
	deviceFcmType            = "device_fcm"
	productFcmType           = "product_fcm"
)

type vintfCompatibilityMatrixProperties struct {
@@ -64,6 +69,9 @@ type vintfCompatibilityMatrixProperties struct {

	// list of kernel_config modules to be combined to final output
	Kernel_configs []string

	// Type of the FCM type, the allowed type are device_fcm and product_fcm and it should only be used under hardware/interfaces/compatibility_matrices
	Type *string
}

type vintfCompatibilityMatrixRule struct {
@@ -72,11 +80,13 @@ type vintfCompatibilityMatrixRule struct {

	genFile                android.WritablePath
	additionalDependencies android.WritablePaths
	phonyOnly              bool
}

func init() {
	pctx.HostBinToolVariable("assembleVintfCmd", "assemble_vintf")
	pctx.HostBinToolVariable("XmlLintCmd", "xmllint")
	pctx.HostBinToolVariable("AvbToolCmd", "avbtool")
	android.RegisterModuleType("vintf_compatibility_matrix", vintfCompatibilityMatrixFactory)
}

@@ -131,6 +141,20 @@ func (g *vintfCompatibilityMatrixRule) getSchema(ctx android.ModuleContext) andr
}

func (g *vintfCompatibilityMatrixRule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
	// Types attribute only allow `device_fcm` or `product_fcm` if set and only restricted it being used under
	// `hardware/interfaces/compatibility_matrices` to prevent accidental external usages.
	matrixType := proptools.String(g.properties.Type)
	if matrixType != "" {
		if matrixType != deviceFcmType && matrixType != productFcmType {
			panic(fmt.Errorf("The attribute 'type' value must be either 'device_fcm' or 'product_fcm' if set!"))
		}
		if !strings.HasPrefix(android.PathForModuleSrc(ctx).String(), "hardware/interfaces/compatibility_matrices") {
			panic(fmt.Errorf("Attribute type can only be set for module under `hardware/interfaces/compatibility_matrices`!"))
		}
		if (len(g.properties.Srcs) + len(g.properties.Kernel_configs)) > 0 {
			panic(fmt.Errorf("Attribute 'type' and 'srcs' or 'kernel_configs' should not set simultaneously! To update inputs for this rule, edit vintf_compatibility_matrix.go directly."))
		}
	}

	outputFilename := proptools.String(g.properties.Stem)
	if outputFilename == "" {
@@ -158,15 +182,72 @@ func (g *vintfCompatibilityMatrixRule) GenerateAndroidBuildActions(ctx android.M
		}
	})

	// For product_compatibility_matrix.xml the source is from the product configuration
	// DEVICE_PRODUCT_COMPATIBILITY_MATRIX_FILE.
	extraArgs := []string{}
	if matrixType == productFcmType {
		productMatrixs := android.PathsForSource(ctx, ctx.Config().DeviceProductCompatibilityMatrixFile())
		if len(productMatrixs) > 0 {
			inputPaths = append(inputPaths, productMatrixs...)
			extraArgs = append(extraArgs, "-c", android.PathForSource(ctx, emptyManifest).String())
		} else {
			// For product_fcm, if DEVICE_PRODUCT_COMPATIBILITY_MATRIX_FILE not set, treat it as a phony target without any output generated.
			g.phonyOnly = true
			return
		}
	}

	// For framework_compatibility_matrix.device.xml the source may come from the product configuration
	// DEVICE_FRAMEWORK_COMPATIBILITY_MATRIX_FILE or use compatibilityEmptyMatrix if not set. We can't
	// use a phony target because we still need to install framework_compatibility_matrix.device.xml to
	// include sepolicy versions.
	frameworkRuleImplicits := []android.Path{}

	if matrixType == deviceFcmType {
		frameworkMatrixs := android.PathsForSource(ctx, ctx.Config().DeviceFrameworkCompatibilityMatrixFile())
		if len(frameworkMatrixs) > 0 {
			inputPaths = append(inputPaths, frameworkMatrixs...)

			// Generate BuildAction for generating the check manifest.
			emptyManifestPath := android.PathForSource(ctx, emptyManifest)
			genCheckManifest := android.PathForModuleGen(ctx, "manifest.check.xml")
			checkManifestInputs := []android.Path{emptyManifestPath}
			genCheckManifestEnvs := []string{
				"BOARD_SEPOLICY_VERS=" + ctx.DeviceConfig().BoardSepolicyVers(),
				"VINTF_IGNORE_TARGET_FCM_VERSION=true",
			}

			ctx.Build(pctx, android.BuildParams{
				Rule:        assembleVintfRule,
				Description: "Framework Check Manifest",
				Implicits:   checkManifestInputs,
				Output:      genCheckManifest,
				Args: map[string]string{
					"inputs":           android.PathForSource(ctx, emptyManifest).String(),
					"extraArgs":        "",
					"assembleVintfEnv": strings.Join(genCheckManifestEnvs, " "),
				},
			})

			frameworkRuleImplicits = append(frameworkRuleImplicits, genCheckManifest)
			extraArgs = append(extraArgs, "-c", genCheckManifest.String())
		} else {
			inputPaths = append(inputPaths, android.PathForSource(ctx, compatibilityEmptyMatrix))
		}
	}

	g.genFile = android.PathForModuleGen(ctx, outputFilename)
	frameworkRuleImplicits = append(frameworkRuleImplicits, inputPaths...)

	ctx.Build(pctx, android.BuildParams{
		Rule:        assembleVintfRule,
		Description: "Framework Compatibility Matrix",
		Implicits:   inputPaths,
		Implicits:   frameworkRuleImplicits,
		Output:      g.genFile,
		Args: map[string]string{
			"inputs":           strings.Join(inputPaths.Strings(), ":"),
			"extraArgs":        strings.Join(extraArgs, " "),
			"assembleVintfEnv": g.getAssembleVintfEnv(ctx),
		},
	})
	g.generateValidateBuildAction(ctx, g.genFile, schema.Path())
@@ -174,7 +255,39 @@ func (g *vintfCompatibilityMatrixRule) GenerateAndroidBuildActions(ctx android.M
	ctx.InstallFile(android.PathForModuleInstall(ctx, "etc", relpath), outputFilename, g.genFile)
}

func (g *vintfCompatibilityMatrixRule) getAssembleVintfEnv(ctx android.ModuleContext) string {
	if proptools.String(g.properties.Type) == deviceFcmType {
		assembleVintfEnvs := []string{
			// POLICYVERS defined in system/sepolicy/build/soong/policy.go
			fmt.Sprintf("POLICYVERS=%d", selinux.PolicyVers),
			fmt.Sprintf("PLATFORM_SEPOLICY_VERSION=%s", ctx.DeviceConfig().PlatformSepolicyVersion()),
			fmt.Sprintf("PLATFORM_SEPOLICY_COMPAT_VERSIONS=\"%s\"", strings.Join(ctx.DeviceConfig().PlatformSepolicyCompatVersions(), " ")),
		}

		if ctx.Config().BoardAvbEnable() {
			assembleVintfEnvs = append(assembleVintfEnvs, fmt.Sprintf("FRAMEWORK_VBMETA_VERSION=\"$$(${AvbToolCmd} add_hashtree_footer --print_required_libavb_version %s)\"", strings.Join(ctx.Config().BoardAvbSystemAddHashtreeFooterArgs(), " ")))
		} else {
			assembleVintfEnvs = append(assembleVintfEnvs, "FRAMEWORK_VBMETA_VERSION=\"0.0\"")
		}

		return strings.Join(assembleVintfEnvs, " ")
	}

	return ""
}

func (g *vintfCompatibilityMatrixRule) AndroidMk() android.AndroidMkData {
	if g.phonyOnly {
		return android.AndroidMkData{
			Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
				fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)", " # vintf.vintf_compatibility_matrix")
				fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
				fmt.Fprintln(w, "LOCAL_MODULE :=", name)
				fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
			},
		}
	}

	return android.AndroidMkData{
		Class:      "ETC",
		OutputFile: android.OptionalPathForPath(g.genFile),
Loading