Re: [Module::Build] ./Build on Win98
Status: Beta
Brought to you by:
kwilliams
|
From: Randy W. S. <ml...@th...> - 2006-02-22 22:59:34
|
Joshua ben Jore wrote: > On 2/22/06, Nick Ing-Simmons <ni...@in...> wrote: >> Randy W. Sims <Ra...@Th...> writes: > >> Build.bat cannot delete itself on Windows. >> You can't delete executing things. This is why Windows needs to >> reboot after installing upgrades. >> A running thing can ask for a delete on next reboot, but cannot delete >> an open file. > > You can have it delete itself if you can manage to call the CreateFile > Win32 API function with the FILE_FLAG_DELETE_ON_CLOSE flag. At least > that's what demerphq told p5p about something similar when trying to > get M::B to be able to install Cwd. That's true of binary executable images, batch scripts turn out to be different... We start with a perl script 'Build', run it through the 'pl2bat' utility which prefaces it with a batch script that invokes the perl interpreter with itself, skipping the batch header. This produces the 'Build.bat' file that we execute. Perl reads the entire file in, closing the handle. Initially, we tried deleting the 'Build.bat' from the perl side of the script. It worked: the file was unlinked. But when execution returned the shell, the batch script was no longer there, producing the "not found" error. This seems to imply that batch files are opened, read & executed one line at a time. This is important. The final solution, the one being tweaked now because of slight syntax differences between commands on 9x vs NT, involves appending DOS commands to the end of the batch script during the execution of the 'realclean' action. The general solution was suggested by some people in the alt.msdos.batch newsgroup. Basically, it's executing the following commands from a batch file: > It will need more quotes for NT, but works here. > > @echo off > start "" /min "%comspec%" /c del "%~f0" > > > For Win9x this should work > > @echo off > start /min "%comspec%" /c del "%~f0" Note the %~f0 syntax is specific to NT, but is not a problem because we fill in the literal path before appending the command to the batch script. The main syntax difference that caused the failure on 9x was from the "" as the first argument; I still don't understand that requirement. When 'Build realclean' is executed, it does it's thing deleting everything but the 'Build.bat'. It opens the 'Build.bat' for appending, adding the command above. When the perl side exits, control returns to the shell which continues execution of the now extended batch script. This works perfectly as far as I can tell; though it's a very odd way to go about it. There is a couple of other issues. Cygwin is running pl2bat; I don't know if it should, and if it is decided it should, the solution will be different under the bash shell. The other is the test failures that Dr Bean noticed; I'm not convinced yet that they are related to any of this, i.e. I wonder if they are pre-existing issues. Randy. PS: Still trying to get caught up on stuff that transpired while I was away on a very nice little vacation. Unfortunately, I also brought back a nasty little cold with me. Catching up as fast as I can, but I came back to over a thousand mails/mailing-list msgs/etc... |