From 8f8558cc2c4e73534508878c7002e64bddcd7cd2 Mon Sep 17 00:00:00 2001 From: Markus Padourek Date: Wed, 29 May 2019 10:28:45 +0200 Subject: [PATCH] Remove node_runfiles. --- internal/node/generate_build_file.js | 79 ---------------------------- internal/node/node_repositories.bzl | 1 - 2 files changed, 80 deletions(-) diff --git a/internal/node/generate_build_file.js b/internal/node/generate_build_file.js index aea6746f00..b1e45b590c 100644 --- a/internal/node/generate_build_file.js +++ b/internal/node/generate_build_file.js @@ -24,7 +24,6 @@ const path = require('path'); const IS_WINDOWS = TEMPLATED_is_windows; const NODE_DIR = 'TEMPLATED_node_dir'; -const YARN_DIR = 'TEMPLATED_yarn_dir'; const NODE_ACTUAL = 'TEMPLATED_node_actual'; const NODE_BIN_ACTUAL = 'TEMPLATED_node_bin_actual'; const NPM_ACTUAL = 'TEMPLATED_npm_actual'; @@ -65,13 +64,6 @@ function main() { module.exports = { main }; function generateBuildFile() { - // *.pyc files are generated during node-gyp compilation and include - // absolute paths, making them non-hermetic. - // See https://github.com/bazelbuild/rules_nodejs/issues/347 - const excludedFiles = ['.md', '.html', '.pyc']; - const nodejsSrcFiles = filterFilesForFilegroup(listFiles(NODE_DIR), [], excludedFiles) - const yarnSrcFiles = filterFilesForFilegroup(listFiles(YARN_DIR), [], excludedFiles) - const binaryExt = IS_WINDOWS ? '.cmd' : ''; const buildFile = `# Generated by node_repositories.bzl package(default_visibility = ["//visibility:public"]) @@ -89,77 +81,6 @@ alias(name = "node_bin", actual = "${NODE_BIN_ACTUAL}") alias(name = "node", actual = "${NODE_ACTUAL}") alias(name = "npm", actual = "${NPM_ACTUAL}") alias(name = "yarn", actual = "${YARN_ACTUAL}") -filegroup( - name = "node_runfiles", - srcs = [ - ${nodejsSrcFiles.map(f => `"${NODE_DIR}/${f}",`).join('\n ')} - ${yarnSrcFiles.map(f => `"${YARN_DIR}/${f}",`).join('\n ')} - ], -) ` writeFileSync('BUILD.bazel', buildFile); } - -/** - * Returns an array of all the files under a directory as relative - * paths to the directory. - */ -function listFiles(rootDir, subDir = '') { - const dir = path.posix.join(rootDir, subDir); - if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory()) { - return []; - } - return fs - .readdirSync(dir) - .reduce((files, file) => { - const fullPath = path.posix.join(dir, file); - const relPath = path.posix.join(subDir, file); - let stat; - try { - stat = fs.statSync(fullPath); - } catch (e) { - throw e; - } - return stat.isDirectory() ? files.concat(listFiles(rootDir, relPath)) : - files.concat(relPath); - }, []); -} - -/** - * A filter function for a bazel filegroup. - * @param files array of files to filter - * @param allowedExts list of white listed extensions; if empty, no filter is done on extensions; - * '' empty string denotes to allow files with no extensions, other extensions - * are listed with '.ext' notation such as '.d.ts'. - */ -function filterFilesForFilegroup(files, allowedExts = [], excludedExts = []) { - // Files with spaces (\x20) or unicode characters (<\x20 && >\x7E) are not allowed in - // Bazel runfiles. See https://github.com/bazelbuild/bazel/issues/4327 - files = files.filter(f => !/[^\x21-\x7E]/.test(f)); - if (allowedExts.length) { - const allowNoExts = allowedExts.includes(''); - files = files.filter(f => { - // include files with no extensions if noExt is true - if (allowNoExts && !path.extname(f)) return true; - // filter files in allowedExts - for (const e of allowedExts) { - if (e && f.endsWith(e)) { - return true; - } - } - return false; - }) - } - if (excludedExts.length) { - files = files.filter(f => { - // filter out files in excludedExts - for (const e of excludedExts) { - if (e && f.endsWith(e)) { - return false; - } - } - return true; - }) - } - return files; -} diff --git a/internal/node/node_repositories.bzl b/internal/node/node_repositories.bzl index 4021d29f06..ef45253920 100644 --- a/internal/node/node_repositories.bzl +++ b/internal/node/node_repositories.bzl @@ -439,7 +439,6 @@ if %errorlevel% neq 0 exit /b %errorlevel% "TEMPLATED_node_dir": NODE_DIR, "TEMPLATED_npm_actual": npm_node_repositories_entry, "TEMPLATED_yarn_actual": yarn_node_repositories_entry, - "TEMPLATED_yarn_dir": YARN_DIR, }, ) result = repository_ctx.execute([node_entry, "generate_build_file.js"])