This repository was archived by the owner on Jun 27, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgo_link.bzl
More file actions
72 lines (63 loc) · 1.9 KB
/
Copy pathgo_link.bzl
File metadata and controls
72 lines (63 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""Golink rule for copying files into the workspace."""
load("@bazel_skylib//lib:shell.bzl", "shell")
def gen_copy_files_script(ctx, files, **kwargs):
""" Generates a script to copy files into the workspace.
Args:
ctx: The context object.
files: The files to copy.
**kwargs: Additional arguments.
Returns:
A list of DefaultInfo objects.
"""
content = ""
for f in files:
line = "cp -f .bazel/%s %s/;\n" % (f.path, ctx.attr.dir)
content += line
substitutions = {
"@@CONTENT@@": shell.quote(content),
}
out = ctx.actions.declare_file(ctx.label.name + ".sh")
ctx.actions.expand_template(
template = ctx.file._template,
output = out,
substitutions = substitutions,
is_executable = True,
)
runfiles = ctx.runfiles(files = [files[0]])
return [
DefaultInfo(
files = depset([out]),
runfiles = runfiles,
executable = out,
**kwargs
),
]
def go_link_impl(ctx, **kwargs):
"""Implementation of the go_link rule.
This rule copies the files from the dependency into the workspace.
Args:
ctx: The context object.
**kwargs: Additional arguments.
Returns:
A DefaultInfo object.
"""
return gen_copy_files_script(ctx, ctx.files.dep, **kwargs)
_go_link = rule(
implementation = go_link_impl,
executable = True,
attrs = {
"dir": attr.string(),
"dep": attr.label(),
"_template": attr.label(
default = ":copy_into_workspace.sh",
allow_single_file = True,
),
# It is not used, just used for versioning since this is experimental
"version": attr.string(),
},
)
def go_link(name, **kwargs):
if not "dir" in kwargs:
dir = native.package_name()
kwargs["dir"] = dir
_go_link(name = name, **kwargs)