How to copy specific headers in Soong

653 views Asked by At

How can I extract specific files in Soong to use as headers?

I was recently writing a blueprint (Android.bp) file for paho-mqtt-c. My consumers require MQTTClient.h which paho-mqtt-c stores in src/ - what I would consider a "private" location. Reading their CMakeLists.txt file, it actually installs this and some other headers to include/.

As far as I can tell, Soong doesn't have this concept of installing so it seems like I could export_include_dirs the src directory - which seems wrong, or use a cc_genrule to copy these headers elsewhere.

But that's where I hit another issue: I can't seem to figure out how to create a cc_genrule that takes n inputs and writes n outputs (n-to-n). i.e.

cc_genrule {
   name: "paho_public_headers",
   cmd: "cp $(in) $(out)",

   srcs: [ "src/MQTTAsync.h",    "src/MQTTClient.h",    "src/MQTTClientPersistence.h",   "src/MQTTLogLevels.h" ]
   out:  [ "public/MQTTAsync.h", "public/MQTTClient.h", "public/MQTTClientPersistence.h", "public/MQTTLogLevels.h" ],
}

results in the failed command cp <all-inputs> <all-outputs>, rather than what I wanted which would be closer to iterating the command over each input/output pairs.

My solution was simply to write four cc_genrules, but that doesn't seem great either.

Is there a better way? (ideally without writing a custom tool)

1

There are 1 answers

0
Matt On

The solution was to use gensrcs with a shard_size of 1.

For example:

gensrcs {
    name: "paho_public_headers",
    cmd: "mkdir -p $(genDir) && cat $(in) > $(out)",
    srcs: [":paho_mqtt_c_header_files"],
    output_extension: "h",
    shard_size: 1,
    export_include_dirs: ["src"],
}

The export_include_dirs is important, as with gensrcs there is little control over the output filename other than the extension, so it's easiest to keep the directory structure $(in) on the $(out) files.