Build System 说明(下面的文字摘自官方文档Build_Systems):
File Format
.build-system files use JSON. Here’s an example:
{
"cmd": ["python", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
Options
-
cmd
-
Array containing the command to run and its desired arguments. If you don’tspecify an absolute path, the external program will be searched in yourPATH, one of your system’s environmental variables.
On Windows, GUIs are supressed.
file_regex
- Optional. Regular expression (Perl-style) to capture error output of cmd. See the next section for details. line_regex
- Optional. If file_regex doesn’t match on the current line, but line_regex exists, and it does match on the current line, thenwalk backwards through the buffer until a line matching fileregex isfound, and use these two matches to determine the file and line to go to. selector
- Optional. Used when Tools | Build System | Automatic is set to true.Sublime Text uses this scope selector to find the appropriate build systemfor the active view. working_dir
- Optional. Directory to change the current directory to before running cmd.The original current directory is restored afterwards. encoding
- Optional. Output encoding of cmd. Must be a valid python encoding.Defaults to UTF-8. target
-
Optional. Sublime Text command to run. Defaults toexec (Packages/Default/exec.py).This command receives the configuration data specified in the.build-system file.
Used to override the default build system command. Note that if you chooseto override the default command for build systems, you can add arbitraryvariables in the.sublime-build file.
env
-
Optional. Dictionary of environment variables to be merged with the currentprocess’ before passing them tocmd.
Use this element, for example, to add or modify environment variableswithout modifying your system’s settings.
shell
- Optional. If true, cmd will be run through the shell ( cmd.exe, bash…). path
-
Optional. This string will replace the current process’PATH beforecallingcmd. The old PATHvalue will be restored after that.
Use this option to add directories toPATH without having to modifyyour system’s settings.
Capturing Error Output withfile_regex
The file_regex option uses a Perl-style regular expression to capture upto four fields of error information from the build program’s output, namely:file name,line number,column number anderror message. Usegroups in the pattern to capture this information. Thefile name field andtheline numberfield are required.
When error information is captured, you can navigate to error instances inyour project’s files withF4 andShift+F4. If available, the capturederror message will be displayed in the status bar.
Platform-specific Options
The windows,osx andlinux elements let you provideplatform-specific data in the build system. Here’s an example:
{
"cmd": ["ant"],
"file_regex": "^ *\\[javac\\] (.+):([0-9]+):() (.*)$",
"working_dir": "${project_path:${folder}}",
"selector": "source.java",
"windows":
{
"cmd": ["ant.bat"]
}
}
In this case,ant will be executed for every platform except Windows, whereant.bat will be used instead.
Variables
Build systems expand the following variables in.sublime-build files:
$file_path | The directory of the current file, e. g.,C:Files. |
$file | The full path to the current file, e. g.,C:FilesChapter1.txt. |
$file_name | The name portion of the current file, e. g.,Chapter1.txt. |
$file_extension | The extension portion of the current file, e. g.,txt. |
$file_base_name | The name only portion of the current file, e. g.,Document. |
$packages | The full path to thePackages folder. |
$project | The full path to the current project file. |
$project_path | The directory of the current project file. |
$project_name | The name portion of the current project file. |
$project_extension | The extension portion of the current project file. |
$project_base_name | The name only portion of the current project file. |
Place Holders for Variables
Features found in snippets can be used with these variables. For example:
${project_name:Default}
This will emit the name of the current project if there is one, otherwiseDefault.
${file/\.php/\.txt/}
This will emit the full path of the current file, replacing.php with.txt.
配置方法:
在“我的电脑”上,右键找到“属性”,选择“高级系统设置”,进到“环境变量”里面;
(1)创建三个系统变量
在命令行输入set命令会有对应的VS信息,vs2010是VS100COMNTOOLS
<1>名字: VS100Common
值: C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7
<2>名字: VS100VC
值: C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC
<3>名字: VS100SDK
值: C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A
(2)创建(或追加)三个用户变量
<1>名字: PATH
值 :%VS100VC%\BIN;%VS100Common%\IDE;%VS100Common%\TOOLS;%VS100SDK%\BIN;%PATH%
<2>名字: INCLUDE
值 :%VS100VC%\INCLUDE;%VS100VC%\ATLMFC\INCLUDE;%VS100SDK%\INCLUDE;%INCLUDE%
<3>名字: LIB
值 :%VS100VC%\LIB;%VS100VC%\ATLMFC\LIB;%VS100SDK%\LIB;%LIB%
(2)创建(或追加)三个用户变量
{
"cmd": ["CL", "/EHsc", "/Fo${file_base_name}", "/O2", "${file}"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++",
"encoding":"cp936",
"variants":
[
{
"name": "Run",
"cmd": ["CMD", "/U", "/C", "CL /Fo${file_base_name} /O2 ${file} && ${file_base_name}"]
}
]}
CTRL+B 显示Building ,无法显示信息解决方案:
exec.py里面替换
proc_env[k] = os.path.expandvars(v).encode(sys.getfilesystemencoding())
为
proc_env[k] = os.path.expandvars(v.decode(sys.getfilesystemencoding())).encode(sys.getfilesystemencoding())