Skip to content

Commit

Permalink
Fix build (#40)
Browse files Browse the repository at this point in the history
The native go build system is broken for this repo, thus the dependencies are no longer managed
correctly with `go module`.  Though the go version has been changed to go 1.19, dependencies are
not updated accordingly.

In this change:

- pin bazel to 5.4.1 with `.bazelversion`
- update `go.mod` to use `go 1.19` to match `WORKSPACE`
- run `go mod tidy` to clean up `go.mod` and `go.sum` for new version
- update `github.com/spf13/viper` to 1.16.0 to resolve compatibility issues
- update `bazel_gazelle` to the latest version (v0.31.1) that is compatible with `rules_go` 0.35.0
- update build files with `bazel run //:gazelle` and remove redundant test targets
- add `//:update-deps` target to manage `deps.bzl`
- regenerate `deps.bzl` with `bazel run //:update-deps`

The change should be a no-op, as versions of direct dependencies that provide core functionalities
are remain unchanged.
  • Loading branch information
ashi009 committed Aug 15, 2023
1 parent 2f76c85 commit cd825c6
Show file tree
Hide file tree
Showing 6 changed files with 621 additions and 954 deletions.
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.4.1
73 changes: 14 additions & 59 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ load("@rules_pkg//:mappings.bzl", "pkg_attributes", "pkg_filegroup", "pkg_files"

gazelle(name = "gazelle")

gazelle(
name = "update-deps",
args = [
"-from_file=go.mod",
"-to_macro=deps.bzl%go_dependencies",
"-prune",
],
command = "update-repos",
)

buildifier(name = "buildifier")

#
Expand All @@ -28,9 +38,10 @@ go_library(
"util.go",
"venv.go",
],
embedsrcs = glob([
"templates/*.html",
]),
embedsrcs = [
"templates/ansible_controller.html",
"templates/index.html",
],
importpath = "github.com/teslamotors/ansible_puller",
visibility = ["//visibility:private"],
deps = [
Expand Down Expand Up @@ -73,62 +84,6 @@ go_test(
],
)

go_test(
name = "http_downloader_test",
srcs = ["http_downloader_test.go"],
data = [
":ansible-puller.json",
":testdata",
],
embed = [":ansible_puller_lib"],
deps = [
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//suite",
],
)

go_test(
name = "http_test",
srcs = ["http_test.go"],
data = [
":ansible-puller.json",
":testdata",
],
embed = [":ansible_puller_lib"],
deps = [
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//suite",
],
)

go_test(
name = "s3_downloader_test",
srcs = ["s3_downloader_test.go"],
data = [
":ansible-puller.json",
":testdata",
],
embed = [":ansible_puller_lib"],
deps = [
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//suite",
],
)

go_test(
name = "unarchive_test",
srcs = ["unarchive_test.go"],
data = [
":ansible-puller.json",
":testdata",
],
embed = [":ansible_puller_lib"],
deps = [
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//suite",
],
)

#
# Packaging Constants
#
Expand Down
35 changes: 14 additions & 21 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,27 @@ http_archive(

http_archive(
name = "bazel_gazelle",
sha256 = "62ca106be173579c0a167deb23358fdfe71ffa1e4cfdddf5582af26520f1c66f",
sha256 = "b8b6d75de6e4bf7c41b7737b183523085f56283f6db929b86c5e7e1f09cf59c9",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.23.0/bazel-gazelle-v0.23.0.tar.gz",
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.23.0/bazel-gazelle-v0.23.0.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.31.1/bazel-gazelle-v0.31.1.tar.gz",
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.31.1/bazel-gazelle-v0.31.1.tar.gz",
],
)

load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
load("//:deps.bzl", "go_dependencies")

go_rules_dependencies()

go_register_toolchains(version = "1.19.1")

gazelle_dependencies()

# gazelle:repository_macro deps.bzl%go_dependencies
go_dependencies()

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

http_archive(
name = "rules_pkg",
Expand All @@ -42,13 +51,6 @@ load("@rules_pkg//toolchains/rpm:rpmbuild_configure.bzl", "find_system_rpmbuild"

find_system_rpmbuild(name = "rules_pkg_rpmbuild")

go_repository(
name = "com_github_mwitkow_go_proto_validators",
importpath = "github.com/mwitkow/go-proto-validators",
sum = "h1:F6LFfmgVnfULfaRsQWBbe7F7ocuHCr9+7m+GAeDzNbQ=",
version = "v0.2.0",
)

git_repository(
name = "com_google_protobuf",
commit = "09745575a923640154bcf307fba8aedff47f240a",
Expand All @@ -66,12 +68,3 @@ http_archive(
"https://zlib.net/zlib-1.2.11.tar.gz",
],
)

# gazelle:repository_macro deps.bzl%go_dependencies
go_dependencies()

go_rules_dependencies()

go_register_toolchains(version = "1.19.1")

gazelle_dependencies()
Loading

0 comments on commit cd825c6

Please sign in to comment.