Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tito integration #447

Closed
wants to merge 16 commits into from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
bin
obj
valgrind.log
__pycache__
115 changes: 115 additions & 0 deletions .tito/custom/fixed_submodule_aware_builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import os

from tito.builder import SubmoduleAwareBuilder as BuggySubmoduleAwareBuilder
from tito.common import (
chdir,
debug,
run_command,
create_tgz,
get_commit_timestamp,
)
from tito.tar import TarFixer


class SubmoduleAwareBuilder(BuggySubmoduleAwareBuilder):
def run_git_archive(self, relative_git_dir, prefix, commit, dest_tar, subdir=None):
# command to generate a git-archive
git_archive_cmd = "git archive --format=tar --prefix=%s/ %s:%s --output=%s" % (
prefix,
commit,
relative_git_dir,
dest_tar,
)

if subdir is None:
return run_command(git_archive_cmd)

with chdir(subdir):
run_command(git_archive_cmd)

# Run git-archive separately if --debug was specified.
# This allows us to detect failure early.
# On git < 1.7.4-rc0, `git archive ... commit:./` fails!
debug(
"git-archive fails if relative dir is not in git tree",
"%s > /dev/null" % git_archive_cmd,
)

def create_tgz(self, git_root, prefix, commit, relative_dir, dest_tgz):
"""
Create a .tar.gz from a projects source in git.
And include submodules
"""

git_root_abspath = os.path.abspath(git_root)
gitmodules_path = os.path.join(git_root_abspath, ".gitmodules")

# if .gitmodules does not exist, just call the existing create_tgz function
# as there is nothing to see here.
if not os.path.exists(gitmodules_path):
return create_tgz(git_root, prefix, commit, relative_dir, dest_tgz)

os.chdir(git_root_abspath)
timestamp = get_commit_timestamp(commit)

# Accommodate standalone projects with specfile in root of git repo:
relative_git_dir = "%s" % relative_dir
if relative_git_dir in ["/", "./"]:
relative_git_dir = ""

basename = os.path.splitext(dest_tgz)[0]
initial_tar = "%s.initial" % basename

# We need to tar up the following:
# 1. the current repo
self.run_git_archive(relative_git_dir, prefix, commit, initial_tar, None)

# 2. all of the submodules
# then combine those into a single archive.
submodules_cmd = "git submodule--helper list"
submodules_output = run_command(submodules_cmd)

# split submodules output on newline
# then on tab, and the directory is the last entry
submodules_list = [
line.split("\t")[-1] for line in submodules_output.split("\n")
]

submodule_tar_files = []
# We ignore the hash in the sub modules list as we'll have to get the correct one
# from the commit id in commit
for submodule in submodules_list:
# to find the submodule shars:
# git rev-parse <commit>:./<submodule>
rev_parse_cmd = "git rev-parse %s:./%s" % (commit, submodule)
submodule_commit = run_command(rev_parse_cmd)
submodule_tar_file = "%s.%s" % (initial_tar, submodule.replace("/", "_"))
# prefix should be <prefix>/<submodule>
submodule_prefix = "%s/%s" % (prefix, submodule)

self.run_git_archive(
relative_git_dir,
submodule_prefix,
submodule_commit,
submodule_tar_file,
submodule,
)
submodule_tar_files.append(submodule_tar_file)

# we need to append all of the submodule tar files onto the initial
# Tar can concatenate only 2 archives at a time
for tar_file in submodule_tar_files:
run_command("tar -Af %s %s" % (initial_tar, tar_file))

fixed_tar = "%s.tar" % basename
fixed_tar_fh = open(fixed_tar, "wb")
try:
tarfixer = TarFixer(
open(initial_tar, "rb"), fixed_tar_fh, timestamp, commit
)
tarfixer.fix()
finally:
fixed_tar_fh.close()

# It's a pity we can't use Python's gzip, but it doesn't offer an equivalent of -n
return run_command("gzip -n -c < %s > %s" % (fixed_tar, dest_tgz))
3 changes: 3 additions & 0 deletions .tito/packages/.readme
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
the .tito/packages directory contains metadata files
named after their packages. Each file has the latest tagged
version and the project's relative directory.
1 change: 1 addition & 0 deletions .tito/packages/ly
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.5.3 ./
7 changes: 7 additions & 0 deletions .tito/tito.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[buildconfig]
builder = fixed_submodule_aware_builder.SubmoduleAwareBuilder
tagger = tito.tagger.VersionTagger
changelog_do_not_remove_cherrypick = 0
changelog_format = %s (%ae)
lib_dir = .tito/custom
tag_format = "v{version}"
85 changes: 85 additions & 0 deletions ly.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
Name: ly
Version: 0.5.3
Release: 5%{?dist}
Summary: a TUI display manager

License: WTFPL
URL: https://github.com/fairyglade/ly.git
Source0: %{name}-%{version}.tar.gz

BuildRequires: make automake
BuildRequires: gcc gcc-c++
BuildRequires: kernel-devel pam-devel
BuildRequires: libxcb-devel
BuildRequires: systemd-rpm-macros
BuildRequires: gawk

Requires(post): policycoreutils-python-utils
Requires(postun): policycoreutils-python-utils
%systemd_requires

%description
Ly is a lightweight TUI (ncurses-like) display manager for Linux and BSD.

%prep
%autosetup


%build
%make_build
mv -f res/config.ini config.ini_orig
awk '{print}
/#save_file/{print "save_file = %{_sharedstatedir}/%{name}/save"}
/#wayland_specifier/{print "wayland_specifier = true"}
' config.ini_orig > res/config.ini


%install
%make_install installsystemd
install -m 755 -d %{buildroot}%{_sharedstatedir}/%{name}

%check


%files
%license license.md
%doc readme.md
%config(noreplace) %{_sysconfdir}/ly
%config %{_sysconfdir}/pam.d/*
%{_unitdir}/*
%{_bindir}/*
%{_sharedstatedir}/%{name}


%post
%systemd_post %{name}.service
semanage fcontext --add --ftype f --type xdm_exec_t '%{_bindir}/ly' 2>/dev/null || :
semanage fcontext --add --ftype a --type xdm_var_lib_t '%{_sharedstatedir}/%{name}(/.*)?' 2>/dev/null || :
restorecon -R %{_bindir}/ly %{_sharedstatedir}/%{name} || :

%preun
%systemd_preun %{name}.service

%postun
if [ $1 -eq 0 ];then
semanage fcontext --delete --ftype f --type xdm_exe_t '%{_bindir}/ly' 2>/dev/null || :
semanage fcontext --delete --ftype a --type xdm_var_lib_t '%{_sharedstatedir}/%{name}(/.*)?' 2>/dev/null || :
fi

%changelog
* Wed Oct 05 2022 Jerzy Drożdż <[email protected]> - 0.5.3-5
- Added patches from PR #446

* Sun Oct 02 2022 Jerzy Drożdż <[email protected]> - 0.5.3-4
- Fixed postun script

* Fri Sep 30 2022 Jerzy Drożdż <[email protected]> - 0.5.3-3
- Added wayland_specifier = true

* Fri Sep 30 2022 Jerzy Drożdż <[email protected]> - 0.5.3-2
- Added setting SELinux contexts
- Added configuration option for state files
- Configuration directory and pam service set to \%config

* Thu Sep 29 2022 Jerzy Drożdż <[email protected]> - 0.5.3-1
- Initial build
5 changes: 4 additions & 1 deletion src/login.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,11 @@ void auth(
char vt[5];
snprintf(vt, 5, "vt%d", config.tty);

// set env
// set env (this clears the environment)
env_init(pwd);
// Re-add XDG environment variables from lines 508,509
env_xdg_session(desktop->display_server[desktop->cur]);
env_xdg(tty_id, desktop->list_simple[desktop->cur]);

if (dgn_catch())
{
Expand Down