Merge topic 'cmake-E-tar-files-from'

44fd71de cmake: Teach "-E tar" command a "--files-from=" option
This commit is contained in:
Brad King 2015-01-27 11:22:08 -05:00 committed by CMake Topic Stage
commit af9cf04647
16 changed files with 82 additions and 0 deletions

View File

@ -0,0 +1,6 @@
cmake-E-tar-files-from
----------------------
* The :manual:`cmake(1)` ``-E tar`` command learned a new
``--files-from=<file>`` option to specify file names using
lines in a file to overcome command-line length limits.

View File

@ -94,6 +94,51 @@ void CMakeCommandUsage(const char* program)
cmSystemTools::Error(errorStream.str().c_str()); cmSystemTools::Error(errorStream.str().c_str());
} }
static bool cmTarFilesFrom(std::string const& file,
std::vector<std::string>& files)
{
if (cmSystemTools::FileIsDirectory(file))
{
std::ostringstream e;
e << "-E tar --files-from= file '" << file << "' is a directory";
cmSystemTools::Error(e.str().c_str());
return false;
}
cmsys::ifstream fin(file.c_str());
if (!fin)
{
std::ostringstream e;
e << "-E tar --files-from= file '" << file << "' not found";
cmSystemTools::Error(e.str().c_str());
return false;
}
std::string line;
while (cmSystemTools::GetLineFromStream(fin, line))
{
if (line.empty())
{
continue;
}
if (cmHasLiteralPrefix(line, "--add-file="))
{
files.push_back(line.substr(11));
}
else if (cmHasLiteralPrefix(line, "-"))
{
std::ostringstream e;
e << "-E tar --files-from='" << file << "' file invalid line:\n"
<< line << "\n";
cmSystemTools::Error(e.str().c_str());
return false;
}
else
{
files.push_back(line);
}
}
return true;
}
int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args) int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
{ {
// IF YOU ADD A NEW COMMAND, DOCUMENT IT ABOVE and in cmakemain.cxx // IF YOU ADD A NEW COMMAND, DOCUMENT IT ABOVE and in cmakemain.cxx
@ -744,6 +789,14 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
{ {
mtime = arg.substr(8); mtime = arg.substr(8);
} }
else if (cmHasLiteralPrefix(arg, "--files-from="))
{
std::string const& files_from = arg.substr(13);
if (!cmTarFilesFrom(files_from, files))
{
return 1;
}
}
else else
{ {
cmSystemTools::Error("Unknown option to -E tar: ", arg.c_str()); cmSystemTools::Error("Unknown option to -E tar: ", arg.c_str());

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1 @@
^CMake Error: -E tar --files-from= file 'bad' not found$

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1 @@
^CMake Error: -E tar --files-from= file '\.' is a directory$

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,2 @@
^CMake Error: -E tar --files-from='.*/Tests/RunCMake/CommandLine/E_tar-bad-from3.txt' file invalid line:
-add-file=option-typo$

View File

@ -0,0 +1 @@
-add-file=option-typo

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,2 @@
^CMake Error: archive_read_disk_entry_from_file 'does-not-exist':.*
CMake Error: Problem creating tar: bad.tar$

View File

@ -0,0 +1,2 @@
does-not-exist

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,2 @@
^CMake Error: archive_read_disk_entry_from_file 'does-not-exist':.*
CMake Error: Problem creating tar: bad.tar$

View File

@ -0,0 +1,2 @@
--add-file=does-not-exist

View File

@ -2,6 +2,11 @@ include(RunCMake)
run_cmake_command(E_tar-bad-opt1 ${CMAKE_COMMAND} -E tar cvf bad.tar --bad) run_cmake_command(E_tar-bad-opt1 ${CMAKE_COMMAND} -E tar cvf bad.tar --bad)
run_cmake_command(E_tar-bad-mtime1 ${CMAKE_COMMAND} -E tar cvf bad.tar --mtime=bad .) run_cmake_command(E_tar-bad-mtime1 ${CMAKE_COMMAND} -E tar cvf bad.tar --mtime=bad .)
run_cmake_command(E_tar-bad-from1 ${CMAKE_COMMAND} -E tar cvf bad.tar --files-from=bad)
run_cmake_command(E_tar-bad-from2 ${CMAKE_COMMAND} -E tar cvf bad.tar --files-from=.)
run_cmake_command(E_tar-bad-from3 ${CMAKE_COMMAND} -E tar cvf bad.tar --files-from=${CMAKE_CURRENT_LIST_DIR}/E_tar-bad-from3.txt)
run_cmake_command(E_tar-bad-from4 ${CMAKE_COMMAND} -E tar cvf bad.tar --files-from=${CMAKE_CURRENT_LIST_DIR}/E_tar-bad-from4.txt)
run_cmake_command(E_tar-bad-from5 ${CMAKE_COMMAND} -E tar cvf bad.tar --files-from=${CMAKE_CURRENT_LIST_DIR}/E_tar-bad-from5.txt)
run_cmake_command(E_tar-end-opt1 ${CMAKE_COMMAND} -E tar cvf bad.tar -- --bad) run_cmake_command(E_tar-end-opt1 ${CMAKE_COMMAND} -E tar cvf bad.tar -- --bad)
run_cmake_command(E_tar-end-opt2 ${CMAKE_COMMAND} -E tar cvf bad.tar --) run_cmake_command(E_tar-end-opt2 ${CMAKE_COMMAND} -E tar cvf bad.tar --)
run_cmake_command(E_tar-mtime ${CMAKE_COMMAND} -E tar cvf bad.tar "--mtime=1970-01-01 00:00:00 UTC") run_cmake_command(E_tar-mtime ${CMAKE_COMMAND} -E tar cvf bad.tar "--mtime=1970-01-01 00:00:00 UTC")