Browse Source

Report a warning if a unit is used from an indirectly used package. We are doing this only for the units used in contained units though as in the "contains" section there can't be such units anyway (and just checking all loaded units would lead to false positives).

pkgutil.pas:
  + new procedure check_for_indirect_package_usages() which walks a TLinkedList of used units and warns on every unit that is from an indirectly imported package
pmodules.pas, proc_package:
  * when checking all loaded units whether they are from a package or not also check for indirect package usages using the new procedure

git-svn-id: branches/svenbarth/packages@32515 -
svenbarth 9 years ago
parent
commit
60739fa0df
2 changed files with 28 additions and 3 deletions
  1. 24 2
      compiler/pkgutil.pas
  2. 4 1
      compiler/pmodules.pas

+ 24 - 2
compiler/pkgutil.pas

@@ -27,7 +27,7 @@ unit pkgutil;
 interface
 
   uses
-    fmodule,fpkg,link,cstreams;
+    fmodule,fpkg,link,cstreams,cclasses;
 
   procedure createimportlibfromexternals;
   Function RewritePPU(const PPUFn:String;OutStream:TCStream):Boolean;
@@ -36,13 +36,14 @@ interface
   procedure add_package(const name:string;ignoreduplicates:boolean;direct:boolean);
   procedure add_package_unit_ref(package:tpackage);
   procedure add_package_libs(l:tlinker);
+  procedure check_for_indirect_package_usages(modules:tlinkedlist);
 
 implementation
 
   uses
     sysutils,
     globtype,systems,
-    cutils,cclasses,
+    cutils,
     globals,verbose,
     aasmbase,aasmdata,aasmtai,
     symtype,symconst,symsym,symdef,symbase,symtable,
@@ -519,6 +520,27 @@ implementation
         end;
     end;
 
+  procedure check_for_indirect_package_usages(modules:tlinkedlist);
+    var
+      uu : tused_unit;
+      pentry : ppackageentry;
+    begin
+      uu:=tused_unit(modules.first);
+      while assigned(uu) do
+        begin
+          if assigned(uu.u.package) then
+            begin
+              pentry:=ppackageentry(packagelist.find(uu.u.package.packagename^));
+              if not assigned(pentry) then
+                internalerror(2015112304);
+              if not pentry^.direct then
+                Message2(package_w_unit_from_indirect_package,uu.u.realmodulename^,uu.u.package.realpackagename^);
+            end;
+
+          uu:=tused_unit(uu.Next);
+        end;
+    end;
+
 
   procedure createimportlibfromexternals;
     type

+ 4 - 1
compiler/pmodules.pas

@@ -1667,7 +1667,10 @@ type
                 if (hp<>current_module) then
                   begin
                     if not assigned(hp.package) then
-                      pkg.addunit(hp)
+                      begin
+                        pkg.addunit(hp);
+                        check_for_indirect_package_usages(hp.used_units);
+                      end
                     else
                       begin
                         pentry:=ppackageentry(packagelist.find(hp.package.packagename^));