Sublime Forum

Own Build System

#1

Hi all
I have configured my own build system as shown below:

{
	"shell_cmd": "splint \"d:\\bin\\splint\\settings.lnt\" \"${file}\"",
	"file_regex": "^(.*):([0-9]*):([0-9]*): (.*)",
	"working_dir": "${file_path}",
	"selector": "source.c",
}

when executed, it works properly and also nicely displays the error messages, but there are two issues:

a) it always prints the environment variables when executed. Example:

...
D:\tmp\firmware\src\main.c:98:2: Warning 527: Unreachable code at token 'return'
:0:0: Note 900: Successful completion, 14 messages produced
[Finished in 0.0s with exit code 14]
[shell_cmd: splint -u -v "d:\bin\splint\settings.lnt" "D:\tmp\firmware\src\main.c"]
[dir: D:\tmp\firmware\src]
[path: C:\ProgramData\Oracle\Java....]

why does it show what command, directory and path it used? I don’t want it to display these values.

b) it seems to execute the command not only for the currently open file, but for all files in my project. When I run it for main.c, it is also run for all other *.c files, even though I didn’t configure the build system to do so, did I?

0 Likes

#2

This is because the tool you’re running is generating a non-zero result code:

D:\tmp\firmware\src\main.c:98:2: Warning 527: Unreachable code at token 'return'
:0:0: Note 900: Successful completion, 14 messages produced
[Finished in 0.0s with exit code 14]

An exit code of 0 is success and everything else is an error. So, Sublime thinks that the build is failing and as a result it’s giving you extra diagnostic information that might be helpful to you in resolving the problem.

If you don’t want to see those messages on error, add the following inside your build:

    "quiet": true,

With that in place you will no longer see the diagnostic information; a side effect of this is that you also won’t see the line that tells you how long the build took to finish.

As defined above, the command is getting a single argument that is the name of the current file; you can see exactly what it tried to execute in the diagnostic information:

[shell_cmd: splint -u -v "d:\bin\splint\settings.lnt" "D:\tmp\firmware\src\main.c"]

If that’s not doing the correct thing, then whatever splint is, it’s doing you favors and executing over more than one file.

That said, based on the output you provided above, I don’t see it linting multiple files (unless that’s information that you trimmed out of the diagnostic).

1 Like

#3

Hey,
HA! thanks, the quiet switch did the trick! Also, now it runs only on a single file. Don’t know what the reason was before it didn’t, perhaps it was also my mistake because I was almost asleep :wink: not everything works as it should, and thanks to the file_regex the errors are nicely displayed inline! yeah!

However one additional question:
is it possible to run an external program as above without using the Build System feature?
the reason I ask is the following: I quite often use “make” or “make clean” to build my software. In between, I sometimes run the code check with splint. However, for that I need to switch the build system which forces me to use multiple menus and stuff. It would be much more comfortable if I could add the splint command e.g. to the command palette. Is that possible? run a tool from the command palette?

0 Likes

#4

What you can do is write a build system with one “main” rule like the one you have above, but also define two variants to run make and make clean. Once written, you can select your variants with ctrlshiftB.

1 Like

#5

hmm I’m afraid I didn’t understand that. Could you maybe show an example?

0 Likes

#6

Here’s a section about variants in the community docs:

https://docs.sublimetext.io/reference/build_systems/configuration.html#variants

1 Like