diff options
author | Brad King <brad.king@kitware.com> | 2015-01-26 18:28:31 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2015-01-26 18:28:31 (GMT) |
commit | 44fd71decbca329d9cdfc196a073a62668af53f2 (patch) | |
tree | 234cbd52ce83a17ec14bed5751f0caff69b02032 /Source/cmcmd.cxx | |
parent | 19e57a48cd1ad562b277c8fb9dc8285ef96acfa0 (diff) | |
download | CMake-44fd71decbca329d9cdfc196a073a62668af53f2.zip CMake-44fd71decbca329d9cdfc196a073a62668af53f2.tar.gz CMake-44fd71decbca329d9cdfc196a073a62668af53f2.tar.bz2 |
cmake: Teach "-E tar" command a "--files-from=" option
Read file names from the lines of a specified file. Reject input lines
starting in '-' to leave room for option parsing to be added later. Add
just '--add-file=' now to allow files starting in '-' to be specified.
Diffstat (limited to 'Source/cmcmd.cxx')
-rw-r--r-- | Source/cmcmd.cxx | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 7ca3eb3..28fcd27 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -94,6 +94,51 @@ void CMakeCommandUsage(const char* program) 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) { // 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); } + else if (cmHasLiteralPrefix(arg, "--files-from=")) + { + std::string const& files_from = arg.substr(13); + if (!cmTarFilesFrom(files_from, files)) + { + return 1; + } + } else { cmSystemTools::Error("Unknown option to -E tar: ", arg.c_str()); |