Skip to content

Instantly share code, notes, and snippets.

@zrong
Created August 29, 2011 13:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save zrong/1178445 to your computer and use it in GitHub Desktop.
Save zrong/1178445 to your computer and use it in GitHub Desktop.
Vim加入所有源文件进入缓冲区,调用Ant使用条件编译
# 设置FLEX SDK的路径
FLEX_HOME=D:/flex_sdks/4.5.1
# 设置源文件路径
# {$basedir} 就是本文件所在的目录
SRC_DIR =${basedir}/src
# libs目录,一般用来放swc文件
LIBS_DIR =${basedir}/libs
# 用于部署的文件夹
DEPLOY_DIR = ${basedir}/bin
#自定义的几个类库源码
SRC_ZRONG = e:/works/zrong.as3.git/src
# 以下为编译中使用的变量
# 设定一个默认的主文件,默认编译的是KTScreen.as。若需要编译其他文件,可以调用ant -Dmain=Other
main = KT2
<project name="kt2" default="build">
<!-- 2011-08-29 利用条件编译 -->
<!-- 3个参数,main指定要编译的文件的主文件名,post参数指定编译后的swf文件后缀,debug指定是否编译成调试版 -->
<property file="build.properties" />
<!-- 取环境变量 -->
<property environment="env"/>
<taskdef resource="flexTasks.tasks" classpath="${FLEX_HOME}/ant/lib/flexTasks.jar" />
<target name="build">
<!-- 如果提供了后缀,就按提供的值处理,否则为空(无后缀) -->
<condition property="postfix" value="${post}" else="">
<isset property="post"/>
</condition>
<!-- 如果设置了debug参数,就按照设置的值处理,否则就设置为true -->
<condition property="isDebug" value="${debug}" else="true">
<isset property="debug"/>
</condition>
<property name="outputSWF" value="${DEPLOY_DIR}/${main}${postfix}.swf"/>
<echo>编译目标:${outputSWF} postfix:${postfix} isDebug:${isDebug}</echo>
<antcall target="init"/>
<antcall target="build_mxmlc"/>
<antcall target="fdb"/>
<antcall target="ftp"/>
</target>
<!-- 清理目录,复制没有嵌入的文件 -->
<target name="init" if="${init}">
<delete dir="${outputSWF}" />
<delete dir="${DEPLOY_DIR}/assets/magic" />
<delete dir="${DEPLOY_DIR}/assets/emotions" />
<!-- 将资源目录复制到部署目录 -->
<copy todir="${DEPLOY_DIR}/assets/magic">
<fileset dir="${SRC_DIR}/assets/magic" />
</copy>
<copy todir="${DEPLOY_DIR}/assets/emotions">
<fileset dir="${SRC_DIR}/assets/emotions" />
</copy>
</target>
<!-- 编译 -->
<target name="build_mxmlc">
<echo>build_mxmlc outSWF:${outputSWF} isDebug:${isDebug}</echo>
<mxmlc file="${SRC_DIR}/${main}.as" output="${outputSWF}">
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
<source-path path-element="${SRC_ZRONG}" />
<compiler.library-path dir="${basedir}" append="true">
<include name="libs" />
</compiler.library-path>
<!-- 必须加上这行,如果不加,当使用[Embed]的标签的时候,就会出现VerifyError: Error #1014: 无法找到类 。 原因应该是没有将mx.core包编译进入。官方文档说这个属性默认是true, 不要相信它-->
<static-link-runtime-shared-libraries>true</static-link-runtime-shared-libraries>
<!-- 编译成可调试的版本 -->
<compiler.debug>${isDebug}</compiler.debug>
</mxmlc>
</target>
<!-- 打开调试器进行调试 -->
<target name="fdb" if="${fdb}">
<exec executable="cmd" spawn="true" osfamily="windows">
<arg line="/K start fdb ${outputSWF}" />
</exec>
</target>
<!-- 上传到ftp -->
<target name="ftp" if="${ftp}">
<ftp server="10.0.0.5" port="21" userid="zr" password="zr" remotedir="kt2/swf/" depends="true" verbose="true">
<fileset dir="${DEPLOY_DIR}" includes="${main}/${postfix}.swf" />
</ftp>
</target>
</project>
" 加入整个项目的所有可编辑文件进入缓冲区列表
lcd E:/Works/KT2
call BaddList("project/src")
call BaddList("json", "json")
lcd project
let init = glob("%")
edit src/KT2.as
bd init
unlet init
command! -nargs=* Make call Ant(<f-args>)
" 参数1 编译的主文件名
" 参数2 文件名后缀
" 参数3 是否编译Debug版
" 参数4 要执行的ant的任务名,逗号分隔。可用值为init,ftp,fdb
function! Ant(...)
let param = ''
if exists('a:1') && a:1 != '0'
let param .= ' -Dmain='.a:1
endif
if exists('a:2') && a:2 != '0'
let param .= " -Dpost=".a:2
endif
if exists('a:3') && a:3 == '0'
let param .= ' -Ddebug=false'
endif
if exists('a:4') && a:4 != '0'
let targets = split(a:4, ',')
for targetName in targets
let param .= ' -D'.targetName.'=true'
endfor
endif
execute 'echo "make'.param.'"'
execute 'make '.param
endfunction
" 获取目录下的所有文件的列表
function! GetFileList(...)
if exists('a:1')
let path = a:1
else
let path = glob("%:h")
endif
if exists('a:2')
let ext = a:2
else
let ext = "as"
endif
let trueList = []
" 获取子目录中的文件列表
let fileList = split(glob(path."/**/*.".ext), "\<NL>")
for afile in fileList
if isdirectory(afile)
" 排除目录
continue
end
call add(trueList, afile)
endfor
return trueList
endfunction
" 输出buffer列表到当前缓冲区
function! EchoBaddList(...)
let baddList = call("GetFileList", a:000)
for afile in baddList
execute 'normal obadd '.afile
endfor
endfunction
" 将path中的文件直接加入buffer列表
function! BaddList(...)
let baddList = call("GetFileList", a:000)
for afile in baddList
execute 'badd '.afile
endfor
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment