Move `VDBStartup` from `jv:vdb/application` to `jv:vdb`
authorJan Vrany <jan.vrany@fit.cvut.cz>
Sun, 23 Sep 2018 07:03:34 +0100
changeset 107 d98c11f9a7f5
parent 106 2a95c11eb590
child 108 277fadaec466
Move `VDBStartup` from `jv:vdb/application` to `jv:vdb` This is required in order to simplify Visual / VM Debugger startup and packaging when using Smalltalk/X jv-branch toy archive.
Make.spec
README.md
VDBStartup.st
application/Make.spec
application/VDBStartup.st
application/jv_vdb_application.st
application/libInit.cc
jv_vdb.st
libInit.cc
--- a/Make.spec	Sat Sep 22 01:01:34 2018 +0100
+++ b/Make.spec	Sun Sep 23 07:03:34 2018 +0100
@@ -91,6 +91,7 @@
 	VDBInstructionListApplication \
 	VDBStackApplication \
 	VDBVariableObjectListApplication \
+	VDBStartup \
 
 
 
@@ -136,6 +137,7 @@
     $(OUTDIR)VDBInstructionListApplication.$(O) \
     $(OUTDIR)VDBStackApplication.$(O) \
     $(OUTDIR)VDBVariableObjectListApplication.$(O) \
+    $(OUTDIR)VDBStartup.$(O) \
     $(OUTDIR)extensions.$(O) \
 
 
--- a/README.md	Sat Sep 22 01:01:34 2018 +0100
+++ b/README.md	Sun Sep 23 07:03:34 2018 +0100
@@ -26,14 +26,16 @@
 Smalltalk/X jv-branch][6] and then run either:
 
 ```
-./build/stx/projects/smalltalk/smalltalk --load jv:vdb/application --run VDBStartup
+./build/stx/projects/smalltalk/smalltalk --load jv:vdb --run VDBStartup
 ```
 
 Or evaluate following in a workspace: 
 
 ```
-Smalltalk loadPackage: 'jv:vdb/application'.
-VDBStartup main: #().
+Smalltalk loadPackage: 'jv:vdb'.
+VDBStartup main.
+"or"
+VDBStartup main: #('--help')
 ```
 
 ## Pre-built binaries
@@ -42,14 +44,16 @@
 and run run:
 
 ```
-stx --load jv:vdb/application --run VDBStartup
+stx --load jv:vdb --run VDBStartup
 ```
 
 Or evaluate following in a workspace: 
 
 ```
-Smalltalk loadPackage: 'jv:vdb/application'.
-VDBStartup main: #().
+Smalltalk loadPackage: 'jv:vdb'.
+VDBStartup main.
+"or"
+VDBStartup main: #('--help')
 ```
 
 ## Reporting issues
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/VDBStartup.st	Sun Sep 23 07:03:34 2018 +0100
@@ -0,0 +1,257 @@
+"
+jv:vdb - Visual / VM Debugger
+Copyright (C) 2015-now Jan Vrany
+
+This software is licensed under 'Creative Commons Attribution-NonCommercial 4.0 International License'
+
+You may find a full license text in LICENSE.txt or at http://creativecommons.org/licenses/by-nc/4.0/
+"
+"{ Package: 'jv:vdb/application' }"
+
+"{ NameSpace: Smalltalk }"
+
+StandaloneStartup subclass:#VDBStartup
+	instanceVariableNames:''
+	classVariableNames:''
+	poolDictionaries:''
+	category:'VDB-UI'
+!
+
+!VDBStartup class methodsFor:'documentation'!
+
+copyright
+"
+jv:vdb - Visual / VM Debugger
+Copyright (C) 2015-now Jan Vrany
+
+This software is licensed under 'Creative Commons Attribution-NonCommercial 4.0 International License'
+
+You may find a full license text in LICENSE.txt or at http://creativecommons.org/licenses/by-nc/4.0/
+"
+! !
+
+!VDBStartup class methodsFor:'constants & defaults'!
+
+applicationRegistryPath
+    "the key under which this application stores its process ID in the registry
+     as a collection of path-components.
+     i.e. if #('foo' 'bar' 'baz') is returned here, the current applications ID will be stored
+     in HKEY_CURRENT_USER\Software\foo\bar\baz\CurrentID.
+     (would also be used as a relative path for a temporary lock file under unix).
+     Used to detect if another instance of this application is already running."
+
+    ^ #('vdb')
+
+    "Modified: / 21-09-2014 / 01:29:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+applicationUUID
+    "answer an application-specific unique uuid.
+     This is used as the name of some exclusive OS-resource, which is used to find out,
+     if another instance of this application is already running.
+     Under win32, a mutex is used; under unix, an exclusive file in the tempDir could be used.
+     If redefined, please return a real UUID (i.e. UUID fromString:'.....') and not a string or
+     similar possibly conflicting identifier.
+     You can paste a fresh worldwide unique id via the editor's more-misc-paste UUID menuFunction."
+
+    ^ UUID fromString:'57b09330-4126-11e4-a80f-606720e43e2c'
+
+    "Modified: / 21-09-2014 / 01:29:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!VDBStartup class methodsFor:'defaults'!
+
+allowDebugOption
+    "enable/disable the --debug startup option.
+     Can be redefined in subclasses to enable it"
+
+    ^ true
+
+    "Created: / 08-09-2014 / 19:30:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!VDBStartup class methodsFor:'private'!
+
+loadPreferenceFile: file
+
+    "Created: / 07-06-2017 / 09:49:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!VDBStartup class methodsFor:'queries'!
+
+applicationName
+    ^ 'vdb'
+
+    "Created: / 06-06-2017 / 22:50:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!VDBStartup class methodsFor:'startup'!
+
+main:argv
+    "Application entry point. `argv` is the array of command arguments (as Array of Strings)"
+
+    | optparser positional settingsFile settingsSuppressed replay 
+      programExecutable programArgs programPid attach 
+      debugger debuggerApp |
+
+    settingsSuppressed := false.
+    replay := false.
+    attach := false.
+
+    "/ Parse options...
+    optparser := CmdLineParser new
+                    ignoreUnknownOptions: true;
+                    on: #('--help') do:[
+                        self usage
+                    ];
+                    on: #('--preferences') do:[:filename |
+                        | file |
+
+                        file := filename asFilename.
+                        file isReadable ifFalse:[
+                            self error: 'preference file does not exists or not readable: ' , filename.
+                        ].
+                        file isRegularFile ifFalse:[
+                            self error: 'preference file is not a regular file: ' , filename.
+                        ].
+                        settingsFile := file.
+                    ];
+                    on: #('--no-preferences') do:[
+                        settingsSuppressed := true
+                    ];
+                    on: #('--replay') do:[
+                        replay := true
+                    ];
+                    yourself.
+    [
+        positional := optparser parse:argv.
+    ] on: CmdLineOptionError do:[:ex |
+        self error: ex description.
+    ].
+
+
+    "/ Now validate and process options
+    settingsSuppressed ifFalse:[
+        | settings |
+
+        settingsFile notNil ifTrue:[
+            settingsFile exists ifFalse:[
+                self error: 'preference file does not exist: ', settingsFile pathName
+            ].
+            settingsFile isDirectory ifTrue:[
+                self error: 'preference file is not a regular file: ', settingsFile pathName
+            ].
+            settingsFile isReadable ifFalse:[
+                self error: 'preference file is not a readable (check permissions): ', settingsFile pathName
+            ].
+            settings := UserPreferences loadSettingsFrom: settingsFile.
+        ] ifFalse:[
+            settings := UserPreferences loadSettings.
+        ].
+        UserPreferences setCurrent: settings.
+    ].
+
+    replay ifTrue:[ 
+        OperatingSystem isLinuxLike ifFalse:[ 
+            self error: 'replay not supported on this platform'.
+        ].
+        RR available ifFalse:[ 
+            self error: 'cannot replay because rr not available'
+        ].
+    ].
+
+    "/ Parse positional arguments - there are two forms:
+    "/
+    "/   vdb [OPTIONS] [PROGRAM [ARGS]]
+    "/   vdb [OPTIONS] [PID]
+    "/
+    "/ [OPTIONS] have already been processed, the rest is in `positional`
+    "/ variable
+
+    positional notEmpty ifTrue:[
+        programExecutable := positional first.
+        programExecutable asFilename exists ifFalse:[
+            "Try to find the executable in PATH..."
+
+            | path |
+
+            path := OperatingSystem pathOfCommand: programExecutable.
+            path notNil ifTrue:[
+                programExecutable := path.
+            ].
+        ].
+        programPid := Integer fromString: positional first onError: [ nil ].
+        programArgs := positional copyFrom: 2.
+
+        replay ifTrue:[ 
+            programArgs notEmptyOrNil ifTrue:[ 
+                self error: 'cannot specify program args when replaying'.
+            ].
+        ] ifFalse:[
+            "/ If * programExecutable does not exists
+            "/    * AND programPid is not nil (i.e., first positional argument can be converted to an integer)
+            "/    * AND programArguments are empty
+            "/ then interpret positional argument as PID and attach to it.
+            "/ Otherwise, interpret positional arguments
+            (programExecutable asFilename exists not and: [ programPid notNil and: [ programArgs isEmpty ]]) ifTrue:[
+                attach := true.
+            ] ifFalse:[
+                programExecutable asFilename exists ifFalse:[
+                    self error: 'cannot find program executable: ', programExecutable.
+                ].
+            ].
+        ].
+    ].
+
+    Debugger := DebugView ? MiniDebugger.
+    Inspector := InspectorView ? MiniInspector.
+
+    debugger := GDBDebugger new.
+    attach ifTrue:[
+        debugger attach: programPid
+    ] ifFalse:[
+        programExecutable notNil ifTrue:[
+            debugger executable: programExecutable arguments: programArgs.
+        ].
+    ].
+    Smalltalk openDisplay.
+    debuggerApp := VDBDebuggerApplication new.
+    debuggerApp debugger: debugger.
+    debuggerApp open.
+    replay ifTrue:[ 
+        debuggerApp doAttachToRR
+    ]. 
+
+    "
+        VDBStartup main: #()
+        VDBStartup main: #('ls')
+        VDBStartup main: #('/bin/ls' '/tmp')
+    "
+
+    "Modified: / 29-07-2018 / 08:51:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+usage
+    Stdout nextPutAll:'usage: '; nextPutAll: self applicationName; nextPutAll: ' [OPTIONS] [PROGRAM [ARGS]] '; cr.
+    Stdout nextPutAll:'       '; nextPutAll: self applicationName; nextPutAll: ' [OPTIONS] [PID]'; cr.
+                                                                          "|"
+    Stdout nextPutLine:'
+options:
+ --replay ..................... replay last rr record
+ --preference FILE ............ read user settings from FILE
+ --no-preferences ............. do not read user settings at all
+ --help ....................... output this message
+'.
+
+    Smalltalk exitIfStandalone: 0.
+
+    "Modified: / 29-07-2018 / 08:55:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!VDBStartup class methodsFor:'documentation'!
+
+version_HG
+
+    ^ '$Changeset: <not expanded> $'
+! !
+
--- a/application/Make.spec	Sat Sep 22 01:01:34 2018 +0100
+++ b/application/Make.spec	Sun Sep 23 07:03:34 2018 +0100
@@ -51,14 +51,12 @@
 STCWARNINGS=-warnNonStandard
 
 COMMON_CLASSES= \
-	VDBStartup \
 	jv_vdb_application \
 
 
 
 
 COMMON_OBJS= \
-    $(OUTDIR)VDBStartup.$(O) \
     $(OUTDIR)jv_vdb_application.$(O) \
 
 
--- a/application/VDBStartup.st	Sat Sep 22 01:01:34 2018 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,257 +0,0 @@
-"
-jv:vdb - Visual / VM Debugger
-Copyright (C) 2015-now Jan Vrany
-
-This software is licensed under 'Creative Commons Attribution-NonCommercial 4.0 International License'
-
-You may find a full license text in LICENSE.txt or at http://creativecommons.org/licenses/by-nc/4.0/
-"
-"{ Package: 'jv:vdb/application' }"
-
-"{ NameSpace: Smalltalk }"
-
-StandaloneStartup subclass:#VDBStartup
-	instanceVariableNames:''
-	classVariableNames:''
-	poolDictionaries:''
-	category:'VDB-UI'
-!
-
-!VDBStartup class methodsFor:'documentation'!
-
-copyright
-"
-jv:vdb - Visual / VM Debugger
-Copyright (C) 2015-now Jan Vrany
-
-This software is licensed under 'Creative Commons Attribution-NonCommercial 4.0 International License'
-
-You may find a full license text in LICENSE.txt or at http://creativecommons.org/licenses/by-nc/4.0/
-"
-! !
-
-!VDBStartup class methodsFor:'constants & defaults'!
-
-applicationRegistryPath
-    "the key under which this application stores its process ID in the registry
-     as a collection of path-components.
-     i.e. if #('foo' 'bar' 'baz') is returned here, the current applications ID will be stored
-     in HKEY_CURRENT_USER\Software\foo\bar\baz\CurrentID.
-     (would also be used as a relative path for a temporary lock file under unix).
-     Used to detect if another instance of this application is already running."
-
-    ^ #('vdb')
-
-    "Modified: / 21-09-2014 / 01:29:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-applicationUUID
-    "answer an application-specific unique uuid.
-     This is used as the name of some exclusive OS-resource, which is used to find out,
-     if another instance of this application is already running.
-     Under win32, a mutex is used; under unix, an exclusive file in the tempDir could be used.
-     If redefined, please return a real UUID (i.e. UUID fromString:'.....') and not a string or
-     similar possibly conflicting identifier.
-     You can paste a fresh worldwide unique id via the editor's more-misc-paste UUID menuFunction."
-
-    ^ UUID fromString:'57b09330-4126-11e4-a80f-606720e43e2c'
-
-    "Modified: / 21-09-2014 / 01:29:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
-!VDBStartup class methodsFor:'defaults'!
-
-allowDebugOption
-    "enable/disable the --debug startup option.
-     Can be redefined in subclasses to enable it"
-
-    ^ true
-
-    "Created: / 08-09-2014 / 19:30:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
-!VDBStartup class methodsFor:'private'!
-
-loadPreferenceFile: file
-
-    "Created: / 07-06-2017 / 09:49:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
-!VDBStartup class methodsFor:'queries'!
-
-applicationName
-    ^ 'vdb'
-
-    "Created: / 06-06-2017 / 22:50:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
-!VDBStartup class methodsFor:'startup'!
-
-main:argv
-    "Application entry point. `argv` is the array of command arguments (as Array of Strings)"
-
-    | optparser positional settingsFile settingsSuppressed replay 
-      programExecutable programArgs programPid attach 
-      debugger debuggerApp |
-
-    settingsSuppressed := false.
-    replay := false.
-    attach := false.
-
-    "/ Parse options...
-    optparser := CmdLineParser new
-                    ignoreUnknownOptions: true;
-                    on: #('--help') do:[
-                        self usage
-                    ];
-                    on: #('--preferences') do:[:filename |
-                        | file |
-
-                        file := filename asFilename.
-                        file isReadable ifFalse:[
-                            self error: 'preference file does not exists or not readable: ' , filename.
-                        ].
-                        file isRegularFile ifFalse:[
-                            self error: 'preference file is not a regular file: ' , filename.
-                        ].
-                        settingsFile := file.
-                    ];
-                    on: #('--no-preferences') do:[
-                        settingsSuppressed := true
-                    ];
-                    on: #('--replay') do:[
-                        replay := true
-                    ];
-                    yourself.
-    [
-        positional := optparser parse:argv.
-    ] on: CmdLineOptionError do:[:ex |
-        self error: ex description.
-    ].
-
-
-    "/ Now validate and process options
-    settingsSuppressed ifFalse:[
-        | settings |
-
-        settingsFile notNil ifTrue:[
-            settingsFile exists ifFalse:[
-                self error: 'preference file does not exist: ', settingsFile pathName
-            ].
-            settingsFile isDirectory ifTrue:[
-                self error: 'preference file is not a regular file: ', settingsFile pathName
-            ].
-            settingsFile isReadable ifFalse:[
-                self error: 'preference file is not a readable (check permissions): ', settingsFile pathName
-            ].
-            settings := UserPreferences loadSettingsFrom: settingsFile.
-        ] ifFalse:[
-            settings := UserPreferences loadSettings.
-        ].
-        UserPreferences setCurrent: settings.
-    ].
-
-    replay ifTrue:[ 
-        OperatingSystem isLinuxLike ifFalse:[ 
-            self error: 'replay not supported on this platform'.
-        ].
-        RR available ifFalse:[ 
-            self error: 'cannot replay because rr not available'
-        ].
-    ].
-
-    "/ Parse positional arguments - there are two forms:
-    "/
-    "/   vdb [OPTIONS] [PROGRAM [ARGS]]
-    "/   vdb [OPTIONS] [PID]
-    "/
-    "/ [OPTIONS] have already been processed, the rest is in `positional`
-    "/ variable
-
-    positional notEmpty ifTrue:[
-        programExecutable := positional first.
-        programExecutable asFilename exists ifFalse:[
-            "Try to find the executable in PATH..."
-
-            | path |
-
-            path := OperatingSystem pathOfCommand: programExecutable.
-            path notNil ifTrue:[
-                programExecutable := path.
-            ].
-        ].
-        programPid := Integer fromString: positional first onError: [ nil ].
-        programArgs := positional copyFrom: 2.
-
-        replay ifTrue:[ 
-            programArgs notEmptyOrNil ifTrue:[ 
-                self error: 'cannot specify program args when replaying'.
-            ].
-        ] ifFalse:[
-            "/ If * programExecutable does not exists
-            "/    * AND programPid is not nil (i.e., first positional argument can be converted to an integer)
-            "/    * AND programArguments are empty
-            "/ then interpret positional argument as PID and attach to it.
-            "/ Otherwise, interpret positional arguments
-            (programExecutable asFilename exists not and: [ programPid notNil and: [ programArgs isEmpty ]]) ifTrue:[
-                attach := true.
-            ] ifFalse:[
-                programExecutable asFilename exists ifFalse:[
-                    self error: 'cannot find program executable: ', programExecutable.
-                ].
-            ].
-        ].
-    ].
-
-    Debugger := DebugView ? MiniDebugger.
-    Inspector := InspectorView ? MiniInspector.
-
-    debugger := GDBDebugger new.
-    attach ifTrue:[
-        debugger attach: programPid
-    ] ifFalse:[
-        programExecutable notNil ifTrue:[
-            debugger executable: programExecutable arguments: programArgs.
-        ].
-    ].
-    Smalltalk openDisplay.
-    debuggerApp := VDBDebuggerApplication new.
-    debuggerApp debugger: debugger.
-    debuggerApp open.
-    replay ifTrue:[ 
-        debuggerApp doAttachToRR
-    ]. 
-
-    "
-        VDBStartup main: #()
-        VDBStartup main: #('ls')
-        VDBStartup main: #('/bin/ls' '/tmp')
-    "
-
-    "Modified: / 29-07-2018 / 08:51:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-usage
-    Stdout nextPutAll:'usage: '; nextPutAll: self applicationName; nextPutAll: ' [OPTIONS] [PROGRAM [ARGS][ '; cr.
-    Stdout nextPutAll:'       '; nextPutAll: self applicationName; nextPutAll: ' [OPTIONS] [PID]'; cr.
-                                                                          "|"
-    Stdout nextPutLine:'
-options:
- --replay ..................... replay last rr record
- --preference FILE ............ read user settings from FILE
- --no-preferences ............. do not read user settings at all
- --help ....................... output this message
-'.
-
-    Smalltalk exitIfStandalone: 0.
-
-    "Modified: / 29-07-2018 / 08:55:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
-!VDBStartup class methodsFor:'documentation'!
-
-version_HG
-
-    ^ '$Changeset: <not expanded> $'
-! !
-
--- a/application/jv_vdb_application.st	Sat Sep 22 01:01:34 2018 +0100
+++ b/application/jv_vdb_application.st	Sun Sep 23 07:03:34 2018 +0100
@@ -122,7 +122,6 @@
 
     ^ #(
         "<className> or (<className> attributes...) in load order"
-        VDBStartup
         #'jv_vdb_application'
     )
 !
--- a/application/libInit.cc	Sat Sep 22 01:01:34 2018 +0100
+++ b/application/libInit.cc	Sun Sep 23 07:03:34 2018 +0100
@@ -27,7 +27,6 @@
 void _libjv_vdb_application_Init(pass, __pRT__, snd)
 OBJ snd; struct __vmData__ *__pRT__; {
 __BEGIN_PACKAGE2__("libjv_vdb_application", _libjv_vdb_application_Init, "jv:vdb/application");
-_VDBStartup_Init(pass,__pRT__,snd);
 _jv_137vdb_137application_Init(pass,__pRT__,snd);
 
 
--- a/jv_vdb.st	Sat Sep 22 01:01:34 2018 +0100
+++ b/jv_vdb.st	Sun Sep 23 07:03:34 2018 +0100
@@ -140,6 +140,7 @@
         VDBInstructionListApplication
         VDBStackApplication
         VDBVariableObjectListApplication
+	VDBStartup
     )
 !
 
--- a/libInit.cc	Sat Sep 22 01:01:34 2018 +0100
+++ b/libInit.cc	Sun Sep 23 07:03:34 2018 +0100
@@ -56,6 +56,7 @@
 extern void _VDBInstructionListApplication_Init(int pass, struct __vmData__ *__pRT__, OBJ snd);
 extern void _VDBStackApplication_Init(int pass, struct __vmData__ *__pRT__, OBJ snd);
 extern void _VDBVariableObjectListApplication_Init(int pass, struct __vmData__ *__pRT__, OBJ snd);
+extern void _VDBStartup_Init(int pass, struct __vmData__ *__pRT__, OBJ snd);
 
 extern void _jv_137vdb_extensions_Init(int pass, struct __vmData__ *__pRT__, OBJ snd);
 
@@ -110,6 +111,7 @@
     _VDBInstructionListApplication_Init(pass,__pRT__,snd);
     _VDBStackApplication_Init(pass,__pRT__,snd);
     _VDBVariableObjectListApplication_Init(pass,__pRT__,snd);
+    _VDBStartup_Init(pass,__pRT__,snd);
 
     _jv_137vdb_extensions_Init(pass,__pRT__,snd);
   __END_PACKAGE__();