Sublime Text, Xeno, and Build Systems

Sublime Text, Xeno, and Build Systems

Tags
Tips & Tricks
Computer Science
Software Development
Published
January 12, 2014
Author
Randall Hand
URL
So I'm still loving the use of xeno.io for editing files on remote machines.  The only problem I've had so far, and 1it's not really a problem as much as an annoyance, is that I can't use Sublime Text's built-in Build features.  I'ld not really noticed how much I missed it until I wound up working back on a machine locally and I could hammer `F7` to build, then `F4` to jump to the first error.  Install the Build Next plugin and it really becomes a nice way to do development for C/C++ (Still missing the fabulous SublimeCLang plugin tho.)
 
So, I spent a bit of time and build a custom build-system that works with it.  It works with a shell script (below) to find the remote host and directory that the code really resides in, then `ssh`'es over to run the build.  Then it takes any filenames in the output (for error messages or warnings) and converts them back to the local path equivalents, so that `F4` works for taking you to the source of errors.
 
It works pretty well.  I also got it to force a `xeno sync` prior to a build, eliminating one of my major annoyances.  It works with either `make` or `ninja` (another favorite tool of mine), and works amazingly well.
 
To get this to work, first you'll need the following shell script, which I call `xeno-build.sh`:
#!/bin/bash if dirname $2 | grep .xeno then     echo This looks like a Xeno project.     SOURCEDIR=`dirname $2`     SYNCID=`git config xeno.syncprocessid`     echo Syncing...     /usr/local/bin/xeno-sync $SYNCID     HOST=`git remote -v | grep origin | grep push | cut -d ' ' -f 1 | cut -f 2 | cut -d '/' -f 3`     RDIR=`git config xeno.remotepath`     BUILDDIR=`dirname $RDIR`/build     echo Host = $HOST     echo BUILDDIR = $BUILDDIR     echo ssh $HOST "cd $BUILDDIR && $1" \| sed s=$RDIR=$SOURCEDIR=g     ssh $HOST "cd $BUILDDIR && env TERM=screen256color && $1" | /usr/local/opt/gnu-sed/libexec/gnubin/sed -u s=$RDIR=$SOURCEDIR=g fi
 
 
You might need to edit the `BUILDDIR` line to match how you do builds . I use `CMake` and do out-of-source builds, so I always have a `root/src` and `root/build` directory.
 
Then, in your Sublime Text 3 Packages folder, you'll want a build systems file like this:
{     "cmd":         [             "/Users/rhand/bin/xeno-build.sh",             "make -j9",             "$project_path/here"         ],     "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",     "variants":     [         {             "name": "Make Tests",             "cmd":             [                 "/Users/rhand/bin/xeno-build.sh",                 "make test",                 "$project_path/here"             ]         },         {             "name": "Make -j4",             "cmd":             [                 "/Users/rhand/bin/xeno-build.sh",                 "make -j4",                 "$project_path/here"             ]         },         {             "name": "Make Single",             "cmd":             [                 "/Users/rhand/bin/xeno-build.sh",                 "make",                 "$project_path/here"             ]         },         {             "name": "Clean",             "cmd":             [                 "/Users/rhand/bin/xeno-build.sh",                 "make clean",                 "$project_path/here"             ]         }     ] }
 
Simply replace "make" with "ninja" here and you can do that too.  The basic usage of the script is `xeno-build.sh command sourcefile`.  The `command` can be anything really (`make`, `ninja`, `rm`, or whatever build system you like), and the `sourcefile` is any file in the source directory (that really doesn't even have to exist).
 
So, hopefully someone out there will find this useful.  I've made it a standard part of my builds.