summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 1b4a760d7253fda744a6f9552a929410f43d3344 (plain)
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
# Maintainer: WithTheBraid <info@braid.business>
# Co-Maintainer: Polarian <polarian@polarian.dev>, Fredy GarcĂ­a <frealgagu at gmail dot com>
# Contributor: Philip Goto <philip.goto@gmail.com>

pkgbase=flutter
_group=flutter
groups=("$_group")
pkgver=3.22.2
_dartver=(3.4.0 3.5.0)
_enginever=edd8546116457bdf1c5bdfb13ecb9463d2bb5ed4
_materialfontsver=3012db47f3130e62f7cc0beabff968a33cbec8d8
_gradlewver=fd5c1f2c013565a3bea56ada6df9d2b8e96d56aa
_flutterarch=$(echo "$CARCH" | sed s/aarch64/arm64/ | sed s/x86_64/x64/)
pkgrel=1
pkgdesc="A new mobile app SDK to help developers and designers build modern mobile apps for iOS and Android."
_pkgdesc="Flutter SDK component"
arch=("x86_64" "aarch64")
url="https://${_group}.dev"
license=("custom" "BSD" "CCPL")
makedepends=(
	"dart>=${_dartver[0]}"
	"dart<${_dartver[1]}"
	"jq"
	"gradle"
	"unzip"
)
options=("!emptydirs")
source=(
  "${_group}-${pkgver}.tar.xz::https://github.com/${_group}/${_group}/archive/refs/tags/${pkgver/.hotfix/+hotfix}.tar.gz"

  "system-dart.patch"
  "gradle-user-home.patch"

  # thanks to lauren n. liberda from Alpine for the awesome patchset used here !
  "${_group}.sh"
  "version.patch"
  "no-lock.patch"
  "no-runtime-download.patch"
  "doctor.patch"
  "opt-in-analytics.patch"
)

sha256sums=('0ab56f96aeb2f075e819aafdf16de94d297fa8a251239171be29cdf7a1ee306a'
            'f0fb98748a911a546fb8211e4ff4b9ed5c8d4631042445e9829caa67b0380aaf'
            'ae41d1ee4b6819bf9747a7ff1c02cf98ca554e88f9c0d78dd9aeaf9865cc5eb1'
            'b4c104129eb57e7e3edca2e23376b8b034de2d466189bdc1c3e2a304506889a3'
            '688a7d6a3c220cf09f7e48af46f1ef1b01d251679962c825eded0b3fa4fc2ab1'
            '544d08716332a9f9358b21010d468b84a9edff0da7bbb1baf0cf4d6322821ea5'
            'a5f19e68e9e4790d017dc4988e715f51c44548df5615aae6106d1a0c84fe49f1'
            '04531ee1732c18c933b5b28f5da88ed183d5aa3698b1d1e912c000928b93ec91'
            '1578e819b6ee479b6db7a095bcfa74372d3ff555642c6d6ea7112e97bb6f2027')

prepare() {
  # this is required in case people try to build with `aur/dart-sdk-dev` instead of `extra/dart`
  DART_BINARY=$(readlink $(which dart))
  DART_ROOT=${DART_ROOT:-${DART_BINARY/\/bin\/dart/}}

  if [ "${DART_ROOT}" != "/opt/dart-sdk" ]; then
    echo -e "\n\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n"

    echo -e "  WARNING !!!\n"

    echo -e "  Your default Dart SDK does not seem to be installed into\n"
    echo -e "    /opt/dart-sdk\n"
    echo -e "  Please consider using the original 'extra/dart' package"
    echo -e "  from the Arch Linux package repositories. We otherwise"
    echo -e "  cannot ensure the Flutter tool will work as expected.\n\n"
    echo -e "  Dart executable:	$(which dart)"
    echo -e "  Resolved Dart SDK:	${DART_ROOT}"

    echo -e "\n\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n"
  fi

  if [[ ! "$DART_ROOT" =~ ^\/opt\/ && ! "$DART_ROOT" =~ ^\/usr\/ ]]; then
    echo "FATAL: DART_ROOT is neither in /opt nor /usr. You must use a system wide Dart installation for this package. Exiting."
    exit 1
  fi

  if [ -d "${srcdir}/${_group}" ]; then
    rm -rf "${srcdir}/${_group}"
  fi

  mv "${srcdir}/${_group}-${pkgver/.hotfix/+hotfix}" "${srcdir}/${_group}"
  patch -p1 -i "${srcdir}/system-dart.patch" -d "${srcdir}/${_group}"
  patch -p1 -i "${srcdir}/gradle-user-home.patch" -d "${srcdir}/${_group}"
  patch -p1 -i "${srcdir}/version.patch" -d "${srcdir}/${_group}"
  patch -p1 -i "${srcdir}/no-lock.patch" -d "${srcdir}/${_group}"
  patch -p1 -i "${srcdir}/no-runtime-download.patch" -d "${srcdir}/${_group}"
  patch -p1 -i "${srcdir}/doctor.patch" -d "${srcdir}/${_group}"
  patch -p1 -i "${srcdir}/opt-in-analytics.patch" -d "${srcdir}/${_group}"

  echo "${pkgver}" > "${srcdir}/${_group}/version"
  mkdir -p "${srcdir}/${_group}/bin/cache/artifacts"
  cat > "${srcdir}/${_group}/bin/cache/flutter.version.json" <<EOF
{
	"frameworkVersion": "$pkgver",
	"channel": "$_channel",
	"repositoryUrl": "https://github.com/flutter/flutter.git",
	"frameworkRevision": "archlinuxaur0000000000000000000000000000",
	"frameworkCommitDate": "2038-01-19 03:14:08",
	"engineRevision": "$(cat "${srcdir}/${_group}/bin/internal/engine.version")",
	"dartSdkVersion": "$(dart --version | awk '{print $4}')",
	"devToolsVersion": $(jq '.version' < ${DART_ROOT}/bin/resources/devtools/version.json),
	"flutterVersion": "$pkgver"
}
EOF

  if [ -d "${srcdir}/gradlew" ]; then
    rm -rf "${srcdir}/gradlew"
  fi

  mkdir "${srcdir}/gradlew"
  pushd ${srcdir}/gradlew
  gradle init --type basic --project-name flutter --dsl kotlin --incubating
  gradle wrapper
  popd

  cd "${srcdir}/${_group}/bin/cache/artifacts"

  # why should we use a pre-build gradle wrapper if we have it in the arch repos ?
  mkdir -p gradle_wrapper/gradle
  cp -pr "${srcdir}/gradlew/gradle/wrapper" gradle_wrapper/gradle
  cp -pr "${srcdir}/gradlew/gradlew" gradle_wrapper
}

build() {
  export PUB_CACHE="${srcdir}/${_group}/pub-cache"
  cd "${srcdir}/${_group}"
  dart pub get -C "packages/flutter_tools" --no-offline --no-precompile
  dart --verbosity=error --disable-dart-dev \
		--snapshot="bin/cache/flutter_tools.snapshot" --snapshot-kind="app-jit" \
		--packages="packages/flutter_tools/.dart_tool/package_config.json" \
		--no-enable-mirrors "packages/flutter_tools/bin/flutter_tools.dart" --version
 cd ../..

  sed -Ei 's|'"$PUB_CACHE"'|/usr/lib/flutter/pub-cache|g' "${srcdir}/${_group}/packages/flutter_tools/.dart_tool/package_config.json"
  find "$PUB_CACHE" -name '*.aot' -delete
}

_package() {
  pkgdesc="${_pkgdesc} - full installation of development tool and runtime"
  depends=("${pkgbase}-devel=${pkgver}" "${pkgbase}-target-linux=${pkgver}" "${pkgbase}-target-android=${pkgver}" "${pkgbase}-target-web=${pkgver}" "${pkgbase}-intellij-patch=${pkgver}")
  conflicts=("${pkgbase}")
}

_package-common() {
  pkgdesc="${_pkgdesc} - common SDK files and pub cache"
  install="${_group}-common.install"
  conflicts=(
        "${_group}<${pkgver}"
        "${_group}-engine-common<${pkgver}"
        "${_group}-intellij-patch<${pkgver}"
        "${_group}-gradle<${pkgver}"
        "${_group}-engine-android<${pkgver}"
        "${_group}-engine-linux<${pkgver}"
        "${_group}-engine-web<${pkgver}"
        "${_group}-tool<${pkgver}"
        "${_group}-devel<${pkgver}"
  )

  install -Dm644 "${srcdir}/${_group}/LICENSE" "${pkgdir}/usr/share/licenses/${_group}/LICENSE"

  install -dm755 "${pkgdir}/usr/lib/${_group}"
  install -dm755 "${pkgdir}/usr/lib/${_group}/packages/flutter"
  install -dm755 "${pkgdir}/usr/lib/${_group}/packages/flutter_driver"
  install -dm755 "${pkgdir}/usr/lib/${_group}/packages/flutter_goldens"
  install -dm755 "${pkgdir}/usr/lib/${_group}/packages/flutter_localizations"
  install -dm755 "${pkgdir}/usr/lib/${_group}/packages/flutter_test"
  install -dm755 "${pkgdir}/usr/lib/${_group}/packages/flutter_web_plugins"
  install -dm755 "${pkgdir}/usr/lib/${_group}/packages/fuchsia_remote_debug_protocol"
  install -dm755 "${pkgdir}/usr/lib/${_group}/packages/integration_test"

  cp -ra "${srcdir}/${_group}/packages/flutter/"{pubspec.yaml,lib} "${pkgdir}/usr/lib/${_group}/packages/flutter"
  cp -ra "${srcdir}/${_group}/packages/flutter_driver/"{pubspec.yaml,lib} "${pkgdir}/usr/lib/${_group}/packages/flutter_driver"
  cp -ra "${srcdir}/${_group}/packages/flutter_goldens/"{pubspec.yaml,lib} "${pkgdir}/usr/lib/${_group}/packages/flutter_goldens"
  cp -ra "${srcdir}/${_group}/packages/flutter_localizations/"{pubspec.yaml,lib} "${pkgdir}/usr/lib/${_group}/packages/flutter_localizations"
  cp -ra "${srcdir}/${_group}/packages/flutter_test/"{pubspec.yaml,lib} "${pkgdir}/usr/lib/${_group}/packages/flutter_test"
  cp -ra "${srcdir}/${_group}/packages/flutter_web_plugins/"{pubspec.yaml,lib} "${pkgdir}/usr/lib/${_group}/packages/flutter_web_plugins"
  cp -ra "${srcdir}/${_group}/packages/fuchsia_remote_debug_protocol/"{pubspec.yaml,lib} "${pkgdir}/usr/lib/${_group}/packages/fuchsia_remote_debug_protocol"
  cp -ra "${srcdir}/${_group}/packages/integration_test/"{pubspec.yaml,lib,android} "${pkgdir}/usr/lib/${_group}/packages/integration_test"
}

_package-target-linux() {
  pkgdesc="${_pkgdesc} - linux target files"
  depends=(
	"${_group}-tool=${pkgver}"
	"${_group}-engine-linux=${pkgver}"
	"dart>=${_dartver[0]}"
	# "dart<${_dartver[1]}"
	"clang"
	"cmake"
        "ninja"
	"pkgconf" # base-devel, but runtime dependency
	# runtime shared libraries
	"gtk3"
	"libglvnd" # https://github.com/flutter/engine/pull/16924
  )

  install -dm755 "${pkgdir}/usr/lib/${_group}/packages/flutter_tools/bin"

  cp -ra "${srcdir}/${_group}/packages/flutter_tools/bin/tool_backend.sh" "${pkgdir}/usr/lib/${_group}/packages/flutter_tools/bin"
  cp -ra "${srcdir}/${_group}/packages/flutter_tools/bin/tool_backend.dart" "${pkgdir}/usr/lib/${_group}/packages/flutter_tools/bin"
}

_package-target-web() {
  pkgdesc="${_pkgdesc} - web target files"
  depends=(
	"${_group}-tool=${pkgver}"
	"${_group}-engine-web=${pkgver}"
  )

  install -dm755 "${pkgdir}/usr/lib/${_group}/packages/flutter_tools/lib/src/web"

  cp -ra "${srcdir}/${_group}/packages/flutter_tools/lib/src/web/file_generators" "${pkgdir}/usr/lib/${_group}/packages/flutter_tools/lib/src/web"
}

_package-target-android() {
  pkgdesc="${_pkgdesc} - android target files"
  depends=(
	"${_group}-tool=${pkgver}"
	"${_group}-engine-android=${pkgver}"
	"${_group}-gradle=${pkgver}"
  )
  optdepends=("android-sdk: develop for Android devices"
	    "java-environment: develop for Android devices"
  )

  install -dm755 "${pkgdir}/usr/lib/${_group}/packages/flutter_tools"
  install -dm755 "${pkgdir}/usr/lib/${_group}/bin/internal"

  cp -ra "${srcdir}/${_group}/packages/flutter_tools/gradle" "${pkgdir}/usr/lib/${_group}/packages/flutter_tools"

  install -Dm644 "${srcdir}/${_group}/bin/internal/engine.version" "${pkgdir}/usr/lib/${_group}/bin/internal"
  install -Dm644 "${srcdir}/${_group}/bin/internal/engine.realm" "${pkgdir}/usr/lib/${_group}/bin/internal"

}

_package-gradle() {
  pkgdesc="${_pkgdesc} - gradle wrapper"
  provides=(
	"${_group}-gradle=${pkgver}"
  )
  conflicts=(
	"${_group}-gradle"
	"${_group}-target-android<${pkgver}"
  )

  install -dm755 "${pkgdir}/usr/lib/${_group}/bin/cache/artifacts"

  cp -ra "${srcdir}/${_group}/bin/cache/artifacts/gradle_wrapper" "${pkgdir}/usr/lib/${_group}/bin/cache/artifacts"
}

_package-tool() {
  pkgdesc="${_pkgdesc} - CLI tool (for packaging only)"
  depends=(
	"${_group}-common=${pkgver}"
	# TODO: completely compile Flutter tool standalone and drop dependency
	"dart>=${_dartver[0]}"
	# "dart<${_dartver[1]}"
	# commands first
	"bash"
	"curl"
	"file" # base-devel, but runtime dependency
	"git"
	"coreutils" # explicit dependency to mkdir, rm
	"unzip"
	"which" # base-devel, but runtime dependency
	"xz"
	"zip"
	"glu" # libGLU.so.1 required for flutter test
  )
  conflicts=("${_group}-devel<${pkgver}" "${_group}-target-android<${pkgver}" "${_group}-target-linux<${pkgver}" "${_group}-target-web<${pkgver}")


  install -dm755 "${pkgdir}/usr/lib/${_group}"
  install -dm755 "${pkgdir}/usr/lib/${_group}/bin/cache"
  install -dm755 "${pkgdir}/usr/lib/${_group}/dev"
  install -dm755 "${pkgdir}/usr/lib/${_group}/packages/flutter_tools/.dart_tool"

  # otherwise flutter analyze will crash
  touch "${pkgdir}/usr/lib/${_group}/dev/.hack-flutter-analyze"

  cp -ra "${srcdir}/${_group}/bin/cache/flutter_tools.snapshot" "${pkgdir}/usr/lib/${_group}/bin/cache/flutter_tools.snapshot"
  cp -ra "${srcdir}/${_group}/bin/cache/flutter.version.json" "${pkgdir}/usr/lib/${_group}/bin/cache"
  cp -ra "${srcdir}/${_group}/version" "${pkgdir}/usr/lib/${_group}"

  cp -ra "${srcdir}/${_group}/packages/flutter_tools/.dart_tool/package_config.json" "${pkgdir}/usr/lib/${_group}/packages/flutter_tools/.dart_tool"

  install -dm755 "${pkgdir}/usr/bin"
  install -Dm755 "${srcdir}/${_group}.sh" "${pkgdir}/usr/lib/${_group}/bin/flutter"
  ln -sf "/usr/lib/flutter/bin/flutter" "${pkgdir}/usr/bin/flutter"
}

_package-devel() {
  pkgdesc="${_pkgdesc} - CLI tool (for application development)"
  depends=(
	"${_group}-tool=${pkgver}"
	"dart>=${_dartver[0]}"
	# "dart<${_dartver[1]}"
  )
  replaces=("${_group}-tool-developer")
  conflicts=("${_group}<${pkgver}")

  install -dm755 "${pkgdir}/usr/lib/${_group}"
  install -dm755 "${pkgdir}/usr/lib/${_group}/packages/flutter_tools"

  cp -ra "${srcdir}/${_group}/examples" "${pkgdir}/usr/lib/${_group}"
  cp -ra "${srcdir}/${_group}/packages/flutter_tools/templates" "${pkgdir}/usr/lib/${_group}/packages/flutter_tools"
  
  # TODO: patch `flutter create` to run without pub cache
  cp -ra "${srcdir}/${_group}/pub-cache" "${pkgdir}/usr/lib/${_group}/pub-cache"
}

_package-intellij-patch() {
  pkgdesc="${_pkgdesc} - IntelliJ Flutter plugin hotfix"
  depends=("${_group}-common=${pkgver}")
  optdepends=(
    "android-studio"
    "intellij-idea-community-edition"
    "intellij-idea-ultimate-edition"
  )

  # this is required in case people try to build with `aur/dart-sdk-dev` instead of `extra/dart`
  DART_BINARY=$(readlink $(which dart))
  DART_ROOT=${DART_ROOT:-${DART_BINARY/\/bin\/dart/}}

  install -dm755 "${pkgdir}/usr/lib/${_group}/bin/cache"
  
  # * not my fault grumble * : The IntelliJ Flutter plugin enforces this relative Dart SDK
  ln -sf "${DART_ROOT}/bin/dart" "${pkgdir}/usr/lib/${_group}/bin/dart"
  ln -sf "${DART_ROOT}" "${pkgdir}/usr/lib/${_group}/bin/cache/dart-sdk"
}

pkgname=("${_group}" "${_group}-common" "${_group}-gradle" "${_group}-tool" "${_group}-devel" "${_group}-target-linux" "${_group}-target-android" "${_group}-target-web" "${_group}-intellij-patch")

for _p in "${pkgname[@]}"; do
  eval "package_$_p() {
    $(declare -f "_package${_p#$_group}")
    _package${_p#$_group}
  }"
done