Код: Выделить всё
# C-make is overrated for me :P
# I don't wanna use c-make 'cause I don't wanna learn it so..
# I just made a better version I guess
# Yes.. I wrote it myself
#
# This should only be used for C++ Builds
from os import system as sys, listdir as ld
from time import perf_counter
from typing import Any
import asyncio
async def compile_single(file_name: str, includes: list[str]) -> None:
includes_: str = ' '.join(f'-I{include_path}' for include_path in includes)
CMD: str = f'g++ -c -Wall -Wpedantic src/{file_name}.cpp -o bin/{file_name}.obj {includes_}'
start_time: float = perf_counter()
process: Any = await asyncio.create_subprocess_shell(CMD)
await process.communicate()
end_time: float = perf_counter()
print(f'|> Compilation of [{file_name.upper()}] took {end_time - start_time:.2f} seconds')
async def compile_all(file_names: list[str], includes: list[str], final_linking: bool) -> None:
await asyncio.gather(*(compile_single(file, includes) for file in file_names))
if final_linking:
CMD: str = 'g++ -O3 -Wall -Wpedantic bin/*.obj -o app'
start_time: float = perf_counter()
process = await asyncio.create_subprocess_shell(CMD)
await process.communicate()
end_time: float = perf_counter()
print(f'Final linking took {end_time - start_time:.2f} seconds')
def get_all_names(dir: str) -> list[str]:
""" Should only be used for cpp """
names: list[str] = ld(dir)
for i in range(0, len(names)):
names[i] = names[i][:-4]
return names
if __name__ == '__main__':
sys('cls')
# The folder "./src" must contain only .cpp files not headers
files: list[str] = get_all_names('./src/')
start_time: float = perf_counter()
asyncio.run(compile_all(files, ['header', 'header/Token', 'header/ast'], True))
end_time: float = perf_counter()
print(f'The compilation of all the files took {end_time - start_time:.2f} seconds\n')
Жду вашей помощи и оскорблений -_-..Так что да.. вот и все.
Подробнее здесь: https://stackoverflow.com/questions/787 ... t-any-good