| 1671 | proc action_select { action portlist opts } { |
| 1672 | if {[llength $portlist] < 2} { |
| 1673 | ui_error "port select <module> <action> <options>" |
| 1674 | return 1 |
| 1675 | } |
| 1676 | set module [lindex $portlist 0] |
| 1677 | set action [lindex $portlist 1] |
| 1678 | |
| 1679 | # By default the $confpath is $prefix/etc/select/$module. |
| 1680 | set confpath "$macports::prefix/etc/select/$module" |
| 1681 | if {![file isdirectory $confpath]} { |
| 1682 | ui_error "The specified module $module does not exist." |
| 1683 | return 1 |
| 1684 | } |
| 1685 | |
| 1686 | # Currently the only two valid actions are list and set. |
| 1687 | switch -- $action { |
| 1688 | list { |
| 1689 | if {[catch {set versions [glob -directory $confpath *]}]} { |
| 1690 | ui_error "No versions were found for $module" |
| 1691 | return 1 |
| 1692 | } |
| 1693 | |
| 1694 | puts "Available Versions:" |
| 1695 | foreach version [lsort $versions] { |
| 1696 | set version [file tail $version] |
| 1697 | # Ignore base. |
| 1698 | if {$version ne "base"} { |
| 1699 | puts "\t$version" |
| 1700 | } |
| 1701 | } |
| 1702 | } |
| 1703 | set { |
| 1704 | # The set action expects a third argument: the version. |
| 1705 | if {[llength $portlist] != 3} { |
| 1706 | ui_error "Specify a version (e.g., port select $module set <version>)" |
| 1707 | return 1; |
| 1708 | } |
| 1709 | set version [lindex $portlist 2] |
| 1710 | |
| 1711 | if {[catch {set versions [glob -directory $confpath *]}]} { |
| 1712 | ui_error "No versions were found for $module" |
| 1713 | return 1 |
| 1714 | } |
| 1715 | |
| 1716 | # Make sure the specified version is valid. |
| 1717 | foreach v $versions { |
| 1718 | set v [file tail $v] |
| 1719 | |
| 1720 | if {$v ne "base" && $v eq $version} { |
| 1721 | puts "Selecting version $version for $module" |
| 1722 | |
| 1723 | # Use $confpath/$version to read in sources. |
| 1724 | if {[catch {set src_file [open [file join $confpath $version]]}]} { |
| 1725 | ui_error "Could not open $confpath/$version" |
| 1726 | return 1 |
| 1727 | } |
| 1728 | set srcs [split [read -nonewline $src_file] "\n"] |
| 1729 | close $src_file |
| 1730 | |
| 1731 | # Use $confpath/base to read in targets. |
| 1732 | if {[catch {set tgt_file [open [file join $confpath "base"]]}]} { |
| 1733 | ui_error "Could not open $confpath/base" |
| 1734 | return 1 |
| 1735 | } |
| 1736 | set tgts [split [read -nonewline $tgt_file] "\n"] |
| 1737 | close $tgt_file |
| 1738 | |
| 1739 | set i 0 |
| 1740 | foreach tgt $tgts { |
| 1741 | set src [lindex $srcs $i] |
| 1742 | |
| 1743 | switch -glob -- $src { |
| 1744 | - { |
| 1745 | # The source is unavailable for this file. |
| 1746 | set tgt [file join $macports::prefix $tgt] |
| 1747 | file delete $tgt |
| 1748 | ui_debug "rm -f $tgt" |
| 1749 | } |
| 1750 | /* { |
| 1751 | # The source is an absolute path. |
| 1752 | set tgt [file join $macports::prefix $tgt] |
| 1753 | file delete $tgt |
| 1754 | file link -symbolic $tgt $src |
| 1755 | ui_debug "ln -sf $src $tgt" |
| 1756 | } |
| 1757 | default { |
| 1758 | # The source is a relative path. |
| 1759 | set src [file join $macports::prefix $src] |
| 1760 | set tgt [file join $macports::prefix $tgt] |
| 1761 | file delete $tgt |
| 1762 | file link -symbolic $tgt $src |
| 1763 | ui_debug "ln -sf $src $tgt" |
| 1764 | } |
| 1765 | } |
| 1766 | set i [expr $i+1] |
| 1767 | } |
| 1768 | return 0 |
| 1769 | } |
| 1770 | } |
| 1771 | ui_error "The specified version $version is invalid" |
| 1772 | return 1 |
| 1773 | } |
| 1774 | default { |
| 1775 | ui_error "The specified action $action does not exist" |
| 1776 | return 1 |
| 1777 | } |
| 1778 | } |
| 1779 | return 0 |
| 1780 | } |