wpiutil: Add shared resources for http servers

Files are named only with major.minor versions.  Full versions are:
* bootstrap 4.1.3
* coreui 2.1.8
* feather 4.8.0
* jquery 3.3.1
* popper 1.14.4
This commit is contained in:
Peter Johnson
2018-11-18 18:35:03 -08:00
parent 0fb24538a7
commit e0e15eafeb
14 changed files with 245 additions and 1 deletions

View File

@@ -33,6 +33,11 @@ tcpsockets wpiutil/src/main/native/cpp/TCP{Stream,Connector,Acceptor}
wpiutil/src/main/native/include/wpi/TCP*.h
Optional wpiutil/src/main/native/include/wpi/optional.h
wpiutil/src/test/native/cpp/test_optional.cpp
Bootstrap wpiutil/src/main/native/resources/bootstrap-*
CoreUI wpiutil/src/main/native/resources/coreui-*
Feather Icons wpiutil/src/main/native/resources/feather-*
jQuery wpiutil/src/main/native/resources/jquery-*
popper.js wpiutil/src/main/native/resources/popper-*
==============================================================================
@@ -244,3 +249,125 @@ SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
==============================================================================
Bootstrap License
==============================================================================
Copyright (c) 2011-2018 Twitter, Inc.
Copyright (c) 2011-2018 The Bootstrap Authors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
==============================================================================
CoreUI License
==============================================================================
Copyright (c) 2018 creativeLabs Łukasz Holeczek.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
==============================================================================
Feather Icons License
==============================================================================
Copyright (c) 2013-2017 Cole Bemis
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
==============================================================================
jQuery License
==============================================================================
Copyright JS Foundation and other contributors, https://js.foundation/
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
==============================================================================
popper.js License
==============================================================================
Copyright (c) 2016 Federico Zivolo and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the “Software”), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,25 @@
MACRO(GENERATE_RESOURCES inputDir outputDir prefix namespace outputFiles)
FILE(GLOB inputFiles ${inputDir}/*)
SET(${outputFiles})
FOREACH(input ${inputFiles})
GET_FILENAME_COMPONENT(inputBase ${input} NAME)
IF("${inputBase}" MATCHES "^\\.")
CONTINUE()
ENDIF()
SET(output "${outputDir}/${inputBase}.cpp")
LIST(APPEND ${outputFiles} "${output}")
ADD_CUSTOM_COMMAND(
OUTPUT ${output}
COMMAND ${CMAKE_COMMAND}
"-Dinput=${input}"
"-Doutput=${output}"
"-Dprefix=${prefix}"
"-Dnamespace=${namespace}"
-P "${CMAKE_SOURCE_DIR}/cmake/scripts/GenResource.cmake"
MAIN_DEPENDENCY ${input}
DEPENDS ${CMAKE_SOURCE_DIR}/cmake/scripts/GenResource.cmake
VERBATIM
)
ENDFOREACH()
ENDMACRO()

View File

@@ -0,0 +1,23 @@
# Parameters: input output prefix namespace
FILE(READ ${input} fileHex HEX)
STRING(LENGTH "${fileHex}" fileHexSize)
MATH(EXPR fileSize "${fileHexSize} / 2")
GET_FILENAME_COMPONENT(inputBase ${input} NAME)
STRING(REGEX REPLACE "[^a-zA-Z0-9]" "_" funcName "${inputBase}")
SET(funcName "GetResource_${funcName}")
FILE(WRITE "${output}" "#include <stddef.h>\n#include <wpi/StringRef.h>\nextern \"C\" {\nstatic const unsigned char contents[] = {")
STRING(REGEX MATCHALL ".." outputData "${fileHex}")
STRING(REGEX REPLACE ";" ", 0x" outputData "${outputData}")
FILE(APPEND "${output}" " 0x${outputData} };\n")
FILE(APPEND "${output}" "const unsigned char* ${prefix}${funcName}(size_t* len) {\n *len = ${fileSize};\n return contents;\n}\n}\n")
IF(NOT namespace STREQUAL "")
FILE(APPEND "${output}" "namespace ${namespace} {\n")
ENDIF()
FILE(APPEND "${output}" "wpi::StringRef ${funcName}() {\n return wpi::StringRef(reinterpret_cast<const char*>(contents), ${fileSize});\n}\n")
IF(NOT namespace STREQUAL "")
FILE(APPEND "${output}" "}\n")
ENDIF()

50
shared/resources.gradle Normal file
View File

@@ -0,0 +1,50 @@
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 <wpi/StringRef.h>
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 """wpi::StringRef ${funcName}() {
return wpi::StringRef(reinterpret_cast<const char*>(contents), ${fileBytes.size()});
}"""
if (!namespace.isEmpty()) {
out.println '}'
}
}
}
}
}
return task
}

View File

@@ -53,6 +53,7 @@ generatedFileExclude {
src/main/native/libuv/
src/main/native/include/wpi/optional\.h$
src/test/native/cpp/test_optional\.cpp$
src/main/native/resources/
}
licenseUpdateExclude {

View File

@@ -1,6 +1,7 @@
project(wpiutil)
include(SubDirList)
include(GenResources)
# Java bindings
if (NOT WITHOUT_JAVA)
@@ -23,6 +24,8 @@ endif()
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
GENERATE_RESOURCES(src/main/native/resources generated/main/cpp WPI wpi wpiutil_resources_src)
file(GLOB_RECURSE wpiutil_native_src src/main/native/cpp/*.cpp)
file(GLOB uv_native_src src/main/native/libuv/*.cpp)
@@ -69,7 +72,7 @@ set(uv_linux_src
src/main/native/libuv/unix/sysinfo-memory.cpp
)
add_library(wpiutil ${wpiutil_native_src} ${uv_native_src})
add_library(wpiutil ${wpiutil_native_src} ${uv_native_src} ${wpiutil_resources_src})
set_target_properties(wpiutil PROPERTIES DEBUG_POSTFIX "d")
set_property(TARGET wpiutil PROPERTY FOLDER "libraries")

View File

@@ -1,7 +1,13 @@
apply from: "${rootDir}/shared/resources.gradle"
ext {
nativeName = 'wpiutil'
devMain = 'edu.wpi.first.wpiutil.DevMain'
def generateTask = createGenerateResourcesTask('main', 'WPI', 'wpi', project)
extraSetup = {
it.tasks.withType(CppCompile) {
dependsOn generateTask
}
it.sources {
libuvCpp(CppSourceSet) {
source {
@@ -12,6 +18,15 @@ ext {
srcDirs 'src/main/native/include', 'src/main/native/include/uv-private', 'src/main/native/libuv'
}
}
resourcesCpp(CppSourceSet) {
source {
srcDirs "$buildDir/generated/main/cpp"
include '*.cpp'
}
exportedHeaders {
srcDirs 'src/main/native/include'
}
}
}
if (it.targetPlatform.operatingSystem.name != 'windows') {
it.cppCompiler.define '_GNU_SOURCE'

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB