From bcddeef839f06918b71986d2560f1331da1414a4 Mon Sep 17 00:00:00 2001 From: Jaroslav Rohel Date: Mon, 20 May 2024 14:40:26 +0200 Subject: [PATCH] dnf5 app, dnf5 plugins: Do not export private symbols --- dnf5-plugins/CMakeLists.txt | 3 +++ dnf5/CMakeLists.txt | 4 ++++ dnf5/include/dnf5/context.hpp | 19 ++++++++++--------- dnf5/include/dnf5/iplugin.hpp | 14 ++++++++------ dnf5/include/dnf5/offline.hpp | 9 +++++---- dnf5/include/dnf5/shared_options.hpp | 18 ++++++++++-------- dnf5/include/dnf5/version.hpp | 6 ++++-- 7 files changed, 44 insertions(+), 29 deletions(-) diff --git a/dnf5-plugins/CMakeLists.txt b/dnf5-plugins/CMakeLists.txt index 635c5b504..503bfe4bc 100644 --- a/dnf5-plugins/CMakeLists.txt +++ b/dnf5-plugins/CMakeLists.txt @@ -2,6 +2,9 @@ if(NOT WITH_DNF5_PLUGINS) return() endif() +set(CMAKE_CXX_VISIBILITY_PRESET hidden) +set(CMAKE_C_VISIBILITY_PRESET hidden) + include_directories("${PROJECT_SOURCE_DIR}/dnf5/include/") # These plugins use symbols from dnf5 program, hence the symbold are undefined # at link time and cannot pass "-z defs" linker check. Disable the check. diff --git a/dnf5/CMakeLists.txt b/dnf5/CMakeLists.txt index 47f911e4f..ca9d91302 100644 --- a/dnf5/CMakeLists.txt +++ b/dnf5/CMakeLists.txt @@ -5,6 +5,8 @@ endif() find_package(Threads) +add_definitions(-DDNF_BUILD_APPLICATION) + # set gettext domain for translations set(GETTEXT_DOMAIN dnf5) add_definitions(-DGETTEXT_DOMAIN=\"${GETTEXT_DOMAIN}\") @@ -28,6 +30,8 @@ add_executable(dnf5 ${DNF5_SOURCES}) # Enable symbol export. Needed for loadable modules (dnf5 plugins). set_property(TARGET dnf5 PROPERTY ENABLE_EXPORTS 1) +# Export only explicitly marked symbols. +set_target_properties(dnf5 PROPERTIES C_VISIBILITY_PRESET hidden CXX_VISIBILITY_PRESET hidden) target_link_libraries(dnf5 PRIVATE common libdnf5 libdnf5-cli Threads::Threads) install(TARGETS dnf5 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/dnf5/include/dnf5/context.hpp b/dnf5/include/dnf5/context.hpp index e1448fdb1..3ade3f3cc 100644 --- a/dnf5/include/dnf5/context.hpp +++ b/dnf5/include/dnf5/context.hpp @@ -20,6 +20,7 @@ along with libdnf. If not, see . #ifndef DNF5_CONTEXT_HPP #define DNF5_CONTEXT_HPP +#include "defs.h" #include "version.hpp" #include @@ -44,7 +45,7 @@ namespace dnf5 { class Plugins; -class Context : public libdnf5::cli::session::Session { +class DNF_API Context : public libdnf5::cli::session::Session { public: enum class LoadAvailableRepos { NONE, ENABLED, ALL }; @@ -161,12 +162,12 @@ class Context : public libdnf5::cli::session::Session { const std::vector, bool>> & get_libdnf_plugins_enablement() const; private: - class Impl; + class DNF_LOCAL Impl; std::unique_ptr p_impl; }; -class Command : public libdnf5::cli::session::Command { +class DNF_API Command : public libdnf5::cli::session::Command { public: using libdnf5::cli::session::Command::Command; @@ -180,7 +181,7 @@ class Command : public libdnf5::cli::session::Command { }; -class RpmTransCB : public libdnf5::rpm::TransactionCallbacks { +class DNF_API RpmTransCB : public libdnf5::rpm::TransactionCallbacks { public: RpmTransCB(Context & context); ~RpmTransCB(); @@ -249,25 +250,25 @@ class RpmTransCB : public libdnf5::rpm::TransactionCallbacks { void verify_stop([[maybe_unused]] uint64_t total) override; private: - void new_progress_bar(int64_t total, const std::string & descr); + DNF_LOCAL void new_progress_bar(int64_t total, const std::string & descr); - static bool is_time_to_print(); + DNF_LOCAL static bool is_time_to_print(); - static std::chrono::time_point prev_print_time; + DNF_LOCAL static std::chrono::time_point prev_print_time; libdnf5::cli::progressbar::MultiProgressBar multi_progress_bar; libdnf5::cli::progressbar::DownloadProgressBar * active_progress_bar{nullptr}; Context & context; }; -void run_transaction(libdnf5::rpm::Transaction & transaction); +DNF_API void run_transaction(libdnf5::rpm::Transaction & transaction); /// Returns the names of matching packages and paths of matching package file names and directories. /// If `nevra_for_same_name` is true, it returns a full nevra for packages with the same name. /// Only files whose names match `file_name_regex` are returned. /// NOTE: This function is intended to be used only for autocompletion purposes as the argument parser's /// complete hook argument. It does the base setup and repos loading inside. -std::vector match_specs( +DNF_API std::vector match_specs( Context & ctx, const std::string & pattern, bool installed, diff --git a/dnf5/include/dnf5/iplugin.hpp b/dnf5/include/dnf5/iplugin.hpp index a11f3db84..c643928e2 100644 --- a/dnf5/include/dnf5/iplugin.hpp +++ b/dnf5/include/dnf5/iplugin.hpp @@ -21,6 +21,7 @@ along with libdnf. If not, see . #define DNF5_PLUGIN_IPLUGIN_HPP #include "context.hpp" +#include "defs.h" #include #include @@ -35,7 +36,7 @@ struct PluginVersion { }; /// @brief A base class for implementing DNF5 plugins that provide one or more commands to users. -class IPlugin { +class DNF_PLUGIN_API IPlugin { public: explicit IPlugin(Context & context); virtual ~IPlugin(); @@ -83,21 +84,22 @@ extern "C" { /// Returns the version of the API required by the plugin. /// Same result as IPlugin::get_api_version(), but can be called without creating an IPlugin instance. -dnf5::PluginAPIVersion dnf5_plugin_get_api_version(void); +DNF_PLUGIN_API dnf5::PluginAPIVersion dnf5_plugin_get_api_version(void); /// Returns the name of the plugin. It can be called at any time. /// Same result as IPlugin::get_name(), but can be called without creating an IPlugin instance. -const char * dnf5_plugin_get_name(void); +DNF_PLUGIN_API const char * dnf5_plugin_get_name(void); /// Returns the version of the plugin. It can be called at any time. /// Same result as IPlugin::get_version(), but can be called without creating an IPlugin instance. -dnf5::PluginVersion dnf5_plugin_get_version(void); +DNF_PLUGIN_API dnf5::PluginVersion dnf5_plugin_get_version(void); /// Creates a new plugin instance. Passes the API version to the plugin. -dnf5::IPlugin * dnf5_plugin_new_instance(dnf5::ApplicationVersion application_version, dnf5::Context & context); +DNF_PLUGIN_API dnf5::IPlugin * dnf5_plugin_new_instance( + dnf5::ApplicationVersion application_version, dnf5::Context & context); /// Deletes plugin instance. -void dnf5_plugin_delete_instance(dnf5::IPlugin * plugin_instance); +DNF_PLUGIN_API void dnf5_plugin_delete_instance(dnf5::IPlugin * plugin_instance); } #endif diff --git a/dnf5/include/dnf5/offline.hpp b/dnf5/include/dnf5/offline.hpp index 9aca7c3c6..f2fd5cb16 100644 --- a/dnf5/include/dnf5/offline.hpp +++ b/dnf5/include/dnf5/offline.hpp @@ -20,9 +20,10 @@ along with libdnf. If not, see . #ifndef DNF5_OFFLINE_HPP #define DNF5_OFFLINE_HPP -#include "dnf5/version.hpp" +#include "context.hpp" +#include "defs.h" +#include "version.hpp" -#include #include #include #include @@ -61,7 +62,7 @@ struct OfflineTransactionStateData { std::string module_platform_id; }; -class OfflineTransactionState { +class DNF_API OfflineTransactionState { public: void write(); OfflineTransactionState(std::filesystem::path path); @@ -76,7 +77,7 @@ class OfflineTransactionState { OfflineTransactionStateData data; }; -void log_status( +DNF_API void log_status( Context & context, const std::string & message, const std::string & message_id, diff --git a/dnf5/include/dnf5/shared_options.hpp b/dnf5/include/dnf5/shared_options.hpp index 49e2b36dc..46b4f3757 100644 --- a/dnf5/include/dnf5/shared_options.hpp +++ b/dnf5/include/dnf5/shared_options.hpp @@ -20,27 +20,29 @@ along with libdnf. If not, see . #ifndef DNF5_COMMANDS_SHARED_OPTIONS_HPP #define DNF5_COMMANDS_SHARED_OPTIONS_HPP +#include "defs.h" + #include #include #include namespace dnf5 { -class AllowErasingOption : public libdnf5::cli::session::BoolOption { +class DNF_API AllowErasingOption : public libdnf5::cli::session::BoolOption { public: explicit AllowErasingOption(libdnf5::cli::session::Command & command); ~AllowErasingOption(); }; -class SkipBrokenOption : public libdnf5::cli::session::BoolOption { +class DNF_API SkipBrokenOption : public libdnf5::cli::session::BoolOption { public: explicit SkipBrokenOption(dnf5::Command & command); ~SkipBrokenOption(); }; -class SkipUnavailableOption : public libdnf5::cli::session::BoolOption { +class DNF_API SkipUnavailableOption : public libdnf5::cli::session::BoolOption { public: explicit SkipUnavailableOption(dnf5::Command & command); ~SkipUnavailableOption(); @@ -49,23 +51,23 @@ class SkipUnavailableOption : public libdnf5::cli::session::BoolOption { /// Create two options (`--allow-downgrade` and `--no-allow-downgrade`) for a command provided as an argument command. /// The values are stored in the `allow_downgrade` configuration option -void create_allow_downgrade_options(dnf5::Command & command); +DNF_API void create_allow_downgrade_options(dnf5::Command & command); /// Create the `--destdir` option for a command provided as an argument. /// The values are stored in the `destdir` configuration option -void create_destdir_option(dnf5::Command & command); +DNF_API void create_destdir_option(dnf5::Command & command); /// Create the `--downloadonly` option for a command provided as an argument. /// The values are stored in the `downloadonly` configuration option -void create_downloadonly_option(dnf5::Command & command); +DNF_API void create_downloadonly_option(dnf5::Command & command); /// Create the `--store` option for a command provided as an argument. /// The value is stored in Context::transaction_store_path. -void create_store_option(dnf5::Command & command); +DNF_API void create_store_option(dnf5::Command & command); /// Create the `--offline` option for a command provided as an argument. -void create_offline_option(dnf5::Command & command); +DNF_API void create_offline_option(dnf5::Command & command); } // namespace dnf5 diff --git a/dnf5/include/dnf5/version.hpp b/dnf5/include/dnf5/version.hpp index 4329cedf5..d7bfe217a 100644 --- a/dnf5/include/dnf5/version.hpp +++ b/dnf5/include/dnf5/version.hpp @@ -20,6 +20,8 @@ along with libdnf. If not, see . #ifndef DNF5_CONFIG_HPP #define DNF5_CONFIG_HPP +#include "defs.h" + #include namespace dnf5 { @@ -49,11 +51,11 @@ static constexpr PluginAPIVersion PLUGIN_API_VERSION{.major = 2, .minor = 0}; /// @return Application version /// @since 5.0 -ApplicationVersion get_application_version() noexcept; +DNF_API ApplicationVersion get_application_version() noexcept; /// @return API version implemented in the application /// @since 5.0 -PluginAPIVersion get_plugin_api_version() noexcept; +DNF_API PluginAPIVersion get_plugin_api_version() noexcept; } // namespace dnf5