Search code examples
androidandroid-soong

Compiler options in Andriod.bp files


everyone. I'm trying to convert a makefile to a .bp file for Android Q and i'm facing some issues.

1) I'm not sure how to define a release version. Previosly in makefile i would just write something along the lines of:

MY_RELEASE_VERSION := $(shell cd $(LOCAL_PATH); git describe --always
--dirty) DSW_VERSION= \"$(MY_RELEASE_VERSION)\" 

Which would be defined as a string like for example: DSW_VERSION="project_specific_3_0"

Now i am able to use a cppflag in .bp with the DSW_VERSION , but i found no way to make the value of it to be taken like in the makefile. Something like:

MY_RELEASE_VERSION = ["__builtin_func:shell cd <'LOCAL_PATH' unset>; git describe --always --dirty"]
CPPFLAGS = [
 "DSW_VERSION = "\"MY_RELEASE_VERSION"\",
]

Does not work.

Secondly i'm facing issues in defining a config variant, which in turn would devine a variable from the source code. Something like this in .mk files:

LOCAL_CPPFLAGS +=$(TARGET_CONFIG)

With a ifdefine in the code that looks like this:

#if defined (TARGET_ONE)
    static const VAR   = 1;
#elif defined (TARGET_TWO)
    static const VAR     = 2; 

i tried in .bp appendind to the cppflags, something like : cppflags: MY_CPPFLAGS + TARGET_CONFIG, where MY_CPPFLAGS is a variable defined with all the flags needed and it doesn't work

Anyone can help me with those?


Solution

  • You can use genrule to generate code at build time (e.g. a header file containing the repository version). Check out the Wayland Android.bp as an example on how a genrule looks like.

    To answer your second question: You can use cflags to add defines:

    <some-module> {
        [...]
        cflags: ["-DTARGET_CONFIG"],
    }