First attempt at consolidating C++ code

main
Simon Quigley 1 week ago
parent 4fccaa40d7
commit 2eca4875cd

@ -1,25 +0,0 @@
cmake_minimum_required(VERSION 3.21)
project(build-packages CXX)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
find_package(yaml-cpp REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBGIT2 REQUIRED IMPORTED_TARGET libgit2)
add_library(common SHARED common.cpp)
target_link_libraries(common yaml-cpp)
add_library(update_maintainer SHARED update_maintainer.cpp)
add_executable(build-packages main.cpp)
target_link_libraries(build-packages common update_maintainer PkgConfig::LIBGIT2 yaml-cpp)
set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
install(TARGETS common LIBRARY DESTINATION lib)
install(TARGETS update_maintainer LIBRARY DESTINATION lib)
install(TARGETS build-packages RUNTIME DESTINATION .)

@ -1,10 +0,0 @@
#pragma once
#include <string>
#include <vector>
#include <filesystem>
#include <optional>
std::string parse_version(const std::filesystem::path &changelog_path);
void run_command(const std::vector<std::string> &cmd, const std::optional<std::filesystem::path> &cwd = std::nullopt, bool show_output=false);
void clean_old_logs(const std::filesystem::path &log_dir, int max_age_seconds=86400);
void create_tarball(const std::string &name, const std::filesystem::path &source_dir, const std::vector<std::string> &exclusions);

@ -1,4 +0,0 @@
#pragma once
#include <string>
void update_maintainer(const std::string &debian_directory, bool verbose=false);

@ -0,0 +1,75 @@
cmake_minimum_required(VERSION 3.21)
project(lubuntuci CXX)
# Set C++ standard
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Specify output directories
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
# Find required packages
find_package(yaml-cpp REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBGIT2 REQUIRED IMPORTED_TARGET libgit2)
find_package(CURL REQUIRED)
find_package(ZLIB REQUIRED)
# Locate Launchpadlib
# Assuming Launchpadlib is installed in /srv/lubuntu-ci/repos/ci-tools/lib/
# Adjust the path if necessary
find_library(LAUNCHPADLIB_LIB NAMES launchpadlib liblaunchpad REQUIRED PATHS /srv/lubuntu-ci/repos/ci-tools/lib/ NO_DEFAULT_PATH)
if(NOT LAUNCHPADLIB_LIB)
message(FATAL_ERROR "launchpadlib not found")
endif()
# Include directories for Launchpadlib
include_directories(/srv/lubuntu-ci/repos/ci-tools/include/launchpadlib-cpp)
# Create the shared library liblubuntuci.so
add_library(lubuntuci SHARED common.cpp utilities.cpp)
target_include_directories(lubuntuci PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(lubuntuci PRIVATE yaml-cpp)
# Ensure liblubuntuci has proper RPATH
set_target_properties(lubuntuci PROPERTIES
BUILD_WITH_INSTALL_RPATH TRUE
INSTALL_RPATH "$ORIGIN/lib"
)
# build-packages executable
add_executable(build-packages build-packages.cpp)
target_link_libraries(build-packages PRIVATE lubuntuci PkgConfig::LIBGIT2 yaml-cpp ${LIBGIT2_LIBRARIES} ${YAML_CPP_LIBRARIES} ${LAUNCHPADLIB_LIB})
# fetch-indexes executable
add_executable(fetch-indexes fetch-indexes.cpp utilities.cpp)
target_include_directories(fetch-indexes PRIVATE ${CURL_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS} /srv/lubuntu-ci/repos/ci-tools/include/launchpadlib-cpp)
target_link_libraries(fetch-indexes PRIVATE lubuntuci CURL::libcurl ZLIB::ZLIB yaml-cpp ${LAUNCHPADLIB_LIB})
# update-maintainer executable
add_executable(update-maintainer update-maintainer.cpp)
# Link only necessary libraries, avoiding liblubuntuci
target_include_directories(update-maintainer PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} /srv/lubuntu-ci/repos/ci-tools/include/launchpadlib-cpp)
target_link_libraries(update-maintainer PRIVATE yaml-cpp ${LAUNCHPADLIB_LIB})
# Ensure executables have proper RPATH
set_target_properties(build-packages fetch-indexes update-maintainer PROPERTIES
BUILD_WITH_INSTALL_RPATH TRUE
INSTALL_RPATH "$ORIGIN/lib"
)
# Install targets
install(TARGETS lubuntuci
LIBRARY DESTINATION lib
)
install(TARGETS build-packages fetch-indexes update-maintainer
RUNTIME DESTINATION bin
)
# Install headers
install(FILES common.h update-maintainer.h utilities.h
DESTINATION include/lubuntuci
)

@ -1,3 +1,18 @@
// Copyright (C) 2024 Simon Quigley <tsimonq2@ubuntu.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU 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 General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "common.h"
#include "update_maintainer.h"
#include <iostream>
@ -333,8 +348,8 @@ int main(int argc, char** argv) {
std::string epoch;
std::string upstream_version = version_match;
if(auto pos=version_match.find(':'); pos!=std::string::npos) {
epoch = version_match.substr(0,pos);
upstream_version = version_match.substr(pos+1);
epoch=version_match.substr(0,pos);
upstream_version=version_match.substr(pos+1);
}
if(auto pos=upstream_version.find('-'); pos!=std::string::npos) {
upstream_version=upstream_version.substr(0,pos);
@ -409,7 +424,7 @@ int main(int argc, char** argv) {
log_info("Completed upload of changes to "+upload_target);
for(auto &file: devel_changes_files) {
if(!file.empty()) {
run_source_lintian(name, file);
run_source_lintian(name,file);
}
}
} catch (...) {
@ -521,7 +536,7 @@ int main(int argc, char** argv) {
fs::path tarball_source = fs::path(BASE_DIR)/(name+"_MAIN.orig.tar.gz");
fs::path tarball_dest = fs::path(BASE_DIR)/(name+"_"+release_version_no_epoch+".orig.tar.gz");
fs::copy_file(tarball_source,tarball_dest,fs::copy_options::overwrite_existing);
std::string version_for_dch = epoch.empty()? release_version_no_epoch : (epoch+":"+release_version_no_epoch);
std::map<std::string,std::string> env_map;

@ -1,3 +1,18 @@
// Copyright (C) 2024 Simon Quigley <tsimonq2@ubuntu.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU 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 General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "common.h"
#include <iostream>
#include <fstream>

@ -0,0 +1,25 @@
// Copyright (C) 2024 Simon Quigley <tsimonq2@ubuntu.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU 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 General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <string>
#include <vector>
#include <filesystem>
#include <optional>
std::string parse_version(const std::filesystem::path &changelog_path);
void run_command(const std::vector<std::string> &cmd, const std::optional<std::filesystem::path> &cwd = std::nullopt, bool show_output=false);
void clean_old_logs(const std::filesystem::path &log_dir, int max_age_seconds=86400);
void create_tarball(const std::string &name, const std::filesystem::path &source_dir, const std::vector<std::string> &exclusions);

@ -13,6 +13,8 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "utilities.h"
#include <iostream>
#include <fstream>
#include <string>
@ -201,7 +203,7 @@ void processRelease(const std::string& RELEASE, const YAML::Node& config) {
// Get current timestamp
std::time_t now_c = std::time(nullptr);
char timestamp[20];
std::strftime(timestamp, sizeof(timestamp), "%Y-%m-%d_%H:%M:%S", std::localtime(&now_c));
std::strftime(timestamp, sizeof(timestamp), "%Y%m%dT%H%M%S", std::gmtime(&now_c));
std::string BRITNEY_TIMESTAMP(timestamp);
std::cout << "Release: " << RELEASE << std::endl;

@ -1,4 +1,19 @@
#include "update_maintainer.h"
// Copyright (C) 2024 Simon Quigley <tsimonq2@ubuntu.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU 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 General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "update-maintainer.h"
#include <filesystem>
#include <fstream>
#include <iostream>
@ -57,19 +72,13 @@ static std::string get_distribution(const fs::path &changelog_file) {
if(!f) throw MaintainerUpdateException("Unable to open changelog.");
std::string first_line;
std::getline(f, first_line);
// Format: "pkg (ver) dist; urgency=..."
// find ') '
size_t pos = first_line.find(')');
if(pos == std::string::npos) throw MaintainerUpdateException("Invalid changelog format");
// after ') ', next token is distribution until space
// skip ')'
pos++;
while(pos < first_line.size() && std::isspace((unsigned char)first_line[pos])) pos++;
// now read until space or ';'
size_t start = pos;
while(pos < first_line.size() && !std::isspace((unsigned char)first_line[pos]) && first_line[pos] != ';') pos++;
std::string dist = first_line.substr(start, pos - start);
// remove -proposed-updates etc
size_t dashpos = dist.find('-');
if (dashpos != std::string::npos) {
dist = dist.substr(0, dashpos);
@ -202,3 +211,31 @@ void update_maintainer(const std::string &debian_directory, bool verbose) {
update_maintainer_file(*control_file, distribution, verbose);
}
int main(int argc, char** argv) {
if(argc < 2) {
std::cerr << "Usage: update-maintainer <debian_directory> [--verbose]" << std::endl;
return 1;
}
std::string debian_directory = argv[1];
bool verbose = false;
if(argc >=3 ) {
std::string flag = argv[2];
if(flag == "--verbose") {
verbose = true;
}
}
try {
update_maintainer(debian_directory, verbose);
if(verbose) {
std::cout << "Maintainer updated successfully." << std::endl;
}
} catch(const MaintainerUpdateException& e) {
std::cerr << "Error: " << e.what() << std::endl;
return 1;
}
return 0;
}

@ -0,0 +1,19 @@
// Copyright (C) 2024 Simon Quigley <tsimonq2@ubuntu.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU 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 General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <string>
void update_maintainer(const std::string &debian_directory, bool verbose=false);

@ -13,8 +13,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef UTILITIES_H
#define UTILITIES_H
#pragma once
#include <string>
#include <filesystem>
@ -38,5 +37,3 @@ void downloadFileWithTimestamping(const std::string& url, const std::filesystem:
// Helper function for libcurl write callback
size_t write_data(void* ptr, size_t size, size_t nmemb, void* stream);
#endif // UTILITIES_H

@ -1,17 +0,0 @@
cmake_minimum_required(VERSION 3.10)
project(fetch-indexes)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED True)
find_package(CURL REQUIRED)
find_package(ZLIB REQUIRED)
find_package(YAML-CPP REQUIRED)
include_directories(${CURL_INCLUDE_DIRS})
include_directories(${ZLIB_INCLUDE_DIRS})
include_directories(${YAML_CPP_INCLUDE_DIR})
include_directories(/srv/lubuntu-ci/repos/ci-tools/include/launchpadlib-cpp)
add_executable(fetch-indexes main.cpp utilities.cpp)
target_link_libraries(fetch-indexes ${CURL_LIBRARIES} ${ZLIB_LIBRARIES} yaml-cpp /srv/lubuntu-ci/repos/ci-tools/lib/liblaunchpad.so)
Loading…
Cancel
Save