Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

Golang.txt 23 KB

You have to be logged in to leave a comment. Sign In
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
  1. = Golang Packaging Guidelines
  2. :last-reviewed: 2019-06-19
  3. This document details best practices for packaging Golang packages. Most of it
  4. is automated by an extensive use of macros.
  5. == go2rpm
  6. https://pagure.io/GoSIG/go2rpm/[go2rpm] is tool that automates many of these steps.
  7. It is advisable to try `+go2rpm import_path+` first
  8. before attempting to write a SPEC by hand.
  9. == Import Path
  10. In Golang, packages are referenced by full URLs. Since this URL is
  11. referenced in several places throughout the rpmspec, set the
  12. base import path as a global define at the top of the spec file
  13. [source,RPMSpec]
  14. ----
  15. %global goipath github.com/kr/pretty
  16. ----
  17. All macros, including package name, source URL, will be computed from this
  18. value.
  19. [NOTE]
  20. ====
  21. *Take the time to identify it accurately.* Changing it later will be
  22. inconvenient.
  23. * it may differ from the repository URL;
  24. * generally, the correct value will be the one used by the project in its
  25. documentation, coding examples, and build assertions;
  26. * use the gopkg import path for all code states when a project uses it.
  27. If upstream confused itself after multiple forks and renamings, you will need
  28. to fix references to past names in the Go source files, unit tests included.
  29. Perform this fixing in `+%prep+`.
  30. ====
  31. == Naming
  32. === Source packages (src.rpm)
  33. * Golang source packages dedicated to providing code MUST be named after their
  34. main import path.
  35. This
  36. process is automated by the `+%{goname}+` macro.
  37. This macro will remove any capitalization, "go" keywords, and any duplication in
  38. the import path.
  39. +
  40. For example:
  41. +
  42. --
  43. ** the import path `+github.com/kr/pretty+` will become
  44. `+golang-github-kr-pretty+`
  45. ** the import path `+github.com/DATA-DOG/go-txdb+` will become
  46. `+golang-github-data-dog-txdb+`
  47. ** the import path `+github.com/gopherjs/gopherjs+` will become
  48. `+golang-github-gopherjs+`
  49. --
  50. +
  51. The filename of spec MUST match the name of the package.
  52. +
  53. If you're not sure what will the name processed by the `+%{goname}+` macro be,
  54. simply build the SRPM with:
  55. fedpkg --release f31 srpm
  56. +
  57. The SRPM filename will be the one to use in your rpmspec and spec filename.
  58. * Source packages that provide a well-known application such as `+etcd+`
  59. MUST be named after the application.
  60. End users do not care about the language their applications are written in. But
  61. do not name packages after an obscure utility binary that happens to be built by
  62. the package.
  63. ==== Implementation: `+%{gorpmname}+`
  64. `+%gometa+` uses the `+%{gorpmname}+` macro to compute the main `+%{goname}+`
  65. from `+%{goipath}+`.
  66. [NOTE]
  67. ====
  68. *`+%{gorpmname}+` can produce collisions*
  69. `+%{gorpmname}+` tries to compute human-friendly and rpm-compatible naming from
  70. Go import paths. It simplifies them, removing redundancies and common
  71. qualifiers.
  72. As a result it is possible for two different import paths to produce the same
  73. result. In that case, feel free to adjust this result manually to avoid the
  74. collision.
  75. ====
  76. === Go code packages: `+%{goname}-devel+`
  77. ==== In a source package dedicated to providing Go code
  78. Packages that ship Go code in `+%{goipath}+` should be named
  79. `+%{goname}-devel+`.
  80. If your source package is already named `+%{goname}+` then:
  81. [source,RPMSpec]
  82. ----
  83. %package devel
  84. […]
  85. %description devel
  86. […]
  87. %files devel -f devel.file-list
  88. ----
  89. This has been automated by the `+%{gopkg}+` and `+%{gopdevelkg}+` macros
  90. described in the <<Package metadata>> section below.
  91. ==== In a another kind of source package
  92. If your source package is named something other than `+%{goname}+`, you SHOULD
  93. use:
  94. [source,RPMSpec]
  95. ----
  96. %package -n %{goname}-devel
  97. […]
  98. %description -n %{goname}-devel
  99. […]
  100. %files -n %{goname}-devel -f devel.file-list
  101. ----
  102. ==== Separate code packages
  103. And, finally, if you wish to split the project Go code in multiple packages,
  104. you can compute the corresponding names with:
  105. [source,RPMSpec]
  106. ----
  107. %global goname1 %gorpmname importpath1
  108. […]
  109. %package -n %{goname1}-devel
  110. […]
  111. %description -n %{goname1}-devel
  112. […]
  113. %files -n %{goname1}-devel -f %{goname1}.file-list
  114. ----
  115. See also the xref:Golang_advanced.adoc#_dealing_with_cyclic_dependencies[Dealing with cyclic dependencies]
  116. chapter.
  117. Do remember that for Go, each directory is a package. Never separate the .go
  118. files contained in a single directory in different packages.
  119. ==== Import path compatibility packages: `+%{compat-%{oldgoname}-devel}+`
  120. When a project can be referenced under multiple import paths, due to forks,
  121. renamings, rehostings, organizational changes, or confusing project
  122. documentation, it is possible to generate compatibility sub-packages to
  123. connect code that uses one of the other import paths to the canonical one.
  124. The canonical import path SHOULD always be the one referenced in the project
  125. documentation.
  126. However some projects do not document import path changes, and rely on HTTPS
  127. redirections (for example https://github.com/docker/docker →
  128. https://github.com/moby/moby).
  129. Such a redirection is a sufficient indicator the canonical import path has
  130. changed (but please make sure with upstream).
  131. The new import path SHOULD be reflected in `+%{goipath}+` and compatibility
  132. import paths MUST be declared with the `+goaltipaths+` macro:
  133. [source,RPMSpec]
  134. ----
  135. # A space-separated list of import paths to simulate.
  136. %global goaltipaths
  137. ----
  138. For example, the Go library `+github.com/Sirupsen/logrus+` was renamed
  139. `+github.com/sirupsen/logrus+` and the documentation reflects this new import
  140. path.
  141. The packager SHOULD thus request a renaming of his package with a new import
  142. path and a compatibility import path:
  143. [source,RPMSpec]
  144. ----
  145. %global goipath github.com/sirupsen/logrus
  146. %global goaltipaths github.com/Sirupsen/logrus
  147. ----
  148. If a project has gone through multiple rename, multiple compatibility import
  149. paths can be specified as well.
  150. [NOTE]
  151. ====
  152. *Never defer renamings*
  153. Packagers MUST NOT use import path compatibility sub-packages to alias the
  154. canonical import path to one of the previous namings.
  155. Packagers MUST apply upstream renaming choices to the main `+%{goipath}+` spec
  156. variable and
  157. everything that derives from it, such as `+%{goname}+`.
  158. Deferred renamings introduce friction with upstream and other packagers.
  159. ====
  160. === Go binary packages
  161. The binaries produced by your rpmspec SHOULD generally be listed in the main
  162. package. However, if you want a more appropriate name or split binaries among
  163. different packages, you can create additional binary subpackage.
  164. Of course these package MUST NOT be noarch.
  165. For example we can create the package bbolt that will contain the binary
  166. of the same name:
  167. [source,RPMSpec]
  168. ----
  169. %package -n bbolt
  170. […]
  171. %description -n bbolt
  172. […]
  173. %files -n bbolt
  174. %license LICENSE
  175. %{_bindir}/bbolt
  176. ----
  177. == Versioning
  178. Many Go libraries do not use package versions or have regular releases and
  179. are instead maintained in public version control.
  180. In this case, follow the standard Fedora version conventions. This means that
  181. often Go packages will have a version number of `+0+` and a release number like
  182. `+0.10.20190319git27435c6+`.
  183. Most of this process is automated by macros so that you don't have to specify
  184. the release number yourself.
  185. You first specify either a Version, tag or commit in the header.
  186. [source,RPMSpec]
  187. ----
  188. Version:
  189. %global tag
  190. %global commit
  191. ----
  192. Then use the `+%gometa+` macro:
  193. %gometa
  194. The `+%gometa+` macro will automatically process the `+%{?dist}+` tag of the
  195. `+Release+` field to take into account the commit if any.
  196. [NOTE]
  197. ====
  198. *Commits vs releases*
  199. You SHOULD package releases in priority.
  200. Please reward the projects that make an effort to identify stable code states.
  201. Only fall back to commits when the project does not release, when the release is
  202. more than six months old, or if
  203. you absolutely need one of the changes of a later commit.
  204. In the later cases please inform the project politely of the reason you needed
  205. to give up on their official releases.
  206. Promoting releases is a way to limit incompatible commit hell.
  207. ====
  208. == Go Language Architectures
  209. To compile on various architectures, golang and gcc-go compilers are available.
  210. The golang compiler currently supports x86, x86_64, ppc64le, ppc64 (partially,
  211. see upstream issue#13192), s390x, armv7hl and aarch64.
  212. Binaries SHOULD set ExclusiveArch so that we only attempt to build packages on
  213. those arches.
  214. This is now automatically added by the `+%gometa+` macro by leveraging the
  215. `+%{golang_arches}+` macro.
  216. Packagers can exclude `+%ix86+`
  217. (see https://fedoraproject.org/wiki/Changes/EncourageI686LeafRemoval[Changes/EncourageI686LeafRemoval])
  218. by passing `+-f+` to the `+%gometa+` macro.
  219. The `+-f+` flag tells `+%gometa+` to set `+ExclusiveArch: %{golang_arches_future}+`
  220. instead of `+ExclusiveArch: %{golang_arches}+`.
  221. `+%{golang_arches_future}+` includes the same architectures as
  222. `+{golang_arches}+` sans `+%ix86+`.
  223. == Dependencies
  224. Packages MUST have `+BuildRequires: go-rpm-macros+`.
  225. This is automated by the `+%gometa+` macro.
  226. === Automatic Dependency Generation
  227. Most of the `+golang-*+` packages are source code only.
  228. The `+*-devel+` sub-package that includes the source code should explicitly have
  229. provides for the golang imports that it includes.
  230. These provides are automatically deduced from import paths.
  231. Binary builds that include these imports will use them in BuildRequires,
  232. for example:
  233. [source,RPMSpec]
  234. ----
  235. BuildRequires: golang(github.com/gorilla/context)
  236. ----
  237. === Bundled or unbundled
  238. At the moment golang projects packaged in Fedora SHOULD be unbundled by
  239. default. It means projects are built from dependencies packaged in Fedora.
  240. For some project it can be reasonable to build from bundled dependencies.
  241. Every bundling needs a proper justification.
  242. === BuildRequires
  243. The BuildRequires of the project contains the dependencies needed by unit tests
  244. and binaries.
  245. You can gather them manually with `golist`.
  246. For example:[[manual_br]]
  247. [source,bash]
  248. ----
  249. export GOPATH=/home/user/go
  250. export GO111MODULE=off
  251. export goipath="github.com/sirupsen/logrus"
  252. go get $goipath
  253. (sort -u | xargs -I{} echo "BuildRequires: golang({})") <<< "$(
  254. golist --imported --package-path $goipath --skip-self
  255. golist --imported --package-path $goipath --skip-self --tests
  256. )"
  257. ----
  258. outputs:
  259. [source]
  260. ----
  261. BuildRequires: golang(github.com/stretchr/testify/assert)
  262. BuildRequires: golang(github.com/stretchr/testify/require)
  263. BuildRequires: golang(golang.org/x/crypto/ssh/terminal)
  264. ----
  265. If automatic buildrequires are available on your build target, you can use
  266. the `+%go_generate_buildrequires+` macro in `+%generate_buildrequires+`:
  267. [source,RPMSpec]
  268. ----
  269. %generate_buildrequires
  270. %go_generate_buildrequires
  271. ----
  272. This macro leverages `+golist+` to gather build dependencies and tests
  273. dependencies from the package source.
  274. == Testing
  275. You MUST run unit tests.
  276. Due to the nature of Go development, especially the lack of use of semantic
  277. versioning, API breakages are frequent.These need to be detected early and dealt
  278. with upstream.
  279. Some tests may be disabled, especially the following kinds of unit tests are
  280. incompatible with a secure build environment such as mock:
  281. * tests that call a remote server or API over the Internet,
  282. * tests that attempt to reconfigure the system,
  283. * tests that rely on a specific app running on the system, like a database
  284. or syslog server.
  285. If a test is broken for some other reason, you can disable it the same way.
  286. However, you SHOULD also report the problem upstream. Remember to trace in a
  287. comment why each check was disabled, with links to eventual upstream problem
  288. reports.
  289. == Walkthrough
  290. This chapter will present a typical Go spec file step by step, with comments
  291. and explanations.
  292. === Spec preamble: `+%{goipath}+`, `+%{forgeurl}+` and `+%gometa+`
  293. ==== Usual case
  294. A Go package is identified by its import path. A Go spec file will therefore
  295. start with the `+%{goipath}+` declaration. Don't get it wrong, it will control
  296. the behaviour of the rest of the spec file.
  297. %global goipath google.golang.org/api
  298. If your package is hosted on a forge like GitHub, GitLab, Bitbucket or Pagure,
  299. the hosting of the Go package will be automatically deduced from this variable
  300. (typically by prefixing it with \https://). If that is not the case, you need
  301. to declare explicitly the hosting URL with the `+%{forgeurl}+` macro
  302. %global forgeurl https://github.com/google/google-api-go-client
  303. The `+%{forgeurl}+` declaration is followed by either `+Version+`, `+commit+` or
  304. `+tag+`. Use the combination that matches your use-case.
  305. %global commit 2dc3ad4d67ba9a37200c5702d36687a940df1111
  306. [NOTE]
  307. ====
  308. You can also define `+date+` to override the mtime of the Source archive.
  309. ====
  310. Now that we have all the required variables, the `+%gometa+` macro can be run
  311. %gometa
  312. It will compute and set the following variables if they are not already set by
  313. the packager:
  314. goname:: an rpm-compatible package name derived from goipath
  315. gosource:: a URL that can be used as SourceX: value
  316. gourl:: a URL that can be used as URL: value
  317. It will delegate processing to the `+%forgemeta+` macro for:
  318. forgesource:: a URL that can be used as SourceX: value
  319. forgesetupargs:: the correct arguments to pass to `+%setup+` for this source
  320. used by `+%forgesetup+` and `+%forgeautosetup+`
  321. archivename:: the source archive filename, without extensions
  322. archiveext:: the source archive filename extensions, without leading dot
  323. archiveurl:: the URL that can be used to download the source archive,
  324. without renaming
  325. topdir:: the source archive top directory (can be empty)
  326. extractdir:: the source directory created inside `+%{_builddir}+` after
  327. using `+%forgesetup+`, `+%forgeautosetup+` or `+%{forgesetupargs}+`
  328. repo:: the repository name
  329. owner:: the repository owner (if used by another computed variable)
  330. shortcommit:: the commit hash clamping used by the forge, if any
  331. scm:: the scm type, when packaging code snapshots: commits or tags
  332. distprefix:: the prefix that needs adding to dist to trace non-release
  333. packaging
  334. Most of the computed variables are both overridable and optional.
  335. Now we can add the remaining elements of the preamble. First, we can define a
  336. multiline description block shared between subpackages:
  337. [source,RPMSpec]
  338. ----
  339. %global common_description %{expand:
  340. cmux is a generic Go library to multiplex connections based on their payload.
  341. Using cmux, you can serve gRPC, SSH, HTTPS, HTTP, Go RPC, and pretty much any
  342. other protocol on the same TCP listener.}
  343. ----
  344. This description MUST stay within 80 characters per line.
  345. [NOTE]
  346. ====
  347. If you need specific devel summary and description, you can also define:
  348. - `+%global godevelsummary+`
  349. - `+%global godeveldescription+`
  350. ====
  351. Then we MUST specify the license files that will be added to the devel
  352. subpackages:
  353. `+%global golicenses+`: A space-separated list of shell globs matching the
  354. project license files.
  355. And the possible documentation that SHOULD be included:
  356. `+%global godocs+`: A space-separated list of shell globs matching the project
  357. documentation files. The Go rpm macros will pick up “.md” files by default
  358. without this.
  359. [NOTE]
  360. ====
  361. You can also exclude files from `+%golicense+` and `+%godocs+` with:
  362. - `+%global golicensesex+`
  363. - `+%global godocsex+`
  364. For example you might want to exclude `+INSTALL*+` files from `+%godocs+` as
  365. these should not be provided.
  366. ====
  367. === Source package metadata: `+%{goname}+`, `+%{gourl}+` and `+%{gosource}+`
  368. We can declare the usual rpm headers, using the values computed by `+%gometa+`:
  369. [source,RPMSpec]
  370. ----
  371. Name: %{goname}
  372. # If not set before
  373. Version:
  374. Release: 1%{?dist}
  375. Summary:
  376. License:
  377. URL: %{gourl}
  378. Source: %{gosource}
  379. ----
  380. You can replace them with manual definitions.
  381. For example, replace `+%{gourl}+` with the project homepage if it exists
  382. separately from the repository URL.
  383. Be careful to only replace `+%{go*}+` variables when it adds value to the
  384. specfile and you understand the consequences. Otherwise you will just add
  385. maintenance-intensive discrepancies in the distribution.
  386. === BuildRequires
  387. If they are not automatically generated, you can now add the dependencies needed
  388. for package building and unit testings:
  389. [source,RPMSpec]
  390. ----
  391. BuildRequires: golang(github.com/stretchr/testify/assert)
  392. BuildRequires: golang(github.com/stretchr/testify/require)
  393. BuildRequires: golang(golang.org/x/crypto/ssh/terminal)
  394. ----
  395. See <<manual_br,this section>> on how to get the BuildRequires list manually.
  396. === Description
  397. Now add the main package description:
  398. [source,RPMSpec]
  399. ----
  400. %description
  401. %{common_description}
  402. ----
  403. === Package metadata
  404. The process of declaring Go code packages has been automated with the
  405. `+%{gopkg}+` macro. It will automatically generate a `+%package+` and
  406. `+%description+` for all primary import paths and compatibility ones.
  407. %gopkg
  408. If you only need to generate Go devel subpackages without compat, use:
  409. %godevelpkg
  410. If necessary, you can then define one or multiple Go packages that will
  411. contain the binaries being built. See the previous <<Go binary packages>>
  412. section.
  413. === %prep: `+%goprep+` , removing vendoring
  414. `+%goprep+` unpacks the Go source archives and creates the project “GOPATH” tree
  415. used in the rest of the spec file. It removes vendored (bundled) code:
  416. use the `+-k+` flag if you wish to keep this vendored code, and deal with the
  417. consequences in the rest of the spec.
  418. %goprep
  419. `+%goprep+` only performs basic vendoring detection. It will miss inventive ways
  420. to vendor code. Remove manually missed vendor code after the `+%goprep+` line.
  421. `+%goprep+` will not fix upstream sources for you. Since all the macro calls
  422. that follow `+%goprep+` assume clean problem-free sources, you need to correct
  423. them just after the `+%goprep+` line:
  424. * replace calls to deprecated import paths with their correct value
  425. * patch code problems
  426. * remove dead code (some upstreams deliberately ship broken source code in
  427. the hope someone will get around to fix it)
  428. [NOTE]
  429. ====
  430. You SHOULD send fixes and problem reports upstream. Any patch used
  431. SHOULD contain a link to an upstream bug report or merge request. At minimum,
  432. a comment SHOULD be added to explain the patch rationale.
  433. ====
  434. When you package an import path, that participates in a dependency loop, you
  435. need bootstrapping to manage the initial builds:
  436. https://docs.fedoraproject.org/en-US/packaging-guidelines/#bootstrapping
  437. For Go code, that means your bootstrap section should:
  438. * remove unit tests that import other parts of the loop
  439. * remove code that imports other parts of the loop
  440. Sometimes one can resolve dependency loops just by splitting specific
  441. subdirectories in a separate -devel subpackage. See also
  442. xref:Golang_advanced.adoc#_dealing_with_cyclic_dependencies[Dealing with cyclic dependencies].
  443. === Automatic BuildRequires
  444. If BuildRequires generator are supported, you can now add them to your build:
  445. [source,RPMSpec]
  446. ----
  447. %generate_buildrequires
  448. %go_generate_buildrequires
  449. ----
  450. === Packaging a binary: the %build section
  451. If your package is a source package only, you can skip this `+%build+` section
  452. entirely.
  453. Otherwise, you first need to identify manually the project parts that can be
  454. built, and how to name the result.
  455. Practically, it’s any directory containing a main() Go section. Nice projects
  456. put those in `+cmd+` subdirectories named after the command that will be built,
  457. which is what we will document here, but it is not a general rule. Sometimes the
  458. whole `+%goipath+` builds as a single binary.
  459. [source,RPMSpec]
  460. ----
  461. for cmd in cmd/* ; do
  462. %gobuild -o %{gobuilddir}/bin/$(basename $cmd) %{goipath}/$cmd
  463. done
  464. ----
  465. === Installing the packages
  466. ==== Source package installation
  467. If you package a library, `+%gopkginstall+` will perform installation steps
  468. for all primary import paths and compatibility ones.
  469. %gopkginstall
  470. If you only need to install Go devel subpackages without compat, use:
  471. %godevelinstall
  472. ==== Binary package installation
  473. For binaries, we simply create the `+%{_bindir}+` directory in the buildroot
  474. and install the commands as executable in it:
  475. [source,RPMSpec]
  476. ----
  477. install -m 0755 -vd %{buildroot}%{_bindir}
  478. install -m 0755 -vp %{gobuilddir}/bin/* %{buildroot}%{_bindir}/
  479. ----
  480. [NOTE]
  481. ====
  482. Be wary of command names which might already exist in Fedora. If you have
  483. any doubt, you can check if the command is already provided in Fedora:
  484. [source,shell]
  485. ----
  486. dnf whatprovides --disablerepo="*" --enablerepo=rawhide "/usr/bin/$cmd"
  487. ----
  488. If this is the case, use your best judgment to rename the command.
  489. ====
  490. === Running the unit tests: `+%gocheck+`
  491. As said before, you MUST run unit tests in `+%check+`:
  492. %gocheck
  493. However it is often necessary to disable some of them. You have 3 exclusion
  494. flags to do so:
  495. * `+-d <directory>+`: exclude the files contained in `+<directory>+`
  496. non-recursively (subdirectories are not excluded)
  497. * `+-t <tree root>+`: exclude the files contained in `+<tree root>+`
  498. recursively (subdirectories are excluded)
  499. * `+-r <regexp>+`: exclude files matching `+<regexp>+`
  500. Remember to document why a test has been disabled.
  501. === %files declaration
  502. ==== When shipping source code
  503. The `+%gopkgfiles+` will process the file list produced in `+%install+` and add
  504. the necessary license and documentation files:
  505. %gopkgfiles
  506. ==== When shipping binaries
  507. Binaries are usually shipped in the main package. This package MUST include
  508. legal files and documentation associated with those binaries.
  509. [source,RPMSpec]
  510. ----
  511. %files
  512. %license LICENSE
  513. %doc cmd/foo/README.md
  514. %{_bindir}/*
  515. ----
  516. == Examples
  517. === Simple source package
  518. .golang-github-stretchr-testify.spec
  519. [source,RPMSpec]
  520. ----
  521. include::{examplesdir}/golang/golang-github-stretchr-testify.spec[]
  522. ----
  523. === Handling package renames
  524. .golang-github-sirupsen-logrus.spec
  525. [source,RPMSpec]
  526. ----
  527. include::{examplesdir}/golang/golang-github-sirupsen-logrus.spec[]
  528. ----
  529. === Simple binary package
  530. .golang-github-boltdb-bolt.spec
  531. [source,RPMSpec]
  532. ----
  533. include::{examplesdir}/golang/golang-gopkg-square-jose-2.spec[]
  534. ----
  535. == Additional resources
  536. === Advanced uses cases
  537. ** xref:Golang_advanced.adoc#_shipping_additional_files[Shipping additional files]
  538. ** xref:Golang_advanced.adoc#_additional_header_declarations[Additional header declarations]
  539. ** xref:Golang_advanced.adoc#_dealing_with_cyclic_dependencie[Dealing with cyclic dependencies]
  540. === Additional annotated templates
  541. ** xref:Golang_templates.adoc#_minimal_source_package[Minimal source package]
  542. ** xref:Golang_templates.adoc#_full_source_package[Full source package]
  543. ** xref:Golang_templates.adoc#_minimal_alternative_import_path[Minimal alternative import path]
  544. ** xref:Golang_templates.adoc#_full_alternative_import_path[Full alternative import path]
  545. ** xref:Golang_templates.adoc#_minimal_binary[Minimal binary]
  546. ** xref:Golang_templates.adoc#_full_binary[Full binary]
  547. ** xref:Golang_templates.adoc#_multi_package[Multi package]
  548. ** xref:Golang_templates.adoc#_manual_package_deprecated[Manual package (deprecated)]
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...