Commit Graph

26 Commits

Author SHA1 Message Date
Saku Laesvuori ab8612d99e
guix: import: Fix parsing Cabal files that import many stanzas
* guix/import/cabal.scm (eval-cabal)[eval]: Split imports to a
normalized list before mapping over it.
* tests/hackage.scm: Test it.

Change-Id: I39ece019251b6a23a937c8562d2d4a545a6bc7df
Signed-off-by: Lars-Dominik Braun <lars@6xq.net>
2023-12-03 16:15:29 +01:00
Saku Laesvuori 5bd00bb542
guix: import: Parse cabal layout blocks correctly
Cabal consideres lines to be part of a layout block if they are indented
at least one space more than the field line the block belongs to.
Previously Guix considered lines to be a part of the block if they were
indented at least as much as the first line in it.

This also makes a workaround that enabled if statements to have multiple
elses redundant and removes it.

Fixes: https://issues.guix.gnu.org/35743

* guix/import/cabal.scm (current-indentation*): Renamed from
current-indentation.
(previous-indentation, current-indentation): New variables.
(make-cabal-parser): Remove outdated comment.
[open]: Use previous-indentation + 1 instead of
current-indentation.
[elif-else]: Split to elif and else to allow only one ELSE in an if
statement.
(read-cabal)[parameterize]: Use current-indentation* and previous-indentation.
* tests/hackage.scm (hackage->guix-package test mixed layout): Expect to
  pass.

Change-Id: I3a1495b1588a022fabbfe8dad9f3231e578af4f3
Signed-off-by: Lars-Dominik Braun <lars@6xq.net>
2023-12-03 09:11:29 +01:00
Ludovic Courtès ae587c2ef0
guix: Strip #:use-module lists.
This was obtained by setting up this environment:

  guix shell -D guix --with-input=guile@3.0.9=guile-next \
    --with-commit=guile-next=e2ed33ef0445c867fe56c247054aa67e834861f2
    -- make -j5

then adding 'unused-module' to (@@ (guix build compiler) %warnings),
building, and checking all the "unused module" warnings and removing
those that were definitely unused.
2023-03-13 15:08:33 +01:00
Lars-Dominik Braun c3fbaee345
import: cabal: Support library names
* guix/import/cabal.scm (make-cabal-parser): Add name to section.
(is-lib): Add optional name to regular expression.
(lex-rx-res): Support selecting different substring.
(lex-lib): Match 2nd substring from IS-LIB.
(lex-line): Adapt to changes for lex-lib.
(cabal-library): Add name field and export CABAL-LIBRARY-NAME.
(eval): Remove special case for 'library, which is not required any more.
(make-cabal-section): Move special case for LIBRARY.
* tests/hackage.scm (test-read-cabal-library-name): New variable.
("read-cabal test 1"): Adapt testcase to changed internal structure.
("read-cabal test: library name"): New testcase.
2022-06-06 13:26:45 +02:00
Lars-Dominik Braun e3337f35af
import: cabal: Allow curly bracket before else statement.
* guix/import/cabal.scm (is-else): Turn into procedure.
(lex-line): Move IS-ELSE…
(lex-word): …here.
* tests/hackage.scm (test-cabal-elif-brackets): Extend testcase.
2022-06-06 13:26:45 +02:00
Lars-Dominik Braun 001e0bac99
import: cabal: Allow properties without space between key and value.
* guix/import/cabal.scm (lex-word): Add colon to delimiters.
* tests/hackage.scm (test-cabal-property-no-space): New variable.
("hackage->guix-package test properties without space"): New test.
2022-06-06 13:26:45 +02:00
Lars-Dominik Braun 0972feaff1
import: cabal: Allow curly brackets in more positions.
* guix/import/cabal.scm (is-layout-property): Do not expect end of line.
(lex-layout-property): Check for newline.
(lex-property): Stop reading on closing curly bracket.
* tests/hackage.scm (test-read-cabal-2): New variable.
("read-cabal test: if brackets on the same line"): New test.
2022-06-06 13:26:45 +02:00
Lars-Dominik Braun 2c5d18e421
import: cabal: Support elif statement.
Fixes <https://issues.guix.gnu.org/54752>.

* guix/import/cabal.scm (make-cabal-parser): Replace if-then-else grammar case with elif-else, modify if-then accordingly.
(is-elif): New procedure.
(lex-elif): Likewise.
(is-id): Add elif keyword.
(lex-word): Add test for elif.
* tests/hackage.scm (test-cabal-if): New variale.
(test-cabal-else): Likewise.
(test-cabal-elif): Likewise.
(test-cabal-elif-brackets): Likewise.
(match-ghc-elif): Likewise.
("hackage->guix-package test lonely if statement",
"hackage->guix-package test else statement",
"hackage->guix-package test elif statement",
"hackage->guix-package test elif statement with brackets"): New tests.
2022-06-06 13:26:09 +02:00
Xinglu Chen a840caccae
import: cabal: Treat identifier names correctly.
* guix/import/cabal.scm (is-id): Accept the location as an argument.  Don’t
check if the identifier name is a reserved keyword unless it is the first word
on the line.
(lex-word): Adjust accordingly.
* tests/hackage ("hackage->guix-package tests flag executable"): Expect it to
pass.

Fixes: <https://issues.guix.gnu.org/25138>
Signed-off-by: Lars-Dominik Braun <lars@6xq.net>
2021-09-15 14:28:38 +02:00
Philip Munksgaard dfac3e643a
import: hackage: Support "common" field and imports
Fixes <https://issues.guix.gnu.org/48701>.

* guix/import/cabal.scm (make-cabal-parser): Modify.
(is-common): New variable.
(lex-common): New procedure.
(is-id): Modify.
(eval-cabal): Modify.
* tests/hackage.scm ("hackage->guix-package test cabal import") New test.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2021-06-25 15:12:05 +02:00
Tobias Geerinckx-Rice bd16cc2902
import: Fix docstring typoes.
* guix/import/cabal.scm (cabal-flags->alist): Fix typo in docstring.
* guix/import/stackage.scm (lts-info-ghc-version): Likewise.
* guix/scripts/import/hackage.scm (show-help): Likewise.
2020-09-23 04:36:59 +02:00
Robert Vollmert ca45da9fc9
import: hackage: Handle Hackage revisions.
Hackage packages can have metadata revisions (Cabal file only) that are
not reflected in the source archive.  The Haskell build system has
support for this, but until now the Hackage importer would create a
package based on the revised Cabal file which would then build using the
old Cabal file.

Fixes <https://bugs.gnu.org/35750>.

* guix/import/cabal.scm (<cabal-package>): Add 'revision' field.
(eval-cabal): Parse 'x-revision:' property.
* guix/import/hackage.scm (read-cabal-and-hash): New procedure.
(hackage-fetch-and-hash): New procedure.
(hackage-fetch): Rewrite using 'hackage-fetch-and-hash'.
(hackage-module->sexp): Add 'cabal-hash' argument and use it to populate
the '#:cabal-revision' argument.
(hackage->guix-package): Use the new '-and-hash' functions to get the
hash of the Cabal file and pass it to 'hackage-module->sexp'.
* guix/tests/hackage.scm: Test import of Cabal file revision.

Signed-off-by: Timothy Sample <samplet@ngyro.com>
2019-06-13 22:18:52 -04:00
Robert Vollmert 959c9d159d
import: hackage: Parse braced properties.
This adds partial support for Cabal properties that use curly
braces instead of the layout rule.  See for example
https://hackage.haskell.org/package/cassava/

* guix/import/cabal.scm (read-braced-value): New procedure.
(is-property): Remove.
(is-layout-property, is-braced-property): New variables.
(lex-property): Rename to...
(lex-layout-property): ... this.
(lex-braced-property, lex-property): New procedures.
(lex-token): Add call to 'lex-property'.
* guix/tests/hackage.scm: Test braced description import.
* tests/hackage.scm (test-cabal-multiline-desc): Rename to...
(test-cabal-multiline-layout): ... this.
("hackage->guix-package test multiline desc"): Rename to...
("hackage->guix-package test multiline desc (layout)"): ... this.
(test-cabal-multiline-braced): New variable.
("hackage->guix-package test multiline desc (braced)"): New test.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2019-06-02 22:16:05 +02:00
Ricardo Wurmus f60784228a
import: cabal, hackage: Avoid error when custom setup section is missing.
Fixes <https://debbugs.gnu.org/32387>.

* guix/import/cabal.scm (eval-cabal): Avoid mis-match when the custom-setup
section cannot be created.
* guix/import/hackage.scm (cabal-custom-setup-dependencies->names): Do not
crash when cabal-package-custom-setup returns #F.
2018-08-07 20:39:12 +02:00
Danny Milosavljevic d804d0b9ef
import: hackage: Emit native-inputs in the importer.
* guix/import/cabal.scm (cabal-custom-setup-dependencies): Export.
(cabal-package-custom-setup): Export.
(<cabal-package>): New field "custom-setup".
(make-cabal-package): Modify.
(eval-cabal): Modify.
* guix/import/hackage.scm (cabal-dependencies->names): Factor out...
(cabal-test-dependencies->names): ...this.
(cabal-custom-setup-dependencies->names): New procedure.
(hackage-module->sexp): Modify.
2018-07-27 11:42:53 +02:00
Danny Milosavljevic e29067d22e
import: hackage: Fix typo.
* guix/import/cabal.scm (cabal-custom-setuo-name): Rename to...
(cabal-custom-setup-name): ...this.
2018-07-13 15:23:40 +02:00
Danny Milosavljevic e39a44f340
import: hackage: Evaluate "-any" and "-none" version comparison operators.
* guix/import/cabal.scm (eval-cabal): Modify.
* tests/hackage.scm (test-cabal-4): New variable and test.
(test-cabal-5): New variable and test.
(test-cabal-6): New variable and test.
2018-07-12 20:35:04 +02:00
Danny Milosavljevic ecba50bb79
import: hackage: Support "-any" and "-none" version comparison operators.
* guix/import/cabal.scm (make-cabal-parser): Modify.
(is-any): New variable.
(is-none): New variable.
(lex-any): New procedure.
(lex-none): New procedure.
(lex-word): Modify.
(eval-cabal): Modify.
2018-07-12 09:06:48 +02:00
Danny Milosavljevic 314b63e0b4
import: hackage: Support "custom-setup" field.
Fixes <https://bugs.gnu.org/23961>.

* guix/import/cabal.scm (make-cabal-parser): Modify.
(is-custom-setup): New variable.
(lex-custom-setup): New procedure.
(is-id): Modify.
(lex-version): Modify.
(<cabal-custom-setup>): New record type.
(eval-cabal): Modify.
(dependencies): Add parameter.
2018-07-12 09:06:48 +02:00
Mathieu Lirzin 74e667d149 packages: Use '@' in package record printers.
* guix/packages.scm <package>: Use '@' in record printer.
* guix/import/cabal.scm <cabal-package>: Likewise
* guix/import/elpa.scm <elpa-package>: Likewise.
* tests/packages.scm: Adapt to it.
2016-01-28 16:31:38 +01:00
Federico Beffa 94abc84887 import: hackage: Make parsing of tests and fields more flexible.
* guix/import/cabal.scm (is-test): Allow spaces between keyword and
  parentheses.
  (is-id): Add argument 'port'.  Allow spaces between keyword and column.
  (lex-word): Adjust call to 'is-id'.
2015-11-26 18:17:23 +01:00
Federico Beffa 876fd23ab6 import: hackage: Make it resilient to missing final newline.
* guix/import/cabal.scm (peek-next-line-indent): Check for missing final
  newline.
2015-11-26 18:17:23 +01:00
Federico Beffa 9be54eb1b1 import: hackage: Imporve parsing of tests.
* guix/import/cabal.scm (lex-word): Add support for tests with no spaces.
  (impl): Rewrite.
2015-11-26 18:17:23 +01:00
Federico Beffa 7716f55c83 import: hackage: Add recognition of 'true' and 'false' symbols.
* guix/import/cabal.scm (is-true, is-false, lex-true, lex-false): New procedures.
  (lex-word): Use them.
  (make-cabal-parser): Add TRUE and FALSE tokens.
  (eval): Add entries for 'true and 'false symbols.
2015-11-26 18:17:22 +01:00
Federico Beffa d8b6fcdeda import: cabal: Make token recognition case-insensitive.
* guix/import/cabal.scm (make-rx-matcher): Add optional parameter FLAG.
  (is-property, is-flag, is-src-repo, is-exec, is-test-suite, is-benchmark,
  is-lib, is-else, is-if): Make test case-insensitive.
2015-07-08 10:53:05 +02:00
Federico Beffa a415474873 import: hackage: Refactor parsing code and add new options.
* guix/import/cabal.scm: New file.
* guix/import/hackage.scm: Update to use the new Cabal parsing module.
* tests/hackage.scm: Update tests.
* guix/scripts/import/hackage.scm: Add new '--cabal-environment' and '--stdin'
  options.
* doc/guix.texi: ... and document them.
* Makefile.am (MODULES): Add 'guix/import/cabal.scm',
  'guix/import/hackage.scm' and 'guix/scripts/import/hackage.scm'.
  (SCM_TESTS): Add 'tests/hackage.scm'.
2015-06-09 09:48:38 +02:00