Skip to content

Commit

Permalink
Install MacPorts under an arbitrary prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
foretspaisibles committed Jun 15, 2024
1 parent 0d551db commit c31a848
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 23 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/continuous-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ jobs:
matrix:
os: ['macos-12', 'macos-13', 'macos-14']
version: ['2.9.3']
prefix: ['/opt/local']
prefix: ['local']
include:
- os: 'macos-14'
version: '2.9.3'
prefix: 'package'
runs-on: '${{ matrix.os }}'
name: 'Install MacPorts'
needs: 'run-testsuite'
Expand All @@ -33,14 +37,15 @@ jobs:
- uses: ./
id: 'macports'
with:
parameters: 'testsuite/run-testsuite-on-${{ matrix.os }}.yaml'
parameters: 'testsuite/run-testsuite-on-${{ matrix.os }}-${{ matrix.prefix }}.yaml'
- name: 'Validate installed MacPorts version'
run: >-
test "$(port version)" = 'Version: ${{ matrix.version }}'
- name: 'Validate transmitted MacPorts prefix'
run: >-
test "${{ steps.macports.outputs.prefix }}" = '${{ matrix.prefix }}'
test "${{ steps.macports.outputs.prefix }}" = '/opt/${{ matrix.prefix }}'
- name: 'Validate transmitted MacPorts version'
run: >-
test "${{ steps.macports.outputs.version }}" = '${{ matrix.version }}'
- run: /opt/${{ matrix.prefix }}/bin/port version
- run: port version
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ The configuration file is in YAML and has the following format:

* `version: '2.9.3'` — The MacPorts version to install.
* `prefix: '/opt/local'` — The installation prefix to install MacPorts to.
Currently the only supported value is '/opt/local'.
The default is `/opt/local` and only needs to be changed when
preparing self-install packages for instane.
* `variants.select: []` — The list of selected variants in the global
variants configuration. See Also variants.conf(5).
* `variants.deselect: []` — The list of deselected variants in the
Expand Down
6 changes: 4 additions & 2 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ runs:
- name: 'Install MacPorts'
if: steps.cache-macports.outputs.cache-hit != 'true'
shell: sh
env:
TOPLEVELDIR: ${{ github.action_path }}
run: |
${{ github.action_path }}/install_macports
env:
TOPLEVELDIR: ${{ github.action_path }}
macports_prefix: ${{ steps.configure-macports.outputs.prefix }}
macports_version: ${{ steps.configure-macports.outputs.version }}
14 changes: 7 additions & 7 deletions configure_macports
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ experimental()

cache_key()
{
openssl ripemd160 "${macports_prefix}/etc/gha-install-macports.yaml"\
openssl ripemd160 "${macports_prefix}/etc/setup-macports.yaml"\
| awk -v "macos=${macos}" '{print(macos "-" $2)}'
}

Expand Down Expand Up @@ -101,8 +101,8 @@ main()
esac

if [ -f "${parameterfile}" -a -r "${parameterfile}" ]; then
version=$(yq ".version // \"${macports_version}\"" < "${parameterfile}")
prefix=$(yq ".prefix // \"${macports_prefix}\"" < "${parameterfile}")
macports_version=$(yq ".version // \"${macports_version}\"" < "${parameterfile}")
macports_prefix=$(yq ".prefix // \"${macports_prefix}\"" < "${parameterfile}")
fi

if [ "${action}" = 'experimental' ]; then
Expand All @@ -112,14 +112,14 @@ main()

setup_path
sudo install -d -o $(id -u -n) -g $(id -g -n) -m 755 "${macports_prefix}"
write_configuration "${parameterfile}" "${macports_prefix}/etc/gha-install-macports.yaml"
write_variants "${macports_prefix}/etc/gha-install-macports.yaml"
write_sources "${macports_prefix}/etc/gha-install-macports.yaml"
write_configuration "${parameterfile}" "${macports_prefix}/etc/setup-macports.yaml"
write_variants "${macports_prefix}/etc/setup-macports.yaml"
write_sources "${macports_prefix}/etc/setup-macports.yaml"

if [ "${GITHUB_ACTIONS}" = 'true' ]; then
{
printf 'prefix=%s\n' "${macports_prefix}"
printf 'parameters=%s\n' "${macports_prefix}/etc/gha-install-macports.yaml"
printf 'parameters=%s\n' "${macports_prefix}/etc/setup-macports.yaml"
printf 'cache-key=%sn\n' "$(cache_key)"
printf 'package=%s\n' "$(make_package)"
printf 'version=%s\n' "${macports_version}"
Expand Down
27 changes: 25 additions & 2 deletions install_macports
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,24 @@ fetch_and_install_package()
sudo chown -R $(id -u -n):$(id -g -n) "${macports_prefix}"
}

install_from_source()
{
local srcdir
srcdir='/opt/local/src'
sudo install -d -o $(id -u -n) -g $(id -g -n) -m 755 "${srcdir}"
(
cd "${srcdir}"
git clone https://github.com/macports/macports-base.git
cd macports-base
git checkout "v${macports_version}"
./configure --enable-readline --prefix="${macports_prefix}"
make
sudo make install
)
sudo rm -Rf "${srcdir}"
sudo port -v selfupdate
}

install_ports()
{
ports_document "$1" | xargs -J '%' sudo port install '%'
Expand Down Expand Up @@ -208,8 +226,13 @@ main()
'Configuration Summary'\
configuration_summary

fetch_and_install_package "$(make_package)"
install_ports "${macports_prefix}/etc/gha-install-macports.yaml"
if [ "${macports_prefix}" = '/opt/local' ]; then
fetch_and_install_package "$(make_package)"
else
install_from_source
fi

install_ports "${macports_prefix}/etc/setup-macports.yaml"
}

main "$@"
Expand Down
8 changes: 4 additions & 4 deletions subr/macports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ YAML
variants_document()
{
if [ "$#" -eq 0 ]; then
set -- "${macports_prefix}/etc/gha-install-macports.yaml"
set -- "${macports_prefix}/etc/setup-macports.yaml"
fi

printf '# MacPorts system-wide global variants configuration file.\n'
Expand All @@ -82,7 +82,7 @@ variants_document()
ports_document()
{
if [ "$#" -eq 0 ]; then
set -- "${macports_prefix}/etc/gha-install-macports.yaml"
set -- "${macports_prefix}/etc/setup-macports.yaml"
fi

yq '
Expand All @@ -100,7 +100,7 @@ ports_document()
sources_document()
{
if [ "$#" -eq 0 ]; then
set -- "${macports_prefix}/etc/gha-install-macports.yaml"
set -- "${macports_prefix}/etc/setup-macports.yaml"
fi

yq '
Expand Down Expand Up @@ -131,7 +131,7 @@ make_package()
case $# in
0)
macos=$(probe_macos)
version=$(yq ".version // \"${macports_version}\"" < "${macports_prefix}/etc/gha-install-macports.yaml")
version=$(yq ".version // \"${macports_version}\"" < "${macports_prefix}/etc/setup-macports.yaml")
;;
1)
macos=$(probe_macos)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions testsuite/run-testsuite-on-macos-14-package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '2.9.3'
prefix: '/opt/package'
variants:
select:
- aqua
- metal
deselect: x11
ports:
- name: db48
deselect: [ java ]
select: [ tcl, universal ]
- name: gmp
select: native
- name: dbus

4 changes: 0 additions & 4 deletions validate_configuration
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ main()
if [ ! -r "$1" ]; then
failwith 'The pathname \047%s\047 does not designate a readable file.' "$1"
fi

if ! [ $(yq '.prefix' "$1") = '/opt/local' ]; then
failwith 'The only supported prefix is \047/opt/local\047.'
fi
}

main "$@"
Expand Down

0 comments on commit c31a848

Please sign in to comment.