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

坚强是说给别人听的谎言 提交于 2020-03-25 16:57:07

问题


Considering the AOSP 7 build with Android.mk files:

How can I add built-time dependency between different LOCAL_MODULE, specifically build a target BEFORE an certain MODULE is built? I want to run a patch apply target, before the a system module is compiled.

My goal is to patch the WifiStateMachine.java from within the built process, because it currently does not support to dynamically disable RSSI polling.


回答1:


TL;DR: copy the Android.mk of the module you want to patch and add a patching rule as prerequisite for the source being targetet by the patch. Then use LOCAL_OVERRIDES_MODULE:=... to make your patched module override the old one. Make sure to add the name of the new module to your PRODUCT_PACKAGES, otherwise the overriding does not work.


The only way to make sure my target is patched before being built and patched only one was to copy the code from frameworks/opt/net/wifi/service/Android.mk of the wifi-service module and make my own Android.mk overriding the old one. The original Android.mk looks like this.

# 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

I added a new directory in my vendor/<target>, including the patch for the wifi state machine and the following Android.mk. The source being patched has a prerequisite on a stamp file, which is being built using the patch apply command. In this stamp file i add the commit hash of the module before the patch. This hash is used in the clean steps to properly reset the module to the original HEAD commit. The only variable I had to change because of the different location of the Android.mk is the arguments of 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


来源:https://stackoverflow.com/questions/60551915/android-aosp-7-build-module-before-other-patch-module-as-part-of-build-proc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!