pastojs: FindDefaultConfig: search in symlinked compiler exe

This commit is contained in:
mattias 2022-10-21 12:10:09 +01:00
parent 229d88c50f
commit 87a9214983

View File

@ -26,7 +26,7 @@ uses
{$IFDEF NodeJS} {$IFDEF NodeJS}
node.fs, node.fs,
{$ENDIF} {$ENDIF}
SysUtils, Pas2jsFileUtils, Pas2JSFS, Pas2jsCompiler; SysUtils, Classes, Pas2jsFileUtils, Pas2JSFS, Pas2jsCompiler;
Type Type
TPas2JSFileConfigSupport = Class(TPas2JSConfigSupport) TPas2JSFileConfigSupport = Class(TPas2JSConfigSupport)
@ -47,12 +47,16 @@ begin
end; end;
Function TPas2JSFileConfigSupport.FindDefaultConfig : String; Function TPas2JSFileConfigSupport.FindDefaultConfig : String;
var
Tried: TStringList;
function TryConfig(aFilename: string): boolean; function TryConfig(aFilename: string): boolean;
begin begin
Result:=false; Result:=false;
if aFilename='' then exit; if aFilename='' then exit;
aFilename:=ExpandFileName(aFilename); aFilename:=ExpandFileName(aFilename);
if Tried.IndexOf(aFilename)>=0 then exit;
Tried.Add(aFilename);
if Compiler.ShowDebug or Compiler.ShowTriedUsedFiles then if Compiler.ShowDebug or Compiler.ShowTriedUsedFiles then
Compiler.Log.LogMsgIgnoreFilter(nConfigFileSearch,[aFilename]); Compiler.Log.LogMsgIgnoreFilter(nConfigFileSearch,[aFilename]);
if not Compiler.FS.FileExists(aFilename) then exit; if not Compiler.FS.FileExists(aFilename) then exit;
@ -65,32 +69,47 @@ var
begin begin
Result:=''; Result:='';
// first try HOME directory Tried:=TStringList.Create;
aFilename:=ChompPathDelim(GetEnvironmentVariablePJ('HOME')); try
if aFilename<>'' then // first try HOME directory
begin aFilename:=ChompPathDelim(GetEnvironmentVariablePJ('HOME'));
aFilename:=aFilename+PathDelim{$IFDEF UNIX}+'.'{$ENDIF}+DefaultConfigFile;
if TryConfig(aFileName) then
exit;
end;
// then try compiler directory
if (Compiler.CompilerExe<>'') then
begin
aFilename:=ExtractFilePath(Compiler.CompilerExe);
if aFilename<>'' then if aFilename<>'' then
begin begin
aFilename:=IncludeTrailingPathDelimiter(aFilename)+DefaultConfigFile; aFilename:=aFilename+PathDelim{$IFDEF UNIX}+'.'{$ENDIF}+DefaultConfigFile;
if TryConfig(aFilename) then if TryConfig(aFileName) then
exit; exit;
end; end;
end;
// finally try global directory // then try compiler directory
{$IFDEF Unix} if (Compiler.CompilerExe<>'') then
if TryConfig('/etc/'+DefaultConfigFile) then begin
exit; aFilename:=ExtractFilePath(Compiler.CompilerExe);
{$ENDIF} if aFilename<>'' then
begin
aFilename:=IncludeTrailingPathDelimiter(aFilename)+DefaultConfigFile;
if TryConfig(aFilename) then
exit;
end;
// resolve symlinks and then search
aFilename:=GetPhysicalFilename(Compiler.CompilerExe,false);
if (aFilename<>'') and (aFilename<>Compiler.CompilerExe) then
begin
aFilename:=ExtractFilePath(aFilename);
aFilename:=IncludeTrailingPathDelimiter(aFilename)+DefaultConfigFile;
if TryConfig(aFilename) then
exit;
end;
end;
// finally try global directory
{$IFDEF Unix}
if TryConfig('/etc/'+DefaultConfigFile) then
exit;
{$ENDIF}
finally
Tried.Free;
end;
end; end;
end. end.