From patchwork Tue May 12 21:31:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Giacomo Leidi X-Patchwork-Id: 22039 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 CA87F27BBE3; Tue, 12 May 2020 22:32:27 +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.0 required=5.0 tests=BAYES_00,DKIM_ADSP_ALL, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,T_DKIM_INVALID, URIBL_BLOCKED autolearn=no 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 ESMTP id 6648A27BBE1 for ; Tue, 12 May 2020 22:32:27 +0100 (BST) Received: from localhost ([::1]:39524 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jYcVm-0007AK-Px for patchwork@mira.cbaines.net; Tue, 12 May 2020 17:32:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35852) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jYcVP-00079i-CX for guix-patches@gnu.org; Tue, 12 May 2020 17:32:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:45159) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jYcVN-0000Il-Ob for guix-patches@gnu.org; Tue, 12 May 2020 17:32:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jYcVN-0001me-LD for guix-patches@gnu.org; Tue, 12 May 2020 17:32:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#41219] [PATCH 1/2] guix: Add globstar support. References: <5ec7ac973bb248a3cca0197836d35459@autistici.org> In-Reply-To: <5ec7ac973bb248a3cca0197836d35459@autistici.org> Resent-From: Giacomo Leidi Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 12 May 2020 21:32:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 41219 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 41219@debbugs.gnu.org Cc: Giacomo Leidi Received: via spool by 41219-submit@debbugs.gnu.org id=B41219.15893191126344 (code B ref 41219); Tue, 12 May 2020 21:32:01 +0000 Received: (at 41219) by debbugs.gnu.org; 12 May 2020 21:31:52 +0000 Received: from localhost ([127.0.0.1]:56703 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jYcVD-0001dv-L1 for submit@debbugs.gnu.org; Tue, 12 May 2020 17:31:51 -0400 Received: from latitanza.investici.org ([82.94.249.234]:62765) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jYcVC-0001c0-3S for 41219@debbugs.gnu.org; Tue, 12 May 2020 17:31:50 -0400 Received: from mx3.investici.org (unknown [127.0.0.1]) by latitanza.investici.org (Postfix) with ESMTP id B46F7120184; Tue, 12 May 2020 21:31:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1589319108; bh=VumB0vjbeUS19YPIePpDLetCbxqDRy5iSc5eeZMLqgw=; h=From:To:Cc:Subject:Date:From; b=kJKq/HVDTOpx82dmXk3Uc3wn9rB8GU0D7zZh+igxJ1NszIj1c2Prqs5lm19J0hLLV GoZtsEav2yqEl69P3dBOc2VBlxIUjiPe/iLBGLAT4PQUfCVWGOPY2X+DvK58a+mbw4 xR6+DzWKZpn944SNCXSLDNP352L1YQM1ENCjh2Sk= Received: from [82.94.249.234] (mx3.investici.org [82.94.249.234]) (Authenticated sender: goodoldpaul@autistici.org) by localhost (Postfix) with ESMTPSA id 823D812016F; Tue, 12 May 2020 21:31:48 +0000 (UTC) From: Giacomo Leidi Date: Tue, 12 May 2020 23:31:30 +0200 Message-Id: <20200512213131.28873-1-goodoldpaul@autistici.org> X-Mailer: git-send-email 2.26.2 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/glob.scm (string->sglob) (glob-match?): Add globstar support. * tests/glob.scm: Update accordingly. --- guix/glob.scm | 15 +++++++++++++++ tests/glob.scm | 8 ++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/guix/glob.scm b/guix/glob.scm index a9fc744802..d73783cd30 100644 --- a/guix/glob.scm +++ b/guix/glob.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2018 Ludovic Courtès +;;; Copyright © 2020 Giacomo Leidi ;;; ;;; This file is part of GNU Guix. ;;; @@ -61,6 +62,11 @@ STR, a glob pattern such as \"foo*\" or \"foo??bar\"." (flatten (reverse (if (null? pending) result (cons-string pending result))))) + ((#\* #\* #\/ . rest) + (if (zero? brackets) + (loop rest '() 0 + (cons* '**/ (cons-string pending result))) + (loop rest (cons '**/ pending) brackets result))) (((and chr (or #\? #\*)) . rest) (let ((wildcard (match chr (#\? '?) @@ -121,6 +127,15 @@ STR, a glob pattern such as \"foo*\" or \"foo??bar\"." (string-null? str)) (('*) #t) + (('**/) + #t) + (('**/ suffix . rest) + (let ((rest (if (eq? '* suffix) (cdr rest) rest)) + (suffix (if (eq? '* suffix) (car rest) suffix))) + (match (string-contains str suffix) + (#f #f) + (index (loop rest (string-drop str + (+ index (string-length suffix)))))))) (('* suffix . rest) (match (string-contains str suffix) (#f #f) diff --git a/tests/glob.scm b/tests/glob.scm index 3134069789..2a5a40c3c6 100644 --- a/tests/glob.scm +++ b/tests/glob.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2018 Ludovic Courtès +;;; Copyright © 2020 Giacomo Leidi ;;; ;;; This file is part of GNU Guix. ;;; @@ -53,7 +54,8 @@ "foo[abc]bar" => '("foo" (set #\a #\b #\c) "bar") "foo[a[b]c]bar" => '("foo" (set #\a #\[ #\b #\] #\c) "bar") "[123]x" => '((set #\1 #\2 #\3) "x") - "[a-z]" => '((range #\a #\z))) + "[a-z]" => '((range #\a #\z)) + "**/*.scm" => '(**/ * ".scm")) (test-glob-match ("foo" matches "foo" (and not "foobar" "barfoo")) @@ -64,6 +66,8 @@ ("ab[0-9]c" matches "ab0c" "ab7c" "ab9c" (and not "ab-c" "ab00c" "ab3")) ("ab[cdefg]" matches "abc" "abd" "abg" - (and not "abh" "abcd" "ab["))) + (and not "abh" "abcd" "ab[")) + ("foo/**/*.scm" matches "foo/bar/baz.scm" "foo/bar.scm" "foo/bar/baz/zab.scm" + (and not "foo/bar/baz.java" "foo/bar.smc"))) (test-end "glob") From patchwork Tue May 12 21:31:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Giacomo Leidi X-Patchwork-Id: 22040 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 7351127BBE3; Tue, 12 May 2020 22:32:29 +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.0 required=5.0 tests=BAYES_00,DKIM_ADSP_ALL, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,T_DKIM_INVALID, URIBL_BLOCKED autolearn=no 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 ESMTP id DFD1727BBE1 for ; Tue, 12 May 2020 22:32:28 +0100 (BST) Received: from localhost ([::1]:39544 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jYcVo-0007BJ-9q for patchwork@mira.cbaines.net; Tue, 12 May 2020 17:32:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35854) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jYcVP-00079j-CY for guix-patches@gnu.org; Tue, 12 May 2020 17:32:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:45160) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jYcVO-0000Im-55 for guix-patches@gnu.org; Tue, 12 May 2020 17:32:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jYcVO-0001n9-1p for guix-patches@gnu.org; Tue, 12 May 2020 17:32:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#41219] [PATCH 2/2] guix: Enforce package.json "files" directive. Resent-From: Giacomo Leidi Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 12 May 2020 21:32:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 41219 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 41219@debbugs.gnu.org Cc: Giacomo Leidi Received: via spool by 41219-submit@debbugs.gnu.org id=B41219.15893191156558 (code B ref 41219); Tue, 12 May 2020 21:32:02 +0000 Received: (at 41219) by debbugs.gnu.org; 12 May 2020 21:31:55 +0000 Received: from localhost ([127.0.0.1]:56705 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jYcVG-0001hE-Vt for submit@debbugs.gnu.org; Tue, 12 May 2020 17:31:55 -0400 Received: from latitanza.investici.org ([82.94.249.234]:23603) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jYcVC-0001c8-2r for 41219@debbugs.gnu.org; Tue, 12 May 2020 17:31:51 -0400 Received: from mx3.investici.org (unknown [127.0.0.1]) by latitanza.investici.org (Postfix) with ESMTP id 0AE471201B0; Tue, 12 May 2020 21:31:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1589319109; bh=UgCtPwH+n1lUBmpaMidDDXgeqikVfNBOw4zW+dCZnr8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gFAzov8y05KEndP43PytNhexY+uQ4t/aWiAatwAhy+AAi6JuvquZ7nzY94k4bJJrj 8scYp/Z/PILqWPKiLGg7F9/ZoQfcZ1GA4xCNMo0wUQI9od5NqcP4tddhlqI5tGAOFs 7wmXjsEHv/cPujKtVbnVoOIrWWBoe6gBWXUEGOZU= Received: from [82.94.249.234] (mx3.investici.org [82.94.249.234]) (Authenticated sender: goodoldpaul@autistici.org) by localhost (Postfix) with ESMTPSA id CEA6012016F; Tue, 12 May 2020 21:31:48 +0000 (UTC) From: Giacomo Leidi Date: Tue, 12 May 2020 23:31:31 +0200 Message-Id: <20200512213131.28873-2-goodoldpaul@autistici.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200512213131.28873-1-goodoldpaul@autistici.org> References: <20200512213131.28873-1-goodoldpaul@autistici.org> 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 fixes https://issues.guix.gnu.org/40710 by implementing support for the "files" directive from https://docs.npmjs.com/files/package.json#files . * guix/build/node-build-system.scm (install): Enforce package.json "files" directive. * guix/build-system/node.scm (%node-build-system-modules) (node-build)[modules]: Add (guix glob). --- guix/build-system/node.scm | 4 +- guix/build/node-build-system.scm | 68 ++++++++++++++++++++++++++------ 2 files changed, 58 insertions(+), 14 deletions(-) diff --git a/guix/build-system/node.scm b/guix/build-system/node.scm index 05c24c47d5..05bc9f2087 100644 --- a/guix/build-system/node.scm +++ b/guix/build-system/node.scm @@ -42,6 +42,7 @@ registry." `((guix build node-build-system) (guix build json) (guix build union) + (guix glob) ,@%gnu-build-system-modules)) ;; TODO: Might be not needed (define (default-node) @@ -90,7 +91,8 @@ registry." (modules '((guix build node-build-system) (guix build json) (guix build union) - (guix build utils)))) + (guix build utils) + (guix glob)))) "Build SOURCE using NODE and INPUTS." (define builder `(begin diff --git a/guix/build/node-build-system.scm b/guix/build/node-build-system.scm index 7799f03595..befcbbeb75 100644 --- a/guix/build/node-build-system.scm +++ b/guix/build/node-build-system.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2015 David Thompson ;;; Copyright © 2016 Jelle Licht +;;; Copyright © 2020 Giacomo Leidi ;;; ;;; This file is part of GNU Guix. ;;; @@ -22,6 +23,7 @@ #:use-module (guix build json) #:use-module (guix build union) #:use-module (guix build utils) + #:use-module (guix glob) #:use-module (ice-9 match) #:use-module (ice-9 popen) #:use-module (ice-9 regex) @@ -110,18 +112,60 @@ the @file{bin} directory." (#f #f))) (dependencies (match (assoc-ref data "dependencies") (('@ deps ...) deps) - (#f #f)))) + (#f #f))) + (patterns (match (assoc-ref data "files") + (() #f) + ((? list? patrn-list) patrn-list) + (#f #f))) + (main (match (assoc-ref data "main") + ("" #f) + ((? string? main-module) main-module) + (#f #f))) + (install-dir (string-append target "/node_modules/" modulename)) + (install-files (lambda (files directory) + (for-each (lambda (file) + (install-file + file + (string-append directory "/" + (dirname file)))) + files)))) (mkdir-p target) - (copy-recursively "." (string-append target "/node_modules/" modulename)) - ;; Remove references to dependencies - (delete-file-recursively - (string-append target "/node_modules/" modulename "/node_modules")) + (if patterns + (install-files + (filter (lambda (file) + (any (lambda (pattern) + (glob-match? + (string->compiled-sglob pattern) + file)) + (append + patterns + '("package.json" + ;; These files get installed no + ;; matter the case or extension. + "[rR][eE][aA][dD][mM][eE]*" + "[cC][hH][aA][nN][gG][eE][sS]*" + "[cC][hH][aA][nN][gG][eE][lL][oO][gG]*" + "[hH][iI][sS][tT][oO][rR][yY]*" + "[nN][oO][tT][iI][cC][eE]*")))) + (map (lambda (path) + (string-drop path 2)) + (find-files "."))) + install-dir) + (begin + (copy-recursively "." install-dir) + ;; Remove references to dependencies + (delete-file-recursively + (string-append install-dir "/node_modules")))) + (if (and main + (not (file-exists? + (string-append + install-dir "/" (dirname main))))) + (install-files (list main) install-dir)) (cond ((string? binary-configuration) (begin (mkdir-p binaries) - (symlink (string-append target "/node_modules/" modulename "/" - binary-configuration) + (symlink (string-append install-dir "/" binary-configuration) (string-append binaries "/" modulename)))) ((list? binary-configuration) (for-each @@ -130,21 +174,19 @@ the @file{bin} directory." ((key . value) (begin (mkdir-p (dirname (string-append binaries "/" key))) - (symlink (string-append target "/node_modules/" modulename "/" - value) + (symlink (string-append install-dir "/" value) (string-append binaries "/" key)))))) - binary-configuration))) + binary-configuration))) (when dependencies (mkdir-p - (string-append target "/node_modules/" modulename "/node_modules")) + (string-append install-dir "/node_modules")) (for-each (lambda (dependency) (let ((dependency (car dependency))) (symlink (string-append (assoc-ref inputs (string-append "node-" dependency)) "/lib/node_modules/" dependency) - (string-append target "/node_modules/" modulename - "/node_modules/" dependency)))) + (string-append install-dir "/node_modules/" dependency)))) dependencies)) #t))