Hardcoded filepaths in compiled exe

Steven Schveighoffer schveiguy at gmail.com
Wed Dec 30 14:14:51 UTC 2020


On 12/29/20 11:43 PM, Basile B. wrote:
> On Wednesday, 30 December 2020 at 01:21:37 UTC, Steven Schveighoffer wrote:
>> On 12/29/20 7:46 PM, Basile B. wrote:
>>> On Tuesday, 29 December 2020 at 23:11:25 UTC, Steven Schveighoffer 
>>> wrote:
>>>> But I would think a feature should exist that masks the base 
>>>> directory of exception file names.
>>>>
>>>> Probably worth an enhancement request.
>>>>
>>>
>>> Also aren't dmd output binaries supposed to be "reproducible" ?
>>
>> If you had an option to change __FILE__ to be canonical, then it could 
>> be.
>>
>> i.e. instead of:
>>
>> C:\D\dmd2\windows\bin\..\..\src\phobos\std\file.d
>>
>> you stored:
>>
>> (imports)\std\file.d
>>
>> where (imports) (or maybe some other token) was substituted in for the 
>> base of every import. Files passed on the command line would just 
>> store the __FILE__ as it was passed.
>>
> 
> actually the string "C:\D\dmd2\windows\bin\..\..\src\phobos\std\file.d"
> looks like it comes from how the ini file variables are expanded.
> 
> __FILE__ is not supposed to represent an absolute file name unless the 
> compiler get passed absolute file names. That why __FILE_FULL_PATH__ was 
> added at some point.

When I tested this code, it spit out a full path:

import std.stdio;
import std.range;

void main()
{
     char[] str = [0xff, 0xff];
     writeln(str.front);
}

------

std.utf.UTFException@/Users/steves/.dvm/compilers/dmd-2.094.2/osx/bin/../../src/phobos/std/utf.d(1508): 
Invalid UTF-8 sequence (at index 1)

The path comes from the ini file to generate the import directory. I 
believe the ini configuration gives a full path (the path to the ini 
file, and then the relative path to the import).

I think if the import was in the project and not the dmd compiler 
directory, then full paths wouldn't be happening.

But that doesn't mean you can't FORCE the compiler to behave better via 
an option switch when importing from elsewhere.

-Steve


More information about the Digitalmars-d-learn mailing list