Recent

Author Topic: $(TargetFile) bug for DLLs with set Host application?  (Read 1045 times)

CCRDude

  • Sr. Member
  • ****
  • Posts: 446
$(TargetFile) bug for DLLs with set Host application?
« on: March 23, 2018, 11:16:49 am »
I've written an IDE plugin to integrate codesigning into the IDE workflow. To determine the output of the binary, I use $(TargetFile).

Code: Pascal  [Select]
  1. procedure TCodeSigningHelper.DoProjectBuildingFinished(ASender: TObject; ABuildSuccessful: boolean);
  2. var
  3.    s: string;
  4.    sTargetOS: string;
  5.    b: boolean;
  6. begin
  7.    s := '$(TargetFile)';
  8.    sTargetOS := GetTargetOS;
  9.    if IDEMacros.SubstituteMacros(s) then begin
  10.       if ABuildSuccessful then begin
  11.          b := False;
  12.          if TMicrosoftSignToolSigner.SupportsLazarusTargetOS(sTargetOS) then begin
  13.             b := CodeSigningOptions.MicrosoftSignToolOptions.AutoSign;
  14.          end else if TAppleCodeSignSigner.SupportsLazarusTargetOS(sTargetOS) then begin
  15.             b := CodeSigningOptions.AppleCodeSignOptions.AutoSign;
  16.          end else if TJavaKeyToolSigner.SupportsLazarusTargetOS(sTargetOS) then begin
  17.             b := CodeSigningOptions.JavaKeyToolOptions.AutoSign;
  18.          end;
  19.          if b then begin
  20.             AddIDEMessage(mluNone, rsCodeSigningStatusSigning, '', 0, 0, rsCodeSigningViewCodeSign);
  21.             CertificateSignExecutable(s);
  22.          end;
  23.  

Today, I was trying to sign a DLL for which I had set a Host application in Run Parameters. The signing code then tried to sign this host application executable, not my library.

According to the Wiki, $(TargetFile) is the stuff to use for 'Execute after'.
According to Macros in the Wiki, libraries are clearly included: "TargetFile - the output file of the current project (e.g. the executable or the library)"

  • I use Lazarus 1.8.2 64 bit secondary (but only) installation as the current stable version
  • Set Host application in Run Parameters to a 64 bit Total Commander executable, and code above will use the TC executable for IDEMacros.SubstituteMacros('$(TargetFile)')
  • If I remove the Host application setting, the code above will use the correct project DLL file.

I assume this is a bug? Or am I missing something?

(Update: I verified this on another machine with a November 2017 trunk svn version, with a different DLL project with different host application, and could verify it. Lazarus wouldn't compile the updated trunk any longer, so I can't confirm for the latest svn version yet)
(Update #2: meanwhile confirmed with the latest trunk)
« Last Edit: March 23, 2018, 08:30:00 pm by CCRDude »

CCRDude

  • Sr. Member
  • ****
  • Posts: 446
Re: $(TargetFile) bug for DLLs with set Host application?
« Reply #1 on: April 04, 2018, 04:54:13 pm »
Got a fresh IDE installed today and verified again; it can be verified much easier using post compile events, here's the reference to Mantis where I now reported it:

https://bugs.freepascal.org/view.php?id=33560

CCRDude

  • Sr. Member
  • ****
  • Posts: 446
Re: $(TargetFile) bug for DLLs with set Host application?
« Reply #2 on: October 31, 2018, 09:49:46 am »
Small update: it's a duplicate of this one:
https://bugs.freepascal.org/view.php?id=27729

I would love to write a better fix for this, but I need some feedback which direction that should take before creating patches.