Skip to content

Commit 5e622e2

Browse files
committed
scripts: pack all .rs files except src/bin/*
1 parent 409e17b commit 5e622e2

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

scripts/srcpack.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,30 @@
33
# Reads and assembles the source code in the crate at the path `crate_root`.
44
# `crate_root` usually equals `basm/`.
55
def read_assemble(crate_root, target_language):
6-
solution_src_path = os.path.join(crate_root, "src/solution.rs")
7-
with open(solution_src_path, encoding='utf8') as f:
8-
sol = f.readlines()
6+
sol_all = []
7+
crate_src_path = os.path.join(crate_root, "src/")
8+
for root, dirs, files in os.walk(crate_src_path):
9+
if os.path.abspath(root).startswith(os.path.abspath(os.path.join(crate_src_path, "bin/"))):
10+
continue
11+
for f in files:
12+
f_path = os.path.join(root, f)
13+
if f_path.endswith(".rs"):
14+
with open(f_path, encoding='utf8') as f:
15+
sol = f.readlines()
16+
sol_all.append((f_path, sol))
17+
if len(sol_all) == 1:
18+
sol_flat = sol_all[0][1]
19+
else:
20+
sol_flat = []
21+
for i, (f_path, sol) in enumerate(sol_all):
22+
if i > 0:
23+
sol_flat.append("\n")
24+
sol_flat.append("// {0}\n".format(f_path))
25+
sol_flat.extend(sol)
926
if target_language in ["Rust", "HTML"]:
10-
return assemble_as_is(sol)
27+
return assemble_as_is(sol_flat)
1128
else:
12-
return assemble_with_commenting(sol)
29+
return assemble_with_commenting(sol_flat)
1330

1431
def assemble_as_is(sol):
1532
sol = [line.replace("\ufeff", "") for line in sol]

0 commit comments

Comments
 (0)