5

First off I would like to say that I am new to sublime text editor and I love it. I have no experience with JSON, however it does not seem difficult at all.

I am trying to write a build system that will call a bash script that will move a makefile into the directory that I am working and call that makefile, which will compile my c code with avr-gcc and then flash it to a connected microcontroller using avrdude.

I realize that sublime text 2 can only have one "cmd" object so I tried calling everything on one line from a terminal emulator and it worked exactly how I intended it to. The call was:

checkAVRmakefile.sh $PWD; make PROJECTNAME+=hello install

my script is in a directory on my $PATH environment variable and I pass it the directory that I am working in so it checks there for the makefile and if it isn't there it copies it from the directory that I have where I keep all of my makefiles. Then I call make and pass it the name I with the project to be called and the install flashes the avr microcontroller.

What I do with sublime is this:

{
"shell":true,
"cmd":[ "checkAVRmakefile.sh", "$file_path", ";" ,"make","PROJECTNAME+=$file_base_name","install"],
}

This only runs the bash script which puts the makefile in the directory but does not run make.

Does anyone see where I went wrong?

Any help is appreciated. I also asked a question similar to this on the sublime forums but no one has answered. Also I am on Ubuntu and am using ST2.

Jesse
  • 901
  • 1
  • 9
  • 25

3 Answers3

13

I found what my problem was. It was a combination of my bash script not handling spaces in my directory names and me not using the shell:true object corectly in the build system. So what works now is:

{
   "shell":true,
   "cmd":["check.sh $file_path && make PROJECTNAME+=$file_base_name install"]

}

It seems that with the shell:true object I don't need every input in the cmd list to be in quotes, just one long string.

(thanks to u/Scoo_ from reddit for suggesting the fix) Hope this helps some one else out

EDIT (17-3-2014): I have uploaded the files that I use for building my AVR projects to my git hub: https://github.com/Jesse-Millwood/AVR-Stuffs.git

Jesse
  • 901
  • 1
  • 9
  • 25
  • Where is `check.sh` stored? I'm trying the same thing but it never finds the script – Ozkan Mar 17 '14 at 11:28
  • 1
    `check.sh` is just a shell script I wrote to check if the make file is in the directory or not. It is pretty short and not very complicated. But that is in my /home/jesse/bin folder, which I have made sure is in my $PATH. If the make file isn't in the project directory, it copies a make file I have for AVR projects to the project directory. – Jesse Mar 17 '14 at 13:00
  • Ozkan I added a link to my git hub page where I have the files I use for AVR projects if you are interested – Jesse Mar 17 '14 at 14:26
  • Yeah, let me know if you have any more questions! – Jesse Mar 17 '14 at 15:11
1

So I've got this other installation of Python on my machine that I need for various purposes and I need to run a .bat or .cmd in my terminal to setup my environment variables before I use that flavor of Python. This needs to be done because otherwise it imports other modules of the same name from my default c:\Python27 python installation. I dug around the internet a bit and this is what I was able to come up with to get it to run from Sublime Text 2 when I hit ctrl+B (build).

I hope someone finds this useful. This is a custom buildfile that runs out of Sublime using my other flavor. You can create a new buildfile in Sublime by selecting Tools>Build System>New Build System and paste this into it with whatever mods you need.

{
    "shell":true,
    "cmd": ["C:\\GIT\\Folder1\\Folder1\\thebatch.cmd", "&;",
        "python", "-u", "$file"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "working_dir": "C:\\GIT\\GBmapper\\AWSInterfaces\\DEM_Processing"
}
Marc
  • 11
  • 2
  • More than 4 years later, this certainly helped me! All I needed to do was Sublime to run pandoc then open the PDF, and it wasn't working until I added the `"shell":true"` and `"&;"` pieces to my script. – Marian Minar Sep 21 '19 at 20:35
0

This is my solution without a wrapping shell script, tested for MacOS:

{
    "cmd": ["sh","-c","nasm -f bin -o '${file_base_name}' '${file}';chmod +x '${file_base_name}'"],
    "file_regex": "^(.+):([0-9]+)()?: error: (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.assembly"
}
Kamil.S
  • 5,205
  • 2
  • 22
  • 51