mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
- Twine, StringRef, Format, and NativeFormatting have been removed - Logging now uses fmtlib style formatting - Nearly all uses of wpi::outs/errs have been replaced with fmt::print() or std::puts()/std::fputs() (for unformatted strings). - A wpi/fmt/raw_ostream.h header has been added to enable fmt::print() with wpi::raw_ostream
51 lines
1.8 KiB
Groovy
51 lines
1.8 KiB
Groovy
ext.createGenerateResourcesTask = { name, prefix, namespace, project ->
|
|
def generatedOutputDir = file("$buildDir/generated/$name/cpp")
|
|
|
|
def inputDir = file("$projectDir/src/$name/native/resources")
|
|
|
|
if (!prefix.isEmpty()) prefix += '_'
|
|
|
|
def task = project.tasks.create("generateResources-$name") {
|
|
outputs.dir generatedOutputDir
|
|
inputs.dir inputDir
|
|
|
|
doLast {
|
|
generatedOutputDir.mkdirs()
|
|
inputDir.eachFile { inputFile ->
|
|
if (inputFile.name.startsWith('.')) return
|
|
def fileBytes = inputFile.bytes
|
|
def outputFile = file("$generatedOutputDir/${inputFile.name}.cpp")
|
|
def funcName = "GetResource_" + inputFile.name.replaceAll('[^a-zA-Z0-9]', '_')
|
|
outputFile.withWriter { out ->
|
|
def inputBytes = inputFile.bytes
|
|
out.print '''#include <stddef.h>
|
|
#include <string_view>
|
|
extern "C" {
|
|
static const unsigned char contents[] = { '''
|
|
|
|
for (int i = 0; i < fileBytes.size(); i++) {
|
|
out.print String.format('0x%02x', (int) fileBytes[i] & 0xff)
|
|
out.print ', '
|
|
}
|
|
out.println """};
|
|
const unsigned char* ${prefix}${funcName}(size_t* len) {
|
|
*len = ${fileBytes.size()};
|
|
return contents;
|
|
}
|
|
}"""
|
|
if (!namespace.isEmpty()) {
|
|
out.println "namespace ${namespace} {"
|
|
}
|
|
out.println """std::string_view ${funcName}() {
|
|
return std::string_view(reinterpret_cast<const char*>(contents), ${fileBytes.size()});
|
|
}"""
|
|
if (!namespace.isEmpty()) {
|
|
out.println '}'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return task
|
|
}
|