[kde-doc-english] [kdesrc-build] /: Add (and document) a --query flag, to print information about modules.

Michael Pyne mpyne at kde.org
Tue May 3 02:41:12 UTC 2016


Git commit 6ce561cb46fd9b03da6ff1c1fb0c4c46f8b51a0c by Michael Pyne.
Committed on 03/05/2016 at 00:46.
Pushed by mpyne into branch 'master'.

Add (and document) a --query flag, to print information about modules.

This still takes too long for most shell shortcuts, but will make it
possible to do things like setup shell functions to cd right to a build
dir based only on a module name, check for which git branch a module is
resolved to, or see what config file options a module ended up falling
under.

As part of the documentation changes, I also ported the docs to KF5.

M  +26   -8    CMakeLists.txt
M  +3    -3    doc/CMakeLists.txt
M  +65   -4    doc/index.docbook
M  +72   -4    doc/man-kdesrc-build.1.docbook
M  +48   -9    modules/ksb/Application.pm

http://commits.kde.org/kdesrc-build/6ce561cb46fd9b03da6ff1c1fb0c4c46f8b51a0c

diff --git a/CMakeLists.txt b/CMakeLists.txt
index d5350a0..45d5902 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,15 +1,29 @@
-cmake_minimum_required(VERSION 2.8.9)
+cmake_minimum_required(VERSION 3.0)
 project(kdesrc-build)
 
-find_package(KDE4) # Needed for the docs, but optional.
+# Needed for the docs, but optional. If not found, we will simply
+# defer to native CMake handling.
+find_package(ECM 5.10.0 NO_MODULE)
 
-if (KDE4_FOUND)
-  include(KDE4Defaults)
-  include(MacroLibrary)
-  macro_optional_add_subdirectory(doc)
+if (ECM_FOUND)
+    set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR})
+
+    include(KDEInstallDirs)
+    include(KDECMakeSettings)
+    include(FeatureSummary)
+    include(ECMOptionalAddSubdirectory)
+
+    find_package(KF5 5.10.0 COMPONENTS DocTools)
+
+    if(KF5_DocTools_FOUND)
+        ecm_optional_add_subdirectory(doc)
+    else()
+        message(WARNING "Found ECM, but not KF5::DocTools; documentation will not be built")
+    endif()
 else()
-   set(DATA_INSTALL_DIR  "${CMAKE_INSTALL_PREFIX}/share/apps" CACHE PATH "The parent directory where applications can install their data")
-   set(BIN_INSTALL_DIR   "${CMAKE_INSTALL_PREFIX}/bin"  CACHE PATH "The install dir for executables")
+    message(WARNING "Did not find extra-cmake-modules; documentation will not be built and install paths will be guessed based on CMake settings.")
+    set(DATA_INSTALL_DIR  "${CMAKE_INSTALL_PREFIX}/share/apps" CACHE PATH "The parent directory where applications can install their data")
+    set(BIN_INSTALL_DIR   "${CMAKE_INSTALL_PREFIX}/bin"  CACHE PATH "The install dir for executables")
 endif()
 
 set(KDESRC_BUILD_INSTALL_MODULES TRUE CACHE BOOL "Controls whether to install the modules that make up the script. Leave enabled unless running straight from source")
@@ -72,3 +86,7 @@ endif()
 
 install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/kdesrc-build DESTINATION ${BIN_INSTALL_DIR})
 install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/kdesrc-build-setup DESTINATION ${BIN_INSTALL_DIR})
+
+if (ECM_FOUND)
+    feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
+endif()
diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt
index c7c3fb4..065436b 100644
--- a/doc/CMakeLists.txt
+++ b/doc/CMakeLists.txt
@@ -1,6 +1,6 @@
 ########### install files ###############
-kde4_create_handbook(index.docbook INSTALL_DESTINATION ${HTML_INSTALL_DIR}/en SUBDIR kdesrc-build)
-kde4_create_manpage(man-kdesrc-build.1.docbook 1 INSTALL_DESTINATION ${MAN_INSTALL_DIR})
-kde4_create_manpage(man-kdesrc-build-setup.1.docbook 1 INSTALL_DESTINATION ${MAN_INSTALL_DIR})
+kdoctools_create_handbook(index.docbook INSTALL_DESTINATION ${HTML_INSTALL_DIR}/en SUBDIR kdesrc-build)
+kdoctools_create_manpage(man-kdesrc-build.1.docbook 1 INSTALL_DESTINATION ${MAN_INSTALL_DIR})
+kdoctools_create_manpage(man-kdesrc-build-setup.1.docbook 1 INSTALL_DESTINATION ${MAN_INSTALL_DIR})
 
 install(PROGRAMS kdesrc-build.desktop DESTINATION ${XDG_APPS_INSTALL_DIR})
diff --git a/doc/index.docbook b/doc/index.docbook
index 7cad9cd..6a83d21 100644
--- a/doc/index.docbook
+++ b/doc/index.docbook
@@ -1,8 +1,8 @@
 <?xml version="1.0" ?>
-<!DOCTYPE book PUBLIC "-//KDE//DTD DocBook XML V4.2-Based Variant V1.1//EN" "dtd/kdex.dtd" [
+<!DOCTYPE book PUBLIC "-//KDE//DTD DocBook XML V4.5-Based Variant V1.1//EN" "dtd/kdedbx45.dtd" [
   <!--
     Documentation for kdesrc-build.
-    Copyright (c) 2005-2008, 2010-2015 Michael Pyne <mpyne at kde.org>
+    Copyright (c) 2005-2008, 2010-2016 Michael Pyne <mpyne at kde.org>
 
     Copyright (c) 2005 Carlos Leonhard Woelz <carloswoelz at imap-mail.com>
     Copyright (c) 2009 Burkhard Lück <lueck at hube-lueck.de>
@@ -100,6 +100,7 @@
 <year>2013</year>
 <year>2014</year>
 <year>2015</year>
+<year>2016</year>
 <holder>Michael Pyne</holder>
 </copyright>
 
@@ -110,8 +111,8 @@
 
 <legalnotice>&FDLNotice;</legalnotice>
 
-<date>2015-09-12</date>
-<releaseinfo>15.09</releaseinfo>
+<date>2016-05-02</date>
+<releaseinfo>16.05</releaseinfo>
 
 <abstract>
 <para>&kdesrc-build; is a script which builds and installs &kde; software
@@ -2999,6 +3000,66 @@ doing in debugging mode.
 </para></listitem>
 </varlistentry>
 
+<varlistentry id="cmdline-query">
+<term><parameter>--query</parameter>=<userinput><replaceable>mode</replaceable></userinput></term>
+<listitem><para>
+This command causes &kdesrc-build; to query a parameter of the modules in the
+build list (either passed on the command line or read in from the configuration
+file), outputting the result to screen (one module per line).</para>
+
+<para>This option must be provided with a <quote>query mode</quote>, which should be
+one of the following:</para>
+    <itemizedlist>
+    <listitem><para><option>source-dir</option>, which causes &kdesrc-build; to
+        output the full path to where the module's source code is stored.
+        </para></listitem>
+    <listitem><para><option>build-dir</option>, which causes &kdesrc-build; to
+        output the full path to where the module build process occurs.
+        </para></listitem>
+    <listitem><para><option>install-dir</option>, which causes &kdesrc-build; to
+        output the full path to where the module will be installed.
+        </para></listitem>
+    <listitem><para><option>project-path</option>, which causes &kdesrc-build; to
+        output the location of the module within the hierarchy of KDE source
+        code repositories. See <xref linkend="kde-projects-module-sets"/> for
+        more information on this hierarchy.
+        </para></listitem>
+    <listitem><para><option>branch</option>, which causes &kdesrc-build; to
+        output the resolved git branch that will be used for each module, based
+        on the <link linkend="conf-tag">tag</link>, <link
+        linkend="conf-branch">branch</link> and <link
+        linkend="conf-branch-group">branch-group</link> settings in effect.
+        </para></listitem>
+    <listitem><para>Otherwise, option names that are valid for modules in the
+        <link linkend="conf-options-table">configuration file</link> can be
+        used, the resolved value of which will be listed for each module.
+        </para></listitem>
+    </itemizedlist>
+
+<para>
+If a single module is passed on the command line, then the output is simply the
+value of the parameter being queried. If multiple (or no) modules are passed on
+the command line, then each line is prefixed by the name of the module. Either way,
+&kdesrc-build; stops running once each value is output.
+</para>
+
+<para>This option was added with &kdesrc-build; 16.05.</para>
+
+<informalexample>
+<para>For example, the command <quote><command>kdesrc-build</command>
+    <parameter>--query</parameter>
+    <parameter><replaceable>branch</replaceable></parameter>
+    <parameter><replaceable>kactivities</replaceable></parameter>
+    <parameter><replaceable>kdepim</replaceable></parameter></quote>
+might end up with output like:</para>
+<screen>
+kactivities: master
+kdepim: master
+</screen>
+</informalexample>
+</listitem>
+</varlistentry>
+
 <varlistentry id="cmdline-no-rebuild-on-fail">
 <term><parameter>--no-rebuild-on-fail</parameter></term>
 <listitem><para>
diff --git a/doc/man-kdesrc-build.1.docbook b/doc/man-kdesrc-build.1.docbook
index c65eb45..27745cb 100644
--- a/doc/man-kdesrc-build.1.docbook
+++ b/doc/man-kdesrc-build.1.docbook
@@ -1,11 +1,11 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE refentry PUBLIC "-//KDE//DTD DocBook XML V4.2-Based Variant V1.1//EN" "dtd/kdex.dtd" [
+<!DOCTYPE refentry PUBLIC "-//KDE//DTD DocBook XML V4.5-Based Variant V1.1//EN" "dtd/kdedbx45.dtd" [
 <!ENTITY % English "INCLUDE">
 ]>
 
 <!--
     Man page for kdesrc-build.
-    Copyright (c) 2011, 2014, 2015 Michael Pyne <mpyne at kde.org>
+    Copyright (c) 2011, 2014-2016 Michael Pyne <mpyne at kde.org>
 
     Permission is granted to copy, distribute and/or modify this document under
     the terms of the GNU Free Documentation License, Version 1.2 or any later
@@ -22,13 +22,13 @@
     <email>mpyne at kde.org</email>
     <personblurb><para>Authored man page</para></personblurb>
 </author>
-<date>2015-03-07</date>
+<date>2016-05-02</date>
 </refentryinfo>
 
 <refmeta>
 <refentrytitle><command>kdesrc-build</command></refentrytitle>
 <manvolnum>1</manvolnum>
-<refmiscinfo class="version">1.16</refmiscinfo>
+<refmiscinfo class="version">16.05</refmiscinfo>
 </refmeta>
 
 <refnamediv>
@@ -584,6 +584,74 @@ combining short options into one at this point. (E.g. running
 
 <varlistentry>
 <term>
+<option>--query=<replaceable>mode</replaceable></option>
+</term>
+
+<listitem>
+<para>
+This command causes <command>kdesrc-build</command> to query a parameter of the
+modules in the build list (either passed on the command line or read in from
+the configuration file), outputting the result to screen (one module per line).
+</para>
+
+<para>
+This option must be provided with a <quote>query mode</quote>, which should be
+one of the following:</para>
+    <itemizedlist>
+    <listitem><para><option>source-dir</option>, which causes
+        <command>kdesrc-build</command> to output the full path to where the
+        module's source code is stored.
+        </para></listitem>
+    <listitem><para><option>build-dir</option>, which causes
+        <command>kdesrc-build</command> to output the full path to where the
+        module build process occurs.
+        </para></listitem>
+    <listitem><para><option>install-dir</option>, which causes
+        <command>kdesrc-build</command> to output the full path to where the
+        module will be installed.
+        </para></listitem>
+    <listitem><para><option>project-path</option>, which causes
+        <command>kdesrc-build</command> to output the location of the module
+        within the hierarchy of KDE source code repositories.
+        </para></listitem>
+    <listitem><para><option>branch</option>, which causes
+        <command>kdesrc-build</command> to output the resolved git branch that
+        will be used for each module, based on the <option>tag</option>,
+        <option>branch</option> and <option>branch-group</option> settings in
+        effect.
+        </para></listitem>
+    <listitem><para>Otherwise, option names that are valid for modules in the
+        configuration file can be used, the resolved value of which will be
+        listed for each module.
+        </para></listitem>
+    </itemizedlist>
+
+<para>
+If a single module is passed on the command line, then the output is simply the
+value of the parameter being queried. If multiple (or no) modules are passed on
+the command line, then each line is prefixed by the name of the module. Either
+way, <command>kdesrc-build</command> stops running once each value is output.
+</para>
+
+<para>This option was added with <command>kdesrc-build</command> 16.05.</para>
+
+<informalexample>
+<para>For example, the command <quote><command>kdesrc-build</command>
+    <parameter>--query</parameter>
+    <parameter><replaceable>branch</replaceable></parameter>
+    <parameter><replaceable>kactivities</replaceable></parameter>
+    <parameter><replaceable>kdepim</replaceable></parameter></quote>
+might end up with output like:</para>
+<screen>
+kactivities: master
+kdepim: master
+</screen>
+</informalexample>
+</listitem>
+</varlistentry>
+
+<varlistentry>
+<term>
 <option>--print-modules</option>
 </term>
 
diff --git a/modules/ksb/Application.pm b/modules/ksb/Application.pm
index d10dec5..b5bab5a 100644
--- a/modules/ksb/Application.pm
+++ b/modules/ksb/Application.pm
@@ -203,6 +203,21 @@ DONE
             $foundOptions{kdedir} = $arg; #TODO: Still needed for compat?
             $foundOptions{reconfigure} = 1;
         },
+        query => sub {
+            my (undef, $arg) = @_;
+
+            my $validMode = qr/^[a-zA-Z0-9_][a-zA-Z0-9_-]*$/;
+            die("Invalid query mode $arg")
+                unless $arg =~ $validMode;
+
+            # Add useful aliases
+            $arg = 'source-dir'  if $arg =~ /^src-?dir$/;
+            $arg = 'build-dir'   if $arg =~ /^build-?dir$/;
+            $arg = 'install-dir' if $arg eq 'prefix';
+
+            $self->{run_mode} = 'query';
+            $auxOptions{query} = $arg;
+        },
         pretend => sub {
             # Set pretend mode but also force the build process to run.
             $auxOptions{pretend} = 1;
@@ -263,7 +278,7 @@ DONE
     }
 
     # Actually read the options.
-    GetOptionsFromArray(\@options, \%foundOptions,
+    my $optsSuccess = GetOptionsFromArray(\@options, \%foundOptions,
         'version', 'author', 'help', 'disable-snapshots|no-snapshots',
         'install', 'uninstall', 'no-src|no-svn', 'no-install', 'no-build',
         'no-tests', 'build-when-unchanged|force-build', 'no-metadata',
@@ -272,7 +287,7 @@ DONE
         'src-only|svn-only', 'build-only', 'install-only', 'build-system-only',
         'rc-file=s', 'prefix=s', 'niceness|nice:10', 'ignore-modules=s{,}',
         'print-modules', 'pretend|dry-run|p', 'refresh-build',
-        'start-program|run=s{,}',
+        'query=s', 'start-program|run=s{,}',
         'revision=i', 'resume-from=s', 'resume-after=s',
         'rebuild-failures', 'resume', 'stop-on-failure',
         'stop-after=s', 'stop-before=s', 'set-module-option-value=s',
@@ -288,6 +303,10 @@ DONE
         '<>', # Required to read non-option args
         );
 
+    if (!$optsSuccess) {
+        croak_runtime("Error reading command-line options.");
+    }
+
     $pendingOptionsRef->{'global'} //= { };
 
     # To store the values we found, need to strip out the values that are
@@ -383,8 +402,7 @@ sub generateModuleList
     # Check if we're supposed to drop into an interactive shell instead.  If so,
     # here's the stop off point.
 
-    if (@startProgramAndArgs)
-    {
+    if (@startProgramAndArgs) {
         $ctx->setupEnvironment(); # Read options from set-env
         $ctx->commitEnvironmentChanges(); # Apply env options to environment
         _executeCommandLineProgram(@startProgramAndArgs); # noreturn
@@ -584,13 +602,34 @@ sub runAllModulePhases
     $ctx->addModule($_) foreach @modules;
 
     my $runMode = $self->runMode();
-    my $result;
 
-    my @update_list = map { $_->name() } ($ctx->modulesInPhase('update'));
-    my @build_list = map { $_->name() } ($ctx->modulesInPhase('build'));
+    if ($runMode eq 'query') {
+        my $queryMode = $ctx->getOption('query', 'module');
+
+        # Default to ->getOption as query method.
+        # $_[0] is short name for first param.
+        my $query = sub { $_[0]->getOption($queryMode) };
+        $query = sub { $_[0]->fullpath('source') } if $queryMode eq 'source-dir';
+        $query = sub { $_[0]->fullpath('build') }  if $queryMode eq 'build-dir';
+        $query = sub { $_[0]->installationPath() } if $queryMode eq 'install-dir';
+        $query = sub { $_[0]->fullProjectPath() }  if $queryMode eq 'project-path';
+        $query = sub { ($_[0]->scm()->_determinePreferredCheckoutSource())[0] // '' }
+            if $queryMode eq 'branch';
+
+        if (@modules == 1) {
+            # No leading module name, just the value
+            say $query->($modules[0]);
+        }
+        else {
+            for my $m (@modules) {
+                say "$m: ", $query->($m);
+            }
+        }
 
-    debug ("Update list is ", join (', ', @update_list));
-    debug ("Build list is ", join (', ', @build_list));
+        return 0;
+    }
+
+    my $result;
 
     if ($runMode eq 'build')
     {


More information about the kde-doc-english mailing list