Mercurial
annotate gui_ze/gui_ze.bzl @ 22:947b81010aba
[Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Tue, 07 Oct 2025 07:11:02 -0700 |
| parents | 2b9e75756825 |
| children | 7d3fa1a7a854 |
| rev | line source |
|---|---|
|
8
98f96b8032e5
[GuiZe] Creating custom bazel rule to deploy to github easily.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
1 def _foo_impl(ctx): |
|
12
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
2 out = ctx.actions.declare_file(ctx.label.name) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
3 ctx.actions.write( |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
4 output = out, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
5 content = "Hello!\n", |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
6 ) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
7 return [DefaultInfo(files = depset([out]))] |
|
8
98f96b8032e5
[GuiZe] Creating custom bazel rule to deploy to github easily.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
8 |
|
98f96b8032e5
[GuiZe] Creating custom bazel rule to deploy to github easily.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
9 foo_binary = rule( |
|
98f96b8032e5
[GuiZe] Creating custom bazel rule to deploy to github easily.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
10 implementation = _foo_impl, |
|
98f96b8032e5
[GuiZe] Creating custom bazel rule to deploy to github easily.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
11 ) |
|
98f96b8032e5
[GuiZe] Creating custom bazel rule to deploy to github easily.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
12 |
|
12
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
13 |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
14 def _bundle_impl(ctx): |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
15 """ |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
16 bundle binary target into a folder which can later be used to make a post to github easily. |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
17 """ |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
18 binary_target = ctx.attr.binary |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
19 binary = binary_target[DefaultInfo].files.to_list()[0] # First files are binary |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
20 runfiles_files = binary_target[DefaultInfo].default_runfiles.files.to_list() |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
21 |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
22 # Name as output directory |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
23 out_dir = ctx.actions.declare_directory(ctx.label.name) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
24 |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
25 copy_cmd = [] |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
26 copy_cmd.append("mkdir -p {}".format(out_dir.path)) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
27 |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
28 for f in runfiles_files: |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
29 if f.path == binary.path: |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
30 continue |
|
15
2b9e75756825
[GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents:
12
diff
changeset
|
31 |
|
2b9e75756825
[GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents:
12
diff
changeset
|
32 start = 0 |
|
2b9e75756825
[GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents:
12
diff
changeset
|
33 for directory in f.path.split("/"): |
|
2b9e75756825
[GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents:
12
diff
changeset
|
34 if directory == binary.short_path.split("/")[0]: |
|
2b9e75756825
[GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents:
12
diff
changeset
|
35 break |
|
2b9e75756825
[GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents:
12
diff
changeset
|
36 print("\n\n equals: ", directory, binary.short_path.split("/")[0]); |
|
2b9e75756825
[GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents:
12
diff
changeset
|
37 start += 1 |
|
2b9e75756825
[GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents:
12
diff
changeset
|
38 |
|
12
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
39 # Remove the first folder (output) and last file (actaul files that needed to be copied) |
|
15
2b9e75756825
[GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents:
12
diff
changeset
|
40 paths = "/".join(f.path.split("/")[start:-1]) |
|
12
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
41 full_path = "{}/{}".format(out_dir.path, paths) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
42 copy_cmd.append("mkdir -p {}".format(full_path)) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
43 copy_cmd.append("cp {} {}".format(f.path, full_path)) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
44 |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
45 copy_cmd.append("cp {} {}".format(binary.path, out_dir.path)) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
46 |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
47 ctx.actions.run_shell( |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
48 inputs = runfiles_files, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
49 outputs = [out_dir], |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
50 command = " && ".join(copy_cmd), |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
51 progress_message = "Bundling {}".format(ctx.label.name), |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
52 ) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
53 |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
54 print("[INFO] See {}".format(out_dir.path)) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
55 |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
56 return [DefaultInfo(files = depset([out_dir]))] |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
57 |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
58 bundle = rule( |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
59 implementation = _bundle_impl, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
60 attrs = { |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
61 "binary": attr.label( |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
62 doc = "The cc_binary target to bundle", |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
63 providers = [DefaultInfo], |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
64 ), |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
65 }, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
66 ) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
67 |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
68 |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
69 def _bun_binary_impl(ctx): |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
70 out = ctx.actions.declare_file("bun") |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
71 ctx.actions.run_shell( |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
72 inputs = ctx.files.srcs, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
73 outputs = [out], |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
74 command = """ |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
75 mkdir -p {outdir} |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
76 unzip -j {src} {inner} -d {outdir} |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
77 chmod +x {outdir}/bun |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
78 mv {outdir}/bun {out} |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
79 """.format( |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
80 outdir = out.dirname, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
81 src = ctx.files.srcs[0].path, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
82 inner = "bun-darwin-aarch64/bun", |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
83 out = out.path, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
84 ), |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
85 ) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
86 return DefaultInfo( |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
87 files = depset([out]), |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
88 executable = out, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
89 ) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
90 |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
91 bun_binary = rule( |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
92 implementation = _bun_binary_impl, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
93 attrs = { |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
94 "srcs": attr.label_list(allow_files=True), |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
95 }, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
96 executable = True, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
97 ) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
98 |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
99 def _bun_build_impl(ctx): |
|
15
2b9e75756825
[GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents:
12
diff
changeset
|
100 """ |
|
2b9e75756825
[GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents:
12
diff
changeset
|
101 Run bun build on the folder |
|
2b9e75756825
[GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents:
12
diff
changeset
|
102 |
|
2b9e75756825
[GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents:
12
diff
changeset
|
103 This sucks because you need to either copy node module into the root folder where main.ts file |
|
2b9e75756825
[GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents:
12
diff
changeset
|
104 exists or copy everything outwards. I chose to do it in this way. |
|
2b9e75756825
[GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents:
12
diff
changeset
|
105 |
|
2b9e75756825
[GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents:
12
diff
changeset
|
106 TODO: If possible, maybe create a node_module inside of the main target path and create a symlink, |
|
2b9e75756825
[GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents:
12
diff
changeset
|
107 but I couldn't get it to work lol. |
|
2b9e75756825
[GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents:
12
diff
changeset
|
108 """ |
|
12
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
109 out = ctx.actions.declare_file(ctx.label.name + ".js") |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
110 inputs = [ctx.file.src] + ctx.files.data |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
111 |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
112 ctx.actions.run_shell( |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
113 inputs = inputs, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
114 outputs = [out], |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
115 tools = [ctx.executable._bun] + inputs, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
116 command = """ |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
117 cp -r third_party/bun/** . \ |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
118 && cp -r playground/** . \ |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
119 && {} build {} --outfile {} |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
120 """.format( |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
121 ctx.executable._bun.path, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
122 ctx.file.src.path.split("/")[-1], |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
123 out.path, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
124 ), |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
125 progress_message = "Bundling {} with Bun!\n\n".format(ctx.file.src.path), |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
126 ) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
127 |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
128 return [DefaultInfo(files=depset([out]))] |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
129 |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
130 bun_build = rule( |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
131 implementation = _bun_build_impl, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
132 attrs = { |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
133 "src": attr.label(allow_single_file = [".ts", ".tsx", ".js", ".jsx"]), |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
134 "_bun": attr.label( |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
135 default = Label("//third_party/bun:bun"), |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
136 executable = True, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
137 cfg = "exec", |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
138 ), |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
139 "data": attr.label_list(allow_files=True), |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
140 }, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
141 ) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
142 |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
143 def _move_files_into_dir_impl(ctx): |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
144 srcs = ctx.files.srcs |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
145 for src in srcs: |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
146 out = ctx.actions.declare_file(ctx.attr.dest + "/" + src.basename) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
147 ctx.actions.symlink( |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
148 output = out, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
149 target_file = src, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
150 ) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
151 return [DefaultInfo(files = depset([out]))] |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
152 |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
153 move_files_into_dir = rule( |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
154 implementation = _move_files_into_dir_impl, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
155 attrs = { |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
156 "srcs": attr.label_list(allow_files=True), |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
157 "dest": attr.string(), |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
158 }, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
159 ) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
160 |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
161 def _move_to_directory_impl(ctx): |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
162 srcs = ctx.files.data |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
163 res = [] |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
164 for src in srcs: |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
165 true = "/".join(src.path.split("/")[2:]) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
166 path = ctx.attr.dest + "/" + true if ctx.attr.dest != "" else true |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
167 out = ctx.actions.declare_file( |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
168 path |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
169 ); |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
170 ctx.actions.symlink( |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
171 output = out, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
172 target_file = src, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
173 ) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
174 res.append(out) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
175 return [DefaultInfo(files = depset(res))] |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
176 |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
177 move_to_directory = rule( |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
178 implementation = _move_to_directory_impl, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
179 attrs = { |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
180 "data": attr.label_list(allow_files=True), |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
181 "dest": attr.string(), |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
182 }, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
183 ) |