Android (AOSP) 7: 在其他模块之前构建模块/补丁模块作为构建过程的一部分/修改系统源

Android (AOSP) 7: Build module before other / Patch module as part of build process / Modify system sources

考虑使用 Android.mk 个文件构建 AOSP 7:

如何在不同 LOCAL_MODULE 之间添加构建时依赖性,特别是在构建某个模块之前构建目标?我想 运行 一个补丁应用目标,然后再编译一个系统模块。

我的目标是从构建过程中修补 WifiStateMachine.java,因为它目前不支持动态禁用 RSSI 轮询。

TL;DR: 复制要修补的模块的 Android.mk 并添加修补规则作为修补程序目标源的先决条件。然后使用 LOCAL_OVERRIDES_MODULE:=... 让你的补丁模块覆盖旧的。确保将新模块的名称添加到您的 PRODUCT_PACKAGES,否则覆盖将不起作用。


确保我的目标在构建之前被修补并且只修补一个的唯一方法是从 wifi-service 模块的 frameworks/opt/net/wifi/service/Android.mk 复制代码并制作我自己的 Android.mk覆盖旧的。 原来的Android.mk是这样的

# Copyright (C) 2011 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)

ifneq ($(TARGET_BUILD_PDK), true)

...

# Build the java code
# ============================================================

include $(CLEAR_VARS)

LOCAL_AIDL_INCLUDES := $(LOCAL_PATH)/java
LOCAL_SRC_FILES := $(call all-java-files-under, java) \
    $(call all-Iaidl-files-under, java) \
    $(call all-logtags-files-under, java) \
    $(call all-proto-files-under, proto)

ifndef INCLUDE_NAN_FEATURE
LOCAL_SRC_FILES := $(filter-out $(call all-java-files-under, \
          java/com/android/server/wifi/nan),$(LOCAL_SRC_FILES))
endif

LOCAL_JAVA_LIBRARIES := bouncycastle conscrypt services
LOCAL_REQUIRED_MODULES := services
LOCAL_MODULE_TAGS :=
LOCAL_MODULE := wifi-service
LOCAL_PROTOC_OPTIMIZE_TYPE := nano

ifeq ($(EMMA_INSTRUMENT_FRAMEWORK),true)
LOCAL_EMMA_INSTRUMENT := true
endif

LOCAL_JACK_COVERAGE_INCLUDE_FILTER := com.android.server.wifi.*

include $(BUILD_JAVA_LIBRARY)

endif

我在我的 vendor/<target> 中添加了一个新目录,包括 wifi 状态机的补丁和以下 Android.mk。正在修补的源有一个戳记文件的先决条件,该文件是使用补丁应用命令构建的。在这个 stamp 文件中,我在补丁之前添加了模块的提交哈希。此哈希用于清理步骤,以将模块正确重置为原始 HEAD 提交。由于 Android.mk 的不同位置,我必须更改的唯一变量是 protoc 的参数。

# Copyright (C) 2011 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.

THIS_LOCAL_PATH := $(realpath $(call my-dir))
LOCAL_PATH := $(ANDROID_BUILD_TOP)/frameworks/opt/net/wifi/service

# Partwise taken from frameworks/opt/net/wifi/service/Android.mk
# ============================================================

ifneq ($(TARGET_BUILD_PDK), true)

include $(CLEAR_VARS)

PATCHED_STAMP_FILE := $(ANDROID_HOST_OUT)/.wsm_patched.stamp
TO_BE_PATCHED_DIR := $(ANDROID_BUILD_TOP)/frameworks/opt/net/wifi
CHECK_IF_PATCHED_FILE := $(LOCAL_PATH)/java/com/android/server/wifi/WifiStateMachine.java
PREVIOUS_HASH := $(shell grep -hs ^ $(PATCHED_STAMP_FILE))

LOCAL_AIDL_INCLUDES := $(LOCAL_PATH)/java
LOCAL_SRC_FILES := $(call all-java-files-under, java) \
    $(call all-Iaidl-files-under, java) \
    $(call all-logtags-files-under, java) \
    $(call all-proto-files-under, proto) \
    $(PATCHED_STAMP_FILE)

$(PATCHED_STAMP_FILE): $(CHECK_IF_PATCHED_FILE)

$(CHECK_IF_PATCHED_FILE):
    git -C $(TO_BE_PATCHED_DIR) rev-parse HEAD > $(PATCHED_STAMP_FILE)
    git -C $(TO_BE_PATCHED_DIR) am $(THIS_LOCAL_PATH)/wifiStateMachine.patch

ifndef INCLUDE_NAN_FEATURE
LOCAL_SRC_FILES := $(filter-out $(call all-java-files-under, \
    java/com/android/server/wifi/nan),$(LOCAL_SRC_FILES))
endif

ifdef PREVIOUS_HASH
$(call add-clean-step, git -C $(TO_BE_PATCHED_DIR) reset --hard $(PREVIOUS_HASH))
$(call add-clean-step, rm $(PATCHED_STAMP_FILE))
endif

LOCAL_JAVA_LIBRARIES := bouncycastle conscrypt services
LOCAL_REQUIRED_MODULES := services
LOCAL_MODULE_TAGS :=
LOCAL_MODULE := wifi-service-anbox
LOCAL_OVERRIDES_MODULE := wifi-service
LOCAL_PROTOC_OPTIMIZE_TYPE := nano

# Protoc uses proto_path=., but wifi.proto is not here
LOCAL_PROTOC_FLAGS := --proto_path=$(LOCAL_PATH)

ifeq ($(EMMA_INSTRUMENT_FRAMEWORK),true)
LOCAL_EMMA_INSTRUMENT := true
endif

LOCAL_JACK_COVERAGE_INCLUDE_FILTER := com.android.server.wifi.*

include $(BUILD_JAVA_LIBRARY)

endif