Sublime Forum

[SOLVED] Intermittent failure in custom build command

#1

Hi there,

I use a custom build script to build our product. It generally works great, except that it works intermittently: when I first start Sublime it usually works the first or second time, but as time goes on it works less and less. If I restart Sublime it goes back to working more frequently. By “works” I mean that the build runs, I can jump to the errors in the output window, etc.; by “doesn’t work” I mean that the build output window is cleared but then nothing is added to it (and the build process either never gets started or terminates immediately). There is no such problem running the build script from the command line. I am on the latest ST3 stable build on OS X, and with the most recent build the problem has gotten worse. I find it bizarre that the problem is intermittent; it’s rare that I encounter such a problem in Python unless there is some sort of uninitialized memory or variable in the underlying C++ code that backs a Python module. Here is the script:

import sublime, sublime_plugin, json

class FabricBuildCommand(sublime_plugin.WindowCommand):
  def run(self, **kwargs):
    if hasattr(self, 'text'):
      text = self.text
    else:
      text = 'Debug klTests'

    def runBuild(text):
      self.text = text
      return self.window.run_command('exec', {
        "working_dir": kwargs["working_dir"],
        "cmd": [
          kwargs["working_dir"] + '/Util/SublimeBuild.sh',
          kwargs["working_dir"]
          ] + text.split(' '),
        "file_regex": kwargs["file_regex"],
        }),

    self.window.show_input_panel(
      "Fabric Build:",
      text,
      runBuild,
      lambda text: None,
      lambda: None
      )

Thanks for any suggestions anyone has on how I can debug this! I am definitely a ST3 scripting newbie.

0 Likes

#2

Have you confirmed that the subprocess with your build command terminates?

If you want an environment similar to your Terminal, you should use shell_cmd instead of cmd. In that case, the argument is a string, not a list of strings.

0 Likes

#3

Yes, at least as seen from the process monitor the build process is definitely terminating.

I changed from using “cmd” to using “shell_cmd” and this appears to have fixed the problem – at least, it successful started six times in a row, which I don’t think was very likely to happen before. Thank you @wbond!

For reference, here is the new build script:

import sublime, sublime_plugin, json

class FabricBuildCommand(sublime_plugin.WindowCommand):
  def run(self, **kwargs):
    if hasattr(self, 'text'):
      text = self.text
    else:
      text = 'Debug klTests'

    def runBuild(text):
      self.text = text
      return self.window.run_command('exec', {
        "working_dir": kwargs["working_dir"],
        "shell_cmd": kwargs["working_dir"] + '/Util/SublimeBuild.sh' + " " + kwargs["working_dir"] + " " + text,
        "file_regex": kwargs["file_regex"],
        }),

    self.window.show_input_panel(
      "Fabric Build:",
      text,
      runBuild,
      lambda text: None,
      lambda: None
      )
0 Likes

#4

Follow up: this is quite certainly solved now, purely by changing “cmd” to “shell_cmd”. Note that the “cmd” syntax was correct since, when it ran, it did run correctly.

0 Likes