n
This commit is contained in:
Julia 2024-05-10 16:59:52 -05:00
parent 2a4bd61bbb
commit 5c55be1ff9
18 changed files with 38 additions and 89 deletions

121
build.py
View file

@ -1,28 +1,12 @@
import hashlib
import json
<<<<<<< HEAD
import subprocess
from subprocess import PIPE
from hashlib import md5
from pathlib import Path
GCC = "gcc"
ARGS = "-fdiagnostics-color -pthread -Wall -std=c17 -pedantic"
=======
import os
import subprocess
import sys
def walk_source_dir(path: str) -> tuple[list[str], list[str]]:
source_paths : list[str] = []
subdirs = []
for dirpath, dirnames, filenames in os.walk(path):
source_paths += [os.path.join(dirpath, f) for f in filenames if f.endswith(".c")]
subdirs.append(dirpath)
return (source_paths, subdirs)
>>>>>>> 41f57d5ba85e72cf801e8ee91afe55d40d535701
ARGS = "-fdiagnostics-color -pthread -Wall -std=c17 -pedantic -g"
SOURCE_DIR = Path("source/")
@ -34,59 +18,24 @@ CHECKSUMS = Path("checksums.txt")
ERRORS = Path("errors.txt")
def disk_scan_chksms(sources: list[Path]) -> list[str]:
chksms: list[str] = []
for source in sources:
with open(source, "rb") as file:
raw = file.read()
chksms.append(hashlib.md5(raw).hexdigest())
return chksms
def scan_checksums(files: list[Path]) -> list[str]:
return (md5(file.read_bytes()).hexdigest() for file in files)
def disk_read_chksms(txt: Path) -> tuple[list[Path], list[str]]:
sources: list[Path]
chksms: list[str]
def read_txt(txt: Path) -> any:
if not txt.exists():
return ([], [])
with open(txt, "rb") as file:
zipped: dict[str, str] = json.loads(file.read())
sources, chksms = [Path(key) for key in zipped.keys()], zipped.values()
return (sources, chksms)
return []
content = txt.read_text("utf-8")
return json.loads(content) if content else []
<<<<<<< HEAD
def disk_write_chksms(txt: Path, sources: list[Path], chksms: list[str]) -> None:
zipped = {str(source): chksm for source, chksm in zip(sources, chksms)}
=======
def build(source_path, obj_path, out_path, recompile):
source_paths, subdirs = walk_source_dir(source_path)
>>>>>>> 41f57d5ba85e72cf801e8ee91afe55d40d535701
with open(txt, "w+") as file:
file.write(json.dumps(zipped))
def write_txt(txt: Path, content) -> None:
txt.write_text(json.dumps(content))
def filter_chksms(sources, chksms, old_chksms) -> list[Path]:
difs = set(chksms).difference(old_chksms)
return [sources[chksms.index(dif)] for dif in difs]
<<<<<<< HEAD
def scan_sources(source_dir: Path) -> tuple[list[Path], list[Path]]:
sources = [source for source in source_dir.rglob("*.c")]
chksms = disk_scan_chksms(sources)
old_sources, old_chksms = disk_read_chksms(CHECKSUMS)
updated_sources = filter_chksms(sources, chksms, old_chksms)
disk_write_chksms(CHECKSUMS, sources, chksms)
return (updated_sources, sources)
def difference(cur, old, vals):
return (vals[cur.index(i)] for i in set(cur) - set(old))
def clean_objects(object_dir: Path, sources: list[Path]) -> None:
@ -99,6 +48,16 @@ def clean_objects(object_dir: Path, sources: list[Path]) -> None:
objects[object_stems.index(stem)].unlink()
def header_dependencies(sources):
tasks = []
for source in sources:
task = subprocess.Popen(f"{GCC} -MMD {source} {ARGS} -o stdout", stdout=PIPE)
tasks.append(task)
for task in tasks:
def compile(source: Path, includes: list[Path], object_dir: Path):
include_arg: str = " ".join(f"-I {dir}" for dir in includes)
output: Path = object_dir / source.with_suffix(".o").name
@ -108,19 +67,6 @@ def compile(source: Path, includes: list[Path], object_dir: Path):
return subprocess.Popen(args, stderr=subprocess.PIPE)
def disk_read_errors(txt: Path) -> dict[str, str]:
if not txt.exists():
return {}
with open(txt, "rb") as file:
return json.loads(file.read())
def disk_write_errors(txt: Path, errs: dict[str, str]):
with open(txt, "w+") as file:
file.write(json.dumps(errs))
def wait_compile_tasks(tasks, updated_sources) -> dict[str, str]:
errors = disk_read_errors(ERRORS)
@ -136,13 +82,19 @@ def wait_compile_tasks(tasks, updated_sources) -> dict[str, str]:
def link(object_dir: Path, output: Path) -> None:
subprocess.run(f"{GCC} -g {object_dir}/*.o {ARGS} -o {output}")
subprocess.run(f"{GCC} {object_dir}/*.o {ARGS} -o {output}")
def build(source_dir: Path, object_dir: Path, output: Path):
updated_sources, all_sources = scan_sources(source_dir)
includes = [path for path in source_dir.rglob("*") if path.is_dir()]
def build(src: Path, object_dir: Path, output: Path):
includes, headers, sources = zip(map(src.rglob, ["*/", "*.h", "*.c"]))
headers_cur, sources_cur = map(scan_checksums, (headers, sources))
headers_old, sources_old = read_txt(CHECKSUMS)
headers_updt = difference(headers_cur, headers_old, headers)
sources_updt = difference(sources_cur, sources_old, sources)
dependencies = {}
tasks = []
for source in updated_sources:
@ -159,7 +111,4 @@ def build(source_dir: Path, object_dir: Path, output: Path):
if __name__ == "__main__":
build(SOURCE_DIR, OBJECT_DIR, OUTPUT)
=======
build("source/", "objects/", "debug", True)
>>>>>>> 41f57d5ba85e72cf801e8ee91afe55d40d535701
build(SOURCE_DIR, OBJECT_DIR, OUTPUT)

View file

@ -1 +1 @@
{"source\\fumoengine\\fumocommon.c": "3253ec40842eaf2b65cca13826e35118", "source\\fumoengine\\fumoengine.c": "e6c26dc323b01d0b8c2e7e2f64833eb7", "source\\fumoengine\\include\\dictionary.c": "aa85678a01e035d45c9f59b6fe917beb", "source\\fumoengine\\include\\event.c": "71e6818ecf285293cf01c791f13c4d00", "source\\fumoengine\\include\\ringbuffer.c": "306556649cea951ef769cdfc5ae2b60d", "source\\fumoengine\\include\\vector.c": "67e0cf60c3a359e6e8c8eb46e01e8513", "source\\fumoengine\\input\\ctrl.c": "87dbff7e38fc406cbf309717e63665ed", "source\\fumoengine\\input\\input.c": "5a57ebd313fc2fc0246a95ce6641e5e8", "source\\fumoengine\\input\\platforms\\parseinput.c": "c1562355adcec7d0dcb0a81e8d7ffcca", "source\\fumoengine\\input\\platforms\\win.c": "2014fc5cdb4c8770f510a63db779f8bf", "source\\fumoengine\\terminal\\terminal.c": "c213e73df14b8d5ebcf5f25d221c3fe6", "source\\fumotris\\fumotris.c": "defad533a34d69352e728dbda3306a79", "source\\fumotris\\tetr.c": "09dcf3a7119ccabe0cb69c0a8fd688e9"}
{"source\\fumoengine\\fumocommon.c": "bdd12a9257829d191f57d442b068db37", "source\\fumoengine\\fumoengine.c": "f3097febe6401acf6d0d8b3032b2da68", "source\\fumotris\\fumotris.c": "1516eb830de511f7987507be279e6f02", "source\\fumotris\\tetr.c": "74901782ad0d235bb6b078d2bb6ef99e", "source\\fumoengine\\include\\dictionary.c": "c8f8e5f99965c5c82caf24790fed78e4", "source\\fumoengine\\include\\event.c": "140ba30120636d5d33875e43447e0642", "source\\fumoengine\\include\\ringbuffer.c": "0d552f9daeeebd7ef23f4aaa7ae3e022", "source\\fumoengine\\include\\vector.c": "3f2ccd6831013ac0428446c776891503", "source\\fumoengine\\input\\ctrl.c": "6113d9b6cbcef5daed308f96a0a96f18", "source\\fumoengine\\input\\input.c": "7004fde9604dd57325d623cf9775b33c", "source\\fumoengine\\terminal\\terminal.c": "42b3d4217c15403b6dd079cee4a68186", "source\\fumoengine\\input\\platforms\\parseinput.c": "e23dafd399743096db434a9869b3b47e", "source\\fumoengine\\input\\platforms\\win.c": "f52c9c1bab5d1f05d78f0420780d486a"}

BIN
debug.exe

Binary file not shown.

View file

@ -1 +1 @@
{"source\\fumoengine\\input\\platforms\\parseinput.c": false, "source\\fumoengine\\terminal\\terminal.c": false, "source\\fumoengine\\fumoengine.c": "In file included from \u001b[01m\u001b[Ksource\\fumoengine\\fumoengine.h:7\u001b[m\u001b[K,\n from \u001b[01m\u001b[Ksource\\fumoengine\\fumoengine.c:1\u001b[m\u001b[K:\n\u001b[01m\u001b[Ksource\\fumoengine\\include/vector.h:25:2:\u001b[m\u001b[K \u001b[01;31m\u001b[Kerror: \u001b[m\u001b[Kexpected '\u001b[01m\u001b[K;\u001b[m\u001b[K' before '\u001b[01m\u001b[K_Bool\u001b[m\u001b[K'\n 25 | g\n | \u001b[01;31m\u001b[K^\u001b[m\u001b[K\n | \u001b[32m\u001b[K;\u001b[m\u001b[K\n", "source\\fumoengine\\include\\vector.c": "In file included from \u001b[01m\u001b[Ksource\\fumoengine\\include\\vector.c:1\u001b[m\u001b[K:\n\u001b[01m\u001b[Ksource\\fumoengine\\include\\vector.h:25:2:\u001b[m\u001b[K \u001b[01;31m\u001b[Kerror: \u001b[m\u001b[Kexpected '\u001b[01m\u001b[K;\u001b[m\u001b[K' before '\u001b[01m\u001b[K_Bool\u001b[m\u001b[K'\n 25 | g\n | \u001b[01;31m\u001b[K^\u001b[m\u001b[K\n | \u001b[32m\u001b[K;\u001b[m\u001b[K\n", "source\\fumoengine\\include\\event.c": false, "source\\fumoengine\\fumocommon.c": false, "source\\fumoengine\\include\\ringbuffer.c": false, "source\\fumoengine\\input\\platforms\\win.c": false, "source\\fumotris\\fumotris.c": "In file included from \u001b[01m\u001b[Ksource\\fumoengine/fumoengine.h:7\u001b[m\u001b[K,\n from \u001b[01m\u001b[Ksource\\fumotris\\fumotris.h:2\u001b[m\u001b[K,\n from \u001b[01m\u001b[Ksource\\fumotris\\fumotris.c:1\u001b[m\u001b[K:\n\u001b[01m\u001b[Ksource\\fumoengine\\include/vector.h:25:2:\u001b[m\u001b[K \u001b[01;31m\u001b[Kerror: \u001b[m\u001b[Kexpected '\u001b[01m\u001b[K;\u001b[m\u001b[K' before '\u001b[01m\u001b[K_Bool\u001b[m\u001b[K'\n 25 | g\n | \u001b[01;31m\u001b[K^\u001b[m\u001b[K\n | \u001b[32m\u001b[K;\u001b[m\u001b[K\n", "source\\fumotris\\tetr.c": false, "source\\fumoengine\\input\\input.c": false, "source\\fumoengine\\input\\ctrl.c": false, "source\\fumoengine\\include\\dictionary.c": false}
{"source\\fumoengine\\terminal\\terminal.c": false, "source\\fumoengine\\fumocommon.c": false, "source\\fumoengine\\include\\event.c": false, "source\\fumoengine\\include\\ringbuffer.c": false, "source\\fumoengine\\input\\platforms\\win.c": false, "source\\fumotris\\tetr.c": "\u001b[01m\u001b[Ksource\\fumotris\\tetr.c:\u001b[m\u001b[K In function '\u001b[01m\u001b[KTetrMapDraw\u001b[m\u001b[K':\n\u001b[01m\u001b[Ksource\\fumotris\\tetr.c:43:31:\u001b[m\u001b[K \u001b[01;31m\u001b[Kerror: \u001b[m\u001b[Kunknown type name '\u001b[01m\u001b[Kff\u001b[m\u001b[K'\n 43 | block[0].ch = '(';\u001b[01;31m\u001b[Kff\u001b[m\u001b[K\n | \u001b[01;31m\u001b[K^~\u001b[m\u001b[K\n\u001b[01m\u001b[Ksource\\fumotris\\tetr.c:44:21:\u001b[m\u001b[K \u001b[01;31m\u001b[Kerror: \u001b[m\u001b[Kexpected '\u001b[01m\u001b[K=\u001b[m\u001b[K', '\u001b[01m\u001b[K,\u001b[m\u001b[K', '\u001b[01m\u001b[K;\u001b[m\u001b[K', '\u001b[01m\u001b[Kasm\u001b[m\u001b[K' or '\u001b[01m\u001b[K__attribute__\u001b[m\u001b[K' before '\u001b[01m\u001b[K.\u001b[m\u001b[K' token\n 44 | block[1]\u001b[01;31m\u001b[K.\u001b[m\u001b[Kch = ')';\n | \u001b[01;31m\u001b[K^\u001b[m\u001b[K\n", "source\\fumoengine\\include\\vector.c": false, "source\\fumoengine\\input\\platforms\\parseinput.c": false, "source\\fumoengine\\include\\dictionary.c": false, "source\\fumoengine\\input\\ctrl.c": false, "source\\fumoengine\\input\\input.c": false, "source\\fumotris\\fumotris.c": false, "source\\fumoengine\\fumoengine.c": false}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -82,7 +82,7 @@ void *DictionarySet(DictT T, struct Dictionary *dict, u32 key, void *val)
usize index = key % dict->capacity;
void *bkt = probe_empty_bkt(T, dict, index, key);
if (*get_key(T, bkt) == 0)
if (*get_key(T, bkt) == 0)
set_bkt(T, bkt, key, val);
return bkt;