Skip to content

Commit

Permalink
Initial commit (seems to work)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Wilkens authored and Jonas Wilkens committed May 19, 2021
1 parent f2dcb2b commit f5a3242
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .vscode/launch.json
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"]
}
]
}
64 changes: 64 additions & 0 deletions main.py
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)
8 changes: 8 additions & 0 deletions make.bat
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
3 changes: 3 additions & 0 deletions test/elo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn lebo() -> String {
String::from("ELO")
}
1 change: 1 addition & 0 deletions test/fakers
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
i bims fake
8 changes: 8 additions & 0 deletions test/main.rs
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());
}

0 comments on commit f5a3242

Please sign in to comment.