-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-lib.py
51 lines (45 loc) · 1.93 KB
/
build-lib.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import os
#Создание директории build/
#############################################################
def create_dir(dir_):
os.mkdir(dir_)
def delete_dir(dir_, file_):
try:
os.remove(dir_ + file_)
except:
pass
os.rmdir(dir_)
dir_ = "build/" # имя директории куда будет собираться библиотека
file_ = "cli.hpp" # имя файла куда будет собираться библиотека
try:
create_dir(dir_)
except FileExistsError:
delete_dir(dir_, file_)
create_dir(dir_)
#############################################################
#Чтение всех файлов из path и объединение всё в переменную code
#############################################################
paths = ["src/Flag/Flag.hpp", "src/Command/Command.hpp", "src/Cli/Cli.hpp",
"src/Cli/Cli.cpp", "src/cli_config.h"] # !Порядок файлов важен (запись в code идёт именно в этом порядке)
code = ""
includes = "#pragma once\n\n" # Собираем сюда все подключаемые библиотеки, чтобы потом в файле поместить их сверху
defines = "\n"
for path in paths:
file = open(path, "r")
for str_ in file:
if ("#" in str_):
if not("#include \"" in str_ or "#pragma" in str_):
if ("#define" in str_):
defines += str_
else:
includes += str_
else:
code += str_
code = includes + defines + code
#############################################################
#Создание файла собранной библиотеки cli.hpp
#############################################################
file = open(dir_ + file_, "w+")
file.write(code)
file.close()
#############################################################