|
3 | 3 | # Reads and assembles the source code in the crate at the path `crate_root`.
|
4 | 4 | # `crate_root` usually equals `basm/`.
|
5 | 5 | 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) |
9 | 26 | if target_language in ["Rust", "HTML"]:
|
10 |
| - return assemble_as_is(sol) |
| 27 | + return assemble_as_is(sol_flat) |
11 | 28 | else:
|
12 |
| - return assemble_with_commenting(sol) |
| 29 | + return assemble_with_commenting(sol_flat) |
13 | 30 |
|
14 | 31 | def assemble_as_is(sol):
|
15 | 32 | sol = [line.replace("\ufeff", "") for line in sol]
|
|
0 commit comments