node-build-system should not install tests

  • Open
  • quality assurance status badge
Details
One participant
  • goodoldpaul
Owner
unassigned
Submitted by
goodoldpaul
Severity
normal
G
G
goodoldpaul wrote on 19 Apr 2020 11:12
(address . bug-guix@gnu.org)
eee33db71991f14383a67a853abf8e7e@autistici.org
As discussed here [0], node-build-system right now installs all the
contents of a package's root node_modules directory, including i.e.
tests.
We should investigate how exactly npm decides what to install and try to
replicate that inside node-build-system. It seems likely that it uses
the "files" array from the package.json file (see [1-2]).

G
G
goodoldpaul wrote on 29 Apr 2020 16:55
WIP solution
(address . 40710@debbugs.gnu.org)
817d2cfae792a3a9483339cbd79e277c@autistici.org
Hello everybody,
I'm attempting to implement the discussed changes. I think these patches
come pretty close but being my first contribution to Guix's core I would
like to ask some feedback before submitting these patches with some
trivial mistake. I tried to base my implementation on [0].

The first patch adds "globstar" support to (guix glob), namely the
ability of recursively matching subdirectories in a glob pattern (i.e.
"foo/**/bar.scm" matches both "foo/bar.scm" and "foo/baz/bar.scm").

The second patch adds (guix glob) to the imported modules of
node-build-system and uses that to parse glob patterns in the "files"
array of a package.json and then install all the matching files.

I tested the patches by verifying that

./pre-inst-env guix build -K node-semver node-util-deprecate
node-statsd-parser node-stack-trace node-oop node-mersenne
node-long-stack-traces node-far node-env-variable node-color-name

runs without error and by running make check TESTS="tests/glob.scm" .

Do you have any feedback/advice?

Thanks,

Giacomo

From 2aaed4af3f171fa0a5d1817d9e0902cf1088b1a7 Mon Sep 17 00:00:00 2001
From: Giacomo Leidi <goodoldpaul@autistici.org>
Date: Wed, 29 Apr 2020 15:59:48 +0200
Subject: [PATCH 1/2] guix: Add globstar support.

* guix/glob.scm (string->sglob)
(glob-match?): Add globstar support.
* tests/glob.scm: Update accordingly.
---
guix/glob.scm | 13 +++++++++++++
tests/glob.scm | 8 ++++++--
2 files changed, 19 insertions(+), 2 deletions(-)

Toggle diff (70 lines)
diff --git a/guix/glob.scm b/guix/glob.scm
index a9fc744802..9b796ffd8f 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 <ludo@gnu.org>
+;;; Copyright © 2020 Giacomo Leidi <goodoldpaul@autistici.org>
;;;
;;; 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,13 @@ STR, a glob pattern such as \"foo*\" or \"foo??bar\"."
(string-null? str))
(('*)
#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 <ludo@gnu.org>
+;;; Copyright © 2020 Giacomo Leidi <goodoldpaul@autistici.org>
;;;
;;; 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")
--
2.26.2
P
Re: node-build-system should not install tests
(address . 40710@debbugs.gnu.org)
99113588-3ea1-5082-4980-df66d562522e@autistici.org
close 40710
?