Julian Noble
1 year ago
2 changed files with 947 additions and 938 deletions
@ -1,90 +1,96 @@ |
|||||||
package provide app-punk 1.0 |
package provide app-punk 1.0 |
||||||
|
|
||||||
|
|
||||||
#punk linerepl launcher |
#punk linerepl launcher |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#------------------------------------------------------------------------------ |
#------------------------------------------------------------------------------ |
||||||
#Module loading |
#Module loading |
||||||
#------------------------------------------------------------------------------ |
#------------------------------------------------------------------------------ |
||||||
#If the current directory contains .tm files when the punk repl starts - then it will attempt to preference them |
#If the current directory contains .tm files when the punk repl starts - then it will attempt to preference them |
||||||
# - but first add our other known relative modules paths - as it won't make sense to use current directory as a modulpath if it's an ancestor of one of these.. |
# - but first add our other known relative modules paths - as it won't make sense to use current directory as a modulpath if it's an ancestor of one of these.. |
||||||
|
|
||||||
set original_tm_list [tcl::tm::list] |
set original_tm_list [tcl::tm::list] |
||||||
tcl::tm::remove {*}$original_tm_list |
tcl::tm::remove {*}$original_tm_list |
||||||
|
|
||||||
|
|
||||||
#1) |
#1) |
||||||
if {[string match "*.vfs/*" [info script]]} { |
if {[string match "*.vfs/*" [info script]]} { |
||||||
#src/xxx.vfs/lib/app-punk/repl.tcl |
#src/xxx.vfs/lib/app-punk/repl.tcl |
||||||
#we assume if calling directly into .vfs that the user would prefer to use src/modules - so go up 4 levels |
#we assume if calling directly into .vfs that the user would prefer to use src/modules - so go up 4 levels |
||||||
set modulefolder [file dirname [file dirname [file dirname [file dirname [info script]]]]]/modules |
set modulefolder [file dirname [file dirname [file dirname [file dirname [info script]]]]]/modules |
||||||
|
|
||||||
} else { |
} else { |
||||||
# .../bin/punkXX.exe look for ../modules (i.e modules folder at same level as bin folder) |
# .../bin/punkXX.exe look for ../modules (i.e modules folder at same level as bin folder) |
||||||
set modulefolder [file dirname [file dirname [info nameofexecutable]]]/modules |
set modulefolder [file dirname [file dirname [info nameofexecutable]]]/modules |
||||||
} |
} |
||||||
|
|
||||||
if {[file exists $modulefolder]} { |
if {[file exists $modulefolder]} { |
||||||
tcl::tm::add $modulefolder |
tcl::tm::add $modulefolder |
||||||
} else { |
} else { |
||||||
puts stderr "Warning unable to find module folder at: $modulefolder" |
puts stderr "Warning unable to find module folder at: $modulefolder" |
||||||
} |
} |
||||||
if {[file exists [pwd]/modules]} { |
if {[file exists [pwd]/modules]} { |
||||||
catch {tcl::tm::add [pwd]/modules} |
catch {tcl::tm::add [pwd]/modules} |
||||||
} |
} |
||||||
|
if {[file exists [pwd]/lib]} { |
||||||
|
lappend ::auto_path [pwd]/lib |
||||||
#2) |
} |
||||||
#now add current dir (if no conflict with above) |
set libfolder [file dirname [file dirname [info nameofexecutable]]]/lib |
||||||
set currentdir_modules [glob -nocomplain -dir [pwd] -type f -tail *.tm] |
if {[file exists $libfolder]} { |
||||||
set tcl_core_packages [list tcl::zlib zlib tcl::oo TclOO tcl::tommath tcl::zipfs Tcl Tk] |
lappend ::auto_path $libfolder |
||||||
if {[llength $currentdir_modules]} { |
} |
||||||
#only forget all *unloaded* package names if we are started in a .tm containing folder |
|
||||||
foreach pkg [package names] { |
#2) |
||||||
if {$pkg in $tcl_core_packages} { |
#now add current dir (if no conflict with above) |
||||||
continue |
set currentdir_modules [glob -nocomplain -dir [pwd] -type f -tail *.tm] |
||||||
} |
set tcl_core_packages [list tcl::zlib zlib tcl::oo TclOO tcl::tommath tcl::zipfs Tcl Tk] |
||||||
if {![llength [package versions $pkg]]} { |
if {[llength $currentdir_modules]} { |
||||||
#puts stderr "Got no versions for pkg $pkg" |
#only forget all *unloaded* package names if we are started in a .tm containing folder |
||||||
continue |
foreach pkg [package names] { |
||||||
} |
if {$pkg in $tcl_core_packages} { |
||||||
if {![string length [package provide $pkg]]} { |
continue |
||||||
package forget $pkg |
} |
||||||
} |
if {![llength [package versions $pkg]]} { |
||||||
} |
#puts stderr "Got no versions for pkg $pkg" |
||||||
catch {tcl::tm::add [pwd]} |
continue |
||||||
} |
} |
||||||
|
if {![string length [package provide $pkg]]} { |
||||||
|
package forget $pkg |
||||||
|
} |
||||||
package require Thread |
} |
||||||
#These are strong dependencies |
catch {tcl::tm::add [pwd]} |
||||||
# - the repl requires Threading and punk,shellfilter,shellrun to call and display properly. |
} |
||||||
# tm list already indexed - need 'package forget' to find modules based on current tcl::tm::list |
|
||||||
|
|
||||||
package forget shellfilter |
#puts stdout "$::auto_path" |
||||||
package require shellfilter |
package require Thread |
||||||
package forget shellrun |
#These are strong dependencies |
||||||
package require shellrun |
# - the repl requires Threading and punk,shellfilter,shellrun to call and display properly. |
||||||
package forget punk |
# tm list already indexed - need 'package forget' to find modules based on current tcl::tm::list |
||||||
package require punk |
|
||||||
|
package forget shellfilter |
||||||
|
package require shellfilter |
||||||
#restore module paths |
package forget shellrun |
||||||
set tm_list_now [tcl::tm::list] |
package require shellrun |
||||||
foreach p $original_tm_list { |
package forget punk |
||||||
if {$p ni $tm_list_now} { |
package require punk |
||||||
#the prior tm paths go to the head of the list. |
|
||||||
#They are processed first.. but an item of same version later in the list will override one at the head. |
|
||||||
tcl::tm::add $p |
#restore module paths |
||||||
} |
set tm_list_now [tcl::tm::list] |
||||||
} |
foreach p $original_tm_list { |
||||||
#------------------------------------------------------------------------------ |
if {$p ni $tm_list_now} { |
||||||
|
#the prior tm paths go to the head of the list. |
||||||
package require punk::repl |
#They are processed first.. but an item of same version later in the list will override one at the head. |
||||||
repl::start stdin |
tcl::tm::add $p |
||||||
|
} |
||||||
|
} |
||||||
|
#------------------------------------------------------------------------------ |
||||||
|
|
||||||
|
package require punk::repl |
||||||
|
repl::start stdin |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in new issue