File: macports-ci

package info (click to toggle)
python-license-expression 30.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,588 kB
  • sloc: python: 6,130; sh: 315; makefile: 51
file content (304 lines) | stat: -rw-r--r-- 8,365 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
#! /bin/bash

# Copyright (c) 2019 Giovanni Bussi

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

export COLUMNS=80

if [ "$GITHUB_ACTIONS" = true ] ; then
    echo "COLUMNS=$COLUMNS" >> "$GITHUB_ENV"
fi

# file to be source at the end of subshell:
export MACPORTS_CI_SOURCEME="$(mktemp)"

(
# start subshell
# this allows to use the script in two ways:
# 1. as ./macports-ci
# 2. as source ./macports-ci
# as of now, choice 2 only changes the env var COLUMNS.

MACPORTS_VERSION=2.6.4
MACPORTS_PREFIX=/opt/local
MACPORTS_SYNC=tarball

action=$1
shift

case "$action" in
(install)

echo "macports-ci: install"

KEEP_BREW=yes

for opt
do
  case "$opt" in
  (--source) SOURCE=yes ;;
  (--binary) SOURCE=no ;;
  (--keep-brew) KEEP_BREW=yes ;;
  (--remove-brew) KEEP_BREW=no ;;
  (--version=*) MACPORTS_VERSION="${opt#--version=}" ;;
  (--prefix=*)  MACPORTS_PREFIX="${opt#--prefix=}" ;;
  (--sync=*)    MACPORTS_SYNC="${opt#--sync=}" ;;
  (*) echo "macports-ci: unknown option $opt"
      exit 1 ;;
  esac
done

if test "$KEEP_BREW" = no ; then
  echo "macports-ci: removing homebrew"
  pushd "$(mktemp -d)"
  curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall > uninstall
  chmod +x uninstall
  ./uninstall --force
  popd
else
  echo "macports-ci: keeping HomeBrew"
fi

echo "macports-ci: prefix=$MACPORTS_PREFIX"

if test "$MACPORTS_PREFIX" != /opt/local ; then
  echo "macports-ci: Installing on non standard prefix $MACPORTS_PREFIX can be only made from sources"
  SOURCE=yes
fi

if test "$SOURCE" = yes ; then
  echo "macports-ci: Installing from source"
else
  echo "macports-ci: Installing from binary"
fi

echo "macports-ci: Sync mode=$MACPORTS_SYNC"

pushd "$(mktemp -d)"

OSX_VERSION="$(sw_vers -productVersion | grep -o '^[0-9][0-9]*\.[0-9][0-9]*')"

if test "$OSX_VERSION" == 10.10 ; then
  OSX_NAME=Yosemite
elif test "$OSX_VERSION" == 10.11 ; then
  OSX_NAME=ElCapitan
elif test "$OSX_VERSION" == 10.12 ; then
  OSX_NAME=Sierra
elif test "$OSX_VERSION" == 10.13 ; then
  OSX_NAME=HighSierra
elif test "$OSX_VERSION" == 10.14 ; then
  OSX_NAME=Mojave
elif test "$OSX_VERSION" == 10.15 ; then
  OSX_NAME=Catalina
else
  echo "macports-ci: Unknown OSX version $OSX_VERSION"
  exit 1
fi

echo "macports-ci: OSX version $OSX_VERSION $OSX_NAME"

MACPORTS_PKG=MacPorts-${MACPORTS_VERSION}-${OSX_VERSION}-${OSX_NAME}.pkg

# this is a workaround needed because binary installer MacPorts-2.6.3-10.12-Sierra.pkg is broken
if [ "$SOURCE" != yes ] && [ "$MACPORTS_PKG" = "MacPorts-2.6.3-10.12-Sierra.pkg" ] ; then
  echo "macports-ci: WARNING $MACPORTS_PKG installer is broken"
  echo "macports-ci: reverting to 2.6.2 installer followed by selfupdate"
  MACPORTS_VERSION=2.6.2
  MACPORTS_PKG=MacPorts-${MACPORTS_VERSION}-${OSX_VERSION}-${OSX_NAME}.pkg
fi

URL="https://distfiles.macports.org/MacPorts"
URL="https://github.com/macports/macports-base/releases/download/v$MACPORTS_VERSION/"

echo "macports-ci: Base URL is $URL"

if test "$SOURCE" = yes ; then
# download source:
  curl -LO $URL/MacPorts-${MACPORTS_VERSION}.tar.bz2
  tar xjf MacPorts-${MACPORTS_VERSION}.tar.bz2
  cd MacPorts-${MACPORTS_VERSION}
# install
  ./configure --prefix="$MACPORTS_PREFIX" --with-applications-dir="$MACPORTS_PREFIX/Applications" >/dev/null &&
    sudo make install >/dev/null
else

# download installer:
  curl -LO $URL/$MACPORTS_PKG
# install:
  sudo installer -verbose -pkg $MACPORTS_PKG -target /
fi

# update:
export PATH="$MACPORTS_PREFIX/bin:$PATH"

echo "PATH=\"$MACPORTS_PREFIX/bin:\$PATH\""  > "$MACPORTS_CI_SOURCEME"

if [ "$GITHUB_ACTIONS" = true ] ; then
    echo "$MACPORTS_PREFIX/bin" >> "$GITHUB_PATH"
fi


SOURCES="${MACPORTS_PREFIX}"/etc/macports/sources.conf

case "$MACPORTS_SYNC" in
(rsync)
  echo "macports-ci: Using rsync"
  ;;
(github)
  echo "macports-ci: Using github"
   pushd "$MACPORTS_PREFIX"/var/macports/sources
   sudo mkdir -p github.com/macports/macports-ports/
   sudo chown -R $USER:admin github.com
   git clone https://github.com/macports/macports-ports.git github.com/macports/macports-ports/
   awk '{if($NF=="[default]") print "file:///opt/local/var/macports/sources/github.com/macports/macports-ports/"; else print}' "$SOURCES" > $HOME/$$.tmp
   sudo mv -f $HOME/$$.tmp "$SOURCES"
   popd
  ;;
(tarball)
  echo "macports-ci: Using tarball"
  awk '{if($NF=="[default]") print "https://distfiles.macports.org/ports.tar.gz [default]"; else print}' "$SOURCES" > $$.tmp
  sudo mv -f $$.tmp "$SOURCES"
  ;;
(*)
  echo "macports-ci: Unknown sync mode $MACPORTS_SYNC"
  ;;
esac

i=1
# run through a while to retry upon failure
while true
do
  echo "macports-ci: Trying to selfupdate (iteration $i)"
# here I test for the presence of a known portfile
# this check confirms that ports were installed
# notice that port -N selfupdate && break is not sufficient as a test
# (sometime it returns a success even though ports have not been installed)
# for some misterious reasons, running without "-d" does not work in some case
  sudo port -d -N selfupdate 2>&1 | grep -v DEBUG | awk '{if($1!="x")print}'
  port info xdrfile > /dev/null && break || true
  sleep 5
  i=$((i+1))
  if ((i>20)) ; then
    echo "macports-ci: Failed after $i iterations"
    exit 1
  fi
done

echo "macports-ci: Selfupdate successful after $i iterations"

dir="$PWD"
popd
sudo rm -fr $dir

;;

(localports)

echo "macports-ci: localports"

for opt
do
  case "$opt" in
  (*) ports="$opt" ;;
  esac
done

if ! test -d "$ports" ; then
  echo "macports-ci: Please provide a port directory"
  exit 1
fi

w=$(which port)

MACPORTS_PREFIX="${w%/bin/port}"

cd "$ports"

ports="$(pwd)"

echo "macports-ci: Portdir fullpath: $ports"
SOURCES="${MACPORTS_PREFIX}"/etc/macports/sources.conf

awk -v repo="file://$ports" '{if($NF=="[default]") print repo; print}' "$SOURCES" > $$.tmp
sudo mv -f $$.tmp "$SOURCES"

portindex

;;

(ccache)
w=$(which port)
MACPORTS_PREFIX="${w%/bin/port}"

echo "macports-ci: ccache"

ccache_do=install

for opt
do
  case "$opt" in
  (--save) ccache_do=save ;;
  (--install) ccache_do=install ;;
  (*) echo "macports-ci: ccache: unknown option $opt"
      exit 1 ;;
  esac
done


case "$ccache_do" in
(install)
# first install ccache
sudo port -N install ccache
# then tell macports to use it
CONF="${MACPORTS_PREFIX}"/etc/macports/macports.conf
awk '{if(match($0,"configureccache")) print "configureccache yes" ; else print }' "$CONF" > $$.tmp
sudo mv -f $$.tmp "$CONF"

# notice that cache size is set to 512Mb, same as it is set by Travis-CI on linux
# might be changed in the future
test -f "$HOME"/.macports-ci-ccache/ccache.conf &&
  sudo rm -fr "$MACPORTS_PREFIX"/var/macports/build/.ccache &&
  sudo mkdir -p "$MACPORTS_PREFIX"/var/macports/build/.ccache &&
  sudo cp -a "$HOME"/.macports-ci-ccache/* "$MACPORTS_PREFIX"/var/macports/build/.ccache/ &&
  sudo echo "max_size = 512M" > "$MACPORTS_PREFIX"/var/macports/build/.ccache/ccache.conf &&
  sudo chown -R macports:admin "$MACPORTS_PREFIX"/var/macports/build/.ccache

;;
(save)

sudo rm -fr "$HOME"/.macports-ci-ccache
sudo mkdir -p "$HOME"/.macports-ci-ccache
sudo cp -a "$MACPORTS_PREFIX"/var/macports/build/.ccache/* "$HOME"/.macports-ci-ccache/

esac

CCACHE_DIR="$MACPORTS_PREFIX"/var/macports/build/.ccache/ ccache -s

;;

(*)
echo "macports-ci: unknown action $action"

esac

)

# allows setting env var if necessary:
source "$MACPORTS_CI_SOURCEME"