Skip to content

Commit

Permalink
Merge pull request #75 from kit-ty-kate/verbose+fixes
Browse files Browse the repository at this point in the history
mitigate ocaml/opam#3782 + call opam-2.1 in verbose mode
  • Loading branch information
kit-ty-kate authored Feb 21, 2021
2 parents ce3e0c2 + d2c5093 commit 93674f0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
22 changes: 21 additions & 1 deletion lib/lint.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type error =
| UnmatchedName of OpamPackage.Name.t
| UnmatchedVersion of OpamPackage.Version.t
| UnexpectedFile of string
| ForbiddenPerm of string
| OpamLint of (int * [`Warning | `Error] * string)

module Check = struct
Expand All @@ -29,6 +30,11 @@ module Check = struct
Analyse.Analysis.get_opam ~cwd (path_from_pkg pkg // "opam") >>/= fun opam ->
Lwt.return (OpamFile.OPAM.read_from_string opam)

let is_perm_644 file =
Lwt_unix.stat file >|= function
| {st_kind = S_REG; st_perm = 0o644; _} -> true
| _ -> false

let get_files dirname =
Lwt_unix.opendir dirname >>= fun dir ->
let rec aux files =
Expand All @@ -52,9 +58,19 @@ module Check = struct
get_files dir >>= fun files ->
let rec aux errors extra_files = function
| [] -> Lwt.return (errors, extra_files)
| "opam"::files -> aux errors extra_files files
| "opam"::files ->
is_perm_644 (dir // "opam") >|= begin function
| true -> errors
| false -> ((pkg, ForbiddenPerm (dir // "opam")) :: errors)
end >>= fun errors ->
aux errors extra_files files
| "files"::files ->
get_files (dir // "files") >>= fun extra_files ->
Lwt_list.fold_left_s (fun errors file ->
is_perm_644 (dir // "files" // file) >|= function
| true -> errors
| false -> ((pkg, ForbiddenPerm (dir // "files" // file)) :: errors)
) errors extra_files >>= fun errors ->
let check_hash file hash = try OpamHash.check_file file hash with _ -> false in
let extra_files =
List.map (fun file ->
Expand Down Expand Up @@ -158,6 +174,10 @@ module Lint = struct
(OpamPackage.Version.to_string (OpamPackage.version package))
| UnexpectedFile file ->
Fmt.str "Error in %s: Unexpected file in %s/files/%s" pkg (Check.path_from_pkg package) file
| ForbiddenPerm file ->
Fmt.str
"Error in %s: Forbidden permission for file %s/files/%s. All files should have permissions 644."
pkg (Check.path_from_pkg package) file
| OpamLint warn ->
let warn = OpamFileTools.warns_to_string [warn] in
Fmt.str "Error in %s: %s" pkg warn
Expand Down
6 changes: 3 additions & 3 deletions lib/opam_build.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let opam_install ~variant ~upgrade_opam ~pin ~with_tests ~pkg =
test "$res" = 0 && exit 0
if test "$res" = 60 && diff -q /usr/bin/opam /usr/bin/opam-2.0; then
sudo ln -f /usr/bin/opam-2.1 /usr/bin/opam
opam remove -y %s && opam install -y%s %s%s
opam remove -y %s && opam install -vy%s %s%s
exit 1
fi
test "$res" != 31 && exit 1
Expand All @@ -37,8 +37,8 @@ let opam_install ~variant ~upgrade_opam ~pin ~with_tests ~pkg =
done
exit 1
|}
pkg (if upgrade_opam then "install -y" else "depext -uivy") (if with_tests then "t" else "") pkg
pkg (if with_tests then "t" else "") pkg (if with_tests then "" else " && opam reinstall -yt "^pkg)
pkg (if upgrade_opam then "install -vy" else "depext -uivy") (if with_tests then "t" else "") pkg
pkg (if with_tests then "t" else "") pkg (if with_tests then "" else " && opam reinstall -vyt "^pkg)
(Variant.distribution variant)
]

Expand Down

0 comments on commit 93674f0

Please sign in to comment.