Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3 from danmx/bazel_run_refactor
Browse files Browse the repository at this point in the history
Refactoring tools
  • Loading branch information
danmx authored Oct 18, 2020
2 parents 0e5409b + a76d811 commit cf03e73
Show file tree
Hide file tree
Showing 21 changed files with 125 additions and 259 deletions.
1 change: 0 additions & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ build --stamp
# Make /tmp hermetic
build --sandbox_tmpfs_path=/tmp

# Ensure that Bazel never runs as root, which can cause unit tests to fail.
build --sandbox_fake_username

test:unit --build_tests_only
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.0
3.6.0
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ bazelisk sync

## Considerations

Some tools were inspired by [atlassian/bazel-tools](https://github.com/atlassian/bazel-tools) and/or copied from [Kubernetes](https://github.com/kubernetes/kubernetes).
`run_in_workspace` was copied from [Kubernetes](https://github.com/kubernetes/kubernetes).
25 changes: 25 additions & 0 deletions bazel/platforms/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package(default_visibility = ["//visibility:public"])

config_setting(
name = "windows-x86_64",
constraint_values = [
"@platforms//os:windows",
"@platforms//cpu:x86_64",
],
)

config_setting(
name = "macos-x86_64",
constraint_values = [
"@platforms//os:macos",
"@platforms//cpu:x86_64",
],
)

config_setting(
name = "linux-x86_64",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
)
10 changes: 9 additions & 1 deletion drone-cli/BUILD
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
package(default_visibility = ["//visibility:public"])
alias(
name = "run",
actual = select({
"@com_github_danmx_bazel_tools//bazel/platforms:linux-x86_64": "@drone-linux-amd64//:drone",
"@com_github_danmx_bazel_tools//bazel/platforms:macos-x86_64": "@drone-darwin-amd64//:drone",
"@com_github_danmx_bazel_tools//bazel/platforms:windows-x86_64": "@drone-windows-amd64//:drone",
}),
visibility = ["//visibility:public"],
)
21 changes: 3 additions & 18 deletions drone-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,13 @@ git_repository(
shallow_since = "<bla>",
)

load("@com_github_danmx_bazel_tools//drone-cli:deps.bzl", "drone_dependencies")
load("@com_github_danmx_bazel_tools//drone-cli:deps.bzl", "drone_cli_dependencies")

drone_dependencies()
```

`BUILD.bazel` typically in the workspace root:

```bzl
load("@com_github_danmx_bazel_tools//drone-cli:def.bzl", "drone")

drone(
name = "drone-fmt",
args = [
"fmt",
"--save",
".drone.yml",
],
)
drone_cli_dependencies()
```

Invoke with

```console
bazel run //:drone-fmt
bazel run @com_github_danmx_bazel_tools//drone-cli:run -- --help
```
12 changes: 0 additions & 12 deletions drone-cli/def.bzl

This file was deleted.

70 changes: 17 additions & 53 deletions drone-cli/deps.bzl
Original file line number Diff line number Diff line change
@@ -1,57 +1,21 @@
_VERSION = "v1.2.1"
_BINARIES = {
"windows-amd64": {
"suffix": "windows_amd64.tar.gz",
"sha256": "58621ce64bbbb060d4eccccc71061bb9671fef7d1980c74200aae12a669810cb",
},
"linux-amd64": {
"suffix": "linux_amd64.tar.gz",
"sha256": "c28f724eb44ad756e550789824b9c73d4970da884966bc71552a281815c13f0a",
},
"linux-arm": {
"suffix": "linux_arm.tar.gz",
"sha256": "297ea83310a7da43d5b25b1ea88cd72c62b024197d58bcf7ab6e7f2b36d4f9eb",
},
"linux-arm64": {
"suffix": "linux_arm64.tar.gz",
"sha256": "31d3faf3cf9ffac1cacbd7695cfd1eadfc9695d6a08d789b0857298fbeacb386",
},
"darwin-amd64": {
"suffix": "darwin_amd64.tar.gz",
"sha256": "0b0028ed785c10455a4d67a099de4979cce7825bc97af91d7ebca61525766923",
},
}
_DOWNLOAD_URI = "https://github.com/drone/drone-cli/releases/download/{version}/drone_{suffix}"
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

def _drone_cli_download_impl(ctx):
if ctx.os.name == "linux":
arch = "linux-amd64"
elif ctx.os.name == "mac os x":
arch = "darwin-amd64"
else:
fail("Unsupported operating system: {}".format(ctx.os.name))

if arch not in _BINARIES:
fail("Unsupported arch {}".format(arch))

url = _DOWNLOAD_URI.format(version = _VERSION, suffix = _BINARIES.get(arch).get("suffix"))
sha256 = _BINARIES.get(arch).get("sha256")

ctx.template(
"BUILD.bazel",
Label("//drone-cli:drone.build.bazel"),
executable = False,
def drone_cli_dependencies():
http_archive(
name = "drone-linux-amd64",
urls = ["https://github.com/drone/drone-cli/releases/download/v1.2.2/drone_linux_amd64.tar.gz"],
sha256 = "59969ed403cab2e8fada1caaf8132c23f5689fde1c7dd9a807cef8786ef25924",
build_file = "@com_github_danmx_bazel_tools//drone-cli:drone.BUILD",
)
ctx.download_and_extract(
url = url,
sha256 = sha256,
http_archive(
name = "drone-darwin-amd64",
urls = ["https://github.com/drone/drone-cli/releases/download/v1.2.2/drone_darwin_amd64.tar.gz"],
sha256 = "73f96ad0a9f3038463a86408b231b80758e64aa4ce85534933d85ee718ae096c",
build_file = "@com_github_danmx_bazel_tools//drone-cli:drone.BUILD",
)

_drone_cli_download = repository_rule(
implementation = _drone_cli_download_impl,
)

def drone_cli_dependencies():
_drone_cli_download(
name = "com_github_danmx_bazel_tools_drone-cli",
http_archive(
name = "drone-windows-amd64",
urls = ["https://github.com/drone/drone-cli/releases/download/v1.2.2/drone_windows_amd64.tar.gz"],
sha256 = "8ae9bb0b07ced2536cc8c8c0e236d1d8ae08b53387e1139a470e2cd37076a3ca",
build_file = "@com_github_danmx_bazel_tools//drone-cli:drone.BUILD",
)
4 changes: 4 additions & 0 deletions drone-cli/drone.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
exports_files(
["drone"],
visibility = ["//visibility:public"],
)
1 change: 0 additions & 1 deletion drone-cli/drone.build.bazel

This file was deleted.

10 changes: 9 additions & 1 deletion git-chglog/BUILD
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
package(default_visibility = ["//visibility:public"])
alias(
name = "run",
actual = select({
"@com_github_danmx_bazel_tools//bazel/platforms:linux-x86_64": "@git-chglog-linux-amd64//file:git-chglog",
"@com_github_danmx_bazel_tools//bazel/platforms:macos-x86_64": "@git-chglog-darwin-amd64//file:git-chglog",
"@com_github_danmx_bazel_tools//bazel/platforms:windows-x86_64": "@git-chglog-windows-amd64//file:git-chglog",
}),
visibility = ["//visibility:public"],
)
16 changes: 1 addition & 15 deletions git-chglog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,8 @@ load("@com_github_danmx_bazel_tools//git-chglog:deps.bzl", "git_chglog_dependenc
git_chglog_dependencies()
```

`BUILD.bazel` typically in the workspace root:

```bzl
load("@com_github_danmx_bazel_tools//git-chglog:def.bzl", "git_chglog")

git_chglog(
name = "git_chglog",
args = [
"-o",
"CHANGELOG.md",
],
)
```

Invoke with

```console
bazel run //:git_chglog
bazel run @com_github_danmx_bazel_tools//git-chglog:run -- --help
```
12 changes: 0 additions & 12 deletions git-chglog/def.bzl

This file was deleted.

77 changes: 19 additions & 58 deletions git-chglog/deps.bzl
Original file line number Diff line number Diff line change
@@ -1,63 +1,24 @@
_VERSION = "0.9.1"
_BINARIES = {
"windows-amd64": {
"suffix": "windows_amd64.exe",
"sha256": "d14da18c6008de0c240b75991368a137068c8a06d3d4c3c240ddc806fd7b9612",
},
"windows-386": {
"suffix": "windows_386.exe",
"sha256": "00971cd3718084f405002d9732ad8758469b04a059feae96f3a943a0706065dd",
},
"linux-amd64": {
"suffix": "linux_amd64",
"sha256": "dca7d683a45cf4f0a871735d9981de4e787ef86b82282e8adc813b8738d2c531",
},
"linux-386": {
"suffix": "linux_386",
"sha256": "25021b185b706e3f0b3cdc56e1f69e1263c5f0d157725e2df0965b31eb2240d8",
},
"darwin-amd64": {
"suffix": "darwin_amd64",
"sha256": "2023d82b5b505cf8ac4db20f096f439650554e80eb509fe080f5e81b6b477d3c",
},
"darwin-386": {
"suffix": "darwin_386",
"sha256": "02011ddcbb5f2c21ba71cbd3bbe978cf74362ba579f31f6178ff835addd9f097",
},
}
_DOWNLOAD_URI = "https://github.com/git-chglog/git-chglog/releases/download/{version}/git-chglog_{suffix}"
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")

def _git_chglog_download_impl(ctx):
if ctx.os.name == "linux":
arch = "linux-amd64"
elif ctx.os.name == "mac os x":
arch = "darwin-amd64"
else:
fail("Unsupported operating system: {}".format(ctx.os.name))

if arch not in _BINARIES:
fail("Unsupported arch {}".format(arch))

url = _DOWNLOAD_URI.format(version = _VERSION, suffix = _BINARIES.get(arch).get("suffix"))
sha256 = _BINARIES.get(arch).get("sha256")

ctx.template(
"BUILD.bazel",
Label("//git-chglog:git-chglog.build.bazel"),
executable = False,
def git_chglog_dependencies():
http_file(
name = "git-chglog-linux-amd64",
urls = ["https://github.com/git-chglog/git-chglog/releases/download/0.9.1/git-chglog_linux_amd64"],
sha256 = "dca7d683a45cf4f0a871735d9981de4e787ef86b82282e8adc813b8738d2c531",
executable = True,
downloaded_file_path = "git-chglog",
)
ctx.download(
output = "git-chglog",
url = url,
sha256 = sha256,
http_file(
name = "git-chglog-darwin-amd64",
urls = ["https://github.com/git-chglog/git-chglog/releases/download/0.9.1/git-chglog_darwin_amd64"],
sha256 = "2023d82b5b505cf8ac4db20f096f439650554e80eb509fe080f5e81b6b477d3c",
executable = True,
downloaded_file_path = "git-chglog",
)

_git_chglog_download = repository_rule(
implementation = _git_chglog_download_impl,
)

def git_chglog_dependencies():
_git_chglog_download(
name = "com_github_danmx_bazel_tools_git-chglog",
http_file(
name = "git-chglog-windows-amd64",
urls = ["https://github.com/git-chglog/git-chglog/releases/download/0.9.1/git-chglog_windows_amd64.exe"],
sha256 = "d14da18c6008de0c240b75991368a137068c8a06d3d4c3c240ddc806fd7b9612",
executable = True,
downloaded_file_path = "git-chglog",
)
1 change: 0 additions & 1 deletion git-chglog/git-chglog.build.bazel

This file was deleted.

10 changes: 9 additions & 1 deletion golangci-lint/BUILD
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
package(default_visibility = ["//visibility:public"])
alias(
name = "run",
actual = select({
"@com_github_danmx_bazel_tools//bazel/platforms:linux-x86_64": "@golangci-lint-linux-amd64//:golangci-lint",
"@com_github_danmx_bazel_tools//bazel/platforms:macos-x86_64": "@golangci-lint-darwin-amd64//:golangci-lint",
"@com_github_danmx_bazel_tools//bazel/platforms:windows-x86_64": "@golangci-lint-windows-amd64//:golangci-lint",
}),
visibility = ["//visibility:public"],
)
20 changes: 3 additions & 17 deletions golangci-lint/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,13 @@ git_repository(
shallow_since = "<bla>",
)

load("@com_github_danmx_bazel_tools//golangci-lint:deps.bzl", "drone_dependencies")
load("@com_github_danmx_bazel_tools//golangci-lint:deps.bzl", "golangci_lint_dependencies")

drone_dependencies()
```

`BUILD.bazel` typically in the workspace root:

```bzl
load("@com_github_danmx_bazel_tools//golangci-lint:def.bzl", "golangci_lint")

golangci_lint(
name = "lint",
args = [
"run",
"./...",
],
)
golangci_lint_dependencies()
```

Invoke with

```console
bazel run //:lint
bazel run @com_github_danmx_bazel_tools//golangci-lint:run -- --help
```
12 changes: 0 additions & 12 deletions golangci-lint/def.bzl

This file was deleted.

Loading

0 comments on commit cf03e73

Please sign in to comment.