Skip to content

Commit ad0cf42

Browse files
author
tommy
committed
enable compiler config
1 parent 8ff1461 commit ad0cf42

File tree

4 files changed

+56
-3
lines changed

4 files changed

+56
-3
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ code_generator_file="~/custom_code_generator.py"
234234
[postprocess]
235235
exec_on_each_problem_dir='clang-format -i ./*.cpp'
236236
exec_on_contest_dir='touch CMakeLists.txt'
237+
[compiler]
238+
compile_command='g++ main.cpp -o main -std=c++17'
239+
compile_only_when_diff_detected=true
237240
[tester]
238241
compile_before_testing=true
239242
compile_only_when_diff_detected=true
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class CompilerConfig:
2+
3+
def __init__(self,
4+
compile_only_when_diff_detected: bool = False,
5+
compile_command: str = None
6+
):
7+
self.compile_only_when_diff_detected = compile_only_when_diff_detected
8+
self.compile_command = compile_command

atcodertools/config/config.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
from atcodertools.config.etc_config import EtcConfig
99
from atcodertools.config.postprocess_config import PostprocessConfig
1010
from atcodertools.config.tester_config import TesterConfig
11+
from atcodertools.config.compiler_config import CompilerConfig
1112

1213

1314
class ConfigType(Enum):
1415
CODESTYLE = "codestyle"
1516
POSTPROCESS = "postprocess"
1617
TESTER = "tester"
1718
ETC = "etc"
19+
COMPILER = "compiler"
1820

1921

2022
def _update_config_dict(target_dic: Dict[str, Any], update_dic: Dict[str, Any]):
@@ -44,7 +46,8 @@ def __init__(self,
4446
code_style_config: CodeStyleConfig = CodeStyleConfig(),
4547
postprocess_config: PostprocessConfig = PostprocessConfig(),
4648
tester_config: TesterConfig = TesterConfig(),
47-
etc_config: EtcConfig = EtcConfig()
49+
etc_config: EtcConfig = EtcConfig(),
50+
compiler_config: CompilerConfig = CompilerConfig()
4851
):
4952
self.code_style_config = code_style_config
5053
self.postprocess_config = postprocess_config
@@ -101,5 +104,12 @@ def load(cls, fp: TextIO, get_config_type, args: Optional[Namespace] = None, lan
101104
save_no_session_cache=args.save_no_session_cache,
102105
skip_existing_problems=args.skip_existing_problems))
103106
result.etc_config = EtcConfig(**etc_config_dic)
107+
if ConfigType.COMPILER in get_config_type:
108+
compiler_config_dic = get_config_dic(config_dic, ConfigType.COMPILER)
109+
if args:
110+
compiler_config_dic = _update_config_dict(compiler_config_dic, dict(
111+
compile_only_when_diff_detected=args.compile_only_when_diff_detected,
112+
compile_command=args.compile_command))
113+
result.compiler_config = CompilerConfig(**compiler_config_dic)
104114

105115
return result

atcodertools/tools/compiler.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
#!/usr/bin/python3
22
import argparse
3+
from os.path import expanduser
34

45
from atcodertools.executils.run_command import run_command_with_returncode
56
from atcodertools.tools.models.metadata import Metadata
67
from atcodertools.common.language import Language
78
import os
89
import pathlib
10+
from atcodertools.config.config import Config, ConfigType
11+
from atcodertools.tools import get_default_config_path
12+
13+
USER_CONFIG_PATH = os.path.join(expanduser("~"), ".atcodertools.toml")
914

1015

1116
class BadStatusCodeException(Exception):
@@ -60,9 +65,36 @@ def main(prog, args):
6065
type=bool,
6166
default=False)
6267

68+
parser.add_argument("--config",
69+
help="File path to your config file\n{0}{1}".format("[Default (Primary)] {}\n".format(
70+
USER_CONFIG_PATH),
71+
"[Default (Secondary)] {}\n".format(
72+
get_default_config_path())),
73+
default=None)
74+
6375
args = parser.parse_args(args)
76+
if args.config is None:
77+
if os.path.exists(USER_CONFIG_PATH):
78+
args.config = USER_CONFIG_PATH
79+
else:
80+
args.config = get_default_config_path()
6481

6582
metadata = Metadata.load_from("./metadata.json")
66-
force_compile = not args.compile_only_when_diff_detected
83+
lang = metadata.lang
84+
85+
with open(args.config, "r") as f:
86+
config = Config.load(f, {ConfigType.COMPILER}, args, lang.name)
87+
88+
if args.compile_only_when_diff_detected:
89+
force_compile = not args.compile_only_when_diff_detected
90+
else:
91+
force_compile = not config.compiler_config.compile_only_when_diff_detected
92+
93+
if args.compile_command:
94+
compile_command = args.compile_command
95+
else:
96+
compile_command = config.compiler_config.compile_command
97+
if compile_command:
98+
compile_command = lang.get_compile_command("main", compile_command)
6799
compile_main_and_judge_programs(metadata.lang, force_compile=force_compile,
68-
compile_command=args.compile_command)
100+
compile_command=compile_command)

0 commit comments

Comments
 (0)