Skip to content

Commit

Permalink
Enforce consistent formatting of BUILD files. (digital-asset#412)
Browse files Browse the repository at this point in the history
* Add buildifier targets.

The tool allows to check and format BUILD files in the repo.

To check if files are well formatted, run:

    bazel run //:buildifier

To fix badly-formatted files run:

    bazel run //:buildifier-fix

* Cleanup dade-copyright-headers formatting.

* Fix dade-copyright-headers on files with just the copyright.

* Run buildifier automatically on CI via 'fmt.sh'.

* Reformat all BUILD files with buildifier.

Excludes autogenerated Bazel files.
  • Loading branch information
gleber-da authored Apr 12, 2019
1 parent 86b1699 commit aa70c7f
Show file tree
Hide file tree
Showing 147 changed files with 5,037 additions and 4,699 deletions.
2 changes: 1 addition & 1 deletion 3rdparty/c/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# SPDX-License-Identifier: Apache-2.0

exports_files([
"zlib.BUILD"
"zlib.BUILD",
])
34 changes: 17 additions & 17 deletions 3rdparty/c/zlib.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,24 @@ cc_library(
# be passed to hazel_repositories.

filegroup(
name = "lib",
srcs = [":z"],
output_group = "dynamic_library",
name = "lib",
srcs = [":z"],
output_group = "dynamic_library",
)

filegroup(
name = "headers",
srcs = [
"crc32.h",
"deflate.h",
"gzguts.h",
"inffast.h",
"inffixed.h",
"inflate.h",
"inftrees.h",
"trees.h",
"zconf.h",
"zlib.h",
"zutil.h",
],
name = "headers",
srcs = [
"crc32.h",
"deflate.h",
"gzguts.h",
"inffast.h",
"inffixed.h",
"inflate.h",
"inftrees.h",
"trees.h",
"zconf.h",
"zlib.h",
"zutil.h",
],
)
5 changes: 4 additions & 1 deletion 3rdparty/haskell/BUILD
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# This file is exported so that we can a 'hazel_symlink' in BUILD.network
exports_files(["network-package.bzl", "c2hs-package.bzl"])
exports_files([
"network-package.bzl",
"c2hs-package.bzl",
])
7 changes: 5 additions & 2 deletions 3rdparty/haskell/ffi_windows/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

package(default_visibility = ["//visibility:public"])

load("@os_info//:os_info.bzl", is_windows = "is_windows")
load("@os_info//:os_info.bzl", "is_windows")

alias(name = "ffi", actual = "@io_tweag_rules_haskell_ghc_windows_amd64//:rts-headers") if is_windows else None
alias(
name = "ffi",
actual = "@io_tweag_rules_haskell_ghc_windows_amd64//:rts-headers",
) if is_windows else None
96 changes: 67 additions & 29 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package(default_visibility = ["//:__subpackages__"])

load("@io_tweag_rules_haskell//haskell:haskell.bzl",
"haskell_toolchain",
load(
"@io_tweag_rules_haskell//haskell:haskell.bzl",
"haskell_toolchain",
)
load("@io_tweag_rules_haskell//haskell:c2hs.bzl",
"c2hs_toolchain",
load(
"@io_tweag_rules_haskell//haskell:c2hs.bzl",
"c2hs_toolchain",
)

load ("//bazel_tools:haskell.bzl", "da_haskell_library")
load("//bazel_tools:haskell.bzl", "da_haskell_library")

exports_files([".hlint.yaml"])

Expand Down Expand Up @@ -44,13 +45,15 @@ load(
"c2hs_toolchain",
)


c2hs_toolchain(
name = "c2hs-toolchain",
c2hs = "@c2hs//:bin",
)

filegroup(name = "node_modules", srcs = glob(["node_modules/**/*"]))
filegroup(
name = "node_modules",
srcs = glob(["node_modules/**/*"]),
)

config_setting(
name = "ghci_data",
Expand All @@ -64,7 +67,13 @@ config_setting(
#

# The VERSION file is inlined in a few builds.
exports_files(["NOTICES", "LICENSE", "VERSION", "CHANGELOG", "tsconfig.json"])
exports_files([
"NOTICES",
"LICENSE",
"VERSION",
"CHANGELOG",
"tsconfig.json",
])

# FIXME(#448): We're currently assigning version (100+x).y.z to all components
# in SDK version x.y.z. As long as x < 10, 10x.y.z == (100+x).y.z. Since we'll
Expand All @@ -82,7 +91,10 @@ genrule(

genrule(
name = "sdk-version-hs",
srcs = ["VERSION", ":component-version"],
srcs = [
"VERSION",
":component-version",
],
outs = ["SdkVersion.hs"],
cmd = """
SDK_VERSION=$$(cat $(location VERSION))
Expand All @@ -105,58 +117,84 @@ da_haskell_library(

genrule(
name = "git-revision",
stamp = True,
outs = [".git-revision"],
cmd = """
grep '^STABLE_GIT_REVISION ' bazel-out/stable-status.txt | cut -d ' ' -f 2 > $@
""",
stamp = True,
)


#
# Common aliases
#

alias(
name = "damli",
actual = "//daml-foundations/daml-tools/da-hs-damli-app:damli"
name = "damli",
actual = "//daml-foundations/daml-tools/da-hs-damli-app:damli",
)

alias(
name = "damli@ghci",
actual = "//daml-foundations/daml-tools/da-hs-damli-app:damli@ghci"
name = "damli@ghci",
actual = "//daml-foundations/daml-tools/da-hs-damli-app:damli@ghci",
)

alias(
name = "damli-dist",
actual = "//daml-foundations/daml-tools/da-hs-damli-app:dist"
name = "damli-dist",
actual = "//daml-foundations/daml-tools/da-hs-damli-app:dist",
)

alias(
name = "damlc",
actual = "//daml-foundations/daml-tools/da-hs-damlc-app:da-hs-damlc-app"
name = "damlc",
actual = "//daml-foundations/daml-tools/da-hs-damlc-app:da-hs-damlc-app",
)

alias(
name = "damlc@ghci",
actual = "//daml-foundations/daml-tools/da-hs-damlc-app:da-hs-damlc-app@ghci"
name = "damlc@ghci",
actual = "//daml-foundations/daml-tools/da-hs-damlc-app:da-hs-damlc-app@ghci",
)

alias(
name = "damlc-dist",
actual = "//daml-foundations/daml-tools/da-hs-damlc-app:damlc-dist"
name = "damlc-dist",
actual = "//daml-foundations/daml-tools/da-hs-damlc-app:damlc-dist",
)

alias(
name = "daml-lf-repl",
actual = "//daml-lf/repl:repl"
name = "daml-lf-repl",
actual = "//daml-lf/repl:repl",
)

alias(
name = "bindings-java",
actual = "//language-support/java/bindings:bindings-java"
name = "bindings-java",
actual = "//language-support/java/bindings:bindings-java",
)

exports_files([
".scalafmt.conf"
".scalafmt.conf",
])

# Buildifier.

load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier")

buildifier_excluded_patterns = [
"./3rdparty/haskell/c2hs-package.bzl",
"./3rdparty/haskell/network-package.bzl",
"./3rdparty/jvm/*",
"./3rdparty/workspace.bzl",
"./hazel/packages.bzl",
]

# Run this to check if BUILD files are well-formatted.
buildifier(
name = "buildifier",
exclude_patterns = buildifier_excluded_patterns,
mode = "check",
)

# Run this to fix the errors in BUILD files.
buildifier(
name = "buildifier-fix",
exclude_patterns = buildifier_excluded_patterns,
mode = "fix",
verbose = True,
)
Loading

0 comments on commit aa70c7f

Please sign in to comment.