From acdf3844160ca11f16e0a38e6f872bc14270c823 Mon Sep 17 00:00:00 2001 From: sekiguchi-nagisa Date: Sat, 11 May 2024 22:17:35 +0800 Subject: [PATCH] add helper script for rpm spec file generation --- package/gen_asset.arsh | 47 ++++++++++++++++++++ package/rpm/arsh.spec.in | 96 ++++++++++++++++++++++++++++++++++++++++ sample/check.ds | 4 +- 3 files changed, 146 insertions(+), 1 deletion(-) create mode 100755 package/gen_asset.arsh create mode 100644 package/rpm/arsh.spec.in diff --git a/package/gen_asset.arsh b/package/gen_asset.arsh new file mode 100755 index 000000000..ae374159b --- /dev/null +++ b/package/gen_asset.arsh @@ -0,0 +1,47 @@ +#!/usr/bin/env arsh + +error() : Nothing { + echo 1>&2 \[error\] $@ + shctl set trace_on_exit + exit 1 +} + +gen_rpm_spec() { + var src = $1 :- error "require src" + var dest = $2 :- error "require dest" + var version = $3 :- error "require version" + + var content = "$(cat $src)" :- error "$src: content is broken" + $content = " +function(VERSION: String, dest: String) => { + cat << EOF > \$dest +$content + +EOF +}" + var func = $MODULE._func($content)()! as (String, String) -> Void + $func($version, $dest) +} + +[] +typedef _Param() { + [] + var version = "" + + [] + var target = "" +} + +_main(param: _Param) { + shctl set errraise + $/^\d+\.\d+\.\d+$/ =~ $param.version || error "invalid version number: ${param.version}" + var dir = "${param.target}/arsh" + mkdir -p $dir + assert test -f $SCRIPT_DIR/rpm/arsh.spec.in + gen_rpm_spec $SCRIPT_DIR/rpm/arsh.spec.in $dir/arsh.spec ${param.version} + curl -Lf "https://github.com/sekiguchi-nagisa/arsh/archive/refs/tags/v${param.version}.tar.gz" \ + > "$dir/arsh-${param.version}.tar.gz" + cp $SCRIPT_DIR/../LICENSE $dir/ +} + +shctl is-sourced || _main $@ \ No newline at end of file diff --git a/package/rpm/arsh.spec.in b/package/rpm/arsh.spec.in new file mode 100644 index 000000000..99e800ebf --- /dev/null +++ b/package/rpm/arsh.spec.in @@ -0,0 +1,96 @@ +# +# spec file for package arsh +# +# Copyright (c) 2024 SUSE LLC +# Copyright (c) 2024 Nagisa Sekiguchi +# +# All modifications and additions to the file contributed by third parties +# remain the property of their copyright owners, unless otherwise agreed +# upon. The license for this file, and modifications and additions to the +# file, is the same license as for the pristine package itself (unless the +# license for the pristine package is not an Open Source License, in which +# case the license is the MIT License). An "Open Source License" is a +# license that conforms to the Open Source Definition (Version 1.9) +# published by the Open Source Initiative. + +# Please submit bugfixes or comments via https://bugs.opensuse.org/ +# + + +Summary: A statically typed scripting language with shell-like features +Name: arsh + +Version: ${VERSION} +Release: 0.%{?dist} + +License: Apache-2.0 +Group: System/Shells +URL: https://github.com/sekiguchi-nagisa/arsh + +Source0: %{name}-%{version}.tar.gz +BuildRequires: gcc-c++ +BuildRequires: git +BuildRequires: pcre2-devel >= 10.30 +BuildRequires: re2c >= 2.0 +BuildRoot: %{_tmppath}/%{name}-%{version}-build +Requires: bash-completion +Requires: fzf + +%if 0%{?suse_version} || 0%{?is_opensuse} +Requires: libpcre2-8-0 >= 10.30 +%else +Requires: pcre2 >= 10.30 +%endif + +%if 0%{?rhel} && 0%{?rhel} < 8 +BuildRequires: cmake3 +%else +BuildRequires: cmake +%endif + +%description + +A statically typed scripting language with shell-like features. + +%if 0%{?suse_version} || 0%{?is_opensuse} +%endif + +%prep +%setup -q -n %{name}-%{version} + +%build +%if 0%{?rhel} && 0%{?rhel} < 8 +%cmake3 -DUSE_CTEST=off -DCMAKE_BUILD_TYPE=RELWITHDEBINFO +%else +%cmake -DUSE_CTEST=off -DCMAKE_BUILD_TYPE=RELWITHDEBINFO +%endif +%if 0%{?cmake_build:1} +%cmake_build +%else +make %{?_smp_mflags} +%endif + +%install +%if 0%{?cmake_install:1} +%cmake_install +%else +%make_install +%endif + +%files +%defattr(0755,root,root) +%{_bindir}/* +%{_datadir}/arsh +%{_datadir}/arsh/completions +%{_datadir}/arsh/modules + +%defattr(0644,root,root) +%{_datadir}/arsh/completions/* +%{_datadir}/arsh/modules/* +%if 0%{?suse_version} < 1500 +%doc LICENSE +%else +%license LICENSE +%endif + +%changelog diff --git a/sample/check.ds b/sample/check.ds index 0b7cf6069..662499faf 100755 --- a/sample/check.ds +++ b/sample/check.ds @@ -10,7 +10,9 @@ for a in @($SCRIPT_DIR/*) { } ## check scripts -for ss in @($SCRIPT_DIR/../scripts/*.ds) { +shctl set nullglob +for ss in @($SCRIPT_DIR/../{scripts,package}/*.{ds,arsh}) { + $ss = $ss.realpath() var r = call $BIN_NAME --compile-only $ss echo ${$r ? "[OK]" : "[NG]"} $ss }