Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lint W59 with a local path that is not an archive #6219

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ users)
## Source

## Lint
* [BUG] fix lint W59 with local urls that are not archives [#6219 @rjbou - fix #6218]

## Repository

Expand Down Expand Up @@ -107,6 +108,7 @@ users)

## Reftests
### Tests
* Add more tests for lint W59 [#6219 @rjbou]

### Engine

Expand Down
12 changes: 9 additions & 3 deletions src/state/opamFileTools.ml
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,15 @@ let t_lint ?check_extra_files ?(check_upstream=false) ?(all=false) t =
| #OpamUrl.version_control -> true
| _ -> false)
in
let url_archive =
let open OpamStd.Option.Op in
t.url >>| OpamFile.URL.url >>| (fun u ->
OpamSystem.is_archive u.OpamUrl.path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think that's right. is_archive will look up the file locally. If you have an url like https:///etc/fstab, the path will be looked up.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, we should then add a function that checks if a path looks like an archive, like looks_like_ssh_path.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not sure we need a new function. Something like that would work just fine i think:

Suggested change
OpamSystem.is_archive u.OpamUrl.path)
OpamSystem.local_file u <> None)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to check file existence on disk (which does OpamUrl.local_file). We want to know if given string seems like an archive path.

Copy link
Member

@kit-ty-kate kit-ty-kate Oct 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about adding a function similar to OpamUrl.kind from #5979?

in
let is_url_archive =
not (OpamFile.OPAM.has_flag Pkgflag_Conf t) &&
url_vcs = Some false
not (OpamFile.OPAM.has_flag Pkgflag_Conf t)
&& url_vcs = Some false
&& url_archive = Some true
in
let check_upstream = check_upstream && is_url_archive in
let check_double compare to_str lst =
Expand Down Expand Up @@ -1001,7 +1007,7 @@ let t_lint ?check_extra_files ?(check_upstream=false) ?(all=false) t =
|> List.map OpamHash.to_string
|> OpamStd.Format.pretty_list)])
t.url)
(url_vcs = Some true
(url_vcs = Some true && url_archive = Some false
&& OpamStd.Option.Op.(t.url >>| fun u -> OpamFile.URL.checksum u <> [])
= Some true);
cond 68 `Warning
Expand Down
51 changes: 49 additions & 2 deletions tests/reftests/lint.test
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,7 @@ ${BASEDIR}/lint.opam: Warnings.
### opam lint ./lint.opam --check-upstream
${BASEDIR}/lint.opam: Warnings.
warning 59: url doesn't contain a checksum
### # package with conf flag
### <lint.opam>
opam-version: "2.0"
synopsis: "A word"
Expand All @@ -864,7 +865,6 @@ dev-repo: "hg+https://to@li.nt"
bug-reports: "https://nobug"
url { src:"an-archive.tgz" }
flags: conf
### # package with conf flag
### opam lint ./lint.opam
${BASEDIR}/lint.opam: Errors.
error 46: Package is flagged "conf" but has source, install or remove instructions
Expand All @@ -873,6 +873,7 @@ ${BASEDIR}/lint.opam: Errors.
${BASEDIR}/lint.opam: Errors.
error 46: Package is flagged "conf" but has source, install or remove instructions
# Return code 1 #
### # package with git url
### <lint.opam>
opam-version: "2.0"
synopsis: "A word"
Expand All @@ -884,7 +885,53 @@ license: "ISC"
dev-repo: "hg+https://to@li.nt"
bug-reports: "https://nobug"
url { src:"git+https://a/repo" }
### # package with git url
### opam lint ./lint.opam
${BASEDIR}/lint.opam: Passed.
### opam lint ./lint.opam --check-upstream
${BASEDIR}/lint.opam: Passed.
### # package with local url
### <repo/stuff>
something
### <lint.opam>
opam-version: "2.0"
synopsis: "A word"
description: "Two words."
authors: "the testing team"
homepage: "egapemoh"
maintainer: "maint@tain.er"
license: "ISC"
dev-repo: "hg+https://to@li.nt"
bug-reports: "https://nobug"
### <add-url.sh>
basedir=$(echo "$BASEDIR" | sed "s/\\\\\\\\/\\\\\\\\\\\\\\\\/g")
cat << EOF >> lint.opam
url { src:"file://$basedir/an-archive" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure to understand the issue. The an-archive directory doesn't exists at this point right? Shouldn't we raise a warning here for this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, linting should only check the content of the file and what is required in an opam file. If we want to check things on disk, it should be another option, as for --check-upstream

EOF
### sh add-url.sh
### opam lint ./lint.opam
${BASEDIR}/lint.opam: Passed.
### opam lint ./lint.opam --check-upstream
${BASEDIR}/lint.opam: Passed.
### # package with local archive url
### <lint.opam>
opam-version: "2.0"
synopsis: "A word"
description: "Two words."
authors: "the testing team"
homepage: "egapemoh"
maintainer: "maint@tain.er"
license: "ISC"
dev-repo: "hg+https://to@li.nt"
bug-reports: "https://nobug"
### <add-url.sh>
basedir=$(echo "$BASEDIR" | sed "s/\\\\\\\\/\\\\\\\\\\\\\\\\/g")
cat << EOF >> lint.opam
url {
src:"file://$basedir/an-archive.tgz"
checksum: "md5=$(openssl md5 an-archive.tgz | cut -f2 -d' ')"
}
EOF
### sh add-url.sh
### opam lint ./lint.opam
${BASEDIR}/lint.opam: Passed.
### opam lint ./lint.opam --check-upstream
Expand Down
Loading