Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement conditional compilation -DWITH_MODULEMD=OFF #1521

Merged
merged 4 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 53 additions & 9 deletions .packit.yaml
Original file line number Diff line number Diff line change
@@ -1,32 +1,55 @@
# See the documentation for more information:
# https://packit.dev/docs/configuration/

specfile_path: dnf5.spec
packages:
dnf5:
specfile_path: dnf5.spec

# add or remove files that should be synced
files_to_sync:
- dnf5.spec
- .packit.yaml
# add or remove files that should be synced
files_to_sync:
- dnf5.spec
- .packit.yaml

# name in upstream package repository or registry (e.g. in PyPI)
upstream_package_name: dnf5
# downstream (Fedora) RPM package name
downstream_package_name: dnf5
# name in upstream package repository or registry (e.g. in PyPI)
upstream_package_name: dnf5
# downstream (Fedora) RPM package name
downstream_package_name: dnf5

# Test build with disabled modules.
# Use separate package configuration because Packit
# doesn't yet support dependencies between jobs so if we
# had multiple copr_builds it woudn't know which to use
# for tests jobs.
# https://github.com/packit/packit-service/issues/1720
dnf5-without-modules:
specfile_path: dnf5.spec

# add or remove files that should be synced
files_to_sync:
- dnf5.spec
- .packit.yaml

# name in upstream package repository or registry (e.g. in PyPI)
upstream_package_name: dnf5
downstream_package_name: dnf5

jobs:
- job: propose_downstream
trigger: release
dist_git_branches:
- fedora-rawhide
copy_upstream_release_description: true
packages: [dnf5]
- job: koji_build
trigger: commit
dist_git_branches:
- fedora-all
packages: [dnf5]
- job: bodhi_update
trigger: commit
dist_git_branches:
- fedora-all
packages: [dnf5]
- job: copr_build
trigger: pull_request
targets:
Expand All @@ -35,6 +58,7 @@ jobs:
actions:
get-current-version:
- bash -c 'rpmspec -q --queryformat "%{VERSION}\n" dnf5.spec | head -n1'
packages: [dnf5]
- job: copr_build
trigger: pull_request
targets:
Expand All @@ -43,6 +67,7 @@ jobs:
actions:
get-current-version:
- bash -c 'rpmspec -q --queryformat "%{VERSION}\n" dnf5.spec | head -n1'
packages: [dnf5]
- job: tests
trigger: pull_request
identifier: "dnf5-tests"
Expand All @@ -51,6 +76,7 @@ jobs:
fmf_url: https://github.com/rpm-software-management/ci-dnf-stack.git
fmf_ref: main
tmt_plan: "^/plans/integration/behave-dnf5$"
packages: [dnf5]
- job: tests
trigger: pull_request
identifier: "createrepo_c-tests"
Expand All @@ -59,6 +85,7 @@ jobs:
fmf_url: https://github.com/rpm-software-management/ci-dnf-stack.git
fmf_ref: main
tmt_plan: "^/plans/integration/behave-createrepo_c$"
packages: [dnf5]
- job: tests
trigger: pull_request
identifier: "dnf-tests"
Expand All @@ -68,6 +95,7 @@ jobs:
fmf_url: https://github.com/rpm-software-management/ci-dnf-stack.git
fmf_ref: main
tmt_plan: "^/plans/integration/behave-dnf$"
packages: [dnf5]
- job: tests
trigger: pull_request
identifier: "dnf5daemon-tests"
Expand All @@ -76,3 +104,19 @@ jobs:
fmf_url: https://github.com/rpm-software-management/ci-dnf-stack.git
fmf_ref: main
tmt_plan: "^/plans/integration/behave-dnf5daemon$"
packages: [dnf5]
- job: copr_build
identifier: "WITH_MODULEMD=OFF"
trigger: pull_request
branch: 'main'
targets:
- fedora-rawhide-x86_64
actions:
fix-spec-file:
# disable modulemd in spec to verify the build is passing without it
- sed -i dnf5.spec -e "s/bcond_without modulemd/bcond_with modulemd/"
# fill in Release as if packit would have done it
- bash -c "sed -i -r \"s/Release:(\s*)\S+/Release:\1${PACKIT_RPMSPEC_RELEASE}%{?dist}/\" dnf5.spec"
get-current-version:
- bash -c 'rpmspec -q --queryformat "%{VERSION}\n" dnf5.spec | head -n1'
packages: [dnf5-without-modules]
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
message("Running CMake on dnf5...")
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.6)


include(VERSION.cmake)
Expand Down Expand Up @@ -119,6 +119,10 @@ if(WITH_TRANSLATIONS)
add_custom_target(gettext-potfiles)
endif()

# When modules are enabled add WITH_MODULEMD definition for all sub-directories (all components).
if (WITH_MODULEMD)
add_definitions(-DWITH_MODULEMD)
endif()

include_directories("${PROJECT_SOURCE_DIR}/include")
include_directories("${PROJECT_SOURCE_DIR}/common")
Expand Down
1 change: 1 addition & 0 deletions dnf5-plugins/automatic_plugin/automatic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#include <libdnf5-cli/output/transaction_table.hpp>
#include <libdnf5/conf/const.hpp>
#include <libdnf5/repo/package_downloader.hpp>
#include <libdnf5/repo/repo_errors.hpp>
#include <libdnf5/rpm/package_query.hpp>
#include <libdnf5/rpm/package_set.hpp>
#include <libdnf5/utils/bgettext/bgettext-mark-domain.h>
Expand Down
8 changes: 7 additions & 1 deletion dnf5/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@ add_definitions(-DINSTALL_PREFIX=\"${CMAKE_INSTALL_PREFIX}\")
# set SYSCONFIG_DIR, used to find the directory containing the dnf5 configuration
add_definitions(-DSYSCONFIG_DIR=\"${CMAKE_INSTALL_FULL_SYSCONFDIR}\")

# use any sources found under the current directory
# use sources found under the current directory
file(GLOB_RECURSE DNF5_SOURCES *.cpp)

# exclude module sources if WITH_MODULEMD not defined
if (NOT WITH_MODULEMD)
file(GLOB_RECURSE DNF5_SOURCES_MODULES commands/module/*.cpp)
list(REMOVE_ITEM DNF5_SOURCES ${DNF5_SOURCES_MODULES})
endif()

include_directories("${PROJECT_SOURCE_DIR}/dnf5/include/")
include_directories(.)

Expand Down
4 changes: 4 additions & 0 deletions dnf5/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#include "commands/list/list.hpp"
#include "commands/makecache/makecache.hpp"
#include "commands/mark/mark.hpp"
#ifdef WITH_MODULEMD
#include "commands/module/module.hpp"
#endif
#include "commands/offline/offline.hpp"
#include "commands/provides/provides.hpp"
#include "commands/reinstall/reinstall.hpp"
Expand Down Expand Up @@ -687,7 +689,9 @@ static void add_commands(Context & context) {

context.add_and_initialize_command(std::make_unique<GroupCommand>(context));
context.add_and_initialize_command(std::make_unique<EnvironmentCommand>(context));
#ifdef WITH_MODULEMD
context.add_and_initialize_command(std::make_unique<ModuleCommand>(context));
#endif
context.add_and_initialize_command(std::make_unique<HistoryCommand>(context));
context.add_and_initialize_command(std::make_unique<RepoCommand>(context));
context.add_and_initialize_command(std::make_unique<AdvisoryCommand>(context));
Expand Down
12 changes: 12 additions & 0 deletions include/libdnf5-cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ endif()

file(GLOB_RECURSE LIBDNF5_CLI_HEADERS *.hpp)

if (NOT WITH_MODULEMD)
file(GLOB_RECURSE LIBDNF5_CLI_HEADERS_MODULES
output/adapters/module.hpp
output/adapters/module_tmpl.hpp
output/interfaces/module.hpp
output/moduleinfo.hpp
output/modulelist.hpp)

list(REMOVE_ITEM LIBDNF5_CLI_HEADERS ${LIBDNF5_CLI_HEADERS_MODULES})
endif()


# preserve relative paths of the header files
foreach(abspath ${LIBDNF5_CLI_HEADERS})
# relative path to the header file
Expand Down
10 changes: 10 additions & 0 deletions include/libdnf5/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
file(GLOB_RECURSE LIBDNF5_HEADERS *.hpp *.h)

if (NOT WITH_MODULEMD)
file(GLOB_RECURSE LIBDNF5_HEADERS_MODULES module/*.hpp)

# module_sack_weak.hpp is needed for base.hpp API
# its not actually used and it doesn't include any other libdnf5 header
list(FILTER LIBDNF5_HEADERS_MODULES EXCLUDE REGEX .*module_sack_weak.hpp)

list(REMOVE_ITEM LIBDNF5_HEADERS ${LIBDNF5_HEADERS_MODULES})
endif()

# preserve relative paths of the header files
foreach(abspath ${LIBDNF5_HEADERS})
# relative path to the header file
Expand Down
9 changes: 4 additions & 5 deletions include/libdnf5/base/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,20 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#include "libdnf5/conf/vars.hpp"
#include "libdnf5/defs.h"
#include "libdnf5/logger/log_router.hpp"
#include "libdnf5/module/module_sack.hpp"
#include "libdnf5/module/module_sack_weak.hpp"
#include "libdnf5/plugin/plugin_info.hpp"
#include "libdnf5/repo/download_callbacks.hpp"
#include "libdnf5/repo/repo_sack.hpp"
#include "libdnf5/rpm/package_sack.hpp"
#include "libdnf5/transaction/transaction_history.hpp"

#include <functional>
#include <map>


namespace libdnf5::module {

class ModuleDB;
class ModuleSack;

}
} // namespace libdnf5::module


namespace libdnf5 {
Expand Down Expand Up @@ -86,6 +84,7 @@ class LIBDNF_API Base {
LogRouterWeakPtr get_logger();
repo::RepoSackWeakPtr get_repo_sack();
rpm::PackageSackWeakPtr get_rpm_package_sack();
/// Throws libdnf5::AssertionError when used with libdnf5 compiled without modules enabled.
module::ModuleSackWeakPtr get_module_sack();

/// Adds a request to enable/disable plugins that match the names (glob patterns) in the list.
Expand Down
3 changes: 3 additions & 0 deletions include/libdnf5/base/goal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,21 @@ class LIBDNF_API Goal {
~Goal();

/// Add module enable request to the goal.
/// Throws libdnf5::AssertionError when used with libdnf5 compiled without modules enabled.
/// @param spec A string with module spec to enable.
/// @param settings A structure to override default goal settings.
// @replaces dnf:dnf/module/module_base.py:method:ModuleBase().enable(self, module_specs)
void add_module_enable(const std::string & spec, const libdnf5::GoalJobSettings & settings);

/// Add module disable request to the goal.
/// Throws libdnf5::AssertionError when used with libdnf5 compiled without modules enabled.
/// @param spec A string with module spec to disable.
/// @param settings A structure to override default goal settings.
// @replaces dnf:dnf/module/module_base.py:method:ModuleBase().disable(self, module_specs)
void add_module_disable(const std::string & spec, const libdnf5::GoalJobSettings & settings);

/// Add module reset request to the goal.
/// Throws libdnf5::AssertionError when used with libdnf5 compiled without modules enabled.
/// @param spec A string with module spec to reset.
/// @param settings A structure to override default goal settings.
// @replaces dnf:dnf/module/module_base.py:method:ModuleBase().reset(self, module_specs)
Expand Down
3 changes: 0 additions & 3 deletions include/libdnf5/repo/repo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#include "repo_callbacks.hpp"

#include "libdnf5/base/base_weak.hpp"
#include "libdnf5/common/exception.hpp"
#include "libdnf5/common/weak_ptr.hpp"
#include "libdnf5/defs.h"
#include "libdnf5/repo/repo_errors.hpp"
#include "libdnf5/repo/repo_weak.hpp"
#include "libdnf5/rpm/package.hpp"

Expand Down
11 changes: 10 additions & 1 deletion libdnf5-cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@ set(GETTEXT_DOMAIN libdnf5-cli)
add_definitions(-DGETTEXT_DOMAIN=\"${GETTEXT_DOMAIN}\")


# use any sources found under the current directory
# use sources found under the current directory
file(GLOB_RECURSE LIBDNF5_CLI_SOURCES *.cpp)

# exclude module sources if WITH_MODULEMD not defined
if (NOT WITH_MODULEMD)
file(GLOB_RECURSE LIBDNF5_CLI_SOURCES_MODULES
output/adapters/module.cpp
output/moduleinfo.cpp
output/modulelist.cpp)

list(REMOVE_ITEM LIBDNF5_CLI_SOURCES ${LIBDNF5_CLI_SOURCES_MODULES})
endif()

# gather all pkg-config requires and write them to a .pc file later
list(APPEND LIBDNF5_CLI_PC_REQUIRES)
Expand Down
18 changes: 13 additions & 5 deletions libdnf5/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# use any sources found under the current directory
# use sources found under the current directory
file(GLOB_RECURSE LIBDNF5_SOURCES *.cpp *.c)

# exclude module sources if WITH_MODULEMD not defined
if (NOT WITH_MODULEMD)
file(GLOB_RECURSE LIBDNF5_SOURCES_MODULES module/*.cpp)
list(REMOVE_ITEM LIBDNF5_SOURCES ${LIBDNF5_SOURCES_MODULES})
endif()

# create config header file
configure_file("config.h.in" ${CMAKE_CURRENT_SOURCE_DIR}/conf/config.h)

Expand Down Expand Up @@ -65,10 +71,12 @@ include_directories(${JSONC_INCLUDE_DIRS})
target_link_libraries(libdnf5 PRIVATE ${JSONC_LIBRARIES})
target_link_libraries(libdnf5_static PRIVATE ${JSONC_LIBRARIES})

pkg_check_modules(LIBMODULEMD REQUIRED modulemd-2.0>=2.11.2)
list(APPEND LIBDNF5_PC_REQUIRES "${LIBMODULEMD_MODULE_NAME}")
target_link_libraries(libdnf5 PRIVATE ${LIBMODULEMD_LIBRARIES})
target_link_libraries(libdnf5_static PRIVATE ${LIBMODULEMD_LIBRARIES})
if (WITH_MODULEMD)
pkg_check_modules(LIBMODULEMD REQUIRED modulemd-2.0>=2.11.2)
list(APPEND LIBDNF5_PC_REQUIRES "${LIBMODULEMD_MODULE_NAME}")
target_link_libraries(libdnf5 PRIVATE ${LIBMODULEMD_LIBRARIES})
target_link_libraries(libdnf5_static PRIVATE ${LIBMODULEMD_LIBRARIES})
endif()

pkg_check_modules(LIBSOLV REQUIRED libsolv>=0.7.25)
list(APPEND LIBDNF5_PC_REQUIRES "${LIBSOLV_MODULE_NAME}")
Expand Down
Loading
Loading