Skip to content

Commit

Permalink
Merge pull request ocaml#5639 from rjbou/lint-extra-files
Browse files Browse the repository at this point in the history
Fix extra-files handling on linting
  • Loading branch information
kit-ty-kate authored Aug 22, 2023
2 parents 560e2fb + 2a44d42 commit 6fa193a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 26 deletions.
2 changes: 2 additions & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ users)
## Source

## Lint
* Fix extra-files handling when linting packages from repositories, see #5068 [#5639 @rjbou]

## Repository

Expand Down Expand Up @@ -96,6 +97,7 @@ users)

## Reftests
### Tests
* Lint: add test for W53, to test extra file with good hash [#5639 @rjbou]

### Engine

Expand Down
16 changes: 7 additions & 9 deletions src/client/opamCommands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3826,8 +3826,8 @@ let lint cli =
let opam = OpamSwitchState.opam st nv in
match OpamPinned.orig_opam_file st (OpamPackage.name nv) opam with
| None -> raise Not_found
| Some f ->
let filename =
| Some file ->
let label =
match OpamFile.OPAM.metadata_dir opam with
| None -> None
| Some (None, abs) ->
Expand All @@ -3844,7 +3844,7 @@ let lint cli =
(OpamRepositoryName.to_string repo)
(OpamPackage.to_string nv))
in
[`pkg (OpamFilename.read (OpamFile.filename f), filename)]
[`pkg (file, label)]
with Not_found ->
OpamConsole.error_and_exit `Not_found "No opam file found for %s%s"
(OpamPackage.Name.to_string (fst pkg))
Expand All @@ -3870,12 +3870,10 @@ let lint cli =
| `file f ->
OpamFileTools.lint_file ~check_upstream ~handle_dirname:true f,
Some (OpamFile.to_string f)
| `pkg (content, filename) ->
OpamFileTools.lint_string
~check_upstream ~handle_dirname:false
OpamStd.Option.(default stdin_f (map to_file filename))
content,
filename
| `pkg (file, label) ->
OpamFileTools.lint_file ~check_upstream ~handle_dirname:false
file,
label
| `stdin ->
OpamFileTools.lint_channel ~check_upstream ~handle_dirname:false
stdin_f stdin,
Expand Down
58 changes: 41 additions & 17 deletions tests/reftests/lint.test
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
N0REP0
### # Needed for extra file check
### OPAMSTRICT=0
### <pkg:lint.1>
opam-version: "2.0"
synopsis: "A word"
description: "Two words."
authors: "the testing team"
homepage: "egapemoh"
maintainer: "[email protected]"
license: "ISC"
dev-repo: "hg+https://[email protected]"
bug-reports: "https://nobug"
extra-files: [ "more-file" "md5=00000000000000000000000000000000" ]
### <pkg:lint.1:more-file>
and there is content!
### opam switch create linting --empty
### # needed for check upstream checks
### <one-more-file>
Expand Down Expand Up @@ -534,19 +521,56 @@ ${BASEDIR}/lint.opam: Errors.
error 52: Package is needlessly flagged "light-uninstall", since it has no remove instructions
# Return code 1 #
### : E53: Mismatching 'extra-files:' field
### opam lint --package lint
### <pkg:lint.1>
opam-version: "2.0"
synopsis: "A word"
description: "Two words."
authors: "the testing team"
homepage: "egapemoh"
maintainer: "[email protected]"
license: "ISC"
dev-repo: "hg+https://[email protected]"
bug-reports: "https://nobug"
extra-files: [ "more-file-bad-md5" "md5=00000000000000000000000000000000" ]
### <pkg:lint.1:more-file-bad-md5>
and there is content!
### <pkg:lint.2>
opam-version: "2.0"
synopsis: "A word"
description: "Two words."
authors: "the testing team"
homepage: "egapemoh"
maintainer: "[email protected]"
license: "ISC"
dev-repo: "hg+https://[email protected]"
bug-reports: "https://nobug"
### <pkg:lint.2:more-file-good-md5>
and there is content!
### <add-hash.sh>
hsh=`openssl md5 REPO/packages/lint/lint.2/files/more-file-good-md5 | cut -d ' ' -f 2`
echo "extra-files: [ \"more-file-good-md5\" \"md5=$hsh\" ]" >> REPO/packages/lint/lint.2/opam
### sh add-hash.sh
### opam update

<><> Updating package repositories ><><><><><><><><><><><><><><><><><><><><><><>
[default] synchronised from file://${BASEDIR}/REPO
### opam lint --package lint.1
<default>/lint.1: Errors.
error 53: Mismatching 'extra-files:' field: "more-file"
error 53: Mismatching 'extra-files:' field: "more-file-bad-md5"
# Return code 1 #
### opam lint --package lint.2
<default>/lint.2: Passed.
### OPAMREPOSITORYTARRING=1
### opam update default

<><> Updating package repositories ><><><><><><><><><><><><><><><><><><><><><><>
[default] no changes from file://${BASEDIR}/REPO
### opam lint --package lint
### opam lint --package lint.1
<default>/lint.1: Errors.
error 53: Mismatching 'extra-files:' field: "more-file"
error 53: Mismatching 'extra-files:' field: "more-file-bad-md5"
# Return code 1 #
### opam lint --package lint.2
<default>/lint.2: Passed.
### : W54: External dependencies should not contain spaces nor empty string
### <lint.opam>
opam-version: "2.0"
Expand Down

0 comments on commit 6fa193a

Please sign in to comment.