buildroot.busybox.net archive mirror
 help / color / mirror / Atom feed
* [Buildroot] [PATCH v6 1/3] package/nushell: new package
@ 2023-03-08 13:15 Sebastian Weyer
  2023-03-08 13:15 ` [Buildroot] [PATCH v6 2/3] package/nushell: Add default configs Sebastian Weyer
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Sebastian Weyer @ 2023-03-08 13:15 UTC (permalink / raw)
  To: buildroot; +Cc: Sebastian Weyer

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=y, Size: 3605 bytes --]

Nushell is a shell - written in Rust - that makes use of the nushell
language to interact with the operating system

Signed-off-by: Sebastian Weyer <sebastian.weyer@smile.fr>
---
This new version adds ncurses-target-progs as a dependency which is a
hidden dependency of nushell. With this option enabled, nushell is also
usable without specifically replacing getty by agetty.

Nushell is not POSIX compliant and therefore should not be used as login
shell since some programs might assume a POSIX-compliant shell and
therefore break the system.

Signed-off-by: Sebastian Weyer <sebastian.weyer@smile.fr>
---
 DEVELOPERS                   |  3 +++
 package/Config.in            |  1 +
 package/nushell/Config.in    | 12 ++++++++++++
 package/nushell/nushell.hash |  3 +++
 package/nushell/nushell.mk   | 20 ++++++++++++++++++++
 5 files changed, 39 insertions(+)
 create mode 100644 package/nushell/Config.in
 create mode 100644 package/nushell/nushell.hash
 create mode 100644 package/nushell/nushell.mk

diff --git a/DEVELOPERS b/DEVELOPERS
index 6256576e02..9e3855423e 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -2550,6 +2550,9 @@ F:	support/misc/toolchainfile.cmake.in
 N:	Sam Voss <sam.voss@gmail.com>
 F:	package/ripgrep/
 
+N:	Sebastian Weyer <sebastian.weyer@smile.fr>
+F:	package/nushell/
+
 N:	Sébastien Szymanski <sebastien.szymanski@armadeus.com>
 F:	package/mmc-utils/
 F:	package/python-flask-jsonrpc/
diff --git a/package/Config.in b/package/Config.in
index 3ace25c665..7fca46afb5 100644
--- a/package/Config.in
+++ b/package/Config.in
@@ -2577,6 +2577,7 @@ comment "Shells"
 	source "package/bash/Config.in"
 	source "package/dash/Config.in"
 	source "package/mksh/Config.in"
+	source "package/nushell/Config.in"
 	source "package/zsh/Config.in"
 comment "Utilities"
 	source "package/apg/Config.in"
diff --git a/package/nushell/Config.in b/package/nushell/Config.in
new file mode 100644
index 0000000000..edb01d2f72
--- /dev/null
+++ b/package/nushell/Config.in
@@ -0,0 +1,12 @@
+config BR2_PACKAGE_NUSHELL
+	bool "nushell"
+	depends on BR2_PACKAGE_HOST_RUSTC_TARGET_ARCH_SUPPORTS
+	select BR2_PACKAGE_HOST_RUSTC
+	select BR2_PACKAGE_OPENSSL
+	select BR2_PACKAGE_HOST_PKGCONF
+	select BR2_PACKAGE_NCURSES
+	select BR2_PACKAGE_NCURSES_TARGET_PROGS
+	help
+	  A new type of shell.
+
+	  https://github.com/nushell/nushell
diff --git a/package/nushell/nushell.hash b/package/nushell/nushell.hash
new file mode 100644
index 0000000000..b553a6c2bc
--- /dev/null
+++ b/package/nushell/nushell.hash
@@ -0,0 +1,3 @@
+# Locally generated
+sha256  352e807698d5f95e9bfdd9dd5512acab3cbef315379299a32e5f322a76eb718a  nushell-0.76.0.tar.gz
+sha256  e189616e535e9f7bf410a72e6fc51ad1e0ae461c58d592e186c2669daa5d1e5d  LICENSE
diff --git a/package/nushell/nushell.mk b/package/nushell/nushell.mk
new file mode 100644
index 0000000000..b9c1ee6434
--- /dev/null
+++ b/package/nushell/nushell.mk
@@ -0,0 +1,20 @@
+################################################################################
+#
+# nushell
+#
+################################################################################
+
+NUSHELL_VERSION = 0.76.0
+NUSHELL_SITE = $(call github,nushell,nushell,$(NUSHELL_VERSION))
+NUSHELL_LICENSE = MIT
+NUSHELL_LICENSE_FILES = LICENSE
+NUSHELL_DEPENDENCIES = host-pkgconf openssl ncurses
+
+# Add /usr/bin/nu to /etc/shells as in package/bash/bash.mk
+define NUSHELL_ADD_NU_TO_SHELLS
+	grep -qsE '^/usr/bin/nu$$' $(TARGET_DIR)/etc/shells \
+		|| echo "/usr/bin/nu" >> $(TARGET_DIR)/etc/shells
+endef
+NUSHELL_TARGET_FINALIZE_HOOKS += NUSHELL_ADD_NU_TO_SHELLS
+
+$(eval $(cargo-package))
-- 
2.25.1


[-- Attachment #2: Type: text/plain, Size: 150 bytes --]

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Buildroot] [PATCH v6 2/3] package/nushell: Add default configs
  2023-03-08 13:15 [Buildroot] [PATCH v6 1/3] package/nushell: new package Sebastian Weyer
@ 2023-03-08 13:15 ` Sebastian Weyer
  2023-08-30 20:36   ` Thomas Petazzoni via buildroot
  2023-03-08 13:15 ` [Buildroot] [PATCH v6 3/3] support/testing/tests/package/test_nu.py: New runtime test Sebastian Weyer
  2023-08-30 20:35 ` [Buildroot] [PATCH v6 1/3] package/nushell: new package Thomas Petazzoni via buildroot
  2 siblings, 1 reply; 6+ messages in thread
From: Sebastian Weyer @ 2023-03-08 13:15 UTC (permalink / raw)
  To: buildroot; +Cc: Sebastian Weyer

Automatically place default files for the nushell environment and
config in the appropriate folder to avoid the prompt at startup, asking
if you want to create them.

Signed-off-by: Sebastian Weyer <sebastian.weyer@smile.fr>
---
These default configs are optional and might not even be necessary, they
only prevent the prompt at the first startup of the shell
---
 package/nushell/nushell.mk | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/package/nushell/nushell.mk b/package/nushell/nushell.mk
index b9c1ee6434..8ac3045c9f 100644
--- a/package/nushell/nushell.mk
+++ b/package/nushell/nushell.mk
@@ -10,6 +10,14 @@ NUSHELL_LICENSE = MIT
 NUSHELL_LICENSE_FILES = LICENSE
 NUSHELL_DEPENDENCIES = host-pkgconf openssl ncurses
 
+define NUSHELL_INSTALL_DEFAULT_CONFIG
+	$(INSTALL) -m 0644 -D $(@D)/crates/nu-utils/src/sample_config/default_config.nu \
+		$(TARGET_DIR)/root/.config/nushell/config.nu
+	$(INSTALL) -m 0644 -D $(@D)/crates/nu-utils/src/sample_config/default_env.nu \
+		$(TARGET_DIR)/root/.config/nushell/env.nu
+endef
+NUSHELL_POST_INSTALL_TARGET_HOOKS += NUSHELL_INSTALL_DEFAULT_CONFIG
+
 # Add /usr/bin/nu to /etc/shells as in package/bash/bash.mk
 define NUSHELL_ADD_NU_TO_SHELLS
 	grep -qsE '^/usr/bin/nu$$' $(TARGET_DIR)/etc/shells \
-- 
2.25.1

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Buildroot] [PATCH v6 3/3] support/testing/tests/package/test_nu.py: New runtime test
  2023-03-08 13:15 [Buildroot] [PATCH v6 1/3] package/nushell: new package Sebastian Weyer
  2023-03-08 13:15 ` [Buildroot] [PATCH v6 2/3] package/nushell: Add default configs Sebastian Weyer
@ 2023-03-08 13:15 ` Sebastian Weyer
  2023-08-30 20:37   ` Thomas Petazzoni via buildroot
  2023-08-30 20:35 ` [Buildroot] [PATCH v6 1/3] package/nushell: new package Thomas Petazzoni via buildroot
  2 siblings, 1 reply; 6+ messages in thread
From: Sebastian Weyer @ 2023-03-08 13:15 UTC (permalink / raw)
  To: buildroot; +Cc: Sebastian Weyer

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=y, Size: 3700 bytes --]

Load sample script support/testing/tests/package/sample_nu.nu onto the
target and verify proper execution by nushell

Signed-off-by: Sebastian Weyer <sebastian.weyer@smile.fr>
---
 DEVELOPERS                                 |  2 +
 support/testing/tests/package/sample_nu.nu |  6 +++
 support/testing/tests/package/test_nu.py   | 62 ++++++++++++++++++++++
 3 files changed, 70 insertions(+)
 create mode 100644 support/testing/tests/package/sample_nu.nu
 create mode 100644 support/testing/tests/package/test_nu.py

diff --git a/DEVELOPERS b/DEVELOPERS
index 9e3855423e..9a7257c4b2 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -2552,6 +2552,8 @@ F:	package/ripgrep/
 
 N:	Sebastian Weyer <sebastian.weyer@smile.fr>
 F:	package/nushell/
+F:	support/testing/tests/package/test_nu.py
+F:	support/testing/tests/package/sample_nu.nu
 
 N:	Sébastien Szymanski <sebastien.szymanski@armadeus.com>
 F:	package/mmc-utils/
diff --git a/support/testing/tests/package/sample_nu.nu b/support/testing/tests/package/sample_nu.nu
new file mode 100644
index 0000000000..5287862cf1
--- /dev/null
+++ b/support/testing/tests/package/sample_nu.nu
@@ -0,0 +1,6 @@
+#! /usr/bin/nu
+def greet [name] {
+  ["hello" $name]
+}
+
+greet "world"
diff --git a/support/testing/tests/package/test_nu.py b/support/testing/tests/package/test_nu.py
new file mode 100644
index 0000000000..ba2ddb9851
--- /dev/null
+++ b/support/testing/tests/package/test_nu.py
@@ -0,0 +1,62 @@
+import os
+
+import infra.basetest
+
+class TestNuBase(infra.basetest.BRTest):
+    # infra.basetest.BASIC_TOOLCHAIN_CONFIG cannot be used as it doesn't
+    # support a host rustc which is necessary for nushell
+    config = \
+        """
+        BR2_arm=y
+        BR2_cortex_a9=y
+        BR2_ARM_ENABLE_NEON=y
+        BR2_ARM_ENABLE_VFP=y
+        BR2_TOOLCHAIN_EXTERNAL=y
+        BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
+        BR2_SYSTEM_DHCP="eth0"
+        BR2_PACKAGE_NUSHELL=y
+        BR2_TARGET_ROOTFS_CPIO=y
+        """
+
+    def login(self):
+        img = os.path.join(self.builddir, "images", "rootfs.cpio")
+        self.emulator.boot(arch="armv7",
+                           kernel="builtin",
+                           options=["-initrd",img])
+        self.emulator.login()
+
+# load a script on the target and check if it is executed correctly by nu
+class TestNu(TestNuBase):
+    config_sample_scripts = \
+        """
+        BR2_ROOTFS_POST_BUILD_SCRIPT="{}"
+        BR2_ROOTFS_POST_SCRIPT_ARGS="{}"
+        """.format(infra.filepath("tests/package/copy-sample-script-to-target.sh"),
+                   "{sample_scripts}")
+
+    #simple hello world script found in the nushell doc
+    sample_scripts = ["tests/package/sample_nu.nu"]
+
+    def __init__(self, names):
+        """Add the scripts to the target in build time."""
+        super(TestNuBase, self).__init__(names)
+        scripts = [infra.filepath(s) for s in self.sample_scripts]
+        self.config += self.config_sample_scripts.format(sample_scripts=" ".join(scripts))
+
+    def check_sample_scripts_exist(self):
+        """Check the scripts were really added to the image."""
+        scripts = [os.path.basename(s) for s in self.sample_scripts]
+        cmd = "md5sum " + " ".join(scripts)
+        _, exit_code = self.emulator.run(cmd)
+        self.assertEqual(exit_code, 0)
+
+    def run_sample_scripts(self):
+        """Run each script previously added to the image."""
+        for script in self.sample_scripts:
+            cmd = "nu " + os.path.basename(script)
+            self.assertRunOk(cmd)
+
+    def test_run(self):
+        self.login()
+        self.check_sample_scripts_exist()
+        self.run_sample_scripts()
-- 
2.25.1


[-- Attachment #2: Type: text/plain, Size: 150 bytes --]

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [Buildroot] [PATCH v6 1/3] package/nushell: new package
  2023-03-08 13:15 [Buildroot] [PATCH v6 1/3] package/nushell: new package Sebastian Weyer
  2023-03-08 13:15 ` [Buildroot] [PATCH v6 2/3] package/nushell: Add default configs Sebastian Weyer
  2023-03-08 13:15 ` [Buildroot] [PATCH v6 3/3] support/testing/tests/package/test_nu.py: New runtime test Sebastian Weyer
@ 2023-08-30 20:35 ` Thomas Petazzoni via buildroot
  2 siblings, 0 replies; 6+ messages in thread
From: Thomas Petazzoni via buildroot @ 2023-08-30 20:35 UTC (permalink / raw)
  To: Sebastian Weyer; +Cc: Romain Naour, buildroot

On Wed,  8 Mar 2023 14:15:51 +0100
Sebastian Weyer <sebastian.weyer@smile.fr> wrote:

> Nushell is a shell - written in Rust - that makes use of the nushell
> language to interact with the operating system
> 
> Signed-off-by: Sebastian Weyer <sebastian.weyer@smile.fr>
> ---
> This new version adds ncurses-target-progs as a dependency which is a
> hidden dependency of nushell. With this option enabled, nushell is also
> usable without specifically replacing getty by agetty.

Applied to next, thanks.

Thomas
-- 
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Buildroot] [PATCH v6 2/3] package/nushell: Add default configs
  2023-03-08 13:15 ` [Buildroot] [PATCH v6 2/3] package/nushell: Add default configs Sebastian Weyer
@ 2023-08-30 20:36   ` Thomas Petazzoni via buildroot
  0 siblings, 0 replies; 6+ messages in thread
From: Thomas Petazzoni via buildroot @ 2023-08-30 20:36 UTC (permalink / raw)
  To: Sebastian Weyer; +Cc: buildroot

On Wed,  8 Mar 2023 14:15:52 +0100
Sebastian Weyer <sebastian.weyer@smile.fr> wrote:

> +define NUSHELL_INSTALL_DEFAULT_CONFIG
> +	$(INSTALL) -m 0644 -D $(@D)/crates/nu-utils/src/sample_config/default_config.nu \
> +		$(TARGET_DIR)/root/.config/nushell/config.nu
> +	$(INSTALL) -m 0644 -D $(@D)/crates/nu-utils/src/sample_config/default_env.nu \
> +		$(TARGET_DIR)/root/.config/nushell/env.nu
> +endef
> +NUSHELL_POST_INSTALL_TARGET_HOOKS += NUSHELL_INSTALL_DEFAULT_CONFIG

I did not apply this patch, because it installs a configuration only
for the root user, so its usefulness seems quite limited, and we
essentially never install special configuration specifically for the
root user (there's a very old exception in the fluxbox package, but
that's it).

Thomas
-- 
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering and training
https://bootlin.com
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Buildroot] [PATCH v6 3/3] support/testing/tests/package/test_nu.py: New runtime test
  2023-03-08 13:15 ` [Buildroot] [PATCH v6 3/3] support/testing/tests/package/test_nu.py: New runtime test Sebastian Weyer
@ 2023-08-30 20:37   ` Thomas Petazzoni via buildroot
  0 siblings, 0 replies; 6+ messages in thread
From: Thomas Petazzoni via buildroot @ 2023-08-30 20:37 UTC (permalink / raw)
  To: Sebastian Weyer; +Cc: Romain Naour, buildroot

On Wed,  8 Mar 2023 14:15:53 +0100
Sebastian Weyer <sebastian.weyer@smile.fr> wrote:

> +class TestNuBase(infra.basetest.BRTest):
> +    # infra.basetest.BASIC_TOOLCHAIN_CONFIG cannot be used as it doesn't
> +    # support a host rustc which is necessary for nushell
> +    config = \
> +        """
> +        BR2_arm=y
> +        BR2_cortex_a9=y
> +        BR2_ARM_ENABLE_NEON=y
> +        BR2_ARM_ENABLE_VFP=y
> +        BR2_TOOLCHAIN_EXTERNAL=y
> +        BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
> +        BR2_SYSTEM_DHCP="eth0"
> +        BR2_PACKAGE_NUSHELL=y
> +        BR2_TARGET_ROOTFS_CPIO=y
> +        """
> +
> +    def login(self):
> +        img = os.path.join(self.builddir, "images", "rootfs.cpio")
> +        self.emulator.boot(arch="armv7",
> +                           kernel="builtin",
> +                           options=["-initrd",img])
> +        self.emulator.login()
> +
> +# load a script on the target and check if it is executed correctly by nu
> +class TestNu(TestNuBase):
> +    config_sample_scripts = \
> +        """
> +        BR2_ROOTFS_POST_BUILD_SCRIPT="{}"
> +        BR2_ROOTFS_POST_SCRIPT_ARGS="{}"
> +        """.format(infra.filepath("tests/package/copy-sample-script-to-target.sh"),
> +                   "{sample_scripts}")
> +
> +    #simple hello world script found in the nushell doc
> +    sample_scripts = ["tests/package/sample_nu.nu"]
> +
> +    def __init__(self, names):
> +        """Add the scripts to the target in build time."""
> +        super(TestNuBase, self).__init__(names)
> +        scripts = [infra.filepath(s) for s in self.sample_scripts]
> +        self.config += self.config_sample_scripts.format(sample_scripts=" ".join(scripts))
> +
> +    def check_sample_scripts_exist(self):
> +        """Check the scripts were really added to the image."""
> +        scripts = [os.path.basename(s) for s in self.sample_scripts]
> +        cmd = "md5sum " + " ".join(scripts)
> +        _, exit_code = self.emulator.run(cmd)
> +        self.assertEqual(exit_code, 0)
> +
> +    def run_sample_scripts(self):
> +        """Run each script previously added to the image."""
> +        for script in self.sample_scripts:
> +            cmd = "nu " + os.path.basename(script)
> +            self.assertRunOk(cmd)
> +
> +    def test_run(self):
> +        self.login()
> +        self.check_sample_scripts_exist()
> +        self.run_sample_scripts()

This was way too complicated, because you based it on the Python
testing infrastructure that aims at being generic. Here we don't need
to be generic, so it can be as simple as:

import os

import infra.basetest


class TestNu(infra.basetest.BRTest):
    # infra.basetest.BASIC_TOOLCHAIN_CONFIG cannot be used as it doesn't
    # support a host rustc which is necessary for nushell
    config = \
        """
        BR2_arm=y
        BR2_cortex_a9=y
        BR2_ARM_ENABLE_NEON=y
        BR2_ARM_ENABLE_VFP=y
        BR2_TOOLCHAIN_EXTERNAL=y
        BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
        BR2_SYSTEM_DHCP="eth0"
        BR2_PACKAGE_NUSHELL=y
        BR2_TARGET_ROOTFS_CPIO=y
        BR2_ROOTFS_POST_BUILD_SCRIPT="{}"
        BR2_ROOTFS_POST_SCRIPT_ARGS="{}"
        """.format(infra.filepath("tests/package/copy-sample-script-to-target.sh"),
                   infra.filepath("tests/package/sample_nu.nu"))

    def test_run(self):
        img = os.path.join(self.builddir, "images", "rootfs.cpio")
        self.emulator.boot(arch="armv7",
                           kernel="builtin",
                           options=["-initrd", img])
        self.emulator.login()
        cmd = "nu sample_nu.nu"
        self.assertRunOk(cmd)

So I adjusted your patch like this and applied to next. Thanks a lot!

Thomas
-- 
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering and training
https://bootlin.com
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-08-30 20:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-08 13:15 [Buildroot] [PATCH v6 1/3] package/nushell: new package Sebastian Weyer
2023-03-08 13:15 ` [Buildroot] [PATCH v6 2/3] package/nushell: Add default configs Sebastian Weyer
2023-08-30 20:36   ` Thomas Petazzoni via buildroot
2023-03-08 13:15 ` [Buildroot] [PATCH v6 3/3] support/testing/tests/package/test_nu.py: New runtime test Sebastian Weyer
2023-08-30 20:37   ` Thomas Petazzoni via buildroot
2023-08-30 20:35 ` [Buildroot] [PATCH v6 1/3] package/nushell: new package Thomas Petazzoni via buildroot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).