From bc1089e900d4287441e5ddeeeb3e71e63c010991 Mon Sep 17 00:00:00 2001 From: Herby Gillot Date: Thu, 12 Mar 2026 23:33:00 -0400 Subject: [PATCH] port: add 'prefix' action to display the configured prefix Adds a new `port prefix` command that prints MacPorts' installation prefix on stdout, unadorned, so it can be used directly in shell scripts. Closes: https://trac.macports.org/ticket/72961 --- doc/Makefile.in | 1 + doc/port-prefix.1 | 48 +++++++++++++++++++++++++++++++++ doc/port-prefix.1.txt | 28 +++++++++++++++++++ doc/port.1 | 5 ++++ doc/port.1.txt | 3 +++ src/port/port.tcl | 8 ++++++ src/port1.0/tests/portmain.test | 12 +++++++++ 7 files changed, 105 insertions(+) create mode 100644 doc/port-prefix.1 create mode 100644 doc/port-prefix.1.txt diff --git a/doc/Makefile.in b/doc/Makefile.in index 653514fcc..aa80f3ceb 100644 --- a/doc/Makefile.in +++ b/doc/Makefile.in @@ -64,6 +64,7 @@ MAN1= \ port-patch.1 \ port-pkg.1 \ port-platform.1 \ + port-prefix.1 \ port-provides.1 \ port-quit.1 \ port-rdependents.1 \ diff --git a/doc/port-prefix.1 b/doc/port-prefix.1 new file mode 100644 index 000000000..e42b72e7f --- /dev/null +++ b/doc/port-prefix.1 @@ -0,0 +1,48 @@ +'\" t +.TH "PORT\-PREFIX" "1" "2\&.12\&.99" "MacPorts 2\&.12\&.99" "MacPorts Manual" +.\" ----------------------------------------------------------------- +.\" * Define some portability stuff +.\" ----------------------------------------------------------------- +.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +.\" http://bugs.debian.org/507673 +.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html +.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +.ie \n(.g .ds Aq \(aq +.el .ds Aq ' +.\" ----------------------------------------------------------------- +.\" * set default formatting +.\" ----------------------------------------------------------------- +.\" disable hyphenation +.nh +.\" disable justification (adjust text to left margin only) +.ad l +.\" ----------------------------------------------------------------- +.\" * MAIN CONTENT STARTS HERE * +.\" ----------------------------------------------------------------- +.SH "NAME" +port-prefix \- Print the prefix for which MacPorts was configured +.SH "SYNOPSIS" +.sp +.nf +\fBport\fR \fBprefix\fR +.fi +.SH "DESCRIPTION" +.sp +This command prints the installation prefix of your MacPorts installation, i\&.e\&., the directory under which MacPorts and all ports are installed\&. The prefix is set at configure time and defaults to \fI/opt/local\fR\&. +.SH "GLOBAL OPTIONS" +.sp +Please see the section \fBGLOBAL OPTIONS\fR in the \fBport\fR(1) man page for a description of global port options\&. +.SH "SEE ALSO" +.sp +\fBport\fR(1) +.SH "AUTHORS" +.sp +.if n \{\ +.RS 4 +.\} +.nf +(C) 2026 The MacPorts Project +.fi +.if n \{\ +.RE +.\} diff --git a/doc/port-prefix.1.txt b/doc/port-prefix.1.txt new file mode 100644 index 000000000..ac16bb616 --- /dev/null +++ b/doc/port-prefix.1.txt @@ -0,0 +1,28 @@ +// vim: set et sw=4 ts=8 ft=asciidoc tw=80: +port-prefix(1) +============== + +NAME +---- +port-prefix - Print the prefix for which MacPorts was configured + +SYNOPSIS +-------- +[cmdsynopsis] +*port* *prefix* + +DESCRIPTION +----------- +This command prints the installation prefix of your MacPorts installation, i.e., +the directory under which MacPorts and all ports are installed. The prefix is +set at configure time and defaults to '/opt/local'. + +include::global-flags.txt[] + +SEE ALSO +-------- +man:port[1] + +AUTHORS +------- + (C) 2026 The MacPorts Project diff --git a/doc/port.1 b/doc/port.1 index 7f35fd1f5..183d3c3ab 100644 --- a/doc/port.1 +++ b/doc/port.1 @@ -1077,6 +1077,11 @@ version Display the release number of the installed MacPorts infrastructure\&. .RE .PP +prefix +.RS 4 +Display the prefix for which MacPorts was configured\&. +.RE +.PP selfupdate .RS 4 Updates the MacPorts system, ports tree(s) and base tools if needed, from the MacPorts rsync server, installing the newest infrastructure available\&. diff --git a/doc/port.1.txt b/doc/port.1.txt index 4346c7197..34cc45232 100644 --- a/doc/port.1.txt +++ b/doc/port.1.txt @@ -539,6 +539,9 @@ mirror:: version:: Display the release number of the installed MacPorts infrastructure. +prefix:: + Display the prefix for which MacPorts was configured. + selfupdate:: Updates the MacPorts system, ports tree(s) and base tools if needed, from the MacPorts rsync server, installing the newest infrastructure available. diff --git a/src/port/port.tcl b/src/port/port.tcl index fe01db369..3389c67b9 100755 --- a/src/port/port.tcl +++ b/src/port/port.tcl @@ -2680,6 +2680,13 @@ proc action_platform { action portlist opts } { } +proc action_prefix { action portlist opts } { + global macports::prefix + puts ${prefix} + return 0 +} + + proc action_dependents { action portlist opts } { if {[require_portlist portlist]} { return 1 @@ -4152,6 +4159,7 @@ set action_array [dict create \ \ version [list action_version [ACTION_ARGS_NONE]] \ platform [list action_platform [ACTION_ARGS_NONE]] \ + prefix [list action_prefix [ACTION_ARGS_NONE]] \ \ uninstall [list action_uninstall [ACTION_ARGS_PORTS]] \ \ diff --git a/src/port1.0/tests/portmain.test b/src/port1.0/tests/portmain.test index 50a7e5334..9264ae48c 100644 --- a/src/port1.0/tests/portmain.test +++ b/src/port1.0/tests/portmain.test @@ -35,6 +35,10 @@ set portpath . set portbuildpath ./build set macports::portdbpath . +set test_tclsh [file normalize [file join $macports::autoconf::top_srcdir tests test-tclsh]] +set port_script [file normalize [file join $pwd .. .. port port.tcl]] +testConstraint portClientAvailable [expr {[file executable $test_tclsh] && [file readable $port_script]}] + test get_default_subport { Get default subport unit test. @@ -59,5 +63,13 @@ test get_subbuildpath { return "Get subbuild path successful." } -result "Get subbuild path successful." +test action_prefix { + `port prefix` prints the configured prefix and nothing else. +} -constraints { + portClientAvailable +} -body { + exec -ignorestderr $test_tclsh $port_script prefix +} -result $pwd/tmpdir + cleanupTests