summaryrefslogtreecommitdiff
path: root/chromium.spec
blob: abc3d6f92b90e602627ce5feabaa79191588d9b5 (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
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
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
%define _lto_cflags %{nil}
# enable | disable system build flags
# official builds have less debugging and go faster... but we have to shut some things off.
%global official_build 1
%global enable_thin_lto 0
# enable | disable bootstrap
# If this is 1, we enable bootstrap
%global bootstrap 0
%global esbuild 1
%global esbuild_version 0.19.11

 
# set default numjobs for the koji build
%global numjobs %{_smp_build_ncpus}

# Fancy build status, so we at least know, where we are..
# %1 where
# %2 what
%global build_target() \
	export NINJA_STATUS="[%2:%f/%t] " ; \
	ninja -v -j %{numjobs}  -C '%1' '%2'
# enable | disable headless client build
%global build_headless 1
# enable|disable chrome-remote-desktop build
%global build_remoting 0
%global system_nodejs 1

# enable | disable system brotli
# disable system brotli due to old system brotli
%global bundlebrotli 1
# Chromium's fork of ICU is now something we can't unbundle.
# This is left here to ease the change if that ever switches.
%global bundleicu 1
%global bundlere2 1

# The libxml_utils code depends on the specific bundled libxml checkout
# which is not compatible with the current code in the 
# 2017-06-08.
%global bundlelibxml 0
# openEuler's Python 2 stack is being removed, we use the bundled Python libraries
# This can be revisited once we upgrade to Python 3
%global bundlepylibs 0
%global bundlezlib 1
%global use_qt 1
# enable gtk3 by default
%global gtk3 1

%global bundleopus 1
%global bundlelibusbx 1
%global bundleharfbuzz 1
%global bundlelibwebp 1
%global bundlelibpng 1
%global bundlelibjpeg 1
%global bundlefreetype 1
%global bundlelibdrm 1
%global bundlefontconfig 1
%global bundleffmpegfree 0
%global bundlelibaom 1
%global bundlevpx 1
%global bundlezstd 0

%global use_vaapi 1
%global use_v4l2_codec 0
%global disable_bti 0
%global enable_swiftshader 0
# enable v4l2 and disable vaapi for aarch64 platform
%ifarch aarch64
%global use_vaapi 0
%global use_v4l2_codec 1
%global optflags %(echo %{optflags} | sed 's/-mbranch-protection=standard /-mbranch-protection=pac-ret /')
# Workaround for https://bugzilla.redhat.com/show_bug.cgi?id=2239523
# Disable BTI until this is fixed upstream.
%global disable_bti 1
%endif

%ifarch riscv64
%global use_vaapi 0
%global bundlevpx 0
%endif

%global python312 0
# Seems like we might need this sometimes
# Practically, no. But it's here in case we do.
%global use_gold 0
%global build_clear_key_cdm 0
# Disabled because of Google, starting with Chromium 88.
%global userestrictedapikeys 0
# openEuer does not currently provide an official Google API key.
%global useapikey 0

# Leave this alone, please.
%global builddir out/Release
%global headlessbuilddir out/Headless
%global remotingbuilddir out/Remoting

# enable|disable debuginfo
%global enable_debug 0
%if ! %{enable_debug}
%global debug_package %{nil}
%global debug_level 0
%else
%global debug_level 1
# workaround for the error empty file debugsource
%undefine _debugsource_packages
%endif

# %%{nil} for Stable; -beta for Beta; -dev for Devel
# dash in -beta and -dev is intentional !
%global chromium_channel %{nil}
%global chromium_menu_name Chromium
%global chromium_browser_channel chromium-browser%{chromium_channel}
%global chromium_path %{_libdir}/chromium-browser%{chromium_channel}
%global crd_path %{_libdir}/chrome-remote-desktop

%global __provides_exclude_from ^(%{chromium_path}/.*\\.so|%{chromium_path}/.*\\.so.*)$
%global __requires_exclude ^(%{chromium_path}/.*\\.so|%{chromium_path}/.*\\.so.*)$

# enable clang by default
%global clang 1
# set correct toolchain
%if %{clang}
%global toolchain clang
%else
%global toolchain gcc
%endif



### Google API keys (see http://www.chromium.org/developers/how-tos/api-keys)
# Currently we do not provide API key unless somebody need this
%if %{useapikey}
%global api_key %nil
%else
%global api_key %nil
%endif
%global default_client_id %nil
%global default_client_secret %nil
%global chromoting_client_id %nil

Name:	chromium%{chromium_channel}
Version: 119.0.6045.159
Release: 1
Summary: A WebKit (Blink) powered web browser.
Url: http://www.chromium.org/Home
License: BSD-3-Clause AND LGPL-2.1-or-later AND Apache-2.0 AND IJG AND MIT AND GPL-2.0-or-later AND ISC AND OpenSSL AND (MPL-1.1 OR GPL-2.0-only OR LGPL-2.0-only)

### Chromium Patches ###
Patch0: chromium-70.0.3538.67-sandbox-pie.patch
# Use /etc/chromium for initial_prefs
Patch1: chromium-115-initial_prefs-etc-path.patch
# system libusb
Patch2: chromium-119-system-libusb.patch
# Do not mangle zlib
Patch5: chromium-77.0.3865.75-no-zlib-mangle.patch
# Do not use unrar code, it is non-free
Patch6: chromium-119-norar.patch
# Try to load widevine from other places
Patch8: chromium-117-widevine-other-locations.patch
# Tell bootstrap.py to always use the version of Python we specify
Patch11: chromium-93.0.4577.63-py3-bootstrap.patch
# debian patch, disable font-test
Patch20: chromium-disable-font-tests.patch
# https://gitweb.gentoo.org/repo/gentoo.git/tree/www-client/chromium/files/chromium-unbundle-zlib.patch
Patch52: chromium-81.0.4044.92-unbundle-zlib.patch
# Fix headers to look for system paths when we are using system minizip
Patch61: chromium-119-system-minizip-header-fix.patch
# Fix issue where closure_compiler thinks java is only allowed in android builds
# https://bugs.chromium.org/p/chromium/issues/detail?id=1192875
Patch65: chromium-91.0.4472.77-java-only-allowed-in-android-builds.patch
# Update rjsmin to 1.2.0
Patch69: chromium-103.0.5060.53-update-rjsmin-to-1.2.0.patch
# Update six to 1.16.0
Patch70: chromium-105.0.5195.52-python-six-1.16.0.patch
# Disable tests on remoting build
Patch82: chromium-98.0.4758.102-remoting-no-tests.patch
# patch for using system brotli
Patch89: chromium-116-system-brotli.patch
# disable GlobalMediaControlsCastStartStop to avoid crash
# when using the address bar media player button
Patch90: chromium-119-disable-GlobalMediaControlsCastStartStop.patch
# patch for using system opus
Patch91: chromium-108-system-opus.patch

# need for old ffmpeg 5.x 
Patch114: chromium-107-ffmpeg-5.x-duration.patch
# disable the check
Patch115: chromium-107-proprietary-codecs.patch
# drop av_stream_get_first_dts from internal ffmpeg
Patch116: chromium-119-ffmpeg-first_dts.patch
# fix tab crash with SIGTRAP error when using system ffmpeg
Patch117: chromium-118-sigtrap_system_ffmpeg.patch
# https://bugs.chromium.org/p/chromium/issues/detail?id=1325301
# https://www.mail-archive.com/ffmpeg-devel@ffmpeg.org/msg121495.html

# revert AV1 VAAPI video encode due to old libva on el9
Patch130: chromium-119-revert-av1enc-el9.patch
# file conflict with old kernel on el8/el9
Patch140: chromium-118-dma_buf_export_sync_file-conflict.patch

Patch200: chromium-117-system-zstd.patch
# fixes for old clang version 
# compiler build errors, no matching constructor for initialization
Patch300: chromium-119-no_matching_constructor.patch
Patch301: chromium-115-compiler-SkColor4f.patch
# workaround for clang bug, https://github.com/llvm/llvm-project/issues/57826
Patch302: chromium-118-workaround_clang_bug-structured_binding.patch
# missing typename
Patch303: chromium-117-typename.patch
# error: invalid operands to binary expression
Patch304: chromium-117-string-convert.patch
# error: constexpr constructor's 3rd parameter type 'std::string' (aka 'basic_string<char>') is not a literal type
Patch305: chromium-119-constexpr.patch
Patch306: chromium-119-assert.patch
# not supported in old glibc < 2.30, error: fatal error: 'sys/ifunc.h' file not found
Patch307: chromium-118-arm64-memory_tagging.patch
# missing include header files
Patch310: chromium-119-missing-header-files.patch
# clang warnings
Patch311: chromium-115-clang-warnings.patch
# imp module is removed in python-3.12
Patch312: chromium-118-python-3.12-deprecated.patch
# build error
Patch351: chromium-117-mnemonic-error.patch
# Workaround for https://bugzilla.redhat.com/show_bug.cgi?id=2239523
# https://bugs.chromium.org/p/chromium/issues/detail?id=1145581#c60
# Disable BTI until this is fixed upstream.
Patch352: chromium-117-workaround_for_crash_on_BTI_capable_system.patch
# upstream patches
Patch400: chromium-119-dont-redefine-ATSPI-version-macros.patch
# fix build error, nullptr_t without namespace std::
Patch401: chromium-119-nullptr_t-without-namespace-std.patch
# workaround for buggy Nvidia drivers fail to return FDs for planes
# of a BO which had already an imported BO destroyed before.
Patch402: chromium-119-nvidia-use-separate-bo-to-verify-modifier.patch
# hide UseChromeOSDirectVideoDecoder flag on VA-API devices to avoid crashes
Patch403: chromium-119-hide-UseChromeOSDirectVideoDecoder-flag-on-VA-API-devices.patch

Patch404:  fix-headers-ldflags.patch

Patch500: chromium-icu72-2.patch

# RISC-V Support
Patch1001: riscv-base.patch
Patch1002: riscv-build.patch
Patch1003: riscv-sandbox.patch
Patch1004: riscv-angle.patch
Patch1005: riscv-dav1d.patch
Patch1006: riscv-swiftshader.patch


# Use chromium-latest.py to generate clean tarball from released build tarballs, found here:
# https://commondatastorage.googleapis.com/chromium-browser-official/chromium-%%{version}.tar.xz
Source0: chromium-%{version}.tar.xz
Source2: chromium.conf
Source3: chromium-browser.sh
Source4: %{chromium_browser_channel}.desktop
Source5: chromium-browser.xml
Source6: chrome-remote-desktop@.service
Source7: master_preferences

# esbuild binary
%if 0%{?esbuild}
Source101: https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-%{esbuild_version}.tgz
Source102: https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-%{esbuild_version}.tgz
Source103: https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-%{esbuild_version}.tgz
%endif
 

%if %{clang}
BuildRequires: clang
BuildRequires: clang-tools-extra
BuildRequires: llvm
BuildRequires: lld
%else
BuildRequires: gcc-c++
BuildRequires: gcc
BuildRequires: binutils
%endif

BuildRequires: libicu-devel
# build with system ffmpeg-free
%if ! %{bundleffmpegfree}
BuildRequires: pkgconfig(libavcodec)
BuildRequires: pkgconfig(libavfilter)
BuildRequires: pkgconfig(libavformat)
BuildRequires: pkgconfig(libavutil)
BuildRequires: ffmpeg-devel
%endif

# build with system libaom
%if ! %{bundlelibaom}
BuildRequires: libaom-devel
%endif

BuildRequires: alsa-lib-devel
BuildRequires: atk-devel
BuildRequires: bison
BuildRequires: cups-devel
BuildRequires: dbus-devel
BuildRequires: desktop-file-utils
BuildRequires: expat-devel
BuildRequires: flex
BuildRequires: fontconfig-devel
BuildRequires: glib2-devel
BuildRequires: glibc-devel
BuildRequires: gperf
BuildRequires: snappy-devel
BuildRequires: pkgconfig(dri)
BuildRequires: pkgconfig(epoxy)

%if %{use_qt}
BuildRequires: pkgconfig(Qt5Core)
BuildRequires: pkgconfig(Qt5Widgets)
%endif

%if ! %{bundleharfbuzz}
BuildRequires: harfbuzz-devel >= 2.4.0
%endif

BuildRequires: libatomic
BuildRequires: libcap-devel
BuildRequires: libcurl-devel

%if ! %{bundlelibdrm}
BuildRequires: libdrm-devel
%endif

BuildRequires: libgcrypt-devel
BuildRequires: libudev-devel
BuildRequires: libuuid-devel
BuildRequires: libusb-devel
BuildRequires: libutempter-devel
BuildRequires: libXdamage-devel
BuildRequires: libXtst-devel
BuildRequires: xcb-proto
BuildRequires: mesa-libgbm-devel

%if ! %{bundlezlib}
BuildRequires: pkgconfig(zlib)  minizip-ng-devel
%endif

%if %{system_nodejs}
BuildRequires: nodejs
%endif

%if ! %{bootstrap}
BuildRequires: gn
%endif

BuildRequires: nss-devel >= 3.26
BuildRequires: pciutils-devel
BuildRequires: pulseaudio-libs-devel

# For screen sharing on Wayland
BuildRequires: pkgconfig(libpipewire-0.3)
# for /usr/bin/appstream-util
BuildRequires: libappstream-glib

%if %{bootstrap}
# gn needs these
BuildRequires: libstdc++-static
%endif

# Tries to use system libs whenever it can.
BuildRequires: bzip2-devel
BuildRequires: dbus-glib-devel
# For eu-strip
BuildRequires:  elfutils
BuildRequires:  elfutils-libelf-devel
BuildRequires:  flac-devel
BuildRequires:  pkgconfig(libexif)

BuildRequires:  pkgconfig(flac++)
BuildRequires:  pkgconfig(slang)
BuildRequires:  pkgconfig(theora)
BuildRequires:  pkgconfig(sqlite3)

%if ! %{bundlefreetype}
BuildRequires: freetype-devel
%endif
BuildRequires: git
BuildRequires: hwdata
BuildRequires: kernel-headers
BuildRequires: libevent-devel
BuildRequires: libffi-devel
BuildRequires: fdupes

%if ! %{bundlelibjpeg}
BuildRequires: libjpeg-devel
%endif

%if ! %{bundlelibpng}
BuildRequires: libpng-devel
%endif

BuildRequires: libudev-devel
%if ! %{bundlelibusbx}
Requires: libusbx >= 1.0.21-0.1.git448584a
BuildRequires: libusbx-devel >= 1.0.21-0.1.git448584a
%endif
%if %{use_vaapi}
BuildRequires: libva-devel
%endif

%if ! %{bundlelibwebp}
BuildRequires: libwebp-devel
%endif

%if ! %{bundlezstd}
BuildRequires: pkgconfig(libzstd)
%endif

BuildRequires: libxslt-devel
BuildRequires: libxshmfence-devel

BuildRequires: mesa-libGL-devel

%if ! %{bundleopus}
BuildRequires: opus-devel
%endif

BuildRequires:  perl(Switch)
BuildRequires:  python3
BuildRequires:  pkgconfig(gtk+-3.0)
BuildRequires:  python3-devel
BuildRequires:  python3-zipp
BuildRequires:  python3-simplejson
BuildRequires:  python3-importlib-metadata
BuildRequires:  python3-six

%if ! %{bundlepylibs}
BuildRequires: python3-beautifulsoup4
BuildRequires: python3-html5lib
BuildRequires: python3-markupsafe
BuildRequires: python3-ply
BuildRequires: python3-jinja2
%endif

%if ! %{bundlere2}
Requires: re2 >= 20160401
BuildRequires: re2-devel >= 20160401
%endif

%if ! %{bundlebrotli}
BuildRequires: brotli-devel
%endif

BuildRequires: speech-dispatcher-devel
BuildRequires: yasm
BuildRequires: zlib-devel

# remote desktop needs this
BuildRequires: pam-devel
BuildRequires: systemd

# using the built from source version on aarch64
BuildRequires: ninja-build

# Yes, java is needed as well..
%if %{build_headless}
BuildRequires: java-17-openjdk-headless
%endif

BuildRequires: libevdev-devel

BuildRequires: procps-ng

# There is a hardcoded check for nss 3.26 in the chromium code (crypto/nss_util.cc)
Requires: nss%{_isa} >= 3.26
Requires: nss-mdns%{_isa}

# GTK modules it expects to find for some reason.
%if %{gtk3}
Requires: libcanberra-gtk3%{_isa}
%else
Requires: libcanberra-gtk2%{_isa}
%endif

# This enables support for u2f tokens
Requires: u2f-hidraw-policy

Requires: chromium-common%{_isa} = %{version}-%{release}

ExclusiveArch: x86_64 aarch64 riscv64

# Bundled bits (I'm sure I've missed some)
Provides: bundled(angle) = 2422
Provides: bundled(bintrees) = 1.0.1
# This is a fork of openssl.
Provides: bundled(boringssl)

%if %{bundlebrotli}
Provides: bundled(brotli) = 222564a95d9ab58865a096b8d9f7324ea5f2e03e
%endif

Provides: bundled(bspatch)
Provides: bundled(cacheinvalidation) = 20150720
Provides: bundled(colorama) = 799604a104
Provides: bundled(crashpad)
Provides: bundled(dmg_fp)
Provides: bundled(expat) = 2.2.0
Provides: bundled(fdmlibm) = 5.3

# Don't get too excited. MPEG and other legally problematic stuff is stripped out.
%if %{bundleffmpegfree}
Provides: bundled(ffmpeg) = 6.0
%endif

%if %{bundlelibaom}
Provides: bundled(libaom)
%endif

Provides: bundled(fips181) = 2.2.3

%if %{bundlefontconfig}
Provides: bundled(fontconfig) = 2.12.6
%endif

%if %{bundlefreetype}
Provides: bundled(freetype) = 2.11.0git
%endif

Provides: bundled(gperftools) = svn144

%if %{bundleharfbuzz}
Provides: bundled(harfbuzz) = 2.4.0
%endif

Provides: bundled(hunspell) = 1.6.0
Provides: bundled(iccjpeg)

%if %{bundleicu}
Provides: bundled(icu)
%endif

Provides: bundled(kitchensink) = 1
Provides: bundled(leveldb) = 1.20
Provides: bundled(libaddressinput) = 0

%if %{bundlelibdrm}
Provides: bundled(libdrm) = 2.4.85
%endif

Provides: bundled(libevent) = 1.4.15
Provides: bundled(libjingle) = 9564

%if %{bundlelibjpeg}
Provides: bundled(libjpeg-turbo) = 1.4.90
%endif

Provides: bundled(libphonenumber) = a4da30df63a097d67e3c429ead6790ad91d36cf4

%if %{bundlelibpng}
Provides: bundled(libpng) = 1.6.22
%endif

Provides: bundled(libsrtp) = 2cbd85085037dc7bf2eda48d4cf62e2829056e2d

%if %{bundlelibusbx}
Provides: bundled(libusbx) = 1.0.17
%endif

Provides: bundled(libvpx) = 1.6.0

%if %{bundlelibwebp}
Provides: bundled(libwebp) = 0.6.0
%endif

%if %{bundlelibxml}
# Well, it's actually newer than 2.9.4 and has code in it that has been reverted upstream... but eh.
Provides: bundled(libxml) = 2.9.4
%endif

Provides: bundled(libXNVCtrl) = 302.17
Provides: bundled(libyuv) = 1651
Provides: bundled(lzma) = 15.14
Provides: bundled(libudis86) = 1.7.1
Provides: bundled(mesa) = 9.0.3
Provides: bundled(NSBezierPath) = 1.0
Provides: bundled(mozc)

%if %{bundleopus}
Provides: bundled(opus) = 1.1.3
%endif

Provides: bundled(ots) = 8d70cffebbfa58f67a5c3ed0e9bc84dccdbc5bc0
Provides: bundled(protobuf) = 3.0.0.beta.3
Provides: bundled(qcms) = 4

%if %{bundlere2}
Provides: bundled(re2)
%endif

Provides: bundled(sfntly) = 04740d2600193b14aa3ef24cd9fbb3d5996b9f77
Provides: bundled(skia)
Provides: bundled(SMHasher) = 0
Provides: bundled(snappy) = 1.1.4-head
Provides: bundled(speech-dispatcher) = 0.7.1
Provides: bundled(sqlite) = 3.17patched
Provides: bundled(superfasthash) = 0
Provides: bundled(talloc) = 2.0.1
Provides: bundled(usrsctp) = 0
Provides: bundled(v8) = 5.9.211.31
Provides: bundled(webrtc) = 90usrsctp
Provides: bundled(woff2) = 445f541996fe8376f3976d35692fd2b9a6eedf2d
Provides: bundled(xdg-mime)
Provides: bundled(xdg-user-dirs)
%if %{bundlezlib}
Provides: bundled(zlib)
%endif

# For selinux scriptlet
Requires(post): /usr/sbin/semanage
Requires(post): /usr/sbin/restorecon

%description
Chromium is an open-source web browser, powered by WebKit (Blink).

%package common
Summary: Files needed for both the headless_shell and full Chromium

# -common doesn't have chrome-remote-desktop bits
# but we need to clean it up if it gets disabled again
# NOTE: Check obsoletes version to be sure it matches
%if ! %{build_remoting}
Provides: chrome-remote-desktop = %{version}-%{release}
Obsoletes: chrome-remote-desktop <= 81.0.4044.138
%endif

%description common
%{summary}.

%if %{build_remoting}
%package -n chrome-remote-desktop
Requires(pre): shadow-utils
Requires(post): systemd
Requires(preun): systemd
Requires(postun): systemd
Requires: xorg-x11-server-Xvfb
Requires: python3-psutil
Requires: chromium-common%{_isa} = %{version}-%{release}
Summary: Remote desktop support for google-chrome & chromium

%description -n chrome-remote-desktop
Remote desktop support for google-chrome & chromium.
%endif

%package -n chromedriver
Summary: WebDriver for Google Chrome/Chromium
Requires: chromium-common%{_isa} = %{version}-%{release}

%description -n chromedriver
WebDriver is an open source tool for automated testing of webapps across many
browsers. It provides capabilities for navigating to web pages, user input,
JavaScript execution, and more. ChromeDriver is a standalone server which
implements WebDriver's wire protocol for Chromium. It is being developed by
members of the Chromium and WebDriver teams.

%package headless
Summary: A minimal headless shell built from Chromium
Requires: chromium-common%{_isa} = %{version}-%{release}

%description headless
A minimal headless client built from Chromium. headless_shell is built
without support for alsa, cups, dbus, gconf, gio, kerberos, pulseaudio, or 
udev.

%prep
# download source0
cd %{_sourcedir}
rm -f %{SOURCE0}
wget https://user-repo.openeuler.openatom.cn/lfs-tar/chromium/chromium-%{version}.tar.xz
cd -

#%{__cat} %{SOURCE101} %{SOURCE102} %{SOURCE103} %{SOURCE104} %{SOURCE105} > %{SOURCE0}

%setup -q -n chromium-%{version}

### Chromium Patches ###
%patch -P0 -p1 -b .sandboxpie
%patch -P1 -p1 -b .etc
%patch -P2 -p1 -b .system-libusb
%patch -P5 -p1 -b .nozlibmangle
%patch -P6 -p1 -b .nounrar
%patch -P8 -p1 -b .widevine-other-locations
%patch -P11 -p1 -b .py3
%patch -P20 -p1 -b .disable-font-test
%if ! %{bundlezlib}
%patch -P52 -p1 -b .unbundle-zlib
%patch -P61 -p1 -b .system-minizip
%endif
%patch -P65 -p1 -b .java-only-allowed
%patch -P69 -p1 -b .update-rjsmin-to-1.2.0
%patch -P70 -p1 -b .update-six-to-1.16.0
%patch -P82 -p1 -b .remoting-no-tests
%if ! %{bundlebrotli}
%patch -P89 -p1 -b .system-brotli
%endif
%patch -P90 -p1 -b .disable-GlobalMediaControlsCastStartStop
%if ! %{bundleopus}
%patch -P91 -p1 -b .system-opus
%endif
%if ! %{bundleffmpegfree}
%patch -P114 -p1 -b .ffmpeg-5.x-duration
%patch -P116 -p1 -b .first_dts
%patch -P115 -p1 -b .prop-codecs
%patch -P117 -p1 -b .sigtrap_system_ffmpeg
%endif
%patch -P140 -p1 -b .dma_buf_export_sync_file-conflict
%patch -P130 -p1 -b .revert-av1enc

%if ! %{bundlezstd}
%patch -P200 -p1 -b .system-zstd
%endif

%if %{clang}
%patch -P300 -p1 -b .no_matching_constructor
%patch -P301 -p1 -b .workaround_clang-SkColor4f
%patch -P302 -p1 -b .workaround_clang_bug-structured_binding
%patch -P303 -p1 -b .typename
%patch -P304 -p1 -b .string-convert
%patch -P305 -p1 -b .constexpr
%patch -P306 -p1 -b .assert
%endif

%ifarch aarch64
%patch -P307 -p1 -b .memory_tagging
%endif

%patch -P310 -p1 -b .missing-header-files
%patch -P311 -p1 -b .clang-warnings

%if 0%{?python312}
%patch -P312 -p1 -b .python-3.12-deprecated
%endif

%patch -P351 -p1 -b .mnemonic-error

%if %{disable_bti}
%patch -P352 -p1 -b .workaround_for_crash_on_BTI_capable_system
%endif

%patch -P400 -p1 -R -b .revert-dont-redefine-ATSPI-version-macros
%patch -P401 -p1 -b .nullptr_t-without-namespace-std
%patch -P402 -p1 -b .nvidia-use-separate-bo-to-verify-modifiers
%patch -P403 -p1 -b .UseChromeOSDirectVideoDecoder-flag-on-VA-API-devices
%patch -P404 -p1 -b .fix-headers-ldflags

%patch -P500 -p1 -b .icu72-2

# riscv patch

%patch -P1001 -p1 -b .riscv-base
%patch -P1002 -p1 -b .riscv-build
%patch -P1003 -p1 -b .riscv-sandbox
%patch -P1004 -p1 -b .riscv-angle
%patch -P1005 -p1 -b .riscv-dav1d
%patch -P1006 -p1 -b .riscv-swiftshader

# Change shebang in all relevant files in this directory and all subdirectories
# See `man find` for how the `-exec command {} +` syntax works
find -type f \( -iname "*.py" \) -exec sed -i '1s=^#! */usr/bin/\(python\|env python\)[23]\?=#!%{__python3}=' {} +

%if %{bundlelibusbx}
# no hackity hack hack
%else
# hackity hack hack
rm -rf third_party/libusb/src/libusb/libusb.h
# we _shouldn't need to do this, but it looks like we do.
cp -a %{_includedir}/libusb-1.0/libusb.h third_party/libusb/src/libusb/libusb.h
%endif

# Hard code extra version
sed -i 's/getenv("CHROME_VERSION_EXTRA")/"openEuler Project"/' chrome/common/channel_info_posix.cc

# Fix hardcoded path in remoting code
sed -i 's|/opt/google/chrome-remote-desktop|%{crd_path}|g' remoting/host/setup/daemon_controller_delegate_linux.cc

# change moc to moc-qt5 for
sed -i 's|moc|moc-qt5|g' ui/qt/moc_wrapper.py

	
# Get rid of the bundled esbuild


%build
%if ! %{esbuild}
  ln -sf %{_bindir}/esbuild third_party/devtools-frontend/src/third_party/esbuild/esbuild
%else
  %ifarch x86_64
    tar -zxf %{SOURCE101} --directory %{_tmppath}
  %endif
  %ifarch aarch64
    tar -zxf %{SOURCE102} --directory %{_tmppath}
  %endif
  %ifarch riscv64
    tar -zxf %{SOURCE103} --directory %{_tmppath}
  %endif
  mv %{_tmppath}/package/bin/esbuild third_party/devtools-frontend/src/third_party/esbuild/esbuild
%endif
 
#correct path for nodejs binary
mkdir -p third_party/node/linux/node-linux-x64/bin
ln -s %{_bindir}/node third_party/node/linux/node-linux-x64/bin/node

# Get rid of the pre-built eu-strip binary, it is x86_64 and of mysterious origin
rm -rf buildtools/third_party/eu-strip/bin/eu-strip
# Replace it with a symlink to  copy
ln -s %{_bindir}/eu-strip buildtools/third_party/eu-strip/bin/eu-strip


# python3
mkdir -p $HOME/bin
export PYTHON=python3
ln -sfn %{_bindir}/$PYTHON $HOME/bin/python
export PATH="$HOME/bin/:$PATH"

# REDUCE DEBUG as it gets TOO large
ARCH_FLAGS="`echo %{optflags} | sed -e 's/^-g / /g' -e 's/ -g / /g' -e 's/ -g$//g'`"
export CXXFLAGS="${ARCH_FLAGS} -Wno-return-type"
# extra flags to reduce warnings that aren't very useful
export CXXFLAGS="${CXXFLAGS} -Wno-pedantic -Wno-unused-result -Wno-unused-function -Wno-unused-variable -Wno-deprecated-declarations"
# ignore warnings for minor mistakes that are too common
export CXXFLAGS="${CXXFLAGS} -Wno-return-type -Wno-parentheses -Wno-misleading-indentation"
# ignore warnings that are not supported well until gcc 8
export CXXFLAGS="${CXXFLAGS} -Wno-attributes"
# ignore warnings due to gcc bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84055)
export CXXFLAGS="${CXXFLAGS} -Wno-ignored-attributes"
# ingore new gcc 8 warnings that aren't yet handled upstream
export CXXFLAGS="${CXXFLAGS} -Wno-address -Wno-dangling-else -D_GNU_SOURCE"
# for wayland
export CXXFLAGS="${CXXFLAGS} -I/usr/include/wayland -I/usr/include/libxkbcommon -I/usr/include/opus"


%if %{clang}
export CC=clang
export CXX=clang++
export AR=llvm-ar
export NM=llvm-nm
export READELF=llvm-readelf
export LDFLAGS="${LDFLAGS} -Wl,--build-id=sha1"
export CXXFLAGS="${CXXFLAGS} -Wno-unused-command-line-argument -Wno-unknown-warning-option"
%define __strip /usr/bin/llvm-strip
%if 0%{?enable_thin_lto}
# reduce the threads for linking even more due to LTO eating ton of memory
_link_threads=$(((%{jobs} - 2)))
test "$_link_threads" -le 0 && _link_threads=1
export LDFLAGS="-flto=$_link_threads --param lto-max-streaming-parallelism=1"
%endif
%else
export CC=gcc
export CXX=g++
export AR=ar
export NM=nm
export READELF=readelf
%endif

%ifarch aarch64
%if %{clang}
export CXXFLAGS="${CXXFLAGS} -flax-vector-conversions=all"
%else
export CXXFLAGS="${CXXFLAGS} -flax-vector-conversions -fno-omit-frame-pointer"
%endif
%endif

# Core defines are flags that are true for both the browser and headless.
CHROMIUM_CORE_GN_DEFINES=""
# using system toolchain
CHROMIUM_CORE_GN_DEFINES+=' custom_toolchain="//build/toolchain/linux/unbundle:default"'
CHROMIUM_CORE_GN_DEFINES+=' host_toolchain="//build/toolchain/linux/unbundle:default"'
CHROMIUM_CORE_GN_DEFINES+=' is_debug=false dcheck_always_on=false dcheck_is_configurable=false'
CHROMIUM_CORE_GN_DEFINES+=' use_goma=false'
CHROMIUM_CORE_GN_DEFINES+=' enable_nacl=false'
CHROMIUM_CORE_GN_DEFINES+=' system_libdir="%{_lib}"'

%if %{official_build}
CHROMIUM_CORE_GN_DEFINES+=' is_official_build=true is_cfi=false chrome_pgo_phase=0 use_debug_fission=true'
sed -i 's|OFFICIAL_BUILD|GOOGLE_CHROME_BUILD|g' tools/generate_shim_headers/generate_shim_headers.py
%endif

%if %{useapikey}
CHROMIUM_CORE_GN_DEFINES+=' google_api_key="%{api_key}"'
%endif

%if %{clang}
CHROMIUM_CORE_GN_DEFINES+=' is_clang=true'
CHROMIUM_CORE_GN_DEFINES+=' clang_base_path="%{_prefix}"'
CHROMIUM_CORE_GN_DEFINES+=' clang_use_chrome_plugins=false'
CHROMIUM_CORE_GN_DEFINES+=' use_lld=true'
%if %{enable_thin_lto}
CHROMIUM_CORE_GN_DEFINES+=" use_thin_lto=true"
%else
CHROMIUM_CORE_GN_DEFINES+=" use_thin_lto=false"
%endif
%else
CHROMIUM_CORE_GN_DEFINES+=' is_clang=false'
CHROMIUM_CORE_GN_DEFINES+=' use_lld=false'
%endif

# disable rust, it's only using for testing
CHROMIUM_CORE_GN_DEFINES+=' enable_rust=false'

CHROMIUM_CORE_GN_DEFINES+=' use_sysroot=false disable_fieldtrial_testing_config=true rtc_enable_symbol_export=true'

%if %{use_gold}
CHROMIUM_CORE_GN_DEFINES+=' use_gold=true'
%else
CHROMIUM_CORE_GN_DEFINES+=' use_gold=false'
%endif

%ifarch x86_64
CHROMIUM_CORE_GN_DEFINES+=' host_cpu="x64"'
%endif
%ifarch aarch64
CHROMIUM_CORE_GN_DEFINES+=' host_cpu="arm64"'
%endif
%ifarch riscv64
CHROMIUM_CORE_GN_DEFINES+=' host_cpu="riscv64"'
%endif

%if ! %{bundleicu}
CHROMIUM_CORE_GN_DEFINES+=' icu_use_data_file=false'
%endif
CHROMIUM_CORE_GN_DEFINES+=' target_os="linux"'
CHROMIUM_CORE_GN_DEFINES+=' current_os="linux"'
CHROMIUM_CORE_GN_DEFINES+=' treat_warnings_as_errors=false'
CHROMIUM_CORE_GN_DEFINES+=' use_custom_libcxx=false'
CHROMIUM_CORE_GN_DEFINES+=' enable_iterator_debugging=false'
CHROMIUM_CORE_GN_DEFINES+=' enable_vr=false'
CHROMIUM_CORE_GN_DEFINES+=' build_dawn_tests=false enable_perfetto_unittests=false'
CHROMIUM_CORE_GN_DEFINES+=' disable_fieldtrial_testing_config=true'
CHROMIUM_CORE_GN_DEFINES+=' symbol_level=1'
CHROMIUM_CORE_GN_DEFINES+=' blink_symbol_level=%{debug_level}  v8_symbol_level=%{debug_level}'
CHROMIUM_CORE_GN_DEFINES+=' blink_enable_generated_code_formatting=false'
CHROMIUM_CORE_GN_DEFINES+=' angle_has_histograms=false'
CHROMIUM_CORE_GN_DEFINES+=' optimize_webui=false'
CHROMIUM_CORE_GN_DEFINES+=' enable_reading_list=false'
CHROMIUM_CORE_GN_DEFINES+=' fatal_linker_warnings=false'
CHROMIUM_CORE_GN_DEFINES+=' use_allocator_shim=true'
CHROMIUM_CORE_GN_DEFINES+=' use_partition_alloc=true'
CHROMIUM_CORE_GN_DEFINES+=' use_unofficial_version_number=false'

%if ! %{bundleharfbuzz}
CHROMIUM_CORE_GN_DEFINES+=" use_system_harfbuzz=true"
%endif

%if ! %{bundlefreetype}
CHROMIUM_CORE_GN_DEFINES+=" use_system_freetype=true"
%endif

%if 0%{?enable_swiftshader}
CHROMIUM_CORE_GN_DEFINES+=" use_swiftshader_with_subzero=true"
%endif

export CHROMIUM_CORE_GN_DEFINES

# browser gn defines
CHROMIUM_BROWSER_GN_DEFINES=""

# if systemwide ffmpeg free is used, the proprietary codecs can be set to true to load the codecs from ffmpeg-free
# the codecs computation is passed to ffmpeg-free in this case
%if ! %{bundleffmpegfree}
CHROMIUM_BROWSER_GN_DEFINES+=' ffmpeg_branding="Chrome" proprietary_codecs=true is_component_ffmpeg=true enable_ffmpeg_video_decoders=true media_use_ffmpeg=true'
%else
CHROMIUM_BROWSER_GN_DEFINES+=' ffmpeg_branding="Chromium" proprietary_codecs=true  is_component_ffmpeg=true enable_ffmpeg_video_decoders=true media_use_ffmpeg=true'
%endif
CHROMIUM_BROWSER_GN_DEFINES+=' media_use_openh264=false'
CHROMIUM_BROWSER_GN_DEFINES+=' rtc_use_h264=false'
CHROMIUM_BROWSER_GN_DEFINES+=' use_kerberos=true'

%if %{use_qt}
CHROMIUM_BROWSER_GN_DEFINES+=' use_qt=true'
%else
CHROMIUM_BROWSER_GN_DEFINES+=' use_qt=false'
%endif

CHROMIUM_BROWSER_GN_DEFINES+=' use_gio=true use_pulseaudio=true link_pulseaudio=true'
CHROMIUM_BROWSER_GN_DEFINES+=' enable_hangout_services_extension=true'
CHROMIUM_BROWSER_GN_DEFINES+=' use_aura=true'
CHROMIUM_BROWSER_GN_DEFINES+=' enable_widevine=true'

%if %{use_vaapi}
CHROMIUM_BROWSER_GN_DEFINES+=' use_vaapi=true'
%else
CHROMIUM_BROWSER_GN_DEFINES+=' use_vaapi=false'
%endif

%if %{use_v4l2_codec}
CHROMIUM_BROWSER_GN_DEFINES+=' use_v4l2_codec=true'
%endif

CHROMIUM_BROWSER_GN_DEFINES+=' rtc_use_pipewire=true rtc_link_pipewire=true'
CHROMIUM_BROWSER_GN_DEFINES+=' use_system_libffi=true'
CHROMIUM_BROWSER_GN_DEFINES+=' use_cups=true'
CHROMIUM_BROWSER_GN_DEFINES+=' use_dbus=true'
export CHROMIUM_BROWSER_GN_DEFINES

# headless gn defines
CHROMIUM_HEADLESS_GN_DEFINES=""
CHROMIUM_HEADLESS_GN_DEFINES+=' use_ozone=true ozone_auto_platforms=false ozone_platform="headless" ozone_platform_headless=true'
CHROMIUM_HEADLESS_GN_DEFINES+=' angle_enable_vulkan=true angle_enable_swiftshader=true headless_use_embedded_resources=false'
CHROMIUM_HEADLESS_GN_DEFINES+=' headless_use_prefs=false headless_use_policy=false'
CHROMIUM_HEADLESS_GN_DEFINES+=' v8_use_external_startup_data=false enable_print_preview=false enable_remoting=false'
CHROMIUM_HEADLESS_GN_DEFINES+=' use_alsa=false use_bluez=false use_cups=false use_dbus=false use_gio=false use_kerberos=false'
CHROMIUM_HEADLESS_GN_DEFINES+=' use_libpci=false use_pulseaudio=false use_udev=false rtc_use_pipewire=false'
CHROMIUM_HEADLESS_GN_DEFINES+=' v8_enable_lazy_source_positions=false use_glib=false use_gtk=false use_pangocairo=false'
CHROMIUM_HEADLESS_GN_DEFINES+=' use_qt=false is_component_build=false enable_ffmpeg_video_decoders=false media_use_ffmpeg=false'
CHROMIUM_HEADLESS_GN_DEFINES+=' media_use_libvpx=false proprietary_codecs=false'
export CHROMIUM_HEADLESS_GN_DEFINES

build/linux/unbundle/replace_gn_files.py --system-libraries \
	libevent \
	snappy \
%if ! %{bundlelibaom}
	libaom \
%endif
%if ! %{bundlezstd}
	zstd \
%endif
%if ! %{bundlebrotli}
	brotli \
%endif
%if ! %{bundlefontconfig}
	fontconfig \
%endif
%if ! %{bundleffmpegfree}
	ffmpeg \
%endif
%if ! %{bundlefreetype}
	freetype \
%endif
%if ! %{bundleharfbuzz}
	harfbuzz-ng \
%endif
%if ! %{bundleicu}
	icu \
%endif
%if ! %{bundlelibdrm}
	libdrm \
%endif
%if ! %{bundlelibjpeg}
	libjpeg \
%endif
%if ! %{bundlelibpng}
	libpng \
%endif
%if ! %{bundlelibusbx}
	libusb \
%endif
%if ! %{bundlelibwebp}
	libwebp \
%endif
%if ! %{bundlelibxml}
	libxml \
%endif
	libxslt \
%if ! %{bundleopus}
	opus \
%endif
%if ! %{bundlere2}
	re2 \
%endif
%if ! %{bundlezlib}
	zlib \
%endif
	flac

# Check that there is no system 'google' module, shadowing bundled ones:
if python3 -c 'import google ; print google.__path__' 2> /dev/null ; then \
    echo "Python 3 'google' module is defined, this will shadow modules of this build"; \
    exit 1 ; \
fi

%if %{bootstrap}
tools/gn/bootstrap/bootstrap.py --gn-gen-args="$CHROMIUM_CORE_GN_DEFINES $CHROMIUM_BROWSER_GN_DEFINES"
%else
mkdir -p %{builddir} && cp -a %{_bindir}/gn %{builddir}/
%endif

%{builddir}/gn --script-executable=python3 gen --args="$CHROMIUM_CORE_GN_DEFINES $CHROMIUM_BROWSER_GN_DEFINES" %{builddir}

%if %{build_headless}
%{builddir}/gn --script-executable=python3 gen --args="$CHROMIUM_CORE_GN_DEFINES $CHROMIUM_HEADLESS_GN_DEFINES" %{headlessbuilddir}
%endif

%if %{build_remoting}
%{builddir}/gn --script-executable=python3 gen --args="$CHROMIUM_CORE_GN_DEFINES $CHROMIUM_BROWSER_GN_DEFINES" %{remotingbuilddir}
%endif

%if %{build_headless}
# Do headless first.
%build_target %{headlessbuilddir} headless_shell
%endif

%build_target %{builddir} chrome
%build_target %{builddir} chrome_sandbox
%build_target %{builddir} chromedriver

%if %{build_clear_key_cdm}
%build_target %{builddir} clear_key_cdm
%endif

%build_target %{builddir} policy_templates

%if %{build_remoting}
# remote client
# ninja -C ../%{builddir} -vvv remoting_me2me_host remoting_start_host remoting_it2me_native_messaging_host remoting_me2me_native_messaging_host remoting_native_messaging_manifests remoting_resources
%build_target %{remotingbuilddir} remoting_all
%endif

%install
rm -rf %{buildroot}

mkdir -p %{buildroot}%{_bindir} \
         %{buildroot}%{chromium_path}/locales \
         %{buildroot}%{_sysconfdir}/%{name}

# install system wide chromium config
%ifnarch riscv64
cp -a %{SOURCE2} %{buildroot}%{_sysconfdir}/%{name}/%{name}.conf
%endif
cp -a %{SOURCE3} %{buildroot}%{chromium_path}/%{chromium_browser_channel}.sh
chmod +x %{buildroot}%{chromium_path}/%{chromium_browser_channel}.sh

%if ! %{use_vaapi}
# remove vaapi flags
echo "# system wide chromium flags" > %{buildroot}%{_sysconfdir}/%{name}/%{name}.conf
%endif

export BUILD_TARGET=`cat /etc/openEuler-release`
export CHROMIUM_PATH=%{chromium_path}
export CHROMIUM_BROWSER_CHANNEL=%{chromium_browser_channel}

sed -i "s|@@BUILD_TARGET@@|$BUILD_TARGET|g" %{buildroot}%{chromium_path}/%{chromium_browser_channel}.sh
sed -i "s|@@CHROMIUM_PATH@@|$CHROMIUM_PATH|g" %{buildroot}%{chromium_path}/%{chromium_browser_channel}.sh
sed -i "s|@@CHROMIUM_BROWSER_CHANNEL@@|$CHROMIUM_BROWSER_CHANNEL|g" %{buildroot}%{chromium_path}/%{chromium_browser_channel}.sh

%if "%{chromium_channel}" == "%{nil}"
	sed -i "s|@@EXTRA_FLAGS@@||g" %{buildroot}%{chromium_path}/%{chromium_browser_channel}.sh
%else
	# Enable debug outputs for beta and dev channels
	export EXTRA_FLAGS="--enable-logging=stderr --v=2"
	sed -i "s|@@EXTRA_FLAGS@@|$EXTRA_FLAGS|g" %{buildroot}%{chromium_path}/%{chromium_browser_channel}.sh
%endif

ln -s ../..%{chromium_path}/%{chromium_browser_channel}.sh %{buildroot}%{_bindir}/%{chromium_browser_channel}
mkdir -p %{buildroot}%{_mandir}/man1/

pushd %{builddir}
	cp -a chrom*.pak resources.pak icudtl.dat %{buildroot}%{chromium_path}
	cp -a locales/*.pak %{buildroot}%{chromium_path}/locales/
	%ifarch x86_64 aarch64 riscv64
		cp -a libvk_swiftshader.so %{buildroot}%{chromium_path}
		cp -a libvulkan.so.1 %{buildroot}%{chromium_path}
		cp -a vk_swiftshader_icd.json %{buildroot}%{chromium_path}
	%endif
	cp -a chrome %{buildroot}%{chromium_path}/%{chromium_browser_channel}
	cp -a chrome_sandbox %{buildroot}%{chromium_path}/chrome-sandbox
	cp -a chrome_crashpad_handler %{buildroot}%{chromium_path}/chrome_crashpad_handler
	cp -a ../../chrome/app/resources/manpage.1.in %{buildroot}%{_mandir}/man1/%{chromium_browser_channel}.1
	sed -i "s|@@PACKAGE@@|%{chromium_browser_channel}|g" %{buildroot}%{_mandir}/man1/%{chromium_browser_channel}.1
	sed -i "s|@@MENUNAME@@|%{chromium_menu_name}|g" %{buildroot}%{_mandir}/man1/%{chromium_browser_channel}.1

	# V8 initial snapshots
	# https://code.google.com/p/chromium/issues/detail?id=421063
	cp -a v8_context_snapshot.bin %{buildroot}%{chromium_path}

	# This is ANGLE, not to be confused with the similarly named files under swiftshader/
	cp -a libEGL.so libGLESv2.so %{buildroot}%{chromium_path}

	%if %{use_qt}
		cp -a libqt5_shim.so %{buildroot}%{chromium_path}
	%endif

	%if %{build_clear_key_cdm}
		%ifarch x86_64
			cp -a ClearKeyCdm/_platform_specific/linux_x64/libclearkeycdm.so %{buildroot}%{chromium_path}
		%endif
		%ifarch aarch64
			cp -a ClearKeyCdm/_platform_specific/linux_arm64/libclearkeycdm.so %{buildroot}%{chromium_path}
		%endif
		%ifarch riscv64
			cp -a ClearKeyCdm/_platform_specific/linux_riscv64/libclearkeycdm.so %{buildroot}%{chromium_path}
		%endif
		%ifnarch x86_64 aarch64 riscv64
			cp -a libclearkeycdm.so %{buildroot}%{chromium_path}
		%endif
	%endif

	# chromedriver
	cp -a chromedriver %{buildroot}%{chromium_path}/chromedriver
	ln -s ../..%{chromium_path}/chromedriver %{buildroot}%{_bindir}/chromedriver

	%if %{build_remoting}
		# Remote desktop bits
		mkdir -p %{buildroot}%{crd_path}
	%endif
popd

%if %{build_remoting}
	pushd %{remotingbuilddir}
		# Hey, there is a library now.
		cp -a libremoting_core.so %{buildroot}%{crd_path}/

		# See remoting/host/installer/linux/Makefile for logic
		mkdir -p %{buildroot}%{crd_path}/remoting_locales
		cp -a remoting_native_messaging_host %{buildroot}%{crd_path}/native-messaging-host
		cp -a remote_assistance_host %{buildroot}%{crd_path}/remote-assistance-host
		cp -a remoting_locales/*.pak %{buildroot}%{crd_path}/remoting_locales/
		cp -a remoting_me2me_host %{buildroot}%{crd_path}/chrome-remote-desktop-host
		cp -a remoting_start_host %{buildroot}%{crd_path}/start-host
		cp -a remoting_user_session %{buildroot}%{crd_path}/user-session
		chmod +s %{buildroot}%{crd_path}/user-session

		# chromium
		mkdir -p %{buildroot}%{_sysconfdir}/chromium/native-messaging-hosts
		# google-chrome
		mkdir -p %{buildroot}%{_sysconfdir}/opt/chrome/
		cp -a remoting/* %{buildroot}%{_sysconfdir}/chromium/native-messaging-hosts/
		for i in %{buildroot}%{_sysconfdir}/chromium/native-messaging-hosts/*.json; do
			sed -i 's|/opt/google/chrome-remote-desktop|%{crd_path}|g' $i
		done
		mkdir -p %{buildroot}%{_sysconfdir}/opt/chrome/native-messaging-hosts
		pushd %{buildroot}%{_sysconfdir}/opt/chrome/native-messaging-hosts
			for i in ../../../chromium/native-messaging-hosts/*; do
				# rpm gets unhappy when we symlink here
				cp -a $i .
			done
		popd
	popd

	mkdir -p %{buildroot}/var/lib/chrome-remote-desktop
	touch %{buildroot}/var/lib/chrome-remote-desktop/hashes

	mkdir -p %{buildroot}%{_sysconfdir}/pam.d/
	pushd %{buildroot}%{_sysconfdir}/pam.d/
		ln -s system-auth chrome-remote-desktop
	popd

   cp -a remoting/host/linux/linux_me2me_host.py %{buildroot}%{crd_path}/chrome-remote-desktop
   cp -a remoting/host/installer/linux/is-remoting-session %{buildroot}%{crd_path}/

   mkdir -p %{buildroot}%{_unitdir}
   cp -a %{SOURCE6} %{buildroot}%{_unitdir}/
   sed -i 's|@@CRD_PATH@@|%{crd_path}|g' %{buildroot}%{_unitdir}/chrome-remote-desktop@.service
%endif

%if %{build_headless}
	pushd %{headlessbuilddir}
		cp -a headless_lib_data.pak headless_lib_strings.pak headless_shell %{buildroot}%{chromium_path}
	popd
%endif

# need to strip binaries explicitly when debug is disable
%if ! %{enable_debug}
pushd %{buildroot}%{chromium_path}/
for f in *.so chrome_crashpad_handler chrome-sandbox chromium-browser headless_shell chromedriver chrome; do
   [ -f $f ] && %{__strip} $f
done
popd
%endif

# Add directories for policy management
mkdir -p %{buildroot}%{_sysconfdir}/chromium/policies/managed
mkdir -p %{buildroot}%{_sysconfdir}/chromium/policies/recommended

cp -a out/Release/gen/chrome/app/policy/common/html/en-US/*.html .
cp -a out/Release/gen/chrome/app/policy/linux/examples/chrome.json .

mkdir -p %{buildroot}%{_datadir}/icons/hicolor/256x256/apps
cp -a chrome/app/theme/chromium/product_logo_256.png %{buildroot}%{_datadir}/icons/hicolor/256x256/apps/%{chromium_browser_channel}.png
mkdir -p %{buildroot}%{_datadir}/icons/hicolor/128x128/apps
cp -a chrome/app/theme/chromium/product_logo_128.png %{buildroot}%{_datadir}/icons/hicolor/128x128/apps/%{chromium_browser_channel}.png
mkdir -p %{buildroot}%{_datadir}/icons/hicolor/64x64/apps
cp -a chrome/app/theme/chromium/product_logo_64.png %{buildroot}%{_datadir}/icons/hicolor/64x64/apps/%{chromium_browser_channel}.png
mkdir -p %{buildroot}%{_datadir}/icons/hicolor/48x48/apps
cp -a chrome/app/theme/chromium/product_logo_48.png %{buildroot}%{_datadir}/icons/hicolor/48x48/apps/%{chromium_browser_channel}.png
mkdir -p %{buildroot}%{_datadir}/icons/hicolor/24x24/apps
cp -a chrome/app/theme/chromium/product_logo_24.png %{buildroot}%{_datadir}/icons/hicolor/24x24/apps/%{chromium_browser_channel}.png

# Install the master_preferences file
install -m 0644 %{SOURCE7} %{buildroot}%{_sysconfdir}/%{name}/

mkdir -p %{buildroot}%{_datadir}/applications/
desktop-file-install --dir %{buildroot}%{_datadir}/applications %{SOURCE4}

install -D -m0644 chrome/installer/linux/common/chromium-browser/chromium-browser.appdata.xml \
  ${RPM_BUILD_ROOT}%{_datadir}/metainfo/%{chromium_browser_channel}.appdata.xml
appstream-util validate-relax --nonet ${RPM_BUILD_ROOT}%{_datadir}/metainfo/%{chromium_browser_channel}.appdata.xml

mkdir -p %{buildroot}%{_datadir}/gnome-control-center/default-apps/
cp -a %{SOURCE5} %{buildroot}%{_datadir}/gnome-control-center/default-apps/


%post
# Set SELinux labels - semanage itself will adjust the lib directory naming
# But only do it when selinux is enabled, otherwise, it gets noisy.
if selinuxenabled; then
	semanage fcontext -a -t bin_t /usr/lib/%{chromium_browser_channel} &>/dev/null || :
	semanage fcontext -a -t bin_t /usr/lib/%{chromium_browser_channel}/%{chromium_browser_channel}.sh &>/dev/null || :
	semanage fcontext -a -t chrome_sandbox_exec_t /usr/lib/chrome-sandbox &>/dev/null || :
	restorecon -R -v %{chromium_path}/%{chromium_browser_channel} &>/dev/null || :
fi

%if %{build_remoting}
%pretrans -n chrome-remote-desktop -p <lua> 
path = "/etc/opt/chrome/native-messaging-hosts"
st = posix.stat(path)
if st and st.type == "link" then
  os.remove(path)
end
%endif

%if %{build_remoting}
%pre -n chrome-remote-desktop
getent group chrome-remote-desktop >/dev/null || groupadd -r chrome-remote-desktop

%post -n chrome-remote-desktop
%systemd_post chrome-remote-desktop@.service

%preun -n chrome-remote-desktop
%systemd_preun chrome-remote-desktop@.service

%postun -n chrome-remote-desktop
%systemd_postun_with_restart chrome-remote-desktop@.service
%endif

%files
%doc chrome_policy_list.html *.json
%license LICENSE
%config(noreplace) %{_sysconfdir}/%{name}/chromium.conf
%config %{_sysconfdir}/%{name}/master_preferences
%config %{_sysconfdir}/%{name}/policies/
%if %{build_remoting}
%exclude %{_sysconfdir}/%{name}/native-messaging-hosts/*
%endif
%{_bindir}/%{chromium_browser_channel}
%{chromium_path}/*.bin
%{chromium_path}/chrome_*.pak
%{chromium_path}/chrome_crashpad_handler
%{chromium_path}/resources.pak
%{chromium_path}/%{chromium_browser_channel}
%{chromium_path}/%{chromium_browser_channel}.sh
%attr(4755, root, root) %{chromium_path}/chrome-sandbox
%if %{use_qt}
%{chromium_path}/libqt5_shim.so
%endif
%{_mandir}/man1/%{chromium_browser_channel}.*
%{_datadir}/icons/hicolor/*/apps/%{chromium_browser_channel}.png
%{_datadir}/applications/*.desktop
%{_datadir}/metainfo/*.appdata.xml
%{_datadir}/gnome-control-center/default-apps/chromium-browser.xml

%files common
%if %{build_clear_key_cdm}
%{chromium_path}/libclearkeycdm.so
%endif
%ifarch x86_64 aarch64 riscv64
%{chromium_path}/libvk_swiftshader.so*
%{chromium_path}/libvulkan.so*
%{chromium_path}/vk_swiftshader_icd.json
%{chromium_path}/libEGL.so*
%{chromium_path}/libGLESv2.so*
%endif
%{chromium_path}/icudtl.dat
%dir %{chromium_path}/
%dir %{chromium_path}/locales/
%lang(af) %{chromium_path}/locales/af.pak
%lang(am) %{chromium_path}/locales/am.pak
%lang(ar) %{chromium_path}/locales/ar.pak
%lang(bg) %{chromium_path}/locales/bg.pak
%lang(bn) %{chromium_path}/locales/bn.pak
%lang(ca) %{chromium_path}/locales/ca.pak
%lang(cs) %{chromium_path}/locales/cs.pak
%lang(da) %{chromium_path}/locales/da.pak
%lang(de) %{chromium_path}/locales/de.pak
%lang(el) %{chromium_path}/locales/el.pak
%lang(en_GB) %{chromium_path}/locales/en-GB.pak
# Chromium _ALWAYS_ needs en-US.pak as a fallback
# This means we cannot apply the lang code here.
# Otherwise, it is filtered out on install.
%{chromium_path}/locales/en-US.pak
%lang(es) %{chromium_path}/locales/es.pak
%lang(es) %{chromium_path}/locales/es-419.pak
%lang(et) %{chromium_path}/locales/et.pak
%lang(fa) %{chromium_path}/locales/fa.pak
%lang(fi) %{chromium_path}/locales/fi.pak
%lang(fil) %{chromium_path}/locales/fil.pak
%lang(fr) %{chromium_path}/locales/fr.pak
%lang(gu) %{chromium_path}/locales/gu.pak
%lang(he) %{chromium_path}/locales/he.pak
%lang(hi) %{chromium_path}/locales/hi.pak
%lang(hr) %{chromium_path}/locales/hr.pak
%lang(hu) %{chromium_path}/locales/hu.pak
%lang(id) %{chromium_path}/locales/id.pak
%lang(it) %{chromium_path}/locales/it.pak
%lang(ja) %{chromium_path}/locales/ja.pak
%lang(kn) %{chromium_path}/locales/kn.pak
%lang(ko) %{chromium_path}/locales/ko.pak
%lang(lt) %{chromium_path}/locales/lt.pak
%lang(lv) %{chromium_path}/locales/lv.pak
%lang(ml) %{chromium_path}/locales/ml.pak
%lang(mr) %{chromium_path}/locales/mr.pak
%lang(ms) %{chromium_path}/locales/ms.pak
%lang(nb) %{chromium_path}/locales/nb.pak
%lang(nl) %{chromium_path}/locales/nl.pak
%lang(pl) %{chromium_path}/locales/pl.pak
%lang(pt_BR) %{chromium_path}/locales/pt-BR.pak
%lang(pt_PT) %{chromium_path}/locales/pt-PT.pak
%lang(ro) %{chromium_path}/locales/ro.pak
%lang(ru) %{chromium_path}/locales/ru.pak
%lang(sk) %{chromium_path}/locales/sk.pak
%lang(sl) %{chromium_path}/locales/sl.pak
%lang(sr) %{chromium_path}/locales/sr.pak
%lang(sv) %{chromium_path}/locales/sv.pak
%lang(sw) %{chromium_path}/locales/sw.pak
%lang(ta) %{chromium_path}/locales/ta.pak
%lang(te) %{chromium_path}/locales/te.pak
%lang(th) %{chromium_path}/locales/th.pak
%lang(tr) %{chromium_path}/locales/tr.pak
%lang(uk) %{chromium_path}/locales/uk.pak
%lang(ur) %{chromium_path}/locales/ur.pak
%lang(vi) %{chromium_path}/locales/vi.pak
%lang(zh_CN) %{chromium_path}/locales/zh-CN.pak
%lang(zh_TW) %{chromium_path}/locales/zh-TW.pak

%if %{build_headless}
%files headless
%{chromium_path}/headless_shell
%{chromium_path}/headless_lib_data.pak
%{chromium_path}/headless_lib_strings.pak
%endif

%if %{build_remoting}
%files -n chrome-remote-desktop
%{crd_path}/chrome-remote-desktop
%{crd_path}/chrome-remote-desktop-host
%{crd_path}/is-remoting-session
%{crd_path}/libremoting_core.so*
%{crd_path}/native-messaging-host
%{crd_path}/remote-assistance-host
%{_sysconfdir}/pam.d/chrome-remote-desktop
%{_sysconfdir}/chromium/native-messaging-hosts/*
%{_sysconfdir}/opt/chrome/
%{crd_path}/remoting_locales/
%{crd_path}/start-host
%{crd_path}/user-session
%{_unitdir}/chrome-remote-desktop@.service
/var/lib/chrome-remote-desktop/
%endif

%files -n chromedriver
%doc AUTHORS
%license LICENSE
%{_bindir}/chromedriver
%{chromium_path}/chromedriver

%changelog
* Wed Mar 06 2024 misaka00251 <liuxin@iscas.ac.cn> - 119.0.6045.159-1
- Upgrade to version 119

* Wed Dec 30 2020 Jeffery.Gao <gaojianxing@huawei.com> - 87.0.4280.88-1
- Package init