cmCPackCygwinSourceGenerator.cxx 5.45 KB
Newer Older
1 2
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file Copyright.txt or https://cmake.org/licensing for details.  */
3 4
#include "cmCPackCygwinSourceGenerator.h"

5 6
#include "cmCPackLog.h"
#include "cmGeneratedFileStream.h"
7 8
#include "cmGlobalGenerator.h"
#include "cmMakefile.h"
9 10
#include "cmSystemTools.h"
#include "cmake.h"
11

12
#include "cmsys/SystemTools.hxx"
13 14 15 16 17

// Includes needed for implementation of RenameFile.  This is not in
// system tools because it is not implemented robustly enough to move
// files across directories.
#ifdef _WIN32
18 19
#  include "cm_sys_stat.h"
#  include <windows.h>
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#endif

cmCPackCygwinSourceGenerator::cmCPackCygwinSourceGenerator()
{
}

cmCPackCygwinSourceGenerator::~cmCPackCygwinSourceGenerator()
{
}

int cmCPackCygwinSourceGenerator::InitializeInternal()
{
  this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "0");
  return this->Superclass::InitializeInternal();
}

36
int cmCPackCygwinSourceGenerator::PackageFiles()
37
{
38
  // Create a tar file of the sources
39
  std::string packageDirFileName =
40
    cmStrCat(this->GetOption("CPACK_TEMPORARY_DIRECTORY"), ".tar.bz2");
41
  packageFileNames[0] = packageDirFileName;
42
  std::string output;
43 44 45
  // skip one parent up to the cmCPackTarBZip2Generator
  // to create tar.bz2 file with the list of source
  // files
46
  this->Compress = cmArchiveWrite::CompressBZip2;
47
  if (!this->cmCPackTarBZip2Generator::PackageFiles()) {
48
    return 0;
49
  }
50 51 52
  // Now create a tar file that contains the above .tar.bz2 file
  // and the CPACK_CYGWIN_PATCH_FILE and CPACK_TOPLEVEL_DIRECTORY
  // files
53
  std::string compressOutFile = packageDirFileName;
54
  // at this point compressOutFile is the full path to
55 56
  // _CPack_Package/.../package-2.5.0.tar.bz2
  // we want to create a tar _CPack_Package/.../package-2.5.0-1-src.tar.bz2
57 58
  // with these
  //   _CPack_Package/.../package-2.5.0-1.patch
59 60 61
  //   _CPack_Package/.../package-2.5.0-1.sh
  //   _CPack_Package/.../package-2.5.0.tar.bz2
  // the -1 is CPACK_CYGWIN_PATCH_NUMBER
62

63 64
  // first copy the patch file and the .sh file
  // to the toplevel cpack temp dir
65

66
  // copy the patch file into place
67
  if (!this->GetOption("CPACK_CYGWIN_PATCH_FILE")) {
68 69 70
    cmCPackLogger(cmCPackLog::LOG_ERROR,
                  "No patch file specified for cygwin sources.");
    return 0;
71 72 73 74
  }
  if (!cmSystemTools::CopyFileAlways(
        this->GetOption("CPACK_CYGWIN_PATCH_FILE"),
        this->GetOption("CPACK_TOPLEVEL_DIRECTORY"))) {
75 76
    cmCPackLogger(cmCPackLog::LOG_ERROR,
                  "problem copying: ["
77 78
                    << this->GetOption("CPACK_CYGWIN_PATCH_FILE") << "]\nto\n["
                    << this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "]\n");
79
    return 0;
80 81
  }
  if (!this->GetOption("CPACK_CYGWIN_BUILD_SCRIPT")) {
82
    cmCPackLogger(cmCPackLog::LOG_ERROR,
83 84
                  "No build script specified for cygwin sources.");
    return 0;
85
  }
86
  // copy the build script into place
87 88 89
  if (!cmSystemTools::CopyFileAlways(
        this->GetOption("CPACK_CYGWIN_BUILD_SCRIPT"),
        this->GetOption("CPACK_TOPLEVEL_DIRECTORY"))) {
90 91
    cmCPackLogger(cmCPackLog::LOG_ERROR,
                  "problem copying: "
92 93
                    << this->GetOption("CPACK_CYGWIN_BUILD_SCRIPT") << "\nto\n"
                    << this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "]\n");
94
    return 0;
95
  }
96 97
  std::string outerTarFile =
    cmStrCat(this->GetOption("CPACK_TEMPORARY_DIRECTORY"), '-');
98
  const char* patch = this->GetOption("CPACK_CYGWIN_PATCH_NUMBER");
99
  if (!patch) {
100 101
    cmCPackLogger(cmCPackLog::LOG_WARNING,
                  "CPACK_CYGWIN_PATCH_NUMBER"
102
                    << " not specified, defaulting to 1\n");
103
    patch = "1";
104
  }
105
  outerTarFile += patch;
106 107
  outerTarFile += "-src.tar.bz2";
  std::string tmpDir = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
108 109 110 111 112 113 114 115
  std::string buildScript =
    cmStrCat(tmpDir, '/',
             cmSystemTools::GetFilenameName(
               this->GetOption("CPACK_CYGWIN_BUILD_SCRIPT")));
  std::string patchFile =
    cmStrCat(tmpDir, '/',
             cmSystemTools::GetFilenameName(
               this->GetOption("CPACK_CYGWIN_PATCH_FILE")));
116

117
  std::string file = cmSystemTools::GetFilenameName(compressOutFile);
118 119
  std::string sourceTar =
    cmStrCat(cmSystemTools::GetFilenamePath(compressOutFile), '/', file);
120 121
  /* reset list of file to be packaged */
  files.clear();
122 123 124 125
  // a source release in cygwin should have the build script used
  // to build the package, the patch file that is different from the
  // regular upstream version of the sources, and a bziped tar file
  // of the original sources
126 127 128 129 130 131 132
  files.push_back(buildScript);
  files.push_back(patchFile);
  files.push_back(sourceTar);
  /* update the name of the produced package */
  packageFileNames[0] = outerTarFile;
  /* update the toplevel dir */
  toplevel = tmpDir;
133
  if (!this->cmCPackTarBZip2Generator::PackageFiles()) {
134
    return 0;
135
  }
136 137 138
  return 1;
}

139
const char* cmCPackCygwinSourceGenerator::GetPackagingInstallPrefix()
140
{
141 142
  this->InstallPrefix =
    cmStrCat('/', this->GetOption("CPACK_PACKAGE_FILE_NAME"));
143 144 145 146 147 148
  return this->InstallPrefix.c_str();
}

const char* cmCPackCygwinSourceGenerator::GetOutputExtension()
{
  this->OutputExtension = "-";
149
  const char* patch = this->GetOption("CPACK_CYGWIN_PATCH_NUMBER");
150
  if (!patch) {
151 152
    cmCPackLogger(cmCPackLog::LOG_WARNING,
                  "CPACK_CYGWIN_PATCH_NUMBER"
153
                    << " not specified, defaulting to 1\n");
154
    patch = "1";
155
  }
156
  this->OutputExtension += patch;
157 158 159
  this->OutputExtension += "-src.tar.bz2";
  return this->OutputExtension.c_str();
}