Add .xsession installation base code.

This isn't turned on yet (the testcase just tries to run the function
without exceptions), but this would be the base for a feature to install
the new sample .xsession file for the "Custom session" login option for
most login managers.

The base .xsession was graciously provided by Michael Janses (of
build-tool fame). I've simplified it a bit for kdesrc-build usage and
tried to make it compatible with less featureful shells. The eventual
idea is that it can be used with kdesrc-build-set and/or kdesrc-build so
that you can run the setup script, kdesrc-build, and be able to login to
your new KDE install.
wilder
Michael Pyne 14 years ago
parent 58c00ca1d3
commit 548489c996
  1. 59
      kdesrc-build
  2. 5
      kdesrc-build-test.pl
  3. 149
      sample-xsession.sh

@ -6418,6 +6418,65 @@ sub safe_rmtree
return 1;
}
# This function takes a given file and a build context, and installs it to a
# given location while expanding out template entries within the source file.
#
# The template language is *extremely* simple: <% foo %> is replaced entirely
# with the result of $ctx->getOption(foo, 'no-inherit'). If the result
# evaluates false for any reason than an exception is thrown. No quoting of
# any sort is used in the result, and there is no way to prevent expansion of
# something that resembles the template format.
#
# Multiple template entries on a line will be replaced.
#
# The destination file will be created if it does not exist. If the file
# already exists then an exception will be thrown.
# TODO: Allow for existing files if existing file was generated by
# kdesrc-build.
#
# Error handling: Any errors will result in an exception being thrown.
# Return value: There is no return value.
# Parameters:
# Pathname to the source file (use absolute paths)
# Pathname to the destination file (use absolute paths)
# BuildContext to use for looking up template values
sub installTemplatedFile
{
my ($sourcePath, $destinationPath, $ctx) = @_;
assert_isa($ctx, 'ksb::BuildContext');
open (my $input, '<', $sourcePath) or
croak_runtime("Unable to open template source $sourcePath: $!");
open (my $output, '>', $destinationPath) or
croak_runtime("Unable to open template output $destinationPath: $!");
while (!eof ($input)) {
my $line = readline($input);
if (!defined ($line)) {
croak_runtime("Failed to read from $sourcePath at line $.: $!");
unlink($destinationPath);
}
next unless $line; # Skip blank lines
$line =~
s {
<% \s* # Template bracket and whitespace
([^\s%]+) # Capture variable name
\s*%> # remaining whitespace and closing bracket
}
{
$ctx->getOption($1, 'module') ||
croak_runtime("Invalid variable $1")
}gxe;
# Replace all matching expressions, use extended regexp w/
# comments, and replacement is Perl code to execute.
(print $output $line) or
croak_runtime("Unable to write line to $destinationPath at line $.: $!");
}
}
# 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.

@ -15,6 +15,7 @@ use 5.010;
use Getopt::Long;
use Scalar::Util qw(blessed);
use Storable qw(freeze);
use FindBin qw($RealBin $Bin);
# Control whether we actually try to svn checkouts, possibly more later.
my $fullRun = 0;
@ -515,6 +516,10 @@ SKIP: {
like ($newQMakePossibility, qr/^qmake/, 'qmake looks like an executable even in scalar context.');
}
# Ensure this function can run without throwing exception.
ok(installTemplatedFile("$RealBin/sample-xsession.sh", "$testSourceDirName/xsession.sh", $ctx) || 1,
'installing-template');
done_testing();
### TESTS GO ABOVE THIS LINE
}; # eval

@ -0,0 +1,149 @@
#!/bin/sh
# A script to start the kde workspace.
# Written by Michael Jansen and Michael Pyne
#
# You can use it in two ways. Just copy the content to the given path.
#
# 1. $HOME/.xsession
# ------------------
# Select "custom" session when logging in. This will use that script.
#
# 2. $KDEDIRS/bin/mystartkde
# See "files xsession" on how to use that. Make sure the script is executable.
# Note: This doesn't work with kdesrc-build -- mpyne
# === User-modifiable variables. Should be set automatically by kdesrc-build.
# Where KDE libraries and applications are installed to.
kde_prefix="<% kdedir %>" # E.g. "$HOME/kde-4"
# Where Qt is installed to. If using the system Qt, leave blank or set to
# 'auto' and this script will try to auto-detect.
qt_prefix="<% qtdir %>" # E.g. "$HOME/qt4" or "/usr" on many systems.
# 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.
# 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, create a file
# .xsession-local, which will be sourced just prior to running KDE. This can
# read .bashrc, just set a few vars, etc.
# === End of user-modifiable variables.
# Find system Qt
if test -z "$qt_prefix"; then
# Find right qmake
for qmake_candidate in qmake-qt4 qmake4 qmake; do
if ${qmake_candidate} --version >/dev/null 2>&1; then
qmake="$qmake_candidate"
break;
fi
done
qt_prefix=$(${qmake} -query QT_INSTALL_PREFIX 2>/dev/null)
test -z "$qt_prefix" && qt_prefix="/usr" # Emergency fallback?
echo "Using Qt found in $qt_prefix"
fi
# Try to auto-determine lib suffix if not set. This requires KDE to already
# have been installed though.
if test -z "$lib_suffix" && test -x "$kde_prefix/bin/kde4-config"; then
lib_suffix=$("$kde_prefix/bin/kde4-config" --libsuffix 2>/dev/null)
fi
# Add path elements to a colon-separated environment variable,
# taking care not to add extra unneeded colons.
# Should be sh-compatible.
# Can't use function keyword in Busybox-sh
path_add()
{
eval curVal=\$'{'$1'}'
if [ -n "$curVal" ]; then
eval "$1"="$2:$curVal";
else
eval "$1"="$2"
fi
}
# Initialize some variables based on Qt and KDE install paths.
# Since this should be run as .xsession there's no guarantee of any
# user-specific variables being set already.
libname="lib$libsuffix"
unset STRIGI_PLUGIN_PATH
unset KDEDIRS
# Now add the necessary directories, starting with Qt.
path_add "PATH" "$qt_prefix/bin";
path_add "LD_LIBRARY_PATH" "$qt_prefix/$libname";
path_add "PKG_CONFIG_PATH" "$qt_prefix/$libname/pkgconfig";
path_add "MANPATH" "$qt_prefix/share/man";
# Now add KDE-specific paths.
path_add "PATH" "$kde_prefix/bin";
path_add "LD_LIBRARY_PATH" "$kde_prefix/$libname";
path_add "PKG_CONFIG_PATH" "$kde_prefix/$libname/pkgconfig";
path_add "MANPATH" "$kde_prefix/share/man";
path_add "CMAKE_PREFIX_PATH" "$kde_prefix";
path_add "KDEDIRS" "$kde_prefix";
path_add "QML_IMPORT_PATH" "$kde_prefix/$libname/kde4/imports";
path_add "STRIGI_PLUGIN_PATH" "$kde_prefix/$libname/strigi";
# For Python bindings support.
path_add "PYTHONPATH" "$kde_prefix/$libname/site-packages";
# http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
path_add "XDG_DATA_DIRS" "$path/share";
path_add "XDG_CONFIG_DIRS" "$path/etc/xdg";
#
### Some Convenience stuff
#
if test -n "$user_path"; then
path_add "PATH" "$user_path"
fi
test -d "$HOME/local/bin" && path_add "PATH" "$HOME/local/bin"
test -d "$HOME/local/man" && path_add "MANPATH" "$HOME/local/man"
# Finally, export the variables.
export CMAKE_PREFIX_PATH
export KDEDIRS
export LD_LIBRARY_PATH
export PATH
export PKG_CONFIG_PATH
export PYTHONPATH
export QML_IMPORT_PATH
export STRIGI_PLUGIN_PATH
export XDG_DATA_DIRS
export XDG_CONFIG_DIRS
export MANPATH
# Read in user-specific customizations
if test -f "$HOME/.xsession-local"; then
source "$HOME/.xsession-local"
fi
#
### Start the standard kde login script.
#
"$kde_prefix/bin/startkde"
# If you experience problems on logout it is sometimes helpful to make copies
# of the xsession-errors file on logout.
# cp $HOME/.xsession-errors $HOME/.xsession-errors-`date +"%Y%m%d%H%M"`
# Use user-specific logout if present
if test -f "$HOME/.xsession-logout"; then
source "$HOME/.xsession-logout"
fi
Loading…
Cancel
Save