Delphi XE3: Problems with complex pre
We are currently in the process of switching from Delphi XE to Delphi XE3, and we are having serious problems with our pre-build-events.
Our pre-build events look like this:
SubWCRev "<SVN-Path>" "<InputFile>" VersionInfo.rc
brcc32 -foProject.res VersionInfo.rc
(note that these two commands appear on separate lines; and contain the absolute paths in our "real" commands) ie we first extract the current SVN version from the working copy, write this information to VersionInfo.rc and then use the Borland resource compiler to generate a resource file.
This worked perfectly in previous Delphi versions, but whenever we open the project options in XE3, XE3 converts this to:
SubWCRev "<SVN-Path>" "<InputFile>" VersionInfo.rc &brcc32 -foProject.res VersionInfo.rc
(note that this is a single line, both commands separated by a single ampersand). which causes the build to fail.
Our current workaround is to manually change this to
SubWCRev "<SVN-Path>" "<InputFile>" VersionInfo.rc && brcc32 -foProject.res VersionInfo.rc
ie we use two ampersands to execute the second command if the first one succeeds.
This works, but only until we edit the project options again - Delphi XE3 always messes up the pre-build event :-(
Does anybody know a solution/workaround for this? I guess we could write a simple command line tool that calls SubWCRev and brcc32, but I'd prefer a simpler solution.
UPDATE : Steps to easily reproduce this bug
IDE
Build Events -> Pre-build events, enter this (two lines, sorry for the formatting):
echo one > out.txt
echo two >> out.txt
Build the project from the IDE
RAD Studio command prompt
IDE
RAD Studio command prompt
We ended up using a workaround similar to what was proposed by David Heffernan:
In case anyone's interested, here's our PreBuild event:
PreBuild "<path_to_SVN_working_copy>" "VersionInfo.rc.in" $(OUTPUTNAME).res
and here's the script PreBuild.rb:
#!/usr/bin/env ruby
require 'tempfile'
if ARGV.length < 3
puts "usage: #{$0} <path> <infile> <outfile>"
exit 1
end
# svnversion.exe is part of the SVN command line client
svnversion = "svnversion.exe"
path, infile, outfile = ARGV[0], ARGV[1], ARGV[2]
# call svnversion executable, storing its output in rev
rev_str = `#{svnversion} "#{path}"`.chop
# extract the first number (get rid of M flag for modified source)
rev = /^[0-9]+/.match(rev_str)[0]
# get current date
date = Time.new
# remove old output file (ignore errors, e.g. if file didn't exist)
begin
File.delete(outfile)
rescue
end
input = File.new(infile, "r")
tmpname = "VersionInfo.rc"
tmp = File.new(tmpname, "w+")
input.each do |line|
# replace $WCREV$ with revision from svnversion call
outline = line.gsub(/$WCREV$/, rev)
# replace $WCDATE$ with current date + time
outline = outline.gsub(/$WCDATE$/, date.to_s)
# write modified line to output file
tmp.puts(outline)
end
input.close
tmp.close
puts "SubWCRev: Revision: #{rev}, date: #{date}, written to #{tmpname}"
call = "brcc32 -fo#{outfile} #{tmpname}"
puts call
system(call)
I'm using Delphi XE4, and I had the same problem with almost the same commands. Our PreBuildEvent has 4 lines, I tried what is described here, put all on 1 line and separating my commands with &&, and it worked. I then tried to modify to see if XE4 will mess my prebuild, but after putting back my prebuild on 4 lines, it was still working.
I finally figured out with other projects where I was able to reproduce this error, that simply editing the script by removing the CRLF at the end of each line, and putting it back, from XE4 environment, it fixed the PreBuildEvent.
链接地址: http://www.djcxy.com/p/67672.html上一篇: Delphi:泛型,接口
下一篇: Delphi XE3:复杂的预处理问题