Commit b3083be7 authored by adridg's avatar adridg
Browse files

Update CMake's FreeBSD pkg(8) generator

There is an OPTION CPACK for CMake that enables a FreeBSD pkg(8)
generator: after building anything CMake-based, `cpack -G FREEBSD`
gives you a a ready-to-go installable package.

Well, assuming you turn the option on, and the bugs in the generator
are fixed. Which this patch does. I've tried it with supertux2
and some other bits and pieces and the patch is in a MR upstream.
parent d2ec4218
......@@ -4,6 +4,7 @@
PORTNAME= cmake
# Remember to update devel/cmake-doc and devel/cmake-gui as well.
DISTVERSION= 3.19.5
PORTREVISION= 1
CATEGORIES= devel
MASTER_SITES= https://github.com/Kitware/CMake/releases/download/v${DISTVERSION}/ \
https://www.cmake.org/files/v${PORTVERSION}/
......
Use newer pkg_create() API
diff --git Source/CPack/cmCPackFreeBSDGenerator.cxx Source/CPack/cmCPackFreeBSDGenerator.cxx
index b673006f25..63c7810b15 100644
--- Source/CPack/cmCPackFreeBSDGenerator.cxx
+++ Source/CPack/cmCPackFreeBSDGenerator.cxx
@@ -35,6 +35,56 @@ int cmCPackFreeBSDGenerator::InitializeInternal()
cmCPackFreeBSDGenerator::~cmCPackFreeBSDGenerator() = default;
+// This is a wrapper for struct pkg_create and pkg_create()
+//
+// Instantiate this class with suitable parameters, then
+// check isValid() to check if it's ok. Afterwards, call
+// Create() to do the actual work. This will leave a package
+// in the given `output_dir`.
+//
+// This wrapper cleans up the struct pkg_create.
+class PkgCreate
+{
+public:
+ PkgCreate()
+ : d(nullptr)
+ {
+ }
+ PkgCreate(const std::string& output_dir, const std::string& toplevel_dir,
+ const std::string& manifest_name)
+ : d(pkg_create_new())
+ , manifest(manifest_name)
+
+ {
+ if (d) {
+ pkg_create_set_format(d, "txz");
+ pkg_create_set_compression_level(d, 0); // Explicitly set default
+ pkg_create_set_overwrite(d, false);
+ pkg_create_set_rootdir(d, toplevel_dir.c_str());
+ pkg_create_set_output_dir(d, output_dir.c_str());
+ }
+ }
+ ~PkgCreate()
+ {
+ if (d)
+ pkg_create_free(d);
+ }
+
+ bool isValid() const { return d; }
+
+ bool Create()
+ {
+ if (!isValid())
+ return false;
+ int r = pkg_create(d, manifest.c_str(), nullptr, false);
+ return r == 0;
+ }
+
+private:
+ struct pkg_create* d;
+ std::string manifest;
+};
+
// This is a wrapper, for use only in stream-based output,
// that will output a string in UCL escaped fashion (in particular,
// quotes and backslashes are escaped). The list of characters
@@ -281,7 +331,7 @@ int cmCPackFreeBSDGenerator::PackageFiles()
{
if (!this->ReadListFile("Internal/CPack/CPackFreeBSD.cmake")) {
cmCPackLogger(cmCPackLog::LOG_ERROR,
- "Error while execution CPackFreeBSD.cmake" << std::endl);
+ "Error while executing CPackFreeBSD.cmake" << std::endl);
return 0;
}
@@ -317,9 +367,25 @@ int cmCPackFreeBSDGenerator::PackageFiles()
ONE_PACKAGE_PER_COMPONENT);
}
+ if (!pkg_initialized() && pkg_init(NULL, NULL) != EPKG_OK) {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Can not initialize FreeBSD libpkg." << std::endl);
+ return 0;
+ }
+
std::string output_dir = cmSystemTools::CollapseFullPath("../", toplevel);
- pkg_create_from_manifest(output_dir.c_str(), ::TXZ, toplevel.c_str(),
- manifestname.c_str(), nullptr);
+ PkgCreate package(output_dir, toplevel, manifestname);
+ if (package.isValid()) {
+ if (!package.Create()) {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error during pkg_create()" << std::endl);
+ return 0;
+ }
+ } else {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error before pkg_create()" << std::endl);
+ return 0;
+ }
std::string broken_suffix =
cmStrCat('-', var_lookup("CPACK_TOPLEVEL_TAG"), ".txz");
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment