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

[wip] fix various bazel incompatibilities #404

Closed
wants to merge 3 commits into from
Closed
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
1 change: 1 addition & 0 deletions platform/.bazelrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
startup --host_jvm_args=-Xmx4G
build --workspace_status_command bazel/workspace-status.sh
build --incompatible_use_python_toolchains=false
74 changes: 60 additions & 14 deletions platform/WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,43 +1,58 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

# rules_go

# TODO: audit all downloads, make sure they're all source code
http_archive(
name = "io_bazel_rules_go",
urls = ["https://github.com/bazelbuild/rules_go/releases/download/0.18.3/rules_go-0.18.3.tar.gz"],
sha256 = "86ae934bd4c43b99893fc64be9d9fc684b81461581df7ea8fc291c816f5ee8c5",
urls = [
"https://storage.googleapis.com/bazel-mirror/github.com/bazelbuild/rules_go/releases/download/0.19.1/rules_go-0.19.1.tar.gz",
"https://github.com/bazelbuild/rules_go/releases/download/0.19.1/rules_go-0.19.1.tar.gz"
],
sha256 = "8df59f11fb697743cbb3f26cfb8750395f30471e9eabde0d174c3aebc7a1cd39",
)
load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies", "go_register_toolchains")
go_rules_dependencies()
# TODO: stop using binaries built by upstream; use our own
go_register_toolchains(
go_version = "1.12.4",
)
load("//bazel:gorepo_patchfix.bzl", "go_repository_alt")

# gazelle

http_archive(
name = "bazel_gazelle",
urls = ["https://github.com/bazelbuild/bazel-gazelle/releases/download/0.17.0/bazel-gazelle-0.17.0.tar.gz"],
sha256 = "3c681998538231a2d24d0c07ed5a7658cb72bfb5fd4bf9911157c0e9ac6a2687",
)
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")
gazelle_dependencies()

load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies", "go_register_toolchains")

go_rules_dependencies()
# protobuf

# TODO: stop using binaries built by upstream; use our own
go_register_toolchains(
go_version = "1.12.4",
git_repository(
name = "com_google_protobuf",
commit = "6a59a2ad1f61d9696092f79b6d74368b4d7970a3", # 3.9.0
remote = "https://github.com/protocolbuffers/protobuf",
shallow_since = "1558721209 -0700",
)
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
protobuf_deps()

load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")
load("//bazel:gorepo_patchfix.bzl", "go_repository_alt")

gazelle_dependencies()
# rules_docker

git_repository(
name = "io_bazel_rules_docker",
remote = "https://github.com/bazelbuild/rules_docker",
commit = "968e0b7c8b3bc7e009531231ac926325cd2745bc",
)

load("@io_bazel_rules_docker//repositories:repositories.bzl", container_repositories = "repositories")

container_repositories()

# k8s repository infrastructure tools, k8s

git_repository(
name = "io_k8s_repo_infra",
remote = "https://github.com/kubernetes/repo-infra/",
Expand Down Expand Up @@ -83,6 +98,19 @@ go_repository(
build_file_proto_mode = "disable_global",
)

# debian packaging

http_archive(
name = "rules_pkg",
# TODO: update once the python 2/3 issues are worked out a bit
# url = "https://github.com/bazelbuild/rules_pkg/releases/download/0.2.0/rules_pkg-0.2.0.tar.gz",
# sha256 = "5bdc04987af79bd27bc5b00fe30f59a858f77ffa0bd2d8143d5b31ad8b1bd71c",
url = "https://github.com/bazelbuild/rules_pkg/releases/download/0.1.0/rules_pkg-0.1.0.tar.gz",
sha256 = "752146e2813f4c135ec9f71b592bf98f96f026049e6d65248534dbeccb2448e1",
)
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
rules_pkg_dependencies()

# debian ISO

http_file(
Expand Down Expand Up @@ -229,12 +257,24 @@ go_repository(
importpath = "github.com/modern-go/concurrent",
)

go_repository(
name = "org_golang_x_net",
commit = "da137c7871d730100384dbcf36e6f8fa493aef5b",
importpath = "golang.org/x/net",
)

go_repository(
name = "org_golang_x_oauth2",
commit = "a6bd8cefa1811bd24b86f8902872e4e8225f74c4",
importpath = "golang.org/x/oauth2",
)

go_repository(
name = "org_golang_x_text",
commit = "f21a4dfb5e38f5895301dc265a8def02365cc3d0", # 0.3.0
importpath = "golang.org/x/text",
)

go_repository(
name = "io_k8s_klog",
commit = "8e90cee79f823779174776412c13478955131846",
Expand All @@ -261,6 +301,12 @@ go_repository(

# keysystem dependencies

go_repository(
name = "org_golang_x_sys",
commit = "fae7ac547cb717d141c433a2a173315e216b64c4",
importpath = "golang.org/x/sys",
)

go_repository(
name = "org_golang_x_crypto",
commit = "88737f569e3a9c7ab309cdc09a07fe7fc87233c3",
Expand Down
8 changes: 4 additions & 4 deletions platform/bazel/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
native.py_binary(
py_binary(
name = "substitute",
srcs = ["substitute.py"],
visibility = ["//visibility:public"],
)

native.py_binary(
py_binary(
name = "version-compute",
srcs = ["version-compute.py"],
visibility = ["//visibility:public"],
)

native.py_binary(
py_binary(
name = "hash-compute",
srcs = ["hash-compute.py"],
visibility = ["//visibility:public"],
)

native.py_binary(
py_binary(
name = "cache-compute",
srcs = ["cache-compute.py"],
visibility = ["//visibility:public"],
Expand Down
2 changes: 1 addition & 1 deletion platform/bazel/hash-compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def sha256_file(f):
hashes = [sha256(b"".join(sha256(arg) for arg in args))]
for input in files:
if input == "--empty":
hashes.append("(empty)") # not a real hash, but we're going to hash it again, so it's okay
hashes.append(b"(empty)") # not a real hash, but we're going to hash it again, so it's okay
else:
with open(input, "rb") as f:
hashes.append(sha256_file(f))
Expand Down
2 changes: 1 addition & 1 deletion platform/bazel/package.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar", "pkg_deb")
load("@rules_pkg//:pkg.bzl", "pkg_tar", "pkg_deb")
load("//bazel:version.bzl", "hash_compute", "version_compute")
load("//bazel:oci_digest.bzl", "oci_digest")
load("@io_bazel_rules_docker//container:container.bzl", "container_image")
Expand Down
1 change: 0 additions & 1 deletion platform/bazel/version.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

def _escape(s):
return "'" + s.replace("$", "$$").replace("'", "'\"'\"'") + "'"

Expand Down
24 changes: 9 additions & 15 deletions platform/bazel/zip_file.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def collect_runfiles(targets):
Returns:
A list of Bazel files.
"""
data = depset()
data = []
for target in targets:
if hasattr(target, "runfiles"):
data += target.runfiles.files
Expand All @@ -156,18 +156,16 @@ def collect_runfiles(targets):
data += target.data_runfiles.files
if hasattr(target, "default_runfiles"):
data += target.default_runfiles.files
return data
return depset(data)

def _zip_file(ctx):
"""Implementation of zip_file() rule."""
for s, d in ctx.attr.mappings.items():
if (s.startswith("/") or s.endswith("/") or
d.startswith("/") or d.endswith("/")):
fail("mappings should not begin or end with slash")
srcs = depset()
srcs += ctx.files.srcs
srcs += ctx.files.data
srcs += collect_runfiles(ctx.attr.data)
srcs = depset(ctx.files.srcs + ctx.files.data,
transitive=[collect_runfiles(ctx.attr.data)]).to_list()
mapped = _map_sources(ctx, srcs, ctx.attr.mappings)
cmd = [
"#!/bin/sh",
Expand Down Expand Up @@ -203,16 +201,12 @@ def _zip_file(ctx):
'cd "${repo}"',
'rm -rf "${tmp}"',
]
if hasattr(ctx, "bin_dir"):
script = ctx.new_file(ctx.bin_dir, "%s.sh" % ctx.label.name)
else:
# TODO(kchodorow): remove this once Bazel 4.0+ is required.
script = ctx.new_file(ctx.configuration.bin_dir, "%s.sh" % ctx.label.name)
ctx.file_action(output = script, content = "\n".join(cmd), executable = True)
script = ctx.actions.declare_file("%s.sh" % ctx.label.name)
ctx.actions.write(output = script, content = "\n".join(cmd), is_executable = True)
inputs = [ctx.file._zipper]
inputs += [dep.zip_file for dep in ctx.attr.deps]
inputs += srcs.to_list()
ctx.action(
inputs += srcs
ctx.actions.run(
inputs = inputs,
outputs = [ctx.outputs.out],
executable = script,
Expand Down Expand Up @@ -281,6 +275,6 @@ zip_file = rule(
"deps": attr.label_list(providers = ["zip_file"]),
"exclude": attr.string_list(),
"mappings": attr.string_dict(),
"_zipper": attr.label(default = Label(ZIPPER), single_file = True),
"_zipper": attr.label(default = Label(ZIPPER), allow_single_file = True),
},
)