Skip to content

Commit

Permalink
Prevent SVN from MSYS if in path
Browse files Browse the repository at this point in the history
  • Loading branch information
LongDirtyAnimAlf committed Dec 2, 2020
1 parent c9ef53c commit 4afc12c
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 55 deletions.
64 changes: 30 additions & 34 deletions crossinstallers/m_any_to_apple_base.pas
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function Tany_apple.GetLibs(Basepath:string): boolean;
var
s:string;
SDKVersion:string;
i,j,k:integer;
Major,Minor,Release:integer;
found:boolean;
begin
result:=FLibsFound;
Expand All @@ -79,60 +79,57 @@ function Tany_apple.GetLibs(Basepath:string): boolean;
// begin simple: check presence of library file in basedir
if not result then
result:=SearchLibrary(Basepath,LibName);

// for osxcross with special libs: search also for libc.tbd
if not result then
result:=SearchLibrary(Basepath,TDBLibName);

if not result then
result:=SearchLibrary(IncludeTrailingPathDelimiter(Basepath)+'usr'+DirectorySeparator+'lib',LibName);

// for osxcross with special libs: search also for libc.tbd
if not result then
result:=SearchLibrary(IncludeTrailingPathDelimiter(Basepath)+'usr'+DirectorySeparator+'lib',TDBLibName);

// first search local paths based on libbraries provided for or adviced by fpc itself
if not result then
result:=SimpleSearchLibrary(BasePath,DirName,LibName);
if not result then
result:=SimpleSearchLibrary(BasePath,DirName,TDBLibName);

// also for cctools
// also for cctools or special fpcupdeluxe tools
if not result then
begin
for i:=MAXOSVERSION downto MINOSVERSION do
for Major:=MAXOSVERSION downto MINOSVERSION do
begin
if found then break;

for j:=16 downto -1 do
for Minor:=16 downto -1 do
begin
if found then break;

if (TargetOS=TOS.darwin) then
begin
if (i>11) then continue;
if (i=11) and (j>5) then continue;
if (i<10) then continue;
if (Major>11) then continue;
if (Major=11) and (Minor>5) then continue;
if (Major<10) then continue;

if (TargetCPU=TCPU.i386) then
begin
if (i>10) then continue;
if (i=10) and (j>13) then continue;
if (Major>10) then continue;
if (Major=10) and (Minor>13) then continue;
end;

if ((TargetCPU=TCPU.powerpc) OR (TargetCPU=TCPU.powerpc64)) then
begin
if (i>10) then continue;
if (i=10) and (j>5) then continue;
if (Major>10) then continue;
if (Major=10) and (Minor>5) then continue;
end;
end;

for k:=15 downto -1 do
for Release:=15 downto -1 do
begin
if found then break;
s:=InttoStr(i);
if j<>-1 then
s:=InttoStr(Major);
if Minor<>-1 then
begin
s:=s+'.'+InttoStr(j);
if k<>-1 then s:=s+'.'+InttoStr(k);
s:=s+'.'+InttoStr(Minor);
if Release<>-1 then s:=s+'.'+InttoStr(Release);
end;
SDKVersion:=s;

Expand Down Expand Up @@ -232,7 +229,7 @@ function Tany_apple.GetLibs(Basepath:string): boolean;
function Tany_apple.GetBinUtils(Basepath:string): boolean;
var
AsFile: string;
i:integer;
i,DarwinRelease:integer;
//S,PresetBinPath: string;
begin
result:=inherited;
Expand All @@ -243,14 +240,14 @@ function Tany_apple.GetBinUtils(Basepath:string): boolean;
begin
if (((TargetOS=TOS.darwin) OR (TargetOS=TOS.ios)) AND (NOT ((TargetCPU=TCPU.powerpc64) OR (TargetCPU=TCPU.powerpc)))) then
begin
// Search in special Apple directory
// Search in special Apple directory for LD
AsFile:=LDSEARCHFILE+GetExeExt;
result:=SimpleSearchBinUtil(BasePath,'all-apple',AsFile);
end;
end;
if not result then
begin
// Search in special all directory
// Search in special all-targetos directory
AsFile:=SEARCHFILE+GetExeExt;
result:=SimpleSearchBinUtil(BasePath,'all-'+TargetOSName,AsFile);
end;
Expand All @@ -267,14 +264,14 @@ function Tany_apple.GetBinUtils(Basepath:string): boolean;
// See https://en.wikipedia.org/wiki/Darwin_%28operating_system%29#Release_history
// Shows relation between macOS and Darwin versions

for i:=MAXDARWINVERSION downto MINDARWINVERSION do
for DarwinRelease:=MAXDARWINVERSION downto MINDARWINVERSION do
begin
if not result then
begin
if i=MINDARWINVERSION then
if DarwinRelease=MINDARWINVERSION then
AsFile:=BinUtilsPrefix
else
AsFile:=StringReplace(BinUtilsPrefix,TargetOSName,TargetOSName+InttoStr(i),[]);
AsFile:=StringReplace(BinUtilsPrefix,TargetOSName,TargetOSName+InttoStr(DarwinRelease),[]);
AsFile:=AsFile+SEARCHFILE+GetExeExt;
result:=SearchBinUtil(BasePath,AsFile);
if not result then
Expand Down Expand Up @@ -314,12 +311,12 @@ function Tany_apple.GetBinUtils(Basepath:string): boolean;
PresetBinPath:=ConcatPaths([BasePath,CROSSPATH,'bin',TargetCPUName+'-'+TargetOSName]);
if DirectoryExists(PresetBinPath) then
begin
for i:=MAXDARWINVERSION downto MINDARWINVERSION do
for DarwinRelease:=MAXDARWINVERSION downto MINDARWINVERSION do
begin
if i=MINDARWINVERSION then
if DarwinRelease=MINDARWINVERSION then
AsFile:=BinUtilsPrefix
else
AsFile:=StringReplace(BinUtilsPrefix,TargetOSName,TargetOSName+InttoStr(i),[]);
AsFile:=StringReplace(BinUtilsPrefix,TargetOSName,TargetOSName+InttoStr(DarwinRelease),[]);
AsFile:=AsFile+SEARCHFILE+GetExeExt;
S:=FindFileInDir(AsFile,PresetBinPath);
if (Length(S)>0) then
Expand All @@ -333,12 +330,12 @@ function Tany_apple.GetBinUtils(Basepath:string): boolean;
PresetBinPath:=ConcatPaths([BasePath,CROSSPATH,'bin','all-'+TargetOSName]);
if DirectoryExists(PresetBinPath) then
begin
for i:=MAXDARWINVERSION downto MINDARWINVERSION do
for DarwinRelease:=MAXDARWINVERSION downto MINDARWINVERSION do
begin
if i=MINDARWINVERSION then
if DarwinRelease=MINDARWINVERSION then
AsFile:=BinUtilsPrefix
else
AsFile:=StringReplace(BinUtilsPrefix,TargetOSName,TargetOSName+InttoStr(i),[]);
AsFile:=StringReplace(BinUtilsPrefix,TargetOSName,TargetOSName+InttoStr(DarwinRelease),[]);
AsFile:=AsFile+SEARCHFILE+GetExeExt;
S:=FindFileInDir(AsFile,PresetBinPath);
if (Length(S)>0) then
Expand All @@ -352,7 +349,6 @@ function Tany_apple.GetBinUtils(Basepath:string): boolean;
end;
*)


if result then
begin
// Remove the searchfile itself to get the binutils prefix
Expand Down
8 changes: 4 additions & 4 deletions gitclient.pas
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ function TGitClient.FindRepoExecutable: string;
// Some popular locations for Tortoisegit:
// Covers both 32 bit and 64 bit Windows.
if not FileExists(FRepoExecutable) then
FRepoExecutable := GetEnvironmentVariable('ProgramFiles\TortoiseGit\bin\' + RepoExecutableName + '.exe');
FRepoExecutable := GetEnvironmentVariable('ProgramFiles')+'\TortoiseGit\bin\' + RepoExecutableName + '.exe';
if not FileExists(FRepoExecutable) then
FRepoExecutable := GetEnvironmentVariable('ProgramFiles(x86)\TortoiseGit\bin\' + RepoExecutableName + '.exe');
FRepoExecutable := GetEnvironmentVariable('ProgramFiles(x86)')+'\TortoiseGit\bin\' + RepoExecutableName + '.exe';
// Commandline git tools
if not FileExists(FRepoExecutable) then
FRepoExecutable := GetEnvironmentVariable('ProgramFiles\Git\bin\' + RepoExecutableName + '.exe');
FRepoExecutable := GetEnvironmentVariable('ProgramFiles')+'\Git\bin\' + RepoExecutableName + '.exe';
if not FileExists(FRepoExecutable) then
FRepoExecutable := GetEnvironmentVariable('ProgramFiles(x86)\Git\bin\' + RepoExecutableName + '.exe');
FRepoExecutable := GetEnvironmentVariable('ProgramFiles(x86)')+'\Git\bin\' + RepoExecutableName + '.exe';
if not FileExists(FRepoExecutable) then
FRepoExecutable := 'C:\Program Files (x86)\Git\bin\' + RepoExecutableName + '.exe';

Expand Down
4 changes: 2 additions & 2 deletions hgclient.pas
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ function THGClient.FindRepoExecutable: string;
// Some popular locations for Tortoisehg:
// Covers both 32 bit and 64 bit Windows.
if not FileExists(FRepoExecutable) then
FRepoExecutable := GetEnvironmentVariable('ProgramFiles\TorToisehg\' + RepoExecutableName + '.exe');
FRepoExecutable := GetEnvironmentVariable('ProgramFiles')+'\TorToisehg\' + RepoExecutableName + '.exe';
if not FileExists(FRepoExecutable) then
FRepoExecutable := GetEnvironmentVariable('ProgramFiles(x86)\TorToisehg\' + RepoExecutableName + '.exe');
FRepoExecutable := GetEnvironmentVariable('ProgramFiles(x86)')+'\TorToisehg\' + RepoExecutableName + '.exe';
//Directory where current executable is:
if not FileExists(FRepoExecutable) then
FRepoExecutable := (SafeGetApplicationPath + RepoExecutableName + '.exe');
Expand Down
37 changes: 22 additions & 15 deletions svnclient.pas
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,6 @@ function TSVNClient.FindRepoExecutable: string;

while True do
begin
// Look in path
// Windows: will also look for <SVNName>.exe
if not FileExists(FRepoExecutable) then
FRepoExecutable := Which(RepoExecutableName+GetExeExt)
else
break;

{$IFDEF DARWIN}
if not FileExists(FRepoExecutable)
then FRepoExecutable := '/Library/Developer/CommandLineTools/usr/bin/svn'
Expand All @@ -130,32 +123,38 @@ function TSVNClient.FindRepoExecutable: string;
// Some popular locations for SlikSVN, Subversion, and TortoiseSVN:
// Covers both 32 bit and 64 bit Windows.
if not FileExists(FRepoExecutable)
then FRepoExecutable := GetEnvironmentVariable('ProgramFiles\Subversion\bin\' + RepoExecutableName + '.exe')
then FRepoExecutable := GetEnvironmentVariable('ProgramFiles')+'\Subversion\bin\' + RepoExecutableName + '.exe'
else break;
if not FileExists(FRepoExecutable)
then FRepoExecutable := GetEnvironmentVariable('ProgramFiles(x86)\Subversion\bin\' + RepoExecutableName + '.exe')
then FRepoExecutable := GetEnvironmentVariable('ProgramFiles(x86)')+'\Subversion\bin\' + RepoExecutableName + '.exe'
else break;
if not FileExists(FRepoExecutable)
then FRepoExecutable := GetEnvironmentVariable('ProgramFiles\SlikSvn\bin\' + RepoExecutableName + '.exe')
then FRepoExecutable := GetEnvironmentVariable('ProgramFiles')+'\SlikSvn\bin\' + RepoExecutableName + '.exe'
else break;
if not FileExists(FRepoExecutable)
then FRepoExecutable := GetEnvironmentVariable('ProgramFiles(x86)\SlikSvn\bin\' + RepoExecutableName + '.exe')
then FRepoExecutable := GetEnvironmentVariable('ProgramFiles(x86)')+'\SlikSvn\bin\' + RepoExecutableName + '.exe'
else break;
if not FileExists(FRepoExecutable)
then FRepoExecutable := GetEnvironmentVariable('ProgramFiles\TorToiseSVN\bin\' + RepoExecutableName + '.exe')
then FRepoExecutable := GetEnvironmentVariable('ProgramFiles')+'\TorToiseSVN\bin\' + RepoExecutableName + '.exe'
else break;
if not FileExists(FRepoExecutable)
then FRepoExecutable := GetEnvironmentVariable('ProgramFiles(x86)\TorToiseSVN\bin\' + RepoExecutableName + '.exe')
then FRepoExecutable := GetEnvironmentVariable('ProgramFiles(x86)')+'\TorToiseSVN\bin\' + RepoExecutableName + '.exe'
else break;
//Directory where current executable is:
if not FileExists(FRepoExecutable)
then FRepoExecutable := (SafeGetApplicationPath + RepoExecutableName + '.exe')
else break;
{$ENDIF MSWINDOWS}
{$ENDIF MSWINDOWS}

// Look in path
// Windows: will also look for <SVNName>.exe
if not FileExists(FRepoExecutable) then
FRepoExecutable := Which(RepoExecutableName+GetExeExt);

break;
end;

if not FileExists(FRepoExecutable) then
if (not FileExists(FRepoExecutable)) then
begin
//current directory. Note: potential for misuse by malicious program.
{$ifdef mswindows}
Expand All @@ -177,6 +176,14 @@ function TSVNClient.FindRepoExecutable: string;
FRepoExecutable := '';
//ThreadLog('SVN client found, but error code during check: '+InttoStr(rv),etError);
ThreadLog('SVN client found, but error code during check !',etError);
end
else
begin
if (CheckExecutable(FRepoExecutable, ['--version'], 'pc-msys')) then
begin
FRepoExecutable := '';
ThreadLog('SVN client found in path, but its from MSYS and that does not work with fpcupdeluxe.',etWarning);
end;
end;
end
else
Expand Down

0 comments on commit 4afc12c

Please sign in to comment.