Sublime Forum

Is it possible to create a build system for only one specific platform?

#1

I have created a super-simple build system to execute batch files in Windows:

{
    
    "selector": "source.dosbatch",
    
    "windows": {
        "shell_cmd": "${file}",
    }
}

But it still shows up in Linux as a possible build system, despite having no shell_cmd defined for that platform. Is there a way to get the build system to only be available on Windows?

(It currently fails on Linux with the error shell_cmd or cmd is required, but I’d prefer it didn’t show up at all…)

I know that if I were to make it part of a package distributed by Package Control, I could set what platforms the entire package is available on, but imagine a situation where you want to include a syntax definition and a build system in a package, but only have the build system available on certain platforms. That way, one can still edit documents with correct syntax highlighting on a different platform.

0 Likes

#2

I can’t test them right now, but here’s two ideas:

  • Implement a proxy WindowCommand and have it forward build system parameters to exec. Make the is_enabled() method return False for other platforms.
  • Have an init step in the package where you remove a suffix from the build system file if you are on Windows (for example, Foo.sublime-build.off to Foo.sublime-build).

With the first one I guess you’ll lose the integration with Ctrl+B, though. ??

I know you’re saying that you don’t necessarily plan to release this as a package, so this may not be an option for you.

2 Likes

#3

Thanks for the ideas, @guillermooo :slight_smile:

I’ll probably go for the latter option - even if it’s not part of a package, I can still have a Python file in my Packages/User folder that will do the renaming, while allowing me to sync my user package folder with other operating systems :slight_smile:

I do wonder, however, whether ST3’s default handling of .sublime-build files missing a cmd or shell_cmd for a platform could be changed in a future ST release :slight_smile: I personally don’t think there is any benefit to the current error over just not showing the build system… :wink:

2 Likes

#4

Debugging. Most people aren’t going to purposefully create a build system that only works on one OS, but are likely to accidentally miss a key or not understand what is required.

0 Likes

#5

ST could show a message in the console when it parses the .sublime-build file to explain what is going on, but I get your point :slight_smile:

0 Likes

#6

Maybe some alternative syntax could be used to make a build system platform specific?

Naming the file name (Windows).sublime-build, for example? Like how keybindings and settings work :slight_smile:

1 Like

#7

I have logged my idea here: https://github.com/SublimeTextIssues/Core/issues/1311

0 Likes