refractor srpm & bootstrap

This commit is contained in:
wiiznokes 2024-08-21 15:48:30 +02:00
commit 6077476adc
7 changed files with 67 additions and 114 deletions

6
.gitignore vendored
View file

@ -1,4 +1,2 @@
__pycache__/
*.py[cod]
*$py.class
/dev
/dev/*
!dev/.keep

0
dev/.keep Normal file
View file

28
justfile Normal file
View file

@ -0,0 +1,28 @@
set working-directory := 'dev'
set export
PACKAGE := 'cosmic-comp'
# REPO := 'https://github.com/pop-os/cosmic-comp.git'
# VERSION := '0.1.0'
# COMMIT := 'latest'
all: init sources spec build
init:
cp ../rpms/{{PACKAGE}}/* .
../scripts/srpm.sh
sources:
cp vendor-* ~/rpmbuild/SOURCES/
cp *.patch ~/rpmbuild/SOURCES/ || true
spec:
cp ../rpms/{{PACKAGE}}/{{PACKAGE}}.spec .
VENDOR=0 ../scripts/srpm.sh
cp {{PACKAGE}}.spec ~/rpmbuild/SPECS/
build:
rpmbuild --undefine=_disable_source_fetch -bb ~/rpmbuild/SPECS/{{PACKAGE}}.spec
fast-build:
rpmbuild -bb --short-circuit ~/rpmbuild/SPECS/{{PACKAGE}}.spec

30
scripts/bootstrap.sh Normal file → Executable file
View file

@ -1,25 +1,9 @@
#!/bin/bash -x
#!/bin/bash -xe
VENDOR=1
# Names (Source name can sometimes be the same as name)
NAME=
SOURCE_NAME=
# Version and commit (latest if using master)
VERSION=0.1.0
COMMIT=LATEST
# Repos
REPO=https://github.com/pop-os/$SOURCE_NAME
RPM_REPO=https://pagure.io/fedora-cosmic/cosmic-packaging.git
# Paths to files
RPM_FILES=cosmic-packaging/rpms/$NAME/*
SCRIPT_FILE=srpm.sh
SCRIPT_DIR=cosmic-packaging/scripts/$SCRIPT_FILE
export PACKAGE=cosmic-comp
# Clone the RPM repo
git clone --recurse-submodules $RPM_REPO
# Get extra RPM files
cp $RPM_FILES .
# Get script file
cp $SCRIPT_DIR .
# Run script file
. $SCRIPT_FILE $NAME $SOURCE_NAME $VERSION $COMMIT $REPO $VENDOR
git clone https://pagure.io/fedora-cosmic/cosmic-packaging.git
cp cosmic-packaging/rpms/$PACKAGE/* .
cp cosmic-packaging/scripts/srpm.sh .
./srpm.sh

View file

@ -1,22 +0,0 @@
#!/bin/bash -xe
# Build a package locally.
# Need to be called from the root of the repo (./scripts/build_local.sh)
PACKAGE=cosmic-settings
REPO=https://github.com/pop-os/cosmic-settings
rm -rf dev
mkdir dev
cp rpms/$PACKAGE/* dev/
cp scripts/srpm.sh dev/
cd dev
./srpm.sh $PACKAGE $PACKAGE 0.1.0 LATEST $REPO 1
cp vendor-* ~/rpmbuild/SOURCES/
cp *.patch ~/rpmbuild/SOURCES/ || true
cp $PACKAGE.spec ~/rpmbuild/SPECS/
rpmbuild -bb ~/rpmbuild/SPECS/$PACKAGE.spec

View file

@ -1,28 +0,0 @@
#!/bin/bash -x
# name of the crate/package
name=$1
# version of the crate/package
version=$2
# commit to target (latest == master)
commit=$3
# path to the spec file on the pc
path_to_spec=$4
# repo link
repo=$5
# Get specfile
cp $path_to_spec $name.spec 2>/dev/null || :
# Make replacements to specfile
sed -i "/^Version: / s/.*/Version: $version~^%{commitdate}git%{sub %{commit} 1 7}/" $name.spec
sed -i "/^%global commit / s/.*/%global commit none/" $name.spec
current_date=$(date +'%Y%m%d')
sed -i "/^%global commitdate / s/.*/%global commitdate $current_date/" $name.spec
sed -i "/^%global commitdatestring / s/.*/%global commitdatestring $current_date/" $name.spec
ls -a
pwd
echo Done! $1 $2 $3 $4 $5

View file

@ -1,39 +1,43 @@
#!/bin/bash -xe
# clone repo, detect last commit, vendor deps, update specfile
#
#
# PACKAGE: package name
# SOURCE_NAME: sometime the same of PACKAGE
# VERSION: tag, semver
# COMMIT: latest or sha
# REPO: link
# VENDOR: 0 or 1
if [ "$#" -lt 6 ]; then
echo "Error: Less than six arguments provided."
exit 1
check_variable() {
local var_name=$1
if [ -z "${!var_name+x}" ]; then
echo "Error: '$var_name' is not defined."
exit 1
fi
}
check_variable PACKAGE
SOURCE_NAME=${SOURCE_NAME:-"$PACKAGE"}
VERSION=${VERSION:-"0.1.0"}
COMMIT=${COMMIT:-"latest"}
REPO=${REPO:-"https://github.com/pop-os/$SOURCE_NAME"}
VENDOR=${VENDOR:-1}
if [ ! -e "$PACKAGE" ]; then
git clone --recurse-submodules $REPO $PACKAGE
fi
# NAME of the crate/package
NAME=$1
SOURCE_NAME=$2
# VERSION of the crate/package
VERSION=$3
# COMMIT to target (LATEST == master)
COMMIT=$4
# REPO link
REPO=$5
# VENDOR?
VENDOR=$6
LATEST="LATEST"
# Clone REPO and cd into it
mkdir $SOURCE_NAME-$COMMIT && cd $SOURCE_NAME-$COMMIT && git clone --recurse-submodules $REPO .
cd $PACKAGE
# Get latest COMMIT hash if COMMIT is set to latest
if [[ "$COMMIT" == "$LATEST" ]]; then
if [[ "$COMMIT" == "latest" ]]; then
COMMIT=$(git rev-parse HEAD)
cd .. && mv $SOURCE_NAME-LATEST $SOURCE_NAME-$COMMIT && cd $SOURCE_NAME-$COMMIT
fi
# Set short commit
SHORTCOMMIT=$(echo ${COMMIT:0:7})
# Reset to specified COMMIT
git reset --hard $COMMIT
COMMITDATE=$(git log -1 --format=%cd --date=format:%Y%m%d)
@ -43,16 +47,10 @@ if [ "$VENDOR" -eq 1 ]; then
echo "VENDOR=1"
# Vendor dependencies and zip vendor
cargo vendor >../vendor-config-$SHORTCOMMIT.toml
tar -pczf vendor-$SHORTCOMMIT.tar.gz vendor && mv vendor-$SHORTCOMMIT.tar.gz ../vendor-$SHORTCOMMIT.tar.gz
# Back into parent directory
rm -rf vendor
cd ..
else
cd ..
tar -pczf ../vendor-$SHORTCOMMIT.tar.gz vendor
fi
# rm repo
rm -rf $SOURCE_NAME-$COMMIT
cd ..
# Make replacements to specfile
sed -i "/^Version: / s/.*/Version: $VERSION~^%{commitdate}git%{shortcommit}/" $NAME.spec
@ -60,8 +58,3 @@ sed -i "/^%global commit / s/.*/%global commit $COMMIT/" $NAME.spec
sed -i "/^%global commitdate / s/.*/%global commitdate $COMMITDATE/" $NAME.spec
sed -i "/^%global commitdatestring / s/.*/%global commitdatestring $COMMITDATESTRING/" $NAME.spec
# Should have these sources
# SOURCE_NAME-SHORTCOMMIT.tar.gz
# vendor-%{shortcommit}.tar.gz
# vendor-config-%{shortcommit}.toml