Skip to content

Commit

Permalink
csproj_template
Browse files Browse the repository at this point in the history
  • Loading branch information
kzrnm committed Mar 22, 2022
1 parent 4a13c59 commit fcfcb9c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .verify-helper/docs/static/document.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`) やそのオプションを指定できます。
Expand Down
4 changes: 3 additions & 1 deletion .verify-helper/docs/static/document.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 18 additions & 3 deletions onlinejudge_verify/languages/csharp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -186,16 +187,30 @@ 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('''<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>{}</TargetFramework>
</PropertyGroup>
</Project>'''.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)

Expand Down

0 comments on commit fcfcb9c

Please sign in to comment.