pmt: Improvement.
- At build time, the version, compile time, CMake version, compiler version, and compiler flags are retrieved with the new CMake module and a header is created. This header provides more robust version management and notifications. - Build warnings fixed, code corrected for compilation. - Improvements were made to CMake code. - Modifications were made to the tests to read the library's version information.
This commit is contained in:
@@ -17,10 +17,6 @@
|
||||
#ifndef LIBHELPER_LIB_HPP
|
||||
#define LIBHELPER_LIB_HPP
|
||||
|
||||
#define LIBHELPER_MAJOR 1
|
||||
#define LIBHELPER_MINOR 0
|
||||
#define LIBHELPER_PATCH 0
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <sstream>
|
||||
@@ -114,11 +110,11 @@ bool eraseDirectoryRecursive(const std::string_view directory);
|
||||
|
||||
// Getters
|
||||
size_t fileSize(const std::string_view file);
|
||||
std::string_view readSymlink(const std::string_view entry);
|
||||
std::string readSymlink(const std::string_view entry);
|
||||
|
||||
// SHA-256
|
||||
bool sha256Compare(const std::string_view file1, const std::string_view file2);
|
||||
std::optional<std::string_view> sha256Of(const std::string_view path);
|
||||
std::optional<std::string> sha256Of(const std::string_view path);
|
||||
|
||||
// Utilities
|
||||
bool copyFile(const std::string_view file, const std::string_view dest);
|
||||
|
||||
@@ -74,8 +74,8 @@ bool isHardLink(const std::string_view entry)
|
||||
|
||||
bool areLinked(const std::string_view entry1, const std::string_view entry2)
|
||||
{
|
||||
const std::string_view st1 = (isSymbolicLink(entry1)) ? readSymlink(entry1) : entry1;
|
||||
const std::string_view st2 = (isSymbolicLink(entry2)) ? readSymlink(entry2) : entry2;
|
||||
const std::string st1 = (isSymbolicLink(entry1)) ? readSymlink(entry1) : std::string(entry1.data());
|
||||
const std::string st2 = (isSymbolicLink(entry2)) ? readSymlink(entry2) : std::string(entry2.data());
|
||||
|
||||
return (st1 == st2);
|
||||
}
|
||||
|
||||
@@ -223,13 +223,13 @@ bool eraseDirectoryRecursive(const std::string_view directory)
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string_view readSymlink(const std::string_view entry)
|
||||
std::string readSymlink(const std::string_view entry)
|
||||
{
|
||||
char target[PATH_MAX];
|
||||
ssize_t len = readlink(entry.data(), target, (sizeof(target) - 1));
|
||||
if (len == -1) {
|
||||
throw Error("Cannot read symlink %s: %s", entry.data(), strerror(errno));
|
||||
return entry;
|
||||
return entry.data();
|
||||
}
|
||||
|
||||
target[len] = '\0';
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
namespace Helper {
|
||||
|
||||
std::optional<std::string_view> sha256Of(const std::string_view path)
|
||||
std::optional<std::string> sha256Of(const std::string_view path)
|
||||
{
|
||||
if (!fileIsExists(path)) {
|
||||
throw Error("Is not exists or not file: %s", path.data());
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <time.h>
|
||||
#include <libgen.h>
|
||||
#include <libhelper/lib.hpp>
|
||||
#include <generated/buildInfo.hpp>
|
||||
|
||||
namespace Helper {
|
||||
|
||||
@@ -130,11 +131,9 @@ std::string pathDirname(const std::string_view entry)
|
||||
|
||||
std::string getLibVersion()
|
||||
{
|
||||
return std::string(
|
||||
std::to_string(LIBHELPER_MAJOR) + "."
|
||||
+ std::to_string(LIBHELPER_MINOR) + "."
|
||||
+ std::to_string(LIBHELPER_PATCH)
|
||||
);
|
||||
char vinfo[512];
|
||||
sprintf(vinfo, "libhelper %s [%s %s]\nBuildType: %s\nCMakeVersion: %s\nCompilerVersion: %s\nBuildFlags: %s\n", BUILD_VERSION, BUILD_DATE, BUILD_TIME, BUILD_TYPE, BUILD_CMAKE_VERSION, BUILD_COMPILER_VERSION, BUILD_FLAGS);
|
||||
return std::string(vinfo);
|
||||
}
|
||||
|
||||
} // namespace Helper
|
||||
|
||||
@@ -88,6 +88,8 @@ int main(int argc, char** argv)
|
||||
std::cout << "pathJoin() test 3: " << Helper::pathJoin("mydir/", "/dir2") << std::endl;
|
||||
std::cout << "pathJoin() test 4: " << Helper::pathJoin("mydir", "/dir2") << std::endl;
|
||||
|
||||
std::cout << Helper::getLibVersion() << std::endl;
|
||||
|
||||
LOG(INFO) << "Info message" << std::endl;
|
||||
LOG(WARNING) << "Warning message" << std::endl;
|
||||
LOG(ERROR) << "Error message" << std::endl;
|
||||
|
||||
@@ -17,10 +17,6 @@
|
||||
#ifndef LIBPARTITION_MAP_LIB_HPP
|
||||
#define LIBPARTITION_MAP_LIB_HPP
|
||||
|
||||
#define LIBPARTITION_MAP_MAJOR 1
|
||||
#define LIBPARTITION_MAP_MINOR 0
|
||||
#define LIBPARTITION_MAP_PATCH 0
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <optional>
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/fs.h>
|
||||
#include <libpartition_map/lib.hpp>
|
||||
#include <generated/buildInfo.hpp>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -199,11 +200,9 @@ bool basic_partition_map_builder::operator!() const
|
||||
|
||||
std::string getLibVersion()
|
||||
{
|
||||
return std::string(
|
||||
std::to_string(LIBPARTITION_MAP_MAJOR) + "."
|
||||
+ std::to_string(LIBPARTITION_MAP_MINOR) + "."
|
||||
+ std::to_string(LIBPARTITION_MAP_PATCH)
|
||||
);
|
||||
char vinfo[512];
|
||||
sprintf(vinfo, "libpartition_map %s [%s %s]\nBuildType: %s\nCMakeVersion: %s\nCompilerVersion: %s\nBuildFlags: %s\n", BUILD_VERSION, BUILD_DATE, BUILD_TIME, BUILD_TYPE, BUILD_CMAKE_VERSION, BUILD_COMPILER_VERSION, BUILD_FLAGS);
|
||||
return std::string(vinfo);
|
||||
}
|
||||
|
||||
} // namespace PartitionMap
|
||||
|
||||
@@ -69,6 +69,8 @@ int main(void) {
|
||||
|
||||
if (MyMap == MyMap2) std::cout << "map1 = map2" << std::endl;
|
||||
if (MyMap != MyMap2) std::cout << "map1 != map2" << std::endl;
|
||||
|
||||
std::cout << PartitionMap::getLibVersion() << std::endl;
|
||||
} catch (PartitionMap::Error& error) {
|
||||
std::cerr << error.what() << std::endl;
|
||||
return 1;
|
||||
|
||||
Reference in New Issue
Block a user