-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jonas Wilkens
authored and
Jonas Wilkens
committed
May 19, 2021
1 parent
f2dcb2b
commit f5a3242
Showing
6 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Python: Current File", | ||
"type": "python", | ||
"request": "launch", | ||
"program": "main.py", | ||
"console": "integratedTerminal", | ||
"args": ["${workspaceRoot}//test", "main.rs"] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import pathlib | ||
import sys | ||
import os | ||
import re | ||
|
||
def parse_file(path: pathlib.Path, main_file: str, content: list): | ||
"""Parses a given rust file into the content list. | ||
Args: | ||
path (pathlib.Path): A path to the file | ||
content (list): A list of all lines of content | ||
""" | ||
with open(path, "r") as file: | ||
# Put file in mod section | ||
if path.name != main_file: | ||
content.append(f"mod {path.stem} {{\n") | ||
|
||
while line := file.readline(): | ||
# Remove mod calls in file | ||
if not re.match("mod\s+.*;", line) is None: | ||
pass | ||
else: | ||
content.append(line) | ||
|
||
# Close file mod section | ||
if path.name != main_file: | ||
content.append(f"\n}}\n") | ||
|
||
# Add newline as delimiter | ||
content.append("\n") | ||
|
||
def find_files(dir: pathlib.Path): | ||
"""Finds all files in the given directory recursively. | ||
Args: | ||
dir (pathlib.Path): The root directory for finding files | ||
Yields: | ||
pathlib.Path: The next file in the given directory | ||
""" | ||
for dirpath, _dirname, files in os.walk(dir): | ||
for name in files: | ||
if name.lower().endswith(".rs"): | ||
yield pathlib.Path(dirpath) / name | ||
|
||
if __name__ == "__main__": | ||
root_dir = pathlib.Path(sys.argv[1]) | ||
main_file = sys.argv[2] | ||
out_file = root_dir / "output.rs" | ||
content = list() | ||
|
||
# Remove output file if it already exists | ||
if out_file.exists(): | ||
out_file.unlink() | ||
|
||
# Parse all files in current directory recursively | ||
for file in find_files(root_dir): | ||
parse_file(file, main_file, content) | ||
|
||
print(f"Writing file {out_file} ..."); | ||
|
||
# Write output file | ||
with open(out_file, "w") as file: | ||
file.writelines(content) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
@echo off | ||
pyinstaller --noconfirm --name "cg_rust_merger" main.py --noconsole >nul 2>&1 | ||
@RD /S /Q "__pycache__" | ||
@RD /S /Q "build" >nul 2>&1 | ||
if exist "build" rd /s /q "build" | ||
DEL "cg_rust_merger.spec" | ||
|
||
echo Build complete |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub fn lebo() -> String { | ||
String::from("ELO") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
i bims fake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
mod elo; | ||
|
||
use std::io; | ||
use crate::elo; | ||
|
||
fn main() { | ||
println!("{}", elo::lebo()); | ||
} |