source: trunk/base/src/upgrade_sources_conf_default.tcl.in @ 118562

Last change on this file since 118562 was 118559, checked in by cal@…, 6 years ago

base: remove macports_fastload.tcl, use correct Tcl, install port-tclsh for contrib software, specify LD_LIBRARY_PATH for intree Tcl for Linux, see #43208

macports_fastload.tcl contained two blocks of code: The first one was dead
because it was only used with Tcl < 8.5, the second one sourced the pkgIndex.tcl
files of all MacPorts Tcl packages. That was previously necessary to ensure
package require macports 1.0 would load the code from the correct prefix and
might also have improved performance because $auto_path of /usr/bin/tclsh
contains 10 entries. With our local copy of Tcl, the number of files read is
around 100 at most, so I think that's a non-issue from a performance POV. We
don't need the preloading to select the correct MacPorts prefix, because the
selection of the Tcl interpreter now does that for us correctly.

For this to work correctly, every Tcl file must now be executed with the correct
Tcl interpreter -- that replaces sourcing macports_fastload.tcl from the correct
prefix. Some of our install scripts still used /usr/bin/env tclsh.

This change also solves a potential build problem on Linux in src/pkg_mkindex.sh
because the Tcl library matching the in-tree Tcl interpreter might not be found
without LD_LIBRARY_PATH.

Furthermore, this adds a $prefix/bin/port-tclsh wrapper script that should be
used by contrib tools that need to use the MacPorts API. The shebang line should
be

#!/usr/bin/env port-tclsh

which will cause the contrib script to automatically work on the port
installation currently first in $PATH.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 4.1 KB
Line 
1#!@TCLSH@
2#
3# $Id: upgrade_sources_conf_default.tcl.in 118559 2014-04-04 22:02:44Z cal@macports.org $
4#
5# Upgrade sources.conf for a given prefix (passed as the first and only
6# argument).
7#
8# For an rsync: repository, if it is the standard MacPorts one and not
9# already tagged, then make it default, if another wasn't already default.
10# For a file:// respository, if it is an svn checkout from the MacPorts
11# server, then make it default if another hasn't already been tagged.
12#
13
14if {[llength $::argv] == 0} {
15   puts "Usage: ${::argv0} <prefix>"
16   exit 1
17}
18
19set prefix [lindex $::argv 0]
20set sourcesConf ${prefix}/etc/macports/sources.conf
21if {[catch {set sourcesConfChannel [open $sourcesConf r]}]} {
22   exit 0
23}
24
25if {[file executable /usr/bin/mktemp]} {
26    set mktemp /usr/bin/mktemp
27} elseif {[file executable /bin/mktemp]} {
28    set mktemp /bin/mktemp
29} else {
30    set mktemp mktemp
31}
32
33set mktempChannel [open "|$mktemp -t macports_sources_upgrade.XXXXXXXXXX" r]
34set tempfile [read -nonewline $mktempChannel]
35close $mktempChannel
36
37set tempfileChannel [open $tempfile w]
38set defaultSeen false
39set defaultWritten false
40
41while {[gets $sourcesConfChannel line] >= 0} {
42   set addDefault false
43   if {!$defaultSeen && ![regexp {^\s*#|^$} $line]} {
44      if {[regexp {^([\w-]+://\S+)(?:\s+\[(\w+(?:,\w+)*)\])?$} $line -> url flags]} {
45         set flags [split $flags ,]
46         if {[lsearch $flags default] >= 0} {
47            set defaultSeen true
48         } elseif {[regexp {rsync://rsync\.(macports|darwinports)\.org/(release|dpupdate)/d?ports} $url]} {
49            set addDefault true
50         } elseif {[regexp {file://(/.+)} $url -> filepath]} {
51            if {[file exists [file join ${filepath} .svn]]} {
52               if {![info exists svnCmd]} {
53                  set svnCmd ""
54                  foreach path [concat [list ${prefix}/bin] [split $env(PATH) :]] {
55                     if {[file executable ${path}/svn]} {
56                        set svnCmd ${path}/svn
57                        break
58                     }
59                  }
60               }
61               if {$svnCmd eq ""} {
62                  puts "WARNING: Unable to check svn URL for '$filepath' because no svn command could be found; please manually verify $sourcesConf!"
63                  continue
64               }
65               if {![catch {set svnChannel [open "|$svnCmd info ${filepath}" r]} err]} {
66                  set svnURL {}
67                  while {[gets $svnChannel svnLine] >= 0} {
68                     regexp {^URL: (.*)} $svnLine -> svnURL
69                  }
70                  if {[catch {close $svnChannel} err]} {
71                     puts $err
72                     puts "WARNING: Unable to check svn URL for '$filepath'; please manually verify $sourcesConf!"
73                  }
74                  if {[regexp {^https?://svn\.(macports|macosforge)\.org/repository/macports/trunk/dports} $svnURL]} {
75                     set addDefault true
76                  }
77               } else {
78                  puts $err
79                  puts "WARNING: Unable to check svn URL for '$filepath'; please manually verify $sourcesConf!"
80               }
81            }
82         }
83         if {$addDefault} {
84            lappend flags default
85            set line "$url \[[join $flags ,]\]"
86            set defaultSeen true
87            set defaultWritten true
88         }
89      }
90   }
91   puts $tempfileChannel $line
92}
93close $tempfileChannel
94close $sourcesConfChannel
95
96if {$defaultWritten} {
97   set attributes [file attributes ${sourcesConf}]
98   if {[catch {file rename ${sourcesConf} "${sourcesConf}.mpsaved"}]} {
99      file rename -force ${sourcesConf} "${sourcesConf}.mpsaved_[clock seconds]"
100   }
101   file rename ${tempfile} ${sourcesConf}
102   eval file attributes ${sourcesConf} $attributes
103} else {
104   file delete ${tempfile}
105   if {!$defaultSeen} {
106      puts "[string repeat - 72]
107Warning, your source config file at:
108
109   $sourcesConf
110
111needs to have a \[default\] tag added to the primary MacPorts repository,
112however the proper entry could not be determined.  Please add the tag
113manually by either appending \[default\] to the end of the correct line,
114or if there are already tags, adding it to the list, e.g.
115\[nosync,default\].
116[string repeat - 72]"
117   }
118}
119
120exit 0
121
Note: See TracBrowser for help on using the repository browser.