From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id +GEPN0eWzGBsWgEAgWs5BA (envelope-from ) for ; Fri, 18 Jun 2021 14:49:11 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id 4JWiMkeWzGCQTQAAB5/wlQ (envelope-from ) for ; Fri, 18 Jun 2021 12:49:11 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 1F18717CDB for ; Fri, 18 Jun 2021 14:49:10 +0200 (CEST) Received: from localhost ([::1]:46044 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1luDvo-0002RG-TX for larch@yhetil.org; Fri, 18 Jun 2021 08:49:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58798) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1luDvi-0002Nj-MN for guix-patches@gnu.org; Fri, 18 Jun 2021 08:49:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:44505) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1luDvi-0005MI-Dd for guix-patches@gnu.org; Fri, 18 Jun 2021 08:49:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1luDvi-0003Wp-Ah for guix-patches@gnu.org; Fri, 18 Jun 2021 08:49:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#48943] [PATCH v2] import: hackage: Support "common" field and imports References: <20210610083953.664318-1-philip@munksgaard.me> In-Reply-To: <20210610083953.664318-1-philip@munksgaard.me> Resent-From: Philip Munksgaard Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 18 Jun 2021 12:49:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 48943 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 48943@debbugs.gnu.org Cc: Philip Munksgaard Received: via spool by 48943-submit@debbugs.gnu.org id=B48943.162402051813524 (code B ref 48943); Fri, 18 Jun 2021 12:49:02 +0000 Received: (at 48943) by debbugs.gnu.org; 18 Jun 2021 12:48:38 +0000 Received: from localhost ([127.0.0.1]:56051 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1luDvK-0003W4-27 for submit@debbugs.gnu.org; Fri, 18 Jun 2021 08:48:38 -0400 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]:52945) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1luDvH-0003Vp-DN for 48943@debbugs.gnu.org; Fri, 18 Jun 2021 08:48:36 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 0B1DB10BF; Fri, 18 Jun 2021 08:48:28 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Fri, 18 Jun 2021 08:48:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=munksgaard.me; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; s=fm1; bh=dLa/igxR/sp4gswv8oc0jh6xWa //Esqj9NdYzpHN7Uc=; b=bUjdfH/g0yxn26Y4Oi3qAyrjnuZ8Po7zfe7ZHPHk0w 4yRsoVh0pb4vncnBmcEJkvyLNgnPUqGMg2DdYtT6b7muPMn40NKKzeyDNpI5CGF7 0VwgEeHWtMfKV4xtq6BG0DyvLQrNV4T2+GRgw+HcqL8ngjqjNWDAvNBmIai/hoCW VuqUwF8mjhf9Jo77mmepXvSpC+Xl83MdQC2Xlil0aqAdEffLGgnTT1vfG/yQiWZY jcAvSIYgcWRV9HnWOl0Acj3Ri5dXggqQ6AgF9BNKJDLXI89IAm0gLbX/GZkVNGiY boZbkvBJx0HO/I3f1dSFR17mEPOE6nv82kEZOEVmuApg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=dLa/igxR/sp4gswv8 oc0jh6xWa//Esqj9NdYzpHN7Uc=; b=FwO01vt3l6x8jP/5w6i4rUBf5AuYIC7xb hAxRn9SK/ISM/B7z4ppkm4eB/5nXMPq/HBGMwUdy6/TVpgamEnkfa9czVCy6ONQc zV3PkQR+ERfNuqaSYB6SfewhxKBvSqL7wmwpgJlZfqflZHFe2oTe7Bft3W6LrvP0 s3oOo1HxS7oh+f+MQCE4u/Hm2FlVX5WlhOdRtmN+owlvA6fu9f+L/Oxh//WZAfXk JrpGi3NjqLgtHT+ESRRX5JsgSi6t5OX8HvMUeOSDLSDGmRSP3KOwTPx2hhUQ+Ffb RAYAQFrPigcVqnG6ffPbvG3ckz03Aw40ILm9CPChcW2mvGqnOvGuA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfeeffedgheekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgggfestdekredtre dttdenucfhrhhomheprfhhihhlihhpucfouhhnkhhsghgrrghrugcuoehphhhilhhiphes mhhunhhkshhgrggrrhgurdhmvgeqnecuggftrfgrthhtvghrnhepfedugefgvdetjefhte ekgfegieefveefledtieelgedttdeftdfghefhkeehleehnecuffhomhgrihhnpehgnhhu rdhorhhgpdhtvghsthdrohhrghdphhgrshhkvghllhdrohhrghenucevlhhushhtvghruf hiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehphhhilhhiphesmhhunhhkshhg rggrrhgurdhmvg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 18 Jun 2021 08:48:27 -0400 (EDT) From: Philip Munksgaard Date: Fri, 18 Jun 2021 14:48:13 +0200 Message-Id: <20210618124813.844948-1-philip@munksgaard.me> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1624020551; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=dLa/igxR/sp4gswv8oc0jh6xWa//Esqj9NdYzpHN7Uc=; b=KMlTZWTgrHdRObD/LRoxG9B55tkjrs6KjeO2BqrVfJgxaTEIt1X4hJ5mY/AOJ04aWYTPuo 4BmPd91FOif1J0IZSG1J2p/3mkUrXhIzVzdAY/VzLaZkhY/otS/32MYvL3kCmfKEZVexLN V3dV2jDcx9cNDds282LQlqmxASfvCx319ydIy/se8bHptnBGlRDf5bnHTAGUVut2SKmRO5 tMbqtikDE1cgw2OsKmXlVC+7U+IZuH4niu3MQBZWnu6/YJmBIhrH5vRPjA5jcZiBZzwCho OO0OTslP/Vr/65blqWbask8CErGILav0P1dRKIAuCXbm301LxIlU0vKKq0zw2Q== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1624020551; a=rsa-sha256; cv=none; b=rkfTdd432HnGLlK5nsAp5vgLcVRWkEFUgiQp4ba9OzvLj8qB9116vzu54aO1vzTvbpySmp 3M3MdhGDFHrz5PkEGXx3YgyJ0Gp58ASb2NExrRFcss6nSabsHCvahZNXemWLqIOtRfQiaW 7g5Fab+z2tWFk22qWDnQj44d7fw4ctuo/ATg/nUI2r9CspeBmILkOv7PY/1H6Mqtaa1cy6 eh+mQfStRthu0sE8p+HBeVbi9KsMh69TVOeJSWqOnqEVtnR6OYMvqMbCRtzgue7Bsuztnj Rd/S4wcL2arN+PRAvJDcioMsy6rWv8uY12j1iP7tRRFnIVsC7g93MDu49G5aZQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=munksgaard.me header.s=fm1 header.b="bUjdfH/g"; dkim=fail ("headers rsa verify failed") header.d=messagingengine.com header.s=fm3 header.b=FwO01vt3; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: 3.57 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=munksgaard.me header.s=fm1 header.b="bUjdfH/g"; dkim=fail ("headers rsa verify failed") header.d=messagingengine.com header.s=fm3 header.b=FwO01vt3; dmarc=none; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: 1F18717CDB X-Spam-Score: 3.57 X-Migadu-Scanner: scn1.migadu.com X-TUID: 0+el2Z3W2mkZ Fixes . * 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. --- guix/import/cabal.scm | 27 +++++++++++++++++++++++++-- tests/hackage.scm | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/guix/import/cabal.scm b/guix/import/cabal.scm index da00019297..22b5d164d0 100644 --- a/guix/import/cabal.scm +++ b/guix/import/cabal.scm @@ -145,7 +145,7 @@ to the stack." (lalr-parser ;; --- token definitions (CCURLY VCCURLY OPAREN CPAREN TEST ID VERSION RELATION TRUE FALSE -ANY -NONE - (right: IF FLAG EXEC TEST-SUITE CUSTOM-SETUP SOURCE-REPO BENCHMARK LIB OCURLY) + (right: IF FLAG EXEC TEST-SUITE CUSTOM-SETUP SOURCE-REPO BENCHMARK LIB COMMON OCURLY) (left: OR) (left: PROPERTY AND) (right: ELSE NOT)) @@ -155,6 +155,7 @@ to the stack." (sections source-repo) : (append $1 (list $2)) (sections executables) : (append $1 $2) (sections test-suites) : (append $1 $2) + (sections common) : (append $1 $2) (sections custom-setup) : (append $1 $2) (sections benchmarks) : (append $1 $2) (sections lib-sec) : (append $1 (list $2)) @@ -178,6 +179,10 @@ to the stack." (ts-sec) : (list $1)) (ts-sec (TEST-SUITE OCURLY exprs CCURLY) : `(section test-suite ,$1 ,$3) (TEST-SUITE open exprs close) : `(section test-suite ,$1 ,$3)) + (common (common common-sec) : (append $1 (list $2)) + (common-sec) : (list $1)) + (common-sec (COMMON OCURLY exprs CCURLY) : `(section common ,$1 ,$3) + (COMMON open exprs close) : `(section common ,$1 ,$3)) (custom-setup (CUSTOM-SETUP exprs) : (list `(section custom-setup ,$1 ,$2))) (benchmarks (benchmarks bm-sec) : (append $1 (list $2)) (bm-sec) : (list $1)) @@ -367,6 +372,9 @@ matching a string against the created regexp." (define is-test-suite (make-rx-matcher "^test-suite +([a-z0-9_-]+)" regexp/icase)) +(define is-common (make-rx-matcher "^common +([a-z0-9_-]+)" + regexp/icase)) + (define is-custom-setup (make-rx-matcher "^(custom-setup)" regexp/icase)) @@ -394,7 +402,7 @@ matching a string against the created regexp." (define (is-id s port) (let ((cabal-reserved-words '("if" "else" "library" "flag" "executable" "test-suite" "custom-setup" - "source-repository" "benchmark")) + "source-repository" "benchmark" "common")) (spaces (read-while (cut char-set-contains? char-set:blank <>) port)) (c (peek-char port))) (unread-string spaces port) @@ -469,6 +477,8 @@ string with the read characters." (define (lex-test-suite ts-rx-res loc) (lex-rx-res ts-rx-res 'TEST-SUITE loc)) +(define (lex-common common-rx-res loc) (lex-rx-res common-rx-res 'COMMON loc)) + (define (lex-custom-setup ts-rx-res loc) (lex-rx-res ts-rx-res 'CUSTOM-SETUP loc)) (define (lex-benchmark bm-rx-res loc) (lex-rx-res bm-rx-res 'BENCHMARK loc)) @@ -570,6 +580,7 @@ the current port location." ((is-src-repo s) => (cut lex-src-repo <> loc)) ((is-exec s) => (cut lex-exec <> loc)) ((is-test-suite s) => (cut lex-test-suite <> loc)) + ((is-common s) => (cut lex-common <> loc)) ((is-custom-setup s) => (cut lex-custom-setup <> loc)) ((is-benchmark s) => (cut lex-benchmark <> loc)) ((is-lib s) (lex-lib loc)) @@ -796,7 +807,16 @@ the ordering operation and the version." (let ((value (or (assoc-ref env name) (assoc-ref (cabal-flags->alist (cabal-flags)) name)))) (if (eq? value 'false) #f #t))) + + (define common-stanzas + (filter-map (cut match <> + (('section 'common common-name common) + (cons common-name common)) + (_ #f)) + cabal-sexp)) + (define (eval sexp) + "Given an SEXP and an ENV, return the evaluated (SEXP . ENV)." (match sexp (() '()) ;; nested 'if' @@ -831,6 +851,9 @@ the ordering operation and the version." (list 'section type name (eval parameters))) (((? string? name) values) (list name values)) + ((("import" imports) rest ...) + (eval (append (append-map (cut assoc-ref common-stanzas <>) imports) + rest))) ((element rest ...) (cons (eval element) (eval rest))) (_ (raise (condition diff --git a/tests/hackage.scm b/tests/hackage.scm index 66a13d9881..53972fc643 100644 --- a/tests/hackage.scm +++ b/tests/hackage.scm @@ -388,4 +388,46 @@ executable cabal #t) (x (pk 'fail x #f)))) +(define test-cabal-import + "name: foo +version: 1.0.0 +homepage: http://test.org +synopsis: synopsis +description: description +license: BSD3 +common commons + build-depends: + HTTP >= 4000.2.5 && < 4000.3, + mtl >= 2.0 && < 3 + +executable cabal + import: commons +") + +(define-package-matcher match-ghc-foo-import + ('package + ('name "ghc-foo") + ('version "1.0.0") + ('source + ('origin + ('method 'url-fetch) + ('uri ('string-append + "https://hackage.haskell.org/package/foo/foo-" + 'version + ".tar.gz")) + ('sha256 + ('base32 + (? string? hash))))) + ('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))) + +(test-assert "hackage->guix-package test cabal import" + (eval-test-with-cabal test-cabal-import match-ghc-foo-import)) + (test-end "hackage") -- 2.31.1