Skip to content

Commit fcfcb9c

Browse files
committed
csproj_template
1 parent 4a13c59 commit fcfcb9c

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

.verify-helper/docs/static/document.ja.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,14 @@ CXXFLAGS = ["-std=c++17", "-Wall", "-g", "-fsanitize=undefined", "-D_GLIBCXX_DEB
5656
`.verify-helper/config.toml` というファイルを作って以下のように設定を書くと各種設定ができます。
5757

5858
- static_embedding: `dotnet-source-expand``--static-embedding` オプション
59+
- csproj_template: テストファイルのコンパイル時に使われる csproj を指定します。
5960

6061
``` toml
6162
[[languages.csharp]]
6263
static_embedding = "// embed"
64+
csproj_template = ".verify-helper/csproj.template"
6365
```
66+
6467
### Nim の設定
6568

6669
`.verify-helper/config.toml` というファイルを作って以下のように設定を書くと、コンパイルの際に変換する言語 (例: `c`, `cpp`) やそのオプションを指定できます。

.verify-helper/docs/static/document.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ For the details refer to [examples/csharpsx](https://github.com/online-judge-too
5454

5555
You can specify compilers and options with writing `.verify-helper/config.toml` as below.
5656

57-
- static_embedding: `dotnet-source-expand` with `--static-embedding` option
57+
- static_embedding: `dotnet-source-expand` with `--static-embedding` option.
58+
- csproj_template: test file will be compiled with this csproj file.
5859

5960
``` toml
6061
[[languages.csharp]]
6162
static_embedding = "// embed"
63+
csproj_template = ".verify-helper/csproj.template"
6264
```
6365

6466
### Settings for Nim

onlinejudge_verify/languages/csharp.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ class CSharpConfig:
178178
def __init__(self, config: Dict[str, Any]) -> None:
179179
root = config.get('languages', {}).get('csharp', {})
180180
self.static_embedding: Optional[str] = root.get('static_embedding', None)
181+
self.csproj_template: Optional[str] = root.get('csproj_template', None)
181182

182183

183184
class CSharpLanguageEnvironment(LanguageEnvironment):
@@ -186,16 +187,30 @@ def __init__(self, config: CSharpConfig) -> None:
186187
self.config = config
187188

188189
@staticmethod
189-
def _create_runner_project(code: bytes, target_framework: str, output_dir):
190-
os.makedirs(str(output_dir), exist_ok=True)
191-
with open(output_dir / 'runner.csproj', 'w') as f:
190+
def _write_default_project(output_file: pathlib.Path, target_framework: str) -> None:
191+
with open(output_file, 'w') as f:
192192
f.write('''<Project Sdk="Microsoft.NET.Sdk">
193193
<PropertyGroup>
194194
<OutputType>Exe</OutputType>
195195
<TargetFramework>{}</TargetFramework>
196196
</PropertyGroup>
197197
</Project>'''.format(target_framework))
198198

199+
def _write_csproj(self, output_file: pathlib.Path, target_framework: str) -> None:
200+
if self.config.csproj_template is None:
201+
self._write_default_project(output_file, target_framework)
202+
return
203+
csproj_template_path = pathlib.Path(self.config.csproj_template)
204+
if not csproj_template_path.exists():
205+
logger.warning('%s is not found.', self.config.csproj_template)
206+
self._write_default_project(output_file, target_framework)
207+
return
208+
209+
shutil.copy(str(csproj_template_path), str(output_file))
210+
211+
def _create_runner_project(self, code: bytes, target_framework: str, output_dir):
212+
os.makedirs(str(output_dir), exist_ok=True)
213+
self._write_csproj(output_dir / 'runner.csproj', target_framework)
199214
with open(output_dir / 'main.cs', 'wb') as f:
200215
f.write(code)
201216

0 commit comments

Comments
 (0)