ENH: More cleanups and add stgz header script, so it does not have to be hard-coded. Also, the user can overwrite it
This commit is contained in:
parent
77771481dd
commit
4709c76f0f
|
@ -0,0 +1,89 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Display usage
|
||||
cpack_usage()
|
||||
{
|
||||
cat <<EOF
|
||||
Usage: $0 [options]
|
||||
Options: [defaults in brackets after descriptions]
|
||||
--help print this message
|
||||
--prefix=dir directory in which to install
|
||||
--include-subdir include the @CPACK_PACKAGE_FILE_NAME@ subdirectory
|
||||
--exclude-subdir exclude the @CPACK_PACKAGE_FILE_NAME@ subdirectory
|
||||
EOF
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Display version
|
||||
cpack_version()
|
||||
{
|
||||
echo "@CPACK_PACKAGE_NAME@ Installer Version: @CPACK_PACKAGE_VERSION@, Copyright (c) @CPACK_PACKAGE_VENDOR@"
|
||||
}
|
||||
|
||||
# Helper function to fix windows paths.
|
||||
cpack_fix_slashes ()
|
||||
{
|
||||
echo "$1" | sed 's/\\/\//g'
|
||||
}
|
||||
|
||||
|
||||
for a in "$@CPACK_AT_SIGN@"; do
|
||||
if echo $a | grep "^--prefix=" > /dev/null 2> /dev/null; then
|
||||
cpack_prefix_dir=`echo $a | sed "s/^--prefix=//"`
|
||||
cpack_prefix_dir=`cpack_fix_slashes "${cpack_prefix_dir}"`
|
||||
fi
|
||||
if echo $a | grep "^--help" > /dev/null 2> /dev/null; then
|
||||
cpack_usage
|
||||
fi
|
||||
if echo $a | grep "^--version" > /dev/null 2> /dev/null; then
|
||||
cpack_version
|
||||
exit 2
|
||||
fi
|
||||
if echo $a | grep "^--include-subdir" > /dev/null 2> /dev/null; then
|
||||
cpack_include_subdir=TRUE
|
||||
fi
|
||||
if echo $a | grep "^--exclude-subdir" > /dev/null 2> /dev/null; then
|
||||
cpack_include_subdir=FALSE
|
||||
fi
|
||||
done
|
||||
|
||||
cpack_version
|
||||
echo "This is a self-extracting archive."
|
||||
toplevel="`pwd`"
|
||||
if [ "x${cpack_prefix_dir}x" != "xx" ]
|
||||
then
|
||||
toplevel="${cpack_prefix_dir}"
|
||||
fi
|
||||
|
||||
echo "The archive will be extracted to: ${toplevel}"
|
||||
echo ""
|
||||
|
||||
if [ "x${cpack_include_subdir}x" == "xx" ]
|
||||
then
|
||||
echo "If you want to stop extracting, please press <ctrl-C>."
|
||||
echo "Include the subdirectory @CPACK_PACKAGE_FILE_NAME@" [Yn]:
|
||||
read line
|
||||
if [ "x${line}x" != "xnx" -a "x${line}x" != "xNx" ]
|
||||
then
|
||||
cpack_include_subdir=TRUE
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "x${cpack_include_subdir}x" == "xTRUEx" ]
|
||||
then
|
||||
toplevel="${toplevel}/@CPACK_PACKAGE_FILE_NAME@"
|
||||
mkdir -p "${toplevel}"
|
||||
fi
|
||||
echo "Extracting... Please wait..."
|
||||
echo ""
|
||||
|
||||
# take the archive portion of this file and pipe it to tar
|
||||
# the NUMERIC parameter in this command should be one more
|
||||
# than the number of lines in this header file
|
||||
tail -n +###CPACK_HEADER_LENGTH### "$0" | gunzip | (cd "${toplevel}" && tar xf -)
|
||||
|
||||
exit 0
|
||||
#-----------------------------------------------------------
|
||||
# Start of TAR.GZ file
|
||||
#-----------------------------------------------------------;
|
||||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -761,6 +768,15 @@ std::string cmCPackGenericGenerator::FindTemplate(const char* name)
|
|||
return ffile;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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"; }
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue