Skip to content

Commit 99a404c

Browse files
committed
lint: add W74 to detect 'pin-depends' packages that are not present in 'depends' nor in 'depopts'
1 parent eec1cc4 commit 99a404c

File tree

3 files changed

+137
-0
lines changed

3 files changed

+137
-0
lines changed

master_changes.md

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ users)
6060
## Source
6161

6262
## Lint
63+
* [NEW] Add W74 to detect `pin-depends` packages that are not present in `depends` nor `depopts` field [#6317 @rjbou - fix #5795]
6364

6465
## Repository
6566
* Accurately tag `curl` download command when loaded from global config file [#6270 @rjbou]

src/state/opamFileTools.ml

+15
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,21 @@ let t_lint ?check_extra_files ?(check_upstream=false) ?(all=false) t =
10981098
"Field 'extra-files' contains path with '..'"
10991099
~detail:relative
11001100
(relative <> []));
1101+
(let missing =
1102+
let pkgs =
1103+
List.map fst t.pin_depends
1104+
|> OpamPackage.Set.of_list
1105+
|> OpamPackage.names_of_packages
1106+
in
1107+
OpamPackage.Name.Set.diff pkgs all_depends
1108+
|> OpamPackage.Name.Set.elements
1109+
|> List.map OpamPackage.Name.to_string
1110+
in
1111+
cond 74 `Warning
1112+
"Field 'pin-depends' contains packages that are not in 'depends' nor in \
1113+
'depopts'"
1114+
~detail:missing
1115+
(missing <> []));
11011116
]
11021117
in
11031118
format_errors @

tests/reftests/lint.test

+121
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,7 @@ pin-depends: [
10351035
### opam lint ./lint.opam
10361036
${BASEDIR}/lint.opam: Errors.
10371037
error 65: URLs must be absolute: "./my/url/path", "/wrong/../mirror", "./../to@li.nt", "/my/./../extrasource/path", "/my/../pinned/package"
1038+
warning 74: Field 'pin-depends' contains packages that are not in 'depends' nor in 'depopts': "pinned"
10381039
# Return code 1 #
10391040
### : W66: String that can't be resolved to bool in filtered package formula
10401041
### <lint.opam>
@@ -1265,6 +1266,126 @@ ${BASEDIR}/lint.opam: Errors.
12651266
error 53: Mismatching 'extra-files:' field: "./relative/path", "/absolute/../relative/path", "/absolute/path", "extra-files..patch.patch"
12661267
error 73: Field 'extra-files' contains path with '..': "/absolute/../relative/path"
12671268
# Return code 1 #
1269+
### : E74: Field 'pin-depends' contains packages that are not in 'depends' nor in 'depopts'
1270+
### <lint.opam>
1271+
opam-version: "2.0"
1272+
synopsis: "A word"
1273+
description: "Two words."
1274+
authors: "the testing team"
1275+
homepage: "egapemoh"
1276+
maintainer: "maint@tain.er"
1277+
license: "ISC"
1278+
dev-repo: "hg+https://to@li.nt"
1279+
bug-reports: "https://nobug"
1280+
pin-depends: [
1281+
[ "foo.1" "file:///some/path" ]
1282+
[ "bar.1" "file:///some/path" ]
1283+
]
1284+
### opam lint ./lint.opam
1285+
${BASEDIR}/lint.opam: Warnings.
1286+
warning 74: Field 'pin-depends' contains packages that are not in 'depends' nor in 'depopts': "bar", "foo"
1287+
### <lint.opam>
1288+
opam-version: "2.0"
1289+
synopsis: "A word"
1290+
description: "Two words."
1291+
authors: "the testing team"
1292+
homepage: "egapemoh"
1293+
maintainer: "maint@tain.er"
1294+
license: "ISC"
1295+
dev-repo: "hg+https://to@li.nt"
1296+
bug-reports: "https://nobug"
1297+
depends: [ "foo" ]
1298+
pin-depends: [
1299+
[ "foo.1" "file:///some/path" ]
1300+
[ "bar.1" "file:///some/path" ]
1301+
]
1302+
### opam lint ./lint.opam
1303+
${BASEDIR}/lint.opam: Warnings.
1304+
warning 74: Field 'pin-depends' contains packages that are not in 'depends' nor in 'depopts': "bar"
1305+
### <lint.opam>
1306+
opam-version: "2.0"
1307+
synopsis: "A word"
1308+
description: "Two words."
1309+
authors: "the testing team"
1310+
homepage: "egapemoh"
1311+
maintainer: "maint@tain.er"
1312+
license: "ISC"
1313+
dev-repo: "hg+https://to@li.nt"
1314+
bug-reports: "https://nobug"
1315+
depopts: [ "bar" ]
1316+
pin-depends: [
1317+
[ "foo.1" "file:///some/path" ]
1318+
[ "bar.1" "file:///some/path" ]
1319+
]
1320+
### opam lint ./lint.opam
1321+
${BASEDIR}/lint.opam: Warnings.
1322+
warning 74: Field 'pin-depends' contains packages that are not in 'depends' nor in 'depopts': "foo"
1323+
### <lint.opam>
1324+
opam-version: "2.0"
1325+
synopsis: "A word"
1326+
description: "Two words."
1327+
authors: "the testing team"
1328+
homepage: "egapemoh"
1329+
maintainer: "maint@tain.er"
1330+
license: "ISC"
1331+
dev-repo: "hg+https://to@li.nt"
1332+
bug-reports: "https://nobug"
1333+
depends: [ "foo" "oof" ]
1334+
depopts: [ "bar" "rab" ]
1335+
pin-depends: [
1336+
[ "foo.1" "file:///some/path" ]
1337+
[ "bar.1" "file:///some/path" ]
1338+
]
1339+
### opam lint ./lint.opam
1340+
${BASEDIR}/lint.opam: Passed.
1341+
### <lint.opam>
1342+
opam-version: "2.0"
1343+
synopsis: "A word"
1344+
description: "Two words."
1345+
authors: "the testing team"
1346+
homepage: "egapemoh"
1347+
maintainer: "maint@tain.er"
1348+
license: "ISC"
1349+
dev-repo: "hg+https://to@li.nt"
1350+
bug-reports: "https://nobug"
1351+
depends: [ "foo" ]
1352+
pin-depends: [
1353+
[ "foo.1" "file:///some/path" ]
1354+
]
1355+
### opam lint ./lint.opam
1356+
${BASEDIR}/lint.opam: Passed.
1357+
### <lint.opam>
1358+
opam-version: "2.0"
1359+
synopsis: "A word"
1360+
description: "Two words."
1361+
authors: "the testing team"
1362+
homepage: "egapemoh"
1363+
maintainer: "maint@tain.er"
1364+
license: "ISC"
1365+
dev-repo: "hg+https://to@li.nt"
1366+
bug-reports: "https://nobug"
1367+
depopts: [ "bar" ]
1368+
pin-depends: [
1369+
[ "bar.1" "file:///some/path" ]
1370+
]
1371+
### opam lint ./lint.opam
1372+
${BASEDIR}/lint.opam: Passed.
1373+
### <lint.opam>
1374+
opam-version: "2.0"
1375+
synopsis: "A word"
1376+
description: "Two words."
1377+
authors: "the testing team"
1378+
homepage: "egapemoh"
1379+
maintainer: "maint@tain.er"
1380+
license: "ISC"
1381+
dev-repo: "hg+https://to@li.nt"
1382+
bug-reports: "https://nobug"
1383+
depends: [ "foo" { = "1" } ]
1384+
pin-depends: [
1385+
[ "foo.2" "file:///some/path" ]
1386+
]
1387+
### opam lint ./lint.opam
1388+
${BASEDIR}/lint.opam: Passed.
12681389
### :::::::::::::::::::::
12691390
### : Test parse errors :
12701391
### :::::::::::::::::::::

0 commit comments

Comments
 (0)