Skip to content

Commit 0893c5e

Browse files
authored
Merge pull request boj-rs#62 from byeongkeunahn/embed-multiple-files
Embed multiple files into output
2 parents 427f324 + f955f20 commit 0893c5e

39 files changed

+97
-55
lines changed

debug-64bit-windows.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@echo off
22
cargo +nightly build --target x86_64-pc-windows-msvc || goto :error
3-
python scripts/static-pie-gen.py basm/src/solution.rs x86_64-pc-windows-msvc target/x86_64-pc-windows-msvc/debug/basm.exe scripts/static-pie-stub-amd64.bin C scripts/static-pie-template-amd64.c || goto :error
3+
python scripts/static-pie-gen.py basm/src/solution.rs x86_64-pc-windows-msvc target/x86_64-pc-windows-msvc/debug/basm.exe scripts/static-pie-stub-amd64.bin C static-pie-template-amd64.c || goto :error
44

55
:; exit 0
66
exit /b 0

release-64bit-windows-fn-impl.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@echo off
22
cargo +nightly build --target x86_64-pc-windows-msvc --bin basm-submit --release || goto :error
3-
python scripts/static-pie-gen.py basm/src/solution.rs x86_64-pc-windows-msvc target/x86_64-pc-windows-msvc/release/basm-submit.exe scripts/static-pie-stub-amd64.bin C scripts/static-pie-template-amd64-fn-impl.c || goto :error
3+
python scripts/static-pie-gen.py basm/src/solution.rs x86_64-pc-windows-msvc target/x86_64-pc-windows-msvc/release/basm-submit.exe static-pie-stub-amd64.bin C static-pie-template-amd64-fn-impl.c || goto :error
44

55
:; exit 0
66
exit /b 0

release-64bit-windows-rs.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@echo off
22
cargo +nightly build --target x86_64-pc-windows-msvc --bin basm-submit --release || goto :error
3-
python scripts/static-pie-gen.py basm/src/solution.rs x86_64-pc-windows-msvc target/x86_64-pc-windows-msvc/release/basm-submit.exe scripts/static-pie-stub-amd64.bin Rust scripts/static-pie-template-amd64.rs || goto :error
3+
python scripts/static-pie-gen.py basm/src/solution.rs x86_64-pc-windows-msvc target/x86_64-pc-windows-msvc/release/basm-submit.exe static-pie-stub-amd64.bin Rust static-pie-template-amd64.rs || goto :error
44

55
:; exit 0
66
exit /b 0

release-64bit-windows.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@echo off
22
cargo +nightly build --target x86_64-pc-windows-msvc --bin basm-submit --release || goto :error
3-
python scripts/static-pie-gen.py basm/src/solution.rs x86_64-pc-windows-msvc target/x86_64-pc-windows-msvc/release/basm-submit.exe scripts/static-pie-stub-amd64.bin C scripts/static-pie-template-amd64.c || goto :error
3+
python scripts/static-pie-gen.py basm/src/solution.rs x86_64-pc-windows-msvc target/x86_64-pc-windows-msvc/release/basm-submit.exe static-pie-stub-amd64.bin C static-pie-template-amd64.c || goto :error
44

55
:; exit 0
66
exit /b 0

release-html.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@echo off
22
cargo +nightly build --target wasm32-unknown-unknown --bin=basm-submit --release || goto :error
3-
python scripts/wasm-gen.py scripts/wasm-template.html || goto :error
3+
python scripts/wasm-gen.py wasm-template.html HTML || goto :error
44

55
:; exit 0
66
exit /b 0

release-html.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
>&2 echo "Building project for target wasm32-unknown-unknown, language JavaScript, build mode Release"
22
cargo +nightly build --target wasm32-unknown-unknown --bin=basm-submit --release "$@"
3-
python3 scripts/wasm-gen.py scripts/wasm-template.html
3+
python3 scripts/wasm-gen.py wasm-template.html HTML

release-wasm32.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@echo off
22
cargo +nightly build --target wasm32-unknown-unknown --bin=basm-submit --release || goto :error
3-
python scripts/wasm-gen.py scripts/wasm-template.js || goto :error
3+
python scripts/wasm-gen.py wasm-template.js JavaScript || goto :error
44

55
:; exit 0
66
exit /b 0

release-wasm32.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
>&2 echo "Building project for target wasm32-unknown-unknown, language JavaScript, build mode Release"
22
cargo +nightly build --target wasm32-unknown-unknown --bin=basm-submit --release "$@"
3-
python3 scripts/wasm-gen.py scripts/wasm-template.js
3+
python3 scripts/wasm-gen.py wasm-template.js JavaScript

scripts/locator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import os
2+
3+
def template_path(template_name):
4+
return os.path.join("scripts/templates/", template_name)

scripts/srcpack.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import os
2+
3+
# Reads and assembles the source code in the crate at the path `crate_root`.
4+
# `crate_root` usually equals `basm/`.
5+
def read_assemble(crate_root, target_language):
6+
sol_first = []
7+
sol_all = []
8+
crate_src_path = os.path.join(crate_root, "src/")
9+
for root, dirs, files in os.walk(crate_src_path):
10+
if os.path.abspath(root).startswith(os.path.abspath(os.path.join(crate_src_path, "bin/"))):
11+
continue
12+
for f in files:
13+
f_path = os.path.join(root, f)
14+
if f_path.endswith(".rs"):
15+
with open(f_path, encoding='utf8') as f:
16+
sol = f.readlines()
17+
if os.path.abspath(f_path) == os.path.abspath(os.path.join(crate_root, "src/solution.rs")):
18+
sol_first.append((f_path, sol))
19+
else:
20+
sol_all.append((f_path, sol))
21+
sol_all = sol_first + sol_all
22+
if len(sol_all) == 1:
23+
sol_flat = sol_all[0][1]
24+
else:
25+
sol_flat = []
26+
for i, (f_path, sol) in enumerate(sol_all):
27+
if i > 0:
28+
sol_flat.append("\n")
29+
sol_flat.append("// {0}\n".format(f_path))
30+
sol_flat.extend(sol)
31+
if target_language in ["Rust", "HTML"]:
32+
return assemble_as_is(sol_flat)
33+
else:
34+
return assemble_with_commenting(sol_flat)
35+
36+
def assemble_as_is(sol):
37+
sol = [line.replace("\ufeff", "") for line in sol]
38+
sol = [line.rstrip() + "\n" for line in sol]
39+
if len(sol) > 0:
40+
sol[-1] = sol[-1].rstrip()
41+
sol = "".join(sol)
42+
return sol
43+
44+
def assemble_with_commenting(sol):
45+
sol_all = "".join(sol)
46+
sol_has_block_comment = "/*" in sol_all or "*/" in sol_all
47+
if sol_has_block_comment:
48+
prefix, begin, end = "//", "", ""
49+
else:
50+
prefix, begin, end = "", "/*\n", "*/\n"
51+
sol = [line.replace("\ufeff", "") for line in sol]
52+
sol = [prefix + line.rstrip() + "\n" for line in sol]
53+
if len(begin) > 0:
54+
sol = [begin] + sol + [end]
55+
if len(sol) > 0:
56+
sol[-1] = sol[-1].rstrip()
57+
sol = "".join(sol)
58+
return sol

0 commit comments

Comments
 (0)