annotate gui_ze/gui_ze.bzl @ 70:4bc56e88e1f3

Remove unnecessary files.
author June Park <parkjune1995@gmail.com>
date Thu, 25 Dec 2025 20:10:46 -0800
parents a30944e5719e
children 7eb79fd91c7e
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 def _bundle_impl(ctx):
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
14 """
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
15 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
16 """
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
17 binary_target = ctx.attr.binary
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
18 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
19 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
20
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
21 # Name as output directory
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
22 out_dir = ctx.actions.declare_directory(ctx.label.name)
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
23
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
24 copy_cmd = []
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
25 copy_cmd.append("mkdir -p {}".format(out_dir.path))
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
26
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
27 for f in runfiles_files:
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
28 if f.path == binary.path:
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
29 continue
15
2b9e75756825 [GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents: 12
diff changeset
30
2b9e75756825 [GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents: 12
diff changeset
31 start = 0
2b9e75756825 [GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents: 12
diff changeset
32 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
33 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
34 break
2b9e75756825 [GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents: 12
diff changeset
35 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
36 start += 1
2b9e75756825 [GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents: 12
diff changeset
37
12
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
38 # 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
39 paths = "/".join(f.path.split("/")[start:-1])
12
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
40 full_path = "{}/{}".format(out_dir.path, paths)
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
41 copy_cmd.append("mkdir -p {}".format(full_path))
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
42 copy_cmd.append("cp {} {}".format(f.path, full_path))
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
43
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
44 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
45
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
46 ctx.actions.run_shell(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
47 inputs = runfiles_files,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
48 outputs = [out_dir],
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
49 command = " && ".join(copy_cmd),
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
50 progress_message = "Bundling {}".format(ctx.label.name),
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
51 )
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 print("[INFO] See {}".format(out_dir.path))
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
54
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
55 return [DefaultInfo(files = depset([out_dir]))]
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
56
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
57 bundle = rule(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
58 implementation = _bundle_impl,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
59 attrs = {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
60 "binary": attr.label(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
61 doc = "The cc_binary target to bundle",
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
62 providers = [DefaultInfo],
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
63 ),
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 def _bun_binary_impl(ctx):
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
69 out = ctx.actions.declare_file("bun")
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
70 ctx.actions.run_shell(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
71 inputs = ctx.files.srcs,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
72 outputs = [out],
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
73 command = """
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
74 mkdir -p {outdir}
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
75 unzip -j {src} {inner} -d {outdir}
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
76 chmod +x {outdir}/bun
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
77 """.format(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
78 outdir = out.dirname,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
79 src = ctx.files.srcs[0].path,
24
7d3fa1a7a854 [GuiZe] Support x86 chip for bun.
June Park <parkjune1995@gmail.com>
parents: 15
diff changeset
80 inner = ctx.attr.src_folder,
12
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
81 out = out.path,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
82 ),
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 return DefaultInfo(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
85 files = depset([out]),
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
86 executable = out,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
87 )
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 bun_binary = rule(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
90 implementation = _bun_binary_impl,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
91 attrs = {
25
342726584be2 [Bun] Fixed how bun would be ran within bazel.
June Park <parkjune1995@gmail.com>
parents: 24
diff changeset
92 "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
93 "src_folder": attr.string(),
12
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
94 },
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
95 executable = True,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
96 )
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 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
99 """
2b9e75756825 [GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents: 12
diff changeset
100 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
101
2b9e75756825 [GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents: 12
diff changeset
102 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
103 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
104
25
342726584be2 [Bun] Fixed how bun would be ran within bazel.
June Park <parkjune1995@gmail.com>
parents: 24
diff changeset
105 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
106 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
107 """
12
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
108 out = ctx.actions.declare_file(ctx.label.name + ".js")
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
109 inputs = [ctx.file.src] + ctx.files.data
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
110
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
111 ctx.actions.run_shell(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
112 inputs = inputs,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
113 outputs = [out],
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
114 tools = [ctx.executable._bun] + inputs,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
115 command = """
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
116 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
117 && cp -r {src_folder}/** . \
342726584be2 [Bun] Fixed how bun would be ran within bazel.
June Park <parkjune1995@gmail.com>
parents: 24
diff changeset
118 && 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
119 """.format(
25
342726584be2 [Bun] Fixed how bun would be ran within bazel.
June Park <parkjune1995@gmail.com>
parents: 24
diff changeset
120 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
121 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
122 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
123 output_path = out.path,
12
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),
25
342726584be2 [Bun] Fixed how bun would be ran within bazel.
June Park <parkjune1995@gmail.com>
parents: 24
diff changeset
140 "src_folder": attr.string(),
12
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
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
144 def _move_files_into_dir_impl(ctx):
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
145 srcs = ctx.files.srcs
64
a30944e5719e Added vibe coded markdown to html script since it is useful for me. Updated Dowa so that it can be compiled without dirnet for windows.
June Park <parkjune1995@gmail.com>
parents: 58
diff changeset
146 outs = []
12
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)
64
a30944e5719e Added vibe coded markdown to html script since it is useful for me. Updated Dowa so that it can be compiled without dirnet for windows.
June Park <parkjune1995@gmail.com>
parents: 58
diff changeset
149 ctx.actions.run_shell(
a30944e5719e Added vibe coded markdown to html script since it is useful for me. Updated Dowa so that it can be compiled without dirnet for windows.
June Park <parkjune1995@gmail.com>
parents: 58
diff changeset
150 inputs = [src],
a30944e5719e Added vibe coded markdown to html script since it is useful for me. Updated Dowa so that it can be compiled without dirnet for windows.
June Park <parkjune1995@gmail.com>
parents: 58
diff changeset
151 outputs = [out],
a30944e5719e Added vibe coded markdown to html script since it is useful for me. Updated Dowa so that it can be compiled without dirnet for windows.
June Park <parkjune1995@gmail.com>
parents: 58
diff changeset
152 command = "cp \"$1\" \"$2\"",
a30944e5719e Added vibe coded markdown to html script since it is useful for me. Updated Dowa so that it can be compiled without dirnet for windows.
June Park <parkjune1995@gmail.com>
parents: 58
diff changeset
153 arguments = [src.path, out.path],
12
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
154 )
64
a30944e5719e Added vibe coded markdown to html script since it is useful for me. Updated Dowa so that it can be compiled without dirnet for windows.
June Park <parkjune1995@gmail.com>
parents: 58
diff changeset
155 outs.append(out)
a30944e5719e Added vibe coded markdown to html script since it is useful for me. Updated Dowa so that it can be compiled without dirnet for windows.
June Park <parkjune1995@gmail.com>
parents: 58
diff changeset
156 return [DefaultInfo(files = depset(outs))]
12
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
157
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
158 move_files_into_dir = rule(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
159 implementation = _move_files_into_dir_impl,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
160 attrs = {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
161 "srcs": attr.label_list(allow_files=True),
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
162 "dest": attr.string(),
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
163 },
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
164 )
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
165
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
166 def _move_to_directory_impl(ctx):
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
167 srcs = ctx.files.data
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
168 res = []
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
169 for src in srcs:
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
170 true = "/".join(src.path.split("/")[2:])
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
171 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
172 out = ctx.actions.declare_file(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
173 path
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
174 );
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
175 ctx.actions.symlink(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
176 output = out,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
177 target_file = src,
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 res.append(out)
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
180 return [DefaultInfo(files = depset(res))]
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
181
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
182 move_to_directory = rule(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
183 implementation = _move_to_directory_impl,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
184 attrs = {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
185 "data": attr.label_list(allow_files=True),
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
186 "dest": attr.string(),
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
187 },
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
188 )
58
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
189
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
190
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
191 def _macos_app_impl(ctx):
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
192 """Implementation for creating a macOS .app bundle from a binary."""
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
193 binary = ctx.file.binary
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
194 app_name = ctx.attr.app_name
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
195 bundle_id = ctx.attr.bundle_id
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
196
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
197 # Declare the .app directory as output
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
198 app_dir = ctx.actions.declare_directory(app_name + ".app")
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
199
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
200 ctx.actions.run_shell(
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
201 inputs = [binary],
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
202 outputs = [app_dir],
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
203 command = """
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
204 set -e
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
205
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
206 APPDIR="{app_dir}"
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
207
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
208 rm -rf "$APPDIR"
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
209 mkdir -p "$APPDIR/Contents/MacOS"
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
210 mkdir -p "$APPDIR/Contents/Resources"
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
211
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
212 cp {binary} "$APPDIR/Contents/MacOS/{app_name}"
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
213 chmod +x "$APPDIR/Contents/MacOS/{app_name}"
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
214
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
215 cat > "$APPDIR/Contents/Info.plist" <<EOF
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
216 <?xml version="1.0" encoding="UTF-8"?>
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
217 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
218 "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
219 <plist version="1.0">
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
220 <dict>
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
221 <key>CFBundleExecutable</key>
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
222 <string>{app_name}</string>
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
223 <key>CFBundleIdentifier</key>
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
224 <string>{bundle_id}</string>
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
225 <key>CFBundleName</key>
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
226 <string>{app_name}</string>
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
227 <key>CFBundleVersion</key>
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
228 <string>1.0</string>
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
229 </dict>
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
230 </plist>
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
231 EOF
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
232 """.format(
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
233 app_dir = app_dir.path,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
234 binary = binary.path,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
235 app_name = app_name,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
236 bundle_id = bundle_id,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
237 ),
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
238 progress_message = "Creating macOS app bundle for {}".format(app_name),
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
239 )
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
240
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
241 return [DefaultInfo(files = depset([app_dir]))]
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
242
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
243 _macos_app = rule(
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
244 implementation = _macos_app_impl,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
245 attrs = {
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
246 "binary": attr.label(
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
247 allow_single_file = True,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
248 mandatory = True,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
249 doc = "The binary to bundle into a .app",
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
250 ),
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
251 "app_name": attr.string(
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
252 mandatory = True,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
253 doc = "Name of the application",
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
254 ),
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
255 "bundle_id": attr.string(
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
256 mandatory = True,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
257 doc = "Bundle identifier (e.g., com.example.app)",
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
258 ),
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
259 },
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
260 )
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
261
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
262 def _macos_signed_app_impl(ctx):
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
263 """Implementation for signing a macOS .app bundle."""
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
264 app_dir = ctx.file.app
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
265 app_name = ctx.attr.app_name
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
266
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
267 # Declare the signed .app directory as output
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
268 signed_app_dir = ctx.actions.declare_directory(app_name + "_signed.app")
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
269
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
270 ctx.actions.run_shell(
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
271 inputs = [app_dir],
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
272 outputs = [signed_app_dir],
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
273 command = """
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
274 set -e
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
275
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
276 APPDIR="{app_dir}"
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
277 SIGNEDDIR="{signed_dir}"
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
278
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
279 rm -rf "$SIGNEDDIR"
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
280 # Use -L to dereference symlinks, as codesign doesn't work with symlinks
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
281 cp -RL "$APPDIR" "$SIGNEDDIR"
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
282
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
283 codesign --deep --force --sign - "$SIGNEDDIR"
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
284 """.format(
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
285 app_dir = app_dir.path,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
286 signed_dir = signed_app_dir.path,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
287 ),
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
288 progress_message = "Signing macOS app bundle {}".format(app_name),
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
289 )
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
290
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
291 return [DefaultInfo(files = depset([signed_app_dir]))]
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
292
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
293 _macos_signed_app = rule(
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
294 implementation = _macos_signed_app_impl,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
295 attrs = {
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
296 "app": attr.label(
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
297 allow_single_file = True,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
298 mandatory = True,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
299 doc = "The .app directory to sign",
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
300 ),
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
301 "app_name": attr.string(
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
302 mandatory = True,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
303 doc = "Name of the application",
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
304 ),
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
305 },
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
306 )
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
307
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
308 def macos_app_and_dmg(name, binary, bundle_id = "com.example.app"):
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
309 """
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
310 Creates a macOS .app bundle, signs it, and packages it into a DMG.
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
311
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
312 Args:
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
313 name: Base name for the generated targets
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
314 binary: Label of the binary target to bundle
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
315 bundle_id: Bundle identifier for the app (default: com.example.app)
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
316
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
317 Generates:
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
318 {name}_app: The .app bundle
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
319 {name}_signed_app: The signed .app bundle
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
320 {name}_dmg: The final DMG file
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
321 """
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
322 # 1. Build the .app bundle
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
323 _macos_app(
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
324 name = name + "_app",
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
325 binary = binary,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
326 app_name = name,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
327 bundle_id = bundle_id,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
328 )
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
329
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
330 # 2. Sign the .app
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
331 _macos_signed_app(
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
332 name = name + "_signed_app",
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
333 app = ":" + name + "_app",
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
334 app_name = name,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
335 )
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
336
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
337 # 3. Create the DMG
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
338 native.genrule(
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
339 name = name + "_dmg",
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
340 srcs = [":" + name + "_signed_app"],
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
341 outs = [name + ".dmg"],
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
342 cmd = """
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
343 set -e
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
344
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
345 SIGNEDDIR="$(location :{name}_signed_app)"
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
346
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
347 hdiutil create \
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
348 -volname {name} \
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
349 -srcfolder "$$SIGNEDDIR" \
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
350 -ov -format UDZO "$@"
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
351 """.format(name = name),
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
352 local = 1, # Disable sandboxing for hdiutil
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
353 tags = ["no-sandbox"],
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
354 )