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

A few arguments construction cleanups #1621

Merged
merged 1 commit into from
Aug 1, 2018
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: 1 addition & 1 deletion extras/bindata.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def _bindata_impl(ctx):
arguments = ctx.actions.args()
arguments.add_all([
"-o",
out.path,
out,
"-pkg",
ctx.attr.package,
"-prefix",
Expand Down
11 changes: 9 additions & 2 deletions go/private/actions/compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ load(
"LINKMODE_C_SHARED",
"LINKMODE_PLUGIN",
)
load(
"@io_bazel_rules_go//go/private:skylib/lib/shell.bzl",
"shell",
)

def _importpath(v):
return v.data.importpath
Expand Down Expand Up @@ -97,7 +101,7 @@ def emit_compile(
)

def _bootstrap_compile(go, sources, out_lib, gc_goopts):
cmd = [go.go.path, "tool", "compile", "-trimpath", "$(pwd)"]
cmd = [shell.quote(go.go.path), "tool", "compile", "-trimpath", "\"$(pwd)\""]
args = go.actions.args()
args.add_all(["-o", out_lib])
args.add_all(gc_goopts)
Expand All @@ -107,5 +111,8 @@ def _bootstrap_compile(go, sources, out_lib, gc_goopts):
outputs = [out_lib],
arguments = [args],
mnemonic = "GoCompile",
command = "export GOROOT=$(pwd)/{} && export GOROOT_FINAL=GOROOT && {} \"$@\"".format(go.root, " ".join(cmd)),
command = "export GOROOT=\"$(pwd)\"/{} && {} \"$@\"".format(shell.quote(go.root), " ".join(cmd)),
env = {
"GOROOT_FINAL": "GOROOT",
},
)
22 changes: 16 additions & 6 deletions go/private/actions/link.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ load(
"LINKMODE_NORMAL",
"LINKMODE_PLUGIN",
)
load(
"@io_bazel_rules_go//go/private:skylib/lib/shell.bzl",
"shell",
)

def _format_archive(d):
return "{}={}={}".format(d.label, d.importmap, d.file.path)
Expand Down Expand Up @@ -156,16 +160,22 @@ def _bootstrap_link(go, archive, executable, gc_linkopts):
"""See go/toolchains.rst#link for full documentation."""

inputs = [archive.data.file] + go.sdk.libs + go.sdk.tools + [go.go]
args = ["tool", "link", "-s", "-linkmode", "internal", "-o", executable.path]
args.extend(gc_linkopts)
args.append(archive.data.file.path)
args = go.actions.args()
args.add_all(["tool", "link", "-s", "-linkmode", "internal", "-o", executable])
args.add_all(gc_linkopts)
args.add(archive.data.file)
go.actions.run_shell(
inputs = inputs,
outputs = [executable],
arguments = [args],
mnemonic = "GoLink",
# workaround: go link tool needs some features of gcc to complete the job on Arm platform.
# So, PATH for 'gcc' is required here on Arm platform.
command = "export GOROOT=$(pwd)/{} && export GOROOT_FINAL=GOROOT && export PATH={} && {} {}".format(go.root, go.cgo_tools.compiler_path, go.go.path, " ".join(args)),
command = "export GOROOT=\"$(pwd)\"/{} && {} \"$@\"".format(shell.quote(go.root), shell.quote(go.go.path)),
env = {
# workaround: go link tool needs some features of gcc to complete the job on Arm platform.
# So, PATH for 'gcc' is required here on Arm platform.
"PATH": go.cgo_tools.compiler_path,
"GOROOT_FINAL": "GOROOT",
},
)

def _extract_extldflags(gc_linkopts, extldflags):
Expand Down
2 changes: 1 addition & 1 deletion go/private/rules/stdlib.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _build_stdlib(go, attr):
args.add("-shared")
if go.mode.link == LINKMODE_PLUGIN:
args.add("-dynlink")
args.add_all(["-filter_buildid", filter_buildid.path])
args.add_all(["-filter_buildid", filter_buildid])
go.actions.write(root_file, "")
env = go.env
env.update({
Expand Down
17 changes: 9 additions & 8 deletions go/private/tools/path.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ def _go_path_impl(ctx):
# Execute the builder
if ctx.attr.mode == "archive":
out = ctx.actions.declare_file(ctx.label.name + ".zip")
out_path = out.path
out_path = out
out_short_path = out.short_path
outputs = [out]
out_file = out
elif ctx.attr.mode == "copy":
out = ctx.actions.declare_directory(ctx.label.name)
out_path = out.path
out_path = out
out_short_path = out.short_path
outputs = [out]
out_file = out
Expand All @@ -128,17 +128,18 @@ def _go_path_impl(ctx):
out_path = tag.dirname
out_short_path = tag.short_path.rpartition("/")[0]
out_file = tag
args = [
"-manifest=" + manifest_file.path,
"-out=" + out_path,
"-mode=" + ctx.attr.mode,
]
args = ctx.actions.args()
args.add_all([
"-manifest", manifest_file,
"-out", out_path,
"-mode", ctx.attr.mode,
])
ctx.actions.run(
outputs = outputs,
inputs = inputs,
mnemonic = "GoPath",
executable = ctx.executable._go_path,
arguments = args,
arguments = [args],
)

return [
Expand Down
2 changes: 1 addition & 1 deletion tests/bazel_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def _md5_sum_impl(ctx):
go = go_context(ctx)
out = go.declare_file(go, ext = ".md5")
arguments = ctx.actions.args()
arguments.add_all(["-output", out.path])
arguments.add_all(["-output", out])
arguments.add_all(ctx.files.srcs)
ctx.actions.run(
inputs = ctx.files.srcs,
Expand Down