diff --git a/deps/download.js b/deps/download.js index 139a5bf..d4ab46f 100644 --- a/deps/download.js +++ b/deps/download.js @@ -12,22 +12,26 @@ const EXTENSION_VERSION = '0.2.1-asm2'; const TAG = [SQLCIPHER_VERSION, EXTENSION_VERSION].join('--'); const URL = `${BASE_URI}/sqlcipher-v2-${TAG}-${HASH}.tar.gz`; -const tmpFile = path.join(__dirname, 'unverified.tmp'); -const finalFile = path.join(__dirname, 'sqlcipher.tar.gz'); +const buildFile = process.argv[2]; +const targetFile = path.join(__dirname, 'sqlcipher.tar.gz'); +const tmpFile = `${targetFile}.tmp`; async function main() { - if (fs.statSync(finalFile, { throwIfNoEntry: false })) { + if (fs.statSync(targetFile, { throwIfNoEntry: false })) { const hash = crypto.createHash('sha256'); const existingHash = await pipeline( - fs.createReadStream(finalFile), + fs.createReadStream(targetFile), hash, ); if (hash.digest('hex') === HASH) { console.log('local build artifact is up-to-date'); + fs.copyFileSync(targetFile, buildFile); return; } console.log('local build artifact is outdated'); + } else { + console.log('local build artifact is absent'); } download(); } @@ -54,8 +58,9 @@ function download() { throw new Error(`Digest mismatch. Expected ${HASH} got ${actualDigest}`); } - fs.renameSync(tmpFile, finalFile); - }) + fs.renameSync(tmpFile, targetFile); + fs.copyFileSync(targetFile, buildFile); + }); } main(); diff --git a/deps/extract.js b/deps/extract.js index 5655fd6..8f3fcf2 100644 --- a/deps/extract.js +++ b/deps/extract.js @@ -2,8 +2,8 @@ const path = require('path'); const tar = require('tar'); -const dest = process.argv[2]; -const source = path.join(__dirname, 'sqlcipher.tar.gz'); +const source = process.argv[2]; +const dest = process.argv[3]; process.on('unhandledRejection', (err) => { throw err; }); diff --git a/deps/sqlite3.gyp b/deps/sqlite3.gyp index e40c36e..61507eb 100755 --- a/deps/sqlite3.gyp +++ b/deps/sqlite3.gyp @@ -8,13 +8,26 @@ { 'includes': ['common.gypi'], 'targets': [ + { + 'target_name': 'download_sqlite3', + 'type': 'none', + 'hard_dependency': 1, + 'actions': [{ + 'action_name': 'download_sqlite3', + 'inputs': ['download.js'], + 'outputs': [ + '<(SHARED_INTERMEDIATE_DIR)/sqlcipher.tar.gz' + ], + 'action': ['node', 'download.js', '<(SHARED_INTERMEDIATE_DIR)/sqlcipher.tar.gz'], + }], + }, { 'target_name': 'locate_sqlite3', 'type': 'none', 'hard_dependency': 1, 'actions': [{ 'action_name': 'extract_sqlite3', - 'inputs': ['sqlcipher.tar.gz'], + 'inputs': ['<(SHARED_INTERMEDIATE_DIR)/sqlcipher.tar.gz'], 'outputs': [ '<(SHARED_INTERMEDIATE_DIR)/sqlite3/sqlite3.c', '<(SHARED_INTERMEDIATE_DIR)/sqlite3/sqlite3.h', @@ -27,7 +40,7 @@ ], }], ], - 'action': ['node', 'extract.js', '<(SHARED_INTERMEDIATE_DIR)/sqlite3'], + 'action': ['node', 'extract.js', '<(SHARED_INTERMEDIATE_DIR)/sqlcipher.tar.gz', '<(SHARED_INTERMEDIATE_DIR)/sqlite3'], }], }, { diff --git a/package.json b/package.json index 8e5dacc..1b24f75 100644 --- a/package.json +++ b/package.json @@ -28,19 +28,14 @@ "cli-color": "^2.0.2", "fs-extra": "^10.1.0", "mocha": "^8.3.2", - "node-gyp": "^9.1.0", "nodemark": "^0.3.0", "sqlite": "^4.0.23", "sqlite3": "^5.0.2" }, "scripts": { "format": "xcrun clang-format --style=chromium -Werror --verbose -i src/*.cpp src/*.hpp", - "install": "npm run download && npm run build-release", - "build-release": "node-gyp rebuild --release", - "build-debug": "node-gyp rebuild --debug", "test": "mocha --exit --slow=75 --timeout=5000", - "benchmark": "node benchmark", - "download": "node ./deps/download.js" + "benchmark": "node benchmark" }, "license": "MIT", "keywords": [