<project name="vb6build">
<sysinfo />
<target name="makex">
<echo level="Warning" message="making ${vbp}" />
<vb6 project="${path::combine(srcroot,vbp)}"
outdir="${path::combine(srcroot,project.module)}"
errorfile="make_errors.txt"
verbose="true"
/>
</target>
<target name="vb6.make">
<call target="vb6.fixvbp" />
<delete file="build.error" if="${file::exists('build.error')}" />
<!-- write out ref file -->
<property name="tempexe32" value="${vbp::getvalue(vbp, 'ExeName32')}" />
<if test="${string::get-length(tempexe32) == 0}">
<property name="tempexe32" value="${vbp::getvalue(vbp, 'Name')}" />
</if>
<property name="exename32" value="${string::substring(tempexe32, 1, string::get-length(tempexe32) - 2)}" />
<echo file="${path::combine(path::combine(srcroot,project.module), path::get-file-name-without-extension(exename32) + '.ref')}" message="${vbp::get-references(path::combine(srcroot,vbp), 'projects.txt')}" />
<property name="conditional.compile" value="" />
<property name="conditional.compile" value="/D RELEASETYPE=1" if="${release.type == '1'}" />
<property name="conditional.compile" value="/D RELEASETYPE=2" if="${release.type == '2'}" />
<property name="conditional.compile" value="/D RELEASETYPE=3" if="${release.type == '3'}" />
<property name="conditional.compile" value="/D RELEASETYPE=4" if="${release.type == '4'}" />
<property name="conditional.compile" value="/D RELEASETYPE=5" if="${release.type == '5'}" />
<exec program="vb6.exe"
commandline="/m "${path::combine(srcroot,vbp)}" ${conditional.compile} /outdir "${path::combine(srcroot,project.module)}" /out build.error"
resultproperty="vb6.result"
failonerror="false"
/>
<!-- <echo message="vb6 returned ${vb6.result}"/> -->
<if test="${int::parse(vb6.result) != 0}">
<if test="${file::exists('build.error')}">
<property name="build.error.file" value="${file::get-file('build.error')}" />
<if test="${string::contains(build.error.file,'The binary compatibility DLL or EXE contains a parameter type or return type whose definition can not be found') or string::contains(build.error.file, 'BadImplementsRefInCompatLib') or string::contains(build.error.file, 'There is a compatibility error between the current project and the version-compatible component')}">
<!-- <echo message="ok here"/>
<fail message="vb6.exe returned failure."/> -->
<echo message="${vbp::setvalue(vbp, '^CompatibleMode=.*', '"1"')}"/>
<exec program="vb6.exe"
commandline="/m "${path::combine(srcroot,vbp)}" ${conditional.compile} /outdir "${path::combine(srcroot,project.module)}" /out build.error"
/>
<echo message="${vbp::setvalue(vbp, '^CompatibleMode=.*', '"2"')}"/>
<exec program="vb6.exe"
commandline="/m "${path::combine(srcroot,vbp)}" ${conditional.compile} /outdir "${path::combine(srcroot,project.module)}" /out build.error"
/>
</if>
<ifnot test="${string::contains(build.error.file,'The binary compatibility DLL or EXE contains a parameter type or return type whose definition can not be found') or string::contains(build.error.file, 'BadImplementsRefInCompatLib') or string::contains(build.error.file, 'There is a compatibility error between the current project and the version-compatible component')}">
<fail message="vb6.exe failed. Not a binary problem?"/>
</ifnot>
</if>
<if test="${file::exists('build.error') == false}">
<fail message="vb6.exe returned failure. No build.error file!"/>
</if>
</if>
<delete file="build.error" if="${file::exists('build.error')}" />
</target>
<!-- <target name="checkout">
<echo message="${cvsversion}" />
<cvs-checkout
destination="${srcroot}"
cvsroot="${cvsroot}"
password=""
module="${project.module}"
usesharpcvslib="false"
commandline="-l -r ${cvsversion}"
verbose="true" />
</target> -->
<target name="vb6.checkout">
<exec program="cvs.exe"
commandline="-d${cvsroot} checkout ${cvsvercmd} "${project.module}""
/>
</target>
<target name="vb6.update">
<exec program="cvs.exe"
commandline="update"
workingdir="${project.module}"
/>
</target>
<target name="vb6.checkpath32">
<property name="isuai" value="false" />
<!-- Search the vbp for the CompatibleEXE32 line and see if it is in the UAI directory -->
<foreach item="Line" in="${path::combine(srcroot,vbp)}" delim="=" property="name,value,a,b,c,d">
<!-- <echo message="${name}" /> -->
<if test="${string::get-length(name) > 0}">
<if test="${name == 'CompatibleEXE32'}">
<property name="CompatibleEXE32" value="${string::replace(value,'"','')}" />
<property name="FileEXE32" value="${path::get-file-name(CompatibleEXE32)}" />
<property name="PathEXE32" value="${path::get-directory-name(CompatibleEXE32)}" />
<echo message="${value}" />
<if test="${string::to-lower(PathEXE32) == 'c:\program files\common files\uai'}">
<property name="isuai" value="true" />
</if>
</if>
</if>
</foreach>
<if test="${isuai}">
<!-- The NAnt cvs task does not add the checkout -d commandline properly -->
<if test="${file::exists(CompatibleEXE32)}">
<exec program="cvs.exe"
commandline="-d${cvsroot} update -l "${FileEXE32}""
workingdir="C:\Program Files\Common Files\UAI"
/>
</if>
<ifnot test="${file::exists(CompatibleEXE32)}">
<exec program="cvs.exe"
commandline="-d${cvsroot} checkout -d "UAI" "${path::combine(string::replace(string::to-lower(PathEXE32),'c:\',''), FileEXE32)}""
workingdir="C:\Program Files\Common Files"
/>
</ifnot>
</if>
</target>
<target name="vb6.register_exename32">
<foreach item="Line" in="${path::combine(srcroot,vbp)}" delim="=" property="name,value,a,b,c,d">
<if test="${string::get-length(name) > 0}">
<if test="${name == 'ExeName32'}">
<property name="ExeName32" value="${string::replace(value,'"','')}" />
<comregister file="${path::combine(path::combine(srcroot,project.module),ExeName32)}" failonerror="false" />
</if>
</if>
</foreach>
</target>
<target name="vb6.fixvbp">
<copy file="${path::combine(srcroot,vbp)}" tofile="${path::combine(srcroot,vbp)}.bak2" overwrite="true" />
<foreach item="Line" in="${path::combine(srcroot,vbp)}.bak2" delim="=" property="name,value,a,b,c,d">
<if test="${string::get-length(name) > 0}">
<if test="${name == 'Reference'}">
<!-- <echo message="${name} ${value}" /> -->
<regex pattern="#0#(?'reffile'.*)#" input="${value}" />
<property name="libraryfile" value="" />
<if test="${string::get-length(libraryfile) == 0}">
<if test="${file::exists(path::get-full-path(reffile))}">
<!-- <echo message="Found Directly ${value}" /> -->
<property name="libraryfile" value="${path::get-full-path(reffile)}" />
</if>
</if>
<!-- get files that are subdirectories and relative paths -->
<if test="${string::get-length(libraryfile) == 0}">
<if test="${string::substring(reffile, 1, 1) != ':' }">
<property name="relativefile" value="${path::get-full-path(path::combine(srcroot, path::combine(path::get-directory-name(vbp) ,reffile)))}" />
<if test="${file::exists(relativefile)}">
<!-- <echo message="Found relative ${relativefile}" /> -->
<property name="libraryfile" value="${relativefile}" />
</if>
</if>
</if>
<!-- look in sys32 folder -->
<if test="${string::get-length(libraryfile) == 0}">
<if test="${file::exists(path::combine(sys.os.folder.system, path::get-file-name(reffile)))}">
<!-- <echo message="Found sysfolder ${path::combine(sys.os.folder.system, path::get-file-name(reffile))}" /> -->
<property name="libraryfile" value="${path::combine(sys.os.folder.system, path::get-file-name(reffile))}" />
</if>
</if>
<if test="${string::get-length(libraryfile) > 0}">
<!-- replace version -->
<property name="dllversion" value="${typelib::major-version(libraryfile) + '.' + typelib::minor-version(libraryfile)}" />
<regex pattern="}#(?'refversion'.*\.*)#0#" input="${value}" />
<if test="${dllversion != refversion}">
<property name="searchstr" value="#0#.*${path::get-file-name(reffile)}#" />
<property name="vbp_replace_result" value="${vbp::replace-line(path::combine(srcroot,vbp), searchstr, '}#.*\.*#0#', '}#' + dllversion + '#0#')}" />
<echo level="Warning" message="Found in ${vbp} ${vbp_replace_result}" if="${string::get-length(vbp_replace_result) > 0}" />
</if>
<!-- replace clsid -->
<property name="clsid" value="${typelib::guid(libraryfile)}" />
<regex pattern="\*\\G(?'refclsid'.*)#.*\..*#0" input="${value}" />
<if test="${clsid != refclsid}">
<echo message="++ ${clsid} ${refclsid} ${path::get-file-name(reffile)}" />
<property name="searchstr" value="#0#.*${path::get-file-name(reffile)}#" />
<property name="vbp_replace_result" value="${vbp::replace-line(path::combine(srcroot,vbp), searchstr, '\*\\G{.*}#', '*\G' + clsid + '#')}" />
<echo level="Warning" message="Found in ${vbp} ${vbp_replace_result}" if="${string::get-length(vbp_replace_result) > 0}" />
</if>
</if>
<if test="${string::get-length(libraryfile) == 0}">
<echo level="Warning" message="not found ${reffile} ${libraryfile}" />
</if>
</if>
<if test="${name == 'Object'}">
<regex pattern="#0; (?'reffile'.*)$" input="${value}" />
<property name="libraryfile" value="" />
<if test="${string::get-length(libraryfile) == 0}">
<if test="${file::exists(path::get-full-path(reffile))}">
<!-- <echo message="Found Directly ${reffile}" /> -->
<property name="libraryfile" value="${path::get-full-path(reffile)}" />
</if>
</if>
<!-- get files that are subdirectories and relative paths -->
<if test="${string::get-length(libraryfile) == 0}">
<if test="${string::substring(reffile, 1, 1) != ':' }">
<property name="relativefile" value="${path::get-full-path(path::combine(srcroot, path::combine(path::get-directory-name(vbp) ,reffile)))}" />
<if test="${file::exists(relativefile)}">
<!-- <echo message="found relative ${relativefile}" /> -->
<property name="libraryfile" value="${relativefile}" />
</if>
</if>
</if>
<!-- look in sys32 folder -->
<if test="${string::get-length(libraryfile) == 0}">
<if test="${file::exists(path::combine(sys.os.folder.system, path::get-file-name(reffile)))}">
<!-- <echo message="found sys32 ${path::combine(sys.os.folder.system, path::get-file-name(reffile))}" /> -->
<property name="libraryfile" value="${path::combine(sys.os.folder.system, path::get-file-name(reffile))}" />
</if>
</if>
<!-- search library.cache -->
<if test="${string::get-length(libraryfile) == 0}">
<if test="${file::exists('library.cache')}" >
<foreach item="Line" in="library.cache" delim="|" property="cache.name,cache.file">
<if test="${cache.name == reffile}">
<!-- <echo message="found library.cache ${cache.file}" /> -->
<property name="libraryfile" value="${cache.file}" />
</if>
</foreach>
</if>
</if>
<!-- search srcroot -->
<if test="${string::get-length(libraryfile) == 0}">
<foreach item="File" property="searchfile">
<in>
<items>
<include name="${srcroot}/**/${reffile}" />
</items>
</in>
<do>
<!-- <echo message="found search ${searchfile}" /> -->
<property name="libraryfile" value="${searchfile}" />
<!-- log to cache file -->
<property name="write.cache" value="true" />
<if test="${file::exists('library.cache')}" >
<foreach item="Line" in="library.cache" delim="|" property="cache.name,cache.file">
<if test="${cache.name == reffile}">
<property name="write.cache" value="false" />
</if>
</foreach>
</if>
<echo message="${reffile}|${searchfile}" file="library.cache" append="true" />
</do>
</foreach>
</if>
<!-- search program files -->
<if test="${string::get-length(libraryfile) == 0}">
<foreach item="File" property="searchfile">
<in>
<items>
<include name="C:/Program Files/**/${reffile}" />
</items>
</in>
<do>
<!-- <echo message="found search ${searchfile}" /> -->
<property name="libraryfile" value="${searchfile}" />
<!-- log to cache file -->
<property name="write.cache" value="true" />
<if test="${file::exists('library.cache')}" >
<foreach item="Line" in="library.cache" delim="|" property="cache.name,cache.file">
<if test="${cache.name == reffile}">
<property name="write.cache" value="false" />
</if>
</foreach>
</if>
<echo message="${reffile}|${searchfile}" file="library.cache" append="true" />
</do>
</foreach>
</if>
<if test="${string::get-length(libraryfile) > 0}">
<!-- replace version -->
<property name="dllversion" value="${typelib::major-version(libraryfile) + '.' + typelib::minor-version(libraryfile)}" />
<regex pattern="}#(?'objversion'.*\.*)#0" input="${value}" />
<if test="${dllversion != objversion}">
<property name="searchstr" value="#0; .*${path::get-file-name(reffile)}$" />
<property name="vbp_replace_result" value="${vbp::replace-line(path::combine(srcroot,vbp), searchstr, '}#.*\.*#0; ', '}#' + dllversion + '#0; ')}" />
<echo level="Warning" message="Found in ${vbp} ${vbp_replace_result}" if="${string::get-length(vbp_replace_result) > 0}" />
</if>
<!-- replace clsid -->
<property name="clsid" value="${typelib::guid(libraryfile)}" />
<regex pattern="^(?'objclsid'.*)#.*\..*#0" input="${value}" />
<if test="${clsid != objclsid}">
<echo message="++ ${clsid} ${objclsid} ${path::get-file-name(reffile)}" />
<property name="searchstr" value="#0; ${path::get-file-name(reffile)}" />
<property name="vbp_replace_result" value="${vbp::replace-line(path::combine(srcroot,vbp), searchstr, '{.*}#', '' + clsid + '#')}" />
<echo level="Warning" message="Found in ${vbp} ${vbp_replace_result}" if="${string::get-length(vbp_replace_result) > 0}" />
</if>
</if>
<if test="${string::get-length(libraryfile) == 0}">
<echo level="Warning" message="not found ${reffile} ${libraryfile}" />
</if>
</if>
</if>
</foreach>
<delete file="${path::combine(srcroot,vbp)}.bak2" />
</target>
<target name="vb6.fix_rel_path">
<foreach item="Line" in="projects.txt" delim="," property="prj,project.group">
<property name="tempexe32" value="${vbp::getvalue(prj, 'ExeName32')}" />
<if test="${string::get-length(tempexe32) > 0}">
<property name="exename32" value="${string::substring(tempexe32, 1, string::get-length(tempexe32) - 2)}" />
<property name="searchstr" value="#0#.*${exename32}#" />
<echo message="Searching for ${exename32}" />
<if test="${prj != vbp}">
<property name="relpath" value="${vbp::get-relative-target(path::combine(srcroot,vbp), path::combine(srcroot,prj))}" />
<property name="result" value="${vbp::replace-line(vbp, searchstr, searchstr, '#0#' + relpath + '#')}" />
<echo level="Warning" message="Found in ${vbp} ${result}" if="${string::get-length(result) > 0}" />
</if>
</if>
</foreach>
</target>
<target name="vb6.fixfrm">
<echo message="${path::combine(path::get-directory-name(vbp), '*.frm')}"/>
<foreach item="File" property="filename">
<in>
<items>
<include name="${path::combine(path::get-directory-name(vbp), '*.frm')}" />
</items>
</in>
<do>
<echo message="${filename}" />
<copy file="${filename}" tofile="${filename}.bak" overwrite="true" />
<foreach item="Line" in="${filename}.bak2" delim="=" property="name,value,a,b,c,d">
</foreach>
<delete file="${filename}.bak" />
</do>
</foreach>
</target>
<target name="vb6.remove_line_numbers">
<echo message="rln ${project.module}" />
<foreach item="File" property="filename">
<in>
<items>
<include name="${project.module}\*.bas" />
<include name="${project.module}\*.frm" />
<include name="${project.module}\*.cls" />
<include name="${project.module}\*.ctl" />
</items>
</in>
<do>
<echo message="${filename}" />
<exec program="linenumber.exe"
basedir="${path::combine(project::get-base-directory(), '2x\Tools\LineNumber\bin\Debug')}"
commandline="-remove ${filename}"
/>
</do>
</foreach>
</target>
<target name="vb6.add_line_numbers">
<echo message="rln ${project.module}" />
<foreach item="File" property="filename">
<in>
<items>
<include name="${project.module}\*.bas" />
<include name="${project.module}\*.frm" />
<include name="${project.module}\*.cls" />
<include name="${project.module}\*.ctl" />
</items>
</in>
<do>
<echo message="${filename}" />
<exec program="linenumber.exe"
basedir="${path::combine(project::get-base-directory(), '2x\Tools\LineNumber\bin\Debug')}"
commandline="-add ${filename}"
/>
</do>
</foreach>
</target>
<target name="vb6.pretty">
<echo message="rln ${project.module}" />
<foreach item="File" property="filename">
<in>
<items>
<include name="${project.module}\*.bas" />
<include name="${project.module}\*.frm" />
<include name="${project.module}\*.cls" />
<include name="${project.module}\*.ctl" />
</items>
</in>
<do>
<echo message="${filename}" />
<exec program="linenumber.exe"
basedir="${path::combine(project::get-base-directory(), '2x\Tools\LineNumber\bin\Debug')}"
commandline="-pretty ${filename}"
/>
</do>
</foreach>
</target>
</project>