Rules
All rules are defined in @rules_contest//contest:defs.bzl
.
To use rules, put the following load
statement to the top of the BUILD
file.
load(
"@rules_contest//contest:defs.bzl",
"dataset_merge",
"dataset_generate",
...
)
dataset_merge
dataset_merge
rule builds a dataset from zero or more datasets and zero or
more data files. This rule can be used to build a dataset from static data
files, as well as to merge multiple datasets.
Parameters
Parameter |
Type |
Default |
Description |
---|---|---|---|
|
|
Required |
A unique name for the rule. |
|
|
|
A list of static data files to include in the new dataset. |
|
|
|
A list of datasets to merge to the new dataset. |
dataset_generate
dataset_generate
rule builds a dataset by running a program. By default,
it should write data files to the directory specified by the OUTPUT_DIR
environment variable.
This rule is typically used to generate random input data files.
Parameters
Parameter |
Type |
Default |
Description |
---|---|---|---|
|
|
Required |
A unique name for the rule. |
|
|
Required |
A label of an executable to run to generate data files. |
|
|
|
A shell command to run. |
Environment variables
The following environment variables are available on running a command.
Variable |
Description |
---|---|
|
A path to the executable specified in the |
|
A path to the directory where generated data files should be saved. |
dataset_derive
dataset_derive
rule extends a dataset by running a program. A program for
the dataset_derive
rule is run for each test case in the input dataset.
By default, a data file with an input file extension (.in
) is opened and
connected to the standard input of the program, and a data file with an output
file extension (.ans
) is opened and connected to the standard output.
The output dataset is built by combining the data files from the input dataset
and the generated output files. This rule is typically used to generate answer
data files by running a reference solution program over input data files.
Parameters
Parameter |
Type |
Default |
Description |
---|---|---|---|
|
|
Required |
A unique name for the rule. |
|
|
Required |
A label of an executable to run to generate data files. |
|
|
Required |
A label of a dataset that the new dataset derives from. |
|
|
|
A shell command to run. |
Environment variables
The following environment variables are available on running a command.
Variable |
Description |
---|---|
|
A path to the executable specified in the |
|
A path to the directory where source data files are located. |
|
A path to the directory where generated data files should be saved. |
|
A test case name to be processed. |
dataset_test
dataset_test
rule tests a dataset by running a program. A program for
the dataset_test
rule is run for each test case in the dataset.
By default, a data file with an input file extension (.in
) is opened and
connected to the standard input of the program. A test passes if the
program exits normally (exit code 0) for all test cases.
Parameters
Parameter |
Type |
Default |
Description |
---|---|---|---|
|
|
Required |
A unique name for the rule. |
|
|
Required |
A label of an executable to run to validate data files. |
|
|
Required |
A label of a dataset to test. |
|
|
|
A shell command to run. |
Environment variables
The following environment variables are available on running a command.
Variable |
Description |
---|---|
|
A path to the executable specified in the |
|
A path to the directory where source data files are located. |
|
A test case name to be processed. |
simple_judge
simple_judge
rule generates a simple judge program from a dataset containing
inputs and answers, and optionally a comparator program. A simple judge runs
a solution for each test case and determines if a program output matches with
an answer by running the specified comparator program. If no comparator is
specified, the default exact comparator is used.
A simple judge optionally accepts a command line flag --expect
that specifies
the expectation of a solution. It can be specified in the solution_test
rule
to customize the judge behavior for a solution.
Flag |
Expectation |
---|---|
|
A solution is accepted for all test cases (default) |
|
A solution is rejected for any one of test cases |
|
A solution is rejected for all test cases |
Parameters
Parameter |
Type |
Default |
Description |
---|---|---|---|
|
|
Required |
A unique name for the rule. |
|
|
Required |
A label of a dataset containing test cases. |
|
|
|
A shell command to run a solution. |
|
|
|
A label of an executable to run to compare an output file and an answer file. |
|
|
|
A shell command to run a comparator. |
Environment variables
The following environment variables are available on running a command.
Variable |
Description |
---|---|
|
A path to the executable being executed (comparator or solution). |
|
A path to the directory where data files are located. |
|
A test case name to be processed. |
|
A file path where a solution should write an output. |
interactive_judge
interactive_judge
rule generates an interactive judge program from a dataset
containing inputs and a server program. For each test case in the dataset,
an interactive judge starts a solution and the server in parallel and connects
their standard input and output for bi-directional interaction. A solution is
considered to pass a test case if the server program exits normally
(exit code 0).
An interactive judge optionally accepts a command line flag --expect
that
specifies the expectation of a solution. It can be specified in the
solution_test
rule to customize the judge behavior for a solution.
Flag |
Expectation |
---|---|
|
A solution is accepted for all test cases (default) |
|
A solution is rejected for any one of test cases |
|
A solution is rejected for all test cases |
Parameters
Parameter |
Type |
Default |
Description |
---|---|---|---|
|
|
Required |
A unique name for the rule. |
|
|
Required |
A label of a dataset containing test cases. |
|
|
Required |
A label of an executable to run to interact with a solution via standard input/output. |
|
|
|
A shell command to run a server. |
Environment variables
The following environment variables are available on running a command.
Variable |
Description |
---|---|
|
A path to the server executable being executed. |
|
A path to the directory where data files are located. |
|
A test case name to be processed. |
solution_test
solution_test
is a test rule that runs a judge against a solution.
On executing a judge program, the path to the specified solution program is
passed as a command line argument. A test is considered pass if the judge
program exits normally (exit code 0). You can also specify extra arguments to
pass to the judge program to control a judge program’s behavior.
Parameters
Parameter |
Type |
Default |
Description |
---|---|---|---|
|
|
Required |
A unique name for the rule. |
|
|
Required |
A label of a solution executable to pass to the judge. |
|
|
Required |
A label of a judge executable. |
|
|
|
A list of extra arguments passed to the judge. |
jinja2_template
jinja2_template
rule renders a Jinja2 template, substituting variables
computed from constraint YAML files, static files and datasets.
Parameters
Parameter |
Type |
Default |
Description |
---|---|---|---|
|
|
Required |
A unique name for the rule. |
|
|
Required |
A list of source template files. |
|
|
|
The label of a main template file. Optional if |
|
|
|
A list of labels of constraint YAML files whose values are made available as template variables. |
|
|
|
A list of labels of static files made available as template variables. |
|
|
|
An optional bale of a dataset whose contents are made available as template variables. |
Template variables
Templates have access to the following variables:
Variable |
Description |
Example |
---|---|---|
|
Constraints from YAML files |
|
|
Content of static files |
|
|
Content of the dataset |
|
markdown
markdown
rule renders a Markdown document to a HTML document. This rule
might be useful to build a file to upload to online judge systems.
Parameters
Parameter |
Type |
Default |
Description |
---|---|---|---|
|
|
Required |
A unique name for the rule. |
|
|
Required |
The label of a source Markdown file. |
cc_yaml_library
cc_yaml_library
rule generates a C++ header file from a constraint YAML file.
Parameters
Parameter |
Type |
Default |
Description |
---|---|---|---|
|
|
Required |
A unique name for the rule. |
|
|
Required |
The name of a YAML file. |
py_yaml_library
py_yaml_library
rule generates a Python module from a constraint YAML file.
Parameters
Parameter |
Type |
Default |
Description |
---|---|---|---|
|
|
Required |
A unique name for the rule. |
|
|
Required |
The name of a YAML file. |