Skip to content

Commit bdbe5e9

Browse files
committed
bazel: add bazelisk run //:format to format all code
Signed-off-by: Øyvind Harboe <[email protected]>
1 parent 51a587e commit bdbe5e9

File tree

5 files changed

+73
-0
lines changed

5 files changed

+73
-0
lines changed

BUILD.bazel

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# run black and tclfmt on the codebase using python installation
2+
load("@orfs-pip//:requirements.bzl", "requirement")
3+
load("@rules_python//python:pip.bzl", "compile_pip_requirements")
4+
5+
exports_files(["open_plots.sh"])
6+
7+
py_binary(
8+
name = "black",
9+
srcs = [
10+
"etc/black.py",
11+
],
12+
args = [],
13+
main = "etc/black.py",
14+
visibility = ["//visibility:public"],
15+
deps = [requirement("black")],
16+
)
17+
18+
py_binary(
19+
name = "tclfmt",
20+
srcs = [
21+
"etc/tclfmt.py",
22+
],
23+
args = [],
24+
data = [":tclint.toml"],
25+
main = "etc/tclfmt.py",
26+
visibility = ["//visibility:public"],
27+
deps = [requirement("tclint")],
28+
)
29+
30+
sh_binary(
31+
name = "format",
32+
srcs = ["etc/format.sh"],
33+
args = [
34+
"$(location :black)",
35+
"$(location :tclfmt)",
36+
],
37+
data = [
38+
":black",
39+
":tclfmt",
40+
],
41+
)

bazel/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@
33
`bazel-orfs` is a Bazel package containing the definitions and logic governing the build process of ORFS designs.
44
The module uses the `openroad/orfs` docker image to extract the flow scripts with dependencies, builds the Bazel environment around them and defines the methods of calling the ORFS Makefiles with selected designs.
55

6+
## Format all code, including submodules
7+
8+
To format all files, run:
9+
10+
bazelisk run //:format
11+
12+
In the above command, bazel sets up all dependencies and configuration files, without depending or using local files of configuration.
13+
14+
Bazel expert tip: bearing in mind that `bazelisk run` will have pwd inside the runfiles of the target, you can run only black using:
15+
16+
bazelisk run :black -- $(pwd)
17+
18+
Or tclfmt:
19+
20+
bazelisk run :tclfmt -- --in-place $(pwd)
21+
622
## Run examples
723

824
`flow/BUILD.bazel` contains definitions for various flows to serve as examples.

etc/black.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# wafer-thin wrapper to invoke module
2+
import black
3+
4+
black.main()

etc/format.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
set -e
3+
black=$1
4+
shift
5+
tclfmt=$1
6+
shift
7+
$tclfmt --in-place ${BUILD_WORKSPACE_DIRECTORY}
8+
$black ${BUILD_WORKSPACE_DIRECTORY}

etc/tclfmt.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# wafer-thin wrapper to invoke module
2+
from tclint.cli.tclfmt import main
3+
4+
main()

0 commit comments

Comments
 (0)