Skip to content

Commit

Permalink
cmake: remove xxd dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
tsl0922 committed Feb 2, 2020
1 parent 9f8e94d commit 0e728e6
Show file tree
Hide file tree
Showing 8 changed files with 34,061 additions and 12 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,4 @@ build
.idea/

# Project files
html.h
!init.d
7 changes: 0 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,6 @@ find_library(LIBUV_LIBRARIES NAMES uv libuv HINTS ${PC_LIBUV_LIBDIR})
find_package_handle_standard_args(LIBUV DEFAULT_MSG LIBUV_LIBRARIES LIBUV_INCLUDE_DIRS)
mark_as_advanced(LIBUV_INCLUDE_DIRS LIBUV_LIBRARIES)

find_program(CMAKE_XXD NAMES xxd)
add_custom_command(OUTPUT html.h
COMMAND ${CMAKE_XXD} -i index.html html.h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src
COMMENT "Generating html.h from index.html")
list(APPEND SOURCE_FILES html.h)

set(INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR} ${LIBWEBSOCKETS_INCLUDE_DIRS} ${JSON-C_INCLUDE_DIRS} ${LIBUV_INCLUDE_DIRS})
set(LINK_LIBS ${OPENSSL_LIBRARIES} ${LIBWEBSOCKETS_LIBRARIES} ${JSON-C_LIBRARIES} ${LIBUV_LIBRARIES})

Expand Down
2 changes: 1 addition & 1 deletion html/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ install [Yarn](https://yarnpkg.com), and run: `yarn install`.

## Publish

Run `yarn run build`, this will compile the inlined html to `../src/index.html`.
Run `yarn run build`, this will compile the inlined html to `../src/html.h`.
39 changes: 37 additions & 2 deletions html/gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,39 @@
const { src, dest, task } = require("gulp");
const clean = require('gulp-clean');
const inlinesource = require('gulp-inline-source');
const inlineSource = require('gulp-inline-source');
const rename = require("gulp-rename");
const through = require('through2');

const toCHeader = () => {
return through.obj((file, enc, cb) => {
const buf = file.contents;
const len = buf.length;
let idx = 0;
let data = "unsigned char index_html[] = {\n ";

for (const value of buf) {
idx++;

let current = value < 0 ? value + 256 : value;

data += "0x";
data += (current >>> 4).toString(16);
data += (current & 0xF).toString(16);

if (idx === len) {
data += "\n";
} else {
data += idx % 12 === 0 ? ",\n " : ", ";
}
}

data += "};\n";
data += `unsigned int index_html_len = ${len};\n`;
file.contents = Buffer.from(data);

return cb(null, file);
});
};

task('clean', () => {
return src('dist', {read: false, allowEmpty: true})
Expand All @@ -9,6 +42,8 @@ task('clean', () => {

task('default', () => {
return src('dist/index.html')
.pipe(inlinesource())
.pipe(inlineSource())
.pipe(toCHeader())
.pipe(rename("html.h"))
.pipe(dest('../src/'));
});
2 changes: 2 additions & 0 deletions html/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"gulp": "^4.0.2",
"gulp-clean": "^0.4.0",
"gulp-inline-source": "^4.0.0",
"gulp-rename": "^2.0.0",
"html-webpack-plugin": "^3.2.0",
"husky": "^4.0.6",
"lint-staged": "^10.0.3",
Expand All @@ -48,6 +49,7 @@
"scssfmt": "^1.0.7",
"style-loader": "^1.0.1",
"terser-webpack-plugin": "^2.2.2",
"through2": "^3.0.1",
"ts-loader": "^6.2.1",
"tslint": "^5.20.1",
"tslint-loader": "^3.5.4",
Expand Down
21 changes: 21 additions & 0 deletions html/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3291,6 +3291,11 @@ gulp-inline-source@^4.0.0:
plugin-error "~1.0.1"
through2 "~2.0.0"

gulp-rename@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/gulp-rename/-/gulp-rename-2.0.0.tgz#9bbc3962b0c0f52fc67cd5eaff6c223ec5b9cf6c"
integrity sha512-97Vba4KBzbYmR5VBs9mWmK+HwIf5mj+/zioxfZhOKeXtx5ZjBk57KFlePf5nxq9QsTtFl0ejnHE3zTC9MHXqyQ==

gulp@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/gulp/-/gulp-4.0.2.tgz#543651070fd0f6ab0a0650c6a3e6ff5a7cb09caa"
Expand Down Expand Up @@ -6502,6 +6507,15 @@ read-pkg@^3.0.0:
string_decoder "~1.1.1"
util-deprecate "~1.0.1"

"readable-stream@2 || 3":
version "3.5.0"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.5.0.tgz#465d70e6d1087f6162d079cd0b5db7fbebfd1606"
integrity sha512-gSz026xs2LfxBPudDuI41V1lka8cxg64E66SGe78zJlsUofOg/yqwezdIcdfwik6B4h8LFmWPA9ef9X3FiNFLA==
dependencies:
inherits "^2.0.3"
string_decoder "^1.1.1"
util-deprecate "^1.0.1"

readable-stream@^3.0.6, readable-stream@^3.1.1, readable-stream@^3.4.0:
version "3.4.0"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.4.0.tgz#a51c26754658e0a3c21dbf59163bd45ba6f447fc"
Expand Down Expand Up @@ -7730,6 +7744,13 @@ through2@^2.0.0, through2@^2.0.3, through2@~2.0.0:
readable-stream "~2.3.6"
xtend "~4.0.1"

through2@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/through2/-/through2-3.0.1.tgz#39276e713c3302edf9e388dd9c812dd3b825bd5a"
integrity sha512-M96dvTalPT3YbYLaKaCuwu+j06D/8Jfib0o/PxbVt6Amhv3dUAtW6rTV1jPgJSBG83I/e04Y6xkVdVhSRhi0ww==
dependencies:
readable-stream "2 || 3"

through@^2.3.6:
version "2.3.8"
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"
Expand Down
Loading

0 comments on commit 0e728e6

Please sign in to comment.