From 7a8f1efab92ac4ddd336870cb098c85647e9e6b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=8C=AF=E5=8D=8E=20=28WANG=20Zhenhua=29?= Date: Fri, 25 Aug 2017 13:56:11 +0800 Subject: [PATCH 1/3] Compatible resource directory determination Previously, the resource directory is generated from `SNAP` if set, `/usr/share/anbox` is used otherwise. This cannot work with binaries installed via `make install` since the loading screen is mostly at `/usr/local/share/anbox/ui/loading-screen.png`. With this patch, anbox can get correct resource directory when it's installed without snap. --- src/anbox/cmds/launch.cpp | 6 ------ src/anbox/config.cpp | 25 +++++++++++++++++++++---- src/anbox/config.h | 7 +++---- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/anbox/cmds/launch.cpp b/src/anbox/cmds/launch.cpp index 7762af3..77a84eb 100644 --- a/src/anbox/cmds/launch.cpp +++ b/src/anbox/cmds/launch.cpp @@ -119,12 +119,6 @@ anbox::cmds::Launch::Launch() auto bus = std::make_shared(bus_type); bus->install_executor(core::dbus::asio::make_executor(bus, rt->service())); - const auto snap_path = utils::get_env_value("SNAP"); - if (!snap_path.empty()) { - const auto resource_path = fs::path(snap_path) / "usr" / "share" / "anbox"; - SystemConfiguration::instance().set_resource_path(resource_path); - } - std::shared_ptr ss; // Instead of relying on the user session init system to start our diff --git a/src/anbox/config.cpp b/src/anbox/config.cpp index a13aa43..eb3d185 100644 --- a/src/anbox/config.cpp +++ b/src/anbox/config.cpp @@ -41,10 +41,6 @@ void anbox::SystemConfiguration::set_data_path(const std::string &path) { data_path = path; } -void anbox::SystemConfiguration::set_resource_path(const fs::path &path) { - resource_path = path; -} - fs::path anbox::SystemConfiguration::data_dir() const { return data_path; } @@ -88,3 +84,24 @@ anbox::SystemConfiguration& anbox::SystemConfiguration::instance() { static SystemConfiguration config; return config; } + +anbox::SystemConfiguration::SystemConfiguration() { + auto gen_resource_path = [] () -> fs::path { + const auto snap_path = utils::get_env_value("SNAP"); + if (!snap_path.empty()) { + return fs::path(snap_path) / "usr/share/anbox"; + } + + const std::string exe = utils::process_get_exe_path(::getpid()); + const std::size_t pos = exe.rfind("/bin/anbox"); + if (pos != std::string::npos) { + const std::string leading_path = exe.substr(0, pos); + return fs::path(leading_path) / "share/anbox"; + } else { + return "/usr/local/share/anbox"; + } + }; + + resource_path = gen_resource_path(); + data_path = "/var/local/lib/anbox"; +} diff --git a/src/anbox/config.h b/src/anbox/config.h index 0fce571..c6b88da 100644 --- a/src/anbox/config.h +++ b/src/anbox/config.h @@ -31,7 +31,6 @@ class SystemConfiguration { virtual ~SystemConfiguration() = default; void set_data_path(const std::string &path); - void set_resource_path(const boost::filesystem::path &path); boost::filesystem::path data_dir() const; std::string rootfs_dir() const; @@ -44,10 +43,10 @@ class SystemConfiguration { std::string resource_dir() const; protected: - SystemConfiguration() = default; + SystemConfiguration(); - boost::filesystem::path data_path = "/var/lib/anbox"; - boost::filesystem::path resource_path = "/usr/share/anbox"; + boost::filesystem::path data_path; + boost::filesystem::path resource_path; }; } // namespace anbox From 202b556bea678db31d5b828b7e769ae264238ae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=8C=AF=E5=8D=8E=20=28WANG=20Zhenhua=29?= Date: Mon, 28 Aug 2017 10:06:57 +0800 Subject: [PATCH 2/3] Configure default resource and data directories from CMake As anbox is expected to installed in two ways (`snap` or `make install`), it should be enough to get `snap` ENV or configure by cmake. --- .gitignore | 4 ++++ CMakeLists.txt | 8 +++++++- src/anbox/config.cpp | 11 ++--------- src/anbox/{config.h => config.h.in} | 4 ++++ 4 files changed, 17 insertions(+), 10 deletions(-) rename src/anbox/{config.h => config.h.in} (89%) diff --git a/.gitignore b/.gitignore index f3b4966..bc7082a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,8 @@ build*/ parts/ stage/ prime/ +snap/ +android-images/ *.snap CMakeLists.txt.user *.o.cmd @@ -14,6 +16,8 @@ CMakeLists.txt.user modules.order .tmp_versions .idea +src/anbox/config.h + debian/anbox-modules-dkms.debhelper.log debian/anbox-modules-dkms.substvars diff --git a/CMakeLists.txt b/CMakeLists.txt index 71aa61d..e613b1e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,6 +108,12 @@ endif() configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/anbox/build/version.h.in ${CMAKE_CURRENT_SOURCE_DIR}/src/anbox/build/version.h) +set(ANBOX_RESOURCE_DIR "${CMAKE_INSTALL_DATADIR}/anbox") +set(ANBOX_RESOURCE_DIR_FULL "${CMAKE_INSTALL_FULL_DATADIR}/anbox") +set(ANBOX_STATEDIR_FULL "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/anbox") +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/anbox/config.h.in + ${CMAKE_CURRENT_SOURCE_DIR}/src/anbox/config.h) + add_subdirectory(external) add_subdirectory(src) add_subdirectory(tests) @@ -118,7 +124,7 @@ if (NOT "${HOST_CMAKE_C_COMPILER}" STREQUAL "") message(STATUS "Host C compiler: ${HOST_CMAKE_CXX_COMPILER}") endif() -install(FILES data/ui/loading-screen.png DESTINATION share/anbox/ui) +install(FILES data/ui/loading-screen.png DESTINATION ${ANBOX_RESOURCE_DIR}/ui) # uninstall target configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" diff --git a/src/anbox/config.cpp b/src/anbox/config.cpp index eb3d185..a1725e2 100644 --- a/src/anbox/config.cpp +++ b/src/anbox/config.cpp @@ -90,18 +90,11 @@ anbox::SystemConfiguration::SystemConfiguration() { const auto snap_path = utils::get_env_value("SNAP"); if (!snap_path.empty()) { return fs::path(snap_path) / "usr/share/anbox"; - } - - const std::string exe = utils::process_get_exe_path(::getpid()); - const std::size_t pos = exe.rfind("/bin/anbox"); - if (pos != std::string::npos) { - const std::string leading_path = exe.substr(0, pos); - return fs::path(leading_path) / "share/anbox"; } else { - return "/usr/local/share/anbox"; + return default_resource_path; } }; resource_path = gen_resource_path(); - data_path = "/var/local/lib/anbox"; + data_path = default_path_path; } diff --git a/src/anbox/config.h b/src/anbox/config.h.in similarity index 89% rename from src/anbox/config.h rename to src/anbox/config.h.in index c6b88da..26f07de 100644 --- a/src/anbox/config.h +++ b/src/anbox/config.h.in @@ -48,6 +48,10 @@ class SystemConfiguration { boost::filesystem::path data_path; boost::filesystem::path resource_path; + private: + static constexpr const char *default_resource_path{"@ANBOX_RESOURCE_DIR_FULL@"}; + static constexpr const char *default_path_path{"@ANBOX_STATEDIR_FULL@"}; + }; } // namespace anbox From f203a750105f5ce435d38d84c7e16cc298b49b64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=8C=AF=E5=8D=8E=20=28WANG=20Zhenhua=29?= Date: Mon, 28 Aug 2017 14:55:46 +0800 Subject: [PATCH 3/3] Merge cmake configured headers into one config.h.in This looks better than leave cmake *.in everywhere in the tree. Also fix typo according to review comments of PR 425. --- .gitignore | 1 - CMakeLists.txt | 7 ++----- src/CMakeLists.txt | 4 ++-- src/anbox/application/database.cpp | 2 +- src/anbox/audio/server.cpp | 2 +- src/anbox/bridge/android_api_stub.cpp | 2 +- src/anbox/build/{version.h.in => config.h.in} | 10 +++++++--- src/anbox/cmds/container_manager.cpp | 2 +- src/anbox/cmds/launch.cpp | 2 +- src/anbox/cmds/session_manager.cpp | 2 +- src/anbox/cmds/system_info.cpp | 2 +- src/anbox/cmds/version.cpp | 2 +- src/anbox/container/client.cpp | 2 +- src/anbox/container/lxc_container.cpp | 2 +- src/anbox/container/service.cpp | 2 +- src/anbox/daemon.cpp | 2 +- src/anbox/input/manager.cpp | 2 +- src/anbox/{config.cpp => system_configuration.cpp} | 13 +++++++------ src/anbox/{config.h.in => system_configuration.h} | 11 +++-------- src/anbox/ui/splash_screen.cpp | 2 +- 20 files changed, 35 insertions(+), 39 deletions(-) rename src/anbox/build/{version.h.in => config.h.in} (77%) rename src/anbox/{config.cpp => system_configuration.cpp} (88%) rename src/anbox/{config.h.in => system_configuration.h} (86%) diff --git a/.gitignore b/.gitignore index bc7082a..a9b4b45 100644 --- a/.gitignore +++ b/.gitignore @@ -16,7 +16,6 @@ CMakeLists.txt.user modules.order .tmp_versions .idea -src/anbox/config.h debian/anbox-modules-dkms.debhelper.log diff --git a/CMakeLists.txt b/CMakeLists.txt index e613b1e..0be25f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,14 +105,11 @@ endif() if (ANBOX_VERSION_SUFFIX) set(ANBOX_VERSION "${ANBOX_VERSION}-${ANBOX_VERSION_SUFFIX}") endif() -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/anbox/build/version.h.in - ${CMAKE_CURRENT_SOURCE_DIR}/src/anbox/build/version.h) - set(ANBOX_RESOURCE_DIR "${CMAKE_INSTALL_DATADIR}/anbox") set(ANBOX_RESOURCE_DIR_FULL "${CMAKE_INSTALL_FULL_DATADIR}/anbox") set(ANBOX_STATEDIR_FULL "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/anbox") -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/anbox/config.h.in - ${CMAKE_CURRENT_SOURCE_DIR}/src/anbox/config.h) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/anbox/build/config.h.in + ${CMAKE_CURRENT_SOURCE_DIR}/src/anbox/build/config.h) add_subdirectory(external) add_subdirectory(src) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cfa9e9f..bca9db8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -60,10 +60,10 @@ set(SOURCES anbox/cli.cpp anbox/runtime.cpp anbox/daemon.cpp - anbox/config.cpp + anbox/system_configuration.cpp anbox/not_reachable.cpp - anbox/build/version.h.in + anbox/build/config.h.in anbox/android/intent.cpp anbox/android/ip_config_builder.cpp diff --git a/src/anbox/application/database.cpp b/src/anbox/application/database.cpp index 6010cf5..c3b2468 100644 --- a/src/anbox/application/database.cpp +++ b/src/anbox/application/database.cpp @@ -17,7 +17,7 @@ #include "anbox/application/database.h" #include "anbox/application/launcher_storage.h" -#include "anbox/config.h" +#include "anbox/system_configuration.h" #include "anbox/logger.h" namespace anbox { diff --git a/src/anbox/audio/server.cpp b/src/anbox/audio/server.cpp index 02f3415..ad13968 100644 --- a/src/anbox/audio/server.cpp +++ b/src/anbox/audio/server.cpp @@ -22,7 +22,7 @@ #include "anbox/network/local_socket_messenger.h" #include "anbox/network/message_processor.h" #include "anbox/common/type_traits.h" -#include "anbox/config.h" +#include "anbox/system_configuration.h" #include "anbox/utils.h" #include "anbox/logger.h" diff --git a/src/anbox/bridge/android_api_stub.cpp b/src/anbox/bridge/android_api_stub.cpp index e08eb30..5010933 100644 --- a/src/anbox/bridge/android_api_stub.cpp +++ b/src/anbox/bridge/android_api_stub.cpp @@ -16,7 +16,7 @@ */ #include "anbox/bridge/android_api_stub.h" -#include "anbox/config.h" +#include "anbox/system_configuration.h" #include "anbox/logger.h" #include "anbox/rpc/channel.h" #include "anbox/utils.h" diff --git a/src/anbox/build/version.h.in b/src/anbox/build/config.h.in similarity index 77% rename from src/anbox/build/version.h.in rename to src/anbox/build/config.h.in index 14c5397..01b7e83 100644 --- a/src/anbox/build/version.h.in +++ b/src/anbox/build/config.h.in @@ -17,8 +17,8 @@ * */ -#ifndef ANBOX_VERSION_H_ -#define ANBOX_VERSION_H_ +#ifndef ANBOX_CONFIG_H_ +#define ANBOX_CONFIG_H_ #include #include @@ -27,7 +27,11 @@ namespace anbox { namespace build { /// @brief version marks the version static constexpr const char *version{"@ANBOX_VERSION@"}; + +// path for system configuration +static constexpr const char *default_resource_path{"@ANBOX_RESOURCE_DIR_FULL@"}; +static constexpr const char *default_data_path{"@ANBOX_STATEDIR_FULL@"}; } // namespace build } // namespace anbox -#endif // ANBOX_VERSION_H_ +#endif // ANBOX_CONFIG_H_ diff --git a/src/anbox/cmds/container_manager.cpp b/src/anbox/cmds/container_manager.cpp index 3356fd7..cac3390 100644 --- a/src/anbox/cmds/container_manager.cpp +++ b/src/anbox/cmds/container_manager.cpp @@ -20,7 +20,7 @@ #include "anbox/common/loop_device_allocator.h" #include "anbox/logger.h" #include "anbox/runtime.h" -#include "anbox/config.h" +#include "anbox/system_configuration.h" #include "core/posix/signal.h" #include "core/posix/exec.h" diff --git a/src/anbox/cmds/launch.cpp b/src/anbox/cmds/launch.cpp index 77a84eb..e5cc5a9 100644 --- a/src/anbox/cmds/launch.cpp +++ b/src/anbox/cmds/launch.cpp @@ -20,7 +20,7 @@ #include "anbox/dbus/stub/application_manager.h" #include "anbox/common/dispatcher.h" #include "anbox/ui/splash_screen.h" -#include "anbox/config.h" +#include "anbox/system_configuration.h" #include "anbox/runtime.h" #include "anbox/logger.h" diff --git a/src/anbox/cmds/session_manager.cpp b/src/anbox/cmds/session_manager.cpp index 4eaf5ac..4988967 100644 --- a/src/anbox/cmds/session_manager.cpp +++ b/src/anbox/cmds/session_manager.cpp @@ -35,7 +35,7 @@ std::istream& operator>>(std::istream& in, anbox::graphics::GLRendererServer::Co #include "anbox/cmds/session_manager.h" #include "anbox/common/dispatcher.h" -#include "anbox/config.h" +#include "anbox/system_configuration.h" #include "anbox/container/client.h" #include "anbox/dbus/skeleton/service.h" #include "anbox/input/manager.h" diff --git a/src/anbox/cmds/system_info.cpp b/src/anbox/cmds/system_info.cpp index 051f3ce..83848c7 100644 --- a/src/anbox/cmds/system_info.cpp +++ b/src/anbox/cmds/system_info.cpp @@ -21,7 +21,7 @@ #include "anbox/utils/environment_file.h" #include "anbox/logger.h" -#include "anbox/build/version.h" +#include "anbox/build/config.h" #include #include diff --git a/src/anbox/cmds/version.cpp b/src/anbox/cmds/version.cpp index 6fea8f9..d63ddf9 100644 --- a/src/anbox/cmds/version.cpp +++ b/src/anbox/cmds/version.cpp @@ -18,7 +18,7 @@ */ #include "anbox/cmds/version.h" -#include "anbox/build/version.h" +#include "anbox/build/config.h" #include "anbox/utils.h" anbox::cmds::Version::Version() diff --git a/src/anbox/container/client.cpp b/src/anbox/container/client.cpp index bfbbf3e..99251e2 100644 --- a/src/anbox/container/client.cpp +++ b/src/anbox/container/client.cpp @@ -16,7 +16,7 @@ */ #include "anbox/container/client.h" -#include "anbox/config.h" +#include "anbox/system_configuration.h" #include "anbox/container/management_api_stub.h" #include "anbox/logger.h" #include "anbox/network/local_socket_messenger.h" diff --git a/src/anbox/container/lxc_container.cpp b/src/anbox/container/lxc_container.cpp index a2e0705..962832b 100644 --- a/src/anbox/container/lxc_container.cpp +++ b/src/anbox/container/lxc_container.cpp @@ -17,7 +17,7 @@ #include "anbox/android/ip_config_builder.h" #include "anbox/container/lxc_container.h" -#include "anbox/config.h" +#include "anbox/system_configuration.h" #include "anbox/logger.h" #include "anbox/utils.h" diff --git a/src/anbox/container/service.cpp b/src/anbox/container/service.cpp index 15d90e2..b84d7db 100644 --- a/src/anbox/container/service.cpp +++ b/src/anbox/container/service.cpp @@ -16,7 +16,7 @@ */ #include "anbox/container/service.h" -#include "anbox/config.h" +#include "anbox/system_configuration.h" #include "anbox/container/lxc_container.h" #include "anbox/container/management_api_message_processor.h" #include "anbox/container/management_api_skeleton.h" diff --git a/src/anbox/daemon.cpp b/src/anbox/daemon.cpp index a40da89..806503d 100644 --- a/src/anbox/daemon.cpp +++ b/src/anbox/daemon.cpp @@ -18,7 +18,7 @@ #include #include -#include "anbox/config.h" +#include "anbox/system_configuration.h" #include "anbox/daemon.h" #include "anbox/logger.h" diff --git a/src/anbox/input/manager.cpp b/src/anbox/input/manager.cpp index 0e5a56d..eacdd8b 100644 --- a/src/anbox/input/manager.cpp +++ b/src/anbox/input/manager.cpp @@ -16,7 +16,7 @@ */ #include "anbox/input/manager.h" -#include "anbox/config.h" +#include "anbox/system_configuration.h" #include "anbox/input/device.h" #include "anbox/runtime.h" #include "anbox/utils.h" diff --git a/src/anbox/config.cpp b/src/anbox/system_configuration.cpp similarity index 88% rename from src/anbox/config.cpp rename to src/anbox/system_configuration.cpp index a1725e2..675c9e5 100644 --- a/src/anbox/config.cpp +++ b/src/anbox/system_configuration.cpp @@ -16,8 +16,9 @@ */ -#include "anbox/config.h" +#include "anbox/system_configuration.h" #include "anbox/utils.h" +#include "anbox/build/config.h" #include "external/xdg/xdg.h" @@ -86,15 +87,15 @@ anbox::SystemConfiguration& anbox::SystemConfiguration::instance() { } anbox::SystemConfiguration::SystemConfiguration() { - auto gen_resource_path = [] () -> fs::path { + auto detect_resource_path = [] () -> fs::path { const auto snap_path = utils::get_env_value("SNAP"); if (!snap_path.empty()) { - return fs::path(snap_path) / "usr/share/anbox"; + return fs::path(snap_path) / "usr" / "share" / "anbox"; } else { - return default_resource_path; + return anbox::build::default_resource_path; } }; - resource_path = gen_resource_path(); - data_path = default_path_path; + resource_path = detect_resource_path(); + data_path = anbox::build::default_data_path; } diff --git a/src/anbox/config.h.in b/src/anbox/system_configuration.h similarity index 86% rename from src/anbox/config.h.in rename to src/anbox/system_configuration.h index 26f07de..e0526ec 100644 --- a/src/anbox/config.h.in +++ b/src/anbox/system_configuration.h @@ -15,8 +15,8 @@ * */ -#ifndef ANBOX_CONFIG_H_ -#define ANBOX_CONFIG_H_ +#ifndef ANBOX_SYSTEM_CONFIGURATION_H_ +#define ANBOX_SYSTEM_CONFIGURATION_H_ #include #include @@ -47,12 +47,7 @@ class SystemConfiguration { boost::filesystem::path data_path; boost::filesystem::path resource_path; - - private: - static constexpr const char *default_resource_path{"@ANBOX_RESOURCE_DIR_FULL@"}; - static constexpr const char *default_path_path{"@ANBOX_STATEDIR_FULL@"}; - }; } // namespace anbox -#endif +#endif // ANBOX_SYSTEM_CONFIGURATION_H_ diff --git a/src/anbox/ui/splash_screen.cpp b/src/anbox/ui/splash_screen.cpp index d5b9b48..01ed648 100644 --- a/src/anbox/ui/splash_screen.cpp +++ b/src/anbox/ui/splash_screen.cpp @@ -16,7 +16,7 @@ */ #include "anbox/ui/splash_screen.h" -#include "anbox/config.h" +#include "anbox/system_configuration.h" #include "anbox/utils.h" #include "anbox/logger.h"