[fpc-pascal] fpc in symlinked directory
Michael Van Canneyt
michael at freepascal.org
Wed Mar 26 11:25:19 CET 2014
On Wed, 26 Mar 2014, Mattias Gaertner wrote:
> On Wed, 26 Mar 2014 09:10:09 +0100 (CET)
> Michael Van Canneyt <michael at freepascal.org> wrote:
>
>>
>>
>> On Tue, 25 Mar 2014, Mattias Gaertner wrote:
>>
>>>>
>>>> So, FPC uses a system call to get the correct (resolved) CWD directory.
>>>> This is the only guaranteed mechanism.
>>>
>>> What's wrong with this:
>>> if GetEnvironmentVariable('PWD')<>'' then
>>> SetCurrentDir(GetEnvironmentVariable('PWD'));
>>
>> It's a hack ?
>
> AFAIK the PWD is the official thing and used by other console tools as
> well. For example when I compile a file with gcc in a symlinked
> directory it creates debugging info with the unresolved file name.
This is not correct.
You seem to think bash-specific behaviour is the correct way to do things.
It is not, it is specific to bash.
I use tcsh:
cadwal: >cd /tmp
cadwal: >ls -ld src1 link
lrwxrwxrwx 1 michael michael 4 Mar 26 11:09 link -> src1/
drwxrwxr-x 2 michael michael 4096 Mar 26 11:12 src1/
cadwal: >cd link
cadwal: >pwd
/tmp/src1
As you see, it has "resolved" the link.
>
> But SetCurrentDir does not work. It seems to resolve directories. The
> documentation does not mention this behavior. Is this by design?
Yes.
It matches GetCurrentDir.
>>> compiler uses its current directory.
>>
>> What does that mean ? Can you give a command-line example ?
>
> I used this one:
> cd /tmp/link
> /usr/bin/fpc -g -gl -vb -Fi/tmp/link -Fu/tmp/link/
> -FU/tmp/link/ /tmp/link/project1.lpr
cadwal: >fpc -g -gl -vb -Fi/tmp/link -Fu/tmp/link -FU/tmp/link /tmp/link/p.pp
/usr/bin/ld: warning: link.res contains output sections; did you forget -T?
So your example works fine here.
>> I have asked in the past to specify paths to packages as absolute
>> paths, never relative:
>> if you use relative paths, things will get messed up when using symlinks.
>
> It works here. Please create a bug report.
Will do.
> Keep in mind that /tmp/link/unit1.pas and /tmp/orig/uni1.pas must be
> treated as two different files and within one project you must use
> only one of them.
There you are wrong. They must be treated as the same file.
They ARE the same file, after all.
That is why FPC resolves everything.
/proc/self/cwd does the same: it resolves the directory.
cadwal: >ls /proc/self/cwd -l
lrwxrwxrwx 1 michael michael 0 Mar 26 11:18 /proc/self/cwd -> /tmp/src1/
So I still think that the FPC behaviour is the only correct behaviour.
And likewise, I think that Lazarus is still wrong using relative paths.
Michael.
More information about the fpc-pascal
mailing list