-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into xlr-entries
- Loading branch information
Showing
19 changed files
with
24,700 additions
and
638 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
load("@bazel_skylib//:bzl_library.bzl", "bzl_library") | ||
load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_missing_pkgs", "bzlformat_pkg") | ||
|
||
bzlformat_pkg(name = "bzlformat") | ||
|
||
bzlformat_missing_pkgs(name = "bzlformat_missing_pkgs") | ||
|
||
bzl_library( | ||
name = "defs", | ||
srcs = ["defs.bzl"], | ||
visibility = ["//visibility:public"], | ||
deps = [], | ||
) | ||
|
||
exports_files(["defs.bzl"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
""" | ||
Public API for JavaScript based project rules | ||
""" | ||
|
||
load("//distribution/tar/private:stamp_tar_files.bzl", _stamp_tar_files = "stamp_tar_files") | ||
|
||
stamp_tar_files = _stamp_tar_files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
load("@aspect_rules_js//js:defs.bzl", "js_binary") | ||
load("@bazel_skylib//:bzl_library.bzl", "bzl_library") | ||
load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_missing_pkgs", "bzlformat_pkg") | ||
|
||
bzlformat_pkg(name = "bzlformat") | ||
|
||
bzlformat_missing_pkgs(name = "bzlformat_missing_pkgs") | ||
|
||
bzl_library( | ||
name = "stamp_tar_files", | ||
srcs = ["stamp_tar_files.bzl"], | ||
visibility = [ | ||
"//distribution:__subpackages__", | ||
], | ||
) | ||
|
||
js_binary( | ||
name = "stamp_tar_files_script", | ||
entry_point = "stamp_tar_files.mjs", | ||
visibility = ["//visibility:public"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
""" | ||
Module for stamping a tar.gz file and repackaging it | ||
""" | ||
|
||
load("@aspect_bazel_lib//lib:stamping.bzl", "STAMP_ATTRS", "maybe_stamp") | ||
load("@bazel_skylib//lib:paths.bzl", "paths") | ||
|
||
_STAMP_TAR_FILES = Label("//distribution/tar/private:stamp_tar_files_script") | ||
|
||
def stamp_tar_impl(ctx): | ||
""" | ||
this takes a tar file, calls maybe_stamp and replaces any variables in that file with the substituions passed, and then repackages the entire tar. | ||
Args: | ||
ctx: tar, substitutions | ||
maybe_stamp() generates a stable and volatile file in bazel-out | ||
Returns: | ||
stamped tar file | ||
""" | ||
|
||
inputs = [] | ||
|
||
stamped_tar = ctx.actions.declare_file(paths.basename(ctx.attr.name + ".tar.gz")) | ||
|
||
stamp = maybe_stamp(ctx) | ||
|
||
args = { | ||
"input_file": ctx.file.tar.short_path, | ||
"output_file": stamped_tar.short_path, | ||
"stable": ctx.attr.stable, | ||
"stamp": ctx.info_file.path if stamp else None, | ||
"substitutions": ctx.attr.substitutions, | ||
} | ||
|
||
if stamp: | ||
inputs = [stamp.volatile_status_file, stamp.stable_status_file] | ||
args["stable_file"] = stamp.stable_status_file.path | ||
args["volatile_file"] = stamp.volatile_status_file.path | ||
|
||
ctx.actions.run( | ||
inputs = inputs + ctx.files.tar, | ||
outputs = [stamped_tar], | ||
arguments = [json.encode(args)], | ||
executable = ctx.executable._stamp_tar_files_exec, | ||
mnemonic = "tar", | ||
env = { | ||
"BAZEL_BINDIR": ctx.bin_dir.path, | ||
}, | ||
) | ||
|
||
return [ | ||
DefaultInfo( | ||
files = depset([stamped_tar]), | ||
), | ||
] | ||
|
||
stamp_tar_files = rule( | ||
implementation = stamp_tar_impl, | ||
attrs = dict({ | ||
"stable": attr.bool( | ||
default = False, | ||
doc = "If true, replaces variables from stable-status. False replaces from volatile-status", | ||
), | ||
"substitutions": attr.string_dict( | ||
doc = "A mapping of values to replace in a file, to the stamp variables", | ||
), | ||
"tar": attr.label( | ||
allow_single_file = True, | ||
mandatory = True, | ||
doc = "The files to stamp", | ||
), | ||
"_stamp_tar_files_exec": attr.label( | ||
default = _STAMP_TAR_FILES, | ||
executable = True, | ||
doc = "The executable to run the stamping", | ||
cfg = "exec", | ||
), | ||
}, **STAMP_ATTRS), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import os from 'os'; | ||
import {spawnSync} from 'child_process'; | ||
import process from 'process'; | ||
|
||
|
||
async function handleSubstitutions(folderOrFile, substitutions) { | ||
if (Object.keys(substitutions).length === 0) { | ||
return; | ||
} | ||
|
||
if ((await fs.promises.stat(folderOrFile)).isDirectory()) { | ||
const files = await fs.promises.readdir(folderOrFile); | ||
for (const file of files) { | ||
await handleSubstitutions(path.join(folderOrFile, file), substitutions); | ||
} | ||
|
||
return; | ||
} | ||
|
||
let contents = await fs.promises.readFile(folderOrFile, "utf-8"); | ||
|
||
const originalContents = contents; | ||
for (const key in substitutions) { | ||
const value = substitutions[key]; | ||
contents = contents.replace(new RegExp(key, "g"), value); | ||
} | ||
|
||
if (contents !== originalContents) { | ||
await fs.promises.writeFile(folderOrFile, contents); | ||
} | ||
|
||
} | ||
|
||
const repackageTar = async (input_file, output_file, substitutions) => { | ||
const tempDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'stamping-')) | ||
const tempOutputDir = path.join(tempDir, "output"); | ||
await fs.promises.mkdir(tempOutputDir, { recursive: true }); | ||
|
||
spawnSync('tar',['-xzvf', input_file, '-C', tempOutputDir], {stdio:'inherit'}) | ||
|
||
await handleSubstitutions(tempOutputDir, substitutions); | ||
|
||
|
||
spawnSync('tar',['-czvf', output_file, '-C', tempOutputDir, '.'], {stdio:'inherit'}) | ||
} | ||
|
||
|
||
const main = async ([config]) => { | ||
const { input_file, output_file,stable, stamp, substitutions,volatile_file, stable_file} = JSON.parse(config); | ||
|
||
const resolvedInputFile = path.resolve(input_file) | ||
const resolvedOutputFile = path.resolve(output_file) | ||
|
||
// If stamping doesnt exist, just copy files | ||
if (!stamp) { | ||
fs.copyFileSync(resolvedInputFile, resolvedOutputFile); | ||
return; | ||
} | ||
|
||
let file = stable ? stable_file : volatile_file | ||
|
||
// need this to find the bazel-out/ path | ||
process.chdir(process.env.JS_BINARY__EXECROOT) | ||
|
||
const stampFile = fs.readFileSync(file,"utf-8"); | ||
|
||
// TODO: Should share this as a common module | ||
stampFile.split("\n").forEach((line) => { | ||
const firstSpace = line.indexOf(" "); | ||
const varName = line.substring(0, firstSpace); | ||
let varVal = line.substring(firstSpace + 1); | ||
|
||
// Using the same match as https://github.com/bazelbuild/rules_nodejs/blob/stable/internal/pkg_npm/packager.js#L139 | ||
if (varName.endsWith('_VERSION')) { | ||
// vscode doesn't let you have `-canary` suffixes | ||
varVal = varVal.replace(/[^\d.]/g, ''); | ||
} | ||
|
||
// Swap out anything referencing the stamped file with the actual value | ||
Object.keys(substitutions).forEach((key) => { | ||
if (substitutions[key] === `{${varName}}`) { | ||
substitutions[key] = varVal; | ||
} | ||
}); | ||
}); | ||
|
||
await repackageTar(resolvedInputFile, resolvedOutputFile, substitutions); | ||
|
||
}; | ||
|
||
main(process.argv.slice(2)).catch((e) => { | ||
console.error(e); | ||
process.exit(1); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
load("@bazel_skylib//:bzl_library.bzl", "bzl_library") | ||
load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_missing_pkgs", "bzlformat_pkg") | ||
|
||
bzlformat_pkg(name = "bzlformat") | ||
|
||
bzlformat_missing_pkgs(name = "bzlformat_missing_pkgs") | ||
|
||
exports_files(["defs.bzl"]) | ||
|
||
bzl_library( | ||
name = "defs", | ||
srcs = ["defs.bzl"], | ||
visibility = ["//visibility:public"], | ||
deps = [], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
""" | ||
Public API for JavaScript based project rules | ||
""" | ||
|
||
load("//gh-pages/private:gh-deploy.bzl", _gh_pages = "gh_pages") | ||
|
||
gh_pages = _gh_pages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
load("@aspect_rules_js//js:defs.bzl", "js_binary","js_run_binary","js_library") | ||
load("@bazel_skylib//:bzl_library.bzl", "bzl_library") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
js_library( | ||
name = "gh_pages_lib", | ||
srcs = [ | ||
"gh-pages.js" | ||
], | ||
visibility = ["//visibility:public"], | ||
) | ||
exports_files([ | ||
"gh-pages.js" | ||
]) | ||
|
||
js_binary( | ||
name = "gh_pages_bin", | ||
data = ["//gh-pages/private:gh-pages.js"], | ||
entry_point = "//gh-pages/private:gh-pages.js", | ||
visibility = ["//visibility:public"], | ||
|
||
) | ||
|
||
filegroup( | ||
name = "npm_depdencies", | ||
srcs = glob(["node_modules/**/*"]), | ||
visibility = [ | ||
"//visibility:public" | ||
] | ||
) |
Oops, something went wrong.