Unit with inline, and recursive uses, needs recompilation right after compilation
Original Reporter info from Mantis: Michalis @michaliskambi
-
Reporter name: Michalis Kamburelis
Original Reporter info from Mantis: Michalis @michaliskambi
- Reporter name: Michalis Kamburelis
Description:
Unit with inline, and recursive uses, needs recompilation right after compilation
See the attached archive and script test.sh inside. It calls FPC two times:
-
To compile unit one.pas, that depends on units a.pas and b.pas. Output PPU of this compilation goes to output/ (that is cleared before whole operation, to always start with a clean state).
-
Then compile unit two.pas, that depends on unit b.pas. Here, be don't pass -Fuonesubdir, so in this pass FPC doesn't know the source code for a.pas and b.pas. But we pass -Fuoutput/, so FPC knows their PPU files. This should be all that is needed, as we just compiled a.pas and b.pas before a second, so they are current. However, we get
$ sh test.sh
Target OS: Linux for i386
Compiling one.pas
Compiling ./onesubdir/b.pas
Compiling ./onesubdir/a.pas
Compiling ./onesubdir/b.pas
39 lines compiled, 0.1 sec
Target OS: Linux for i386
Compiling two.pas
PPU Loading output/b.ppu
PPU Source: b.pas not found
PPU Loading output/b.ppu
PPU Source: b.pas not found
Recompiling B, checksum changed for A
b.pas(5,7) Fatal: Can't find unit B used by A
Fatal: Compilation aborted
So the second FPC call fails, because FPC searches for A and B source code. But it shouldn't --- they were just compiled, and we know they are up-to-date.
Three special things about units A and B, that seem necessary to trigger this error:
-
A and B recursively use each other (B even uses A in the interface)
-
A unit has procedure declared with "inline" in the interface.
-
Also, I noticed that they must be compiled with explicit -M option. It seems the problem occurs with -Mobjfpc, -Mdelphi, and -Mfpc. It doesn't occur when I don't specify any -M option (yes, I know that -Mfpc is the default, and I don't have any -Mxxx or -S2 or similar option in my ~/.fpc.cfg or /etc/fpc.cfg...).
-----
Background info:
This may seem like a harmless problem (what's the problem with adding the -Fu for units A,B to the second fpc call), but this actually bites you when you deal with dependent Lazarus packages. Imagine two Lazarus packages:
-
First one contains units A, B (so it will be compiled using temporary unit similar to one.pas and command-line similar to 1st FPC call), with it's specific compilation options, and paths.
-
Second Lazarus package contains some unit C that depends on 1st package, but 2nd package doesn't include again units A,B (so it also doesn't contain -Fu paths to A,B source code, and possibly has different compilation options that A,B require).
The effect of this bug: when you compile 1st package from Lazarus, you cannot compile 2nd package (as it will fail saying that checksum changed). You have to compile 1st package once again, before going further.
Mantis conversion info:
- Mantis ID: 12223
- OS: Debian GNU/Linux
- OS Build: (testing)
- Platform: i386
- Version: 2.2.2