Home Download Buy Blog Forum Support

lock build file

lock build file

Postby shagwana on Mon Jul 11, 2011 9:11 pm

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! :D
shagwana
 
Posts: 17
Joined: Mon Jul 11, 2011 8:37 pm

Re: lock build file

Postby bizoo on Wed Jul 13, 2011 5:34 am

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

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 ?
bizoo
 
Posts: 873
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: lock build file

Postby shagwana on Wed Jul 13, 2011 7:21 pm

I am *trying* to use sublime text with a programming language called monkey ( http://www.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!
shagwana
 
Posts: 17
Joined: Mon Jul 11, 2011 8:37 pm

Re: lock build file

Postby guillermooo on Wed Jul 13, 2011 7:40 pm

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:

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


You can read up on build systems here:

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

Hope that helps!
guillermooo
 
Posts: 723
Joined: Thu Jul 23, 2009 9:06 am

Re: lock build file

Postby shagwana on Thu Jul 14, 2011 6:29 am

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!.
shagwana
 
Posts: 17
Joined: Mon Jul 11, 2011 8:37 pm

Re: lock build file

Postby shagwana on Thu Jul 14, 2011 5:03 pm

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)
Code: Select all

        #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)
Code: Select all
{
"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?
shagwana
 
Posts: 17
Joined: Mon Jul 11, 2011 8:37 pm

Re: lock build file

Postby shagwana on Thu Jul 14, 2011 5:08 pm

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

just saved it to User rather then Default!
shagwana
 
Posts: 17
Joined: Mon Jul 11, 2011 8:37 pm

Re: lock build file

Postby guillermooo on Thu Jul 14, 2011 5:28 pm

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".
guillermooo
 
Posts: 723
Joined: Thu Jul 23, 2009 9:06 am


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 12 guests