Browse Source

* compile command added
* basic work for package dependencies

git-svn-id: trunk@9168 -

peter 18 years ago
parent
commit
33b5d4d73c

+ 0 - 1
.gitattributes

@@ -8741,7 +8741,6 @@ utils/fppkg/lnet/sys/lkqueueeventerh.inc svneol=native#text/plain
 utils/fppkg/lnet/sys/lspawnfcgiunix.inc svneol=native#text/plain
 utils/fppkg/lnet/sys/lspawnfcgiwin.inc svneol=native#text/plain
 utils/fppkg/lnet/sys/osunits.inc svneol=native#text/plain
-utils/fppkg/pkgarchive.pp svneol=native#text/plain
 utils/fppkg/pkgcommands.pp svneol=native#text/plain
 utils/fppkg/pkgdownload.pp svneol=native#text/plain
 utils/fppkg/pkgfpmake.pp svneol=native#text/plain

+ 21 - 39
utils/fppkg/fppkg.pp

@@ -13,7 +13,7 @@ uses
   pkgmessages, pkgglobals, pkgoptions, pkgrepos,
   // Package Handler components
   pkghandler,pkgmkconv, pkgdownload,
-  pkgarchive, pkgfpmake, pkgcommands
+  pkgfpmake, pkgcommands
   // Downloaders
 {$if defined(unix) or defined(windows)}
   ,pkgwget
@@ -25,10 +25,9 @@ Type
 
   TMakeTool = Class(TCustomApplication)
   Private
-    ActionStack : TActionStack;
-    ParaAction : string;
+    ActionStack  : TActionStack;
+    ParaAction   : string;
     ParaPackages : TStringList;
-    procedure GenerateParaActions;
     procedure MaybeCreateLocalDirs;
     procedure ShowUsage;
   Public
@@ -248,40 +247,12 @@ begin
 end;
 
 
-procedure TMakeTool.GenerateParaActions;
-var
-  ActionPackage : TFPPackage;
-  i : integer;
-begin
-  if GetPkgHandler(ParaAction)<>nil then
-    begin
-      if ParaPackages.Count=0 then
-        begin
-          Log(vDebug,SLogCommandLineAction,['[<currentdir>]',ParaAction]);
-          ActionStack.Push(nil,ParaAction,[]);
-        end
-      else
-        begin
-          for i:=0 to ParaPackages.Count-1 do
-            begin
-              ActionPackage:=CurrentRepository.PackageByName(ParaPackages[i]);
-              Log(vDebug,SLogCommandLineAction,['['+ActionPackage.Name+']',ParaAction]);
-              ActionStack.Push(ActionPackage,ParaAction,[]);
-            end;
-        end;
-    end
-  else
-    Raise EMakeToolError.CreateFmt(SErrInvalidCommand,[ParaAction]);
-end;
-
-
 procedure TMakeTool.DoRun;
 var
-  Action : string;
   ActionPackage : TFPPackage;
-  Args   : TActionArgs;
   OldCurrDir : String;
   Res    : Boolean;
+  i      : Integer;
 begin
   OldCurrDir:=GetCurrentDir;
   LoadGlobalDefaults;
@@ -290,13 +261,24 @@ begin
     MaybeCreateLocalDirs;
     LoadCompilerDefaults;
     LoadLocalRepository;
-    GenerateParaActions;
 
-    repeat
-      if not ActionStack.Pop(ActionPackage,Action,Args) then
-        break;
-      res:=pkghandler.ExecuteAction(ActionPackage,Action,Args);
-    until not res;
+    if ParaPackages.Count=0 then
+      begin
+        Log(vDebug,SLogCommandLineAction,['[<currentdir>]',ParaAction]);
+        res:=pkghandler.ExecuteAction(nil,ParaAction);
+      end
+    else
+      begin
+        for i:=0 to ParaPackages.Count-1 do
+          begin
+            ActionPackage:=CurrentRepository.PackageByName(ParaPackages[i]);
+            Log(vDebug,SLogCommandLineAction,['['+ActionPackage.Name+']',ParaAction]);
+            res:=pkghandler.ExecuteAction(ActionPackage,ParaAction);
+            if not res then
+              break;
+          end;
+      end;
+
     Terminate;
 
   except

+ 13 - 33
utils/fppkg/fprepos.pp

@@ -26,15 +26,20 @@ Const
   StreamSignature = $FEEF;
 
 Type
-  TOS = (osNone,Amiga,Atari,Darwin,FreeBSD,Go32v2,Linux,MacOS,MorphOS,NetBSD,
-         Netware,NetwLibc,OpenBSD,OS2,PalmOS,Solaris,Win32,Win64,WinCE,Emx);
-  TOSes = Set of TOS;
-
-  TCPU = (cpuNone,Arm,I386,PPC,SPARC,X86_64,M68K,PPC64);
+  // Keep syncronized with fpmkunit.pp
+  TCpu=(cpuNone,
+    i386,m68k,powerpc,sparc,x86_64,arm,powerpc64
+  );
   TCPUS = Set of TCPU;
 
-  TCompilerMode = (cmFPC,cmTP,cmObjFPC,cmDelphi,cmMacPas);
-  TCompilerModes = Set of TCompilerMode;
+  // Keep syncronized with fpmkunit.pp
+  TOS=(osNone,
+    linux,go32v2,win32,os2,freebsd,beos,netbsd,
+    amiga,atari, solaris, qnx, netware, openbsd,wdosx,
+    palmos,macos,darwin,emx,watcom,morphos,netwlibc,
+    win64,wince,gba,nds,embedded,symbian
+  );
+  TOSes = Set of TOS;
 
   { TFPVersion }
 
@@ -214,8 +219,6 @@ Function StringToOS(S : String) : TOS;
 Function OSesToString(S : String) : TOSes;
 Function StringToCPU(S : String) : TCPU;
 Function StringToCPUS(S : String) : TCPUS;
-Function ModeToString(Mode: TCompilerMode) : String;
-Function StringToMode(S : String) : TCompilerMode;
 Function MakeTargetString(CPU : TCPU;OS: TOS) : String;
 Procedure StringToCPUOS(S : String; Var CPU : TCPU; Var OS: TOS);
 
@@ -300,25 +303,6 @@ begin
   Result:=TCPUS(StringToSet(PTypeInfo(TypeInfo(TCPUS)),S));
 end;
 
-Function ModeToString(Mode: TCompilerMode) : String;
-
-begin
-  Result:=LowerCase(GetenumName(TypeInfo(TCompilerMode),Ord(Mode)));
-end;
-
-Function StringToMode(S : String) : TCompilerMode;
-
-Var
-  I : Integer;
-
-begin
-  I:=GetEnumValue(TypeInfo(TCompilerMode),S);
-  if (I=-1) then
-    Raise EPackage.CreateFmt(SErrInvalidMode,[S]);
-  Result:=TCompilerMode(I);
-end;
-
-
 Function MakeTargetString(CPU : TCPU;OS: TOS) : String;
 
 begin
@@ -460,9 +444,6 @@ end;
 
 procedure TFPPackage.SetName(const AValue: String);
 
-Var
-  I : Integer;
-
 begin
   If (AValue<>FName) and (AValue<>'') then
     If (Collection<>Nil) and (Collection is TFPPackages) then
@@ -482,7 +463,7 @@ end;
 
 function TFPPackage.GetHasDependencies: Boolean;
 begin
-  Result:=Assigned(FDependencies) and (FDependencies.Count>0);
+  Result:=(Dependencies<>nil) and (FDependencies.Count>0);
 end;
 
 function TFPPackage.GetFileName: String;
@@ -766,7 +747,6 @@ procedure TFPRepository.SaveToFile(AFileName: String);
 
 Var
   F : TFileStream;
-  S : String;
 
 begin
   If FileExists(AFileName) and BackupFiles then

+ 0 - 142
utils/fppkg/pkgarchive.pp

@@ -1,142 +0,0 @@
-unit pkgarchive;
-
-{$mode objfpc}{$H+}
-
-interface
-
-uses
-  Classes,SysUtils,pkghandler;
-
-type
-  { TUnzipArchive }
-
-  TUnzipArchive = Class(TPackagehandler)
-  Private
-    Procedure UnzipArchive;
-  Public
-    Function Execute(const Args:TActionArgs):boolean;override;
-  end;
-
-
-{$ifdef OLDCREATEARCHIVE}
-  { TCreateArchive }
-
-  TCreateArchive = Class(TPackagehandler)
-  Private
-    Procedure CreateArchive;
-  Public
-    Function Execute(const Args:TActionArgs):boolean;override;
-  end;
-{$endif OLDCREATEARCHIVE}
-
-
-implementation
-
-uses
-  fprepos,
-  fpxmlrep,
-  zipper,
-  uriparser,
-  pkgglobals,
-  pkgmessages;
-
-{ TUnzipArchive }
-
-Procedure TUnzipArchive.UnzipArchive;
-Var
-  BuildDir : string;
-  ArchiveFile : String;
-begin
-  ArchiveFile:=PackageLocalArchive;
-  BuildDir:=PackageBuildPath;
-  { Download file if it doesn't exists yet }
-  if not FileExists(ArchiveFile) then
-    ExecuteAction(CurrentPackage,'downloadpackage');
-  { Create builddir, remove it first if needed }
-  if DirectoryExists(BuildDir) then
-    DeleteDir(BuildDir);
-  ForceDirectories(BuildDir);
-  SetCurrentDir(BuildDir);
-  { Unzip Archive }
-  With TUnZipper.Create do
-    try
-      Log(vCommands,SLogUnzippping,[ArchiveFile]);
-      OutputPath:=PackageBuildPath;
-      UnZipAllFiles(ArchiveFile);
-    Finally
-      Free;
-    end;
-end;
-
-
-function TUnzipArchive.Execute(const Args:TActionArgs):boolean;
-begin
-{$warning TODO Check arguments}
-  UnzipArchive;
-  result:=true;
-end;
-
-
-{$ifdef OLDCREATEARCHIVE}
-{ TCreateArchive }
-
-procedure TCreateArchive.CreateArchive;
-var
-  P : TFPPackage;
-  PS : TFPPackages;
-  X : TFPXMLRepositoryHandler;
-  SL : TStringList;
-begin
-  if assigned(CurrentPackage) then
-    Error(SErrOnlyLocalDir);
-  { Generate manifest.xml if it doesn't exists yet }
-  if not FileExists(PackageManifestFile) then
-    ExecuteAction(CurrentPackage,'fpmakemanifest');
-  { Load manifest.xml }
-  PS:=TFPPackages.Create(TFPPackage);
-  X:=TFPXMLRepositoryHandler.Create;
-  With X do
-    try
-      LoadFromXml(PS,PackageManifestFile);
-    finally
-      Free;
-    end;
-  { Create archive, currently support only 1 file per package, this
-    can be enhanced in the future if needed }
-  if PS.Count<>1 then
-    Error('Only one package supported per manifest');
-  P:=PS[0];
-  { Unzip Archive }
-  With TZipper.Create do
-    try
-      Log(vCommands,SLogZippping,[P.FileName]);
-{$warning TODO replace with files from manifest}
-      try
-        SL:=TStringList.Create;
-        SearchFiles(SL,AllFiles);
-        if SL.Count=0 then
-          Error('No files found');
-        ZipFiles(P.FileName,SL);
-      finally
-        SL.Free;
-      end;
-    Finally
-      Free;
-    end;
-  P.Free;
-end;
-
-function TCreateArchive.Execute(const Args: TActionArgs): boolean;
-begin
-  CreateArchive;
-  Result:=true;
-end;
-{$endif OLDCREATEARCHIVE}
-
-
-initialization
-  RegisterPkgHandler('unziparchive',TUnzipArchive);
-{$ifdef OLDCREATEARCHIVE}
-  RegisterPkgHandler('createarchive',TCreateArchive);
-{$endif OLDCREATEARCHIVE}
-end.

+ 98 - 4
utils/fppkg/pkgcommands.pp

@@ -10,11 +10,13 @@ uses
 implementation
 
 uses
+  zipper,
   pkgmessages,
   pkgglobals,
   pkgoptions,
   pkgdownload,
-  pkgrepos;
+  pkgrepos,
+  fprepos;
 
 type
   { TCommandAddConfig }
@@ -59,6 +61,13 @@ type
     Function Execute(const Args:TActionArgs):boolean;override;
   end;
 
+  { TCommandCompile }
+
+  TCommandCompile = Class(TPackagehandler)
+  Public
+    Function Execute(const Args:TActionArgs):boolean;override;
+  end;
+
   { TCommandBuild }
 
   TCommandBuild = Class(TPackagehandler)
@@ -80,6 +89,13 @@ type
     Function Execute(const Args:TActionArgs):boolean;override;
   end;
 
+  { TCommandInstallDependencies }
+
+  TCommandInstallDependencies = Class(TPackagehandler)
+  Public
+    Function Execute(const Args:TActionArgs):boolean;override;
+  end;
+
 
 function TCommandAddConfig.Execute(const Args:TActionArgs):boolean;
 begin
@@ -127,10 +143,42 @@ end;
 
 
 function TCommandUnzip.Execute(const Args:TActionArgs):boolean;
+Var
+  BuildDir : string;
+  ArchiveFile : String;
 begin
+  BuildDir:=PackageBuildPath;
+  ArchiveFile:=PackageLocalArchive;
   if not assigned(CurrentPackage) then
     Error(SErrNoPackageSpecified);
-  ExecuteAction(CurrentPackage,'unziparchive',Args);
+  if not FileExists(ArchiveFile) then
+    ExecuteAction(CurrentPackage,'downloadpackage');
+  { Create builddir, remove it first if needed }
+  if DirectoryExists(BuildDir) then
+    DeleteDir(BuildDir);
+  ForceDirectories(BuildDir);
+  SetCurrentDir(BuildDir);
+  { Unzip Archive }
+  With TUnZipper.Create do
+    try
+      Log(vCommands,SLogUnzippping,[ArchiveFile]);
+      OutputPath:=PackageBuildPath;
+      UnZipAllFiles(ArchiveFile);
+    Finally
+      Free;
+    end;
+  Result:=true;
+end;
+
+
+function TCommandCompile.Execute(const Args:TActionArgs):boolean;
+begin
+  if assigned(CurrentPackage) then
+    begin
+      ExecuteAction(CurrentPackage,'unzip',Args);
+      ExecuteAction(CurrentPackage,'installdependencies',Args);
+    end;
+  ExecuteAction(CurrentPackage,'fpmakecompile',Args);
   Result:=true;
 end;
 
@@ -139,8 +187,8 @@ function TCommandBuild.Execute(const Args:TActionArgs):boolean;
 begin
   if assigned(CurrentPackage) then
     begin
-      if not DirectoryExists(PackageBuildPath) then
-        ExecuteAction(CurrentPackage,'unziparchive',Args);
+      ExecuteAction(CurrentPackage,'unzip',Args);
+      ExecuteAction(CurrentPackage,'installdependencies',Args);
     end;
   ExecuteAction(CurrentPackage,'fpmakebuild',Args);
   Result:=true;
@@ -149,6 +197,8 @@ end;
 
 function TCommandInstall.Execute(const Args:TActionArgs):boolean;
 begin
+  if assigned(CurrentPackage) then
+    ExecuteAction(CurrentPackage,'build',Args);
   ExecuteAction(CurrentPackage,'fpmakeinstall',Args);
   Result:=true;
 end;
@@ -161,13 +211,57 @@ begin
 end;
 
 
+function TCommandInstallDependencies.Execute(const Args:TActionArgs):boolean;
+var
+  i : Integer;
+  D : TFPDependency;
+  DepPackage : TFPPackage;
+  L : TStringList;
+  status : string;
+begin
+  if not assigned(CurrentPackage) then
+    Error(SErrNoPackageSpecified);
+  // List dependencies
+  L:=TStringList.Create;
+  for i:=0 to CurrentPackage.Dependencies.Count-1 do
+    begin
+      D:=CurrentPackage.Dependencies[i];
+      DepPackage:=CurrentRepository.PackageByName(D.PackageName);
+      // Need installation?
+      if (not DepPackage.InstalledVersion.Empty) and
+         (DepPackage.InstalledVersion.CompareVersion(D.MinVersion)<0) then
+        begin
+          if DepPackage.Version.CompareVersion(D.MinVersion)<0 then
+            status:='Required Version Not Available!'
+          else
+            status:='Needs update';
+          L.Add(DepPackage.Name);
+        end
+      else
+        status:='OK';
+      Log(vDebug,'Dependency '+D.PackageName+'-'+D.MinVersion.AsString+' ('+status+')');
+    end;
+  // Install needed updates
+  for i:=0 to L.Count-1 do
+    begin
+      DepPackage:=CurrentRepository.PackageByName(L[i]);
+      ExecuteAction(DepPackage,'install');
+    end;
+
+  FreeAndNil(L);
+  Result:=true;
+end;
+
+
 initialization
   RegisterPkgHandler('update',TCommandUpdate);
   RegisterPkgHandler('avail',TCommandAvail);
   RegisterPkgHandler('scan',TCommandScanPackages);
   RegisterPkgHandler('download',TCommandDownload);
   RegisterPkgHandler('unzip',TCommandUnzip);
+  RegisterPkgHandler('compile',TCommandCompile);
   RegisterPkgHandler('build',TCommandBuild);
   RegisterPkgHandler('install',TCommandInstall);
   RegisterPkgHandler('archive',TCommandArchive);
+  RegisterPkgHandler('installdependencies',TCommandInstallDependencies);
 end.

+ 1 - 1
utils/fppkg/pkgdownload.pp

@@ -104,7 +104,6 @@ Var
   F : TFileStream;
 
 begin
-  Log(vCommands,SLogDownloading,[URL,DestFileName]);
   If FileExists(DestFileName) and BackupFiles then
     BackupFile(DestFileName);
   F:=TFileStream.Create(DestFileName,fmCreate);
@@ -141,6 +140,7 @@ function TDownloadPackage.Execute(const Args:TActionArgs):boolean;
 begin
   with DownloaderClass.Create(nil) do
     try
+      Log(vCommands,SLogDownloading,[PackageRemoteArchive,PackageLocalArchive]);
       Download(PackageRemoteArchive,PackageLocalArchive);
     finally
       Free;

+ 15 - 1
utils/fppkg/pkgfpmake.pp

@@ -34,6 +34,14 @@ type
   end;
 
 
+  { TFPMakeRunnerCompile }
+
+  TFPMakeRunnerCompile = Class(TFPMakeRunner)
+  Public
+    Function Execute(const Args:TActionArgs):boolean;override;
+  end;
+
+
   { TFPMakeRunnerBuild }
 
   TFPMakeRunnerBuild = Class(TFPMakeRunner)
@@ -276,13 +284,18 @@ begin
 end;
 
 
+function TFPMakeRunnerCompile.Execute(const Args:TActionArgs):boolean;
+begin
+  result:=(RunFPMake('compile')=0);
+end;
+
+
 function TFPMakeRunnerBuild.Execute(const Args:TActionArgs):boolean;
 begin
   result:=(RunFPMake('build')=0);
 end;
 
 
-
 function TFPMakeRunnerInstall.Execute(const Args:TActionArgs):boolean;
 begin
   result:=(RunFPMake('install')=0);
@@ -305,6 +318,7 @@ end;
 
 initialization
   RegisterPkgHandler('compilefpmake',TFPMakeCompiler);
+  RegisterPkgHandler('fpmakecompile',TFPMakeRunnerCompile);
   RegisterPkgHandler('fpmakebuild',TFPMakeRunnerBuild);
   RegisterPkgHandler('fpmakeinstall',TFPMakeRunnerInstall);
   RegisterPkgHandler('fpmakemanifest',TFPMakeRunnerManifest);

+ 3 - 0
utils/fppkg/pkgglobals.pp

@@ -201,6 +201,9 @@ Procedure DeleteDir(const ADir:string);
 var
   Info : TSearchRec;
 begin
+  // Prevent accidently deleting all files in current or root dir
+  if (ADir='') or (ADir=PathDelim) then
+    exit;
   if FindFirst(ADir+PathDelim+AllFiles,faAnyFile, Info)=0 then
     try
       repeat

+ 20 - 2
utils/fppkg/pkghandler.pp

@@ -76,7 +76,8 @@ uses
   pkgmessages;
 
 var
-  PkgHandlerList : TFPHashList;
+  PkgHandlerList  : TFPHashList;
+  ExecutedActions : TFPHashList;
 
 procedure RegisterPkgHandler(const AAction:string;pkghandlerclass:TPackageHandlerClass);
 begin
@@ -102,8 +103,22 @@ var
   pkghandlerclass : TPackageHandlerClass;
   i : integer;
   logargs : string;
+  FullActionName : string;
 begin
   result:=false;
+  // Check if we have already executed or are executing the action
+  if assigned(Apackage) then
+    FullActionName:=APackage.Name+AAction
+  else
+    FullActionName:=AAction;
+  if ExecutedActions.Find(FullActionName)<>nil then
+    begin
+      Log(vDebug,'Already executed or executing action '+FullActionName);
+      result:=true;
+      exit;
+    end;
+  ExecutedActions.Add(FullActionName,Pointer(PtrUInt(1)));
+  // Create action handler class
   pkghandlerclass:=GetPkgHandler(AAction);
   With pkghandlerclass.Create(nil,APackage) do
     try
@@ -115,8 +130,9 @@ begin
           else
             logargs:=logargs+','+Args[i];
         end;
-      Log(vDebug,SLogRunAction,[AAction,logargs]);
+      Log(vDebug,SLogRunAction+' start',[AAction,logargs]);
       result:=Execute(Args);
+      Log(vDebug,SLogRunAction+' end',[AAction,logargs]);
     finally
       Free;
     end;
@@ -278,6 +294,8 @@ end;
 
 initialization
   PkgHandlerList:=TFPHashList.Create;
+  ExecutedActions:=TFPHashList.Create;
 finalization
   FreeAndNil(PkgHandlerList);
+  FreeAndNil(ExecutedActions);
 end.