Skip to content

Commit

Permalink
inv *.set-buildtags sets all the build tags (#27050)
Browse files Browse the repository at this point in the history
  • Loading branch information
L3n41c committed Jun 28, 2024
1 parent 8ae0943 commit 1248ec4
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 41 deletions.
45 changes: 29 additions & 16 deletions tasks/emacs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,24 @@

from invoke import task

from tasks.build_tags import build_tags, filter_incompatible_tags, get_build_tags, get_default_build_tags
from tasks.build_tags import (
build_tags,
filter_incompatible_tags,
get_build_tags,
get_default_build_tags,
)
from tasks.flavor import AgentFlavor


@task
@task(
help={
"targets": f"Comma separated list of targets to include. Possible values: all, {', '.join(build_tags[AgentFlavor.base].keys())}. Default: all",
"flavor": f"Agent flavor to use. Possible values: {', '.join(AgentFlavor.__members__.keys())}. Default: {AgentFlavor.base.name}",
}
)
def set_buildtags(
_,
target="agent",
targets="all",
build_include=None,
build_exclude=None,
flavor=AgentFlavor.base.name,
Expand All @@ -23,21 +33,24 @@ def set_buildtags(
"""
flavor = AgentFlavor[flavor]

if target not in build_tags[flavor]:
print("Must choose a valid target. Valid targets are: \n")
print(f'{", ".join(build_tags[flavor].keys())} \n')
return
if targets == "all":
targets = build_tags[flavor].keys()
else:
targets = targets.split(",")
if not set(targets).issubset(build_tags[flavor]):
print("Must choose valid targets. Valid targets are:")
print(f'{", ".join(build_tags[flavor].keys())}')
return

if build_include is None:
build_include = []
for target in targets:
build_include.extend(get_default_build_tags(build=target, flavor=flavor))
else:
build_include = filter_incompatible_tags(build_include.split(","))

build_include = (
get_default_build_tags(build=target, flavor=flavor)
if build_include is None
else filter_incompatible_tags(build_include.split(","))
)
build_exclude = [] if build_exclude is None else build_exclude.split(",")
use_tags = get_build_tags(build_include, build_exclude)

with open(".dir-locals.el", "w") as f:
f.write(f'((go-mode . ((lsp-go-build-flags . ["-tags", "{",".join(use_tags)}"])\n')
f.write(
' (eval . (lsp-register-custom-settings \'(("gopls.allowImplicitNetworkAccess" t t)))))))\n'
)
f.write(f'((go-mode . ((lsp-go-build-flags . ["-tags" "{",".join(sorted(use_tags))}"]))))\n')
35 changes: 23 additions & 12 deletions tasks/vim.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@
from tasks.flavor import AgentFlavor


@task
@task(
help={
"targets": f"Comma separated list of targets to include. Possible values: all, {', '.join(build_tags[AgentFlavor.base].keys())}. Default: all",
"flavor": f"Agent flavor to use. Possible values: {', '.join(AgentFlavor.__members__.keys())}. Default: {AgentFlavor.base.name}",
}
)
def set_buildtags(
_,
target="agent",
targets="all",
build_include=None,
build_exclude=None,
flavor=AgentFlavor.base.name,
Expand All @@ -28,18 +33,24 @@ def set_buildtags(
"""
flavor = AgentFlavor[flavor]

if target not in build_tags[flavor]:
print("Must choose a valid target. Valid targets are: \n")
print(f'{", ".join(build_tags[flavor].keys())} \n')
return
if targets == "all":
targets = build_tags[flavor].keys()
else:
targets = targets.split(",")
if not set(targets).issubset(build_tags[flavor]):
print("Must choose valid targets. Valid targets are:")
print(f'{", ".join(build_tags[flavor].keys())}')
return

if build_include is None:
build_include = []
for target in targets:
build_include.extend(get_default_build_tags(build=target, flavor=flavor))
else:
build_include = filter_incompatible_tags(build_include.split(","))

build_include = (
get_default_build_tags(build=target, flavor=flavor)
if build_include is None
else filter_incompatible_tags(build_include.split(","))
)
build_exclude = [] if build_exclude is None else build_exclude.split(",")
use_tags = get_build_tags(build_include, build_exclude)

with open(".vimrc", "w") as f:
f.write(f"let g:ale_go_gopls_init_options = {{'buildFlags': ['-tags', '{','.join(use_tags)}']}}\n")
f.write(f"let g:ale_go_gopls_init_options = {{'buildFlags': ['-tags', '{','.join(sorted(use_tags))}']}}\n")
42 changes: 29 additions & 13 deletions tasks/vscode.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
from invoke import Context, task
from invoke.exceptions import Exit

from tasks.build_tags import build_tags, filter_incompatible_tags, get_build_tags, get_default_build_tags
from tasks.build_tags import (
build_tags,
filter_incompatible_tags,
get_build_tags,
get_default_build_tags,
)
from tasks.flavor import AgentFlavor
from tasks.libs.common.color import Color, color_message
from tasks.libs.json import JSONWithCommentsDecoder
Expand All @@ -25,10 +30,15 @@
VSCODE_EXTENSIONS_FILE = "extensions.json"


@task
@task(
help={
"targets": f"Comma separated list of targets to include. Possible values: all, {', '.join(build_tags[AgentFlavor.base].keys())}. Default: all",
"flavor": f"Agent flavor to use. Possible values: {', '.join(AgentFlavor.__members__.keys())}. Default: {AgentFlavor.base.name}",
}
)
def set_buildtags(
_,
target="agent",
targets="all",
build_include=None,
build_exclude=None,
flavor=AgentFlavor.base.name,
Expand All @@ -38,16 +48,22 @@ def set_buildtags(
"""
flavor = AgentFlavor[flavor]

if target not in build_tags[flavor]:
print("Must choose a valid target. Valid targets are: \n")
print(f'{", ".join(build_tags[flavor].keys())} \n')
return
if targets == "all":
targets = build_tags[flavor].keys()
else:
targets = targets.split(",")
if not set(targets).issubset(build_tags[flavor]):
print("Must choose valid targets. Valid targets are:")
print(f'{", ".join(build_tags[flavor].keys())}')
return

if build_include is None:
build_include = []
for target in targets:
build_include.extend(get_default_build_tags(build=target, flavor=flavor))
else:
build_include = filter_incompatible_tags(build_include.split(","))

build_include = (
get_default_build_tags(build=target, flavor=flavor)
if build_include is None
else filter_incompatible_tags(build_include.split(","))
)
build_exclude = [] if build_exclude is None else build_exclude.split(",")
use_tags = get_build_tags(build_include, build_exclude)

Expand All @@ -60,7 +76,7 @@ def set_buildtags(
with open(fullpath) as sf:
settings = json.load(sf, object_pairs_hook=OrderedDict)

settings["go.buildTags"] = ",".join(use_tags)
settings["go.buildTags"] = ",".join(sorted(use_tags))

with open(fullpath, "w") as sf:
json.dump(settings, sf, indent=4, sort_keys=False, separators=(',', ': '))
Expand Down

0 comments on commit 1248ec4

Please sign in to comment.