File: .gitlab-ci.yml

package info (click to toggle)
wireshark 3.4.10-0%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 259,504 kB
  • sloc: ansic: 2,461,727; cpp: 100,168; xml: 75,931; python: 42,670; perl: 25,517; lex: 7,460; sh: 4,380; pascal: 4,375; ruby: 91; makefile: 60; awk: 58; tcl: 35
file content (556 lines) | stat: -rw-r--r-- 23,664 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
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
# In the interest of reliability and performance, please avoid installing
# external dependencies here, e.g. via tools/*-setup.sh, apt, dnf, or yum.
# Do so in the appropriate Dockerfile at
# https://gitlab.com/wireshark/wireshark-containers/ instead.
# The resulting images can be found at
# https://gitlab.com/wireshark/wireshark-containers/container_registry

stages:
  - build
  - test
  - fuzz-asan
  - fuzz-randpkt
  - fuzz-valgrind

variables:
  # Ensure that checkouts are a) fast and b) have a reachable tag. In a
  # brighter, more glorious future we might be able to use --shallow-since:
  # https://gitlab.com/gitlab-org/gitlab-runner/-/issues/3460
  # In the mean time, fetching the last 2000 commits does the job.
  GIT_DEPTH: "1"
  GIT_FETCH_EXTRA_FLAGS: "--depth=2000"
  CCACHE_DIR: "${CI_PROJECT_DIR}/ccache"
  CLANG_VERSION: 10

# Common rule stanzas
# These must currently be including using "!reference tags". "extends:" and
# YAML anchors won't work:
# https://gitlab.com/gitlab-org/gitlab/-/issues/322992
#
# Commits that have been approved and merged. Run automatically in the main
# repo and allow manual runs in the web UI and in forks.
.if-merged:
  - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "release-3.4" && $CI_PROJECT_URL =~ /.*gitlab.com\/wireshark\/wireshark/'
    when: always
  - if: '$CI_PIPELINE_SOURCE == "web"'
    when: always
  - if: '$CI_PIPELINE_SOURCE == "push" && $CI_PROJECT_URL !~ /.*gitlab.com\/wireshark\/wireshark/'
    when: manual
# Incoming merge requests.
.if-merge-request:
  - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
    when: always
# Incoming non-detached merge requests. Must be used for runners which are only
# available in wireshark/wireshark, e.g. wireshark-windows-*
.if-attached-merge-request:
  - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_PROJECT_URL =~ /.*gitlab.com\/wireshark\/wireshark/'
    when: always
# Fuzz jobs. Care should be taken when changing this since the scheduler
# often doesn't report errors.
.if-fuzz-schedule:
  - if: '$CI_PIPELINE_SOURCE == "schedule" && $SCHEDULE_TYPE == "fuzz"'
    when: always

.build-linux:
  stage: build
  tags:
    - docker
  after_script:
    - for builddir in build/packaging/rpm/BUILD/wireshark-*/build build/packaging/rpm/BUILD/wireshark-* build obj-*; do [ ! -d "$builddir/run" ] || break; done
    - if [[ "$CI_JOB_NAME" == "build:rpm-opensuse-"* ]]; then export LD_LIBRARY_PATH=$builddir/run; fi
    - if [ -f $builddir/run/tshark ]; then $builddir/run/tshark --version; fi

.test-linux:
  stage: test
  tags:
    - docker
  variables:
    GIT_STRATEGY: none

.build-ubuntu:
  extends: .build-linux
  image: registry.gitlab.com/wireshark/wireshark-containers/ubuntu-dev
  retry: 1
  # https://gould.cx/ted/blog/2017/06/10/ccache-for-Gitlab-CI/
  cache:
    # XXX Use ${CI_JOB_NAME}-${CI_MERGE_REQUEST_TARGET_BRANCH_NAME} instead?
    key: ${CI_JOB_NAME}-release-3.4
    paths:
      - ccache/
  before_script:
    - useradd user
    - locale-gen en_US.UTF-8
    - export LANG=en_US.UTF-8
    - export PYTEST_ADDOPTS=--skip-missing-programs=dumpcap,rawshark
    - mkdir -p ccache
    - export CCACHE_BASEDIR=${PWD}
    - ccache --show-stats
    - export DEB_BUILD_OPTIONS=nocheck
    - export DH_QUIET=1
    - export MAKEFLAGS=--silent
    - mkdir build
    - cd build
  script:
    # setcap restricts our library paths
    - CFLAGS=-Wl,-rpath=$(pwd)/run CXXFLAGS=-Wl,-rpath=$(pwd)/run cmake -GNinja -DENABLE_CCACHE=ON ..
    - ninja
    - ninja test-programs
    - chown -R user .
    - if [ -f run/dumpcap ]; then setcap cap_net_raw,cap_net_admin+eip run/dumpcap; fi
    - if [ -f run/dumpcap ]; then su user -c "run/dumpcap -D" ; fi
    - su user -c pytest-3

.build-rpm:
  extends: .build-linux
  rules: !reference [.if-merged]
  artifacts:
    paths:
      - build/packaging/rpm/RPMS
    expire_in: 3 days

.test-rpm:
  extends: .test-linux
  rules: !reference [.if-merged]

# Rely on fedora:latest and debian-stable jobs for testing a recent GCC version.
Clang 10:
  extends: .build-ubuntu
  rules: !reference [.if-merged]
  variables:
    CC: "clang-$CLANG_VERSION"
    CXX: "clang++-$CLANG_VERSION"

Source Package:
  extends: .build-ubuntu
  rules: !reference [.if-merged]
  script:
    # Print some variables to make rule writing easier.
    - env | grep -E "CI_(COMMIT|JOB|PROJECT)"
    - perl ../tools/make-version.pl --set-release || ../perl make-version.pl --set-release
    - cmake -G Ninja $CMAKE_ARGS -DENABLE_CCACHE=ON ..
    - cd $CI_PROJECT_DIR
    - build/packaging/source/git-export-release.sh -d .
  after_script:
    # - ccache --max-size $( du --summarize --block-size=1M "$CI_PROJECT_DIR/build" | awk '{printf ("%dM", $1 * 1.5)}' )
    - for digest in sha256 rmd160 sha1 ; do openssl $digest wireshark-*.tar.* ; done
    # This will break if we produce multiple tarballs, which is arguably a good thing.
    - if [ -n "$AWS_ACCESS_KEY_ID" ] && [ -n "$AWS_SECRET_ACCESS_KEY" ] && [ -n "$S3_DESTINATION_DIST" ] ; then aws s3 cp wireshark-*.tar.* "$S3_DESTINATION_DIST/" ; fi
  artifacts:
    paths:
      - wireshark-*.tar.*

CentOS 7 RPM Package:
  extends: .build-rpm
  image: registry.gitlab.com/wireshark/wireshark-containers/centos-7-dev
  script:
    - mkdir build
    - cd build
    - cmake3 -GNinja ..
    - ninja-build rpm-package
CentOS 7 RPM Test:
  extends: .test-rpm
  image: registry.gitlab.com/wireshark/wireshark-containers/centos-7-dev
  script:
    - yum --nogpgcheck localinstall -y build/packaging/rpm/RPMS/x86_64/*.rpm
    - tshark --version
  dependencies: [ 'CentOS 7 RPM Package' ]

openSUSE 15.1 RPM Package:
  extends: .build-rpm
  image: registry.gitlab.com/wireshark/wireshark-containers/opensuse-15.1-dev
  script:
    - mkdir build
    - cd build
    - cmake -GNinja ..
    - ninja rpm-package
openSUSE 15.1 RPM Test:
  extends: .test-rpm
  image: registry.gitlab.com/wireshark/wireshark-containers/opensuse-15.1-dev
  script:
    - zypper --no-gpg-checks install -y build/packaging/rpm/RPMS/x86_64/*.rpm
    - tshark --version
  dependencies: [ 'openSUSE 15.1 RPM Package' ]

# Disabled for now due to issues with Fedora 33.
.Fedora RPM Package:
  extends: .build-rpm
  image: registry.gitlab.com/wireshark/wireshark-containers/fedora-dev
  script:
    - mkdir build
    - cd build
    - cmake3 -GNinja ..
    - ninja-build rpm-package

# .Fedora RPM Test:
#   extends: .test-rpm
#   image: fedora
#   script:
#     - dnf install -y build/packaging/rpm/RPMS/x86_64/*.rpm
#     - tshark --version
#   dependencies: [ 'Fedora RPM Package' ]

# Job to generate packages for Debian stable
Debian Stable APT Package:
  extends: .build-linux
  rules: !reference [.if-merged]
  image: registry.gitlab.com/wireshark/wireshark-containers/debian-stable-dev
  script:
    # Shared GitLab runners limit the log size to 4M, so reduce verbosity. See
    # https://gitlab.com/gitlab-com/support-forum/issues/2790
    - export DH_QUIET=1
    - export MAKEFLAGS=--silent
    - dpkg-buildpackage -b --no-sign -jauto
    - mkdir debian-packages
    - mv ../*.deb debian-packages/
  artifacts:
    paths:
      - debian-packages/*.deb
    expire_in: 3 days
Debian Stable APT Test:
  extends: .test-linux
  rules: !reference [.if-merged]
  image: registry.gitlab.com/wireshark/wireshark-containers/debian-stable-dev
  stage: test
  script:
    - DEBIAN_FRONTEND=noninteractive apt-get install ./debian-packages/*.deb -y
    - tshark --version
  after_script:
    # Used for https://www.wireshark.org/docs/dfref/
    - TSHARK_VERSION=$( tshark --version | head -n 1 | sed -e 's/.*(v//' -e 's/)$//' )
    - tshark -G fields > dfilter-list-${TSHARK_VERSION}.txt
  artifacts:
    paths:
      - dfilter-list-*.txt
  variables:
    GIT_STRATEGY: none
  dependencies: [ 'Debian Stable APT Package' ]

Win64 Package:
  stage: build
  rules: !reference [.if-merged]
  tags:
    - wireshark-win64-package
  before_script:
    - $env:WIRESHARK_BASE_DIR = "C:\Development"
    - $env:Configuration = "RelWithDebInfo"
    - $env:Path += ";C:\Program Files\CMake\bin"
    - $env:Path += ";C:\Strawberry\c\bin;C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin"
    - $env:Path += ";C:\qt\5.15.2\msvc2019_64\bin"
    - $env:Path += ";C:\Program Files (x86)\NSIS"
    - $env:Path += ";C:\Program Files (x86)\WiX Toolset v3.11\bin"
    - $env:Path += ";C:\Program Files\Amazon\AWSCLIV2"
    # https://help.appveyor.com/discussions/questions/18777-how-to-use-vcvars64bat-from-powershell
    - cmd.exe /c "call `"C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvars64.bat`" && set > %temp%\vcvars.txt"
    - Get-Content "$env:temp\vcvars.txt" | Foreach-Object { if ($_ -match "^(.*?)=(.*)$") { Set-Content "env:\$($matches[1])" $matches[2] } }
    - mkdir build
    - cd build
  script:
    - perl ../tools/make-version.pl --set-release
    - cmake -G "Visual Studio 16 2019" -A x64 -DDISABLE_WERROR=OFF -DTEST_EXTRA_ARGS=--enable-release -DENABLE_LTO=off ..
    - msbuild /verbosity:minimal "/consoleloggerparameters:PerformanceSummary;NoSummary" /maxcpucount Wireshark.sln
    - msbuild /verbosity:minimal /maxcpucount test-programs.vcxproj
    - msbuild /verbosity:minimal /maxcpucount nsis_package_prep.vcxproj
    - msbuild /verbosity:minimal /maxcpucount wix_package_prep.vcxproj
    - C:\gitlab-builds\bin\sign-files.ps1 -Recurse -Path run\RelWithDebInfo
    - msbuild /verbosity:minimal nsis_package.vcxproj
    - C:\gitlab-builds\bin\sign-files.ps1 -Path packaging\nsis
    - msbuild /verbosity:minimal wix_package.vcxproj
    - C:\gitlab-builds\bin\sign-files.ps1 -Path packaging\wix
    - $plugins = Get-ChildItem run\RelWithDebInfo\plugins\*\*.dll ; signtool verify /v /pa /all run\RelWithDebInfo\*.exe run\RelWithDebInfo\extcap\*.exe $plugins run\RelWithDebInfo\libwireshark.dll run\RelWithDebInfo\libwiretap.dll run\RelWithDebInfo\libwsutil.dll packaging\nsis\Wireshark-win??-*.exe packaging\wix\Wireshark-win??-*.msi
    - msbuild /verbosity:minimal pdb_zip_package.vcxproj
    - C:\gitlab-builds\bin\mse-scan.ps1
    - $packages = Get-ChildItem "packaging\nsis\Wireshark-win??-*.exe", "packaging\wix\Wireshark-win??-*.msi", "Wireshark-pdb-win??-*.zip"
    - foreach ($package in $packages) { certutil -hashfile $package SHA256 }
    - |
      if ((Test-Path env:AWS_ACCESS_KEY_ID) -and (Test-Path env:AWS_SECRET_ACCESS_KEY) -and (Test-Path env:S3_DESTINATION_WIN64)) {
        foreach ($package in $packages) {
          aws s3 cp "$package" "$env:S3_DESTINATION_WIN64/"
        }
      }
    - ctest -C RelWithDebInfo --parallel 3 --force-new-ctest-process --verbose

Win32 Package:
  stage: build
  rules: !reference [.if-merged]
  tags:
    - wireshark-win32-package
  before_script:
    - $env:WIRESHARK_BASE_DIR = "C:\Development"
    - $env:Configuration = "RelWithDebInfo"
    - $env:Path += ";C:\Program Files\CMake\bin"
    - $env:Path += ";C:\Strawberry\c\bin;C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin"
    - $env:Path += ";C:\qt\5.15.2\msvc2019\bin"
    - $env:Path += ";C:\Program Files (x86)\NSIS"
    - $env:Path += ";C:\Program Files (x86)\WiX Toolset v3.11\bin"
    - $env:Path += ";C:\Program Files\Amazon\AWSCLIV2"
    # https://help.appveyor.com/discussions/questions/18777-how-to-use-vcvars64bat-from-powershell
    - cmd.exe /c "call `"C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvarsamd64_x86.bat`" && set > %temp%\vcvars.txt"
    - Get-Content "$env:temp\vcvars.txt" | Foreach-Object { if ($_ -match "^(.*?)=(.*)$") { Set-Content "env:\$($matches[1])" $matches[2] } }
    - $env:Platform = "Win32"
    - mkdir build
    - cd build
  script:
    - perl ../tools/make-version.pl --set-release
    - cmake -G "Visual Studio 16 2019" -A Win32 -DDISABLE_WERROR=OFF -DTEST_EXTRA_ARGS=--enable-release -DENABLE_LTO=off ..
    - msbuild /verbosity:minimal "/consoleloggerparameters:PerformanceSummary;NoSummary" /maxcpucount Wireshark.sln
    - msbuild /verbosity:minimal /maxcpucount test-programs.vcxproj
    - msbuild /verbosity:minimal /maxcpucount nsis_package_prep.vcxproj
    - msbuild /verbosity:minimal /maxcpucount wix_package_prep.vcxproj
    - C:\gitlab-builds\bin\sign-files.ps1 -Recurse -Path run\RelWithDebInfo
    - msbuild /verbosity:minimal nsis_package.vcxproj
    - C:\gitlab-builds\bin\sign-files.ps1 -Path packaging\nsis
    - msbuild /verbosity:minimal wix_package.vcxproj
    - C:\gitlab-builds\bin\sign-files.ps1 -Path packaging\wix
    - msbuild /verbosity:minimal portableapps_package.vcxproj
    - C:\gitlab-builds\bin\sign-files.ps1 -Path packaging\portableapps
    - $plugins = Get-ChildItem run\RelWithDebInfo\plugins\*\*.dll ; signtool verify /v /pa /all run\RelWithDebInfo\*.exe run\RelWithDebInfo\extcap\*.exe $plugins run\RelWithDebInfo\libwireshark.dll run\RelWithDebInfo\libwiretap.dll run\RelWithDebInfo\libwsutil.dll packaging\nsis\Wireshark-win??-*.exe packaging\wix\Wireshark-win??-*.msi packaging\portableapps\WiresharkPortable_*.paf.exe
    - msbuild /verbosity:minimal pdb_zip_package.vcxproj
    - C:\gitlab-builds\bin\mse-scan.ps1
    - $packages = Get-ChildItem "packaging\nsis\Wireshark-win??-*.exe", "packaging\wix\Wireshark-win??-*.msi", "packaging\portableapps\WiresharkPortable_*.paf.exe", "Wireshark-pdb-win??-*.zip"
    - foreach ($package in $packages) { certutil -hashfile $package SHA256 }
    - |
      if ((Test-Path env:AWS_ACCESS_KEY_ID) -and (Test-Path env:AWS_SECRET_ACCESS_KEY) -and (Test-Path env:S3_DESTINATION_WIN32)) {
        foreach ($package in $packages) {
          aws s3 cp "$package" "$env:S3_DESTINATION_WIN32/"
        }
      }
    - ctest -C RelWithDebInfo --parallel 3 --force-new-ctest-process --verbose

macOS Intel Package:
  stage: build
  rules: !reference [.if-merged]
  variables:
    CODE_SIGN_IDENTITY: "Wireshark Foundation, Inc."
  tags:
    - wireshark-macos-intel-package
  retry: 1
  script:
    - export CMAKE_PREFIX_PATH="$HOME/Qt5.12.6/5.12.6/clang_64/lib/cmake"
    - export PATH="$PATH:$HOME/bin"
    - perl tools/make-version.pl --set-release
    - mkdir build
    - cd build
    - printf "\e[0Ksection_start:%s:cmake_section[collapsed=true]\r\e[0KRunning CMake" "$( date +%s)"
    - cmake -DENABLE_CCACHE=ON -DCMAKE_OSX_DEPLOYMENT_TARGET=10.12 -DCMAKE_OSX_SYSROOT=macosx10.15 -DTEST_EXTRA_ARGS=--enable-release -G Ninja ..
    - printf "\e[0Ksection_end:%s:cmake_section\r\e[0K" "$( date +%s)"
    - ninja
    - package-prep
    - ninja dmg_package
    - cd run
    - notarize-build
    - stat -f "%N %z bytes" Wireshark*Intel*.dmg
    - for digest in sha256 rmd160 sha1 ; do openssl $digest Wireshark*Intel*.dmg ; done
    - |
      if [ -n "$AWS_ACCESS_KEY_ID" ] && [ -n "$AWS_SECRET_ACCESS_KEY" ] && [ -n "$S3_DESTINATION_MACOS_INTEL64" ] ; then
        aws s3 cp Wireshark*Intel*.dmg "$S3_DESTINATION_MACOS_INTEL64/"
      fi
    - cd ..
    - ninja test-programs
    - ctest --parallel 4 --output-on-failure
  needs: []

# Build Wireshark manuals
# Note: Need ubuntu:focal with `ruby-coderay` and `ruby-asciidoctor-pdf` packages to build PDF docs
Documentation:
  extends: .build-linux
  image: registry.gitlab.com/wireshark/wireshark-containers/ubuntu-dev
  rules:
    - if: '$CI_PIPELINE_SOURCE == "push" && $CI_PROJECT_URL =~ /.*gitlab.com\/wireshark\/wireshark/'
      changes:
        - "docbook/**"
        - "epan/wslua/**"
      when: always
  script:
    # XXX We might want to move this to wireshark-ubuntu-dev or debian-setup.sh.
    - DEBIAN_FRONTEND=noninteractive apt-get update
    - DEBIAN_FRONTEND=noninteractive apt-get --yes install ruby-coderay ruby-asciidoctor-pdf
    - mkdir build
    - cd build
    - cmake -GNinja ..
    - ninja all_guides
  after_script:
    - mv build/docbook/wsug_html/ .
    - mv build/docbook/wsug_html_chunked/ .
    - mv build/docbook/wsdg_html/ .
    - mv build/docbook/wsdg_html_chunked/ .
  artifacts:
    paths:
      - wsug_html/
      - wsug_html_chunked/
      - wsdg_html/
      - wsdg_html_chunked/

# https://docs.gitlab.com/ee/user/gitlab_com/index.html#linux-shared-runners

Commit Checks:
  extends: .build-ubuntu
  rules: !reference [.if-merge-request]
  script:
    # build-ubuntu puts us in `build`.
    - cd ..
    - bash ./tools/pre-commit 'HEAD^1'
    - tools/validate-commit.py

Ubuntu .dpkg:
  extends: .build-ubuntu
  rules: !reference [.if-merge-request]
  script:
    # build-ubuntu puts us in `build`.
    - cd ..
    - CC=/usr/lib/ccache/gcc CXX=/usr/lib/ccache/g++ dpkg-buildpackage -us -uc -rfakeroot -jauto -Zgzip -zfast
    - lintian --suppress-tags library-not-linked-against-libc,copyright-excludes-files-in-native-package --display-experimental --display-info --pedantic --profile debian

GCC Warnings:
  extends: .build-ubuntu
  rules: !reference [.if-merge-request]
  script:
    # build-ubuntu puts us in `build`.
    - perl ../tools/make-version.pl --set-release || ../perl make-version.pl --set-release
    - CC=gcc CXX=g++ cmake -DENABLE_EXTRA_COMPILER_WARNINGS=on -DCMAKE_EXPORT_COMPILE_COMMANDS=on -DENABLE_CCACHE=ON -G Ninja ..
    - ninja
    - ninja test-programs
    - chown -R user .
    - su user -c "ctest --parallel 3 --force-new-ctest-process --verbose"

Code Checks + Clang Warnings:
  extends: .build-ubuntu
  rules: !reference [.if-merge-request]
  variables:
    CC: clang-$CLANG_VERSION
    CXX: clang++-$CLANG_VERSION
  script:
    # build-ubuntu puts us in `build`.
    - cd ..
    - python3 tools/checklicenses.py
    - ./tools/cppcheck/cppcheck.sh -l 1 -x | tee cppcheck_report.xml
    - if [[ -s "cppcheck_report.xml" ]]; then cppcheck-htmlreport --file cppcheck_report.xml  --report-dir . ; fi
    - cd build
    - cmake -DENABLE_EXTRA_COMPILER_WARNINGS=on -DENABLE_CHECKHF_CONFLICT=on -DCMAKE_EXPORT_COMPILE_COMMANDS=on -DENABLE_CCACHE=ON -G Ninja ..
    - ninja
    - ./run/tshark -v
    - sh -c '[ ! -e ../tools/validate-clang-check.sh ] || ../tools/validate-clang-check.sh'
    - ninja checkAPI
  artifacts:
    paths:
      - cppcheck_report.xml
      - cppcheck_report.html

# XXX This is still beta:
# https://docs.gitlab.com/ee/user/gitlab_com/index.html#windows-shared-runners-beta
# Dockerfile at https://github.com/wireshark/wireshark-windows-dev-docker.
# XXX We currently depend on Qt being installed in C:\Qt on the host. We should
# find a more independent way of installing Qt, e.g. via a download+cache.
Windows Build:
  rules: !reference [.if-attached-merge-request]
  tags:
    - wireshark-windows-merge-req
  stage: build
  before_script:
    # XXX Find a better location.
    - mkdir c:\Development
    - $env:WIRESHARK_BASE_DIR = "C:\Development"
    - $env:Configuration = "RelWithDebInfo"
    - $env:Path += ";C:\Program Files\CMake\bin"
    - $env:Path += ";C:\Strawberry\c\bin;C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin"
    - $env:Path += ";C:\qt\5.15.2\msvc2019_64\bin"
    # https://help.appveyor.com/discussions/questions/18777-how-to-use-vcvars64bat-from-powershell
    - cmd.exe /c "call `"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat`" && set > %temp%\vcvars.txt"
    - Get-Content "$env:temp\vcvars.txt" | Foreach-Object { if ($_ -match "^(.*?)=(.*)$") { Set-Content "env:\$($matches[1])" $matches[2] } }
    # Testing / debugging only.
    #- dir c:\
    #- dir c:\qt
    #- $env:path.split(";")
    #- cmd.exe /c "set"
    #- Get-Location
  script:
    - perl tools/make-version.pl --set-release
    - mkdir build
    - cd build
    - cmake -G "Visual Studio 16 2019" -A x64 ..
    - msbuild "/consoleloggerparameters:PerformanceSummary;NoSummary" /maxcpucount Wireshark.sln
    - msbuild "/consoleloggerparameters:PerformanceSummary;NoSummary" test-programs.vcxproj
    - ctest -C RelWithDebInfo --parallel 3 --force-new-ctest-process --verbose

# Fuzz TShark using ASAN and valgrind.
.fuzz-ubuntu:
  extends: .build-ubuntu
  rules: !reference [.if-fuzz-schedule]
  tags:
    - wireshark-ubuntu-fuzz
  resource_group: fuzz-release-3.4
  variables:
    CC: "clang-$CLANG_VERSION"
    CXX: "clang++-$CLANG_VERSION"
    INSTALL_PREFIX: "$CI_PROJECT_DIR/_install"
    MIN_PLUGINS: 10
    MAX_PASSES: 5
  before_script:
    - DEBIAN_FRONTEND=noninteractive apt-get update
    - DEBIAN_FRONTEND=noninteractive apt-get --yes install llvm-$CLANG_VERSION
    - mkdir -p ccache
    # Signal after_script, which runs in its own shell.
    - echo "export FUZZ_PASSED=true" > /tmp/fuzz_result.sh
    - mkdir /tmp/fuzz
    - mkdir build
    - cd build
  after_script:
    - . /tmp/fuzz_result.sh
    - if $FUZZ_PASSED ; then exit 0 ; fi
    - echo Fuzzing failed. Generating report.
    - FUZZ_CAPTURE=$( ls /tmp/fuzz/fuzz-*.pcap | head -n 1 )
    - FUZZ_ERRORS="/tmp/fuzz/$( basename "$FUZZ_CAPTURE" .pcap ).err"
    - printf "\nfuzz-test.sh stderr:\n" >> "$FUZZ_ERRORS"
    - cat fuzz-test.err >> "$FUZZ_ERRORS"
    - |
      if [ -n "$AWS_ACCESS_KEY_ID" ] && [ -n "$AWS_SECRET_ACCESS_KEY" ] && [ -n "$S3_DESTINATION_FUZZ" ] ; then
        aws s3 cp "$FUZZ_CAPTURE" "$S3_DESTINATION_FUZZ/"
        aws s3 cp "$FUZZ_ERRORS" "$S3_DESTINATION_FUZZ/"
      fi
    # The cache should be large enough to be useful but it shouldn't take
    # too long to restore+save each run.
    - ccache --max-size $( du --summarize --block-size=1M "$CI_PROJECT_DIR/build" | awk '{printf ("%dM", $1 * 1.5)}' )

ASan Menagerie Fuzz:
  extends: .fuzz-ubuntu
  stage: fuzz-asan
  script:
    - MAX_SECONDS=$(( 4 * 60 * 60 ))
    - printf "\e[0Ksection_start:%s:cmake_section[collapsed=true]\r\e[0KRunning CMake" "$( date +%s)"
    - cmake -G Ninja -DBUILD_wireshark=OFF -DCMAKE_BUILD_TYPE=Debug -DENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX -DENABLE_CCACHE=ON ..
    - printf "\e[0Ksection_end:%s:cmake_section\r\e[0K" "$( date +%s)"
    - ninja
    - ninja install
    - cd ..
    # /var/menagerie contains captures harvested from wireshark.org's mailing list, wiki, issues, etc.
    # We have more captures than we can fuzz in $MAX_SECONDS, so we shuffle them each run.
    - ./tools/fuzz-test.sh -a -2 -P $MIN_PLUGINS -b $INSTALL_PREFIX/bin -d /tmp/fuzz -t $MAX_SECONDS $( shuf -e /var/menagerie/*/* ) 2> fuzz-test.err || echo "export FUZZ_PASSED=false" > /tmp/fuzz_result.sh

ASan randpkt Fuzz:
  extends: .fuzz-ubuntu
  stage: fuzz-randpkt
  script:
    # XXX Reuse fuzz-asan?
    - printf "\e[0Ksection_start:%s:cmake_section[collapsed=true]\r\e[0KRunning CMake" "$( date +%s)"
    - cmake -G Ninja -DBUILD_wireshark=OFF -DCMAKE_BUILD_TYPE=Debug -DENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX -DENABLE_CCACHE=ON ..
    - printf "\e[0Ksection_end:%s:cmake_section\r\e[0K" "$( date +%s)"
    - ninja
    - ninja install
    - cd ..
    - ./tools/randpkt-test.sh -a -b $INSTALL_PREFIX/bin -d /tmp/fuzz -p $MAX_PASSES 2> fuzz-test.err || echo "export FUZZ_PASSED=false" > /tmp/fuzz_result.sh
  needs: [ 'ASan Menagerie Fuzz' ]

Valgrind Menagerie Fuzz:
  extends: .fuzz-ubuntu
  stage: fuzz-valgrind
  script:
    - DEBIAN_FRONTEND=noninteractive apt-get update
    - DEBIAN_FRONTEND=noninteractive apt-get --yes install valgrind
    - MAX_SECONDS=$(( 2 * 60 * 60 ))
    - printf "\e[0Ksection_start:%s:cmake_section[collapsed=true]\r\e[0KRunning CMake" "$( date +%s)"
    - cmake -G Ninja -DBUILD_wireshark=OFF -DCMAKE_BUILD_TYPE=Debug -DENABLE_ASAN=OFF -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX -DENABLE_CCACHE=ON ..
    - printf "\e[0Ksection_end:%s:cmake_section\r\e[0K" "$( date +%s)"
    - ninja
    - ninja install
    - cd ..
    - ./tools/fuzz-test.sh -g -P $MIN_PLUGINS -b $INSTALL_PREFIX/bin -d /tmp/fuzz -t $MAX_SECONDS $( shuf -e /var/menagerie/*/* ) 2> fuzz-test.err || echo "export FUZZ_PASSED=false" > /tmp/fuzz_result.sh
  needs: [ 'ASan randpkt Fuzz' ]