public inbox for cygwin-apps@cygwin.com
 help / color / mirror / Atom feed
* Cygport Bug: "find: No such file" Errors When Packaging
@ 2022-09-15 19:38 William Hu
  2022-09-17 12:27 ` Jon Turney
  0 siblings, 1 reply; 5+ messages in thread
From: William Hu @ 2022-09-15 19:38 UTC (permalink / raw)
  To: cygwin-apps

Hello,

I think I've found a (relatively innocuous) bug in cygport. It can be reproduced 
by compiling the OCaml package without having OCaml installed (which doesn't 
sound like an unreasonable thing to try; it'd be odd if OCaml depended on 
itself). This results in many unattractive errors at the end of the `cygport 
package` stage when cygport searches for dependencies:

*** Info: Tagging package hint files as test:
find: ‘/usr/lib/ocaml’: No such file or directory
find: ‘/usr/lib/ocaml’: No such file or directory
>>> ocaml requires: cygwin libgcc1 flexdll ocaml-runtime
find: ‘/usr/lib/ocaml’: No such file or directory
find: ‘/usr/lib/ocaml’: No such file or directory
>>> ocaml-runtime requires: cygwin libgcc1
find: ‘/usr/lib/ocaml’: No such file or directory
find: ‘/usr/lib/ocaml’: No such file or directory
>>> ocaml-compiler-libs requires: ocaml-runtime ocaml
find: ‘/usr/lib/ocaml’: No such file or directory
find: ‘/usr/lib/ocaml’: No such file or directory
>>> ocaml-ocamldoc requires: cygwin libgcc1 ocaml-compiler-libs ocaml-runtime
find: ‘/usr/lib/ocaml’: No such file or directory
find: ‘/usr/lib/ocaml’: No such file or directory
>>> ocaml-source requires:
find: ‘/usr/lib/ocaml’: No such file or directory
find: ‘/usr/lib/ocaml’: No such file or directory
>>> ocaml-doc requires:

Looking at cygport's code 
<https://github.com/cygwin/cygport/blob/8407994126516d73aeb17b6b829578c0848a4c4d/lib/pkg_info.cygpart#L364>
 it seems cygport checks for the existence of ocamlc.opt on PATH. Because the 
(package being built)'s install directory is appended to PATH by cygport, this 
will always be true in my case.

OCaml's compilers hardcode their location at compile time, so ocamlc.opt believes 
the standard library lives in "/usr/lib/ocaml" which is placed in `mldir`.

Cygport checks one more time to make sure mldir exists in the package being built 
(this second check is why those errors are hard to trigger on a non-OCaml package) 
and then calls `find` on both ${D}${mldir} and ${mldir}. Of course, since the 
*real* /usr/lib/ocaml won't exist if OCaml isn't installed on your actual system 
when you build it, find will output an error when run on those two directories.

Two ways to fix this would be to either remove the ${mldir} argument from find or 
test if ${mldir} exists and set it to the empty string if it doesn't. The second 
would likely preserve compatibility if there exist packages that depend on find 
searching both directories. The buggy test was added in 
<https://github.com/cygwin/cygport/commit/7d24eb71bdd91e2a368739728dbd522ddd4faaac>. 
Does anyone else have any insights or suggestions or does the above fix sound
reasonable?

Thanks,
William


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Cygport Bug: "find: No such file" Errors When Packaging
  2022-09-15 19:38 Cygport Bug: "find: No such file" Errors When Packaging William Hu
@ 2022-09-17 12:27 ` Jon Turney
  2022-09-17 21:14   ` William Hu
  0 siblings, 1 reply; 5+ messages in thread
From: Jon Turney @ 2022-09-17 12:27 UTC (permalink / raw)
  To: William Hu, cygwin-apps

On 15/09/2022 20:38, William Hu via Cygwin-apps wrote:
> Hello,
> 
[...]
> 
> Cygport checks one more time to make sure mldir exists in the package being built
> (this second check is why those errors are hard to trigger on a non-OCaml package)
> and then calls `find` on both ${D}${mldir} and ${mldir}. Of course, since the
> *real* /usr/lib/ocaml won't exist if OCaml isn't installed on your actual system
> when you build it, find will output an error when run on those two directories.
> 
> Two ways to fix this would be to either remove the ${mldir} argument from find or
> test if ${mldir} exists and set it to the empty string if it doesn't. The second
> would likely preserve compatibility if there exist packages that depend on find
> searching both directories. The buggy test was added in
> <https://github.com/cygwin/cygport/commit/7d24eb71bdd91e2a368739728dbd522ddd4faaac>.
> Does anyone else have any insights or suggestions or does the above fix sound
> reasonable?

I think just dropping ${mldir} would prevent cygport from detecting the 
dependencies of an ocaml library (other ocaml libraries, or ocaml 
itself?), but the second alternative sounds acceptable.

Patches welcome, as always :)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Cygport Bug: "find: No such file" Errors When Packaging
  2022-09-17 12:27 ` Jon Turney
@ 2022-09-17 21:14   ` William Hu
  2022-09-18 13:17     ` Jon Turney
  0 siblings, 1 reply; 5+ messages in thread
From: William Hu @ 2022-09-17 21:14 UTC (permalink / raw)
  To: Jon Turney; +Cc: cygwin-apps

[-- Attachment #1: Type: text/plain, Size: 305 bytes --]

Hi Jon,

> I think just dropping ${mldir} would prevent cygport from detecting the
> dependencies of an ocaml library (other ocaml libraries, or ocaml
> itself?), but the second alternative sounds acceptable.
> 
> Patches welcome, as always :)

Thanks for the insight! Patch attached :)

William

[-- Attachment #2: cygport_check_mldir_exist.patch --]
[-- Type: application/octet-stream, Size: 393 bytes --]

--- origsrc/cygport-0.35.2/lib/pkg_info.cygpart	2022-06-07 13:39:54.941449400 -0400
+++ src/cygport-0.35.2/lib/pkg_info.cygpart	2022-09-17 17:08:50.009165400 -0400
@@ -364,6 +364,10 @@
 	if check_prog ocamlc.opt
 	then
 		mldir=$(ocamlc.opt -where)
+		if [ ! -d ${mldir} ]
+		then
+			mldir=""
+		fi
 		if [ -d ${D}${mldir} ]
 		then
 			for cma in $(find ${D}${mldir} ${mldir} -name '*.cma')

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Cygport Bug: "find: No such file" Errors When Packaging
  2022-09-17 21:14   ` William Hu
@ 2022-09-18 13:17     ` Jon Turney
  2022-10-02 20:49       ` William Hu
  0 siblings, 1 reply; 5+ messages in thread
From: Jon Turney @ 2022-09-18 13:17 UTC (permalink / raw)
  To: William Hu, cygwin-apps

On 17/09/2022 22:14, William Hu via Cygwin-apps wrote:
> Hi Jon,
> 
>> I think just dropping ${mldir} would prevent cygport from detecting the
>> dependencies of an ocaml library (other ocaml libraries, or ocaml
>> itself?), but the second alternative sounds acceptable.
>>
>> Patches welcome, as always :)
> 
> Thanks for the insight! Patch attached :)

Thanks.

This change is probably safe and does what you say, but it looks like it 
could potentially misbehave when ${mldir} doesn't exist, but 
${D}/${mldir} does (a situation which probably can't occur, as it 
doesn't seem to make sense to build ocaml libraries when ocaml isn't 
installed?)

In future, please try to use git-format-patch, if possible, as that 
saves me having to write patch commentary, and ensures correct patch 
attribution.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Cygport Bug: "find: No such file" Errors When Packaging
  2022-09-18 13:17     ` Jon Turney
@ 2022-10-02 20:49       ` William Hu
  0 siblings, 0 replies; 5+ messages in thread
From: William Hu @ 2022-10-02 20:49 UTC (permalink / raw)
  To: Jon Turney; +Cc: cygwin-apps

[-- Attachment #1: Type: text/plain, Size: 740 bytes --]

Hi Jon,

> This change is probably safe and does what you say, but it looks like it
> could potentially misbehave when ${mldir} doesn't exist, but
> ${D}/${mldir} does (a situation which probably can't occur, as it
> doesn't seem to make sense to build ocaml libraries when ocaml isn't
> installed?)

Sorry for the delay - I fell ill but I'm better now. You make a very good 
point which was actually the edge case I initially intended to fix. Thanks 
for the catch!

> In future, please try to use git-format-patch, if possible, as that
> saves me having to write patch commentary, and ensures correct patch
> attribution.

Patch attached. Please let me know if I did it properly (first time using 
git format).

William

[-- Attachment #2: 0001-Fix-find-errors-for-nonexistent-mldir.patch --]
[-- Type: application/octet-stream, Size: 1133 bytes --]

From bc6be2bb4bcb94a7331db61fe7c174648aa44dbf Mon Sep 17 00:00:00 2001
From: William Hu <purplearmadillo77@proton.me>
Date: Sun, 2 Oct 2022 16:20:35 -0400
Subject: [PATCH] Fix find errors for nonexistent ${mldir}

---
 lib/pkg_info.cygpart | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/lib/pkg_info.cygpart b/lib/pkg_info.cygpart
index 4c51483..c399cc5 100644
--- a/lib/pkg_info.cygpart
+++ b/lib/pkg_info.cygpart
@@ -364,13 +364,18 @@ __list_deps() {
 	if check_prog ocamlc.opt
 	then
 		mldir=$(ocamlc.opt -where)
+		sys_mldir=$mldir
+		if [ ! -d ${sys_mldir} ]
+		then
+			sys_mldir=""
+		fi
 		if [ -d ${D}${mldir} ]
 		then
-			for cma in $(find ${D}${mldir} ${mldir} -name '*.cma')
+			for cma in $(find ${D}${mldir} ${sys_mldir} -name '*.cma')
 			do
 				ocamlobjinfo $cma | sed -nr "s#(Unit|Module) name: #$cma:#p"
 			done > ${T}/.cmaobjinfo.out
-			for cmxa in $(find ${D}${mldir} ${mldir} -name '*.cmxa')
+			for cmxa in $(find ${D}${mldir} ${sys_mldir} -name '*.cmxa')
 			do
 				ocamlobjinfo $cmxa | sed -nr "s#(Unit|Module) name: #$cmxa:#p"
 			done > ${T}/.cmxaobjinfo.out
-- 
2.37.3


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-10-02 20:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-15 19:38 Cygport Bug: "find: No such file" Errors When Packaging William Hu
2022-09-17 12:27 ` Jon Turney
2022-09-17 21:14   ` William Hu
2022-09-18 13:17     ` Jon Turney
2022-10-02 20:49       ` William Hu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).