Improve application manangement and create desktop entries for available app

This commit is contained in:
Simon Fels 2016-12-02 16:11:38 +01:00
commit 00aadb5467
45 changed files with 1435 additions and 249 deletions

View file

@ -1,3 +1,4 @@
add_subdirectory(bubblewrap)
add_subdirectory(process-cpp-minimal)
add_subdirectory(android-emugl)
add_subdirectory(xdg)

24
external/xdg/CMakeLists.txt vendored Normal file
View file

@ -0,0 +1,24 @@
# We have to manually alter the cxx flags to have a working
# travis-ci build. Its container-based infrastructure only features
# a very old cmake that does not support the more current:
# set_property(TARGET xdg_test PROPERTY CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
find_package(Boost COMPONENTS filesystem system unit_test_framework)
include_directories(
.
${Boost_INCLUDE_DIRS}
)
add_library(xdg xdg.cpp)
set_property(TARGET xdg PROPERTY CXX_STANDARD 11)
target_link_libraries(xdg ${Boost_LIBRARIES})
enable_testing()
add_definitions(-DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN -DBOOST_TEST_MODULE=xdg)
add_executable(xdg_test xdg_test.cpp)
set_property(TARGET xdg_test PROPERTY CXX_STANDARD 11)
target_link_libraries(xdg_test xdg)
add_test(xdg_test xdg_test)

166
external/xdg/LICENSE vendored Normal file
View file

@ -0,0 +1,166 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.

203
external/xdg/xdg.cpp vendored Normal file
View file

@ -0,0 +1,203 @@
// Copyright (C) 2015 Thomas Voß <thomas.voss.bochum@gmail.com>
//
// This library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <xdg.h>
#include <boost/algorithm/string.hpp>
#include <cstdlib>
#include <stdexcept>
namespace fs = boost::filesystem;
namespace
{
fs::path throw_if_not_absolute(const fs::path& p)
{
if (p.has_root_directory())
return p;
throw std::runtime_error{"Directores MUST be absolute."};
}
namespace env
{
std::string get(const std::string& key, const std::string& default_value)
{
if (auto value = std::getenv(key.c_str()))
return value;
return default_value;
}
std::string get_or_throw(const std::string& key)
{
if (auto value = std::getenv(key.c_str()))
{
return value;
}
throw std::runtime_error{key + " not set in environment"};
}
constexpr const char* xdg_data_home{"XDG_DATA_HOME"};
constexpr const char* xdg_data_dirs{"XDG_DATA_DIRS"};
constexpr const char* xdg_config_home{"XDG_CONFIG_HOME"};
constexpr const char* xdg_config_dirs{"XDG_CONFIG_DIRS"};
constexpr const char* xdg_cache_home{"XDG_CACHE_HOME"};
constexpr const char* xdg_runtime_dir{"XDG_RUNTIME_DIR"};
}
namespace impl
{
class BaseDirSpecification : public xdg::BaseDirSpecification
{
public:
static const BaseDirSpecification& instance()
{
static const BaseDirSpecification spec;
return spec;
}
BaseDirSpecification()
{
}
const xdg::Data& data() const override
{
return data_;
}
const xdg::Config& config() const override
{
return config_;
}
const xdg::Cache& cache() const override
{
return cache_;
}
const xdg::Runtime& runtime() const override
{
return runtime_;
}
private:
xdg::Data data_;
xdg::Config config_;
xdg::Cache cache_;
xdg::Runtime runtime_;
};
}
}
fs::path xdg::Data::home() const
{
auto v = env::get(env::xdg_data_home, "");
if (v.empty())
return throw_if_not_absolute(fs::path{env::get_or_throw("HOME")} / ".local" / "share");
return throw_if_not_absolute(fs::path(v));
}
std::vector<fs::path> xdg::Data::dirs() const
{
auto v = env::get(env::xdg_data_dirs, "");
if (v.empty())
return {fs::path{"/usr/local/share"}, fs::path{"/usr/share"}};
std::vector<std::string> tokens;
tokens = boost::split(tokens, v, boost::is_any_of(":"));
std::vector<fs::path> result;
for (const auto& token : tokens)
{
result.push_back(throw_if_not_absolute(fs::path(token)));
}
return result;
}
fs::path xdg::Config::home() const
{
auto v = env::get(env::xdg_config_home, "");
if (v.empty())
return throw_if_not_absolute(fs::path{env::get_or_throw("HOME")} / ".config");
return throw_if_not_absolute(fs::path(v));
}
std::vector<fs::path> xdg::Config::dirs() const
{
auto v = env::get(env::xdg_config_dirs, "");
if (v.empty())
return {fs::path{"/etc/xdg"}};
std::vector<std::string> tokens;
tokens = boost::split(tokens, v, boost::is_any_of(":"));
std::vector<fs::path> result;
for (const auto& token : tokens)
{
fs::path p(token);
result.push_back(throw_if_not_absolute(p));
}
return result;
}
fs::path xdg::Cache::home() const
{
auto v = env::get(env::xdg_cache_home, "");
if (v.empty())
return throw_if_not_absolute(fs::path{env::get_or_throw("HOME")} / ".cache");
return throw_if_not_absolute(fs::path(v));
}
fs::path xdg::Runtime::dir() const
{
auto v = env::get(env::xdg_config_home, "");
if (v.empty())
{
// We do not fall back gracefully and instead throw, dispatching to calling
// code for handling the case of a safe user-specfic runtime directory missing.
throw std::runtime_error{"Runtime directory not set"};
}
return throw_if_not_absolute(fs::path(v));
}
std::shared_ptr<xdg::BaseDirSpecification> xdg::BaseDirSpecification::create()
{
return std::make_shared<impl::BaseDirSpecification>();
}
const xdg::Data& xdg::data()
{
return impl::BaseDirSpecification::instance().data();
}
const xdg::Config& xdg::config()
{
return impl::BaseDirSpecification::instance().config();
}
const xdg::Cache& xdg::cache()
{
return impl::BaseDirSpecification::instance().cache();
}
const xdg::Runtime& xdg::runtime()
{
return impl::BaseDirSpecification::instance().runtime();
}

118
external/xdg/xdg.h vendored Normal file
View file

@ -0,0 +1,118 @@
// Copyright (C) 2015 Thomas Voß <thomas.voss.bochum@gmail.com>
//
// This library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef XDG_H_
#define XDG_H_
#include <boost/filesystem.hpp>
#include <string>
#include <vector>
namespace xdg
{
// NotCopyable deletes the copy c'tor and the assignment operator.
struct NotCopyable
{
NotCopyable() = default;
NotCopyable(const NotCopyable&) = delete;
virtual ~NotCopyable() = default;
NotCopyable& operator=(const NotCopyable&) = delete;
};
// NotMoveable deletes the move c'tor and the move assignment operator.
struct NotMoveable
{
NotMoveable() = default;
NotMoveable(NotMoveable&&) = delete;
virtual ~NotMoveable() = default;
NotMoveable& operator=(NotMoveable&&) = delete;
};
// Data provides functions to query the XDG_DATA_* entries.
class Data : NotCopyable, NotMoveable
{
public:
// home returns the base directory relative to which user specific
// data files should be stored.
virtual boost::filesystem::path home() const;
// dirs returns the preference-ordered set of base directories to
// search for data files in addition to the $XDG_DATA_HOME base
// directory.
virtual std::vector<boost::filesystem::path> dirs() const;
};
// Config provides functions to query the XDG_CONFIG_* entries.
class Config : NotCopyable, NotMoveable
{
public:
// home returns the base directory relative to which user specific
// configuration files should be stored.
virtual boost::filesystem::path home() const;
// dirs returns the preference-ordered set of base directories to
// search for configuration files in addition to the
// $XDG_CONFIG_HOME base directory.
virtual std::vector<boost::filesystem::path> dirs() const;
};
// Cache provides functions to query the XDG_CACHE_HOME entry.
class Cache : NotCopyable, NotMoveable
{
public:
// home returns the base directory relative to which user specific
// non-essential data files should be stored.
virtual boost::filesystem::path home() const;
};
// Runtime provides functions to query the XDG_RUNTIME_DIR entry.
class Runtime : NotCopyable, NotMoveable
{
public:
// home returns the base directory relative to which user-specific
// non-essential runtime files and other file objects (such as
// sockets, named pipes, ...) should be stored.
virtual boost::filesystem::path dir() const;
};
// A BaseDirSpecification implements the XDG base dir specification:
// http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
class BaseDirSpecification : NotCopyable, NotMoveable
{
public:
// create returns an Implementation of BaseDirSpecification.
static std::shared_ptr<BaseDirSpecification> create();
// data returns an immutable Data instance.
virtual const Data& data() const = 0;
// config returns an immutable Config instance.
virtual const Config& config() const = 0;
// cache returns an immutable Cache instance.
virtual const Cache& cache() const = 0;
// runtime returns an immutable Runtime instance.
virtual const Runtime& runtime() const = 0;
protected:
BaseDirSpecification() = default;
};
// data returns an immutable reference to a Data instance.
const Data& data();
// config returns an immutable reference to a Config instance.
const Config& config();
// cache returns an immutable reference to a Cache instance.
const Cache& cache();
// runtime returns an immutable reference to a Runtime instance.
const Runtime& runtime();
}
#endif // XDG_H_

130
external/xdg/xdg_test.cpp vendored Normal file
View file

@ -0,0 +1,130 @@
// Copyright (C) 2015 Thomas Voß <thomas.voss.bochum@gmail.com>
//
// This library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <xdg.h>
#include <boost/test/unit_test.hpp>
#include <cstdlib>
#include <iostream>
BOOST_AUTO_TEST_CASE(XdgDataHomeThrowsForRelativeDirectoryFromEnv)
{
::setenv("XDG_DATA_HOME", "tmp", 1);
BOOST_CHECK_THROW(xdg::BaseDirSpecification::create()->data().home(), std::runtime_error);
BOOST_CHECK_THROW(xdg::data().home(), std::runtime_error);
}
BOOST_AUTO_TEST_CASE(XdgDataHomeReturnsDefaultValueForEmptyEnv)
{
::setenv("HOME", "/tmp", 1);
::setenv("XDG_DATA_HOME", "", 1);
BOOST_CHECK_EQUAL("/tmp/.local/share", xdg::BaseDirSpecification::create()->data().home());
BOOST_CHECK_EQUAL("/tmp/.local/share", xdg::data().home());
}
BOOST_AUTO_TEST_CASE(XdgDataDirsCorrectlyTokenizesEnv)
{
::setenv("XDG_DATA_DIRS", "/tmp:/tmp", 1);
BOOST_CHECK(2 == xdg::BaseDirSpecification::create()->data().dirs().size());
BOOST_CHECK(2 == xdg::data().dirs().size());
}
BOOST_AUTO_TEST_CASE(XdgDataDirsThrowsForRelativeDirectoryFromEnv)
{
::setenv("XDG_DATA_DIRS", "/tmp:tmp", 1);
BOOST_CHECK_THROW(xdg::BaseDirSpecification::create()->data().dirs(), std::runtime_error);
BOOST_CHECK_THROW(xdg::data().dirs(), std::runtime_error);
}
BOOST_AUTO_TEST_CASE(XdgDataDirsReturnsDefaultValueForEmptyEnv)
{
::setenv("XDG_DATA_DIRS", "", 1);
auto dirs = xdg::data().dirs();
BOOST_CHECK_EQUAL("/usr/local/share", dirs[0]);
BOOST_CHECK_EQUAL("/usr/share", dirs[1]);
dirs = xdg::BaseDirSpecification::create()->data().dirs();
BOOST_CHECK_EQUAL("/usr/local/share", dirs[0]);
BOOST_CHECK_EQUAL("/usr/share", dirs[1]);
}
BOOST_AUTO_TEST_CASE(XdgConfigHomeThrowsForRelativeDirectoryFromEnv)
{
::setenv("XDG_CONFIG_HOME", "tmp", 1);
BOOST_CHECK_THROW(xdg::BaseDirSpecification::create()->config().home(), std::runtime_error);
BOOST_CHECK_THROW(xdg::config().home(), std::runtime_error);
}
BOOST_AUTO_TEST_CASE(XdgConfigHomeReturnsDefaultValueForEmptyEnv)
{
::setenv("HOME", "/tmp", 1);
::setenv("XDG_CONFIG_HOME", "", 1);
BOOST_CHECK_EQUAL("/tmp/.config", xdg::BaseDirSpecification::create()->config().home());
BOOST_CHECK_EQUAL("/tmp/.config", xdg::config().home());
}
BOOST_AUTO_TEST_CASE(XdgConfigDirsCorrectlyTokenizesEnv)
{
::setenv("XDG_CONFIG_DIRS", "/tmp:/tmp", 1);
BOOST_CHECK(2 == xdg::BaseDirSpecification::create()->config().dirs().size());
BOOST_CHECK(2 == xdg::config().dirs().size());
}
BOOST_AUTO_TEST_CASE(XdgConfigDirsThrowsForRelativeDirectoryFromEnv)
{
::setenv("XDG_CONFIG_DIRS", "/tmp:tmp", 1);
BOOST_CHECK_THROW(xdg::BaseDirSpecification::create()->config().dirs(), std::runtime_error);
BOOST_CHECK_THROW(xdg::config().dirs(), std::runtime_error);
}
BOOST_AUTO_TEST_CASE(XdgConfigDirsReturnsDefaultValueForEmptyEnv)
{
::setenv("XDG_CONFIG_DIRS", "", 1);
auto dirs = xdg::config().dirs();
BOOST_CHECK_EQUAL("/etc/xdg", dirs[0]);
dirs = xdg::BaseDirSpecification::create()->config().dirs();
BOOST_CHECK_EQUAL("/etc/xdg", dirs[0]);
}
BOOST_AUTO_TEST_CASE(XdgCacheHomeThrowsForRelativeDirectoryFromEnv)
{
::setenv("XDG_CACHE_HOME", "tmp", 1);
BOOST_CHECK_THROW(xdg::BaseDirSpecification::create()->cache().home(), std::runtime_error);
BOOST_CHECK_THROW(xdg::cache().home(), std::runtime_error);
}
BOOST_AUTO_TEST_CASE(XdgCacheHomeReturnsDefaultValueForEmptyEnv)
{
::setenv("HOME", "/tmp", 1);
::setenv("XDG_CACHE_HOME", "", 1);
BOOST_CHECK_EQUAL("/tmp/.cache", xdg::BaseDirSpecification::create()->cache().home());
BOOST_CHECK_EQUAL("/tmp/.cache", xdg::cache().home());
}
BOOST_AUTO_TEST_CASE(XdgRuntimeDirThrowsForRelativeDirectoryFromEnv)
{
::setenv("XDG_RUNTIME_DIR", "tmp", 1);
BOOST_CHECK_THROW(xdg::BaseDirSpecification::create()->runtime().dir(), std::runtime_error);
BOOST_CHECK_THROW(xdg::runtime().dir(), std::runtime_error);
}
BOOST_AUTO_TEST_CASE(XdgRuntimeDirThrowsForEmptyEnv)
{
::setenv("XDG_RUNTIME_DIR", "", 1);
BOOST_CHECK_THROW(xdg::BaseDirSpecification::create()->runtime().dir(), std::runtime_error);
BOOST_CHECK_THROW(xdg::runtime().dir(), std::runtime_error);
}