Recent

Author Topic: Sharing same source file in two projects  (Read 9462 times)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11452
  • FPC developer.
Re: Sharing same source file in two projects
« Reply #45 on: October 07, 2021, 11:03:13 pm »
@marcov,
What if the suggested check is performed only on the .ppu's residing into intermediate directory? The compiler should know that directory by its command-line parameters, I believe.

Theoretically possible. However I think it too narrow an usecase. But as said, I'm no compilerdevel.

In the IDE it is also possible with ppu scanning, but the compiler only scans required files, and that is harder in the IDE, so a file removed from the project (and a leftover ppu) could trip up this. PPU scanning could alleviate this somewhat, but depends on a build of the same project being succeeded before.
« Last Edit: October 09, 2021, 01:43:20 pm by marcov »

alpine

  • Hero Member
  • *****
  • Posts: 1064
Re: Sharing same source file in two projects
« Reply #46 on: October 09, 2021, 05:07:06 pm »
@marcov,
What if the suggested check is performed only on the .ppu's residing into intermediate directory? The compiler should know that directory by its command-line parameters, I believe.

Theoretically possible. However I think it too narrow an usecase. But as said, I'm no compilerdevel.

In the IDE it is also possible with ppu scanning, but the compiler only scans required files, and that is harder in the IDE, so a file removed from the project (and a leftover ppu) could trip up this. PPU scanning could alleviate this somewhat, but depends on a build of the same project being succeeded before.
I've tried to experiment with the idea, thought that I can put on 'Project|Compiler commands|Execute before' small utility to hash the compiler options and touch the file $(ProjPath)/hash.inc only when different. Then {$I hash.inc} in every source file should have the same effect, i.e. tried to use .ppu's entry for include dependency in place of the proposed new entry.

Then I found there is no suitable IDE macro to substitute for the compiler options...

Ditching into IDE sources I found it in function TMainIDE.DoBuildProject():
Code: Pascal  [Select][+][-]
  1.  
  2.       // execute compilation tool 'Before'
  3.       if not (pbfSkipTools in Flags) then begin
  4.         ToolBefore:=TProjectCompilationToolOptions(
  5.                                           Project1.CompilerOptions.ExecuteBefore);
  6.         if (AReason in ToolBefore.CompileReasons) then begin
  7.           Result:=Project1.CompilerOptions.ExecuteBefore.Execute(
  8.                  WorkingDir, lisProject2+lisExecutingCommandBefore,
  9.                  aCompileHint);
  10.  
  11.     // ... (many lines after)
  12.  
  13.         CompilerParams :=
  14.           Project1.CompilerOptions.MakeOptionsString([ccloAbsolutePaths])
  15.                  + ' ' + PrepareCmdLineOption(SrcFilename);
  16.         // write state file, to avoid building clean every time
  17.         Result:=Project1.SaveStateFile(CompilerFilename,CompilerParams,false);
  18.         if Result<>mrOk then begin
  19.           debugln(['Error: (lazarus) [TMainIDE.DoBuildProject] SaveStateFile before compile failed']);
  20.           exit;
  21.         end;
  22.  
  23.         WarnSuspiciousCompilerOptions('Project checks','',CompilerParams);
  24.  
  25.         StartTime:=Now;
  26.         Result:=TheCompiler.Compile(Project1,
  27.  
That convinced me that I have no chance of knowing them at the time of "Execute before".

In that point I wonder is there some helper docs how to write an IDE package, which eventually will be compiled with the IDE and will have access to Project1.CompilerOptions.MakeOptionsString()?

I have seen plenty such packages (e.g. EducationLaz, AnchorDockingDsgn) which seems to be an integral part of the IDE after installed. I don't want to mess with the original IDE sources but rather to make such package for the test.
 

 
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

cpicanco

  • Hero Member
  • *****
  • Posts: 618
  • Behavioral Scientist and Programmer
    • Portfolio
Re: Sharing same source file in two projects
« Reply #47 on: October 09, 2021, 07:50:21 pm »
Hi y.ivanov, I am just curious, are you using the "Compile Many Modes" option (if not, have you tried it)?
Be mindful and excellent with each other.
https://github.com/cpicanco/

 

TinyPortal © 2005-2018