File: dist_build.sh

package info (click to toggle)
plover 5.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,356 kB
  • sloc: python: 21,589; sh: 682; ansic: 25; makefile: 11
file content (159 lines) | stat: -rwxr-xr-x 3,612 bytes parent folder | download
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
#!/bin/bash

set -e

. ./plover_build_utils/functions.sh

opt_incremental=0
opt_installer=0
opt_trim=0
opt_zipdir=0
args=()

while [ $# -ne 0 ]
do
  case "$1" in
    --incremental)
      opt_incremental=1
      ;;
    -i|--installer)
      opt_installer=1
      ;;
    -t|--trim)
      opt_trim=1
      ;;
    -z|--zipdir)
      opt_zipdir=1
      ;;
    -*)
      die 1 "invalid option \`$1\`"
      ;;
    *)
      args+=("$1")
      ;;
  esac
  shift
done

[ ${#args[@]} -eq 3 ] || die 1 "expected 3 arguments, got ${#args[@]}: ${args[*]}"

name="${args[0]}" version="${args[1]}" wheel="${args[2]}"
builddir="build/windist"
distdir="dist/$name-$version-win64"
distzip="$distdir.zip"
installer="$distdir.setup.exe"
python='python'

. ./windows/dist_deps.sh

py_base_ver="${py_version%.*}"
py_base_ver="${py_base_ver//.}"

build_dist()
{(
  # Fetch official python distribution.
  py_zip="$(run "$python" -m plover_build_utils.download "https://www.python.org/ftp/python/$py_version/python-$py_version-amd64.zip" "$py_sha1")" || die
  
  # Setup Python distribution.
  dist_data="$builddir/data"
  run mkdir -p "$dist_data"
  run unzip -d "$dist_data" "$py_zip"

  # Switch to the distribution Python.
  dist_python=("$dist_data/python.exe")

  kernel="$(uname -s)" || die
  if [ "$kernel" = "Linux" ]
  then
    dist_python=(wine "$dist_python")
  fi
  run_eval "dist_python(){ env PYTHONNOUSERSITE=1 "${dist_python[@]}" \"\$@\"; }"
  python='dist_python'

  # Install Plover and dependencies.
  bootstrap_dist "$wheel" --no-warn-script-location

  # Trim the fat...
  if [ $opt_trim -eq 1 ]
  then
    run "$python" -m plover_build_utils.trim "$dist_data" 'windows/dist_blacklist.txt'
  fi

  # Add miscellaneous files: icon, license, ...
  run cp LICENSE.txt "$builddir/"
  run cp plover/assets/plover.ico "$dist_data/"

  # Create launchers.
  run_eval "$python <<EOF
from pip._vendor.distlib.scripts import ScriptMaker
sm = ScriptMaker(source_dir=r'$builddir', target_dir=r'$builddir')
sm.executable = r'data\\python.exe'
sm.variants = set(('',))
sm.make('plover = plover.scripts.dist_main:main', options={'gui': True})
sm.make('plover_console = plover.scripts.dist_main:main', options={'gui': False})
EOF"

  # Fix Visual C++ Redistributable DLL location.
  run mv {"$dist_data","$builddir"}/vcruntime140.dll

  # Make distribution source-less.
  # Keep pip sources, as we need them for pip install
  run "$python" -m plover_build_utils.source_less "$dist_data" "*/site-packages/pip/*"

  # Check requirements.
  run "$python" -I -m plover_build_utils.check_requirements

  run mv "$builddir" "$distdir"
)}

zip_dist()
{
  run "$python" -m plover_build_utils.zipdir "$distdir"
}

build_installer()
{
  # Compute installed size.
  install_size="$($python - "$distdir" <<EOF
import os, sys
size = sum(os.path.getsize(os.path.join(dirpath, f))
           for dirpath, dirnames, filenames
           in os.walk(sys.argv[1]) for f in filenames)
print((size + 1023) // 1024)
EOF
)" || die
  # Create installer.
  run makensis -NOCD \
    -Dsrcdir="$distdir" \
    -Dversion="$version" \
    -Dinstall_size="$install_size" \
    windows/installer.nsi \
    "-XOutFile $installer"
}

artifacts=("$builddir" "$distdir")
if [ $opt_zipdir -eq 1 ]
then
  artifacts+=("$distzip")
fi
if [ $opt_installer -eq 1 ]
then
  artifacts+=("$installer")
fi
if [ $opt_incremental -eq 0 -o ! -e "$distdir" ]
then
  run rm -rf "${artifacts[@]}"
fi

if [ ! -e "$distdir" ]
then
  build_dist
fi
if [ $opt_zipdir -eq 1 -a ! -e "$distzip" ]
then
  zip_dist
fi
if [ $opt_installer -eq 1 -a ! -e "$installer" ]
then
  build_installer
fi