Why can we not change Global Cflags anymore?

875 views
Skip to first unread message

Jimmy Xiao

unread,
Jan 15, 2016, 1:10:57 AM1/15/16
to Android Building
This commit is breaking a lot of my builds, and I want to know the reasoning for it? https://android.googlesource.com/platform/build/+/d443abf1aaa12c1b0fb82c940df60046c06aaed7

David Hacker

unread,
Jan 15, 2016, 5:36:27 PM1/15/16
to Android Building
Maybe if you look at the actual commit https://android.googlesource.com/platform/build/+/93b8a1294c0ce0cda18d64882e31325c14242320 instead of the merge commit it will be clearer.  If you change Global Cflags on a per device basis it requires rebuilding a lot of the common elements and host tools with each device you switch too, which increases build times.

Dan Willemsen

unread,
Jan 15, 2016, 5:36:28 PM1/15/16
to Android Building
Yes, I’ve been refactoring a lot of the *flag handling recently.

Device-specific BoardConfig.mk files never should have been setting COMMON_GLOBAL_CFLAGS in the first place - that affects host tools too, which are not supposed to change between devices. All cases that I found actually wanted to change TARGET_GLOBAL_CFLAGS, which was already restricted.

In general, we’d like to keep the core modules using the standard cflags, with the same compiled binary across devices. If devices want to configure a binary, either do it at runtime, or use explicit make variables supported by the specific module’s Android.mk file instead of global cflags that could affect everything.

In some cases, I found devices setting global cflags to configure a small number of device-specific libraries. In those cases, just setting a variable in BoardConfig.mk and checking it in the Android.mk to change the LOCAL_CFLAGS works fine.

For cases where the use is more widespread, in particular for vendor-specific code, that can be a complicated and error prone migration. Another option is to define a wrapper around BUILD_SHARED_LIBRARY / BUILD_STATIC_LIBRARY / BUILD_EXECUTABLE that can be used to add additional common settings for modules owned by you:

  vendor/<name>/build/core/definitions.mk:
    LOCAL_PATH := $(call my-dir)
    <name>_SHARED_LIBRARY := $(LOCAL_PATH)/shared_library.mk

  vendor/<name>/build/core/shared_library.mk:
    ifeq ($(MY_BOARDCONFIG_VAR),true)
      LOCAL_CFLAGS += -DMY_CONFIG
    endif
    include $(BUILD_SHARED_LIBRARY)

  vendor/<name>/src/Android.mk
    include $(CLEAR_VARS)
    LOCAL_MODULE := mycode
    LOCAL_SRC_FILES := ...
    ...
    include $(<name>_SHARED_LIBRARY)

It’s also possible to use all sorts of Make macros to accomplish the same thing, but the above is the simplest solution that I’ve seen.

If you are making changes to existing parts of AOSP, then you should be making local Android.mk changes to conditionally modify the LOCAL_CFLAGS along with the code changes to use them.

- Dan

On Thu, Jan 14, 2016 at 5:43 PM, Jimmy Xiao <xiao...@gmail.com> wrote:
This commit is breaking a lot of my builds, and I want to know the reasoning for it? https://android.googlesource.com/platform/build/+/d443abf1aaa12c1b0fb82c940df60046c06aaed7

--
--
You received this message because you are subscribed to the "Android Building" mailing list.
To post to this group, send email to android-...@googlegroups.com
To unsubscribe from this group, send email to
android-buildi...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-building?hl=en

---
You received this message because you are subscribed to the Google Groups "Android Building" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-buildi...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kira L

unread,
Jul 3, 2017, 10:51:00 PM7/3/17
to Android Building
I've to change MALLOC_IMPL := bimalloc to MALLOC_SVELTE := true in Boardconfig.mk
How can I add this without changing the COMMON_GLOBAL_C(PP)FLAGS
Reply all
Reply to author
Forward
0 new messages