Commit 7dd4484d authored by Michael Pyne's avatar Michael Pyne
Browse files

Merge branch 'xsession-support'

Feature seems to work in my testing, time to push out to master and verify it
doesn't break anything. I will also post the revised documentation to the
website.

If you don't like the idea of kdesrc-build adding a .xsession for you, then
you can set 'install-session-driver' to false in your kdesrc-buildrc.
parents 8c038f9b fb5bd6fc
This diff is collapsed.
......@@ -40,6 +40,7 @@ use warnings;
use Fcntl qw(:DEFAULT :seek); # For sysopen constants
use Carp;
use POSIX qw(strftime :sys_wait_h _exit);
use File::Basename; # basename
use File::Find; # For our lndir reimplementation.
use File::Path qw(remove_tree);
use File::Glob ':glob';
......@@ -1616,6 +1617,7 @@ EOF
"debug" => "",
"debug-level" => ksb::Debug::INFO,
"delete-my-patches" => 0, # Should only be set from cmdline
"delete-my-settings" => 0, # Should only be set from cmdline
"dest-dir" => '${MODULE}', # single quotes used on purpose!
"disable-agent-check" => 0, # If true we don't check on ssh-agent
"do-not-compile" => "",
......@@ -1623,6 +1625,7 @@ EOF
"git-repository-base" => {}, # Base path template for use multiple times.
"http-proxy" => '', # Proxy server to use for HTTP.
"install-after-build" => 1, # Default to true
"install-session-driver" => 1,# Default to true
"kdedir" => "$ENV{HOME}/kde",
"kde-languages" => "",
"libpath" => "",
......@@ -6596,6 +6599,117 @@ sub installTemplatedFile
}
}
# This function installs a source file to a destination path, assuming the
# source file is a "templated" source file (see also installTemplatedFile), and
# records a digest of the file actually installed. This function will overwrite
# a destination if the destination is identical to the last-installed file.
#
# Error handling: Any errors will result in an exception being thrown.
# Return value: There is no return value.
# Parameters:
# BuildContext to use for looking up template values,
# The full path to the source file.
# The full path to the destination file (incl. name)
# The key name to use for searching/recording installed MD5 digest.
sub installCustomFile
{
use File::Copy qw(copy);
my $ctx = assert_isa(shift, 'ksb::BuildContext');
my ($sourceFilePath, $destFilePath, $md5KeyName) = @_;
my $baseName = basename($sourceFilePath);
if (-e $destFilePath) {
my $existingMD5 = $ctx->getPersistentOption('/digests', $md5KeyName) // '';
if (fileDigestMD5($destFilePath) ne $existingMD5) {
if (!$ctx->getOption('#delete-my-settings')) {
error ("\tr[*] Installing \"b[$baseName]\" would overwrite an existing file:");
error ("\tr[*] y[b[$destFilePath]");
error ("\tr[*] If this is acceptable, please delete the existing file and re-run,");
error ("\tr[*] or pass b[--delete-my-settings] and re-run.");
return;
}
elsif (!pretending()) {
copy ($destFilePath, "$destFilePath.kdesrc-build-backup");
}
}
}
if (!pretending()) {
installTemplatedFile($sourceFilePath, $destFilePath, $ctx);
$ctx->setPersistentOption('/digests', $md5KeyName, fileDigestMD5($destFilePath));
}
}
# This function installs the included sample .xsession and environment variable
# setup files, and records the md5sum of the installed results.
#
# If a file already exists, then its md5sum is taken and if the same as what
# was previously installed, is overwritten. If not the same, the original file
# is left in place and the .xsession is instead installed to
# .xsession-kdesrc-build
#
# Error handling: Any errors will result in an exception being thrown.
# Return value: There is no return value.
# Parameters:
# BuildContext to use for looking up template values,
sub installCustomSessionDriver
{
use FindBin qw($RealBin);
use List::Util qw(first);
use File::Copy qw(copy);
my $ctx = assert_isa(shift, 'ksb::BuildContext');
my @xdgDataDirs = split(':', $ENV{XDG_DATA_DIRS} || '/usr/local/share/:/usr/share/');
my $xdgDataHome = $ENV{XDG_DATA_HOME} || "$ENV{HOME}/.local/share";
# First we have to find the source
my @searchPaths = ($RealBin, map { "$_/kdesrc-build" } ($xdgDataHome, @xdgDataDirs));
s{/+$}{} foreach @searchPaths; # Remove trailing slashes
s{//+}{/}g foreach @searchPaths; # Remove duplicate slashes
my $envScript = first { -f $_ } (
map { "$_/sample-kde-env-master.sh" } @searchPaths
);
my $sessionScript = first { -f $_ } (
map { "$_/sample-xsession.sh" } @searchPaths
);
my $userSample = first { -f $_ } (
map { "$_/sample-kde-env-user.sh" } @searchPaths
);
if (!$envScript || !$sessionScript) {
warning ("b[*] Unable to find helper files to setup a login session.");
warning ("b[*] You will have to setup login yourself, or install kdesrc-build properly.");
return;
}
my $destDir = $ENV{XDG_CONFIG_HOME} || "$ENV{HOME}/.config";
super_mkdir($destDir) unless -d $destDir;
installCustomFile($ctx, $envScript, "$destDir/kde-env-master.sh",
'kde-env-master-digest');
installCustomFile($ctx, $sessionScript, "$ENV{HOME}/.xsession",
'xsession-digest');
if (!pretending()) {
if (! -e "$destDir/kde-env-user.sh") {
copy($userSample, "$destDir/kde-env-user.sh") or do {
warning ("b[*] Unable to install b[$userSample]: $!");
warning ("b[*] You should create b[~/.config/kde-env-user.sh] yourself or fix the error and re-run");
};
}
chmod (0744, "$ENV{HOME}/.xsession") or do {
error ("\tb[r[*] Error making b[~/.xsession] executable: $!");
error ("\tb[r[*] If this file is not executable you may not be able to login!");
};
}
}
# Reads a "line" from a file. This line is stripped of comments and extraneous
# whitespace. Also, backslash-continued multiple lines are merged into a single
# line.
......@@ -7637,6 +7751,11 @@ DONE
last SWITCH;
};
/^--delete-my-settings$/ && do {
$ctx->setOption('#delete-my-settings', 1);
last SWITCH;
};
/^(--revision|-r)=?/ && do {
my $revision = extract_option_value_required($_, @options);
$ctx->setOption('#revision', $revision);
......@@ -9148,6 +9267,7 @@ eval
cleanup_log_directory($ctx) if $ctx->getOption('purge-old-logs');
output_failed_module_lists($ctx);
installCustomSessionDriver($ctx) if $ctx->getOption('install-session-driver');
$time = localtime;
my $color = '';
......
......@@ -517,31 +517,37 @@ SKIP: {
like ($newQMakePossibility, qr/^qmake/, 'qmake looks like an executable even in scalar context.');
}
# This test set must be run first as xsession depends on this env-master.
is(system('/bin/sh', '-n', "$RealBin/sample-kde-env-master.sh"), 0,
'env-master pre-install syntax check');
do {
local $ENV{HOME} = "$testSourceDirName"; # Search right spot for kde-env-master.sh
local $ENV{XDG_CONFIG_HOME} = $testSourceDirName;
$ENV{KDESRC_BUILD_TESTING} = 1; # Tell sample-xsession.sh not to run.
# This test set must be run first as xsession depends on this env-master.
is(system('/bin/sh', '-n', "$RealBin/sample-kde-env-master.sh"), 0,
'env-master pre-install syntax check');
is(system('/bin/sh', '-u', "$RealBin/sample-kde-env-master.sh"), 0,
'env-master unset variable check');
local $ENV{KDESRC_BUILD_TESTING} = 1; # Tell sample-xsession.sh not to run.
# Ensure this function can run without throwing exception.
ok(installTemplatedFile("$RealBin/sample-kde-env-master.sh", "$testSourceDirName/.kde-env-master.sh", $ctx) || 1,
'env-master template installation');
is(system('/bin/sh', '-u', "$RealBin/sample-kde-env-master.sh"), 0,
'env-master unset variable check');
is(system('/bin/sh', '-n', "$RealBin/sample-xsession.sh"), 0,
'xsession pre-install syntax check');
# Deliberately after env-master, env-master should have no unset variables if user doesn't set
# this up.
ok(File::Copy::copy("$RealBin/sample-kde-env-user.sh", "$testSourceDirName/kde-env-user.sh"),
'env-user sample installation');
ok(File::Copy::copy("$RealBin/sample-xsession.sh", "$testSourceDirName/xsession.sh"),
'xsession installation');
# Ensure this function can run without throwing exception.
ok(installTemplatedFile("$RealBin/sample-kde-env-master.sh", "$testSourceDirName/kde-env-master.sh", $ctx) || 1,
'env-master template installation');
$ENV{KDESRC_BUILD_TESTING} = 1; # Tell sample-xsession.sh not to run.
is(system('/bin/sh', '-u', "$RealBin/sample-xsession.sh"), 0,
'xsession unset variable check');
is(system('/bin/sh', '-n', "$RealBin/sample-xsession.sh"), 0,
'xsession pre-install syntax check');
ok(File::Copy::copy("$RealBin/sample-xsession.sh", "$testSourceDirName/xsession.sh"),
'xsession installation');
is(system('/bin/sh', '-u', "$RealBin/sample-xsession.sh"), 0,
'xsession unset variable check');
do {
local $ENV{HOME} = "$testSourceDirName"; # Search right spot for kde-env-master.sh
is(system('/bin/sh', '-n', "$testSourceDirName/xsession.sh"), 0,
'xsession post-install syntax check');
};
......
......@@ -9,10 +9,22 @@
#
# See also the sample xsession setup script which requires this file.
#
# Use by copying this script to ~/.kde-env-master (this will be done for you by
# kdesrc-build and/or kdesrc-build-setup, later).
# Use by copying this script to $XDG_CONFIG_HOME/kde-env-master.sh (this will
# be done for you by kdesrc-build and/or kdesrc-build-setup, later). 99% of the
# time this means ~/.config/kde-env-master.sh
#
# NOTHING IN THIS FILE IS MODIFIABLE, OTHERWISE WARNINGS WILL BE GENERATED
# === Load user environment settings (i.e. not set through kdesrc-buildrc)
XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
# === User-modifiable variables. Should be set automatically by kdesrc-build.
# ALL USER MODS GO HERE ↴
if test -f "$XDG_CONFIG_HOME/kde-env-user.sh"; then
. "$XDG_CONFIG_HOME/kde-env-user.sh"
fi
# === Modifiable variables. Should be set automatically by kdesrc-build based
# on kdesrc-buildrc settings. Nothing below this line is user-modifiable!
# kdesrc-build: filter | The KDESRC_BUILD_TESTING stuff is to allow the script to
# kdesrc-build: filter | be executable by testsuite. It is filtered from destination.
......@@ -28,21 +40,12 @@ kde_prefix="$HOME/kde" # kdesrc-build: filter
qt_prefix="$HOME/qt4" # kdesrc-build: filter
fi # kdesrc-build: filter
# Directory to use for KDE configuration and other user customizations.
KDEHOME="$HOME/.kde4-self" # Or perhaps "$HOME/.kde-selfmade", etc.
# "Bitness" suffix to use for library directories. If left blank, will try to
# auto-detect from installed KDE's compiled defaults, which may still leave
# this blank.
lib_suffix="" # Or 32, or 64, as appropriate for your system.
# === End of modifiable variables.
# Additional paths to add to PATH, can be left blank.
user_path="" # Set to colon-separated PATH to add to the Qt/KDE paths.
# If more user customizations to the environment are needed, you can "source"
# this file from a more-specific file such as .bashrc, .profile, etc.
# === End of user-modifiable variables.
# Set defaults if these are unset or null. ':' is a null command
: ${lib_suffix:=""}
: ${user_path:=""}
: ${KDEHOME:="$HOME/.kde4-self"}
# Find system Qt
if test -z "$qt_prefix"; then
......@@ -133,3 +136,7 @@ export XDG_DATA_DIRS
export XDG_CONFIG_DIRS
export MANPATH
export KDEHOME
if ! test -e "$KDEHOME"; then
mkdir -p "$KDEHOME" >/dev/null 2>&1
fi
#!/bin/sh
#
# This is a sample user customization script. Unlike other example environment
# setup files, this one can be modified by the user, and kdesrc-build will not
# warn about it or overwrite it.
#
# This file should be installed to $XDG_CONFIG_HOME/kde-env-user.sh (which
# normally means ~/.config/kde-env-user.sh)
#
# As long as it is found here, the kdesrc-build sample session and environment
# setup scripts will pull in settings from that file first.
### Variables supported by the environment script:
# Directory to use for KDE configuration and other user customizations.
# Syntax uses existing value if set, otherwise sets a different one.
# You can also leave blank, but this risks interfering with system KDE.
KDEHOME="$HOME/.kde4-self"
# "Bitness" suffix to use for library directories. If left blank, will try to
# auto-detect from installed KDE's compiled defaults, which may still leave
# this blank.
lib_suffix="" # Or 32, or 64, as appropriate for your system.
# lib_suffix="32"
# lib_suffix="64"
# Additional paths to add to PATH, can be left blank.
user_path="" # Set to colon-separated PATH to add to the Qt/KDE paths.
### KDE-specific environment variables:
# KDE supports various environment variables that might be useful for your
# kdesrc-build desktop. See also:
# http://techbase.kde.org/KDE_System_Administration/Environment_Variables
KDE_COLOR_DEBUG=1
export KDE_COLOR_DEBUG # Be sure to "export" variables you set yourself.
# If more user customizations to the environment are needed, you can add them
# here.
......@@ -12,14 +12,16 @@
# .xsession-local, which will be sourced just prior to running KDE. This can
# read .bashrc, just set a few vars, etc.
source "$HOME/.kde-env-master.sh" # Should be installed by kdesrc-build
XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
. "${XDG_CONFIG_HOME}/kde-env-master.sh" # Should be installed by kdesrc-build
# See .kde-env-master.sh for details on the kdesrc-build: filter stuff
if ! test -n "$KDESRC_BUILD_TESTING"; then # kdesrc-build: filter
# Read in user-specific customizations
if test -f "$HOME/.xsession-local"; then
source "$HOME/.xsession-local"
. "$HOME/.xsession-local"
fi
#
......@@ -33,6 +35,6 @@ fi
# Use user-specific logout if present
if test -f "$HOME/.xsession-logout"; then
source "$HOME/.xsession-logout"
. "$HOME/.xsession-logout"
fi
fi # kdesrc-build: filter
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment