Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 7d6473bf authored by BAROLLET Theo's avatar BAROLLET Theo
Browse files

make_level.py update with --dev option

parent 0c22da4f
No related branches found
No related tags found
No related merge requests found
......@@ -70,6 +70,11 @@ parser.add_argument(
action="store_true",
help="Option to create the directory in teacher mode so we have the warnings enabled in the Makefile. However you still have to specify BUG in defines or udefines to have the bug or not.",
)
parser.add_argument(
"--dev",
action="store_true",
help="Option to toggle development mode and use symbolic links.",
)
parser.add_argument(
"--defines",
nargs="+",
......@@ -126,25 +131,40 @@ else:
create_dir(DEST_DIR, args.clear)
def copy_with_unifdef(in_file: str, defines: list[str] = [], udefines: list[str] = []):
def copy_with_unifdef(
in_file: str, out_file: str, defines: list[str] = [], udefines: list[str] = []
):
"""Copy the file to destination directory by applying unifdef"""
# outfile is basename of the in_file in the dest directory
out_file = os.path.join(DEST_DIR, os.path.basename(in_file))
apply_unifdef(in_file, out_file, args.defines + defines, args.udefines + udefines)
def process_directory(src_dir: str, defines: list[str] = [], udefines: list[str] = []):
"""Applies copy_with_unifdef to all the files in a directory"""
"""Applies copy_with_unifdef to all the files in a directory.
In development mode, creates symbolic links and don't apply unifdef"""
for file_path in os.listdir(src_dir):
# if the file a .c or .h apply unifdef
abs_path = os.path.join(src_dir, file_path)
if file_path.endswith(".c") or file_path.endswith(".h"):
copy_with_unifdef(abs_path)
logging.debug(f"Applied unifdef to {file_path}")
elif os.path.isfile(abs_path):
# simple copy to the destination directory
shutil.copy(abs_path, DEST_DIR)
logging.debug(f"Copied {file_path}")
# skip files that starts with _
if os.path.basename(file_path).startswith("_"):
continue
abs_path = os.path.abspath(os.path.join(src_dir, file_path))
out_file = os.path.abspath(os.path.join(DEST_DIR, os.path.basename(file_path)))
if args.dev:
# in development mode, just symlink the files
os.symlink(abs_path, out_file)
logging.debug(f"linked named {out_file} to {abs_path}")
else:
# if the file a .c or .h apply unifdef
if file_path.endswith(".c") or file_path.endswith(".h"):
copy_with_unifdef(abs_path, out_file, defines, udefines)
logging.debug(f"Applied unifdef to {file_path}")
elif os.path.isfile(abs_path):
# simple copy to the destination directory
shutil.copy(abs_path, DEST_DIR)
logging.debug(f"Copied {file_path}")
# === copy level files
......@@ -173,7 +193,7 @@ SRCS = $$(wildcard *.c)
OBJS = $$(SRCS:.c=.o)
CC := gcc
CFLAGS := -O0 -g$warnings
CFLAGS := -O0 -g$warnings $defines
all: $$(MAINPROG)
......@@ -199,8 +219,13 @@ if args.teacher:
else:
warnings = ""
if args.dev:
define_str = " -D".join([""] + args.defines)
else:
define_str = ""
makefile_string = template_makefile.substitute(
exec_name=metadata["exec_name"], warnings=warnings
exec_name=metadata["exec_name"], warnings=warnings, defines=define_str
)
# write it into Makefile
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment