Skip to content

Commit

Permalink
add helper script for rpm spec file generation
Browse files Browse the repository at this point in the history
  • Loading branch information
sekiguchi-nagisa committed May 11, 2024
1 parent ede1519 commit acdf384
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 1 deletion.
47 changes: 47 additions & 0 deletions 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)
}

[<CLI(toplevel: $true)>]
typedef _Param() {
[<Option(required: $true, short: "v", long: "version", help: "specify package version (such as 0.0.0)")>]
var version = ""

[<Arg(required: $true, placeholder: "target_dir")>]
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 $@
96 changes: 96 additions & 0 deletions package/rpm/arsh.spec.in
@@ -0,0 +1,96 @@
#
# spec file for package arsh
#
# Copyright (c) 2024 SUSE LLC
# Copyright (c) 2024 Nagisa Sekiguchi <s dot nagisa dot xyz at gmail dot com>
#
# 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
4 changes: 3 additions & 1 deletion sample/check.ds
Expand Up @@ -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
}
Expand Down

0 comments on commit acdf384

Please sign in to comment.