annotate gui_ze/gui_ze.bzl @ 37:fb9bcd3145cb

[ReactGames] Few games I made using react just to practice few things.
author MrJuneJune <me@mrjunejune.com>
date Mon, 01 Dec 2025 20:22:47 -0800
parents 342726584be2
children ccb42d5bf8fd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 """.format(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
79 outdir = out.dirname,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
80 src = ctx.files.srcs[0].path,
24
7d3fa1a7a854 [GuiZe] Support x86 chip for bun.
June Park <parkjune1995@gmail.com>
parents: 15
diff changeset
81 inner = ctx.attr.src_folder,
12
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
82 out = out.path,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
83 ),
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 return DefaultInfo(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
86 files = depset([out]),
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
87 executable = out,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
88 )
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 bun_binary = rule(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
91 implementation = _bun_binary_impl,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
92 attrs = {
25
342726584be2 [Bun] Fixed how bun would be ran within bazel.
June Park <parkjune1995@gmail.com>
parents: 24
diff changeset
93 "srcs": attr.label_list(allow_files=True),
342726584be2 [Bun] Fixed how bun would be ran within bazel.
June Park <parkjune1995@gmail.com>
parents: 24
diff changeset
94 "src_folder": attr.string(),
12
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
25
342726584be2 [Bun] Fixed how bun would be ran within bazel.
June Park <parkjune1995@gmail.com>
parents: 24
diff changeset
106 TODO: If possible, maybe create a node_module inside of the main target path and create a symlink
342726584be2 [Bun] Fixed how bun would be ran within bazel.
June Park <parkjune1995@gmail.com>
parents: 24
diff changeset
107 TODO: Add a specific path for node_modules
15
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/** . \
25
342726584be2 [Bun] Fixed how bun would be ran within bazel.
June Park <parkjune1995@gmail.com>
parents: 24
diff changeset
118 && cp -r {src_folder}/** . \
342726584be2 [Bun] Fixed how bun would be ran within bazel.
June Park <parkjune1995@gmail.com>
parents: 24
diff changeset
119 && export NODE_PATH=./node_modules && {bun_path} build {input_path} --outfile {output_path}
12
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
120 """.format(
25
342726584be2 [Bun] Fixed how bun would be ran within bazel.
June Park <parkjune1995@gmail.com>
parents: 24
diff changeset
121 bun_path = ctx.executable._bun.path,
342726584be2 [Bun] Fixed how bun would be ran within bazel.
June Park <parkjune1995@gmail.com>
parents: 24
diff changeset
122 src_folder = ctx.attr.src_folder,
342726584be2 [Bun] Fixed how bun would be ran within bazel.
June Park <parkjune1995@gmail.com>
parents: 24
diff changeset
123 input_path = ctx.file.src.path.split("/")[-1],
342726584be2 [Bun] Fixed how bun would be ran within bazel.
June Park <parkjune1995@gmail.com>
parents: 24
diff changeset
124 output_path = out.path,
12
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
125 ),
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
126 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
127 )
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
128
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
129 return [DefaultInfo(files=depset([out]))]
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
130
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
131 bun_build = rule(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
132 implementation = _bun_build_impl,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
133 attrs = {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
134 "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
135 "_bun": attr.label(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
136 default = Label("//third_party/bun:bun"),
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
137 executable = True,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
138 cfg = "exec",
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
139 ),
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
140 "data": attr.label_list(allow_files=True),
25
342726584be2 [Bun] Fixed how bun would be ran within bazel.
June Park <parkjune1995@gmail.com>
parents: 24
diff changeset
141 "src_folder": attr.string(),
12
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 )
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
144
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
145 def _move_files_into_dir_impl(ctx):
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
146 srcs = ctx.files.srcs
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
147 for src in srcs:
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
148 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
149 ctx.actions.symlink(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
150 output = out,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
151 target_file = src,
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 return [DefaultInfo(files = depset([out]))]
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
154
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
155 move_files_into_dir = rule(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
156 implementation = _move_files_into_dir_impl,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
157 attrs = {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
158 "srcs": attr.label_list(allow_files=True),
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
159 "dest": attr.string(),
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 )
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
162
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
163 def _move_to_directory_impl(ctx):
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
164 srcs = ctx.files.data
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
165 res = []
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
166 for src in srcs:
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
167 true = "/".join(src.path.split("/")[2:])
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
168 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
169 out = ctx.actions.declare_file(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
170 path
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
171 );
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
172 ctx.actions.symlink(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
173 output = out,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
174 target_file = src,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
175 )
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
176 res.append(out)
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
177 return [DefaultInfo(files = depset(res))]
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
178
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
179 move_to_directory = rule(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
180 implementation = _move_to_directory_impl,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
181 attrs = {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
182 "data": attr.label_list(allow_files=True),
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
183 "dest": attr.string(),
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
184 },
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
185 )