-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrunfile.bzl
112 lines (89 loc) · 3.21 KB
/
runfile.bzl
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
runfile_template = """{{
"name": "{name}",
"lastName": "Smith",
"isAlive": true,
"age": 27,
"address": {{
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": "10021-3100"
}},
"phoneNumbers": [
{{
"type": "home",
"number": "212 555-1234"
}},
{{
"type": "office",
"number": "646 555-4567"
}},
{{
"type": "mobile",
"number": "123 456-7890"
}}
],
"children": [],
"spouse": null
}}
"""
common_runfiles_args = {
"collect_data": True,
"collect_default": True,
}
def _runfile_impl(ctx):
out = ctx.actions.declare_file("{name}.json".format(name = ctx.attr.name))
content = runfile_template.format(name = ctx.attr.name)
ctx.actions.write(output = out, content = content)
runfiles = ctx.runfiles(files = [out], **common_runfiles_args)
return DefaultInfo(runfiles = runfiles)
runfile = rule(
attrs = {},
implementation = _runfile_impl,
)
def _default_runfile_impl(ctx):
out = ctx.actions.declare_file("{name}.json".format(name = ctx.attr.name))
content = runfile_template.format(name = ctx.attr.name)
ctx.actions.write(output = out, content = content)
runfiles = ctx.runfiles(files = [out], **common_runfiles_args)
return DefaultInfo(default_runfiles = runfiles)
default_runfile = rule(
attrs = {},
implementation = _default_runfile_impl,
)
def _data_runfile_impl(ctx):
out = ctx.actions.declare_file("{name}.json".format(name = ctx.attr.name))
content = runfile_template.format(name = ctx.attr.name)
ctx.actions.write(output = out, content = content)
runfiles = ctx.runfiles(files = [out], **common_runfiles_args)
return DefaultInfo(data_runfiles = runfiles)
data_runfile = rule(
attrs = {},
implementation = _data_runfile_impl,
)
def _runfile_symlinks_impl(ctx):
out = ctx.actions.declare_file("{name}.json".format(name = ctx.attr.name))
content = runfile_template.format(name = ctx.attr.name)
ctx.actions.write(output = out, content = content)
linked_file = ctx.actions.declare_file("sub_folder/{name}.json".format(name = ctx.attr.name))
content = runfile_template.format(name = ctx.attr.name)
ctx.actions.write(output = linked_file, content = content)
runfiles = ctx.runfiles(symlinks = {"{name}_link".format(name = ctx.attr.name): linked_file}, **common_runfiles_args)
return DefaultInfo(runfiles = runfiles)
runfile_symlinks = rule(
attrs = {},
implementation = _runfile_symlinks_impl,
)
def _runfile_root_symlinks_impl(ctx):
out = ctx.actions.declare_file("{name}.json".format(name = ctx.attr.name))
content = runfile_template.format(name = ctx.attr.name)
ctx.actions.write(output = out, content = content)
linked_file = ctx.actions.declare_file("sub_folder/{name}.json".format(name = ctx.attr.name))
content = runfile_template.format(name = ctx.attr.name)
ctx.actions.write(output = linked_file, content = content)
runfiles = ctx.runfiles(root_symlinks = {"{name}_root_link".format(name = ctx.attr.name): linked_file}, **common_runfiles_args)
return DefaultInfo(runfiles = runfiles)
runfile_root_symlinks = rule(
attrs = {},
implementation = _runfile_root_symlinks_impl,
)