From patchwork Sun Jul 4 11:54:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Xinglu Chen X-Patchwork-Id: 31125 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 9282827BC78; Sun, 4 Jul 2021 12:55:14 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,SPF_HELO_PASS,T_DKIM_INVALID,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id BB04527BC81 for ; Sun, 4 Jul 2021 12:55:13 +0100 (BST) Received: from localhost ([::1]:59854 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m00iO-0003pT-Sf for patchwork@mira.cbaines.net; Sun, 04 Jul 2021 07:55:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49900) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m00iE-0003oI-LM for guix-patches@gnu.org; Sun, 04 Jul 2021 07:55:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:57149) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m00iE-0006yy-Ds for guix-patches@gnu.org; Sun, 04 Jul 2021 07:55:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1m00iE-0000cQ-Db for guix-patches@gnu.org; Sun, 04 Jul 2021 07:55:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#48999] [PATCH v2 1/3] import: hackage: Accept local source for package. Resent-From: Xinglu Chen Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 04 Jul 2021 11:55:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 48999 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 48999@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= , zimoun Received: via spool by 48999-submit@debbugs.gnu.org id=B48999.16253996512266 (code B ref 48999); Sun, 04 Jul 2021 11:55:02 +0000 Received: (at 48999) by debbugs.gnu.org; 4 Jul 2021 11:54:11 +0000 Received: from localhost ([127.0.0.1]:40455 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m00hO-0000aU-J6 for submit@debbugs.gnu.org; Sun, 04 Jul 2021 07:54:10 -0400 Received: from h87-96-130-155.cust.a3fiber.se ([87.96.130.155]:45466 helo=mail.yoctocell.xyz) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m00hM-0000a2-PM for 48999@debbugs.gnu.org; Sun, 04 Jul 2021 07:54:09 -0400 From: Xinglu Chen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yoctocell.xyz; s=mail; t=1625399643; bh=cmcvjkAs5+0r+k46+djafKT2CgLBJybMyMNJOZ1jCV8=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=UYG1fCzle7GH1q6wfwov5YHNoEx83V7GHAxrn5rPMRzgwrPH0da205KAgYgEj7Jan 9Fj11expo71nl2MWCslgXDBXE3hg3zMNqS9KXyEpJBW3oYAJ0qDQY4T1EzvwhweI4h 0D0/sEGsdwzn/pCeBVZUPKyxmG49nq15+YugvCf8= In-Reply-To: References: Message-Id: Date: Sun, 04 Jul 2021 13:54:02 +0200 MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches When developing a Haskell package it is often useful to have a Guix package definition for that package, previously one would have to write that package definition by hand, and if the .cabal file changed one would manually update the Guix package definition. This commit allows one to specify a custom source for their package, meaning that one could programatically generate a Guix package definition for their local Haskell package. If the .cabal file changes, the generated package definition will also change accordingly. One could for instance write the following in a guix.scm file: (define-values (ghc-haskeme deps) (call-with-input-file "haskeme.cabal" (lambda (port) (hackage->guix-package "haskeme" #:port port #:source (local-file "." "haskeme-checkout" #:recursive? #t #:select? hg-predicate))))) ghc-haskeme Invoking ‘guix build -f guix.scm’ would then always build an up-to-date version of the package. * guix/import/hackage.scm (hackage-module->sexp): Add optional keyword argument ‘source’ (hackage->guix-package): Likewise. * tests/hackage.scm (eval-test-with-cabal): Likewise. ("hackage->guix-package local source"): New test. --- guix/import/hackage.scm | 43 ++++++++++++++++++++++++++--------------- tests/hackage.scm | 28 +++++++++++++++++++++++++-- 2 files changed, 53 insertions(+), 18 deletions(-) diff --git a/guix/import/hackage.scm b/guix/import/hackage.scm index f94a1e7087..326ab92365 100644 --- a/guix/import/hackage.scm +++ b/guix/import/hackage.scm @@ -227,10 +227,13 @@ package being processed and is used to filter references to itself." dependencies)) (define* (hackage-module->sexp cabal cabal-hash - #:key (include-test-dependencies? #t)) + #:key + (include-test-dependencies? #t) + (source #f)) "Return the `package' S-expression for a Cabal package. CABAL is the -representation of a Cabal file as produced by 'read-cabal'. CABAL-HASH is -the hash of the Cabal file." +representation of a Cabal file as produced by 'read-cabal'. CABAL-HASH is the +hash of the Cabal file. If SOURCE is specified, it will be used as the source +for the package." (define name (cabal-package-name cabal)) @@ -294,20 +297,24 @@ the hash of the Cabal file." (() '()) (args `((arguments (,'quasiquote ,args)))))) - (let ((tarball (with-store store - (download-to-store store source-url)))) + (let ((tarball (if source + #f + (with-store store + (download-to-store store source-url))))) (values `(package (name ,(hackage-name->package-name name)) (version ,version) - (source (origin - (method url-fetch) - (uri (string-append ,@(factorize-uri source-url version))) - (sha256 - (base32 - ,(if tarball - (bytevector->nix-base32-string (file-sha256 tarball)) - "failed to download tar archive"))))) + (source ,(if source + source + `(origin + (method url-fetch) + (uri (string-append ,@(factorize-uri source-url version))) + (sha256 + (base32 + ,(if tarball + (bytevector->nix-base32-string (file-sha256 tarball)) + "failed to download tar archive")))))) (build-system haskell-build-system) ,@(maybe-inputs 'inputs dependencies) ,@(maybe-inputs 'native-inputs native-dependencies) @@ -321,10 +328,12 @@ the hash of the Cabal file." (define* (hackage->guix-package package-name #:key (include-test-dependencies? #t) (port #f) + (source #f) (cabal-environment '())) "Fetch the Cabal file for PACKAGE-NAME from hackage.haskell.org, or, if the -called with keyword parameter PORT, from PORT. Return the `package' -S-expression corresponding to that package, or #f on failure. +called with keyword parameter PORT, from PORT. If SOURCE is specified, use it +as the source for the package instead of trying to fetch a tarball. Return +the `package' S-expression corresponding to that package, or #f on failure. CABAL-ENVIRONMENT is an alist defining the environment in which the Cabal conditionals are evaluated. The accepted keys are: \"os\", \"arch\", \"impl\" and the name of a flag. The value associated with a flag has to be either the @@ -338,7 +347,9 @@ respectively." (hackage-fetch-and-hash package-name)))) (and=> cabal-meta (compose (cut hackage-module->sexp <> cabal-hash #:include-test-dependencies? - include-test-dependencies?) + include-test-dependencies? + #:source + source) (cut eval-cabal <> cabal-environment))))) (define hackage->guix-package/m ;memoized variant diff --git a/tests/hackage.scm b/tests/hackage.scm index 53972fc643..3083a5d4df 100644 --- a/tests/hackage.scm +++ b/tests/hackage.scm @@ -22,6 +22,7 @@ #:use-module (guix import cabal) #:use-module (guix import hackage) #:use-module (guix tests) + #:use-module (guix gexp) #:use-module (srfi srfi-64) #:use-module (ice-9 match)) @@ -186,9 +187,28 @@ library ('description (? string?)) ('license 'license:bsd-3))) -(define* (eval-test-with-cabal test-cabal matcher #:key (cabal-environment '())) +(define-package-matcher match-ghc-foo-local-source + ('package + ('name "ghc-foo") + ('version "1.0.0") + ('source + (? file-like?)) + ('build-system 'haskell-build-system) + ('inputs + ('quasiquote + (("ghc-http" ('unquote 'ghc-http))))) + ('home-page "http://test.org") + ('synopsis (? string?)) + ('description (? string?)) + ('license 'license:bsd-3))) + +(define* (eval-test-with-cabal test-cabal matcher + #:key (cabal-environment '()) (source #f)) (define port (open-input-string test-cabal)) - (matcher (hackage->guix-package "foo" #:port port #:cabal-environment cabal-environment))) + (matcher (hackage->guix-package "foo" + #:port port + #:cabal-environment cabal-environment + #:source source))) (test-assert "hackage->guix-package test 1" (eval-test-with-cabal test-cabal-1 match-ghc-foo)) @@ -208,6 +228,10 @@ library (eval-test-with-cabal test-cabal-5 match-ghc-foo #:cabal-environment '(("impl" . "ghc-7.8")))) +(test-assert "hackage->guix-package local source" + (eval-test-with-cabal test-cabal-1 match-ghc-foo-local-source + #:source (plain-file "dummy source" "source"))) + (define-package-matcher match-ghc-foo-6 ('package ('name "ghc-foo") From patchwork Sun Jul 4 11:54:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Xinglu Chen X-Patchwork-Id: 31126 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 6764D27BC81; Sun, 4 Jul 2021 12:55:22 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,SPF_HELO_PASS,T_DKIM_INVALID,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 2BAA727BC78 for ; Sun, 4 Jul 2021 12:55:22 +0100 (BST) Received: from localhost ([::1]:60240 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m00iX-000462-95 for patchwork@mira.cbaines.net; Sun, 04 Jul 2021 07:55:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49902) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m00iF-0003oR-2O for guix-patches@gnu.org; Sun, 04 Jul 2021 07:55:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:57150) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m00iE-0006z4-RN for guix-patches@gnu.org; Sun, 04 Jul 2021 07:55:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1m00iE-0000cY-R6 for guix-patches@gnu.org; Sun, 04 Jul 2021 07:55:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#48999] [PATCH v2 2/3] import: utils: Add predicates for checking VCS repositories. Resent-From: Xinglu Chen Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 04 Jul 2021 11:55:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 48999 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 48999@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= , zimoun Received: via spool by 48999-submit@debbugs.gnu.org id=B48999.16253996662301 (code B ref 48999); Sun, 04 Jul 2021 11:55:02 +0000 Received: (at 48999) by debbugs.gnu.org; 4 Jul 2021 11:54:26 +0000 Received: from localhost ([127.0.0.1]:40458 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m00he-0000b3-1x for submit@debbugs.gnu.org; Sun, 04 Jul 2021 07:54:26 -0400 Received: from h87-96-130-155.cust.a3fiber.se ([87.96.130.155]:45484 helo=mail.yoctocell.xyz) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m00hc-0000an-93 for 48999@debbugs.gnu.org; Sun, 04 Jul 2021 07:54:24 -0400 From: Xinglu Chen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yoctocell.xyz; s=mail; t=1625399658; bh=SUKiCktpIliPTlYO8GWL93wkIVLqZ5R0FlszaIM3rEs=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=Rb0aWdAPebKvEL/t+UpT2eCtw55cQXVCTxB+QEGz5Nr13MamNNHIV56uQwfoenaeD qAyU5fjH+bjQrz3OboC489mj93AEr8RbtP1Eqn0qb/TKGq/aZZiKxYb3YMpzTGC8N3 M8ExhT6vBPOcnpIyCzmrrzi/+JcUeUKutJCvTWSc= In-Reply-To: References: Message-Id: <6f3fa1769c57d6c81765939a40b1c505d0cefb66.1625399149.git.public@yoctocell.xyz> Date: Sun, 04 Jul 2021 13:54:18 +0200 MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * guix/import/utils.scm (git-repository?, hg-repository?): New procedures. --- guix/import/utils.scm | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/guix/import/utils.scm b/guix/import/utils.scm index d817318a91..bcf26ae363 100644 --- a/guix/import/utils.scm +++ b/guix/import/utils.scm @@ -8,6 +8,7 @@ ;;; Copyright © 2020 Helio Machado <0x2b3bfa0+guix@googlemail.com> ;;; Copyright © 2020 Martin Becze ;;; Copyright © 2021 Maxim Cournoyer +;;; Copyright © 2021 Xinglu Chen ;;; ;;; This file is part of GNU Guix. ;;; @@ -43,6 +44,7 @@ #:use-module (ice-9 rdelim) #:use-module (ice-9 receive) #:use-module (ice-9 regex) + #:use-module (ice-9 ftw) #:use-module (srfi srfi-1) #:use-module (srfi srfi-9) #:use-module (srfi srfi-11) @@ -74,6 +76,9 @@ guix-name + git-repository? + hg-repository? + recursive-import)) (define (factorize-uri uri version) @@ -422,6 +427,16 @@ separated by PRED." (chr (char-downcase chr))) name))) +(define (git-repository? directory) + "Check whether DIRECTORY is a Git repository." + (let ((contents (scandir directory))) + (if (member ".git" contents) #t #f))) + +(define (hg-repository? directory) + "Check whether DIRECTORY is a Hg repository." + (let ((contents (scandir directory))) + (if (member ".hg" contents) #t #f))) + (define (topological-sort nodes node-dependencies node-name) From patchwork Sun Jul 4 11:54:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Xinglu Chen X-Patchwork-Id: 31127 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 57F1B27BC78; Sun, 4 Jul 2021 12:55:28 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,SPF_HELO_PASS,T_DKIM_INVALID,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id B582027BC81 for ; Sun, 4 Jul 2021 12:55:27 +0100 (BST) Received: from localhost ([::1]:60472 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m00ic-0004Gr-RX for patchwork@mira.cbaines.net; Sun, 04 Jul 2021 07:55:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49904) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m00iF-0003od-G1 for guix-patches@gnu.org; Sun, 04 Jul 2021 07:55:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:57151) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m00iF-0006zA-8c for guix-patches@gnu.org; Sun, 04 Jul 2021 07:55:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1m00iF-0000cf-8v for guix-patches@gnu.org; Sun, 04 Jul 2021 07:55:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#48999] [PATCH v2 3/3] scripts: import: hackage: Add option to import package from local filesystem. Resent-From: Xinglu Chen Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 04 Jul 2021 11:55:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 48999 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 48999@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= , zimoun Received: via spool by 48999-submit@debbugs.gnu.org id=B48999.16253996702320 (code B ref 48999); Sun, 04 Jul 2021 11:55:03 +0000 Received: (at 48999) by debbugs.gnu.org; 4 Jul 2021 11:54:30 +0000 Received: from localhost ([127.0.0.1]:40461 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m00hi-0000bM-AD for submit@debbugs.gnu.org; Sun, 04 Jul 2021 07:54:30 -0400 Received: from h87-96-130-155.cust.a3fiber.se ([87.96.130.155]:45494 helo=mail.yoctocell.xyz) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m00hf-0000as-3V for 48999@debbugs.gnu.org; Sun, 04 Jul 2021 07:54:28 -0400 From: Xinglu Chen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yoctocell.xyz; s=mail; t=1625399661; bh=7C7QEzkflnhQc5ic1PfcaX7wJVpYn+YK5wpeZn2hic0=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=J7Q1N3UtN9As2vzxOiPsKCw0BNCLps8E1HumPc9IxX75lYEDBQbj6a6aKcrI3Fyzk ln5mGFVZM2osS1Xmp3YeTa7qnjQUkw9L4teup9sGOvfk+IN4flTbx1/AZiVH1P5pNf z3T8MHciLj4P7t9Pw54RKdd6mpowFLqw5xWYDygM= In-Reply-To: References: Message-Id: <52f526989b25468210fa05e62580589f2c1cc4ea.1625399149.git.public@yoctocell.xyz> Date: Sun, 04 Jul 2021 13:54:20 +0200 MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches This adds a ‘--path’ option for importing a Haskell package from the local filesystem * guix/scripts/import/hackage.scm (show-help, %options): Add ‘-p’ and ‘--path’ options. (guix-import-hackage): Set the #:port and #:source keywords when the ‘--path’ option is used. --- guix/scripts/import/hackage.scm | 43 +++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/guix/scripts/import/hackage.scm b/guix/scripts/import/hackage.scm index 906dca24b1..8728791b52 100644 --- a/guix/scripts/import/hackage.scm +++ b/guix/scripts/import/hackage.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2015 Federico Beffa ;;; Copyright © 2018 Ricardo Wurmus +;;; Copyright © 2021 Xinglu Chen ;;; ;;; This file is part of GNU Guix. ;;; @@ -22,6 +23,7 @@ #:use-module (guix utils) #:use-module (guix packages) #:use-module (guix scripts) + #:use-module (guix import utils) #:use-module (guix import hackage) #:use-module (guix scripts import) #:use-module (srfi srfi-1) @@ -29,6 +31,7 @@ #:use-module (srfi srfi-37) #:use-module (ice-9 match) #:use-module (ice-9 format) + #:use-module (rnrs io ports) #:export (guix-import-hackage)) @@ -62,6 +65,8 @@ version.\n")) (display (G_ " -s, --stdin read from standard input")) (display (G_ " + -p, --path=DIR use local directory as source")) + (display (G_ " -t, --no-test-dependencies don't include test-only dependencies")) (display (G_ " -V, --version display version information and exit")) @@ -87,6 +92,11 @@ version.\n")) (alist-cons 'read-from-stdin? #t (alist-delete 'read-from-stdin? result)))) + (option '(#\p "path") #t #f + (lambda (opt name arg result) + (alist-cons 'read-path arg + (alist-delete 'read-path + result)))) (option '(#\e "cabal-environment") #t #f (lambda (opt name arg result) (alist-cons 'cabal-environment (read/eval arg) @@ -113,22 +123,39 @@ version.\n")) %default-options)) (define (run-importer package-name opts error-fn) - (let* ((arguments (list + (let* ((local-directory (assoc-ref opts 'read-path)) + (arguments (list package-name #:include-test-dependencies? (assoc-ref opts 'include-test-dependencies?) - #:port (if (assoc-ref opts 'read-from-stdin?) - (current-input-port) - #f) + #:port + (cond + ((assoc-ref opts 'read-from-stdin?) + (current-input-port)) + (local-directory + (open-file-input-port + (string-append local-directory + "/" package-name ".cabal"))) + (else #f)) + #:source + `(local-file ,local-directory + ,package-name + #:recursive? #t + #:select? ,(cond + ((git-repository? local-directory) + 'git-predicate) + ((hg-repository? local-directory) + 'hg-predicate) + (else '(const #t)))) #:cabal-environment (assoc-ref opts 'cabal-environment))) (sexp (if (assoc-ref opts 'recursive) ;; Recursive import (map (match-lambda - ((and ('package ('name name) . rest) pkg) - `(define-public ,(string->symbol name) - ,pkg)) - (_ #f)) + ((and ('package ('name name) . rest) pkg) + `(define-public ,(string->symbol name) + ,pkg)) + (_ #f)) (apply hackage-recursive-import arguments)) ;; Single import (apply hackage->guix-package arguments))))