Sublime Forum

How to force my build `target` to be optional?

#1

How to force my build target to be optional?

My sublime build on my .sublime-project file is like this:

        {
            "working_dir": "$project_path/source",
            "name": "Build Main file",
            "cmd": ["sh", "make_run.sh", "main"],

            "target": "ansi_color_build",
        }

However, if someone forks my project and open it with Sublime Text, and does not have the package ANSIescape installed (the "target": "ansi_color_build"), I would like to it be ignored instead of not build anything at all and throw the error on the Sublime Text console:

Unable to find target command: ansi_color_build
0 Likes

#2

include a command in your project, which will execute ansi_color_build if the command exists or exec if it doesn’t, and use that in your build sustem

1 Like

#3

When users install your package, you could do a check if the other package is already installed and give them an option to do so if not.

Compare (for ST3):

0 Likes

#4

I do not now how to create a command for a project. The only thing I can think of is to create a new package where I create my own custom target which switches between the default exec and ansi_color_build.

However this does not solve the problem. Anyone who will download my project will still have to install a third part package.

I am not developing any package for Sublime Text. This is any normal .sublime-project as a C++ project:

{
    "folders":
    [
        {
            "path": ".",
        }
    ],
    "build_systems":
    [
        {
            "working_dir": "$project_path/source",
            "name": "Build Main file",
            "cmd": ["sh", "make_run.sh", "main"],

            "target": "ansi_color_build",
        }
    ]
}

I want to when someone open my project sublime-project embedded with a build system, as above, they can run it despite they have, not have not the package ANSIescape installed, and without the need to edit the sublime-project to remove the build target ansi_color_build.

I would like to the target ansi_color_build be ignored instead of not build anything at all and throw the error on the Sublime Text console:

Unable to find target command: ansi_color_build

When someone does not have the package ANSIescape installed.

0 Likes

#5

oh sorry, I wasn’t thinking properly and I kinda assumed your project was an ST plugin. Probably what you want to do isn’t really possible.

Even setting the syntax in your project build settings would cause an error when a user tries to build without the syntax definition installed

0 Likes

#6

For the purposes of having this be specific to a project the only thing I can think of that you could do would be to have your project specific build system include a variant that overrides target to be the default exec again (or make the default be exec and have the variant use target to override).

The downside to that is that everyone has to select an appropriate variant the first time they build.

3 Likes

#7

that seems like probably the best solution - good thinking batman!

0 Likes

#8

Thanks y’all for the time. I opened an feature request on the Sublime Text Core for it:

  1. $1617 Ignore invalid target and syntax settings on an .sublime-project
0 Likes