Build Systems

Build systems run external programs to process your files, and print their output to the output panel. Ultimately, they call subprocess.Popen.

Essentially, build systems are configuration data for an external program. In them, you specify the switches, options and environment information you want passed to the executable.

Optionally, you can override the default middleman between the configuration data and the external program. For example, you could implement the build system entirely in a Sublime Text plugin, without ever calling an external program. You can do this because this middleman is simply a Sublime Text plugin, implemented in Packages/Default/

File Format

Build systems use JSON. Here’s an example:

    "cmd": ["python", "-u", "$file"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python"



Array containing the command to run and its desired arguments. If you don’t specify an absolute path, the external program must be in your PATH, one of your system’s environmental variables.


Under Windows, GUIs are supressed.

Optional. Regular expression (Perl-style) to capture error output of cmd. See next section for more details.
Optional. If file_regex doesn’t match on the current line, but line_regex is specified, and it does match on the current line, then walk backwards through the buffer until a line matching file regex is found, and use these two matches to determine the file and line to go to.
Optional. Used when Tools | Build System | Automatic is set to true. Sublime Text uses this scope selector to find the appropriate build system for the active view automatically.
Optional. Directory to change the current directory to before running cmd. The original current directory is restored afterwards.
Optional. Output encoding of cmd. Must be a valid python encoding. Defaults to UTF-8.
Optional. Sublime Text command to run. Defaults to exec (Packages/Default/ It receives the configuration data specified in the .build-system file.
Optional. Dictionary of environment variables to be merged with the current process’ that will be passed to cmd.
Optional. If true, cmd will be run through the shell (cmd.exe, bash…).
Optional. This string will replace the current process’ PATH before calling cmd. The old PATH value will be restored after that. It’s useful to add directories to PATH that you don’t have or want in your regular PATH variable everywhere.

Capturing Error Output with file_regex

The file_regex option uses a Perl-style regular expression to capture up to four fields of error information from the build program’s output, namely: file name, line number, column number and error message. Use groups in the pattern to capture this information. The file name field and the line number field are required.

When error information is captured, you can navigate to error instances in your project’s files with F4 and Shift+F4. If available, the captured error message will be displayed in the status bar.

Platform-specific Options

windows, osx and linux are additional options to provide platform-specific data. Here’s an example:

    "cmd": ["ant"],
    "file_regex": "^ *\\[javac\\] (.+):([0-9]+):() (.*)$",
    "working_dir": "${project_path:${folder}}",
    "selector": "",

        "cmd": ["ant.bat"]

In this case, ant will be executed for every platform except Windows, where ant.bat will be used instead.


Build systems expand the following variables:

$file The full path to the current file, e. g., C:\Files\Chapter1.txt.
$file_path The directory of the current file, e. g., C:\Files.
$file_name The name portion of the current file, e. g., Chapter1.txt.
$file_extension The extension portion of the current file, e. g., txt.
$file_base_name The name only portion of the current file, e. g., Document.
$packages The full path to the Packages folder.
$project The full path to the current project file.
$project_path The directory of the current project file.
$project_name The name portion of the current project file.
$project_extension The extension portion of the current project file.
$project_base_name The name only portion of the current project file.

Place Holders for Variables

Features found in snippets can be used with these variables. For example:


This will emit the name of the current project if there is one, otherwise Default.


This will emit the full path of the current file, replacing .php with .txt.

Running Build Systems

Select the desired build system from Tools | Build System, and then select Tools | Build or press F7.

Troubleshooting Build Systems

External programs used in build systems need to be in your PATH. As a quick test, you can try to run them from the command line first and see whether they work. Note, however, that your shell’s PATH variable might differ to that seen by Sublime Text due to your shell’s profile. Remember that you can use the path option in a .build-system file to add directories to PATH without changing your system’s settings.

See also

Managing Environment Variables in Windows
Search Microsoft for this topic.