gtk-osx-setup.sh 8.81 KB
Newer Older
1
2
#!/usr/bin/env bash
 ####################################################################
3
 # gtk-osx-setup.sh: gtk-osx setup with python virtual environments.#
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
 #                                                                  #
 # Copyright 2018 John Ralls <jralls@ceridwen.us>                   #
 #                                                                  #
 # This program is free software; you can redistribute it and/or    #
 # modify it under the terms of the GNU General Public License as   #
 # published by the Free Software Foundation; either version 2 of   #
 # the License, or (at your option) any later version.              #
 #                                                                  #
 # This program is distributed in the hope that it will be useful,  #
 # but WITHOUT ANY WARRANTY; without even the implied warranty of   #
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    #
 # GNU General Public License for more details.                     #
 #                                                                  #
 # You should have received a copy of the GNU General Public License#
 # along with this program; if not, contact:                        #
 #                                                                  #
 # Free Software Foundation           Voice:  +1-617-542-5942       #
 # 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       #
 # Boston, MA  02110-1301,  USA       gnu@gnu.org                   #
 ####################################################################

# Function envvardir. Tests environment variable, sets default value if unset,
# and creates the specified directory if it doesn't already exist. This
# will barf if the name indicates a file that isn't a directory.
envvar ()
{
    local _varname=$1
31
32
33
34
    eval local _var=\$$_varname
    if test -z "$_var"; then
        eval export $_varname="$2"
        _var=$2
35
    fi
36
37
    if test ! -d "$_var"; then
        mkdir -p "$_var"
38
39
    fi
}
40
41
42
43
44
45
46
47
48
49
50

pip_remove()
{
    local _package=$1
    local _local_package=`$PIP show $_package | grep Location | grep $PYTHONUSERBASE`
    if test -n "$_local_package"; then
        echo $_local_package
        $PIP uninstall -y $_package
    fi
}

51
52
# Environment variable defaults:
#
53
54
55
56
envvar DEVROOT "$HOME"
envvar DEVPREFIX "$DEVROOT/.new_local"
envvar PYTHONUSERBASE "$DEVROOT/.new_local"
envvar DEV_SRC_ROOT "$DEVROOT/Source"
57
58
envvar PYENV_INSTALL_ROOT "$DEV_SRC_ROOT/pyenv"
envvar PYENV_ROOT "$DEVPREFIX/share/pyenv"
59
envvar PIP_CONFIG_DIR "$HOME/.config/pip"
John Ralls's avatar
John Ralls committed
60
envvar PYTHON_VERSION 3.10.2
61

62
export PYTHONWARNINGS=ignore:DEPRECATION::pip._internal.cli.base_command
63

64
65
if test ! -d "$DEVPREFIX/bin" ; then
    mkdir -p "$DEVPREFIX/bin"
66
67
68
69
70
71
fi

GITLAB="https://gitlab.gnome.org/GNOME"
GITHUB="https://github.com"

# We need to have a local copy of bash when compiling to prevent SIP problems.
72
73
if test ! -x "$DEVPREFIX/bin/bash"; then
    cp /bin/bash "$DEVPREFIX/bin"
74
75
76
fi

# Setup pyenv
77
78
79
if test ! -x "$PYENV_INSTALL_ROOT/libexec/pyenv"; then
  if test -d "$PYENV_INSTALL_ROOT"; then
     rm -rf "$PYENV_INSTALL_ROOT";
80
  fi
81
82
83
  git clone $GITHUB/pyenv/pyenv.git "$PYENV_INSTALL_ROOT"
else
    pushd "$PYENV_INSTALL_ROOT"
84
    git pull --ff-only
85
    popd
86
87
fi

John Ralls's avatar
John Ralls committed
88
89
90
PYENV="$DEVPREFIX/bin/pyenv"

if test ! -x "$PYENV" ; then
91
    ln -s "$PYENV_INSTALL_ROOT/bin/pyenv" "$DEVPREFIX/bin"
92
93
fi

John Ralls's avatar
John Ralls committed
94
95
96
97
#Force installation and we hope use of Python with PyEnv. We must
#avoid using the Apple-provided Python2 because jhbuild doesn't work
#with python2 any more, and the Apple-provided python3 because it
#doesn't include a usable libpython for libxml2 to link against.
John Ralls's avatar
John Ralls committed
98

John Ralls's avatar
John Ralls committed
99
export PYTHON_CONFIGURE_OPTS="--enable-shared"
100
101
102
103
#This really means pyenv's *python* version. It's poorly named but
#it's defined by pyenv so it can't be changed.
export PYENV_VERSION=$PYTHON_VERSION
$PYENV install -v $PYENV_VERSION
John Ralls's avatar
John Ralls committed
104
105
PIP="$PYENV_ROOT/shims/pip3"

John Ralls's avatar
John Ralls committed
106
$PIP install --upgrade --user pip
107
108

# Install pipenv
John Ralls's avatar
John Ralls committed
109
$PIP install --upgrade --user pipenv==2020.11.15
110
PIPENV="$PYTHONUSERBASE/bin/pipenv"
111
export WORKON_HOME=$DEVPREFIX/share/virtualenvs
112

John Ralls's avatar
John Ralls committed
113
JHBUILD_RELEASE_VERSION=3.38.0
114
# Install jhbuild
115
if test ! -d "$DEV_SRC_ROOT/jhbuild/.git" ; then
116
    git clone -b $JHBUILD_RELEASE_VERSION $GITLAB/jhbuild.git "$DEV_SRC_ROOT/jhbuild"
117
    cd "$DEV_SRC_ROOT/jhbuild"
118
else #Get the latest if it's already installed
119
    cd "$DEV_SRC_ROOT/jhbuild"
120
    git pull
121
    git reset --hard $JHBUILD_RELEASE_VERSION
122
123
124
125
fi

# Install Ninja
NINJA=`which ninja`
126
if test ! -x "$NINJA" -a ! -x "$DEVPREFIX/bin/ninja"; then
Jiří Techet's avatar
Jiří Techet committed
127
    curl -kLs https://github.com/ninja-build/ninja/releases/download/v1.10.2/ninja-mac.zip -o "$DEVPREFIX/ninja-mac.zip"
128
129
    unzip -d "$DEVPREFIX/bin" "$DEVPREFIX/ninja-mac.zip"
    rm "$DEVPREFIX/ninja-mac.zip"
130
131
fi

132
133
#Install Rust (required for librsvg, which gtk needs to render its icons.)
RUSTUP=`which rustup`
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
if test -x "$RUSTUP"; then
    case `dirname "$RUSTUP"` in
        "$DEVPREFIX"*)
            DEFAULT_CARGO_HOME=$(dirname $(dirname "$RUSTUP"))
            envvar CARGO_HOME "$DEFAULT_CARGO_HOME"
            CARGO_HOME_DIR=$(basename "$CARGO_HOME")
            if test "$CARGO_HOME_DIR" == "cargo"; then
                CARGO_HOME_BASE=$(dirname "$CARGO_HOME")
                envvar RUSTUP_HOME "$CARGO_HOME_BASE"/rustup
            else
                envvar RUSTUP_HOME "$CARGO_HOME"
            fi
            ;;
        *)
            envvar CARGO_HOME "$HOME/.cargo"
            envvar RUSTUP_HOME "$HOME/.rustup"
            ;;
    esac
else
    envvar CARGO_HOME "$DEVPREFIX"
    envvar RUSTUP_HOME "$DEVPREFIX"
John Ralls's avatar
John Ralls committed
155
    curl https://sh.rustup.rs -sSf | sh -s -- -y --profile minimal --no-modify-path 
156
157
fi

158
159
if test ! -d "$DEVPREFIX/etc" ; then
    mkdir -p "$DEVPREFIX/etc"
160
fi
161

162
PYENV_MINOR_VERSION=$(echo $PYENV_VERSION | cut -d . -f 1,2)
163
cat  <<EOF > "$DEVPREFIX/etc/Pipfile"
164
165
166
167
168
[[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true

[packages]
169
170
pygments = "*"
meson = {version=">=0.56.0"}
171
172
docutils = "*"
gi-docgen = "*"
173
174
175
176
177

[scripts]
jhbuild = "$DEVPREFIX/libexec/run_jhbuild.py"

[requires]
John Ralls's avatar
John Ralls committed
178
python_version = "$PYENV_MINOR_VERSION"
179
EOF
180
cat <<EOF > "$DEVPREFIX/etc/pipenv-env"
181
182
183
184
export PYTHONUSERBASE="$PYTHONUSERBASE"
export DEV_SRC_ROOT="$DEV_SRC_ROOT"
export PYENV_ROOT="$PYENV_ROOT"
export PIP_CONFIG_DIR="$PIP_CONFIG_DIR"
185
186
export LANG=C
EOF
187
188

cat <<EOF > "$DEVPREFIX/bin/jhbuild"
189
#!$DEVPREFIX/bin/bash
190
191
export DEVROOT="$DEVROOT"
export DEVPREFIX="$DEVPREFIX"
192
export PYTHONUSERBASE="$PYTHONUSERBASE"
193
export PIPENV_DOTENV_LOCATION="$DEVPREFIX/etc/pipenv-env"
194
export PIPENV_PIPFILE="$DEVPREFIX/etc/Pipfile"
195
export PYENV_ROOT="$PYENV_ROOT"
196
export PYENV_VERSION="$PYENV_VERSION"
197
export PATH="$PYENV_ROOT/shims:\$PATH"
198
export CARGO_HOME="$CARGO_HOME"
199
export RUSTUP_HOME="$RUSTUP_HOME"
200
export WORKON_HOME="$WORKON_HOME"
201

202
exec $DEVPREFIX/bin/pipenv run jhbuild \$@
203
EOF
204

205
206
if test ! -d "$DEVPREFIX/libexec" ; then
    mkdir -p "$DEVPREFIX/libexec"
207
fi
208
cat <<EOF > "$DEVPREFIX/libexec/run_jhbuild.py"
209
#!/usr/bin/env python3
210
211
212
213
# -*- coding: utf-8 -*-

import sys
import os
214
import builtins
215
216
217
218
219
sys.path.insert(0, '$DEV_SRC_ROOT/jhbuild')
pkgdatadir = None
datadir = None
import jhbuild
srcdir = os.path.abspath(os.path.join(os.path.dirname(jhbuild.__file__), '..'))
220
221
222
builtins.__dict__['PKGDATADIR'] = pkgdatadir
builtins.__dict__['DATADIR'] = datadir
builtins.__dict__['SRCDIR'] = srcdir
223
224
225
226
227

import jhbuild.main
jhbuild.main.main(sys.argv[1:])

EOF
228

229
230
if test ! -x "$DEVPREFIX/bin/jhbuild" ; then
    chmod +x "$DEVPREFIX/bin/jhbuild"
231
fi
232
233
if test ! -x "$DEVPREFIX/libexec/run_jhbuild.py" ; then
    chmod +x "$DEVPREFIX/libexec/run_jhbuild.py"
234
fi
235
if test "x`echo $PATH | grep "$DEVPREFIX/bin"`" == x ; then
236
    echo "PATH does not contain $DEVPREFIX/bin. You probably want to fix that."
John Ralls's avatar
John Ralls committed
237
    export PATH="$DEVPREFIX/bin:$PATH"
238
239
fi

240
241
SDKROOT=`xcrun --show-sdk-path`

242
243
export PIPENV_DOTENV_LOCATION="$DEVPREFIX/etc/pipenv-env"
export PIPENV_PIPFILE="$DEVPREFIX/etc/Pipfile"
244
export PATH="$PYENV_ROOT/shims:$DEVPREFIX/bin:$PYENV_INSTALL_ROOT/plugins/python-build/bin:$PATH"
245

John Ralls's avatar
John Ralls committed
246
if test -d "$SDKROOT"; then
John Ralls's avatar
John Ralls committed
247
248
    export CFLAGS="-isysroot $SDKROOT -I$SDKROOT/usr/include"
fi
249

250
$PIPENV install
251

252
BASEURL="https://gitlab.gnome.org/GNOME/gtk-osx/raw/master"
253

254
config_dir=""
255
256
257
258
259
260
261
262
263
if test -n "$XDG_CONFIG_HOME"; then
   config_dir="$XDG_CONFIG_HOME"
else
   config_dir="$HOME/.config"
fi
if test ! -d "$config_dir"; then
    mkdir -p "$config_dir"
fi

264
265
if test -e "$HOME/.jhbuildrc"; then
    JHBUILDRC="$HOME/.jhbuildrc"
266
else
267
    JHBUILDRC="$config_dir/jhbuildrc"
268
fi
269
270
echo "Installing jhbuild configuration at $JHBUILDRC"
curl -ks $BASEURL/jhbuildrc-gtk-osx -o "$JHBUILDRC"
271

272
if test -z "$JHBUILDRC_CUSTOM"; then
John Ralls's avatar
John Ralls committed
273
274
    JHBUILDRC_CUSTOM="$config_dir/jhbuildrc-custom"
fi
275
if test ! -e "$JHBUILDRC_CUSTOM" -a ! -e "$HOME/.jhbuildrc-custom"; then
276
    JHBUILDRC_CUSTOM_DIR=`dirname $JHBUILDRC_CUSTOM`
277
278
279
    echo "Installing jhbuild custom configuration at $JHBUILDRC_CUSTOM"
    if test ! -d "$JHBUILDRC_CUSTOM_DIR"; then
        mkdir -p "$JHBUILDRC_CUSTOM_DIR"
280
    fi
281
    curl -ks $BASEURL/jhbuildrc-gtk-osx-custom-example -o "$JHBUILDRC_CUSTOM"
282
fi