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

feat(build): allow use local path to replace git repositories #12881

Merged
merged 1 commit into from
Apr 19, 2024
Merged
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
2 changes: 2 additions & 0 deletions .requirements
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ OPENSSL=3.2.1
PCRE=10.43
LIBEXPAT=2.5.0

# Note: git repositories can be loaded from local path if path is set as value

LUA_KONG_NGINX_MODULE=691ba795ced07364d491e8abbdf0c8c8d3778c14 # 0.10.0
LUA_RESTY_LMDB=7d2581cbe30cde18a8482d820c227ca0845c0ded # 1.4.2
LUA_RESTY_EVENTS=8448a92cec36ac04ea522e78f6496ba03c9b1fd8 # 0.2.0
Expand Down
27 changes: 27 additions & 0 deletions build/build_system.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ and rules that you'd like to use in your BUILD files.
"""

load("@bazel_skylib//lib:dicts.bzl", "dicts")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository", "new_git_repository")
load("@kong_bindings//:variables.bzl", "KONG_VAR")

# A genrule variant that can output a directory.
Expand Down Expand Up @@ -208,3 +209,29 @@ github_release = repository_rule(
"skip_add_copyright_header": attr.bool(default = False, doc = "Whether to inject COPYRIGHT-HEADER into downloaded files, only required for webuis"),
},
)

def git_or_local_repository(name, branch, **kwargs):
new_repo = "build_file" in kwargs or "build_file_content" in kwargs
if branch.startswith("/") or branch.startswith("."):
print("Note @%s is initialized as a local repository from path %s" % (name, branch))

func = new_repo and native.new_local_repository or native.local_repository
func(
name = name,
path = branch,
build_file = kwargs.get("build_file"),
build_file_content = kwargs.get("build_file_content"),
)
else:
func = new_repo and new_git_repository or git_repository

# if "branch" is likely a commit hash, use it as commit
if branch.isalnum() and len(branch) == 40:
kwargs["commit"] = branch
branch = None

func(
name = name,
branch = branch,
**kwargs
)
6 changes: 2 additions & 4 deletions build/openresty/atc_router/atc_router_repositories.bzl
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
"""A module defining the dependency atc-router"""

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("//build:build_system.bzl", "git_or_local_repository")
load("@kong_bindings//:variables.bzl", "KONG_VAR")

def atc_router_repositories():
maybe(
git_repository,
git_or_local_repository(
name = "atc_router",
branch = KONG_VAR["ATC_ROUTER"],
remote = "https://github.com/Kong/atc-router",
Expand Down
4 changes: 2 additions & 2 deletions build/openresty/brotli/brotli_repositories.bzl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""A module defining the dependency """

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
load("//build:build_system.bzl", "git_or_local_repository")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("@kong_bindings//:variables.bzl", "KONG_VAR")

def brotli_repositories():
maybe(
git_repository,
git_or_local_repository,
name = "brotli",
branch = KONG_VAR["BROTLI"],
remote = "https://github.com/google/brotli",
Expand Down
10 changes: 5 additions & 5 deletions build/openresty/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository")
load("//build:build_system.bzl", "git_or_local_repository")
load("@kong_bindings//:variables.bzl", "KONG_VAR")
load("//build/openresty/pcre:pcre_repositories.bzl", "pcre_repositories")
load("//build/openresty/openssl:openssl_repositories.bzl", "openssl_repositories")
Expand Down Expand Up @@ -43,7 +43,7 @@ def openresty_repositories():
)

maybe(
new_git_repository,
git_or_local_repository,
name = "lua-kong-nginx-module",
branch = KONG_VAR["LUA_KONG_NGINX_MODULE"],
remote = "https://github.com/Kong/lua-kong-nginx-module",
Expand All @@ -52,7 +52,7 @@ def openresty_repositories():
)

maybe(
new_git_repository,
git_or_local_repository,
name = "lua-resty-lmdb",
branch = KONG_VAR["LUA_RESTY_LMDB"],
remote = "https://github.com/Kong/lua-resty-lmdb",
Expand All @@ -63,7 +63,7 @@ def openresty_repositories():
)

maybe(
new_git_repository,
git_or_local_repository,
name = "lua-resty-events",
branch = KONG_VAR["LUA_RESTY_EVENTS"],
remote = "https://github.com/Kong/lua-resty-events",
Expand All @@ -72,7 +72,7 @@ def openresty_repositories():
)

maybe(
new_git_repository,
git_or_local_repository,
name = "ngx_brotli",
branch = KONG_VAR["NGX_BROTLI"],
remote = "https://github.com/google/ngx_brotli",
Expand Down
4 changes: 2 additions & 2 deletions build/openresty/wasmx/wasmx_repositories.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""A module defining the third party dependency WasmX"""

load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository")
load("//build:build_system.bzl", "git_or_local_repository")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@kong_bindings//:variables.bzl", "KONG_VAR")

Expand Down Expand Up @@ -57,7 +57,7 @@ def wasmx_repositories():
if wasm_module_branch == "":
wasm_module_branch = KONG_VAR["NGX_WASM_MODULE"]

new_git_repository(
git_or_local_repository(
name = "ngx_wasmx_module",
branch = wasm_module_branch,
remote = KONG_VAR["NGX_WASM_MODULE_REMOTE"],
Expand Down
4 changes: 2 additions & 2 deletions build/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository")
load("//build:build_system.bzl", "git_or_local_repository")
load("//build/luarocks:luarocks_repositories.bzl", "luarocks_repositories")
load("//build/cross_deps:repositories.bzl", "cross_deps_repositories")
load("//build/libexpat:repositories.bzl", "libexpat_repositories")
Expand Down Expand Up @@ -67,7 +67,7 @@ filegroup(
)

def kong_resty_websocket_repositories():
new_git_repository(
git_or_local_repository(
name = "lua-resty-websocket",
branch = KONG_VAR["LUA_RESTY_WEBSOCKET"],
remote = "https://github.com/Kong/lua-resty-websocket",
Expand Down
Loading