Changed to read project definition files *before* class libraries,
authorStefan Vogel <sv@exept.de>
Thu, 01 Feb 2007 18:16:18 +0100
changeset 10367 2228ee94e567
parent 10366 8990764f8911
child 10368 402117e3a3ef
Changed to read project definition files *before* class libraries, in order that superclasses defined in prerequisites are loaded before the subclasses.
Smalltalk.st
--- a/Smalltalk.st	Thu Feb 01 18:14:38 2007 +0100
+++ b/Smalltalk.st	Thu Feb 01 18:16:18 2007 +0100
@@ -6390,84 +6390,94 @@
 !
 
 loadPackageWithId:aPackageId fromDirectory:packageDirOrStringOrNil asAutoloaded:doLoadAsAutoloaded
-    |f packageDir packageName shLibName defClass defClassName silent|
+    "load a package referenced by aPackageId - a string like 'stx:libbasic'.
+     The package is either located in packageDirOrStringOrNil, or in the current directory"
+
+    |packageDir packageName shLibName filename
+     projectDefinitionClass projectDefinitionClassName silent|
 
     packageDirOrStringOrNil notNil ifTrue:[
         packageDir := packageDirOrStringOrNil asFilename.
     ].
     silent := SilentLoading or:[ StandAlone ].
 
-    "/ .so ?
-    shLibName := aPackageId asPackageId libraryName , ObjectFileLoader sharedLibraryExtension.
-
-    f := Filename currentDirectory construct:shLibName.
-    f exists ifFalse:[
-        packageDir notNil ifTrue:[
-            f := packageDir construct:shLibName.
-            f exists ifFalse:[
-                f := (packageDir construct:'objbc') construct:shLibName.
-            ]
-        ]
-    ].
-    f exists ifTrue:[
-        (self loadPackage:aPackageId fromClassLibrary:f) ifTrue:[
-            silent ifFalse:[
-                Transcript showCR:('loaded package: ' , aPackageId , ' from binary classLib file: ' , f pathName).
+    "For now: have to read the project definition first!!
+     The class library may contain subclasses of classes in prerequisite packages -
+     so the prerequisite packages have to be loaded first"
+
+    "normally there is a project definiton, use that one to pull in the rest"
+
+    "maybe, it is already in the image - autoloaded"
+    projectDefinitionClass := ProjectDefinition definitionClassForPackage:aPackageId.
+
+    "if not, file it in ..."
+    (projectDefinitionClass isNil and:[packageDir notNil]) ifTrue:[
+        projectDefinitionClassName := ProjectDefinition initialClassNameForDefinitionOf:aPackageId.
+        "/ try to load the project definition class
+        filename := (packageDir construct:projectDefinitionClassName) withSuffix:'st'.
+        filename exists ifFalse:[
+            filename := ((packageDir construct:'source') construct:projectDefinitionClassName) withSuffix:'st'.
+        ].    
+        filename exists ifTrue:[
+            Class withoutUpdatingChangesDo:[
+                filename fileIn.
             ].
-            doLoadAsAutoloaded ifFalse:[
-                "/ force autoloading...
-                Smalltalk allClassesDo:[:eachClass |
-                    eachClass package == aPackageId ifTrue:[ eachClass autoload].
-                ].
-            ].
-            ^ true
-        ]
-    ].
-
-    "/ if there is a project definiton, use that one to pull in the rest.
-    defClass := ProjectDefinition definitionClassForPackage:aPackageId.
-    defClass notNil ifTrue:[
-        defClass autoload.
-        defClass load.
+            projectDefinitionClass := ProjectDefinition definitionClassForPackage:aPackageId.
+        ].
+    ].
+    
+    projectDefinitionClass notNil ifTrue:[
+        projectDefinitionClass autoload.
+
+        "XXX have to honor doLoadAsAutoloaded here!!"
+        projectDefinitionClass load.
         silent ifFalse:[
             Transcript showCR:('Smalltalk [info]: loaded package: ' , aPackageId , ' from project definition').
         ].
         ^ true.
     ].
 
+    "Is there a shared library (.dll or .so) ?"
+    shLibName := aPackageId asPackageId libraryName , ObjectFileLoader sharedLibraryExtension.
+
+    filename := Filename currentDirectory construct:shLibName.
+    filename exists ifFalse:[
+        packageDir notNil ifTrue:[
+            filename := packageDir construct:shLibName.
+            filename exists ifFalse:[
+                filename := (packageDir construct:'objbc') construct:shLibName.
+            ]
+        ]
+    ].
+    filename exists ifTrue:[
+        (self loadPackage:aPackageId fromClassLibrary:filename) ifTrue:[
+            silent ifFalse:[
+                Transcript showCR:('loaded package: ' , aPackageId , ' from binary classLib file: ' , filename pathName).
+            ].
+            doLoadAsAutoloaded ifFalse:[
+                "/ force autoloading...
+                Smalltalk allClassesDo:[:eachClass |
+                    eachClass package == aPackageId ifTrue:[eachClass autoload].
+                ].
+            ].
+            ^ true
+        ]
+    ].
+
     packageDir isNil ifTrue:[
         ^ false.
     ].
 
-    defClassName := ProjectDefinition initialClassNameForDefinitionOf:aPackageId.
-    "/ try to load the project definition class
-    f := (packageDir construct:defClassName) withSuffix:'st'.
-    f exists ifFalse:[
-        f := ((packageDir construct:'source') construct:defClassName) withSuffix:'st'.
-    ].    
-    f exists ifTrue:[
-        Class withoutUpdatingChangesDo:[
-            f fileIn.
-        ].
-        defClass := ProjectDefinition definitionClassForPackage:aPackageId.
-        defClass notNil ifTrue:[
-            defClass load.
-            silent ifFalse:[
-                Transcript showCR:('Smalltalk [info]: loaded package: ' , aPackageId , ' from project file: ' , f pathName).
-            ].
-            ^ true
-        ].
-    ].
 
     "/ loadAll ? - well be soon obsolete
-    f := packageDir construct:'loadAll'.
-    f exists ifFalse:[
-        f := packageDir construct:'loadall'.
-    ].
-    f exists ifTrue:[
-        (self loadPackage:aPackageId fromLoadAllFile:f) ifTrue:[
+    filename := packageDir construct:'loadAll'.
+    filename exists ifFalse:[
+        filename := packageDir construct:'loadall'.
+    ].
+    filename exists ifTrue:[
+        (self loadPackage:aPackageId fromLoadAllFile:filename) ifTrue:[
             silent ifFalse:[
-                Transcript showCR:('loaded package: ' , aPackageId , ' from loadAll file: ' , f pathName).
+                Transcript showCR:('loaded package: ' , aPackageId , ' from loadAll file: ' , filename pathName).
             ].
             ^ true
         ]
@@ -6944,5 +6954,5 @@
 !Smalltalk class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Smalltalk.st,v 1.804 2007-01-24 15:39:43 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Smalltalk.st,v 1.805 2007-02-01 17:16:18 stefan Exp $'
 ! !