소스 검색

Provide possibility to pass packages and search paths for packages as parameters.

fpkg.pas:
  + new unit which contains the base types related to package files (most importantly "tpackage")
globals.pas:
  + new variable "packagesearchpath" which contains all paths in which package files should be looked for
  + new variable "packagelist" which contains a list of all packages that should be used in a program or library
  * InitGlobals & DoneGlobals: initialize/finalize "packagesearchpath" accordingly ("packagelist" is handled in unit fpkg using a init/done-callback)
options.pas:
  + TOption: new fields "parapackagepath" and "parapackages" to keep track of package search paths and package files passed as parameters
  * TOption.interpret_option: use '-Fp' for package search paths and '-FP' for package files
  * read_arguments: apply the passed package search paths and packages to their respective containers

git-svn-id: branches/svenbarth/packages@28796 -
svenbarth 10 년 전
부모
커밋
b46e909349
4개의 변경된 파일165개의 추가작업 그리고 3개의 파일을 삭제
  1. 1 0
      .gitattributes
  2. 131 0
      compiler/fpkg.pas
  3. 5 0
      compiler/globals.pas
  4. 28 3
      compiler/options.pas

+ 1 - 0
.gitattributes

@@ -177,6 +177,7 @@ compiler/finput.pas svneol=native#text/plain
 compiler/fmodule.pas svneol=native#text/plain
 compiler/fpccrc.pas svneol=native#text/plain
 compiler/fpcdefs.inc svneol=native#text/plain
+compiler/fpkg.pas svneol=native#text/pascal
 compiler/fppu.pas svneol=native#text/plain
 compiler/gendef.pas svneol=native#text/plain
 compiler/generic/cpuinfo.pas svneol=native#text/plain

+ 131 - 0
compiler/fpkg.pas

@@ -0,0 +1,131 @@
+{
+    Copyright (c) 2013-2014 by Free Pascal Development Team
+
+    This unit implements basic parts of the package system
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit fpkg;
+
+{$i fpcdefs.inc}
+
+interface
+
+  uses
+    cclasses,
+    globtype,
+    finput;
+
+  type
+    tcontainedunit=record
+      module:tmodulebase;
+      ppufile:tpathstr;
+    end;
+    pcontainedunit=^tcontainedunit;
+
+    tpackage=class
+    public
+      realpackagename,
+      packagename : pshortstring;
+      containedmodules : TFPHashList;
+      requiredpackages : TFPHashObjectList;
+      pcpfilename,
+      ppafilename,
+      pplfilename : tpathstr;
+      constructor create(const pn:string);
+      destructor destroy;override;
+    end;
+
+    tpackageentry=record
+      package : tpackage;
+      realpkgname : string;
+    end;
+    ppackageentry=^tpackageentry;
+
+    procedure addpackage(list:tfphashlist;const pn:string);
+
+implementation
+
+  uses
+    cutils,globals;
+
+  procedure addpackage(list: tfphashlist;const pn:string);
+    var
+      pkgentry : ppackageentry;
+    begin
+      new(pkgentry);
+      pkgentry^.realpkgname:=pn;
+      pkgentry^.package:=nil;
+      list.add(upper(pn),pkgentry);
+    end;
+
+  { tpackage }
+
+  constructor tpackage.create(const pn: string);
+    begin
+      realpackagename:=stringdup(pn);
+      packagename:=stringdup(upper(pn));
+      containedmodules:=TFPHashList.Create;
+      requiredpackages:=TFPHashObjectList.Create(false);
+    end;
+
+  destructor tpackage.destroy;
+    var
+      p : pcontainedunit;
+      i : longint;
+    begin
+      if assigned(containedmodules) then
+        for i:=0 to containedmodules.count-1 do
+          begin
+            p:=pcontainedunit(containedmodules[i]);
+            dispose(p);
+          end;
+      containedmodules.free;
+      requiredpackages.free;
+      inherited destroy;
+    end;
+
+
+    procedure packageinit;
+      begin
+        packagelist:=TFPHashList.Create;
+      end;
+
+
+    procedure packagedone;
+      var
+        i : longint;
+        pkgentry : ppackageentry;
+      begin
+        if assigned(packagelist) then
+          begin
+            for i:=0 to packagelist.count-1 do
+              begin
+                pkgentry:=ppackageentry(packagelist[i]);
+                pkgentry^.package.free;
+                dispose(pkgentry);
+              end;
+          end;
+        packagelist.Free;
+        packagelist:=nil;
+      end;
+
+
+initialization
+  register_initdone_proc(@packageinit,@packagedone);
+end.
+

+ 5 - 0
compiler/globals.pas

@@ -266,6 +266,9 @@ interface
        objectsearchpath,
        includesearchpath,
        frameworksearchpath  : TSearchPathList;
+       packagesearchpath     : TSearchPathList;
+       { contains tpackageentry entries }
+       packagelist : TFPHashList;
        autoloadunits      : string;
 
        { linking }
@@ -1400,6 +1403,7 @@ implementation
        frameworksearchpath.Free;
        LinkLibraryAliases.Free;
        LinkLibraryOrder.Free;
+       packagesearchpath.Free;
      end;
 
    procedure InitGlobals;
@@ -1439,6 +1443,7 @@ implementation
         includesearchpath:=TSearchPathList.Create;
         objectsearchpath:=TSearchPathList.Create;
         frameworksearchpath:=TSearchPathList.Create;
+        packagesearchpath:=TSearchPathList.Create;
 
         { Def file }
         usewindowapi:=false;

+ 28 - 3
compiler/options.pas

@@ -26,8 +26,8 @@ unit options;
 interface
 
 uses
-  cfileutl,
-  globtype,globals,verbose,systems,cpuinfo,comprsrc;
+  cfileutl,cclasses,
+  globtype,globals,verbose,systems,cpuinfo, comprsrc;
 
 Type
   TOption=class
@@ -47,8 +47,10 @@ Type
     ParaUnitPath,
     ParaObjectPath,
     ParaLibraryPath,
-    ParaFrameworkPath : TSearchPathList;
+    ParaFrameworkPath,
+    parapackagepath : TSearchPathList;
     ParaAlignment   : TAlignmentInfo;
+    parapackages : tfphashobjectlist;
     Constructor Create;
     Destructor Destroy;override;
     procedure WriteLogo;
@@ -92,6 +94,7 @@ uses
   symtable,scanner,rabase,
   symconst,
   dirparse,
+  fpkg,
   i_bsd;
 
 const
@@ -1242,6 +1245,20 @@ begin
                      else
                        ObjectSearchPath.AddPath(More,true);
                    end;
+                 'P' :
+                   begin
+                     if ispara then
+                       parapackages.add(more,nil)
+                     else
+                       addpackage(packagelist,more);
+                   end;
+                 'p' :
+                   begin
+                     if ispara then
+                       parapackagepath.AddPath(More,false)
+                     else
+                       packagesearchpath.AddPath(More,true);
+                   end;
                  'r' :
                    Msgfilename:=More;
                  'R' :
@@ -2791,6 +2808,8 @@ begin
   ParaUnitPath:=TSearchPathList.Create;
   ParaLibraryPath:=TSearchPathList.Create;
   ParaFrameworkPath:=TSearchPathList.Create;
+  parapackagepath:=TSearchPathList.Create;
+  parapackages:=TFPHashObjectList.Create;
   FillChar(ParaAlignment,sizeof(ParaAlignment),0);
   MacVersionSet:=false;
 end;
@@ -2804,6 +2823,8 @@ begin
   ParaUnitPath.Free;
   ParaLibraryPath.Free;
   ParaFrameworkPath.Free;
+  parapackagepath.Free;
+  ParaPackages.Free;
 end;
 
 
@@ -2877,6 +2898,7 @@ procedure read_arguments(cmd:TCmdStr);
 var
   env: ansistring;
   i : tfeature;
+  j : longint;
   abi : tabi;
 {$if defined(cpucapabilities)}
   cpuflag : tcpuflags;
@@ -3270,6 +3292,9 @@ begin
   IncludeSearchPath.AddList(option.ParaIncludePath,true);
   LibrarySearchPath.AddList(option.ParaLibraryPath,true);
   FrameworkSearchPath.AddList(option.ParaFrameworkPath,true);
+  packagesearchpath.addlist(option.parapackagepath,true);
+  for j:=0 to option.parapackages.count-1 do
+    addpackage(packagelist,option.parapackages.NameOfIndex(j));
 
   { add unit environment and exepath to the unit search path }
   if inputfilepath<>'' then