guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: java: How to patch a jar-sources


From: Gábor Boskovits
Subject: Re: java: How to patch a jar-sources
Date: Tue, 16 Apr 2019 11:50:45 +0200

Hello Björn,

Björn Höfling <address@hidden> ezt írta (időpont:
2019. ápr. 16., K, 1:49):
>
> On Mon, 15 Apr 2019 17:19:53 +0200
> Danny Milosavljevic <address@hidden> wrote:
>
> > (define* (unpack #:key source #:allow-other-keys)
> >   "Unpack the jar archive SOURCE.  When SOURCE is not a jar archive
> > fall back to the default GNU unpack strategy."
> >   (if (string-suffix? ".jar" source)
> >       (begin
> >         (mkdir "src")
> >         (with-directory-excursion "src"
> >           (invoke "jar" "-xf" source))
> >         #t)
> >       ;; Use GNU unpack strategy for things that aren't jar archives.
> >       ((assq-ref gnu:%standard-phases 'unpack) #:source source)))
>
> This is only for the case without patches.
>
> > Hmm... maybe the patched source gets a random name that doesn't end
> > in ".jar"
>
> The problem is before: It occurs during unpacking: The .jar file is
> getting handled with "tar xvf". I looked into the source-derivation and
> found the pieces. I added this line:
>
> diff --git a/guix/packages.scm b/guix/packages.scm
> index c94a651f27..412dfcc04c 100644
> --- a/guix/packages.scm
> +++ b/guix/packages.scm
> @@ -488,12 +488,13 @@ specifies modules in scope when evaluating SNIPPET."
>    (define decompression-type
>      (cond ((string-suffix? "gz" source-file-name)  "gzip")
>            ((string-suffix? "Z" source-file-name)  "gzip")
>            ((string-suffix? "bz2" source-file-name) "bzip2")
>            ((string-suffix? "lz" source-file-name)  "lzip")
>            ((string-suffix? "zip" source-file-name) "unzip")
> +          ((string-suffix? "jar" source-file-name) "unzip")
>            (else "xz")))
>
>
> This brings me a step further: The .jar-file will now be extracted.
> Unfortunately, we have this in line number 593:
>
>             (let ((directory (first-file ".")))
>               (format (current-error-port)
>                       "source is under '~a'~%" directory)
>               (chdir directory)
>
> That means: It is expected that the tarball/zipfile/archive contains a
> single directory under which the sources are contained. That seams to
> be the case for all .tar.* and .zip archives used within Guix packages.
>
> To verify that, I (randomly) picked the fcgi package and repacked the
> tarball, such that sources are directly in the root folder. I then get
> this expected error:
>
> [..]
> Win32/logdump.dsp
> source is under 'acinclude.m4'
> Backtrace:
>            2 (primitive-load "/gnu/store/phlnb6vy2gqjn75pivpsajyf9mq?")
> In ice-9/eval.scm:
>     619:8  1 (_ #(#<directory (guile-user) 5ce140> "acinclude.m4"))
> In unknown file:
>            0 (chdir "acinclude.m4")
>
> ERROR: In procedure chdir:
> In procedure chdir: Not a directory
>
>
> Unfortunately, .jar-source-files ARE organized in such a way that
> sources are organized directly in the root folder of the jar. I
> currently don't see a quick AND nice way to fix this.
>
> Wait, I have this idea:
>
> diff --git a/guix/packages.scm b/guix/packages.scm
> index c94a651f27..ffd06de358 100644
> --- a/guix/packages.scm
> +++ b/guix/packages.scm
> @@ -491,6 +491,7 @@ specifies modules in scope when evaluating SNIPPET."
>            ((string-suffix? "bz2" source-file-name) "bzip2")
>            ((string-suffix? "lz" source-file-name)  "lzip")
>            ((string-suffix? "zip" source-file-name) "unzip")
> +          ((string-suffix? "jar" source-file-name) "jar")
>            (else "xz")))
>
>    (define original-file-name
> @@ -584,12 +585,16 @@ specifies modules in scope when evaluating SNIPPET."
>                         (directory (string-drop base (+ 1 dash))))
>                    (mkdir directory)
>                    (copy-recursively #+source directory))
> -                #+(if (string=? decompression-type "unzip")
> +                #+(if (or
> +                       (string=? decompression-type "unzip")
> +                       (string=? decompression-type "jar"))
>                        #~(invoke "unzip" #+source)
>                        #~(invoke (string-append #+tar "/bin/tar")
>                                  "xvf" #+source)))
>
> -            (let ((directory (first-file ".")))
> +            (let ((directory (if (string=? decompression-type "jar")
> +                                 "."
> +                                 (first-file "."))))
>                (format (current-error-port)
>                        "source is under '~a'~%" directory)
>                (chdir directory)
>
> But it fails with:
>
> In unknown file:
>    ?: 5 [primitive-load 
> "/gnu/store/kg3pa52ydp3qjy41wgl0jcx3a98m82x9-guile-2.2.4.tar.xz-builder"]
> In ice-9/eval.scm:
>  411: 4 [eval # ()]
>  399: 3 [eval # ()]
>  387: 2 [eval # ()]
>  393: 1 [eval #<memoized decompression-type> ()]
> In unknown file:
>    ?: 0 [memoize-variable-access! # #]
>
> ERROR: In procedure memoize-variable-access!:
> ERROR: Unbound variable: decompression-type
>
> What's wrong here?
>

I don't see the whole code here, but I  guess that the last time use
decompression-type in a section under
different quoting rules. Is that possible?

Also, you might have a look at url-fetch/tarbomb, as something similar
must be done there.

> Björn

Best regards,
g_bor



reply via email to

[Prev in Thread] Current Thread [Next in Thread]