Skip to content

Commit

Permalink
dnf5 app, dnf5 plugins: Do not export private symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
jrohel committed May 21, 2024
1 parent f832497 commit bcddeef
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 29 deletions.
3 changes: 3 additions & 0 deletions dnf5-plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions dnf5/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}\")
Expand All @@ -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})
Expand Down
19 changes: 10 additions & 9 deletions dnf5/include/dnf5/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#ifndef DNF5_CONTEXT_HPP
#define DNF5_CONTEXT_HPP

#include "defs.h"
#include "version.hpp"

#include <libdnf5-cli/argument_parser.hpp>
Expand All @@ -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 };

Expand Down Expand Up @@ -161,12 +162,12 @@ class Context : public libdnf5::cli::session::Session {
const std::vector<std::pair<std::vector<std::string>, bool>> & get_libdnf_plugins_enablement() const;

private:
class Impl;
class DNF_LOCAL Impl;
std::unique_ptr<Impl> 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;

Expand All @@ -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();
Expand Down Expand Up @@ -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<std::chrono::steady_clock> prev_print_time;
DNF_LOCAL static std::chrono::time_point<std::chrono::steady_clock> 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<std::string> match_specs(
DNF_API std::vector<std::string> match_specs(
Context & ctx,
const std::string & pattern,
bool installed,
Expand Down
14 changes: 8 additions & 6 deletions dnf5/include/dnf5/iplugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#define DNF5_PLUGIN_IPLUGIN_HPP

#include "context.hpp"
#include "defs.h"

#include <cstdint>
#include <vector>
Expand All @@ -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();
Expand Down Expand Up @@ -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
9 changes: 5 additions & 4 deletions dnf5/include/dnf5/offline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#ifndef DNF5_OFFLINE_HPP
#define DNF5_OFFLINE_HPP

#include "dnf5/version.hpp"
#include "context.hpp"
#include "defs.h"
#include "version.hpp"

#include <dnf5/context.hpp>
#include <libdnf5/conf/const.hpp>
#include <libdnf5/conf/option_bool.hpp>
#include <libdnf5/conf/option_number.hpp>
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand Down
18 changes: 10 additions & 8 deletions dnf5/include/dnf5/shared_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,29 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#ifndef DNF5_COMMANDS_SHARED_OPTIONS_HPP
#define DNF5_COMMANDS_SHARED_OPTIONS_HPP

#include "defs.h"

#include <dnf5/context.hpp>
#include <libdnf5-cli/session.hpp>
#include <libdnf5/utils/bgettext/bgettext-lib.h>

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();
Expand All @@ -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

Expand Down
6 changes: 4 additions & 2 deletions dnf5/include/dnf5/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#ifndef DNF5_CONFIG_HPP
#define DNF5_CONFIG_HPP

#include "defs.h"

#include <cstdint>

namespace dnf5 {
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit bcddeef

Please sign in to comment.