Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: cleanup _maybe helpers #3127

Merged
merged 1 commit into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions internal/node/node_repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This is a set of repository rules for setting up hermetic copies of NodeJS and Y
See https://docs.bazel.build/versions/main/skylark/repository_rules.html
"""

load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("//internal/common:check_bazel_version.bzl", "check_bazel_version")
load("//nodejs/private:nodejs_repo_host_os_alias.bzl", "nodejs_repo_host_os_alias")
load("//nodejs/private:os_name.bzl", "OS_ARCH_NAMES", "node_exists_for_os", "os_name")
Expand Down Expand Up @@ -51,7 +52,7 @@ def node_repositories(**kwargs):
if not node_exists_for_os(node_version, os_name):
continue
node_repository_name = "nodejs_%s" % os_name
_maybe(
maybe(
node_repositories_rule,
name = node_repository_name,
**kwargs
Expand All @@ -65,12 +66,8 @@ def node_repositories(**kwargs):

# This "nodejs" repo is just for convenience so one does not have to target @nodejs_<os_name>//...
# All it does is create aliases to the @nodejs_<host_os>_<host_arch> repository
_maybe(
maybe(
nodejs_repo_host_os_alias,
name = "nodejs",
node_version = node_version,
)

def _maybe(repo_rule, name, **kwargs):
if name not in native.existing_rules():
repo_rule(name = name, **kwargs)
6 changes: 2 additions & 4 deletions internal/npm_install/generate_build_file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,9 @@ async function generateBazelWorkspaces(pkgs: Dep[]) {
*/
async function generateBazelWorkspace(pkg: Dep, workspace: string) {
let bzlFile = `# Generated by the yarn_install/npm_install rule
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("@build_bazel_rules_nodejs//internal/copy_repository:copy_repository.bzl", "copy_repository")

def _maybe(repo_rule, name, **kwargs):
if name not in native.existing_rules():
repo_rule(name = name, **kwargs)
`;

const rootPath = pkg.bazelWorkspaces[workspace].rootPath;
Expand Down Expand Up @@ -463,7 +461,7 @@ def _maybe(repo_rule, name, **kwargs):
`# Marker file to used by custom copy_repository rule\n${sha256sum.digest('hex')}`);

bzlFile += `def install_${workspace}():
_maybe(
maybe(
copy_repository,
name = "${workspace}",
marker_file = "@${config.workspace}//_workspaces/${workspace}:_bazel_workspace_marker",
Expand Down
6 changes: 2 additions & 4 deletions internal/npm_install/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,9 @@ async function generateBazelWorkspaces(pkgs) {
}
async function generateBazelWorkspace(pkg, workspace) {
let bzlFile = `# Generated by the yarn_install/npm_install rule
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("@build_bazel_rules_nodejs//internal/copy_repository:copy_repository.bzl", "copy_repository")

def _maybe(repo_rule, name, **kwargs):
if name not in native.existing_rules():
repo_rule(name = name, **kwargs)
`;
const rootPath = pkg.bazelWorkspaces[workspace].rootPath;
if (!rootPath) {
Expand Down Expand Up @@ -295,7 +293,7 @@ def _maybe(repo_rule, name, **kwargs):
sha256sum.update(await fs_1.promises.readFile(config.package_lock, { encoding: 'utf8' }));
await writeFile(path.posix.join(workspaceSourcePath, '_bazel_workspace_marker'), `# Marker file to used by custom copy_repository rule\n${sha256sum.digest('hex')}`);
bzlFile += `def install_${workspace}():
_maybe(
maybe(
copy_repository,
name = "${workspace}",
marker_file = "@${config.workspace}//_workspaces/${workspace}:_bazel_workspace_marker",
Expand Down
23 changes: 10 additions & 13 deletions package.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Fulfills similar role as the package.json file.
"""

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

def rules_nodejs_dev_dependencies():
"""
Expand All @@ -28,7 +29,7 @@ def rules_nodejs_dev_dependencies():
"""

# Dependencies for generating documentation
_maybe(
maybe(
http_archive,
name = "io_bazel_rules_sass",
sha256 = "c6249cf64dffbc81312191800b0984b5197d77864c13d0dc4d469937cc3f8108",
Expand All @@ -40,7 +41,7 @@ def rules_nodejs_dev_dependencies():
)

# Needed for com_google_protobuf
_maybe(
maybe(
http_archive,
name = "zlib",
build_file = "@com_google_protobuf//:third_party/zlib.BUILD",
Expand All @@ -52,7 +53,7 @@ def rules_nodejs_dev_dependencies():
],
)

_maybe(
maybe(
http_archive,
name = "io_bazel_stardoc",
sha256 = "d681269c40a368c6eb7e9eccfee44a9919d22f84f80e331e41e74bdf99a3108e",
Expand All @@ -62,7 +63,7 @@ def rules_nodejs_dev_dependencies():
],
)

_maybe(
maybe(
http_archive,
name = "bazel_skylib",
sha256 = "58f558d04a936cade1d4744d12661317e51f6a21e3dd7c50b96dc14f3fa3b87d",
Expand All @@ -74,7 +75,7 @@ def rules_nodejs_dev_dependencies():

# Needed for Remote Build Execution
# See https://releases.bazel.build/bazel-toolchains.html
_maybe(
maybe(
http_archive,
name = "bazel_toolchains",
sha256 = "179ec02f809e86abf56356d8898c8bd74069f1bd7c56044050c2cd3d79d0e024",
Expand All @@ -85,7 +86,7 @@ def rules_nodejs_dev_dependencies():
],
)

_maybe(
maybe(
http_archive,
name = "build_bazel_integration_testing",
urls = [
Expand All @@ -95,7 +96,7 @@ def rules_nodejs_dev_dependencies():
sha256 = "2401b1369ef44cc42f91dc94443ef491208dbd06da1e1e10b702d8c189f098e3",
)

_maybe(
maybe(
http_archive,
name = "rules_codeowners",
strip_prefix = "rules_codeowners-27fe3bbe6e5b0df196e360fc9e081835f22a10be",
Expand All @@ -105,7 +106,7 @@ def rules_nodejs_dev_dependencies():
],
)

_maybe(
maybe(
http_archive,
name = "rules_pkg",
urls = [
Expand All @@ -115,13 +116,9 @@ def rules_nodejs_dev_dependencies():
sha256 = "aeca78988341a2ee1ba097641056d168320ecc51372ef7ff8e64b139516a4937",
)

_maybe(
maybe(
http_archive,
name = "io_bazel_rules_webtesting",
sha256 = "e9abb7658b6a129740c0b3ef6f5a2370864e102a5ba5ffca2cea565829ed825a",
urls = ["https://github.com/bazelbuild/rules_webtesting/releases/download/0.3.5/rules_webtesting.tar.gz"],
)

def _maybe(repo_rule, name, **kwargs):
if name not in native.existing_rules():
repo_rule(name = name, **kwargs)
15 changes: 6 additions & 9 deletions packages/concatjs/package.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

def rules_typescript_dev_dependencies():
"""
Expand All @@ -27,15 +28,15 @@ def rules_typescript_dev_dependencies():
Also this allows other repos to reference our sources with local_repository and install the needed deps.
"""

_maybe(
maybe(
http_archive,
name = "build_bazel_rules_nodejs",
sha256 = "b6670f9f43faa66e3009488bbd909bc7bc46a5a9661a33f6bc578068d1837f37",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/1.3.0/rules_nodejs-1.3.0.tar.gz"],
)

# For protocol buffers
_maybe(
maybe(
http_archive,
name = "io_bazel",
urls = ["https://github.com/bazelbuild/bazel/releases/download/0.25.0/bazel-0.25.0-dist.zip"],
Expand All @@ -44,7 +45,7 @@ def rules_typescript_dev_dependencies():

# For building concatjs_devserver binary
# See https://github.com/bazelbuild/rules_go#setup for the latest version.
_maybe(
maybe(
http_archive,
name = "io_bazel_rules_go",
sha256 = "8e968b5fcea1d2d64071872b12737bbb5514524ee5f0a4f54f5920266c261acb",
Expand All @@ -55,7 +56,7 @@ def rules_typescript_dev_dependencies():
)

# go_repository is defined in bazel_gazelle
_maybe(
maybe(
http_archive,
name = "bazel_gazelle",
sha256 = "62ca106be173579c0a167deb23358fdfe71ffa1e4cfdddf5582af26520f1c66f",
Expand All @@ -65,14 +66,10 @@ def rules_typescript_dev_dependencies():
],
)

_maybe(
maybe(
http_archive,
name = "com_google_protobuf",
sha256 = "98e615d592d237f94db8bf033fba78cd404d979b0b70351a9e5aaff725398357",
strip_prefix = "protobuf-3.9.1",
urls = ["https://github.com/protocolbuffers/protobuf/archive/v3.9.1.tar.gz"],
)

def _maybe(repo_rule, name, **kwargs):
if not native.existing_rule(name):
repo_rule(name = name, **kwargs)
7 changes: 2 additions & 5 deletions packages/protractor/package.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

def npm_bazel_protractor_dependencies():
"""
Expand All @@ -26,13 +27,9 @@ def npm_bazel_protractor_dependencies():
"""

# protractor rules depend on the web testing rules to provision browsers.
_maybe(
maybe(
http_archive,
name = "io_bazel_rules_webtesting",
sha256 = "e9abb7658b6a129740c0b3ef6f5a2370864e102a5ba5ffca2cea565829ed825a",
urls = ["https://github.com/bazelbuild/rules_webtesting/releases/download/0.3.5/rules_webtesting.tar.gz"],
)

def _maybe(repo_rule, name, **kwargs):
if name not in native.existing_rules():
repo_rule(name = name, **kwargs)
7 changes: 2 additions & 5 deletions toolchains/esbuild/esbuild_repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ Helper macro for fetching esbuild versions
"""

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("@build_bazel_rules_nodejs//:index.bzl", "npm_install")
load(":esbuild_packages.bzl", "ESBUILD_PACKAGES")

def _maybe(repo_rule, name, **kwargs):
if name not in native.existing_rules():
repo_rule(name = name, **kwargs)

def esbuild_repositories(name = "", npm_repository = "npm", npm_args = []):
"""Helper for fetching and setting up the esbuild versions and toolchains

Expand All @@ -35,7 +32,7 @@ def esbuild_repositories(name = "", npm_repository = "npm", npm_args = []):
"""

for name, meta in ESBUILD_PACKAGES.platforms.items():
_maybe(
maybe(
http_archive,
name = "esbuild_%s" % name,
urls = meta.urls,
Expand Down