Browse Source

Also load all packages that are required by packages, but that are not part of the directly used packages.

pkgutil.pas, load_packages:
  * check the list of required packages for packages that are not yet part of the package list and add these as indirect packages
  * establish the links to loaded packages in the required packages once all packages were loaded

git-svn-id: branches/svenbarth/packages@32509 -
svenbarth 9 years ago
parent
commit
c768cc7dc1
1 changed files with 42 additions and 3 deletions
  1. 42 3
      compiler/pkgutil.pas

+ 42 - 3
compiler/pkgutil.pas

@@ -400,13 +400,17 @@ implementation
 
   procedure load_packages;
     var
-      i : longint;
+      i,j : longint;
       pcp: tpcppackage;
-      entry : ppackageentry;
+      entry,
+      entryreq : ppackageentry;
+      name,
+      uname : string;
     begin
       if not (tf_supports_packages in target_info.flags) then
         exit;
-      for i:=0 to packagelist.count-1 do
+      i:=0;
+      while i<packagelist.count do
         begin
           entry:=ppackageentry(packagelist[i]);
           if assigned(entry^.package) then
@@ -415,6 +419,41 @@ implementation
           pcp:=tpcppackage.create(entry^.realpkgname);
           pcp.loadpcp;
           entry^.package:=pcp;
+
+          { add all required packages that are not yet part of packagelist }
+          for j:=0 to pcp.requiredpackages.count-1 do
+            begin
+              name:=pcp.requiredpackages.NameOfIndex(j);
+              uname:=upper(name);
+              if not assigned(packagelist.Find(uname)) then
+                begin
+                  New(entryreq);
+                  entryreq^.realpkgname:=name;
+                  entryreq^.package:=nil;
+                  entryreq^.usedunits:=0;
+                  entryreq^.direct:=false;
+                  packagelist.add(uname,entryreq);
+                end;
+            end;
+
+          Inc(i);
+        end;
+
+      { all packages are now loaded, so we can fill in the links of the required packages }
+      for i:=0 to packagelist.count-1 do
+        begin
+          entry:=ppackageentry(packagelist[i]);
+          if not assigned(entry^.package) then
+            internalerror(2015111301);
+          for j:=0 to entry^.package.requiredpackages.count-1 do
+            begin
+              if assigned(entry^.package.requiredpackages[j]) then
+                internalerror(2015111303);
+              entryreq:=packagelist.find(upper(entry^.package.requiredpackages.NameOfIndex(j)));
+              if not assigned(entryreq) then
+                internalerror(2015111302);
+              entry^.package.requiredpackages[j]:=entryreq^.package;
+            end;
         end;
     end;