Multi-file mode


In the basic scenario, the submission contains source code that is a single file. The feature known as the "multi-file mode" allows for creating submissions consisting of multiple files. This opens up many possibilities, including:

  • launching complex projects consisting of multiple files,
  • using external libraries,
  • attaching files that are not the source code,
  • attaching configuration files.

The Sphere Engine service allows you to use the multi-file mode in two ways:

  1. By sending an archive (.tar.gz) with the file structure of the submission.
    This method is especially useful when you want to send a complex project containing a large number of files (e.g. when attaching an external library).

    The archive is sent using the source parameter of the POST /submissions method. An example using the curl command on Linux:

    $client = new CompilersClientV4('<access_token>', '<endpoint>');
    
    $tarSource = '<tar_source>';
    try {
        $response = $client->createSubmissionWithTarSource($tarSource, 11);
        // response['id'] stores the ID of the created submission
    } catch (SphereEngineResponseException $e) {
        // catch errors
    }
    See a complete example of how to use PHP Client library in a multi-file mode at github.com: Sphere Engine Compilers example and Sphere Engine Problems example
    curl -X POST -F "compilerId=1" -F "source=@prog.cpp.tar.gz" "https://<endpoint>/api/v4/submissions?access_token=<access_token>"
  2. By sending all files separately. This method can be conveniently used for a small number of files.

    Individual files are uploaded using (potentially multiple times) the files parameter of the POST /submissions method (the source parameter is ignored in this case). An example of using the curl command on Linux:

    $client = new CompilersClientV4('<access_token>', '<endpoint>');
    
    $files = array(
        'prog.c' => '<source_code>',
        'prog.h' => '<source_code>'
    );
    try {
        $response = $client->createSubmissionMultiFiles($files, 11);
        // response['id'] stores the ID of the created submission
    } catch (SphereEngineResponseException $e) {
        // catch errors
    }
    See a complete example of how to use PHP Client library in a multi-file mode at github.com: Sphere Engine Compilers example and Sphere Engine Problems example
    curl -X POST -F "compilerId=1" -F "files[prog.cpp]=@prog.cpp" -F "files[prog.h]=@prog.h" "https://<endpoint>/api/v4/submissions?access_token=<access_token>"

The submission can be sent in the form of binary data (in the case of uploading an archive) or contain such data (e.g. graphic files). Therefore, when using the multi-file mode you must create requests in the MULTIPART format (i.e. Content-Type: multipart/form-data) (i.e. it is impossible to use the JSON format; we advise against using the FORM format – in this case, the binary data is converted to a text form which can generate significant overhead on the size of the data transferred).

Note: The MULTIPART format allows you to transfer files in their explicit form, i.e. without converting them to a text format. The examples presented before (curl commands) use this approach.

The structure of a multi-file submission

The structure of files and directories of a submissions sent in the multi-file mode is not limited in any way. However, in some programming languages ​​there is a need to send the so-called entry file with the appropriate name and extension (depending on the programming language).

The entry file will be used to execute the submission. It must be at the highest level of the submission's directory structure. For example, a submission in Python must contain a file named prog.py and this file will be executed.

Supported programming languages

The following table shows a list of programming languages supported by the multi-file mode. In addition, we define the entry file, which should be at the highest level of the submission's directory structure:

ID Name Entry file
1 C++ (gcc) a file with a "cpp" extension containing the function named "main"
2 Pascal (gpc) prog.pas
3 Perl prog.pl
4 Python 2 prog.py
10 Java a file with a "java" extension containing a class that has a method named "main"
11 C (gcc) a file with a "c" extension containing the function named "main"
15 Prolog prog
17 Ruby prog.rb
19 Pike prog
21 Haskell prog.hs
22 Pascal (fpc) prog.pas
26 Lua prog.lua
27 C# a file with a "cs" extension containing a class that has a method named "main"
28 Bash prog.sh
29 PHP prog.php
35 JavaScript (rhino) prog.js
39 Scala a file with a "scala" extension containing a global scope class named "Main"
43 Objective-C prog.m
48 Dart prog.dart
50 VB.net a file with a "vb" extension containing a module that has a function named "Main"
54 Perl 6 prog.pl
56 Node.js prog.js
99 Python (PyPy) prog.py
104 AWK (gawk) prog.awk
114 Go a file with a "go" extension containing the function named "main" in the main package
116 Python 3 prog.py
117 R prog.r
126 Python 3 nbc prog.py