diff --git a/.verify-helper/docs/static/document.ja.md b/.verify-helper/docs/static/document.ja.md index 4267ae94..8d7550cb 100644 --- a/.verify-helper/docs/static/document.ja.md +++ b/.verify-helper/docs/static/document.ja.md @@ -56,11 +56,14 @@ CXXFLAGS = ["-std=c++17", "-Wall", "-g", "-fsanitize=undefined", "-D_GLIBCXX_DEB `.verify-helper/config.toml` というファイルを作って以下のように設定を書くと各種設定ができます。 - static_embedding: `dotnet-source-expand` の `--static-embedding` オプション +- csproj_template: テストファイルのコンパイル時に使われる csproj を指定します。 ``` toml [[languages.csharp]] static_embedding = "// embed" +csproj_template = ".verify-helper/csproj.template" ``` + ### Nim の設定 `.verify-helper/config.toml` というファイルを作って以下のように設定を書くと、コンパイルの際に変換する言語 (例: `c`, `cpp`) やそのオプションを指定できます。 diff --git a/.verify-helper/docs/static/document.md b/.verify-helper/docs/static/document.md index 55b41955..9b966564 100644 --- a/.verify-helper/docs/static/document.md +++ b/.verify-helper/docs/static/document.md @@ -54,11 +54,13 @@ For the details refer to [examples/csharpsx](https://github.com/online-judge-too You can specify compilers and options with writing `.verify-helper/config.toml` as below. -- static_embedding: `dotnet-source-expand` with `--static-embedding` option +- static_embedding: `dotnet-source-expand` with `--static-embedding` option. +- csproj_template: test file will be compiled with this csproj file. ``` toml [[languages.csharp]] static_embedding = "// embed" +csproj_template = ".verify-helper/csproj.template" ``` ### Settings for Nim diff --git a/onlinejudge_verify/languages/csharp.py b/onlinejudge_verify/languages/csharp.py index 941ddf31..fe0a3a8d 100644 --- a/onlinejudge_verify/languages/csharp.py +++ b/onlinejudge_verify/languages/csharp.py @@ -178,6 +178,7 @@ class CSharpConfig: def __init__(self, config: Dict[str, Any]) -> None: root = config.get('languages', {}).get('csharp', {}) self.static_embedding: Optional[str] = root.get('static_embedding', None) + self.csproj_template: Optional[str] = root.get('csproj_template', None) class CSharpLanguageEnvironment(LanguageEnvironment): @@ -186,9 +187,8 @@ def __init__(self, config: CSharpConfig) -> None: self.config = config @staticmethod - def _create_runner_project(code: bytes, target_framework: str, output_dir): - os.makedirs(str(output_dir), exist_ok=True) - with open(output_dir / 'runner.csproj', 'w') as f: + def _write_default_project(output_file: pathlib.Path, target_framework: str) -> None: + with open(output_file, 'w') as f: f.write(''' Exe @@ -196,6 +196,21 @@ def _create_runner_project(code: bytes, target_framework: str, output_dir): '''.format(target_framework)) + def _write_csproj(self, output_file: pathlib.Path, target_framework: str) -> None: + if self.config.csproj_template is None: + self._write_default_project(output_file, target_framework) + return + csproj_template_path = pathlib.Path(self.config.csproj_template) + if not csproj_template_path.exists(): + logger.warning('%s is not found.', self.config.csproj_template) + self._write_default_project(output_file, target_framework) + return + + shutil.copy(str(csproj_template_path), str(output_file)) + + def _create_runner_project(self, code: bytes, target_framework: str, output_dir): + os.makedirs(str(output_dir), exist_ok=True) + self._write_csproj(output_dir / 'runner.csproj', target_framework) with open(output_dir / 'main.cs', 'wb') as f: f.write(code)