]> git.pld-linux.org Git - packages/python3-adblock.git/commitdiff
new
authorJan Palus <atler@pld-linux.org>
Wed, 14 Apr 2021 15:59:58 +0000 (17:59 +0200)
committerJan Palus <atler@pld-linux.org>
Wed, 14 Apr 2021 15:59:58 +0000 (17:59 +0200)
create-crates.sh [new file with mode: 0755]
python3-adblock.spec [new file with mode: 0644]

diff --git a/create-crates.sh b/create-crates.sh
new file mode 100755 (executable)
index 0000000..4591e85
--- /dev/null
@@ -0,0 +1,71 @@
+#!/bin/sh
+
+force_cargo_package=adblock
+
+for cmd in bsdtar rpm-specdump cargo perl; do
+  if ! command -v $cmd > /dev/null 2> /dev/null; then
+    not_installed="$not_installed$cmd "
+  fi
+done
+
+if [ -n "$not_installed" ]; then
+  echo "ERROR: required commands not found: $not_installed" >&2
+  exit 1
+fi
+
+pkg_dir=$(readlink -f $(dirname "$0"))
+pkg_name=$(basename "$pkg_dir")
+
+if [ ! -f "$pkg_dir/$pkg_name.spec" ]; then
+  echo "ERROR: unable to determine package name" >&2
+  exit 1
+fi
+
+spec_dump=$(rpm-specdump "$pkg_dir/$pkg_name.spec")
+pkg_version=$(echo "$spec_dump" | grep PACKAGE_VERSION | cut -f3 -d' ')
+pkg_src=$(basename $(echo "$spec_dump" | grep SOURCEURL0 | cut -f3- -d' '))
+crates_file="$pkg_name-crates-$pkg_version.tar.xz"
+cargo_package=${force_cargo_package:-$pkg_name}
+
+if [ -e "$pkg_dir/$crates_file" ]; then
+  echo "ERROR: crates file $crates_file already exists" >&2
+  exit 1
+fi
+
+if [ ! -f "$pkg_dir/$pkg_src" ]; then
+  echo "ERROR: source file $pkg_src not found" >&2
+  exit 1
+fi
+
+tmpdir=$(mktemp -d)
+
+rm_tmpdir() {
+  if [ -n "$tmpdir" -a -d "$tmpdir" ]; then
+    rm -rf "$tmpdir"
+  fi
+}
+
+trap rm_tmpdir EXIT INT HUP
+
+cd "$tmpdir"
+bsdtar xf "$pkg_dir/$pkg_src"
+src_dir=$(ls)
+if [ $(echo "$src_dir" | wc -l) -ne 1 ]; then
+  echo "ERROR: unexpected source structure:\n$src_dir" >&2
+  exit 1
+fi
+
+cd "$src_dir"
+cargo vendor
+if [ $? -ne 0 ]; then
+  echo "ERROR: cargo vendor failed" >&2
+  exit 1
+fi
+
+# replace cargo package version with @@VERSION@@
+perl -pi -e 'BEGIN { undef $/;} s/(\[\[package\]\]\nname\s*=\s*"'"$cargo_package"'"\nversion\s*=\s*")[^"]+/$1\@\@VERSION\@\@/m' Cargo.lock
+
+cd ..
+tar cJf "$pkg_dir/$crates_file" "$src_dir"/{Cargo.lock,vendor}
+
+# vim: expandtab shiftwidth=2 tabstop=2
diff --git a/python3-adblock.spec b/python3-adblock.spec
new file mode 100644 (file)
index 0000000..91148db
--- /dev/null
@@ -0,0 +1,70 @@
+%define                crates_ver      0.4.4
+%define        module  adblock
+
+Summary:       Brave's adblock library in Python
+Name:          python3-%{module}
+Version:       0.4.4
+Release:       1
+License:       MIT or Apache v2.0
+Group:         Libraries/Python
+Source0:       https://files.pythonhosted.org/packages/source/a/adblock/%{module}-%{version}.tar.gz
+# Source0-md5: 6958de33e5034c1241a69c91989f0e86
+# ./create-crates.sh
+Source1:       %{name}-crates-%{crates_ver}.tar.xz
+# Source1-md5: 932c699a7fa6016098e56026ae389322
+URL:           https://github.com/ArniDagur/python-adblock
+BuildRequires: cargo
+BuildRequires: maturin >= 0.10
+BuildRequires: python3-devel >= 1:3.6
+BuildRequires: rpm-pythonprov
+BuildRequires: rpmbuild(macros) >= 2.004
+BuildRequires: rust >= 1.45
+ExclusiveArch: %{rust_arches}
+BuildRoot:     %{tmpdir}/%{name}-%{version}-root-%(id -u -n)
+
+%description
+Python wrapper for Brave's adblocking library, which is written in
+Rust.
+
+%prep
+%setup -q -n %{module}-%{version} -a1
+
+%{__mv} %{module}-%{crates_ver}/* .
+sed -i -e 's/@@VERSION@@/%{version}/' Cargo.lock
+
+# use our offline registry
+export CARGO_HOME="$(pwd)/.cargo"
+
+mkdir -p "$CARGO_HOME"
+cat >.cargo/config <<EOF
+[source.crates-io]
+registry = 'https://github.com/rust-lang/crates.io-index'
+replace-with = 'vendored-sources'
+
+[source.vendored-sources]
+directory = '$PWD/vendor'
+EOF
+
+%build
+CARGO_HOME="$(pwd)/.cargo" \
+CARGO_NET_OFFLINE=true \
+CARGO_TERM_VERBOSE=true \
+RUSTFLAGS="%{rpmrustflags}" \
+/usr/bin/maturin build --release --no-sdist \
+%ifarch x32
+       --target x86_64-unknown-linux-gnux32
+%endif
+
+%install
+rm -rf $RPM_BUILD_ROOT
+
+install -d $RPM_BUILD_ROOT%{py3_sitedir}
+cp -p target/release/libadblock.so $RPM_BUILD_ROOT%{py3_sitedir}/%{module}.so
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+%files -n python3-%{module}
+%defattr(644,root,root,755)
+%doc CHANGELOG.md README.md
+%attr(755,root,root) %{py3_sitedir}/%{module}.so
This page took 0.110783 seconds and 4 git commands to generate.