Verified Commit 3950afb4 authored by Michael Pyne's avatar Michael Pyne
Browse files

Merge branch 'kogiokka/kdesrc-build-kdesrc-run'

This converts the kdesrc-run helper function to be a real program
(written in Perl since we're already using that with kdesrc-build),
which can easily read kdesrc-build's metadata to quickly find the
appropriate prefix.sh rather than having to make guesses.

Contributed by Luis Kao in MR !85. However I manually squashed the
commits and rebased against origin/master.
parents dd8b6352 b95b5d3b
......@@ -96,6 +96,7 @@ endif()
install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/kdesrc-build DESTINATION ${KDE_INSTALL_BINDIR})
install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/kdesrc-build-setup DESTINATION ${KDE_INSTALL_BINDIR})
install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/kdesrc-run DESTINATION ${KDE_INSTALL_BINDIR})
install(PROGRAMS
${CMAKE_SOURCE_DIR}/sample-kde-env-master.sh
......
#!/usr/bin/env perl
=pod
=encoding UTF-8
=head1 NAME
kdesrc-run - Run KDE applications built with kdesrc-build.
=head1 SYNOPSIS
kdesrc-run [options] <module-name> [arguments]
=head1 OPTIONS
-e, --exec <program> Specify program of the module. Default to module name.
-f, --fork Launch the program in a new session.
-q, --quiet Do not print run information.
-h, --help Print usage information and exit.
--list-installed Print installed modules and exit.
=head1 EXAMPLES
B<kdesrc-run -f kate -l 5 file1.txt>
Launch kate in a new session with '-l 5 file1.txt' arguments.
B<kdesrc-run -e kate-syntax-highlighter kate --list-themes>
Launch kate-syntax-highlighter of module kate with '--list-themes' argument.
=cut
use 5.014;
use strict;
use warnings;
use autodie;
use Pod::Usage;
use Getopt::Long qw(:config pass_through require_order);
use JSON::PP;
use List::Util qw(first);
binmode STDOUT, 'encoding(UTF-8)';
binmode STDERR, 'encoding(UTF-8)';
our $optArgs;
our $optExec;
our $optFork = 0;
our $optHelp = 0;
our $optQuiet = 0;
our $optListInstalled = 0;
GetOptions(
'exec|e=s' => \$optExec,
'fork|f' => \$optFork,
'help|h' => sub { pod2usage(0); },
'quiet|q' => \$optQuiet,
'list-installed' => \$optListInstalled,
);
if ($#ARGV == -1 && not $optListInstalled) {
pod2usage(0);
}
my $module = shift @ARGV;
my $exec = $optExec // $module;
my $buildDataFile = first { -e $_ }
('./.kdesrc-build-data', "$ENV{HOME}/.kdesrc-build-data");
if (not defined $buildDataFile) {
say qq(".kdesrc-build-data" file is not available. Exit now.);
exit 1;
}
my $buildData = do {
open my $fh, '<', $buildDataFile;
local $/ = undef;
decode_json(<$fh>);
};
if ($optListInstalled) {
say foreach sort { $a cmp $b }
grep { defined $buildData->{$_}{'install-dir'} } keys %$buildData;
exit;
}
if (not defined $buildData->{$module}) {
say qq(Module "$module" has not been built yet.);
exit 1;
}
my $buildDir = $buildData->{$module}{'build-dir'};
my $installDir = $buildData->{$module}{'install-dir'};
my $revision = $buildData->{$module}{'last-build-rev'};
my $execPath = "$installDir/bin/$exec";
if (not -e $execPath) {
say qq(Program "$exec" does not exist.);
say qq(Try to set executable name with -e option.);
exit 127; # Command not found
}
# Most of the logic is done by Perl, so the shell script here should be POSIX
# compliant. Consider using ShellCheck to make sure of that.
my $script = qq{
#!/bin/sh
# Set up environment variables (dot command).
. "$buildDir/prefix.sh";
# Launch the program with optional arguments.
if [ "$optFork" = 1 ]; then
setsid -f "$execPath" "\$@";
else
"$execPath" "\$@";
fi;
};
# Print run information
if (not $optQuiet) {
print '#' x 80, "\n";
print ' ' x 35, 'kdesrc-run', "\n";
say "Module: $module";
say "Program: $exec";
say "Revision: $revision";
say "Arguments: @ARGV";
print '#' x 80, "\n";
print "\n";
}
# Instead of embedding @ARGV in shell script with string interpolation, pass
# them as arguments of the script. Let the shell handle the list through "$@",
# so it will do the quoting on each one of them.
#
# Run the script with sh options specification:
# sh -c command_string command_name $1 $2 $3...
exec('/bin/sh', '-c', $script, $exec, @ARGV);
......@@ -36,20 +36,6 @@ use constant {
## Add kdesrc-build to PATH
export PATH="$HOME/kde/src/kdesrc-build:$PATH"
## Run projects built with kdesrc-build
function kdesrc-run
{
# get the build directory and install directory from cache. save as array.
local moduledirs=( $(perl -MJSON::PP -Mautodie \
-E "my \$dir = -e q(kdesrc-buildrc) ? q(.) : \$ENV{HOME};" \
-E "open my \$json, q(<), qq(\$dir/.kdesrc-build-data);" \
-E "local \$/; my \$m = decode_json(<\$json>);" \
-E "say \$m->{q($1)}->{q(build-dir)};" \
-E "say \$m->{q($1)}->{q(install-dir)};") )
source "${moduledirs[0]}/prefix.sh" && "${moduledirs[1]}/bin/$1" "${@:2:$#}"
}
## Autocomplete for kdesrc-run
function _comp-kdesrc-run
{
......@@ -63,12 +49,7 @@ function _comp-kdesrc-run
fi
# Filter cache to get build modules
local modules=$(perl -MJSON::PP -Mautodie \
-E 'my $dir = -e q(kdesrc-buildrc) ? q(.) : $ENV{HOME};' \
-E 'open my $json, q(<), qq($dir/.kdesrc-build-data);' \
-E 'local $/; my $m = decode_json(<$json>);' \
-E 'my @modules_in_cache = keys %{$m};' \
-E 'print qq(@modules_in_cache);' )
local modules=$(kdesrc-run --list-installed)
# intersect lists
COMPREPLY=($(compgen -W "${modules}" $cur))
......@@ -344,21 +325,21 @@ __DATA__
@@ pkg/debian/unknown
# This is woefully incomplete and not very useful.
# Perl support
libyaml-libyaml-perl
libio-socket-ssl-perl
libyaml-libyaml-perl
libio-socket-ssl-perl
libjson-xs-perl
liburi-perl
liburi-perl
# Basic build tools
bison
build-essential
cmake
flex
bison
build-essential
cmake
flex
gettext
git
gperf
libssl-dev
git
gperf
libssl-dev
intltool
shared-mime-info
shared-mime-info
# Qt-related
libdbusmenu-qt5-dev
# And others
......@@ -371,56 +352,56 @@ libqrencode-dev
# Neon is a lot like Debian, except we know Qt is sufficiently new
# to install Qt dev-tools.
# Perl support
libyaml-libyaml-perl
libio-socket-ssl-perl
libyaml-libyaml-perl
libio-socket-ssl-perl
libjson-xs-perl
liburi-perl
liburi-perl
# Basic build tools
bison
build-essential
cmake
flex
bison
build-essential
cmake
flex
gettext
git
gperf
libssl-dev
git
gperf
libssl-dev
intltool
meson
ninja-build
shared-mime-info
shared-mime-info
# Qt-related
libdbusmenu-qt5-dev
libqt5svg5-dev
libqt5waylandclient5-dev
libqt5x11extras5-dev
libqt5waylandclient5-dev
libqt5x11extras5-dev
qtbase5-private-dev
qtdeclarative5-dev
qtmultimedia5-dev
qtquickcontrols2-5-dev
qtscript5-dev
qtmultimedia5-dev
qtquickcontrols2-5-dev
qtscript5-dev
qttools5-dev
qtwayland5-dev-tools
qtwayland5-dev-tools
qtxmlpatterns5-dev-tools
# Frameworks dependencies
# .. polkit-qt-1
libpolkit-gobject-1-dev
libpolkit-agent-1-dev
libpolkit-gobject-1-dev
libpolkit-agent-1-dev
# .. kdoctools
libxml2-dev
libxml2-dev
libxslt-dev
# .. kwindowsystem
libwayland-dev
libxcb-icccm4-dev
libxcb-keysyms1-dev
libxcb-res0-dev
libxcb-icccm4-dev
libxcb-keysyms1-dev
libxcb-res0-dev
libxcb-xfixes0-dev
libxcb-xkb-dev
libxfixes-dev
libxcb-xkb-dev
libxfixes-dev
libxrender-dev
wayland-protocols
wayland-protocols
# .. kwallet
libgcrypt-dev
libgpgme11-dev
libgcrypt-dev
libgpgme11-dev
libgpgmepp-dev
# .. kactivities
libboost-dev
......@@ -432,12 +413,12 @@ libx11-xcb-dev
# And others
qt5keychain-dev
libopenal-dev
libopenjp2-7-dev
libopenjp2-7-dev
qtlocation5-dev
libraw-dev
libraw-dev
libsane-dev
libsndfile1-dev
libxcb-glx0-dev
libsndfile1-dev
libxcb-glx0-dev
liblmdb-dev
libsm-dev
libnm-dev
......
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