Home Download Buy Blog Forum Support

Custom build system command output?

Custom build system command output?

Postby Fidde on Fri Mar 30, 2012 7:40 pm

I am new to Sublime and Python so this may be a really simple question.

I wrote a custom sublime window command to perform builds using existing running versions of Visual Studio (based on the excellent visual_studio.vim plugin for gvim). Everything works splendidly (well as splendidly as you could expect when you use COM interop). One of the problems I have though is that I can't pipe the output back to Sublime's build system file regexp.

My build system is really simple and just calls the plugin.

Code: Select all
{
    "target": "vs_build_solution",
    "file_regex": "(...*?)/(([0-9]*)/) : error C[0-9]*:(...*?)",
}


The custom command looks like this:

Code: Select all
class VsBuildSolution(sublime_plugin.WindowCommand):
  def run(self):
     dte_build_solution(0, _filename_output, _option_write_before_build)

     fp_output = file (_filename_output, 'r')
     output_msg = fp_output.read ()
     fp_output.close()

     sys.stderr.write(output_msg)

     pass


Where _filename_output is, obviously enough, the file name of the Visual Studio output (i.e. the output of the build). I now want to pipe this output back to the Sublime build system but for the life of me I can't seem to be able to do it. I tried the following and they just end up displaying the information in the Sublime console but no the sublime build results:

Code: Select all
sys.stderr.write
sys.stdout.write
print


Every other build system example I've seen just ends up calling a shell command through the use of 'exec' so I am a bit stuck here.
Fidde
 
Posts: 4
Joined: Fri Mar 30, 2012 7:25 pm

Re: Custom build system command output?

Postby bizoo on Sun Apr 01, 2012 8:24 am

Basically for a standard build system:
Code: Select all
import sublime, sublime_plugin
execcmd = __import__("exec")

class ExampleExecCommand(execcmd.ExecCommand):
    def finish(self, *args, **kwargs):       
        self.append_data(self.proc, "My content to add to build message\n")
        super(ExampleExecCommand, self).finish(*args, **kwargs)   

Now for you, it looks like you don't execute an external program but use a COM object, so more tweak are probably needed to the standard build system.
Look at "Sublime Text 2\Packages\Default\exec.py" that contains the the build command (ExecCommand).

Maybe the simplest way is to copy the exec.py source into a new one and rewrite it for your need.
bizoo
 
Posts: 879
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: Custom build system command output?

Postby Fidde on Sun Apr 01, 2012 7:01 pm

Thank you.

By looking at the exec command (excellent suggestion by the way). It turns out that what I want to do is rather simple. The exec command simply pipes its output to the "exec" panel.

Code: Select all
self.window.get_output_panel("exec")


When I do the same everything seems to work as intended.

In the long run I should probably follow your advice and copy/customize more of the infrastructure in the exec.py implementation.
Fidde
 
Posts: 4
Joined: Fri Mar 30, 2012 7:25 pm


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 5 guests