summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/CPack/cmCPackGenericGenerator.cxx18
-rw-r--r--Source/CPack/cmCPackGenericGenerator.h3
-rw-r--r--Source/CPack/cmCPackSTGZGenerator.cxx98
-rw-r--r--Source/CPack/cmCPackSTGZGenerator.h2
-rw-r--r--Source/CPack/cpack.cxx6
-rw-r--r--Source/cmFileCommand.cxx4
6 files changed, 99 insertions, 32 deletions
diff --git a/Source/CPack/cmCPackGenericGenerator.cxx b/Source/CPack/cmCPackGenericGenerator.cxx
index 7d7975e..1f8aca6 100644
--- a/Source/CPack/cmCPackGenericGenerator.cxx
+++ b/Source/CPack/cmCPackGenericGenerator.cxx
@@ -532,10 +532,17 @@ int cmCPackGenericGenerator::ProcessGenerator()
}
//----------------------------------------------------------------------
-int cmCPackGenericGenerator::Initialize(const char* name, cmMakefile* mf)
+int cmCPackGenericGenerator::Initialize(const char* name, cmMakefile* mf,
+ const char* argv0)
{
this->MakefileMap = mf;
this->Name = name;
+ if ( !this->FindRunningCMake(argv0) )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Cannot initialize the generator" << std::endl);
+ return 0;
+ }
return this->InitializeInternal();
}
@@ -762,6 +769,15 @@ std::string cmCPackGenericGenerator::FindTemplate(const char* name)
}
//----------------------------------------------------------------------
+bool cmCPackGenericGenerator::ConfigureString(const std::string& inString,
+ std::string& outString)
+{
+ this->MakefileMap->ConfigureString(inString,
+ outString, true, false);
+ return true;
+}
+
+//----------------------------------------------------------------------
bool cmCPackGenericGenerator::ConfigureFile(const char* inName,
const char* outName)
{
diff --git a/Source/CPack/cmCPackGenericGenerator.h b/Source/CPack/cmCPackGenericGenerator.h
index 40e8740..6867613 100644
--- a/Source/CPack/cmCPackGenericGenerator.h
+++ b/Source/CPack/cmCPackGenericGenerator.h
@@ -68,7 +68,7 @@ public:
/**
* Initialize generator
*/
- int Initialize(const char* name, cmMakefile* mf);
+ int Initialize(const char* name, cmMakefile* mf, const char* argv0);
/**
* Construct generator
@@ -100,6 +100,7 @@ protected:
virtual std::string FindTemplate(const char* name);
virtual bool ConfigureFile(const char* inName, const char* outName);
+ virtual bool ConfigureString(const std::string& input, std::string& output);
virtual int InitializeInternal();
bool GeneratorVerbose;
diff --git a/Source/CPack/cmCPackSTGZGenerator.cxx b/Source/CPack/cmCPackSTGZGenerator.cxx
index 1ce9935..d31b120 100644
--- a/Source/CPack/cmCPackSTGZGenerator.cxx
+++ b/Source/CPack/cmCPackSTGZGenerator.cxx
@@ -24,6 +24,11 @@
#include "cmMakefile.h"
#include "cmCPackLog.h"
+#include "CPack/cmCPackSTGZGeneratorEncodedHeader.h"
+
+#include <cmsys/ios/sstream>
+#include <sys/types.h>
+#include <sys/stat.h>
//----------------------------------------------------------------------
cmCPackSTGZGenerator::cmCPackSTGZGenerator()
@@ -39,36 +44,81 @@ cmCPackSTGZGenerator::~cmCPackSTGZGenerator()
int cmCPackSTGZGenerator::InitializeInternal()
{
this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "0");
+
+ std::string inFile = this->FindTemplate("CPack.STGZ_Header.sh.in");
+ if ( inFile.empty() )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find template file: "
+ << inFile.c_str() << std::endl);
+ return 0;
+ }
+ this->SetOptionIfNotSet("CPACK_STGZ_HEADER_FILE", inFile.c_str());
+ this->SetOption("CPACK_AT_SIGN", "@");
+
return this->Superclass::InitializeInternal();
}
//----------------------------------------------------------------------
+int cmCPackSTGZGenerator::CompressFiles(const char* outFileName,
+ const char* toplevel, const std::vector<std::string>& files)
+{
+ if ( !this->Superclass::CompressFiles(outFileName, toplevel, files) )
+ {
+ return 0;
+ }
+ return cmSystemTools::SetPermissions(outFileName,
+#if defined( _MSC_VER ) || defined( __MINGW32__ )
+ S_IREAD | S_IWRITE | S_IEXEC
+#elif defined( __BORLANDC__ )
+ S_IRUSR | S_IWUSR | S_IXUSR
+#else
+ S_IRUSR | S_IWUSR | S_IXUSR |
+ S_IRGRP | S_IWGRP | S_IXGRP |
+ S_IROTH | S_IWOTH | S_IXOTH
+#endif
+ );
+}
+
+//----------------------------------------------------------------------
int cmCPackSTGZGenerator::GenerateHeader(std::ostream* os)
{
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Writing header" << std::endl);
- *os
- << "#!/bin/sh" << std::endl
- << "echo \"" << this->GetOption("CPACK_PACKAGE_NAME")
- << " - self-extracting archive.\"" << std::endl
- << "echo \"If you want to stop extracting, please press <ctrl-C>.\""
- << std::endl
- << "read line" << std::endl
- << "echo \"Extracting... Please wait...\"" << std::endl
- << "echo \"\"" << std::endl
- << "" << std::endl
- << "# take the archive portion of this file and pipe it to tar"
- << std::endl
- << "# the NUMERIC parameter in this command should be one more"
- << std::endl
- << "# than the number of lines in this header file" << std::endl
- << "tail +18 \"$0\" | gunzip | tar xf -" << std::endl
- << "" << std::endl
- << "exit 0" << std::endl
- << "echo \"\"" << std::endl
- << "#-----------------------------------------------------------"
- << std::endl
- << "# Start of TAR.GZ file" << std::endl
- << "#-----------------------------------------------------------"
- << std::endl;
+ cmsys_ios::ostringstream str;
+ int counter = 0;
+
+ const char headerLengthTag[] = "###CPACK_HEADER_LENGTH###";
+
+ // Create the header
+ std::string inFile = this->GetOption("CPACK_STGZ_HEADER_FILE");
+ std::string line;
+ std::ifstream ifs(inFile.c_str());
+ std::string packageHeaderText;
+ while ( cmSystemTools::GetLineFromStream(ifs, line) )
+ {
+ packageHeaderText += line + "\n";
+ }
+
+ // Configure in the values
+ std::string res;
+ this->ConfigureString(packageHeaderText, res);
+
+ // Count the lines
+ const char* ptr = res.c_str();
+ while ( *ptr )
+ {
+ if ( *ptr == '\n' )
+ {
+ counter ++;
+ }
+ ++ptr;
+ }
+ counter ++;
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Counter: " << counter << std::endl);
+ char buffer[1024];
+ sprintf(buffer, "%d", counter);
+ cmSystemTools::ReplaceString(res, headerLengthTag, buffer);
+
+ // Write in file
+ *os << res.c_str();
return this->Superclass::GenerateHeader(os);
}
diff --git a/Source/CPack/cmCPackSTGZGenerator.h b/Source/CPack/cmCPackSTGZGenerator.h
index 050da9d..5d7ead8 100644
--- a/Source/CPack/cmCPackSTGZGenerator.h
+++ b/Source/CPack/cmCPackSTGZGenerator.h
@@ -37,6 +37,8 @@ public:
virtual ~cmCPackSTGZGenerator();
protected:
+ int CompressFiles(const char* outFileName, const char* toplevel,
+ const std::vector<std::string>& files);
virtual int InitializeInternal();
int GenerateHeader(std::ostream* os);
virtual const char* GetOutputExtension() { return "sh"; }
diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx
index 8dff672..fa4afb1 100644
--- a/Source/CPack/cpack.cxx
+++ b/Source/CPack/cpack.cxx
@@ -338,11 +338,7 @@ int main (int argc, char *argv[])
<< generator.c_str() << std::endl);
parsed = 0;
}
- if ( parsed && !cpackGenerator->Initialize(gen, mf) )
- {
- parsed = 0;
- }
- if ( parsed && !cpackGenerator->FindRunningCMake(argv[0]) )
+ if ( parsed && !cpackGenerator->Initialize(gen, mf, argv[0]) )
{
cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"Cannot initialize the generator" << std::endl);
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx
index 2808c58..68bc52d 100644
--- a/Source/cmFileCommand.cxx
+++ b/Source/cmFileCommand.cxx
@@ -108,7 +108,9 @@ bool cmFileCommand::HandleWriteCommand(std::vector<std::string> const& args,
}
if ( !this->Makefile->CanIWriteThisFile(fileName.c_str()) )
{
- std::string e = "attempted to write a file: " + fileName + " into a source directory.";
+ std::string e
+ = "attempted to write a file: " + fileName +
+ " into a source directory.";
this->SetError(e.c_str());
cmSystemTools::SetFatalErrorOccured();
return false;