Sublime Forum

Understanding build system Advanced Example - how does it work?

#1

hello,

I need some help to understand how advanced build example works. It is so completely different.

here is shown the advanced example of a build system.

It consists of 2 files, my_example_build.py and My Example Build.sublime-build

Now, is the 2nd file building the 1st, or is the 1st called by the 2nd to build something completely different?

I don’t understand that python script at all, what is its purpose? Is this to replace a makefile?

thank you

0 Likes

#2

A sublime-build file represents instructions for Sublime that ostensibly is for building your program by way of executing some external program(s) or taking some other action.

In a regular build system, you specify either a cmd or a shell_cmd to specify the external program to run, and Sublime uses the built in exec command to run that program, using the other information in the sublime-build file to either tell the exec command how to proceed (e.g. by changing the environment) or to determine what build to use (e.g. by selecting based on the current file type).

The advanced example of a build does two things:

  1. It defines a custom WindowCommand subclass, which creates a new Sublime command in the same way that other plugins are created; this is the Python script.

  2. It includes a key named target in the sublime-build file that instructs Sublime that when this build is selected and used, the custom command should be used to carry out the build instead of the exec command; this is the sublime-build file.

An advanced build is generally only needed when your build needs to do something instead of or in addition to just running an external program of some sort, which includes if you need to provide more information to the build than the defaults allow.

The example you linked to is still executing an external program, it’s just using custom code to do it. It’s also selecting on its own the command to execute by way of custom arguments in the sublime-build file.

I’m currently working on a series of videos that goes through the creation of a custom build system and target that goes into this in more detail, though it will be a little while still before it’s completed,

3 Likes