diff --git a/ThirdPartyNotices.txt b/ThirdPartyNotices.txt index e75ca4afa4..0d29d577c5 100644 --- a/ThirdPartyNotices.txt +++ b/ThirdPartyNotices.txt @@ -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. diff --git a/cmake/modules/GenResources.cmake b/cmake/modules/GenResources.cmake new file mode 100644 index 0000000000..2b2386f4b0 --- /dev/null +++ b/cmake/modules/GenResources.cmake @@ -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() diff --git a/cmake/scripts/GenResource.cmake b/cmake/scripts/GenResource.cmake new file mode 100644 index 0000000000..d28e5648e3 --- /dev/null +++ b/cmake/scripts/GenResource.cmake @@ -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 \n#include \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(contents), ${fileSize});\n}\n") +IF(NOT namespace STREQUAL "") + FILE(APPEND "${output}" "}\n") +ENDIF() diff --git a/shared/resources.gradle b/shared/resources.gradle new file mode 100644 index 0000000000..21da736a5e --- /dev/null +++ b/shared/resources.gradle @@ -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 +#include +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(contents), ${fileBytes.size()}); +}""" + if (!namespace.isEmpty()) { + out.println '}' + } + } + } + } + } + return task +} diff --git a/wpiutil/.styleguide b/wpiutil/.styleguide index 04d87906f3..2c65222522 100644 --- a/wpiutil/.styleguide +++ b/wpiutil/.styleguide @@ -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 { diff --git a/wpiutil/CMakeLists.txt b/wpiutil/CMakeLists.txt index 94e177ec4e..ac18ebde64 100644 --- a/wpiutil/CMakeLists.txt +++ b/wpiutil/CMakeLists.txt @@ -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") diff --git a/wpiutil/build.gradle b/wpiutil/build.gradle index e987a90fff..4b950e996f 100644 --- a/wpiutil/build.gradle +++ b/wpiutil/build.gradle @@ -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' diff --git a/wpiutil/src/main/native/resources/bootstrap-4.1.min.js.gz b/wpiutil/src/main/native/resources/bootstrap-4.1.min.js.gz new file mode 100644 index 0000000000..a7797e1a79 Binary files /dev/null and b/wpiutil/src/main/native/resources/bootstrap-4.1.min.js.gz differ diff --git a/wpiutil/src/main/native/resources/coreui-2.1.min.css.gz b/wpiutil/src/main/native/resources/coreui-2.1.min.css.gz new file mode 100644 index 0000000000..d4f43add5e Binary files /dev/null and b/wpiutil/src/main/native/resources/coreui-2.1.min.css.gz differ diff --git a/wpiutil/src/main/native/resources/coreui-2.1.min.js.gz b/wpiutil/src/main/native/resources/coreui-2.1.min.js.gz new file mode 100644 index 0000000000..cf4ccb185e Binary files /dev/null and b/wpiutil/src/main/native/resources/coreui-2.1.min.js.gz differ diff --git a/wpiutil/src/main/native/resources/feather-4.8.min.js.gz b/wpiutil/src/main/native/resources/feather-4.8.min.js.gz new file mode 100644 index 0000000000..d275865b3e Binary files /dev/null and b/wpiutil/src/main/native/resources/feather-4.8.min.js.gz differ diff --git a/wpiutil/src/main/native/resources/jquery-3.3.slim.min.js.gz b/wpiutil/src/main/native/resources/jquery-3.3.slim.min.js.gz new file mode 100644 index 0000000000..712e06cbd1 Binary files /dev/null and b/wpiutil/src/main/native/resources/jquery-3.3.slim.min.js.gz differ diff --git a/wpiutil/src/main/native/resources/popper-1.14.min.js.gz b/wpiutil/src/main/native/resources/popper-1.14.min.js.gz new file mode 100644 index 0000000000..c6ebec8ddd Binary files /dev/null and b/wpiutil/src/main/native/resources/popper-1.14.min.js.gz differ diff --git a/wpiutil/src/main/native/resources/wpilib-128.png b/wpiutil/src/main/native/resources/wpilib-128.png new file mode 100644 index 0000000000..0169c0dc83 Binary files /dev/null and b/wpiutil/src/main/native/resources/wpilib-128.png differ