Sort include directives within each block (separated by a blank line) in lexicographic order (except to prioritize `sys/types.h` first). First run `clang-format` with the config file: --- SortIncludes: false ... Commit the result temporarily. Then run `clang-format` again with: --- SortIncludes: true IncludeCategories: - Regex: 'sys/types.h' Priority: -1 ... Commit the result temporarily. Start a new branch and cherry-pick the second commit. Manually resolve conflicts to preserve indentation of re-ordered includes. This cleans up the include ordering without changing any other style. Use the following command to run `clang-format`: $ git ls-files -z -- \ '*.c' '*.cc' '*.cpp' '*.cxx' '*.h' '*.hh' '*.hpp' '*.hxx' | egrep -z -v '(Lexer|Parser|ParserHelper)\.' | egrep -z -v '^Source/cm_sha2' | egrep -z -v '^Source/(kwsys|CursesDialog/form)/' | egrep -z -v '^Utilities/(KW|cm).*/' | egrep -z -v '^Tests/Module/GenerateExportHeader' | egrep -z -v '^Tests/RunCMake/CommandLine/cmake_depends/test_UTF-16LE.h' | xargs -0 clang-format -i This selects source files that do not come from a third-party. Inspired-by: Daniel Pfeifer <daniel@pfeifer-mail.de>
136 lines
3.8 KiB
C++
136 lines
3.8 KiB
C++
/*============================================================================
|
|
CMake - Cross Platform Makefile Generator
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
see accompanying file Copyright.txt for details.
|
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
See the License for more information.
|
|
============================================================================*/
|
|
|
|
#include "cmCPackSTGZGenerator.h"
|
|
|
|
#include "cmCPackLog.h"
|
|
#include "cmGlobalGenerator.h"
|
|
#include "cmMakefile.h"
|
|
#include "cmSystemTools.h"
|
|
#include "cmake.h"
|
|
|
|
#include <sys/types.h>
|
|
#include <cmsys/FStream.hxx>
|
|
#include <sys/stat.h>
|
|
|
|
//----------------------------------------------------------------------
|
|
cmCPackSTGZGenerator::cmCPackSTGZGenerator()
|
|
{
|
|
}
|
|
|
|
//----------------------------------------------------------------------
|
|
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 << std::endl);
|
|
return 0;
|
|
}
|
|
this->SetOptionIfNotSet("CPACK_STGZ_HEADER_FILE", inFile.c_str());
|
|
this->SetOptionIfNotSet("CPACK_AT_SIGN", "@");
|
|
|
|
return this->Superclass::InitializeInternal();
|
|
}
|
|
|
|
//----------------------------------------------------------------------
|
|
int cmCPackSTGZGenerator::PackageFiles()
|
|
{
|
|
bool retval = true;
|
|
if ( !this->Superclass::PackageFiles() )
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
/* TGZ generator (our Superclass) may
|
|
* have generated several packages (component packaging)
|
|
* so we must iterate over generated packages.
|
|
*/
|
|
for (std::vector<std::string>::iterator it=packageFileNames.begin();
|
|
it != packageFileNames.end(); ++it)
|
|
{
|
|
retval &= cmSystemTools::SetPermissions((*it).c_str(),
|
|
#if defined( _MSC_VER ) || defined( __MINGW32__ )
|
|
S_IREAD | S_IWRITE | S_IEXEC
|
|
#else
|
|
S_IRUSR | S_IWUSR | S_IXUSR |
|
|
S_IRGRP | S_IWGRP | S_IXGRP |
|
|
S_IROTH | S_IWOTH | S_IXOTH
|
|
#endif
|
|
);
|
|
}
|
|
return retval;
|
|
}
|
|
|
|
//----------------------------------------------------------------------
|
|
int cmCPackSTGZGenerator::GenerateHeader(std::ostream* os)
|
|
{
|
|
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Writing header" << std::endl);
|
|
std::ostringstream str;
|
|
int counter = 0;
|
|
|
|
std::string inLicFile = this->GetOption("CPACK_RESOURCE_FILE_LICENSE");
|
|
std::string line;
|
|
cmsys::ifstream ilfs(inLicFile.c_str());
|
|
std::string licenseText;
|
|
while ( cmSystemTools::GetLineFromStream(ilfs, line) )
|
|
{
|
|
licenseText += line + "\n";
|
|
}
|
|
this->SetOptionIfNotSet("CPACK_RESOURCE_FILE_LICENSE_CONTENT",
|
|
licenseText.c_str());
|
|
|
|
const char headerLengthTag[] = "###CPACK_HEADER_LENGTH###";
|
|
|
|
// Create the header
|
|
std::string inFile = this->GetOption("CPACK_STGZ_HEADER_FILE");
|
|
cmsys::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_DEBUG,
|
|
"Number of lines: " << counter << std::endl);
|
|
char buffer[1024];
|
|
sprintf(buffer, "%d", counter);
|
|
cmSystemTools::ReplaceString(res, headerLengthTag, buffer);
|
|
|
|
// Write in file
|
|
*os << res;
|
|
return this->Superclass::GenerateHeader(os);
|
|
}
|