Sublime Forum

Lock build file

#1

Hi, before I try and develop this, does anyone have ideas on how (or does it already exist) I go about setting up a plug that will let me lock the build file?

The idea goes like this;
I can lock the build file (and unlock it) - maybe a extra symbol on the file title or something to show its the locked one.
When it is locked, the build command will build only that file.
At any time it should be possible to unlock the build file as well.
Lock remains if the build file is closed!

I will say I am very new to sublime text how ever I am mighty impressed! :smiley:

0 Likes

#2

Sorry, I didn’t understand what you want here, and since there’s no answer I’m probably not the only one :smiley:

What do you mean by build file, xxx.sublime-build ?
And what do you mean by lock ?

Do you mean that whatever your current file is, the build system must process the same file for your project ?

0 Likes

#3

I am trying to use sublime text with a programming language called monkey ( monkeycoder.co.nz/ ). So far a user of the programming language has created a build file at that works great (Commands hi-light correctly and compiling/building works great)

In order to build my code (with include files) I need to build the main file.

Being able to lock this file would be ideal.

So when I try and build/compile, it automatically uses the locked file.

However after two days of poking about in sublime text 2, I think this is beyond me, I can’t even figure out how to call the build command!

0 Likes

#4

If I understand you correctly, Sublime Text won’t do what you need out of the box. There is no default way of excluding files in build systems. But perhaps you can setup your build system so that your compiler doesn’t rebuild certain files, but that’s a job extraneous to Sublime Text. Sublime Text, in the build-system file will merely turn on switches and options in your compiler. You compiler does the job, not Sublime Text.

Alternatively, you can wrap the build system (to reiterate, a build system is just configuration data for your compiler or any other similar thing that has options) and do the filtering of files yourself. For that, you need to create a plugin, use “target” in the build system, examine the options passed to you from the build system, preprocess files, and forward the desired options to the compiler.

Key concepts:

  1. exec (Python command in Packages/Default) - this one does the heavy lifting for build-systems; essentially it’s a subprocess call
  2. build-system dict (what you write in a build-system file is passed as args to exec)
  3. target element in build-system files (lets you replace “exec” as final command to execute with the build-system dict) - here you can do pre- and post-processing as needed. This option’s value would be a plugin in Sublime.

Sublime Text is all about customization, so there’s yet another way you can do this: you just create a shell script (or Python, Perl, C++… program) that does exactly what you want and specify its name in the build-system file (no target here). exec will then forward the options specified in the build-system file to your own build program.

Example:

{ "cmd": "my_script_that_locks_the_main_file.sh", "-foo", "-bar", "-K", "$file"] }

You can read up on build systems here:

sublimetext.info/docs/en/core/build_systems.html

Hope that helps!

0 Likes

#5

Thanks, the way I managed to get my select file to compile when I wanted it was to configure a new build system called custom. This build system will only compile one file (the master file).

I got the result I wanted without the pain!.

0 Likes

#6

After some further messing, I have managed to get a better implementation of a locked build file thing working.

I added…
exec.py (Packages\Default\exec.py) In ExecCommand class, def run (at around line 113)


        #If locked file, then use it (from settings!)
        settings = sublime.load_settings("Global.sublime-settings")
        sLockedBuildFile = settings.get('Locked_Build_File')
        if (sLockedBuildFile!=""):
            #We have a locked build file so make it the one to compile
            cmd[3]=sLockedBuildFile

Then to User Global.sublime-settings I added … (via preferences menu)

{
"Locked_Build_File": ""
}

Now when I place a file in this preference, its used for compiling rather then the selected file.

Now this is almost what I want, just need the ability to set the current file to the “Locked_Build_File” and a way to clear it, and I am golden.

I have a question, I figure its not wise to alter the exec.py file (ExecCommand), is there a way I can override it in a package in a safer way?

0 Likes

#7

Heh, figured out how to over ride the exec.py!

just saved it to User rather then Default!

0 Likes

#8

You can also just give your new copy a different name in order to avoid breakage of other build sys that do use exec. Then you’d have to specify the command’s new name in the “target” element of the .build-system file so that it doesn’t use “exec”.

0 Likes