From e545ebe8c5de5784c78977d8c8a40ff530e31345 Mon Sep 17 00:00:00 2001 From: Joshua Root Date: Thu, 18 Jun 2026 05:39:46 +1000 Subject: [PATCH] Defer loading of some packages --- src/macports1.0/macports.tcl | 29 ++++++++++++++++------------- src/macports1.0/snapshot.tcl | 5 +++-- src/port1.0/portdestroot.tcl | 2 +- src/port1.0/portinstall.tcl | 1 - src/registry2.0/registry.tcl | 1 - src/registry2.0/registry_util.tcl | 2 +- 6 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/macports1.0/macports.tcl b/src/macports1.0/macports.tcl index d2268f312..6a07994eb 100644 --- a/src/macports1.0/macports.tcl +++ b/src/macports1.0/macports.tcl @@ -35,15 +35,7 @@ package provide macports 1.0 package require macports_dlist 1.0 package require macports_util 1.0 -package require mport_fetch_thread -package require diagnose 1.0 -package require reclaim 1.0 -package require selfupdate 1.0 -package require snapshot 1.0 -package require restore 1.0 -package require migrate 1.0 package require Tclx -package require uri # catch wrapper shared with port1.0 package require mpcommon 1.0 @@ -1154,6 +1146,8 @@ proc mportinit {{up_ui_options {}} {up_options {}} {up_variations {}}} { package require registry 1.0 package require registry2 2.0 package require machista 1.0 + package require mport_fetch_thread + package require uri # Set the system encoding to utf-8 encoding system utf-8 @@ -1737,10 +1731,13 @@ match macports.conf.default." # Check that the current platform is the one we were configured for, otherwise need to do migration set skip_migration_check [expr {[info exists macports::global_options(ports_no_migration_check)] && $macports::global_options(ports_no_migration_check)}] - if {!$skip_migration_check && [migrate::needs_migration migrate_reason]} { - ui_error $migrate_reason - ui_error "Please run 'sudo port migrate' or follow the migration instructions: https://trac.macports.org/wiki/Migration" - return -code error "OS platform mismatch" + if {!$skip_migration_check} { + package require migrate 1.0 + if {[migrate::needs_migration migrate_reason]} { + ui_error $migrate_reason + ui_error "Please run 'sudo port migrate' or follow the migration instructions: https://trac.macports.org/wiki/Migration" + return -code error "OS platform mismatch" + } } if {![info exists macosx_deployment_target]} { @@ -5079,6 +5076,7 @@ proc macports::_variants_to_variations {variants} { # selfupdate procedure proc macports::selfupdate {{options {}} {updatestatusvar {}}} { + package require selfupdate 1.0 return [uplevel [list selfupdate::main $options $updatestatusvar]] } @@ -6269,7 +6267,7 @@ proc macports::diagnose_main {opts} { # None # Returns: # 0 on successful execution. - + package require diagnose 1.0 diagnose::main $opts return 0 } @@ -6284,6 +6282,7 @@ proc macports::reclaim_check_and_run {} { return 0 } + package require reclaim 1.0 try { return [reclaim::check_last_run] } trap {POSIX SIG SIGINT} {} { @@ -6311,6 +6310,7 @@ proc macports::snapshot_main {opts} { # Returns: # 0 on successful execution. + package require snapshot 1.0 return [snapshot::main $opts] } @@ -6324,6 +6324,7 @@ proc macports::restore_main {opts} { # Returns: # 0 on successful execution. + package require restore 1.0 return [restore::main $opts] } @@ -6334,6 +6335,7 @@ proc macports::restore_main {opts} { # caller should re-run itself and invoke migration with the --continue # flag set. proc macports::migrate_main {opts} { + package require migrate 1.0 return [migrate::main $opts] } @@ -6345,6 +6347,7 @@ proc macports::reclaim_main {opts} { # Returns: # None + package require reclaim 1.0 try { reclaim::main $opts } trap {POSIX SIG SIGINT} {} { diff --git a/src/macports1.0/snapshot.tcl b/src/macports1.0/snapshot.tcl index 41b83f20e..0790c4a85 100644 --- a/src/macports1.0/snapshot.tcl +++ b/src/macports1.0/snapshot.tcl @@ -32,8 +32,6 @@ package provide snapshot 1.0 package require macports 1.0 package require registry 1.0 -package require json -package require json::write namespace eval snapshot { proc print_usage {} { @@ -259,6 +257,8 @@ namespace eval snapshot { # Returns: # string representation of the snapshot object + package require json::write + # The conversion can take quite a while because we're querying all # files installed by the various ports, so display a progress bar global macports::ui_options @@ -344,6 +344,7 @@ namespace eval snapshot { # Returns: # The imported snapshot as a snapshot object + package require json set data [json::json2dict $contents] try { diff --git a/src/port1.0/portdestroot.tcl b/src/port1.0/portdestroot.tcl index 6bd4baa7a..0537de6af 100644 --- a/src/port1.0/portdestroot.tcl +++ b/src/port1.0/portdestroot.tcl @@ -33,7 +33,6 @@ package provide portdestroot 1.0 package require portutil 1.0 -package require fileutil set org.macports.destroot [target_new org.macports.destroot portdestroot::destroot_main] target_provides ${org.macports.destroot} destroot @@ -225,6 +224,7 @@ proc portdestroot::destroot_finish {args} { } # Prune empty directories in ${destroot} + package require fileutil foreach path ${destroot.keepdirs} { # Prepend $destroot if $path isn't already inside it set path [::fileutil::jail $destroot $path] diff --git a/src/port1.0/portinstall.tcl b/src/port1.0/portinstall.tcl index 14496a7f0..fc5026aef 100644 --- a/src/port1.0/portinstall.tcl +++ b/src/port1.0/portinstall.tcl @@ -33,7 +33,6 @@ package provide portinstall 1.0 package require portutil 1.0 -package require machista 1.0 set org.macports.install [target_new org.macports.install portinstall::install_main] target_provides ${org.macports.install} install diff --git a/src/registry2.0/registry.tcl b/src/registry2.0/registry.tcl index 849b5f18a..16e38e082 100644 --- a/src/registry2.0/registry.tcl +++ b/src/registry2.0/registry.tcl @@ -37,7 +37,6 @@ package require receipt_flat 1.0 package require receipt_sqlite 1.0 package require portimage 2.0 package require registry_uninstall 2.0 -package require msgcat package require Pextlib 1.0 namespace eval registry { diff --git a/src/registry2.0/registry_util.tcl b/src/registry2.0/registry_util.tcl index 6b9d4d7f5..7c7ecaa1b 100644 --- a/src/registry2.0/registry_util.tcl +++ b/src/registry2.0/registry_util.tcl @@ -33,7 +33,6 @@ package provide registry_util 2.0 package require registry2 2.0 -package require tdbc::sqlite3 namespace eval registry { @@ -177,6 +176,7 @@ proc run_target {port target options} { ## Create and configure a tdbc connection to the registry proc tdbc_connect {args} { + package require tdbc::sqlite3 variable tdbc_connection set reg_path [::file join ${::macports::registry.path} registry registry.db] set tdbc_connection [tdbc::sqlite3::connection new $reg_path]