mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-20 18:09:27 +02:00
* initial code for bootstrapping using only source dirs
git-svn-id: trunk@8943 -
This commit is contained in:
parent
5c2f23e433
commit
6ea1339f0a
@ -75,20 +75,20 @@ begin
|
||||
GeneratedConfig:=false;
|
||||
// Load file or create new default configuration
|
||||
if FileExists(cfgfile) then
|
||||
Defaults.LoadGlobalFromFile(cfgfile)
|
||||
Options.LoadGlobalFromFile(cfgfile)
|
||||
else
|
||||
begin
|
||||
ForceDirectories(ExtractFilePath(cfgfile));
|
||||
Defaults.SaveGlobalToFile(cfgfile);
|
||||
Options.SaveGlobalToFile(cfgfile);
|
||||
GeneratedConfig:=true;
|
||||
end;
|
||||
// Load default verbosity from config
|
||||
SL:=TStringList.Create;
|
||||
SL.CommaText:=Defaults.DefaultVerbosity;
|
||||
SL.CommaText:=Options.DefaultVerbosity;
|
||||
for i:=0 to SL.Count-1 do
|
||||
Include(Verbosity,StringToVerbosity(SL[i]));
|
||||
SL.Free;
|
||||
Defaults.CurrentCompilerConfig:=Defaults.DefaultCompilerConfig;
|
||||
Options.CurrentCompilerConfig:=Options.DefaultCompilerConfig;
|
||||
// Tracing of what we've done above, need to be done after the verbosity is set
|
||||
if GeneratedConfig then
|
||||
Log(vDebug,SLogGeneratingGlobalConfig,[cfgfile])
|
||||
@ -99,9 +99,9 @@ end;
|
||||
|
||||
procedure TMakeTool.MaybeCreateLocalDirs;
|
||||
begin
|
||||
ForceDirectories(Defaults.BuildDir);
|
||||
ForceDirectories(Defaults.PackagesDir);
|
||||
ForceDirectories(Defaults.CompilerConfigDir);
|
||||
ForceDirectories(Options.BuildDir);
|
||||
ForceDirectories(Options.PackagesDir);
|
||||
ForceDirectories(Options.CompilerConfigDir);
|
||||
end;
|
||||
|
||||
|
||||
@ -109,17 +109,23 @@ procedure TMakeTool.LoadCompilerDefaults;
|
||||
var
|
||||
S : String;
|
||||
begin
|
||||
S:=Defaults.CompilerConfigDir+Defaults.CurrentCompilerConfig;
|
||||
S:=Options.CompilerConfigDir+Options.CurrentCompilerConfig;
|
||||
if FileExists(S) then
|
||||
begin
|
||||
Log(vDebug,SLogLoadingCompilerConfig,[S]);
|
||||
Defaults.LoadCompilerFromFile(S)
|
||||
Options.LoadCompilerFromFile(S)
|
||||
end
|
||||
else
|
||||
begin
|
||||
Log(vDebug,SLogGeneratingCompilerConfig,[S]);
|
||||
Defaults.InitCompilerDefaults;
|
||||
Defaults.SaveCompilerToFile(S);
|
||||
// Generate a default configuration if it doesn't exists
|
||||
if Options.CurrentCompilerConfig='default' then
|
||||
begin
|
||||
Log(vDebug,SLogGeneratingCompilerConfig,[S]);
|
||||
Options.InitCompilerDefaults('');
|
||||
Options.SaveCompilerToFile(S);
|
||||
end
|
||||
else
|
||||
Error(SErrMissingCompilerConfig,[S]);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -131,6 +137,7 @@ begin
|
||||
Writeln(' -c --config Set compiler configuration to use');
|
||||
Writeln(' -h --help This help');
|
||||
Writeln(' -v --verbose Set verbosity');
|
||||
Writeln(' -b --bootstrap Special bootstrapping mode');
|
||||
Writeln('Actions:');
|
||||
Writeln(' update Update packages list');
|
||||
Writeln(' avail List available packages');
|
||||
@ -138,6 +145,7 @@ begin
|
||||
Writeln(' install Install package');
|
||||
Writeln(' download Download package');
|
||||
Writeln(' convertmk Convert Makefile.fpc to fpmake.pp');
|
||||
Writeln(' addconfig Add a compiler configuration for the supplied compiler');
|
||||
Halt(0);
|
||||
end;
|
||||
|
||||
@ -207,9 +215,11 @@ begin
|
||||
Inc(I);
|
||||
// Check options.
|
||||
if CheckOption(I,'c','config') then
|
||||
Defaults.CurrentCompilerConfig:=OptionArg(I)
|
||||
Options.CurrentCompilerConfig:=OptionArg(I)
|
||||
else if CheckOption(I,'v','verbose') then
|
||||
Include(Verbosity,StringToVerbosity(OptionArg(I)))
|
||||
else if CheckOption(I,'b','bootstrap') then
|
||||
Options.BootStrap:=true
|
||||
else if CheckOption(I,'h','help') then
|
||||
begin
|
||||
ShowUsage;
|
||||
|
@ -7,7 +7,23 @@ interface
|
||||
uses
|
||||
Classes, SysUtils,pkghandler;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
pkgmessages,
|
||||
pkgglobals,
|
||||
pkgoptions,
|
||||
pkgdownload,
|
||||
pkgrepos;
|
||||
|
||||
type
|
||||
{ TCommandAddConfig }
|
||||
|
||||
TCommandAddConfig = Class(TPackagehandler)
|
||||
Public
|
||||
Function Execute(const Args:TActionArgs):boolean;override;
|
||||
end;
|
||||
|
||||
{ TCommandUpdate }
|
||||
|
||||
TCommandUpdate = Class(TPackagehandler)
|
||||
@ -59,25 +75,27 @@ type
|
||||
end;
|
||||
|
||||
|
||||
implementation
|
||||
function TCommandAddConfig.Execute(const Args:TActionArgs):boolean;
|
||||
begin
|
||||
Log(vInfo,SLogGeneratingCompilerConfig,[S]);
|
||||
Options.InitCompilerDefaults(Args[2]);
|
||||
Options.SaveCompilerToFile(S);
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
uses
|
||||
pkgmessages,
|
||||
pkgglobals,
|
||||
pkgoptions,
|
||||
pkgdownload,
|
||||
pkgrepos;
|
||||
|
||||
function TCommandUpdate.Execute(const Args:TActionArgs):boolean;
|
||||
begin
|
||||
DownloadFile(Defaults.RemotePackagesFile,Defaults.LocalPackagesFile);
|
||||
DownloadFile(Options.RemotePackagesFile,Options.LocalPackagesFile);
|
||||
LoadLocalRepository;
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
|
||||
function TCommandAvail.Execute(const Args:TActionArgs):boolean;
|
||||
begin
|
||||
ListRepository;
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
|
||||
@ -86,6 +104,7 @@ begin
|
||||
RebuildRepository;
|
||||
ListRepository;
|
||||
SaveRepository;
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
|
||||
@ -95,6 +114,7 @@ begin
|
||||
Error(SErrNoPackageSpecified);
|
||||
if not FileExists(PackageLocalArchive) then
|
||||
ExecuteAction(CurrentPackage,'downloadpackage',Args);
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
|
||||
@ -103,6 +123,7 @@ begin
|
||||
if not assigned(CurrentPackage) then
|
||||
Error(SErrNoPackageSpecified);
|
||||
ExecuteAction(CurrentPackage,'unziparchive',Args);
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
|
||||
@ -114,6 +135,7 @@ begin
|
||||
ExecuteAction(CurrentPackage,'unziparchive',Args);
|
||||
end;
|
||||
ExecuteAction(CurrentPackage,'fpmakebuild',Args);
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
|
||||
@ -121,6 +143,7 @@ function TCommandInstall.Execute(const Args:TActionArgs):boolean;
|
||||
begin
|
||||
ExecuteAction(CurrentPackage,'build',Args);
|
||||
ExecuteAction(CurrentPackage,'fpmakeinstall',Args);
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
|
||||
|
@ -7,6 +7,13 @@ interface
|
||||
uses
|
||||
Classes, SysUtils,pkghandler;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
pkgoptions,
|
||||
pkgglobals,
|
||||
pkgmessages;
|
||||
|
||||
type
|
||||
{ TFPMakeCompiler }
|
||||
|
||||
@ -50,22 +57,19 @@ type
|
||||
end;
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
pkgoptions,
|
||||
pkgglobals,
|
||||
pkgmessages;
|
||||
|
||||
{ TFPMakeCompiler }
|
||||
|
||||
Procedure TFPMakeCompiler.CompileFPMake;
|
||||
const
|
||||
TempBuildDir = 'build-fpmake';
|
||||
Var
|
||||
O,C : String;
|
||||
RTLDir,
|
||||
FPPkgDir,
|
||||
i : Integer;
|
||||
OOptions,
|
||||
BaseDir,
|
||||
DepDir,
|
||||
FPMakeBin,
|
||||
FPMakeSrc : string;
|
||||
DoBootStrap,
|
||||
HaveFpmake : boolean;
|
||||
begin
|
||||
SetCurrentDir(PackageBuildPath);
|
||||
@ -85,21 +89,64 @@ begin
|
||||
begin
|
||||
if Not HaveFPMake then
|
||||
Error(SErrMissingFPMake);
|
||||
{ Detect installed units directories }
|
||||
if not DirectoryExists(Defaults.FPMakeUnitDir) then
|
||||
Error(SErrMissingDirectory,[Defaults.FPMakeUnitDir]);
|
||||
RTLDir:=Defaults.FPMakeUnitDir+'..'+PathDelim+'rtl'+PathDelim;
|
||||
if not DirectoryExists(RTLDir) then
|
||||
Error(SErrMissingDirectory,[RTLDir]);
|
||||
FPPkgDir:=Defaults.FPMakeUnitDir+'..'+PathDelim+'fppkg'+PathDelim;
|
||||
if not DirectoryExists(FPPkgDir) then
|
||||
FPPkgDir:='';
|
||||
{ Call compiler }
|
||||
C:=Defaults.FPMakeCompiler;
|
||||
O:='-vi -n -Fu'+Defaults.FPMakeUnitDir+' -Fu'+RTLDir;
|
||||
O:=O+' '+FPmakeSrc;
|
||||
If ExecuteProcess(C,O)<>0 then
|
||||
Error(SErrFailedToCompileFPCMake)
|
||||
// Special bootstrapping mode to compile fpmake?
|
||||
DoBootStrap:=False;
|
||||
if Options.BootStrap then
|
||||
begin
|
||||
{$ifdef check_bootstrap_names}
|
||||
for i:=low(FPMKUnitDeps) to high(FPMKUnitDeps) do
|
||||
if CurrentPackage.Name=FPMKUnitDeps[i] then
|
||||
begin
|
||||
DoBootStrap:=True;
|
||||
break;
|
||||
end;
|
||||
{$else check_bootstrap_names}
|
||||
DoBootStrap:=True;
|
||||
{$endif check_bootstrap_names}
|
||||
end;
|
||||
// Compile options
|
||||
// -- bootstrapping compile with -g
|
||||
// -- default is to optimize, smartlink and strip to reduce
|
||||
// the executable size (there can be 100's of fpmake's on a system)
|
||||
OOptions:='-n';
|
||||
if vInfo in Verbosity then
|
||||
OOptions:=OOptions+' -vi';
|
||||
if DoBootStrap then
|
||||
OOptions:=OOptions+' -g'
|
||||
else
|
||||
OOptions:=OOptions+' -O2 -XXs';
|
||||
// Find required units directories
|
||||
if DoBootStrap then
|
||||
BaseDir:='../'
|
||||
else
|
||||
BaseDir:=Options.FPMakeUnitDir;
|
||||
if not DirectoryExists(BaseDir) then
|
||||
Error(SErrMissingDirectory,[BaseDir]);
|
||||
for i:=high(FPMKUnitDeps) downto low(FPMKUnitDeps) do
|
||||
begin
|
||||
// RTL is always take from the installed compiler
|
||||
if FPMKUnitDeps[i]='rtl' then
|
||||
DepDir:=IncludeTrailingPathDelimiter(Options.FPMakeUnitDir+FPMKUnitDeps[i])
|
||||
else
|
||||
begin
|
||||
if DoBootStrap then
|
||||
DepDir:=IncludeTrailingPathDelimiter(BaseDir+FPMKUnitDeps[i]+PathDelim+'src')
|
||||
else
|
||||
DepDir:=IncludeTrailingPathDelimiter(BaseDir+FPMKUnitDeps[i]);
|
||||
end;
|
||||
if not DirectoryExists(DepDir) then
|
||||
Error(SErrMissingDirectory,[DepDir]);
|
||||
OOptions:=OOptions+' -Fu'+DepDir;
|
||||
end;
|
||||
// Units in a directory for easy cleaning
|
||||
DeleteDir(TempBuildDir);
|
||||
ForceDirectories(TempBuildDir);
|
||||
OOptions:=OOptions+' -FU'+TempBuildDir;
|
||||
// Call compiler
|
||||
If ExecuteProcess(Options.FPMakeCompiler,OOptions+' '+FPmakeSrc)<>0 then
|
||||
Error(SErrFailedToCompileFPCMake);
|
||||
// Cleanup units
|
||||
DeleteDir(TempBuildDir);
|
||||
end
|
||||
else
|
||||
Log(vCommands,SLogNotCompilingFPMake);
|
||||
|
@ -17,6 +17,9 @@ Const
|
||||
AllFiles='*.*';
|
||||
{$endif unix}
|
||||
|
||||
// Dependencies for compiling the fpmkunit unit
|
||||
FPMKUnitDeps : array[0..3] of string[8] = ('rtl','hash','paszlib','fpmkunit');
|
||||
|
||||
Type
|
||||
TVerbosity = (vError,vWarning,vInfo,vCommands,vDebug);
|
||||
TVerbosities = Set of TVerbosity;
|
||||
@ -187,6 +190,7 @@ begin
|
||||
finally
|
||||
FindClose(Info);
|
||||
end;
|
||||
RemoveDir(Adir);
|
||||
end;
|
||||
|
||||
|
||||
|
@ -150,7 +150,7 @@ begin
|
||||
if CurrentPackage=nil then
|
||||
Result:='.'
|
||||
else
|
||||
Result:=Defaults.BuildDir+CurrentPackage.Name;
|
||||
Result:=Options.BuildDir+CurrentPackage.Name;
|
||||
end;
|
||||
|
||||
function TPackageHandler.PackageRemoteArchive: String;
|
||||
@ -160,14 +160,14 @@ begin
|
||||
if CurrentPackage.ExternalURL<>'' then
|
||||
Result:=CurrentPackage.ExternalURL
|
||||
else
|
||||
Result:=Defaults.RemoteRepository+CurrentPackage.FileName;
|
||||
Result:=Options.RemoteRepository+CurrentPackage.FileName;
|
||||
end;
|
||||
|
||||
function TPackageHandler.PackageLocalArchive: String;
|
||||
begin
|
||||
if not assigned(CurrentPackage) then
|
||||
Error(SErrNoPackageSpecified);
|
||||
Result:=Defaults.PackagesDir+CurrentPackage.FileName;
|
||||
Result:=Options.PackagesDir+CurrentPackage.FileName;
|
||||
end;
|
||||
|
||||
|
||||
|
@ -15,6 +15,7 @@ Resourcestring
|
||||
SErrMissingFPMake = 'Missing configuration fpmake.pp';
|
||||
SErrMissingMakefilefpc = 'Missing configuration Makefile.fpc';
|
||||
SErrMissingDirectory = 'Missing directory "%s"';
|
||||
SErrMissingCompilerConfig = 'Could not found compiler configuration "%s"';
|
||||
SErrNoPackageSpecified = 'No package specified';
|
||||
SErrOnlyLocalDir = 'The speficied command "%s" works only on current dir, not on a (remote) package';
|
||||
SErrRunning = 'The FPC make tool encountered the following error:';
|
||||
@ -37,7 +38,7 @@ Resourcestring
|
||||
SErrCWDFailed = 'FTP CWD "%s" command failed.';
|
||||
SErrGETFailed = 'FTP GET "%s" command failed.';
|
||||
|
||||
SWarnFPMKUnitNotFound = 'Unit directory of fpmkunit is not found, compiling fpmake may file';
|
||||
SWarnFPMKUnitNotFound = 'Unit directory "%s" needed to compile fpmkunit is not found, compiling fpmake may file';
|
||||
|
||||
SLogGeneratingFPMake = 'Generating fpmake.pp';
|
||||
SLogNotCompilingFPMake = 'Skipping compiling of fpmake.pp, fpmake executable already exists';
|
||||
|
@ -48,6 +48,8 @@ Type
|
||||
// Compiler settings for compiling FPMake.pp
|
||||
FFPMakeCompiler : String;
|
||||
FFPMakeUnitDir : String;
|
||||
// Parameter options
|
||||
FBootStrap : Boolean;
|
||||
function GetOptString(Index: integer): String;
|
||||
procedure SetOptString(Index: integer; const AValue: String);
|
||||
procedure SetCompilerCPU(const AValue: TCPU);
|
||||
@ -87,10 +89,11 @@ Type
|
||||
Property CurrentCompilerConfig : String Index 16 Read GetOptString Write SetOptString;
|
||||
Property CompilerOS : TOS Read FCompilerOS Write SetCompilerOS;
|
||||
Property CompilerCPU : TCPU Read FCompilerCPU Write SetCompilerCPU;
|
||||
Property BootStrap : Boolean Read FBootStrap Write FBootStrap;
|
||||
end;
|
||||
|
||||
var
|
||||
Defaults : TPackagerOptions;
|
||||
Options : TPackagerOptions;
|
||||
|
||||
Implementation
|
||||
|
||||
@ -259,12 +262,15 @@ begin
|
||||
FDefaultCompilerConfig:='default';
|
||||
FCurrentCompilerConfig:=FDefaultCompilerConfig;
|
||||
FDefaultVerbosity:='error,warning,info,debug,commands';
|
||||
FBootStrap:=False;
|
||||
end;
|
||||
|
||||
|
||||
Procedure TPackagerOptions.InitCompilerDefaults;
|
||||
var
|
||||
infoSL : TStringList;
|
||||
DepDir : String;
|
||||
i : Integer;
|
||||
begin
|
||||
FCompiler:=FileSearch('fpc'+ExeExt,GetEnvironmentVariable('PATH'));
|
||||
if FCompiler='' then
|
||||
@ -302,9 +308,13 @@ begin
|
||||
Log(vDebug,SLogDetectedFPCDIR,[FInstallDir]);
|
||||
// Detect directory where fpmake units are located
|
||||
FFPMakeCompiler:=FCompiler;
|
||||
FFPMakeUnitDir:=FInstallDir+'units'+PathDelim+CompilerTarget+PathDelim+'fpmkunit'+PathDelim;
|
||||
if not DirectoryExists(FFPMakeUnitDir) then
|
||||
Log(vWarning,SWarnFPMKUnitNotFound);
|
||||
FFPMakeUnitDir:=FInstallDir+'units'+PathDelim+CompilerTarget+PathDelim;
|
||||
for i:=low(FPMKUnitDeps) to high(FPMKUnitDeps) do
|
||||
begin
|
||||
DepDir:=FFPMakeUnitDir+FPMKUnitDeps[i]+PathDelim;
|
||||
if not DirectoryExists(DepDir) then
|
||||
Log(vWarning,SWarnFPMKUnitNotFound,[DepDir]);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
@ -425,8 +435,9 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
initialization
|
||||
Defaults:=TPackagerOptions.Create;
|
||||
Options:=TPackagerOptions.Create;
|
||||
finalization
|
||||
FreeAndNil(Defaults);
|
||||
FreeAndNil(Options);
|
||||
end.
|
||||
|
@ -36,19 +36,19 @@ begin
|
||||
CurrentRepository.Free;
|
||||
CurrentRepository:=TFPRepository.Create(Nil);
|
||||
// Repository
|
||||
Log(vDebug,SLogLoadingPackagesFile,[Defaults.LocalPackagesFile]);
|
||||
if FileExists(Defaults.LocalPackagesFile) then
|
||||
Log(vDebug,SLogLoadingPackagesFile,[Options.LocalPackagesFile]);
|
||||
if FileExists(Options.LocalPackagesFile) then
|
||||
begin
|
||||
X:=TFPXMLRepositoryHandler.Create;
|
||||
With X do
|
||||
try
|
||||
LoadFromXml(CurrentRepository,Defaults.LocalPackagesFile);
|
||||
LoadFromXml(CurrentRepository,Options.LocalPackagesFile);
|
||||
finally
|
||||
Free;
|
||||
end;
|
||||
end;
|
||||
// Versions
|
||||
S:=Defaults.LocalVersionsFile(Defaults.CurrentCompilerConfig);
|
||||
S:=Options.LocalVersionsFile(Options.CurrentCompilerConfig);
|
||||
Log(vDebug,SLogLoadingVersionsFile,[S]);
|
||||
if FileExists(S) then
|
||||
CurrentRepository.LoadStatusFromFile(S);
|
||||
|
Loading…
Reference in New Issue
Block a user