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
|
package pkglint
import "gopkg.in/check.v1"
func (s *Suite) Test_CheckLinesOptionsMk__autofix(c *check.C) {
t := s.Init(c)
t.SetUpOption("opt", "")
t.CreateFileLines("mk/bsd.options.mk")
t.SetUpPackage("category/package",
".include \"options.mk\"")
t.CreateFileLines("category/package/options.mk",
MkCvsID,
"",
"PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
"PKG_SUPPORTED_OPTIONS=\t# none",
"",
".include \"../../mk/bsd.options.mk\"",
"",
".if 0",
".if 0",
".endif",
".endif")
t.FinishSetUp()
t.Chdir("category/package")
G.Check(".")
t.CheckOutputLines(
"NOTE: options.mk:9: This directive should be indented by 2 spaces.",
"NOTE: options.mk:10: This directive should be indented by 2 spaces.")
t.SetUpCommandLine("-Wall", "--show-autofix")
G.Check(".")
t.CheckOutputLines(
"NOTE: options.mk:9: This directive should be indented by 2 spaces.",
"AUTOFIX: options.mk:9: Replacing \".\" with \". \".",
"NOTE: options.mk:10: This directive should be indented by 2 spaces.",
"AUTOFIX: options.mk:10: Replacing \".\" with \". \".")
t.SetUpCommandLine("-Wall", "--autofix")
G.Check(".")
t.CheckOutputLines(
"AUTOFIX: options.mk:9: Replacing \".\" with \". \".",
"AUTOFIX: options.mk:10: Replacing \".\" with \". \".")
t.CheckFileLinesDetab("options.mk",
MkCvsID,
"",
"PKG_OPTIONS_VAR= PKG_OPTIONS.package",
"PKG_SUPPORTED_OPTIONS= # none",
"",
".include \"../../mk/bsd.options.mk\"",
"",
".if 0",
". if 0",
". endif",
".endif")
}
func (s *Suite) Test_CheckLinesOptionsMk__literal(c *check.C) {
t := s.Init(c)
t.SetUpOption("declared", "")
t.SetUpOption("both", "")
t.SetUpOption("handled", "")
t.SetUpPackage("category/package",
".include \"../../mk/bsd.options.mk\"")
t.CreateFileLines("mk/bsd.options.mk",
MkCvsID)
mklines := t.SetUpFileMkLines("category/package/options.mk",
MkCvsID,
"",
"PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
"PKG_SUPPORTED_OPTIONS=\tdeclared both",
"",
".include \"../../mk/bsd.options.mk\"",
"",
".if ${PKG_OPTIONS:Mboth}",
".endif",
"",
".if ${PKG_OPTIONS:Mhandled}",
".endif")
t.Chdir("category/package")
t.FinishSetUp()
CheckLinesOptionsMk(mklines, "")
t.CheckOutputLines(
"WARN: ~/category/package/options.mk:4: "+
"Option \"declared\" should be handled below in an .if block.",
"WARN: ~/category/package/options.mk:11: "+
"Option \"handled\" is handled but not added to PKG_SUPPORTED_OPTIONS.")
}
func (s *Suite) Test_CheckLinesOptionsMk__literal_in_for_loop(c *check.C) {
t := s.Init(c)
t.SetUpOption("declared", "")
t.SetUpOption("both", "")
t.SetUpOption("handled", "")
t.SetUpPackage("category/package",
".include \"../../mk/bsd.options.mk\"")
t.CreateFileLines("mk/bsd.options.mk",
MkCvsID)
mklines := t.SetUpFileMkLines("category/package/options.mk",
MkCvsID,
"",
"PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
".for declared_option in declared both",
"PKG_SUPPORTED_OPTIONS=\t${declared_option}",
".endfor",
"",
".include \"../../mk/bsd.options.mk\"",
"",
".for handled_option in both handled",
". if ${PKG_OPTIONS:M${handled_option}}",
". endif",
".endfor")
t.Chdir("category/package")
t.FinishSetUp()
CheckLinesOptionsMk(mklines, "")
t.CheckOutputLines(
"WARN: ~/category/package/options.mk:5: "+
"Option \"declared\" should be handled below in an .if block.",
"WARN: ~/category/package/options.mk:11: "+
"Option \"handled\" is handled but not added to PKG_SUPPORTED_OPTIONS.")
}
// Before version 19.3.5, pkglint warned when bsd.prefs.mk was
// included in the top half of the file.
func (s *Suite) Test_CheckLinesOptionsMk__prefs(c *check.C) {
t := s.Init(c)
t.SetUpOption("option", "")
t.SetUpPackage("category/package",
".include \"../../mk/bsd.options.mk\"")
t.CreateFileLines("mk/bsd.options.mk",
MkCvsID)
mklines := t.SetUpFileMkLines("category/package/options.mk",
MkCvsID,
"",
".include \"../../mk/bsd.prefs.mk\"",
"",
"PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
"PKG_SUPPORTED_OPTIONS=\toption",
"",
".include \"../../mk/bsd.options.mk\"",
"",
".if ${PKG_OPTIONS:Moption}",
".endif")
t.Chdir("category/package")
t.FinishSetUp()
CheckLinesOptionsMk(mklines, "")
t.CheckOutputEmpty()
}
func (s *Suite) Test_CheckLinesOptionsMk__variable_order(c *check.C) {
t := s.Init(c)
t.SetUpOption("option", "")
t.SetUpPackage("category/package",
".include \"options.mk\"")
t.CreateFileLines("mk/bsd.options.mk",
MkCvsID)
mklines := t.SetUpFileMkLines("category/package/options.mk",
MkCvsID,
"",
"PKG_SUPPORTED_OPTIONS=\toption",
"PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
"",
".include \"../../mk/bsd.options.mk\"",
"",
".if ${PKG_OPTIONS:Moption}",
".endif")
t.Chdir("category/package")
t.FinishSetUp()
CheckLinesOptionsMk(mklines, "")
t.CheckOutputLines(
"WARN: ~/category/package/options.mk:3: " +
"Expected definition of PKG_OPTIONS_VAR.")
}
func (s *Suite) Test_CheckLinesOptionsMk__empty(c *check.C) {
t := s.Init(c)
t.SetUpPackage("category/package",
".include \"options.mk\"")
mklines := t.SetUpFileMkLines("category/package/options.mk",
MkCvsID)
t.Chdir("category/package")
t.FinishSetUp()
CheckLinesOptionsMk(mklines, "")
t.CheckOutputLines(
"ERROR: ~/category/package/options.mk: "+
"Each options.mk file must define PKG_OPTIONS_VAR.",
"ERROR: ~/category/package/options.mk: "+
"Each options.mk file must .include \"../../mk/bsd.options.mk\".")
}
func (s *Suite) Test_CheckLinesOptionsMk__conditionals(c *check.C) {
t := s.Init(c)
t.SetUpOption("option", "")
t.SetUpPackage("category/package",
".include \"../../mk/bsd.options.mk\"")
t.CreateFileLines("mk/bsd.options.mk",
MkCvsID)
t.Chdir("category/package")
mklines := t.SetUpFileMkLines("options.mk",
MkCvsID,
"",
"PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
"PKG_SUPPORTED_OPTIONS=\toption",
"",
".include \"../../mk/bsd.options.mk\"",
"",
".if ${PKG_OPTIONS}", // typo: should be ${PKG_OPTIONS:Moption}
".endif",
"",
".if ${PKG_OPTIONS:Nnegative}", // :N instead of :M, is ignored
".endif",
"",
".if ${PKG_OPTIONS:Ncodec-*}",
".endif",
"",
".if ${PKG_OPTIONS:tl}", // doesn't make sense, just for branch coverage
".endif")
t.FinishSetUp()
CheckLinesOptionsMk(mklines, "")
t.CheckOutputLines(
// This warning comes from VarTypeCheck.PkgOption
"WARN: options.mk:11: Undocumented option \"negative\".",
"WARN: options.mk:4: "+
"Option \"option\" should be handled below in an .if block.")
}
func (s *Suite) Test_CheckLinesOptionsMk(c *check.C) {
t := s.Init(c)
t.SetUpVartypes()
t.SetUpOption("mc-charset", "")
t.SetUpOption("mysql", "")
t.SetUpOption("ncurses", "")
t.SetUpOption("negative", "Demonstrates negated .if/.else")
t.SetUpOption("slang", "")
t.SetUpOption("sqlite", "")
t.SetUpOption("x11", "")
t.CreateFileLines("mk/bsd.options.mk",
MkCvsID)
mklines := t.SetUpFileMkLines("category/package/options.mk",
MkCvsID,
"",
"PKG_OPTIONS_VAR=\t\tPKG_OPTIONS.mc",
"PKG_OPTIONS_REQUIRED_GROUPS=\tscreen",
"PKG_OPTIONS_GROUP.screen=\tncurses slang",
"PKG_SUPPORTED_OPTIONS=\t\tmc-charset x11 lang-${l} negative",
"PKG_SUGGESTED_OPTIONS=\t\tmc-charset slang",
"PKG_OPTIONS_NONEMPTY_SETS+=\tdb",
"PKG_OPTIONS_SET.db=\t\tmysql sqlite",
"",
".include \"../../mk/bsd.options.mk\"",
"",
"PKGNAME?=\tdefault-pkgname-1.",
"",
".if !empty(PKG_OPTIONS:Mx11)",
".endif",
"",
".if !empty(PKG_OPTIONS:Mundeclared)",
".endif",
"",
".if empty(PKG_OPTIONS:Mnegative)",
".else",
".endif",
"",
".if empty(PKG_OPTIONS:Mnegative)",
".endif",
"",
".if !empty(PKG_OPTIONS:Mncurses)",
".elif !empty(PKG_OPTIONS:Mslang)",
".endif",
"",
".if !empty(PKG_OPTIONS:Mmysql)",
".elif !empty(PKG_OPTIONS:Msqlite)",
".endif")
CheckLinesOptionsMk(mklines, "")
t.CheckOutputLines(
"WARN: ~/category/package/options.mk:6: l is used but not defined.",
"WARN: ~/category/package/options.mk:18: Undocumented option \"undeclared\".",
"WARN: ~/category/package/options.mk:21: "+
"The positive branch of the .if/.else should be the one where the option is set.",
// TODO: The diagnostics should appear in the correct order.
"WARN: ~/category/package/options.mk:6: "+
"Option \"mc-charset\" should be handled below in an .if block.")
// TODO: There is no warning for the option "undeclared" since
// the option lang-${l} sets declaredArbitrary. This in turn
// disables possible wrong warnings, but a few too many.
}
// If there is no .include line after the declaration of the package-settable
// variables, the whole analysis stops.
//
// This case doesn't happen in practice and thus is not worth being handled in detail.
func (s *Suite) Test_CheckLinesOptionsMk__unexpected_line(c *check.C) {
t := s.Init(c)
t.SetUpVartypes()
t.CreateFileLines("mk/bsd.options.mk",
MkCvsID)
mklines := t.SetUpFileMkLines("category/package/options.mk",
MkCvsID,
"",
"PKG_OPTIONS_VAR=\tPKG_OPTIONS.mc",
"",
"pre-configure:",
"\techo \"In the pre-configure stage.\"")
CheckLinesOptionsMk(mklines, "")
t.CheckOutputLines(
"WARN: ~/category/package/options.mk:6: "+
"Unknown shell command \"echo\".",
"ERROR: ~/category/package/options.mk: "+
"Each options.mk file must .include \"../../mk/bsd.options.mk\".")
}
func (s *Suite) Test_CheckLinesOptionsMk__malformed_condition(c *check.C) {
t := s.Init(c)
t.SetUpPkgsrc()
t.Chdir(".")
t.SetUpOption("mc-charset", "")
t.SetUpOption("ncurses", "")
t.SetUpOption("slang", "")
t.SetUpOption("x11", "")
t.CreateFileLines("mk/bsd.options.mk",
MkCvsID)
t.FinishSetUp()
mklines := t.SetUpFileMkLines("category/package/options.mk",
MkCvsID,
"",
"PKG_OPTIONS_VAR=\t\tPKG_OPTIONS.mc",
"PKG_SUPPORTED_OPTIONS=\t\t# none",
"PKG_SUGGESTED_OPTIONS=\t\t# none",
"",
".include \"../../mk/bsd.fast.prefs.mk\"",
"",
"# Comments and conditionals are allowed at this point.",
".if ${OPSYS} == NetBSD",
".endif",
"",
".include \"../../mk/bsd.options.mk\"",
"",
".if ${OPSYS} == 'Darwin'",
".endif")
CheckLinesOptionsMk(mklines, "")
t.CheckOutputLines(
"WARN: category/package/options.mk:15: Invalid condition, unrecognized part: \"${OPSYS} == 'Darwin'\".")
}
func (s *Suite) Test_CheckLinesOptionsMk__PLIST_VARS_based_on_PKG_SUPPORTED_OPTIONS(c *check.C) {
t := s.Init(c)
t.SetUpOption("one", "")
t.SetUpOption("two", "")
t.SetUpOption("three", "")
t.SetUpPackage("category/package")
t.CreateFileLines("mk/bsd.options.mk")
t.SetUpFileMkLines("category/package/options.mk",
MkCvsID,
"",
"PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
"PKG_SUPPORTED_OPTIONS+=\tone",
"PKG_SUPPORTED_OPTIONS+=\ttwo",
"PKG_SUPPORTED_OPTIONS+=\tthree",
"",
".include \"../../mk/bsd.options.mk\"",
"",
"PLIST_VARS+=\t${PKG_SUPPORTED_OPTIONS}",
"",
".if ${PKG_OPTIONS:Mone}",
"PLIST.one=\tyes",
".endif",
"",
".if ${PKG_OPTIONS:Mthree}",
"PLIST.three=\tyes",
".endif")
t.Chdir("category/package")
t.FinishSetUp()
G.Check(".")
// Even though PLIST_VARS is defined indirectly by referencing
// PKG_SUPPORTED_OPTIONS and that variable is defined in several
// lines, pkglint gets all the facts correct and knows that
// only PLIST.two is missing.
t.CheckOutputLines(
"WARN: options.mk:10: "+
"\"two\" is added to PLIST_VARS, but PLIST.two is not defined in this file.",
"WARN: options.mk:5: Option \"two\" should be handled below in an .if block.")
}
// https://gnats.netbsd.org/57038
func (s *Suite) Test_CheckLinesOptionsMk__PLIST_VARS_based_on_groups(c *check.C) {
t := s.Init(c)
t.SetUpOption("one", "")
t.SetUpOption("two", "")
t.SetUpOption("opt-one", "")
t.SetUpOption("opt-two", "")
t.SetUpOption("req-one", "")
t.SetUpOption("req-two", "")
t.SetUpPackage("category/package")
t.CreateFileLines("mk/bsd.options.mk")
t.SetUpFileMkLines("category/package/options.mk",
MkCvsID,
"",
"PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
"PKG_SUPPORTED_OPTIONS+=\tone two",
"",
"PKG_OPTIONS_OPTIONAL_GROUPS+=\topt",
"PKG_OPTIONS_GROUP.opt+=\t\topt-one opt-two",
"",
"PKG_OPTIONS_REQUIRED_GROUPS+=\treq",
"PKG_OPTIONS_GROUP.req+=\t\treq-one req-two",
"",
// bsd.options.mk adds the options from the groups to
// PKG_SUPPORTED_OPTIONS. So does MkLines.collectPlistVars.
".include \"../../mk/bsd.options.mk\"",
"",
// All 6 options are added at this point.
"PLIST_VARS+=\t${PKG_SUPPORTED_OPTIONS}",
"",
// Only the 'one' options are covered properly, the 'two'
// options produce warnings, to demonstrate that all cases of
// option groups are covered.
".if ${PKG_OPTIONS:Mone}",
"PLIST.one=\tyes",
".endif",
".if ${PKG_OPTIONS:Mopt-one}",
"PLIST.opt-one=\tyes",
".endif",
".if ${PKG_OPTIONS:Mreq-one}",
"PLIST.req-one=\tyes",
".endif")
t.Chdir("category/package")
t.FinishSetUp()
G.Check(".")
t.CheckOutputLines(
"WARN: options.mk:14: \"two\" is added to PLIST_VARS, "+
"but PLIST.two is not defined in this file.",
"WARN: options.mk:14: \"opt-two\" is added to PLIST_VARS, "+
"but PLIST.opt-two is not defined in this file.",
"WARN: options.mk:14: \"req-two\" is added to PLIST_VARS, "+
"but PLIST.req-two is not defined in this file.",
"WARN: options.mk:4: Option \"two\" "+
"should be handled below in an .if block.",
"WARN: options.mk:7: Option \"opt-two\" "+
"should be handled below in an .if block.",
"WARN: options.mk:10: Option \"req-two\" "+
"should be handled below in an .if block.")
}
// A few packages (such as www/w3m) define several options that are
// handled by a single .if block in the lower part.
func (s *Suite) Test_CheckLinesOptionsMk__combined_option_handling(c *check.C) {
t := s.Init(c)
t.SetUpOption("opt-variant1", "")
t.SetUpOption("opt-variant2", "")
t.SetUpOption("other", "")
t.CreateFileLines("mk/bsd.options.mk")
t.SetUpPackage("category/package",
".include \"options.mk\"")
t.CreateFileLines("category/package/options.mk",
MkCvsID,
"",
"PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
"PKG_SUPPORTED_OPTIONS=\topt-variant1 opt-variant2",
"",
".include \"../../mk/bsd.options.mk\"",
"",
".if ${PKG_OPTIONS:Mopt-variant*}",
".endif")
t.FinishSetUp()
t.Chdir("category/package")
G.Check(".")
// Before 5.7.21 on 2019-08-17, pkglint issued an error about the
// "invalid option name opt-variant*" and warnings about the
// unhandled options "opt-variant1" and "opt-variant2".
t.CheckOutputEmpty()
}
func (s *Suite) Test_CheckLinesOptionsMk__combined_option_handling_coverage(c *check.C) {
t := s.Init(c)
t.SetUpOption("opt-variant", "")
t.CreateFileLines("mk/bsd.options.mk")
t.SetUpPackage("category/package",
".include \"options.mk\"")
t.CreateFileLines("category/package/options.mk",
MkCvsID,
"",
"PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
"PKG_SUPPORTED_OPTIONS=\topt-variant",
"",
".include \"../../mk/bsd.options.mk\"",
"",
".if ${PKG_OPTIONS:Mopt-[}", // intentional syntax error
".endif",
"",
".if ${PKG_OPTIONS:Mother-*}",
".endif")
t.FinishSetUp()
t.Chdir("category/package")
G.Check(".")
// The pattern "opt-[" does not match any of the declared options
// since the pattern is malformed and pkglint does not distinguish
// between invalid and non-matching patterns.
//
// The pattern "other-*" also doesn't match.
//
// Since the patterns don't match any of the variables from
// PKG_SUPPORTED_OPTIONS, pkglint cannot analyze all possible cases
// and therefore suppresses all warnings about options that are
// declared but not handled.
t.CheckOutputEmpty()
}
func (s *Suite) Test_CheckLinesOptionsMk__options_in_for_loop(c *check.C) {
t := s.Init(c)
t.SetUpOption("idea", "")
t.SetUpOption("md2", "")
t.SetUpOption("md5", "")
t.SetUpOption("other", "")
t.CreateFileLines("mk/bsd.options.mk")
t.SetUpPackage("category/package",
".include \"options.mk\"")
t.CreateFileLines("category/package/options.mk",
MkCvsID,
"",
"PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
"PKG_SUPPORTED_OPTIONS=\tidea md2 md5 other",
"",
".include \"../../mk/bsd.options.mk\"",
"",
".for alg in idea md2 md5",
". if ${PKG_OPTIONS:M${alg}}",
". endif",
".endfor")
t.FinishSetUp()
t.Chdir("category/package")
G.Check(".")
t.CheckOutputLines(
"WARN: options.mk:4: Option \"other\" should be handled below in an .if block.")
}
// In this scenario, the evaluation of the PKG_OPTIONS takes place in a
// loop over the PLIST_VARS, which is quite indirect, compared to a
// direct ${PKG_OPTIONS:Mnetbsd}. In most practical cases, the identifiers
// in PLIST_VARS are literals, which still allows that they are analyzed.
func (s *Suite) Test_CheckLinesOptionsMk__indirect(c *check.C) {
t := s.Init(c)
t.SetUpOption("generic", "")
t.SetUpOption("netbsd", "")
t.SetUpOption("os", "")
t.CreateFileLines("mk/bsd.options.mk")
t.SetUpPackage("category/package",
".include \"options.mk\"")
t.Chdir("category/package")
t.CreateFileLines("options.mk",
MkCvsID,
"",
"PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
"PKG_SUPPORTED_OPTIONS=\tgeneric",
"PKG_SUGGESTED_OPTIONS=\tgeneric",
"",
"PKG_SUPPORTED_OPTIONS.FreeBSD=\tos",
"PKG_SUGGESTED_OPTIONS.FreeBSD=\tos",
"",
"PKG_SUPPORTED_OPTIONS.NetBSD+=\tnetbsd os",
"PKG_SUGGESTED_OPTIONS.NetBSD+=\tnetbsd os",
"",
".include \"../../mk/bsd.options.mk\"",
"",
"PLIST_VARS+=\tgeneric netbsd os",
"",
".for option in ${PLIST_VARS}",
". if ${PKG_OPTIONS:M${option}}",
"CONFIGURE_ARGS+=\t--enable-${option:S/-/_/}",
"PLIST.${option}=\tyes",
". endif",
".endfor")
t.CreateFileLines("PLIST",
PlistCvsID,
"${PLIST.generic}bin/generic",
"${PLIST.netbsd}bin/netbsd",
"${PLIST.os}bin/os")
t.FinishSetUp()
G.Check(".")
t.CheckOutputEmpty()
}
// An unrealistic scenario, but necessary for code coverage.
func (s *Suite) Test_CheckLinesOptionsMk__partly_indirect(c *check.C) {
t := s.Init(c)
t.CreateFileLines("mk/bsd.options.mk")
t.SetUpPackage("category/package",
".include \"options.mk\"")
t.CreateFileLines("category/package/options.mk",
MkCvsID,
"",
"# Including bsd.prefs.mk is not necessary here since the OPSYS",
"# in PKG_SUPPORTED_OPTIONS is only evaluated lazily inside",
"# bsd.options.mk, at which point bsd.prefs.mk will be included",
"# as well.",
"",
"PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
"PKG_SUPPORTED_OPTIONS=\tgeneric-${OPSYS}",
"",
".include \"../../mk/bsd.options.mk\"",
"",
".for option in generic-${OPSYS}",
". if ${PKG_OPTIONS:M${option}}",
". endif",
".endfor")
t.FinishSetUp()
t.Chdir("category/package")
G.Check(".")
t.CheckOutputEmpty()
}
func (s *Suite) Test_CheckLinesOptionsMk__indirect_supported_options_parentheses(c *check.C) {
t := s.Init(c)
t.SetUpOption("indirect", "")
t.SetUpOption("direct", "")
t.SetUpVartypes()
t.CreateFileLines("mk/bsd.options.mk",
MkCvsID)
mklines := t.SetUpFileMkLines("category/package/options.mk",
MkCvsID,
"",
"PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
"OPTIONS=\t\tindirect",
"PKG_SUPPORTED_OPTIONS=\t$(OPTIONS) direct",
"",
".include \"../../mk/bsd.options.mk\"",
"",
".for option in ${OPTIONS}",
". if ${PKG_OPTIONS:M${option}}",
". endif",
".endfor")
CheckLinesOptionsMk(mklines, "")
t.CheckOutputLines(
"WARN: ~/category/package/options.mk:5: "+
"Please use curly braces {} instead of round parentheses () for OPTIONS.",
"WARN: ~/category/package/options.mk:5: "+
"Option \"direct\" should be handled below in an .if block.")
}
func (s *Suite) Test_CheckLinesOptionsMk__handled_but_not_supported(c *check.C) {
t := s.Init(c)
t.SetUpOption("option", "")
t.SetUpVartypes()
t.CreateFileLines("mk/bsd.options.mk",
MkCvsID)
mklines := t.SetUpFileMkLines("category/package/options.mk",
MkCvsID,
"",
"PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
"PKG_SUPPORTED_OPTIONS=\t# none",
"",
".include \"../../mk/bsd.options.mk\"",
"",
".if ${PKG_OPTIONS:Moption}",
".endif")
CheckLinesOptionsMk(mklines, "")
t.CheckOutputLines(
"WARN: ~/category/package/options.mk:8: " +
"Option \"option\" is handled but not added to PKG_SUPPORTED_OPTIONS.")
}
func (s *Suite) Test_CheckLinesOptionsMk__supported_but_not_checked(c *check.C) {
t := s.Init(c)
t.SetUpOption("option", "")
t.SetUpVartypes()
t.CreateFileLines("mk/bsd.options.mk",
MkCvsID)
mklines := t.SetUpFileMkLines("category/package/options.mk",
MkCvsID,
"",
"PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
"PKG_SUPPORTED_OPTIONS=\toption",
"",
".include \"../../mk/bsd.options.mk\"",
"",
".if ${PKG_OPTIONS:Mopt${:Uion}}",
".endif")
CheckLinesOptionsMk(mklines, "")
// Pkglint does not expand the ${:Uion}, therefore it doesn't know that
// the option is indeed handled. Because of this uncertainty, pkglint
// does not issue any warnings about possibly unhandled options at all.
t.CheckOutputEmpty()
}
// Up to April 2019, pkglint logged a wrong note saying that OTHER_VARIABLE
// should have the positive branch first. That note was only ever intended
// for PKG_OPTIONS.
func (s *Suite) Test_OptionsLinesChecker_handleLowerCondition__foreign_variable(c *check.C) {
t := s.Init(c)
t.SetUpOption("opt", "")
t.CreateFileLines("mk/bsd.options.mk")
t.SetUpPackage("category/package",
".include \"options.mk\"")
t.CreateFileLines("category/package/options.mk",
MkCvsID,
"",
"PKG_OPTIONS_VAR=\tPKG_OPTIONS.package",
"PKG_SUPPORTED_OPTIONS=\topt",
"",
".include \"../../mk/bsd.options.mk\"",
"",
".if empty(OTHER_VARIABLE)",
".else",
".endif")
t.FinishSetUp()
G.Check(t.File("category/package"))
t.CheckOutputLines(
"WARN: ~/category/package/options.mk:8: OTHER_VARIABLE is used but not defined.",
"WARN: ~/category/package/options.mk:4: Option \"opt\" should be handled below in an .if block.")
}
|