Recent

Author Topic: Execute after  (Read 7347 times)

timppl

  • Jr. Member
  • **
  • Posts: 80
Execute after
« on: August 20, 2021, 07:22:02 am »
For the application I maintain at work, I build for all platforms on Linux using cross-compiling.
I have an Execute After command to do some housekeeping when a build is finished.
The other day  I needed to build it under windows and the script called from Execute after did not work ( not surprising as it is a bash script ).
So my question is, is it possible to automatically select what runs in Execute after ( eg .sh on Linux and .bat on Windows) depending on the build platform?

Thanks

Tim
Mageia 8 Linux on x86

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 1111
  • Professional amateur ;-P
Re: Execute after
« Reply #1 on: August 20, 2021, 02:22:06 pm »
Hey Timppl,

I'm not sure that there's a way to run different things based on the architecture, but let me propose a quick and dirty solution:

- Name the shell script execute_after, with the appropriate chmod +x and the hash bang (#!/bin/bash) to follow.
- Name the batch file execute_after.bat.

This way, the appropriate script will be run under the Linux and Windows architectures, since Windows will search for a *.com, *.exe and *.bat file and Linux will not.

Hope this workaround make sense and is of any use.

If there is a way to differentiate between architectures, I'm sure a more experienced person will chime in :)

Cheers,
Gus
« Last Edit: August 20, 2021, 04:38:25 pm by Gustavo 'Gus' Carreno »
Lazarus 3.99(main) FPC 3.3.1(main) Ubuntu 23.10 64b Dark Theme
Lazarus 3.0.0(stable) FPC 3.2.2(stable) Ubuntu 23.10 64b Dark Theme
http://github.com/gcarreno

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: Execute after
« Reply #2 on: August 20, 2021, 04:26:50 pm »
Oh wow. This reminds me of the bad old days when geeks spent ridiculous amounts of time trying to get a single file compiling sensibly in both FORTRAN and Pascal.

I think it's a mighty good question, and one which I'd almost certainly have raised in the past if I were still using Windows. I think there's three possibilities:

a) Install a suitable extension to Windows which adds a shell and standard unix-style utilities.

b) Start the IDE with some shell/environment variables defining external commands: I think these can be expanded in the execute-after sequence. It might alternatively be possible to put these in the fpc.cfg file etc.

c) Modify the IDE to recognise predicates, i.e. "execute this bit if the OS is DOS/Windows, this if it's unix/Linux" and so on.

I've tinkered with the execute-after bit of the IDE in the past in order to allow it to be run with elevated privilege if it were necessary to "bless" the generated executable with e.g. additional POSIX-style capabilities. I haven't a clue what happened to my patch, it's vanished somewhere into the svn/git swithcover morass and I'm not going there... but it really wasn't too bad to work with.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

timppl

  • Jr. Member
  • **
  • Posts: 80
Re: Execute after
« Reply #3 on: August 23, 2021, 07:23:52 am »
Thanks chaps

Gustavo, I tried your solution but could not get it to work.

I did some playing around and found a solution. Instead of using a script, I rewrote it in pascal and compiled a version for linux and one for windows. Then in the execute after I put
Quote
$MakeExe($(ProjSrcPath)/clean_after)
The MakeExe macro does nothing under linux so that "clean_after" is executed, and under windows it adds .exe to the name so that "clean_after.exe" is executed.
Once I worked this out it seemed so simple :D.

 Thanks Lazarus devs for this facility
Mageia 8 Linux on x86

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: Execute after
« Reply #4 on: August 23, 2021, 08:28:37 am »
Thanks chaps

Gustavo, I tried your solution but could not get it to work.

I did some playing around and found a solution. Instead of using a script, I rewrote it in pascal and compiled a version for linux and one for windows. Then in the execute after I put
Quote
$MakeExe($(ProjSrcPath)/clean_after)
The MakeExe macro does nothing under linux so that "clean_after" is executed, and under windows it adds .exe to the name so that "clean_after.exe" is executed.
Once I worked this out it seemed so simple :D.

 Thanks Lazarus devs for this facility

Congratulations, that's an elegant hack. Please make sure it gets into the wiki somewhere.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 1111
  • Professional amateur ;-P
Re: Execute after
« Reply #5 on: August 23, 2021, 02:04:41 pm »
Hey Tim,

Gustavo, I tried your solution but could not get it to work.

Humm, that's rather strange, I would swear that the way windows works it should work. At least what I thought would be the way Windows would look for the extension.
Maybe I'm confused and it's only possible if you use the cmd.exe.
I guess that the extension guessing does not apply when Lazarus is running it under a TProcess.

I did some playing around and found a solution. Instead of using a script, I rewrote it in pascal and compiled a version for linux and one for windows. Then in the execute after I put
Quote
$MakeExe($(ProjSrcPath)/clean_after)
The MakeExe macro does nothing under linux so that "clean_after" is executed, and under windows it adds .exe to the name so that "clean_after.exe" is executed.
Once I worked this out it seemed so simple :D.

 Thanks Lazarus devs for this facility

Oddly enough, this was exactly what I was trying to achieve, LOL :D !!
Well, almost. I was trying with the .bat instead of the .exe.
But HEY, it works, so problem solved :)

Looks like I need to revisit my knowledge of how, if even it does, TProcess looks for the extension of an executable file when you don't include it.

Cheers,
Gus
Lazarus 3.99(main) FPC 3.3.1(main) Ubuntu 23.10 64b Dark Theme
Lazarus 3.0.0(stable) FPC 3.2.2(stable) Ubuntu 23.10 64b Dark Theme
http://github.com/gcarreno

timppl

  • Jr. Member
  • **
  • Posts: 80
Re: Execute after
« Reply #6 on: August 24, 2021, 07:48:25 am »
Hi all

The small problem with this can occur if cross compiling, because $MakeExe uses the build target to name the executable, so, for example, building a Win32 target on linux it looks for foo.exe.

Those clever Lazarus developers have thought of this as well  :D.
In later varsions of Lazarus ( certainly from 2.0.12 ) there is a $MakeExe which takes two parameters so you can do $MakeExe(ide, $(ProjSrcPath)/foo) which will rename foo according to the OS that the IDE is running under.

Mageia 8 Linux on x86

 

TinyPortal © 2005-2018