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

Allow setting build tags per target #201

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
12 changes: 9 additions & 3 deletions build_defs/go.build_defs
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,7 @@ def _module_rule_name(module):

def go_repo(module: str, version:str='', download:str=None, name:str=None, install:list=[], requirements:list=[],
licences:list=None, patch:list=None, visibility:list=["PUBLIC"], deps:list=[],
third_party_path:str="third_party/go", strip:list=None):
third_party_path:str="third_party/go", strip:list=None, build_tags:list=[]):
"""Adds a third party go module to the build graph as a subrepo. This is designed to be closer to how the `go.mod`
file works, requiring only the module name and version to be specified. Unlike go_module, each package is compiled
individually, and dependencies between packages are inferred by convention.
Expand Down Expand Up @@ -1185,6 +1185,8 @@ def go_repo(module: str, version:str='', download:str=None, name:str=None, insta
migrate to go_repo incrementally, one module at a time.
third_party_path(str): Optional path of third_party directory.
strip(list): A list of directories to strip from the repo
build_tags(list): A list of build tags to pass to the go compiler. Will override any build tags set in the
plzconfig.
"""
subrepo_name = _module_rule_name(module)

Expand Down Expand Up @@ -1219,13 +1221,17 @@ def go_repo(module: str, version:str='', download:str=None, name:str=None, insta
labels += [f"go_module:{module}@{version}"]
requirements = " ".join(requirements)

build_tags = '--build_tag ' + ' --build_tag '.join(CONFIG.GO.BUILD_TAGS) if CONFIG.GO.BUILD_TAGS else ''
build_tags_args = ''
if build_tags:
build_tags_args = ' '.join([f'--build_tag={tag}' for tag in build_tags])
elif CONFIG.GO.BUILD_TAGS:
build_tags_args = ' '.join([f'--build_tag={tag}' for tag in CONFIG.GO.BUILD_TAGS])

repo = build_rule(
name = name,
tag = "repo" if install else None,
srcs = srcs,
cmd = f"rm -rf $SRCS_DOWNLOAD/.plzconfig && find $SRCS_DOWNLOAD -name BUILD -delete && $TOOL generate {modFileArg} --module {module} --version '{version}' {build_tags} --src_root=$SRCS_DOWNLOAD --third_part_folder='{third_party_path}' {install_args} {requirements} && mv $SRCS_DOWNLOAD $OUT",
cmd = f"rm -rf $SRCS_DOWNLOAD/.plzconfig && find $SRCS_DOWNLOAD -name BUILD -delete && $TOOL generate {modFileArg} --module {module} --version '{version}' {build_tags_args} --src_root=$SRCS_DOWNLOAD --third_part_folder='{third_party_path}' {install_args} {requirements} && mv $SRCS_DOWNLOAD $OUT",
outs = [subrepo_name],
tools = [CONFIG.GO.PLEASE_GO_TOOL],
env= {
Expand Down
Loading