简体   繁体   中英

How to copy specific headers in Soong

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 ). ie

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_genrule s, but that doesn't seem great either.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM