1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
3 #include "cmCPackCygwinSourceGenerator.h"
5 #include "cmsys/SystemTools.hxx"
7 #include "cmCPackLog.h"
8 #include "cmGeneratedFileStream.h"
9 #include "cmGlobalGenerator.h"
10 #include "cmMakefile.h"
11 #include "cmSystemTools.h"
15 // Includes needed for implementation of RenameFile. This is not in
16 // system tools because it is not implemented robustly enough to move
17 // files across directories.
21 # include "cm_sys_stat.h"
24 cmCPackCygwinSourceGenerator::cmCPackCygwinSourceGenerator()
25 : cmCPackArchiveGenerator(cmArchiveWrite::CompressBZip2
, "paxr", ".tar.bz2")
29 cmCPackCygwinSourceGenerator::~cmCPackCygwinSourceGenerator() = default;
31 int cmCPackCygwinSourceGenerator::InitializeInternal()
33 this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "0");
34 return this->Superclass::InitializeInternal();
37 int cmCPackCygwinSourceGenerator::PackageFiles()
39 // Create a tar file of the sources
40 std::string packageDirFileName
=
41 cmStrCat(this->GetOption("CPACK_TEMPORARY_DIRECTORY"), ".tar.bz2");
42 packageFileNames
[0] = packageDirFileName
;
44 // create tar.bz2 file with the list of source files
45 if (!this->cmCPackArchiveGenerator::PackageFiles()) {
48 // Now create a tar file that contains the above .tar.bz2 file
49 // and the CPACK_CYGWIN_PATCH_FILE and CPACK_TOPLEVEL_DIRECTORY
51 const std::string
& compressOutFile
= packageDirFileName
;
52 // at this point compressOutFile is the full path to
53 // _CPack_Package/.../package-2.5.0.tar.bz2
54 // we want to create a tar _CPack_Package/.../package-2.5.0-1-src.tar.bz2
56 // _CPack_Package/.../package-2.5.0-1.patch
57 // _CPack_Package/.../package-2.5.0-1.sh
58 // _CPack_Package/.../package-2.5.0.tar.bz2
59 // the -1 is CPACK_CYGWIN_PATCH_NUMBER
61 // first copy the patch file and the .sh file
62 // to the toplevel cpack temp dir
64 // copy the patch file into place
65 if (!this->GetOption("CPACK_CYGWIN_PATCH_FILE")) {
66 cmCPackLogger(cmCPackLog::LOG_ERROR
,
67 "No patch file specified for cygwin sources.");
70 if (!cmSystemTools::CopyFileAlways(
71 this->GetOption("CPACK_CYGWIN_PATCH_FILE"),
72 this->GetOption("CPACK_TOPLEVEL_DIRECTORY"))) {
73 cmCPackLogger(cmCPackLog::LOG_ERROR
,
75 << this->GetOption("CPACK_CYGWIN_PATCH_FILE") << "]\nto\n["
76 << this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "]\n");
79 if (!this->GetOption("CPACK_CYGWIN_BUILD_SCRIPT")) {
80 cmCPackLogger(cmCPackLog::LOG_ERROR
,
81 "No build script specified for cygwin sources.");
84 // copy the build script into place
85 if (!cmSystemTools::CopyFileAlways(
86 this->GetOption("CPACK_CYGWIN_BUILD_SCRIPT"),
87 this->GetOption("CPACK_TOPLEVEL_DIRECTORY"))) {
88 cmCPackLogger(cmCPackLog::LOG_ERROR
,
90 << this->GetOption("CPACK_CYGWIN_BUILD_SCRIPT") << "\nto\n"
91 << this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "]\n");
94 std::string outerTarFile
=
95 cmStrCat(this->GetOption("CPACK_TEMPORARY_DIRECTORY"), '-');
96 cmValue patch
= this->GetOption("CPACK_CYGWIN_PATCH_NUMBER");
98 cmCPackLogger(cmCPackLog::LOG_WARNING
,
99 "CPACK_CYGWIN_PATCH_NUMBER"
100 << " not specified, defaulting to 1\n");
103 outerTarFile
+= patch
;
105 outerTarFile
+= "-src.tar.bz2";
106 std::string tmpDir
= this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
107 std::string buildScript
=
108 cmStrCat(tmpDir
, '/',
109 cmSystemTools::GetFilenameName(
110 this->GetOption("CPACK_CYGWIN_BUILD_SCRIPT")));
111 std::string patchFile
=
112 cmStrCat(tmpDir
, '/',
113 cmSystemTools::GetFilenameName(
114 this->GetOption("CPACK_CYGWIN_PATCH_FILE")));
116 std::string file
= cmSystemTools::GetFilenameName(compressOutFile
);
117 std::string sourceTar
=
118 cmStrCat(cmSystemTools::GetFilenamePath(compressOutFile
), '/', file
);
119 /* reset list of file to be packaged */
121 // a source release in cygwin should have the build script used
122 // to build the package, the patch file that is different from the
123 // regular upstream version of the sources, and a bziped tar file
124 // of the original sources
125 files
.push_back(buildScript
);
126 files
.push_back(patchFile
);
127 files
.push_back(sourceTar
);
128 /* update the name of the produced package */
129 packageFileNames
[0] = outerTarFile
;
130 /* update the toplevel dir */
132 if (!this->cmCPackArchiveGenerator::PackageFiles()) {
138 const char* cmCPackCygwinSourceGenerator::GetPackagingInstallPrefix()
140 this->InstallPrefix
=
141 cmStrCat('/', this->GetOption("CPACK_PACKAGE_FILE_NAME"));
142 return this->InstallPrefix
.c_str();
145 const char* cmCPackCygwinSourceGenerator::GetOutputExtension()
147 this->OutputExtension
= "-";
148 cmValue patch
= this->GetOption("CPACK_CYGWIN_PATCH_NUMBER");
150 cmCPackLogger(cmCPackLog::LOG_WARNING
,
151 "CPACK_CYGWIN_PATCH_NUMBER"
152 << " not specified, defaulting to 1\n");
153 this->OutputExtension
+= '1';
155 this->OutputExtension
+= patch
;
157 this->OutputExtension
+= "-src.tar.bz2";
158 return this->OutputExtension
.c_str();