From kwrobot at kitware.com Sat Sep 1 00:05:12 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Sat, 1 Sep 2018 00:05:12 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.1-542-gef5022e Message-ID: <20180901040512.5015411FD51@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via ef5022e8c65c321dab3c6bde6b86c29b36f63700 (commit) from ed80d89b98123b2bc2ca8033ebe758b29feb1367 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=ef5022e8c65c321dab3c6bde6b86c29b36f63700 commit ef5022e8c65c321dab3c6bde6b86c29b36f63700 Author: Kitware Robot AuthorDate: Sat Sep 1 00:01:24 2018 -0400 Commit: Kitware Robot CommitDate: Sat Sep 1 00:01:24 2018 -0400 CMake Nightly Date Stamp diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index bcc291e..7fd50f7 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 12) -set(CMake_VERSION_PATCH 20180831) +set(CMake_VERSION_PATCH 20180901) #set(CMake_VERSION_RC 1) ----------------------------------------------------------------------- Summary of changes: Source/CMakeVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) hooks/post-receive -- CMake From kwrobot at kitware.com Sun Sep 2 00:05:06 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Sun, 2 Sep 2018 00:05:06 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.1-543-gd5a12cc Message-ID: <20180902040506.50E0A11FFC7@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via d5a12cc84dd671288eae8b81ba4e8bac29755bb8 (commit) from ef5022e8c65c321dab3c6bde6b86c29b36f63700 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=d5a12cc84dd671288eae8b81ba4e8bac29755bb8 commit d5a12cc84dd671288eae8b81ba4e8bac29755bb8 Author: Kitware Robot AuthorDate: Sun Sep 2 00:01:09 2018 -0400 Commit: Kitware Robot CommitDate: Sun Sep 2 00:01:09 2018 -0400 CMake Nightly Date Stamp diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 7fd50f7..5110008 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 12) -set(CMake_VERSION_PATCH 20180901) +set(CMake_VERSION_PATCH 20180902) #set(CMake_VERSION_RC 1) ----------------------------------------------------------------------- Summary of changes: Source/CMakeVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) hooks/post-receive -- CMake From kwrobot at kitware.com Mon Sep 3 00:05:04 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Mon, 3 Sep 2018 00:05:04 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.1-544-g0878a79 Message-ID: <20180903040504.E592C11EF56@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 0878a79414d4b7a0a24162c7365f188dba4a9bd4 (commit) from d5a12cc84dd671288eae8b81ba4e8bac29755bb8 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=0878a79414d4b7a0a24162c7365f188dba4a9bd4 commit 0878a79414d4b7a0a24162c7365f188dba4a9bd4 Author: Kitware Robot AuthorDate: Mon Sep 3 00:01:08 2018 -0400 Commit: Kitware Robot CommitDate: Mon Sep 3 00:01:08 2018 -0400 CMake Nightly Date Stamp diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 5110008..fd184cd 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 12) -set(CMake_VERSION_PATCH 20180902) +set(CMake_VERSION_PATCH 20180903) #set(CMake_VERSION_RC 1) ----------------------------------------------------------------------- Summary of changes: Source/CMakeVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) hooks/post-receive -- CMake From kwrobot at kitware.com Tue Sep 4 00:05:04 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Tue, 4 Sep 2018 00:05:04 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.1-545-g6b5f4ff Message-ID: <20180904040504.DE8FE1201EC@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 6b5f4ff9292fbe38e2a00b2c1052ee8b65f24b1d (commit) from 0878a79414d4b7a0a24162c7365f188dba4a9bd4 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=6b5f4ff9292fbe38e2a00b2c1052ee8b65f24b1d commit 6b5f4ff9292fbe38e2a00b2c1052ee8b65f24b1d Author: Kitware Robot AuthorDate: Tue Sep 4 00:01:06 2018 -0400 Commit: Kitware Robot CommitDate: Tue Sep 4 00:01:06 2018 -0400 CMake Nightly Date Stamp diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index fd184cd..d0075ff 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 12) -set(CMake_VERSION_PATCH 20180903) +set(CMake_VERSION_PATCH 20180904) #set(CMake_VERSION_RC 1) ----------------------------------------------------------------------- Summary of changes: Source/CMakeVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) hooks/post-receive -- CMake From kwrobot at kitware.com Tue Sep 4 10:05:08 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Tue, 4 Sep 2018 10:05:08 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.1-552-g612975c Message-ID: <20180904140508.BF71511EF6F@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 612975c6652c83c29fcfcf56a7b5a0cfe0218c93 (commit) via 69ce0629696ae8673d9063ba6a2878cf841beb0c (commit) via 0a1426f00833cd1ceca669ac9a87df55fb85c080 (commit) via 1bfe6991ff887dcc7cc9666a6971d21a097d6167 (commit) via 1fa0f2bd03621121e0a5d4c6cf0b4bcf74ad2ceb (commit) via d74c2282ea2b7df2276ce73c790fafe9a5571c56 (commit) via 7a7e94d6f7b74eeb165cab39f3aeeaba690160ef (commit) from 6b5f4ff9292fbe38e2a00b2c1052ee8b65f24b1d (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=612975c6652c83c29fcfcf56a7b5a0cfe0218c93 commit 612975c6652c83c29fcfcf56a7b5a0cfe0218c93 Merge: 69ce062 7a7e94d Author: Brad King AuthorDate: Tue Sep 4 13:58:51 2018 +0000 Commit: Kitware Robot CommitDate: Tue Sep 4 09:59:12 2018 -0400 Merge topic 'cpack_test' 7a7e94d6f7 CPack (DEB/RPM): add test for per-component description/summmary. Acked-by: Kitware Robot Merge-request: !2333 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=69ce0629696ae8673d9063ba6a2878cf841beb0c commit 69ce0629696ae8673d9063ba6a2878cf841beb0c Merge: 0a1426f d74c228 Author: Brad King AuthorDate: Tue Sep 4 13:57:46 2018 +0000 Commit: Kitware Robot CommitDate: Tue Sep 4 09:57:58 2018 -0400 Merge topic 'cmakeServerSourcesForInterfaceLibraries' d74c2282ea cmake-server: Support codemodel filegroups for INTERFACE_SOURCES Acked-by: Kitware Robot Acked-by: Tobias Hunger Acked-by: Markus Enzenberger Merge-request: !2282 diff --cc Source/cmServerProtocol.cxx index 31101e4,db7be2a..af4b466 --- a/Source/cmServerProtocol.cxx +++ b/Source/cmServerProtocol.cxx @@@ -765,14 -784,71 +784,71 @@@ static void PopulateFileGroupData } fileData.IsGenerated = file->GetPropertyAsBool("GENERATED"); - std::vector& groupFileList = fileGroups[fileData]; - groupFileList.push_back(file->GetFullPath()); + FileGroupSources& groupFileList = fileGroups[fileData]; + groupFileList.IsInterfaceSources = isInterfaceSources; + groupFileList.Files.push_back(file->GetFullPath()); + } + } + + static Json::Value DumpSourceFilesList( + cmGeneratorTarget* target, const std::string& config, + const std::map& languageDataMap) + { + const cmStateEnums::TargetType type = target->GetType(); + std::unordered_map fileGroups; + + // Collect sourcefile groups: + + std::vector files; + if (type == cmStateEnums::INTERFACE_LIBRARY) { + // INTERFACE_LIBRARY targets do not create all the data structures + // associated with regular targets. If properties are explicitly specified + // for files in INTERFACE_SOURCES then we can get them through the Makefile + // rather than the target. + files = target->Makefile->GetSourceFiles(); + } else { + target->GetSourceFiles(files, config); + PopulateFileGroupData(target, false /* isInterfaceSources */, files, + config, languageDataMap, fileGroups); + } + + // Collect interface sourcefile groups: + + auto targetProp = target->Target->GetProperty("INTERFACE_SOURCES"); + if (targetProp != nullptr) { + cmGeneratorExpressionInterpreter genexInterpreter( + target->GetLocalGenerator(), target, config, target->GetName(), ""); + + auto evaluatedSources = cmsys::SystemTools::SplitString( + genexInterpreter.Evaluate(targetProp, "INTERFACE_SOURCES"), ';'); + + std::map filesMap; + for (auto file : files) { + filesMap[file->GetFullPath()] = file; + } + + std::vector interfaceSourceFiles; + for (const std::string& interfaceSourceFilePath : evaluatedSources) { + auto entry = filesMap.find(interfaceSourceFilePath); + if (entry != filesMap.end()) { + // use what we have since it has all the associated properties + interfaceSourceFiles.push_back(entry->second); + } else { + interfaceSourceFiles.push_back( + new cmSourceFile(target->Makefile, interfaceSourceFilePath)); + } + } + + PopulateFileGroupData(target, true /* isInterfaceSources */, + interfaceSourceFiles, config, languageDataMap, + fileGroups); } - const std::string baseDir = target->Makefile->GetCurrentSourceDirectory(); + const std::string& baseDir = target->Makefile->GetCurrentSourceDirectory(); Json::Value result = Json::arrayValue; for (auto const& it : fileGroups) { - Json::Value group = DumpSourceFileGroup(it.first, it.second, baseDir); + Json::Value group = DumpSourceFileGroup( + it.first, it.second.IsInterfaceSources, it.second.Files, baseDir); if (!group.isNull()) { result.append(group); } https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=0a1426f00833cd1ceca669ac9a87df55fb85c080 commit 0a1426f00833cd1ceca669ac9a87df55fb85c080 Merge: 6b5f4ff 1bfe699 Author: Brad King AuthorDate: Tue Sep 4 13:57:15 2018 +0000 Commit: Kitware Robot CommitDate: Tue Sep 4 09:57:22 2018 -0400 Merge topic 'improve-isonoff' 1bfe6991ff cmSystemTools: Re-implement IsOn,IsOff with manual branching 1fa0f2bd03 cmSystemTools: Add IsOn(),IsOff() overloads accepting std::string Acked-by: Kitware Robot Acked-by: vvs31415 Merge-request: !2336 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=1bfe6991ff887dcc7cc9666a6971d21a097d6167 commit 1bfe6991ff887dcc7cc9666a6971d21a097d6167 Author: Brad King AuthorDate: Thu Aug 30 14:41:54 2018 -0400 Commit: Brad King CommitDate: Fri Aug 31 14:58:03 2018 -0400 cmSystemTools: Re-implement IsOn,IsOff with manual branching Replace use of std::string allocation, std::set lookups, and toupper conversions with explicit manual logic to do case-insensitive recognition of a specific set of strings. diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 7663af1..79e5ccf 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -42,7 +42,6 @@ #include #include #include -#include #include #include #include @@ -372,24 +371,31 @@ bool cmSystemTools::IsOn(const char* val) if (!val) { return false; } - size_t len = strlen(val); - if (len > 4) { - return false; + /* clang-format off */ + // "1" + if (val[0] == '1' && val[1] == '\0') { + return true; } - std::string v(val, len); - - static std::set onValues; - if (onValues.empty()) { - onValues.insert("ON"); - onValues.insert("1"); - onValues.insert("YES"); - onValues.insert("TRUE"); - onValues.insert("Y"); + // "ON" + if ((val[0] == 'O' || val[0] == 'o') && + (val[1] == 'N' || val[1] == 'n') && val[2] == '\0') { + return true; } - for (char& c : v) { - c = static_cast(toupper(c)); + // "Y", "YES" + if ((val[0] == 'Y' || val[0] == 'y') && (val[1] == '\0' || ( + (val[1] == 'E' || val[1] == 'e') && + (val[2] == 'S' || val[2] == 's') && val[3] == '\0'))) { + return true; } - return (onValues.count(v) > 0); + // "TRUE" + if ((val[0] == 'T' || val[0] == 't') && + (val[1] == 'R' || val[1] == 'r') && + (val[2] == 'U' || val[2] == 'u') && + (val[3] == 'E' || val[3] == 'e') && val[4] == '\0') { + return true; + } + /* clang-format on */ + return false; } bool cmSystemTools::IsOn(const std::string& val) @@ -407,30 +413,45 @@ bool cmSystemTools::IsNOTFOUND(const char* val) bool cmSystemTools::IsOff(const char* val) { - if (!val || !*val) { + // "" + if (!val || val[0] == '\0') { return true; } - size_t len = strlen(val); - // Try and avoid toupper() for large strings. - if (len > 6) { - return cmSystemTools::IsNOTFOUND(val); + /* clang-format off */ + // "0" + if (val[0] == '0' && val[1] == '\0') { + return true; } - - static std::set offValues; - if (offValues.empty()) { - offValues.insert("OFF"); - offValues.insert("0"); - offValues.insert("NO"); - offValues.insert("FALSE"); - offValues.insert("N"); - offValues.insert("IGNORE"); + // "OFF" + if ((val[0] == 'O' || val[0] == 'o') && + (val[1] == 'F' || val[1] == 'f') && + (val[2] == 'F' || val[2] == 'f') && val[3] == '\0') { + return true; } - // Try and avoid toupper(). - std::string v(val, len); - for (char& c : v) { - c = static_cast(toupper(c)); + // "N", "NO" + if ((val[0] == 'N' || val[0] == 'n') && (val[1] == '\0' || ( + (val[1] == 'O' || val[1] == 'o') && val[2] == '\0'))) { + return true; + } + // "FALSE" + if ((val[0] == 'F' || val[0] == 'f') && + (val[1] == 'A' || val[1] == 'a') && + (val[2] == 'L' || val[2] == 'l') && + (val[3] == 'S' || val[3] == 's') && + (val[4] == 'E' || val[4] == 'e') && val[5] == '\0') { + return true; + } + // "IGNORE" + if ((val[0] == 'I' || val[0] == 'i') && + (val[1] == 'G' || val[1] == 'g') && + (val[2] == 'N' || val[2] == 'n') && + (val[3] == 'O' || val[3] == 'o') && + (val[4] == 'R' || val[4] == 'r') && + (val[5] == 'E' || val[5] == 'e') && val[6] == '\0') { + return true; } - return (offValues.count(v) > 0); + /* clang-format on */ + return cmSystemTools::IsNOTFOUND(val); } bool cmSystemTools::IsOff(const std::string& val) https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=1fa0f2bd03621121e0a5d4c6cf0b4bcf74ad2ceb commit 1fa0f2bd03621121e0a5d4c6cf0b4bcf74ad2ceb Author: Vitaly Stakhovsky AuthorDate: Tue Aug 28 21:47:07 2018 -0400 Commit: Brad King CommitDate: Fri Aug 31 14:58:03 2018 -0400 cmSystemTools: Add IsOn(),IsOff() overloads accepting std::string diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 72fd2bb..7663af1 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -392,6 +392,11 @@ bool cmSystemTools::IsOn(const char* val) return (onValues.count(v) > 0); } +bool cmSystemTools::IsOn(const std::string& val) +{ + return cmSystemTools::IsOn(val.c_str()); +} + bool cmSystemTools::IsNOTFOUND(const char* val) { if (strcmp(val, "NOTFOUND") == 0) { @@ -428,6 +433,11 @@ bool cmSystemTools::IsOff(const char* val) return (offValues.count(v) > 0); } +bool cmSystemTools::IsOff(const std::string& val) +{ + return cmSystemTools::IsOff(val.c_str()); +} + void cmSystemTools::ParseWindowsCommandLine(const char* command, std::vector& args) { diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index c0a1b6b..5c383ee 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -129,6 +129,7 @@ public: * as ifdef. */ static bool IsOn(const char* val); + static bool IsOn(const std::string& val); /** * does a string indicate a false or off value ? Note that this is @@ -138,6 +139,7 @@ public: * NOTFOUND, *-NOTFOUND or IGNORE will cause IsOff to return true. */ static bool IsOff(const char* val); + static bool IsOff(const std::string& val); ///! Return true if value is NOTFOUND or ends in -NOTFOUND. static bool IsNOTFOUND(const char* value); https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=d74c2282ea2b7df2276ce73c790fafe9a5571c56 commit d74c2282ea2b7df2276ce73c790fafe9a5571c56 Author: Justin Goshi AuthorDate: Fri Aug 10 10:45:56 2018 -0700 Commit: Justin Goshi CommitDate: Thu Aug 30 16:09:22 2018 -0700 cmake-server: Support codemodel filegroups for INTERFACE_SOURCES This change returns information for INTERFACE_SOURCES. We add a flag to the filegroup to indicate if the target represents interface sources. Protocol version is updated to 1.3 since this is a change to what was released in cmake version 3.12. diff --git a/Help/manual/cmake-server.7.rst b/Help/manual/cmake-server.7.rst index 25d364c..b4c1436 100644 --- a/Help/manual/cmake-server.7.rst +++ b/Help/manual/cmake-server.7.rst @@ -308,6 +308,9 @@ which will result in a response type "reply":: indicating that the server is ready for action. +Protocol version 1.3 introduces an optional flag on the target filegroup +that indicates if the filegroup represents :prop_tgt:`INTERFACE_SOURCES`. + Type "globalSettings" ^^^^^^^^^^^^^^^^^^^^^ @@ -524,6 +527,8 @@ FileGroups are used to group sources using similar settings together. Each fileGroup object may contain the following keys: +"isInterfaceSources" + true if the fileGroup represents :prop_tgt:`INTERFACE_SOURCES`. "language" contains the programming language used by all files in the group. "compileFlags" @@ -538,6 +543,8 @@ Each fileGroup object may contain the following keys: "defines" with a list of defines in the form "SOMEVALUE" or "SOMEVALUE=42". This value is encoded in the system's native shell format. +"isGenerated" + true if the files were generated. "sources" with a list of source files. diff --git a/Source/cmServerDictionary.h b/Source/cmServerDictionary.h index 685542c..ebf16eb 100644 --- a/Source/cmServerDictionary.h +++ b/Source/cmServerDictionary.h @@ -96,6 +96,7 @@ static const std::string kCTEST_COMMAND = "ctestCommand"; static const std::string kCTEST_INFO = "ctestInfo"; static const std::string kMINIMUM_CMAKE_VERSION = "minimumCMakeVersion"; static const std::string kIS_GENERATOR_PROVIDED_KEY = "isGeneratorProvided"; +static const std::string kIS_INTERFACE_SOURCES_KEY = "isInterfaceSources"; static const std::string kSTART_MAGIC = "[== \"CMake Server\" ==["; static const std::string kEND_MAGIC = "]== \"CMake Server\" ==]"; diff --git a/Source/cmServerProtocol.cxx b/Source/cmServerProtocol.cxx index c267160..db7be2a 100644 --- a/Source/cmServerProtocol.cxx +++ b/Source/cmServerProtocol.cxx @@ -256,7 +256,12 @@ bool cmServerProtocol::DoActivate(const cmServerRequest& /*request*/, std::pair cmServerProtocol1::ProtocolVersion() const { - return std::make_pair(1, 2); + // Revision history + // 1, 1 - Report backtraces in codemodel response + // 1, 2 - Add target install destinations to codemodel + // 1, 3 - Add a flag to target filegroups indicating whether or not the + // filegroup is for INTERFACE_SOURCES + return std::make_pair(1, 3); } static void setErrorMessage(std::string* errorMessage, const std::string& text) @@ -593,6 +598,8 @@ cmServerResponse cmServerProtocol1::ProcessCMakeInputs( return request.Reply(result); } +const std::string kInterfaceSourcesLanguageDataKey = + "INTERFACE_SOURCES_LD_KEY"; class LanguageData { public: @@ -625,6 +632,12 @@ void LanguageData::SetDefines(const std::set& defines) Defines = std::move(result); } +struct FileGroupSources +{ + bool IsInterfaceSources; + std::vector Files; +}; + namespace std { template <> @@ -652,31 +665,35 @@ struct hash } // namespace std static Json::Value DumpSourceFileGroup(const LanguageData& data, + bool isInterfaceSource, const std::vector& files, const std::string& baseDir) { Json::Value result = Json::objectValue; + if (isInterfaceSource) { + result[kIS_INTERFACE_SOURCES_KEY] = true; + } if (!data.Language.empty()) { result[kLANGUAGE_KEY] = data.Language; - if (!data.Flags.empty()) { - result[kCOMPILE_FLAGS_KEY] = data.Flags; - } - if (!data.IncludePathList.empty()) { - Json::Value includes = Json::arrayValue; - for (auto const& i : data.IncludePathList) { - Json::Value tmp = Json::objectValue; - tmp[kPATH_KEY] = i.first; - if (i.second) { - tmp[kIS_SYSTEM_KEY] = i.second; - } - includes.append(tmp); + } + if (!data.Flags.empty()) { + result[kCOMPILE_FLAGS_KEY] = data.Flags; + } + if (!data.IncludePathList.empty()) { + Json::Value includes = Json::arrayValue; + for (auto const& i : data.IncludePathList) { + Json::Value tmp = Json::objectValue; + tmp[kPATH_KEY] = i.first; + if (i.second) { + tmp[kIS_SYSTEM_KEY] = i.second; } - result[kINCLUDE_PATH_KEY] = includes; - } - if (!data.Defines.empty()) { - result[kDEFINES_KEY] = fromStringList(data.Defines); + includes.append(tmp); } + result[kINCLUDE_PATH_KEY] = includes; + } + if (!data.Defines.empty()) { + result[kDEFINES_KEY] = fromStringList(data.Defines); } result[kIS_GENERATED_KEY] = data.IsGenerated; @@ -691,21 +708,19 @@ static Json::Value DumpSourceFileGroup(const LanguageData& data, return result; } -static Json::Value DumpSourceFilesList( - cmGeneratorTarget* target, const std::string& config, - const std::map& languageDataMap) +static void PopulateFileGroupData( + cmGeneratorTarget* target, bool isInterfaceSources, + const std::vector& files, const std::string& config, + const std::map& languageDataMap, + std::unordered_map& fileGroups) { - // Collect sourcefile groups: - - std::vector files; - target->GetSourceFiles(files, config); - - std::unordered_map> fileGroups; for (cmSourceFile* file : files) { LanguageData fileData; fileData.Language = file->GetLanguage(); - if (!fileData.Language.empty()) { - const LanguageData& ld = languageDataMap.at(fileData.Language); + if (!fileData.Language.empty() || isInterfaceSources) { + const LanguageData& ld = isInterfaceSources + ? languageDataMap.at(kInterfaceSourcesLanguageDataKey) + : languageDataMap.at(fileData.Language); cmLocalGenerator* lg = target->GetLocalGenerator(); cmGeneratorExpressionInterpreter genexInterpreter( lg, target, config, target->GetName(), fileData.Language); @@ -733,10 +748,14 @@ static Json::Value DumpSourceFilesList( lg->AppendIncludeDirectories(includes, evaluatedIncludes, *file); for (const auto& include : includes) { + // INTERFACE_LIBRARY targets do not support the + // IsSystemIncludeDirectory call so just set it to false. + const bool isSystemInclude = isInterfaceSources + ? false + : target->IsSystemIncludeDirectory(include, config, + fileData.Language); fileData.IncludePathList.push_back( - std::make_pair(include, - target->IsSystemIncludeDirectory( - include, config, fileData.Language))); + std::make_pair(include, isSystemInclude)); } } @@ -765,14 +784,71 @@ static Json::Value DumpSourceFilesList( } fileData.IsGenerated = file->GetPropertyAsBool("GENERATED"); - std::vector& groupFileList = fileGroups[fileData]; - groupFileList.push_back(file->GetFullPath()); + FileGroupSources& groupFileList = fileGroups[fileData]; + groupFileList.IsInterfaceSources = isInterfaceSources; + groupFileList.Files.push_back(file->GetFullPath()); + } +} + +static Json::Value DumpSourceFilesList( + cmGeneratorTarget* target, const std::string& config, + const std::map& languageDataMap) +{ + const cmStateEnums::TargetType type = target->GetType(); + std::unordered_map fileGroups; + + // Collect sourcefile groups: + + std::vector files; + if (type == cmStateEnums::INTERFACE_LIBRARY) { + // INTERFACE_LIBRARY targets do not create all the data structures + // associated with regular targets. If properties are explicitly specified + // for files in INTERFACE_SOURCES then we can get them through the Makefile + // rather than the target. + files = target->Makefile->GetSourceFiles(); + } else { + target->GetSourceFiles(files, config); + PopulateFileGroupData(target, false /* isInterfaceSources */, files, + config, languageDataMap, fileGroups); + } + + // Collect interface sourcefile groups: + + auto targetProp = target->Target->GetProperty("INTERFACE_SOURCES"); + if (targetProp != nullptr) { + cmGeneratorExpressionInterpreter genexInterpreter( + target->GetLocalGenerator(), target, config, target->GetName(), ""); + + auto evaluatedSources = cmsys::SystemTools::SplitString( + genexInterpreter.Evaluate(targetProp, "INTERFACE_SOURCES"), ';'); + + std::map filesMap; + for (auto file : files) { + filesMap[file->GetFullPath()] = file; + } + + std::vector interfaceSourceFiles; + for (const std::string& interfaceSourceFilePath : evaluatedSources) { + auto entry = filesMap.find(interfaceSourceFilePath); + if (entry != filesMap.end()) { + // use what we have since it has all the associated properties + interfaceSourceFiles.push_back(entry->second); + } else { + interfaceSourceFiles.push_back( + new cmSourceFile(target->Makefile, interfaceSourceFilePath)); + } + } + + PopulateFileGroupData(target, true /* isInterfaceSources */, + interfaceSourceFiles, config, languageDataMap, + fileGroups); } const std::string baseDir = target->Makefile->GetCurrentSourceDirectory(); Json::Value result = Json::arrayValue; for (auto const& it : fileGroups) { - Json::Value group = DumpSourceFileGroup(it.first, it.second, baseDir); + Json::Value group = DumpSourceFileGroup( + it.first, it.second.IsInterfaceSources, it.second.Files, baseDir); if (!group.isNull()) { result.append(group); } @@ -883,6 +959,59 @@ static Json::Value DumpCTestConfigurationsList(const cmake* cm) return result; } +static void GetTargetProperty( + cmGeneratorExpressionInterpreter& genexInterpreter, + cmGeneratorTarget* target, const char* propertyName, + std::vector& propertyValue) +{ + auto targetProp = target->Target->GetProperty(propertyName); + if (targetProp != nullptr) { + propertyValue = cmsys::SystemTools::SplitString( + genexInterpreter.Evaluate(targetProp, propertyName), ';'); + } +} + +static void CreateInterfaceSourcesEntry( + cmLocalGenerator* lg, cmGeneratorTarget* target, const std::string& config, + std::map& languageDataMap) +{ + LanguageData& ld = languageDataMap[kInterfaceSourcesLanguageDataKey]; + ld.Language = ""; + + cmGeneratorExpressionInterpreter genexInterpreter(lg, target, config, + target->GetName(), ""); + std::vector propertyValue; + GetTargetProperty(genexInterpreter, target, "INTERFACE_INCLUDE_DIRECTORIES", + propertyValue); + for (std::string const& i : propertyValue) { + ld.IncludePathList.push_back( + std::make_pair(i, false /* isSystemInclude */)); + } + + propertyValue.clear(); + GetTargetProperty(genexInterpreter, target, + "INTERFACE_SYSTEM_INCLUDE_DIRECTORIES", propertyValue); + for (std::string const& i : propertyValue) { + ld.IncludePathList.push_back( + std::make_pair(i, true /* isSystemInclude */)); + } + + propertyValue.clear(); + GetTargetProperty(genexInterpreter, target, "INTERFACE_COMPILE_OPTIONS", + propertyValue); + for (const auto& s : propertyValue) { + ld.Flags += " " + s; + } + + propertyValue.clear(); + GetTargetProperty(genexInterpreter, target, "INTERFACE_COMPILE_DEFINITIONS", + propertyValue); + if (!propertyValue.empty()) { + std::set defines(propertyValue.begin(), propertyValue.end()); + ld.SetDefines(defines); + } +} + static Json::Value DumpTarget(cmGeneratorTarget* target, const std::string& config) { @@ -912,11 +1041,6 @@ static Json::Value DumpTarget(cmGeneratorTarget* target, result[kTYPE_KEY] = typeName; result[kSOURCE_DIRECTORY_KEY] = lg->GetCurrentSourceDirectory(); result[kBUILD_DIRECTORY_KEY] = lg->GetCurrentBinaryDirectory(); - - if (type == cmStateEnums::INTERFACE_LIBRARY) { - return result; - } - result[kFULL_NAME_KEY] = target->GetFullName(config); if (target->Target->GetHaveInstallRule()) { @@ -1003,8 +1127,22 @@ static Json::Value DumpTarget(cmGeneratorTarget* target, } std::set languages; - target->GetLanguages(languages, config); std::map languageDataMap; + if (type == cmStateEnums::INTERFACE_LIBRARY) { + // INTERFACE_LIBRARY targets do not create all the data structures + // associated with regular targets. If properties are explicitly specified + // for files in INTERFACE_SOURCES then we can get them through the Makefile + // rather than the target. + for (auto file : target->Makefile->GetSourceFiles()) { + const std::string& language = file->GetLanguage(); + if (!language.empty()) { + languages.insert(language); + } + } + } else { + target->GetLanguages(languages, config); + } + for (std::string const& lang : languages) { LanguageData& ld = languageDataMap[lang]; ld.Language = lang; @@ -1020,6 +1158,11 @@ static Json::Value DumpTarget(cmGeneratorTarget* target, } } + if (target->Target->GetProperty("INTERFACE_SOURCES") != nullptr) { + // Create an entry in the languageDataMap for interface sources. + CreateInterfaceSourcesEntry(lg, target, config, languageDataMap); + } + Json::Value sourceGroupsValue = DumpSourceFilesList(target, config, languageDataMap); if (!sourceGroupsValue.empty()) { https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=7a7e94d6f7b74eeb165cab39f3aeeaba690160ef commit 7a7e94d6f7b74eeb165cab39f3aeeaba690160ef Author: David Faure AuthorDate: Thu Aug 30 19:52:19 2018 +0200 Commit: David Faure CommitDate: Thu Aug 30 22:08:11 2018 +0200 CPack (DEB/RPM): add test for per-component description/summmary. diff --git a/Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/VerifyResult.cmake b/Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/VerifyResult.cmake index 18ef63c..b4bdb61 100644 --- a/Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/VerifyResult.cmake +++ b/Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/VerifyResult.cmake @@ -1,7 +1,7 @@ function(checkPackageInfo_ TYPE FILE REGEX) getPackageInfo("${FILE}" "FILE_INFO_") if(NOT FILE_INFO_ MATCHES "${REGEX}") - message(FATAL_ERROR "Unexpected ${TYPE} in '${FILE}'; file info: '${FILE_INFO_}'") + message(FATAL_ERROR "Unexpected ${TYPE} in '${FILE}'; file info: '${FILE_INFO_}'; does not match '${REGEX}'") endif() endfunction() @@ -24,3 +24,15 @@ checkPackageInfo_("name" "${FOUND_FILE_3}" ".*${name_}${whitespaces_}:${whitespa checkPackageInfo_("group" "${FOUND_FILE_1}" ".*${group_}${whitespaces_}:${whitespaces_}default") checkPackageInfo_("group" "${FOUND_FILE_2}" ".*${group_}${whitespaces_}:${whitespaces_}second_group") checkPackageInfo_("group" "${FOUND_FILE_3}" ".*${group_}${whitespaces_}:${whitespaces_}default") + +# check package summaries (not available in DEB) +if(GENERATOR_TYPE STREQUAL "RPM") + checkPackageInfo_("summary" "${FOUND_FILE_1}" ".*Summary${whitespaces_}:${whitespaces_}Global summary") + checkPackageInfo_("summary" "${FOUND_FILE_2}" ".*Summary${whitespaces_}:${whitespaces_}Summary for pkg_2") + checkPackageInfo_("summary" "${FOUND_FILE_3}" ".*Summary${whitespaces_}:${whitespaces_}Global summary") +endif() + +# check package description +checkPackageInfo_("description" "${FOUND_FILE_1}" ".*Description${whitespaces_}:${whitespaces_}Description for pkg_1") +checkPackageInfo_("description" "${FOUND_FILE_2}" ".*Description${whitespaces_}:${whitespaces_}Description for pkg_2") +checkPackageInfo_("description" "${FOUND_FILE_3}" ".*Description${whitespaces_}:${whitespaces_}Description for pkg_3") diff --git a/Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/test.cmake b/Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/test.cmake index 8719c0b..dc61d0a 100644 --- a/Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/test.cmake +++ b/Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/test.cmake @@ -11,6 +11,13 @@ if(GENERATOR_TYPE STREQUAL "DEB" OR GENERATOR_TYPE STREQUAL "RPM") set(CPACK_${GENERATOR_TYPE}${generator_type_suffix_}_PACKAGE_${group_} "default") set(CPACK_${GENERATOR_TYPE}${generator_type_suffix_}_PKG_2_PACKAGE_NAME "second") set(CPACK_${GENERATOR_TYPE}${generator_type_suffix_}_PKG_2_PACKAGE_${group_} "second_group") + + set(CPACK_${GENERATOR_TYPE}${generator_type_suffix_}_PACKAGE_SUMMARY "Global summary") # not used for DEB + set(CPACK_${GENERATOR_TYPE}${generator_type_suffix_}_PKG_2_PACKAGE_SUMMARY "Summary for pkg_2") # not used for DEB + + set(CPACK_COMPONENT_PKG_1_DESCRIPTION "Description for pkg_1") + set(CPACK_COMPONENT_PKG_2_DESCRIPTION "Description for pkg_2") + set(CPACK_COMPONENT_PKG_3_DESCRIPTION "Description for pkg_3") endif() install(FILES CMakeLists.txt DESTINATION foo COMPONENT pkg_1) ----------------------------------------------------------------------- Summary of changes: Help/manual/cmake-server.7.rst | 7 + Source/cmServerDictionary.h | 1 + Source/cmServerProtocol.cxx | 223 +++++++++++++++++---- Source/cmSystemTools.cxx | 101 ++++++---- Source/cmSystemTools.h | 2 + .../tests/PER_COMPONENT_FIELDS/VerifyResult.cmake | 14 +- .../CPack/tests/PER_COMPONENT_FIELDS/test.cmake | 7 + 7 files changed, 279 insertions(+), 76 deletions(-) hooks/post-receive -- CMake From kwrobot at kitware.com Wed Sep 5 00:05:07 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Wed, 5 Sep 2018 00:05:07 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.1-553-gcc5bac4 Message-ID: <20180905040508.0706F11ED87@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via cc5bac458b85081f813a2c169fda104f59233c37 (commit) from 612975c6652c83c29fcfcf56a7b5a0cfe0218c93 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=cc5bac458b85081f813a2c169fda104f59233c37 commit cc5bac458b85081f813a2c169fda104f59233c37 Author: Kitware Robot AuthorDate: Wed Sep 5 00:01:09 2018 -0400 Commit: Kitware Robot CommitDate: Wed Sep 5 00:01:09 2018 -0400 CMake Nightly Date Stamp diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index d0075ff..6e18571 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 12) -set(CMake_VERSION_PATCH 20180904) +set(CMake_VERSION_PATCH 20180905) #set(CMake_VERSION_RC 1) ----------------------------------------------------------------------- Summary of changes: Source/CMakeVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) hooks/post-receive -- CMake From kwrobot at kitware.com Wed Sep 5 14:35:03 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Wed, 5 Sep 2018 14:35:03 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.1-555-gcb800eb Message-ID: <20180905183503.59465107A19@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via cb800ebb83646ef4ef2b2e2950d90837bc5c14a7 (commit) via 9a800c12fcf357b0eeb585a973a6f61790687795 (commit) from cc5bac458b85081f813a2c169fda104f59233c37 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=cb800ebb83646ef4ef2b2e2950d90837bc5c14a7 commit cb800ebb83646ef4ef2b2e2950d90837bc5c14a7 Merge: cc5bac4 9a800c1 Author: Brad King AuthorDate: Wed Sep 5 18:32:20 2018 +0000 Commit: Kitware Robot CommitDate: Wed Sep 5 14:32:27 2018 -0400 Merge topic 'FindBoost-old-context' 9a800c12fc FindBoost: Fix context discovery for 1.60 and below Acked-by: Kitware Robot Merge-request: !2348 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=9a800c12fcf357b0eeb585a973a6f61790687795 commit 9a800c12fcf357b0eeb585a973a6f61790687795 Author: Igor Kostenko AuthorDate: Tue Sep 4 15:12:23 2018 +0100 Commit: Brad King CommitDate: Tue Sep 4 12:41:36 2018 -0400 FindBoost: Fix context discovery for 1.60 and below * `all.hpp` was removed in 1.68: https://github.com/boostorg/context/commit/2e37599461912cc1679f106a25456a493f7f0b27 * `fcontext.hpp` was moved to detail in 1.61: https://github.com/boostorg/context/commit/c2f0dfdf2608c1ebaa2229fa6f358fe6aa103561 Fixes: #18126 diff --git a/Modules/FindBoost.cmake b/Modules/FindBoost.cmake index 4e5c45d..d5e7011 100644 --- a/Modules/FindBoost.cmake +++ b/Modules/FindBoost.cmake @@ -881,7 +881,11 @@ function(_Boost_COMPONENT_HEADERS component _hdrs) set(_Boost_CHRONO_HEADERS "boost/chrono.hpp") set(_Boost_CONTAINER_HEADERS "boost/container/container_fwd.hpp") set(_Boost_CONTRACT_HEADERS "boost/contract.hpp") - set(_Boost_CONTEXT_HEADERS "boost/context/detail/fcontext.hpp") + if(Boost_VERSION VERSION_LESS 106100) + set(_Boost_CONTEXT_HEADERS "boost/context/all.hpp") + else() + set(_Boost_CONTEXT_HEADERS "boost/context/detail/fcontext.hpp") + endif() set(_Boost_COROUTINE_HEADERS "boost/coroutine/all.hpp") set(_Boost_DATE_TIME_HEADERS "boost/date_time/date.hpp") set(_Boost_EXCEPTION_HEADERS "boost/exception/exception.hpp") ----------------------------------------------------------------------- Summary of changes: Modules/FindBoost.cmake | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) hooks/post-receive -- CMake From kwrobot at kitware.com Wed Sep 5 14:45:02 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Wed, 5 Sep 2018 14:45:02 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.1-562-gb0f769a Message-ID: <20180905184503.073A0FE790@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via b0f769ad2da5162f7f65e13061b18b4538f06d9a (commit) via 182522a209331cd1d221420972ed6b200918f6e6 (commit) via b6524f6f3425aaffc1e5fa2f6d3f5847ed3f94f5 (commit) via 925b95fbadae0fe59f38b744dfb0f665436d8d11 (commit) via 0b82e68f2f52847e4c14f1b22e6ef537b42f415a (commit) via 13a2751ca6e45789631bf2457d6bc519926441cc (commit) via 6be7097dbe7373e78d5a3fe054895443f962aa0a (commit) from cb800ebb83646ef4ef2b2e2950d90837bc5c14a7 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=b0f769ad2da5162f7f65e13061b18b4538f06d9a commit b0f769ad2da5162f7f65e13061b18b4538f06d9a Merge: 182522a 13a2751 Author: Brad King AuthorDate: Wed Sep 5 18:40:20 2018 +0000 Commit: Kitware Robot CommitDate: Wed Sep 5 14:40:26 2018 -0400 Merge topic 'cmake-gui-align-text' 13a2751ca6 cmake-gui: Align source and binary directory path text Acked-by: Kitware Robot Merge-request: !2344 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=182522a209331cd1d221420972ed6b200918f6e6 commit 182522a209331cd1d221420972ed6b200918f6e6 Merge: b6524f6 925b95f Author: Brad King AuthorDate: Wed Sep 5 14:36:47 2018 -0400 Commit: Brad King CommitDate: Wed Sep 5 14:36:47 2018 -0400 Merge branch 'release-3.12' https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=b6524f6f3425aaffc1e5fa2f6d3f5847ed3f94f5 commit b6524f6f3425aaffc1e5fa2f6d3f5847ed3f94f5 Merge: cb800eb 0b82e68 Author: Brad King AuthorDate: Wed Sep 5 18:35:41 2018 +0000 Commit: Kitware Robot CommitDate: Wed Sep 5 14:35:46 2018 -0400 Merge topic 'vs-CMakeLists.txt' 0b82e68f2f VS: Restore CMakeLists.txt references in each target Acked-by: Kitware Robot Merge-request: !2349 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=13a2751ca6e45789631bf2457d6bc519926441cc commit 13a2751ca6e45789631bf2457d6bc519926441cc Author: Zeex AuthorDate: Tue Sep 4 16:41:28 2018 +0600 Commit: Brad King CommitDate: Tue Sep 4 13:01:00 2018 -0400 cmake-gui: Align source and binary directory path text Text inputs for "where is the source code" and "where to build the binaries" had different amount of left spacing, so the two paths were not aligned. This could create a feeling that you typed something wrong in the input even though the paths were identical or had a common root path. diff --git a/Source/QtDialog/CMakeSetupDialog.ui b/Source/QtDialog/CMakeSetupDialog.ui index 8d8e0cd..dc22a29 100644 --- a/Source/QtDialog/CMakeSetupDialog.ui +++ b/Source/QtDialog/CMakeSetupDialog.ui @@ -57,6 +57,9 @@ 0 + + padding-left: 0 + true ----------------------------------------------------------------------- Summary of changes: Source/QtDialog/CMakeSetupDialog.ui | 3 +++ Source/cmVisualStudio10TargetGenerator.cxx | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) hooks/post-receive -- CMake From kwrobot at kitware.com Wed Sep 5 14:45:03 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Wed, 5 Sep 2018 14:45:03 -0400 (EDT) Subject: [Cmake-commits] CMake branch, release, updated. v3.12.1-20-g925b95f Message-ID: <20180905184503.14B89FE791@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, release has been updated via 925b95fbadae0fe59f38b744dfb0f665436d8d11 (commit) via 0b82e68f2f52847e4c14f1b22e6ef537b42f415a (commit) via 6be7097dbe7373e78d5a3fe054895443f962aa0a (commit) via 9a800c12fcf357b0eeb585a973a6f61790687795 (commit) from 80bb9214dd6bac5c0d2e8eea04d111ee419a89fe (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- ----------------------------------------------------------------------- Summary of changes: Modules/FindBoost.cmake | 6 +++++- Source/cmVisualStudio10TargetGenerator.cxx | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) hooks/post-receive -- CMake From kwrobot at kitware.com Thu Sep 6 00:05:03 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Thu, 6 Sep 2018 00:05:03 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.1-563-g6d2a2fe Message-ID: <20180906040503.1615F115209@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 6d2a2fe66027b6eeb2817a8e667894ad2e233d03 (commit) from b0f769ad2da5162f7f65e13061b18b4538f06d9a (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=6d2a2fe66027b6eeb2817a8e667894ad2e233d03 commit 6d2a2fe66027b6eeb2817a8e667894ad2e233d03 Author: Kitware Robot AuthorDate: Thu Sep 6 00:01:09 2018 -0400 Commit: Kitware Robot CommitDate: Thu Sep 6 00:01:09 2018 -0400 CMake Nightly Date Stamp diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 6e18571..3bd0714 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 12) -set(CMake_VERSION_PATCH 20180905) +set(CMake_VERSION_PATCH 20180906) #set(CMake_VERSION_RC 1) ----------------------------------------------------------------------- Summary of changes: Source/CMakeVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) hooks/post-receive -- CMake From kwrobot at kitware.com Thu Sep 6 09:55:09 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Thu, 6 Sep 2018 09:55:09 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.1-567-ge1ebec5 Message-ID: <20180906135509.ADCEF103085@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via e1ebec55d4b3e9db2c718064237707252ec4abf5 (commit) via 3ecbe1987d56b905853a5fae4f5664befed0e223 (commit) via 4d89830d7117a6fb68346d4ebe5f2f3c6d3223a0 (commit) via 6f16be6a6265ee19bd8193da8a7a0d111717ee80 (commit) from 6d2a2fe66027b6eeb2817a8e667894ad2e233d03 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=e1ebec55d4b3e9db2c718064237707252ec4abf5 commit e1ebec55d4b3e9db2c718064237707252ec4abf5 Merge: 3ecbe19 4d89830 Author: Brad King AuthorDate: Thu Sep 6 13:54:23 2018 +0000 Commit: Kitware Robot CommitDate: Thu Sep 6 09:54:56 2018 -0400 Merge topic 'grd-stdstring' 4d89830d71 cmMakefile: Make GetRequiredDefinition return std::string Acked-by: Kitware Robot Merge-request: !2347 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=3ecbe1987d56b905853a5fae4f5664befed0e223 commit 3ecbe1987d56b905853a5fae4f5664befed0e223 Merge: 6d2a2fe 6f16be6 Author: Brad King AuthorDate: Thu Sep 6 13:54:07 2018 +0000 Commit: Kitware Robot CommitDate: Thu Sep 6 09:54:18 2018 -0400 Merge topic 'isonoff-cstr' 6f16be6a62 Remove unnecessary c_str() calls Acked-by: Kitware Robot Merge-request: !2346 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=4d89830d7117a6fb68346d4ebe5f2f3c6d3223a0 commit 4d89830d7117a6fb68346d4ebe5f2f3c6d3223a0 Author: Vitaly Stakhovsky AuthorDate: Tue Sep 4 11:08:50 2018 -0400 Commit: Brad King CommitDate: Wed Sep 5 15:15:55 2018 -0400 cmMakefile: Make GetRequiredDefinition return std::string In all cases the return value is converted to std::string anyway. Also remove unnecessary `c_str()` calls in arguments to `GetRequiredDefinition`. diff --git a/Source/cmFLTKWrapUICommand.cxx b/Source/cmFLTKWrapUICommand.cxx index 03d1ad1..effb446 100644 --- a/Source/cmFLTKWrapUICommand.cxx +++ b/Source/cmFLTKWrapUICommand.cxx @@ -23,7 +23,7 @@ bool cmFLTKWrapUICommand::InitialPass(std::vector const& args, // what is the current source dir std::string cdir = this->Makefile->GetCurrentSourceDirectory(); - const char* fluid_exe = + std::string const& fluid_exe = this->Makefile->GetRequiredDefinition("FLTK_FLUID_EXECUTABLE"); // get parameter for the command diff --git a/Source/cmFindLibraryCommand.cxx b/Source/cmFindLibraryCommand.cxx index 02bae82..1e1ab14 100644 --- a/Source/cmFindLibraryCommand.cxx +++ b/Source/cmFindLibraryCommand.cxx @@ -236,9 +236,9 @@ cmFindLibraryHelper::cmFindLibraryHelper(cmMakefile* mf) this->GG = this->Makefile->GetGlobalGenerator(); // Collect the list of library name prefixes/suffixes to try. - const char* prefixes_list = + std::string const& prefixes_list = this->Makefile->GetRequiredDefinition("CMAKE_FIND_LIBRARY_PREFIXES"); - const char* suffixes_list = + std::string const& suffixes_list = this->Makefile->GetRequiredDefinition("CMAKE_FIND_LIBRARY_SUFFIXES"); cmSystemTools::ExpandListArgument(prefixes_list, this->Prefixes, true); cmSystemTools::ExpandListArgument(suffixes_list, this->Suffixes, true); diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 92ede7f..2c82c64 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -205,7 +205,7 @@ void cmGlobalGenerator::ResolveLanguageCompiler(const std::string& lang, } return; } - const char* name = mf->GetRequiredDefinition(langComp); + std::string const& name = mf->GetRequiredDefinition(langComp); std::string path; if (!cmSystemTools::FileIsFullPath(name)) { path = cmSystemTools::FindProgram(name); diff --git a/Source/cmLocalCommonGenerator.cxx b/Source/cmLocalCommonGenerator.cxx index 5a43f2e..7ce2c82 100644 --- a/Source/cmLocalCommonGenerator.cxx +++ b/Source/cmLocalCommonGenerator.cxx @@ -54,9 +54,8 @@ std::string cmLocalCommonGenerator::GetTargetFortranFlags( this->Makefile->GetSafeDefinition("CMAKE_Fortran_MODDIR_DEFAULT"); } if (!mod_dir.empty()) { - const char* moddir_flag = + std::string modflag = this->Makefile->GetRequiredDefinition("CMAKE_Fortran_MODDIR_FLAG"); - std::string modflag = moddir_flag; modflag += mod_dir; this->AppendFlags(flags, modflag); } diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 532f9a9..d3ade3a 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1655,7 +1655,7 @@ void cmLocalGenerator::AddCompilerRequirementFlag( std::string option_flag = "CMAKE_" + lang + *stdIt + "_" + type + "_COMPILE_OPTION"; - const char* opt = + std::string const& opt = target->Target->GetMakefile()->GetRequiredDefinition(option_flag); std::vector optVec; cmSystemTools::ExpandListArgument(opt, optVec); diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 80f2803..13bd214 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -665,11 +665,11 @@ void cmLocalVisualStudio7Generator::WriteConfiguration( std::string baseFlagVar = "CMAKE_"; baseFlagVar += langForClCompile; baseFlagVar += "_FLAGS"; - flags = this->Makefile->GetRequiredDefinition(baseFlagVar.c_str()); + flags = this->Makefile->GetRequiredDefinition(baseFlagVar); std::string flagVar = baseFlagVar + std::string("_") + cmSystemTools::UpperCase(configName); flags += " "; - flags += this->Makefile->GetRequiredDefinition(flagVar.c_str()); + flags += this->Makefile->GetRequiredDefinition(flagVar); } // set the correct language if (linkLanguage == "C") { @@ -931,8 +931,7 @@ std::string cmLocalVisualStudio7Generator::GetBuildTypeLinkerFlags( rootLinkerFlags + "_" + configTypeUpper; std::string extraLinkOptionsBuildType = - this->Makefile->GetRequiredDefinition( - extraLinkOptionsBuildTypeDef.c_str()); + this->Makefile->GetRequiredDefinition(extraLinkOptionsBuildTypeDef); return extraLinkOptionsBuildType; } diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 6127b57..5fd61bf 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -2354,16 +2354,16 @@ bool cmMakefile::CanIWriteThisFile(std::string const& fileName) const cmSystemTools::SameFile(fileName, this->GetHomeOutputDirectory()); } -const char* cmMakefile::GetRequiredDefinition(const std::string& name) const +std::string cmMakefile::GetRequiredDefinition(const std::string& name) const { const char* ret = this->GetDefinition(name); if (!ret) { cmSystemTools::Error("Error required internal CMake variable not " "set, cmake may not be built correctly.\n", "Missing variable is:\n", name.c_str()); - return ""; + return std::string(); } - return ret; + return std::string(ret); } bool cmMakefile::IsDefinitionSet(const std::string& name) const diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 4085e99..0ab4371 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -423,7 +423,7 @@ public: */ const char* GetDefinition(const std::string&) const; const char* GetSafeDefinition(const std::string&) const; - const char* GetRequiredDefinition(const std::string& name) const; + std::string GetRequiredDefinition(const std::string& name) const; bool IsDefinitionSet(const std::string&) const; /** * Get the list of all variables in the current space. If argument diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index b634b0a..6436969 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -530,7 +530,7 @@ std::vector cmNinjaNormalTargetGenerator::ComputeLinkCmd() linkCmdVar = this->GeneratorTarget->GetFeatureSpecificLinkRuleVariable( linkCmdVar, this->TargetLinkLanguage, this->GetConfigName()); - const char* linkCmd = mf->GetRequiredDefinition(linkCmdVar); + std::string const& linkCmd = mf->GetRequiredDefinition(linkCmdVar); cmSystemTools::ExpandListArgument(linkCmd, linkCmds); } { @@ -541,7 +541,7 @@ std::vector cmNinjaNormalTargetGenerator::ComputeLinkCmd() linkCmdVar = this->GeneratorTarget->GetFeatureSpecificLinkRuleVariable( linkCmdVar, this->TargetLinkLanguage, this->GetConfigName()); - const char* linkCmd = mf->GetRequiredDefinition(linkCmdVar); + std::string const& linkCmd = mf->GetRequiredDefinition(linkCmdVar); cmSystemTools::ExpandListArgument(linkCmd, linkCmds); } return linkCmds; diff --git a/Source/cmQTWrapCPPCommand.cxx b/Source/cmQTWrapCPPCommand.cxx index 09cc63a..d2133ed 100644 --- a/Source/cmQTWrapCPPCommand.cxx +++ b/Source/cmQTWrapCPPCommand.cxx @@ -21,7 +21,7 @@ bool cmQTWrapCPPCommand::InitialPass(std::vector const& args, } // Get the moc executable to run in the custom command. - const char* moc_exe = + std::string const& moc_exe = this->Makefile->GetRequiredDefinition("QT_MOC_EXECUTABLE"); // Get the variable holding the list of sources. diff --git a/Source/cmQTWrapUICommand.cxx b/Source/cmQTWrapUICommand.cxx index da36cdf..25dcd1a 100644 --- a/Source/cmQTWrapUICommand.cxx +++ b/Source/cmQTWrapUICommand.cxx @@ -21,9 +21,9 @@ bool cmQTWrapUICommand::InitialPass(std::vector const& args, } // Get the uic and moc executables to run in the custom commands. - const char* uic_exe = + std::string const& uic_exe = this->Makefile->GetRequiredDefinition("QT_UIC_EXECUTABLE"); - const char* moc_exe = + std::string const& moc_exe = this->Makefile->GetRequiredDefinition("QT_MOC_EXECUTABLE"); // Get the variable holding the list of sources. diff --git a/Source/cmUtilitySourceCommand.cxx b/Source/cmUtilitySourceCommand.cxx index a601637..f374626 100644 --- a/Source/cmUtilitySourceCommand.cxx +++ b/Source/cmUtilitySourceCommand.cxx @@ -28,7 +28,7 @@ bool cmUtilitySourceCommand::InitialPass(std::vector const& args, // If it exists already and appears up to date then we are done. If // the string contains "(IntDir)" but that is not the // CMAKE_CFG_INTDIR setting then the value is out of date. - const char* intDir = + std::string const& intDir = this->Makefile->GetRequiredDefinition("CMAKE_CFG_INTDIR"); bool haveCacheValue = false; @@ -46,7 +46,7 @@ bool cmUtilitySourceCommand::InitialPass(std::vector const& args, cmState* state = this->Makefile->GetState(); haveCacheValue = (cacheValue && (strstr(cacheValue, "(IntDir)") == nullptr || - (intDir && strcmp(intDir, "$(IntDir)") == 0)) && + (intDir == "$(IntDir)")) && (state->GetCacheMajorVersion() != 0 && state->GetCacheMinorVersion() != 0)); } diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index ea65e21..fdef1b8 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -2468,7 +2468,7 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( baseFlagVar += "_FLAGS"; flags = this->Makefile->GetRequiredDefinition(baseFlagVar); std::string flagVar = - baseFlagVar + std::string("_") + cmSystemTools::UpperCase(configName); + baseFlagVar + "_" + cmSystemTools::UpperCase(configName); flags += " "; flags += this->Makefile->GetRequiredDefinition(flagVar); this->LocalGenerator->AddCompileOptions(flags, this->GeneratorTarget, https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=6f16be6a6265ee19bd8193da8a7a0d111717ee80 commit 6f16be6a6265ee19bd8193da8a7a0d111717ee80 Author: Vitaly Stakhovsky AuthorDate: Fri Aug 31 19:01:22 2018 -0400 Commit: Brad King CommitDate: Wed Sep 5 15:12:57 2018 -0400 Remove unnecessary c_str() calls Use the new IsOn(),IsOff() overloads. diff --git a/Source/CTest/cmCTestBuildHandler.cxx b/Source/CTest/cmCTestBuildHandler.cxx index c5941ce..a8309d9 100644 --- a/Source/CTest/cmCTestBuildHandler.cxx +++ b/Source/CTest/cmCTestBuildHandler.cxx @@ -327,7 +327,7 @@ int cmCTestBuildHandler::ProcessHandler() std::string const& useLaunchers = this->CTest->GetCTestConfiguration("UseLaunchers"); - this->UseCTestLaunch = cmSystemTools::IsOn(useLaunchers.c_str()); + this->UseCTestLaunch = cmSystemTools::IsOn(useLaunchers); // Create a last build log cmGeneratedFileStream ofs; diff --git a/Source/CTest/cmCTestGIT.cxx b/Source/CTest/cmCTestGIT.cxx index b919c79..71fcafb 100644 --- a/Source/CTest/cmCTestGIT.cxx +++ b/Source/CTest/cmCTestGIT.cxx @@ -272,7 +272,7 @@ bool cmCTestGIT::UpdateImpl() std::string init_submodules = this->CTest->GetCTestConfiguration("GITInitSubmodules"); - if (cmSystemTools::IsOn(init_submodules.c_str())) { + if (cmSystemTools::IsOn(init_submodules)) { char const* git_submodule_init[] = { git, "submodule", "init", nullptr }; ret = this->RunChild(git_submodule_init, &submodule_out, &submodule_err, top_dir.c_str()); diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index d1d8d08..7fb5e80 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -2126,10 +2126,10 @@ bool cmCTestTestHandler::SetTestsProperties( for (cmCTestTestProperties& rt : this->TestList) { if (t == rt.Name) { if (key == "WILL_FAIL") { - rt.WillFail = cmSystemTools::IsOn(val.c_str()); + rt.WillFail = cmSystemTools::IsOn(val); } if (key == "DISABLED") { - rt.Disabled = cmSystemTools::IsOn(val.c_str()); + rt.Disabled = cmSystemTools::IsOn(val); } if (key == "ATTACHED_FILES") { cmSystemTools::ExpandListArgument(val, rt.AttachedFiles); @@ -2172,7 +2172,7 @@ bool cmCTestTestHandler::SetTestsProperties( cmSystemTools::ExpandListArgument(val, rt.RequiredFiles); } if (key == "RUN_SERIAL") { - rt.RunSerial = cmSystemTools::IsOn(val.c_str()); + rt.RunSerial = cmSystemTools::IsOn(val); } if (key == "FAIL_REGULAR_EXPRESSION") { std::vector lval; @@ -2188,7 +2188,7 @@ bool cmCTestTestHandler::SetTestsProperties( } } if (key == "PROCESSOR_AFFINITY") { - rt.WantAffinity = cmSystemTools::IsOn(val.c_str()); + rt.WantAffinity = cmSystemTools::IsOn(val); } if (key == "SKIP_RETURN_CODE") { rt.SkipReturnCode = atoi(val.c_str()); diff --git a/Source/CTest/cmCTestVC.cxx b/Source/CTest/cmCTestVC.cxx index a59d671..21c8889 100644 --- a/Source/CTest/cmCTestVC.cxx +++ b/Source/CTest/cmCTestVC.cxx @@ -146,7 +146,7 @@ bool cmCTestVC::Update() // if update version only is on then do not actually update, // just note the current version and finish if (!cmSystemTools::IsOn( - this->CTest->GetCTestConfiguration("UpdateVersionOnly").c_str())) { + this->CTest->GetCTestConfiguration("UpdateVersionOnly"))) { result = this->NoteOldRevision() && result; this->Log << "--- Begin Update ---\n"; result = this->UpdateImpl() && result; diff --git a/Source/CursesDialog/cmCursesMainForm.cxx b/Source/CursesDialog/cmCursesMainForm.cxx index 4a379c3..931797a 100644 --- a/Source/CursesDialog/cmCursesMainForm.cxx +++ b/Source/CursesDialog/cmCursesMainForm.cxx @@ -709,7 +709,7 @@ void cmCursesMainForm::FixValue(cmStateEnums::CacheEntryType type, cmSystemTools::ConvertToUnixSlashes(out); } if (type == cmStateEnums::BOOL) { - if (cmSystemTools::IsOff(out.c_str())) { + if (cmSystemTools::IsOff(out)) { out = "OFF"; } else { out = "ON"; diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index 3d3d526..e847bae 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -292,8 +292,7 @@ cmCTest::cmCTest() this->RepeatUntilFail = false; std::string outOnFail; if (cmSystemTools::GetEnv("CTEST_OUTPUT_ON_FAILURE", outOnFail)) { - this->OutputTestOutputOnTestFailure = - !cmSystemTools::IsOff(outOnFail.c_str()); + this->OutputTestOutputOnTestFailure = !cmSystemTools::IsOff(outOnFail); } this->InitStreams(); @@ -747,8 +746,8 @@ bool cmCTest::UpdateCTestConfiguration() } } if (this->ProduceXML) { - this->CompressXMLFiles = cmSystemTools::IsOn( - this->GetCTestConfiguration("CompressSubmission").c_str()); + this->CompressXMLFiles = + cmSystemTools::IsOn(this->GetCTestConfiguration("CompressSubmission")); } return true; } @@ -1936,7 +1935,7 @@ bool cmCTest::HandleCommandLineArguments(size_t& i, if (this->CheckArgument(arg, "--interactive-debug-mode") && i < args.size() - 1) { i++; - this->InteractiveDebugMode = cmSystemTools::IsOn(args[i].c_str()); + this->InteractiveDebugMode = cmSystemTools::IsOn(args[i]); } if (this->CheckArgument(arg, "--submit-index") && i < args.size() - 1) { i++; diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx index 5091c97..d2d419f 100644 --- a/Source/cmCacheManager.cxx +++ b/Source/cmCacheManager.cxx @@ -616,7 +616,7 @@ void cmCacheManager::CacheIterator::SetValue(const char* value) bool cmCacheManager::CacheIterator::GetValueAsBool() const { - return cmSystemTools::IsOn(this->GetEntry().Value.c_str()); + return cmSystemTools::IsOn(this->GetEntry().Value); } std::vector cmCacheManager::CacheEntry::GetPropertyList() const diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index 1c29017..54af2f4 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -784,10 +784,10 @@ bool cmFileCommand::HandleGlobCommand(std::vector const& args, if (*i == "LIST_DIRECTORIES") { ++i; // skip LIST_DIRECTORIES if (i != args.end()) { - if (cmSystemTools::IsOn(i->c_str())) { + if (cmSystemTools::IsOn(*i)) { g.SetListDirs(true); g.SetRecurseListDirs(true); - } else if (cmSystemTools::IsOff(i->c_str())) { + } else if (cmSystemTools::IsOff(*i)) { g.SetListDirs(false); g.SetRecurseListDirs(false); } else { @@ -1756,7 +1756,7 @@ struct cmFileInstaller : public cmFileCopier // Check whether to copy files always or only if they have changed. std::string install_always; if (cmSystemTools::GetEnv("CMAKE_INSTALL_ALWAYS", install_always)) { - this->Always = cmSystemTools::IsOn(install_always.c_str()); + this->Always = cmSystemTools::IsOn(install_always); } // Get the current manifest. this->Manifest = @@ -2747,7 +2747,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector const& args) } else if (*i == "TLS_VERIFY") { ++i; if (i != args.end()) { - tls_verify = cmSystemTools::IsOn(i->c_str()); + tls_verify = cmSystemTools::IsOn(*i); } else { this->SetError("TLS_VERIFY missing bool value."); return false; diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index 3381e6d..9aa5212 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -156,7 +156,7 @@ static const struct BoolNode : public cmGeneratorExpressionNode const GeneratorExpressionContent* /*content*/, cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override { - return !cmSystemTools::IsOff(parameters.begin()->c_str()) ? "1" : "0"; + return !cmSystemTools::IsOff(*parameters.begin()) ? "1" : "0"; } } boolNode; diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index eb1852d..80a99d5 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -2556,7 +2556,7 @@ static void processIncludeDirectories( } } - if (!cmSystemTools::IsOff(entryInclude.c_str())) { + if (!cmSystemTools::IsOff(entryInclude)) { cmSystemTools::ConvertToUnixSlashes(entryInclude); } std::string inc = entryInclude; diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 92ede7f..ef5f6e9 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -176,7 +176,7 @@ std::string cmGlobalGenerator::SelectMakeProgram( const std::string& inMakeProgram, const std::string& makeDefault) const { std::string makeProgram = inMakeProgram; - if (cmSystemTools::IsOff(makeProgram.c_str())) { + if (cmSystemTools::IsOff(makeProgram)) { const char* makeProgramCSTR = this->CMakeInstance->GetCacheDefinition("CMAKE_MAKE_PROGRAM"); if (cmSystemTools::IsOff(makeProgramCSTR)) { @@ -184,7 +184,7 @@ std::string cmGlobalGenerator::SelectMakeProgram( } else { makeProgram = makeProgramCSTR; } - if (cmSystemTools::IsOff(makeProgram.c_str()) && !makeProgram.empty()) { + if (cmSystemTools::IsOff(makeProgram) && !makeProgram.empty()) { makeProgram = "CMAKE_MAKE_PROGRAM-NOTFOUND"; } } diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx index 28cbdc7..21121f2 100644 --- a/Source/cmGlobalVisualStudio7Generator.cxx +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -679,7 +679,7 @@ std::set cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild( std::unique_ptr cge = ge.Parse(propertyValue); if (cmSystemTools::IsOn( - cge->Evaluate(target->GetLocalGenerator(), i).c_str())) { + cge->Evaluate(target->GetLocalGenerator(), i))) { activeConfigs.insert(i); } } diff --git a/Source/cmIncludeDirectoryCommand.cxx b/Source/cmIncludeDirectoryCommand.cxx index 4f80fb8..eaaf64d 100644 --- a/Source/cmIncludeDirectoryCommand.cxx +++ b/Source/cmIncludeDirectoryCommand.cxx @@ -120,7 +120,7 @@ void cmIncludeDirectoryCommand::NormalizeInclude(std::string& inc) return; } - if (!cmSystemTools::IsOff(inc.c_str())) { + if (!cmSystemTools::IsOff(inc)) { cmSystemTools::ConvertToUnixSlashes(inc); if (!cmSystemTools::FileIsFullPath(inc)) { diff --git a/Source/cmInstalledFile.cxx b/Source/cmInstalledFile.cxx index 3ffeabd..0e06029 100644 --- a/Source/cmInstalledFile.cxx +++ b/Source/cmInstalledFile.cxx @@ -102,7 +102,7 @@ bool cmInstalledFile::GetPropertyAsBool(const std::string& prop) const { std::string value; bool isSet = this->GetProperty(prop, value); - return isSet && cmSystemTools::IsOn(value.c_str()); + return isSet && cmSystemTools::IsOn(value); } void cmInstalledFile::GetPropertyAsList(const std::string& prop, diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 532f9a9..aef9aa6 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2024,7 +2024,7 @@ void cmLocalGenerator::AppendIncludeDirectories( std::string inc = include; - if (!cmSystemTools::IsOff(inc.c_str())) { + if (!cmSystemTools::IsOff(inc)) { cmSystemTools::ConvertToUnixSlashes(inc); } diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 6127b57..90c8599 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1738,7 +1738,7 @@ void cmMakefile::AddCacheDefinition(const std::string& name, const char* value, cmSystemTools::ExpandListArgument(nvalue, files); nvalue.clear(); for (cc = 0; cc < files.size(); cc++) { - if (!cmSystemTools::IsOff(files[cc].c_str())) { + if (!cmSystemTools::IsOff(files[cc])) { files[cc] = cmSystemTools::CollapseFullPath(files[cc]); } if (cc > 0) { diff --git a/Source/cmOptionCommand.cxx b/Source/cmOptionCommand.cxx index 239cd00..816f06c 100644 --- a/Source/cmOptionCommand.cxx +++ b/Source/cmOptionCommand.cxx @@ -67,7 +67,7 @@ bool cmOptionCommand::InitialPass(std::vector const& args, if (args.size() == 3) { initialValue = args[2]; } - bool init = cmSystemTools::IsOn(initialValue.c_str()); + bool init = cmSystemTools::IsOn(initialValue); this->Makefile->AddCacheDefinition(args[0], init ? "ON" : "OFF", args[1].c_str(), cmStateEnums::BOOL); diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index 5dd3c8b..8bd985a 100644 --- a/Source/cmQtAutoGenInitializer.cxx +++ b/Source/cmQtAutoGenInitializer.cxx @@ -205,8 +205,7 @@ bool cmQtAutoGenInitializer::InitCustomTargets() unsigned long iVerb = 0; if (!cmSystemTools::StringToULong(this->Verbosity.c_str(), &iVerb)) { // Non numeric verbosity - this->Verbosity = - cmSystemTools::IsOn(this->Verbosity.c_str()) ? "1" : "0"; + this->Verbosity = cmSystemTools::IsOn(this->Verbosity) ? "1" : "0"; } } diff --git a/Source/cmQtAutoGenerator.cxx b/Source/cmQtAutoGenerator.cxx index 64ce0e3..734b2d7 100644 --- a/Source/cmQtAutoGenerator.cxx +++ b/Source/cmQtAutoGenerator.cxx @@ -645,7 +645,7 @@ cmQtAutoGenerator::cmQtAutoGenerator() Logger_.SetVerbosity(static_cast(iVerbose)); } else { // Non numeric verbosity - Logger_.SetVerbose(cmSystemTools::IsOn(verbose.c_str())); + Logger_.SetVerbose(cmSystemTools::IsOn(verbose)); } } } @@ -653,7 +653,7 @@ cmQtAutoGenerator::cmQtAutoGenerator() std::string colorEnv; cmSystemTools::GetEnv("COLOR", colorEnv); if (!colorEnv.empty()) { - Logger_.SetColorOutput(cmSystemTools::IsOn(colorEnv.c_str())); + Logger_.SetColorOutput(cmSystemTools::IsOn(colorEnv)); } else { Logger_.SetColorOutput(true); } diff --git a/Source/cmSetPropertyCommand.cxx b/Source/cmSetPropertyCommand.cxx index 171b62e..3c4111b 100644 --- a/Source/cmSetPropertyCommand.cxx +++ b/Source/cmSetPropertyCommand.cxx @@ -330,8 +330,8 @@ bool cmSetPropertyCommand::HandleTest(cmTest* test) bool cmSetPropertyCommand::HandleCacheMode() { if (this->PropertyName == "ADVANCED") { - if (!this->Remove && !cmSystemTools::IsOn(this->PropertyValue.c_str()) && - !cmSystemTools::IsOff(this->PropertyValue.c_str())) { + if (!this->Remove && !cmSystemTools::IsOn(this->PropertyValue) && + !cmSystemTools::IsOff(this->PropertyValue)) { std::ostringstream e; e << "given non-boolean value \"" << this->PropertyValue << "\" for CACHE property \"ADVANCED\". "; diff --git a/Source/cmSetSourceFilesPropertiesCommand.cxx b/Source/cmSetSourceFilesPropertiesCommand.cxx index 33e1b2e..8445b02 100644 --- a/Source/cmSetSourceFilesPropertiesCommand.cxx +++ b/Source/cmSetSourceFilesPropertiesCommand.cxx @@ -87,7 +87,7 @@ bool cmSetSourceFilesPropertiesCommand::RunCommand( propertyPairs.push_back(*j); if (*j == "GENERATED") { ++j; - if (j != propend && cmSystemTools::IsOn(j->c_str())) { + if (j != propend && cmSystemTools::IsOn(*j)) { generated = true; } } else { diff --git a/Source/cmSiteNameCommand.cxx b/Source/cmSiteNameCommand.cxx index d2e83a6..7f33b7a 100644 --- a/Source/cmSiteNameCommand.cxx +++ b/Source/cmSiteNameCommand.cxx @@ -50,7 +50,7 @@ bool cmSiteNameCommand::InitialPass(std::vector const& args, } #else // try to find the hostname for this computer - if (!cmSystemTools::IsOff(hostname_cmd.c_str())) { + if (!cmSystemTools::IsOff(hostname_cmd)) { std::string host; cmSystemTools::RunSingleCommand(hostname_cmd.c_str(), &host, nullptr, nullptr, nullptr, diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index ea65e21..d239193 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -1798,7 +1798,7 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(Elem& e1, "EnableDebuggingInformation", "'$(Configuration)|$(Platform)'=='" + this->Configurations[i] + "|" + this->Platform + "'", - cmSystemTools::IsOn(enableDebug.c_str()) ? "true" : "false"); + cmSystemTools::IsOn(enableDebug) ? "true" : "false"); } } } @@ -1815,8 +1815,7 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(Elem& e1, "DisableOptimizations", "'$(Configuration)|$(Platform)'=='" + this->Configurations[i] + "|" + this->Platform + "'", - (cmSystemTools::IsOn(disableOptimizations.c_str()) ? "true" - : "false")); + (cmSystemTools::IsOn(disableOptimizations) ? "true" : "false")); } } } diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 2027722..87da108 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -917,8 +917,8 @@ int cmcmd::ExecuteCMakeCommand(std::vector& args) if (args.size() >= 9 && args[8].length() >= 8 && args[8].substr(0, 8) == "--color=") { // Enable or disable color based on the switch value. - color = (args[8].size() == 8 || - cmSystemTools::IsOn(args[8].substr(8).c_str())); + color = + (args[8].size() == 8 || cmSystemTools::IsOn(args[8].substr(8))); } } else { // Support older signature for existing makefiles: @@ -1354,7 +1354,7 @@ int cmcmd::ExecuteEchoColor(std::vector& args) // Enable or disable color based on the switch value. std::string value = args[i].substr(9); if (!value.empty()) { - enabled = cmSystemTools::IsOn(value.c_str()); + enabled = cmSystemTools::IsOn(value); } } else if (cmHasLiteralPrefix(args[i], "--progress-dir=")) { progressDir = args[i].substr(15); @@ -1407,7 +1407,7 @@ int cmcmd::ExecuteLinkScript(std::vector& args) bool verbose = false; if (args.size() >= 4) { if (args[3].find("--verbose=") == 0) { - if (!cmSystemTools::IsOff(args[3].substr(10).c_str())) { + if (!cmSystemTools::IsOff(args[3].substr(10))) { verbose = true; } } ----------------------------------------------------------------------- Summary of changes: Source/CTest/cmCTestBuildHandler.cxx | 2 +- Source/CTest/cmCTestGIT.cxx | 2 +- Source/CTest/cmCTestTestHandler.cxx | 8 ++++---- Source/CTest/cmCTestVC.cxx | 2 +- Source/CursesDialog/cmCursesMainForm.cxx | 2 +- Source/cmCTest.cxx | 9 ++++----- Source/cmCacheManager.cxx | 2 +- Source/cmFLTKWrapUICommand.cxx | 2 +- Source/cmFileCommand.cxx | 8 ++++---- Source/cmFindLibraryCommand.cxx | 4 ++-- Source/cmGeneratorExpressionNode.cxx | 2 +- Source/cmGeneratorTarget.cxx | 2 +- Source/cmGlobalGenerator.cxx | 6 +++--- Source/cmGlobalVisualStudio7Generator.cxx | 2 +- Source/cmIncludeDirectoryCommand.cxx | 2 +- Source/cmInstalledFile.cxx | 2 +- Source/cmLocalCommonGenerator.cxx | 3 +-- Source/cmLocalGenerator.cxx | 4 ++-- Source/cmLocalVisualStudio7Generator.cxx | 7 +++---- Source/cmMakefile.cxx | 8 ++++---- Source/cmMakefile.h | 2 +- Source/cmNinjaNormalTargetGenerator.cxx | 4 ++-- Source/cmOptionCommand.cxx | 2 +- Source/cmQTWrapCPPCommand.cxx | 2 +- Source/cmQTWrapUICommand.cxx | 4 ++-- Source/cmQtAutoGenInitializer.cxx | 3 +-- Source/cmQtAutoGenerator.cxx | 4 ++-- Source/cmSetPropertyCommand.cxx | 4 ++-- Source/cmSetSourceFilesPropertiesCommand.cxx | 2 +- Source/cmSiteNameCommand.cxx | 2 +- Source/cmUtilitySourceCommand.cxx | 4 ++-- Source/cmVisualStudio10TargetGenerator.cxx | 7 +++---- Source/cmcmd.cxx | 8 ++++---- 33 files changed, 61 insertions(+), 66 deletions(-) hooks/post-receive -- CMake From kwrobot at kitware.com Thu Sep 6 10:05:09 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Thu, 6 Sep 2018 10:05:09 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.1-573-gf782759 Message-ID: <20180906140509.6CC94110269@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via f782759ed0997eb3d71e1187a829da62668ed5d2 (commit) via 036db90b9def3022091e4dd366dc42fc50d7b8ac (commit) via 488faed3ce62fc98395bbb6e38c99a63e90a5584 (commit) via 3dd926f4a8b0994f46b9dc877bc954fb3531bc5e (commit) via bfe883af60cdf8f1c31a8b1d39a6f4f818578773 (commit) via 53bae4cc5e654266fa7f476d6e7e2b27217c8c38 (commit) from e1ebec55d4b3e9db2c718064237707252ec4abf5 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=f782759ed0997eb3d71e1187a829da62668ed5d2 commit f782759ed0997eb3d71e1187a829da62668ed5d2 Merge: 036db90 53bae4c Author: Brad King AuthorDate: Thu Sep 6 14:00:11 2018 +0000 Commit: Kitware Robot CommitDate: Thu Sep 6 10:00:25 2018 -0400 Merge topic 'CMakeFindBinUtils-fix-not-cached' 53bae4cc5e CMakeFindBinUtils: Fix use with non-cached tool settings Acked-by: Kitware Robot Merge-request: !2355 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=036db90b9def3022091e4dd366dc42fc50d7b8ac commit 036db90b9def3022091e4dd366dc42fc50d7b8ac Merge: 488faed 3dd926f Author: Brad King AuthorDate: Thu Sep 6 09:57:08 2018 -0400 Commit: Brad King CommitDate: Thu Sep 6 09:57:08 2018 -0400 Merge branch 'release-3.12' https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=488faed3ce62fc98395bbb6e38c99a63e90a5584 commit 488faed3ce62fc98395bbb6e38c99a63e90a5584 Merge: e1ebec5 bfe883a Author: Brad King AuthorDate: Thu Sep 6 13:56:25 2018 +0000 Commit: Kitware Robot CommitDate: Thu Sep 6 09:56:36 2018 -0400 Merge topic 'FindMatlab-no-CMAKE_CL_64' bfe883af60 FindMatlab: Remove erroneous duplicate code Acked-by: Kitware Robot Merge-request: !2354 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=53bae4cc5e654266fa7f476d6e7e2b27217c8c38 commit 53bae4cc5e654266fa7f476d6e7e2b27217c8c38 Author: Brad King AuthorDate: Wed Sep 5 14:57:15 2018 -0400 Commit: Brad King CommitDate: Wed Sep 5 15:03:02 2018 -0400 CMakeFindBinUtils: Fix use with non-cached tool settings If a project or toolchain file hard-codes a tool location such as `CMAKE_LINKER` with a plain `set()` then the value will be stored in compiler information files but not cached. If the value is not cached then we should not mark it as advanced because doing so will initialize an empty cache entry. Fixes: #18315 diff --git a/Modules/CMakeFindBinUtils.cmake b/Modules/CMakeFindBinUtils.cmake index 1b6823c..830639d 100644 --- a/Modules/CMakeFindBinUtils.cmake +++ b/Modules/CMakeFindBinUtils.cmake @@ -38,6 +38,8 @@ if(CMAKE_LINKER) endif() endif() +set(_CMAKE_TOOL_VARS "") + # if it's the MS C/CXX compiler, search for link if("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_SIMULATE_ID}" STREQUAL "xMSVC" OR "x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" STREQUAL "xMSVC" @@ -47,7 +49,7 @@ if("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_SIMULATE_ID}" STREQUAL "xMSVC" find_program(CMAKE_LINKER NAMES link HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) - mark_as_advanced(CMAKE_LINKER) + list(APPEND _CMAKE_TOOL_VARS CMAKE_LINKER) # in all other cases search for ar, ranlib, etc. else() @@ -70,7 +72,7 @@ else() find_program(CMAKE_OBJDUMP NAMES ${_CMAKE_TOOLCHAIN_PREFIX}objdump HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) find_program(CMAKE_OBJCOPY NAMES ${_CMAKE_TOOLCHAIN_PREFIX}objcopy HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) - mark_as_advanced(CMAKE_AR CMAKE_RANLIB CMAKE_STRIP CMAKE_LINKER CMAKE_NM CMAKE_OBJDUMP CMAKE_OBJCOPY) + list(APPEND _CMAKE_TOOL_VARS CMAKE_AR CMAKE_RANLIB CMAKE_STRIP CMAKE_LINKER CMAKE_NM CMAKE_OBJDUMP CMAKE_OBJCOPY) endif() @@ -81,5 +83,15 @@ if(CMAKE_PLATFORM_HAS_INSTALLNAME) message(FATAL_ERROR "Could not find install_name_tool, please check your installation.") endif() - mark_as_advanced(CMAKE_INSTALL_NAME_TOOL) + list(APPEND _CMAKE_TOOL_VARS CMAKE_INSTALL_NAME_TOOL) endif() + +# Mark any tool cache entries as advanced. +foreach(var IN LISTS _CMAKE_TOOL_VARS) + get_property(_CMAKE_TOOL_CACHED CACHE ${var} PROPERTY TYPE) + if(_CMAKE_TOOL_CACHED) + mark_as_advanced(${var}) + endif() +endforeach() +unset(_CMAKE_TOOL_VARS) +unset(_CMAKE_TOOL_CACHED) ----------------------------------------------------------------------- Summary of changes: Modules/CMakeFindBinUtils.cmake | 18 +++++++++++++++--- Modules/FindMatlab.cmake | 15 --------------- 2 files changed, 15 insertions(+), 18 deletions(-) hooks/post-receive -- CMake From kwrobot at kitware.com Thu Sep 6 10:05:09 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Thu, 6 Sep 2018 10:05:09 -0400 (EDT) Subject: [Cmake-commits] CMake branch, release, updated. v3.12.1-22-g3dd926f Message-ID: <20180906140509.AB56D1100AC@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, release has been updated via 3dd926f4a8b0994f46b9dc877bc954fb3531bc5e (commit) via bfe883af60cdf8f1c31a8b1d39a6f4f818578773 (commit) from 925b95fbadae0fe59f38b744dfb0f665436d8d11 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- ----------------------------------------------------------------------- Summary of changes: Modules/FindMatlab.cmake | 15 --------------- 1 file changed, 15 deletions(-) hooks/post-receive -- CMake From kwrobot at kitware.com Fri Sep 7 00:05:09 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Fri, 7 Sep 2018 00:05:09 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.1-574-gb218841 Message-ID: <20180907040511.590351250AE@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via b218841079a71671a0ac6c8ad287cddeb66386e7 (commit) from f782759ed0997eb3d71e1187a829da62668ed5d2 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=b218841079a71671a0ac6c8ad287cddeb66386e7 commit b218841079a71671a0ac6c8ad287cddeb66386e7 Author: Kitware Robot AuthorDate: Fri Sep 7 00:01:11 2018 -0400 Commit: Kitware Robot CommitDate: Fri Sep 7 00:01:11 2018 -0400 CMake Nightly Date Stamp diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 3bd0714..e46ab68 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 12) -set(CMake_VERSION_PATCH 20180906) +set(CMake_VERSION_PATCH 20180907) #set(CMake_VERSION_RC 1) ----------------------------------------------------------------------- Summary of changes: Source/CMakeVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) hooks/post-receive -- CMake From kwrobot at kitware.com Fri Sep 7 08:05:08 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Fri, 7 Sep 2018 08:05:08 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-553-g424d86b Message-ID: <20180907120509.46040113926@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 424d86be5b332d2f5b85dfd2ba2900430f7e02c3 (commit) via f478fa633daeb1432805821adddc40730ffd283d (commit) from b218841079a71671a0ac6c8ad287cddeb66386e7 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=424d86be5b332d2f5b85dfd2ba2900430f7e02c3 commit 424d86be5b332d2f5b85dfd2ba2900430f7e02c3 Merge: b218841 f478fa6 Author: Brad King AuthorDate: Fri Sep 7 07:54:44 2018 -0400 Commit: Brad King CommitDate: Fri Sep 7 07:54:44 2018 -0400 Merge branch 'release-3.12' ----------------------------------------------------------------------- Summary of changes: hooks/post-receive -- CMake From kwrobot at kitware.com Fri Sep 7 08:05:09 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Fri, 7 Sep 2018 08:05:09 -0400 (EDT) Subject: [Cmake-commits] CMake branch, release, updated. v3.12.2 Message-ID: <20180907120509.87D90113870@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, release has been updated via f478fa633daeb1432805821adddc40730ffd283d (commit) from 3dd926f4a8b0994f46b9dc877bc954fb3531bc5e (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- ----------------------------------------------------------------------- Summary of changes: Source/CMakeVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) hooks/post-receive -- CMake From kwrobot at kitware.com Fri Sep 7 08:05:09 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Fri, 7 Sep 2018 08:05:09 -0400 (EDT) Subject: [Cmake-commits] CMake annotated tag, v3.12.2, created. v3.12.2 Message-ID: <20180907120510.251EF113926@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The annotated tag, v3.12.2 has been created at 653d3a7d858dc082e75919e4d784fb020c351658 (tag) tagging f478fa633daeb1432805821adddc40730ffd283d (commit) replaces v3.12.1 tagged by Brad King on Fri Sep 7 07:52:33 2018 -0400 - Log ----------------------------------------------------------------- CMake 3.12.2 -----BEGIN PGP SIGNATURE----- iQJKBAABCgA0FiEExsJlMku+vcNQtRPQLSzvEDSSFoQFAluSZoEWHGJyYWQua2lu Z0BraXR3YXJlLmNvbQAKCRAtLO8QNJIWhG7SD/4vpJsLKDlmCSf3Jd8+KsJLLV1S XqjD3zOSdkUMj3zOl4F9js4ILAjKpGJiiM9YhSsgcH3q80uk1lOE9wGvtfJ80Eh/ iE19qWHH0T2wM8hXwjJjpKD5EY4j+/cS2rCQO+4p0GxJ4kKNbacHSM8iJTYdBR0w aEAUTF9reH3GGeQ5tE8qOKVhxfEHZVVAYX1mBi4Ab9HtfvOukaF8LY527tAmHQC7 jZLgdo5uW+Y0Vm5TiWeQrNrszqiOqaBtGqo3N1K63dLgbYUBOIJsNeB9RTRDGdfL XdTINy/Pa7yh20Z88xP/EOLmBrnUyKbaJtjUJ7jdUEr1T9pBbxjYe60T6sgEoL7K TfRaEZtB6qE2DEY8jRAXvy1+68/6xNuHaUFlNIepoQmuugaiaZThJoK1ExquAA4j 7f03eeuGNY+uP41CMJu2m5Mffu5OIlBYsia9qM3DrC3GGvk2/YB5zhxYLgu91HZ+ t/055eN+nsQ3PBT7t+ljrHEUOAcWYE0I28aa57PqZSa3zN4TUbwdbR4jb+ER4H4Y JmU8NXUQMbTtrImNQ5f9UVwTX1mmnDc8KaRk5Ycqlozuzf5+8YZUcj3F9JaKClT0 y7TNjukQStYtnZl+YvKbGRCrro5nLLM+IRt4gR43VMS+q0jcuGt4GIq8aPcCuDnv B2m6sxDQPM05Fgy5ew== =Jhtf -----END PGP SIGNATURE----- Brad King (14): Merge branch 'state-reset-glob' into release-3.12 Merge branch 'cuda-no-cublas_device' into release-3.12 Merge branch 'FindCUDA-deprecate-cublas_device' into release-3.12 Merge branch 'doc-clang-tidy-typo' into release-3.12 Android: Add support for NDK r18 Merge branch 'android-ndk-r18' into release-3.12 CheckIPOSupported: Simplify result reporting logic CheckIPOSupported: Tolerate backslashes in output of failed checks Merge branch 'CheckIPOSupported-output-backslashes' into release-3.12 Merge branch 'FindBoost-old-context' into release-3.12 VS: Restore CMakeLists.txt references in each target Merge branch 'vs-CMakeLists.txt' into release-3.12 Merge branch 'FindMatlab-no-CMAKE_CL_64' into release-3.12 CMake 3.12.2 Craig Scott (3): EXPORT_PROPERTIES: Add test for an undefined property EXPORT_PROPERTIES: Prevent null dereference for undefined property Merge branch 'export-properties-undefined' into release-3.12 David Demelier (1): Help: Fix typo in clang-tidy example -checks option Igor Kostenko (1): FindBoost: Fix context discovery for 1.60 and below Kenta Kubo (1): FindCUDA: Do not find cublas_device on CUDA >= 9.2 Raffi Enficiaud (1): FindMatlab: Remove erroneous duplicate code Robert Maynard (1): CUDA: Avoid using deprecated cublas_device to identify device lib dirs Shane Parris (1): cmState: Clear GlobVerificationManager state on Reset ----------------------------------------------------------------------- hooks/post-receive -- CMake From kwrobot at kitware.com Fri Sep 7 16:15:05 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Fri, 7 Sep 2018 16:15:05 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-555-g917d986 Message-ID: <20180907201505.656CEE5CB0@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 917d98699e8dd13de89e2993b0b630cf64f17706 (commit) via 437d0c16c72a45da8c81919f953859f5af71b19b (commit) from 424d86be5b332d2f5b85dfd2ba2900430f7e02c3 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=917d98699e8dd13de89e2993b0b630cf64f17706 commit 917d98699e8dd13de89e2993b0b630cf64f17706 Merge: 424d86b 437d0c1 Author: Brad King AuthorDate: Fri Sep 7 20:07:48 2018 +0000 Commit: Kitware Robot CommitDate: Fri Sep 7 16:08:02 2018 -0400 Merge topic 'definitions-get' 437d0c16c7 cmStateSnapshot::GetDefinition(): Return std::string const* Acked-by: Kitware Robot Merge-request: !2356 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=437d0c16c72a45da8c81919f953859f5af71b19b commit 437d0c16c72a45da8c81919f953859f5af71b19b Author: Vitaly Stakhovsky AuthorDate: Wed Sep 5 20:08:17 2018 -0400 Commit: Vitaly Stakhovsky CommitDate: Wed Sep 5 20:08:17 2018 -0400 cmStateSnapshot::GetDefinition(): Return std::string const* Expose std::string type used internally in cmDefinitions instead of const char* diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx index e766854..5fafaf9 100644 --- a/Source/cmDefinitions.cxx +++ b/Source/cmDefinitions.cxx @@ -30,11 +30,11 @@ cmDefinitions::Def const& cmDefinitions::GetInternal(const std::string& key, return begin->Map.insert(MapType::value_type(key, def)).first->second; } -const char* cmDefinitions::Get(const std::string& key, StackIter begin, - StackIter end) +const std::string* cmDefinitions::Get(const std::string& key, StackIter begin, + StackIter end) { Def const& def = cmDefinitions::GetInternal(key, begin, end, false); - return def.Exists ? def.c_str() : nullptr; + return def.Exists ? &def : nullptr; } void cmDefinitions::Raise(const std::string& key, StackIter begin, diff --git a/Source/cmDefinitions.h b/Source/cmDefinitions.h index 528b157..4ab5be6 100644 --- a/Source/cmDefinitions.h +++ b/Source/cmDefinitions.h @@ -23,8 +23,8 @@ class cmDefinitions typedef cmLinkedTree::iterator StackIter; public: - static const char* Get(const std::string& key, StackIter begin, - StackIter end); + static const std::string* Get(const std::string& key, StackIter begin, + StackIter end); static void Raise(const std::string& key, StackIter begin, StackIter end); diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 6127b57..8d2f932 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -2368,8 +2368,10 @@ const char* cmMakefile::GetRequiredDefinition(const std::string& name) const bool cmMakefile::IsDefinitionSet(const std::string& name) const { - const char* def = this->StateSnapshot.GetDefinition(name); - if (!def) { + const char* def; + if (const std::string* d = this->StateSnapshot.GetDefinition(name)) { + def = d->c_str(); + } else { def = this->GetState()->GetInitializedCacheValue(name); } #ifdef CMAKE_BUILD_WITH_CMAKE @@ -2385,8 +2387,10 @@ bool cmMakefile::IsDefinitionSet(const std::string& name) const const char* cmMakefile::GetDefinition(const std::string& name) const { - const char* def = this->StateSnapshot.GetDefinition(name); - if (!def) { + const char* def; + if (const std::string* d = this->StateSnapshot.GetDefinition(name)) { + def = d->c_str(); + } else { def = this->GetState()->GetInitializedCacheValue(name); } #ifdef CMAKE_BUILD_WITH_CMAKE @@ -2402,8 +2406,9 @@ const char* cmMakefile::GetDefinition(const std::string& name) const // A callback was executed and may have caused re-allocation of the // variable storage. Look it up again for now. // FIXME: Refactor variable storage to avoid this problem. - def = this->StateSnapshot.GetDefinition(name); - if (!def) { + if (const std::string* d = this->StateSnapshot.GetDefinition(name)) { + def = d->c_str(); + } else { def = this->GetState()->GetInitializedCacheValue(name); } } diff --git a/Source/cmOptionCommand.cxx b/Source/cmOptionCommand.cxx index 239cd00..7d620bd 100644 --- a/Source/cmOptionCommand.cxx +++ b/Source/cmOptionCommand.cxx @@ -31,7 +31,7 @@ bool cmOptionCommand::InitialPass(std::vector const& args, bool checkAndWarn = false; { auto status = this->Makefile->GetPolicyStatus(cmPolicies::CMP0077); - const char* existsBeforeSet = + const auto* existsBeforeSet = this->Makefile->GetStateSnapshot().GetDefinition(args[0]); switch (status) { case cmPolicies::WARN: @@ -72,7 +72,7 @@ bool cmOptionCommand::InitialPass(std::vector const& args, args[1].c_str(), cmStateEnums::BOOL); if (checkAndWarn) { - const char* existsAfterSet = + const auto* existsAfterSet = this->Makefile->GetStateSnapshot().GetDefinition(args[0]); if (!existsAfterSet) { std::ostringstream w; diff --git a/Source/cmState.cxx b/Source/cmState.cxx index 5651594..89738f4 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -298,9 +298,9 @@ cmStateSnapshot cmState::Reset() { std::string srcDir = - cmDefinitions::Get("CMAKE_SOURCE_DIR", pos->Vars, pos->Root); + *cmDefinitions::Get("CMAKE_SOURCE_DIR", pos->Vars, pos->Root); std::string binDir = - cmDefinitions::Get("CMAKE_BINARY_DIR", pos->Vars, pos->Root); + *cmDefinitions::Get("CMAKE_BINARY_DIR", pos->Vars, pos->Root); this->VarTree.Clear(); pos->Vars = this->VarTree.Push(this->VarTree.Root()); pos->Parent = this->VarTree.Root(); diff --git a/Source/cmStateSnapshot.cxx b/Source/cmStateSnapshot.cxx index ec428a6..0379e7e 100644 --- a/Source/cmStateSnapshot.cxx +++ b/Source/cmStateSnapshot.cxx @@ -204,7 +204,8 @@ bool cmStateSnapshot::HasDefinedPolicyCMP0011() return !this->Position->Policies->IsEmpty(); } -const char* cmStateSnapshot::GetDefinition(std::string const& name) const +std::string const* cmStateSnapshot::GetDefinition( + std::string const& name) const { assert(this->Position->Vars.IsValid()); return cmDefinitions::Get(name, this->Position->Vars, this->Position->Root); @@ -426,8 +427,8 @@ std::string cmStateSnapshot::GetProjectName() const void cmStateSnapshot::InitializeFromParent_ForSubdirsCommand() { - std::string currentSrcDir = this->GetDefinition("CMAKE_CURRENT_SOURCE_DIR"); - std::string currentBinDir = this->GetDefinition("CMAKE_CURRENT_BINARY_DIR"); + std::string currentSrcDir = *this->GetDefinition("CMAKE_CURRENT_SOURCE_DIR"); + std::string currentBinDir = *this->GetDefinition("CMAKE_CURRENT_BINARY_DIR"); this->InitializeFromParent(); this->SetDefinition("CMAKE_SOURCE_DIR", this->State->GetSourceDirectory()); this->SetDefinition("CMAKE_BINARY_DIR", this->State->GetBinaryDirectory()); diff --git a/Source/cmStateSnapshot.h b/Source/cmStateSnapshot.h index af5653b..014c62e 100644 --- a/Source/cmStateSnapshot.h +++ b/Source/cmStateSnapshot.h @@ -22,7 +22,7 @@ public: cmStateSnapshot(cmState* state = nullptr); cmStateSnapshot(cmState* state, cmStateDetail::PositionType position); - const char* GetDefinition(std::string const& name) const; + std::string const* GetDefinition(std::string const& name) const; bool IsInitialized(std::string const& name) const; void SetDefinition(std::string const& name, std::string const& value); void RemoveDefinition(std::string const& name); ----------------------------------------------------------------------- Summary of changes: Source/cmDefinitions.cxx | 6 +++--- Source/cmDefinitions.h | 4 ++-- Source/cmMakefile.cxx | 17 +++++++++++------ Source/cmOptionCommand.cxx | 4 ++-- Source/cmState.cxx | 4 ++-- Source/cmStateSnapshot.cxx | 7 ++++--- Source/cmStateSnapshot.h | 2 +- 7 files changed, 25 insertions(+), 19 deletions(-) hooks/post-receive -- CMake From kwrobot at kitware.com Fri Sep 7 19:45:04 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Fri, 7 Sep 2018 19:45:04 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-557-g49cb2a5 Message-ID: <20180907234504.3EB1BFBA42@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 49cb2a504d1e00e51774a23bf1b91c982fa69e5d (commit) via df1ddeec128d68cc636f2dde6c2acd87af5658b6 (commit) from 917d98699e8dd13de89e2993b0b630cf64f17706 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=49cb2a504d1e00e51774a23bf1b91c982fa69e5d commit 49cb2a504d1e00e51774a23bf1b91c982fa69e5d Merge: 917d986 df1ddee Author: Craig Scott AuthorDate: Fri Sep 7 23:40:15 2018 +0000 Commit: Kitware Robot CommitDate: Fri Sep 7 19:40:24 2018 -0400 Merge topic 'ExternalProject-check-explicit-include' df1ddeec12 ExternalProject: Report error if local variables are not defined Acked-by: Kitware Robot Acked-by: Brad King Merge-request: !2281 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=df1ddeec128d68cc636f2dde6c2acd87af5658b6 commit df1ddeec128d68cc636f2dde6c2acd87af5658b6 Author: Jean-Christophe Fillion-Robin AuthorDate: Fri Aug 10 12:30:48 2018 -0400 Commit: Craig Scott CommitDate: Thu Sep 6 23:02:24 2018 +1000 ExternalProject: Report error if local variables are not defined Since in some situations, ExternalProject module may be included in a sub-directory, functions will be available in the global scope but local variables like "_ep_keywords_" will not be defined, this commit checks and reports an error indicating that the ExternalProject module must be explicitly included before using any of the ExternalProject_* functions that require the module's inclusion within the current scope or above. Co-authored-by: Pablo Hernandez Co-authored-by: Craig Scott diff --git a/Modules/ExternalProject.cmake b/Modules/ExternalProject.cmake index 0c5b33f..f987d2d 100644 --- a/Modules/ExternalProject.cmake +++ b/Modules/ExternalProject.cmake @@ -934,6 +934,11 @@ function(_ep_parse_arguments f name ns args) # We loop through ARGN and consider the namespace starting with an # upper-case letter followed by at least two more upper-case letters, # numbers or underscores to be keywords. + + if(NOT DEFINED _ExternalProject_SELF) + message(FATAL_ERROR "error: ExternalProject module must be explicitly included before using ${f} function") + endif() + set(key) foreach(arg IN LISTS args) diff --git a/Tests/RunCMake/ExternalProject/IncludeScope-Add-result.txt b/Tests/RunCMake/ExternalProject/IncludeScope-Add-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/ExternalProject/IncludeScope-Add-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/ExternalProject/IncludeScope-Add-stderr.txt b/Tests/RunCMake/ExternalProject/IncludeScope-Add-stderr.txt new file mode 100644 index 0000000..ff3e5c1 --- /dev/null +++ b/Tests/RunCMake/ExternalProject/IncludeScope-Add-stderr.txt @@ -0,0 +1,7 @@ +^CMake Error at .*/Modules/ExternalProject.cmake:[0-9]+ \(message\): + error: ExternalProject module must be explicitly included before using + ExternalProject_Add function +Call Stack \(most recent call first\): + .*/Modules/ExternalProject.cmake:[0-9]+ \(_ep_parse_arguments\) + IncludeScope-Add.cmake:[0-9]+ \(ExternalProject_Add\) + CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/ExternalProject/IncludeScope-Add.cmake b/Tests/RunCMake/ExternalProject/IncludeScope-Add.cmake new file mode 100644 index 0000000..1061ffd --- /dev/null +++ b/Tests/RunCMake/ExternalProject/IncludeScope-Add.cmake @@ -0,0 +1,12 @@ +function(IncludeScope_IncludeOnly) + include(ExternalProject) +endfunction() + +IncludeScope_IncludeOnly() + +ExternalProject_Add(MyProj + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" +) diff --git a/Tests/RunCMake/ExternalProject/IncludeScope-Add_Step-result.txt b/Tests/RunCMake/ExternalProject/IncludeScope-Add_Step-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/ExternalProject/IncludeScope-Add_Step-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/ExternalProject/IncludeScope-Add_Step-stderr.txt b/Tests/RunCMake/ExternalProject/IncludeScope-Add_Step-stderr.txt new file mode 100644 index 0000000..cbad4be --- /dev/null +++ b/Tests/RunCMake/ExternalProject/IncludeScope-Add_Step-stderr.txt @@ -0,0 +1,7 @@ +^CMake Error at .*/Modules/ExternalProject.cmake:[0-9]+ \(message\): + error: ExternalProject module must be explicitly included before using + ExternalProject_Add_Step function +Call Stack \(most recent call first\): + .*/Modules/ExternalProject.cmake:[0-9]+ \(_ep_parse_arguments\) + IncludeScope-Add_Step.cmake:[0-9]+ \(ExternalProject_Add_Step\) + CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/ExternalProject/IncludeScope-Add_Step.cmake b/Tests/RunCMake/ExternalProject/IncludeScope-Add_Step.cmake new file mode 100644 index 0000000..2a820f8 --- /dev/null +++ b/Tests/RunCMake/ExternalProject/IncludeScope-Add_Step.cmake @@ -0,0 +1,13 @@ +function(IncludeScope_DefineProj) + include(ExternalProject) + ExternalProject_Add(MyProj + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + ) +endfunction() + +IncludeScope_DefineProj() + +ExternalProject_Add_Step(MyProj extraStep COMMENT "Foo") diff --git a/Tests/RunCMake/ExternalProject/RunCMakeTest.cmake b/Tests/RunCMake/ExternalProject/RunCMakeTest.cmake index 09607f6..bf11381 100644 --- a/Tests/RunCMake/ExternalProject/RunCMakeTest.cmake +++ b/Tests/RunCMake/ExternalProject/RunCMakeTest.cmake @@ -1,5 +1,7 @@ include(RunCMake) +run_cmake(IncludeScope-Add) +run_cmake(IncludeScope-Add_Step) run_cmake(NoOptions) run_cmake(SourceEmpty) run_cmake(SourceMissing) ----------------------------------------------------------------------- Summary of changes: Modules/ExternalProject.cmake | 5 +++++ .../IncludeScope-Add-result.txt} | 0 Tests/RunCMake/ExternalProject/IncludeScope-Add-stderr.txt | 7 +++++++ Tests/RunCMake/ExternalProject/IncludeScope-Add.cmake | 12 ++++++++++++ .../IncludeScope-Add_Step-result.txt} | 0 .../ExternalProject/IncludeScope-Add_Step-stderr.txt | 7 +++++++ Tests/RunCMake/ExternalProject/IncludeScope-Add_Step.cmake | 13 +++++++++++++ Tests/RunCMake/ExternalProject/RunCMakeTest.cmake | 2 ++ 8 files changed, 46 insertions(+) copy Tests/RunCMake/{while/MissingArgument-result.txt => ExternalProject/IncludeScope-Add-result.txt} (100%) create mode 100644 Tests/RunCMake/ExternalProject/IncludeScope-Add-stderr.txt create mode 100644 Tests/RunCMake/ExternalProject/IncludeScope-Add.cmake copy Tests/RunCMake/{while/MissingArgument-result.txt => ExternalProject/IncludeScope-Add_Step-result.txt} (100%) create mode 100644 Tests/RunCMake/ExternalProject/IncludeScope-Add_Step-stderr.txt create mode 100644 Tests/RunCMake/ExternalProject/IncludeScope-Add_Step.cmake hooks/post-receive -- CMake From kwrobot at kitware.com Sat Sep 8 00:05:10 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Sat, 8 Sep 2018 00:05:10 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-558-g958518c Message-ID: <20180908040510.D9AC4114220@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 958518c4c53e52b04cf51a8b1346c20878ce2800 (commit) from 49cb2a504d1e00e51774a23bf1b91c982fa69e5d (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=958518c4c53e52b04cf51a8b1346c20878ce2800 commit 958518c4c53e52b04cf51a8b1346c20878ce2800 Author: Kitware Robot AuthorDate: Sat Sep 8 00:01:11 2018 -0400 Commit: Kitware Robot CommitDate: Sat Sep 8 00:01:11 2018 -0400 CMake Nightly Date Stamp diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index e46ab68..a189c93 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 12) -set(CMake_VERSION_PATCH 20180907) +set(CMake_VERSION_PATCH 20180908) #set(CMake_VERSION_RC 1) ----------------------------------------------------------------------- Summary of changes: Source/CMakeVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) hooks/post-receive -- CMake From kwrobot at kitware.com Sun Sep 9 00:05:07 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Sun, 9 Sep 2018 00:05:07 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-559-gccb6dab Message-ID: <20180909040507.DFD8411D7C7@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via ccb6dab9f19bd19968dc2b94806dfc4cf22cdd79 (commit) from 958518c4c53e52b04cf51a8b1346c20878ce2800 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=ccb6dab9f19bd19968dc2b94806dfc4cf22cdd79 commit ccb6dab9f19bd19968dc2b94806dfc4cf22cdd79 Author: Kitware Robot AuthorDate: Sun Sep 9 00:01:08 2018 -0400 Commit: Kitware Robot CommitDate: Sun Sep 9 00:01:08 2018 -0400 CMake Nightly Date Stamp diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index a189c93..55b4cfc 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 12) -set(CMake_VERSION_PATCH 20180908) +set(CMake_VERSION_PATCH 20180909) #set(CMake_VERSION_RC 1) ----------------------------------------------------------------------- Summary of changes: Source/CMakeVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) hooks/post-receive -- CMake From kwrobot at kitware.com Mon Sep 10 00:05:04 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Mon, 10 Sep 2018 00:05:04 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-560-g1504c6d Message-ID: <20180910040504.C135F11EF55@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 1504c6db9067f30e293430c61641cfd6c2c515a6 (commit) from ccb6dab9f19bd19968dc2b94806dfc4cf22cdd79 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=1504c6db9067f30e293430c61641cfd6c2c515a6 commit 1504c6db9067f30e293430c61641cfd6c2c515a6 Author: Kitware Robot AuthorDate: Mon Sep 10 00:01:07 2018 -0400 Commit: Kitware Robot CommitDate: Mon Sep 10 00:01:07 2018 -0400 CMake Nightly Date Stamp diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 55b4cfc..83b75fb 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 12) -set(CMake_VERSION_PATCH 20180909) +set(CMake_VERSION_PATCH 20180910) #set(CMake_VERSION_RC 1) ----------------------------------------------------------------------- Summary of changes: Source/CMakeVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) hooks/post-receive -- CMake From kwrobot at kitware.com Mon Sep 10 08:05:07 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Mon, 10 Sep 2018 08:05:07 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-568-g11de149 Message-ID: <20180910120507.9FADD11394F@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 11de1492d3d96f4527990aee212cd94c944c6f64 (commit) via 0aab59809caea3cc69a4d24c95a38ea9657943c3 (commit) via 62b56b5ec961a6c44cdae598fac98fbde11a0cd3 (commit) via d6853ef405f1ac291d8304b9dbc30afb33831b01 (commit) via 68d015fc94af6e39212b051336d7dc7f5c18d1d2 (commit) via 0239b586bdca2173f8b7309bce7771f59ac99568 (commit) via 46855d000fcd624d2e1ea3ce79d0e8c6d0ba614c (commit) via 192e552099fcfbb30009db9d4284a04bb779231a (commit) from 1504c6db9067f30e293430c61641cfd6c2c515a6 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=11de1492d3d96f4527990aee212cd94c944c6f64 commit 11de1492d3d96f4527990aee212cd94c944c6f64 Merge: 0aab598 192e552 Author: Brad King AuthorDate: Mon Sep 10 12:01:06 2018 +0000 Commit: Kitware Robot CommitDate: Mon Sep 10 08:01:21 2018 -0400 Merge topic 'FindOpenSceneGraph-debug' 192e552099 FindOpenSceneGraph: Fix find in Debug Acked-by: Kitware Robot Merge-request: !2341 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=0aab59809caea3cc69a4d24c95a38ea9657943c3 commit 0aab59809caea3cc69a4d24c95a38ea9657943c3 Merge: 62b56b5 46855d0 Author: Brad King AuthorDate: Mon Sep 10 12:00:36 2018 +0000 Commit: Kitware Robot CommitDate: Mon Sep 10 08:00:41 2018 -0400 Merge topic 'gicv-stdstring' 46855d000f cmCacheManager::GetInitializedCacheValue(): Return as const std::string* Acked-by: Kitware Robot Merge-request: !2357 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=62b56b5ec961a6c44cdae598fac98fbde11a0cd3 commit 62b56b5ec961a6c44cdae598fac98fbde11a0cd3 Merge: d6853ef 68d015f Author: Brad King AuthorDate: Mon Sep 10 11:59:33 2018 +0000 Commit: Kitware Robot CommitDate: Mon Sep 10 07:59:42 2018 -0400 Merge topic 'FindSubversion-wc-info-error' 68d015fc94 FindSubversion: Add Subversion_WC_INFO option to suppress failures Acked-by: Kitware Robot Merge-request: !2292 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=d6853ef405f1ac291d8304b9dbc30afb33831b01 commit d6853ef405f1ac291d8304b9dbc30afb33831b01 Merge: 1504c6d 0239b58 Author: Brad King AuthorDate: Mon Sep 10 11:58:04 2018 +0000 Commit: Kitware Robot CommitDate: Mon Sep 10 07:58:10 2018 -0400 Merge topic 'extra-generator-split-arg1' 0239b586bd Extra Generator: Fix handling of CMAKE__COMPILER_ARG1 Acked-by: Kitware Robot Merge-request: !2352 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=68d015fc94af6e39212b051336d7dc7f5c18d1d2 commit 68d015fc94af6e39212b051336d7dc7f5c18d1d2 Author: Jason Heeris AuthorDate: Thu Aug 16 10:57:35 2018 +1000 Commit: Brad King CommitDate: Fri Sep 7 16:17:28 2018 -0400 FindSubversion: Add Subversion_WC_INFO option to suppress failures Subversion fails when the directory is not actually under its control. Allow projects to tolerate this case optionally. Fixes: #18264 diff --git a/Help/release/dev/FindSubversion-wc-info-error.rst b/Help/release/dev/FindSubversion-wc-info-error.rst new file mode 100644 index 0000000..eaf6bfe --- /dev/null +++ b/Help/release/dev/FindSubversion-wc-info-error.rst @@ -0,0 +1,6 @@ +FindSubversion-wc-info-error +---------------------------- + +* The :module:`FindSubversion` module ``Subversion_WC_INFO`` command + gained an ``IGNORE_SVN_FAILURE`` option to suppress failures, + e.g. when the source tree is not under Subversion control. diff --git a/Modules/FindSubversion.cmake b/Modules/FindSubversion.cmake index 537d3b2..e18ae88 100644 --- a/Modules/FindSubversion.cmake +++ b/Modules/FindSubversion.cmake @@ -19,17 +19,21 @@ # # # The minimum required version of Subversion can be specified using the -# standard syntax, e.g. find_package(Subversion 1.4) +# standard syntax, e.g. ``find_package(Subversion 1.4)``. # # If the command line client executable is found two macros are defined: # # :: # -# Subversion_WC_INFO( ) +# Subversion_WC_INFO( [IGNORE_SVN_FAILURE]) # Subversion_WC_LOG( ) # -# Subversion_WC_INFO extracts information of a subversion working copy -# at a given location. This macro defines the following variables: +# ``Subversion_WC_INFO`` extracts information of a subversion working copy at a +# given location. This macro defines the following variables if running +# Subversion's ``info`` command on ```` succeeds; otherwise a +# ``SEND_ERROR`` message is generated. The error can be ignored by providing the +# ``IGNORE_SVN_FAILURE`` option, which causes these variables to remain +# undefined. # # :: # @@ -41,9 +45,8 @@ # _WC_LAST_CHANGED_REV - revision of last commit # _WC_INFO - output of command `svn info ' # -# Subversion_WC_LOG retrieves the log message of the base revision of a -# subversion working copy at a given location. This macro defines the -# variable: +# ``Subversion_WC_LOG`` retrieves the log message of the base revision of a +# subversion working copy at a given location. This macro defines the variable: # # :: # @@ -84,6 +87,14 @@ if(Subversion_SVN_EXECUTABLE) "\\2" Subversion_VERSION_SVN "${Subversion_VERSION_SVN}") macro(Subversion_WC_INFO dir prefix) + + cmake_parse_arguments( + "Subversion_WC_INFO" + "IGNORE_SVN_FAILURE" + "" "" + ${ARGN} + ) + # the subversion commands should be executed with the C locale, otherwise # the message (which are parsed) may be translated, Alex set(_Subversion_SAVED_LC_ALL "$ENV{LC_ALL}") @@ -95,10 +106,7 @@ if(Subversion_SVN_EXECUTABLE) RESULT_VARIABLE Subversion_svn_info_result OUTPUT_STRIP_TRAILING_WHITESPACE) - if(NOT ${Subversion_svn_info_result} EQUAL 0) - message(SEND_ERROR "Command \"${Subversion_SVN_EXECUTABLE} info ${dir}\" failed with output:\n${Subversion_svn_info_error}") - else() - + if(${Subversion_svn_info_result} EQUAL 0) string(REGEX REPLACE "^(.*\n)?URL: ([^\n]+).*" "\\2" ${prefix}_WC_URL "${${prefix}_WC_INFO}") string(REGEX REPLACE "^(.*\n)?Repository Root: ([^\n]+).*" @@ -111,7 +119,8 @@ if(Subversion_SVN_EXECUTABLE) "\\2" ${prefix}_WC_LAST_CHANGED_REV "${${prefix}_WC_INFO}") string(REGEX REPLACE "^(.*\n)?Last Changed Date: ([^\n]+).*" "\\2" ${prefix}_WC_LAST_CHANGED_DATE "${${prefix}_WC_INFO}") - + elseif(NOT Subversion_WC_INFO_IGNORE_SVN_FAILURE) + message(SEND_ERROR "Command \"${Subversion_SVN_EXECUTABLE} info ${dir}\" failed with output:\n${Subversion_svn_info_error}") endif() # restore the previous LC_ALL https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=0239b586bdca2173f8b7309bce7771f59ac99568 commit 0239b586bdca2173f8b7309bce7771f59ac99568 Author: Adam Oleksy AuthorDate: Wed Sep 5 14:55:08 2018 +0200 Commit: Brad King CommitDate: Fri Sep 7 16:11:11 2018 -0400 Extra Generator: Fix handling of CMAKE__COMPILER_ARG1 The "arg1" value is a command-line string so we must parse it to get separate arguments for `execute_process`. diff --git a/Modules/CMakeExtraGeneratorDetermineCompilerMacrosAndIncludeDirs.cmake b/Modules/CMakeExtraGeneratorDetermineCompilerMacrosAndIncludeDirs.cmake index 55e0373..11f4a29 100644 --- a/Modules/CMakeExtraGeneratorDetermineCompilerMacrosAndIncludeDirs.cmake +++ b/Modules/CMakeExtraGeneratorDetermineCompilerMacrosAndIncludeDirs.cmake @@ -27,6 +27,7 @@ macro(_DETERMINE_GCC_SYSTEM_INCLUDE_DIRS _lang _resultIncludeDirs _resultDefines set(_compilerExecutable "${CMAKE_C_COMPILER}") set(_arg1 "${CMAKE_C_COMPILER_ARG1}") endif () + separate_arguments(_arg1 NATIVE_COMMAND "${_arg1}") execute_process(COMMAND ${_compilerExecutable} ${_arg1} ${_stdver} ${_stdlib} -v -E -x ${_lang} -dD dummy WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/CMakeFiles ERROR_VARIABLE _gccOutput https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=46855d000fcd624d2e1ea3ce79d0e8c6d0ba614c commit 46855d000fcd624d2e1ea3ce79d0e8c6d0ba614c Author: Vitaly Stakhovsky AuthorDate: Thu Sep 6 12:49:57 2018 -0400 Commit: Vitaly Stakhovsky CommitDate: Thu Sep 6 12:49:57 2018 -0400 cmCacheManager::GetInitializedCacheValue(): Return as const std::string* Expose std::string type used internally instead of const char* diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx index d2d419f..b391dc4 100644 --- a/Source/cmCacheManager.cxx +++ b/Source/cmCacheManager.cxx @@ -127,15 +127,15 @@ bool cmCacheManager::LoadCache(const std::string& path, bool internal, } this->CacheMajorVersion = 0; this->CacheMinorVersion = 0; - if (const char* cmajor = + if (const std::string* cmajor = this->GetInitializedCacheValue("CMAKE_CACHE_MAJOR_VERSION")) { unsigned int v = 0; - if (sscanf(cmajor, "%u", &v) == 1) { + if (sscanf(cmajor->c_str(), "%u", &v) == 1) { this->CacheMajorVersion = v; } - if (const char* cminor = + if (const std::string* cminor = this->GetInitializedCacheValue("CMAKE_CACHE_MINOR_VERSION")) { - if (sscanf(cminor, "%u", &v) == 1) { + if (sscanf(cminor->c_str(), "%u", &v) == 1) { this->CacheMinorVersion = v; } } @@ -153,18 +153,20 @@ bool cmCacheManager::LoadCache(const std::string& path, bool internal, } // check to make sure the cache directory has not // been moved - const char* oldDir = this->GetInitializedCacheValue("CMAKE_CACHEFILE_DIR"); + const std::string* oldDir = + this->GetInitializedCacheValue("CMAKE_CACHEFILE_DIR"); if (internal && oldDir) { std::string currentcwd = path; - std::string oldcwd = oldDir; + std::string oldcwd = *oldDir; cmSystemTools::ConvertToUnixSlashes(currentcwd); currentcwd += "/CMakeCache.txt"; oldcwd += "/CMakeCache.txt"; if (!cmSystemTools::SameFile(oldcwd, currentcwd)) { + const std::string* dir = + this->GetInitializedCacheValue("CMAKE_CACHEFILE_DIR"); std::ostringstream message; message << "The current CMakeCache.txt directory " << currentcwd - << " is different than the directory " - << this->GetInitializedCacheValue("CMAKE_CACHEFILE_DIR") + << " is different than the directory " << (dir ? *dir : "") << " where CMakeCache.txt was created. This may result " "in binaries being created in the wrong place. If you " "are not sure, reedit the CMakeCache.txt"; @@ -512,12 +514,12 @@ cmCacheManager::CacheIterator cmCacheManager::GetCacheIterator(const char* key) return CacheIterator(*this, key); } -const char* cmCacheManager::GetInitializedCacheValue( +const std::string* cmCacheManager::GetInitializedCacheValue( const std::string& key) const { CacheEntryMap::const_iterator i = this->Cache.find(key); if (i != this->Cache.end() && i->second.Initialized) { - return i->second.Value.c_str(); + return &i->second.Value; } return nullptr; } diff --git a/Source/cmCacheManager.h b/Source/cmCacheManager.h index 73923d1..a269271 100644 --- a/Source/cmCacheManager.h +++ b/Source/cmCacheManager.h @@ -126,7 +126,7 @@ public: int GetSize() { return static_cast(this->Cache.size()); } ///! Get a value from the cache given a key - const char* GetInitializedCacheValue(const std::string& key) const; + const std::string* GetInitializedCacheValue(const std::string& key) const; const char* GetCacheEntryValue(const std::string& key) { diff --git a/Source/cmState.cxx b/Source/cmState.cxx index 5651594..6c27a7d 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -142,7 +142,8 @@ const char* cmState::GetCacheEntryValue(std::string const& key) const const char* cmState::GetInitializedCacheValue(std::string const& key) const { - return this->CacheManager->GetInitializedCacheValue(key); + const std::string* p = this->CacheManager->GetInitializedCacheValue(key); + return p ? p->c_str() : nullptr; } cmStateEnums::CacheEntryType cmState::GetCacheEntryType( https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=192e552099fcfbb30009db9d4284a04bb779231a commit 192e552099fcfbb30009db9d4284a04bb779231a Author: Cyril Boucher AuthorDate: Wed Sep 5 16:15:37 2018 +0200 Commit: Cyril Boucher CommitDate: Thu Sep 6 09:32:56 2018 +0200 FindOpenSceneGraph: Fix find in Debug As of now, it is not possible to find OpenSceneGraph in Debug because the only variable find_package_handle_standard_args is checking is ${module}_LIBRARY while the debug library is in ${module}_LIBRARY_DEBUG. The refactoring gets rid of the old behaviour to replace with a call to select_library_configurations which will populated ${module}_LIBRARY accordingly. [Modules/Findosg_functions.cmake Modules/FindOpenThreads.cmake] - Include SelectLibraryConfigurations module - Modify the name of the variable that will be populated by the first find_library to ${MODULE}_LIBRARY_RELEASE so that SelectLibraryConfigurations can act on it - Add call to select_library_configurations after attempting to find libraries in debug and release diff --git a/Modules/FindOpenThreads.cmake b/Modules/FindOpenThreads.cmake index a197e4d..91545e0 100644 --- a/Modules/FindOpenThreads.cmake +++ b/Modules/FindOpenThreads.cmake @@ -47,6 +47,8 @@ # standard install paths. # Explicit -DVAR=value arguments should still be able to override everything. +include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake) + find_path(OPENTHREADS_INCLUDE_DIR OpenThreads/Thread HINTS ENV OPENTHREADS_INCLUDE_DIR @@ -62,7 +64,7 @@ find_path(OPENTHREADS_INCLUDE_DIR OpenThreads/Thread ) -find_library(OPENTHREADS_LIBRARY +find_library(OPENTHREADS_LIBRARY_RELEASE NAMES OpenThreads OpenThreadsWin32 HINTS ENV OPENTHREADS_LIBRARY_DIR @@ -93,13 +95,7 @@ find_library(OPENTHREADS_LIBRARY_DEBUG PATH_SUFFIXES lib ) -if(OPENTHREADS_LIBRARY_DEBUG) - set(OPENTHREADS_LIBRARIES - optimized ${OPENTHREADS_LIBRARY} - debug ${OPENTHREADS_LIBRARY_DEBUG}) -else() - set(OPENTHREADS_LIBRARIES ${OPENTHREADS_LIBRARY}) -endif() +select_library_configurations(OPENTHREADS) include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenThreads DEFAULT_MSG diff --git a/Modules/Findosg_functions.cmake b/Modules/Findosg_functions.cmake index 60de726..adaeb6b 100644 --- a/Modules/Findosg_functions.cmake +++ b/Modules/Findosg_functions.cmake @@ -13,6 +13,8 @@ # libraries and nodekits. Please see FindOpenSceneGraph.cmake for full # documentation. +include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake) + # # OSG_FIND_PATH # @@ -39,7 +41,7 @@ endfunction() function(OSG_FIND_LIBRARY module library) string(TOUPPER ${module} module_uc) - find_library(${module_uc}_LIBRARY + find_library(${module_uc}_LIBRARY_RELEASE NAMES ${library} HINTS ENV ${module_uc}_DIR @@ -63,18 +65,12 @@ function(OSG_FIND_LIBRARY module library) PATH_SUFFIXES lib ) - if(NOT ${module_uc}_LIBRARY_DEBUG) - # They don't have a debug library - set(${module_uc}_LIBRARY_DEBUG ${${module_uc}_LIBRARY} PARENT_SCOPE) - set(${module_uc}_LIBRARIES ${${module_uc}_LIBRARY} PARENT_SCOPE) - else() - # They really have a FOO_LIBRARY_DEBUG - set(${module_uc}_LIBRARIES - optimized ${${module_uc}_LIBRARY} - debug ${${module_uc}_LIBRARY_DEBUG} - PARENT_SCOPE - ) - endif() + select_library_configurations(${module_uc}) + + # the variables set by select_library_configurations go out of scope + # here, so we need to set them again + set(${module_uc}_LIBRARY ${${module_uc}_LIBRARY} PARENT_SCOPE) + set(${module_uc}_LIBRARIES ${${module_uc}_LIBRARIES} PARENT_SCOPE) endfunction() # ----------------------------------------------------------------------- Summary of changes: Help/release/dev/FindSubversion-wc-info-error.rst | 6 ++++ ...atorDetermineCompilerMacrosAndIncludeDirs.cmake | 1 + Modules/FindOpenThreads.cmake | 12 +++----- Modules/FindSubversion.cmake | 33 ++++++++++++++-------- Modules/Findosg_functions.cmake | 22 ++++++--------- Source/cmCacheManager.cxx | 22 ++++++++------- Source/cmCacheManager.h | 2 +- Source/cmState.cxx | 3 +- 8 files changed, 56 insertions(+), 45 deletions(-) create mode 100644 Help/release/dev/FindSubversion-wc-info-error.rst hooks/post-receive -- CMake From kwrobot at kitware.com Tue Sep 11 00:05:04 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Tue, 11 Sep 2018 00:05:04 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-569-ge895a8f Message-ID: <20180911040504.C24F5125294@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via e895a8f050d5e68a8e23dea7fb3e5a718344cd03 (commit) from 11de1492d3d96f4527990aee212cd94c944c6f64 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=e895a8f050d5e68a8e23dea7fb3e5a718344cd03 commit e895a8f050d5e68a8e23dea7fb3e5a718344cd03 Author: Kitware Robot AuthorDate: Tue Sep 11 00:01:07 2018 -0400 Commit: Kitware Robot CommitDate: Tue Sep 11 00:01:07 2018 -0400 CMake Nightly Date Stamp diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 83b75fb..1e9f499 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 12) -set(CMake_VERSION_PATCH 20180910) +set(CMake_VERSION_PATCH 20180911) #set(CMake_VERSION_RC 1) ----------------------------------------------------------------------- Summary of changes: Source/CMakeVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) hooks/post-receive -- CMake From kwrobot at kitware.com Tue Sep 11 05:55:10 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Tue, 11 Sep 2018 05:55:10 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-573-g78d165c Message-ID: <20180911095510.D691B11275D@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 78d165c9905f73237229497772769a6dc2c32982 (commit) via 151fc668273ca69ce0a75c1c03b489b08e531f10 (commit) via 3914108c4aecc758e0f23dda76ca4ad5cc1c1085 (commit) via 228a2b0d825712d6648f7bdf920850c7f38ed2b4 (commit) from e895a8f050d5e68a8e23dea7fb3e5a718344cd03 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=78d165c9905f73237229497772769a6dc2c32982 commit 78d165c9905f73237229497772769a6dc2c32982 Merge: 151fc66 3914108 Author: Craig Scott AuthorDate: Tue Sep 11 09:50:55 2018 +0000 Commit: Kitware Robot CommitDate: Tue Sep 11 05:51:03 2018 -0400 Merge topic 'generator_expressions_typo_fix' 3914108c4a Help: Formatting typo fix in cmake-generator-expressions(7) Acked-by: Kitware Robot Merge-request: !2360 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=151fc668273ca69ce0a75c1c03b489b08e531f10 commit 151fc668273ca69ce0a75c1c03b489b08e531f10 Merge: e895a8f 228a2b0 Author: Craig Scott AuthorDate: Tue Sep 11 09:48:33 2018 +0000 Commit: Kitware Robot CommitDate: Tue Sep 11 05:48:43 2018 -0400 Merge topic 'cmake-host-system-information-doc-fix' 228a2b0d82 Help: Clarify cmake_host_system_information memory units Acked-by: Kitware Robot Merge-request: !2339 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=3914108c4aecc758e0f23dda76ca4ad5cc1c1085 commit 3914108c4aecc758e0f23dda76ca4ad5cc1c1085 Author: Raul Tambre AuthorDate: Mon Sep 10 15:08:02 2018 +0300 Commit: Raul Tambre CommitDate: Mon Sep 10 15:08:02 2018 +0300 Help: Formatting typo fix in cmake-generator-expressions(7) diff --git a/Help/manual/cmake-generator-expressions.7.rst b/Help/manual/cmake-generator-expressions.7.rst index 8fd07d7..c3428d1 100644 --- a/Help/manual/cmake-generator-expressions.7.rst +++ b/Help/manual/cmake-generator-expressions.7.rst @@ -51,7 +51,7 @@ Available logical expressions are: ``0`` if all ``?`` are ``0``, else ``1`` ``$`` ``0`` if ``?`` is ``1``, else ``1`` -``$``` +``$`` ``true-value...`` if ``?`` is ``1``, ``false-value...`` if ``?`` is ``0`` ``$`` ``1`` if ``a`` is STREQUAL ``b``, else ``0`` https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=228a2b0d825712d6648f7bdf920850c7f38ed2b4 commit 228a2b0d825712d6648f7bdf920850c7f38ed2b4 Author: Taylor Holberton AuthorDate: Sun Sep 2 10:16:56 2018 -0400 Commit: Craig Scott CommitDate: Mon Sep 10 15:55:07 2018 +0800 Help: Clarify cmake_host_system_information memory units The memory size query implementations report in units of one mebibyte (2^20). Clarify the unit in the documentation because "megabyte" might also be interpreted as 10^6. diff --git a/Help/command/cmake_host_system_information.rst b/Help/command/cmake_host_system_information.rst index 9893151..2dee93a 100644 --- a/Help/command/cmake_host_system_information.rst +++ b/Help/command/cmake_host_system_information.rst @@ -20,10 +20,10 @@ Key Description ``NUMBER_OF_PHYSICAL_CORES`` Number of physical cores ``HOSTNAME`` Hostname ``FQDN`` Fully qualified domain name -``TOTAL_VIRTUAL_MEMORY`` Total virtual memory in megabytes -``AVAILABLE_VIRTUAL_MEMORY`` Available virtual memory in megabytes -``TOTAL_PHYSICAL_MEMORY`` Total physical memory in megabytes -``AVAILABLE_PHYSICAL_MEMORY`` Available physical memory in megabytes +``TOTAL_VIRTUAL_MEMORY`` Total virtual memory in MiB [#mebibytes]_ +``AVAILABLE_VIRTUAL_MEMORY`` Available virtual memory in MiB [#mebibytes]_ +``TOTAL_PHYSICAL_MEMORY`` Total physical memory in MiB [#mebibytes]_ +``AVAILABLE_PHYSICAL_MEMORY`` Available physical memory in MiB [#mebibytes]_ ``IS_64BIT`` One if processor is 64Bit ``HAS_FPU`` One if processor has floating point unit ``HAS_MMX`` One if processor supports MMX instructions @@ -44,3 +44,7 @@ Key Description ``OS_VERSION`` The OS build ID ``OS_PLATFORM`` See :variable:`CMAKE_HOST_SYSTEM_PROCESSOR` ============================= ================================================ + +.. rubric:: Footnotes + +.. [#mebibytes] One MiB (mebibyte) is equal to 1024x1024 bytes. ----------------------------------------------------------------------- Summary of changes: Help/command/cmake_host_system_information.rst | 12 ++++++++---- Help/manual/cmake-generator-expressions.7.rst | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) hooks/post-receive -- CMake From kwrobot at kitware.com Tue Sep 11 08:15:14 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Tue, 11 Sep 2018 08:15:14 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-575-gc669b59 Message-ID: <20180911121514.5A182102D88@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via c669b59095bf01ab0e254949989677496946ec08 (commit) via 292ec157b67b5570d5bc2e00bba554cc157d9dae (commit) from 78d165c9905f73237229497772769a6dc2c32982 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=c669b59095bf01ab0e254949989677496946ec08 commit c669b59095bf01ab0e254949989677496946ec08 Merge: 78d165c 292ec15 Author: Brad King AuthorDate: Tue Sep 11 12:12:03 2018 +0000 Commit: Kitware Robot CommitDate: Tue Sep 11 08:12:09 2018 -0400 Merge topic 'ctest-fix-test-load' 292ec157b6 CTest: Fix --test-load regression Acked-by: Kitware Robot Merge-request: !2362 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=292ec157b67b5570d5bc2e00bba554cc157d9dae commit 292ec157b67b5570d5bc2e00bba554cc157d9dae Author: Brad King AuthorDate: Sun Sep 9 11:11:38 2018 -0400 Commit: Brad King CommitDate: Mon Sep 10 07:32:16 2018 -0400 CTest: Fix --test-load regression The `ctest --test-load` option is implemented in `StartNextTests` by not starting any tests when the load is too high and instead sleeping and then returning. Prior to commit v3.11.0-rc1~117^2 (CTest: Re-implement test process handling using libuv, 2017-12-10) our outer loop in `RunTests` would immediately call `StartNextTests` again. However, now the `uv_run` loop may simply terminate if there are no tests running because no events are left pending. Fix this by converting the sleep in `StartNextTests` into a libuv timer that it starts instead. This avoids leaving `uv_run` with no pending events. In the case that there are other running tests this also allows CTest to detect when they finish even if it during the wait period where we previously slept. This regression was not caught by the test suite because it only verified that we do not start new tests when the load was too high and not that we proceed to start tests when the load drops. Revise the test suite to cover both. Fixes: #18338 diff --git a/Source/CTest/cmCTestMultiProcessHandler.cxx b/Source/CTest/cmCTestMultiProcessHandler.cxx index dcef8a0..322da23 100644 --- a/Source/CTest/cmCTestMultiProcessHandler.cxx +++ b/Source/CTest/cmCTestMultiProcessHandler.cxx @@ -5,7 +5,6 @@ #include "cmAffinity.h" #include "cmCTest.h" #include "cmCTestRunTest.h" -#include "cmCTestScriptHandler.h" #include "cmCTestTestHandler.h" #include "cmSystemTools.h" #include "cmWorkingDirectory.h" @@ -53,6 +52,7 @@ cmCTestMultiProcessHandler::cmCTestMultiProcessHandler() { this->ParallelLevel = 1; this->TestLoad = 0; + this->FakeLoadForTesting = 0; this->Completed = 0; this->RunningCount = 0; this->ProcessorsAvailable = cmAffinity::GetProcessorsAvailable(); @@ -97,6 +97,16 @@ void cmCTestMultiProcessHandler::SetParallelLevel(size_t level) void cmCTestMultiProcessHandler::SetTestLoad(unsigned long load) { this->TestLoad = load; + + std::string fake_load_value; + if (cmSystemTools::GetEnv("__CTEST_FAKE_LOAD_AVERAGE_FOR_TESTING", + fake_load_value)) { + if (!cmSystemTools::StringToULong(fake_load_value.c_str(), + &this->FakeLoadForTesting)) { + cmSystemTools::Error("Failed to parse fake load value: ", + fake_load_value.c_str()); + } + } } void cmCTestMultiProcessHandler::RunTests() @@ -259,12 +269,19 @@ bool cmCTestMultiProcessHandler::StartTest(int test) void cmCTestMultiProcessHandler::StartNextTests() { - size_t numToStart = 0; + if (this->TestLoadRetryTimer.get() != nullptr) { + // This timer may be waiting to call StartNextTests again. + // Since we have been called it is no longer needed. + uv_timer_stop(this->TestLoadRetryTimer); + } if (this->Tests.empty()) { + this->TestLoadRetryTimer.reset(); return; } + size_t numToStart = 0; + if (this->RunningCount < this->ParallelLevel) { numToStart = this->ParallelLevel - this->RunningCount; } @@ -280,7 +297,6 @@ void cmCTestMultiProcessHandler::StartNextTests() } bool allTestsFailedTestLoadCheck = false; - bool usedFakeLoadForTesting = false; size_t minProcessorsRequired = this->ParallelLevel; std::string testWithMinProcessors; @@ -293,15 +309,11 @@ void cmCTestMultiProcessHandler::StartNextTests() allTestsFailedTestLoadCheck = true; // Check for a fake load average value used in testing. - std::string fake_load_value; - if (cmSystemTools::GetEnv("__CTEST_FAKE_LOAD_AVERAGE_FOR_TESTING", - fake_load_value)) { - usedFakeLoadForTesting = true; - if (!cmSystemTools::StringToULong(fake_load_value.c_str(), - &systemLoad)) { - cmSystemTools::Error("Failed to parse fake load value: ", - fake_load_value.c_str()); - } + if (this->FakeLoadForTesting > 0) { + systemLoad = this->FakeLoadForTesting; + // Drop the fake load for the next iteration to a value low enough + // that the next iteration will start tests. + this->FakeLoadForTesting = 1; } // If it's not set, look up the true load average. else { @@ -385,18 +397,25 @@ void cmCTestMultiProcessHandler::StartNextTests() } cmCTestLog(this->CTest, HANDLER_OUTPUT, "*****" << std::endl); - if (usedFakeLoadForTesting) { - // Break out of the infinite loop of waiting for our fake load - // to come down. - this->StopTimePassed = true; - } else { - // Wait between 1 and 5 seconds before trying again. - cmCTestScriptHandler::SleepInSeconds(cmSystemTools::RandomSeed() % 5 + - 1); + // Wait between 1 and 5 seconds before trying again. + unsigned int milliseconds = (cmSystemTools::RandomSeed() % 5 + 1) * 1000; + if (this->FakeLoadForTesting) { + milliseconds = 10; + } + if (this->TestLoadRetryTimer.get() == nullptr) { + this->TestLoadRetryTimer.init(this->Loop, this); } + this->TestLoadRetryTimer.start( + &cmCTestMultiProcessHandler::OnTestLoadRetryCB, milliseconds, 0); } } +void cmCTestMultiProcessHandler::OnTestLoadRetryCB(uv_timer_t* timer) +{ + auto self = static_cast(timer->data); + self->StartNextTests(); +} + void cmCTestMultiProcessHandler::FinishTestProcess(cmCTestRunTest* runner, bool started) { diff --git a/Source/CTest/cmCTestMultiProcessHandler.h b/Source/CTest/cmCTestMultiProcessHandler.h index 203170e..07a5fe7 100644 --- a/Source/CTest/cmCTestMultiProcessHandler.h +++ b/Source/CTest/cmCTestMultiProcessHandler.h @@ -12,6 +12,7 @@ #include #include +#include "cmUVHandlePtr.h" #include "cm_uv.h" class cmCTest; @@ -101,6 +102,8 @@ protected: void EraseTest(int index); void FinishTestProcess(cmCTestRunTest* runner, bool started); + static void OnTestLoadRetryCB(uv_timer_t* timer); + void RemoveTest(int index); // Check if we need to resume an interrupted test set void CheckResume(); @@ -135,7 +138,9 @@ protected: std::vector* TestResults; size_t ParallelLevel; // max number of process that can be run at once unsigned long TestLoad; + unsigned long FakeLoadForTesting; uv_loop_t Loop; + cm::uv_timer_ptr TestLoadRetryTimer; cmCTestTestHandler* TestHandler; cmCTest* CTest; bool HasCycles; diff --git a/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake index 3033c9c..9e8d050 100644 --- a/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake @@ -111,8 +111,8 @@ endfunction() set(ENV{__CTEST_FAKE_LOAD_AVERAGE_FOR_TESTING} 5) # Verify that new tests are not started when the load average exceeds -# our threshold. -run_TestLoad(test-load-fail 2) +# our threshold and that they then run once the load average drops. +run_TestLoad(test-load-wait 3) # Verify that warning message is displayed but tests still start when # an invalid argument is given. diff --git a/Tests/RunCMake/CTestCommandLine/test-load-fail-stderr.txt b/Tests/RunCMake/CTestCommandLine/test-load-fail-stderr.txt deleted file mode 100644 index eafba1c..0000000 --- a/Tests/RunCMake/CTestCommandLine/test-load-fail-stderr.txt +++ /dev/null @@ -1 +0,0 @@ -No tests were found!!! diff --git a/Tests/RunCMake/CTestCommandLine/test-load-fail-stdout.txt b/Tests/RunCMake/CTestCommandLine/test-load-fail-stdout.txt deleted file mode 100644 index 153da09..0000000 --- a/Tests/RunCMake/CTestCommandLine/test-load-fail-stdout.txt +++ /dev/null @@ -1,2 +0,0 @@ -^Test project .*/Tests/RunCMake/CTestCommandLine/TestLoad -\*\*\*\*\* WAITING, System Load: 5, Max Allowed Load: 2, Smallest test TestLoad[1-2] requires 1\*\*\*\*\* diff --git a/Tests/RunCMake/CTestCommandLine/test-load-pass-stderr.txt b/Tests/RunCMake/CTestCommandLine/test-load-pass-stderr.txt deleted file mode 100644 index 10f3293..0000000 --- a/Tests/RunCMake/CTestCommandLine/test-load-pass-stderr.txt +++ /dev/null @@ -1 +0,0 @@ -^$ diff --git a/Tests/RunCMake/CTestCommandLine/test-load-wait-stdout.txt b/Tests/RunCMake/CTestCommandLine/test-load-wait-stdout.txt new file mode 100644 index 0000000..11a768a --- /dev/null +++ b/Tests/RunCMake/CTestCommandLine/test-load-wait-stdout.txt @@ -0,0 +1,8 @@ +^Test project .*/Tests/RunCMake/CTestCommandLine/TestLoad +\*\*\*\*\* WAITING, System Load: 5, Max Allowed Load: 3, Smallest test TestLoad[1-2] requires 1\*\*\*\*\* + Start 1: TestLoad1 + Start 2: TestLoad2 +1/2 Test #[1-2]: TestLoad[1-2] ........................ Passed +[0-9.]+ sec +2/2 Test #[1-2]: TestLoad[1-2] ........................ Passed +[0-9.]+ sec ++ +100% tests passed, 0 tests failed out of 2 diff --git a/Tests/RunCMake/ctest_test/CTestTestLoadFail-result.txt b/Tests/RunCMake/ctest_test/CTestTestLoadFail-result.txt deleted file mode 100644 index b57e2de..0000000 --- a/Tests/RunCMake/ctest_test/CTestTestLoadFail-result.txt +++ /dev/null @@ -1 +0,0 @@ -(-1|255) diff --git a/Tests/RunCMake/ctest_test/CTestTestLoadFail-stderr.txt b/Tests/RunCMake/ctest_test/CTestTestLoadFail-stderr.txt deleted file mode 100644 index eafba1c..0000000 --- a/Tests/RunCMake/ctest_test/CTestTestLoadFail-stderr.txt +++ /dev/null @@ -1 +0,0 @@ -No tests were found!!! diff --git a/Tests/RunCMake/ctest_test/CTestTestLoadFail-stdout.txt b/Tests/RunCMake/ctest_test/CTestTestLoadFail-stdout.txt deleted file mode 100644 index e203c10..0000000 --- a/Tests/RunCMake/ctest_test/CTestTestLoadFail-stdout.txt +++ /dev/null @@ -1,2 +0,0 @@ -Test project .*/Tests/RunCMake/ctest_test/CTestTestLoadFail-build -\*\*\*\*\* WAITING, System Load: 5, Max Allowed Load: 4, Smallest test RunCMakeVersion requires 1\*\*\*\*\*$ diff --git a/Tests/RunCMake/ctest_test/CTestTestLoadWait-stdout.txt b/Tests/RunCMake/ctest_test/CTestTestLoadWait-stdout.txt new file mode 100644 index 0000000..2af3838 --- /dev/null +++ b/Tests/RunCMake/ctest_test/CTestTestLoadWait-stdout.txt @@ -0,0 +1,8 @@ +Test project .*/Tests/RunCMake/ctest_test/CTestTestLoadWait-build +\*\*\*\*\* WAITING, System Load: 5, Max Allowed Load: 4, Smallest test RunCMakeVersion requires 1\*\*\*\*\* + Start 1: RunCMakeVersion +1/1 Test #1: RunCMakeVersion .................. Passed +[0-9.]+ sec ++ +100% tests passed, 0 tests failed out of 1 ++ +Total Test time \(real\) = +[0-9.]+ sec$ diff --git a/Tests/RunCMake/ctest_test/RunCMakeTest.cmake b/Tests/RunCMake/ctest_test/RunCMakeTest.cmake index 1b31726..6877e6a 100644 --- a/Tests/RunCMake/ctest_test/RunCMakeTest.cmake +++ b/Tests/RunCMake/ctest_test/RunCMakeTest.cmake @@ -21,8 +21,8 @@ set(ENV{__CTEST_FAKE_LOAD_AVERAGE_FOR_TESTING} 5) run_ctest_test(TestLoadPass TEST_LOAD 6) # Verify that new tests are not started when the load average exceeds -# our threshold. -run_ctest_test(TestLoadFail TEST_LOAD 2) +# our threshold and that they then run once the load average drops. +run_ctest_test(TestLoadWait TEST_LOAD 2) # Verify that when an invalid "TEST_LOAD" value is given, a warning # message is displayed and the value is ignored. @@ -34,9 +34,9 @@ set(CASE_CTEST_TEST_LOAD 7) run_ctest_test(CTestTestLoadPass) # Verify that new tests are not started when the load average exceeds -# our threshold. +# our threshold and that they then run once the load average drops. set(CASE_CTEST_TEST_LOAD 4) -run_ctest_test(CTestTestLoadFail) +run_ctest_test(CTestTestLoadWait) # Verify that when an invalid "CTEST_TEST_LOAD" value is given, # a warning message is displayed and the value is ignored. diff --git a/Tests/RunCMake/ctest_test/TestLoadFail-result.txt b/Tests/RunCMake/ctest_test/TestLoadFail-result.txt deleted file mode 100644 index b57e2de..0000000 --- a/Tests/RunCMake/ctest_test/TestLoadFail-result.txt +++ /dev/null @@ -1 +0,0 @@ -(-1|255) diff --git a/Tests/RunCMake/ctest_test/TestLoadFail-stderr.txt b/Tests/RunCMake/ctest_test/TestLoadFail-stderr.txt deleted file mode 100644 index eafba1c..0000000 --- a/Tests/RunCMake/ctest_test/TestLoadFail-stderr.txt +++ /dev/null @@ -1 +0,0 @@ -No tests were found!!! diff --git a/Tests/RunCMake/ctest_test/TestLoadFail-stdout.txt b/Tests/RunCMake/ctest_test/TestLoadFail-stdout.txt deleted file mode 100644 index 4d7ce48..0000000 --- a/Tests/RunCMake/ctest_test/TestLoadFail-stdout.txt +++ /dev/null @@ -1,2 +0,0 @@ -Test project .*/Tests/RunCMake/ctest_test/TestLoadFail-build -\*\*\*\*\* WAITING, System Load: 5, Max Allowed Load: 2, Smallest test RunCMakeVersion requires 1\*\*\*\*\*$ diff --git a/Tests/RunCMake/ctest_test/TestLoadWait-stdout.txt b/Tests/RunCMake/ctest_test/TestLoadWait-stdout.txt new file mode 100644 index 0000000..07f4ed3 --- /dev/null +++ b/Tests/RunCMake/ctest_test/TestLoadWait-stdout.txt @@ -0,0 +1,8 @@ +Test project .*/Tests/RunCMake/ctest_test/TestLoadWait-build +\*\*\*\*\* WAITING, System Load: 5, Max Allowed Load: 2, Smallest test RunCMakeVersion requires 1\*\*\*\*\* + Start 1: RunCMakeVersion +1/1 Test #1: RunCMakeVersion .................. Passed +[0-9.]+ sec ++ +100% tests passed, 0 tests failed out of 1 ++ +Total Test time \(real\) = +[0-9.]+ sec$ ----------------------------------------------------------------------- Summary of changes: Source/CTest/cmCTestMultiProcessHandler.cxx | 59 ++++++++++++++-------- Source/CTest/cmCTestMultiProcessHandler.h | 5 ++ Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake | 4 +- .../CTestCommandLine/test-load-fail-stderr.txt | 1 - .../CTestCommandLine/test-load-fail-stdout.txt | 2 - .../CTestCommandLine/test-load-pass-stderr.txt | 1 - ...nvalid-stdout.txt => test-load-wait-stdout.txt} | 1 + .../ctest_test/CTestTestLoadFail-result.txt | 1 - .../ctest_test/CTestTestLoadFail-stderr.txt | 1 - .../ctest_test/CTestTestLoadFail-stdout.txt | 2 - ...ass-stdout.txt => CTestTestLoadWait-stdout.txt} | 3 +- Tests/RunCMake/ctest_test/RunCMakeTest.cmake | 8 +-- Tests/RunCMake/ctest_test/TestLoadFail-result.txt | 1 - Tests/RunCMake/ctest_test/TestLoadFail-stderr.txt | 1 - Tests/RunCMake/ctest_test/TestLoadFail-stdout.txt | 2 - ...LoadPass-stdout.txt => TestLoadWait-stdout.txt} | 3 +- 16 files changed, 55 insertions(+), 40 deletions(-) delete mode 100644 Tests/RunCMake/CTestCommandLine/test-load-fail-stderr.txt delete mode 100644 Tests/RunCMake/CTestCommandLine/test-load-fail-stdout.txt delete mode 100644 Tests/RunCMake/CTestCommandLine/test-load-pass-stderr.txt copy Tests/RunCMake/CTestCommandLine/{test-load-invalid-stdout.txt => test-load-wait-stdout.txt} (74%) delete mode 100644 Tests/RunCMake/ctest_test/CTestTestLoadFail-result.txt delete mode 100644 Tests/RunCMake/ctest_test/CTestTestLoadFail-stderr.txt delete mode 100644 Tests/RunCMake/ctest_test/CTestTestLoadFail-stdout.txt copy Tests/RunCMake/ctest_test/{CTestTestLoadPass-stdout.txt => CTestTestLoadWait-stdout.txt} (52%) delete mode 100644 Tests/RunCMake/ctest_test/TestLoadFail-result.txt delete mode 100644 Tests/RunCMake/ctest_test/TestLoadFail-stderr.txt delete mode 100644 Tests/RunCMake/ctest_test/TestLoadFail-stdout.txt copy Tests/RunCMake/ctest_test/{CTestTestLoadPass-stdout.txt => TestLoadWait-stdout.txt} (52%) hooks/post-receive -- CMake From kwrobot at kitware.com Tue Sep 11 08:25:06 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Tue, 11 Sep 2018 08:25:06 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-588-gb1c8d95 Message-ID: <20180911122506.B0E1D112D87@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via b1c8d95dbe97ab2511e08518bf8eee1f5da2e941 (commit) via 4188b8fd6a17b7959aff8cf695ad02c291171950 (commit) via dcbad14d23c8ca6673251a3f6ea9587ee0fe3d51 (commit) via bb59e362cca795543a551f765fb8d39c0236df45 (commit) via e0e56abe3479efddd994cc1a3ee9b8a123111903 (commit) via 3eda5cdd939e0bae5241e2286e7524d552ab455c (commit) via e374b9f1ebae70ca4381588362d6d3418f832ea7 (commit) via 09f0325eaffb6b32b570e3339aa8b8332350b31d (commit) via f35be599612b788125d08a7c3e61d0fad3805bdd (commit) via 68f2b471df7687e37ab2a5808585aad76c7c3122 (commit) via 1b57f49586afc9e8663d5e146732b1cd0597e7ef (commit) via bea390e9bd68e1aa7d86b6aef7384f502c39068c (commit) via fc7e4d1ed85370d03acbd62bc753cced3550752b (commit) from c669b59095bf01ab0e254949989677496946ec08 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=b1c8d95dbe97ab2511e08518bf8eee1f5da2e941 commit b1c8d95dbe97ab2511e08518bf8eee1f5da2e941 Merge: 4188b8f f35be59 Author: Brad King AuthorDate: Tue Sep 11 12:20:44 2018 +0000 Commit: Kitware Robot CommitDate: Tue Sep 11 08:20:50 2018 -0400 Merge topic 'imported-same-name' f35be59961 Fix transitive usage requirements through same-name imported targets 1b57f49586 genex: Simplify cmGeneratorExpressionInterpreter bea390e9bd Fix dependency propagation through same-name imported targets fc7e4d1ed8 cmLinkItem: Convert to a "sum type" over a string and target pointer Acked-by: Kitware Robot Merge-request: !2359 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=4188b8fd6a17b7959aff8cf695ad02c291171950 commit 4188b8fd6a17b7959aff8cf695ad02c291171950 Merge: dcbad14 e0e56ab Author: Brad King AuthorDate: Tue Sep 11 08:19:44 2018 -0400 Commit: Brad King CommitDate: Tue Sep 11 08:19:44 2018 -0400 Merge branch 'release-3.12' https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=dcbad14d23c8ca6673251a3f6ea9587ee0fe3d51 commit dcbad14d23c8ca6673251a3f6ea9587ee0fe3d51 Merge: bb59e36 e374b9f Author: Brad King AuthorDate: Tue Sep 11 12:18:38 2018 +0000 Commit: Kitware Robot CommitDate: Tue Sep 11 08:18:55 2018 -0400 Merge topic 'FindMPI-restore-flags-string' e374b9f1eb FindMPI: Restore MPI__COMPILE_FLAGS as a command-line string Acked-by: Kitware Robot Reviewed-by: Christoph Junghans Reviewed-by: Christian Pfeiffer Merge-request: !2368 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=bb59e362cca795543a551f765fb8d39c0236df45 commit bb59e362cca795543a551f765fb8d39c0236df45 Merge: c669b59 09f0325 Author: Brad King AuthorDate: Tue Sep 11 12:18:01 2018 +0000 Commit: Kitware Robot CommitDate: Tue Sep 11 08:18:08 2018 -0400 Merge topic 'fix-ctest_start-track' 09f0325eaf CTest: Fix regression in ctest_start() Acked-by: Kitware Robot Merge-request: !2366 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=f35be599612b788125d08a7c3e61d0fad3805bdd commit f35be599612b788125d08a7c3e61d0fad3805bdd Author: Brad King AuthorDate: Thu Sep 6 18:22:31 2018 -0400 Commit: Brad King CommitDate: Mon Sep 10 07:51:44 2018 -0400 Fix transitive usage requirements through same-name imported targets If two imported targets in different directories have the same name we should still be able to propagate transitive usage requirements from both. Fix the DAG checker to work with target pointers instead of target names since the pointers will not be duplicated even if the names are. Fixes: #18345 diff --git a/Source/cmExportBuildAndroidMKGenerator.cxx b/Source/cmExportBuildAndroidMKGenerator.cxx index bb370c4..3d32b84 100644 --- a/Source/cmExportBuildAndroidMKGenerator.cxx +++ b/Source/cmExportBuildAndroidMKGenerator.cxx @@ -108,7 +108,7 @@ void cmExportBuildAndroidMKGenerator::GenerateInterfaceProperties( // build type of the makefile cmGeneratorExpression ge; cmGeneratorExpressionDAGChecker dagChecker( - target->GetName(), "INTERFACE_LINK_LIBRARIES", nullptr, nullptr); + target, "INTERFACE_LINK_LIBRARIES", nullptr, nullptr); std::unique_ptr cge = ge.Parse(property.second); std::string evaluated = cge->Evaluate( diff --git a/Source/cmExportTryCompileFileGenerator.cxx b/Source/cmExportTryCompileFileGenerator.cxx index 87648cb..c169032 100644 --- a/Source/cmExportTryCompileFileGenerator.cxx +++ b/Source/cmExportTryCompileFileGenerator.cxx @@ -65,8 +65,7 @@ std::string cmExportTryCompileFileGenerator::FindTargets( cmGeneratorExpression ge; - cmGeneratorExpressionDAGChecker dagChecker(tgt->GetName(), propName, nullptr, - nullptr); + cmGeneratorExpressionDAGChecker dagChecker(tgt, propName, nullptr, nullptr); std::unique_ptr cge = ge.Parse(prop); diff --git a/Source/cmGeneratorExpression.cxx b/Source/cmGeneratorExpression.cxx index 6d83a3f..658e9a7 100644 --- a/Source/cmGeneratorExpression.cxx +++ b/Source/cmGeneratorExpression.cxx @@ -13,7 +13,6 @@ #include "cmGeneratorExpressionEvaluator.h" #include "cmGeneratorExpressionLexer.h" #include "cmGeneratorExpressionParser.h" -#include "cmGeneratorTarget.h" #include "cmSystemTools.h" cmGeneratorExpression::cmGeneratorExpression( @@ -395,7 +394,7 @@ const std::string& cmGeneratorExpressionInterpreter::Evaluate( // Specify COMPILE_OPTIONS to DAGchecker, same semantic as COMPILE_FLAGS cmGeneratorExpressionDAGChecker dagChecker( - this->HeadTarget->GetName(), + this->HeadTarget, property == "COMPILE_FLAGS" ? "COMPILE_OPTIONS" : property, nullptr, nullptr); diff --git a/Source/cmGeneratorExpressionDAGChecker.cxx b/Source/cmGeneratorExpressionDAGChecker.cxx index face282..8d57441 100644 --- a/Source/cmGeneratorExpressionDAGChecker.cxx +++ b/Source/cmGeneratorExpressionDAGChecker.cxx @@ -14,7 +14,7 @@ #include cmGeneratorExpressionDAGChecker::cmGeneratorExpressionDAGChecker( - const cmListFileBacktrace& backtrace, const std::string& target, + const cmListFileBacktrace& backtrace, cmGeneratorTarget const* target, const std::string& property, const GeneratorExpressionContent* content, cmGeneratorExpressionDAGChecker* parent) : Parent(parent) @@ -28,7 +28,7 @@ cmGeneratorExpressionDAGChecker::cmGeneratorExpressionDAGChecker( } cmGeneratorExpressionDAGChecker::cmGeneratorExpressionDAGChecker( - const std::string& target, const std::string& property, + cmGeneratorTarget const* target, const std::string& property, const GeneratorExpressionContent* content, cmGeneratorExpressionDAGChecker* parent) : Parent(parent) @@ -58,8 +58,8 @@ void cmGeneratorExpressionDAGChecker::Initialize() TEST_TRANSITIVE_PROPERTY_METHOD) false)) // NOLINT(clang-tidy) #undef TEST_TRANSITIVE_PROPERTY_METHOD { - std::map>::const_iterator it = - top->Seen.find(this->Target); + std::map>::const_iterator + it = top->Seen.find(this->Target); if (it != top->Seen.end()) { const std::set& propSet = it->second; if (propSet.find(this->Property) != propSet.end()) { @@ -166,7 +166,8 @@ bool cmGeneratorExpressionDAGChecker::EvaluatingGenexExpression() return top->Property == "TARGET_GENEX_EVAL" || top->Property == "GENEX_EVAL"; } -bool cmGeneratorExpressionDAGChecker::EvaluatingLinkLibraries(const char* tgt) +bool cmGeneratorExpressionDAGChecker::EvaluatingLinkLibraries( + cmGeneratorTarget const* tgt) { const cmGeneratorExpressionDAGChecker* top = this; const cmGeneratorExpressionDAGChecker* parent = this->Parent; @@ -189,7 +190,7 @@ bool cmGeneratorExpressionDAGChecker::EvaluatingLinkLibraries(const char* tgt) strcmp(prop, "INTERFACE_LINK_LIBRARIES") == 0; } -std::string cmGeneratorExpressionDAGChecker::TopTarget() const +cmGeneratorTarget const* cmGeneratorExpressionDAGChecker::TopTarget() const { const cmGeneratorExpressionDAGChecker* top = this; const cmGeneratorExpressionDAGChecker* parent = this->Parent; diff --git a/Source/cmGeneratorExpressionDAGChecker.h b/Source/cmGeneratorExpressionDAGChecker.h index cd23904..8b1697b 100644 --- a/Source/cmGeneratorExpressionDAGChecker.h +++ b/Source/cmGeneratorExpressionDAGChecker.h @@ -13,6 +13,7 @@ struct GeneratorExpressionContent; struct cmGeneratorExpressionContext; +class cmGeneratorTarget; #define CM_SELECT_BOTH(F, A1, A2) F(A1, A2) #define CM_SELECT_FIRST(F, A1, A2) F(A1) @@ -41,11 +42,11 @@ struct cmGeneratorExpressionContext; struct cmGeneratorExpressionDAGChecker { cmGeneratorExpressionDAGChecker(const cmListFileBacktrace& backtrace, - const std::string& target, + cmGeneratorTarget const* target, const std::string& property, const GeneratorExpressionContent* content, cmGeneratorExpressionDAGChecker* parent); - cmGeneratorExpressionDAGChecker(const std::string& target, + cmGeneratorExpressionDAGChecker(cmGeneratorTarget const* target, const std::string& property, const GeneratorExpressionContent* content, cmGeneratorExpressionDAGChecker* parent); @@ -64,7 +65,7 @@ struct cmGeneratorExpressionDAGChecker const std::string& expr); bool EvaluatingGenexExpression(); - bool EvaluatingLinkLibraries(const char* tgt = nullptr); + bool EvaluatingLinkLibraries(cmGeneratorTarget const* tgt = nullptr); #define DECLARE_TRANSITIVE_PROPERTY_METHOD(METHOD) bool METHOD() const; @@ -75,7 +76,7 @@ struct cmGeneratorExpressionDAGChecker bool GetTransitivePropertiesOnly(); void SetTransitivePropertiesOnly() { this->TransitivePropertiesOnly = true; } - std::string TopTarget() const; + cmGeneratorTarget const* TopTarget() const; private: Result CheckGraph() const; @@ -83,9 +84,9 @@ private: private: const cmGeneratorExpressionDAGChecker* const Parent; - const std::string Target; + cmGeneratorTarget const* Target; const std::string Property; - std::map> Seen; + std::map> Seen; const GeneratorExpressionContent* const Content; const cmListFileBacktrace Backtrace; Result CheckResult; diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index 9aa5212..1e51f09 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -378,8 +378,8 @@ protected: { if (context->HeadTarget) { cmGeneratorExpressionDAGChecker dagChecker( - context->Backtrace, context->HeadTarget->GetName(), genexOperator, - content, dagCheckerParent); + context->Backtrace, context->HeadTarget, genexOperator, content, + dagCheckerParent); switch (dagChecker.Check()) { case cmGeneratorExpressionDAGChecker::SELF_REFERENCE: case cmGeneratorExpressionDAGChecker::CYCLIC_REFERENCE: { @@ -1196,9 +1196,8 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode return target->GetLinkerLanguage(context->Config); } - cmGeneratorExpressionDAGChecker dagChecker(context->Backtrace, - target->GetName(), propertyName, - content, dagCheckerParent); + cmGeneratorExpressionDAGChecker dagChecker( + context->Backtrace, target, propertyName, content, dagCheckerParent); switch (dagChecker.Check()) { case cmGeneratorExpressionDAGChecker::SELF_REFERENCE: @@ -1911,9 +1910,9 @@ struct TargetFilesystemArtifact : public cmGeneratorExpressionNode return std::string(); } if (dagChecker && - (dagChecker->EvaluatingLinkLibraries(name.c_str()) || + (dagChecker->EvaluatingLinkLibraries(target) || (dagChecker->EvaluatingSources() && - name == dagChecker->TopTarget()))) { + target == dagChecker->TopTarget()))) { ::reportError(context, content->GetOriginalExpression(), "Expressions which require the linker language may not " "be used while evaluating link libraries"); diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 080ff1c..e8e7b90 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -773,7 +773,7 @@ bool cmGeneratorTarget::IsSystemIncludeDirectory( if (iter == this->SystemIncludesCache.end()) { cmGeneratorExpressionDAGChecker dagChecker( - this->GetName(), "SYSTEM_INCLUDE_DIRECTORIES", nullptr, nullptr); + this, "SYSTEM_INCLUDE_DIRECTORIES", nullptr, nullptr); bool excludeImported = this->GetPropertyAsBool("NO_SYSTEM_FROM_IMPORTED"); @@ -964,8 +964,8 @@ void cmGeneratorTarget::GetSourceFiles(std::vector& files, this->DebugSourcesDone = true; } - cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), "SOURCES", - nullptr, nullptr); + cmGeneratorExpressionDAGChecker dagChecker(this, "SOURCES", nullptr, + nullptr); std::unordered_set uniqueSrcs; bool contextDependentDirectSources = @@ -2078,8 +2078,8 @@ void cmGeneratorTarget::GetAutoUicOptions(std::vector& result, } cmGeneratorExpression ge; - cmGeneratorExpressionDAGChecker dagChecker( - this->GetName(), "AUTOUIC_OPTIONS", nullptr, nullptr); + cmGeneratorExpressionDAGChecker dagChecker(this, "AUTOUIC_OPTIONS", nullptr, + nullptr); cmSystemTools::ExpandListArgument( ge.Parse(prop)->Evaluate(this->LocalGenerator, config, false, this, &dagChecker), @@ -2588,8 +2588,8 @@ std::vector cmGeneratorTarget::GetIncludeDirectories( std::vector includes; std::unordered_set uniqueIncludes; - cmGeneratorExpressionDAGChecker dagChecker( - this->GetName(), "INCLUDE_DIRECTORIES", nullptr, nullptr); + cmGeneratorExpressionDAGChecker dagChecker(this, "INCLUDE_DIRECTORIES", + nullptr, nullptr); std::vector debugProperties; const char* debugProp = @@ -2710,8 +2710,8 @@ void cmGeneratorTarget::GetCompileOptions(std::vector& result, { std::unordered_set uniqueOptions; - cmGeneratorExpressionDAGChecker dagChecker( - this->GetName(), "COMPILE_OPTIONS", nullptr, nullptr); + cmGeneratorExpressionDAGChecker dagChecker(this, "COMPILE_OPTIONS", nullptr, + nullptr); std::vector debugProperties; const char* debugProp = @@ -2763,8 +2763,8 @@ void cmGeneratorTarget::GetCompileFeatures(std::vector& result, { std::unordered_set uniqueFeatures; - cmGeneratorExpressionDAGChecker dagChecker( - this->GetName(), "COMPILE_FEATURES", nullptr, nullptr); + cmGeneratorExpressionDAGChecker dagChecker(this, "COMPILE_FEATURES", nullptr, + nullptr); std::vector debugProperties; const char* debugProp = @@ -2814,8 +2814,8 @@ void cmGeneratorTarget::GetCompileDefinitions( { std::unordered_set uniqueOptions; - cmGeneratorExpressionDAGChecker dagChecker( - this->GetName(), "COMPILE_DEFINITIONS", nullptr, nullptr); + cmGeneratorExpressionDAGChecker dagChecker(this, "COMPILE_DEFINITIONS", + nullptr, nullptr); std::vector debugProperties; const char* debugProp = @@ -2895,8 +2895,8 @@ void cmGeneratorTarget::GetLinkOptions(std::vector& result, { std::unordered_set uniqueOptions; - cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), "LINK_OPTIONS", - nullptr, nullptr); + cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_OPTIONS", nullptr, + nullptr); std::vector debugProperties; const char* debugProp = @@ -3043,8 +3043,8 @@ void cmGeneratorTarget::GetStaticLibraryLinkOptions( std::vector entries; std::unordered_set uniqueOptions; - cmGeneratorExpressionDAGChecker dagChecker( - this->GetName(), "STATIC_LIBRARY_OPTIONS", nullptr, nullptr); + cmGeneratorExpressionDAGChecker dagChecker(this, "STATIC_LIBRARY_OPTIONS", + nullptr, nullptr); if (const char* linkOptions = this->GetProperty("STATIC_LIBRARY_OPTIONS")) { std::vector options; @@ -3083,8 +3083,8 @@ void cmGeneratorTarget::GetLinkDepends(std::vector& result, { std::vector linkDependsEntries; std::unordered_set uniqueOptions; - cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), "LINK_DEPENDS", - nullptr, nullptr); + cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_DEPENDS", nullptr, + nullptr); if (const char* linkDepends = this->GetProperty("LINK_DEPENDS")) { std::vector depends; @@ -4509,8 +4509,7 @@ void cmGeneratorTarget::ExpandLinkItems( std::vector& items, bool& hadHeadSensitiveCondition) const { cmGeneratorExpression ge; - cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), prop, nullptr, - nullptr); + cmGeneratorExpressionDAGChecker dagChecker(this, prop, nullptr, nullptr); // The $ expression may be in a link interface to specify private // link dependencies that are otherwise excluded from usage requirements. if (usage_requirements_only) { @@ -5561,8 +5560,8 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries( end = entryRange.end(); le != end; ++le, ++btIt) { std::vector llibs; - cmGeneratorExpressionDAGChecker dagChecker( - this->GetName(), "LINK_LIBRARIES", nullptr, nullptr); + cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_LIBRARIES", nullptr, + nullptr); cmGeneratorExpression ge(*btIt); std::unique_ptr const cge = ge.Parse(*le); std::string const& evaluated = diff --git a/Tests/ImportedSameName/A/CMakeLists.txt b/Tests/ImportedSameName/A/CMakeLists.txt index 9417a2c..0a31b40 100644 --- a/Tests/ImportedSameName/A/CMakeLists.txt +++ b/Tests/ImportedSameName/A/CMakeLists.txt @@ -1,4 +1,5 @@ add_library(a STATIC a.c) +target_compile_definitions(a INTERFACE DEF_A) add_library(sameName INTERFACE IMPORTED) target_link_libraries(sameName INTERFACE a) diff --git a/Tests/ImportedSameName/B/CMakeLists.txt b/Tests/ImportedSameName/B/CMakeLists.txt index 6947fa9..d930326 100644 --- a/Tests/ImportedSameName/B/CMakeLists.txt +++ b/Tests/ImportedSameName/B/CMakeLists.txt @@ -1,4 +1,5 @@ add_library(b STATIC b.c) +target_compile_definitions(b INTERFACE DEF_B) add_library(sameName INTERFACE IMPORTED) target_link_libraries(sameName INTERFACE b) diff --git a/Tests/ImportedSameName/main.c b/Tests/ImportedSameName/main.c index 33196b7..a0cb27f 100644 --- a/Tests/ImportedSameName/main.c +++ b/Tests/ImportedSameName/main.c @@ -1,3 +1,10 @@ +#ifndef DEF_A +# error "DEF_A not defined" +#endif +#ifndef DEF_B +# error "DEF_B not defined" +#endif + extern void a(void); extern void b(void); https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=1b57f49586afc9e8663d5e146732b1cd0597e7ef commit 1b57f49586afc9e8663d5e146732b1cd0597e7ef Author: Brad King AuthorDate: Thu Sep 6 16:49:34 2018 -0400 Commit: Brad King CommitDate: Fri Sep 7 09:23:43 2018 -0400 genex: Simplify cmGeneratorExpressionInterpreter All callers were constructing with a non-empty target name using the target whose pointer was passed anyway. Drop this argument. Simplify logic accordingly. Re-order constructor arguments to match the cmCompiledGeneratorExpression::Evaluate arguments. Also remove unnecessary getters. diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx index 14e7927..c4cca07 100644 --- a/Source/cmExtraSublimeTextGenerator.cxx +++ b/Source/cmExtraSublimeTextGenerator.cxx @@ -354,8 +354,8 @@ std::string cmExtraSublimeTextGenerator::ComputeFlagsForObject( lg->GetTargetCompileFlags(gtgt, config, language, flags); // Add source file specific flags. - cmGeneratorExpressionInterpreter genexInterpreter(lg, gtgt, config, - gtgt->GetName(), language); + cmGeneratorExpressionInterpreter genexInterpreter(lg, config, gtgt, + language); const std::string COMPILE_FLAGS("COMPILE_FLAGS"); if (const char* cflags = source->GetProperty(COMPILE_FLAGS)) { @@ -381,8 +381,8 @@ std::string cmExtraSublimeTextGenerator::ComputeDefines( cmMakefile* makefile = lg->GetMakefile(); const std::string& language = source->GetLanguage(); const std::string& config = makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); - cmGeneratorExpressionInterpreter genexInterpreter( - lg, target, config, target->GetName(), language); + cmGeneratorExpressionInterpreter genexInterpreter(lg, config, target, + language); // Add the export symbol definition for shared library objects. if (const char* exportMacro = target->GetExportMacro()) { @@ -419,8 +419,8 @@ std::string cmExtraSublimeTextGenerator::ComputeIncludes( cmMakefile* makefile = lg->GetMakefile(); const std::string& language = source->GetLanguage(); const std::string& config = makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); - cmGeneratorExpressionInterpreter genexInterpreter( - lg, target, config, target->GetName(), language); + cmGeneratorExpressionInterpreter genexInterpreter(lg, config, target, + language); // Add include directories for this source file const std::string INCLUDE_DIRECTORIES("INCLUDE_DIRECTORIES"); diff --git a/Source/cmGeneratorExpression.cxx b/Source/cmGeneratorExpression.cxx index 6823cd5..6d83a3f 100644 --- a/Source/cmGeneratorExpression.cxx +++ b/Source/cmGeneratorExpression.cxx @@ -13,6 +13,7 @@ #include "cmGeneratorExpressionEvaluator.h" #include "cmGeneratorExpressionLexer.h" #include "cmGeneratorExpressionParser.h" +#include "cmGeneratorTarget.h" #include "cmSystemTools.h" cmGeneratorExpression::cmGeneratorExpression( @@ -389,14 +390,16 @@ void cmCompiledGeneratorExpression::GetMaxLanguageStandard( const std::string& cmGeneratorExpressionInterpreter::Evaluate( const char* expression, const std::string& property) { - if (this->Target.empty()) { - return this->EvaluateExpression(expression); - } + this->CompiledGeneratorExpression = + this->GeneratorExpression.Parse(expression); // Specify COMPILE_OPTIONS to DAGchecker, same semantic as COMPILE_FLAGS cmGeneratorExpressionDAGChecker dagChecker( - this->Target, property == "COMPILE_FLAGS" ? "COMPILE_OPTIONS" : property, - nullptr, nullptr); + this->HeadTarget->GetName(), + property == "COMPILE_FLAGS" ? "COMPILE_OPTIONS" : property, nullptr, + nullptr); - return this->EvaluateExpression(expression, &dagChecker); + return this->CompiledGeneratorExpression->Evaluate( + this->LocalGenerator, this->Config, false, this->HeadTarget, &dagChecker, + this->Language); } diff --git a/Source/cmGeneratorExpression.h b/Source/cmGeneratorExpression.h index 2b7df91..8176d5c 100644 --- a/Source/cmGeneratorExpression.h +++ b/Source/cmGeneratorExpression.h @@ -160,24 +160,15 @@ class cmGeneratorExpressionInterpreter public: cmGeneratorExpressionInterpreter(cmLocalGenerator* localGenerator, - cmGeneratorTarget* generatorTarget, - const std::string& config, - const std::string& target, - const std::string& lang) + std::string const& config, + cmGeneratorTarget const* headTarget, + std::string const& lang = std::string()) : LocalGenerator(localGenerator) - , GeneratorTarget(generatorTarget) , Config(config) - , Target(target) + , HeadTarget(headTarget) , Language(lang) { } - cmGeneratorExpressionInterpreter(cmLocalGenerator* localGenerator, - cmGeneratorTarget* generatorTarget, - const std::string& config) - : cmGeneratorExpressionInterpreter(localGenerator, generatorTarget, config, - std::string(), std::string()) - { - } const std::string& Evaluate(const char* expression, const std::string& property); @@ -188,47 +179,11 @@ public: } protected: - cmGeneratorExpression& GetGeneratorExpression() - { - return this->GeneratorExpression; - } - - cmCompiledGeneratorExpression& GetCompiledGeneratorExpression() - { - return *(this->CompiledGeneratorExpression); - } - - cmLocalGenerator* GetLocalGenerator() { return this->LocalGenerator; } - - cmGeneratorTarget* GetGeneratorTarget() { return this->GeneratorTarget; } - - const std::string& GetTargetName() const { return this->Target; } - const std::string& GetLanguage() const { return this->Language; } - - const std::string& EvaluateExpression( - const char* expression, - cmGeneratorExpressionDAGChecker* dagChecker = nullptr) - { - this->CompiledGeneratorExpression = - this->GeneratorExpression.Parse(expression); - - if (dagChecker == nullptr) { - return this->CompiledGeneratorExpression->Evaluate( - this->LocalGenerator, this->Config, false, this->GeneratorTarget); - } - - return this->CompiledGeneratorExpression->Evaluate( - this->LocalGenerator, this->Config, false, this->GeneratorTarget, - dagChecker, this->Language); - } - -private: cmGeneratorExpression GeneratorExpression; std::unique_ptr CompiledGeneratorExpression; cmLocalGenerator* LocalGenerator = nullptr; - cmGeneratorTarget* GeneratorTarget = nullptr; std::string Config; - std::string Target; + cmGeneratorTarget const* HeadTarget = nullptr; std::string Language; }; diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 7456d3c..e353a37 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -751,11 +751,10 @@ class XCodeGeneratorExpressionInterpreter public: XCodeGeneratorExpressionInterpreter(cmSourceFile* sourceFile, cmLocalGenerator* localGenerator, - cmGeneratorTarget* generatorTarget, + cmGeneratorTarget* headTarget, const std::string& lang) - : cmGeneratorExpressionInterpreter(localGenerator, generatorTarget, - "NO-PER-CONFIG-SUPPORT-IN-XCODE", - generatorTarget->GetName(), lang) + : cmGeneratorExpressionInterpreter( + localGenerator, "NO-PER-CONFIG-SUPPORT-IN-XCODE", headTarget, lang) , SourceFile(sourceFile) { } @@ -767,8 +766,7 @@ public: { const std::string& processed = this->cmGeneratorExpressionInterpreter::Evaluate(expression, property); - if (this->GetCompiledGeneratorExpression() - .GetHadContextSensitiveCondition()) { + if (this->CompiledGeneratorExpression->GetHadContextSensitiveCondition()) { std::ostringstream e; /* clang-format off */ e << @@ -777,7 +775,7 @@ public: "specified for source:\n" " " << this->SourceFile->GetFullPath() << "\n"; /* clang-format on */ - this->GetLocalGenerator()->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str()); } return processed; diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 13bd214..c05b085 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -1497,8 +1497,7 @@ cmLocalVisualStudio7GeneratorFCInfo::cmLocalVisualStudio7GeneratorFCInfo( lang = sourceLang; } - cmGeneratorExpressionInterpreter genexInterpreter(lg, gt, *i, - gt->GetName(), lang); + cmGeneratorExpressionInterpreter genexInterpreter(lg, *i, gt, lang); bool needfc = false; if (!objectName.empty()) { diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index e8cf255..c8dc392 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -434,8 +434,7 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile( std::string config = this->LocalGenerator->GetConfigName(); std::string configUpper = cmSystemTools::UpperCase(config); cmGeneratorExpressionInterpreter genexInterpreter( - this->LocalGenerator, this->GeneratorTarget, config, - this->GeneratorTarget->GetName(), lang); + this->LocalGenerator, config, this->GeneratorTarget, lang); // Add Fortran format flags. if (lang == "Fortran") { diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 1cfaac5..ebcc501 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -136,9 +136,8 @@ std::string cmNinjaTargetGenerator::ComputeFlagsForObject( // Add source file specific flags. cmGeneratorExpressionInterpreter genexInterpreter( - this->LocalGenerator, this->GeneratorTarget, - this->LocalGenerator->GetConfigName(), this->GeneratorTarget->GetName(), - language); + this->LocalGenerator, this->LocalGenerator->GetConfigName(), + this->GeneratorTarget, language); const std::string COMPILE_FLAGS("COMPILE_FLAGS"); if (const char* cflags = source->GetProperty(COMPILE_FLAGS)) { @@ -188,8 +187,7 @@ std::string cmNinjaTargetGenerator::ComputeDefines(cmSourceFile const* source, std::set defines; const std::string config = this->LocalGenerator->GetConfigName(); cmGeneratorExpressionInterpreter genexInterpreter( - this->LocalGenerator, this->GeneratorTarget, config, - this->GeneratorTarget->GetName(), language); + this->LocalGenerator, config, this->GeneratorTarget, language); const std::string COMPILE_DEFINITIONS("COMPILE_DEFINITIONS"); if (const char* compile_defs = source->GetProperty(COMPILE_DEFINITIONS)) { @@ -217,8 +215,7 @@ std::string cmNinjaTargetGenerator::ComputeIncludes( std::vector includes; const std::string config = this->LocalGenerator->GetConfigName(); cmGeneratorExpressionInterpreter genexInterpreter( - this->LocalGenerator, this->GeneratorTarget, config, - this->GeneratorTarget->GetName(), language); + this->LocalGenerator, config, this->GeneratorTarget, language); const std::string INCLUDE_DIRECTORIES("INCLUDE_DIRECTORIES"); if (const char* cincludes = source->GetProperty(INCLUDE_DIRECTORIES)) { diff --git a/Source/cmServerProtocol.cxx b/Source/cmServerProtocol.cxx index af4b466..231cacb 100644 --- a/Source/cmServerProtocol.cxx +++ b/Source/cmServerProtocol.cxx @@ -722,8 +722,8 @@ static void PopulateFileGroupData( ? languageDataMap.at(kInterfaceSourcesLanguageDataKey) : languageDataMap.at(fileData.Language); cmLocalGenerator* lg = target->GetLocalGenerator(); - cmGeneratorExpressionInterpreter genexInterpreter( - lg, target, config, target->GetName(), fileData.Language); + cmGeneratorExpressionInterpreter genexInterpreter(lg, config, target, + fileData.Language); std::string compileFlags = ld.Flags; const std::string COMPILE_FLAGS("COMPILE_FLAGS"); @@ -817,7 +817,7 @@ static Json::Value DumpSourceFilesList( auto targetProp = target->Target->GetProperty("INTERFACE_SOURCES"); if (targetProp != nullptr) { cmGeneratorExpressionInterpreter genexInterpreter( - target->GetLocalGenerator(), target, config, target->GetName(), ""); + target->GetLocalGenerator(), config, target); auto evaluatedSources = cmsys::SystemTools::SplitString( genexInterpreter.Evaluate(targetProp, "INTERFACE_SOURCES"), ';'); @@ -977,8 +977,7 @@ static void CreateInterfaceSourcesEntry( LanguageData& ld = languageDataMap[kInterfaceSourcesLanguageDataKey]; ld.Language = ""; - cmGeneratorExpressionInterpreter genexInterpreter(lg, target, config, - target->GetName(), ""); + cmGeneratorExpressionInterpreter genexInterpreter(lg, config, target); std::vector propertyValue; GetTargetProperty(genexInterpreter, target, "INTERFACE_INCLUDE_DIRECTORIES", propertyValue); diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 9e74335..53a2a59 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -2117,8 +2117,7 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( flagtable = gg->GetCSharpFlagTable(); } cmGeneratorExpressionInterpreter genexInterpreter( - this->LocalGenerator, this->GeneratorTarget, config, - this->GeneratorTarget->GetName(), lang); + this->LocalGenerator, config, this->GeneratorTarget, lang); cmVS10GeneratorOptions clOptions( this->LocalGenerator, cmVisualStudioGeneratorOptions::Compiler, flagtable, this); https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=bea390e9bd68e1aa7d86b6aef7384f502c39068c commit bea390e9bd68e1aa7d86b6aef7384f502c39068c Author: Brad King AuthorDate: Thu Sep 6 14:21:06 2018 -0400 Commit: Brad King CommitDate: Fri Sep 7 09:23:43 2018 -0400 Fix dependency propagation through same-name imported targets If two imported targets in different directories have the same name we should still be able to propagate transitive link dependencies from both. Fix the target and link dependency analyzers to de-duplicate targets using target pointers rather than target names since the pointers will not be duplicated even if the names are. Issue: #18345 diff --git a/Source/cmComputeLinkDepends.cxx b/Source/cmComputeLinkDepends.cxx index 3659a1e..aa17de6 100644 --- a/Source/cmComputeLinkDepends.cxx +++ b/Source/cmComputeLinkDepends.cxx @@ -279,12 +279,12 @@ cmComputeLinkDepends::Compute() return this->FinalLinkEntries; } -std::map::iterator cmComputeLinkDepends::AllocateLinkEntry( - std::string const& item) +std::map::iterator cmComputeLinkDepends::AllocateLinkEntry( + cmLinkItem const& item) { - std::map::value_type index_entry( + std::map::value_type index_entry( item, static_cast(this->EntryList.size())); - std::map::iterator lei = + std::map::iterator lei = this->LinkEntryIndex.insert(index_entry).first; this->EntryList.emplace_back(); this->InferredDependSets.push_back(nullptr); @@ -295,15 +295,14 @@ std::map::iterator cmComputeLinkDepends::AllocateLinkEntry( int cmComputeLinkDepends::AddLinkEntry(cmLinkItem const& item) { // Check if the item entry has already been added. - std::map::iterator lei = - this->LinkEntryIndex.find(item.AsStr()); + std::map::iterator lei = this->LinkEntryIndex.find(item); if (lei != this->LinkEntryIndex.end()) { // Yes. We do not need to follow the item's dependencies again. return lei->second; } // Allocate a spot for the item entry. - lei = this->AllocateLinkEntry(item.AsStr()); + lei = this->AllocateLinkEntry(item); // Initialize the item entry. int index = lei->second; @@ -397,11 +396,11 @@ void cmComputeLinkDepends::QueueSharedDependencies( void cmComputeLinkDepends::HandleSharedDependency(SharedDepEntry const& dep) { // Check if the target already has an entry. - std::map::iterator lei = - this->LinkEntryIndex.find(dep.Item.AsStr()); + std::map::iterator lei = + this->LinkEntryIndex.find(dep.Item); if (lei == this->LinkEntryIndex.end()) { // Allocate a spot for the item entry. - lei = this->AllocateLinkEntry(dep.Item.AsStr()); + lei = this->AllocateLinkEntry(dep.Item); // Initialize the item entry. LinkEntry& entry = this->EntryList[lei->second]; diff --git a/Source/cmComputeLinkDepends.h b/Source/cmComputeLinkDepends.h index fb3a02f..66fb1e6 100644 --- a/Source/cmComputeLinkDepends.h +++ b/Source/cmComputeLinkDepends.h @@ -72,8 +72,8 @@ private: std::string Config; EntryVector FinalLinkEntries; - std::map::iterator AllocateLinkEntry( - std::string const& item); + std::map::iterator AllocateLinkEntry( + cmLinkItem const& item); int AddLinkEntry(cmLinkItem const& item); void AddVarLinkEntries(int depender_index, const char* value); void AddDirectLinkEntries(); @@ -83,7 +83,7 @@ private: // One entry for each unique item. std::vector EntryList; - std::map LinkEntryIndex; + std::map LinkEntryIndex; // BFS of initial dependencies. struct BFSEntry diff --git a/Source/cmComputeTargetDepends.cxx b/Source/cmComputeTargetDepends.cxx index edda2bd..268e749 100644 --- a/Source/cmComputeTargetDepends.cxx +++ b/Source/cmComputeTargetDepends.cxx @@ -195,7 +195,7 @@ void cmComputeTargetDepends::CollectTargetDepends(int depender_index) // dependencies in all targets, because the generated build-systems can't // deal with config-specific dependencies. { - std::set emitted; + std::set emitted; std::vector configs; depender->Makefile->GetConfigurations(configs); @@ -206,30 +206,34 @@ void cmComputeTargetDepends::CollectTargetDepends(int depender_index) std::vector objectFiles; depender->GetExternalObjects(objectFiles, it); for (cmSourceFile const* o : objectFiles) { - std::string objLib = o->GetObjectLibrary(); - if (!objLib.empty() && emitted.insert(objLib).second) { - if (depender->GetType() != cmStateEnums::EXECUTABLE && - depender->GetType() != cmStateEnums::STATIC_LIBRARY && - depender->GetType() != cmStateEnums::SHARED_LIBRARY && - depender->GetType() != cmStateEnums::MODULE_LIBRARY && - depender->GetType() != cmStateEnums::OBJECT_LIBRARY) { - this->GlobalGenerator->GetCMakeInstance()->IssueMessage( - cmake::FATAL_ERROR, - "Only executables and libraries may reference target objects.", - depender->GetBacktrace()); - return; + std::string const& objLib = o->GetObjectLibrary(); + if (!objLib.empty()) { + cmLinkItem const& objItem = depender->ResolveLinkItem(objLib); + if (emitted.insert(objItem).second) { + if (depender->GetType() != cmStateEnums::EXECUTABLE && + depender->GetType() != cmStateEnums::STATIC_LIBRARY && + depender->GetType() != cmStateEnums::SHARED_LIBRARY && + depender->GetType() != cmStateEnums::MODULE_LIBRARY && + depender->GetType() != cmStateEnums::OBJECT_LIBRARY) { + this->GlobalGenerator->GetCMakeInstance()->IssueMessage( + cmake::FATAL_ERROR, + "Only executables and libraries may reference target objects.", + depender->GetBacktrace()); + return; + } + const_cast(depender)->Target->AddUtility( + objLib); } - const_cast(depender)->Target->AddUtility(objLib); } } cmLinkImplementation const* impl = depender->GetLinkImplementation(it); // A target should not depend on itself. - emitted.insert(depender->GetName()); + emitted.insert(cmLinkItem(depender)); for (cmLinkImplItem const& lib : impl->Libraries) { // Don't emit the same library twice for this target. - if (emitted.insert(lib.AsStr()).second) { + if (emitted.insert(lib).second) { this->AddTargetDepend(depender_index, lib, true); this->AddInterfaceDepends(depender_index, lib, it, emitted); } @@ -240,12 +244,12 @@ void cmComputeTargetDepends::CollectTargetDepends(int depender_index) // Loop over all utility dependencies. { std::set const& tutils = depender->GetUtilityItems(); - std::set emitted; + std::set emitted; // A target should not depend on itself. - emitted.insert(depender->GetName()); + emitted.insert(cmLinkItem(depender)); for (cmLinkItem const& litem : tutils) { // Don't emit the same utility twice for this target. - if (emitted.insert(litem.AsStr()).second) { + if (emitted.insert(litem).second) { this->AddTargetDepend(depender_index, litem, false); } } @@ -254,14 +258,14 @@ void cmComputeTargetDepends::CollectTargetDepends(int depender_index) void cmComputeTargetDepends::AddInterfaceDepends( int depender_index, const cmGeneratorTarget* dependee, - const std::string& config, std::set& emitted) + const std::string& config, std::set& emitted) { cmGeneratorTarget const* depender = this->Targets[depender_index]; if (cmLinkInterface const* iface = dependee->GetLinkInterface(config, depender)) { for (cmLinkItem const& lib : iface->Libraries) { // Don't emit the same library twice for this target. - if (emitted.insert(lib.AsStr()).second) { + if (emitted.insert(lib).second) { this->AddTargetDepend(depender_index, lib, true); this->AddInterfaceDepends(depender_index, lib, config, emitted); } @@ -271,7 +275,7 @@ void cmComputeTargetDepends::AddInterfaceDepends( void cmComputeTargetDepends::AddInterfaceDepends( int depender_index, cmLinkItem const& dependee_name, - const std::string& config, std::set& emitted) + const std::string& config, std::set& emitted) { cmGeneratorTarget const* depender = this->Targets[depender_index]; cmGeneratorTarget const* dependee = dependee_name.Target; @@ -285,7 +289,7 @@ void cmComputeTargetDepends::AddInterfaceDepends( if (dependee) { // A target should not depend on itself. - emitted.insert(depender->GetName()); + emitted.insert(cmLinkItem(depender)); this->AddInterfaceDepends(depender_index, dependee, config, emitted); } } diff --git a/Source/cmComputeTargetDepends.h b/Source/cmComputeTargetDepends.h index e93e376..3046e8a 100644 --- a/Source/cmComputeTargetDepends.h +++ b/Source/cmComputeTargetDepends.h @@ -51,11 +51,11 @@ private: bool ComputeFinalDepends(cmComputeComponentGraph const& ccg); void AddInterfaceDepends(int depender_index, cmLinkItem const& dependee_name, const std::string& config, - std::set& emitted); + std::set& emitted); void AddInterfaceDepends(int depender_index, cmGeneratorTarget const* dependee, const std::string& config, - std::set& emitted); + std::set& emitted); cmGlobalGenerator* GlobalGenerator; bool DebugMode; bool NoCycles; diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 377c008..080ff1c 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -4575,14 +4575,14 @@ void cmGeneratorTarget::ComputeLinkInterface( this->GetType() == cmStateEnums::INTERFACE_LIBRARY) { // Shared libraries may have runtime implementation dependencies // on other shared libraries that are not in the interface. - std::unordered_set emitted; + std::set emitted; for (cmLinkItem const& lib : iface.Libraries) { - emitted.insert(lib.AsStr()); + emitted.insert(lib); } if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY) { cmLinkImplementation const* impl = this->GetLinkImplementation(config); for (cmLinkImplItem const& lib : impl->Libraries) { - if (emitted.insert(lib.AsStr()).second) { + if (emitted.insert(lib).second) { if (lib.Target) { // This is a runtime dependency on another shared library. if (lib.Target->GetType() == cmStateEnums::SHARED_LIBRARY) { diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 971d7ff..a22521b 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -396,6 +396,7 @@ if(BUILD_TESTING) ADD_TEST_MACRO(CompatibleInterface CompatibleInterface) ADD_TEST_MACRO(AliasTarget AliasTarget) ADD_TEST_MACRO(StagingPrefix StagingPrefix) + ADD_TEST_MACRO(ImportedSameName ImportedSameName) ADD_TEST_MACRO(InterfaceLibrary InterfaceLibrary) if (CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]") set(ConfigSources_BUILD_OPTIONS -DCMAKE_BUILD_TYPE=Debug) diff --git a/Tests/ImportedSameName/A/CMakeLists.txt b/Tests/ImportedSameName/A/CMakeLists.txt new file mode 100644 index 0000000..9417a2c --- /dev/null +++ b/Tests/ImportedSameName/A/CMakeLists.txt @@ -0,0 +1,7 @@ +add_library(a STATIC a.c) + +add_library(sameName INTERFACE IMPORTED) +target_link_libraries(sameName INTERFACE a) + +add_library(ifaceA INTERFACE) +target_link_libraries(ifaceA INTERFACE sameName) diff --git a/Tests/ImportedSameName/A/a.c b/Tests/ImportedSameName/A/a.c new file mode 100644 index 0000000..4ef3698 --- /dev/null +++ b/Tests/ImportedSameName/A/a.c @@ -0,0 +1,3 @@ +void a(void) +{ +} diff --git a/Tests/ImportedSameName/B/CMakeLists.txt b/Tests/ImportedSameName/B/CMakeLists.txt new file mode 100644 index 0000000..6947fa9 --- /dev/null +++ b/Tests/ImportedSameName/B/CMakeLists.txt @@ -0,0 +1,7 @@ +add_library(b STATIC b.c) + +add_library(sameName INTERFACE IMPORTED) +target_link_libraries(sameName INTERFACE b) + +add_library(ifaceB INTERFACE) +target_link_libraries(ifaceB INTERFACE sameName) diff --git a/Tests/ImportedSameName/B/b.c b/Tests/ImportedSameName/B/b.c new file mode 100644 index 0000000..c7c7df4 --- /dev/null +++ b/Tests/ImportedSameName/B/b.c @@ -0,0 +1,3 @@ +void b(void) +{ +} diff --git a/Tests/ImportedSameName/CMakeLists.txt b/Tests/ImportedSameName/CMakeLists.txt new file mode 100644 index 0000000..4292c12 --- /dev/null +++ b/Tests/ImportedSameName/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.12) +project(ImportedSameName C) + +add_subdirectory(A) +add_subdirectory(B) + +add_executable(ImportedSameName main.c) +target_link_libraries(ImportedSameName PRIVATE ifaceA ifaceB) diff --git a/Tests/ImportedSameName/main.c b/Tests/ImportedSameName/main.c new file mode 100644 index 0000000..33196b7 --- /dev/null +++ b/Tests/ImportedSameName/main.c @@ -0,0 +1,9 @@ +extern void a(void); +extern void b(void); + +int main(void) +{ + a(); + b(); + return 0; +} https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=fc7e4d1ed85370d03acbd62bc753cced3550752b commit fc7e4d1ed85370d03acbd62bc753cced3550752b Author: Brad King AuthorDate: Thu Sep 6 13:10:55 2018 -0400 Commit: Brad King CommitDate: Fri Sep 7 08:57:51 2018 -0400 cmLinkItem: Convert to a "sum type" over a string and target pointer Avoid exposing the item name implicitly as std::string. When the item is a target, avoid storing a second copy of its name. Most link item construction is paired with calls to `FindTargetToLink` to get the possible target pointer. Rename these methods to `ResolveLinkItem` and refactor them to construct the entire item. diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 0457984..628cc6f 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -265,6 +265,7 @@ set(SRCS cmInstallDirectoryGenerator.h cmInstallDirectoryGenerator.cxx cmLinkedTree.h + cmLinkItem.cxx cmLinkItem.h cmLinkLineComputer.cxx cmLinkLineComputer.h diff --git a/Source/cmComputeLinkDepends.cxx b/Source/cmComputeLinkDepends.cxx index b1f3860..3659a1e 100644 --- a/Source/cmComputeLinkDepends.cxx +++ b/Source/cmComputeLinkDepends.cxx @@ -295,22 +295,24 @@ std::map::iterator cmComputeLinkDepends::AllocateLinkEntry( int cmComputeLinkDepends::AddLinkEntry(cmLinkItem const& item) { // Check if the item entry has already been added. - std::map::iterator lei = this->LinkEntryIndex.find(item); + std::map::iterator lei = + this->LinkEntryIndex.find(item.AsStr()); if (lei != this->LinkEntryIndex.end()) { // Yes. We do not need to follow the item's dependencies again. return lei->second; } // Allocate a spot for the item entry. - lei = this->AllocateLinkEntry(item); + lei = this->AllocateLinkEntry(item.AsStr()); // Initialize the item entry. int index = lei->second; LinkEntry& entry = this->EntryList[index]; - entry.Item = item; + entry.Item = item.AsStr(); entry.Target = item.Target; - entry.IsFlag = (!entry.Target && item[0] == '-' && item[1] != 'l' && - item.substr(0, 10) != "-framework"); + entry.IsFlag = + (!entry.Target && entry.Item[0] == '-' && entry.Item[1] != 'l' && + entry.Item.substr(0, 10) != "-framework"); // If the item has dependencies queue it to follow them. if (entry.Target) { @@ -396,14 +398,14 @@ void cmComputeLinkDepends::HandleSharedDependency(SharedDepEntry const& dep) { // Check if the target already has an entry. std::map::iterator lei = - this->LinkEntryIndex.find(dep.Item); + this->LinkEntryIndex.find(dep.Item.AsStr()); if (lei == this->LinkEntryIndex.end()) { // Allocate a spot for the item entry. - lei = this->AllocateLinkEntry(dep.Item); + lei = this->AllocateLinkEntry(dep.Item.AsStr()); // Initialize the item entry. LinkEntry& entry = this->EntryList[lei->second]; - entry.Item = dep.Item; + entry.Item = dep.Item.AsStr(); entry.Target = dep.Item.Target; // This item was added specifically because it is a dependent @@ -473,9 +475,9 @@ void cmComputeLinkDepends::AddVarLinkEntries(int depender_index, // If the library is meant for this link type then use it. if (llt == GENERAL_LibraryType || llt == this->LinkType) { - actual_libs.emplace_back(d, this->FindTargetToLink(depender_index, d)); + actual_libs.emplace_back(this->ResolveLinkItem(depender_index, d)); } else if (this->OldLinkDirMode) { - cmLinkItem item(d, this->FindTargetToLink(depender_index, d)); + cmLinkItem item = this->ResolveLinkItem(depender_index, d); this->CheckWrongConfigItem(item); } @@ -512,7 +514,7 @@ void cmComputeLinkDepends::AddLinkEntries(int depender_index, // Skip entries that will resolve to the target getting linked or // are empty. cmLinkItem const& item = l; - if (item == this->Target->GetName() || item.empty()) { + if (item.AsStr() == this->Target->GetName() || item.AsStr().empty()) { continue; } @@ -553,8 +555,8 @@ void cmComputeLinkDepends::AddLinkEntries(int depender_index, } } -cmGeneratorTarget const* cmComputeLinkDepends::FindTargetToLink( - int depender_index, const std::string& name) +cmLinkItem cmComputeLinkDepends::ResolveLinkItem(int depender_index, + const std::string& name) { // Look for a target in the scope of the depender. cmGeneratorTarget const* from = this->Target; @@ -564,7 +566,7 @@ cmGeneratorTarget const* cmComputeLinkDepends::FindTargetToLink( from = depender; } } - return from->FindTargetToLink(name); + return from->ResolveLinkItem(name); } void cmComputeLinkDepends::InferDependencies() diff --git a/Source/cmComputeLinkDepends.h b/Source/cmComputeLinkDepends.h index dd0e029..fb3a02f 100644 --- a/Source/cmComputeLinkDepends.h +++ b/Source/cmComputeLinkDepends.h @@ -79,8 +79,7 @@ private: void AddDirectLinkEntries(); template void AddLinkEntries(int depender_index, std::vector const& libs); - cmGeneratorTarget const* FindTargetToLink(int depender_index, - const std::string& name); + cmLinkItem ResolveLinkItem(int depender_index, const std::string& name); // One entry for each unique item. std::vector EntryList; diff --git a/Source/cmComputeTargetDepends.cxx b/Source/cmComputeTargetDepends.cxx index efdd3a5..edda2bd 100644 --- a/Source/cmComputeTargetDepends.cxx +++ b/Source/cmComputeTargetDepends.cxx @@ -229,7 +229,7 @@ void cmComputeTargetDepends::CollectTargetDepends(int depender_index) emitted.insert(depender->GetName()); for (cmLinkImplItem const& lib : impl->Libraries) { // Don't emit the same library twice for this target. - if (emitted.insert(lib).second) { + if (emitted.insert(lib.AsStr()).second) { this->AddTargetDepend(depender_index, lib, true); this->AddInterfaceDepends(depender_index, lib, it, emitted); } @@ -245,7 +245,7 @@ void cmComputeTargetDepends::CollectTargetDepends(int depender_index) emitted.insert(depender->GetName()); for (cmLinkItem const& litem : tutils) { // Don't emit the same utility twice for this target. - if (emitted.insert(litem).second) { + if (emitted.insert(litem.AsStr()).second) { this->AddTargetDepend(depender_index, litem, false); } } @@ -261,7 +261,7 @@ void cmComputeTargetDepends::AddInterfaceDepends( dependee->GetLinkInterface(config, depender)) { for (cmLinkItem const& lib : iface->Libraries) { // Don't emit the same library twice for this target. - if (emitted.insert(lib).second) { + if (emitted.insert(lib.AsStr()).second) { this->AddTargetDepend(depender_index, lib, true); this->AddInterfaceDepends(depender_index, lib, config, emitted); } @@ -324,7 +324,7 @@ void cmComputeTargetDepends::AddTargetDepend(int depender_index, << depender->GetName() << "\" does not exist."; cmListFileBacktrace const* backtrace = - depender->GetUtilityBacktrace(dependee_name); + depender->GetUtilityBacktrace(dependee_name.AsStr()); if (backtrace) { cm->IssueMessage(messageType, e.str(), *backtrace); } else { diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index 75d3374..1c5040a 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -831,6 +831,16 @@ void cmExportFileGenerator::SetImportDetailProperties( } } +static std::string const& asString(std::string const& l) +{ + return l; +} + +static std::string const& asString(cmLinkItem const& l) +{ + return l.AsStr(); +} + template void cmExportFileGenerator::SetImportLinkProperty( std::string const& suffix, cmGeneratorTarget* target, @@ -850,7 +860,7 @@ void cmExportFileGenerator::SetImportLinkProperty( link_entries += sep; sep = ";"; - std::string temp = l; + std::string temp = asString(l); this->AddTargetNamespace(temp, target, missingTargets); link_entries += temp; } diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 80a99d5..377c008 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -671,9 +671,12 @@ std::set const& cmGeneratorTarget::GetUtilityItems() const this->UtilityItemsDone = true; std::set const& utilities = this->GetUtilities(); for (std::string const& i : utilities) { - cmGeneratorTarget* gt = - this->LocalGenerator->FindGeneratorTargetToUse(i); - this->UtilityItems.insert(cmLinkItem(i, gt)); + if (cmGeneratorTarget* gt = + this->LocalGenerator->FindGeneratorTargetToUse(i)) { + this->UtilityItems.insert(cmLinkItem(gt)); + } else { + this->UtilityItems.insert(cmLinkItem(i)); + } } } return this->UtilityItems; @@ -816,7 +819,8 @@ static void AddInterfaceEntries( thisTarget->GetLinkImplementationLibraries(config)) { for (cmLinkImplItem const& lib : impl->Libraries) { if (lib.Target) { - std::string genex = "$"; + std::string genex = + "$"; cmGeneratorExpression ge(lib.Backtrace); std::unique_ptr cge = ge.Parse(genex); cge->SetEvaluateForBuildsystem(true); @@ -836,7 +840,7 @@ static void AddObjectEntries( for (cmLinkImplItem const& lib : impl->Libraries) { if (lib.Target && lib.Target->GetType() == cmStateEnums::OBJECT_LIBRARY) { - std::string genex = "$"; + std::string genex = "$"; cmGeneratorExpression ge(lib.Backtrace); std::unique_ptr cge = ge.Parse(genex); cge->SetEvaluateForBuildsystem(true); @@ -860,7 +864,7 @@ static bool processSources( for (cmGeneratorTarget::TargetPropertyEntry* entry : entries) { cmLinkImplItem const& item = entry->LinkImplItem; - std::string const& targetName = item; + std::string const& targetName = item.AsStr(); std::vector entrySources; cmSystemTools::ExpandListArgument( entry->ge->Evaluate(tgt->GetLocalGenerator(), config, false, tgt, tgt, @@ -1756,7 +1760,7 @@ public: void Visit(cmLinkItem const& item) { if (!item.Target) { - if (item.find("::") != std::string::npos) { + if (item.AsStr().find("::") != std::string::npos) { bool noMessage = false; cmake::MessageType messageType = cmake::FATAL_ERROR; std::ostringstream e; @@ -1777,7 +1781,7 @@ public: if (!noMessage) { e << "Target \"" << this->Target->GetName() - << "\" links to target \"" << item + << "\" links to target \"" << item.AsStr() << "\" but the target was not found. Perhaps a find_package() " "call is missing for an IMPORTED target, or an ALIAS target is " "missing?"; @@ -2477,7 +2481,7 @@ static void processIncludeDirectories( { for (cmGeneratorTarget::TargetPropertyEntry* entry : entries) { cmLinkImplItem const& item = entry->LinkImplItem; - std::string const& targetName = item; + std::string const& targetName = item.AsStr(); bool const fromImported = item.Target && item.Target->IsImported(); bool const checkCMP0027 = item.FromGenex; std::vector entryIncludes; @@ -2615,7 +2619,7 @@ std::vector cmGeneratorTarget::GetIncludeDirectories( cmLinkImplementationLibraries const* impl = this->GetLinkImplementationLibraries(config); for (cmLinkImplItem const& lib : impl->Libraries) { - std::string libDir = cmSystemTools::CollapseFullPath(lib); + std::string libDir = cmSystemTools::CollapseFullPath(lib.AsStr()); static cmsys::RegularExpression frameworkCheck( "(.*\\.framework)(/Versions/[^/]+)?/[^/]+$"); @@ -4495,7 +4499,7 @@ void cmGeneratorTarget::LookupLinkItems(std::vector const& names, if (name == this->GetName() || name.empty()) { continue; } - items.emplace_back(name, this->FindTargetToLink(name)); + items.push_back(this->ResolveLinkItem(name)); } } @@ -4573,12 +4577,12 @@ void cmGeneratorTarget::ComputeLinkInterface( // on other shared libraries that are not in the interface. std::unordered_set emitted; for (cmLinkItem const& lib : iface.Libraries) { - emitted.insert(lib); + emitted.insert(lib.AsStr()); } if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY) { cmLinkImplementation const* impl = this->GetLinkImplementation(config); for (cmLinkImplItem const& lib : impl->Libraries) { - if (emitted.insert(lib).second) { + if (emitted.insert(lib.AsStr()).second) { if (lib.Target) { // This is a runtime dependency on another shared library. if (lib.Target->GetType() == cmStateEnums::SHARED_LIBRARY) { @@ -5603,7 +5607,7 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries( } // The entry is meant for this configuration. - impl.Libraries.emplace_back(name, this->FindTargetToLink(name), *btIt, + impl.Libraries.emplace_back(this->ResolveLinkItem(name), *btIt, evaluated != *le); } @@ -5631,14 +5635,12 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries( continue; } // Support OLD behavior for CMP0003. - impl.WrongConfigLibraries.emplace_back(name, - this->FindTargetToLink(name)); + impl.WrongConfigLibraries.push_back(this->ResolveLinkItem(name)); } } } -cmGeneratorTarget* cmGeneratorTarget::FindTargetToLink( - std::string const& name) const +cmLinkItem cmGeneratorTarget::ResolveLinkItem(std::string const& name) const { cmGeneratorTarget* tgt = this->LocalGenerator->FindGeneratorTargetToUse(name); @@ -5651,7 +5653,11 @@ cmGeneratorTarget* cmGeneratorTarget::FindTargetToLink( tgt = nullptr; } - return tgt; + if (tgt) { + return cmLinkItem(tgt); + } + + return cmLinkItem(name); } std::string cmGeneratorTarget::GetPDBDirectory(const std::string& config) const diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 1030d91..a847e21 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -357,7 +357,7 @@ public: cmOptionalLinkImplementation& impl, const cmGeneratorTarget* head) const; - cmGeneratorTarget* FindTargetToLink(std::string const& name) const; + cmLinkItem ResolveLinkItem(std::string const& name) const; // Compute the set of languages compiled by the target. This is // computed every time it is called because the languages can change diff --git a/Source/cmLinkItem.cxx b/Source/cmLinkItem.cxx new file mode 100644 index 0000000..69b6821 --- /dev/null +++ b/Source/cmLinkItem.cxx @@ -0,0 +1,72 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmLinkItem.h" + +#include "cmGeneratorTarget.h" + +#include // IWYU pragma: keep + +cmLinkItem::cmLinkItem() + : String() + , Target(nullptr) +{ +} + +cmLinkItem::cmLinkItem(std::string const& n) + : String(n) + , Target(nullptr) +{ +} + +cmLinkItem::cmLinkItem(cmGeneratorTarget const* t) + : String() + , Target(t) +{ +} + +std::string const& cmLinkItem::AsStr() const +{ + return this->Target ? this->Target->GetName() : this->String; +} + +bool operator<(cmLinkItem const& l, cmLinkItem const& r) +{ + // Order among targets. + if (l.Target && r.Target) { + return l.Target < r.Target; + } + // Order targets before strings. + if (l.Target) { + return true; + } + if (r.Target) { + return false; + } + // Order among strings. + return l.String < r.String; +} + +bool operator==(cmLinkItem const& l, cmLinkItem const& r) +{ + return l.Target == r.Target && l.String == r.String; +} + +std::ostream& operator<<(std::ostream& os, cmLinkItem const& item) +{ + return os << item.AsStr(); +} + +cmLinkImplItem::cmLinkImplItem() + : cmLinkItem() + , Backtrace() + , FromGenex(false) +{ +} + +cmLinkImplItem::cmLinkImplItem(cmLinkItem item, cmListFileBacktrace const& bt, + bool fromGenex) + : cmLinkItem(std::move(item)) + , Backtrace(bt) + , FromGenex(fromGenex) +{ +} diff --git a/Source/cmLinkItem.h b/Source/cmLinkItem.h index e8c9487..74fd298 100644 --- a/Source/cmLinkItem.h +++ b/Source/cmLinkItem.h @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -17,40 +18,27 @@ class cmGeneratorTarget; // Basic information about each link item. -class cmLinkItem : public std::string +class cmLinkItem { - typedef std::string std_string; + std::string String; public: - cmLinkItem() - : std_string() - , Target(nullptr) - { - } - cmLinkItem(const std_string& n, cmGeneratorTarget const* t) - : std_string(n) - , Target(t) - { - } + cmLinkItem(); + explicit cmLinkItem(std::string const& s); + explicit cmLinkItem(cmGeneratorTarget const* t); + std::string const& AsStr() const; cmGeneratorTarget const* Target; + friend bool operator<(cmLinkItem const& l, cmLinkItem const& r); + friend bool operator==(cmLinkItem const& l, cmLinkItem const& r); + friend std::ostream& operator<<(std::ostream& os, cmLinkItem const& item); }; class cmLinkImplItem : public cmLinkItem { public: - cmLinkImplItem() - : cmLinkItem() - , Backtrace() - , FromGenex(false) - { - } - cmLinkImplItem(std::string const& n, cmGeneratorTarget const* t, - cmListFileBacktrace const& bt, bool fromGenex) - : cmLinkItem(n, t) - , Backtrace(bt) - , FromGenex(fromGenex) - { - } + cmLinkImplItem(); + cmLinkImplItem(cmLinkItem item, cmListFileBacktrace const& bt, + bool fromGenex); cmListFileBacktrace Backtrace; bool FromGenex; }; diff --git a/bootstrap b/bootstrap index 0b49b74..188193d 100755 --- a/bootstrap +++ b/bootstrap @@ -352,6 +352,7 @@ CMAKE_CXX_SOURCES="\ cmInstallTargetsCommand \ cmInstalledFile \ cmLinkDirectoriesCommand \ + cmLinkItem \ cmLinkLineComputer \ cmListCommand \ cmListFileCache \ ----------------------------------------------------------------------- Summary of changes: Modules/FindMPI.cmake | 2 +- Source/CMakeLists.txt | 1 + Source/cmCTest.cxx | 6 +- Source/cmComputeLinkDepends.cxx | 33 ++++---- Source/cmComputeLinkDepends.h | 9 +-- Source/cmComputeTargetDepends.cxx | 46 ++++++------ Source/cmComputeTargetDepends.h | 4 +- Source/cmExportBuildAndroidMKGenerator.cxx | 2 +- Source/cmExportFileGenerator.cxx | 12 ++- Source/cmExportTryCompileFileGenerator.cxx | 3 +- Source/cmExtraSublimeTextGenerator.cxx | 12 +-- Source/cmGeneratorExpression.cxx | 14 ++-- Source/cmGeneratorExpression.h | 55 ++------------ Source/cmGeneratorExpressionDAGChecker.cxx | 13 ++-- Source/cmGeneratorExpressionDAGChecker.h | 13 ++-- Source/cmGeneratorExpressionNode.cxx | 13 ++-- Source/cmGeneratorTarget.cxx | 87 ++++++++++++---------- Source/cmGeneratorTarget.h | 2 +- Source/cmGlobalXCodeGenerator.cxx | 12 ++- Source/cmLinkItem.cxx | 72 ++++++++++++++++++ Source/cmLinkItem.h | 38 ++++------ Source/cmLocalVisualStudio7Generator.cxx | 3 +- Source/cmMakefileTargetGenerator.cxx | 3 +- Source/cmNinjaTargetGenerator.cxx | 11 +-- Source/cmServerProtocol.cxx | 9 +-- Source/cmVisualStudio10TargetGenerator.cxx | 3 +- Tests/CMakeLists.txt | 1 + Tests/ImportedSameName/A/CMakeLists.txt | 8 ++ Tests/ImportedSameName/A/a.c | 3 + Tests/ImportedSameName/B/CMakeLists.txt | 8 ++ Tests/ImportedSameName/B/b.c | 3 + Tests/ImportedSameName/CMakeLists.txt | 8 ++ Tests/ImportedSameName/main.c | 16 ++++ .../ctest_start/NoAppendDifferentTrack-stdout.txt | 8 ++ Tests/RunCMake/ctest_start/RunCMakeTest.cmake | 1 + Tests/RunCMake/ctest_start/test.cmake.in | 2 +- bootstrap | 1 + 37 files changed, 312 insertions(+), 225 deletions(-) create mode 100644 Source/cmLinkItem.cxx create mode 100644 Tests/ImportedSameName/A/CMakeLists.txt create mode 100644 Tests/ImportedSameName/A/a.c create mode 100644 Tests/ImportedSameName/B/CMakeLists.txt create mode 100644 Tests/ImportedSameName/B/b.c create mode 100644 Tests/ImportedSameName/CMakeLists.txt create mode 100644 Tests/ImportedSameName/main.c create mode 100644 Tests/RunCMake/ctest_start/NoAppendDifferentTrack-stdout.txt hooks/post-receive -- CMake From kwrobot at kitware.com Tue Sep 11 08:25:06 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Tue, 11 Sep 2018 08:25:06 -0400 (EDT) Subject: [Cmake-commits] CMake branch, release, updated. v3.12.2-6-ge0e56ab Message-ID: <20180911122506.F360C11374F@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, release has been updated via e0e56abe3479efddd994cc1a3ee9b8a123111903 (commit) via 3eda5cdd939e0bae5241e2286e7524d552ab455c (commit) via e374b9f1ebae70ca4381588362d6d3418f832ea7 (commit) via 09f0325eaffb6b32b570e3339aa8b8332350b31d (commit) via 68f2b471df7687e37ab2a5808585aad76c7c3122 (commit) via 292ec157b67b5570d5bc2e00bba554cc157d9dae (commit) from f478fa633daeb1432805821adddc40730ffd283d (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- ----------------------------------------------------------------------- Summary of changes: Modules/FindMPI.cmake | 2 +- Source/CTest/cmCTestMultiProcessHandler.cxx | 59 ++++++++++++++-------- Source/CTest/cmCTestMultiProcessHandler.h | 5 ++ Source/cmCTest.cxx | 6 ++- Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake | 4 +- .../CTestCommandLine/test-load-fail-stderr.txt | 1 - .../CTestCommandLine/test-load-fail-stdout.txt | 2 - .../CTestCommandLine/test-load-pass-stderr.txt | 1 - ...nvalid-stdout.txt => test-load-wait-stdout.txt} | 1 + .../ctest_start/NoAppendDifferentTrack-stdout.txt | 8 +++ Tests/RunCMake/ctest_start/RunCMakeTest.cmake | 1 + Tests/RunCMake/ctest_start/test.cmake.in | 2 +- .../ctest_test/CTestTestLoadFail-result.txt | 1 - .../ctest_test/CTestTestLoadFail-stderr.txt | 1 - .../ctest_test/CTestTestLoadFail-stdout.txt | 2 - ...ass-stdout.txt => CTestTestLoadWait-stdout.txt} | 3 +- Tests/RunCMake/ctest_test/RunCMakeTest.cmake | 8 +-- Tests/RunCMake/ctest_test/TestLoadFail-result.txt | 1 - Tests/RunCMake/ctest_test/TestLoadFail-stderr.txt | 1 - Tests/RunCMake/ctest_test/TestLoadFail-stdout.txt | 2 - ...LoadPass-stdout.txt => TestLoadWait-stdout.txt} | 3 +- 21 files changed, 70 insertions(+), 44 deletions(-) delete mode 100644 Tests/RunCMake/CTestCommandLine/test-load-fail-stderr.txt delete mode 100644 Tests/RunCMake/CTestCommandLine/test-load-fail-stdout.txt delete mode 100644 Tests/RunCMake/CTestCommandLine/test-load-pass-stderr.txt copy Tests/RunCMake/CTestCommandLine/{test-load-invalid-stdout.txt => test-load-wait-stdout.txt} (74%) create mode 100644 Tests/RunCMake/ctest_start/NoAppendDifferentTrack-stdout.txt delete mode 100644 Tests/RunCMake/ctest_test/CTestTestLoadFail-result.txt delete mode 100644 Tests/RunCMake/ctest_test/CTestTestLoadFail-stderr.txt delete mode 100644 Tests/RunCMake/ctest_test/CTestTestLoadFail-stdout.txt copy Tests/RunCMake/ctest_test/{CTestTestLoadPass-stdout.txt => CTestTestLoadWait-stdout.txt} (52%) delete mode 100644 Tests/RunCMake/ctest_test/TestLoadFail-result.txt delete mode 100644 Tests/RunCMake/ctest_test/TestLoadFail-stderr.txt delete mode 100644 Tests/RunCMake/ctest_test/TestLoadFail-stdout.txt copy Tests/RunCMake/ctest_test/{CTestTestLoadPass-stdout.txt => TestLoadWait-stdout.txt} (52%) hooks/post-receive -- CMake From kwrobot at kitware.com Tue Sep 11 08:35:05 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Tue, 11 Sep 2018 08:35:05 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-598-g528d762 Message-ID: <20180911123505.ABDCC113E16@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 528d7625b89e0343bbf541edd256971493a6e455 (commit) via 9a5b04a5f6cc3f6e8e35b9b2e6858406c4ecf4a1 (commit) via f13d4b10775cd4d6a604a7f1b013b5d064864a41 (commit) via e9f72e9c94e17758aada77c5ba05502739242432 (commit) via 5ff7149298971e87df5e28b1bc5f48785bce551a (commit) via a26ebb894b192b0156f6a0802ecc4b1f872fcff3 (commit) via 6d8cabe8d40d09827d0353b7553a27d61ca60846 (commit) via 7b9d8ce168a707c0a9aa81e945eef82e231db9ba (commit) via ab2e35d6144c6e666eb0cfffe144d2b93c72949b (commit) via fc1602456abf04f301a8fcd9ac71fd0975c6bbde (commit) from b1c8d95dbe97ab2511e08518bf8eee1f5da2e941 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=528d7625b89e0343bbf541edd256971493a6e455 commit 528d7625b89e0343bbf541edd256971493a6e455 Merge: 9a5b04a a26ebb8 Author: Brad King AuthorDate: Tue Sep 11 12:31:13 2018 +0000 Commit: Kitware Robot CommitDate: Tue Sep 11 08:31:19 2018 -0400 Merge topic 'iar-fail-early' a26ebb894b IAR: Abort if compiler version or target architecture is not detected Acked-by: Kitware Robot Merge-request: !2353 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=9a5b04a5f6cc3f6e8e35b9b2e6858406c4ecf4a1 commit 9a5b04a5f6cc3f6e8e35b9b2e6858406c4ecf4a1 Merge: f13d4b1 5ff7149 Author: Brad King AuthorDate: Tue Sep 11 12:30:09 2018 +0000 Commit: Kitware Robot CommitDate: Tue Sep 11 08:30:15 2018 -0400 Merge topic 'cmake_cpack_command-doc' 5ff7149298 Help: Document existence of CMAKE_CPACK_COMMAND Acked-by: Kitware Robot Merge-request: !2367 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=f13d4b10775cd4d6a604a7f1b013b5d064864a41 commit f13d4b10775cd4d6a604a7f1b013b5d064864a41 Merge: e9f72e9 ab2e35d Author: Brad King AuthorDate: Tue Sep 11 12:27:58 2018 +0000 Commit: Kitware Robot CommitDate: Tue Sep 11 08:28:05 2018 -0400 Merge topic 'replace-os-x-name-with-macos' ab2e35d614 Replace occurrences of "Mac OS X" with "macOS" in comments fc1602456a Help: Replace occurrences of "Mac OS X" with "macOS" Acked-by: Kitware Robot Reviewed-by: Gregor Jasny Reviewed-by: Clinton Stimpson Merge-request: !2351 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=e9f72e9c94e17758aada77c5ba05502739242432 commit e9f72e9c94e17758aada77c5ba05502739242432 Merge: b1c8d95 6d8cabe Author: Brad King AuthorDate: Tue Sep 11 12:26:37 2018 +0000 Commit: Kitware Robot CommitDate: Tue Sep 11 08:26:42 2018 -0400 Merge topic 'docs/setdirproprs' 6d8cabe8d4 Help: Clarify INCLUDE_DIRECTORIES directory property behavior 7b9d8ce168 Help: Clarify wording of set_directory_properties docs Acked-by: Kitware Robot Merge-request: !2337 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=5ff7149298971e87df5e28b1bc5f48785bce551a commit 5ff7149298971e87df5e28b1bc5f48785bce551a Author: Kyle Edwards AuthorDate: Mon Sep 10 12:36:41 2018 -0400 Commit: Kyle Edwards CommitDate: Mon Sep 10 12:36:41 2018 -0400 Help: Document existence of CMAKE_CPACK_COMMAND This useful variable was previously undocumented. This commit adds brief documentation for it. diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst index 3eea8a2..d8a5def 100644 --- a/Help/manual/cmake-variables.7.rst +++ b/Help/manual/cmake-variables.7.rst @@ -24,6 +24,7 @@ Variables that Provide Information /variable/CMAKE_CACHE_PATCH_VERSION /variable/CMAKE_CFG_INTDIR /variable/CMAKE_COMMAND + /variable/CMAKE_CPACK_COMMAND /variable/CMAKE_CROSSCOMPILING /variable/CMAKE_CROSSCOMPILING_EMULATOR /variable/CMAKE_CTEST_COMMAND diff --git a/Help/variable/CMAKE_CPACK_COMMAND.rst b/Help/variable/CMAKE_CPACK_COMMAND.rst new file mode 100644 index 0000000..559108a --- /dev/null +++ b/Help/variable/CMAKE_CPACK_COMMAND.rst @@ -0,0 +1,8 @@ +CMAKE_CPACK_COMMAND +------------------- + +Full path to :manual:`cpack(1)` command installed with CMake. + +This is the full path to the CPack executable :manual:`cpack(1)` which is +useful from custom commands that want to use the :manual:`cmake(1)` ``-E`` +option for portable system commands. https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=a26ebb894b192b0156f6a0802ecc4b1f872fcff3 commit a26ebb894b192b0156f6a0802ecc4b1f872fcff3 Author: Daniel Sch?rmann AuthorDate: Mon Sep 10 13:44:26 2018 +0200 Commit: Brad King CommitDate: Mon Sep 10 09:03:47 2018 -0400 IAR: Abort if compiler version or target architecture is not detected If these are not detected then we cannot support the IAR compiler. Fail early with an explicit message instead of silently proceeding and getting strange errors. Issue: #18333 diff --git a/Modules/Compiler/IAR-ASM.cmake b/Modules/Compiler/IAR-ASM.cmake index 651bc3a..e12bfd1 100644 --- a/Modules/Compiler/IAR-ASM.cmake +++ b/Modules/Compiler/IAR-ASM.cmake @@ -18,4 +18,6 @@ elseif("${CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID}" STREQUAL "AVR") __compiler_iar_AVR(ASM) set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS s90;asm;msa) +else() + message(FATAL_ERROR "CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID not detected as \"AVR\" or \"ARM\". This should be automatic.") endif() diff --git a/Modules/Compiler/IAR-C.cmake b/Modules/Compiler/IAR-C.cmake index 55e019e..2ed8818 100644 --- a/Modules/Compiler/IAR-C.cmake +++ b/Modules/Compiler/IAR-C.cmake @@ -5,6 +5,9 @@ include(Compiler/CMakeCommonCompilerMacros) # The toolchains for ARM and AVR are quite different: if("${CMAKE_C_COMPILER_ARCHITECTURE_ID}" STREQUAL "ARM") + if(NOT CMAKE_C_COMPILER_VERSION) + message(FATAL_ERROR "CMAKE_C_COMPILER_VERSION not detected. This should be automatic.") + endif() set(CMAKE_C_EXTENSION_COMPILE_OPTION -e) @@ -40,4 +43,7 @@ elseif("${CMAKE_C_COMPILER_ARCHITECTURE_ID}" STREQUAL "AVR") get_filename_component(_compilerDir "${CMAKE_C_COMPILER}" PATH) get_filename_component(_compilerDir "${_compilerDir}" PATH) include_directories("${_compilerDir}/inc" ) + +else() + message(FATAL_ERROR "CMAKE_C_COMPILER_ARCHITECTURE_ID not detected as \"AVR\" or \"ARM\". This should be automatic.") endif() diff --git a/Modules/Compiler/IAR-CXX.cmake b/Modules/Compiler/IAR-CXX.cmake index 8d86100..5b783b2 100644 --- a/Modules/Compiler/IAR-CXX.cmake +++ b/Modules/Compiler/IAR-CXX.cmake @@ -10,6 +10,9 @@ if("${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}" STREQUAL "ARM") # # --c++ is full C++ and supported since 6.10 if(NOT CMAKE_IAR_CXX_FLAG) + if(NOT CMAKE_CXX_COMPILER_VERSION) + message(FATAL_ERROR "CMAKE_CXX_COMPILER_VERSION not detected. This should be automatic.") + endif() if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.10) set(CMAKE_IAR_CXX_FLAG --c++) else() @@ -48,4 +51,7 @@ elseif("${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}" STREQUAL "AVR") get_filename_component(_compilerDir "${CMAKE_C_COMPILER}" PATH) get_filename_component(_compilerDir "${_compilerDir}" PATH) include_directories("${_compilerDir}/inc") + +else() + message(FATAL_ERROR "CMAKE_CXX_COMPILER_ARCHITECTURE_ID not detected as \"AVR\" or \"ARM\". This should be automatic." ) endif() https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=6d8cabe8d40d09827d0353b7553a27d61ca60846 commit 6d8cabe8d40d09827d0353b7553a27d61ca60846 Author: Brian Heim AuthorDate: Sun Sep 2 00:20:57 2018 -0500 Commit: Brad King CommitDate: Mon Sep 10 08:28:44 2018 -0400 Help: Clarify INCLUDE_DIRECTORIES directory property behavior Ordering w.r.t. target creation is important for this property. Fixes: #17754 diff --git a/Help/prop_dir/INCLUDE_DIRECTORIES.rst b/Help/prop_dir/INCLUDE_DIRECTORIES.rst index 6789a56..5d856b8 100644 --- a/Help/prop_dir/INCLUDE_DIRECTORIES.rst +++ b/Help/prop_dir/INCLUDE_DIRECTORIES.rst @@ -11,11 +11,17 @@ target property, which is used by the generators to set the include directories for the compiler. In addition to accepting values from that command, values may be set -directly on any directory using the :command:`set_property` command. A -directory gets its initial value from its parent directory if it has one. -The initial value of the :prop_tgt:`INCLUDE_DIRECTORIES` target property +directly on any directory using the :command:`set_property` command, and can be +set on the current directory using the :command:`set_directory_properties` +command. A directory gets its initial value from its parent directory if it has +one. The initial value of the :prop_tgt:`INCLUDE_DIRECTORIES` target property comes from the value of this property. Both directory and target property values are adjusted by calls to the :command:`include_directories` command. +Calls to :command:`set_property` or :command:`set_directory_properties`, +however, will update the directory property value without updating target +property values. Therefore direct property updates must be made before +calls to :command:`add_executable` or :command:`add_library` for targets +they are meant to affect. The target property values are used by the generators to set the include paths for the compiler. https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=7b9d8ce168a707c0a9aa81e945eef82e231db9ba commit 7b9d8ce168a707c0a9aa81e945eef82e231db9ba Author: Brian Heim AuthorDate: Sun Sep 2 00:20:57 2018 -0500 Commit: Brad King CommitDate: Mon Sep 10 08:28:30 2018 -0400 Help: Clarify wording of set_directory_properties docs diff --git a/Help/command/set_directory_properties.rst b/Help/command/set_directory_properties.rst index e485fce..42e7fd7 100644 --- a/Help/command/set_directory_properties.rst +++ b/Help/command/set_directory_properties.rst @@ -1,12 +1,11 @@ set_directory_properties ------------------------ -Set a property of the directory. +Set properties of the current directory and subdirectories in key-value pairs. :: set_directory_properties(PROPERTIES prop1 value1 prop2 value2) -Set a property for the current directory and subdirectories. See -:ref:`Directory Properties` for the list of properties known -to CMake. +See :ref:`Directory Properties` for the list of properties known to CMake +and their individual documentation for the behavior of each property. https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=ab2e35d6144c6e666eb0cfffe144d2b93c72949b commit ab2e35d6144c6e666eb0cfffe144d2b93c72949b Author: Bartosz Kosiorek AuthorDate: Wed Sep 5 14:19:28 2018 +0200 Commit: Bartosz Kosiorek CommitDate: Mon Sep 10 13:34:09 2018 +0200 Replace occurrences of "Mac OS X" with "macOS" in comments Apple's main Operating system changed their name from OS X to macOS: https://www.engadget.com/2016/06/13/os-x-is-now-macos/ Revise source comments accordingly. diff --git a/Modules/FindBoost.cmake b/Modules/FindBoost.cmake index c14e402..9db141f 100644 --- a/Modules/FindBoost.cmake +++ b/Modules/FindBoost.cmake @@ -493,11 +493,11 @@ function(_Boost_GUESS_COMPILER_PREFIX _ret) if(Boost_MINOR_VERSION) if(${Boost_MINOR_VERSION} GREATER 35) # In Boost 1.36.0 and newer, the mangled compiler name used - # on Mac OS X/Darwin is "xgcc". + # on macOS/Darwin is "xgcc". set(_boost_COMPILER "-xgcc${_boost_COMPILER_VERSION}") else() # In Boost <= 1.35.0, there is no mangled compiler name for - # the Mac OS X/Darwin version of GCC. + # the macOS/Darwin version of GCC. set(_boost_COMPILER "") endif() else() diff --git a/Source/QtDialog/CMakeSetupDialog.cxx b/Source/QtDialog/CMakeSetupDialog.cxx index 5d589cc..3761bd3 100644 --- a/Source/QtDialog/CMakeSetupDialog.cxx +++ b/Source/QtDialog/CMakeSetupDialog.cxx @@ -108,7 +108,7 @@ CMakeSetupDialog::CMakeSetupDialog() QMenu* ToolsMenu = this->menuBar()->addMenu(tr("&Tools")); this->ConfigureAction = ToolsMenu->addAction(tr("&Configure")); - // prevent merging with Preferences menu item on Mac OS X + // prevent merging with Preferences menu item on macOS this->ConfigureAction->setMenuRole(QAction::NoRole); QObject::connect(this->ConfigureAction, SIGNAL(triggered(bool)), this, SLOT(doConfigure())); diff --git a/Source/QtDialog/QCMakeCacheView.cxx b/Source/QtDialog/QCMakeCacheView.cxx index 1b3fb15..7d3aa57 100644 --- a/Source/QtDialog/QCMakeCacheView.cxx +++ b/Source/QtDialog/QCMakeCacheView.cxx @@ -614,7 +614,7 @@ bool QCMakeCacheModelDelegate::editorEvent(QEvent* e, // Can remove this function and FileDialogFlag when minimum Qt version is 4.5 bool QCMakeCacheModelDelegate::eventFilter(QObject* object, QEvent* evt) { - // workaround for what looks like a bug in Qt on Mac OS X + // workaround for what looks like a bug in Qt on macOS // where it doesn't create a QWidget wrapper for the native file dialog // so the Qt library ends up assuming the focus was lost to something else diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx index 8d6efde..2107d32 100644 --- a/Source/cmComputeLinkInformation.cxx +++ b/Source/cmComputeLinkInformation.cxx @@ -30,7 +30,7 @@ Notes about linking on various platforms: ------------------------------------------------------------------------------ -Linux, FreeBSD, Mac OS X, IRIX, Sun, Windows: +Linux, FreeBSD, macOS, IRIX, Sun, Windows: Linking to libraries using the full path works fine. diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 532f9a9..f3f957e 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1345,7 +1345,7 @@ void cmLocalGenerator::AddArchitectureFlags(std::string& flags, const std::string& lang, const std::string& config) { - // Only add Mac OS X specific flags on Darwin platforms (OSX and iphone): + // Only add macOS specific flags on Darwin platforms (macOS and iOS): if (this->Makefile->IsOn("APPLE") && this->EmitUniversalBinaryFlags) { std::vector archs; target->GetAppleArchs(config, archs); diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index 27a42b3..58b7762 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -300,14 +300,14 @@ public: std::string const& GetCurrentSourceDirectory() const; /** - * Generate a Mac OS X application bundle Info.plist file. + * Generate a macOS application bundle Info.plist file. */ void GenerateAppleInfoPList(cmGeneratorTarget* target, const std::string& targetName, const char* fname); /** - * Generate a Mac OS X framework Info.plist file. + * Generate a macOS framework Info.plist file. */ void GenerateFrameworkInfoPList(cmGeneratorTarget* target, const std::string& targetName, diff --git a/Source/cmMakefileTargetGenerator.h b/Source/cmMakefileTargetGenerator.h index f21362a..529b4db 100644 --- a/Source/cmMakefileTargetGenerator.h +++ b/Source/cmMakefileTargetGenerator.h @@ -71,7 +71,7 @@ protected: // write the depend rules for this target void WriteTargetDependRules(); - // write rules for Mac OS X Application Bundle content. + // write rules for macOS Application Bundle content. struct MacOSXContentGeneratorType : cmOSXBundleGenerator::MacOSXContentGeneratorType { @@ -237,7 +237,7 @@ protected: std::string TargetNameImport; std::string TargetNamePDB; - // Mac OS X content info. + // macOS content info. std::set MacContentFolders; cmOSXBundleGenerator* OSXBundleGenerator; MacOSXContentGeneratorType* MacOSXContentGenerator; diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h index e58a8a0..373c693 100644 --- a/Source/cmNinjaTargetGenerator.h +++ b/Source/cmNinjaTargetGenerator.h @@ -135,7 +135,7 @@ protected: void EnsureDirectoryExists(const std::string& dir) const; void EnsureParentDirectoryExists(const std::string& path) const; - // write rules for Mac OS X Application Bundle content. + // write rules for macOS Application Bundle content. struct MacOSXContentGeneratorType : cmOSXBundleGenerator::MacOSXContentGeneratorType { https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=fc1602456abf04f301a8fcd9ac71fd0975c6bbde commit fc1602456abf04f301a8fcd9ac71fd0975c6bbde Author: Bartosz Kosiorek AuthorDate: Wed Sep 5 14:19:28 2018 +0200 Commit: Brad King CommitDate: Wed Sep 5 16:10:49 2018 -0400 Help: Replace occurrences of "Mac OS X" with "macOS" Apple's main Operating system changed their name from OS X to macOS: https://www.engadget.com/2016/06/13/os-x-is-now-macos/ Revise documentation accordingly. diff --git a/Help/command/FIND_XXX.txt b/Help/command/FIND_XXX.txt index 38c231a..73dbd57 100644 --- a/Help/command/FIND_XXX.txt +++ b/Help/command/FIND_XXX.txt @@ -137,7 +137,7 @@ If ``NO_DEFAULT_PATH`` is not specified, the search process is as follows: .. |FIND_ARGS_XXX| replace:: NAMES name -On OS X the :variable:`CMAKE_FIND_FRAMEWORK` and +On macOS the :variable:`CMAKE_FIND_FRAMEWORK` and :variable:`CMAKE_FIND_APPBUNDLE` variables determine the order of preference between Apple-style and unix-style package components. diff --git a/Help/command/add_library.rst b/Help/command/add_library.rst index b7ba724..c4c512c 100644 --- a/Help/command/add_library.rst +++ b/Help/command/add_library.rst @@ -35,7 +35,7 @@ variable :variable:`BUILD_SHARED_LIBS` is ``ON``. For ``SHARED`` and ``MODULE`` libraries the :prop_tgt:`POSITION_INDEPENDENT_CODE` target property is set to ``ON`` automatically. A ``SHARED`` or ``STATIC`` library may be marked with the :prop_tgt:`FRAMEWORK` -target property to create an OS X Framework. +target property to create an macOS Framework. If a library does not export any symbols, it must not be declared as a ``SHARED`` library. For example, a Windows resource DLL or a managed C++/CLI diff --git a/Help/command/find_package.rst b/Help/command/find_package.rst index bbe8c4d..b486b79 100644 --- a/Help/command/find_package.rst +++ b/Help/command/find_package.rst @@ -216,7 +216,7 @@ Each entry is meant for installation trees following Windows (W), UNIX /*/(lib/|lib*|share)/*/ (W/U) /*/(lib/|lib*|share)/*/(cmake|CMake)/ (W/U) -On systems supporting OS X Frameworks and Application Bundles the +On systems supporting macOS Frameworks and Application Bundles the following directories are searched for frameworks or bundles containing a configuration file:: diff --git a/Help/command/install.rst b/Help/command/install.rst index 8b2a971..3a2b4da 100644 --- a/Help/command/install.rst +++ b/Help/command/install.rst @@ -115,19 +115,19 @@ project. There are several kinds of target files that may be installed: ``ARCHIVE`` Static libraries are treated as ``ARCHIVE`` targets, except those - marked with the ``FRAMEWORK`` property on OS X (see ``FRAMEWORK`` + marked with the ``FRAMEWORK`` property on macOS (see ``FRAMEWORK`` below.) For DLL platforms (all Windows-based systems including Cygwin), the DLL import library is treated as an ``ARCHIVE`` target. ``LIBRARY`` Module libraries are always treated as ``LIBRARY`` targets. For non- DLL platforms shared libraries are treated as ``LIBRARY`` targets, - except those marked with the ``FRAMEWORK`` property on OS X (see + except those marked with the ``FRAMEWORK`` property on macOS (see ``FRAMEWORK`` below.) ``RUNTIME`` Executables are treated as ``RUNTIME`` objects, except those marked - with the ``MACOSX_BUNDLE`` property on OS X (see ``BUNDLE`` below.) + with the ``MACOSX_BUNDLE`` property on macOS (see ``BUNDLE`` below.) For DLL platforms (all Windows-based systems including Cygwin), the DLL part of a shared library is treated as a ``RUNTIME`` target. @@ -137,11 +137,11 @@ project. There are several kinds of target files that may be installed: ``FRAMEWORK`` Both static and shared libraries marked with the ``FRAMEWORK`` - property are treated as ``FRAMEWORK`` targets on OS X. + property are treated as ``FRAMEWORK`` targets on macOS. ``BUNDLE`` Executables marked with the ``MACOSX_BUNDLE`` property are treated as - ``BUNDLE`` targets on OS X. + ``BUNDLE`` targets on macOS. ``PUBLIC_HEADER`` Any ``PUBLIC_HEADER`` files associated with a library are installed in diff --git a/Help/cpack_gen/bundle.rst b/Help/cpack_gen/bundle.rst index 4628968..29727e2 100644 --- a/Help/cpack_gen/bundle.rst +++ b/Help/cpack_gen/bundle.rst @@ -1,14 +1,14 @@ CPack Bundle Generator ---------------------- -CPack Bundle generator (Mac OS X) specific options +CPack Bundle generator (macOS) specific options Variables specific to CPack Bundle generator ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Installers built on Mac OS X using the Bundle generator use the -aforementioned DragNDrop (CPACK_DMG_xxx) variables, plus the following -Bundle-specific parameters (CPACK_BUNDLE_xxx). +Installers built on macOS using the Bundle generator use the +aforementioned DragNDrop (``CPACK_DMG_xxx``) variables, plus the following +Bundle-specific parameters (``CPACK_BUNDLE_xxx``). .. variable:: CPACK_BUNDLE_NAME @@ -25,7 +25,7 @@ Bundle-specific parameters (CPACK_BUNDLE_xxx). Path to an OSX icon file that will be used as the icon for the generated bundle. This is the icon that appears in the OSX finder for the bundle, and - in the OSX dock when the bundle is opened. Required. + in the OSX dock when the bundle is opened. Required. .. variable:: CPACK_BUNDLE_STARTUP_COMMAND @@ -36,13 +36,13 @@ Bundle-specific parameters (CPACK_BUNDLE_xxx). .. variable:: CPACK_BUNDLE_APPLE_CERT_APP The name of your Apple supplied code signing certificate for the application. - The name usually takes the form "Developer ID Application: [Name]" or - "3rd Party Mac Developer Application: [Name]". If this variable is not set + The name usually takes the form ``Developer ID Application: [Name]`` or + ``3rd Party Mac Developer Application: [Name]``. If this variable is not set the application will not be signed. .. variable:: CPACK_BUNDLE_APPLE_ENTITLEMENTS - The name of the plist file that contains your apple entitlements for sandboxing + The name of the ``Plist`` file that contains your apple entitlements for sandboxing your application. This file is required for submission to the Mac App Store. .. variable:: CPACK_BUNDLE_APPLE_CODESIGN_FILES @@ -53,12 +53,12 @@ Bundle-specific parameters (CPACK_BUNDLE_xxx). .. variable:: CPACK_BUNDLE_APPLE_CODESIGN_PARAMETER - Additional parameter that will passed to codesign. - Default value: "--deep -f" + Additional parameter that will passed to ``codesign``. + Default value: ``--deep -f`` .. variable:: CPACK_COMMAND_CODESIGN - Path to the codesign(1) command used to sign applications with an + Path to the ``codesign(1)`` command used to sign applications with an Apple cert. This variable can be used to override the automatically detected command (or specify its location if the auto-detection fails - to find it.) + to find it). diff --git a/Help/cpack_gen/dmg.rst b/Help/cpack_gen/dmg.rst index e4482ef..b7b3a0a 100644 --- a/Help/cpack_gen/dmg.rst +++ b/Help/cpack_gen/dmg.rst @@ -1,13 +1,13 @@ CPack DMG Generator ------------------- -DragNDrop CPack generator (Mac OS X). +DragNDrop CPack generator (macOS). Variables specific to CPack DragNDrop generator ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The following variables are specific to the DragNDrop installers built -on Mac OS X: +on macOS: .. variable:: CPACK_DMG_VOLUME_NAME @@ -16,33 +16,33 @@ on Mac OS X: .. variable:: CPACK_DMG_FORMAT - The disk image format. Common values are UDRO (UDIF read-only), UDZO (UDIF - zlib-compressed) or UDBZ (UDIF bzip2-compressed). Refer to hdiutil(1) for - more information on other available formats. Defaults to UDZO. + The disk image format. Common values are ``UDRO`` (UDIF read-only), ``UDZO`` (UDIF + zlib-compressed) or ``UDBZ`` (UDIF bzip2-compressed). Refer to ``hdiutil(1)`` for + more information on other available formats. Defaults to ``UDZO``. .. variable:: CPACK_DMG_DS_STORE - Path to a custom DS_Store file. This .DS_Store file e.g. can be used to + Path to a custom ``.DS_Store`` file. This ``.DS_Store`` file can be used to specify the Finder window position/geometry and layout (such as hidden toolbars, placement of the icons etc.). This file has to be generated by the Finder (either manually or through AppleScript) using a normal folder - from which the .DS_Store file can then be extracted. + from which the ``.DS_Store`` file can then be extracted. .. variable:: CPACK_DMG_DS_STORE_SETUP_SCRIPT Path to a custom AppleScript file. This AppleScript is used to generate - a .DS_Store file which specifies the Finder window position/geometry and + a ``.DS_Store`` file which specifies the Finder window position/geometry and layout (such as hidden toolbars, placement of the icons etc.). By specifying a custom AppleScript there is no need to use - CPACK_DMG_DS_STORE, as the .DS_Store that is generated by the AppleScript + ``CPACK_DMG_DS_STORE``, as the ``.DS_Store`` that is generated by the AppleScript will be packaged. .. variable:: CPACK_DMG_BACKGROUND_IMAGE Path to an image file to be used as the background. This file will be - copied to .background/background., where ext is the original image file + copied to ``.background``/``background.``, where ```` is the original image file extension. The background image is installed into the image before - CPACK_DMG_DS_STORE_SETUP_SCRIPT is executed or CPACK_DMG_DS_STORE is + ``CPACK_DMG_DS_STORE_SETUP_SCRIPT`` is executed or ``CPACK_DMG_DS_STORE`` is installed. By default no background image is set. .. variable:: CPACK_DMG_DISABLE_APPLICATIONS_SYMLINK @@ -83,19 +83,19 @@ on Mac OS X: .. variable:: CPACK_COMMAND_HDIUTIL - Path to the hdiutil(1) command used to operate on disk image files on Mac - OS X. This variable can be used to override the automatically detected - command (or specify its location if the auto-detection fails to find it.) + Path to the ``hdiutil(1)`` command used to operate on disk image files on + macOS. This variable can be used to override the automatically detected + command (or specify its location if the auto-detection fails to find it). .. variable:: CPACK_COMMAND_SETFILE - Path to the SetFile(1) command used to set extended attributes on files and - directories on Mac OS X. This variable can be used to override the + Path to the ``SetFile(1)`` command used to set extended attributes on files and + directories on macOS. This variable can be used to override the automatically detected command (or specify its location if the - auto-detection fails to find it.) + auto-detection fails to find it). .. variable:: CPACK_COMMAND_REZ - Path to the Rez(1) command used to compile resources on Mac OS X. This + Path to the ``Rez(1)`` command used to compile resources on macOS. This variable can be used to override the automatically detected command (or - specify its location if the auto-detection fails to find it.) + specify its location if the auto-detection fails to find it). diff --git a/Help/cpack_gen/ifw.rst b/Help/cpack_gen/ifw.rst index 68776e1..e43b1d6 100644 --- a/Help/cpack_gen/ifw.rst +++ b/Help/cpack_gen/ifw.rst @@ -17,7 +17,7 @@ and meta information for QtIFW_ tools. The QtIFW_ provides a set of tools and utilities to create installers for the supported desktop Qt platforms: Linux, Microsoft Windows, -and Mac OS X. +and macOS. You should also install QtIFW_ to use CPack ``IFW`` generator. @@ -107,7 +107,7 @@ Package .. variable:: CPACK_IFW_PACKAGE_ICON - Filename for a custom installer icon. The actual file is '.icns' (Mac OS X), + Filename for a custom installer icon. The actual file is '.icns' (macOS), '.ico' (Windows). No functionality on Unix. .. variable:: CPACK_IFW_PACKAGE_WINDOW_ICON diff --git a/Help/cpack_gen/packagemaker.rst b/Help/cpack_gen/packagemaker.rst index f9abdd8..e9464b7 100644 --- a/Help/cpack_gen/packagemaker.rst +++ b/Help/cpack_gen/packagemaker.rst @@ -1,23 +1,23 @@ CPack PackageMaker Generator ---------------------------- -PackageMaker CPack generator (Mac OS X). +PackageMaker CPack generator (macOS). Variables specific to CPack PackageMaker generator ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The following variable is specific to installers built on Mac -OS X using PackageMaker: +macOS using PackageMaker: .. variable:: CPACK_OSX_PACKAGE_VERSION - The version of Mac OS X that the resulting PackageMaker archive should be - compatible with. Different versions of Mac OS X support different + The version of macOS that the resulting PackageMaker archive should be + compatible with. Different versions of macOS support different features. For example, CPack can only build component-based installers for - Mac OS X 10.4 or newer, and can only build installers that download - component son-the-fly for Mac OS X 10.5 or newer. If left blank, this value - will be set to the minimum version of Mac OS X that supports the requested + macOS 10.4 or newer, and can only build installers that download + component son-the-fly for macOS 10.5 or newer. If left blank, this value + will be set to the minimum version of macOS that supports the requested features. Set this variable to some value (e.g., 10.4) only if you want to - guarantee that your installer will work on that version of Mac OS X, and + guarantee that your installer will work on that version of macOS, and don't mind missing extra features available in the installer shipping with - later versions of Mac OS X. + later versions of macOS. diff --git a/Help/cpack_gen/productbuild.rst b/Help/cpack_gen/productbuild.rst index 1a6e0f8..d22fcd4 100644 --- a/Help/cpack_gen/productbuild.rst +++ b/Help/cpack_gen/productbuild.rst @@ -1,20 +1,20 @@ CPack productbuild Generator ---------------------------- -productbuild CPack generator (Mac OS X). +productbuild CPack generator (macOS). Variables specific to CPack productbuild generator ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The following variable is specific to installers built on Mac -OS X using ProductBuild: +macOS using ProductBuild: .. variable:: CPACK_COMMAND_PRODUCTBUILD - Path to the productbuild(1) command used to generate a product archive for - the OS X Installer or Mac App Store. This variable can be used to override + Path to the ``productbuild(1)`` command used to generate a product archive for + the macOS Installer or Mac App Store. This variable can be used to override the automatically detected command (or specify its location if the - auto-detection fails to find it.) + auto-detection fails to find it). .. variable:: CPACK_PRODUCTBUILD_IDENTITY_NAME @@ -28,9 +28,9 @@ OS X using ProductBuild: .. variable:: CPACK_COMMAND_PKGBUILD - Path to the pkgbuild(1) command used to generate an OS X component package - on OS X. This variable can be used to override the automatically detected - command (or specify its location if the auto-detection fails to find it.) + Path to the ``pkgbuild(1)`` command used to generate an macOS component package + on macOS. This variable can be used to override the automatically detected + command (or specify its location if the auto-detection fails to find it). .. variable:: CPACK_PKGBUILD_IDENTITY_NAME diff --git a/Help/envvar/CMAKE_OSX_ARCHITECTURES.rst b/Help/envvar/CMAKE_OSX_ARCHITECTURES.rst index 8bbf993..5fd6e52 100644 --- a/Help/envvar/CMAKE_OSX_ARCHITECTURES.rst +++ b/Help/envvar/CMAKE_OSX_ARCHITECTURES.rst @@ -1,7 +1,7 @@ CMAKE_OSX_ARCHITECTURES ----------------------- -Target specific architectures for OS X. +Target specific architectures for macOS. The ``CMAKE_OSX_ARCHITECTURES`` environment variable sets the default value for the :variable:`CMAKE_OSX_ARCHITECTURES` variable. See diff --git a/Help/envvar/MACOSX_DEPLOYMENT_TARGET.rst b/Help/envvar/MACOSX_DEPLOYMENT_TARGET.rst index e6051b4..9dafa32 100644 --- a/Help/envvar/MACOSX_DEPLOYMENT_TARGET.rst +++ b/Help/envvar/MACOSX_DEPLOYMENT_TARGET.rst @@ -1,7 +1,7 @@ MACOSX_DEPLOYMENT_TARGET ------------------------ -Specify the minimum version of OS X on which the target binaries are +Specify the minimum version of macOS on which the target binaries are to be deployed. The ``MACOSX_DEPLOYMENT_TARGET`` environment variable sets the default value for diff --git a/Help/manual/cmake-buildsystem.7.rst b/Help/manual/cmake-buildsystem.7.rst index dd7934a..4fc484b 100644 --- a/Help/manual/cmake-buildsystem.7.rst +++ b/Help/manual/cmake-buildsystem.7.rst @@ -95,7 +95,7 @@ Apple Frameworks """""""""""""""" A ``SHARED`` library may be marked with the :prop_tgt:`FRAMEWORK` -target property to create an OS X or iOS Framework Bundle. +target property to create an macOS or iOS Framework Bundle. The ``MACOSX_FRAMEWORK_IDENTIFIER`` sets ``CFBundleIdentifier`` key and it uniquely identifies the bundle. diff --git a/Help/prop_sf/MACOSX_PACKAGE_LOCATION.rst b/Help/prop_sf/MACOSX_PACKAGE_LOCATION.rst index a064afa..d185d91 100644 --- a/Help/prop_sf/MACOSX_PACKAGE_LOCATION.rst +++ b/Help/prop_sf/MACOSX_PACKAGE_LOCATION.rst @@ -3,19 +3,19 @@ MACOSX_PACKAGE_LOCATION Place a source file inside a Application Bundle (:prop_tgt:`MACOSX_BUNDLE`), Core Foundation Bundle (:prop_tgt:`BUNDLE`), -or Framework Bundle (:prop_tgt:`FRAMEWORK`). It is applicable for OS X +or Framework Bundle (:prop_tgt:`FRAMEWORK`). It is applicable for macOS and iOS. Executable targets with the :prop_tgt:`MACOSX_BUNDLE` property set are -built as OS X or iOS application bundles on Apple platforms. Shared +built as macOS or iOS application bundles on Apple platforms. Shared library targets with the :prop_tgt:`FRAMEWORK` property set are built as -OS X or iOS frameworks on Apple platforms. Module library targets with -the :prop_tgt:`BUNDLE` property set are built as OS X ``CFBundle`` bundles +macOS or iOS frameworks on Apple platforms. Module library targets with +the :prop_tgt:`BUNDLE` property set are built as macOS ``CFBundle`` bundles on Apple platforms. Source files listed in the target with this property set will be copied to a directory inside the bundle or framework content -folder specified by the property value. For OS X Application Bundles the -content folder is ``.app/Contents``. For OS X Frameworks the -content folder is ``.framework/Versions/``. For OS X +folder specified by the property value. For macOS Application Bundles the +content folder is ``.app/Contents``. For macOS Frameworks the +content folder is ``.framework/Versions/``. For macOS CFBundles the content folder is ``.bundle/Contents`` (unless the extension is changed). See the :prop_tgt:`PUBLIC_HEADER`, :prop_tgt:`PRIVATE_HEADER`, and :prop_tgt:`RESOURCE` target properties for diff --git a/Help/prop_tgt/BUNDLE.rst b/Help/prop_tgt/BUNDLE.rst index 075f017..c556ac3 100644 --- a/Help/prop_tgt/BUNDLE.rst +++ b/Help/prop_tgt/BUNDLE.rst @@ -1,7 +1,7 @@ BUNDLE ------ -This target is a ``CFBundle`` on the OS X. +This target is a ``CFBundle`` on the macOS. If a module library target has this property set to true it will be built as a ``CFBundle`` when built on the mac. It will have the directory diff --git a/Help/prop_tgt/BUNDLE_EXTENSION.rst b/Help/prop_tgt/BUNDLE_EXTENSION.rst index 6b3d580..70de11c 100644 --- a/Help/prop_tgt/BUNDLE_EXTENSION.rst +++ b/Help/prop_tgt/BUNDLE_EXTENSION.rst @@ -2,7 +2,7 @@ BUNDLE_EXTENSION ---------------- The file extension used to name a :prop_tgt:`BUNDLE`, a :prop_tgt:`FRAMEWORK`, -or a :prop_tgt:`MACOSX_BUNDLE` target on the OS X and iOS. +or a :prop_tgt:`MACOSX_BUNDLE` target on the macOS and iOS. The default value is ``bundle``, ``framework``, or ``app`` for the respective target types. diff --git a/Help/prop_tgt/ENABLE_EXPORTS.rst b/Help/prop_tgt/ENABLE_EXPORTS.rst index 9e22309..581c2b9 100644 --- a/Help/prop_tgt/ENABLE_EXPORTS.rst +++ b/Help/prop_tgt/ENABLE_EXPORTS.rst @@ -12,7 +12,7 @@ dependency on the executable is created for targets that link to it. For DLL platforms an import library will be created for the exported symbols and then used for linking. All Windows-based systems including Cygwin are DLL platforms. For non-DLL platforms that -require all symbols to be resolved at link time, such as OS X, the +require all symbols to be resolved at link time, such as macOS, the module will "link" to the executable using a flag like ``-bundle_loader``. For other non-DLL platforms the link rule is simply ignored since the dynamic loader will automatically bind symbols when diff --git a/Help/prop_tgt/FRAMEWORK.rst b/Help/prop_tgt/FRAMEWORK.rst index 495d30e..9dad060 100644 --- a/Help/prop_tgt/FRAMEWORK.rst +++ b/Help/prop_tgt/FRAMEWORK.rst @@ -1,17 +1,17 @@ FRAMEWORK --------- -Build ``SHARED`` or ``STATIC`` library as Framework Bundle on the OS X and iOS. +Build ``SHARED`` or ``STATIC`` library as Framework Bundle on the macOS and iOS. If such a library target has this property set to ``TRUE`` it will be -built as a framework when built on the OS X and iOS. It will have the +built as a framework when built on the macOS and iOS. It will have the directory structure required for a framework and will be suitable to be used with the ``-framework`` option To customize ``Info.plist`` file in the framework, use :prop_tgt:`MACOSX_FRAMEWORK_INFO_PLIST` target property. -For OS X see also the :prop_tgt:`FRAMEWORK_VERSION` target property. +For macOS see also the :prop_tgt:`FRAMEWORK_VERSION` target property. Example of creation ``dynamicFramework``: diff --git a/Help/prop_tgt/FRAMEWORK_VERSION.rst b/Help/prop_tgt/FRAMEWORK_VERSION.rst index 6aa3026..c2ae7b9 100644 --- a/Help/prop_tgt/FRAMEWORK_VERSION.rst +++ b/Help/prop_tgt/FRAMEWORK_VERSION.rst @@ -4,5 +4,5 @@ FRAMEWORK_VERSION Version of a framework created using the :prop_tgt:`FRAMEWORK` target property (e.g. ``A``). -This property only affects OS X, as iOS doesn't have versioned +This property only affects macOS, as iOS doesn't have versioned directory structure. diff --git a/Help/prop_tgt/IMPORTED_LOCATION.rst b/Help/prop_tgt/IMPORTED_LOCATION.rst index 8cfef73..2d07aad 100644 --- a/Help/prop_tgt/IMPORTED_LOCATION.rst +++ b/Help/prop_tgt/IMPORTED_LOCATION.rst @@ -5,11 +5,11 @@ Full path to the main file on disk for an IMPORTED target. Set this to the location of an IMPORTED target file on disk. For executables this is the location of the executable file. For bundles -on OS X this is the location of the executable file inside +on macOS this is the location of the executable file inside Contents/MacOS under the application bundle folder. For static libraries and modules this is the location of the library or module. For shared libraries on non-DLL platforms this is the location of the -shared library. For frameworks on OS X this is the location of the +shared library. For frameworks on macOS this is the location of the library file symlink just inside the framework folder. For DLLs this is the location of the ".dll" part of the library. For UNKNOWN libraries this is the location of the file to be linked. Ignored for diff --git a/Help/prop_tgt/MACOSX_BUNDLE.rst b/Help/prop_tgt/MACOSX_BUNDLE.rst index f9e11ee..92bce53 100644 --- a/Help/prop_tgt/MACOSX_BUNDLE.rst +++ b/Help/prop_tgt/MACOSX_BUNDLE.rst @@ -1,9 +1,9 @@ MACOSX_BUNDLE ------------- -Build an executable as an Application Bundle on OS X or iOS. +Build an executable as an Application Bundle on macOS or iOS. -When this property is set to ``TRUE`` the executable when built on OS X +When this property is set to ``TRUE`` the executable when built on macOS or iOS will be created as an application bundle. This makes it a GUI executable that can be launched from the Finder. See the :prop_tgt:`MACOSX_BUNDLE_INFO_PLIST` target property for information about diff --git a/Help/prop_tgt/MACOSX_BUNDLE_INFO_PLIST.rst b/Help/prop_tgt/MACOSX_BUNDLE_INFO_PLIST.rst index 8515acc..443a645 100644 --- a/Help/prop_tgt/MACOSX_BUNDLE_INFO_PLIST.rst +++ b/Help/prop_tgt/MACOSX_BUNDLE_INFO_PLIST.rst @@ -1,10 +1,10 @@ MACOSX_BUNDLE_INFO_PLIST ------------------------ -Specify a custom ``Info.plist`` template for a OS X and iOS Application Bundle. +Specify a custom ``Info.plist`` template for a macOS and iOS Application Bundle. An executable target with :prop_tgt:`MACOSX_BUNDLE` enabled will be built as an -application bundle on OS X. By default its ``Info.plist`` file is created +application bundle on macOS. By default its ``Info.plist`` file is created by configuring a template called ``MacOSXBundleInfo.plist.in`` located in the :variable:`CMAKE_MODULE_PATH`. This property specifies an alternative template file name which may be a full path. diff --git a/Help/prop_tgt/MACOSX_FRAMEWORK_INFO_PLIST.rst b/Help/prop_tgt/MACOSX_FRAMEWORK_INFO_PLIST.rst index 58f31d4..82fdcc0 100644 --- a/Help/prop_tgt/MACOSX_FRAMEWORK_INFO_PLIST.rst +++ b/Help/prop_tgt/MACOSX_FRAMEWORK_INFO_PLIST.rst @@ -1,10 +1,10 @@ MACOSX_FRAMEWORK_INFO_PLIST --------------------------- -Specify a custom ``Info.plist`` template for a OS X and iOS Framework. +Specify a custom ``Info.plist`` template for a macOS and iOS Framework. A library target with :prop_tgt:`FRAMEWORK` enabled will be built as a -framework on OS X. By default its ``Info.plist`` file is created by +framework on macOS. By default its ``Info.plist`` file is created by configuring a template called ``MacOSXFrameworkInfo.plist.in`` located in the :variable:`CMAKE_MODULE_PATH`. This property specifies an alternative template file name which may be a full path. diff --git a/Help/prop_tgt/MACOSX_RPATH.rst b/Help/prop_tgt/MACOSX_RPATH.rst index 1f9a036..acd5a7a 100644 --- a/Help/prop_tgt/MACOSX_RPATH.rst +++ b/Help/prop_tgt/MACOSX_RPATH.rst @@ -1,7 +1,7 @@ MACOSX_RPATH ------------ -Whether this target on OS X or iOS is located at runtime using rpaths. +Whether this target on macOS or iOS is located at runtime using rpaths. When this property is set to ``TRUE``, the directory portion of the ``install_name`` field of this shared library will be ``@rpath`` diff --git a/Help/prop_tgt/OSX_ARCHITECTURES.rst b/Help/prop_tgt/OSX_ARCHITECTURES.rst index cefe03f..996a4be 100644 --- a/Help/prop_tgt/OSX_ARCHITECTURES.rst +++ b/Help/prop_tgt/OSX_ARCHITECTURES.rst @@ -1,10 +1,10 @@ OSX_ARCHITECTURES ----------------- -Target specific architectures for OS X. +Target specific architectures for macOS. The ``OSX_ARCHITECTURES`` property sets the target binary architecture for -targets on OS X (``-arch``). This property is initialized by the value of the +targets on macOS (``-arch``). This property is initialized by the value of the variable :variable:`CMAKE_OSX_ARCHITECTURES` if it is set when a target is created. Use :prop_tgt:`OSX_ARCHITECTURES_` to set the binary architectures on a per-configuration basis, where ```` is an diff --git a/Help/prop_tgt/OSX_ARCHITECTURES_CONFIG.rst b/Help/prop_tgt/OSX_ARCHITECTURES_CONFIG.rst index fb78177..06da4fb 100644 --- a/Help/prop_tgt/OSX_ARCHITECTURES_CONFIG.rst +++ b/Help/prop_tgt/OSX_ARCHITECTURES_CONFIG.rst @@ -1,7 +1,7 @@ OSX_ARCHITECTURES_ -------------------------- -Per-configuration OS X and iOS binary architectures for a target. +Per-configuration macOS and iOS binary architectures for a target. This property is the configuration-specific version of :prop_tgt:`OSX_ARCHITECTURES`. diff --git a/Help/prop_tgt/PRIVATE_HEADER.rst b/Help/prop_tgt/PRIVATE_HEADER.rst index c4412ed..2bd4079 100644 --- a/Help/prop_tgt/PRIVATE_HEADER.rst +++ b/Help/prop_tgt/PRIVATE_HEADER.rst @@ -4,7 +4,7 @@ PRIVATE_HEADER Specify private header files in a :prop_tgt:`FRAMEWORK` shared library target. Shared library targets marked with the :prop_tgt:`FRAMEWORK` property generate -frameworks on OS X, iOS and normal shared libraries on other platforms. +frameworks on macOS, iOS and normal shared libraries on other platforms. This property may be set to a list of header files to be placed in the PrivateHeaders directory inside the framework folder. On non-Apple platforms these headers may be installed using the ``PRIVATE_HEADER`` diff --git a/Help/prop_tgt/PUBLIC_HEADER.rst b/Help/prop_tgt/PUBLIC_HEADER.rst index d4a636c..549ac7c 100644 --- a/Help/prop_tgt/PUBLIC_HEADER.rst +++ b/Help/prop_tgt/PUBLIC_HEADER.rst @@ -4,7 +4,7 @@ PUBLIC_HEADER Specify public header files in a :prop_tgt:`FRAMEWORK` shared library target. Shared library targets marked with the :prop_tgt:`FRAMEWORK` property generate -frameworks on OS X, iOS and normal shared libraries on other platforms. +frameworks on macOS, iOS and normal shared libraries on other platforms. This property may be set to a list of header files to be placed in the ``Headers`` directory inside the framework folder. On non-Apple platforms these headers may be installed using the ``PUBLIC_HEADER`` option to the diff --git a/Help/prop_tgt/RESOURCE.rst b/Help/prop_tgt/RESOURCE.rst index d837f7b..55ae774 100644 --- a/Help/prop_tgt/RESOURCE.rst +++ b/Help/prop_tgt/RESOURCE.rst @@ -4,10 +4,10 @@ RESOURCE Specify resource files in a :prop_tgt:`FRAMEWORK` or :prop_tgt:`BUNDLE`. Target marked with the :prop_tgt:`FRAMEWORK` or :prop_tgt:`BUNDLE` property -generate framework or application bundle (both OS X and iOS is supported) +generate framework or application bundle (both macOS and iOS is supported) or normal shared libraries on other platforms. This property may be set to a list of files to be placed in the corresponding -directory (eg. ``Resources`` directory for OS X) inside the bundle. +directory (eg. ``Resources`` directory for macOS) inside the bundle. On non-Apple platforms these files may be installed using the ``RESOURCE`` option to the ``install(TARGETS)`` command. @@ -42,7 +42,7 @@ will produce flat structure for iOS systems:: Info.plist resourcefile.txt -For OS X systems it will produce following directory structure:: +For macOS systems it will produce following directory structure:: ExecutableTarget.app/ Contents diff --git a/Help/prop_tgt/SOVERSION.rst b/Help/prop_tgt/SOVERSION.rst index 82b6b97..b07c17c 100644 --- a/Help/prop_tgt/SOVERSION.rst +++ b/Help/prop_tgt/SOVERSION.rst @@ -20,7 +20,7 @@ These numbers are used as the image version of the binary. Mach-O Versions ^^^^^^^^^^^^^^^ -For shared libraries and executables on Mach-O systems (e.g. OS X, iOS), +For shared libraries and executables on Mach-O systems (e.g. macOS, iOS), the ``SOVERSION`` property corresponds to *compatibility version* and :prop_tgt:`VERSION` to *current version*. See the :prop_tgt:`FRAMEWORK` target property for an example. Versions of Mach-O binaries may be checked with the diff --git a/Help/prop_tgt/VERSION.rst b/Help/prop_tgt/VERSION.rst index 66e7bde..ff3b303 100644 --- a/Help/prop_tgt/VERSION.rst +++ b/Help/prop_tgt/VERSION.rst @@ -22,7 +22,7 @@ These numbers are used as the image version of the binary. Mach-O Versions ^^^^^^^^^^^^^^^ -For shared libraries and executables on Mach-O systems (e.g. OS X, iOS), +For shared libraries and executables on Mach-O systems (e.g. macOS, iOS), the :prop_tgt:`SOVERSION` property correspond to *compatibility version* and ``VERSION`` to *current version*. See the :prop_tgt:`FRAMEWORK` target property for an example. Versions of Mach-O binaries may be checked with the diff --git a/Help/variable/CMAKE_APPBUNDLE_PATH.rst b/Help/variable/CMAKE_APPBUNDLE_PATH.rst index 2bc79ac..c1f0951 100644 --- a/Help/variable/CMAKE_APPBUNDLE_PATH.rst +++ b/Help/variable/CMAKE_APPBUNDLE_PATH.rst @@ -2,5 +2,5 @@ CMAKE_APPBUNDLE_PATH -------------------- :ref:`;-list ` of directories specifying a search path -for OS X application bundles used by the :command:`find_program`, and +for macOS application bundles used by the :command:`find_program`, and :command:`find_package` commands. diff --git a/Help/variable/CMAKE_ENABLE_EXPORTS.rst b/Help/variable/CMAKE_ENABLE_EXPORTS.rst index 9a877e7..7ec4d63 100644 --- a/Help/variable/CMAKE_ENABLE_EXPORTS.rst +++ b/Help/variable/CMAKE_ENABLE_EXPORTS.rst @@ -12,7 +12,7 @@ dependency on the executable is created for targets that link to it. For DLL platforms an import library will be created for the exported symbols and then used for linking. All Windows-based systems including Cygwin are DLL platforms. For non-DLL platforms that -require all symbols to be resolved at link time, such as OS X, the +require all symbols to be resolved at link time, such as macOS, the module will ``link`` to the executable using a flag like ``-bundle_loader``. For other non-DLL platforms the link rule is simply ignored since the dynamic loader will automatically bind symbols when diff --git a/Help/variable/CMAKE_FIND_APPBUNDLE.rst b/Help/variable/CMAKE_FIND_APPBUNDLE.rst index e0727b5..7a05fac 100644 --- a/Help/variable/CMAKE_FIND_APPBUNDLE.rst +++ b/Help/variable/CMAKE_FIND_APPBUNDLE.rst @@ -2,9 +2,9 @@ CMAKE_FIND_APPBUNDLE -------------------- This variable affects how ``find_*`` commands choose between -OS X Application Bundles and unix-style package components. +macOS Application Bundles and unix-style package components. -On Darwin or systems supporting OS X Application Bundles, the +On Darwin or systems supporting macOS Application Bundles, the ``CMAKE_FIND_APPBUNDLE`` variable can be set to empty or one of the following: diff --git a/Help/variable/CMAKE_FIND_FRAMEWORK.rst b/Help/variable/CMAKE_FIND_FRAMEWORK.rst index 790694a..4d5078f 100644 --- a/Help/variable/CMAKE_FIND_FRAMEWORK.rst +++ b/Help/variable/CMAKE_FIND_FRAMEWORK.rst @@ -2,9 +2,9 @@ CMAKE_FIND_FRAMEWORK -------------------- This variable affects how ``find_*`` commands choose between -OS X Frameworks and unix-style package components. +macOS Frameworks and unix-style package components. -On Darwin or systems supporting OS X Frameworks, the +On Darwin or systems supporting macOS Frameworks, the ``CMAKE_FIND_FRAMEWORK`` variable can be set to empty or one of the following: diff --git a/Help/variable/CMAKE_FRAMEWORK_PATH.rst b/Help/variable/CMAKE_FRAMEWORK_PATH.rst index 5ff08e6..04751f8 100644 --- a/Help/variable/CMAKE_FRAMEWORK_PATH.rst +++ b/Help/variable/CMAKE_FRAMEWORK_PATH.rst @@ -2,6 +2,6 @@ CMAKE_FRAMEWORK_PATH -------------------- :ref:`;-list ` of directories specifying a search path -for OS X frameworks used by the :command:`find_library`, +for macOS frameworks used by the :command:`find_library`, :command:`find_package`, :command:`find_path`, and :command:`find_file` commands. diff --git a/Help/variable/CMAKE_HOST_APPLE.rst b/Help/variable/CMAKE_HOST_APPLE.rst index ac7b030..9c205ec 100644 --- a/Help/variable/CMAKE_HOST_APPLE.rst +++ b/Help/variable/CMAKE_HOST_APPLE.rst @@ -1,6 +1,6 @@ CMAKE_HOST_APPLE ---------------- -``True`` for Apple OS X operating systems. +``True`` for Apple macOS operating systems. -Set to ``true`` when the host system is Apple OS X. +Set to ``true`` when the host system is Apple macOS. diff --git a/Help/variable/CMAKE_HOST_SYSTEM_NAME.rst b/Help/variable/CMAKE_HOST_SYSTEM_NAME.rst index c673592..e892677 100644 --- a/Help/variable/CMAKE_HOST_SYSTEM_NAME.rst +++ b/Help/variable/CMAKE_HOST_SYSTEM_NAME.rst @@ -4,5 +4,5 @@ CMAKE_HOST_SYSTEM_NAME Name of the OS CMake is running on. On systems that have the uname command, this variable is set to the -output of ``uname -s``. ``Linux``, ``Windows``, and ``Darwin`` for OS X +output of ``uname -s``. ``Linux``, ``Windows``, and ``Darwin`` for macOS are the values found on the big three operating systems. diff --git a/Help/variable/CMAKE_INSTALL_NAME_DIR.rst b/Help/variable/CMAKE_INSTALL_NAME_DIR.rst index 1f2d62b..5ba4c04 100644 --- a/Help/variable/CMAKE_INSTALL_NAME_DIR.rst +++ b/Help/variable/CMAKE_INSTALL_NAME_DIR.rst @@ -1,7 +1,7 @@ CMAKE_INSTALL_NAME_DIR ---------------------- -OS X directory name for installed targets. +macOS directory name for installed targets. ``CMAKE_INSTALL_NAME_DIR`` is used to initialize the :prop_tgt:`INSTALL_NAME_DIR` property on all targets. See that target diff --git a/Help/variable/CMAKE_MACOSX_RPATH.rst b/Help/variable/CMAKE_MACOSX_RPATH.rst index 042e807..2fc648d 100644 --- a/Help/variable/CMAKE_MACOSX_RPATH.rst +++ b/Help/variable/CMAKE_MACOSX_RPATH.rst @@ -1,7 +1,7 @@ CMAKE_MACOSX_RPATH ------------------- -Whether to use rpaths on OS X and iOS. +Whether to use rpaths on macOS and iOS. This variable is used to initialize the :prop_tgt:`MACOSX_RPATH` property on all targets. diff --git a/Help/variable/CMAKE_OSX_ARCHITECTURES.rst b/Help/variable/CMAKE_OSX_ARCHITECTURES.rst index 51b840d..fdaca28 100644 --- a/Help/variable/CMAKE_OSX_ARCHITECTURES.rst +++ b/Help/variable/CMAKE_OSX_ARCHITECTURES.rst @@ -1,7 +1,7 @@ CMAKE_OSX_ARCHITECTURES ----------------------- -Target specific architectures for OS X and iOS. +Target specific architectures for macOS and iOS. This variable is used to initialize the :prop_tgt:`OSX_ARCHITECTURES` property on each target as it is created. See that target property diff --git a/Help/variable/CMAKE_OSX_SYSROOT.rst b/Help/variable/CMAKE_OSX_SYSROOT.rst index f1d58c6..db9fccd 100644 --- a/Help/variable/CMAKE_OSX_SYSROOT.rst +++ b/Help/variable/CMAKE_OSX_SYSROOT.rst @@ -1,7 +1,7 @@ CMAKE_OSX_SYSROOT ----------------- -Specify the location or name of the OS X platform SDK to be used. +Specify the location or name of the macOS platform SDK to be used. CMake uses this value to compute the value of the ``-isysroot`` flag or equivalent and to help the ``find_*`` commands locate files in the SDK. diff --git a/Help/variable/CMAKE_SYSTEM_APPBUNDLE_PATH.rst b/Help/variable/CMAKE_SYSTEM_APPBUNDLE_PATH.rst index 3c6687c..666af46 100644 --- a/Help/variable/CMAKE_SYSTEM_APPBUNDLE_PATH.rst +++ b/Help/variable/CMAKE_SYSTEM_APPBUNDLE_PATH.rst @@ -1,7 +1,7 @@ CMAKE_SYSTEM_APPBUNDLE_PATH --------------------------- -Search path for OS X application bundles used by the :command:`find_program`, +Search path for macOS application bundles used by the :command:`find_program`, and :command:`find_package` commands. By default it contains the standard directories for the current system. It is *not* intended to be modified by the project, use :variable:`CMAKE_APPBUNDLE_PATH` for this. diff --git a/Help/variable/CMAKE_SYSTEM_FRAMEWORK_PATH.rst b/Help/variable/CMAKE_SYSTEM_FRAMEWORK_PATH.rst index 1e8b0d9..14ba18e 100644 --- a/Help/variable/CMAKE_SYSTEM_FRAMEWORK_PATH.rst +++ b/Help/variable/CMAKE_SYSTEM_FRAMEWORK_PATH.rst @@ -1,7 +1,7 @@ CMAKE_SYSTEM_FRAMEWORK_PATH --------------------------- -Search path for OS X frameworks used by the :command:`find_library`, +Search path for macOS frameworks used by the :command:`find_library`, :command:`find_package`, :command:`find_path`, and :command:`find_file` commands. By default it contains the standard directories for the current system. It is *not* intended to be modified by the project, diff --git a/Modules/CPack.cmake b/Modules/CPack.cmake index cdc38a6..f3e3423 100644 --- a/Modules/CPack.cmake +++ b/Modules/CPack.cmake @@ -19,7 +19,7 @@ command (and the deprecated :command:`install_files`, :command:`install_programs` and :command:`install_targets` commands). For certain kinds of binary installers (including the graphical -installers on Mac OS X and Windows), CPack generates installers that +installers on macOS and Windows), CPack generates installers that allow users to select individual application components to install. See :module:`CPackComponent` module for further details. diff --git a/Modules/CPackComponent.cmake b/Modules/CPackComponent.cmake index 6c122e5..a0d9935 100644 --- a/Modules/CPackComponent.cmake +++ b/Modules/CPackComponent.cmake @@ -14,7 +14,7 @@ # part of CPack. See CPack module for general information about CPack. # # For certain kinds of binary installers (including the graphical -# installers on Mac OS X and Windows), CPack generates installers that +# installers on macOS and Windows), CPack generates installers that # allow users to select individual application components to install. # The contents of each of the components are identified by the COMPONENT # argument of CMake's INSTALL command. These components can be @@ -283,8 +283,8 @@ # # # -# On Mac OS X, installers that download components on-the-fly can only -# be built and installed on system using Mac OS X 10.5 or later. +# On macOS, installers that download components on-the-fly can only +# be built and installed on system using macOS 10.5 or later. # # The site argument is a URL where the archives for downloadable # components will reside, e.g., diff --git a/Modules/ProcessorCount.cmake b/Modules/ProcessorCount.cmake index 772a615..8a37884 100644 --- a/Modules/ProcessorCount.cmake +++ b/Modules/ProcessorCount.cmake @@ -12,7 +12,7 @@ # Sets the variable named ${var} to the number of physical cores # available on the machine if the information can be determined. # Otherwise it is set to 0. Currently this functionality is implemented -# for AIX, cygwin, FreeBSD, HPUX, IRIX, Linux, Mac OS X, QNX, Sun and +# for AIX, cygwin, FreeBSD, HPUX, IRIX, Linux, macOS, QNX, Sun and # Windows. # # This function is guaranteed to return a positive integer (>=1) if it ----------------------------------------------------------------------- Summary of changes: Help/command/FIND_XXX.txt | 2 +- Help/command/add_library.rst | 2 +- Help/command/find_package.rst | 2 +- Help/command/install.rst | 10 +++---- Help/command/set_directory_properties.rst | 7 +++-- Help/cpack_gen/bundle.rst | 24 ++++++++--------- Help/cpack_gen/dmg.rst | 38 +++++++++++++-------------- Help/cpack_gen/ifw.rst | 4 +-- Help/cpack_gen/packagemaker.rst | 18 ++++++------- Help/cpack_gen/productbuild.rst | 16 +++++------ Help/envvar/CMAKE_OSX_ARCHITECTURES.rst | 2 +- Help/envvar/MACOSX_DEPLOYMENT_TARGET.rst | 2 +- Help/manual/cmake-buildsystem.7.rst | 2 +- Help/manual/cmake-variables.7.rst | 1 + Help/prop_dir/INCLUDE_DIRECTORIES.rst | 12 ++++++--- Help/prop_sf/MACOSX_PACKAGE_LOCATION.rst | 14 +++++----- Help/prop_tgt/BUNDLE.rst | 2 +- Help/prop_tgt/BUNDLE_EXTENSION.rst | 2 +- Help/prop_tgt/ENABLE_EXPORTS.rst | 2 +- Help/prop_tgt/FRAMEWORK.rst | 6 ++--- Help/prop_tgt/FRAMEWORK_VERSION.rst | 2 +- Help/prop_tgt/IMPORTED_LOCATION.rst | 4 +-- Help/prop_tgt/MACOSX_BUNDLE.rst | 4 +-- Help/prop_tgt/MACOSX_BUNDLE_INFO_PLIST.rst | 4 +-- Help/prop_tgt/MACOSX_FRAMEWORK_INFO_PLIST.rst | 4 +-- Help/prop_tgt/MACOSX_RPATH.rst | 2 +- Help/prop_tgt/OSX_ARCHITECTURES.rst | 4 +-- Help/prop_tgt/OSX_ARCHITECTURES_CONFIG.rst | 2 +- Help/prop_tgt/PRIVATE_HEADER.rst | 2 +- Help/prop_tgt/PUBLIC_HEADER.rst | 2 +- Help/prop_tgt/RESOURCE.rst | 6 ++--- Help/prop_tgt/SOVERSION.rst | 2 +- Help/prop_tgt/VERSION.rst | 2 +- Help/variable/CMAKE_APPBUNDLE_PATH.rst | 2 +- Help/variable/CMAKE_CPACK_COMMAND.rst | 8 ++++++ Help/variable/CMAKE_ENABLE_EXPORTS.rst | 2 +- Help/variable/CMAKE_FIND_APPBUNDLE.rst | 4 +-- Help/variable/CMAKE_FIND_FRAMEWORK.rst | 4 +-- Help/variable/CMAKE_FRAMEWORK_PATH.rst | 2 +- Help/variable/CMAKE_HOST_APPLE.rst | 4 +-- Help/variable/CMAKE_HOST_SYSTEM_NAME.rst | 2 +- Help/variable/CMAKE_INSTALL_NAME_DIR.rst | 2 +- Help/variable/CMAKE_MACOSX_RPATH.rst | 2 +- Help/variable/CMAKE_OSX_ARCHITECTURES.rst | 2 +- Help/variable/CMAKE_OSX_SYSROOT.rst | 2 +- Help/variable/CMAKE_SYSTEM_APPBUNDLE_PATH.rst | 2 +- Help/variable/CMAKE_SYSTEM_FRAMEWORK_PATH.rst | 2 +- Modules/CPack.cmake | 2 +- Modules/CPackComponent.cmake | 6 ++--- Modules/Compiler/IAR-ASM.cmake | 2 ++ Modules/Compiler/IAR-C.cmake | 6 +++++ Modules/Compiler/IAR-CXX.cmake | 6 +++++ Modules/FindBoost.cmake | 4 +-- Modules/ProcessorCount.cmake | 2 +- Source/QtDialog/CMakeSetupDialog.cxx | 2 +- Source/QtDialog/QCMakeCacheView.cxx | 2 +- Source/cmComputeLinkInformation.cxx | 2 +- Source/cmLocalGenerator.cxx | 2 +- Source/cmLocalGenerator.h | 4 +-- Source/cmMakefileTargetGenerator.h | 4 +-- Source/cmNinjaTargetGenerator.h | 2 +- 61 files changed, 161 insertions(+), 133 deletions(-) create mode 100644 Help/variable/CMAKE_CPACK_COMMAND.rst hooks/post-receive -- CMake From kwrobot at kitware.com Tue Sep 11 09:45:02 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Tue, 11 Sep 2018 09:45:02 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-601-g344eb9c Message-ID: <20180911134502.D9088FA41E@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 344eb9c8dc3b16a524729cb66ad25fc1c127a02c (commit) via 31c82143bfdb1d9bc5e6282f3341fc09a0ab2234 (commit) via d6b06d8d876a1cd240f347cdebe527354cb6fd2a (commit) from 528d7625b89e0343bbf541edd256971493a6e455 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=344eb9c8dc3b16a524729cb66ad25fc1c127a02c commit 344eb9c8dc3b16a524729cb66ad25fc1c127a02c Merge: 528d762 31c8214 Author: Craig Scott AuthorDate: Tue Sep 11 13:42:24 2018 +0000 Commit: Kitware Robot CommitDate: Tue Sep 11 09:42:31 2018 -0400 Merge topic 'gtest_add_tests-empty-file' 31c82143bf GoogleTest: gtest_add_tests() fails if any source file is empty d6b06d8d87 GoogleTest: Modify test to verify that empty files can be scanned Acked-by: Kitware Robot Merge-request: !2342 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=31c82143bfdb1d9bc5e6282f3341fc09a0ab2234 commit 31c82143bfdb1d9bc5e6282f3341fc09a0ab2234 Author: Alessandro AuthorDate: Mon Sep 3 09:53:43 2018 -0400 Commit: Craig Scott CommitDate: Mon Sep 10 16:21:48 2018 +0800 GoogleTest: gtest_add_tests() fails if any source file is empty Fixes #18321 diff --git a/Modules/GoogleTest.cmake b/Modules/GoogleTest.cmake index 2c9ee11..a5bb863 100644 --- a/Modules/GoogleTest.cmake +++ b/Modules/GoogleTest.cmake @@ -308,7 +308,7 @@ function(gtest_add_tests) set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${source}) endif() file(READ "${source}" contents) - string(REGEX MATCHALL "${gtest_test_type_regex} *\\(([A-Za-z_0-9 ,]+)\\)" found_tests ${contents}) + string(REGEX MATCHALL "${gtest_test_type_regex} *\\(([A-Za-z_0-9 ,]+)\\)" found_tests "${contents}") foreach(hit ${found_tests}) string(REGEX MATCH "${gtest_test_type_regex}" test_type ${hit}) https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=d6b06d8d876a1cd240f347cdebe527354cb6fd2a commit d6b06d8d876a1cd240f347cdebe527354cb6fd2a Author: Craig Scott AuthorDate: Mon Sep 10 16:20:40 2018 +0800 Commit: Craig Scott CommitDate: Mon Sep 10 16:21:48 2018 +0800 GoogleTest: Modify test to verify that empty files can be scanned The modified test confirms the bug described in issue #18321. diff --git a/Tests/GoogleTest/Test/CMakeLists.txt b/Tests/GoogleTest/Test/CMakeLists.txt index f798d31..baf00d5 100644 --- a/Tests/GoogleTest/Test/CMakeLists.txt +++ b/Tests/GoogleTest/Test/CMakeLists.txt @@ -44,12 +44,13 @@ endif() set_tests_properties(set2.GoogleTest.ConditionalFail.foo PROPERTIES WILL_FAIL YES) -# Search specific sources to get the test list -add_executable(test_gtest2 main2.cxx) +# Search specific sources to get the test list. Include an empty file +# to ensure they are handled correctly too. +add_executable(test_gtest2 main2.cxx empty.cxx) target_link_libraries(test_gtest2 GTest::Main) gtest_add_tests(TARGET test_gtest2 TEST_LIST testList - SOURCES main2.h + SOURCES main2.h empty.cxx ) set(expectedTests GoogleTest.SomethingElse diff --git a/Tests/GoogleTest/Test/empty.cxx b/Tests/GoogleTest/Test/empty.cxx new file mode 100644 index 0000000..e69de29 ----------------------------------------------------------------------- Summary of changes: Modules/GoogleTest.cmake | 2 +- Tests/GoogleTest/Test/CMakeLists.txt | 7 ++++--- Tests/{Wrapping/vtkIncluded.cxx => GoogleTest/Test/empty.cxx} | 0 3 files changed, 5 insertions(+), 4 deletions(-) copy Tests/{Wrapping/vtkIncluded.cxx => GoogleTest/Test/empty.cxx} (100%) hooks/post-receive -- CMake From kwrobot at kitware.com Wed Sep 12 00:05:04 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Wed, 12 Sep 2018 00:05:04 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-602-gf53bd80 Message-ID: <20180912040504.2103A11EA3D@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via f53bd80de17546351a635a47434b2ac66b4100a7 (commit) from 344eb9c8dc3b16a524729cb66ad25fc1c127a02c (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=f53bd80de17546351a635a47434b2ac66b4100a7 commit f53bd80de17546351a635a47434b2ac66b4100a7 Author: Kitware Robot AuthorDate: Wed Sep 12 00:01:08 2018 -0400 Commit: Kitware Robot CommitDate: Wed Sep 12 00:01:08 2018 -0400 CMake Nightly Date Stamp diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 1e9f499..1819564 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 12) -set(CMake_VERSION_PATCH 20180911) +set(CMake_VERSION_PATCH 20180912) #set(CMake_VERSION_RC 1) ----------------------------------------------------------------------- Summary of changes: Source/CMakeVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) hooks/post-receive -- CMake From kwrobot at kitware.com Wed Sep 12 09:35:07 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Wed, 12 Sep 2018 09:35:07 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-604-ge7a45e3 Message-ID: <20180912133507.0A0E31254DE@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via e7a45e3ec34df651ea165ea7344c474245ded7df (commit) via 2c154fec6b117945941c8ef1fce4899965f75a58 (commit) from f53bd80de17546351a635a47434b2ac66b4100a7 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=e7a45e3ec34df651ea165ea7344c474245ded7df commit e7a45e3ec34df651ea165ea7344c474245ded7df Merge: f53bd80 2c154fe Author: Craig Scott AuthorDate: Wed Sep 12 13:32:11 2018 +0000 Commit: Kitware Robot CommitDate: Wed Sep 12 09:32:19 2018 -0400 Merge topic 'unused-variables-cleanup' 2c154fec6b Warnings: Remove unused variables Acked-by: Kitware Robot Merge-request: !2364 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=2c154fec6b117945941c8ef1fce4899965f75a58 commit 2c154fec6b117945941c8ef1fce4899965f75a58 Author: Craig Scott AuthorDate: Mon Sep 10 17:58:03 2018 +0800 Commit: Craig Scott CommitDate: Tue Sep 11 10:20:35 2018 +0800 Warnings: Remove unused variables diff --git a/Source/CPack/cmCPackGenerator.cxx b/Source/CPack/cmCPackGenerator.cxx index 6347eed..acd6650 100644 --- a/Source/CPack/cmCPackGenerator.cxx +++ b/Source/CPack/cmCPackGenerator.cxx @@ -360,8 +360,6 @@ int cmCPackGenerator::InstallProjectViaInstalledDirectories( return 0; } files = gl.GetFiles(); - std::vector::iterator gfit; - std::vector::iterator regIt; for (std::string const& gf : files) { bool skip = false; std::string inFile = gf; @@ -1499,7 +1497,6 @@ cmCPackComponent* cmCPackGenerator::GetComponent( if (installTypes && *installTypes) { std::vector installTypesVector; cmSystemTools::ExpandListArgument(installTypes, installTypesVector); - std::vector::iterator installTypesIt; for (std::string const& installType : installTypesVector) { component->InstallationTypes.push_back( this->GetInstallationType(projectName, installType)); @@ -1511,7 +1508,6 @@ cmCPackComponent* cmCPackGenerator::GetComponent( if (depends && *depends) { std::vector dependsVector; cmSystemTools::ExpandListArgument(depends, dependsVector); - std::vector::iterator dependIt; for (std::string const& depend : dependsVector) { cmCPackComponent* child = GetComponent(projectName, depend); component->Dependencies.push_back(child); diff --git a/Source/cmCommandArgumentParserHelper.cxx b/Source/cmCommandArgumentParserHelper.cxx index c7210b4..83352bb 100644 --- a/Source/cmCommandArgumentParserHelper.cxx +++ b/Source/cmCommandArgumentParserHelper.cxx @@ -253,7 +253,6 @@ int cmCommandArgumentParserHelper::ParseString(const char* str, int verb) void cmCommandArgumentParserHelper::CleanupParser() { - std::vector::iterator sit; for (char* var : this->Variables) { delete[] var; } ----------------------------------------------------------------------- Summary of changes: Source/CPack/cmCPackGenerator.cxx | 4 ---- Source/cmCommandArgumentParserHelper.cxx | 1 - 2 files changed, 5 deletions(-) hooks/post-receive -- CMake From kwrobot at kitware.com Wed Sep 12 09:45:04 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Wed, 12 Sep 2018 09:45:04 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-614-g42212f7 Message-ID: <20180912134504.741891100AD@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 42212f7539040139ecec092547b7d58ef12a4d72 (commit) via 708b3fecfe4ea4f92f49bb5eea5c9eed370a5956 (commit) via 1c1a1e08e82626aaf53ec0285ff4eabdb75d6d71 (commit) via 920ac301b5516273036fdabb334bcd38dff20a20 (commit) via 8bf5c2326e3e37a3431adb72a1cb46623a65f331 (commit) via c1fd1607b8b2e879258f4257a86f9262ccd3d27c (commit) via e8213404cec972ba43b16ec1b49b62f43c9f48b8 (commit) via 3e125c0c017e346768f9882882c31b81cc07940f (commit) via 8fdf08c097edadd134dc36cc80b4b557cddbfea8 (commit) via 13d10ee61642ab384d506fa81a991e51d90c6488 (commit) from e7a45e3ec34df651ea165ea7344c474245ded7df (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=42212f7539040139ecec092547b7d58ef12a4d72 commit 42212f7539040139ecec092547b7d58ef12a4d72 Merge: 708b3fe 3e125c0 Author: Brad King AuthorDate: Wed Sep 12 13:39:41 2018 +0000 Commit: Kitware Robot CommitDate: Wed Sep 12 09:39:46 2018 -0400 Merge topic 'rule-launch-custom-extra-space' 3e125c0c01 Ninja,Makefile: Drop extra space after RULE_LAUNCH_CUSTOM value Acked-by: Kitware Robot Merge-request: !2372 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=708b3fecfe4ea4f92f49bb5eea5c9eed370a5956 commit 708b3fecfe4ea4f92f49bb5eea5c9eed370a5956 Merge: 1c1a1e0 13d10ee Author: Brad King AuthorDate: Wed Sep 12 13:38:30 2018 +0000 Commit: Kitware Robot CommitDate: Wed Sep 12 09:38:37 2018 -0400 Merge topic 'gicv-stdstring' 13d10ee616 cmState::GetInitializedCacheValue: Return as const std::string* Acked-by: Kitware Robot Merge-request: !2365 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=1c1a1e08e82626aaf53ec0285ff4eabdb75d6d71 commit 1c1a1e08e82626aaf53ec0285ff4eabdb75d6d71 Merge: 920ac30 8fdf08c Author: Brad King AuthorDate: Wed Sep 12 13:37:53 2018 +0000 Commit: Kitware Robot CommitDate: Wed Sep 12 09:37:58 2018 -0400 Merge topic 'IAR_6_50_6_fix' 8fdf08c097 IAR: Fix compiler id, version, and arch detection on 6.50.6 Acked-by: Kitware Robot Merge-request: !2371 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=920ac301b5516273036fdabb334bcd38dff20a20 commit 920ac301b5516273036fdabb334bcd38dff20a20 Merge: 8bf5c23 c1fd160 Author: Brad King AuthorDate: Wed Sep 12 09:36:46 2018 -0400 Commit: Brad King CommitDate: Wed Sep 12 09:36:46 2018 -0400 Merge branch 'release-3.12' https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=8bf5c2326e3e37a3431adb72a1cb46623a65f331 commit 8bf5c2326e3e37a3431adb72a1cb46623a65f331 Merge: e7a45e3 e821340 Author: Brad King AuthorDate: Wed Sep 12 13:35:39 2018 +0000 Commit: Kitware Robot CommitDate: Wed Sep 12 09:35:45 2018 -0400 Merge topic 'FindDoxygen-CMP0057' e8213404ce FindDoxygen: Ensure policy settings allow use of IN_LIST Acked-by: Kitware Robot Merge-request: !2373 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=3e125c0c017e346768f9882882c31b81cc07940f commit 3e125c0c017e346768f9882882c31b81cc07940f Author: Brad King AuthorDate: Tue Sep 11 14:04:33 2018 -0400 Commit: Brad King CommitDate: Tue Sep 11 14:18:10 2018 -0400 Ninja,Makefile: Drop extra space after RULE_LAUNCH_CUSTOM value The Ninja and Makefile generators were adding a space to the value both before and after expanding rule variables. Only the latter is needed. While at it, revise some outdated comments since the rule variable expansion is no longer responsible for inserting the launcher. Suggested-by: Mate Pek Fixes: #18340 diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index 360f73d..eb31478 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -564,8 +564,7 @@ std::string cmLocalNinjaGenerator::MakeCustomLauncher( return std::string(); } - // Expand rules in the empty string. It may insert the launcher and - // perform replacements. + // Expand rule variables referenced in the given launcher command. cmRulePlaceholderExpander::RuleVariables vars; std::string output; @@ -580,12 +579,10 @@ std::string cmLocalNinjaGenerator::MakeCustomLauncher( } vars.Output = output.c_str(); - std::string launcher = property_value; - launcher += " "; - std::unique_ptr rulePlaceholderExpander( this->CreateRulePlaceholderExpander()); + std::string launcher = property_value; rulePlaceholderExpander->ExpandRuleVariables(this, launcher, vars); if (!launcher.empty()) { launcher += " "; diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index bc83ce2..690b827 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -967,8 +967,7 @@ void cmLocalUnixMakefileGenerator3::AppendCustomCommand( // Short-circuit if there is no launcher. const char* val = this->GetRuleLauncher(target, "RULE_LAUNCH_CUSTOM"); if (val && *val) { - // Expand rules in the empty string. It may insert the launcher and - // perform replacements. + // Expand rule variables referenced in the given launcher command. cmRulePlaceholderExpander::RuleVariables vars; vars.CMTargetName = target->GetName().c_str(); vars.CMTargetType = cmState::GetTargetTypeName(target->GetType()); @@ -986,7 +985,6 @@ void cmLocalUnixMakefileGenerator3::AppendCustomCommand( vars.Output = output.c_str(); launcher = val; - launcher += " "; rulePlaceholderExpander->ExpandRuleVariables(this, launcher, vars); if (!launcher.empty()) { launcher += " "; https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=8fdf08c097edadd134dc36cc80b4b557cddbfea8 commit 8fdf08c097edadd134dc36cc80b4b557cddbfea8 Author: Daniel Sch?rmann AuthorDate: Tue Sep 11 15:24:20 2018 +0200 Commit: Brad King CommitDate: Tue Sep 11 10:43:03 2018 -0400 IAR: Fix compiler id, version, and arch detection on 6.50.6 The IAR 6.50.6 compiler places extra/truncated copies of the compiler id `INFO:` strings into binaries with a prefix like `?". Remove the incomplete copies. + list(FILTER CMAKE_${lang}_COMPILER_ID_STRINGS EXCLUDE REGEX "\\? AuthorDate: Mon Sep 10 09:31:48 2018 -0400 Commit: Vitaly Stakhovsky CommitDate: Mon Sep 10 09:31:48 2018 -0400 cmState::GetInitializedCacheValue: Return as const std::string* diff --git a/Source/QtDialog/QCMake.cxx b/Source/QtDialog/QCMake.cxx index 0e14a3f..0133b88 100644 --- a/Source/QtDialog/QCMake.cxx +++ b/Source/QtDialog/QCMake.cxx @@ -94,11 +94,11 @@ void QCMake::setBinaryDirectory(const QString& _dir) } const char* gen = state->GetCacheEntryValue("CMAKE_GENERATOR"); if (gen) { - const char* extraGen = + const std::string* extraGen = state->GetInitializedCacheValue("CMAKE_EXTRA_GENERATOR"); std::string curGen = cmExternalMakefileProjectGenerator::CreateFullGeneratorName( - gen, extraGen ? extraGen : ""); + gen, extraGen ? *extraGen : ""); this->setGenerator(QString::fromLocal8Bit(curGen.c_str())); } diff --git a/Source/cmCommandArgumentParserHelper.cxx b/Source/cmCommandArgumentParserHelper.cxx index c7210b4..650d02d 100644 --- a/Source/cmCommandArgumentParserHelper.cxx +++ b/Source/cmCommandArgumentParserHelper.cxx @@ -68,12 +68,12 @@ const char* cmCommandArgumentParserHelper::ExpandSpecialVariable( return ""; } if (strcmp(key, "CACHE") == 0) { - if (const char* c = + if (const std::string* c = this->Makefile->GetState()->GetInitializedCacheValue(var)) { if (this->EscapeQuotes) { - return this->AddString(cmSystemTools::EscapeQuotes(c)); + return this->AddString(cmSystemTools::EscapeQuotes(*c)); } - return this->AddString(c); + return this->AddString(*c); } return ""; } diff --git a/Source/cmExtraEclipseCDT4Generator.cxx b/Source/cmExtraEclipseCDT4Generator.cxx index 313d46b..34f58ad 100644 --- a/Source/cmExtraEclipseCDT4Generator.cxx +++ b/Source/cmExtraEclipseCDT4Generator.cxx @@ -215,7 +215,7 @@ void cmExtraEclipseCDT4Generator::AddEnvVar(std::ostream& out, std::string cacheEntryName = "CMAKE_ECLIPSE_ENVVAR_"; cacheEntryName += envVar; - const char* cacheValue = + const std::string* cacheValue = lg->GetState()->GetInitializedCacheValue(cacheEntryName); // now we have both, decide which one to use @@ -232,14 +232,14 @@ void cmExtraEclipseCDT4Generator::AddEnvVar(std::ostream& out, mf->GetCMakeInstance()->SaveCache(lg->GetBinaryDirectory()); } else if (!envVarSet && cacheValue != nullptr) { // It is already in the cache, but not in the env, so use it from the cache - valueToUse = cacheValue; + valueToUse = *cacheValue; } else { // It is both in the cache and in the env. // Use the version from the env. except if the value from the env is // completely contained in the value from the cache (for the case that we // now have a PATH without MSVC dirs in the env. but had the full PATH with // all MSVC dirs during the cmake run which stored the var in the cache: - valueToUse = cacheValue; + valueToUse = *cacheValue; if (valueToUse.find(envVarValue) == std::string::npos) { valueToUse = envVarValue; mf->AddCacheDefinition(cacheEntryName, valueToUse.c_str(), diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index b5212fc..99135c8 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -215,15 +215,15 @@ void cmGlobalGenerator::ResolveLanguageCompiler(const std::string& lang, if (!optional && (path.empty() || !cmSystemTools::FileExists(path))) { return; } - const char* cname = + const std::string* cname = this->GetCMakeInstance()->GetState()->GetInitializedCacheValue(langComp); std::string changeVars; if (cname && !optional) { std::string cnameString; - if (!cmSystemTools::FileIsFullPath(cname)) { - cnameString = cmSystemTools::FindProgram(cname); + if (!cmSystemTools::FileIsFullPath(*cname)) { + cnameString = cmSystemTools::FindProgram(*cname); } else { - cnameString = cname; + cnameString = *cname; } std::string pathString = path; // get rid of potentially multiple slashes: @@ -239,7 +239,7 @@ void cmGlobalGenerator::ResolveLanguageCompiler(const std::string& lang, } changeVars += langComp; changeVars += ";"; - changeVars += cname; + changeVars += *cname; this->GetCMakeInstance()->GetState()->SetGlobalProperty( "__CMAKE_DELETE_CACHE_CHANGE_VARS_", changeVars.c_str()); } @@ -1970,7 +1970,7 @@ void cmGlobalGenerator::AddMakefile(cmMakefile* mf) // update progress // estimate how many lg there will be - const char* numGenC = + const std::string* numGenC = this->CMakeInstance->GetState()->GetInitializedCacheValue( "CMAKE_NUMBER_OF_MAKEFILES"); @@ -1988,7 +1988,7 @@ void cmGlobalGenerator::AddMakefile(cmMakefile* mf) return; } - int numGen = atoi(numGenC); + int numGen = atoi(numGenC->c_str()); float prog = 0.9f * static_cast(this->Makefiles.size()) / static_cast(numGen); if (prog > 0.9f) { diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 5498ad2..dce7bd0 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1718,7 +1718,8 @@ void cmMakefile::AddCacheDefinition(const std::string& name, const char* value, cmStateEnums::CacheEntryType type, bool force) { - const char* existingValue = this->GetState()->GetInitializedCacheValue(name); + const std::string* existingValue = + this->GetState()->GetInitializedCacheValue(name); // must be outside the following if() to keep it alive long enough std::string nvalue; @@ -1728,7 +1729,7 @@ void cmMakefile::AddCacheDefinition(const std::string& name, const char* value, // if this is not a force, then use the value from the cache // if it is a force, then use the value being passed in if (!force) { - value = existingValue; + value = existingValue->c_str(); } if (type == cmStateEnums::PATH || type == cmStateEnums::FILEPATH) { std::vector::size_type cc; @@ -1748,7 +1749,7 @@ void cmMakefile::AddCacheDefinition(const std::string& name, const char* value, } this->GetCMakeInstance()->AddCacheEntry(name, nvalue.c_str(), doc, type); - nvalue = this->GetState()->GetInitializedCacheValue(name); + nvalue = *this->GetState()->GetInitializedCacheValue(name); value = nvalue.c_str(); } } @@ -2368,17 +2369,15 @@ std::string cmMakefile::GetRequiredDefinition(const std::string& name) const bool cmMakefile::IsDefinitionSet(const std::string& name) const { - const char* def; - if (const std::string* d = this->StateSnapshot.GetDefinition(name)) { - def = d->c_str(); - } else { + const std::string* def = this->StateSnapshot.GetDefinition(name); + if (!def) { def = this->GetState()->GetInitializedCacheValue(name); } #ifdef CMAKE_BUILD_WITH_CMAKE if (cmVariableWatch* vv = this->GetVariableWatch()) { if (!def) { vv->VariableAccessed( - name, cmVariableWatch::UNKNOWN_VARIABLE_DEFINED_ACCESS, def, this); + name, cmVariableWatch::UNKNOWN_VARIABLE_DEFINED_ACCESS, nullptr, this); } } #endif @@ -2387,10 +2386,8 @@ bool cmMakefile::IsDefinitionSet(const std::string& name) const const char* cmMakefile::GetDefinition(const std::string& name) const { - const char* def; - if (const std::string* d = this->StateSnapshot.GetDefinition(name)) { - def = d->c_str(); - } else { + const std::string* def = this->StateSnapshot.GetDefinition(name); + if (!def) { def = this->GetState()->GetInitializedCacheValue(name); } #ifdef CMAKE_BUILD_WITH_CMAKE @@ -2400,21 +2397,20 @@ const char* cmMakefile::GetDefinition(const std::string& name) const vv->VariableAccessed(name, def ? cmVariableWatch::VARIABLE_READ_ACCESS : cmVariableWatch::UNKNOWN_VARIABLE_READ_ACCESS, - def, this); + (def ? def->c_str() : nullptr), this); if (watch_function_executed) { // A callback was executed and may have caused re-allocation of the // variable storage. Look it up again for now. // FIXME: Refactor variable storage to avoid this problem. - if (const std::string* d = this->StateSnapshot.GetDefinition(name)) { - def = d->c_str(); - } else { + def = this->StateSnapshot.GetDefinition(name); + if (!def) { def = this->GetState()->GetInitializedCacheValue(name); } } } #endif - return def; + return (def ? def->c_str() : nullptr); } const char* cmMakefile::GetSafeDefinition(const std::string& def) const diff --git a/Source/cmServerProtocol.cxx b/Source/cmServerProtocol.cxx index af4b466..0ed3953 100644 --- a/Source/cmServerProtocol.cxx +++ b/Source/cmServerProtocol.cxx @@ -1340,20 +1340,20 @@ cmServerResponse cmServerProtocol1::ProcessConfigure( if (cm->LoadCache(buildDir)) { // build directory has been set up before - const char* cachedSourceDir = + const std::string* cachedSourceDir = cm->GetState()->GetInitializedCacheValue("CMAKE_HOME_DIRECTORY"); if (!cachedSourceDir) { return request.ReportError("No CMAKE_HOME_DIRECTORY found in cache."); } if (sourceDir.empty()) { - sourceDir = std::string(cachedSourceDir); + sourceDir = *cachedSourceDir; cm->SetHomeDirectory(sourceDir); } - const char* cachedGenerator = + const std::string* cachedGenerator = cm->GetState()->GetInitializedCacheValue("CMAKE_GENERATOR"); if (cachedGenerator) { - if (gg && gg->GetName() != cachedGenerator) { + if (gg && gg->GetName() != *cachedGenerator) { return request.ReportError("Configured generator does not match with " "CMAKE_GENERATOR found in cache."); } diff --git a/Source/cmState.cxx b/Source/cmState.cxx index e01bf71..c8b8653 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -140,10 +140,10 @@ const char* cmState::GetCacheEntryValue(std::string const& key) const return e->Value.c_str(); } -const char* cmState::GetInitializedCacheValue(std::string const& key) const +const std::string* cmState::GetInitializedCacheValue( + std::string const& key) const { - const std::string* p = this->CacheManager->GetInitializedCacheValue(key); - return p ? p->c_str() : nullptr; + return this->CacheManager->GetInitializedCacheValue(key); } cmStateEnums::CacheEntryType cmState::GetCacheEntryType( diff --git a/Source/cmState.h b/Source/cmState.h index 38bdfec..ca7093a 100644 --- a/Source/cmState.h +++ b/Source/cmState.h @@ -68,7 +68,7 @@ public: std::vector GetCacheEntryKeys() const; const char* GetCacheEntryValue(std::string const& key) const; - const char* GetInitializedCacheValue(std::string const& key) const; + const std::string* GetInitializedCacheValue(std::string const& key) const; cmStateEnums::CacheEntryType GetCacheEntryType(std::string const& key) const; void SetCacheEntryValue(std::string const& key, std::string const& value); void SetCacheValue(std::string const& key, std::string const& value); diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 1bf8f7d..783dbf2 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -319,9 +319,10 @@ bool cmake::SetCacheArgs(const std::vector& args) bool haveValue = false; std::string cachedValue; if (this->WarnUnusedCli) { - if (const char* v = this->State->GetInitializedCacheValue(var)) { + if (const std::string* v = + this->State->GetInitializedCacheValue(var)) { haveValue = true; - cachedValue = v; + cachedValue = *v; } } @@ -331,7 +332,7 @@ bool cmake::SetCacheArgs(const std::vector& args) if (this->WarnUnusedCli) { if (!haveValue || - cachedValue != this->State->GetInitializedCacheValue(var)) { + cachedValue != *this->State->GetInitializedCacheValue(var)) { this->WatchUnusedCli(var); } } @@ -1107,7 +1108,7 @@ int cmake::DoPreConfigureChecks() // do a sanity check on some values if (this->State->GetInitializedCacheValue("CMAKE_HOME_DIRECTORY")) { std::string cacheStart = - this->State->GetInitializedCacheValue("CMAKE_HOME_DIRECTORY"); + *this->State->GetInitializedCacheValue("CMAKE_HOME_DIRECTORY"); cacheStart += "/CMakeLists.txt"; std::string currentStart = this->GetHomeDirectory(); currentStart += "/CMakeLists.txt"; @@ -1276,14 +1277,14 @@ int cmake::ActualConfigure() // no generator specified on the command line if (!this->GlobalGenerator) { - const char* genName = + const std::string* genName = this->State->GetInitializedCacheValue("CMAKE_GENERATOR"); - const char* extraGenName = + const std::string* extraGenName = this->State->GetInitializedCacheValue("CMAKE_EXTRA_GENERATOR"); if (genName) { std::string fullName = cmExternalMakefileProjectGenerator::CreateFullGeneratorName( - genName, extraGenName ? extraGenName : ""); + *genName, extraGenName ? *extraGenName : ""); this->GlobalGenerator = this->CreateGlobalGenerator(fullName); } if (this->GlobalGenerator) { @@ -1301,14 +1302,14 @@ int cmake::ActualConfigure() } } - const char* genName = + const std::string* genName = this->State->GetInitializedCacheValue("CMAKE_GENERATOR"); if (genName) { - if (!this->GlobalGenerator->MatchesGeneratorName(genName)) { + if (!this->GlobalGenerator->MatchesGeneratorName(*genName)) { std::string message = "Error: generator : "; message += this->GlobalGenerator->GetName(); message += "\nDoes not match the generator used previously: "; - message += genName; + message += *genName; message += "\nEither remove the CMakeCache.txt file and CMakeFiles " "directory or choose a different binary directory."; cmSystemTools::Error(message.c_str()); @@ -1325,14 +1326,14 @@ int cmake::ActualConfigure() cmStateEnums::INTERNAL); } - if (const char* instance = + if (const std::string* instance = this->State->GetInitializedCacheValue("CMAKE_GENERATOR_INSTANCE")) { if (!this->GeneratorInstance.empty() && - this->GeneratorInstance != instance) { + this->GeneratorInstance != *instance) { std::string message = "Error: generator instance: "; message += this->GeneratorInstance; message += "\nDoes not match the instance used previously: "; - message += instance; + message += *instance; message += "\nEither remove the CMakeCache.txt file and CMakeFiles " "directory or choose a different binary directory."; cmSystemTools::Error(message.c_str()); @@ -1344,14 +1345,14 @@ int cmake::ActualConfigure() "Generator instance identifier.", cmStateEnums::INTERNAL); } - if (const char* platformName = + if (const std::string* platformName = this->State->GetInitializedCacheValue("CMAKE_GENERATOR_PLATFORM")) { if (!this->GeneratorPlatform.empty() && - this->GeneratorPlatform != platformName) { + this->GeneratorPlatform != *platformName) { std::string message = "Error: generator platform: "; message += this->GeneratorPlatform; message += "\nDoes not match the platform used previously: "; - message += platformName; + message += *platformName; message += "\nEither remove the CMakeCache.txt file and CMakeFiles " "directory or choose a different binary directory."; cmSystemTools::Error(message.c_str()); @@ -1363,13 +1364,13 @@ int cmake::ActualConfigure() "Name of generator platform.", cmStateEnums::INTERNAL); } - if (const char* tsName = + if (const std::string* tsName = this->State->GetInitializedCacheValue("CMAKE_GENERATOR_TOOLSET")) { - if (!this->GeneratorToolset.empty() && this->GeneratorToolset != tsName) { + if (!this->GeneratorToolset.empty() && this->GeneratorToolset != *tsName) { std::string message = "Error: generator toolset: "; message += this->GeneratorToolset; message += "\nDoes not match the toolset used previously: "; - message += tsName; + message += *tsName; message += "\nEither remove the CMakeCache.txt file and CMakeFiles " "directory or choose a different binary directory."; cmSystemTools::Error(message.c_str()); @@ -1685,7 +1686,8 @@ std::string cmake::StripExtension(const std::string& file) const const char* cmake::GetCacheDefinition(const std::string& name) const { - return this->State->GetInitializedCacheValue(name); + const std::string* p = this->State->GetInitializedCacheValue(name); + return p ? p->c_str() : nullptr; } void cmake::AddScriptingCommands() @@ -1868,14 +1870,14 @@ void cmake::PrintGeneratorList() void cmake::UpdateConversionPathTable() { // Update the path conversion table with any specified file: - const char* tablepath = + const std::string* tablepath = this->State->GetInitializedCacheValue("CMAKE_PATH_TRANSLATION_FILE"); if (tablepath) { - cmsys::ifstream table(tablepath); + cmsys::ifstream table(tablepath->c_str()); if (!table) { - cmSystemTools::Error("CMAKE_PATH_TRANSLATION_FILE set to ", tablepath, - ". CMake can not open file."); + cmSystemTools::Error("CMAKE_PATH_TRANSLATION_FILE set to ", + tablepath->c_str(), ". CMake can not open file."); cmSystemTools::ReportLastSystemError("CMake can not open file."); } else { std::string a, b; @@ -2527,11 +2529,11 @@ bool cmake::Open(const std::string& dir, bool dryRun) std::cerr << "Error: could not find CMAKE_GENERATOR in Cache\n"; return false; } - const char* extraGenName = + const std::string* extraGenName = this->State->GetInitializedCacheValue("CMAKE_EXTRA_GENERATOR"); std::string fullName = cmExternalMakefileProjectGenerator::CreateFullGeneratorName( - genName, extraGenName ? extraGenName : ""); + genName, extraGenName ? *extraGenName : ""); std::unique_ptr gen( this->CreateGlobalGenerator(fullName)); ----------------------------------------------------------------------- Summary of changes: Modules/CMakeDetermineCompilerId.cmake | 3 ++ Modules/FindDoxygen.cmake | 5 +++ Source/QtDialog/QCMake.cxx | 4 +-- Source/cmCommandArgumentParserHelper.cxx | 6 ++-- Source/cmExtraEclipseCDT4Generator.cxx | 6 ++-- Source/cmGlobalGenerator.cxx | 14 ++++----- Source/cmLocalNinjaGenerator.cxx | 7 ++--- Source/cmLocalUnixMakefileGenerator3.cxx | 4 +-- Source/cmMakefile.cxx | 30 ++++++++---------- Source/cmServerProtocol.cxx | 8 ++--- Source/cmState.cxx | 6 ++-- Source/cmState.h | 2 +- Source/cmake.cxx | 54 +++++++++++++++++--------------- 13 files changed, 75 insertions(+), 74 deletions(-) hooks/post-receive -- CMake From kwrobot at kitware.com Wed Sep 12 09:45:04 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Wed, 12 Sep 2018 09:45:04 -0400 (EDT) Subject: [Cmake-commits] CMake branch, release, updated. v3.12.2-8-gc1fd160 Message-ID: <20180912134504.83A60112D87@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, release has been updated via c1fd1607b8b2e879258f4257a86f9262ccd3d27c (commit) via e8213404cec972ba43b16ec1b49b62f43c9f48b8 (commit) from e0e56abe3479efddd994cc1a3ee9b8a123111903 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- ----------------------------------------------------------------------- Summary of changes: Modules/FindDoxygen.cmake | 5 +++++ 1 file changed, 5 insertions(+) hooks/post-receive -- CMake From kwrobot at kitware.com Thu Sep 13 00:05:05 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Thu, 13 Sep 2018 00:05:05 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-615-g98e6877 Message-ID: <20180913040505.E3A5911FD4D@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 98e6877d1efe3412ca79f4acd8c03894b074fb35 (commit) from 42212f7539040139ecec092547b7d58ef12a4d72 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=98e6877d1efe3412ca79f4acd8c03894b074fb35 commit 98e6877d1efe3412ca79f4acd8c03894b074fb35 Author: Kitware Robot AuthorDate: Thu Sep 13 00:01:06 2018 -0400 Commit: Kitware Robot CommitDate: Thu Sep 13 00:01:06 2018 -0400 CMake Nightly Date Stamp diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 1819564..24e96af 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 12) -set(CMake_VERSION_PATCH 20180912) +set(CMake_VERSION_PATCH 20180913) #set(CMake_VERSION_RC 1) ----------------------------------------------------------------------- Summary of changes: Source/CMakeVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) hooks/post-receive -- CMake From kwrobot at kitware.com Fri Sep 14 00:05:09 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Fri, 14 Sep 2018 00:05:09 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-616-gf0c8434 Message-ID: <20180914040510.33D6611D819@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via f0c84346ed25f6b8ce3a9f79aece87a58c8a4748 (commit) from 98e6877d1efe3412ca79f4acd8c03894b074fb35 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=f0c84346ed25f6b8ce3a9f79aece87a58c8a4748 commit f0c84346ed25f6b8ce3a9f79aece87a58c8a4748 Author: Kitware Robot AuthorDate: Fri Sep 14 00:01:04 2018 -0400 Commit: Kitware Robot CommitDate: Fri Sep 14 00:01:04 2018 -0400 CMake Nightly Date Stamp diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 24e96af..bd8ad4d 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 12) -set(CMake_VERSION_PATCH 20180913) +set(CMake_VERSION_PATCH 20180914) #set(CMake_VERSION_RC 1) ----------------------------------------------------------------------- Summary of changes: Source/CMakeVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) hooks/post-receive -- CMake From kwrobot at kitware.com Fri Sep 14 13:25:08 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Fri, 14 Sep 2018 13:25:08 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-625-g88e6e35 Message-ID: <20180914172508.A2A861250AF@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 88e6e35358f0be59d2ceddb77fcb67091110b56c (commit) via cff5151822d4f3e68befed01f47013d478e85bcd (commit) via 14a4f9a3618650771b90d6eb9f02119cbcd6983d (commit) via 7c94434351171a30eda1bb97ea15b3fa5ab4c0d2 (commit) via ed71ec757995e78de31a083a6c8b1092b13dbc08 (commit) via bdd0e2d7095932730162faebd99bc28152ca0c1c (commit) via ee300dc25ddb1968d266c70cad2d382702e43b25 (commit) via 8ede35523e6e3b6d562d30a3df7780b66bdbd971 (commit) via e549e31f798b05345de5a36f876197b595296eb4 (commit) from f0c84346ed25f6b8ce3a9f79aece87a58c8a4748 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=88e6e35358f0be59d2ceddb77fcb67091110b56c commit 88e6e35358f0be59d2ceddb77fcb67091110b56c Merge: cff5151 8ede355 Author: Brad King AuthorDate: Fri Sep 14 17:23:03 2018 +0000 Commit: Kitware Robot CommitDate: Fri Sep 14 13:23:10 2018 -0400 Merge topic 'module_policy_protection' 8ede35523e IN_LIST: Ensure policy allows if(IN_LIST) if used by a module e549e31f79 CMakeIOSInstallCombined: Prevent policy leakage Acked-by: Kitware Robot Merge-request: !2375 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=cff5151822d4f3e68befed01f47013d478e85bcd commit cff5151822d4f3e68befed01f47013d478e85bcd Merge: 14a4f9a ee300dc Author: Brad King AuthorDate: Fri Sep 14 17:20:50 2018 +0000 Commit: Kitware Robot CommitDate: Fri Sep 14 13:22:18 2018 -0400 Merge topic 'boost-notfound' ee300dc25d FindBoost: Suppress imported targets warning if Boost was not found Acked-by: Kitware Robot Merge-request: !2376 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=14a4f9a3618650771b90d6eb9f02119cbcd6983d commit 14a4f9a3618650771b90d6eb9f02119cbcd6983d Merge: 7c94434 ed71ec7 Author: Brad King AuthorDate: Fri Sep 14 17:20:26 2018 +0000 Commit: Kitware Robot CommitDate: Fri Sep 14 13:21:26 2018 -0400 Merge topic 'ctest-stop-time-test' ed71ec7579 CTest: Improve stop-time implementation Acked-by: Kitware Robot Merge-request: !2378 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=7c94434351171a30eda1bb97ea15b3fa5ab4c0d2 commit 7c94434351171a30eda1bb97ea15b3fa5ab4c0d2 Merge: f0c8434 bdd0e2d Author: Brad King AuthorDate: Fri Sep 14 17:20:20 2018 +0000 Commit: Kitware Robot CommitDate: Fri Sep 14 13:20:27 2018 -0400 Merge topic 'test-ninja-sub-build-fs-delay' bdd0e2d709 Tests: Extend RunCMake.Ninja filesystem delays Acked-by: Kitware Robot Merge-request: !2310 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=ed71ec757995e78de31a083a6c8b1092b13dbc08 commit ed71ec757995e78de31a083a6c8b1092b13dbc08 Author: Brad King AuthorDate: Wed Sep 12 10:49:08 2018 -0400 Commit: Brad King CommitDate: Wed Sep 12 10:59:55 2018 -0400 CTest: Improve stop-time implementation The CTestTestStopTime test has been failing sporadically because the stop time causes the first internal test to have a timeout short enough that we might hit it and start the second test just before the stop time is reached. Instead we should track when a timeout is shortened in order to stay within the stop time. If a test times out for this reason then we should consider the stop time reached and not start any more tests. diff --git a/Source/CTest/cmCTestMultiProcessHandler.cxx b/Source/CTest/cmCTestMultiProcessHandler.cxx index 54b4be2..3e0c1ac 100644 --- a/Source/CTest/cmCTestMultiProcessHandler.cxx +++ b/Source/CTest/cmCTestMultiProcessHandler.cxx @@ -56,7 +56,6 @@ cmCTestMultiProcessHandler::cmCTestMultiProcessHandler() this->RunningCount = 0; this->ProcessorsAvailable = cmAffinity::GetProcessorsAvailable(); this->HaveAffinity = this->ProcessorsAvailable.size(); - this->StopTimePassed = false; this->HasCycles = false; this->SerialTestRunning = false; } @@ -130,17 +129,6 @@ void cmCTestMultiProcessHandler::RunTests() bool cmCTestMultiProcessHandler::StartTestProcess(int test) { - std::chrono::system_clock::time_point stop_time = this->CTest->GetStopTime(); - if (stop_time != std::chrono::system_clock::time_point() && - stop_time <= std::chrono::system_clock::now()) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "The stop time has been passed. " - "Stopping all tests." - << std::endl); - this->StopTimePassed = true; - return false; - } - if (this->HaveAffinity && this->Properties[test]->WantAffinity) { size_t needProcessors = this->GetProcessorsUsed(test); if (needProcessors > this->ProcessorsAvailable.size()) { @@ -199,6 +187,30 @@ bool cmCTestMultiProcessHandler::StartTestProcess(int test) return false; } +bool cmCTestMultiProcessHandler::CheckStopTimePassed() +{ + if (!this->StopTimePassed) { + std::chrono::system_clock::time_point stop_time = + this->CTest->GetStopTime(); + if (stop_time != std::chrono::system_clock::time_point() && + stop_time <= std::chrono::system_clock::now()) { + this->SetStopTimePassed(); + } + } + return this->StopTimePassed; +} + +void cmCTestMultiProcessHandler::SetStopTimePassed() +{ + if (!this->StopTimePassed) { + cmCTestLog(this->CTest, ERROR_MESSAGE, + "The stop time has been passed. " + "Stopping all tests." + << std::endl); + this->StopTimePassed = true; + } +} + void cmCTestMultiProcessHandler::LockResources(int index) { this->LockedResources.insert( @@ -279,6 +291,10 @@ void cmCTestMultiProcessHandler::StartNextTests() return; } + if (this->CheckStopTimePassed()) { + return; + } + size_t numToStart = 0; if (this->RunningCount < this->ParallelLevel) { @@ -358,10 +374,6 @@ void cmCTestMultiProcessHandler::StartNextTests() } if (testLoadOk && processors <= numToStart && this->StartTest(test)) { - if (this->StopTimePassed) { - return; - } - numToStart -= processors; } else if (numToStart == 0) { break; @@ -424,8 +436,11 @@ void cmCTestMultiProcessHandler::FinishTestProcess(cmCTestRunTest* runner, auto properties = runner->GetTestProperties(); bool testResult = runner->EndTest(this->Completed, this->Total, started); + if (runner->TimedOutForStopTime()) { + this->SetStopTimePassed(); + } if (started) { - if (runner->StartAgain()) { + if (!this->StopTimePassed && runner->StartAgain()) { this->Completed--; // remove the completed test because run again return; } diff --git a/Source/CTest/cmCTestMultiProcessHandler.h b/Source/CTest/cmCTestMultiProcessHandler.h index 07a5fe7..3927a8a 100644 --- a/Source/CTest/cmCTestMultiProcessHandler.h +++ b/Source/CTest/cmCTestMultiProcessHandler.h @@ -113,6 +113,9 @@ protected: inline size_t GetProcessorsUsed(int index); std::string GetName(int index); + bool CheckStopTimePassed(); + void SetStopTimePassed(); + void LockResources(int index); void UnlockResources(int index); // map from test number to set of depend tests @@ -125,7 +128,7 @@ protected: size_t RunningCount; std::set ProcessorsAvailable; size_t HaveAffinity; - bool StopTimePassed; + bool StopTimePassed = false; // list of test properties (indices concurrent to the test map) PropertiesMap Properties; std::map TestRunningMap; diff --git a/Source/CTest/cmCTestRunTest.cxx b/Source/CTest/cmCTestRunTest.cxx index ef0a49d..23d4616 100644 --- a/Source/CTest/cmCTestRunTest.cxx +++ b/Source/CTest/cmCTestRunTest.cxx @@ -140,6 +140,9 @@ bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started) bool passed = true; cmProcess::State res = started ? this->TestProcess->GetProcessStatus() : cmProcess::State::Error; + if (res != cmProcess::State::Expired) { + this->TimeoutIsForStopTime = false; + } int retVal = this->TestProcess->GetExitValue(); bool forceFail = false; bool skipped = false; @@ -537,6 +540,7 @@ bool cmCTestRunTest::StartTest(size_t total) auto timeout = this->TestProperties->Timeout; + this->TimeoutIsForStopTime = false; std::chrono::system_clock::time_point stop_time = this->CTest->GetStopTime(); if (stop_time != std::chrono::system_clock::time_point()) { std::chrono::duration stop_timeout = @@ -547,6 +551,7 @@ bool cmCTestRunTest::StartTest(size_t total) } if (timeout == std::chrono::duration::zero() || stop_timeout < timeout) { + this->TimeoutIsForStopTime = true; timeout = stop_timeout; } } diff --git a/Source/CTest/cmCTestRunTest.h b/Source/CTest/cmCTestRunTest.h index 3b1d674..7e80157 100644 --- a/Source/CTest/cmCTestRunTest.h +++ b/Source/CTest/cmCTestRunTest.h @@ -80,6 +80,8 @@ public: void FinalizeTest(); + bool TimedOutForStopTime() const { return this->TimeoutIsForStopTime; } + private: bool NeedsToRerun(); void DartProcessing(); @@ -92,6 +94,7 @@ private: void MemCheckPostProcess(); cmCTestTestHandler::cmCTestTestProperties* TestProperties; + bool TimeoutIsForStopTime = false; // Pointer back to the "parent"; the handler that invoked this test run cmCTestTestHandler* TestHandler; cmCTest* CTest; https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=bdd0e2d7095932730162faebd99bc28152ca0c1c commit bdd0e2d7095932730162faebd99bc28152ca0c1c Author: Brad King AuthorDate: Wed Sep 12 10:21:12 2018 -0400 Commit: Brad King CommitDate: Wed Sep 12 10:22:22 2018 -0400 Tests: Extend RunCMake.Ninja filesystem delays On filesystems with 1s resolution the `run_sub_cmake` cases fail occasionally when the 1 second sleep does not cause files to have a different time. Use 3 seconds instead. diff --git a/Tests/RunCMake/Ninja/RunCMakeTest.cmake b/Tests/RunCMake/Ninja/RunCMakeTest.cmake index e0ddc9c..4b366a8 100644 --- a/Tests/RunCMake/Ninja/RunCMakeTest.cmake +++ b/Tests/RunCMake/Ninja/RunCMakeTest.cmake @@ -205,15 +205,16 @@ function(run_sub_cmake test ninja_output_path_prefix) set(cmd_prefix "") set(cmd_suffix "") endif() + set(fs_delay 3) # We assume the system as 1 sec timestamp resolution. file(WRITE "${top_build_ninja}" "\ subninja ${escaped_ninja_output_path_prefix}/build.ninja default ${escaped_ninja_output_path_prefix}/all -# Sleep for 1 second before to regenerate to make sure the timestamp of +# Sleep for long enough before regenerating to make sure the timestamp of # the top build.ninja will be strictly greater than the timestamp of the -# sub/build.ninja file. We assume the system as 1 sec timestamp resolution. +# sub/build.ninja file. rule RERUN - command = ${cmd_prefix}\"${escaped_CMAKE_COMMAND}\" -E sleep 1 && \"${escaped_CMAKE_COMMAND}\" -E touch \"${escaped_top_build_ninja}\"${cmd_suffix} + command = ${cmd_prefix}\"${escaped_CMAKE_COMMAND}\" -E sleep ${fs_delay} && \"${escaped_CMAKE_COMMAND}\" -E touch \"${escaped_top_build_ninja}\"${cmd_suffix} description = Testing regeneration generator = 1 @@ -239,7 +240,7 @@ build build.ninja: RERUN ${escaped_build_ninja_dep} || ${escaped_ninja_output_pa # Test regeneration rules run in order. set(main_cmakelists "${RunCMake_SOURCE_DIR}/CMakeLists.txt") - sleep(1) # Assume the system as 1 sec timestamp resolution. + sleep(${fs_delay}) touch("${main_cmakelists}") touch("${build_ninja_dep}") run_ninja("${top_build_dir}") https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=ee300dc25ddb1968d266c70cad2d382702e43b25 commit ee300dc25ddb1968d266c70cad2d382702e43b25 Author: Roger Leigh AuthorDate: Wed Sep 12 13:23:24 2018 +0100 Commit: Roger Leigh CommitDate: Wed Sep 12 14:44:57 2018 +0100 FindBoost: Suppress imported targets warning if Boost was not found Fixes: #18330 diff --git a/Modules/FindBoost.cmake b/Modules/FindBoost.cmake index 24ee1f2..37539ba 100644 --- a/Modules/FindBoost.cmake +++ b/Modules/FindBoost.cmake @@ -573,7 +573,7 @@ function(_Boost_COMPONENT_DEPENDENCIES component _ret) endif() set(_Boost_IMPORTED_TARGETS TRUE) - if(Boost_VERSION VERSION_LESS 103300) + if(Boost_VERSION AND Boost_VERSION VERSION_LESS 103300) message(WARNING "Imported targets and dependency information not available for Boost version ${Boost_VERSION} (all versions older than 1.33)") set(_Boost_IMPORTED_TARGETS FALSE) elseif(NOT Boost_VERSION VERSION_LESS 103300 AND Boost_VERSION VERSION_LESS 103500) https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=8ede35523e6e3b6d562d30a3df7780b66bdbd971 commit 8ede35523e6e3b6d562d30a3df7780b66bdbd971 Author: Craig Scott AuthorDate: Wed Sep 12 14:50:16 2018 +0800 Commit: Craig Scott CommitDate: Wed Sep 12 14:50:16 2018 +0800 IN_LIST: Ensure policy allows if(IN_LIST) if used by a module diff --git a/Modules/CSharpUtilities.cmake b/Modules/CSharpUtilities.cmake index e9e1510..6a4b5c7 100644 --- a/Modules/CSharpUtilities.cmake +++ b/Modules/CSharpUtilities.cmake @@ -184,6 +184,9 @@ Helper functions which are used by the above ones #]=======================================================================] +cmake_policy(PUSH) +cmake_policy(SET CMP0057 NEW) # if IN_LIST + function(csharp_get_filename_keys OUT) set(${OUT} "") foreach(f ${ARGN}) @@ -304,3 +307,5 @@ function(csharp_set_xaml_cs_properties) endif() endforeach() endfunction() + +cmake_policy(POP) diff --git a/Modules/Internal/CPack/CPackDeb.cmake b/Modules/Internal/CPack/CPackDeb.cmake index 4ef4539..ca3a004 100644 --- a/Modules/Internal/CPack/CPackDeb.cmake +++ b/Modules/Internal/CPack/CPackDeb.cmake @@ -10,6 +10,9 @@ if(CMAKE_BINARY_DIR) message(FATAL_ERROR "CPackDeb.cmake may only be used by CPack internally.") endif() +cmake_policy(PUSH) +cmake_policy(SET CMP0057 NEW) # if IN_LIST + function(cpack_deb_variable_fallback OUTPUT_VAR_NAME) set(FALLBACK_VAR_NAMES ${ARGN}) @@ -579,3 +582,5 @@ function(cpack_deb_prepare_package_vars) endfunction() cpack_deb_prepare_package_vars() + +cmake_policy(POP) diff --git a/Modules/Internal/CPack/CPackRPM.cmake b/Modules/Internal/CPack/CPackRPM.cmake index 06298d7..3bd5147 100644 --- a/Modules/Internal/CPack/CPackRPM.cmake +++ b/Modules/Internal/CPack/CPackRPM.cmake @@ -3,6 +3,9 @@ # Author: Eric Noulard with the help of Alexander Neundorf. +cmake_policy(PUSH) +cmake_policy(SET CMP0057 NEW) # if IN_LIST + function(get_file_permissions FILE RETURN_VAR) execute_process(COMMAND ls -l ${FILE} OUTPUT_VARIABLE permissions_ @@ -1865,3 +1868,5 @@ mv %_topdir/tmpBBroot $RPM_BUILD_ROOT endfunction() cpack_rpm_generate_package() + +cmake_policy(POP) diff --git a/Modules/Platform/Android-Determine.cmake b/Modules/Platform/Android-Determine.cmake index e623902..bb42eed 100644 --- a/Modules/Platform/Android-Determine.cmake +++ b/Modules/Platform/Android-Determine.cmake @@ -18,6 +18,9 @@ if(CMAKE_SYSTEM_VERSION EQUAL 1) return() endif() +cmake_policy(PUSH) +cmake_policy(SET CMP0057 NEW) # if IN_LIST + # If the user provided CMAKE_SYSROOT for us, extract information from it. set(_ANDROID_SYSROOT_NDK "") set(_ANDROID_SYSROOT_API "") @@ -371,3 +374,5 @@ endif() # Report the chosen architecture. message(STATUS "Android: Targeting API '${CMAKE_SYSTEM_VERSION}' with architecture '${CMAKE_ANDROID_ARCH}', ABI '${CMAKE_ANDROID_ARCH_ABI}', and processor '${CMAKE_SYSTEM_PROCESSOR}'") + +cmake_policy(POP) https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=e549e31f798b05345de5a36f876197b595296eb4 commit e549e31f798b05345de5a36f876197b595296eb4 Author: Craig Scott AuthorDate: Wed Sep 12 14:40:37 2018 +0800 Commit: Craig Scott CommitDate: Wed Sep 12 14:44:59 2018 +0800 CMakeIOSInstallCombined: Prevent policy leakage Functions do not introduce a new policy scope, so surround these policy changes with a push-pop to prevent them from affecting the caller. diff --git a/Modules/CMakeIOSInstallCombined.cmake b/Modules/CMakeIOSInstallCombined.cmake index fad2e8f..418bafd 100644 --- a/Modules/CMakeIOSInstallCombined.cmake +++ b/Modules/CMakeIOSInstallCombined.cmake @@ -1,6 +1,8 @@ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. +cmake_policy(PUSH) +cmake_policy(SET CMP0057 NEW) # if IN_LIST # Function to print messages of this module function(_ios_install_combined_message) @@ -57,6 +59,7 @@ endfunction() # Get architectures of given SDK (iphonesimulator/iphoneos) function(_ios_install_combined_get_valid_archs sdk resultvar) + cmake_policy(PUSH) cmake_policy(SET CMP0007 NEW) if("${resultvar}" STREQUAL "") @@ -73,6 +76,8 @@ function(_ios_install_combined_get_valid_archs sdk resultvar) _ios_install_combined_message("Architectures (${sdk}): ${printable}") set("${resultvar}" "${valid_archs}" PARENT_SCOPE) + + cmake_policy(POP) endfunction() # Final target can contain more architectures that specified by SDK. This @@ -161,8 +166,6 @@ function(_ios_install_combined_keep_archs lib archs) endfunction() function(_ios_install_combined_detect_sdks this_sdk_var corr_sdk_var) - cmake_policy(SET CMP0057 NEW) - set(this_sdk "$ENV{PLATFORM_NAME}") if("${this_sdk}" STREQUAL "") message(FATAL_ERROR "Environment variable PLATFORM_NAME is empty") @@ -305,3 +308,5 @@ function(ios_install_combined target destination) _ios_install_combined_message("Install done: ${destination}") endfunction() + +cmake_policy(POP) ----------------------------------------------------------------------- Summary of changes: Modules/CMakeIOSInstallCombined.cmake | 9 ++++-- Modules/CSharpUtilities.cmake | 5 +++ Modules/FindBoost.cmake | 2 +- Modules/Internal/CPack/CPackDeb.cmake | 5 +++ Modules/Internal/CPack/CPackRPM.cmake | 5 +++ Modules/Platform/Android-Determine.cmake | 5 +++ Source/CTest/cmCTestMultiProcessHandler.cxx | 49 +++++++++++++++++++---------- Source/CTest/cmCTestMultiProcessHandler.h | 5 ++- Source/CTest/cmCTestRunTest.cxx | 5 +++ Source/CTest/cmCTestRunTest.h | 3 ++ Tests/RunCMake/Ninja/RunCMakeTest.cmake | 9 +++--- 11 files changed, 77 insertions(+), 25 deletions(-) hooks/post-receive -- CMake From kwrobot at kitware.com Fri Sep 14 13:35:02 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Fri, 14 Sep 2018 13:35:02 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-633-g333804f Message-ID: <20180914173502.E0BFD1252B4@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 333804fa0e12c3df9ef16fec163451cffda52df4 (commit) via a1ad0a699be3a2e9e3a18cc07c3bf069dedcfbfc (commit) via 9bbae5ae2870082a3e62596e25f53dcdadaa51a9 (commit) via f9cb6f618a72b0aa129006b79311f1fa7c9197bc (commit) via 18441a626901ec559d3ebaed7fd99f09360c5b39 (commit) via 2f708f5d65557ecbfe4ebe7c14b02dbba6bf0ffe (commit) via 94a75801c834891f47358e9f5763c56245dff3fe (commit) via 8a63b23d1606e4eb04e729369fa5ecccc2f5c7ea (commit) from 88e6e35358f0be59d2ceddb77fcb67091110b56c (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=333804fa0e12c3df9ef16fec163451cffda52df4 commit 333804fa0e12c3df9ef16fec163451cffda52df4 Merge: 88e6e35 a1ad0a6 Author: Brad King AuthorDate: Fri Sep 14 17:24:59 2018 +0000 Commit: Kitware Robot CommitDate: Fri Sep 14 13:25:07 2018 -0400 Merge topic 'out-of-dir-linking' a1ad0a699b target_link_libraries: Allow use with targets in other directories 9bbae5ae28 cmTarget: Future-proof AddLinkLibrary target lookup scope f9cb6f618a cmExportFileGenerator: Use cmGeneratorTarget::ResolveTargetReference 18441a6269 cmGeneratorTarget: Factor target name resolution out of link item resolution 2f708f5d65 Make internal TARGET_PROPERTY generator expressions more robust 94a75801c8 Android.mk: De-duplicate link libraries logic during export 8a63b23d16 cmGlobalGenerator: Remove unused FindLocalGenerator method Acked-by: Kitware Robot Reviewed-by: Patrick Stotko Merge-request: !2370 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=a1ad0a699be3a2e9e3a18cc07c3bf069dedcfbfc commit a1ad0a699be3a2e9e3a18cc07c3bf069dedcfbfc Author: Brad King AuthorDate: Fri Sep 7 12:59:52 2018 -0400 Commit: Brad King CommitDate: Wed Sep 12 13:06:36 2018 -0400 target_link_libraries: Allow use with targets in other directories Previously the command did not allow naming targets on the LHS that were not created in the calling directory. Lift this restriction to enable more flexible use by projects. Targets named on the RHS will need to be looked up during generation in the scope of the call site rather than the scope of the LHS target. Introduce an internal syntax in `[INTERFACE_]LINK_LIBRARIES` properties to specify target names that need to be looked up in a directory other than that containing the target on which the property is set. Add minimal documentation of the syntax to help users that encounter it. Unfortunately CMake previously did allow such calls in the case that only `INTERFACE` libraries are specified, but those libraries would be looked up in the target's directory rather than the caller's. Add policy `CMP0079` to enable the new behavior with new lookup scope in a compatible way. Fixes: #17943 diff --git a/Help/command/target_link_libraries.rst b/Help/command/target_link_libraries.rst index 1f0d69e..e1c374e 100644 --- a/Help/command/target_link_libraries.rst +++ b/Help/command/target_link_libraries.rst @@ -18,10 +18,13 @@ All of them have the general form:: target_link_libraries( ... ... ...) -The named ```` must have been created in the current directory by -a command such as :command:`add_executable` or :command:`add_library` and -must not be an :ref:`ALIAS target `. -Repeated calls for the same ```` append items in the order called. +The named ```` must have been created by a command such as +:command:`add_executable` or :command:`add_library` and must not be an +:ref:`ALIAS target `. If policy :policy:`CMP0079` is not +set to ``NEW`` then the target must have been created in the current +directory. Repeated calls for the same ```` append items in +the order called. + Each ```` may be: * **A library target name**: The generated link line will have the diff --git a/Help/manual/cmake-policies.7.rst b/Help/manual/cmake-policies.7.rst index 32a0118..8ecca4d 100644 --- a/Help/manual/cmake-policies.7.rst +++ b/Help/manual/cmake-policies.7.rst @@ -57,6 +57,7 @@ Policies Introduced by CMake 3.13 .. toctree:: :maxdepth: 1 + CMP0079: target_link_libraries allows use with targets in other directories. CMP0078: UseSWIG generates standard target names. CMP0077: option() honors normal variables. CMP0076: target_sources() command converts relative paths to absolute. diff --git a/Help/policy/CMP0079.rst b/Help/policy/CMP0079.rst new file mode 100644 index 0000000..0244d6c --- /dev/null +++ b/Help/policy/CMP0079.rst @@ -0,0 +1,40 @@ +CMP0079 +------- + +:command:`target_link_libraries` allows use with targets in other directories. + +Prior to CMake 3.13 the :command:`target_link_libraries` command did not +accept targets not created in the calling directory as its first argument +for calls that update the :prop_tgt:`LINK_LIBRARIES` of the target itself. +It did accidentally accept targets from other directories on calls that +only update the :prop_tgt:`INTERFACE_LINK_LIBRARIES`, but would simply +add entries to the property as if the call were made in the original +directory. Thus link interface libraries specified this way were always +looked up by generators in the scope of the original target rather than +in the scope that called :command:`target_link_libraries`. + +CMake 3.13 now allows the :command:`target_link_libraries` command to +be called from any directory to add link dependencies and link interface +libraries to targets created in other directories. The entries are added +to :prop_tgt:`LINK_LIBRARIES` and :prop_tgt:`INTERFACE_LINK_LIBRARIES` +using a special (internal) suffix to tell the generators to look up the +names in the calling scope rather than the scope that created the target. + +This policy provides compatibility with projects that already use +:command:`target_link_libraries` with the ``INTERFACE`` keyword +on a target in another directory to add :prop_tgt:`INTERFACE_LINK_LIBRARIES` +entries to be looked up in the target's directory. Such projects should +be updated to be aware of the new scoping rules in that case. + +The ``OLD`` behavior of this policy is to disallow +:command:`target_link_libraries` calls naming targets from another directory +except in the previously accidentally allowed case of using the ``INTERFACE`` +keyword only. The ``NEW`` behavior of this policy is to allow all such +calls but use the new scoping rules. + +This policy was introduced in CMake version 3.13. CMake version +|release| warns when the policy is not set and uses ``OLD`` behavior. +Use the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` +explicitly. + +.. include:: DEPRECATED.txt diff --git a/Help/prop_tgt/INTERFACE_LINK_LIBRARIES.rst b/Help/prop_tgt/INTERFACE_LINK_LIBRARIES.rst index 832d12b..bf7f72f 100644 --- a/Help/prop_tgt/INTERFACE_LINK_LIBRARIES.rst +++ b/Help/prop_tgt/INTERFACE_LINK_LIBRARIES.rst @@ -17,6 +17,8 @@ with the syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)` manual for available expressions. See the :manual:`cmake-buildsystem(7)` manual for more on defining buildsystem properties. +.. include:: LINK_LIBRARIES_INDIRECTION.txt + Creating Relocatable Packages ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/Help/prop_tgt/LINK_LIBRARIES.rst b/Help/prop_tgt/LINK_LIBRARIES.rst index aa4b9f5..d88e798 100644 --- a/Help/prop_tgt/LINK_LIBRARIES.rst +++ b/Help/prop_tgt/LINK_LIBRARIES.rst @@ -15,3 +15,5 @@ Contents of ``LINK_LIBRARIES`` may use "generator expressions" with the syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)` manual for available expressions. See the :manual:`cmake-buildsystem(7)` manual for more on defining buildsystem properties. + +.. include:: LINK_LIBRARIES_INDIRECTION.txt diff --git a/Help/prop_tgt/LINK_LIBRARIES_INDIRECTION.txt b/Help/prop_tgt/LINK_LIBRARIES_INDIRECTION.txt new file mode 100644 index 0000000..1fdb6ad --- /dev/null +++ b/Help/prop_tgt/LINK_LIBRARIES_INDIRECTION.txt @@ -0,0 +1,10 @@ +.. note:: + A call to :command:`target_link_libraries( ...)` may update this + property on ````. If ```` was not created in the same + directory as the call then :command:`target_link_libraries` will add a + suffix of the form ``::@`` to each entry, where the + ``::@`` is a separator and the ```` is unspecified. + This tells the generators that the named libraries must be looked up in + the scope of the caller rather than in the scope in which the + ```` was created. Valid directory ids are stripped on export + by the :command:`install(EXPORT)` and :command:`export` commands. diff --git a/Help/release/dev/out-of-dir-linking.rst b/Help/release/dev/out-of-dir-linking.rst new file mode 100644 index 0000000..6166be6 --- /dev/null +++ b/Help/release/dev/out-of-dir-linking.rst @@ -0,0 +1,6 @@ +out-of-dir-linking +------------------ + +* The :command:`target_link_libraries` command may now be called + to modify targets created outside the current directory. + See policy :policy:`CMP0079`. diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 1bd98e2..efcfaf7 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -5648,11 +5648,38 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries( cmGeneratorTarget::TargetOrString cmGeneratorTarget::ResolveTargetReference( std::string const& name) const { + cmLocalGenerator const* lg = this->LocalGenerator; + std::string const* lookupName = &name; + + // When target_link_libraries() is called with a LHS target that is + // not created in the calling directory it adds a directory id suffix + // that we can use to look up the calling directory. It is that scope + // in which the item name is meaningful. This case is relatively rare + // so we allocate a separate string only when the directory id is present. + std::string::size_type pos = name.find(CMAKE_DIRECTORY_ID_SEP); + std::string plainName; + if (pos != std::string::npos) { + // We will look up the plain name without the directory id suffix. + plainName = name.substr(0, pos); + + // We will look up in the scope of the directory id. + // If we do not recognize the id then leave the original + // syntax in place to produce an indicative error later. + cmDirectoryId const dirId = + name.substr(pos + sizeof(CMAKE_DIRECTORY_ID_SEP) - 1); + if (cmLocalGenerator const* otherLG = + this->GlobalGenerator->FindLocalGenerator(dirId)) { + lg = otherLG; + lookupName = &plainName; + } + } + TargetOrString resolved; - if (cmGeneratorTarget* tgt = - this->LocalGenerator->FindGeneratorTargetToUse(name)) { + if (cmGeneratorTarget* tgt = lg->FindGeneratorTargetToUse(*lookupName)) { resolved.Target = tgt; + } else if (lookupName == &plainName) { + resolved.String = std::move(plainName); } else { resolved.String = name; } diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 0aba67c..8a8b3e4 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1139,11 +1139,14 @@ void cmGlobalGenerator::ClearEnabledLanguages() void cmGlobalGenerator::CreateLocalGenerators() { + this->LocalGeneratorSearchIndex.clear(); cmDeleteAll(this->LocalGenerators); this->LocalGenerators.clear(); this->LocalGenerators.reserve(this->Makefiles.size()); for (cmMakefile* m : this->Makefiles) { - this->LocalGenerators.push_back(this->CreateLocalGenerator(m)); + cmLocalGenerator* lg = this->CreateLocalGenerator(m); + this->LocalGenerators.push_back(lg); + this->IndexLocalGenerator(lg); } } @@ -1661,6 +1664,7 @@ void cmGlobalGenerator::ClearGeneratorMembers() this->TargetSearchIndex.clear(); this->GeneratorTargetSearchIndex.clear(); this->MakefileSearchIndex.clear(); + this->LocalGeneratorSearchIndex.clear(); this->ProjectMap.clear(); this->RuleHashes.clear(); this->DirectoryContentMap.clear(); @@ -2130,6 +2134,17 @@ cmMakefile* cmGlobalGenerator::FindMakefile(const std::string& start_dir) const return nullptr; } +cmLocalGenerator* cmGlobalGenerator::FindLocalGenerator( + cmDirectoryId const& id) const +{ + LocalGeneratorMap::const_iterator i = + this->LocalGeneratorSearchIndex.find(id.String); + if (i != this->LocalGeneratorSearchIndex.end()) { + return i->second; + } + return nullptr; +} + void cmGlobalGenerator::AddAlias(const std::string& name, std::string const& tgtName) { @@ -2184,6 +2199,12 @@ void cmGlobalGenerator::IndexMakefile(cmMakefile* mf) MakefileMap::value_type(mf->GetCurrentSourceDirectory(), mf)); } +void cmGlobalGenerator::IndexLocalGenerator(cmLocalGenerator* lg) +{ + cmDirectoryId id = lg->GetMakefile()->GetDirectoryId(); + this->LocalGeneratorSearchIndex[id.String] = lg; +} + cmTarget* cmGlobalGenerator::FindTargetImpl(std::string const& name) const { TargetMap::const_iterator i = this->TargetSearchIndex.find(name); diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 6b972eb..f240f1d 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -26,6 +26,9 @@ # include "cmFileLockPool.h" #endif +#define CMAKE_DIRECTORY_ID_SEP "::@" + +class cmDirectoryId; class cmExportBuildFileGenerator; class cmExternalMakefileProjectGenerator; class cmGeneratorTarget; @@ -284,6 +287,7 @@ public: bool NameResolvesToFramework(const std::string& libname) const; cmMakefile* FindMakefile(const std::string& start_dir) const; + cmLocalGenerator* FindLocalGenerator(cmDirectoryId const& id) const; /** Append the subdirectory for the given configuration. If anything is appended the given prefix and suffix will be appended around it, which @@ -516,6 +520,7 @@ private: typedef std::unordered_map GeneratorTargetMap; typedef std::unordered_map MakefileMap; + typedef std::unordered_map LocalGeneratorMap; // Map efficiently from target name to cmTarget instance. // Do not use this structure for looping over all targets. // It contains both normal and globally visible imported targets. @@ -527,6 +532,11 @@ private: // It may not contain all of them (see note in IndexMakefile method). MakefileMap MakefileSearchIndex; + // Map efficiently from source directory path to cmLocalGenerator instance. + // Do not use this structure for looping over all directories. + // Its order is not deterministic. + LocalGeneratorMap LocalGeneratorSearchIndex; + cmMakefile* TryCompileOuterMakefile; // If you add a new map here, make sure it is copied // in EnableLanguagesFromGenerator @@ -585,6 +595,7 @@ private: std::string const& reason) const; void IndexMakefile(cmMakefile* mf); + void IndexLocalGenerator(cmLocalGenerator* lg); virtual const char* GetBuildIgnoreErrorsFlag() const { return nullptr; } diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 5498ad2..28e8195 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -11,6 +11,7 @@ #include #include // IWYU pragma: keep #include +#include #include #include @@ -48,6 +49,11 @@ class cmMessenger; +cmDirectoryId::cmDirectoryId(std::string s) + : String(std::move(s)) +{ +} + // default is not to be building executables cmMakefile::cmMakefile(cmGlobalGenerator* globalGenerator, cmStateSnapshot const& snapshot) @@ -111,6 +117,17 @@ cmMakefile::~cmMakefile() cmDeleteAll(this->EvaluationFiles); } +cmDirectoryId cmMakefile::GetDirectoryId() const +{ + // Use the instance pointer value to uniquely identify this directory. + // If we ever need to expose this to CMake language code we should + // add a read-only property in cmMakefile::GetProperty. + char buf[32]; + sprintf(buf, "<%p>", + static_cast(this)); // cast avoids format warning + return std::string(buf); +} + void cmMakefile::IssueMessage(cmake::MessageType t, std::string const& text) const { diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 0ab4371..54730b5 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -47,6 +47,14 @@ class cmTest; class cmTestGenerator; class cmVariableWatch; +/** A type-safe wrapper for a string representing a directory id. */ +class cmDirectoryId +{ +public: + cmDirectoryId(std::string s); + std::string String; +}; + /** \class cmMakefile * \brief Process the input CMakeLists.txt file. * @@ -75,6 +83,8 @@ public: */ ~cmMakefile(); + cmDirectoryId GetDirectoryId() const; + bool ReadListFile(const char* filename); bool ReadDependentFile(const char* filename, bool noPolicyScope = true); diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index 91ed924..4ffe803 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -230,7 +230,11 @@ class cmMakefile; SELECT(POLICY, CMP0077, "option() honors normal variables.", 3, 13, 0, \ cmPolicies::WARN) \ SELECT(POLICY, CMP0078, "UseSWIG generates standard target names.", 3, 13, \ - 0, cmPolicies::WARN) + 0, cmPolicies::WARN) \ + SELECT( \ + POLICY, CMP0079, \ + "target_link_libraries allows use with targets in other directories.", 3, \ + 13, 0, cmPolicies::WARN) #define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1) #define CM_FOR_EACH_POLICY_ID(POLICY) \ diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 927b218..cd40223 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -745,20 +745,27 @@ void cmTarget::GetTllSignatureTraces(std::ostream& s, TLLSignature sig) const void cmTarget::AddLinkLibrary(cmMakefile& mf, const std::string& lib, cmTargetLinkLibraryType llt) { + this->AddLinkLibrary(mf, lib, lib, llt); +} + +void cmTarget::AddLinkLibrary(cmMakefile& mf, std::string const& lib, + std::string const& libRef, + cmTargetLinkLibraryType llt) +{ cmTarget* tgt = mf.FindTargetToUse(lib); { const bool isNonImportedTarget = tgt && !tgt->IsImported(); const std::string libName = (isNonImportedTarget && llt != GENERAL_LibraryType) - ? targetNameGenex(lib) - : lib; + ? targetNameGenex(libRef) + : libRef; this->AppendProperty( "LINK_LIBRARIES", this->GetDebugGeneratorExpressions(libName, llt).c_str()); } - if (cmGeneratorExpression::Find(lib) != std::string::npos || + if (cmGeneratorExpression::Find(lib) != std::string::npos || lib != libRef || (tgt && (tgt->GetType() == cmStateEnums::INTERFACE_LIBRARY || tgt->GetType() == cmStateEnums::OBJECT_LIBRARY)) || diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 7a3ab65..1f380df 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -142,6 +142,9 @@ public: void AddLinkLibrary(cmMakefile& mf, const std::string& lib, cmTargetLinkLibraryType llt); + void AddLinkLibrary(cmMakefile& mf, std::string const& lib, + std::string const& libRef, cmTargetLinkLibraryType llt); + enum TLLSignature { KeywordTLLSignature, diff --git a/Source/cmTargetLinkLibrariesCommand.cxx b/Source/cmTargetLinkLibrariesCommand.cxx index 1bbcf46..ad33f98 100644 --- a/Source/cmTargetLinkLibrariesCommand.cxx +++ b/Source/cmTargetLinkLibrariesCommand.cxx @@ -359,30 +359,53 @@ bool cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib, } } + bool warnRemoteInterface = false; + bool rejectRemoteLinking = false; + bool encodeRemoteReference = false; + if (this->Makefile != this->Target->GetMakefile()) { + // The LHS target was created in another directory. + switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0079)) { + case cmPolicies::WARN: + warnRemoteInterface = true; + CM_FALLTHROUGH; + case cmPolicies::OLD: + rejectRemoteLinking = true; + break; + case cmPolicies::REQUIRED_ALWAYS: + case cmPolicies::REQUIRED_IF_USED: + case cmPolicies::NEW: + encodeRemoteReference = true; + break; + } + } + + std::string libRef; + if (encodeRemoteReference && !cmSystemTools::FileIsFullPath(lib)) { + // This is a library name added by a caller that is not in the + // same directory as the target was created. Add a suffix to + // the name to tell ResolveLinkItem to look up the name in the + // caller's directory. + cmDirectoryId const dirId = this->Makefile->GetDirectoryId(); + libRef = lib + CMAKE_DIRECTORY_ID_SEP + dirId.String; + } else { + // This is an absolute path or a library name added by a caller + // in the same directory as the target was created. We can use + // the original name directly. + libRef = lib; + } + // Handle normal case where the command was called with another keyword than // INTERFACE / LINK_INTERFACE_LIBRARIES or none at all. (The "LINK_LIBRARIES" // property of the target on the LHS shall be populated.) if (this->CurrentProcessingState != ProcessingKeywordLinkInterface && this->CurrentProcessingState != ProcessingPlainLinkInterface) { - // Assure that the target on the LHS was created in the current directory. - cmTarget* t = - this->Makefile->FindLocalNonAliasTarget(this->Target->GetName()); - if (!t) { - const std::vector& importedTargets = - this->Makefile->GetOwnedImportedTargets(); - for (cmTarget* importedTarget : importedTargets) { - if (importedTarget->GetName() == this->Target->GetName()) { - t = importedTarget; - break; - } - } - } - if (!t) { + if (rejectRemoteLinking) { std::ostringstream e; e << "Attempt to add link library \"" << lib << "\" to target \"" << this->Target->GetName() - << "\" which is not built in this directory."; + << "\" which is not built in this directory.\n" + << "This is allowed only when policy CMP0079 is set to NEW."; this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); return false; } @@ -404,7 +427,20 @@ bool cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib, this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); } - this->Target->AddLinkLibrary(*this->Makefile, lib, llt); + this->Target->AddLinkLibrary(*this->Makefile, lib, libRef, llt); + } + + if (warnRemoteInterface) { + std::ostringstream w; + /* clang-format off */ + w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0079) << "\n" + "Target\n " << this->Target->GetName() << "\nis not created in this " + "directory. For compatibility with older versions of CMake, link " + "library\n " << lib << "\nwill be looked up in the directory in " + "which the target was created rather than in this calling " + "directory."; + /* clang-format on */ + this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str()); } // Handle (additional) case where the command was called with PRIVATE / @@ -415,9 +451,9 @@ bool cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib, this->CurrentProcessingState == ProcessingPlainPrivateInterface) { if (this->Target->GetType() == cmStateEnums::STATIC_LIBRARY) { std::string configLib = - this->Target->GetDebugGeneratorExpressions(lib, llt); - if (cmGeneratorExpression::IsValidTargetName(lib) || - cmGeneratorExpression::Find(lib) != std::string::npos) { + this->Target->GetDebugGeneratorExpressions(libRef, llt); + if (cmGeneratorExpression::IsValidTargetName(libRef) || + cmGeneratorExpression::Find(libRef) != std::string::npos) { configLib = "$"; } this->Target->AppendProperty("INTERFACE_LINK_LIBRARIES", @@ -431,7 +467,7 @@ bool cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib, // property of the target on the LHS shall be populated.) this->Target->AppendProperty( "INTERFACE_LINK_LIBRARIES", - this->Target->GetDebugGeneratorExpressions(lib, llt).c_str()); + this->Target->GetDebugGeneratorExpressions(libRef, llt).c_str()); // Stop processing if called without any keyword. if (this->CurrentProcessingState == ProcessingLinkLibraries) { @@ -464,12 +500,12 @@ bool cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib, for (std::string const& dc : debugConfigs) { prop = "LINK_INTERFACE_LIBRARIES_"; prop += dc; - this->Target->AppendProperty(prop, lib.c_str()); + this->Target->AppendProperty(prop, libRef.c_str()); } } if (llt == OPTIMIZED_LibraryType || llt == GENERAL_LibraryType) { // Put in the non-DEBUG configuration interfaces. - this->Target->AppendProperty("LINK_INTERFACE_LIBRARIES", lib.c_str()); + this->Target->AppendProperty("LINK_INTERFACE_LIBRARIES", libRef.c_str()); // Make sure the DEBUG configuration interfaces exist so that the // general one will not be used as a fall-back. diff --git a/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt b/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt index e11f980..85ce1f7 100644 --- a/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt +++ b/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt @@ -130,3 +130,15 @@ target_link_libraries(newsignature1 PRIVATE depC INTERFACE depD PUBLIC depB PRIV assert_property(newsignature1 INTERFACE_LINK_LIBRARIES "depD;depB") assert_property(newsignature1 LINK_LIBRARIES "depC;depB;subdirlib") + +#---------------------------------------------------------------------------- +# Test cross-directory linking. +cmake_policy(PUSH) +cmake_policy(SET CMP0079 NEW) +add_executable(TopDir TopDir.c) +add_subdirectory(SubDirA) +add_subdirectory(SubDirB) +target_link_libraries(SubDirB TopDirImported) +add_library(TopDirImported IMPORTED INTERFACE) +target_compile_definitions(TopDirImported INTERFACE DEF_TopDirImported) +cmake_policy(POP) diff --git a/Tests/CMakeCommands/target_link_libraries/SubDirA/CMakeLists.txt b/Tests/CMakeCommands/target_link_libraries/SubDirA/CMakeLists.txt new file mode 100644 index 0000000..4dae103 --- /dev/null +++ b/Tests/CMakeCommands/target_link_libraries/SubDirA/CMakeLists.txt @@ -0,0 +1,15 @@ +add_executable(SubDirA SubDirA.c) + +# Link to a target imported in this directory that would not normally +# be visible to the directory in which TopDir is defined. +target_link_libraries(TopDir PUBLIC SameNameImported) + +# Link SubDirA to a target imported in this directory that has the same +# name as a target imported in SubDirB's directory. SubDirB will also +# tell us to link its copy. At compile time we verify both are linked. +target_link_libraries(SubDirA PRIVATE SameNameImported) + +# Import a target with the same name as a target imported in SubDirB. +# Distinguish this copy by having a unique usage requirement. +add_library(SameNameImported IMPORTED INTERFACE) +target_compile_definitions(SameNameImported INTERFACE DEF_SameNameImportedSubDirA) diff --git a/Tests/CMakeCommands/target_link_libraries/SubDirA/SubDirA.c b/Tests/CMakeCommands/target_link_libraries/SubDirA/SubDirA.c new file mode 100644 index 0000000..4706bb9 --- /dev/null +++ b/Tests/CMakeCommands/target_link_libraries/SubDirA/SubDirA.c @@ -0,0 +1,14 @@ +#ifndef DEF_SameNameImportedSubDirA +# error "DEF_SameNameImportedSubDirA is not defined but should be!" +#endif +#ifndef DEF_SameNameImportedSubDirB +# error "DEF_SameNameImportedSubDirB is not defined but should be!" +#endif +#ifdef DEF_TopDirImported +# error "DEF_TopDirImported is defined but should not be!" +#endif + +int main(void) +{ + return 0; +} diff --git a/Tests/CMakeCommands/target_link_libraries/SubDirB/CMakeLists.txt b/Tests/CMakeCommands/target_link_libraries/SubDirB/CMakeLists.txt new file mode 100644 index 0000000..7c918e6 --- /dev/null +++ b/Tests/CMakeCommands/target_link_libraries/SubDirB/CMakeLists.txt @@ -0,0 +1,15 @@ +add_executable(SubDirB SubDirB.c) + +# Link to a target imported in this directory that would not normally +# be visible to the directory in which TopDir is defined. +target_link_libraries(TopDir PUBLIC SameNameImported) + +# Link SubDirA to a target imported in this directory that has the same +# name as a target imported in SubDirA's directory. We verify when +# compiling SubDirA that it sees our target and its own. +target_link_libraries(SubDirA PRIVATE SameNameImported) + +# Import a target with the same name as a target imported in SubDirA. +# Distinguish this copy by having a unique usage requirement. +add_library(SameNameImported IMPORTED INTERFACE) +target_compile_definitions(SameNameImported INTERFACE DEF_SameNameImportedSubDirB) diff --git a/Tests/CMakeCommands/target_link_libraries/SubDirB/SubDirB.c b/Tests/CMakeCommands/target_link_libraries/SubDirB/SubDirB.c new file mode 100644 index 0000000..6e56729 --- /dev/null +++ b/Tests/CMakeCommands/target_link_libraries/SubDirB/SubDirB.c @@ -0,0 +1,14 @@ +#ifdef DEF_SameNameImportedSubDirA +# error "DEF_SameNameImportedSubDirA is defined but should not be!" +#endif +#ifdef DEF_SameNameImportedSubDirB +# error "DEF_SameNameImportedSubDirB is defined but should not be!" +#endif +#ifndef DEF_TopDirImported +# error "DEF_TopDirImported is not defined but should be!" +#endif + +int main(void) +{ + return 0; +} diff --git a/Tests/CMakeCommands/target_link_libraries/TopDir.c b/Tests/CMakeCommands/target_link_libraries/TopDir.c new file mode 100644 index 0000000..4706bb9 --- /dev/null +++ b/Tests/CMakeCommands/target_link_libraries/TopDir.c @@ -0,0 +1,14 @@ +#ifndef DEF_SameNameImportedSubDirA +# error "DEF_SameNameImportedSubDirA is not defined but should be!" +#endif +#ifndef DEF_SameNameImportedSubDirB +# error "DEF_SameNameImportedSubDirB is not defined but should be!" +#endif +#ifdef DEF_TopDirImported +# error "DEF_TopDirImported is defined but should not be!" +#endif + +int main(void) +{ + return 0; +} diff --git a/Tests/ExportImport/Export/CMakeLists.txt b/Tests/ExportImport/Export/CMakeLists.txt index fdb2fa1..cb048be 100644 --- a/Tests/ExportImport/Export/CMakeLists.txt +++ b/Tests/ExportImport/Export/CMakeLists.txt @@ -155,6 +155,13 @@ add_library(testStaticLibRequiredPrivate testStaticLibRequiredPrivate.c) target_link_libraries(testLibDepends PRIVATE testStaticLibRequiredPrivate) cmake_policy(POP) +cmake_policy(PUSH) +cmake_policy(SET CMP0079 NEW) +add_library(TopDirLib STATIC testTopDirLib.c) +add_subdirectory(SubDirLinkA) +add_subdirectory(SubDirLinkB) +cmake_policy(POP) + macro(add_include_lib _libName) file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${_libName}.c" "/* no content */\n") add_library(${_libName} "${CMAKE_CURRENT_BINARY_DIR}/${_libName}.c") @@ -508,6 +515,7 @@ install( testLibCycleA testLibCycleB testLibNoSONAME cmp0022NEW cmp0022OLD + TopDirLib SubDirLinkA systemlib EXPORT exp RUNTIME DESTINATION $<1:bin>$<0:/wrong> @@ -566,6 +574,7 @@ export(TARGETS testExe1 testLib1 testLib2 testLib3 testSharedLibRequired testSharedLibRequiredUser testSharedLibRequiredUser2 testSharedLibDepends renamed_on_export cmp0022NEW cmp0022OLD + TopDirLib SubDirLinkA systemlib NAMESPACE bld_ FILE ExportBuildTree.cmake diff --git a/Tests/ExportImport/Export/SubDirLinkA/CMakeLists.txt b/Tests/ExportImport/Export/SubDirLinkA/CMakeLists.txt new file mode 100644 index 0000000..1c3c9dc --- /dev/null +++ b/Tests/ExportImport/Export/SubDirLinkA/CMakeLists.txt @@ -0,0 +1,6 @@ +add_library(SubDirLinkAImported IMPORTED INTERFACE) +target_compile_definitions(SubDirLinkAImported INTERFACE DEF_SubDirLinkAImportedForExport) + +target_link_libraries(TopDirLib PUBLIC SubDirLinkAImported) + +add_library(SubDirLinkA STATIC SubDirLinkA.c) diff --git a/Tests/ExportImport/Export/SubDirLinkA/SubDirLinkA.c b/Tests/ExportImport/Export/SubDirLinkA/SubDirLinkA.c new file mode 100644 index 0000000..abf76f5 --- /dev/null +++ b/Tests/ExportImport/Export/SubDirLinkA/SubDirLinkA.c @@ -0,0 +1,11 @@ +#ifdef DEF_SubDirLinkAImportedForExport +# error "DEF_SubDirLinkAImportedForExport is defined but should not be!" +#endif +#ifndef DEF_SubDirLinkBImportedForExport +# error "DEF_SubDirLinkBImportedForExport is not defined but should be!" +#endif + +int testSubDirLinkA(void) +{ + return 0; +} diff --git a/Tests/ExportImport/Export/SubDirLinkB/CMakeLists.txt b/Tests/ExportImport/Export/SubDirLinkB/CMakeLists.txt new file mode 100644 index 0000000..22e168f --- /dev/null +++ b/Tests/ExportImport/Export/SubDirLinkB/CMakeLists.txt @@ -0,0 +1,4 @@ +add_library(SubDirLinkBImported IMPORTED INTERFACE) +target_compile_definitions(SubDirLinkBImported INTERFACE DEF_SubDirLinkBImportedForExport) + +target_link_libraries(SubDirLinkA PUBLIC SubDirLinkBImported) diff --git a/Tests/ExportImport/Export/testTopDirLib.c b/Tests/ExportImport/Export/testTopDirLib.c new file mode 100644 index 0000000..1ec68de --- /dev/null +++ b/Tests/ExportImport/Export/testTopDirLib.c @@ -0,0 +1,11 @@ +#ifndef DEF_SubDirLinkAImportedForExport +# error "DEF_SubDirLinkAImportedForExport is not defined but should be!" +#endif +#ifdef DEF_SubDirLinkBImportedForExport +# error "DEF_SubDirLinkBImportedForExport is defined but should not be!" +#endif + +int testTopDirLib(void) +{ + return 0; +} diff --git a/Tests/ExportImport/Import/A/CMakeLists.txt b/Tests/ExportImport/Import/A/CMakeLists.txt index 7510d7e..8791a19 100644 --- a/Tests/ExportImport/Import/A/CMakeLists.txt +++ b/Tests/ExportImport/Import/A/CMakeLists.txt @@ -1,3 +1,9 @@ +# Prepare imported targets that the exported project itself imported. +add_library(SubDirLinkAImported IMPORTED INTERFACE) +target_compile_definitions(SubDirLinkAImported INTERFACE DEF_SubDirLinkAImportedForImport) +add_library(SubDirLinkBImported IMPORTED INTERFACE) +target_compile_definitions(SubDirLinkBImported INTERFACE DEF_SubDirLinkBImportedForImport) + # Import targets from the exported build tree. include(${Import_BINARY_DIR}/../Export/ExportBuildTree.cmake) @@ -158,6 +164,11 @@ target_link_libraries(cmp0022OLD_exp_test exp_cmp0022OLD) add_executable(cmp0022NEW_exp_test cmp0022NEW_test_vs6_2.cpp) target_link_libraries(cmp0022NEW_exp_test exp_cmp0022NEW) +add_executable(SubDirLink_bld SubDirLink.c) +target_link_libraries(SubDirLink_bld PRIVATE bld_TopDirLib bld_SubDirLinkA) +add_executable(SubDirLink_exp SubDirLink.c) +target_link_libraries(SubDirLink_exp PRIVATE exp_TopDirLib exp_SubDirLinkA) + # Try building a plugin to an executable imported from the build tree. add_library(imp_mod1b MODULE imp_mod1.c) target_link_libraries(imp_mod1b bld_testExe2) diff --git a/Tests/ExportImport/Import/A/SubDirLink.c b/Tests/ExportImport/Import/A/SubDirLink.c new file mode 100644 index 0000000..eb4b860 --- /dev/null +++ b/Tests/ExportImport/Import/A/SubDirLink.c @@ -0,0 +1,14 @@ +#ifndef DEF_SubDirLinkAImportedForImport +# error "DEF_SubDirLinkAImportedForImport is not defined but should be!" +#endif +#ifndef DEF_SubDirLinkBImportedForImport +# error "DEF_SubDirLinkBImportedForImport is not defined but should be!" +#endif + +extern int testTopDirLib(void); +extern int testSubDirLinkA(void); + +int main(void) +{ + return (testTopDirLib() + testSubDirLinkA() + 0); +} diff --git a/Tests/RunCMake/target_link_libraries/CMP0079-iface-NEW-stdout.txt b/Tests/RunCMake/target_link_libraries/CMP0079-iface-NEW-stdout.txt new file mode 100644 index 0000000..89cd806 --- /dev/null +++ b/Tests/RunCMake/target_link_libraries/CMP0079-iface-NEW-stdout.txt @@ -0,0 +1 @@ +-- INTERFACE_LINK_LIBRARIES='foo::@<[Xx0-9A-Fa-f]+>' diff --git a/Tests/RunCMake/target_link_libraries/CMP0079-iface-NEW.cmake b/Tests/RunCMake/target_link_libraries/CMP0079-iface-NEW.cmake new file mode 100644 index 0000000..82486c4 --- /dev/null +++ b/Tests/RunCMake/target_link_libraries/CMP0079-iface-NEW.cmake @@ -0,0 +1,2 @@ +cmake_policy(SET CMP0079 NEW) +include(CMP0079-iface-common.cmake) diff --git a/Tests/RunCMake/target_link_libraries/CMP0079-iface-OLD-stdout.txt b/Tests/RunCMake/target_link_libraries/CMP0079-iface-OLD-stdout.txt new file mode 100644 index 0000000..e575e16 --- /dev/null +++ b/Tests/RunCMake/target_link_libraries/CMP0079-iface-OLD-stdout.txt @@ -0,0 +1 @@ +-- INTERFACE_LINK_LIBRARIES='foo' diff --git a/Tests/RunCMake/target_link_libraries/CMP0079-iface-OLD.cmake b/Tests/RunCMake/target_link_libraries/CMP0079-iface-OLD.cmake new file mode 100644 index 0000000..e04a2bb --- /dev/null +++ b/Tests/RunCMake/target_link_libraries/CMP0079-iface-OLD.cmake @@ -0,0 +1,2 @@ +cmake_policy(SET CMP0079 OLD) +include(CMP0079-iface-common.cmake) diff --git a/Tests/RunCMake/target_link_libraries/CMP0079-iface-WARN-stderr.txt b/Tests/RunCMake/target_link_libraries/CMP0079-iface-WARN-stderr.txt new file mode 100644 index 0000000..6dd7d30 --- /dev/null +++ b/Tests/RunCMake/target_link_libraries/CMP0079-iface-WARN-stderr.txt @@ -0,0 +1,17 @@ +^CMake Warning \(dev\) at CMP0079-iface/CMakeLists.txt:[0-9]+ \(target_link_libraries\): + Policy CMP0079 is not set: target_link_libraries allows use with targets in + other directories. Run "cmake --help-policy CMP0079" for policy details. + Use the cmake_policy command to set the policy and suppress this warning. + + Target + + top + + is not created in this directory. For compatibility with older versions of + CMake, link library + + foo + + will be looked up in the directory in which the target was created rather + than in this calling directory. +This warning is for project developers. Use -Wno-dev to suppress it.$ diff --git a/Tests/RunCMake/target_link_libraries/CMP0079-iface-WARN-stdout.txt b/Tests/RunCMake/target_link_libraries/CMP0079-iface-WARN-stdout.txt new file mode 100644 index 0000000..e575e16 --- /dev/null +++ b/Tests/RunCMake/target_link_libraries/CMP0079-iface-WARN-stdout.txt @@ -0,0 +1 @@ +-- INTERFACE_LINK_LIBRARIES='foo' diff --git a/Tests/RunCMake/target_link_libraries/CMP0079-iface-WARN.cmake b/Tests/RunCMake/target_link_libraries/CMP0079-iface-WARN.cmake new file mode 100644 index 0000000..2041893 --- /dev/null +++ b/Tests/RunCMake/target_link_libraries/CMP0079-iface-WARN.cmake @@ -0,0 +1 @@ +include(CMP0079-iface-common.cmake) diff --git a/Tests/RunCMake/target_link_libraries/CMP0079-iface-common.cmake b/Tests/RunCMake/target_link_libraries/CMP0079-iface-common.cmake new file mode 100644 index 0000000..3982ff2 --- /dev/null +++ b/Tests/RunCMake/target_link_libraries/CMP0079-iface-common.cmake @@ -0,0 +1,6 @@ +enable_language(C) + +add_executable(top empty.c) +add_subdirectory(CMP0079-iface) +get_property(libs TARGET top PROPERTY INTERFACE_LINK_LIBRARIES) +message(STATUS "INTERFACE_LINK_LIBRARIES='${libs}'") diff --git a/Tests/RunCMake/target_link_libraries/CMP0079-iface/CMakeLists.txt b/Tests/RunCMake/target_link_libraries/CMP0079-iface/CMakeLists.txt new file mode 100644 index 0000000..4b15b32 --- /dev/null +++ b/Tests/RunCMake/target_link_libraries/CMP0079-iface/CMakeLists.txt @@ -0,0 +1 @@ +target_link_libraries(top INTERFACE foo) diff --git a/Tests/RunCMake/target_link_libraries/SubDirTarget-result.txt b/Tests/RunCMake/target_link_libraries/CMP0079-link-NEW-bogus-result.txt similarity index 100% copy from Tests/RunCMake/target_link_libraries/SubDirTarget-result.txt copy to Tests/RunCMake/target_link_libraries/CMP0079-link-NEW-bogus-result.txt diff --git a/Tests/RunCMake/target_link_libraries/CMP0079-link-NEW-bogus-stderr.txt b/Tests/RunCMake/target_link_libraries/CMP0079-link-NEW-bogus-stderr.txt new file mode 100644 index 0000000..b9fe3f6 --- /dev/null +++ b/Tests/RunCMake/target_link_libraries/CMP0079-link-NEW-bogus-stderr.txt @@ -0,0 +1,6 @@ +^CMake Error at CMP0079-link-NEW-bogus.cmake:[0-9]+ \(add_executable\): + Target "top" links to target "foo::@<0xdeadbeef>" but the target was not + found. Perhaps a find_package\(\) call is missing for an IMPORTED target, or + an ALIAS target is missing\? +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/target_link_libraries/CMP0079-link-NEW-bogus.cmake b/Tests/RunCMake/target_link_libraries/CMP0079-link-NEW-bogus.cmake new file mode 100644 index 0000000..8622f14 --- /dev/null +++ b/Tests/RunCMake/target_link_libraries/CMP0079-link-NEW-bogus.cmake @@ -0,0 +1,6 @@ +cmake_policy(SET CMP0028 NEW) +cmake_policy(SET CMP0079 NEW) +enable_language(C) + +add_executable(top empty.c) +set_property(TARGET top APPEND PROPERTY LINK_LIBRARIES "foo::@<0xdeadbeef>") diff --git a/Tests/RunCMake/target_link_libraries/CMP0079-link-NEW-stdout.txt b/Tests/RunCMake/target_link_libraries/CMP0079-link-NEW-stdout.txt new file mode 100644 index 0000000..84b30bd --- /dev/null +++ b/Tests/RunCMake/target_link_libraries/CMP0079-link-NEW-stdout.txt @@ -0,0 +1 @@ +-- LINK_LIBRARIES='foo::@<[Xx0-9A-Fa-f]+>' diff --git a/Tests/RunCMake/target_link_libraries/CMP0079-link-NEW.cmake b/Tests/RunCMake/target_link_libraries/CMP0079-link-NEW.cmake new file mode 100644 index 0000000..72e4574 --- /dev/null +++ b/Tests/RunCMake/target_link_libraries/CMP0079-link-NEW.cmake @@ -0,0 +1,2 @@ +cmake_policy(SET CMP0079 NEW) +include(CMP0079-link-common.cmake) diff --git a/Tests/RunCMake/target_link_libraries/SubDirTarget-result.txt b/Tests/RunCMake/target_link_libraries/CMP0079-link-OLD-result.txt similarity index 100% copy from Tests/RunCMake/target_link_libraries/SubDirTarget-result.txt copy to Tests/RunCMake/target_link_libraries/CMP0079-link-OLD-result.txt diff --git a/Tests/RunCMake/target_link_libraries/CMP0079-link-OLD-stderr.txt b/Tests/RunCMake/target_link_libraries/CMP0079-link-OLD-stderr.txt new file mode 100644 index 0000000..0b4c4c6 --- /dev/null +++ b/Tests/RunCMake/target_link_libraries/CMP0079-link-OLD-stderr.txt @@ -0,0 +1,5 @@ +^CMake Error at CMP0079-link/CMakeLists.txt:[0-9]+ \(target_link_libraries\): + Attempt to add link library "foo" to target "top" which is not built in + this directory. + + This is allowed only when policy CMP0079 is set to NEW.$ diff --git a/Tests/RunCMake/target_link_libraries/CMP0079-link-OLD.cmake b/Tests/RunCMake/target_link_libraries/CMP0079-link-OLD.cmake new file mode 100644 index 0000000..caa7231 --- /dev/null +++ b/Tests/RunCMake/target_link_libraries/CMP0079-link-OLD.cmake @@ -0,0 +1,2 @@ +cmake_policy(SET CMP0079 OLD) +include(CMP0079-link-common.cmake) diff --git a/Tests/RunCMake/target_link_libraries/SubDirTarget-result.txt b/Tests/RunCMake/target_link_libraries/CMP0079-link-WARN-result.txt similarity index 100% rename from Tests/RunCMake/target_link_libraries/SubDirTarget-result.txt rename to Tests/RunCMake/target_link_libraries/CMP0079-link-WARN-result.txt diff --git a/Tests/RunCMake/target_link_libraries/CMP0079-link-WARN-stderr.txt b/Tests/RunCMake/target_link_libraries/CMP0079-link-WARN-stderr.txt new file mode 100644 index 0000000..0b4c4c6 --- /dev/null +++ b/Tests/RunCMake/target_link_libraries/CMP0079-link-WARN-stderr.txt @@ -0,0 +1,5 @@ +^CMake Error at CMP0079-link/CMakeLists.txt:[0-9]+ \(target_link_libraries\): + Attempt to add link library "foo" to target "top" which is not built in + this directory. + + This is allowed only when policy CMP0079 is set to NEW.$ diff --git a/Tests/RunCMake/target_link_libraries/CMP0079-link-WARN.cmake b/Tests/RunCMake/target_link_libraries/CMP0079-link-WARN.cmake new file mode 100644 index 0000000..e83818a --- /dev/null +++ b/Tests/RunCMake/target_link_libraries/CMP0079-link-WARN.cmake @@ -0,0 +1 @@ +include(CMP0079-link-common.cmake) diff --git a/Tests/RunCMake/target_link_libraries/CMP0079-link-common.cmake b/Tests/RunCMake/target_link_libraries/CMP0079-link-common.cmake new file mode 100644 index 0000000..4f9454f --- /dev/null +++ b/Tests/RunCMake/target_link_libraries/CMP0079-link-common.cmake @@ -0,0 +1,6 @@ +enable_language(C) + +add_executable(top empty.c) +add_subdirectory(CMP0079-link) +get_property(libs TARGET top PROPERTY LINK_LIBRARIES) +message(STATUS "LINK_LIBRARIES='${libs}'") diff --git a/Tests/RunCMake/target_link_libraries/CMP0079-link/CMakeLists.txt b/Tests/RunCMake/target_link_libraries/CMP0079-link/CMakeLists.txt new file mode 100644 index 0000000..8b2b3c9 --- /dev/null +++ b/Tests/RunCMake/target_link_libraries/CMP0079-link/CMakeLists.txt @@ -0,0 +1 @@ +target_link_libraries(top PUBLIC foo) diff --git a/Tests/RunCMake/target_link_libraries/CMakeLists.txt b/Tests/RunCMake/target_link_libraries/CMakeLists.txt index 12cd3c7..8f85fbf 100644 --- a/Tests/RunCMake/target_link_libraries/CMakeLists.txt +++ b/Tests/RunCMake/target_link_libraries/CMakeLists.txt @@ -1,3 +1,3 @@ cmake_minimum_required(VERSION 2.8.4) project(${RunCMake_TEST} NONE) -include(${RunCMake_TEST}.cmake) +include(${RunCMake_TEST}.cmake NO_POLICY_SCOPE) diff --git a/Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake b/Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake index 97b0888..a041d6d 100644 --- a/Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake +++ b/Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake @@ -4,11 +4,17 @@ run_cmake(CMP0023-WARN) run_cmake(CMP0023-NEW) run_cmake(CMP0023-WARN-2) run_cmake(CMP0023-NEW-2) +run_cmake(CMP0079-iface-WARN) +run_cmake(CMP0079-iface-OLD) +run_cmake(CMP0079-iface-NEW) +run_cmake(CMP0079-link-WARN) +run_cmake(CMP0079-link-OLD) +run_cmake(CMP0079-link-NEW) +run_cmake(CMP0079-link-NEW-bogus) run_cmake(ImportedTarget) run_cmake(ImportedTargetFailure) run_cmake(MixedSignature) run_cmake(Separate-PRIVATE-LINK_PRIVATE-uses) -run_cmake(SubDirTarget) run_cmake(SharedDepNotTarget) run_cmake(StaticPrivateDepNotExported) run_cmake(StaticPrivateDepNotTarget) diff --git a/Tests/RunCMake/target_link_libraries/SubDirTarget-stderr.txt b/Tests/RunCMake/target_link_libraries/SubDirTarget-stderr.txt deleted file mode 100644 index 5cd1f23..0000000 --- a/Tests/RunCMake/target_link_libraries/SubDirTarget-stderr.txt +++ /dev/null @@ -1,5 +0,0 @@ -^CMake Error at SubDirTarget.cmake:[0-9]+ \(target_link_libraries\): - Attempt to add link library "m" to target "subexe" which is not built in - this directory. -Call Stack \(most recent call first\): - CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/target_link_libraries/SubDirTarget.cmake b/Tests/RunCMake/target_link_libraries/SubDirTarget.cmake deleted file mode 100644 index 32431ce..0000000 --- a/Tests/RunCMake/target_link_libraries/SubDirTarget.cmake +++ /dev/null @@ -1,3 +0,0 @@ -enable_language(C) -add_subdirectory(SubDirTarget) -target_link_libraries(subexe m) diff --git a/Tests/RunCMake/target_link_libraries/SubDirTarget/CMakeLists.txt b/Tests/RunCMake/target_link_libraries/SubDirTarget/CMakeLists.txt deleted file mode 100644 index b0b2380..0000000 --- a/Tests/RunCMake/target_link_libraries/SubDirTarget/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_executable(subexe ../empty.c) https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=9bbae5ae2870082a3e62596e25f53dcdadaa51a9 commit 9bbae5ae2870082a3e62596e25f53dcdadaa51a9 Author: Brad King AuthorDate: Mon Sep 10 13:07:50 2018 -0400 Commit: Brad King CommitDate: Wed Sep 12 12:46:51 2018 -0400 cmTarget: Future-proof AddLinkLibrary target lookup scope The `AddLinkLibrary` method takes a `cmMakefile` pointer to represent the scope of the caller that wants to link to the named library. Currently in all call sites this is the same as the target's `Makefile` member, but in principle the library named by the caller is visible in its scope so we should use the `cmMakefile` it provided to look up the library target. diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index cfcb31a..927b218 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -745,7 +745,7 @@ void cmTarget::GetTllSignatureTraces(std::ostream& s, TLLSignature sig) const void cmTarget::AddLinkLibrary(cmMakefile& mf, const std::string& lib, cmTargetLinkLibraryType llt) { - cmTarget* tgt = this->Makefile->FindTargetToUse(lib); + cmTarget* tgt = mf.FindTargetToUse(lib); { const bool isNonImportedTarget = tgt && !tgt->IsImported(); https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=f9cb6f618a72b0aa129006b79311f1fa7c9197bc commit f9cb6f618a72b0aa129006b79311f1fa7c9197bc Author: Brad King AuthorDate: Mon Sep 10 09:42:19 2018 -0400 Commit: Brad King CommitDate: Wed Sep 12 12:46:51 2018 -0400 cmExportFileGenerator: Use cmGeneratorTarget::ResolveTargetReference Avoid calling `FindGeneratorTargetToUse` directly. diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index 1c5040a..67df6fd 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -567,14 +567,17 @@ bool cmExportFileGenerator::AddTargetNamespace( std::string& input, cmGeneratorTarget* target, std::vector& missingTargets) { - cmLocalGenerator* lg = target->GetLocalGenerator(); + cmGeneratorTarget::TargetOrString resolved = + target->ResolveTargetReference(input); - cmGeneratorTarget* tgt = lg->FindGeneratorTargetToUse(input); + cmGeneratorTarget* tgt = resolved.Target; if (!tgt) { + input = resolved.String; return false; } if (tgt->IsImported()) { + input = tgt->GetName(); return true; } if (this->ExportedTargets.find(tgt) != this->ExportedTargets.end()) { @@ -584,6 +587,8 @@ bool cmExportFileGenerator::AddTargetNamespace( this->HandleMissingTarget(namespacedTarget, missingTargets, target, tgt); if (!namespacedTarget.empty()) { input = namespacedTarget; + } else { + input = tgt->GetName(); } } return true; https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=18441a626901ec559d3ebaed7fd99f09360c5b39 commit 18441a626901ec559d3ebaed7fd99f09360c5b39 Author: Brad King AuthorDate: Mon Sep 10 10:11:57 2018 -0400 Commit: Brad King CommitDate: Wed Sep 12 12:46:51 2018 -0400 cmGeneratorTarget: Factor target name resolution out of link item resolution diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 40ee01e..1bd98e2 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -5645,24 +5645,38 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries( } } +cmGeneratorTarget::TargetOrString cmGeneratorTarget::ResolveTargetReference( + std::string const& name) const +{ + TargetOrString resolved; + + if (cmGeneratorTarget* tgt = + this->LocalGenerator->FindGeneratorTargetToUse(name)) { + resolved.Target = tgt; + } else { + resolved.String = name; + } + + return resolved; +} + cmLinkItem cmGeneratorTarget::ResolveLinkItem(std::string const& name) const { - cmGeneratorTarget* tgt = - this->LocalGenerator->FindGeneratorTargetToUse(name); + TargetOrString resolved = this->ResolveTargetReference(name); + + if (!resolved.Target) { + return cmLinkItem(resolved.String); + } // Skip targets that will not really be linked. This is probably a // name conflict between an external library and an executable // within the project. - if (tgt && tgt->GetType() == cmStateEnums::EXECUTABLE && - !tgt->IsExecutableWithExports()) { - tgt = nullptr; - } - - if (tgt) { - return cmLinkItem(tgt); + if (resolved.Target->GetType() == cmStateEnums::EXECUTABLE && + !resolved.Target->IsExecutableWithExports()) { + return cmLinkItem(resolved.Target->GetName()); } - return cmLinkItem(name); + return cmLinkItem(resolved.Target); } std::string cmGeneratorTarget::GetPDBDirectory(const std::string& config) const diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index a847e21..9d8c9f5 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -357,6 +357,13 @@ public: cmOptionalLinkImplementation& impl, const cmGeneratorTarget* head) const; + struct TargetOrString + { + std::string String; + cmGeneratorTarget* Target = nullptr; + }; + TargetOrString ResolveTargetReference(std::string const& name) const; + cmLinkItem ResolveLinkItem(std::string const& name) const; // Compute the set of languages compiled by the target. This is https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=2f708f5d65557ecbfe4ebe7c14b02dbba6bf0ffe commit 2f708f5d65557ecbfe4ebe7c14b02dbba6bf0ffe Author: Brad King AuthorDate: Fri Sep 7 10:56:17 2018 -0400 Commit: Brad King CommitDate: Wed Sep 12 12:46:25 2018 -0400 Make internal TARGET_PROPERTY generator expressions more robust While collecting usage requirements from the `INTERFACE_*` properties of directly linked targets, we internally generate `TARGET_PROPERTY:` and `TARGET_OBJECTS:` generator expressions to refer to those properties on those targets. At the point we generate these expressions we already have a pointer to an exact `cmGeneratorTarget` instance. Switch from using the target name in these generator expressions to using an internal unique name generated for each `cmGeneratorTarget` instance to be referenced. This avoids depending on the user-facing target name to find the same target we already have. diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index 1e51f09..16ac88c 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -1054,7 +1054,9 @@ std::string getLinkedTargetsContent( // Don't follow such link interface entries so as not to create a // self-referencing loop. if (l.Target && l.Target != target) { - depString += sep + "$GetName() + "," + + std::string uniqueName = + target->GetGlobalGenerator()->IndexGeneratorTargetUniquely(l.Target); + depString += sep + "$"; sep = ";"; } diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index e8e7b90..40ee01e 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -819,8 +819,11 @@ static void AddInterfaceEntries( thisTarget->GetLinkImplementationLibraries(config)) { for (cmLinkImplItem const& lib : impl->Libraries) { if (lib.Target) { + std::string uniqueName = + thisTarget->GetGlobalGenerator()->IndexGeneratorTargetUniquely( + lib.Target); std::string genex = - "$"; + "$"; cmGeneratorExpression ge(lib.Backtrace); std::unique_ptr cge = ge.Parse(genex); cge->SetEvaluateForBuildsystem(true); @@ -840,7 +843,10 @@ static void AddObjectEntries( for (cmLinkImplItem const& lib : impl->Libraries) { if (lib.Target && lib.Target->GetType() == cmStateEnums::OBJECT_LIBRARY) { - std::string genex = "$"; + std::string uniqueName = + thisTarget->GetGlobalGenerator()->IndexGeneratorTargetUniquely( + lib.Target); + std::string genex = "$"; cmGeneratorExpression ge(lib.Backtrace); std::unique_ptr cge = ge.Parse(genex); cge->SetEvaluateForBuildsystem(true); diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 207d492..0aba67c 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -2155,6 +2155,24 @@ void cmGlobalGenerator::IndexGeneratorTarget(cmGeneratorTarget* gt) } } +std::string cmGlobalGenerator::IndexGeneratorTargetUniquely( + cmGeneratorTarget const* gt) +{ + // Use the pointer value to uniquely identify the target instance. + // Use a "T" prefix to indicate that this identifier is for a target. + // We must satisfy cmGeneratorExpression::IsValidTargetName so use no + // other special characters. + char buf[64]; + sprintf(buf, "::T%p", + static_cast(gt)); // cast avoids format warning + std::string id = gt->GetName() + buf; + // We internally index pointers to non-const generator targets + // but our callers only have pointers to const generator targets. + // They will give up non-const privileges when looking up anyway. + this->GeneratorTargetSearchIndex[id] = const_cast(gt); + return id; +} + void cmGlobalGenerator::IndexMakefile(cmMakefile* mf) { // FIXME: add_subdirectory supports multiple build directories diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 720938d..6b972eb 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -303,6 +303,10 @@ public: void IndexTarget(cmTarget* t); void IndexGeneratorTarget(cmGeneratorTarget* gt); + // Index the target using a name that is unique to that target + // even if other targets have the same name. + std::string IndexGeneratorTargetUniquely(cmGeneratorTarget const* gt); + static bool IsReservedTarget(std::string const& name); virtual const char* GetAllTargetName() const { return "ALL_BUILD"; } https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=94a75801c834891f47358e9f5763c56245dff3fe commit 94a75801c834891f47358e9f5763c56245dff3fe Author: Brad King AuthorDate: Mon Sep 10 09:40:01 2018 -0400 Commit: Brad King CommitDate: Tue Sep 11 13:17:11 2018 -0400 Android.mk: De-duplicate link libraries logic during export Use the normal target link interface computation logic to get the list of libraries in the link interface instead of trying to interpret the `INTERFACE_LINK_LIBRARIES` property directly. diff --git a/Source/cmExportBuildAndroidMKGenerator.cxx b/Source/cmExportBuildAndroidMKGenerator.cxx index 3d32b84..d12ad7f 100644 --- a/Source/cmExportBuildAndroidMKGenerator.cxx +++ b/Source/cmExportBuildAndroidMKGenerator.cxx @@ -8,11 +8,8 @@ #include #include "cmAlgorithms.h" -#include "cmGeneratorExpression.h" -#include "cmGeneratorExpressionDAGChecker.h" #include "cmGeneratorTarget.h" #include "cmLinkItem.h" -#include "cmLocalGenerator.h" #include "cmMakefile.h" #include "cmPolicies.h" #include "cmStateTypes.h" @@ -104,27 +101,14 @@ void cmExportBuildAndroidMKGenerator::GenerateInterfaceProperties( os << "LOCAL_CPP_FEATURES += "; os << (property.second) << "\n"; } else if (property.first == "INTERFACE_LINK_LIBRARIES") { - // evaluate any generator expressions with the current - // build type of the makefile - cmGeneratorExpression ge; - cmGeneratorExpressionDAGChecker dagChecker( - target, "INTERFACE_LINK_LIBRARIES", nullptr, nullptr); - std::unique_ptr cge = - ge.Parse(property.second); - std::string evaluated = cge->Evaluate( - target->GetLocalGenerator(), config, false, target, &dagChecker); - // need to look at list in pi->second and see if static or shared - // FindTargetToLink - // target->GetLocalGenerator()->FindGeneratorTargetToUse() - // then add to LOCAL_CPPFLAGS - std::vector libraries; - cmSystemTools::ExpandListArgument(evaluated, libraries); std::string staticLibs; std::string sharedLibs; std::string ldlibs; - for (std::string const& lib : libraries) { - cmGeneratorTarget* gt = - target->GetLocalGenerator()->FindGeneratorTargetToUse(lib); + cmLinkInterfaceLibraries const* linkIFace = + target->GetLinkInterfaceLibraries(config, target, false); + for (cmLinkItem const& item : linkIFace->Libraries) { + cmGeneratorTarget const* gt = item.Target; + std::string const& lib = item.AsStr(); if (gt) { if (gt->GetType() == cmStateEnums::SHARED_LIBRARY || https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=8a63b23d1606e4eb04e729369fa5ecccc2f5c7ea commit 8a63b23d1606e4eb04e729369fa5ecccc2f5c7ea Author: Brad King AuthorDate: Mon Sep 10 08:09:53 2018 -0400 Commit: Brad King CommitDate: Tue Sep 11 08:21:22 2018 -0400 cmGlobalGenerator: Remove unused FindLocalGenerator method This method has not been used since commit v3.4.0-rc1~234^2~1 (cmGlobalGenerator: Port Find API to cmMakefile, 2015-08-02). diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index b5212fc..207d492 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -2130,19 +2130,6 @@ cmMakefile* cmGlobalGenerator::FindMakefile(const std::string& start_dir) const return nullptr; } -///! Find a local generator by its startdirectory -cmLocalGenerator* cmGlobalGenerator::FindLocalGenerator( - const std::string& start_dir) const -{ - for (cmLocalGenerator* lg : this->LocalGenerators) { - std::string sd = lg->GetCurrentSourceDirectory(); - if (sd == start_dir) { - return lg; - } - } - return nullptr; -} - void cmGlobalGenerator::AddAlias(const std::string& name, std::string const& tgtName) { diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index c06ac52..720938d 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -284,8 +284,6 @@ public: bool NameResolvesToFramework(const std::string& libname) const; cmMakefile* FindMakefile(const std::string& start_dir) const; - ///! Find a local generator by its startdirectory - cmLocalGenerator* FindLocalGenerator(const std::string& start_dir) const; /** Append the subdirectory for the given configuration. If anything is appended the given prefix and suffix will be appended around it, which ----------------------------------------------------------------------- Summary of changes: Help/command/target_link_libraries.rst | 11 +-- Help/manual/cmake-policies.7.rst | 1 + Help/policy/CMP0079.rst | 40 +++++++++++ Help/prop_tgt/INTERFACE_LINK_LIBRARIES.rst | 2 + Help/prop_tgt/LINK_LIBRARIES.rst | 2 + Help/prop_tgt/LINK_LIBRARIES_INDIRECTION.txt | 10 +++ Help/release/dev/out-of-dir-linking.rst | 6 ++ Source/cmExportBuildAndroidMKGenerator.cxx | 26 ++----- Source/cmExportFileGenerator.cxx | 9 ++- Source/cmGeneratorExpressionNode.cxx | 4 +- Source/cmGeneratorTarget.cxx | 71 +++++++++++++++---- Source/cmGeneratorTarget.h | 7 ++ Source/cmGlobalGenerator.cxx | 42 +++++++++--- Source/cmGlobalGenerator.h | 17 ++++- Source/cmMakefile.cxx | 17 +++++ Source/cmMakefile.h | 10 +++ Source/cmPolicies.h | 6 +- Source/cmTarget.cxx | 15 ++-- Source/cmTarget.h | 3 + Source/cmTargetLinkLibrariesCommand.cxx | 80 ++++++++++++++++------ .../target_link_libraries/CMakeLists.txt | 12 ++++ .../target_link_libraries/SubDirA/CMakeLists.txt | 15 ++++ .../target_link_libraries/SubDirA/SubDirA.c | 14 ++++ .../target_link_libraries/SubDirB/CMakeLists.txt | 15 ++++ .../target_link_libraries/SubDirB/SubDirB.c | 14 ++++ Tests/CMakeCommands/target_link_libraries/TopDir.c | 14 ++++ Tests/ExportImport/Export/CMakeLists.txt | 9 +++ .../ExportImport/Export/SubDirLinkA/CMakeLists.txt | 6 ++ .../ExportImport/Export/SubDirLinkA/SubDirLinkA.c | 11 +++ .../ExportImport/Export/SubDirLinkB/CMakeLists.txt | 4 ++ Tests/ExportImport/Export/testTopDirLib.c | 11 +++ Tests/ExportImport/Import/A/CMakeLists.txt | 11 +++ Tests/ExportImport/Import/A/SubDirLink.c | 14 ++++ .../CMP0079-iface-NEW-stdout.txt | 1 + .../target_link_libraries/CMP0079-iface-NEW.cmake | 2 + .../CMP0079-iface-OLD-stdout.txt | 1 + .../target_link_libraries/CMP0079-iface-OLD.cmake | 2 + .../CMP0079-iface-WARN-stderr.txt | 17 +++++ .../CMP0079-iface-WARN-stdout.txt | 1 + .../target_link_libraries/CMP0079-iface-WARN.cmake | 1 + .../CMP0079-iface-common.cmake | 6 ++ .../CMP0079-iface/CMakeLists.txt | 1 + ...esult.txt => CMP0079-link-NEW-bogus-result.txt} | 0 .../CMP0079-link-NEW-bogus-stderr.txt | 6 ++ .../CMP0079-link-NEW-bogus.cmake | 6 ++ .../CMP0079-link-NEW-stdout.txt | 1 + .../target_link_libraries/CMP0079-link-NEW.cmake | 2 + .../CMP0079-link-OLD-result.txt} | 0 .../CMP0079-link-OLD-stderr.txt | 5 ++ .../target_link_libraries/CMP0079-link-OLD.cmake | 2 + .../CMP0079-link-WARN-result.txt} | 0 .../CMP0079-link-WARN-stderr.txt | 5 ++ .../target_link_libraries/CMP0079-link-WARN.cmake | 1 + .../CMP0079-link-common.cmake | 6 ++ .../CMP0079-link/CMakeLists.txt | 1 + .../RunCMake/target_link_libraries/CMakeLists.txt | 2 +- .../target_link_libraries/RunCMakeTest.cmake | 8 ++- .../target_link_libraries/SubDirTarget-stderr.txt | 5 -- .../target_link_libraries/SubDirTarget.cmake | 3 - .../SubDirTarget/CMakeLists.txt | 1 - 60 files changed, 527 insertions(+), 88 deletions(-) create mode 100644 Help/policy/CMP0079.rst create mode 100644 Help/prop_tgt/LINK_LIBRARIES_INDIRECTION.txt create mode 100644 Help/release/dev/out-of-dir-linking.rst create mode 100644 Tests/CMakeCommands/target_link_libraries/SubDirA/CMakeLists.txt create mode 100644 Tests/CMakeCommands/target_link_libraries/SubDirA/SubDirA.c create mode 100644 Tests/CMakeCommands/target_link_libraries/SubDirB/CMakeLists.txt create mode 100644 Tests/CMakeCommands/target_link_libraries/SubDirB/SubDirB.c create mode 100644 Tests/CMakeCommands/target_link_libraries/TopDir.c create mode 100644 Tests/ExportImport/Export/SubDirLinkA/CMakeLists.txt create mode 100644 Tests/ExportImport/Export/SubDirLinkA/SubDirLinkA.c create mode 100644 Tests/ExportImport/Export/SubDirLinkB/CMakeLists.txt create mode 100644 Tests/ExportImport/Export/testTopDirLib.c create mode 100644 Tests/ExportImport/Import/A/SubDirLink.c create mode 100644 Tests/RunCMake/target_link_libraries/CMP0079-iface-NEW-stdout.txt create mode 100644 Tests/RunCMake/target_link_libraries/CMP0079-iface-NEW.cmake create mode 100644 Tests/RunCMake/target_link_libraries/CMP0079-iface-OLD-stdout.txt create mode 100644 Tests/RunCMake/target_link_libraries/CMP0079-iface-OLD.cmake create mode 100644 Tests/RunCMake/target_link_libraries/CMP0079-iface-WARN-stderr.txt create mode 100644 Tests/RunCMake/target_link_libraries/CMP0079-iface-WARN-stdout.txt create mode 100644 Tests/RunCMake/target_link_libraries/CMP0079-iface-WARN.cmake create mode 100644 Tests/RunCMake/target_link_libraries/CMP0079-iface-common.cmake create mode 100644 Tests/RunCMake/target_link_libraries/CMP0079-iface/CMakeLists.txt rename Tests/RunCMake/target_link_libraries/{SubDirTarget-result.txt => CMP0079-link-NEW-bogus-result.txt} (100%) create mode 100644 Tests/RunCMake/target_link_libraries/CMP0079-link-NEW-bogus-stderr.txt create mode 100644 Tests/RunCMake/target_link_libraries/CMP0079-link-NEW-bogus.cmake create mode 100644 Tests/RunCMake/target_link_libraries/CMP0079-link-NEW-stdout.txt create mode 100644 Tests/RunCMake/target_link_libraries/CMP0079-link-NEW.cmake copy Tests/RunCMake/{while/MissingArgument-result.txt => target_link_libraries/CMP0079-link-OLD-result.txt} (100%) create mode 100644 Tests/RunCMake/target_link_libraries/CMP0079-link-OLD-stderr.txt create mode 100644 Tests/RunCMake/target_link_libraries/CMP0079-link-OLD.cmake copy Tests/RunCMake/{while/MissingArgument-result.txt => target_link_libraries/CMP0079-link-WARN-result.txt} (100%) create mode 100644 Tests/RunCMake/target_link_libraries/CMP0079-link-WARN-stderr.txt create mode 100644 Tests/RunCMake/target_link_libraries/CMP0079-link-WARN.cmake create mode 100644 Tests/RunCMake/target_link_libraries/CMP0079-link-common.cmake create mode 100644 Tests/RunCMake/target_link_libraries/CMP0079-link/CMakeLists.txt delete mode 100644 Tests/RunCMake/target_link_libraries/SubDirTarget-stderr.txt delete mode 100644 Tests/RunCMake/target_link_libraries/SubDirTarget.cmake delete mode 100644 Tests/RunCMake/target_link_libraries/SubDirTarget/CMakeLists.txt hooks/post-receive -- CMake From kwrobot at kitware.com Sat Sep 15 00:05:07 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Sat, 15 Sep 2018 00:05:07 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-634-g18eb4c6 Message-ID: <20180915040507.869C911DA48@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 18eb4c637a6fb35bf8207e5f39d3e701fdcf973b (commit) from 333804fa0e12c3df9ef16fec163451cffda52df4 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=18eb4c637a6fb35bf8207e5f39d3e701fdcf973b commit 18eb4c637a6fb35bf8207e5f39d3e701fdcf973b Author: Kitware Robot AuthorDate: Sat Sep 15 00:01:15 2018 -0400 Commit: Kitware Robot CommitDate: Sat Sep 15 00:01:15 2018 -0400 CMake Nightly Date Stamp diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index bd8ad4d..09cb58a 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 12) -set(CMake_VERSION_PATCH 20180914) +set(CMake_VERSION_PATCH 20180915) #set(CMake_VERSION_RC 1) ----------------------------------------------------------------------- Summary of changes: Source/CMakeVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) hooks/post-receive -- CMake From kwrobot at kitware.com Sun Sep 16 00:05:03 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Sun, 16 Sep 2018 00:05:03 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-635-ge173c25 Message-ID: <20180916040503.56EAE11EB7A@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via e173c25f19a8b532d8175ba77a57012a99779ea3 (commit) from 18eb4c637a6fb35bf8207e5f39d3e701fdcf973b (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=e173c25f19a8b532d8175ba77a57012a99779ea3 commit e173c25f19a8b532d8175ba77a57012a99779ea3 Author: Kitware Robot AuthorDate: Sun Sep 16 00:01:06 2018 -0400 Commit: Kitware Robot CommitDate: Sun Sep 16 00:01:06 2018 -0400 CMake Nightly Date Stamp diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 09cb58a..ee31122 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 12) -set(CMake_VERSION_PATCH 20180915) +set(CMake_VERSION_PATCH 20180916) #set(CMake_VERSION_RC 1) ----------------------------------------------------------------------- Summary of changes: Source/CMakeVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) hooks/post-receive -- CMake From kwrobot at kitware.com Mon Sep 17 00:05:09 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Mon, 17 Sep 2018 00:05:09 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-636-g19daeda Message-ID: <20180917040510.11BCB12540D@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 19daeda516f6c9008475511a578909ae578a8b41 (commit) from e173c25f19a8b532d8175ba77a57012a99779ea3 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=19daeda516f6c9008475511a578909ae578a8b41 commit 19daeda516f6c9008475511a578909ae578a8b41 Author: Kitware Robot AuthorDate: Mon Sep 17 00:01:10 2018 -0400 Commit: Kitware Robot CommitDate: Mon Sep 17 00:01:10 2018 -0400 CMake Nightly Date Stamp diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index ee31122..b42fafa 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 12) -set(CMake_VERSION_PATCH 20180916) +set(CMake_VERSION_PATCH 20180917) #set(CMake_VERSION_RC 1) ----------------------------------------------------------------------- Summary of changes: Source/CMakeVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) hooks/post-receive -- CMake From kwrobot at kitware.com Mon Sep 17 09:25:04 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Mon, 17 Sep 2018 09:25:04 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-641-ga6ae99e Message-ID: <20180917132504.26BD310D58C@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via a6ae99ebbe01350f46d8540cc8b792bc6c1cc3d6 (commit) via b3f1e654860f6e1481fc0e07f6fb7dfab585472f (commit) via 6209434b441b0857b8601dd39498c3796d338c5a (commit) via 49e7a82c90bd1ccd59089b6c0b1687c341e51d5e (commit) via b13c8526b1f617f5dd146f42c6e1d48040cb527d (commit) from 19daeda516f6c9008475511a578909ae578a8b41 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=a6ae99ebbe01350f46d8540cc8b792bc6c1cc3d6 commit a6ae99ebbe01350f46d8540cc8b792bc6c1cc3d6 Merge: b3f1e65 6209434 Author: Brad King AuthorDate: Mon Sep 17 13:23:23 2018 +0000 Commit: Kitware Robot CommitDate: Mon Sep 17 09:24:10 2018 -0400 Merge topic 'FindCUDA-doc-typo' 6209434b44 FindCUDA: Fix "alphabetical" typo Acked-by: Kitware Robot Merge-request: !2387 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=b3f1e654860f6e1481fc0e07f6fb7dfab585472f commit b3f1e654860f6e1481fc0e07f6fb7dfab585472f Merge: 19daeda 49e7a82 Author: Brad King AuthorDate: Mon Sep 17 13:22:22 2018 +0000 Commit: Kitware Robot CommitDate: Mon Sep 17 09:22:38 2018 -0400 Merge topic 'update-kwsys' 49e7a82c90 Merge branch 'upstream-KWSys' into update-kwsys b13c8526b1 KWSys 2018-09-14 (1809bedd) Acked-by: Kitware Robot Merge-request: !2385 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=6209434b441b0857b8601dd39498c3796d338c5a commit 6209434b441b0857b8601dd39498c3796d338c5a Author: Nikolaus Wittenstein AuthorDate: Fri Sep 14 14:34:35 2018 -0400 Commit: Nikolaus Wittenstein CommitDate: Fri Sep 14 14:53:03 2018 -0400 FindCUDA: Fix "alphabetical" typo diff --git a/Modules/FindCUDA.cmake b/Modules/FindCUDA.cmake index 1650e55..5547dee 100644 --- a/Modules/FindCUDA.cmake +++ b/Modules/FindCUDA.cmake @@ -43,7 +43,7 @@ # matches what is needed by the CUDA runtime version. # # The following variables affect the behavior of the macros in the -# script (in alphebetical order). Note that any of these flags can be +# script (in alphabetical order). Note that any of these flags can be # changed multiple times in the same directory before calling # ``CUDA_ADD_EXECUTABLE``, ``CUDA_ADD_LIBRARY``, ``CUDA_COMPILE``, # ``CUDA_COMPILE_PTX``, ``CUDA_COMPILE_FATBIN``, ``CUDA_COMPILE_CUBIN`` @@ -147,7 +147,7 @@ # VERBOSE=1 to see output), although setting CUDA_VERBOSE_BUILD to ON will # always print the output. # -# The script creates the following macros (in alphebetical order):: +# The script creates the following macros (in alphabetical order):: # # CUDA_ADD_CUFFT_TO_TARGET( cuda_target ) # -- Adds the cufft library to the target (can be any target). Handles whether https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=49e7a82c90bd1ccd59089b6c0b1687c341e51d5e commit 49e7a82c90bd1ccd59089b6c0b1687c341e51d5e Merge: 333804f b13c852 Author: Brad King AuthorDate: Fri Sep 14 13:25:53 2018 -0400 Commit: Brad King CommitDate: Fri Sep 14 13:25:53 2018 -0400 Merge branch 'upstream-KWSys' into update-kwsys * upstream-KWSys: KWSys 2018-09-14 (1809bedd) https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=b13c8526b1f617f5dd146f42c6e1d48040cb527d commit b13c8526b1f617f5dd146f42c6e1d48040cb527d Author: KWSys Upstream AuthorDate: Fri Sep 14 13:13:00 2018 -0400 Commit: Brad King CommitDate: Fri Sep 14 13:25:53 2018 -0400 KWSys 2018-09-14 (1809bedd) Code extracted from: https://gitlab.kitware.com/utils/kwsys.git at commit 1809bedde0491d078ad42200bf2834c345e65398 (master). Upstream Shortlog ----------------- Ben Boeckel (2): b5b294c1 SystemTools::Split: fix copy-pasta comments ab0d44c9 SystemTools::Split: use str.find_first_of(char) Roger Leigh (1): bdd39241 Process: On Windows do not open stdin file with write permission diff --git a/ProcessWin32.c b/ProcessWin32.c index 9fa0cb1..2a2e737 100644 --- a/ProcessWin32.c +++ b/ProcessWin32.c @@ -973,8 +973,8 @@ void kwsysProcess_Execute(kwsysProcess* cp) wchar_t* wstdin = kwsysEncoding_DupToWide(cp->PipeFileSTDIN); DWORD error; cp->PipeChildStd[0] = - CreateFileW(wstdin, GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0); + CreateFileW(wstdin, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, + OPEN_EXISTING, 0, 0); error = GetLastError(); /* Check now in case free changes this. */ free(wstdin); if (cp->PipeChildStd[0] == INVALID_HANDLE_VALUE) { diff --git a/SystemTools.cxx b/SystemTools.cxx index 476fe08..0a4ad7a 100644 --- a/SystemTools.cxx +++ b/SystemTools.cxx @@ -3640,11 +3640,11 @@ bool SystemTools::Split(const std::string& str, while (lpos < data.length()) { std::string::size_type rpos = data.find_first_of(separator, lpos); if (rpos == std::string::npos) { - // Line ends at end of string without a newline. + // String ends at end of string without a separator. lines.push_back(data.substr(lpos)); return false; } else { - // Line ends in a "\n", remove the character. + // String ends in a separator, remove the character. lines.push_back(data.substr(lpos, rpos - lpos)); } lpos = rpos + 1; @@ -3658,7 +3658,7 @@ bool SystemTools::Split(const std::string& str, std::string data(str); std::string::size_type lpos = 0; while (lpos < data.length()) { - std::string::size_type rpos = data.find_first_of("\n", lpos); + std::string::size_type rpos = data.find_first_of('\n', lpos); if (rpos == std::string::npos) { // Line ends at end of string without a newline. lines.push_back(data.substr(lpos)); ----------------------------------------------------------------------- Summary of changes: Modules/FindCUDA.cmake | 4 ++-- Source/kwsys/ProcessWin32.c | 4 ++-- Source/kwsys/SystemTools.cxx | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) hooks/post-receive -- CMake From kwrobot at kitware.com Mon Sep 17 09:35:04 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Mon, 17 Sep 2018 09:35:04 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-645-g2af106a Message-ID: <20180917133504.BE5061142B5@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 2af106a43a259533b0cec262ca368f577c3925b0 (commit) via 7bf9796f3d0170f35c674635c9a274b982ba5436 (commit) via 6da8b67c3f9c07352fa36e717e79e15ef36495f3 (commit) via e3f9ea8616966b4f71e75a7ce8484ab6e398eb25 (commit) from a6ae99ebbe01350f46d8540cc8b792bc6c1cc3d6 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=2af106a43a259533b0cec262ca368f577c3925b0 commit 2af106a43a259533b0cec262ca368f577c3925b0 Merge: 7bf9796 6da8b67 Author: Brad King AuthorDate: Mon Sep 17 13:25:24 2018 +0000 Commit: Kitware Robot CommitDate: Mon Sep 17 09:25:40 2018 -0400 Merge topic 'link-options' 6da8b67c3f target_link_options: fix erroneous handling of BEFORE keyword. Acked-by: Kitware Robot Merge-request: !2384 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=7bf9796f3d0170f35c674635c9a274b982ba5436 commit 7bf9796f3d0170f35c674635c9a274b982ba5436 Merge: a6ae99e e3f9ea8 Author: Brad King AuthorDate: Mon Sep 17 13:24:55 2018 +0000 Commit: Kitware Robot CommitDate: Mon Sep 17 09:25:03 2018 -0400 Merge topic 'docs/gen-see-also' e3f9ea8616 docs: add some 'see also' helper texts Acked-by: Kitware Robot Merge-request: !2381 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=6da8b67c3f9c07352fa36e717e79e15ef36495f3 commit 6da8b67c3f9c07352fa36e717e79e15ef36495f3 Author: Marc Chevrier AuthorDate: Fri Sep 14 18:10:58 2018 +0200 Commit: Marc Chevrier CommitDate: Fri Sep 14 18:10:58 2018 +0200 target_link_options: fix erroneous handling of BEFORE keyword. diff --git a/Source/cmTargetLinkOptionsCommand.cxx b/Source/cmTargetLinkOptionsCommand.cxx index f0f13fd..d6ed5ae 100644 --- a/Source/cmTargetLinkOptionsCommand.cxx +++ b/Source/cmTargetLinkOptionsCommand.cxx @@ -33,9 +33,9 @@ std::string cmTargetLinkOptionsCommand::Join( } bool cmTargetLinkOptionsCommand::HandleDirectContent( - cmTarget* tgt, const std::vector& content, bool, bool) + cmTarget* tgt, const std::vector& content, bool prepend, bool) { cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); - tgt->InsertLinkOption(this->Join(content), lfbt); + tgt->InsertLinkOption(this->Join(content), lfbt, prepend); return true; // Successfully handled. } diff --git a/Tests/CMakeCommands/target_link_options/CMakeLists.txt b/Tests/CMakeCommands/target_link_options/CMakeLists.txt index 3bb6ff3..e84d041 100644 --- a/Tests/CMakeCommands/target_link_options/CMakeLists.txt +++ b/Tests/CMakeCommands/target_link_options/CMakeLists.txt @@ -24,3 +24,11 @@ get_target_property(result target_link_options_3 INTERFACE_LINK_OPTIONS) if (NOT result MATCHES "-INTERFACE_FLAG") message(SEND_ERROR "target_link_options not populated the INTERFACE_LINK_OPTIONS target property of static library") endif() + +add_library(target_link_options_4 SHARED EXCLUDE_FROM_ALL LinkOptionsLib.c) +target_link_options(target_link_options_4 PRIVATE -PRIVATE_FLAG) +target_link_options(target_link_options_4 BEFORE PRIVATE -BEFORE_PRIVATE_FLAG) +get_target_property(result target_link_options_4 LINK_OPTIONS) +if (NOT result MATCHES "-BEFORE_PRIVATE_FLAG.*-PRIVATE_FLAG") + message(SEND_ERROR "target_link_options not managing correctly 'BEFORE' keyword") +endif() https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=e3f9ea8616966b4f71e75a7ce8484ab6e398eb25 commit e3f9ea8616966b4f71e75a7ce8484ab6e398eb25 Author: Brian Heim AuthorDate: Thu Sep 13 00:32:01 2018 -0500 Commit: Brian Heim CommitDate: Thu Sep 13 00:32:01 2018 -0500 docs: add some 'see also' helper texts in cmake-generator-expressions diff --git a/Help/manual/cmake-generator-expressions.7.rst b/Help/manual/cmake-generator-expressions.7.rst index c3428d1..76fd3d9 100644 --- a/Help/manual/cmake-generator-expressions.7.rst +++ b/Help/manual/cmake-generator-expressions.7.rst @@ -68,10 +68,13 @@ Available logical expressions are: target. ``$`` ``1`` if the CMake-id of the platform matches ``comp``, otherwise ``0``. + See also the :variable:`CMAKE_SYSTEM_NAME` variable. ``$`` ``1`` if the CMake-id of the C compiler matches ``comp``, otherwise ``0``. + See also the :variable:`CMAKE__COMPILER_ID` variable. ``$`` ``1`` if the CMake-id of the CXX compiler matches ``comp``, otherwise ``0``. + See also the :variable:`CMAKE__COMPILER_ID` variable. ``$`` ``1`` if ``v1`` is a version less than ``v2``, else ``0``. ``$`` @@ -84,8 +87,10 @@ Available logical expressions are: ``1`` if ``v1`` is a version greater than or equal to ``v2``, else ``0``. ``$`` ``1`` if the version of the C compiler matches ``ver``, otherwise ``0``. + See also the :variable:`CMAKE__COMPILER_VERSION` variable. ``$`` ``1`` if the version of the CXX compiler matches ``ver``, otherwise ``0``. + See also the :variable:`CMAKE__COMPILER_VERSION` variable. ``$`` ``1`` if the policy ``pol`` was NEW when the 'head' target was created, else ``0``. If the policy was not set, the warning message for the policy ----------------------------------------------------------------------- Summary of changes: Help/manual/cmake-generator-expressions.7.rst | 5 +++++ Source/cmTargetLinkOptionsCommand.cxx | 4 ++-- Tests/CMakeCommands/target_link_options/CMakeLists.txt | 8 ++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) hooks/post-receive -- CMake From kwrobot at kitware.com Mon Sep 17 11:35:05 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Mon, 17 Sep 2018 11:35:05 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-647-ge7fcd3b Message-ID: <20180917153505.61AA411F4BB@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via e7fcd3b8ebe0889e47164fd5a93138570e638228 (commit) via 17e581af4c950d26310b4665a051cf68bc0f7269 (commit) from 2af106a43a259533b0cec262ca368f577c3925b0 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=e7fcd3b8ebe0889e47164fd5a93138570e638228 commit e7fcd3b8ebe0889e47164fd5a93138570e638228 Merge: 2af106a 17e581a Author: Brad King AuthorDate: Mon Sep 17 15:27:21 2018 +0000 Commit: Kitware Robot CommitDate: Mon Sep 17 11:27:29 2018 -0400 Merge topic 'cmake_rule_messages_doc' 17e581af4c Help: Document CMAKE_RULE_MESSAGES variable Acked-by: Kitware Robot Merge-request: !2383 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=17e581af4c950d26310b4665a051cf68bc0f7269 commit 17e581af4c950d26310b4665a051cf68bc0f7269 Author: Julien Schueller AuthorDate: Fri Sep 14 09:19:27 2018 +0200 Commit: Julien Schueller CommitDate: Mon Sep 17 10:05:30 2018 +0200 Help: Document CMAKE_RULE_MESSAGES variable Fixes: #18368 diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst index d8a5def..6071999 100644 --- a/Help/manual/cmake-variables.7.rst +++ b/Help/manual/cmake-variables.7.rst @@ -78,6 +78,7 @@ Variables that Provide Information /variable/CMAKE_PROJECT_VERSION_TWEAK /variable/CMAKE_RANLIB /variable/CMAKE_ROOT + /variable/CMAKE_RULE_MESSAGES /variable/CMAKE_SCRIPT_MODE_FILE /variable/CMAKE_SHARED_LIBRARY_PREFIX /variable/CMAKE_SHARED_LIBRARY_SUFFIX diff --git a/Help/prop_gbl/RULE_MESSAGES.rst b/Help/prop_gbl/RULE_MESSAGES.rst index 87a5ca6..a9734a7 100644 --- a/Help/prop_gbl/RULE_MESSAGES.rst +++ b/Help/prop_gbl/RULE_MESSAGES.rst @@ -8,6 +8,6 @@ progress message describing what each build rule does. If the property is not set the default is ON. Set the property to OFF to disable granular messages and report only as each target completes. This is intended to allow scripted builds to avoid the build time cost -of detailed reports. If a ``CMAKE_RULE_MESSAGES`` cache entry exists +of detailed reports. If a :variable:`CMAKE_RULE_MESSAGES` cache entry exists its value initializes the value of this property. Non-Makefile generators currently ignore this property. diff --git a/Help/variable/CMAKE_RULE_MESSAGES.rst b/Help/variable/CMAKE_RULE_MESSAGES.rst new file mode 100644 index 0000000..7460a81 --- /dev/null +++ b/Help/variable/CMAKE_RULE_MESSAGES.rst @@ -0,0 +1,8 @@ +CMAKE_RULE_MESSAGES +------------------- + +Specify whether to report a message for each make rule. + +If set in the cache it is used to initialize the value of the :prop_gbl:`RULE_MESSAGES` property. +Users may disable the option in their local build tree to disable granular messages +and report only as each target completes in Makefile builds. ----------------------------------------------------------------------- Summary of changes: Help/manual/cmake-variables.7.rst | 1 + Help/prop_gbl/RULE_MESSAGES.rst | 2 +- Help/variable/CMAKE_RULE_MESSAGES.rst | 8 ++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 Help/variable/CMAKE_RULE_MESSAGES.rst hooks/post-receive -- CMake From kwrobot at kitware.com Tue Sep 18 00:05:03 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Tue, 18 Sep 2018 00:05:03 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-648-g6097d8d Message-ID: <20180918040503.C40CF11ED8A@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 6097d8dd3d6ea6e5a0a6012952b722d0719d39e9 (commit) from e7fcd3b8ebe0889e47164fd5a93138570e638228 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=6097d8dd3d6ea6e5a0a6012952b722d0719d39e9 commit 6097d8dd3d6ea6e5a0a6012952b722d0719d39e9 Author: Kitware Robot AuthorDate: Tue Sep 18 00:01:09 2018 -0400 Commit: Kitware Robot CommitDate: Tue Sep 18 00:01:09 2018 -0400 CMake Nightly Date Stamp diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index b42fafa..d0cce8b 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 12) -set(CMake_VERSION_PATCH 20180917) +set(CMake_VERSION_PATCH 20180918) #set(CMake_VERSION_RC 1) ----------------------------------------------------------------------- Summary of changes: Source/CMakeVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) hooks/post-receive -- CMake From kwrobot at kitware.com Tue Sep 18 11:25:04 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Tue, 18 Sep 2018 11:25:04 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-661-g7162630 Message-ID: <20180918152504.94B0C1076BA@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 7162630beebeac105c1cd90270d26f29aa8c118f (commit) via fc74fcc853641c3369670a15811b38c818d6b840 (commit) via a8f628c0a456f74680bfdad0050f2614dbe50853 (commit) via f4ff60a803170311f49511a60a381eef8b78c5dd (commit) via 7adf3aabd55dd80784727a229a37c394740db628 (commit) via f9eac2ae4b986f74a97fe16fa19df94331a52b34 (commit) via bef80e66231a0bd2feffab02fe8d1d8f55eb793c (commit) via 567fabe88e97c3e39503fd353b484648bcf1cbb2 (commit) via 53ad52d66d2056a4bf797d22ce1d3ee5395679a6 (commit) via 2a2f0ac231fe31052c6fabc2b2829653c5cea2fa (commit) via 329f6aeca5011e423a65ccede3177cd4f0ef1e21 (commit) via ffb560adc98ee7c07d0e3cd50b28a38a4997cc8b (commit) via b0b53921cef242acc91e6ab4dd495daff54191d6 (commit) from 6097d8dd3d6ea6e5a0a6012952b722d0719d39e9 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=7162630beebeac105c1cd90270d26f29aa8c118f commit 7162630beebeac105c1cd90270d26f29aa8c118f Merge: fc74fcc bef80e6 Author: Brad King AuthorDate: Tue Sep 18 15:22:33 2018 +0000 Commit: Kitware Robot CommitDate: Tue Sep 18 11:22:41 2018 -0400 Merge topic 'vs-ipo' bef80e6623 VS: Do not specify incremental linking if LTCG is enabled 567fabe88e IPO: INTERPROCEDURAL_OPTIMIZATION (LTCG) for Visual Studio Acked-by: Kitware Robot Merge-request: !2363 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=fc74fcc853641c3369670a15811b38c818d6b840 commit fc74fcc853641c3369670a15811b38c818d6b840 Merge: a8f628c 53ad52d Author: Brad King AuthorDate: Tue Sep 18 15:18:52 2018 +0000 Commit: Kitware Robot CommitDate: Tue Sep 18 11:18:57 2018 -0400 Merge topic 'link-options' 53ad52d66d LINK_OPTIONS: Add missing initialization actions Acked-by: Kitware Robot Merge-request: !2395 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=a8f628c0a456f74680bfdad0050f2614dbe50853 commit a8f628c0a456f74680bfdad0050f2614dbe50853 Merge: 7adf3aa f4ff60a Author: Brad King AuthorDate: Tue Sep 18 15:17:45 2018 +0000 Commit: Kitware Robot CommitDate: Tue Sep 18 11:18:00 2018 -0400 Merge topic 'getsafedef-stdstring' f4ff60a803 cmMakefile: Make GetSafeDefinition return std::string const& Acked-by: Kitware Robot Merge-request: !2350 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=f4ff60a803170311f49511a60a381eef8b78c5dd commit f4ff60a803170311f49511a60a381eef8b78c5dd Author: Vitaly Stakhovsky AuthorDate: Wed Sep 5 06:41:28 2018 -0400 Commit: Brad King CommitDate: Tue Sep 18 11:16:46 2018 -0400 cmMakefile: Make GetSafeDefinition return std::string const& diff --git a/Source/CTest/cmCTestHandlerCommand.cxx b/Source/CTest/cmCTestHandlerCommand.cxx index 8863dc8..667a8ba 100644 --- a/Source/CTest/cmCTestHandlerCommand.cxx +++ b/Source/CTest/cmCTestHandlerCommand.cxx @@ -151,9 +151,9 @@ bool cmCTestHandlerCommand::InitialPass(std::vector const& args, cmSystemTools::CollapseFullPath(this->Values[ct_BUILD]).c_str(), this->Quiet); } else { - const char* bdir = + std::string const& bdir = this->Makefile->GetSafeDefinition("CTEST_BINARY_DIRECTORY"); - if (bdir) { + if (!bdir.empty()) { this->CTest->SetCTestConfiguration( "BuildDirectory", cmSystemTools::CollapseFullPath(bdir).c_str(), this->Quiet); diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx index 2107d32..a3e135f 100644 --- a/Source/cmComputeLinkInformation.cxx +++ b/Source/cmComputeLinkInformation.cxx @@ -1725,7 +1725,7 @@ void cmComputeLinkInformation::GetRPath(std::vector& runtimeDirs, } const char* stagePath = this->Makefile->GetDefinition("CMAKE_STAGING_PREFIX"); - const char* installPrefix = + std::string const& installPrefix = this->Makefile->GetSafeDefinition("CMAKE_INSTALL_PREFIX"); cmSystemTools::ConvertToUnixSlashes(rootPath); std::vector const& rdirs = this->GetRuntimeSearchPath(); diff --git a/Source/cmDepends.cxx b/Source/cmDepends.cxx index 4716e14..6f1afd7 100644 --- a/Source/cmDepends.cxx +++ b/Source/cmDepends.cxx @@ -36,7 +36,7 @@ bool cmDepends::Write(std::ostream& makeDepends, std::ostream& internalDepends) std::string srcLang = "CMAKE_DEPENDS_CHECK_"; srcLang += this->Language; cmMakefile* mf = this->LocalGenerator->GetMakefile(); - const char* srcStr = mf->GetSafeDefinition(srcLang); + std::string const& srcStr = mf->GetSafeDefinition(srcLang); std::vector pairs; cmSystemTools::ExpandListArgument(srcStr, pairs); diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index 1c5040a..d440080 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -195,7 +195,7 @@ static bool checkInterfaceDirs(const std::string& prepro, cmGeneratorTarget* target, const std::string& prop) { - const char* installDir = + std::string const& installDir = target->Makefile->GetSafeDefinition("CMAKE_INSTALL_PREFIX"); std::string const& topSourceDir = target->GetLocalGenerator()->GetSourceDirectory(); diff --git a/Source/cmExtraCodeBlocksGenerator.cxx b/Source/cmExtraCodeBlocksGenerator.cxx index fbf6560..07a60de 100644 --- a/Source/cmExtraCodeBlocksGenerator.cxx +++ b/Source/cmExtraCodeBlocksGenerator.cxx @@ -666,7 +666,7 @@ std::string cmExtraCodeBlocksGenerator::GetCBCompilerId(const cmMakefile* mf) pureFortran = true; } - std::string compilerId = mf->GetSafeDefinition(compilerIdVar); + std::string const& compilerId = mf->GetSafeDefinition(compilerIdVar); std::string compiler = "gcc"; // default to gcc if (compilerId == "MSVC") { if (mf->IsDefinitionSet("MSVC10")) { diff --git a/Source/cmExtraCodeLiteGenerator.cxx b/Source/cmExtraCodeLiteGenerator.cxx index fe5c7bb..28106d1 100644 --- a/Source/cmExtraCodeLiteGenerator.cxx +++ b/Source/cmExtraCodeLiteGenerator.cxx @@ -599,7 +599,7 @@ std::string cmExtraCodeLiteGenerator::GetCodeLiteCompilerName( compilerIdVar = "CMAKE_C_COMPILER_ID"; } - std::string compilerId = mf->GetSafeDefinition(compilerIdVar); + std::string const& compilerId = mf->GetSafeDefinition(compilerIdVar); std::string compiler = "gnu g++"; // default to g++ // Since we need the compiler for parsing purposes only diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index 1e51f09..54e33c5 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -580,10 +580,11 @@ struct CompilerIdNode : public cmGeneratorExpressionNode cmGeneratorExpressionDAGChecker* /*unused*/, const std::string& lang) const { - const char* compilerId = context->LG->GetMakefile()->GetSafeDefinition( - "CMAKE_" + lang + "_COMPILER_ID"); + std::string const& compilerId = + context->LG->GetMakefile()->GetSafeDefinition("CMAKE_" + lang + + "_COMPILER_ID"); if (parameters.empty()) { - return compilerId ? compilerId : ""; + return compilerId; } static cmsys::RegularExpression compilerIdValidator("^[A-Za-z0-9_]*$"); if (!compilerIdValidator.find(*parameters.begin())) { @@ -591,15 +592,16 @@ struct CompilerIdNode : public cmGeneratorExpressionNode "Expression syntax not recognized."); return std::string(); } - if (!compilerId) { + if (compilerId.empty()) { return parameters.front().empty() ? "1" : "0"; } - if (strcmp(parameters.begin()->c_str(), compilerId) == 0) { + if (strcmp(parameters.begin()->c_str(), compilerId.c_str()) == 0) { return "1"; } - if (cmsysString_strcasecmp(parameters.begin()->c_str(), compilerId) == 0) { + if (cmsysString_strcasecmp(parameters.begin()->c_str(), + compilerId.c_str()) == 0) { switch (context->LG->GetPolicyStatus(cmPolicies::CMP0044)) { case cmPolicies::WARN: { std::ostringstream e; @@ -676,11 +678,11 @@ struct CompilerVersionNode : public cmGeneratorExpressionNode cmGeneratorExpressionDAGChecker* /*unused*/, const std::string& lang) const { - const char* compilerVersion = + std::string const& compilerVersion = context->LG->GetMakefile()->GetSafeDefinition("CMAKE_" + lang + "_COMPILER_VERSION"); if (parameters.empty()) { - return compilerVersion ? compilerVersion : ""; + return compilerVersion; } static cmsys::RegularExpression compilerIdValidator("^[0-9\\.]*$"); @@ -689,13 +691,13 @@ struct CompilerVersionNode : public cmGeneratorExpressionNode "Expression syntax not recognized."); return std::string(); } - if (!compilerVersion) { + if (compilerVersion.empty()) { return parameters.front().empty() ? "1" : "0"; } return cmSystemTools::VersionCompare(cmSystemTools::OP_EQUAL, parameters.begin()->c_str(), - compilerVersion) + compilerVersion.c_str()) ? "1" : "0"; } @@ -757,17 +759,17 @@ struct PlatformIdNode : public cmGeneratorExpressionNode const GeneratorExpressionContent* /*content*/, cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override { - const char* platformId = + std::string const& platformId = context->LG->GetMakefile()->GetSafeDefinition("CMAKE_SYSTEM_NAME"); if (parameters.empty()) { - return platformId ? platformId : ""; + return platformId; } - if (!platformId) { + if (platformId.empty()) { return parameters.front().empty() ? "1" : "0"; } - if (strcmp(parameters.begin()->c_str(), platformId) == 0) { + if (*parameters.begin() == platformId) { return "1"; } return "0"; diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index e8e7b90..f563dd8 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -138,8 +138,7 @@ cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg) this->SourceEntries, true); this->DLLPlatform = - strcmp(this->Makefile->GetSafeDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"), - "") != 0; + !this->Makefile->GetSafeDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX").empty(); this->PolicyMap = t->PolicyMap; } @@ -3489,12 +3488,13 @@ void cmGeneratorTarget::GetFullNameInternal( } // if there is no prefix on the target use the cmake definition + std::string targetPrefix2, targetSuffix2; if (!targetPrefix && prefixVar) { - targetPrefix = this->Makefile->GetSafeDefinition(prefixVar); + targetPrefix2 = this->Makefile->GetSafeDefinition(prefixVar); } // if there is no suffix on the target use the cmake definition if (!targetSuffix && suffixVar) { - targetSuffix = this->Makefile->GetSafeDefinition(suffixVar); + targetSuffix2 = this->Makefile->GetSafeDefinition(suffixVar); } // frameworks have directory prefix but no suffix @@ -3502,19 +3502,19 @@ void cmGeneratorTarget::GetFullNameInternal( if (this->IsFrameworkOnApple()) { fw_prefix = this->GetFrameworkDirectory(config, ContentLevel); fw_prefix += "/"; - targetPrefix = fw_prefix.c_str(); - targetSuffix = nullptr; + targetPrefix2 = fw_prefix; + targetSuffix2.clear(); } if (this->IsCFBundleOnApple()) { fw_prefix = this->GetCFBundleDirectory(config, FullLevel); fw_prefix += "/"; - targetPrefix = fw_prefix.c_str(); - targetSuffix = nullptr; + targetPrefix2 = fw_prefix; + targetSuffix2.clear(); } // Begin the final name with the prefix. - outPrefix = targetPrefix ? targetPrefix : ""; + outPrefix = targetPrefix2; // Append the target name or property-specified name. outBase += this->GetOutputName(config, artifact); @@ -3533,7 +3533,7 @@ void cmGeneratorTarget::GetFullNameInternal( } // Append the suffix. - outSuffix = targetSuffix ? targetSuffix : ""; + outSuffix = targetSuffix2; } std::string cmGeneratorTarget::GetLinkerLanguage( diff --git a/Source/cmGetDirectoryPropertyCommand.cxx b/Source/cmGetDirectoryPropertyCommand.cxx index bf464d9..0d4d653 100644 --- a/Source/cmGetDirectoryPropertyCommand.cxx +++ b/Source/cmGetDirectoryPropertyCommand.cxx @@ -65,7 +65,7 @@ bool cmGetDirectoryPropertyCommand::InitialPass( "providing the name of the variable to get."); return false; } - std::string output = dir->GetSafeDefinition(*i); + std::string const& output = dir->GetSafeDefinition(*i); this->Makefile->AddDefinition(variable, output.c_str()); return true; } diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 99135c8..f504b9f 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -828,8 +828,9 @@ void cmGlobalGenerator::EnableLanguage( std::string sharedLibFlagsVar = "CMAKE_SHARED_LIBRARY_"; sharedLibFlagsVar += lang; sharedLibFlagsVar += "_FLAGS"; - const char* sharedLibFlags = mf->GetSafeDefinition(sharedLibFlagsVar); - if (sharedLibFlags) { + std::string const& sharedLibFlags = + mf->GetSafeDefinition(sharedLibFlagsVar); + if (!sharedLibFlags.empty()) { this->LanguageToOriginalSharedLibFlags[lang] = sharedLibFlags; } @@ -1092,7 +1093,7 @@ void cmGlobalGenerator::FillExtensionToLanguageMap(const std::string& l, { std::string extensionsVar = std::string("CMAKE_") + std::string(l) + std::string("_SOURCE_FILE_EXTENSIONS"); - std::string exts = mf->GetSafeDefinition(extensionsVar); + const std::string& exts = mf->GetSafeDefinition(extensionsVar); std::vector extensionList; cmSystemTools::ExpandListArgument(exts, extensionList); for (std::string const& i : extensionList) { @@ -1112,7 +1113,7 @@ bool cmGlobalGenerator::GlobalSettingIsOn(std::string const& name) const return this->Makefiles[0]->IsOn(name); } -const char* cmGlobalGenerator::GetSafeGlobalSetting( +std::string cmGlobalGenerator::GetSafeGlobalSetting( std::string const& name) const { assert(!this->Makefiles.empty()); @@ -1593,7 +1594,7 @@ void cmGlobalGenerator::FinalizeTargetCompileInfo() for (std::string const& li : langs) { std::string const standardIncludesVar = "CMAKE_" + li + "_STANDARD_INCLUDE_DIRECTORIES"; - std::string const standardIncludesStr = + std::string const& standardIncludesStr = mf->GetSafeDefinition(standardIncludesVar); std::vector standardIncludesVec; cmSystemTools::ExpandListArgument(standardIncludesStr, diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index c06ac52..8924772 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -230,7 +230,7 @@ public: const char* GetGlobalSetting(std::string const& name) const; bool GlobalSettingIsOn(std::string const& name) const; - const char* GetSafeGlobalSetting(std::string const& name) const; + std::string GetSafeGlobalSetting(std::string const& name) const; /** Add a file to the manifest of generated targets for a configuration. */ void AddToManifest(std::string const& f); diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 0c80910..4948c73 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -651,13 +651,13 @@ void cmGlobalNinjaGenerator::EnableLanguage( this->ResolveLanguageCompiler(l, mf, optional); } #ifdef _WIN32 - if (strcmp(mf->GetSafeDefinition("CMAKE_C_SIMULATE_ID"), "MSVC") != 0 && - strcmp(mf->GetSafeDefinition("CMAKE_CXX_SIMULATE_ID"), "MSVC") != 0 && + if ((mf->GetSafeDefinition("CMAKE_C_SIMULATE_ID") != "MSVC") && + (mf->GetSafeDefinition("CMAKE_CXX_SIMULATE_ID") != "MSVC") && (mf->IsOn("CMAKE_COMPILER_IS_MINGW") || - strcmp(mf->GetSafeDefinition("CMAKE_C_COMPILER_ID"), "GNU") == 0 || - strcmp(mf->GetSafeDefinition("CMAKE_CXX_COMPILER_ID"), "GNU") == 0 || - strcmp(mf->GetSafeDefinition("CMAKE_C_COMPILER_ID"), "Clang") == 0 || - strcmp(mf->GetSafeDefinition("CMAKE_CXX_COMPILER_ID"), "Clang") == 0)) { + (mf->GetSafeDefinition("CMAKE_C_COMPILER_ID") == "GNU") || + (mf->GetSafeDefinition("CMAKE_CXX_COMPILER_ID") == "GNU") || + (mf->GetSafeDefinition("CMAKE_C_COMPILER_ID") == "Clang") || + (mf->GetSafeDefinition("CMAKE_CXX_COMPILER_ID") == "Clang"))) { this->UsingGCCOnWindows = true; } #endif diff --git a/Source/cmInstallCommand.cxx b/Source/cmInstallCommand.cxx index d7fe777..6e33cf7 100644 --- a/Source/cmInstallCommand.cxx +++ b/Source/cmInstallCommand.cxx @@ -5,7 +5,6 @@ #include "cmsys/Glob.hxx" #include #include -#include #include #include "cmAlgorithms.h" @@ -350,8 +349,7 @@ bool cmInstallCommand::HandleTargetsMode(std::vector const& args) // Check whether this is a DLL platform. bool dll_platform = - strcmp(this->Makefile->GetSafeDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"), - "") != 0; + !this->Makefile->GetSafeDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX").empty(); for (std::string const& tgt : targetList.GetVector()) { diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 4f8f2e7..7eb4ef4 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -683,7 +683,7 @@ std::string cmLocalGenerator::GetIncludeFlags( std::string flagVar = "CMAKE_INCLUDE_FLAG_"; flagVar += lang; - const char* includeFlag = this->Makefile->GetSafeDefinition(flagVar); + std::string const& includeFlag = this->Makefile->GetSafeDefinition(flagVar); flagVar = "CMAKE_INCLUDE_FLAG_SEP_"; flagVar += lang; const char* sep = this->Makefile->GetDefinition(flagVar); @@ -1824,9 +1824,9 @@ bool cmLocalGenerator::GetShouldUseOldFlags(bool shared, std::string flagsVar = "CMAKE_SHARED_LIBRARY_"; flagsVar += lang; flagsVar += "_FLAGS"; - const char* flags = this->Makefile->GetSafeDefinition(flagsVar); + std::string const& flags = this->Makefile->GetSafeDefinition(flagsVar); - if (flags && flags != originalFlags) { + if (!flags.empty() && flags != originalFlags) { switch (this->GetPolicyStatus(cmPolicies::CMP0018)) { case cmPolicies::WARN: { std::ostringstream e; @@ -1859,7 +1859,7 @@ void cmLocalGenerator::AddPositionIndependentFlags(std::string& flags, std::string const& lang, int targetType) { - const char* picFlags = nullptr; + std::string picFlags; if (targetType == cmStateEnums::EXECUTABLE) { std::string flagsVar = "CMAKE_"; @@ -1867,13 +1867,13 @@ void cmLocalGenerator::AddPositionIndependentFlags(std::string& flags, flagsVar += "_COMPILE_OPTIONS_PIE"; picFlags = this->Makefile->GetSafeDefinition(flagsVar); } - if (!picFlags) { + if (picFlags.empty()) { std::string flagsVar = "CMAKE_"; flagsVar += lang; flagsVar += "_COMPILE_OPTIONS_PIC"; picFlags = this->Makefile->GetSafeDefinition(flagsVar); } - if (picFlags) { + if (!picFlags.empty()) { std::vector options; cmSystemTools::ExpandListArgument(picFlags, options); for (std::string const& o : options) { diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index 690b827..272cc0e 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -1422,7 +1422,8 @@ bool cmLocalUnixMakefileGenerator3::ScanDependencies( this->WriteDisclaimer(internalRuleFileStream); // for each language we need to scan, scan it - const char* langStr = mf->GetSafeDefinition("CMAKE_DEPENDS_LANGUAGES"); + std::string const& langStr = + mf->GetSafeDefinition("CMAKE_DEPENDS_LANGUAGES"); std::vector langs; cmSystemTools::ExpandListArgument(langStr, langs); for (std::string const& lang : langs) { diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index c05b085..c03afdd 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -1082,7 +1082,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool( // Use the NOINHERIT macro to avoid getting VS project default // libraries which may be set by the user to something bad. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) " - << this->Makefile->GetSafeDefinition(standardLibsVar.c_str()); + << this->Makefile->GetSafeDefinition(standardLibsVar); if (this->FortranProject) { this->Internal->OutputObjects(fout, target, configName, " "); } @@ -1167,7 +1167,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool( // Use the NOINHERIT macro to avoid getting VS project default // libraries which may be set by the user to something bad. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) " - << this->Makefile->GetSafeDefinition(standardLibsVar.c_str()); + << this->Makefile->GetSafeDefinition(standardLibsVar); if (this->FortranProject) { this->Internal->OutputObjects(fout, target, configName, " "); } diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index dce7bd0..26cc10d 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -2384,7 +2384,7 @@ bool cmMakefile::IsDefinitionSet(const std::string& name) const return def != nullptr; } -const char* cmMakefile::GetDefinition(const std::string& name) const +const std::string* cmMakefile::GetDef(const std::string& name) const { const std::string* def = this->StateSnapshot.GetDefinition(name); if (!def) { @@ -2410,16 +2410,26 @@ const char* cmMakefile::GetDefinition(const std::string& name) const } } #endif - return (def ? def->c_str() : nullptr); + return def; } -const char* cmMakefile::GetSafeDefinition(const std::string& def) const +const char* cmMakefile::GetDefinition(const std::string& name) const { - const char* ret = this->GetDefinition(def); - if (!ret) { - return ""; + const std::string* def = GetDef(name); + if (!def) { + return nullptr; } - return ret; + return def->c_str(); +} + +const std::string& cmMakefile::GetSafeDefinition(const std::string& name) const +{ + static std::string const empty; + const std::string* def = GetDef(name); + if (!def) { + return empty; + } + return *def; } std::vector cmMakefile::GetDefinitions() const diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 0ab4371..8c7eb31 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -422,7 +422,8 @@ public: * cache is then queried. */ const char* GetDefinition(const std::string&) const; - const char* GetSafeDefinition(const std::string&) const; + const std::string* GetDef(const std::string&) const; + const std::string& GetSafeDefinition(const std::string&) const; std::string GetRequiredDefinition(const std::string& name) const; bool IsDefinitionSet(const std::string&) const; /** diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index ebcc501..7ac8d1b 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -10,7 +10,6 @@ #include #include // IWYU pragma: keep #include -#include #include "cmAlgorithms.h" #include "cmComputeLinkInformation.h" @@ -174,9 +173,8 @@ void cmNinjaTargetGenerator::AddIncludeFlags(std::string& languageFlags, bool cmNinjaTargetGenerator::NeedDepTypeMSVC(const std::string& lang) const { - return strcmp(this->GetMakefile()->GetSafeDefinition("CMAKE_NINJA_DEPTYPE_" + - lang), - "msvc") == 0; + return (this->GetMakefile()->GetSafeDefinition("CMAKE_NINJA_DEPTYPE_" + + lang) == "msvc"); } // TODO: Refactor with diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx index ba50fb8..5caea7d 100644 --- a/Source/cmPolicies.cxx +++ b/Source/cmPolicies.cxx @@ -135,7 +135,7 @@ static bool GetPolicyDefault(cmMakefile* mf, std::string const& policy, cmPolicies::PolicyStatus* defaultSetting) { std::string defaultVar = "CMAKE_POLICY_DEFAULT_" + policy; - std::string defaultValue = mf->GetSafeDefinition(defaultVar); + std::string const& defaultValue = mf->GetSafeDefinition(defaultVar); if (defaultValue == "NEW") { *defaultSetting = cmPolicies::NEW; } else if (defaultValue == "OLD") { diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index 8bd985a..8a202a2 100644 --- a/Source/cmQtAutoGenInitializer.cxx +++ b/Source/cmQtAutoGenInitializer.cxx @@ -1126,7 +1126,7 @@ bool cmQtAutoGenInitializer::SetupWriteAutogenInfo() } }; auto MfDef = [makefile](const char* key) { - return std::string(makefile->GetSafeDefinition(key)); + return makefile->GetSafeDefinition(key); }; // Write diff --git a/Source/cmQtAutoGeneratorMocUic.cxx b/Source/cmQtAutoGeneratorMocUic.cxx index c364700..2e6f90f 100644 --- a/Source/cmQtAutoGeneratorMocUic.cxx +++ b/Source/cmQtAutoGeneratorMocUic.cxx @@ -1204,7 +1204,7 @@ bool cmQtAutoGeneratorMocUic::Init(cmMakefile* makefile) valueConf = makefile->GetDefinition(keyConf); } if (valueConf == nullptr) { - valueConf = makefile->GetSafeDefinition(key); + return makefile->GetSafeDefinition(key); } return std::string(valueConf); }; @@ -1226,7 +1226,7 @@ bool cmQtAutoGeneratorMocUic::Init(cmMakefile* makefile) Base_.MultiConfig = InfoGetBool("AM_MULTI_CONFIG"); { unsigned long num = Base_.NumThreads; - if (cmSystemTools::StringToULong(InfoGet("AM_PARALLEL"), &num)) { + if (cmSystemTools::StringToULong(InfoGet("AM_PARALLEL").c_str(), &num)) { num = std::max(num, 1); num = std::min(num, ParallelMax); Base_.NumThreads = static_cast(num); @@ -1264,7 +1264,8 @@ bool cmQtAutoGeneratorMocUic::Init(cmMakefile* makefile) // - Qt environment { unsigned long qtv = Base_.QtVersionMajor; - if (cmSystemTools::StringToULong(InfoGet("AM_QT_VERSION_MAJOR"), &qtv)) { + if (cmSystemTools::StringToULong(InfoGet("AM_QT_VERSION_MAJOR").c_str(), + &qtv)) { Base_.QtVersionMajor = static_cast(qtv); } } diff --git a/Source/cmQtAutoGeneratorRcc.cxx b/Source/cmQtAutoGeneratorRcc.cxx index 6caa0d8..65c6741 100644 --- a/Source/cmQtAutoGeneratorRcc.cxx +++ b/Source/cmQtAutoGeneratorRcc.cxx @@ -52,7 +52,7 @@ bool cmQtAutoGeneratorRcc::Init(cmMakefile* makefile) valueConf = makefile->GetDefinition(keyConf); } if (valueConf == nullptr) { - valueConf = makefile->GetSafeDefinition(key); + return makefile->GetSafeDefinition(key); } return std::string(valueConf); }; diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index cfcb31a..703c552 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -190,13 +190,11 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, // Check whether this is a DLL platform. this->DLLPlatform = - strcmp(this->Makefile->GetSafeDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"), - "") != 0; + !this->Makefile->GetSafeDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX").empty(); // Check whether we are targeting an Android platform. this->IsAndroid = - strcmp(this->Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME"), - "Android") == 0; + (this->Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME") == "Android"); // Setup default property values. if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY && diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 53a2a59..9d9703c 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -2699,11 +2699,9 @@ bool cmVisualStudio10TargetGenerator::ComputeRcOptions( Options& rcOptions = *pOptions; std::string CONFIG = cmSystemTools::UpperCase(configName); - std::string rcConfigFlagsVar = std::string("CMAKE_RC_FLAGS_") + CONFIG; - std::string flags = - std::string(this->Makefile->GetSafeDefinition("CMAKE_RC_FLAGS")) + - std::string(" ") + - std::string(this->Makefile->GetSafeDefinition(rcConfigFlagsVar)); + std::string rcConfigFlagsVar = "CMAKE_RC_FLAGS_" + CONFIG; + std::string flags = this->Makefile->GetSafeDefinition("CMAKE_RC_FLAGS") + + " " + this->Makefile->GetSafeDefinition(rcConfigFlagsVar); rcOptions.Parse(flags); @@ -2757,10 +2755,8 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaOptions( // Get compile flags for CUDA in this directory. std::string CONFIG = cmSystemTools::UpperCase(configName); std::string configFlagsVar = std::string("CMAKE_CUDA_FLAGS_") + CONFIG; - std::string flags = - std::string(this->Makefile->GetSafeDefinition("CMAKE_CUDA_FLAGS")) + - std::string(" ") + - std::string(this->Makefile->GetSafeDefinition(configFlagsVar)); + std::string flags = this->Makefile->GetSafeDefinition("CMAKE_CUDA_FLAGS") + + " " + this->Makefile->GetSafeDefinition(configFlagsVar); this->LocalGenerator->AddCompileOptions(flags, this->GeneratorTarget, "CUDA", configName); @@ -2971,9 +2967,8 @@ bool cmVisualStudio10TargetGenerator::ComputeMasmOptions( std::string CONFIG = cmSystemTools::UpperCase(configName); std::string configFlagsVar = std::string("CMAKE_ASM_MASM_FLAGS_") + CONFIG; std::string flags = - std::string(this->Makefile->GetSafeDefinition("CMAKE_ASM_MASM_FLAGS")) + - std::string(" ") + - std::string(this->Makefile->GetSafeDefinition(configFlagsVar)); + this->Makefile->GetSafeDefinition("CMAKE_ASM_MASM_FLAGS") + " " + + this->Makefile->GetSafeDefinition(configFlagsVar); masmOptions.Parse(flags); @@ -3024,14 +3019,11 @@ bool cmVisualStudio10TargetGenerator::ComputeNasmOptions( Options& nasmOptions = *pOptions; std::string CONFIG = cmSystemTools::UpperCase(configName); - std::string configFlagsVar = std::string("CMAKE_ASM_NASM_FLAGS_") + CONFIG; + std::string configFlagsVar = "CMAKE_ASM_NASM_FLAGS_" + CONFIG; std::string flags = - std::string(this->Makefile->GetSafeDefinition("CMAKE_ASM_NASM_FLAGS")) + - std::string(" -f") + - std::string( - this->Makefile->GetSafeDefinition("CMAKE_ASM_NASM_OBJECT_FORMAT")) + - std::string(" ") + - std::string(this->Makefile->GetSafeDefinition(configFlagsVar)); + this->Makefile->GetSafeDefinition("CMAKE_ASM_NASM_FLAGS") + " -f" + + this->Makefile->GetSafeDefinition("CMAKE_ASM_NASM_OBJECT_FORMAT") + " " + + this->Makefile->GetSafeDefinition(configFlagsVar); nasmOptions.Parse(flags); // Get includes for this target https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=7adf3aabd55dd80784727a229a37c394740db628 commit 7adf3aabd55dd80784727a229a37c394740db628 Merge: f9eac2a 2a2f0ac Author: Brad King AuthorDate: Tue Sep 18 15:16:03 2018 +0000 Commit: Kitware Robot CommitDate: Tue Sep 18 11:16:09 2018 -0400 Merge topic 'if-version-docs' 2a2f0ac231 Help: Clarify handling of non-integer components in if() version tests Acked-by: Kitware Robot Merge-request: !2393 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=f9eac2ae4b986f74a97fe16fa19df94331a52b34 commit f9eac2ae4b986f74a97fe16fa19df94331a52b34 Merge: 6097d8d 329f6ae Author: Brad King AuthorDate: Tue Sep 18 15:15:07 2018 +0000 Commit: Kitware Robot CommitDate: Tue Sep 18 11:15:13 2018 -0400 Merge topic 'FindPython-updates' 329f6aeca5 FindPython*: Windows: add facility to select lookup order for registry. ffb560adc9 FindPython*: MacOS: Fix erroneous handling of Frameworks. b0b53921ce FindPython: clean-up lookup names strategy Acked-by: Kitware Robot Merge-request: !2369 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=bef80e66231a0bd2feffab02fe8d1d8f55eb793c commit bef80e66231a0bd2feffab02fe8d1d8f55eb793c Author: Brad King AuthorDate: Wed Sep 12 13:45:05 2018 -0400 Commit: Brad King CommitDate: Mon Sep 17 10:53:27 2018 -0400 VS: Do not specify incremental linking if LTCG is enabled Otherwise the linker may warn: LNK4075: ignoring '/INCREMENTAL' due to '/LTCG' specification diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index c0b0435..2a54cfc 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -2374,9 +2374,11 @@ void cmVisualStudio10TargetGenerator::OutputLinkIncremental( Options& linkOptions = *(this->LinkOptions[configName]); const std::string cond = this->CalcCondition(configName); - const char* incremental = linkOptions.GetFlag("LinkIncremental"); - e1.WritePlatformConfigTag("LinkIncremental", cond, - (incremental ? incremental : "true")); + if (this->IPOEnabledConfigurations.count(configName) == 0) { + const char* incremental = linkOptions.GetFlag("LinkIncremental"); + e1.WritePlatformConfigTag("LinkIncremental", cond, + (incremental ? incremental : "true")); + } linkOptions.RemoveFlag("LinkIncremental"); const char* manifest = linkOptions.GetFlag("GenerateManifest"); https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=567fabe88e97c3e39503fd353b484648bcf1cbb2 commit 567fabe88e97c3e39503fd353b484648bcf1cbb2 Author: Niels Dekker AuthorDate: Sun Sep 9 23:04:59 2018 +0200 Commit: Brad King CommitDate: Mon Sep 17 10:53:10 2018 -0400 IPO: INTERPROCEDURAL_OPTIMIZATION (LTCG) for Visual Studio Add IPO support for Visual Studio (which is referred to by VS as "Link Time Code Generation" and "Whole Program Optimization"), for VS version >= 10. This allows CMake/VS users to enable IPO by setting property `INTERPROCEDURAL_OPTIMIZATION`. Fixes: #16748 diff --git a/Help/release/dev/vs-ipo.rst b/Help/release/dev/vs-ipo.rst new file mode 100644 index 0000000..a31601f --- /dev/null +++ b/Help/release/dev/vs-ipo.rst @@ -0,0 +1,6 @@ +vs-ipo +------ + +* The :ref:`Visual Studio Generators` for VS 2010 and above learned to + support the :prop_tgt:`INTERPROCEDURAL_OPTIMIZATION` target property + and supporting :module:`CheckIPOSupported` module. diff --git a/Modules/CheckIPOSupported.cmake b/Modules/CheckIPOSupported.cmake index 3344834..ad8852c 100644 --- a/Modules/CheckIPOSupported.cmake +++ b/Modules/CheckIPOSupported.cmake @@ -226,7 +226,7 @@ function(check_ipo_supported) endif() endforeach() - if(CMAKE_GENERATOR MATCHES "^Visual Studio ") + if(CMAKE_GENERATOR MATCHES "^Visual Studio 9 ") _ipo_not_supported("CMake doesn't support IPO for current generator") return() endif() diff --git a/Source/cmGlobalVisualStudio10Generator.h b/Source/cmGlobalVisualStudio10Generator.h index 6eb597c..63e6903 100644 --- a/Source/cmGlobalVisualStudio10Generator.h +++ b/Source/cmGlobalVisualStudio10Generator.h @@ -111,6 +111,8 @@ public: bool FindMakeProgram(cmMakefile* mf) override; + bool IsIPOSupported() const override { return true; } + static std::string GetInstalledNsightTegraVersion(); cmIDEFlagTable const* GetClFlagTable() const; diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 9e74335..c0b0435 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -1122,6 +1122,9 @@ void cmVisualStudio10TargetGenerator::WriteMSToolConfigurationValues( this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_EXTENSIONS")) { e1.Element("WindowsAppContainer", "true"); } + if (this->IPOEnabledConfigurations.count(config) > 0) { + e1.Element("WholeProgramOptimization", "true"); + } } void cmVisualStudio10TargetGenerator::WriteMSToolConfigurationValuesManaged( @@ -2485,8 +2488,10 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( clOptions.AddFlag("CompileAs", "CompileAsCpp"); } - // Check IPO related warning/error. - this->GeneratorTarget->IsIPOEnabled(linkLanguage, configName); + // Put the IPO enabled configurations into a set. + if (this->GeneratorTarget->IsIPOEnabled(linkLanguage, configName)) { + this->IPOEnabledConfigurations.insert(configName); + } // Get preprocessor definitions for this directory. std::string defineFlags = this->Makefile->GetDefineFlags(); diff --git a/Source/cmVisualStudio10TargetGenerator.h b/Source/cmVisualStudio10TargetGenerator.h index 15e47b4..829d2bf 100644 --- a/Source/cmVisualStudio10TargetGenerator.h +++ b/Source/cmVisualStudio10TargetGenerator.h @@ -204,6 +204,7 @@ private: bool NsightTegra; unsigned int NsightTegraVersion[4]; bool TargetCompileAsWinRT; + std::set IPOEnabledConfigurations; cmGlobalVisualStudio10Generator* const GlobalGenerator; cmLocalVisualStudio10Generator* const LocalGenerator; std::set CSharpCustomCommandNames; diff --git a/Tests/RunCMake/CMP0069/RunCMakeTest.cmake b/Tests/RunCMake/CMP0069/RunCMakeTest.cmake index f44f840..456e6a6 100644 --- a/Tests/RunCMake/CMP0069/RunCMakeTest.cmake +++ b/Tests/RunCMake/CMP0069/RunCMakeTest.cmake @@ -5,6 +5,6 @@ run_cmake(CMP0069-NEW-cmake) run_cmake(CMP0069-NEW-compiler) run_cmake(CMP0069-WARN) -if(RunCMake_GENERATOR MATCHES "^Visual Studio ") +if(RunCMake_GENERATOR MATCHES "^Visual Studio 9 ") run_cmake(CMP0069-NEW-generator) endif() diff --git a/Tests/RunCMake/CheckIPOSupported/RunCMakeTest.cmake b/Tests/RunCMake/CheckIPOSupported/RunCMakeTest.cmake index e145569..b7d524c 100644 --- a/Tests/RunCMake/CheckIPOSupported/RunCMakeTest.cmake +++ b/Tests/RunCMake/CheckIPOSupported/RunCMakeTest.cmake @@ -8,6 +8,6 @@ run_cmake(not-supported-by-compiler) run_cmake(save-to-result) run_cmake(cmp0069-is-old) -if(RunCMake_GENERATOR MATCHES "^Visual Studio ") +if(RunCMake_GENERATOR MATCHES "^Visual Studio 9 ") run_cmake(not-supported-by-generator) endif() https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=53ad52d66d2056a4bf797d22ce1d3ee5395679a6 commit 53ad52d66d2056a4bf797d22ce1d3ee5395679a6 Author: Marc Chevrier AuthorDate: Mon Sep 17 16:42:37 2018 +0200 Commit: Marc Chevrier CommitDate: Mon Sep 17 16:42:37 2018 +0200 LINK_OPTIONS: Add missing initialization actions diff --git a/Source/cmState.cxx b/Source/cmState.cxx index c8b8653..c6667f6 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -659,6 +659,7 @@ cmStateSnapshot cmState::CreateBaseSnapshot() pos->IncludeDirectoryPosition = 0; pos->CompileDefinitionsPosition = 0; pos->CompileOptionsPosition = 0; + pos->LinkOptionsPosition = 0; pos->BuildSystemDirectory->DirectoryEnd = pos; pos->Policies = this->PolicyStack.Root(); pos->PolicyRoot = this->PolicyStack.Root(); @@ -810,6 +811,8 @@ cmStateSnapshot cmState::Pop(cmStateSnapshot const& originSnapshot) prevPos->BuildSystemDirectory->CompileDefinitions.size(); prevPos->CompileOptionsPosition = prevPos->BuildSystemDirectory->CompileOptions.size(); + prevPos->LinkOptionsPosition = + prevPos->BuildSystemDirectory->LinkOptions.size(); prevPos->BuildSystemDirectory->DirectoryEnd = prevPos; if (!pos->Keep && this->SnapshotData.IsLast(pos)) { https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=2a2f0ac231fe31052c6fabc2b2829653c5cea2fa commit 2a2f0ac231fe31052c6fabc2b2829653c5cea2fa Author: Craig Scott AuthorDate: Sun Sep 16 11:15:47 2018 +0800 Commit: Craig Scott CommitDate: Mon Sep 17 18:12:08 2018 +0800 Help: Clarify handling of non-integer components in if() version tests diff --git a/Help/command/if.rst b/Help/command/if.rst index f04f233..5294ce8 100644 --- a/Help/command/if.rst +++ b/Help/command/if.rst @@ -148,23 +148,33 @@ Possible expressions are: ``if( VERSION_LESS )`` Component-wise integer version number comparison (version format is - ``major[.minor[.patch[.tweak]]]``). + ``major[.minor[.patch[.tweak]]]``, omitted components are treated as zero). + Any non-integer version component or non-integer trailing part of a version + component effectively truncates the string at that point. ``if( VERSION_GREATER )`` Component-wise integer version number comparison (version format is - ``major[.minor[.patch[.tweak]]]``). + ``major[.minor[.patch[.tweak]]]``, omitted components are treated as zero). + Any non-integer version component or non-integer trailing part of a version + component effectively truncates the string at that point. ``if( VERSION_EQUAL )`` Component-wise integer version number comparison (version format is - ``major[.minor[.patch[.tweak]]]``). + ``major[.minor[.patch[.tweak]]]``, omitted components are treated as zero). + Any non-integer version component or non-integer trailing part of a version + component effectively truncates the string at that point. ``if( VERSION_LESS_EQUAL )`` Component-wise integer version number comparison (version format is - ``major[.minor[.patch[.tweak]]]``). + ``major[.minor[.patch[.tweak]]]``, omitted components are treated as zero). + Any non-integer version component or non-integer trailing part of a version + component effectively truncates the string at that point. ``if( VERSION_GREATER_EQUAL )`` Component-wise integer version number comparison (version format is - ``major[.minor[.patch[.tweak]]]``). + ``major[.minor[.patch[.tweak]]]``, omitted components are treated as zero). + Any non-integer version component or non-integer trailing part of a version + component effectively truncates the string at that point. ``if( IN_LIST )`` True if the given element is contained in the named list variable. https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=329f6aeca5011e423a65ccede3177cd4f0ef1e21 commit 329f6aeca5011e423a65ccede3177cd4f0ef1e21 Author: Marc Chevrier AuthorDate: Tue Sep 11 10:48:08 2018 +0200 Commit: Marc Chevrier CommitDate: Wed Sep 12 10:04:05 2018 +0200 FindPython*: Windows: add facility to select lookup order for registry. Fixes: #18302 diff --git a/Help/release/dev/FindPython-lookup-strategy.rst b/Help/release/dev/FindPython-lookup-strategy.rst new file mode 100644 index 0000000..f6d6db5 --- /dev/null +++ b/Help/release/dev/FindPython-lookup-strategy.rst @@ -0,0 +1,6 @@ +FindPython-lookup-strategy +-------------------------- + +* Modules :module:`FindPython3`, :module:`FindPython2` and :module:`FindPython` + gain capability to control order of resource lookup on macOS (Framework) and + Windows (Registry). diff --git a/Modules/FindPython.cmake b/Modules/FindPython.cmake index b8657b4..0bf0b4f 100644 --- a/Modules/FindPython.cmake +++ b/Modules/FindPython.cmake @@ -116,6 +116,17 @@ Hints * If set to TRUE, search **only** for static libraries. * If set to FALSE, search **only** for shared libraries. +``Python_FIND_REGISTRY`` + On Windows the ``Python_FIND_REGISTRY`` variable determine the order + of preference between registry and environment variables. + the ``Python_FIND_REGISTRY`` variable can be set to empty or one of the + following: + + * ``FIRST``: Try to use registry before environment variables. + This is the default. + * ``LAST``: Try to use registry after environment variables. + * ``NEVER``: Never try to use registry. + ``CMAKE_FIND_FRAMEWORK`` On OS X the :variable:`CMAKE_FIND_FRAMEWORK` variable determine the order of preference between Apple-style and unix-style package components. diff --git a/Modules/FindPython/Support.cmake b/Modules/FindPython/Support.cmake index 137c769..1834591 100644 --- a/Modules/FindPython/Support.cmake +++ b/Modules/FindPython/Support.cmake @@ -100,7 +100,7 @@ function (_PYTHON_VALIDATE_INTERPRETER) return() endif() else() - if (python_name STREQUAL "python${CMAKE_EXECUTABLE_SUFFIX}") + if (NOT python_name STREQUAL "python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}${CMAKE_EXECUTABLE_SUFFIX}") # executable found do not have version in name # ensure major version is OK execute_process (COMMAND "${${_PYTHON_PREFIX}_EXECUTABLE}" -c @@ -135,6 +135,33 @@ function (_PYTHON_VALIDATE_INTERPRETER) endfunction() +function (_PYTHON_VALIDATE_COMPILER expected_version) + if (NOT ${_PYTHON_PREFIX}_COMPILER) + return() + endif() + + # retrieve python environment version from compiler + set (working_dir "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/PythonCompilerVersion.dir") + file (WRITE "${working_dir}/version.py" "import sys; sys.stdout.write('.'.join([str(x) for x in sys.version_info[:2]]))\n") + execute_process (COMMAND "${${_PYTHON_PREFIX}_COMPILER}" /target:exe /embed "${working_dir}/version.py" + WORKING_DIRECTORY "${working_dir}" + OUTPUT_QUIET + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process (COMMAND "${working_dir}/version" + WORKING_DIRECTORY "${working_dir}" + RESULT_VARIABLE result + OUTPUT_VARIABLE version + ERROR_QUIET) + file (REMOVE_RECURSE "${_${_PYTHON_PREFIX}_VERSION_DIR}") + + if (result OR NOT version EQUAL expected_version) + # Compiler not usable or has wrong major version + set (${_PYTHON_PREFIX}_COMPILER ${_PYTHON_PREFIX}_COMPILER-NOTFOUND CACHE INTERNAL "" FORCE) + endif() +endfunction() + + function (_PYTHON_FIND_RUNTIME_LIBRARY _PYTHON_LIB) string (REPLACE "_RUNTIME" "" _PYTHON_LIB "${_PYTHON_LIB}") # look at runtime part on systems supporting it @@ -223,6 +250,7 @@ else() # architecture unknown, search for natural interpreter set (_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES ipy) endif() +set (_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES net45 net40) # Apple frameworks handling _python_find_frameworks () @@ -252,6 +280,18 @@ endif() # To avoid framework lookup set (CMAKE_FIND_FRAMEWORK "NEVER") +# Windows Registry handling +if (DEFINED ${_PYTHON_PREFIX}_FIND_REGISTRY) + if (NOT ${_PYTHON_PREFIX}_FIND_REGISTRY MATCHES "^(FIRST|LAST|NEVER)$") + message (AUTHOR_WARNING "Find${_PYTHON_PREFIX}: ${${_PYTHON_PREFIX}_FIND_REGISTRY}: invalid value for '${_PYTHON_PREFIX}_FIND_REGISTRY'. 'FIRST', 'LAST' or 'NEVER' expected.") + set (_${_PYTHON_PREFIX}_FIND_REGISTRY "FIRST") + else() + set (_${_PYTHON_PREFIX}_FIND_REGISTRY ${${_PYTHON_PREFIX}_FIND_REGISTRY}) + endif() +else() + set (_${_PYTHON_PREFIX}_FIND_REGISTRY "FIRST") +endif() + unset (_${_PYTHON_PREFIX}_REQUIRED_VARS) unset (_${_PYTHON_PREFIX}_CACHED_VARS) @@ -286,18 +326,8 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) NO_CMAKE_SYSTEM_PATH) endif() - # try using HINTS - find_program (${_PYTHON_PREFIX}_EXECUTABLE - NAMES python${_${_PYTHON_PREFIX}_VERSION} - python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR} - NAMES_PER_DIR - HINTS ${_${_PYTHON_PREFIX}_HINTS} - PATH_SUFFIXES bin - NO_SYSTEM_ENVIRONMENT_PATH - NO_CMAKE_SYSTEM_PATH) - - # try using registry - if (WIN32) + # Windows registry + if (WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "FIRST") find_program (${_PYTHON_PREFIX}_EXECUTABLE NAMES python${_${_PYTHON_PREFIX}_VERSION} python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR} @@ -312,15 +342,33 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath] [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH2}\\InstallPath] [HKEY_LOCAL_MACHINE\\SOFTWARE\\IronPython\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath] - PATH_SUFFIXES bin + PATH_SUFFIXES bin ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES} NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) endif() - # try in standard paths + # try using HINTS find_program (${_PYTHON_PREFIX}_EXECUTABLE NAMES python${_${_PYTHON_PREFIX}_VERSION} - NAMES_PER_DIR) + python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR} + python + ${_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES} + NAMES_PER_DIR + HINTS ${_${_PYTHON_PREFIX}_HINTS} + PATH_SUFFIXES bin + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH) + # try using standard paths. + # NAMES_PER_DIR is not defined on purpose to have a chance to find + # expected version. + # For example, typical systems have 'python' for version 2.* and 'python3' + # for version 3.*. So looking for names per dir will find, potentially, + # systematically 'python' (i.e. version 2) even if version 3 is searched. + find_program (${_PYTHON_PREFIX}_EXECUTABLE + NAMES python${_${_PYTHON_PREFIX}_VERSION} + python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR} + python + ${_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES}) # Apple frameworks handling if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "LAST") @@ -333,24 +381,52 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) NO_DEFAULT_PATH) endif() + # Windows registry + if (WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "LAST") + find_program (${_PYTHON_PREFIX}_EXECUTABLE + NAMES python${_${_PYTHON_PREFIX}_VERSION} + python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR} + python + ${_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES} + NAMES_PER_DIR + PATHS [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath] + [HKEY_CURRENT_USER\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath] + [HKEY_CURRENT_USER\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH2}\\InstallPath] + [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath] + [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath] + [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH2}\\InstallPath] + [HKEY_LOCAL_MACHINE\\SOFTWARE\\IronPython\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath] + PATH_SUFFIXES bin ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES} + NO_DEFAULT_PATH) + endif() + _python_validate_interpreter (${_${_PYTHON_PREFIX}_VERSION}) if (${_PYTHON_PREFIX}_EXECUTABLE) break() endif() endforeach() - # try more generic names. NAMES_PER_DIR is not specified on purpose to have a - # chance to find expected version. - # For example, typical systems have 'python' for version 2.* and 'python3' - # for version 3.*. So looking for names per dir will find, potentially, - # systematically 'python' (i.e. version 2) even if version 3 is searched. if (NOT ${_PYTHON_PREFIX}_EXECUTABLE) + # No specific version found. Retry with generic names + # try using HINTS find_program (${_PYTHON_PREFIX}_EXECUTABLE NAMES python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR} python ${_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES} HINTS ${_${_PYTHON_PREFIX}_HINTS} - PATH_SUFFIXES bin) + PATH_SUFFIXES bin ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES} + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH) + # try using standard paths. + # NAMES_PER_DIR is not defined on purpose to have a chance to find + # expected version. + # For example, typical systems have 'python' for version 2.* and 'python3' + # for version 3.*. So looking for names per dir will find, potentially, + # systematically 'python' (i.e. version 2) even if version 3 is searched. + find_program (${_PYTHON_PREFIX}_EXECUTABLE + NAMES python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR} + python + ${_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES}) _python_validate_interpreter () endif() @@ -451,19 +527,42 @@ if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) # try using root dir and registry foreach (_${_PYTHON_PREFIX}_VERSION IN LISTS _${_PYTHON_PREFIX}_FIND_VERSIONS) + if (_${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "FIRST") + find_program (${_PYTHON_PREFIX}_COMPILER + NAMES ipyc + HINTS ${_${_PYTHON_PREFIX}_IRON_ROOT} ${_${_PYTHON_PREFIX}_HINTS} + PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\IronPython\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath] + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES} + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH) + endif() + find_program (${_PYTHON_PREFIX}_COMPILER NAMES ipyc HINTS ${_${_PYTHON_PREFIX}_IRON_ROOT} ${_${_PYTHON_PREFIX}_HINTS} - PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\IronPython\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath] + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES} NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) + + if (_${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "LAST") + find_program (${_PYTHON_PREFIX}_COMPILER + NAMES ipyc + PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\IronPython\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath] + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES} + NO_DEFAULT_PATH) + endif() + + _python_validate_compiler (${_${_PYTHON_PREFIX}_VERSION}) if (${_PYTHON_PREFIX}_COMPILER) break() endif() endforeach() - # try in standard paths + + # no specific version found, re-try in standard paths find_program (${_PYTHON_PREFIX}_COMPILER - NAMES ipyc) + NAMES ipyc + HINTS ${_${_PYTHON_PREFIX}_IRON_ROOT} ${_${_PYTHON_PREFIX}_HINTS} + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES}) if (${_PYTHON_PREFIX}_COMPILER) # retrieve python environment version from compiler @@ -664,6 +763,12 @@ if ("Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS _python_get_frameworks (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS ${_${_PYTHON_PREFIX}_VERSION}) + set (_${_PYTHON_PREFIX}_REGISTRY_PATHS + [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath] + [HKEY_CURRENT_USER\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath] + [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath] + [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath]) + if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "FIRST") find_library (${_PYTHON_PREFIX}_LIBRARY_RELEASE NAMES python${_${_PYTHON_PREFIX}_VERSION_NO_DOTS} @@ -685,7 +790,27 @@ if ("Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS NO_CMAKE_SYSTEM_PATH) endif() - # search first in known locations + if (WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "FIRST") + find_library (${_PYTHON_PREFIX}_LIBRARY_RELEASE + NAMES python${_${_PYTHON_PREFIX}_VERSION_NO_DOTS} + python${_${_PYTHON_PREFIX}_VERSION}mu + python${_${_PYTHON_PREFIX}_VERSION}m + python${_${_PYTHON_PREFIX}_VERSION}u + python${_${_PYTHON_PREFIX}_VERSION} + NAMES_PER_DIR + HINTS ${_${_PYTHON_PREFIX}_HINTS} + PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS} + PATH_SUFFIXES lib/${CMAKE_LIBRARY_ARCHITECTURE} lib libs + lib/python${_${_PYTHON_PREFIX}_VERSION}/config-${_${_PYTHON_PREFIX}_VERSION}mu + lib/python${_${_PYTHON_PREFIX}_VERSION}/config-${_${_PYTHON_PREFIX}_VERSION}m + lib/python${_${_PYTHON_PREFIX}_VERSION}/config-${_${_PYTHON_PREFIX}_VERSION}u + lib/python${_${_PYTHON_PREFIX}_VERSION}/config-${_${_PYTHON_PREFIX}_VERSION} + lib/python${_${_PYTHON_PREFIX}_VERSION}/config + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH) + endif() + + # search in HINTS locations find_library (${_PYTHON_PREFIX}_LIBRARY_RELEASE NAMES python${_${_PYTHON_PREFIX}_VERSION_NO_DOTS} python${_${_PYTHON_PREFIX}_VERSION}mu @@ -694,10 +819,6 @@ if ("Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS python${_${_PYTHON_PREFIX}_VERSION} NAMES_PER_DIR HINTS ${_${_PYTHON_PREFIX}_HINTS} - PATHS [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath] - [HKEY_CURRENT_USER\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath] - [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath] - [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath] PATH_SUFFIXES lib/${CMAKE_LIBRARY_ARCHITECTURE} lib libs lib/python${_${_PYTHON_PREFIX}_VERSION}/config-${_${_PYTHON_PREFIX}_VERSION}mu lib/python${_${_PYTHON_PREFIX}_VERSION}/config-${_${_PYTHON_PREFIX}_VERSION}m @@ -713,6 +834,12 @@ if ("Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS unset (__${_PYTHON_PREFIX}_FRAMEWORK_PATHS) endif() + if (WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "LAST") + set (__${_PYTHON_PREFIX}_REGISTRY_PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS}) + else() + unset (__${_PYTHON_PREFIX}_REGISTRY_PATHS) + endif() + # search in all default paths find_library (${_PYTHON_PREFIX}_LIBRARY_RELEASE NAMES python${_${_PYTHON_PREFIX}_VERSION_NO_DOTS} @@ -722,6 +849,7 @@ if ("Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS python${_${_PYTHON_PREFIX}_VERSION} NAMES_PER_DIR PATHS ${__${_PYTHON_PREFIX}_FRAMEWORK_PATHS} + ${__${_PYTHON_PREFIX}_REGISTRY_PATHS} PATH_SUFFIXES lib/${CMAKE_LIBRARY_ARCHITECTURE} lib libs lib/python${_${_PYTHON_PREFIX}_VERSION}/config-${_${_PYTHON_PREFIX}_VERSION}mu lib/python${_${_PYTHON_PREFIX}_VERSION}/config-${_${_PYTHON_PREFIX}_VERSION}m @@ -739,10 +867,6 @@ if ("Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS python${_${_PYTHON_PREFIX}_VERSION} NAMES_PER_DIR HINTS "${_${_PYTHON_PREFIX}_PATH}" ${_${_PYTHON_PREFIX}_HINTS} - PATHS [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath] - [HKEY_CURRENT_USER\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath] - [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath] - [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath] PATH_SUFFIXES bin) endif() @@ -752,27 +876,28 @@ if ("Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS # use library location as a hint get_filename_component (_${_PYTHON_PREFIX}_PATH "${${_PYTHON_PREFIX}_LIBRARY_RELEASE}" DIRECTORY) find_library (${_PYTHON_PREFIX}_LIBRARY_DEBUG - NAMES python${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}_d - NAMES_PER_DIR - HINTS "${_${_PYTHON_PREFIX}_PATH}" ${_${_PYTHON_PREFIX}_HINTS} - NO_DEFAULT_PATH) - else() - # search first in known locations - find_library (${_PYTHON_PREFIX}_LIBRARY_DEBUG NAMES python${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}_d NAMES_PER_DIR - HINTS ${_${_PYTHON_PREFIX}_HINTS} - PATHS [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath] - [HKEY_CURRENT_USER\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath] - [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath] - [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath] - PATH_SUFFIXES lib libs - NO_SYSTEM_ENVIRONMENT_PATH - NO_CMAKE_SYSTEM_PATH) + HINTS "${_${_PYTHON_PREFIX}_PATH}" ${_${_PYTHON_PREFIX}_HINTS} + NO_DEFAULT_PATH) + else() + # search first in known locations + if (_${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "FIRST") + find_library (${_PYTHON_PREFIX}_LIBRARY_DEBUG + NAMES python${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}_d + NAMES_PER_DIR + HINTS ${_${_PYTHON_PREFIX}_HINTS} + PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS} + PATH_SUFFIXES lib libs + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH) + endif() # search in all default paths find_library (${_PYTHON_PREFIX}_LIBRARY_DEBUG NAMES python${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}_d NAMES_PER_DIR + HINTS ${_${_PYTHON_PREFIX}_HINTS} + PATHS ${__${_PYTHON_PREFIX}_REGISTRY_PATHS} PATH_SUFFIXES lib libs) endif() if (${_PYTHON_PREFIX}_LIBRARY_DEBUG) @@ -781,10 +906,6 @@ if ("Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS NAMES python${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}_d NAMES_PER_DIR HINTS "${_${_PYTHON_PREFIX}_PATH}" ${_${_PYTHON_PREFIX}_HINTS} - PATHS [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath] - [HKEY_CURRENT_USER\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath] - [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath] - [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath] PATH_SUFFIXES bin) endif() endif() @@ -792,6 +913,21 @@ if ("Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS # Don't search for include dir until library location is known if (${_PYTHON_PREFIX}_LIBRARY_RELEASE OR ${_PYTHON_PREFIX}_LIBRARY_DEBUG) unset (_${_PYTHON_PREFIX}_INCLUDE_HINTS) + + if (${_PYTHON_PREFIX}_EXECUTABLE) + # pick up include directory from configuration + execute_process (COMMAND "${${_PYTHON_PREFIX}_EXECUTABLE}" -c + "import sys; import sysconfig; sys.stdout.write(sysconfig.get_path('include'))" + RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT + OUTPUT_VARIABLE _${_PYTHON_PREFIX}_PATH + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + if (NOT _${_PYTHON_PREFIX}_RESULT) + file (TO_CMAKE_PATH "${_${_PYTHON_PREFIX}_PATH}" _${_PYTHON_PREFIX}_PATH) + list (APPEND _${_PYTHON_PREFIX}_INCLUDE_HINTS "${_${_PYTHON_PREFIX}_PATH}") + endif() + endif() + foreach (_${_PYTHON_PREFIX}_LIB IN ITEMS ${_PYTHON_PREFIX}_LIBRARY_RELEASE ${_PYTHON_PREFIX}_LIBRARY_DEBUG) if (${_${_PYTHON_PREFIX}_LIB}) # Use the library's install prefix as a hint @@ -826,18 +962,26 @@ if ("Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) endif() - if (NOT _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "LAST") - unset (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS) + + if (WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "FIRST") + find_path (${_PYTHON_PREFIX}_INCLUDE_DIR + NAMES Python.h + HINTS ${_${_PYTHON_PREFIX}_INCLUDE_HINTS} ${_${_PYTHON_PREFIX}_HINTS} + PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS} + PATH_SUFFIXES include/python${_${_PYTHON_PREFIX}_VERSION}mu + include/python${_${_PYTHON_PREFIX}_VERSION}m + include/python${_${_PYTHON_PREFIX}_VERSION}u + include/python${_${_PYTHON_PREFIX}_VERSION} + include + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH) endif() find_path (${_PYTHON_PREFIX}_INCLUDE_DIR NAMES Python.h HINTS ${_${_PYTHON_PREFIX}_INCLUDE_HINTS} ${_${_PYTHON_PREFIX}_HINTS} - PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS} - [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath] - [HKEY_CURRENT_USER\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath] - [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath] - [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath] + PATHS ${__${_PYTHON_PREFIX}_FRAMEWORK_PATHS} + ${__${_PYTHON_PREFIX}_REGISTRY_PATHS} PATH_SUFFIXES include/python${_${_PYTHON_PREFIX}_VERSION}mu include/python${_${_PYTHON_PREFIX}_VERSION}m include/python${_${_PYTHON_PREFIX}_VERSION}u diff --git a/Modules/FindPython2.cmake b/Modules/FindPython2.cmake index 78ed29a..2735a25 100644 --- a/Modules/FindPython2.cmake +++ b/Modules/FindPython2.cmake @@ -117,8 +117,19 @@ Hints * If set to TRUE, search **only** for static libraries. * If set to FALSE, search **only** for shared libraries. +``Python2_FIND_REGISTRY`` + On Windows the ``Python2_FIND_REGISTRY`` variable determine the order + of preference between registry and environment variables. + the ``Python2_FIND_REGISTRY`` variable can be set to empty or one of the + following: + + * ``FIRST``: Try to use registry before environment variables. + This is the default. + * ``LAST``: Try to use registry after environment variables. + * ``NEVER``: Never try to use registry. + ``CMAKE_FIND_FRAMEWORK`` - On OS X the :variable:`CMAKE_FIND_FRAMEWORK` variable determine the order of + On macOS the :variable:`CMAKE_FIND_FRAMEWORK` variable determine the order of preference between Apple-style and unix-style package components. .. note:: diff --git a/Modules/FindPython3.cmake b/Modules/FindPython3.cmake index 48054a9..ed7e1a3 100644 --- a/Modules/FindPython3.cmake +++ b/Modules/FindPython3.cmake @@ -117,6 +117,17 @@ Hints * If set to TRUE, search **only** for static libraries. * If set to FALSE, search **only** for shared libraries. +``Python3_FIND_REGISTRY`` + On Windows the ``Python3_FIND_REGISTRY`` variable determine the order + of preference between registry and environment variables. + the ``Python3_FIND_REGISTRY`` variable can be set to empty or one of the + following: + + * ``FIRST``: Try to use registry before environment variables. + This is the default. + * ``LAST``: Try to use registry after environment variables. + * ``NEVER``: Never try to use registry. + ``CMAKE_FIND_FRAMEWORK`` On OS X the :variable:`CMAKE_FIND_FRAMEWORK` variable determine the order of preference between Apple-style and unix-style package components. https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=ffb560adc98ee7c07d0e3cd50b28a38a4997cc8b commit ffb560adc98ee7c07d0e3cd50b28a38a4997cc8b Author: Marc Chevrier AuthorDate: Thu Aug 2 16:50:40 2018 +0200 Commit: Marc Chevrier CommitDate: Wed Sep 12 10:04:04 2018 +0200 FindPython*: MacOS: Fix erroneous handling of Frameworks. Fixes: #18204 diff --git a/Modules/FindPython.cmake b/Modules/FindPython.cmake index 8139e53..b8657b4 100644 --- a/Modules/FindPython.cmake +++ b/Modules/FindPython.cmake @@ -116,6 +116,14 @@ Hints * If set to TRUE, search **only** for static libraries. * If set to FALSE, search **only** for shared libraries. +``CMAKE_FIND_FRAMEWORK`` + On OS X the :variable:`CMAKE_FIND_FRAMEWORK` variable determine the order of + preference between Apple-style and unix-style package components. + + .. note:: + + Value ``ONLY`` is not supported so ``FIRST`` will be used instead. + Commands ^^^^^^^^ diff --git a/Modules/FindPython/Support.cmake b/Modules/FindPython/Support.cmake index 9144ba4..137c769 100644 --- a/Modules/FindPython/Support.cmake +++ b/Modules/FindPython/Support.cmake @@ -44,9 +44,28 @@ macro (_PYTHON_DISPLAY_FAILURE _PYTHON_MSG) endmacro() +macro (_PYTHON_FIND_FRAMEWORKS) + set (${_PYTHON_PREFIX}_FRAMEWORKS) + if (APPLE) + set (_pff_frameworks ${CMAKE_FRAMEWORK_PATH} + $ENV{CMAKE_FRAMEWORK_PATH} + ~/Library/Frameworks + /usr/local/Frameworks + ${CMAKE_SYSTEM_FRAMEWORK_PATH}) + list (REMOVE_DUPLICATES _pff_frameworks) + foreach (_pff_framework IN LISTS _pff_frameworks) + if (EXISTS ${_pff_framework}/Python.framework) + list (APPEND ${_PYTHON_PREFIX}_FRAMEWORKS ${_pff_framework}/Python.framework) + endif() + endforeach() + unset (_pff_frameworks) + unset (_pff_framework) + endif() +endmacro() + function (_PYTHON_GET_FRAMEWORKS _PYTHON_PGF_FRAMEWORK_PATHS _PYTHON_VERSION) set (_PYTHON_FRAMEWORK_PATHS) - foreach (_PYTHON_FRAMEWORK IN LISTS Python_FRAMEWORKS) + foreach (_PYTHON_FRAMEWORK IN LISTS ${_PYTHON_PREFIX}_FRAMEWORKS) list (APPEND _PYTHON_FRAMEWORK_PATHS "${_PYTHON_FRAMEWORK}/Versions/${_PYTHON_VERSION}") endforeach() @@ -59,20 +78,43 @@ function (_PYTHON_VALIDATE_INTERPRETER) return() endif() - if (${_PYTHON_PREFIX}_EXECUTABLE MATCHES "python${CMAKE_EXECUTABLE_SUFFIX}$") - # executable found do not have version in name - # ensure major version is OK + if (ARGC EQUAL 1) + set (expected_version ${ARGV0}) + else() + unset (expected_version) + endif() + + get_filename_component (python_name "${${_PYTHON_PREFIX}_EXECUTABLE}" NAME) + + if (expected_version AND NOT python_name STREQUAL "python${expected_version}${CMAKE_EXECUTABLE_SUFFIX}") + # executable found must have a specific version execute_process (COMMAND "${${_PYTHON_PREFIX}_EXECUTABLE}" -c - "import sys; sys.stdout.write(str(sys.version_info[0]))" + "import sys; sys.stdout.write('.'.join([str(x) for x in sys.version_info[:2]]))" RESULT_VARIABLE result OUTPUT_VARIABLE version ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) - if (result OR NOT version EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR) + if (result OR NOT version EQUAL expected_version) # interpreter not usable or has wrong major version set (${_PYTHON_PREFIX}_EXECUTABLE ${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND CACHE INTERNAL "" FORCE) return() endif() + else() + if (python_name STREQUAL "python${CMAKE_EXECUTABLE_SUFFIX}") + # executable found do not have version in name + # ensure major version is OK + execute_process (COMMAND "${${_PYTHON_PREFIX}_EXECUTABLE}" -c + "import sys; sys.stdout.write(str(sys.version_info[0]))" + RESULT_VARIABLE result + OUTPUT_VARIABLE version + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + if (result OR NOT version EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR) + # interpreter not usable or has wrong major version + set (${_PYTHON_PREFIX}_EXECUTABLE ${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND CACHE INTERNAL "" FORCE) + return() + endif() + endif() endif() if (CMAKE_SIZEOF_VOID_P AND "Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS @@ -183,17 +225,32 @@ else() endif() # Apple frameworks handling -include (${CMAKE_CURRENT_LIST_DIR}/../CMakeFindFrameworks.cmake) -cmake_find_frameworks (Python) +_python_find_frameworks () + +# Save CMAKE_FIND_APPBUNDLE +if (DEFINED CMAKE_FIND_APPBUNDLE) + set (_${_PYTHON_PREFIX}_CMAKE_FIND_APPBUNDLE ${CMAKE_FIND_APPBUNDLE}) +else() + unset (_${_PYTHON_PREFIX}_CMAKE_FIND_APPBUNDLE) +endif() +# To avoid app bundle lookup +set (CMAKE_FIND_APPBUNDLE "NEVER") # Save CMAKE_FIND_FRAMEWORK if (DEFINED CMAKE_FIND_FRAMEWORK) set (_${_PYTHON_PREFIX}_CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK}) + if (CMAKE_FIND_FRAMEWORK STREQUAL "ONLY") + message (AUTHOR_WARNING "Find${_PYTHON_PREFIX}: CMAKE_FIND_FRAMEWORK: 'ONLY' value is not supported. 'FIRST' will be used instead.") + set (_${_PYTHON_PREFIX}_FIND_FRAMEWORK "FIRST") + else() + set (_${_PYTHON_PREFIX}_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK}) + endif() else() unset (_${_PYTHON_PREFIX}_CMAKE_FIND_FRAMEWORK) + set (_${_PYTHON_PREFIX}_FIND_FRAMEWORK "FIRST") endif() -# To avoid picking up the system elements pre-maturely. -set (CMAKE_FIND_FRAMEWORK LAST) +# To avoid framework lookup +set (CMAKE_FIND_FRAMEWORK "NEVER") unset (_${_PYTHON_PREFIX}_REQUIRED_VARS) @@ -215,19 +272,36 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) _python_get_frameworks (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS ${_${_PYTHON_PREFIX}_VERSION}) + # Apple frameworks handling + if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "FIRST") + find_program (${_PYTHON_PREFIX}_EXECUTABLE + NAMES python${_${_PYTHON_PREFIX}_VERSION} + python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR} + NAMES_PER_DIR + PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS} + PATH_SUFFIXES bin + NO_CMAKE_PATH + NO_CMAKE_ENVIRONMENT_PATH + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH) + endif() + # try using HINTS find_program (${_PYTHON_PREFIX}_EXECUTABLE NAMES python${_${_PYTHON_PREFIX}_VERSION} + python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR} NAMES_PER_DIR HINTS ${_${_PYTHON_PREFIX}_HINTS} - PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS} PATH_SUFFIXES bin NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) + # try using registry if (WIN32) find_program (${_PYTHON_PREFIX}_EXECUTABLE - NAMES python${_${_PYTHON_PREFIX}_VERSION} python + NAMES python${_${_PYTHON_PREFIX}_VERSION} + python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR} + python ${_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES} NAMES_PER_DIR HINTS ${_${_PYTHON_PREFIX}_HINTS} @@ -242,12 +316,24 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) endif() + # try in standard paths find_program (${_PYTHON_PREFIX}_EXECUTABLE NAMES python${_${_PYTHON_PREFIX}_VERSION} NAMES_PER_DIR) - _python_validate_interpreter () + # Apple frameworks handling + if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "LAST") + find_program (${_PYTHON_PREFIX}_EXECUTABLE + NAMES python${_${_PYTHON_PREFIX}_VERSION} + python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR} + NAMES_PER_DIR + PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS} + PATH_SUFFIXES bin + NO_DEFAULT_PATH) + endif() + + _python_validate_interpreter (${_${_PYTHON_PREFIX}_VERSION}) if (${_PYTHON_PREFIX}_EXECUTABLE) break() endif() @@ -578,6 +664,27 @@ if ("Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS _python_get_frameworks (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS ${_${_PYTHON_PREFIX}_VERSION}) + if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "FIRST") + find_library (${_PYTHON_PREFIX}_LIBRARY_RELEASE + NAMES python${_${_PYTHON_PREFIX}_VERSION_NO_DOTS} + python${_${_PYTHON_PREFIX}_VERSION}mu + python${_${_PYTHON_PREFIX}_VERSION}m + python${_${_PYTHON_PREFIX}_VERSION}u + python${_${_PYTHON_PREFIX}_VERSION} + NAMES_PER_DIR + PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS} + PATH_SUFFIXES lib/${CMAKE_LIBRARY_ARCHITECTURE} lib libs + lib/python${_${_PYTHON_PREFIX}_VERSION}/config-${_${_PYTHON_PREFIX}_VERSION}mu + lib/python${_${_PYTHON_PREFIX}_VERSION}/config-${_${_PYTHON_PREFIX}_VERSION}m + lib/python${_${_PYTHON_PREFIX}_VERSION}/config-${_${_PYTHON_PREFIX}_VERSION}u + lib/python${_${_PYTHON_PREFIX}_VERSION}/config-${_${_PYTHON_PREFIX}_VERSION} + lib/python${_${_PYTHON_PREFIX}_VERSION}/config + NO_CMAKE_PATH + NO_CMAKE_ENVIRONMENT_PATH + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH) + endif() + # search first in known locations find_library (${_PYTHON_PREFIX}_LIBRARY_RELEASE NAMES python${_${_PYTHON_PREFIX}_VERSION_NO_DOTS} @@ -587,8 +694,7 @@ if ("Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS python${_${_PYTHON_PREFIX}_VERSION} NAMES_PER_DIR HINTS ${_${_PYTHON_PREFIX}_HINTS} - PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS} - [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath] + PATHS [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath] [HKEY_CURRENT_USER\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath] [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath] [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath] @@ -600,6 +706,13 @@ if ("Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS lib/python${_${_PYTHON_PREFIX}_VERSION}/config NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) + + if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "LAST") + set (__${_PYTHON_PREFIX}_FRAMEWORK_PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}) + else() + unset (__${_PYTHON_PREFIX}_FRAMEWORK_PATHS) + endif() + # search in all default paths find_library (${_PYTHON_PREFIX}_LIBRARY_RELEASE NAMES python${_${_PYTHON_PREFIX}_VERSION_NO_DOTS} @@ -608,6 +721,7 @@ if ("Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS python${_${_PYTHON_PREFIX}_VERSION}u python${_${_PYTHON_PREFIX}_VERSION} NAMES_PER_DIR + PATHS ${__${_PYTHON_PREFIX}_FRAMEWORK_PATHS} PATH_SUFFIXES lib/${CMAKE_LIBRARY_ARCHITECTURE} lib libs lib/python${_${_PYTHON_PREFIX}_VERSION}/config-${_${_PYTHON_PREFIX}_VERSION}mu lib/python${_${_PYTHON_PREFIX}_VERSION}/config-${_${_PYTHON_PREFIX}_VERSION}m @@ -625,8 +739,7 @@ if ("Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS python${_${_PYTHON_PREFIX}_VERSION} NAMES_PER_DIR HINTS "${_${_PYTHON_PREFIX}_PATH}" ${_${_PYTHON_PREFIX}_HINTS} - PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS} - [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath] + PATHS [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath] [HKEY_CURRENT_USER\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath] [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath] [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath] @@ -698,6 +811,25 @@ if ("Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS endforeach() list (REMOVE_DUPLICATES _${_PYTHON_PREFIX}_INCLUDE_HINTS) + if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "FIRST") + find_path (${_PYTHON_PREFIX}_INCLUDE_DIR + NAMES Python.h + HINTS ${_${_PYTHON_PREFIX}_HINTS} + PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS} + PATH_SUFFIXES include/python${_${_PYTHON_PREFIX}_VERSION}mu + include/python${_${_PYTHON_PREFIX}_VERSION}m + include/python${_${_PYTHON_PREFIX}_VERSION}u + include/python${_${_PYTHON_PREFIX}_VERSION} + include + NO_CMAKE_PATH + NO_CMAKE_ENVIRONMENT_PATH + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH) + endif() + if (NOT _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "LAST") + unset (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS) + endif() + find_path (${_PYTHON_PREFIX}_INCLUDE_DIR NAMES Python.h HINTS ${_${_PYTHON_PREFIX}_INCLUDE_HINTS} ${_${_PYTHON_PREFIX}_HINTS} @@ -921,6 +1053,13 @@ endif() # final clean-up +# Restore CMAKE_FIND_APPBUNDLE +if (DEFINED _${_PYTHON_PREFIX}_CMAKE_FIND_APPBUNDLE) + set (CMAKE_FIND_APPBUNDLE ${_${_PYTHON_PREFIX}_CMAKE_FIND_APPBUNDLE}) + unset (_${_PYTHON_PREFIX}_CMAKE_FIND_APPBUNDLE) +else() + unset (CMAKE_FIND_APPBUNDLE) +endif() # Restore CMAKE_FIND_FRAMEWORK if (DEFINED _${_PYTHON_PREFIX}_CMAKE_FIND_FRAMEWORK) set (CMAKE_FIND_FRAMEWORK ${_${_PYTHON_PREFIX}_CMAKE_FIND_FRAMEWORK}) diff --git a/Modules/FindPython2.cmake b/Modules/FindPython2.cmake index 22e9a8f..78ed29a 100644 --- a/Modules/FindPython2.cmake +++ b/Modules/FindPython2.cmake @@ -117,6 +117,14 @@ Hints * If set to TRUE, search **only** for static libraries. * If set to FALSE, search **only** for shared libraries. +``CMAKE_FIND_FRAMEWORK`` + On OS X the :variable:`CMAKE_FIND_FRAMEWORK` variable determine the order of + preference between Apple-style and unix-style package components. + + .. note:: + + Value ``ONLY`` is not supported so ``FIRST`` will be used instead. + Commands ^^^^^^^^ diff --git a/Modules/FindPython3.cmake b/Modules/FindPython3.cmake index 99c159b..48054a9 100644 --- a/Modules/FindPython3.cmake +++ b/Modules/FindPython3.cmake @@ -117,6 +117,14 @@ Hints * If set to TRUE, search **only** for static libraries. * If set to FALSE, search **only** for shared libraries. +``CMAKE_FIND_FRAMEWORK`` + On OS X the :variable:`CMAKE_FIND_FRAMEWORK` variable determine the order of + preference between Apple-style and unix-style package components. + + .. note:: + + Value ``ONLY`` is not supported so ``FIRST`` will be used instead. + Commands ^^^^^^^^ https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=b0b53921cef242acc91e6ab4dd495daff54191d6 commit b0b53921cef242acc91e6ab4dd495daff54191d6 Author: Marc Chevrier AuthorDate: Tue Sep 4 16:26:26 2018 +0200 Commit: Marc Chevrier CommitDate: Wed Sep 12 10:04:04 2018 +0200 FindPython: clean-up lookup names strategy diff --git a/Modules/FindPython/Support.cmake b/Modules/FindPython/Support.cmake index fe3df91..9144ba4 100644 --- a/Modules/FindPython/Support.cmake +++ b/Modules/FindPython/Support.cmake @@ -244,7 +244,8 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) endif() # try in standard paths find_program (${_PYTHON_PREFIX}_EXECUTABLE - NAMES python${_${_PYTHON_PREFIX}_VERSION}) + NAMES python${_${_PYTHON_PREFIX}_VERSION} + NAMES_PER_DIR) _python_validate_interpreter () if (${_PYTHON_PREFIX}_EXECUTABLE) @@ -252,10 +253,15 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) endif() endforeach() - # try more generic names + # try more generic names. NAMES_PER_DIR is not specified on purpose to have a + # chance to find expected version. + # For example, typical systems have 'python' for version 2.* and 'python3' + # for version 3.*. So looking for names per dir will find, potentially, + # systematically 'python' (i.e. version 2) even if version 3 is searched. if (NOT ${_PYTHON_PREFIX}_EXECUTABLE) find_program (${_PYTHON_PREFIX}_EXECUTABLE - NAMES python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR} python + NAMES python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR} + python ${_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES} HINTS ${_${_PYTHON_PREFIX}_HINTS} PATH_SUFFIXES bin) @@ -483,6 +489,7 @@ if ("Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS list (APPEND _${_PYTHON_PREFIX}_CONFIG_NAMES "python${_${_PYTHON_PREFIX}_VERSION}-config") find_program (_${_PYTHON_PREFIX}_CONFIG NAMES ${_${_PYTHON_PREFIX}_CONFIG_NAMES} + NAMES_PER_DIR HINTS ${_${_PYTHON_PREFIX}_HINTS} PATH_SUFFIXES bin) unset (_${_PYTHON_PREFIX}_CONFIG_NAMES) ----------------------------------------------------------------------- Summary of changes: Help/command/if.rst | 20 +- Help/release/dev/FindPython-lookup-strategy.rst | 6 + Help/release/dev/vs-ipo.rst | 6 + Modules/CheckIPOSupported.cmake | 2 +- Modules/FindPython.cmake | 19 + Modules/FindPython/Support.cmake | 416 +++++++++++++++++---- Modules/FindPython2.cmake | 19 + Modules/FindPython3.cmake | 19 + Source/CTest/cmCTestHandlerCommand.cxx | 4 +- Source/cmComputeLinkInformation.cxx | 2 +- Source/cmDepends.cxx | 2 +- Source/cmExportFileGenerator.cxx | 2 +- Source/cmExtraCodeBlocksGenerator.cxx | 2 +- Source/cmExtraCodeLiteGenerator.cxx | 2 +- Source/cmGeneratorExpressionNode.cxx | 30 +- Source/cmGeneratorTarget.cxx | 20 +- Source/cmGetDirectoryPropertyCommand.cxx | 2 +- Source/cmGlobalGenerator.cxx | 11 +- Source/cmGlobalGenerator.h | 2 +- Source/cmGlobalNinjaGenerator.cxx | 12 +- Source/cmGlobalVisualStudio10Generator.h | 2 + Source/cmInstallCommand.cxx | 4 +- Source/cmLocalGenerator.cxx | 12 +- Source/cmLocalUnixMakefileGenerator3.cxx | 3 +- Source/cmLocalVisualStudio7Generator.cxx | 4 +- Source/cmMakefile.cxx | 24 +- Source/cmMakefile.h | 3 +- Source/cmNinjaTargetGenerator.cxx | 6 +- Source/cmPolicies.cxx | 2 +- Source/cmQtAutoGenInitializer.cxx | 2 +- Source/cmQtAutoGeneratorMocUic.cxx | 7 +- Source/cmQtAutoGeneratorRcc.cxx | 2 +- Source/cmState.cxx | 3 + Source/cmTarget.cxx | 6 +- Source/cmVisualStudio10TargetGenerator.cxx | 47 ++- Source/cmVisualStudio10TargetGenerator.h | 1 + Tests/RunCMake/CMP0069/RunCMakeTest.cmake | 2 +- .../RunCMake/CheckIPOSupported/RunCMakeTest.cmake | 2 +- 38 files changed, 557 insertions(+), 173 deletions(-) create mode 100644 Help/release/dev/FindPython-lookup-strategy.rst create mode 100644 Help/release/dev/vs-ipo.rst hooks/post-receive -- CMake From kwrobot at kitware.com Wed Sep 19 00:05:16 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Wed, 19 Sep 2018 00:05:16 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-662-g3ada513 Message-ID: <20180919040519.9A5F7125328@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 3ada513413e2a911efac2de2c90bbebd820fef5d (commit) from 7162630beebeac105c1cd90270d26f29aa8c118f (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=3ada513413e2a911efac2de2c90bbebd820fef5d commit 3ada513413e2a911efac2de2c90bbebd820fef5d Author: Kitware Robot AuthorDate: Wed Sep 19 00:01:07 2018 -0400 Commit: Kitware Robot CommitDate: Wed Sep 19 00:01:07 2018 -0400 CMake Nightly Date Stamp diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index d0cce8b..1a5fd15 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 12) -set(CMake_VERSION_PATCH 20180918) +set(CMake_VERSION_PATCH 20180919) #set(CMake_VERSION_RC 1) ----------------------------------------------------------------------- Summary of changes: Source/CMakeVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) hooks/post-receive -- CMake From kwrobot at kitware.com Wed Sep 19 10:35:05 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Wed, 19 Sep 2018 10:35:05 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-665-g76a19eb Message-ID: <20180919143505.B997912542F@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 76a19eb6c16272e4600267aed6ed7aff0fd9c765 (commit) via 2428422c02de1feac008d2ba1a6ad075aaf7ba2c (commit) via d686f81e58200c68c1e89094210e9587e0e90983 (commit) from 3ada513413e2a911efac2de2c90bbebd820fef5d (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=76a19eb6c16272e4600267aed6ed7aff0fd9c765 commit 76a19eb6c16272e4600267aed6ed7aff0fd9c765 Merge: 3ada513 2428422 Author: Brad King AuthorDate: Wed Sep 19 14:32:55 2018 +0000 Commit: Kitware Robot CommitDate: Wed Sep 19 10:33:01 2018 -0400 Merge topic 'fix-getsafedef-stdstring' 2428422c02 Fix regression in target output file naming logic d686f81e58 Restore possibly regressed CMP0018 logic Acked-by: Kitware Robot Merge-request: !2402 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=2428422c02de1feac008d2ba1a6ad075aaf7ba2c commit 2428422c02de1feac008d2ba1a6ad075aaf7ba2c Author: Brad King AuthorDate: Wed Sep 19 07:43:34 2018 -0400 Commit: Brad King CommitDate: Wed Sep 19 08:14:48 2018 -0400 Fix regression in target output file naming logic Refactoring in commit f4ff60a803 (cmMakefile: Make GetSafeDefinition return std::string const&, 2018-09-05) accidentally changed the logic for target artifact prefix and suffix names such that setting a PREFIX or SUFFIX target property would cause an empty value to be used. Revert that part of the change and use a simpler alternative. Add a test case. Reported-by: Alan W. Irwin diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index f563dd8..434e0a3 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -3488,13 +3488,12 @@ void cmGeneratorTarget::GetFullNameInternal( } // if there is no prefix on the target use the cmake definition - std::string targetPrefix2, targetSuffix2; if (!targetPrefix && prefixVar) { - targetPrefix2 = this->Makefile->GetSafeDefinition(prefixVar); + targetPrefix = this->Makefile->GetSafeDefinition(prefixVar).c_str(); } // if there is no suffix on the target use the cmake definition if (!targetSuffix && suffixVar) { - targetSuffix2 = this->Makefile->GetSafeDefinition(suffixVar); + targetSuffix = this->Makefile->GetSafeDefinition(suffixVar).c_str(); } // frameworks have directory prefix but no suffix @@ -3502,19 +3501,19 @@ void cmGeneratorTarget::GetFullNameInternal( if (this->IsFrameworkOnApple()) { fw_prefix = this->GetFrameworkDirectory(config, ContentLevel); fw_prefix += "/"; - targetPrefix2 = fw_prefix; - targetSuffix2.clear(); + targetPrefix = fw_prefix.c_str(); + targetSuffix = nullptr; } if (this->IsCFBundleOnApple()) { fw_prefix = this->GetCFBundleDirectory(config, FullLevel); fw_prefix += "/"; - targetPrefix2 = fw_prefix; - targetSuffix2.clear(); + targetPrefix = fw_prefix.c_str(); + targetSuffix = nullptr; } // Begin the final name with the prefix. - outPrefix = targetPrefix2; + outPrefix = targetPrefix ? targetPrefix : ""; // Append the target name or property-specified name. outBase += this->GetOutputName(config, artifact); @@ -3533,7 +3532,7 @@ void cmGeneratorTarget::GetFullNameInternal( } // Append the suffix. - outSuffix = targetSuffix2; + outSuffix = targetSuffix ? targetSuffix : ""; } std::string cmGeneratorTarget::GetLinkerLanguage( diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index a22521b..28aab1c 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -368,6 +368,7 @@ if(BUILD_TESTING) ADD_TEST_MACRO(CxxSubdirC CxxSubdirC) ADD_TEST_MACRO(IPO COnly/COnly) ADD_TEST_MACRO(OutDir runtime/OutDir) + ADD_TEST_MACRO(OutName exe.OutName.exe) ADD_TEST_MACRO(ObjectLibrary UseCshared) ADD_TEST_MACRO(NewlineArgs NewlineArgs) ADD_TEST_MACRO(SetLang SetLang) diff --git a/Tests/OutName/CMakeLists.txt b/Tests/OutName/CMakeLists.txt new file mode 100644 index 0000000..f024def --- /dev/null +++ b/Tests/OutName/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.12) +project(OutName C) + +add_executable(OutName main.c) +set_property(TARGET OutName PROPERTY PREFIX exe.) +set_property(TARGET OutName PROPERTY SUFFIX .exe) diff --git a/Tests/OutName/main.c b/Tests/OutName/main.c new file mode 100644 index 0000000..8488f4e --- /dev/null +++ b/Tests/OutName/main.c @@ -0,0 +1,4 @@ +int main(void) +{ + return 0; +} https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=d686f81e58200c68c1e89094210e9587e0e90983 commit d686f81e58200c68c1e89094210e9587e0e90983 Author: Brad King AuthorDate: Wed Sep 19 07:41:22 2018 -0400 Commit: Brad King CommitDate: Wed Sep 19 07:42:08 2018 -0400 Restore possibly regressed CMP0018 logic Refactoring in commit f4ff60a803 (cmMakefile: Make GetSafeDefinition return std::string const&, 2018-09-05) changed the treatment of the empty string in CMP0018 diagnostic logic. Restore the behavior. diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index f504b9f..c45acf7 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -828,11 +828,8 @@ void cmGlobalGenerator::EnableLanguage( std::string sharedLibFlagsVar = "CMAKE_SHARED_LIBRARY_"; sharedLibFlagsVar += lang; sharedLibFlagsVar += "_FLAGS"; - std::string const& sharedLibFlags = + this->LanguageToOriginalSharedLibFlags[lang] = mf->GetSafeDefinition(sharedLibFlagsVar); - if (!sharedLibFlags.empty()) { - this->LanguageToOriginalSharedLibFlags[lang] = sharedLibFlags; - } // Translate compiler ids for compatibility. this->CheckCompilerIdCompatibility(mf, lang); diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 7eb4ef4..7030725 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1826,7 +1826,7 @@ bool cmLocalGenerator::GetShouldUseOldFlags(bool shared, flagsVar += "_FLAGS"; std::string const& flags = this->Makefile->GetSafeDefinition(flagsVar); - if (!flags.empty() && flags != originalFlags) { + if (flags != originalFlags) { switch (this->GetPolicyStatus(cmPolicies::CMP0018)) { case cmPolicies::WARN: { std::ostringstream e; ----------------------------------------------------------------------- Summary of changes: Source/cmGeneratorTarget.cxx | 17 ++++++++--------- Source/cmGlobalGenerator.cxx | 5 +---- Source/cmLocalGenerator.cxx | 2 +- Tests/CMakeLists.txt | 1 + Tests/OutName/CMakeLists.txt | 6 ++++++ Tests/{VSExcludeFromDefaultBuild => OutName}/main.c | 0 6 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 Tests/OutName/CMakeLists.txt copy Tests/{VSExcludeFromDefaultBuild => OutName}/main.c (100%) hooks/post-receive -- CMake From kwrobot at kitware.com Wed Sep 19 10:45:09 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Wed, 19 Sep 2018 10:45:09 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-673-ga9df54e Message-ID: <20180919144509.06FED111C0A@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via a9df54ec313cf832a30f7aab0180a74d114ee5b5 (commit) via ec9ef691feab1ae8fc4209330af91169b4faa076 (commit) via c0cedaa6435d2eb1a49afab1eaa08ba3cd40290e (commit) via afb7f6e4ff8a0c1a68c8d8cf2d6cf72401cfb8ff (commit) via 7f530cc54e070257ea0a59ea4f63ab6f34bcf878 (commit) via 638f00117a8166702950a6c730fdfa453f788659 (commit) via de962cc00d66a5303e42ba7ea2311b131eaefe18 (commit) via a10d63d5783275f9972aaa86d41071a1ddca7921 (commit) from 76a19eb6c16272e4600267aed6ed7aff0fd9c765 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=a9df54ec313cf832a30f7aab0180a74d114ee5b5 commit a9df54ec313cf832a30f7aab0180a74d114ee5b5 Merge: ec9ef69 afb7f6e Author: Brad King AuthorDate: Wed Sep 19 14:40:58 2018 +0000 Commit: Kitware Robot CommitDate: Wed Sep 19 10:41:07 2018 -0400 Merge topic 'symlink' afb7f6e4ff cmake: Add '-E create_symlink' support on Windows Acked-by: Kitware Robot Merge-request: !2144 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=ec9ef691feab1ae8fc4209330af91169b4faa076 commit ec9ef691feab1ae8fc4209330af91169b4faa076 Merge: c0cedaa 638f001 Author: Brad King AuthorDate: Wed Sep 19 14:38:11 2018 +0000 Commit: Kitware Robot CommitDate: Wed Sep 19 10:38:19 2018 -0400 Merge topic 'provide_explicit_source_and_build_command_line_options' 638f00117a Add release note for the -S and -B options. de962cc00d CMake: Internally uses -S instead of -H to specify source directory a10d63d578 cmake: -S and -B can be used to specify source and build directories Acked-by: Kitware Robot Merge-request: !2358 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=c0cedaa6435d2eb1a49afab1eaa08ba3cd40290e commit c0cedaa6435d2eb1a49afab1eaa08ba3cd40290e Merge: 76a19eb 7f530cc Author: Brad King AuthorDate: Wed Sep 19 14:36:05 2018 +0000 Commit: Kitware Robot CommitDate: Wed Sep 19 10:36:11 2018 -0400 Merge topic 'ctest-more_submit_params' 7f530cc54e ctest_submit: pass additional info to CDash Acked-by: Kitware Robot Merge-request: !2380 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=afb7f6e4ff8a0c1a68c8d8cf2d6cf72401cfb8ff commit afb7f6e4ff8a0c1a68c8d8cf2d6cf72401cfb8ff Author: Jon Chronopoulos AuthorDate: Mon Jun 11 17:28:09 2018 +1000 Commit: Brad King CommitDate: Tue Sep 18 11:24:08 2018 -0400 cmake: Add '-E create_symlink' support on Windows The allows `-E create_symlink` to work on Windows. It utilizes `uv_fs_symlink`. I am still unsure exactly which Windows platforms will work without requiring Administrator privileges or needing a user/group with the "Create Symbolic Links" User Rights. It does work with my Windows 10 Pro with Developer Mode turned on. In the test suite check that the symlink either worked or failed with a permissions error. Use recent changes in cmSystemTools::FileExists to check that a symlink is broken. diff --git a/Help/manual/cmake.1.rst b/Help/manual/cmake.1.rst index 177acd4..00d95ce 100644 --- a/Help/manual/cmake.1.rst +++ b/Help/manual/cmake.1.rst @@ -353,11 +353,6 @@ Available commands are: Touch a file if it exists but do not create it. If a file does not exist it will be silently ignored. -UNIX-specific Command-Line Tools --------------------------------- - -The following ``cmake -E`` commands are available only on UNIX: - ``create_symlink `` Create a symbolic link ```` naming ````. diff --git a/Help/release/dev/create_symlink-windows.rst b/Help/release/dev/create_symlink-windows.rst new file mode 100644 index 0000000..e3ea491 --- /dev/null +++ b/Help/release/dev/create_symlink-windows.rst @@ -0,0 +1,5 @@ +create_symlink-windows +------------------------- + +* The :manual:`cmake(1)` ``-E create_symlink`` command can now be used + on Windows. diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 79e5ccf..8339aac 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -6,6 +6,7 @@ #include "cmDuration.h" #include "cmProcessOutput.h" #include "cm_sys_stat.h" +#include "cm_uv.h" #if defined(CMAKE_BUILD_WITH_CMAKE) # include "cmArchiveWrite.h" @@ -55,8 +56,6 @@ # include # include /* _O_TEXT */ - -# include "cm_uv.h" #else # include # include @@ -2988,3 +2987,25 @@ bool cmSystemTools::StringToULong(const char* str, unsigned long* value) *value = strtoul(str, &endp, 10); return (*endp == '\0') && (endp != str) && (errno == 0); } + +bool cmSystemTools::CreateSymlink(const std::string& origName, + const std::string& newName) +{ + uv_fs_t req; + int flags = 0; +#if defined(_WIN32) + if (cmsys::SystemTools::FileIsDirectory(origName)) { + flags |= UV_FS_SYMLINK_DIR; + } +#endif + int err = uv_fs_symlink(nullptr, &req, origName.c_str(), newName.c_str(), + flags, nullptr); + if (err) { + std::string e = + "failed to create symbolic link '" + newName + "': " + uv_strerror(err); + cmSystemTools::Error(e.c_str()); + return false; + } + + return true; +} diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 5c383ee..98300eb 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -513,6 +513,11 @@ public: /** Perform one-time initialization of libuv. */ static void InitializeLibUV(); + /** Create a symbolic link if the platform supports it. Returns whether + creation succeeded. */ + static bool CreateSymlink(const std::string& origName, + const std::string& newName); + private: static bool s_ForceUnixPaths; static bool s_RunCommandHideConsole; diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 87da108..1d2f741 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -108,6 +108,7 @@ void CMakeCommandUsage(const char* program) << " time command [args...] - run command and display elapsed time\n" << " touch file - touch a file.\n" << " touch_nocreate file - touch a file but do not create it.\n" + << " create_symlink old new - create a symbolic link new -> old\n" #if defined(_WIN32) && !defined(__CYGWIN__) << "Available on Windows only:\n" << " delete_regv key - delete registry value\n" @@ -116,9 +117,6 @@ void CMakeCommandUsage(const char* program) << " env_vs9_wince sdkname - displays a batch file which sets the " "environment for the provided Windows CE SDK installed in VS2008\n" << " write_regv key value - write registry value\n" -#else - << "Available on UNIX only:\n" - << " create_symlink old new - create a symbolic link new -> old\n" #endif ; /* clang-format on */ @@ -868,9 +866,6 @@ int cmcmd::ExecuteCMakeCommand(std::vector& args) return 1; } if (!cmSystemTools::CreateSymlink(args[2], args[3])) { - std::string emsg = cmSystemTools::GetLastSystemError(); - std::cerr << "failed to create symbolic link '" << destinationFileName - << "': " << emsg << "\n"; return 1; } return 0; diff --git a/Tests/RunCMake/CommandLine/E_create_symlink-broken-create-check.cmake b/Tests/RunCMake/CommandLine/E_create_symlink-broken-create-check.cmake index d7e652d..5df5f2f 100644 --- a/Tests/RunCMake/CommandLine/E_create_symlink-broken-create-check.cmake +++ b/Tests/RunCMake/CommandLine/E_create_symlink-broken-create-check.cmake @@ -1,6 +1,10 @@ -if(NOT IS_SYMLINK ${RunCMake_TEST_BINARY_DIR}/L) - set(RunCMake_TEST_FAILED "Symlink 'L' incorrectly not created!") -endif() -if(EXISTS ${RunCMake_TEST_BINARY_DIR}/L) - set(RunCMake_TEST_FAILED "Symlink 'L' not broken!") +if(${actual_stderr_var} MATCHES "operation not permitted") + unset(msg) +else() + if(NOT IS_SYMLINK ${RunCMake_TEST_BINARY_DIR}/L) + set(RunCMake_TEST_FAILED "Symlink 'L' incorrectly not created!") + endif() + if(EXISTS ${RunCMake_TEST_BINARY_DIR}/L) + set(RunCMake_TEST_FAILED "Symlink 'L' not broken!") + endif() endif() diff --git a/Tests/RunCMake/CommandLine/E_create_symlink-broken-replace-check.cmake b/Tests/RunCMake/CommandLine/E_create_symlink-broken-replace-check.cmake index c078ae8..d37df01 100644 --- a/Tests/RunCMake/CommandLine/E_create_symlink-broken-replace-check.cmake +++ b/Tests/RunCMake/CommandLine/E_create_symlink-broken-replace-check.cmake @@ -1,3 +1,7 @@ -if(NOT IS_DIRECTORY ${RunCMake_TEST_BINARY_DIR}/L) - set(RunCMake_TEST_FAILED "Symlink 'L' not replaced correctly!") +if(${actual_stderr_var} MATCHES "operation not permitted") + unset(msg) +else() + if(NOT IS_DIRECTORY ${RunCMake_TEST_BINARY_DIR}/L) + set(RunCMake_TEST_FAILED "Symlink 'L' not replaced correctly!") + endif() endif() diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake index cef2b9b..5c80281 100644 --- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake @@ -102,32 +102,35 @@ if(RunCMake_GENERATOR STREQUAL "Ninja") unset(RunCMake_TEST_NO_CLEAN) endif() -if(UNIX) - run_cmake_command(E_create_symlink-no-arg - ${CMAKE_COMMAND} -E create_symlink - ) - run_cmake_command(E_create_symlink-missing-dir - ${CMAKE_COMMAND} -E create_symlink T missing-dir/L - ) +run_cmake_command(E_create_symlink-no-arg + ${CMAKE_COMMAND} -E create_symlink + ) +run_cmake_command(E_create_symlink-missing-dir + ${CMAKE_COMMAND} -E create_symlink T missing-dir/L + ) - # Use a single build tree for a few tests without cleaning. - set(RunCMake_TEST_BINARY_DIR - ${RunCMake_BINARY_DIR}/E_create_symlink-broken-build) - set(RunCMake_TEST_NO_CLEAN 1) - file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") - run_cmake_command(E_create_symlink-broken-create - ${CMAKE_COMMAND} -E create_symlink T L - ) - run_cmake_command(E_create_symlink-broken-replace - ${CMAKE_COMMAND} -E create_symlink . L - ) - unset(RunCMake_TEST_BINARY_DIR) - unset(RunCMake_TEST_NO_CLEAN) +# Use a single build tree for a few tests without cleaning. +# These tests are special on Windows since it will only fail if the user +# running the test does not have the priveldge to create symlinks. If this +# happens we clear the msg in the -check.cmake and say that the test passes +set(RunCMake_DEFAULT_stderr "(operation not permitted)?") +set(RunCMake_TEST_BINARY_DIR + ${RunCMake_BINARY_DIR}/E_create_symlink-broken-build) +set(RunCMake_TEST_NO_CLEAN 1) +file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") +run_cmake_command(E_create_symlink-broken-create + ${CMAKE_COMMAND} -E create_symlink T L + ) +run_cmake_command(E_create_symlink-broken-replace + ${CMAKE_COMMAND} -E create_symlink . L + ) +unset(RunCMake_TEST_BINARY_DIR) +unset(RunCMake_TEST_NO_CLEAN) +unset(RunCMake_DEFAULT_stderr) - run_cmake_command(E_create_symlink-no-replace-dir - ${CMAKE_COMMAND} -E create_symlink T . - ) -endif() +run_cmake_command(E_create_symlink-no-replace-dir + ${CMAKE_COMMAND} -E create_symlink T . + ) set(in ${RunCMake_SOURCE_DIR}/copy_input) set(out ${RunCMake_BINARY_DIR}/copy_output) https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=7f530cc54e070257ea0a59ea4f63ab6f34bcf878 commit 7f530cc54e070257ea0a59ea4f63ab6f34bcf878 Author: Zack Galbreath AuthorDate: Wed Sep 12 10:39:25 2018 -0400 Commit: Zack Galbreath CommitDate: Mon Sep 17 10:38:33 2018 -0400 ctest_submit: pass additional info to CDash Specify buildname, site, and buildstamp to CDash upon submission. CDash will use this extra info to assign and report back a buildid. diff --git a/Source/CTest/cmCTestSubmitHandler.cxx b/Source/CTest/cmCTestSubmitHandler.cxx index cbed40e..c7f3f39 100644 --- a/Source/CTest/cmCTestSubmitHandler.cxx +++ b/Source/CTest/cmCTestSubmitHandler.cxx @@ -425,6 +425,29 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP(const std::string& localprefix, ((url.find('?') == std::string::npos) ? '?' : '&') + "FileName=" + ofile; + cmCTestCurl ctest_curl(this->CTest); + upload_as += "&build="; + upload_as += + ctest_curl.Escape(this->CTest->GetCTestConfiguration("BuildName")); + upload_as += "&site="; + upload_as += + ctest_curl.Escape(this->CTest->GetCTestConfiguration("Site")); + upload_as += "&stamp="; + upload_as += ctest_curl.Escape(this->CTest->GetCurrentTag()); + upload_as += "-"; + upload_as += ctest_curl.Escape(this->CTest->GetTestModelString()); + cmCTestScriptHandler* ch = + static_cast(this->CTest->GetHandler("script")); + cmake* cm = ch->GetCMake(); + if (cm) { + const char* subproject = + cm->GetState()->GetGlobalProperty("SubProject"); + if (subproject) { + upload_as += "&subproject="; + upload_as += ctest_curl.Escape(subproject); + } + } + upload_as += "&MD5="; if (cmSystemTools::IsOn(this->GetOption("InternalTest"))) { diff --git a/Tests/RunCMake/ctest_submit/CDashSubmitVerbose-result.txt b/Tests/RunCMake/ctest_submit/CDashSubmitVerbose-result.txt new file mode 100644 index 0000000..b57e2de --- /dev/null +++ b/Tests/RunCMake/ctest_submit/CDashSubmitVerbose-result.txt @@ -0,0 +1 @@ +(-1|255) diff --git a/Tests/RunCMake/ctest_submit/CDashSubmitVerbose-stderr.txt b/Tests/RunCMake/ctest_submit/CDashSubmitVerbose-stderr.txt new file mode 100644 index 0000000..a8f10b5 --- /dev/null +++ b/Tests/RunCMake/ctest_submit/CDashSubmitVerbose-stderr.txt @@ -0,0 +1 @@ + *Error message was: ([Cc]ould *n.t resolve host:? '?-no-site-'?.*|The requested URL returned error:.*) diff --git a/Tests/RunCMake/ctest_submit/CDashSubmitVerbose-stdout.txt b/Tests/RunCMake/ctest_submit/CDashSubmitVerbose-stdout.txt new file mode 100644 index 0000000..11a4edf --- /dev/null +++ b/Tests/RunCMake/ctest_submit/CDashSubmitVerbose-stdout.txt @@ -0,0 +1 @@ +Upload file: .* to http:\/\/-no-site-\?FileName=test-site___test-build-name___.*-Experimental___XML___Configure.xml&build=test-build-name&site=test-site&stamp=.*-Experimental&subproject=mysubproj&MD5=.* Size: .* diff --git a/Tests/RunCMake/ctest_submit/RunCMakeTest.cmake b/Tests/RunCMake/ctest_submit/RunCMakeTest.cmake index ed0e666..7661383 100644 --- a/Tests/RunCMake/ctest_submit/RunCMakeTest.cmake +++ b/Tests/RunCMake/ctest_submit/RunCMakeTest.cmake @@ -30,6 +30,7 @@ run_ctest_submit(CDashUploadNone CDASH_UPLOAD) run_ctest_submit(CDashUploadMissingFile CDASH_UPLOAD bad-upload) run_ctest_submit(CDashUploadRetry CDASH_UPLOAD ${CMAKE_CURRENT_LIST_FILE} CDASH_UPLOAD_TYPE foo RETRY_COUNT 2 RETRY_DELAY 1 INTERNAL_TEST_CHECKSUM) run_ctest_submit(CDashSubmitQuiet QUIET) +run_ctest_submit_debug(CDashSubmitVerbose) run_ctest_submit_debug(CDashSubmitHeaders HTTPHEADER "Authorization: Bearer asdf") run_ctest_submit_debug(CDashUploadHeaders CDASH_UPLOAD ${CMAKE_CURRENT_LIST_FILE} CDASH_UPLOAD_TYPE foo HTTPHEADER "Authorization: Bearer asdf") diff --git a/Tests/RunCMake/ctest_submit/test.cmake.in b/Tests/RunCMake/ctest_submit/test.cmake.in index ba826f1..35cd16a 100644 --- a/Tests/RunCMake/ctest_submit/test.cmake.in +++ b/Tests/RunCMake/ctest_submit/test.cmake.in @@ -9,6 +9,7 @@ set(CTEST_CMAKE_GENERATOR_PLATFORM "@RunCMake_GENERATOR_PLATFORM@") set(CTEST_CMAKE_GENERATOR_TOOLSET "@RunCMake_GENERATOR_TOOLSET@") set(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}") +set_property(GLOBAL PROPERTY SubProject "mysubproj") ctest_start(Experimental) ctest_configure() https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=638f00117a8166702950a6c730fdfa453f788659 commit 638f00117a8166702950a6c730fdfa453f788659 Author: Robert Maynard AuthorDate: Sat Sep 8 17:28:03 2018 -0400 Commit: Robert Maynard CommitDate: Sat Sep 15 11:25:47 2018 -0400 Add release note for the -S and -B options. diff --git a/Help/release/dev/cmake-explicit-dirs.rst b/Help/release/dev/cmake-explicit-dirs.rst new file mode 100644 index 0000000..35f2d3a --- /dev/null +++ b/Help/release/dev/cmake-explicit-dirs.rst @@ -0,0 +1,10 @@ +cmake-explicit-dirs +------------------- + +* The :manual:`cmake ` command gained the ``-S `` + command line option to specify the location of the source directory. + This option can be used independently of ``-B``. + +* The :manual:`cmake ` command gained the ``-B `` + command line option to specify the location of the build directory. + This option can be used independently of ``-S``. https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=de962cc00d66a5303e42ba7ea2311b131eaefe18 commit de962cc00d66a5303e42ba7ea2311b131eaefe18 Author: Robert Maynard AuthorDate: Thu Sep 6 13:02:09 2018 -0400 Commit: Robert Maynard CommitDate: Sat Sep 15 11:25:47 2018 -0400 CMake: Internally uses -S instead of -H to specify source directory diff --git a/Source/QtDialog/CMakeSetup.cxx b/Source/QtDialog/CMakeSetup.cxx index 2646c9a..7b980a0 100644 --- a/Source/QtDialog/CMakeSetup.cxx +++ b/Source/QtDialog/CMakeSetup.cxx @@ -150,7 +150,7 @@ int main(int argc, char** argv) typedef cmsys::CommandLineArguments argT; arg.AddArgument("-B", argT::CONCAT_ARGUMENT, &binaryDirectory, "Binary Directory"); - arg.AddArgument("-H", argT::CONCAT_ARGUMENT, &sourceDirectory, + arg.AddArgument("-S", argT::CONCAT_ARGUMENT, &sourceDirectory, "Source Directory"); // do not complain about unknown options arg.StoreUnusedArguments(true); diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 92ede7f..34c5db7 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -2430,7 +2430,7 @@ void cmGlobalGenerator::AddGlobalTarget_EditCache( std::string edit_cmd = this->GetEditCacheCommand(); if (!edit_cmd.empty()) { singleLine.push_back(std::move(edit_cmd)); - singleLine.push_back("-H$(CMAKE_SOURCE_DIR)"); + singleLine.push_back("-S$(CMAKE_SOURCE_DIR)"); singleLine.push_back("-B$(CMAKE_BINARY_DIR)"); gti.Message = "Running CMake cache editor..."; gti.UsesTerminal = true; @@ -2460,7 +2460,7 @@ void cmGlobalGenerator::AddGlobalTarget_RebuildCache( gti.UsesTerminal = true; cmCustomCommandLine singleLine; singleLine.push_back(cmSystemTools::GetCMakeCommand()); - singleLine.push_back("-H$(CMAKE_SOURCE_DIR)"); + singleLine.push_back("-S$(CMAKE_SOURCE_DIR)"); singleLine.push_back("-B$(CMAKE_BINARY_DIR)"); gti.CommandLines.push_back(std::move(singleLine)); targets.push_back(std::move(gti)); diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 0c80910..a21d6dc 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -1340,7 +1340,7 @@ void cmGlobalNinjaGenerator::WriteTargetRebuildManifest(std::ostream& os) std::ostringstream cmd; cmd << lg->ConvertToOutputFormat(cmSystemTools::GetCMakeCommand(), cmOutputConverter::SHELL) - << " -H" + << " -S" << lg->ConvertToOutputFormat(lg->GetSourceDirectory(), cmOutputConverter::SHELL) << " -B" diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx index 117d051..ba138c2 100644 --- a/Source/cmGlobalVisualStudio8Generator.cxx +++ b/Source/cmGlobalVisualStudio8Generator.cxx @@ -177,9 +177,9 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget() // Create a rule to re-run CMake. cmCustomCommandLine commandLine; commandLine.push_back(cmSystemTools::GetCMakeCommand()); - std::string argH = "-H"; - argH += lg->GetSourceDirectory(); - commandLine.push_back(argH); + std::string argS = "-S"; + argS += lg->GetSourceDirectory(); + commandLine.push_back(argS); std::string argB = "-B"; argB += lg->GetBinaryDirectory(); commandLine.push_back(argB); diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index bc83ce2..8820042 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -773,7 +773,7 @@ void cmLocalUnixMakefileGenerator3::WriteSpecialTargetsBottom( std::string cmakefileName = cmake::GetCMakeFilesDirectoryPostSlash(); cmakefileName += "Makefile.cmake"; std::string runRule = - "$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)"; + "$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)"; runRule += " --check-build-system "; runRule += this->ConvertToOutputFormat(cmakefileName, cmOutputConverter::SHELL); @@ -1684,7 +1684,7 @@ void cmLocalUnixMakefileGenerator3::WriteLocalAllRules( cmakefileName += "Makefile.cmake"; { std::string runRule = - "$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)"; + "$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)"; runRule += " --check-build-system "; runRule += this->ConvertToOutputFormat(cmakefileName, cmOutputConverter::SHELL); diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 80f2803..d3a1fa1 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -260,7 +260,7 @@ cmSourceFile* cmLocalVisualStudio7Generator::CreateVCProjBuildRule() std::string comment = "Building Custom Rule "; comment += makefileIn; std::string args; - args = "-H"; + args = "-S"; args += this->GetSourceDirectory(); commandLine.push_back(args); args = "-B"; https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=a10d63d5783275f9972aaa86d41071a1ddca7921 commit a10d63d5783275f9972aaa86d41071a1ddca7921 Author: Robert Maynard AuthorDate: Thu Sep 6 10:13:39 2018 -0400 Commit: Robert Maynard CommitDate: Sat Sep 15 11:25:47 2018 -0400 cmake: -S and -B can be used to specify source and build directories Document the previously internal option of '-B' and provide a matching source directory option with '-S'. Both '-B', and '-S' can be used independently of each other. diff --git a/Help/manual/OPTIONS_BUILD.txt b/Help/manual/OPTIONS_BUILD.txt index 33d27af..baa73d5 100644 --- a/Help/manual/OPTIONS_BUILD.txt +++ b/Help/manual/OPTIONS_BUILD.txt @@ -1,3 +1,11 @@ +``-S `` + Path to root directory of the CMake project to build. + +``-B `` + Path to directory which CMake will use as the root of build directory. + + If the directory doesn't already exist CMake will make it. + ``-C `` Pre-load a script to populate the cache. diff --git a/Help/manual/cmake.1.rst b/Help/manual/cmake.1.rst index 177acd4..9fe0c0b 100644 --- a/Help/manual/cmake.1.rst +++ b/Help/manual/cmake.1.rst @@ -9,6 +9,7 @@ Synopsis .. parsed-literal:: cmake [] { | } + cmake [] -S -B cmake [{-D =}...] -P cmake --build [...] [-- ...] cmake --open diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 1bf8f7d..68e4506 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -611,19 +611,43 @@ void cmake::SetArgs(const std::vector& args, bool havePlatform = false; for (unsigned int i = 1; i < args.size(); ++i) { std::string const& arg = args[i]; - if (arg.find("-H", 0) == 0) { + if (arg.find("-H", 0) == 0 || arg.find("-S", 0) == 0) { directoriesSet = true; std::string path = arg.substr(2); + if (path.empty()) { + ++i; + if (i >= args.size()) { + cmSystemTools::Error("No source directory specified for -S"); + return; + } + path = args[i]; + if (path[0] == '-') { + cmSystemTools::Error("No source directory specified for -S"); + return; + } + } + path = cmSystemTools::CollapseFullPath(path); cmSystemTools::ConvertToUnixSlashes(path); this->SetHomeDirectory(path); - } else if (arg.find("-S", 0) == 0) { - // There is no local generate anymore. Ignore -S option. } else if (arg.find("-O", 0) == 0) { // There is no local generate anymore. Ignore -O option. } else if (arg.find("-B", 0) == 0) { directoriesSet = true; std::string path = arg.substr(2); + if (path.empty()) { + ++i; + if (i >= args.size()) { + cmSystemTools::Error("No build directory specified for -B"); + return; + } + path = args[i]; + if (path[0] == '-') { + cmSystemTools::Error("No build directory specified for -B"); + return; + } + } + path = cmSystemTools::CollapseFullPath(path); cmSystemTools::ConvertToUnixSlashes(path); this->SetHomeOutputDirectory(path); @@ -835,20 +859,27 @@ void cmake::SetDirectoriesFromFile(const char* arg) this->SetHomeOutputDirectory(listPath); } else { // Source directory given on command line. Use current working - // directory as build tree. - std::string cwd = cmSystemTools::GetCurrentWorkingDirectory(); - this->SetHomeOutputDirectory(cwd); + // directory as build tree if -B hasn't been given already + if (this->GetHomeOutputDirectory().empty()) { + std::string cwd = cmSystemTools::GetCurrentWorkingDirectory(); + this->SetHomeOutputDirectory(cwd); + } } return; } - // We didn't find a CMakeLists.txt or CMakeCache.txt file from the - // argument. Assume it is the path to the source tree, and use the - // current working directory as the build tree. - std::string full = cmSystemTools::CollapseFullPath(arg); - std::string cwd = cmSystemTools::GetCurrentWorkingDirectory(); - this->SetHomeDirectory(full); - this->SetHomeOutputDirectory(cwd); + if (this->GetHomeDirectory().empty()) { + // We didn't find a CMakeLists.txt and it wasn't specified + // with -S. Assume it is the path to the source tree + std::string full = cmSystemTools::CollapseFullPath(arg); + this->SetHomeDirectory(full); + } + if (this->GetHomeOutputDirectory().empty()) { + // We didn't find a CMakeCache.txt and it wasn't specified + // with -B. Assume the current working directory as the build tree. + std::string cwd = cmSystemTools::GetCurrentWorkingDirectory(); + this->SetHomeOutputDirectory(cwd); + } } // at the end of this CMAKE_ROOT and CMAKE_COMMAND should be added to the diff --git a/Source/cmake.h b/Source/cmake.h index 4b4c67c..f7dc3f7 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -556,7 +556,9 @@ private: }; #define CMAKE_STANDARD_OPTIONS_TABLE \ - { "-C ", "Pre-load a script to populate the cache." }, \ + { "-S ", "Explicitly specify a source directory." }, \ + { "-B ", "Explicitly specify a build directory." }, \ + { "-C ", "Pre-load a script to populate the cache." }, \ { "-D [:]=", "Create or update a cmake cache entry." }, \ { "-U ", "Remove matching entries from CMake cache." }, \ { "-G ", "Specify a build system generator." }, \ diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index e3d94f6..75dabde 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -38,7 +38,8 @@ static const char* cmDocumentationName[][2] = { static const char* cmDocumentationUsage[][2] = { { nullptr, " cmake [options] \n" - " cmake [options] " }, + " cmake [options] \n" + " cmake [options] -S -B " }, { nullptr, "Specify a source directory to (re-)generate a build system for " "it in the current working directory. Specify an existing build " diff --git a/Tests/RunCMake/CommandLine/B-no-arg-result.txt b/Tests/RunCMake/CommandLine/B-no-arg-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CommandLine/B-no-arg-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/B-no-arg-stderr.txt b/Tests/RunCMake/CommandLine/B-no-arg-stderr.txt new file mode 100644 index 0000000..2309c5e --- /dev/null +++ b/Tests/RunCMake/CommandLine/B-no-arg-stderr.txt @@ -0,0 +1 @@ +CMake Error: No build directory specified for -B diff --git a/Tests/RunCMake/CommandLine/B-no-arg2-result.txt b/Tests/RunCMake/CommandLine/B-no-arg2-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CommandLine/B-no-arg2-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/B-no-arg2-stderr.txt b/Tests/RunCMake/CommandLine/B-no-arg2-stderr.txt new file mode 100644 index 0000000..2309c5e --- /dev/null +++ b/Tests/RunCMake/CommandLine/B-no-arg2-stderr.txt @@ -0,0 +1 @@ +CMake Error: No build directory specified for -B diff --git a/Tests/RunCMake/CommandLine/ExplicitDirs/CMakeLists.txt b/Tests/RunCMake/CommandLine/ExplicitDirs/CMakeLists.txt new file mode 100644 index 0000000..0ca5a0a --- /dev/null +++ b/Tests/RunCMake/CommandLine/ExplicitDirs/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR) +add_custom_command( + OUTPUT output.txt + COMMAND ${CMAKE_COMMAND} -E echo CustomCommand > output.txt + ) +add_custom_target(CustomTarget ALL DEPENDS output.txt) +add_custom_target(CustomTarget2 ALL DEPENDS output.txt) +add_custom_target(CustomTarget3 ALL DEPENDS output.txt) diff --git a/Tests/RunCMake/CommandLine/NoArgs-stdout.txt b/Tests/RunCMake/CommandLine/NoArgs-stdout.txt index 1cd3469..f1dafc8 100644 --- a/Tests/RunCMake/CommandLine/NoArgs-stdout.txt +++ b/Tests/RunCMake/CommandLine/NoArgs-stdout.txt @@ -2,6 +2,7 @@ cmake \[options\] cmake \[options\] + cmake \[options\] -S -B Specify a source directory to \(re-\)generate a build system for it in the current working directory. Specify an existing build directory to diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake index cef2b9b..e332336 100644 --- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake @@ -48,6 +48,31 @@ run_cmake_command(cache-bad-entry run_cmake_command(cache-empty-entry ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR}/cache-empty-entry/) +function(run_ExplicitDirs) + set(source_dir ${RunCMake_SOURCE_DIR}/ExplicitDirs) + set(binary_dir ${RunCMake_BINARY_DIR}/ExplicitDirs-build) + + file(REMOVE_RECURSE "${binary_dir}") + file(MAKE_DIRECTORY "${binary_dir}") + run_cmake_command(S-arg ${CMAKE_COMMAND} -S ${source_dir} ${binary_dir}) + run_cmake_command(S-arg-reverse-order ${CMAKE_COMMAND} ${binary_dir} -S${source_dir} ) + run_cmake_command(S-no-arg ${CMAKE_COMMAND} -S ) + run_cmake_command(S-no-arg2 ${CMAKE_COMMAND} -S -T) + run_cmake_command(S-B ${CMAKE_COMMAND} -S ${source_dir} -B ${binary_dir}) + + # make sure that -B can explicitly construct build directories + file(REMOVE_RECURSE "${binary_dir}") + run_cmake_command(B-arg ${CMAKE_COMMAND} -B ${binary_dir} ${source_dir}) + file(REMOVE_RECURSE "${binary_dir}") + run_cmake_command(B-arg-reverse-order ${CMAKE_COMMAND} ${source_dir} -B${binary_dir}) + run_cmake_command(B-no-arg ${CMAKE_COMMAND} -B ) + run_cmake_command(B-no-arg2 ${CMAKE_COMMAND} -B -T) + file(REMOVE_RECURSE "${binary_dir}") + run_cmake_command(B-S ${CMAKE_COMMAND} -B${binary_dir} -S${source_dir}) + +endfunction() +run_ExplicitDirs() + function(run_BuildDir) # Use a single build tree for a few tests without cleaning. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/BuildDir-build) diff --git a/Tests/RunCMake/CommandLine/S-no-arg-result.txt b/Tests/RunCMake/CommandLine/S-no-arg-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CommandLine/S-no-arg-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/S-no-arg-stderr.txt b/Tests/RunCMake/CommandLine/S-no-arg-stderr.txt new file mode 100644 index 0000000..d1a2ce3 --- /dev/null +++ b/Tests/RunCMake/CommandLine/S-no-arg-stderr.txt @@ -0,0 +1 @@ +CMake Error: No source directory specified for -S diff --git a/Tests/RunCMake/CommandLine/S-no-arg2-result.txt b/Tests/RunCMake/CommandLine/S-no-arg2-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CommandLine/S-no-arg2-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/S-no-arg2-stderr.txt b/Tests/RunCMake/CommandLine/S-no-arg2-stderr.txt new file mode 100644 index 0000000..d1a2ce3 --- /dev/null +++ b/Tests/RunCMake/CommandLine/S-no-arg2-stderr.txt @@ -0,0 +1 @@ +CMake Error: No source directory specified for -S ----------------------------------------------------------------------- Summary of changes: Help/manual/OPTIONS_BUILD.txt | 8 +++ Help/manual/cmake.1.rst | 6 +- Help/release/dev/cmake-explicit-dirs.rst | 10 +++ Help/release/dev/create_symlink-windows.rst | 5 ++ Source/CTest/cmCTestSubmitHandler.cxx | 23 +++++++ Source/QtDialog/CMakeSetup.cxx | 2 +- Source/cmGlobalGenerator.cxx | 4 +- Source/cmGlobalNinjaGenerator.cxx | 2 +- Source/cmGlobalVisualStudio8Generator.cxx | 6 +- Source/cmLocalUnixMakefileGenerator3.cxx | 4 +- Source/cmLocalVisualStudio7Generator.cxx | 2 +- Source/cmSystemTools.cxx | 25 ++++++- Source/cmSystemTools.h | 5 ++ Source/cmake.cxx | 57 ++++++++++++---- Source/cmake.h | 4 +- Source/cmakemain.cxx | 3 +- Source/cmcmd.cxx | 7 +- .../B-no-arg-result.txt} | 0 Tests/RunCMake/CommandLine/B-no-arg-stderr.txt | 1 + .../B-no-arg2-result.txt} | 0 Tests/RunCMake/CommandLine/B-no-arg2-stderr.txt | 1 + .../E_create_symlink-broken-create-check.cmake | 14 ++-- .../E_create_symlink-broken-replace-check.cmake | 8 ++- .../{BuildDir => ExplicitDirs}/CMakeLists.txt | 1 + Tests/RunCMake/CommandLine/NoArgs-stdout.txt | 1 + Tests/RunCMake/CommandLine/RunCMakeTest.cmake | 76 +++++++++++++++------- .../S-no-arg-result.txt} | 0 Tests/RunCMake/CommandLine/S-no-arg-stderr.txt | 1 + .../S-no-arg2-result.txt} | 0 Tests/RunCMake/CommandLine/S-no-arg2-stderr.txt | 1 + ...UE-result.txt => CDashSubmitVerbose-result.txt} | 0 ...rs-stderr.txt => CDashSubmitVerbose-stderr.txt} | 0 .../ctest_submit/CDashSubmitVerbose-stdout.txt | 1 + Tests/RunCMake/ctest_submit/RunCMakeTest.cmake | 1 + Tests/RunCMake/ctest_submit/test.cmake.in | 1 + 35 files changed, 211 insertions(+), 69 deletions(-) create mode 100644 Help/release/dev/cmake-explicit-dirs.rst create mode 100644 Help/release/dev/create_symlink-windows.rst copy Tests/RunCMake/{while/MissingArgument-result.txt => CommandLine/B-no-arg-result.txt} (100%) create mode 100644 Tests/RunCMake/CommandLine/B-no-arg-stderr.txt copy Tests/RunCMake/{while/MissingArgument-result.txt => CommandLine/B-no-arg2-result.txt} (100%) create mode 100644 Tests/RunCMake/CommandLine/B-no-arg2-stderr.txt copy Tests/RunCMake/CommandLine/{BuildDir => ExplicitDirs}/CMakeLists.txt (84%) copy Tests/RunCMake/{while/MissingArgument-result.txt => CommandLine/S-no-arg-result.txt} (100%) create mode 100644 Tests/RunCMake/CommandLine/S-no-arg-stderr.txt copy Tests/RunCMake/{while/MissingArgument-result.txt => CommandLine/S-no-arg2-result.txt} (100%) create mode 100644 Tests/RunCMake/CommandLine/S-no-arg2-stderr.txt copy Tests/RunCMake/ctest_submit/{RepeatRETURN_VALUE-result.txt => CDashSubmitVerbose-result.txt} (100%) copy Tests/RunCMake/ctest_submit/{CDashSubmitHeaders-stderr.txt => CDashSubmitVerbose-stderr.txt} (100%) create mode 100644 Tests/RunCMake/ctest_submit/CDashSubmitVerbose-stdout.txt hooks/post-receive -- CMake From kwrobot at kitware.com Thu Sep 20 00:05:04 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Thu, 20 Sep 2018 00:05:04 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-674-g2d119e5 Message-ID: <20180920040504.60EB9125228@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 2d119e53093c9489c80ce9bc3f21eadc254b6e10 (commit) from a9df54ec313cf832a30f7aab0180a74d114ee5b5 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=2d119e53093c9489c80ce9bc3f21eadc254b6e10 commit 2d119e53093c9489c80ce9bc3f21eadc254b6e10 Author: Kitware Robot AuthorDate: Thu Sep 20 00:01:08 2018 -0400 Commit: Kitware Robot CommitDate: Thu Sep 20 00:01:08 2018 -0400 CMake Nightly Date Stamp diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 1a5fd15..cb0833f 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 12) -set(CMake_VERSION_PATCH 20180919) +set(CMake_VERSION_PATCH 20180920) #set(CMake_VERSION_RC 1) ----------------------------------------------------------------------- Summary of changes: Source/CMakeVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) hooks/post-receive -- CMake From kwrobot at kitware.com Thu Sep 20 09:35:13 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Thu, 20 Sep 2018 09:35:13 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-683-gece1859 Message-ID: <20180920133513.4520E1253A7@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via ece1859e1e123adb2386df1c7d1ce53194f5a73f (commit) via f082414107fd2a77c370a8d87aa589dad0e6f55d (commit) via cf1764b395eabebcee6908f699493bf12b4b0b4b (commit) via cfe77802795699e829105346acc2d92c791f88fa (commit) via 63eb43f1311aedd03a4274ec4321234723f54359 (commit) via 173d29a379b5fc4a41116486ca2af4d006188ee5 (commit) via 7e33050558bd7807f5b718f5f0d170159cc532ee (commit) via 83ddc4d2891a0bbb06fb1e3daa00245b3c23eddc (commit) via 6b7b54d476a297b32f8f1521f3255052b9dda1b6 (commit) from 2d119e53093c9489c80ce9bc3f21eadc254b6e10 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=ece1859e1e123adb2386df1c7d1ce53194f5a73f commit ece1859e1e123adb2386df1c7d1ce53194f5a73f Merge: f082414 cfe7780 Author: Brad King AuthorDate: Thu Sep 20 13:32:49 2018 +0000 Commit: Kitware Robot CommitDate: Thu Sep 20 09:33:56 2018 -0400 Merge topic 'doc-updates' cfe7780279 Help: TESTS property: clarify usage. Acked-by: Kitware Robot Merge-request: !2401 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=f082414107fd2a77c370a8d87aa589dad0e6f55d commit f082414107fd2a77c370a8d87aa589dad0e6f55d Merge: cf1764b 63eb43f Author: Brad King AuthorDate: Thu Sep 20 13:32:30 2018 +0000 Commit: Kitware Robot CommitDate: Thu Sep 20 09:33:05 2018 -0400 Merge topic 'vs-2015-max-sdk' 63eb43f131 Tests: Add VSWinStorePhone for VS 15 2017 173d29a379 Tests: Fix VSWinStorePhone to properly identify VS 14 2015 83ddc4d289 VS: Do not select a Windows SDK too high for current VS version Acked-by: Kitware Robot Merge-request: !2388 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=cf1764b395eabebcee6908f699493bf12b4b0b4b commit cf1764b395eabebcee6908f699493bf12b4b0b4b Merge: 2d119e5 7e33050 Author: Brad King AuthorDate: Thu Sep 20 13:31:30 2018 +0000 Commit: Kitware Robot CommitDate: Thu Sep 20 09:31:57 2018 -0400 Merge topic '18375-kfreebsd-bootstrap' 7e33050558 libuv: Add kFreeBSD platform-specific files 6b7b54d476 bootstrap: Add missing libraries for kFreeBSD Acked-by: Kitware Robot Merge-request: !2394 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=cfe77802795699e829105346acc2d92c791f88fa commit cfe77802795699e829105346acc2d92c791f88fa Author: Marc Chevrier AuthorDate: Wed Sep 19 09:38:13 2018 +0200 Commit: Brad King CommitDate: Wed Sep 19 10:46:22 2018 -0400 Help: TESTS property: clarify usage. diff --git a/Help/prop_dir/TESTS.rst b/Help/prop_dir/TESTS.rst index c6e1d88..91acd3e 100644 --- a/Help/prop_dir/TESTS.rst +++ b/Help/prop_dir/TESTS.rst @@ -4,4 +4,4 @@ TESTS List of tests. This read-only property holds a :ref:`;-list ` of tests -defined so far by the :command:`add_test` command. +defined so far, in the current directory, by the :command:`add_test` command. https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=63eb43f1311aedd03a4274ec4321234723f54359 commit 63eb43f1311aedd03a4274ec4321234723f54359 Author: Gilles Khouzam AuthorDate: Mon Aug 7 10:38:50 2017 -0700 Commit: Brad King CommitDate: Wed Sep 19 09:40:17 2018 -0400 Tests: Add VSWinStorePhone for VS 15 2017 VS 2017 needs several components installed to support this test, so enable it only via an explicit option that can be set on specific builders. diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 7e8fef8..77a96b1 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -2162,6 +2162,11 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release -DCMAKE_SYSTEM_VERSION=8.1 ) endif() + if(CMake_TEST_VSWinStorePhone_VS_2017 AND ws10_0) + add_test_VSWinStorePhone(vs15-store10_0-X86 "Visual Studio 15 2017" WindowsStore 10.0) + add_test_VSWinStorePhone(vs15-store10_0-ARM "Visual Studio 15 2017 ARM" WindowsStore 10.0) + add_test_VSWinStorePhone(vs15-store10_0-X64 "Visual Studio 15 2017 Win64" WindowsStore 10.0) + endif() if(vs14 AND ws10_0) add_test_VSWinStorePhone(vs14-store10_0-X86 "Visual Studio 14 2015" WindowsStore 10.0) add_test_VSWinStorePhone(vs14-store10_0-ARM "Visual Studio 14 2015 ARM" WindowsStore 10.0) https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=173d29a379b5fc4a41116486ca2af4d006188ee5 commit 173d29a379b5fc4a41116486ca2af4d006188ee5 Author: Gilles Khouzam AuthorDate: Mon Aug 7 10:38:50 2017 -0700 Commit: Brad King CommitDate: Wed Sep 19 09:39:25 2018 -0400 Tests: Fix VSWinStorePhone to properly identify VS 14 2015 VS 14 2015 was only identified by the Windows 10 SDK. On machines with only VS 2017 and the Windows 10 SDKs, this would incorrectly identify that VS 2015 was installed. Check for VS 14 2015 with its proper registry entry. diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index a22521b..7e8fef8 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -2106,7 +2106,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release set(reg_vs10 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\10.0;InstallDir]") set(reg_vs11 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\11.0;InstallDir]") set(reg_vs12 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\12.0;InstallDir]") - set(reg_vs14 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot10]") + set(reg_vs14 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\14.0;InstallDir]") set(reg_ws80 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v8.0;InstallationFolder]") set(reg_ws81 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v8.1;InstallationFolder]") set(reg_ws10_0 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\14.0\\Setup\\Build Tools for Windows 10;srcPath]") https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=7e33050558bd7807f5b718f5f0d170159cc532ee commit 7e33050558bd7807f5b718f5f0d170159cc532ee Author: Gregor Jasny AuthorDate: Tue Sep 18 20:21:58 2018 +0200 Commit: Gregor Jasny CommitDate: Tue Sep 18 20:22:55 2018 +0200 libuv: Add kFreeBSD platform-specific files Issue 18375 diff --git a/Utilities/cmlibuv/CMakeLists.txt b/Utilities/cmlibuv/CMakeLists.txt index ba1638e..a503041 100644 --- a/Utilities/cmlibuv/CMakeLists.txt +++ b/Utilities/cmlibuv/CMakeLists.txt @@ -208,6 +208,22 @@ if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") ) endif() +if(CMAKE_SYSTEM_NAME STREQUAL "kFreeBSD") + list(APPEND uv_libraries + freebsd-glue + kvm + ) + list(APPEND uv_headers + include/uv-bsd.h + ) + list(APPEND uv_sources + src/unix/bsd-ifaddrs.c + src/unix/freebsd.c + src/unix/kqueue.c + src/unix/posix-hrtime.c + ) +endif() + if(CMAKE_SYSTEM_NAME STREQUAL "NetBSD") list(APPEND uv_libraries kvm https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=83ddc4d2891a0bbb06fb1e3daa00245b3c23eddc commit 83ddc4d2891a0bbb06fb1e3daa00245b3c23eddc Author: Gilles Khouzam AuthorDate: Mon Aug 7 10:38:50 2017 -0700 Commit: Brad King CommitDate: Mon Sep 17 13:07:40 2018 -0400 VS: Do not select a Windows SDK too high for current VS version Add an internal API for the maximum Windows 10 SDK version supported by a toolset. For Visual Studio 14 2015 that would be the version "10.0.14393.0". Fixes: #17788 diff --git a/Source/cmGlobalVisualStudio14Generator.cxx b/Source/cmGlobalVisualStudio14Generator.cxx index b0db146..c3ddb3e 100644 --- a/Source/cmGlobalVisualStudio14Generator.cxx +++ b/Source/cmGlobalVisualStudio14Generator.cxx @@ -212,6 +212,12 @@ bool cmGlobalVisualStudio14Generator::IsWindowsStoreToolsetInstalled() const cmSystemTools::KeyWOW64_32); } +std::string cmGlobalVisualStudio14Generator::GetWindows10SDKMaxVersion() const +{ + // The last Windows 10 SDK version that VS 2015 can target is 10.0.14393.0. + return "10.0.14393.0"; +} + #if defined(_WIN32) && !defined(__CYGWIN__) struct NoWindowsH { @@ -220,6 +226,20 @@ struct NoWindowsH return !cmSystemTools::FileExists(p + "/um/windows.h", true); } }; +class WindowsSDKTooRecent +{ + std::string const& MaxVersion; + +public: + WindowsSDKTooRecent(std::string const& maxVersion) + : MaxVersion(maxVersion) + { + } + bool operator()(std::string const& v) + { + return cmSystemTools::VersionCompareGreater(v, MaxVersion); + } +}; #endif std::string cmGlobalVisualStudio14Generator::GetWindows10SDKVersion() @@ -276,6 +296,12 @@ std::string cmGlobalVisualStudio14Generator::GetWindows10SDKVersion() // Sort the results to make sure we select the most recent one. std::sort(sdks.begin(), sdks.end(), cmSystemTools::VersionCompareGreater); + // Skip SDKs that cannot be used with our toolset. + std::string maxVersion = this->GetWindows10SDKMaxVersion(); + if (!maxVersion.empty()) { + cmEraseIf(sdks, WindowsSDKTooRecent(maxVersion)); + } + // Look for a SDK exactly matching the requested target version. for (std::string const& i : sdks) { if (cmSystemTools::VersionCompareEqual(i, this->SystemVersion)) { diff --git a/Source/cmGlobalVisualStudio14Generator.h b/Source/cmGlobalVisualStudio14Generator.h index 4868df0..9f5bb4e 100644 --- a/Source/cmGlobalVisualStudio14Generator.h +++ b/Source/cmGlobalVisualStudio14Generator.h @@ -37,6 +37,10 @@ protected: // of the toolset is installed bool IsWindowsStoreToolsetInstalled() const; + // Used to make sure that the Windows 10 SDK selected can work with the + // version of the toolset. + virtual std::string GetWindows10SDKMaxVersion() const; + const char* GetIDEVersion() override { return "14.0"; } virtual bool SelectWindows10SDK(cmMakefile* mf, bool required); diff --git a/Source/cmGlobalVisualStudio15Generator.cxx b/Source/cmGlobalVisualStudio15Generator.cxx index 9983a43..23fd2d5 100644 --- a/Source/cmGlobalVisualStudio15Generator.cxx +++ b/Source/cmGlobalVisualStudio15Generator.cxx @@ -258,6 +258,11 @@ bool cmGlobalVisualStudio15Generator::IsWin81SDKInstalled() const return false; } +std::string cmGlobalVisualStudio15Generator::GetWindows10SDKMaxVersion() const +{ + return std::string(); +} + std::string cmGlobalVisualStudio15Generator::FindMSBuildCommand() { std::string msbuild; diff --git a/Source/cmGlobalVisualStudio15Generator.h b/Source/cmGlobalVisualStudio15Generator.h index cdc97ad..8ab63f1 100644 --- a/Source/cmGlobalVisualStudio15Generator.h +++ b/Source/cmGlobalVisualStudio15Generator.h @@ -52,6 +52,8 @@ protected: // Check for a Win 8 SDK known to the registry or VS installer tool. bool IsWin81SDKInstalled() const; + std::string GetWindows10SDKMaxVersion() const override; + std::string FindMSBuildCommand() override; std::string FindDevEnvCommand() override; https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=6b7b54d476a297b32f8f1521f3255052b9dda1b6 commit 6b7b54d476a297b32f8f1521f3255052b9dda1b6 Author: Gregor Jasny AuthorDate: Sun Sep 16 14:35:44 2018 +0200 Commit: Gregor Jasny CommitDate: Sun Sep 16 14:35:44 2018 +0200 bootstrap: Add missing libraries for kFreeBSD Closes #18375 diff --git a/bootstrap b/bootstrap index 188193d..416a3d6 100755 --- a/bootstrap +++ b/bootstrap @@ -1370,6 +1370,9 @@ else uv_c_flags="${uv_c_flags} -D_GNU_SOURCE" libs="${libs} -ldl -lrt" ;; + *kFreeBSD*) + libs="${libs} -lkvm -lfreebsd-glue" + ;; *BSD*) libs="${libs} -lkvm" ;; ----------------------------------------------------------------------- Summary of changes: Help/prop_dir/TESTS.rst | 2 +- Source/cmGlobalVisualStudio14Generator.cxx | 26 ++++++++++++++++++++++++++ Source/cmGlobalVisualStudio14Generator.h | 4 ++++ Source/cmGlobalVisualStudio15Generator.cxx | 5 +++++ Source/cmGlobalVisualStudio15Generator.h | 2 ++ Tests/CMakeLists.txt | 7 ++++++- Utilities/cmlibuv/CMakeLists.txt | 16 ++++++++++++++++ bootstrap | 3 +++ 8 files changed, 63 insertions(+), 2 deletions(-) hooks/post-receive -- CMake From kwrobot at kitware.com Thu Sep 20 09:45:06 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Thu, 20 Sep 2018 09:45:06 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-696-g3523990 Message-ID: <20180920134506.EB117120428@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 3523990f7b96b0f25836cf319a7c8112c55e5acd (commit) via 366df05ac028772097ac4d1aed2752d8a821b554 (commit) via 22db0d5c6e45d3ce247c2ebe5e5c54810363486f (commit) via 99648081085d8ec48a7846c918bee39a2bdde908 (commit) via cc6e2b95d92d233c755c4649ba2d6914255a1e04 (commit) via b69159324a386b48ff992725827029a432f8a549 (commit) via eedd91ab085d551d7953f8bb6fe01fd5540af004 (commit) via fd28ea35ca5f62e52d030288bf60ca6fe769cb96 (commit) via 3925407e76856c6e6bc6090fdee09a1008462840 (commit) via bab868be135b721a5867275f8ffce38cb7b28d06 (commit) via bfd93b73a03a6b2c1e8bb298f7085f90c30337c1 (commit) via 60e6e5db61d6f27814bb68dee1f497848e147ffb (commit) via 8085799ce3a311e3f0f3c2f2119ae0dcb8b2e0a3 (commit) from ece1859e1e123adb2386df1c7d1ce53194f5a73f (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=3523990f7b96b0f25836cf319a7c8112c55e5acd commit 3523990f7b96b0f25836cf319a7c8112c55e5acd Merge: 366df05 b691593 Author: Brad King AuthorDate: Thu Sep 20 13:36:25 2018 +0000 Commit: Kitware Robot CommitDate: Thu Sep 20 09:38:04 2018 -0400 Merge topic 'bundleutilities-policy' b69159324a Help: Add release notes for new BundleUtilities policy eedd91ab08 BundleUtilities: Disallow inclusion at configure time fd28ea35ca Help: Add note for BundleUtilities usage 3925407e76 Help: Convert BundleUtilities help to block-style comment Acked-by: Kitware Robot Merge-request: !2379 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=366df05ac028772097ac4d1aed2752d8a821b554 commit 366df05ac028772097ac4d1aed2752d8a821b554 Merge: 22db0d5 bab868b Author: Brad King AuthorDate: Thu Sep 20 13:36:07 2018 +0000 Commit: Kitware Robot CommitDate: Thu Sep 20 09:37:24 2018 -0400 Merge topic 'rel-win-nightly' bab868be13 Utilities/Release: Skip spurious ExternalData test for nightly binary Acked-by: Kitware Robot Merge-request: !2404 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=22db0d5c6e45d3ce247c2ebe5e5c54810363486f commit 22db0d5c6e45d3ce247c2ebe5e5c54810363486f Merge: 9964808 bfd93b7 Author: Brad King AuthorDate: Thu Sep 20 13:35:45 2018 +0000 Commit: Kitware Robot CommitDate: Thu Sep 20 09:36:31 2018 -0400 Merge topic 'FindCUDA-filter-compute-capabilities' bfd93b73a0 FindCUDA: Filter unrelated content in compute capabilities output Acked-by: Kitware Robot Merge-request: !2400 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=99648081085d8ec48a7846c918bee39a2bdde908 commit 99648081085d8ec48a7846c918bee39a2bdde908 Merge: cc6e2b9 8085799 Author: Brad King AuthorDate: Thu Sep 20 13:35:39 2018 +0000 Commit: Kitware Robot CommitDate: Thu Sep 20 09:35:45 2018 -0400 Merge topic 'FindCUDA-ccbin-env' 8085799ce3 FindCUDA: Add option to set CUDA_HOST_COMPILER via environment Acked-by: Kitware Robot Merge-request: !2391 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=cc6e2b95d92d233c755c4649ba2d6914255a1e04 commit cc6e2b95d92d233c755c4649ba2d6914255a1e04 Merge: ece1859 60e6e5d Author: Brad King AuthorDate: Thu Sep 20 09:34:50 2018 -0400 Commit: Brad King CommitDate: Thu Sep 20 09:34:50 2018 -0400 Merge branch 'release-3.12' https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=b69159324a386b48ff992725827029a432f8a549 commit b69159324a386b48ff992725827029a432f8a549 Author: Kyle Edwards AuthorDate: Wed Sep 19 11:23:16 2018 -0400 Commit: Kyle Edwards CommitDate: Wed Sep 19 11:23:16 2018 -0400 Help: Add release notes for new BundleUtilities policy diff --git a/Help/release/dev/bundleutilities-policy.rst b/Help/release/dev/bundleutilities-policy.rst new file mode 100644 index 0000000..e293f92 --- /dev/null +++ b/Help/release/dev/bundleutilities-policy.rst @@ -0,0 +1,5 @@ +bundleutilities-policy +---------------------- + +* The :module:`BundleUtilities` module may no longer be included at configure + time. This was always a bug anyway. See policy :policy:`CMP0080`. https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=eedd91ab085d551d7953f8bb6fe01fd5540af004 commit eedd91ab085d551d7953f8bb6fe01fd5540af004 Author: Kyle Edwards AuthorDate: Wed Sep 12 13:33:04 2018 -0400 Commit: Kyle Edwards CommitDate: Wed Sep 19 11:23:08 2018 -0400 BundleUtilities: Disallow inclusion at configure time This commit adds a new CMake policy, CMP0080, which prohibits the inclusion of BundleUtilities at configure time. The old behavior is to allow the inclusion. diff --git a/Help/manual/cmake-policies.7.rst b/Help/manual/cmake-policies.7.rst index 8ecca4d..904ebee 100644 --- a/Help/manual/cmake-policies.7.rst +++ b/Help/manual/cmake-policies.7.rst @@ -57,6 +57,7 @@ Policies Introduced by CMake 3.13 .. toctree:: :maxdepth: 1 + CMP0080: BundleUtilities cannot be included at configure time. CMP0079: target_link_libraries allows use with targets in other directories. CMP0078: UseSWIG generates standard target names. CMP0077: option() honors normal variables. diff --git a/Help/policy/CMP0080.rst b/Help/policy/CMP0080.rst new file mode 100644 index 0000000..5ce9591 --- /dev/null +++ b/Help/policy/CMP0080.rst @@ -0,0 +1,25 @@ +CMP0080 +------- + +:module:`BundleUtilities` cannot be included at configure time. + +The macros provided by :module:`BundleUtilities` are intended to be invoked +at install time rather than at configure time, because they depend on the +listed targets already existing at the time they are invoked. If they are +invoked at configure time, the targets haven't been built yet, and the +commands will fail. + +This policy restricts the inclusion of :module:`BundleUtilities` to +``cmake -P`` style scripts and install rules. Specifically, it looks for the +presence of :variable:`CMAKE_GENERATOR` and throws a fatal error if it exists. + +The ``OLD`` behavior of this policy is to allow :module:`BundleUtilities` to +be included at configure time. The ``NEW`` behavior of this policy is to +disallow such inclusion. + +This policy was introduced in CMake version 3.13. CMake version +|release| warns when the policy is not set and uses ``OLD`` behavior. +Use the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` +explicitly. + +.. include:: DEPRECATED.txt diff --git a/Modules/BundleUtilities.cmake b/Modules/BundleUtilities.cmake index 191149c..31db25a 100644 --- a/Modules/BundleUtilities.cmake +++ b/Modules/BundleUtilities.cmake @@ -224,6 +224,20 @@ that are already also in the bundle... Anything that points to an external file causes this function to fail the verification. #]=======================================================================] +# Do not include this module at configure time! +if(DEFINED CMAKE_GENERATOR) + cmake_policy(GET CMP0080 _BundleUtilities_CMP0080) + if(_BundleUtilities_CMP0080 STREQUAL "NEW") + message(FATAL_ERROR "BundleUtilities cannot be included at configure time!") + elseif(NOT _BundleUtilities_CMP0080 STREQUAL "OLD") + message(AUTHOR_WARNING + "Policy CMP0080 is not set: BundleUtilities prefers not to be included at configure time. " + "Run \"cmake --help-policy CMP0080\" for policy details. " + "Use the cmake_policy command to set the policy and suppress this warning." + ) + endif() +endif() + # The functions defined in this file depend on the get_prerequisites function # (and possibly others) found in: # diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index 4ffe803..f99cc0f 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -234,7 +234,10 @@ class cmMakefile; SELECT( \ POLICY, CMP0079, \ "target_link_libraries allows use with targets in other directories.", 3, \ - 13, 0, cmPolicies::WARN) + 13, 0, cmPolicies::WARN) \ + SELECT(POLICY, CMP0080, \ + "BundleUtilities cannot be included at configure time", 3, 13, 0, \ + cmPolicies::WARN) #define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1) #define CM_FOR_EACH_POLICY_ID(POLICY) \ diff --git a/Tests/RunCMake/BundleUtilities/CMP0080-COMMAND.cmake b/Tests/RunCMake/BundleUtilities/CMP0080-COMMAND.cmake new file mode 100644 index 0000000..063a7f3 --- /dev/null +++ b/Tests/RunCMake/BundleUtilities/CMP0080-COMMAND.cmake @@ -0,0 +1,5 @@ +if(DEFINED CMP0080_VALUE) + cmake_policy(SET CMP0080 ${CMP0080_VALUE}) +endif() + +include(BundleUtilities) diff --git a/Tests/RunCMake/BundleUtilities/CMP0080-NEW-result.txt b/Tests/RunCMake/BundleUtilities/CMP0080-NEW-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/BundleUtilities/CMP0080-NEW-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/BundleUtilities/CMP0080-NEW-stderr.txt b/Tests/RunCMake/BundleUtilities/CMP0080-NEW-stderr.txt new file mode 100644 index 0000000..1454b0c --- /dev/null +++ b/Tests/RunCMake/BundleUtilities/CMP0080-NEW-stderr.txt @@ -0,0 +1,2 @@ +CMake Error at .*/Modules/BundleUtilities\.cmake:[0-9]+ \(message\): + BundleUtilities cannot be included at configure time! diff --git a/Tests/RunCMake/BundleUtilities/CMP0080-NEW.cmake b/Tests/RunCMake/BundleUtilities/CMP0080-NEW.cmake new file mode 100644 index 0000000..558c16d --- /dev/null +++ b/Tests/RunCMake/BundleUtilities/CMP0080-NEW.cmake @@ -0,0 +1,2 @@ +cmake_policy(SET CMP0080 NEW) +include(BundleUtilities) diff --git a/Tests/RunCMake/BundleUtilities/CMP0080-OLD.cmake b/Tests/RunCMake/BundleUtilities/CMP0080-OLD.cmake new file mode 100644 index 0000000..a65d92f --- /dev/null +++ b/Tests/RunCMake/BundleUtilities/CMP0080-OLD.cmake @@ -0,0 +1,2 @@ +cmake_policy(SET CMP0080 OLD) +include(BundleUtilities) diff --git a/Tests/RunCMake/BundleUtilities/CMP0080-WARN-stderr.txt b/Tests/RunCMake/BundleUtilities/CMP0080-WARN-stderr.txt new file mode 100644 index 0000000..a1a0e8f --- /dev/null +++ b/Tests/RunCMake/BundleUtilities/CMP0080-WARN-stderr.txt @@ -0,0 +1,4 @@ +CMake Warning \(dev\) at .*/Modules/BundleUtilities\.cmake:[0-9]+ \(message\): + Policy CMP0080 is not set: BundleUtilities prefers not to be included at + configure time\. Run "cmake --help-policy CMP0080" for policy details\. Use + the cmake_policy command to set the policy and suppress this warning\. diff --git a/Tests/RunCMake/BundleUtilities/CMP0080-WARN.cmake b/Tests/RunCMake/BundleUtilities/CMP0080-WARN.cmake new file mode 100644 index 0000000..45f6f92 --- /dev/null +++ b/Tests/RunCMake/BundleUtilities/CMP0080-WARN.cmake @@ -0,0 +1 @@ +include(BundleUtilities) diff --git a/Tests/RunCMake/BundleUtilities/CMakeLists.txt b/Tests/RunCMake/BundleUtilities/CMakeLists.txt new file mode 100644 index 0000000..6dd8cdf --- /dev/null +++ b/Tests/RunCMake/BundleUtilities/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.4) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/BundleUtilities/RunCMakeTest.cmake b/Tests/RunCMake/BundleUtilities/RunCMakeTest.cmake new file mode 100644 index 0000000..14aaff1 --- /dev/null +++ b/Tests/RunCMake/BundleUtilities/RunCMakeTest.cmake @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.4) +include(RunCMake) + +# TODO Migrate Tests/BundleUtilities here + +run_cmake(CMP0080-OLD) +run_cmake(CMP0080-NEW) +run_cmake(CMP0080-WARN) +run_cmake_command(CMP0080-COMMAND-OLD ${CMAKE_COMMAND} -DCMP0080_VALUE:STRING=OLD -P ${RunCMake_SOURCE_DIR}/CMP0080-COMMAND.cmake) +run_cmake_command(CMP0080-COMMAND-NEW ${CMAKE_COMMAND} -DCMP0080_VALUE:STRING=NEW -P ${RunCMake_SOURCE_DIR}/CMP0080-COMMAND.cmake) +run_cmake_command(CMP0080-COMMAND-WARN ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/CMP0080-COMMAND.cmake) diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index c6c90d0..69cb5b7 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -251,6 +251,7 @@ add_RunCMake_test(separate_arguments) add_RunCMake_test(set_property) add_RunCMake_test(string) add_RunCMake_test(test_include_dirs) +add_RunCMake_test(BundleUtilities) function(add_RunCMake_test_try_compile) if(CMAKE_VERSION VERSION_LESS 3.9.20170907 AND "x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xMSVC") https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=fd28ea35ca5f62e52d030288bf60ca6fe769cb96 commit fd28ea35ca5f62e52d030288bf60ca6fe769cb96 Author: Kyle Edwards AuthorDate: Wed Sep 12 11:57:14 2018 -0400 Commit: Kyle Edwards CommitDate: Wed Sep 19 11:23:08 2018 -0400 Help: Add note for BundleUtilities usage The macros defined in BundleUtilities are intended to be used from an install() rule rather than at configure time. Add a note clarifying this. diff --git a/Modules/BundleUtilities.cmake b/Modules/BundleUtilities.cmake index f271521..191149c 100644 --- a/Modules/BundleUtilities.cmake +++ b/Modules/BundleUtilities.cmake @@ -35,6 +35,10 @@ The following functions are provided by this module: Requires CMake 2.6 or greater because it uses function, break and PARENT_SCOPE. Also depends on GetPrerequisites.cmake. +DO NOT USE THESE FUNCTIONS AT CONFIGURE TIME (from ``CMakeLists.txt``)! +Instead, invoke them from an :command:`install(CODE)` or +:command:`install(SCRIPT)` rule. + :: FIXUP_BUNDLE( ) https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=3925407e76856c6e6bc6090fdee09a1008462840 commit 3925407e76856c6e6bc6090fdee09a1008462840 Author: Kyle Edwards AuthorDate: Wed Sep 12 11:48:12 2018 -0400 Commit: Kyle Edwards CommitDate: Wed Sep 19 11:23:08 2018 -0400 Help: Convert BundleUtilities help to block-style comment diff --git a/Modules/BundleUtilities.cmake b/Modules/BundleUtilities.cmake index 4727f03..f271521 100644 --- a/Modules/BundleUtilities.cmake +++ b/Modules/BundleUtilities.cmake @@ -1,223 +1,224 @@ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. -#.rst: -# BundleUtilities -# --------------- -# -# Functions to help assemble a standalone bundle application. -# -# A collection of CMake utility functions useful for dealing with .app -# bundles on the Mac and bundle-like directories on any OS. -# -# The following functions are provided by this module: -# -# :: -# -# fixup_bundle -# copy_and_fixup_bundle -# verify_app -# get_bundle_main_executable -# get_dotapp_dir -# get_bundle_and_executable -# get_bundle_all_executables -# get_item_key -# get_item_rpaths -# clear_bundle_keys -# set_bundle_key_values -# get_bundle_keys -# copy_resolved_item_into_bundle -# copy_resolved_framework_into_bundle -# fixup_bundle_item -# verify_bundle_prerequisites -# verify_bundle_symlinks -# -# Requires CMake 2.6 or greater because it uses function, break and -# PARENT_SCOPE. Also depends on GetPrerequisites.cmake. -# -# :: -# -# FIXUP_BUNDLE( ) -# -# Fix up a bundle in-place and make it standalone, such that it can be -# drag-n-drop copied to another machine and run on that machine as long -# as all of the system libraries are compatible. -# -# If you pass plugins to fixup_bundle as the libs parameter, you should -# install them or copy them into the bundle before calling fixup_bundle. -# The "libs" parameter is a list of libraries that must be fixed up, but -# that cannot be determined by otool output analysis. (i.e., plugins) -# -# Gather all the keys for all the executables and libraries in a bundle, -# and then, for each key, copy each prerequisite into the bundle. Then -# fix each one up according to its own list of prerequisites. -# -# Then clear all the keys and call verify_app on the final bundle to -# ensure that it is truly standalone. -# -# As an optional parameter (IGNORE_ITEM) a list of file names can be passed, -# which are then ignored (e.g. IGNORE_ITEM "vcredist_x86.exe;vcredist_x64.exe") -# -# :: -# -# COPY_AND_FIXUP_BUNDLE( ) -# -# Makes a copy of the bundle at location and then fixes up -# the new copied bundle in-place at ... -# -# :: -# -# VERIFY_APP() -# -# Verifies that an application appears valid based on running -# analysis tools on it. Calls "message(FATAL_ERROR" if the application -# is not verified. -# -# As an optional parameter (IGNORE_ITEM) a list of file names can be passed, -# which are then ignored (e.g. IGNORE_ITEM "vcredist_x86.exe;vcredist_x64.exe") -# -# :: -# -# GET_BUNDLE_MAIN_EXECUTABLE( ) -# -# The result will be the full path name of the bundle's main executable -# file or an "error:" prefixed string if it could not be determined. -# -# :: -# -# GET_DOTAPP_DIR( ) -# -# Returns the nearest parent dir whose name ends with ".app" given the -# full path to an executable. If there is no such parent dir, then -# simply return the dir containing the executable. -# -# The returned directory may or may not exist. -# -# :: -# -# GET_BUNDLE_AND_EXECUTABLE( ) -# -# Takes either a ".app" directory name or the name of an executable -# nested inside a ".app" directory and returns the path to the ".app" -# directory in and the path to its main executable in -# -# -# :: -# -# GET_BUNDLE_ALL_EXECUTABLES( ) -# -# Scans the given bundle recursively for all executable files and -# accumulates them into a variable. -# -# :: -# -# GET_ITEM_KEY( ) -# -# Given a file (item) name, generate a key that should be unique -# considering the set of libraries that need copying or fixing up to -# make a bundle standalone. This is essentially the file name including -# extension with "." replaced by "_" -# -# This key is used as a prefix for CMake variables so that we can -# associate a set of variables with a given item based on its key. -# -# :: -# -# CLEAR_BUNDLE_KEYS() -# -# Loop over the list of keys, clearing all the variables associated with -# each key. After the loop, clear the list of keys itself. -# -# Caller of get_bundle_keys should call clear_bundle_keys when done with -# list of keys. -# -# :: -# -# SET_BUNDLE_KEY_VALUES( -# []) -# -# Add a key to the list (if necessary) for the given item. If added, -# also set all the variables associated with that key. -# -# :: -# -# GET_BUNDLE_KEYS( ) -# -# Loop over all the executable and library files within the bundle (and -# given as extra ) and accumulate a list of keys representing -# them. Set values associated with each key such that we can loop over -# all of them and copy prerequisite libs into the bundle and then do -# appropriate install_name_tool fixups. -# -# As an optional parameter (IGNORE_ITEM) a list of file names can be passed, -# which are then ignored (e.g. IGNORE_ITEM "vcredist_x86.exe;vcredist_x64.exe") -# -# :: -# -# COPY_RESOLVED_ITEM_INTO_BUNDLE( ) -# -# Copy a resolved item into the bundle if necessary. Copy is not -# necessary if the resolved_item is "the same as" the -# resolved_embedded_item. -# -# :: -# -# COPY_RESOLVED_FRAMEWORK_INTO_BUNDLE( ) -# -# Copy a resolved framework into the bundle if necessary. Copy is not -# necessary if the resolved_item is "the same as" the -# resolved_embedded_item. -# -# By default, BU_COPY_FULL_FRAMEWORK_CONTENTS is not set. If you want -# full frameworks embedded in your bundles, set -# BU_COPY_FULL_FRAMEWORK_CONTENTS to ON before calling fixup_bundle. By -# default, COPY_RESOLVED_FRAMEWORK_INTO_BUNDLE copies the framework -# dylib itself plus the framework Resources directory. -# -# :: -# -# FIXUP_BUNDLE_ITEM( ) -# -# Get the direct/non-system prerequisites of the resolved embedded item. -# For each prerequisite, change the way it is referenced to the value of -# the _EMBEDDED_ITEM keyed variable for that prerequisite. (Most likely -# changing to an "@executable_path" style reference.) -# -# This function requires that the resolved_embedded_item be "inside" the -# bundle already. In other words, if you pass plugins to fixup_bundle -# as the libs parameter, you should install them or copy them into the -# bundle before calling fixup_bundle. The "libs" parameter is a list of -# libraries that must be fixed up, but that cannot be determined by -# otool output analysis. (i.e., plugins) -# -# Also, change the id of the item being fixed up to its own -# _EMBEDDED_ITEM value. -# -# Accumulate changes in a local variable and make *one* call to -# install_name_tool at the end of the function with all the changes at -# once. -# -# If the BU_CHMOD_BUNDLE_ITEMS variable is set then bundle items will be -# marked writable before install_name_tool tries to change them. -# -# :: -# -# VERIFY_BUNDLE_PREREQUISITES( ) -# -# Verifies that the sum of all prerequisites of all files inside the -# bundle are contained within the bundle or are "system" libraries, -# presumed to exist everywhere. -# -# As an optional parameter (IGNORE_ITEM) a list of file names can be passed, -# which are then ignored (e.g. IGNORE_ITEM "vcredist_x86.exe;vcredist_x64.exe") -# -# :: -# -# VERIFY_BUNDLE_SYMLINKS( ) -# -# Verifies that any symlinks found in the bundle point to other files -# that are already also in the bundle... Anything that points to an -# external file causes this function to fail the verification. +#[=======================================================================[.rst: +BundleUtilities +--------------- + +Functions to help assemble a standalone bundle application. + +A collection of CMake utility functions useful for dealing with .app +bundles on the Mac and bundle-like directories on any OS. + +The following functions are provided by this module: + +:: + + fixup_bundle + copy_and_fixup_bundle + verify_app + get_bundle_main_executable + get_dotapp_dir + get_bundle_and_executable + get_bundle_all_executables + get_item_key + get_item_rpaths + clear_bundle_keys + set_bundle_key_values + get_bundle_keys + copy_resolved_item_into_bundle + copy_resolved_framework_into_bundle + fixup_bundle_item + verify_bundle_prerequisites + verify_bundle_symlinks + +Requires CMake 2.6 or greater because it uses function, break and +PARENT_SCOPE. Also depends on GetPrerequisites.cmake. + +:: + + FIXUP_BUNDLE( ) + +Fix up a bundle in-place and make it standalone, such that it can be +drag-n-drop copied to another machine and run on that machine as long +as all of the system libraries are compatible. + +If you pass plugins to fixup_bundle as the libs parameter, you should +install them or copy them into the bundle before calling fixup_bundle. +The "libs" parameter is a list of libraries that must be fixed up, but +that cannot be determined by otool output analysis. (i.e., plugins) + +Gather all the keys for all the executables and libraries in a bundle, +and then, for each key, copy each prerequisite into the bundle. Then +fix each one up according to its own list of prerequisites. + +Then clear all the keys and call verify_app on the final bundle to +ensure that it is truly standalone. + +As an optional parameter (IGNORE_ITEM) a list of file names can be passed, +which are then ignored (e.g. IGNORE_ITEM "vcredist_x86.exe;vcredist_x64.exe") + +:: + + COPY_AND_FIXUP_BUNDLE( ) + +Makes a copy of the bundle at location and then fixes up +the new copied bundle in-place at ... + +:: + + VERIFY_APP() + +Verifies that an application appears valid based on running +analysis tools on it. Calls "message(FATAL_ERROR" if the application +is not verified. + +As an optional parameter (IGNORE_ITEM) a list of file names can be passed, +which are then ignored (e.g. IGNORE_ITEM "vcredist_x86.exe;vcredist_x64.exe") + +:: + + GET_BUNDLE_MAIN_EXECUTABLE( ) + +The result will be the full path name of the bundle's main executable +file or an "error:" prefixed string if it could not be determined. + +:: + + GET_DOTAPP_DIR( ) + +Returns the nearest parent dir whose name ends with ".app" given the +full path to an executable. If there is no such parent dir, then +simply return the dir containing the executable. + +The returned directory may or may not exist. + +:: + + GET_BUNDLE_AND_EXECUTABLE( ) + +Takes either a ".app" directory name or the name of an executable +nested inside a ".app" directory and returns the path to the ".app" +directory in and the path to its main executable in + + +:: + + GET_BUNDLE_ALL_EXECUTABLES( ) + +Scans the given bundle recursively for all executable files and +accumulates them into a variable. + +:: + + GET_ITEM_KEY( ) + +Given a file (item) name, generate a key that should be unique +considering the set of libraries that need copying or fixing up to +make a bundle standalone. This is essentially the file name including +extension with "." replaced by "_" + +This key is used as a prefix for CMake variables so that we can +associate a set of variables with a given item based on its key. + +:: + + CLEAR_BUNDLE_KEYS() + +Loop over the list of keys, clearing all the variables associated with +each key. After the loop, clear the list of keys itself. + +Caller of get_bundle_keys should call clear_bundle_keys when done with +list of keys. + +:: + + SET_BUNDLE_KEY_VALUES( + []) + +Add a key to the list (if necessary) for the given item. If added, +also set all the variables associated with that key. + +:: + + GET_BUNDLE_KEYS( ) + +Loop over all the executable and library files within the bundle (and +given as extra ) and accumulate a list of keys representing +them. Set values associated with each key such that we can loop over +all of them and copy prerequisite libs into the bundle and then do +appropriate install_name_tool fixups. + +As an optional parameter (IGNORE_ITEM) a list of file names can be passed, +which are then ignored (e.g. IGNORE_ITEM "vcredist_x86.exe;vcredist_x64.exe") + +:: + + COPY_RESOLVED_ITEM_INTO_BUNDLE( ) + +Copy a resolved item into the bundle if necessary. Copy is not +necessary if the resolved_item is "the same as" the +resolved_embedded_item. + +:: + + COPY_RESOLVED_FRAMEWORK_INTO_BUNDLE( ) + +Copy a resolved framework into the bundle if necessary. Copy is not +necessary if the resolved_item is "the same as" the +resolved_embedded_item. + +By default, BU_COPY_FULL_FRAMEWORK_CONTENTS is not set. If you want +full frameworks embedded in your bundles, set +BU_COPY_FULL_FRAMEWORK_CONTENTS to ON before calling fixup_bundle. By +default, COPY_RESOLVED_FRAMEWORK_INTO_BUNDLE copies the framework +dylib itself plus the framework Resources directory. + +:: + + FIXUP_BUNDLE_ITEM( ) + +Get the direct/non-system prerequisites of the resolved embedded item. +For each prerequisite, change the way it is referenced to the value of +the _EMBEDDED_ITEM keyed variable for that prerequisite. (Most likely +changing to an "@executable_path" style reference.) + +This function requires that the resolved_embedded_item be "inside" the +bundle already. In other words, if you pass plugins to fixup_bundle +as the libs parameter, you should install them or copy them into the +bundle before calling fixup_bundle. The "libs" parameter is a list of +libraries that must be fixed up, but that cannot be determined by +otool output analysis. (i.e., plugins) + +Also, change the id of the item being fixed up to its own +_EMBEDDED_ITEM value. + +Accumulate changes in a local variable and make *one* call to +install_name_tool at the end of the function with all the changes at +once. + +If the BU_CHMOD_BUNDLE_ITEMS variable is set then bundle items will be +marked writable before install_name_tool tries to change them. + +:: + + VERIFY_BUNDLE_PREREQUISITES( ) + +Verifies that the sum of all prerequisites of all files inside the +bundle are contained within the bundle or are "system" libraries, +presumed to exist everywhere. + +As an optional parameter (IGNORE_ITEM) a list of file names can be passed, +which are then ignored (e.g. IGNORE_ITEM "vcredist_x86.exe;vcredist_x64.exe") + +:: + + VERIFY_BUNDLE_SYMLINKS( ) + +Verifies that any symlinks found in the bundle point to other files +that are already also in the bundle... Anything that points to an +external file causes this function to fail the verification. +#]=======================================================================] # The functions defined in this file depend on the get_prerequisites function # (and possibly others) found in: https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=bab868be135b721a5867275f8ffce38cb7b28d06 commit bab868be135b721a5867275f8ffce38cb7b28d06 Author: Brad King AuthorDate: Wed Sep 19 08:34:40 2018 -0400 Commit: Brad King CommitDate: Wed Sep 19 10:59:21 2018 -0400 Utilities/Release: Skip spurious ExternalData test for nightly binary This test fails spuriously too often and prevents the nightly binary from finishing. Simply skip it for the nightly binary to allow it to complete more regularly. diff --git a/Utilities/Release/win32_release.cmake b/Utilities/Release/win32_release.cmake index f9e35a5..2e817d9 100644 --- a/Utilities/Release/win32_release.cmake +++ b/Utilities/Release/win32_release.cmake @@ -39,6 +39,6 @@ get_filename_component(path "${CMAKE_CURRENT_LIST_FILE}" PATH) set(GIT_EXTRA "git config core.autocrlf true") if(CMAKE_CREATE_VERSION STREQUAL "nightly") # Some tests fail spuriously too often. - set(EXTRA_CTEST_ARGS "-E 'ConsoleBuf'") + set(EXTRA_CTEST_ARGS "-E 'ConsoleBuf|Module.ExternalData'") endif() include(${path}/release_cmake.cmake) diff --git a/Utilities/Release/win64_release.cmake b/Utilities/Release/win64_release.cmake index 02e4096..33af830 100644 --- a/Utilities/Release/win64_release.cmake +++ b/Utilities/Release/win64_release.cmake @@ -39,6 +39,6 @@ get_filename_component(path "${CMAKE_CURRENT_LIST_FILE}" PATH) set(GIT_EXTRA "git config core.autocrlf true") if(CMAKE_CREATE_VERSION STREQUAL "nightly") # Some tests fail spuriously too often. - set(EXTRA_CTEST_ARGS "-E 'ConsoleBuf'") + set(EXTRA_CTEST_ARGS "-E 'ConsoleBuf|Module.ExternalData'") endif() include(${path}/release_cmake.cmake) https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=bfd93b73a03a6b2c1e8bb298f7085f90c30337c1 commit bfd93b73a03a6b2c1e8bb298f7085f90c30337c1 Author: Soumith Chintala AuthorDate: Tue Sep 18 19:50:23 2018 -0700 Commit: Brad King CommitDate: Wed Sep 19 10:55:02 2018 -0400 FindCUDA: Filter unrelated content in compute capabilities output Working around CUDA-level nvrm_gpu log statements to stdout on some embedded platforms (ex. Drive PX2). See-also: https://github.com/pytorch/pytorch/issues/11518#issue-359113249 diff --git a/Modules/FindCUDA/select_compute_arch.cmake b/Modules/FindCUDA/select_compute_arch.cmake index cf4fc39..1baf051 100644 --- a/Modules/FindCUDA/select_compute_arch.cmake +++ b/Modules/FindCUDA/select_compute_arch.cmake @@ -109,6 +109,9 @@ function(CUDA_DETECT_INSTALLED_GPUS OUT_VARIABLE) RUN_OUTPUT_VARIABLE compute_capabilities) endif() + # Filter unrelated content out of the output. + string(REGEX MATCHALL "[0-9]+\\.[0-9]+" compute_capabilities "${compute_capabilities}") + if(run_result EQUAL 0) string(REPLACE "2.1" "2.1(2.0)" compute_capabilities "${compute_capabilities}") set(CUDA_GPU_DETECT_OUTPUT ${compute_capabilities} https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=8085799ce3a311e3f0f3c2f2119ae0dcb8b2e0a3 commit 8085799ce3a311e3f0f3c2f2119ae0dcb8b2e0a3 Author: peterjc123 AuthorDate: Sat Sep 15 05:14:38 2018 -0400 Commit: Brad King CommitDate: Tue Sep 18 11:41:47 2018 -0400 FindCUDA: Add option to set CUDA_HOST_COMPILER via environment Re-use the `CUDAHOSTCXX` environment variable from the first-class CUDA language support to specify the host compiler for FindCUDA. diff --git a/Help/envvar/CUDAHOSTCXX.rst b/Help/envvar/CUDAHOSTCXX.rst index f0f94f6..bb786ca 100644 --- a/Help/envvar/CUDAHOSTCXX.rst +++ b/Help/envvar/CUDAHOSTCXX.rst @@ -7,3 +7,7 @@ determine ``CUDA`` host compiler, after which the value for ``CUDAHOSTCXX`` is stored in the cache as :variable:`CMAKE_CUDA_HOST_COMPILER`. For any configuration run (including the first), the environment variable will be ignored if the :variable:`CMAKE_CUDA_HOST_COMPILER` variable is defined. + +This environment variable is primarily meant for use with projects that +enable ``CUDA`` as a first-class language. The :module:`FindCUDA` +module will also use it to initialize its ``CUDA_HOST_COMPILER`` setting. diff --git a/Modules/FindCUDA.cmake b/Modules/FindCUDA.cmake index 1650e55..686e2e7 100644 --- a/Modules/FindCUDA.cmake +++ b/Modules/FindCUDA.cmake @@ -105,6 +105,8 @@ # the host compiler is constructed with one or more visual studio macros # such as $(VCInstallDir), that expands out to the path when # the command is run from within VS. +# If the CUDAHOSTCXX environment variable is set it will +# be used as the default. # # CUDA_NVCC_FLAGS # CUDA_NVCC_FLAGS_ @@ -527,7 +529,9 @@ option(CUDA_HOST_COMPILATION_CPP "Generated file extension" ON) # Extra user settable flags cmake_initialize_per_config_variable(CUDA_NVCC_FLAGS "Semi-colon delimit multiple arguments.") -if(CMAKE_GENERATOR MATCHES "Visual Studio") +if(DEFINED ENV{CUDAHOSTCXX}) + set(CUDA_HOST_COMPILER "$ENV{CUDAHOSTCXX}" CACHE FILEPATH "Host side compiler used by NVCC") +elseif(CMAKE_GENERATOR MATCHES "Visual Studio") set(_CUDA_MSVC_HOST_COMPILER "$(VCInstallDir)Tools/MSVC/$(VCToolsVersion)/bin/Host$(Platform)/$(PlatformTarget)") if(MSVC_VERSION LESS 1910) set(_CUDA_MSVC_HOST_COMPILER "$(VCInstallDir)bin") ----------------------------------------------------------------------- Summary of changes: Help/envvar/CUDAHOSTCXX.rst | 4 + Help/manual/cmake-policies.7.rst | 1 + Help/policy/CMP0080.rst | 25 ++ Help/release/dev/bundleutilities-policy.rst | 5 + Modules/BundleUtilities.cmake | 453 +++++++++++---------- Modules/FindCUDA.cmake | 6 +- Modules/FindCUDA/select_compute_arch.cmake | 3 + Source/cmPolicies.h | 5 +- .../RunCMake/BundleUtilities/CMP0080-COMMAND.cmake | 5 + .../CMP0080-NEW-result.txt} | 0 .../BundleUtilities/CMP0080-NEW-stderr.txt | 2 + Tests/RunCMake/BundleUtilities/CMP0080-NEW.cmake | 2 + Tests/RunCMake/BundleUtilities/CMP0080-OLD.cmake | 2 + .../BundleUtilities/CMP0080-WARN-stderr.txt | 4 + Tests/RunCMake/BundleUtilities/CMP0080-WARN.cmake | 1 + .../{install => BundleUtilities}/CMakeLists.txt | 0 Tests/RunCMake/BundleUtilities/RunCMakeTest.cmake | 11 + Tests/RunCMake/CMakeLists.txt | 1 + Utilities/Release/win32_release.cmake | 2 +- Utilities/Release/win64_release.cmake | 2 +- 20 files changed, 313 insertions(+), 221 deletions(-) create mode 100644 Help/policy/CMP0080.rst create mode 100644 Help/release/dev/bundleutilities-policy.rst create mode 100644 Tests/RunCMake/BundleUtilities/CMP0080-COMMAND.cmake copy Tests/RunCMake/{while/MissingArgument-result.txt => BundleUtilities/CMP0080-NEW-result.txt} (100%) create mode 100644 Tests/RunCMake/BundleUtilities/CMP0080-NEW-stderr.txt create mode 100644 Tests/RunCMake/BundleUtilities/CMP0080-NEW.cmake create mode 100644 Tests/RunCMake/BundleUtilities/CMP0080-OLD.cmake create mode 100644 Tests/RunCMake/BundleUtilities/CMP0080-WARN-stderr.txt create mode 100644 Tests/RunCMake/BundleUtilities/CMP0080-WARN.cmake copy Tests/RunCMake/{install => BundleUtilities}/CMakeLists.txt (100%) create mode 100644 Tests/RunCMake/BundleUtilities/RunCMakeTest.cmake hooks/post-receive -- CMake From kwrobot at kitware.com Thu Sep 20 09:45:07 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Thu, 20 Sep 2018 09:45:07 -0400 (EDT) Subject: [Cmake-commits] CMake branch, release, updated. v3.12.2-10-g60e6e5d Message-ID: <20180920134507.051381217E6@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, release has been updated via 60e6e5db61d6f27814bb68dee1f497848e147ffb (commit) via cfe77802795699e829105346acc2d92c791f88fa (commit) from c1fd1607b8b2e879258f4257a86f9262ccd3d27c (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- ----------------------------------------------------------------------- Summary of changes: Help/prop_dir/TESTS.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) hooks/post-receive -- CMake From kwrobot at kitware.com Thu Sep 20 11:35:06 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Thu, 20 Sep 2018 11:35:06 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-698-gfe751ad Message-ID: <20180920153506.3EB4112535B@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via fe751ad1fb6b4c54f7662b01777142f2c598c958 (commit) via 0c709cb2a214ec37100d38f06e1bbf157d8c4cb8 (commit) from 3523990f7b96b0f25836cf319a7c8112c55e5acd (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=fe751ad1fb6b4c54f7662b01777142f2c598c958 commit fe751ad1fb6b4c54f7662b01777142f2c598c958 Merge: 3523990 0c709cb Author: Craig Scott AuthorDate: Thu Sep 20 15:30:14 2018 +0000 Commit: Kitware Robot CommitDate: Thu Sep 20 11:30:24 2018 -0400 Merge topic 'deprecate-policy-old' 0c709cb2a2 Add deprecation warnings for policies CMP0063 and below Acked-by: Kitware Robot Merge-request: !2397 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=0c709cb2a214ec37100d38f06e1bbf157d8c4cb8 commit 0c709cb2a214ec37100d38f06e1bbf157d8c4cb8 Author: Brad King AuthorDate: Mon Sep 17 06:47:46 2018 -0400 Commit: Brad King CommitDate: Mon Sep 17 14:16:48 2018 -0400 Add deprecation warnings for policies CMP0063 and below The OLD behaviors of all policies are deprecated, but only by documentation. Add an explicit deprecation diagnostic for some policies to encourage projects to port away from setting policies to OLD. diff --git a/Help/release/dev/deprecate-policy-old.rst b/Help/release/dev/deprecate-policy-old.rst new file mode 100644 index 0000000..7e9862f --- /dev/null +++ b/Help/release/dev/deprecate-policy-old.rst @@ -0,0 +1,8 @@ +deprecate-policy-old +-------------------- + +* An explicit deprecation diagnostic was added for policies ``CMP0055`` + through ``CMP0063`` (``CMP0054`` and below were already deprecated). + The :manual:`cmake-policies(7)` manual explains that the OLD behaviors + of all policies are deprecated and that projects should port to the + NEW behaviors. diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index fdcf0a8..6e646a8 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -4184,7 +4184,7 @@ bool cmMakefile::SetPolicy(cmPolicies::PolicyID id, // Deprecate old policies, especially those that require a lot // of code to maintain the old behavior. - if (status == cmPolicies::OLD && id <= cmPolicies::CMP0054) { + if (status == cmPolicies::OLD && id <= cmPolicies::CMP0063) { this->IssueMessage(cmake::DEPRECATION_WARNING, cmPolicies::GetPolicyDeprecatedWarning(id)); } diff --git a/Tests/RunCMake/CMP0055/CMP0055-OLD-Out-of-Scope-stderr.txt b/Tests/RunCMake/CMP0055/CMP0055-OLD-Out-of-Scope-stderr.txt new file mode 100644 index 0000000..d0a156c --- /dev/null +++ b/Tests/RunCMake/CMP0055/CMP0055-OLD-Out-of-Scope-stderr.txt @@ -0,0 +1,10 @@ +^CMake Deprecation Warning at CMP0055-OLD-Out-of-Scope.cmake:[0-9]+ \(cmake_policy\): + The OLD behavior for policy CMP0055 will be removed from a future version + of CMake. + + The cmake-policies\(7\) manual explains that the OLD behaviors of all + policies are deprecated and that a policy should be set to OLD only under + specific short-term circumstances. Projects should be ported to the NEW + behavior and not rely on setting a policy to OLD. +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/CMP0055/CMP0055-OLD-Reject-Arguments-stderr.txt b/Tests/RunCMake/CMP0055/CMP0055-OLD-Reject-Arguments-stderr.txt new file mode 100644 index 0000000..937b352 --- /dev/null +++ b/Tests/RunCMake/CMP0055/CMP0055-OLD-Reject-Arguments-stderr.txt @@ -0,0 +1,10 @@ +^CMake Deprecation Warning at CMP0055-OLD-Reject-Arguments.cmake:[0-9]+ \(cmake_policy\): + The OLD behavior for policy CMP0055 will be removed from a future version + of CMake. + + The cmake-policies\(7\) manual explains that the OLD behaviors of all + policies are deprecated and that a policy should be set to OLD only under + specific short-term circumstances. Projects should be ported to the NEW + behavior and not rely on setting a policy to OLD. +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/CMP0060/CMP0060-OLD-stderr.txt b/Tests/RunCMake/CMP0060/CMP0060-OLD-stderr.txt new file mode 100644 index 0000000..4658747 --- /dev/null +++ b/Tests/RunCMake/CMP0060/CMP0060-OLD-stderr.txt @@ -0,0 +1,10 @@ +^CMake Deprecation Warning at CMP0060-OLD.cmake:[0-9]+ \(cmake_policy\): + The OLD behavior for policy CMP0060 will be removed from a future version + of CMake. + + The cmake-policies\(7\) manual explains that the OLD behaviors of all + policies are deprecated and that a policy should be set to OLD only under + specific short-term circumstances. Projects should be ported to the NEW + behavior and not rely on setting a policy to OLD. +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/Ninja/CMP0058-OLD-by-stderr.txt b/Tests/RunCMake/Ninja/CMP0058-OLD-by-stderr.txt new file mode 100644 index 0000000..9a606ee --- /dev/null +++ b/Tests/RunCMake/Ninja/CMP0058-OLD-by-stderr.txt @@ -0,0 +1,10 @@ +^CMake Deprecation Warning at CMP0058-OLD-by.cmake:[0-9]+ \(cmake_policy\): + The OLD behavior for policy CMP0058 will be removed from a future version + of CMake. + + The cmake-policies\(7\) manual explains that the OLD behaviors of all + policies are deprecated and that a policy should be set to OLD only under + specific short-term circumstances. Projects should be ported to the NEW + behavior and not rely on setting a policy to OLD. +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/Ninja/CMP0058-OLD-no-stderr.txt b/Tests/RunCMake/Ninja/CMP0058-OLD-no-stderr.txt new file mode 100644 index 0000000..ba6e5da --- /dev/null +++ b/Tests/RunCMake/Ninja/CMP0058-OLD-no-stderr.txt @@ -0,0 +1,10 @@ +^CMake Deprecation Warning at CMP0058-OLD-no.cmake:[0-9]+ \(cmake_policy\): + The OLD behavior for policy CMP0058 will be removed from a future version + of CMake. + + The cmake-policies\(7\) manual explains that the OLD behaviors of all + policies are deprecated and that a policy should be set to OLD only under + specific short-term circumstances. Projects should be ported to the NEW + behavior and not rely on setting a policy to OLD. +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/VisibilityPreset/CMP0063-OLD-stderr.txt b/Tests/RunCMake/VisibilityPreset/CMP0063-OLD-stderr.txt new file mode 100644 index 0000000..34ac57d --- /dev/null +++ b/Tests/RunCMake/VisibilityPreset/CMP0063-OLD-stderr.txt @@ -0,0 +1,10 @@ +^CMake Deprecation Warning at CMP0063-OLD.cmake:[0-9]+ \(cmake_policy\): + The OLD behavior for policy CMP0063 will be removed from a future version + of CMake. + + The cmake-policies\(7\) manual explains that the OLD behaviors of all + policies are deprecated and that a policy should be set to OLD only under + specific short-term circumstances. Projects should be ported to the NEW + behavior and not rely on setting a policy to OLD. +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/build_command/CMP0061-OLD-make-stderr.txt b/Tests/RunCMake/build_command/CMP0061-OLD-make-stderr.txt index 28e0e72..1938da3 100644 --- a/Tests/RunCMake/build_command/CMP0061-OLD-make-stderr.txt +++ b/Tests/RunCMake/build_command/CMP0061-OLD-make-stderr.txt @@ -1,4 +1,15 @@ -^[^ +^CMake Deprecation Warning at CMP0061-OLD-make.cmake:[0-9]+ \(cmake_policy\): + The OLD behavior for policy CMP0061 will be removed from a future version + of CMake. + + The cmake-policies\(7\) manual explains that the OLD behaviors of all + policies are deprecated and that a policy should be set to OLD only under + specific short-term circumstances. Projects should be ported to the NEW + behavior and not rely on setting a policy to OLD. +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\) ++ +[^ ]+ --build \. --config "Release" -- -i [^ ]+ --build \. --config "Release" --target "MyTarget" -- -i diff --git a/Tests/RunCMake/build_command/CMP0061-OLD-other-stderr.txt b/Tests/RunCMake/build_command/CMP0061-OLD-other-stderr.txt index 1dde843..85bbdf1 100644 --- a/Tests/RunCMake/build_command/CMP0061-OLD-other-stderr.txt +++ b/Tests/RunCMake/build_command/CMP0061-OLD-other-stderr.txt @@ -1,4 +1,15 @@ -^[^ +^CMake Deprecation Warning at CMP0061-OLD-other.cmake:[0-9]+ \(cmake_policy\): + The OLD behavior for policy CMP0061 will be removed from a future version + of CMake. + + The cmake-policies\(7\) manual explains that the OLD behaviors of all + policies are deprecated and that a policy should be set to OLD only under + specific short-term circumstances. Projects should be ported to the NEW + behavior and not rely on setting a policy to OLD. +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\) ++ +[^ ]+ --build \. --config "Release" [^ ]+ --build \. --config "Release" --target "MyTarget" diff --git a/Tests/RunCMake/install/CMP0062-OLD-stderr.txt b/Tests/RunCMake/install/CMP0062-OLD-stderr.txt new file mode 100644 index 0000000..de0b70f --- /dev/null +++ b/Tests/RunCMake/install/CMP0062-OLD-stderr.txt @@ -0,0 +1,10 @@ +^CMake Deprecation Warning at CMP0062-OLD.cmake:[0-9]+ \(cmake_policy\): + The OLD behavior for policy CMP0062 will be removed from a future version + of CMake. + + The cmake-policies\(7\) manual explains that the OLD behaviors of all + policies are deprecated and that a policy should be set to OLD only under + specific short-term circumstances. Projects should be ported to the NEW + behavior and not rely on setting a policy to OLD. +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/try_compile/CMP0056-stderr.txt b/Tests/RunCMake/try_compile/CMP0056-stderr.txt index 5c1f0e4..de44205 100644 --- a/Tests/RunCMake/try_compile/CMP0056-stderr.txt +++ b/Tests/RunCMake/try_compile/CMP0056-stderr.txt @@ -10,4 +10,15 @@ CMake Warning \(dev\) at CMP0056.cmake:[0-9]+ \(try_compile\): caller link flags \(e.g. CMAKE_EXE_LINKER_FLAGS\) in the test project. Call Stack \(most recent call first\): CMakeLists.txt:[0-9]+ \(include\) -This warning is for project developers. Use -Wno-dev to suppress it.$ +This warning is for project developers. Use -Wno-dev to suppress it. + +CMake Deprecation Warning at CMP0056.cmake:[0-9]+ \(cmake_policy\): + The OLD behavior for policy CMP0056 will be removed from a future version + of CMake. + + The cmake-policies\(7\) manual explains that the OLD behaviors of all + policies are deprecated and that a policy should be set to OLD only under + specific short-term circumstances. Projects should be ported to the NEW + behavior and not rely on setting a policy to OLD. +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\)$ ----------------------------------------------------------------------- Summary of changes: Help/release/dev/deprecate-policy-old.rst | 8 ++++++++ Source/cmMakefile.cxx | 2 +- .../CMP0055-OLD-Out-of-Scope-stderr.txt} | 4 ++-- .../CMP0055-OLD-Reject-Arguments-stderr.txt} | 4 ++-- .../CMP0060-OLD-stderr.txt} | 4 ++-- .../CMP0058-OLD-by-stderr.txt} | 4 ++-- .../CMP0058-OLD-no-stderr.txt} | 4 ++-- .../CMP0063-OLD-stderr.txt} | 4 ++-- Tests/RunCMake/build_command/CMP0061-OLD-make-stderr.txt | 13 ++++++++++++- Tests/RunCMake/build_command/CMP0061-OLD-other-stderr.txt | 13 ++++++++++++- .../CMP0062-OLD-stderr.txt} | 4 ++-- Tests/RunCMake/try_compile/CMP0056-stderr.txt | 13 ++++++++++++- 12 files changed, 59 insertions(+), 18 deletions(-) create mode 100644 Help/release/dev/deprecate-policy-old.rst copy Tests/RunCMake/{CMP0026/clear-cached-information-stderr.txt => CMP0055/CMP0055-OLD-Out-of-Scope-stderr.txt} (75%) copy Tests/RunCMake/{CMP0026/CMP0026-CONFIG-LOCATION-OLD-stderr.txt => CMP0055/CMP0055-OLD-Reject-Arguments-stderr.txt} (70%) copy Tests/RunCMake/{CMP0028/CMP0028-OLD-stderr.txt => CMP0060/CMP0060-OLD-stderr.txt} (75%) copy Tests/RunCMake/{CMP0028/CMP0028-OLD-stderr.txt => Ninja/CMP0058-OLD-by-stderr.txt} (72%) copy Tests/RunCMake/{CMP0028/CMP0028-OLD-stderr.txt => Ninja/CMP0058-OLD-no-stderr.txt} (72%) copy Tests/RunCMake/{CMP0026/CMP0026-OLD-stderr.txt => VisibilityPreset/CMP0063-OLD-stderr.txt} (75%) copy Tests/RunCMake/{CMP0028/CMP0028-OLD-stderr.txt => install/CMP0062-OLD-stderr.txt} (75%) hooks/post-receive -- CMake From kwrobot at kitware.com Fri Sep 21 00:05:10 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Fri, 21 Sep 2018 00:05:10 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-699-g227b2be Message-ID: <20180921040511.BA61E125597@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 227b2be9d6a77efd95c4e99aab8e6255cb95a380 (commit) from fe751ad1fb6b4c54f7662b01777142f2c598c958 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=227b2be9d6a77efd95c4e99aab8e6255cb95a380 commit 227b2be9d6a77efd95c4e99aab8e6255cb95a380 Author: Kitware Robot AuthorDate: Fri Sep 21 00:01:09 2018 -0400 Commit: Kitware Robot CommitDate: Fri Sep 21 00:01:09 2018 -0400 CMake Nightly Date Stamp diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index cb0833f..22d519f 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 12) -set(CMake_VERSION_PATCH 20180920) +set(CMake_VERSION_PATCH 20180921) #set(CMake_VERSION_RC 1) ----------------------------------------------------------------------- Summary of changes: Source/CMakeVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) hooks/post-receive -- CMake From kwrobot at kitware.com Sat Sep 22 00:05:09 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Sat, 22 Sep 2018 00:05:09 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-700-gaa4d3e1 Message-ID: <20180922040509.5D0B5125328@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via aa4d3e18d28ef7fec017738970f57793ef313f82 (commit) from 227b2be9d6a77efd95c4e99aab8e6255cb95a380 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=aa4d3e18d28ef7fec017738970f57793ef313f82 commit aa4d3e18d28ef7fec017738970f57793ef313f82 Author: Kitware Robot AuthorDate: Sat Sep 22 00:01:10 2018 -0400 Commit: Kitware Robot CommitDate: Sat Sep 22 00:01:10 2018 -0400 CMake Nightly Date Stamp diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 22d519f..e022866 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 12) -set(CMake_VERSION_PATCH 20180921) +set(CMake_VERSION_PATCH 20180922) #set(CMake_VERSION_RC 1) ----------------------------------------------------------------------- Summary of changes: Source/CMakeVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) hooks/post-receive -- CMake From kwrobot at kitware.com Sun Sep 23 00:05:08 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Sun, 23 Sep 2018 00:05:08 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-701-gee4a56b Message-ID: <20180923040508.2BD5611ED8A@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via ee4a56bbdf40a9e1f5de33642463467c329ea076 (commit) from aa4d3e18d28ef7fec017738970f57793ef313f82 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=ee4a56bbdf40a9e1f5de33642463467c329ea076 commit ee4a56bbdf40a9e1f5de33642463467c329ea076 Author: Kitware Robot AuthorDate: Sun Sep 23 00:01:04 2018 -0400 Commit: Kitware Robot CommitDate: Sun Sep 23 00:01:04 2018 -0400 CMake Nightly Date Stamp diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index e022866..a0cc6dc 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 12) -set(CMake_VERSION_PATCH 20180922) +set(CMake_VERSION_PATCH 20180923) #set(CMake_VERSION_RC 1) ----------------------------------------------------------------------- Summary of changes: Source/CMakeVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) hooks/post-receive -- CMake From kwrobot at kitware.com Mon Sep 24 00:05:04 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Mon, 24 Sep 2018 00:05:04 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-702-ga7aef7a Message-ID: <20180924040504.A115B1252F5@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via a7aef7a1820b24050ecdc1acb02cf790c1d8e065 (commit) from ee4a56bbdf40a9e1f5de33642463467c329ea076 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=a7aef7a1820b24050ecdc1acb02cf790c1d8e065 commit a7aef7a1820b24050ecdc1acb02cf790c1d8e065 Author: Kitware Robot AuthorDate: Mon Sep 24 00:01:07 2018 -0400 Commit: Kitware Robot CommitDate: Mon Sep 24 00:01:07 2018 -0400 CMake Nightly Date Stamp diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index a0cc6dc..2dab997 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 12) -set(CMake_VERSION_PATCH 20180923) +set(CMake_VERSION_PATCH 20180924) #set(CMake_VERSION_RC 1) ----------------------------------------------------------------------- Summary of changes: Source/CMakeVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) hooks/post-receive -- CMake From kwrobot at kitware.com Mon Sep 24 07:15:06 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Mon, 24 Sep 2018 07:15:06 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-708-g03ffd44 Message-ID: <20180924111506.9A154107A19@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 03ffd442bd34e2a3478b125ef1055837926bcd0c (commit) via 72b4c2c48ae7dfd8c2813018c72ed0d2e6bb907a (commit) via b48165346f7dfcd025beca743abf2eaf849bf17d (commit) via 85be67217bea4f1f655b16fdd6ac938800a96326 (commit) via aabce528519eaa1db64fb4eef48e12669b028f05 (commit) via fc43492e44c67ed73a6483a4cd587eae02657949 (commit) from a7aef7a1820b24050ecdc1acb02cf790c1d8e065 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=03ffd442bd34e2a3478b125ef1055837926bcd0c commit 03ffd442bd34e2a3478b125ef1055837926bcd0c Merge: a7aef7a 72b4c2c Author: Brad King AuthorDate: Mon Sep 24 11:07:30 2018 +0000 Commit: Kitware Robot CommitDate: Mon Sep 24 07:07:38 2018 -0400 Merge topic 'server-separate-json' 72b4c2c48a server: Compile json object generation source separately b48165346f server: Split json dictionary into separate header 85be67217b server: Split json object generation into separate source aabce52851 server: factor out json object generation entry points fc43492e44 cmake: Factor json version object construction into helper Acked-by: Kitware Robot Merge-request: !2408 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=72b4c2c48ae7dfd8c2813018c72ed0d2e6bb907a commit 72b4c2c48ae7dfd8c2813018c72ed0d2e6bb907a Author: Brad King AuthorDate: Fri Sep 21 11:11:36 2018 -0400 Commit: Brad King CommitDate: Fri Sep 21 11:39:59 2018 -0400 server: Compile json object generation source separately Declare entry points in a dedicated header and compile the source separately instead of including it in the server implementation. diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 628cc6f..bfddbc6 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -1047,6 +1047,9 @@ target_link_libraries(cmake CMakeLib) add_library(CMakeServerLib cmConnection.h cmConnection.cxx cmFileMonitor.cxx cmFileMonitor.h + cmJsonObjectDictionary.h + cmJsonObjects.h + cmJsonObjects.cxx cmPipeConnection.cxx cmPipeConnection.h cmServer.cxx cmServer.h cmServerConnection.cxx cmServerConnection.h diff --git a/Source/cmJsonObjects.cxx b/Source/cmJsonObjects.cxx index b534471..a7db75f 100644 --- a/Source/cmJsonObjects.cxx +++ b/Source/cmJsonObjects.cxx @@ -1,11 +1,14 @@ /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmJsonObjects.h" // IWYU pragma: keep #include "cmGeneratorExpression.h" #include "cmGeneratorTarget.h" #include "cmGlobalGenerator.h" #include "cmInstallGenerator.h" #include "cmInstallTargetGenerator.h" +#include "cmJsonObjectDictionary.h" +#include "cmJsonObjects.h" #include "cmLinkLineComputer.h" #include "cmLocalGenerator.h" #include "cmMakefile.h" @@ -66,11 +69,14 @@ Json::Value fromStringList(const T& in) return result; } -void getCMakeInputs(const cmGlobalGenerator* gg, const std::string& sourceDir, - const std::string& buildDir, - std::vector* internalFiles, - std::vector* explicitFiles, - std::vector* tmpFiles) +} // namespace + +void cmGetCMakeInputs(const cmGlobalGenerator* gg, + const std::string& sourceDir, + const std::string& buildDir, + std::vector* internalFiles, + std::vector* explicitFiles, + std::vector* tmpFiles) { const std::string cmakeRootDir = cmSystemTools::GetCMakeRoot() + '/'; std::vector const& makefiles = gg->GetMakefiles(); @@ -109,9 +115,7 @@ void getCMakeInputs(const cmGlobalGenerator* gg, const std::string& sourceDir, } } -} // namespace - -static Json::Value DumpCMakeInputs(const cmake* cm) +Json::Value cmDumpCMakeInputs(const cmake* cm) { const cmGlobalGenerator* gg = cm->GetGlobalGenerator(); const std::string& buildDir = cm->GetHomeOutputDirectory(); @@ -120,8 +124,8 @@ static Json::Value DumpCMakeInputs(const cmake* cm) std::vector internalFiles; std::vector explicitFiles; std::vector tmpFiles; - getCMakeInputs(gg, sourceDir, buildDir, &internalFiles, &explicitFiles, - &tmpFiles); + cmGetCMakeInputs(gg, sourceDir, buildDir, &internalFiles, &explicitFiles, + &tmpFiles); Json::Value array = Json::arrayValue; @@ -506,7 +510,7 @@ static Json::Value DumpCTestConfigurationsList(const cmake* cm) return result; } -static Json::Value DumpCTestInfo(const cmake* cm) +Json::Value cmDumpCTestInfo(const cmake* cm) { Json::Value result = Json::objectValue; result[kCONFIGURATIONS_KEY] = DumpCTestConfigurationsList(cm); @@ -811,7 +815,7 @@ static Json::Value DumpConfigurationsList(const cmake* cm) return result; } -static Json::Value DumpCodeModel(const cmake* cm) +Json::Value cmDumpCodeModel(const cmake* cm) { Json::Value result = Json::objectValue; result[kCONFIGURATIONS_KEY] = DumpConfigurationsList(cm); diff --git a/Source/cmJsonObjects.h b/Source/cmJsonObjects.h new file mode 100644 index 0000000..cd4da94 --- /dev/null +++ b/Source/cmJsonObjects.h @@ -0,0 +1,27 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmJsonObjects_h +#define cmJsonObjects_h + +#include "cmConfigure.h" // IWYU pragma: keep + +#include "cm_jsoncpp_value.h" + +#include +#include + +class cmake; +class cmGlobalGenerator; + +extern void cmGetCMakeInputs(const cmGlobalGenerator* gg, + const std::string& sourceDir, + const std::string& buildDir, + std::vector* internalFiles, + std::vector* explicitFiles, + std::vector* tmpFiles); + +extern Json::Value cmDumpCodeModel(const cmake* cm); +extern Json::Value cmDumpCTestInfo(const cmake* cm); +extern Json::Value cmDumpCMakeInputs(const cmake* cm); + +#endif diff --git a/Source/cmServerProtocol.cxx b/Source/cmServerProtocol.cxx index 6a09776..f75a5ce 100644 --- a/Source/cmServerProtocol.cxx +++ b/Source/cmServerProtocol.cxx @@ -7,6 +7,7 @@ #include "cmFileMonitor.h" #include "cmGlobalGenerator.h" #include "cmJsonObjectDictionary.h" +#include "cmJsonObjects.h" #include "cmServer.h" #include "cmServerDictionary.h" #include "cmState.h" @@ -37,8 +38,6 @@ std::vector toStringList(const Json::Value& in) } // namespace -#include "cmJsonObjects.cxx" - cmServerRequest::cmServerRequest(cmServer* server, cmConnection* connection, const std::string& t, const std::string& c, const Json::Value& d) @@ -473,7 +472,7 @@ cmServerResponse cmServerProtocol1::ProcessCMakeInputs( Json::Value result = Json::objectValue; result[kSOURCE_DIRECTORY_KEY] = sourceDir; result[kCMAKE_ROOT_DIRECTORY_KEY] = cmakeRootDir; - result[kBUILD_FILES_KEY] = DumpCMakeInputs(cm); + result[kBUILD_FILES_KEY] = cmDumpCMakeInputs(cm); return request.Reply(result); } @@ -484,7 +483,7 @@ cmServerResponse cmServerProtocol1::ProcessCodeModel( return request.ReportError("No build system was generated yet."); } - return request.Reply(DumpCodeModel(this->CMakeInstance())); + return request.Reply(cmDumpCodeModel(this->CMakeInstance())); } cmServerResponse cmServerProtocol1::ProcessCompute( @@ -601,7 +600,8 @@ cmServerResponse cmServerProtocol1::ProcessConfigure( } std::vector toWatchList; - getCMakeInputs(gg, std::string(), buildDir, nullptr, &toWatchList, nullptr); + cmGetCMakeInputs(gg, std::string(), buildDir, nullptr, &toWatchList, + nullptr); FileMonitor()->MonitorPaths(toWatchList, [this](const std::string& p, int e, int s) { @@ -707,7 +707,7 @@ cmServerResponse cmServerProtocol1::ProcessCTests( return request.ReportError("This instance was not yet computed."); } - return request.Reply(DumpCTestInfo(this->CMakeInstance())); + return request.Reply(cmDumpCTestInfo(this->CMakeInstance())); } cmServerProtocol1::GeneratorInformation::GeneratorInformation( https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=b48165346f7dfcd025beca743abf2eaf849bf17d commit b48165346f7dfcd025beca743abf2eaf849bf17d Author: Brad King AuthorDate: Fri Sep 21 11:21:37 2018 -0400 Commit: Brad King CommitDate: Fri Sep 21 11:39:21 2018 -0400 server: Split json dictionary into separate header Move dictionary entries used by the json object generation code into a separate header. These are distinct from the server-only entries used in the protocol implementation. diff --git a/Source/cmJsonObjectDictionary.h b/Source/cmJsonObjectDictionary.h new file mode 100644 index 0000000..a4d41f3 --- /dev/null +++ b/Source/cmJsonObjectDictionary.h @@ -0,0 +1,46 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#pragma once + +#include + +// Vocabulary: + +static const std::string kARTIFACTS_KEY = "artifacts"; +static const std::string kBUILD_DIRECTORY_KEY = "buildDirectory"; +static const std::string kCOMPILE_FLAGS_KEY = "compileFlags"; +static const std::string kCONFIGURATIONS_KEY = "configurations"; +static const std::string kDEFINES_KEY = "defines"; +static const std::string kFILE_GROUPS_KEY = "fileGroups"; +static const std::string kFRAMEWORK_PATH_KEY = "frameworkPath"; +static const std::string kFULL_NAME_KEY = "fullName"; +static const std::string kINCLUDE_PATH_KEY = "includePath"; +static const std::string kIS_CMAKE_KEY = "isCMake"; +static const std::string kIS_GENERATED_KEY = "isGenerated"; +static const std::string kIS_SYSTEM_KEY = "isSystem"; +static const std::string kIS_TEMPORARY_KEY = "isTemporary"; +static const std::string kKEY_KEY = "key"; +static const std::string kLANGUAGE_KEY = "language"; +static const std::string kLINKER_LANGUAGE_KEY = "linkerLanguage"; +static const std::string kLINK_FLAGS_KEY = "linkFlags"; +static const std::string kLINK_LANGUAGE_FLAGS_KEY = "linkLanguageFlags"; +static const std::string kLINK_LIBRARIES_KEY = "linkLibraries"; +static const std::string kLINK_PATH_KEY = "linkPath"; +static const std::string kNAME_KEY = "name"; +static const std::string kPATH_KEY = "path"; +static const std::string kPROJECTS_KEY = "projects"; +static const std::string kPROPERTIES_KEY = "properties"; +static const std::string kSOURCE_DIRECTORY_KEY = "sourceDirectory"; +static const std::string kSOURCES_KEY = "sources"; +static const std::string kSYSROOT_KEY = "sysroot"; +static const std::string kTARGETS_KEY = "targets"; +static const std::string kTYPE_KEY = "type"; +static const std::string kVALUE_KEY = "value"; +static const std::string kHAS_INSTALL_RULE = "hasInstallRule"; +static const std::string kINSTALL_PATHS = "installPaths"; +static const std::string kCTEST_NAME = "ctestName"; +static const std::string kCTEST_COMMAND = "ctestCommand"; +static const std::string kCTEST_INFO = "ctestInfo"; +static const std::string kMINIMUM_CMAKE_VERSION = "minimumCMakeVersion"; +static const std::string kIS_GENERATOR_PROVIDED_KEY = "isGeneratorProvided"; +static const std::string kIS_INTERFACE_SOURCES_KEY = "isInterfaceSources"; diff --git a/Source/cmServer.cxx b/Source/cmServer.cxx index 1b04ca2..f15a14a 100644 --- a/Source/cmServer.cxx +++ b/Source/cmServer.cxx @@ -5,6 +5,7 @@ #include "cmAlgorithms.h" #include "cmConnection.h" #include "cmFileMonitor.h" +#include "cmJsonObjectDictionary.h" #include "cmServerDictionary.h" #include "cmServerProtocol.h" #include "cmSystemTools.h" diff --git a/Source/cmServerDictionary.h b/Source/cmServerDictionary.h index ebf16eb..961e4b7 100644 --- a/Source/cmServerDictionary.h +++ b/Source/cmServerDictionary.h @@ -25,78 +25,40 @@ static const std::string kSET_GLOBAL_SETTINGS_TYPE = "setGlobalSettings"; static const std::string kSIGNAL_TYPE = "signal"; static const std::string kCTEST_INFO_TYPE = "ctestInfo"; -static const std::string kARTIFACTS_KEY = "artifacts"; -static const std::string kBUILD_DIRECTORY_KEY = "buildDirectory"; static const std::string kBUILD_FILES_KEY = "buildFiles"; static const std::string kCACHE_ARGUMENTS_KEY = "cacheArguments"; static const std::string kCACHE_KEY = "cache"; static const std::string kCAPABILITIES_KEY = "capabilities"; static const std::string kCHECK_SYSTEM_VARS_KEY = "checkSystemVars"; static const std::string kCMAKE_ROOT_DIRECTORY_KEY = "cmakeRootDirectory"; -static const std::string kCOMPILE_FLAGS_KEY = "compileFlags"; -static const std::string kCONFIGURATIONS_KEY = "configurations"; static const std::string kCOOKIE_KEY = "cookie"; static const std::string kDEBUG_OUTPUT_KEY = "debugOutput"; -static const std::string kDEFINES_KEY = "defines"; static const std::string kERROR_MESSAGE_KEY = "errorMessage"; static const std::string kEXTRA_GENERATOR_KEY = "extraGenerator"; -static const std::string kFILE_GROUPS_KEY = "fileGroups"; -static const std::string kFRAMEWORK_PATH_KEY = "frameworkPath"; -static const std::string kFULL_NAME_KEY = "fullName"; static const std::string kGENERATOR_KEY = "generator"; -static const std::string kINCLUDE_PATH_KEY = "includePath"; -static const std::string kIS_CMAKE_KEY = "isCMake"; static const std::string kIS_EXPERIMENTAL_KEY = "isExperimental"; -static const std::string kIS_GENERATED_KEY = "isGenerated"; -static const std::string kIS_SYSTEM_KEY = "isSystem"; -static const std::string kIS_TEMPORARY_KEY = "isTemporary"; -static const std::string kKEY_KEY = "key"; static const std::string kKEYS_KEY = "keys"; -static const std::string kLANGUAGE_KEY = "language"; -static const std::string kLINKER_LANGUAGE_KEY = "linkerLanguage"; -static const std::string kLINK_FLAGS_KEY = "linkFlags"; -static const std::string kLINK_LANGUAGE_FLAGS_KEY = "linkLanguageFlags"; -static const std::string kLINK_LIBRARIES_KEY = "linkLibraries"; -static const std::string kLINK_PATH_KEY = "linkPath"; static const std::string kMAJOR_KEY = "major"; static const std::string kMESSAGE_KEY = "message"; static const std::string kMINOR_KEY = "minor"; -static const std::string kNAME_KEY = "name"; -static const std::string kPATH_KEY = "path"; static const std::string kPLATFORM_KEY = "platform"; static const std::string kPROGRESS_CURRENT_KEY = "progressCurrent"; static const std::string kPROGRESS_MAXIMUM_KEY = "progressMaximum"; static const std::string kPROGRESS_MESSAGE_KEY = "progressMessage"; static const std::string kPROGRESS_MINIMUM_KEY = "progressMinimum"; -static const std::string kPROJECTS_KEY = "projects"; -static const std::string kPROPERTIES_KEY = "properties"; static const std::string kPROTOCOL_VERSION_KEY = "protocolVersion"; static const std::string kREPLY_TO_KEY = "inReplyTo"; -static const std::string kSOURCE_DIRECTORY_KEY = "sourceDirectory"; -static const std::string kSOURCES_KEY = "sources"; static const std::string kSUPPORTED_PROTOCOL_VERSIONS = "supportedProtocolVersions"; -static const std::string kSYSROOT_KEY = "sysroot"; -static const std::string kTARGETS_KEY = "targets"; static const std::string kTITLE_KEY = "title"; static const std::string kTOOLSET_KEY = "toolset"; static const std::string kTRACE_EXPAND_KEY = "traceExpand"; static const std::string kTRACE_KEY = "trace"; -static const std::string kTYPE_KEY = "type"; -static const std::string kVALUE_KEY = "value"; static const std::string kWARN_UNINITIALIZED_KEY = "warnUninitialized"; static const std::string kWARN_UNUSED_CLI_KEY = "warnUnusedCli"; static const std::string kWARN_UNUSED_KEY = "warnUnused"; static const std::string kWATCHED_DIRECTORIES_KEY = "watchedDirectories"; static const std::string kWATCHED_FILES_KEY = "watchedFiles"; -static const std::string kHAS_INSTALL_RULE = "hasInstallRule"; -static const std::string kINSTALL_PATHS = "installPaths"; -static const std::string kCTEST_NAME = "ctestName"; -static const std::string kCTEST_COMMAND = "ctestCommand"; -static const std::string kCTEST_INFO = "ctestInfo"; -static const std::string kMINIMUM_CMAKE_VERSION = "minimumCMakeVersion"; -static const std::string kIS_GENERATOR_PROVIDED_KEY = "isGeneratorProvided"; -static const std::string kIS_INTERFACE_SOURCES_KEY = "isInterfaceSources"; static const std::string kSTART_MAGIC = "[== \"CMake Server\" ==["; static const std::string kEND_MAGIC = "]== \"CMake Server\" ==]"; diff --git a/Source/cmServerProtocol.cxx b/Source/cmServerProtocol.cxx index 5d29bf8..6a09776 100644 --- a/Source/cmServerProtocol.cxx +++ b/Source/cmServerProtocol.cxx @@ -6,6 +6,7 @@ #include "cmExternalMakefileProjectGenerator.h" #include "cmFileMonitor.h" #include "cmGlobalGenerator.h" +#include "cmJsonObjectDictionary.h" #include "cmServer.h" #include "cmServerDictionary.h" #include "cmState.h" https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=85be67217bea4f1f655b16fdd6ac938800a96326 commit 85be67217bea4f1f655b16fdd6ac938800a96326 Author: Brad King AuthorDate: Fri Sep 21 09:59:04 2018 -0400 Commit: Brad King CommitDate: Fri Sep 21 11:39:21 2018 -0400 server: Split json object generation into separate source For now just move the content and `#include` it back in to the original translation unit. That way `git blame` can cleanly track the original lines. diff --git a/Source/cmServerProtocol.cxx b/Source/cmJsonObjects.cxx similarity index 53% copy from Source/cmServerProtocol.cxx copy to Source/cmJsonObjects.cxx index 266d05c..b534471 100644 --- a/Source/cmServerProtocol.cxx +++ b/Source/cmJsonObjects.cxx @@ -1,10 +1,6 @@ /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying file Copyright.txt or https://cmake.org/licensing for details. */ -#include "cmServerProtocol.h" -#include "cmAlgorithms.h" -#include "cmExternalMakefileProjectGenerator.h" -#include "cmFileMonitor.h" #include "cmGeneratorExpression.h" #include "cmGeneratorTarget.h" #include "cmGlobalGenerator.h" @@ -14,8 +10,6 @@ #include "cmLocalGenerator.h" #include "cmMakefile.h" #include "cmProperty.h" -#include "cmServer.h" -#include "cmServerDictionary.h" #include "cmSourceFile.h" #include "cmState.h" #include "cmStateDirectory.h" @@ -24,7 +18,6 @@ #include "cmSystemTools.h" #include "cmTarget.h" #include "cmTest.h" -#include "cm_uv.h" #include "cmake.h" #include @@ -33,15 +26,12 @@ #include #include #include -#include #include #include #include +#include #include -// Get rid of some windows macros: -#undef max - namespace { std::vector getConfigurations(const cmake* cm) @@ -76,15 +66,6 @@ Json::Value fromStringList(const T& in) return result; } -std::vector toStringList(const Json::Value& in) -{ - std::vector result; - for (auto const& it : in) { - result.push_back(it.asString()); - } - return result; -} - void getCMakeInputs(const cmGlobalGenerator* gg, const std::string& sourceDir, const std::string& buildDir, std::vector* internalFiles, @@ -130,426 +111,6 @@ void getCMakeInputs(const cmGlobalGenerator* gg, const std::string& sourceDir, } // namespace -cmServerRequest::cmServerRequest(cmServer* server, cmConnection* connection, - const std::string& t, const std::string& c, - const Json::Value& d) - : Type(t) - , Cookie(c) - , Data(d) - , Connection(connection) - , m_Server(server) -{ -} - -void cmServerRequest::ReportProgress(int min, int current, int max, - const std::string& message) const -{ - this->m_Server->WriteProgress(*this, min, current, max, message); -} - -void cmServerRequest::ReportMessage(const std::string& message, - const std::string& title) const -{ - m_Server->WriteMessage(*this, message, title); -} - -cmServerResponse cmServerRequest::Reply(const Json::Value& data) const -{ - cmServerResponse response(*this); - response.SetData(data); - return response; -} - -cmServerResponse cmServerRequest::ReportError(const std::string& message) const -{ - cmServerResponse response(*this); - response.SetError(message); - return response; -} - -cmServerResponse::cmServerResponse(const cmServerRequest& request) - : Type(request.Type) - , Cookie(request.Cookie) -{ -} - -void cmServerResponse::SetData(const Json::Value& data) -{ - assert(this->m_Payload == PAYLOAD_UNKNOWN); - if (!data[kCOOKIE_KEY].isNull() || !data[kTYPE_KEY].isNull()) { - this->SetError("Response contains cookie or type field."); - return; - } - this->m_Payload = PAYLOAD_DATA; - this->m_Data = data; -} - -void cmServerResponse::SetError(const std::string& message) -{ - assert(this->m_Payload == PAYLOAD_UNKNOWN); - this->m_Payload = PAYLOAD_ERROR; - this->m_ErrorMessage = message; -} - -bool cmServerResponse::IsComplete() const -{ - return this->m_Payload != PAYLOAD_UNKNOWN; -} - -bool cmServerResponse::IsError() const -{ - assert(this->m_Payload != PAYLOAD_UNKNOWN); - return this->m_Payload == PAYLOAD_ERROR; -} - -std::string cmServerResponse::ErrorMessage() const -{ - if (this->m_Payload == PAYLOAD_ERROR) { - return this->m_ErrorMessage; - } - return std::string(); -} - -Json::Value cmServerResponse::Data() const -{ - assert(this->m_Payload != PAYLOAD_UNKNOWN); - return this->m_Data; -} - -bool cmServerProtocol::Activate(cmServer* server, - const cmServerRequest& request, - std::string* errorMessage) -{ - assert(server); - this->m_Server = server; - this->m_CMakeInstance = cm::make_unique(cmake::RoleProject); - const bool result = this->DoActivate(request, errorMessage); - if (!result) { - this->m_CMakeInstance = nullptr; - } - return result; -} - -cmFileMonitor* cmServerProtocol::FileMonitor() const -{ - return this->m_Server ? this->m_Server->FileMonitor() : nullptr; -} - -void cmServerProtocol::SendSignal(const std::string& name, - const Json::Value& data) const -{ - if (this->m_Server) { - this->m_Server->WriteSignal(name, data); - } -} - -cmake* cmServerProtocol::CMakeInstance() const -{ - return this->m_CMakeInstance.get(); -} - -bool cmServerProtocol::DoActivate(const cmServerRequest& /*request*/, - std::string* /*errorMessage*/) -{ - return true; -} - -std::pair cmServerProtocol1::ProtocolVersion() const -{ - // Revision history - // 1, 1 - Report backtraces in codemodel response - // 1, 2 - Add target install destinations to codemodel - // 1, 3 - Add a flag to target filegroups indicating whether or not the - // filegroup is for INTERFACE_SOURCES - return std::make_pair(1, 3); -} - -static void setErrorMessage(std::string* errorMessage, const std::string& text) -{ - if (errorMessage) { - *errorMessage = text; - } -} - -static bool getOrTestHomeDirectory(cmState* state, std::string& value, - std::string* errorMessage) -{ - const std::string cachedValue = - std::string(state->GetCacheEntryValue("CMAKE_HOME_DIRECTORY")); - if (value.empty()) { - value = cachedValue; - return true; - } - const std::string suffix = "/CMakeLists.txt"; - const std::string cachedValueCML = cachedValue + suffix; - const std::string valueCML = value + suffix; - if (!cmSystemTools::SameFile(valueCML, cachedValueCML)) { - setErrorMessage(errorMessage, - std::string("\"CMAKE_HOME_DIRECTORY\" is set but " - "incompatible with configured " - "source directory value.")); - return false; - } - return true; -} - -static bool getOrTestValue(cmState* state, const std::string& key, - std::string& value, - const std::string& keyDescription, - std::string* errorMessage) -{ - const char* entry = state->GetCacheEntryValue(key); - const std::string cachedValue = - entry == nullptr ? std::string() : std::string(entry); - if (value.empty()) { - value = cachedValue; - } - if (!cachedValue.empty() && cachedValue != value) { - setErrorMessage(errorMessage, - std::string("\"") + key + - "\" is set but incompatible with configured " + - keyDescription + " value."); - return false; - } - return true; -} - -bool cmServerProtocol1::DoActivate(const cmServerRequest& request, - std::string* errorMessage) -{ - std::string sourceDirectory = request.Data[kSOURCE_DIRECTORY_KEY].asString(); - const std::string buildDirectory = - request.Data[kBUILD_DIRECTORY_KEY].asString(); - std::string generator = request.Data[kGENERATOR_KEY].asString(); - std::string extraGenerator = request.Data[kEXTRA_GENERATOR_KEY].asString(); - std::string toolset = request.Data[kTOOLSET_KEY].asString(); - std::string platform = request.Data[kPLATFORM_KEY].asString(); - - if (buildDirectory.empty()) { - setErrorMessage(errorMessage, - std::string("\"") + kBUILD_DIRECTORY_KEY + - "\" is missing."); - return false; - } - - cmake* cm = CMakeInstance(); - if (cmSystemTools::PathExists(buildDirectory)) { - if (!cmSystemTools::FileIsDirectory(buildDirectory)) { - setErrorMessage(errorMessage, - std::string("\"") + kBUILD_DIRECTORY_KEY + - "\" exists but is not a directory."); - return false; - } - - const std::string cachePath = cm->FindCacheFile(buildDirectory); - if (cm->LoadCache(cachePath)) { - cmState* state = cm->GetState(); - - // Check generator: - if (!getOrTestValue(state, "CMAKE_GENERATOR", generator, "generator", - errorMessage)) { - return false; - } - - // check extra generator: - if (!getOrTestValue(state, "CMAKE_EXTRA_GENERATOR", extraGenerator, - "extra generator", errorMessage)) { - return false; - } - - // check sourcedir: - if (!getOrTestHomeDirectory(state, sourceDirectory, errorMessage)) { - return false; - } - - // check toolset: - if (!getOrTestValue(state, "CMAKE_GENERATOR_TOOLSET", toolset, "toolset", - errorMessage)) { - return false; - } - - // check platform: - if (!getOrTestValue(state, "CMAKE_GENERATOR_PLATFORM", platform, - "platform", errorMessage)) { - return false; - } - } - } - - if (sourceDirectory.empty()) { - setErrorMessage(errorMessage, - std::string("\"") + kSOURCE_DIRECTORY_KEY + - "\" is unset but required."); - return false; - } - if (!cmSystemTools::FileIsDirectory(sourceDirectory)) { - setErrorMessage(errorMessage, - std::string("\"") + kSOURCE_DIRECTORY_KEY + - "\" is not a directory."); - return false; - } - if (generator.empty()) { - setErrorMessage(errorMessage, - std::string("\"") + kGENERATOR_KEY + - "\" is unset but required."); - return false; - } - - std::vector generators; - cm->GetRegisteredGenerators(generators); - auto baseIt = std::find_if(generators.begin(), generators.end(), - [&generator](const cmake::GeneratorInfo& info) { - return info.name == generator; - }); - if (baseIt == generators.end()) { - setErrorMessage(errorMessage, - std::string("Generator \"") + generator + - "\" not supported."); - return false; - } - auto extraIt = std::find_if( - generators.begin(), generators.end(), - [&generator, &extraGenerator](const cmake::GeneratorInfo& info) { - return info.baseName == generator && info.extraName == extraGenerator; - }); - if (extraIt == generators.end()) { - setErrorMessage(errorMessage, - std::string("The combination of generator \"" + generator + - "\" and extra generator \"" + extraGenerator + - "\" is not supported.")); - return false; - } - if (!extraIt->supportsToolset && !toolset.empty()) { - setErrorMessage(errorMessage, - std::string("Toolset was provided but is not supported by " - "the requested generator.")); - return false; - } - if (!extraIt->supportsPlatform && !platform.empty()) { - setErrorMessage(errorMessage, - std::string("Platform was provided but is not supported " - "by the requested generator.")); - return false; - } - - this->GeneratorInfo = - GeneratorInformation(generator, extraGenerator, toolset, platform, - sourceDirectory, buildDirectory); - - this->m_State = STATE_ACTIVE; - return true; -} - -void cmServerProtocol1::HandleCMakeFileChanges(const std::string& path, - int event, int status) -{ - assert(status == 0); - static_cast(status); - - if (!m_isDirty) { - m_isDirty = true; - SendSignal(kDIRTY_SIGNAL, Json::objectValue); - } - Json::Value obj = Json::objectValue; - obj[kPATH_KEY] = path; - Json::Value properties = Json::arrayValue; - if (event & UV_RENAME) { - properties.append(kRENAME_PROPERTY_VALUE); - } - if (event & UV_CHANGE) { - properties.append(kCHANGE_PROPERTY_VALUE); - } - - obj[kPROPERTIES_KEY] = properties; - SendSignal(kFILE_CHANGE_SIGNAL, obj); -} - -const cmServerResponse cmServerProtocol1::Process( - const cmServerRequest& request) -{ - assert(this->m_State >= STATE_ACTIVE); - - if (request.Type == kCACHE_TYPE) { - return this->ProcessCache(request); - } - if (request.Type == kCMAKE_INPUTS_TYPE) { - return this->ProcessCMakeInputs(request); - } - if (request.Type == kCODE_MODEL_TYPE) { - return this->ProcessCodeModel(request); - } - if (request.Type == kCOMPUTE_TYPE) { - return this->ProcessCompute(request); - } - if (request.Type == kCONFIGURE_TYPE) { - return this->ProcessConfigure(request); - } - if (request.Type == kFILESYSTEM_WATCHERS_TYPE) { - return this->ProcessFileSystemWatchers(request); - } - if (request.Type == kGLOBAL_SETTINGS_TYPE) { - return this->ProcessGlobalSettings(request); - } - if (request.Type == kSET_GLOBAL_SETTINGS_TYPE) { - return this->ProcessSetGlobalSettings(request); - } - if (request.Type == kCTEST_INFO_TYPE) { - return this->ProcessCTests(request); - } - - return request.ReportError("Unknown command!"); -} - -bool cmServerProtocol1::IsExperimental() const -{ - return true; -} - -cmServerResponse cmServerProtocol1::ProcessCache( - const cmServerRequest& request) -{ - cmState* state = this->CMakeInstance()->GetState(); - - Json::Value result = Json::objectValue; - - std::vector allKeys = state->GetCacheEntryKeys(); - - Json::Value list = Json::arrayValue; - std::vector keys = toStringList(request.Data[kKEYS_KEY]); - if (keys.empty()) { - keys = allKeys; - } else { - for (auto const& i : keys) { - if (std::find(allKeys.begin(), allKeys.end(), i) == allKeys.end()) { - return request.ReportError("Key \"" + i + "\" not found in cache."); - } - } - } - std::sort(keys.begin(), keys.end()); - for (auto const& key : keys) { - Json::Value entry = Json::objectValue; - entry[kKEY_KEY] = key; - entry[kTYPE_KEY] = - cmState::CacheEntryTypeToString(state->GetCacheEntryType(key)); - entry[kVALUE_KEY] = state->GetCacheEntryValue(key); - - Json::Value props = Json::objectValue; - bool haveProperties = false; - for (auto const& prop : state->GetCacheEntryPropertyList(key)) { - haveProperties = true; - props[prop] = state->GetCacheEntryProperty(key, prop); - } - if (haveProperties) { - entry[kPROPERTIES_KEY] = props; - } - - list.append(entry); - } - - result[kCACHE_KEY] = list; - return request.Reply(result); -} - static Json::Value DumpCMakeInputs(const cmake* cm) { const cmGlobalGenerator* gg = cm->GetGlobalGenerator(); @@ -585,24 +146,6 @@ static Json::Value DumpCMakeInputs(const cmake* cm) return array; } -cmServerResponse cmServerProtocol1::ProcessCMakeInputs( - const cmServerRequest& request) -{ - if (this->m_State < STATE_CONFIGURED) { - return request.ReportError("This instance was not yet configured."); - } - - const cmake* cm = this->CMakeInstance(); - const std::string cmakeRootDir = cmSystemTools::GetCMakeRoot(); - const std::string& sourceDir = cm->GetHomeDirectory(); - - Json::Value result = Json::objectValue; - result[kSOURCE_DIRECTORY_KEY] = sourceDir; - result[kCMAKE_ROOT_DIRECTORY_KEY] = cmakeRootDir; - result[kBUILD_FILES_KEY] = DumpCMakeInputs(cm); - return request.Reply(result); -} - const std::string kInterfaceSourcesLanguageDataKey = "INTERFACE_SOURCES_LD_KEY"; class LanguageData @@ -1274,274 +817,3 @@ static Json::Value DumpCodeModel(const cmake* cm) result[kCONFIGURATIONS_KEY] = DumpConfigurationsList(cm); return result; } - -cmServerResponse cmServerProtocol1::ProcessCodeModel( - const cmServerRequest& request) -{ - if (this->m_State != STATE_COMPUTED) { - return request.ReportError("No build system was generated yet."); - } - - return request.Reply(DumpCodeModel(this->CMakeInstance())); -} - -cmServerResponse cmServerProtocol1::ProcessCompute( - const cmServerRequest& request) -{ - if (this->m_State > STATE_CONFIGURED) { - return request.ReportError("This build system was already generated."); - } - if (this->m_State < STATE_CONFIGURED) { - return request.ReportError("This project was not configured yet."); - } - - cmake* cm = this->CMakeInstance(); - int ret = cm->Generate(); - - if (ret < 0) { - return request.ReportError("Failed to compute build system."); - } - m_State = STATE_COMPUTED; - return request.Reply(Json::Value()); -} - -cmServerResponse cmServerProtocol1::ProcessConfigure( - const cmServerRequest& request) -{ - if (this->m_State == STATE_INACTIVE) { - return request.ReportError("This instance is inactive."); - } - - FileMonitor()->StopMonitoring(); - - std::string errorMessage; - cmake* cm = this->CMakeInstance(); - this->GeneratorInfo.SetupGenerator(cm, &errorMessage); - if (!errorMessage.empty()) { - return request.ReportError(errorMessage); - } - - // Make sure the types of cacheArguments matches (if given): - std::vector cacheArgs = { "unused" }; - bool cacheArgumentsError = false; - const Json::Value passedArgs = request.Data[kCACHE_ARGUMENTS_KEY]; - if (!passedArgs.isNull()) { - if (passedArgs.isString()) { - cacheArgs.push_back(passedArgs.asString()); - } else if (passedArgs.isArray()) { - for (auto const& arg : passedArgs) { - if (!arg.isString()) { - cacheArgumentsError = true; - break; - } - cacheArgs.push_back(arg.asString()); - } - } else { - cacheArgumentsError = true; - } - } - if (cacheArgumentsError) { - request.ReportError( - "cacheArguments must be unset, a string or an array of strings."); - } - - std::string sourceDir = cm->GetHomeDirectory(); - const std::string buildDir = cm->GetHomeOutputDirectory(); - - cmGlobalGenerator* gg = cm->GetGlobalGenerator(); - - if (buildDir.empty()) { - return request.ReportError("No build directory set via Handshake."); - } - - if (cm->LoadCache(buildDir)) { - // build directory has been set up before - const std::string* cachedSourceDir = - cm->GetState()->GetInitializedCacheValue("CMAKE_HOME_DIRECTORY"); - if (!cachedSourceDir) { - return request.ReportError("No CMAKE_HOME_DIRECTORY found in cache."); - } - if (sourceDir.empty()) { - sourceDir = *cachedSourceDir; - cm->SetHomeDirectory(sourceDir); - } - - const std::string* cachedGenerator = - cm->GetState()->GetInitializedCacheValue("CMAKE_GENERATOR"); - if (cachedGenerator) { - if (gg && gg->GetName() != *cachedGenerator) { - return request.ReportError("Configured generator does not match with " - "CMAKE_GENERATOR found in cache."); - } - } - } else { - // build directory has not been set up before - if (sourceDir.empty()) { - return request.ReportError("No sourceDirectory set via " - "setGlobalSettings and no cache found in " - "buildDirectory."); - } - } - - cmSystemTools::ResetErrorOccuredFlag(); // Reset error state - - if (cm->AddCMakePaths() != 1) { - return request.ReportError("Failed to set CMake paths."); - } - - if (!cm->SetCacheArgs(cacheArgs)) { - return request.ReportError("cacheArguments could not be set."); - } - - int ret = cm->Configure(); - if (ret < 0) { - return request.ReportError("Configuration failed."); - } - - std::vector toWatchList; - getCMakeInputs(gg, std::string(), buildDir, nullptr, &toWatchList, nullptr); - - FileMonitor()->MonitorPaths(toWatchList, - [this](const std::string& p, int e, int s) { - this->HandleCMakeFileChanges(p, e, s); - }); - - m_State = STATE_CONFIGURED; - m_isDirty = false; - return request.Reply(Json::Value()); -} - -cmServerResponse cmServerProtocol1::ProcessGlobalSettings( - const cmServerRequest& request) -{ - cmake* cm = this->CMakeInstance(); - Json::Value obj = Json::objectValue; - - // Capabilities information: - obj[kCAPABILITIES_KEY] = cm->ReportCapabilitiesJson(true); - - obj[kDEBUG_OUTPUT_KEY] = cm->GetDebugOutput(); - obj[kTRACE_KEY] = cm->GetTrace(); - obj[kTRACE_EXPAND_KEY] = cm->GetTraceExpand(); - obj[kWARN_UNINITIALIZED_KEY] = cm->GetWarnUninitialized(); - obj[kWARN_UNUSED_KEY] = cm->GetWarnUnused(); - obj[kWARN_UNUSED_CLI_KEY] = cm->GetWarnUnusedCli(); - obj[kCHECK_SYSTEM_VARS_KEY] = cm->GetCheckSystemVars(); - - obj[kSOURCE_DIRECTORY_KEY] = this->GeneratorInfo.SourceDirectory; - obj[kBUILD_DIRECTORY_KEY] = this->GeneratorInfo.BuildDirectory; - - // Currently used generator: - obj[kGENERATOR_KEY] = this->GeneratorInfo.GeneratorName; - obj[kEXTRA_GENERATOR_KEY] = this->GeneratorInfo.ExtraGeneratorName; - - return request.Reply(obj); -} - -static void setBool(const cmServerRequest& request, const std::string& key, - std::function const& setter) -{ - if (request.Data[key].isNull()) { - return; - } - setter(request.Data[key].asBool()); -} - -cmServerResponse cmServerProtocol1::ProcessSetGlobalSettings( - const cmServerRequest& request) -{ - const std::vector boolValues = { - kDEBUG_OUTPUT_KEY, kTRACE_KEY, kTRACE_EXPAND_KEY, - kWARN_UNINITIALIZED_KEY, kWARN_UNUSED_KEY, kWARN_UNUSED_CLI_KEY, - kCHECK_SYSTEM_VARS_KEY - }; - for (std::string const& i : boolValues) { - if (!request.Data[i].isNull() && !request.Data[i].isBool()) { - return request.ReportError("\"" + i + - "\" must be unset or a bool value."); - } - } - - cmake* cm = this->CMakeInstance(); - - setBool(request, kDEBUG_OUTPUT_KEY, - [cm](bool e) { cm->SetDebugOutputOn(e); }); - setBool(request, kTRACE_KEY, [cm](bool e) { cm->SetTrace(e); }); - setBool(request, kTRACE_EXPAND_KEY, [cm](bool e) { cm->SetTraceExpand(e); }); - setBool(request, kWARN_UNINITIALIZED_KEY, - [cm](bool e) { cm->SetWarnUninitialized(e); }); - setBool(request, kWARN_UNUSED_KEY, [cm](bool e) { cm->SetWarnUnused(e); }); - setBool(request, kWARN_UNUSED_CLI_KEY, - [cm](bool e) { cm->SetWarnUnusedCli(e); }); - setBool(request, kCHECK_SYSTEM_VARS_KEY, - [cm](bool e) { cm->SetCheckSystemVars(e); }); - - return request.Reply(Json::Value()); -} - -cmServerResponse cmServerProtocol1::ProcessFileSystemWatchers( - const cmServerRequest& request) -{ - const cmFileMonitor* const fm = FileMonitor(); - Json::Value result = Json::objectValue; - Json::Value files = Json::arrayValue; - for (auto const& f : fm->WatchedFiles()) { - files.append(f); - } - Json::Value directories = Json::arrayValue; - for (auto const& d : fm->WatchedDirectories()) { - directories.append(d); - } - result[kWATCHED_FILES_KEY] = files; - result[kWATCHED_DIRECTORIES_KEY] = directories; - - return request.Reply(result); -} - -cmServerResponse cmServerProtocol1::ProcessCTests( - const cmServerRequest& request) -{ - if (this->m_State < STATE_COMPUTED) { - return request.ReportError("This instance was not yet computed."); - } - - return request.Reply(DumpCTestInfo(this->CMakeInstance())); -} - -cmServerProtocol1::GeneratorInformation::GeneratorInformation( - const std::string& generatorName, const std::string& extraGeneratorName, - const std::string& toolset, const std::string& platform, - const std::string& sourceDirectory, const std::string& buildDirectory) - : GeneratorName(generatorName) - , ExtraGeneratorName(extraGeneratorName) - , Toolset(toolset) - , Platform(platform) - , SourceDirectory(sourceDirectory) - , BuildDirectory(buildDirectory) -{ -} - -void cmServerProtocol1::GeneratorInformation::SetupGenerator( - cmake* cm, std::string* errorMessage) -{ - const std::string fullGeneratorName = - cmExternalMakefileProjectGenerator::CreateFullGeneratorName( - GeneratorName, ExtraGeneratorName); - - cm->SetHomeDirectory(SourceDirectory); - cm->SetHomeOutputDirectory(BuildDirectory); - - cmGlobalGenerator* gg = cm->CreateGlobalGenerator(fullGeneratorName); - if (!gg) { - setErrorMessage( - errorMessage, - std::string("Could not set up the requested combination of \"") + - kGENERATOR_KEY + "\" and \"" + kEXTRA_GENERATOR_KEY + "\""); - return; - } - - cm->SetGlobalGenerator(gg); - - cm->SetGeneratorToolset(Toolset); - cm->SetGeneratorPlatform(Platform); -} diff --git a/Source/cmServerProtocol.cxx b/Source/cmServerProtocol.cxx index 266d05c..5d29bf8 100644 --- a/Source/cmServerProtocol.cxx +++ b/Source/cmServerProtocol.cxx @@ -5,38 +5,19 @@ #include "cmAlgorithms.h" #include "cmExternalMakefileProjectGenerator.h" #include "cmFileMonitor.h" -#include "cmGeneratorExpression.h" -#include "cmGeneratorTarget.h" #include "cmGlobalGenerator.h" -#include "cmInstallGenerator.h" -#include "cmInstallTargetGenerator.h" -#include "cmLinkLineComputer.h" -#include "cmLocalGenerator.h" -#include "cmMakefile.h" -#include "cmProperty.h" #include "cmServer.h" #include "cmServerDictionary.h" -#include "cmSourceFile.h" #include "cmState.h" -#include "cmStateDirectory.h" -#include "cmStateSnapshot.h" -#include "cmStateTypes.h" #include "cmSystemTools.h" -#include "cmTarget.h" -#include "cmTest.h" #include "cm_uv.h" #include "cmake.h" #include #include -#include #include -#include -#include #include -#include #include -#include #include // Get rid of some windows macros: @@ -44,38 +25,6 @@ namespace { -std::vector getConfigurations(const cmake* cm) -{ - std::vector configurations; - auto makefiles = cm->GetGlobalGenerator()->GetMakefiles(); - if (makefiles.empty()) { - return configurations; - } - - makefiles[0]->GetConfigurations(configurations); - if (configurations.empty()) { - configurations.push_back(""); - } - return configurations; -} - -bool hasString(const Json::Value& v, const std::string& s) -{ - return !v.isNull() && - std::any_of(v.begin(), v.end(), - [s](const Json::Value& i) { return i.asString() == s; }); -} - -template -Json::Value fromStringList(const T& in) -{ - Json::Value result = Json::arrayValue; - for (std::string const& i : in) { - result.append(i); - } - return result; -} - std::vector toStringList(const Json::Value& in) { std::vector result; @@ -85,51 +34,10 @@ std::vector toStringList(const Json::Value& in) return result; } -void getCMakeInputs(const cmGlobalGenerator* gg, const std::string& sourceDir, - const std::string& buildDir, - std::vector* internalFiles, - std::vector* explicitFiles, - std::vector* tmpFiles) -{ - const std::string cmakeRootDir = cmSystemTools::GetCMakeRoot() + '/'; - std::vector const& makefiles = gg->GetMakefiles(); - for (cmMakefile const* mf : makefiles) { - for (std::string const& lf : mf->GetListFiles()) { - - const std::string startOfFile = lf.substr(0, cmakeRootDir.size()); - const bool isInternal = (startOfFile == cmakeRootDir); - const bool isTemporary = !isInternal && (lf.find(buildDir + '/') == 0); - - std::string toAdd = lf; - if (!sourceDir.empty()) { - const std::string& relative = - cmSystemTools::RelativePath(sourceDir, lf); - if (toAdd.size() > relative.size()) { - toAdd = relative; - } - } - - if (isInternal) { - if (internalFiles) { - internalFiles->push_back(std::move(toAdd)); - } - } else { - if (isTemporary) { - if (tmpFiles) { - tmpFiles->push_back(std::move(toAdd)); - } - } else { - if (explicitFiles) { - explicitFiles->push_back(std::move(toAdd)); - } - } - } - } - } -} - } // namespace +#include "cmJsonObjects.cxx" + cmServerRequest::cmServerRequest(cmServer* server, cmConnection* connection, const std::string& t, const std::string& c, const Json::Value& d) @@ -550,41 +458,6 @@ cmServerResponse cmServerProtocol1::ProcessCache( return request.Reply(result); } -static Json::Value DumpCMakeInputs(const cmake* cm) -{ - const cmGlobalGenerator* gg = cm->GetGlobalGenerator(); - const std::string& buildDir = cm->GetHomeOutputDirectory(); - const std::string& sourceDir = cm->GetHomeDirectory(); - - std::vector internalFiles; - std::vector explicitFiles; - std::vector tmpFiles; - getCMakeInputs(gg, sourceDir, buildDir, &internalFiles, &explicitFiles, - &tmpFiles); - - Json::Value array = Json::arrayValue; - - Json::Value tmp = Json::objectValue; - tmp[kIS_CMAKE_KEY] = true; - tmp[kIS_TEMPORARY_KEY] = false; - tmp[kSOURCES_KEY] = fromStringList(internalFiles); - array.append(tmp); - - tmp = Json::objectValue; - tmp[kIS_CMAKE_KEY] = false; - tmp[kIS_TEMPORARY_KEY] = false; - tmp[kSOURCES_KEY] = fromStringList(explicitFiles); - array.append(tmp); - - tmp = Json::objectValue; - tmp[kIS_CMAKE_KEY] = false; - tmp[kIS_TEMPORARY_KEY] = true; - tmp[kSOURCES_KEY] = fromStringList(tmpFiles); - array.append(tmp); - - return array; -} - cmServerResponse cmServerProtocol1::ProcessCMakeInputs( const cmServerRequest& request) { @@ -603,678 +476,6 @@ cmServerResponse cmServerProtocol1::ProcessCMakeInputs( return request.Reply(result); } -const std::string kInterfaceSourcesLanguageDataKey = - "INTERFACE_SOURCES_LD_KEY"; -class LanguageData -{ -public: - bool operator==(const LanguageData& other) const; - - void SetDefines(const std::set& defines); - - bool IsGenerated = false; - std::string Language; - std::string Flags; - std::vector Defines; - std::vector> IncludePathList; -}; - -bool LanguageData::operator==(const LanguageData& other) const -{ - return Language == other.Language && Defines == other.Defines && - Flags == other.Flags && IncludePathList == other.IncludePathList && - IsGenerated == other.IsGenerated; -} - -void LanguageData::SetDefines(const std::set& defines) -{ - std::vector result; - result.reserve(defines.size()); - for (std::string const& i : defines) { - result.push_back(i); - } - std::sort(result.begin(), result.end()); - Defines = std::move(result); -} - -struct FileGroupSources -{ - bool IsInterfaceSources; - std::vector Files; -}; - -namespace std { - -template <> -struct hash -{ - std::size_t operator()(const LanguageData& in) const - { - using std::hash; - size_t result = - hash()(in.Language) ^ hash()(in.Flags); - for (auto const& i : in.IncludePathList) { - result = result ^ - (hash()(i.first) ^ - (i.second ? std::numeric_limits::max() : 0)); - } - for (auto const& i : in.Defines) { - result = result ^ hash()(i); - } - result = - result ^ (in.IsGenerated ? std::numeric_limits::max() : 0); - return result; - } -}; - -} // namespace std - -static Json::Value DumpSourceFileGroup(const LanguageData& data, - bool isInterfaceSource, - const std::vector& files, - const std::string& baseDir) -{ - Json::Value result = Json::objectValue; - - if (isInterfaceSource) { - result[kIS_INTERFACE_SOURCES_KEY] = true; - } - if (!data.Language.empty()) { - result[kLANGUAGE_KEY] = data.Language; - } - if (!data.Flags.empty()) { - result[kCOMPILE_FLAGS_KEY] = data.Flags; - } - if (!data.IncludePathList.empty()) { - Json::Value includes = Json::arrayValue; - for (auto const& i : data.IncludePathList) { - Json::Value tmp = Json::objectValue; - tmp[kPATH_KEY] = i.first; - if (i.second) { - tmp[kIS_SYSTEM_KEY] = i.second; - } - includes.append(tmp); - } - result[kINCLUDE_PATH_KEY] = includes; - } - if (!data.Defines.empty()) { - result[kDEFINES_KEY] = fromStringList(data.Defines); - } - - result[kIS_GENERATED_KEY] = data.IsGenerated; - - Json::Value sourcesValue = Json::arrayValue; - for (auto const& i : files) { - const std::string relPath = cmSystemTools::RelativePath(baseDir, i); - sourcesValue.append(relPath.size() < i.size() ? relPath : i); - } - - result[kSOURCES_KEY] = sourcesValue; - return result; -} - -static void PopulateFileGroupData( - cmGeneratorTarget* target, bool isInterfaceSources, - const std::vector& files, const std::string& config, - const std::map& languageDataMap, - std::unordered_map& fileGroups) -{ - for (cmSourceFile* file : files) { - LanguageData fileData; - fileData.Language = file->GetLanguage(); - if (!fileData.Language.empty() || isInterfaceSources) { - const LanguageData& ld = isInterfaceSources - ? languageDataMap.at(kInterfaceSourcesLanguageDataKey) - : languageDataMap.at(fileData.Language); - cmLocalGenerator* lg = target->GetLocalGenerator(); - cmGeneratorExpressionInterpreter genexInterpreter(lg, config, target, - fileData.Language); - - std::string compileFlags = ld.Flags; - const std::string COMPILE_FLAGS("COMPILE_FLAGS"); - if (const char* cflags = file->GetProperty(COMPILE_FLAGS)) { - lg->AppendFlags(compileFlags, - genexInterpreter.Evaluate(cflags, COMPILE_FLAGS)); - } - const std::string COMPILE_OPTIONS("COMPILE_OPTIONS"); - if (const char* coptions = file->GetProperty(COMPILE_OPTIONS)) { - lg->AppendCompileOptions( - compileFlags, genexInterpreter.Evaluate(coptions, COMPILE_OPTIONS)); - } - fileData.Flags = compileFlags; - - // Add include directories from source file properties. - std::vector includes; - - const std::string INCLUDE_DIRECTORIES("INCLUDE_DIRECTORIES"); - if (const char* cincludes = file->GetProperty(INCLUDE_DIRECTORIES)) { - const std::string& evaluatedIncludes = - genexInterpreter.Evaluate(cincludes, INCLUDE_DIRECTORIES); - lg->AppendIncludeDirectories(includes, evaluatedIncludes, *file); - - for (const auto& include : includes) { - // INTERFACE_LIBRARY targets do not support the - // IsSystemIncludeDirectory call so just set it to false. - const bool isSystemInclude = isInterfaceSources - ? false - : target->IsSystemIncludeDirectory(include, config, - fileData.Language); - fileData.IncludePathList.push_back( - std::make_pair(include, isSystemInclude)); - } - } - - fileData.IncludePathList.insert(fileData.IncludePathList.end(), - ld.IncludePathList.begin(), - ld.IncludePathList.end()); - - const std::string COMPILE_DEFINITIONS("COMPILE_DEFINITIONS"); - std::set defines; - if (const char* defs = file->GetProperty(COMPILE_DEFINITIONS)) { - lg->AppendDefines( - defines, genexInterpreter.Evaluate(defs, COMPILE_DEFINITIONS)); - } - - const std::string defPropName = - "COMPILE_DEFINITIONS_" + cmSystemTools::UpperCase(config); - if (const char* config_defs = file->GetProperty(defPropName)) { - lg->AppendDefines( - defines, - genexInterpreter.Evaluate(config_defs, COMPILE_DEFINITIONS)); - } - - defines.insert(ld.Defines.begin(), ld.Defines.end()); - - fileData.SetDefines(defines); - } - - fileData.IsGenerated = file->GetPropertyAsBool("GENERATED"); - FileGroupSources& groupFileList = fileGroups[fileData]; - groupFileList.IsInterfaceSources = isInterfaceSources; - groupFileList.Files.push_back(file->GetFullPath()); - } -} - -static Json::Value DumpSourceFilesList( - cmGeneratorTarget* target, const std::string& config, - const std::map& languageDataMap) -{ - const cmStateEnums::TargetType type = target->GetType(); - std::unordered_map fileGroups; - - // Collect sourcefile groups: - - std::vector files; - if (type == cmStateEnums::INTERFACE_LIBRARY) { - // INTERFACE_LIBRARY targets do not create all the data structures - // associated with regular targets. If properties are explicitly specified - // for files in INTERFACE_SOURCES then we can get them through the Makefile - // rather than the target. - files = target->Makefile->GetSourceFiles(); - } else { - target->GetSourceFiles(files, config); - PopulateFileGroupData(target, false /* isInterfaceSources */, files, - config, languageDataMap, fileGroups); - } - - // Collect interface sourcefile groups: - - auto targetProp = target->Target->GetProperty("INTERFACE_SOURCES"); - if (targetProp != nullptr) { - cmGeneratorExpressionInterpreter genexInterpreter( - target->GetLocalGenerator(), config, target); - - auto evaluatedSources = cmsys::SystemTools::SplitString( - genexInterpreter.Evaluate(targetProp, "INTERFACE_SOURCES"), ';'); - - std::map filesMap; - for (auto file : files) { - filesMap[file->GetFullPath()] = file; - } - - std::vector interfaceSourceFiles; - for (const std::string& interfaceSourceFilePath : evaluatedSources) { - auto entry = filesMap.find(interfaceSourceFilePath); - if (entry != filesMap.end()) { - // use what we have since it has all the associated properties - interfaceSourceFiles.push_back(entry->second); - } else { - interfaceSourceFiles.push_back( - new cmSourceFile(target->Makefile, interfaceSourceFilePath)); - } - } - - PopulateFileGroupData(target, true /* isInterfaceSources */, - interfaceSourceFiles, config, languageDataMap, - fileGroups); - } - - const std::string& baseDir = target->Makefile->GetCurrentSourceDirectory(); - Json::Value result = Json::arrayValue; - for (auto const& it : fileGroups) { - Json::Value group = DumpSourceFileGroup( - it.first, it.second.IsInterfaceSources, it.second.Files, baseDir); - if (!group.isNull()) { - result.append(group); - } - } - - return result; -} - -static Json::Value DumpCTestInfo(cmLocalGenerator* lg, cmTest* testInfo, - const std::string& config) -{ - Json::Value result = Json::objectValue; - result[kCTEST_NAME] = testInfo->GetName(); - - // Concat command entries together. After the first should be the arguments - // for the command - std::string command; - for (auto const& cmd : testInfo->GetCommand()) { - command.append(cmd); - command.append(" "); - } - - // Remove any config specific variables from the output. - cmGeneratorExpression ge; - auto cge = ge.Parse(command); - const std::string& processed = cge->Evaluate(lg, config); - result[kCTEST_COMMAND] = processed; - - // Build up the list of properties that may have been specified - Json::Value properties = Json::arrayValue; - for (auto& prop : testInfo->GetProperties()) { - Json::Value entry = Json::objectValue; - entry[kKEY_KEY] = prop.first; - - // Remove config variables from the value too. - auto cge_value = ge.Parse(prop.second.GetValue()); - const std::string& processed_value = cge_value->Evaluate(lg, config); - entry[kVALUE_KEY] = processed_value; - properties.append(entry); - } - result[kPROPERTIES_KEY] = properties; - - return result; -} - -static void DumpMakefileTests(cmLocalGenerator* lg, const std::string& config, - Json::Value* result) -{ - auto mf = lg->GetMakefile(); - std::vector tests; - mf->GetTests(config, tests); - for (auto test : tests) { - Json::Value tmp = DumpCTestInfo(lg, test, config); - if (!tmp.isNull()) { - result->append(tmp); - } - } -} - -static Json::Value DumpCTestProjectList(const cmake* cm, - std::string const& config) -{ - Json::Value result = Json::arrayValue; - - auto globalGen = cm->GetGlobalGenerator(); - - for (const auto& projectIt : globalGen->GetProjectMap()) { - Json::Value pObj = Json::objectValue; - pObj[kNAME_KEY] = projectIt.first; - - Json::Value tests = Json::arrayValue; - - // Gather tests for every generator - for (const auto& lg : projectIt.second) { - // Make sure they're generated. - lg->GenerateTestFiles(); - DumpMakefileTests(lg, config, &tests); - } - - pObj[kCTEST_INFO] = tests; - - result.append(pObj); - } - - return result; -} - -static Json::Value DumpCTestConfiguration(const cmake* cm, - const std::string& config) -{ - Json::Value result = Json::objectValue; - result[kNAME_KEY] = config; - - result[kPROJECTS_KEY] = DumpCTestProjectList(cm, config); - - return result; -} - -static Json::Value DumpCTestConfigurationsList(const cmake* cm) -{ - Json::Value result = Json::arrayValue; - - for (const std::string& c : getConfigurations(cm)) { - result.append(DumpCTestConfiguration(cm, c)); - } - - return result; -} - -static Json::Value DumpCTestInfo(const cmake* cm) -{ - Json::Value result = Json::objectValue; - result[kCONFIGURATIONS_KEY] = DumpCTestConfigurationsList(cm); - return result; -} - -static void GetTargetProperty( - cmGeneratorExpressionInterpreter& genexInterpreter, - cmGeneratorTarget* target, const char* propertyName, - std::vector& propertyValue) -{ - auto targetProp = target->Target->GetProperty(propertyName); - if (targetProp != nullptr) { - propertyValue = cmsys::SystemTools::SplitString( - genexInterpreter.Evaluate(targetProp, propertyName), ';'); - } -} - -static void CreateInterfaceSourcesEntry( - cmLocalGenerator* lg, cmGeneratorTarget* target, const std::string& config, - std::map& languageDataMap) -{ - LanguageData& ld = languageDataMap[kInterfaceSourcesLanguageDataKey]; - ld.Language = ""; - - cmGeneratorExpressionInterpreter genexInterpreter(lg, config, target); - std::vector propertyValue; - GetTargetProperty(genexInterpreter, target, "INTERFACE_INCLUDE_DIRECTORIES", - propertyValue); - for (std::string const& i : propertyValue) { - ld.IncludePathList.push_back( - std::make_pair(i, false /* isSystemInclude */)); - } - - propertyValue.clear(); - GetTargetProperty(genexInterpreter, target, - "INTERFACE_SYSTEM_INCLUDE_DIRECTORIES", propertyValue); - for (std::string const& i : propertyValue) { - ld.IncludePathList.push_back( - std::make_pair(i, true /* isSystemInclude */)); - } - - propertyValue.clear(); - GetTargetProperty(genexInterpreter, target, "INTERFACE_COMPILE_OPTIONS", - propertyValue); - for (const auto& s : propertyValue) { - ld.Flags += " " + s; - } - - propertyValue.clear(); - GetTargetProperty(genexInterpreter, target, "INTERFACE_COMPILE_DEFINITIONS", - propertyValue); - if (!propertyValue.empty()) { - std::set defines(propertyValue.begin(), propertyValue.end()); - ld.SetDefines(defines); - } -} - -static Json::Value DumpTarget(cmGeneratorTarget* target, - const std::string& config) -{ - cmLocalGenerator* lg = target->GetLocalGenerator(); - const cmState* state = lg->GetState(); - - const cmStateEnums::TargetType type = target->GetType(); - const std::string typeName = state->GetTargetTypeName(type); - - Json::Value ttl = Json::arrayValue; - ttl.append("EXECUTABLE"); - ttl.append("STATIC_LIBRARY"); - ttl.append("SHARED_LIBRARY"); - ttl.append("MODULE_LIBRARY"); - ttl.append("OBJECT_LIBRARY"); - ttl.append("UTILITY"); - ttl.append("INTERFACE_LIBRARY"); - - if (!hasString(ttl, typeName) || target->IsImported()) { - return Json::Value(); - } - - Json::Value result = Json::objectValue; - result[kNAME_KEY] = target->GetName(); - result[kIS_GENERATOR_PROVIDED_KEY] = - target->Target->GetIsGeneratorProvided(); - result[kTYPE_KEY] = typeName; - result[kSOURCE_DIRECTORY_KEY] = lg->GetCurrentSourceDirectory(); - result[kBUILD_DIRECTORY_KEY] = lg->GetCurrentBinaryDirectory(); - result[kFULL_NAME_KEY] = target->GetFullName(config); - - if (target->Target->GetHaveInstallRule()) { - result[kHAS_INSTALL_RULE] = true; - - Json::Value installPaths = Json::arrayValue; - auto targetGenerators = target->Makefile->GetInstallGenerators(); - for (auto installGenerator : targetGenerators) { - auto installTargetGenerator = - dynamic_cast(installGenerator); - if (installTargetGenerator != nullptr && - installTargetGenerator->GetTarget()->Target == target->Target) { - auto dest = installTargetGenerator->GetDestination(config); - - std::string installPath; - if (!dest.empty() && cmSystemTools::FileIsFullPath(dest)) { - installPath = dest; - } else { - std::string installPrefix = - target->Makefile->GetSafeDefinition("CMAKE_INSTALL_PREFIX"); - installPath = installPrefix + '/' + dest; - } - - installPaths.append(installPath); - } - } - - result[kINSTALL_PATHS] = installPaths; - } - - if (target->HaveWellDefinedOutputFiles()) { - Json::Value artifacts = Json::arrayValue; - artifacts.append( - target->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact)); - if (target->IsDLLPlatform()) { - artifacts.append( - target->GetFullPath(config, cmStateEnums::ImportLibraryArtifact)); - const cmGeneratorTarget::OutputInfo* output = - target->GetOutputInfo(config); - if (output && !output->PdbDir.empty()) { - artifacts.append(output->PdbDir + '/' + target->GetPDBName(config)); - } - } - result[kARTIFACTS_KEY] = artifacts; - - result[kLINKER_LANGUAGE_KEY] = target->GetLinkerLanguage(config); - - std::string linkLibs; - std::string linkFlags; - std::string linkLanguageFlags; - std::string frameworkPath; - std::string linkPath; - cmLinkLineComputer linkLineComputer(lg, - lg->GetStateSnapshot().GetDirectory()); - lg->GetTargetFlags(&linkLineComputer, config, linkLibs, linkLanguageFlags, - linkFlags, frameworkPath, linkPath, target); - - linkLibs = cmSystemTools::TrimWhitespace(linkLibs); - linkFlags = cmSystemTools::TrimWhitespace(linkFlags); - linkLanguageFlags = cmSystemTools::TrimWhitespace(linkLanguageFlags); - frameworkPath = cmSystemTools::TrimWhitespace(frameworkPath); - linkPath = cmSystemTools::TrimWhitespace(linkPath); - - if (!cmSystemTools::TrimWhitespace(linkLibs).empty()) { - result[kLINK_LIBRARIES_KEY] = linkLibs; - } - if (!cmSystemTools::TrimWhitespace(linkFlags).empty()) { - result[kLINK_FLAGS_KEY] = linkFlags; - } - if (!cmSystemTools::TrimWhitespace(linkLanguageFlags).empty()) { - result[kLINK_LANGUAGE_FLAGS_KEY] = linkLanguageFlags; - } - if (!frameworkPath.empty()) { - result[kFRAMEWORK_PATH_KEY] = frameworkPath; - } - if (!linkPath.empty()) { - result[kLINK_PATH_KEY] = linkPath; - } - const std::string sysroot = - lg->GetMakefile()->GetSafeDefinition("CMAKE_SYSROOT"); - if (!sysroot.empty()) { - result[kSYSROOT_KEY] = sysroot; - } - } - - std::set languages; - std::map languageDataMap; - if (type == cmStateEnums::INTERFACE_LIBRARY) { - // INTERFACE_LIBRARY targets do not create all the data structures - // associated with regular targets. If properties are explicitly specified - // for files in INTERFACE_SOURCES then we can get them through the Makefile - // rather than the target. - for (auto file : target->Makefile->GetSourceFiles()) { - const std::string& language = file->GetLanguage(); - if (!language.empty()) { - languages.insert(language); - } - } - } else { - target->GetLanguages(languages, config); - } - - for (std::string const& lang : languages) { - LanguageData& ld = languageDataMap[lang]; - ld.Language = lang; - lg->GetTargetCompileFlags(target, config, lang, ld.Flags); - std::set defines; - lg->GetTargetDefines(target, config, lang, defines); - ld.SetDefines(defines); - std::vector includePathList; - lg->GetIncludeDirectories(includePathList, target, lang, config, true); - for (std::string const& i : includePathList) { - ld.IncludePathList.push_back( - std::make_pair(i, target->IsSystemIncludeDirectory(i, config, lang))); - } - } - - if (target->Target->GetProperty("INTERFACE_SOURCES") != nullptr) { - // Create an entry in the languageDataMap for interface sources. - CreateInterfaceSourcesEntry(lg, target, config, languageDataMap); - } - - Json::Value sourceGroupsValue = - DumpSourceFilesList(target, config, languageDataMap); - if (!sourceGroupsValue.empty()) { - result[kFILE_GROUPS_KEY] = sourceGroupsValue; - } - - return result; -} - -static Json::Value DumpTargetsList( - const std::vector& generators, const std::string& config) -{ - Json::Value result = Json::arrayValue; - - std::vector targetList; - for (auto const& lgIt : generators) { - const auto& list = lgIt->GetGeneratorTargets(); - targetList.insert(targetList.end(), list.begin(), list.end()); - } - std::sort(targetList.begin(), targetList.end()); - - for (cmGeneratorTarget* target : targetList) { - Json::Value tmp = DumpTarget(target, config); - if (!tmp.isNull()) { - result.append(tmp); - } - } - - return result; -} - -static Json::Value DumpProjectList(const cmake* cm, std::string const& config) -{ - Json::Value result = Json::arrayValue; - - auto globalGen = cm->GetGlobalGenerator(); - - for (auto const& projectIt : globalGen->GetProjectMap()) { - Json::Value pObj = Json::objectValue; - pObj[kNAME_KEY] = projectIt.first; - - // All Projects must have at least one local generator - assert(!projectIt.second.empty()); - const cmLocalGenerator* lg = projectIt.second.at(0); - - // Project structure information: - const cmMakefile* mf = lg->GetMakefile(); - auto minVersion = mf->GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION"); - pObj[kMINIMUM_CMAKE_VERSION] = minVersion ? minVersion : ""; - pObj[kSOURCE_DIRECTORY_KEY] = mf->GetCurrentSourceDirectory(); - pObj[kBUILD_DIRECTORY_KEY] = mf->GetCurrentBinaryDirectory(); - pObj[kTARGETS_KEY] = DumpTargetsList(projectIt.second, config); - - // For a project-level install rule it might be defined in any of its - // associated generators. - bool hasInstallRule = false; - for (const auto generator : projectIt.second) { - hasInstallRule = - generator->GetMakefile()->GetInstallGenerators().empty() == false; - - if (hasInstallRule) { - break; - } - } - - pObj[kHAS_INSTALL_RULE] = hasInstallRule; - - result.append(pObj); - } - - return result; -} - -static Json::Value DumpConfiguration(const cmake* cm, - const std::string& config) -{ - Json::Value result = Json::objectValue; - result[kNAME_KEY] = config; - - result[kPROJECTS_KEY] = DumpProjectList(cm, config); - - return result; -} - -static Json::Value DumpConfigurationsList(const cmake* cm) -{ - Json::Value result = Json::arrayValue; - - for (std::string const& c : getConfigurations(cm)) { - result.append(DumpConfiguration(cm, c)); - } - - return result; -} - -static Json::Value DumpCodeModel(const cmake* cm) -{ - Json::Value result = Json::objectValue; - result[kCONFIGURATIONS_KEY] = DumpConfigurationsList(cm); - return result; -} - cmServerResponse cmServerProtocol1::ProcessCodeModel( const cmServerRequest& request) { https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=aabce528519eaa1db64fb4eef48e12669b028f05 commit aabce528519eaa1db64fb4eef48e12669b028f05 Author: Brad King AuthorDate: Fri Sep 21 09:35:28 2018 -0400 Commit: Brad King CommitDate: Fri Sep 21 11:36:55 2018 -0400 server: factor out json object generation entry points Make entry points for these that do not reference the server code. For now we leave the "cache" object generation alone because its implementation interleaves error handling and the format may not suitable outside a server response. diff --git a/Source/cmServerProtocol.cxx b/Source/cmServerProtocol.cxx index 2cad657..266d05c 100644 --- a/Source/cmServerProtocol.cxx +++ b/Source/cmServerProtocol.cxx @@ -550,23 +550,12 @@ cmServerResponse cmServerProtocol1::ProcessCache( return request.Reply(result); } -cmServerResponse cmServerProtocol1::ProcessCMakeInputs( - const cmServerRequest& request) +static Json::Value DumpCMakeInputs(const cmake* cm) { - if (this->m_State < STATE_CONFIGURED) { - return request.ReportError("This instance was not yet configured."); - } - - const cmake* cm = this->CMakeInstance(); const cmGlobalGenerator* gg = cm->GetGlobalGenerator(); - const std::string cmakeRootDir = cmSystemTools::GetCMakeRoot(); const std::string& buildDir = cm->GetHomeOutputDirectory(); const std::string& sourceDir = cm->GetHomeDirectory(); - Json::Value result = Json::objectValue; - result[kSOURCE_DIRECTORY_KEY] = sourceDir; - result[kCMAKE_ROOT_DIRECTORY_KEY] = cmakeRootDir; - std::vector internalFiles; std::vector explicitFiles; std::vector tmpFiles; @@ -593,8 +582,24 @@ cmServerResponse cmServerProtocol1::ProcessCMakeInputs( tmp[kSOURCES_KEY] = fromStringList(tmpFiles); array.append(tmp); - result[kBUILD_FILES_KEY] = array; + return array; +} + +cmServerResponse cmServerProtocol1::ProcessCMakeInputs( + const cmServerRequest& request) +{ + if (this->m_State < STATE_CONFIGURED) { + return request.ReportError("This instance was not yet configured."); + } + const cmake* cm = this->CMakeInstance(); + const std::string cmakeRootDir = cmSystemTools::GetCMakeRoot(); + const std::string& sourceDir = cm->GetHomeDirectory(); + + Json::Value result = Json::objectValue; + result[kSOURCE_DIRECTORY_KEY] = sourceDir; + result[kCMAKE_ROOT_DIRECTORY_KEY] = cmakeRootDir; + result[kBUILD_FILES_KEY] = DumpCMakeInputs(cm); return request.Reply(result); } @@ -958,6 +963,13 @@ static Json::Value DumpCTestConfigurationsList(const cmake* cm) return result; } +static Json::Value DumpCTestInfo(const cmake* cm) +{ + Json::Value result = Json::objectValue; + result[kCONFIGURATIONS_KEY] = DumpCTestConfigurationsList(cm); + return result; +} + static void GetTargetProperty( cmGeneratorExpressionInterpreter& genexInterpreter, cmGeneratorTarget* target, const char* propertyName, @@ -1256,6 +1268,13 @@ static Json::Value DumpConfigurationsList(const cmake* cm) return result; } +static Json::Value DumpCodeModel(const cmake* cm) +{ + Json::Value result = Json::objectValue; + result[kCONFIGURATIONS_KEY] = DumpConfigurationsList(cm); + return result; +} + cmServerResponse cmServerProtocol1::ProcessCodeModel( const cmServerRequest& request) { @@ -1263,9 +1282,7 @@ cmServerResponse cmServerProtocol1::ProcessCodeModel( return request.ReportError("No build system was generated yet."); } - Json::Value result = Json::objectValue; - result[kCONFIGURATIONS_KEY] = DumpConfigurationsList(this->CMakeInstance()); - return request.Reply(result); + return request.Reply(DumpCodeModel(this->CMakeInstance())); } cmServerResponse cmServerProtocol1::ProcessCompute( @@ -1488,10 +1505,7 @@ cmServerResponse cmServerProtocol1::ProcessCTests( return request.ReportError("This instance was not yet computed."); } - Json::Value result = Json::objectValue; - result[kCONFIGURATIONS_KEY] = - DumpCTestConfigurationsList(this->CMakeInstance()); - return request.Reply(result); + return request.Reply(DumpCTestInfo(this->CMakeInstance())); } cmServerProtocol1::GeneratorInformation::GeneratorInformation( https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=fc43492e44c67ed73a6483a4cd587eae02657949 commit fc43492e44c67ed73a6483a4cd587eae02657949 Author: Brad King AuthorDate: Mon Aug 27 10:02:50 2018 -0400 Commit: Brad King CommitDate: Fri Sep 21 11:36:11 2018 -0400 cmake: Factor json version object construction into helper diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 6c14834..c26a380 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -225,10 +225,8 @@ cmake::~cmake() } #if defined(CMAKE_BUILD_WITH_CMAKE) -Json::Value cmake::ReportCapabilitiesJson(bool haveServerMode) const +Json::Value cmake::ReportVersionJson() const { - Json::Value obj = Json::objectValue; - // Version information: Json::Value version = Json::objectValue; version["string"] = CMake_VERSION; version["major"] = CMake_VERSION_MAJOR; @@ -236,8 +234,15 @@ Json::Value cmake::ReportCapabilitiesJson(bool haveServerMode) const version["suffix"] = CMake_VERSION_SUFFIX; version["isDirty"] = (CMake_VERSION_IS_DIRTY == 1); version["patch"] = CMake_VERSION_PATCH; + return version; +} - obj["version"] = version; +Json::Value cmake::ReportCapabilitiesJson(bool haveServerMode) const +{ + Json::Value obj = Json::objectValue; + + // Version information: + obj["version"] = this->ReportVersionJson(); // Generators: std::vector generatorInfoList; diff --git a/Source/cmake.h b/Source/cmake.h index f7dc3f7..d3d0e80 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -128,6 +128,7 @@ public: ~cmake(); #if defined(CMAKE_BUILD_WITH_CMAKE) + Json::Value ReportVersionJson() const; Json::Value ReportCapabilitiesJson(bool haveServerMode) const; #endif std::string ReportCapabilities(bool haveServerMode) const; ----------------------------------------------------------------------- Summary of changes: Source/CMakeLists.txt | 3 + Source/cmJsonObjectDictionary.h | 46 ++ Source/{cmServerProtocol.cxx => cmJsonObjects.cxx} | 760 +------------------- Source/cmJsonObjects.h | 27 + Source/cmServer.cxx | 1 + Source/cmServerDictionary.h | 38 - Source/cmServerProtocol.cxx | 798 +-------------------- Source/cmake.cxx | 13 +- Source/cmake.h | 1 + 9 files changed, 119 insertions(+), 1568 deletions(-) create mode 100644 Source/cmJsonObjectDictionary.h copy Source/{cmServerProtocol.cxx => cmJsonObjects.cxx} (52%) create mode 100644 Source/cmJsonObjects.h hooks/post-receive -- CMake From kwrobot at kitware.com Tue Sep 25 00:05:12 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Tue, 25 Sep 2018 00:05:12 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-709-g1fea56c Message-ID: <20180925040512.7070211180E@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 1fea56c3bd99be6c7a6bfaa1454ba67e7a04da72 (commit) from 03ffd442bd34e2a3478b125ef1055837926bcd0c (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=1fea56c3bd99be6c7a6bfaa1454ba67e7a04da72 commit 1fea56c3bd99be6c7a6bfaa1454ba67e7a04da72 Author: Kitware Robot AuthorDate: Tue Sep 25 00:01:13 2018 -0400 Commit: Kitware Robot CommitDate: Tue Sep 25 00:01:13 2018 -0400 CMake Nightly Date Stamp diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 2dab997..360b561 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 12) -set(CMake_VERSION_PATCH 20180924) +set(CMake_VERSION_PATCH 20180925) #set(CMake_VERSION_RC 1) ----------------------------------------------------------------------- Summary of changes: Source/CMakeVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) hooks/post-receive -- CMake From kwrobot at kitware.com Tue Sep 25 08:45:04 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Tue, 25 Sep 2018 08:45:04 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-714-g55a5b56 Message-ID: <20180925124504.7A4F610A530@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 55a5b56e083c4c2d4e768212422991a22569ecb4 (commit) via 65f8eb5ae548a764bf41c43f5622888fcd8b3133 (commit) via 15e211df803a7bcfeefc7b2aa91741f308fb609c (commit) via 22aa6b67b41808bb9c27aeb0f8f662cd81466843 (commit) via 1fe0d72eb6aef12148be0b37d73cf31fbd5f9ca0 (commit) from 1fea56c3bd99be6c7a6bfaa1454ba67e7a04da72 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=55a5b56e083c4c2d4e768212422991a22569ecb4 commit 55a5b56e083c4c2d4e768212422991a22569ecb4 Merge: 65f8eb5 22aa6b6 Author: Brad King AuthorDate: Tue Sep 25 12:41:43 2018 +0000 Commit: Kitware Robot CommitDate: Tue Sep 25 08:41:49 2018 -0400 Merge topic 'refactor-backtrace' 22aa6b67b4 cmListFileCache: Refactor cmListFileBacktrace internals 1fe0d72eb6 clang-tidy: exclude 'misc-noexcept-move-constructor' Acked-by: Kitware Robot Merge-request: !2410 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=65f8eb5ae548a764bf41c43f5622888fcd8b3133 commit 65f8eb5ae548a764bf41c43f5622888fcd8b3133 Merge: 1fea56c 15e211d Author: Brad King AuthorDate: Tue Sep 25 12:39:37 2018 +0000 Commit: Kitware Robot CommitDate: Tue Sep 25 08:39:46 2018 -0400 Merge topic 'doc-vs-cmake-A' 15e211df80 Help: Suggest using -A to specify platform for VS generators Acked-by: Kitware Robot Merge-request: !2411 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=15e211df803a7bcfeefc7b2aa91741f308fb609c commit 15e211df803a7bcfeefc7b2aa91741f308fb609c Author: Brad King AuthorDate: Mon Sep 24 15:00:46 2018 -0400 Commit: Brad King CommitDate: Tue Sep 25 06:52:35 2018 -0400 Help: Suggest using -A to specify platform for VS generators We already suggest `-T` for the toolset. Create a dedicated section for platform selection and suggest `-A`. Provide examples. diff --git a/Help/generator/Visual Studio 10 2010.rst b/Help/generator/Visual Studio 10 2010.rst index b8d6872..0446b8c 100644 --- a/Help/generator/Visual Studio 10 2010.rst +++ b/Help/generator/Visual Studio 10 2010.rst @@ -3,18 +3,6 @@ Visual Studio 10 2010 Generates Visual Studio 10 (VS 2010) project files. -The :variable:`CMAKE_GENERATOR_PLATFORM` variable may be set -to specify a target platform name (architecture). - -For compatibility with CMake versions prior to 3.1, one may specify -a target platform name optionally at the end of this generator name: - -``Visual Studio 10 2010 Win64`` - Specify target platform ``x64``. - -``Visual Studio 10 2010 IA64`` - Specify target platform ``Itanium``. - For compatibility with CMake versions prior to 3.0, one may specify this generator using the name ``Visual Studio 10`` without the year component. @@ -24,6 +12,27 @@ Project Types Only Visual C++ and C# projects may be generated. Other types of projects (Database, Website, etc.) are not supported. +Platform Selection +^^^^^^^^^^^^^^^^^^ + +The :variable:`CMAKE_GENERATOR_PLATFORM` variable may be set, perhaps +via the :manual:`cmake(1)` ``-A`` option, to specify a target platform +name (architecture). For example: + +* ``cmake -G "Visual Studio 10 2010" -A Win32`` +* ``cmake -G "Visual Studio 10 2010" -A x64`` +* ``cmake -G "Visual Studio 10 2010" -A Itanium`` + +For compatibility with CMake versions prior to 3.1, one may specify +a target platform name optionally at the end of the generator name. +This is supported only for: + +``Visual Studio 10 2010 Win64`` + Specify target platform ``x64``. + +``Visual Studio 10 2010 IA64`` + Specify target platform ``Itanium``. + Toolset Selection ^^^^^^^^^^^^^^^^^ diff --git a/Help/generator/Visual Studio 11 2012.rst b/Help/generator/Visual Studio 11 2012.rst index 8e9998a..8fddbb3 100644 --- a/Help/generator/Visual Studio 11 2012.rst +++ b/Help/generator/Visual Studio 11 2012.rst @@ -3,11 +3,31 @@ Visual Studio 11 2012 Generates Visual Studio 11 (VS 2012) project files. -The :variable:`CMAKE_GENERATOR_PLATFORM` variable may be set -to specify a target platform name (architecture). +For compatibility with CMake versions prior to 3.0, one may specify this +generator using the name "Visual Studio 11" without the year component. + +Project Types +^^^^^^^^^^^^^ + +Only Visual C++ and C# projects may be generated. Other types of +projects (JavaScript, Database, Website, etc.) are not supported. + +Platform Selection +^^^^^^^^^^^^^^^^^^ + +The :variable:`CMAKE_GENERATOR_PLATFORM` variable may be set, perhaps +via the :manual:`cmake(1)` ``-A`` option, to specify a target platform +name (architecture). For example: + +* ``cmake -G "Visual Studio 11 2012" -A Win32`` +* ``cmake -G "Visual Studio 11 2012" -A x64`` +* ``cmake -G "Visual Studio 11 2012" -A ARM`` +* ``cmake -G "Visual Studio 11 2012" -A `` + (Specify a target platform matching a Windows CE SDK name.) For compatibility with CMake versions prior to 3.1, one may specify -a target platform name optionally at the end of this generator name: +a target platform name optionally at the end of the generator name. +This is supported only for: ``Visual Studio 11 2012 Win64`` Specify target platform ``x64``. @@ -18,15 +38,6 @@ a target platform name optionally at the end of this generator name: ``Visual Studio 11 2012 `` Specify target platform matching a Windows CE SDK name. -For compatibility with CMake versions prior to 3.0, one may specify this -generator using the name "Visual Studio 11" without the year component. - -Project Types -^^^^^^^^^^^^^ - -Only Visual C++ and C# projects may be generated. Other types of -projects (JavaScript, Database, Website, etc.) are not supported. - Toolset Selection ^^^^^^^^^^^^^^^^^ diff --git a/Help/generator/Visual Studio 12 2013.rst b/Help/generator/Visual Studio 12 2013.rst index 03f7586..8b4c162 100644 --- a/Help/generator/Visual Studio 12 2013.rst +++ b/Help/generator/Visual Studio 12 2013.rst @@ -3,18 +3,6 @@ Visual Studio 12 2013 Generates Visual Studio 12 (VS 2013) project files. -The :variable:`CMAKE_GENERATOR_PLATFORM` variable may be set -to specify a target platform name (architecture). - -For compatibility with CMake versions prior to 3.1, one may specify -a target platform name optionally at the end of this generator name: - -``Visual Studio 12 2013 Win64`` - Specify target platform ``x64``. - -``Visual Studio 12 2013 ARM`` - Specify target platform ``ARM``. - For compatibility with CMake versions prior to 3.0, one may specify this generator using the name "Visual Studio 12" without the year component. @@ -24,6 +12,27 @@ Project Types Only Visual C++ and C# projects may be generated. Other types of projects (JavaScript, Powershell, Python, etc.) are not supported. +Platform Selection +^^^^^^^^^^^^^^^^^^ + +The :variable:`CMAKE_GENERATOR_PLATFORM` variable may be set, perhaps +via the :manual:`cmake(1)` ``-A`` option, to specify a target platform +name (architecture). For example: + +* ``cmake -G "Visual Studio 12 2013" -A Win32`` +* ``cmake -G "Visual Studio 12 2013" -A x64`` +* ``cmake -G "Visual Studio 12 2013" -A ARM`` + +For compatibility with CMake versions prior to 3.1, one may specify +a target platform name optionally at the end of the generator name. +This is supported only for: + +``Visual Studio 12 2013 Win64`` + Specify target platform ``x64``. + +``Visual Studio 12 2013 ARM`` + Specify target platform ``ARM``. + Toolset Selection ^^^^^^^^^^^^^^^^^ diff --git a/Help/generator/Visual Studio 14 2015.rst b/Help/generator/Visual Studio 14 2015.rst index e55bc73..917d8e5 100644 --- a/Help/generator/Visual Studio 14 2015.rst +++ b/Help/generator/Visual Studio 14 2015.rst @@ -3,11 +3,26 @@ Visual Studio 14 2015 Generates Visual Studio 14 (VS 2015) project files. -The :variable:`CMAKE_GENERATOR_PLATFORM` variable may be set -to specify a target platform name (architecture). +Project Types +^^^^^^^^^^^^^ + +Only Visual C++ and C# projects may be generated. Other types of +projects (JavaScript, Powershell, Python, etc.) are not supported. + +Platform Selection +^^^^^^^^^^^^^^^^^^ + +The :variable:`CMAKE_GENERATOR_PLATFORM` variable may be set, perhaps +via the :manual:`cmake(1)` ``-A`` option, to specify a target platform +name (architecture). For example: + +* ``cmake -G "Visual Studio 14 2015" -A Win32`` +* ``cmake -G "Visual Studio 14 2015" -A x64`` +* ``cmake -G "Visual Studio 14 2015" -A ARM`` For compatibility with CMake versions prior to 3.1, one may specify -a target platform name optionally at the end of this generator name: +a target platform name optionally at the end of the generator name. +This is supported only for: ``Visual Studio 14 2015 Win64`` Specify target platform ``x64``. @@ -15,12 +30,6 @@ a target platform name optionally at the end of this generator name: ``Visual Studio 14 2015 ARM`` Specify target platform ``ARM``. -Project Types -^^^^^^^^^^^^^ - -Only Visual C++ and C# projects may be generated. Other types of -projects (JavaScript, Powershell, Python, etc.) are not supported. - Toolset Selection ^^^^^^^^^^^^^^^^^ diff --git a/Help/generator/Visual Studio 15 2017.rst b/Help/generator/Visual Studio 15 2017.rst index 809be4b..42a3bb6 100644 --- a/Help/generator/Visual Studio 15 2017.rst +++ b/Help/generator/Visual Studio 15 2017.rst @@ -3,18 +3,6 @@ Visual Studio 15 2017 Generates Visual Studio 15 (VS 2017) project files. -The :variable:`CMAKE_GENERATOR_PLATFORM` variable may be set -to specify a target platform name (architecture). - -For compatibility with CMake versions prior to 3.1, one may specify -a target platform name optionally at the end of this generator name: - -``Visual Studio 15 2017 Win64`` - Specify target platform ``x64``. - -``Visual Studio 15 2017 ARM`` - Specify target platform ``ARM``. - Project Types ^^^^^^^^^^^^^ @@ -37,6 +25,28 @@ one of the instances, that instance will be used. Otherwise, if more than one instance is installed we do not define which one is chosen by default. +Platform Selection +^^^^^^^^^^^^^^^^^^ + +The :variable:`CMAKE_GENERATOR_PLATFORM` variable may be set, perhaps +via the :manual:`cmake(1)` ``-A`` option, to specify a target platform +name (architecture). For example: + +* ``cmake -G "Visual Studio 15 2017" -A Win32`` +* ``cmake -G "Visual Studio 15 2017" -A x64`` +* ``cmake -G "Visual Studio 15 2017" -A ARM`` +* ``cmake -G "Visual Studio 15 2017" -A ARM64`` + +For compatibility with CMake versions prior to 3.1, one may specify +a target platform name optionally at the end of the generator name. +This is supported only for: + +``Visual Studio 15 2017 Win64`` + Specify target platform ``x64``. + +``Visual Studio 15 2017 ARM`` + Specify target platform ``ARM``. + Toolset Selection ^^^^^^^^^^^^^^^^^ diff --git a/Help/generator/Visual Studio 9 2008.rst b/Help/generator/Visual Studio 9 2008.rst index 40471b9..a29033f 100644 --- a/Help/generator/Visual Studio 9 2008.rst +++ b/Help/generator/Visual Studio 9 2008.rst @@ -3,11 +3,22 @@ Visual Studio 9 2008 Generates Visual Studio 9 2008 project files. -The :variable:`CMAKE_GENERATOR_PLATFORM` variable may be set -to specify a target platform name. +Platform Selection +^^^^^^^^^^^^^^^^^^ + +The :variable:`CMAKE_GENERATOR_PLATFORM` variable may be set, perhaps +via the :manual:`cmake(1)` ``-A`` option, to specify a target platform +name (architecture). For example: + +* ``cmake -G "Visual Studio 9 2008" -A Win32`` +* ``cmake -G "Visual Studio 9 2008" -A x64`` +* ``cmake -G "Visual Studio 9 2008" -A Itanium`` +* ``cmake -G "Visual Studio 9 2008" -A `` + (Specify a target platform matching a Windows CE SDK name.) For compatibility with CMake versions prior to 3.1, one may specify -a target platform name optionally at the end of this generator name: +a target platform name optionally at the end of the generator name. +This is supported only for: ``Visual Studio 9 2008 Win64`` Specify target platform ``x64``. https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=22aa6b67b41808bb9c27aeb0f8f662cd81466843 commit 22aa6b67b41808bb9c27aeb0f8f662cd81466843 Author: Brad King AuthorDate: Mon Sep 24 09:21:29 2018 -0400 Commit: Brad King CommitDate: Mon Sep 24 17:29:15 2018 -0400 cmListFileCache: Refactor cmListFileBacktrace internals Replace use of raw pointers and explicit reference counting with `std::shared_ptr<>`. Use a discriminated union to store either the bottom level or a call/file context in each heap-allocated entry. This avoids storing a copy of the bottom in every `cmListFileBacktrace` instance and shrinks the structure to a single `shared_ptr`. diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx index b468257..e465e1a 100644 --- a/Source/cmListFileCache.cxx +++ b/Source/cmListFileCache.cxx @@ -11,6 +11,7 @@ #include #include +#include #include cmCommandContext::cmCommandName& cmCommandContext::cmCommandName::operator=( @@ -285,91 +286,66 @@ bool cmListFileParser::AddArgument(cmListFileLexer_Token* token, return true; } -struct cmListFileBacktrace::Entry : public cmListFileContext +// We hold either the bottom scope of a directory or a call/file context. +// Discriminate these cases via the parent pointer. +struct cmListFileBacktrace::Entry { - Entry(cmListFileContext const& lfc, Entry* up) - : cmListFileContext(lfc) - , Up(up) - , RefCount(0) + Entry(cmStateSnapshot bottom) + : Bottom(bottom) { - if (this->Up) { - this->Up->Ref(); - } } - ~Entry() + + Entry(std::shared_ptr parent, cmListFileContext lfc) + : Context(std::move(lfc)) + , Parent(std::move(parent)) { - if (this->Up) { - this->Up->Unref(); - } } - void Ref() { ++this->RefCount; } - void Unref() + + ~Entry() { - if (--this->RefCount == 0) { - delete this; + if (this->Parent) { + this->Context.~cmListFileContext(); + } else { + this->Bottom.~cmStateSnapshot(); } } - Entry* Up; - unsigned int RefCount; -}; -cmListFileBacktrace::cmListFileBacktrace(cmStateSnapshot const& bottom, - Entry* up, - cmListFileContext const& lfc) - : Bottom(bottom) - , Cur(new Entry(lfc, up)) -{ - assert(this->Bottom.IsValid()); - this->Cur->Ref(); -} - -cmListFileBacktrace::cmListFileBacktrace(cmStateSnapshot const& bottom, - Entry* cur) - : Bottom(bottom) - , Cur(cur) -{ - if (this->Cur) { - assert(this->Bottom.IsValid()); - this->Cur->Ref(); - } -} + bool IsBottom() const { return !this->Parent; } -cmListFileBacktrace::cmListFileBacktrace() - : Bottom() - , Cur(nullptr) -{ -} + union + { + cmStateSnapshot Bottom; + cmListFileContext Context; + }; + std::shared_ptr Parent; +}; cmListFileBacktrace::cmListFileBacktrace(cmStateSnapshot const& snapshot) - : Bottom(snapshot.GetCallStackBottom()) - , Cur(nullptr) + : TopEntry(std::make_shared(snapshot.GetCallStackBottom())) { } -cmListFileBacktrace::cmListFileBacktrace(cmListFileBacktrace const& r) - : Bottom(r.Bottom) - , Cur(r.Cur) +cmListFileBacktrace::cmListFileBacktrace(std::shared_ptr parent, + cmListFileContext const& lfc) + : TopEntry(std::make_shared(std::move(parent), lfc)) { - if (this->Cur) { - assert(this->Bottom.IsValid()); - this->Cur->Ref(); - } } -cmListFileBacktrace& cmListFileBacktrace::operator=( - cmListFileBacktrace const& r) +cmListFileBacktrace::cmListFileBacktrace(std::shared_ptr top) + : TopEntry(std::move(top)) { - cmListFileBacktrace tmp(r); - std::swap(this->Cur, tmp.Cur); - std::swap(this->Bottom, tmp.Bottom); - return *this; } -cmListFileBacktrace::~cmListFileBacktrace() +cmStateSnapshot cmListFileBacktrace::GetBottom() const { - if (this->Cur) { - this->Cur->Unref(); + cmStateSnapshot bottom; + if (Entry const* cur = this->TopEntry.get()) { + while (Entry const* parent = cur->Parent.get()) { + cur = parent; + } + bottom = cur->Bottom; } + return bottom; } cmListFileBacktrace cmListFileBacktrace::Push(std::string const& file) const @@ -380,54 +356,61 @@ cmListFileBacktrace cmListFileBacktrace::Push(std::string const& file) const // skipped during call stack printing. cmListFileContext lfc; lfc.FilePath = file; - return cmListFileBacktrace(this->Bottom, this->Cur, lfc); + return this->Push(lfc); } cmListFileBacktrace cmListFileBacktrace::Push( cmListFileContext const& lfc) const { - return cmListFileBacktrace(this->Bottom, this->Cur, lfc); + assert(this->TopEntry); + assert(!this->TopEntry->IsBottom() || this->TopEntry->Bottom.IsValid()); + return cmListFileBacktrace(this->TopEntry, lfc); } cmListFileBacktrace cmListFileBacktrace::Pop() const { - assert(this->Cur); - return cmListFileBacktrace(this->Bottom, this->Cur->Up); + assert(this->TopEntry); + assert(!this->TopEntry->IsBottom()); + return cmListFileBacktrace(this->TopEntry->Parent); } cmListFileContext const& cmListFileBacktrace::Top() const { - if (this->Cur) { - return *this->Cur; - } - static cmListFileContext const empty; - return empty; + assert(this->TopEntry); + return this->TopEntry->Context; } void cmListFileBacktrace::PrintTitle(std::ostream& out) const { - if (!this->Cur) { + // The title exists only if we have a call on top of the bottom. + if (!this->TopEntry || this->TopEntry->IsBottom()) { return; } - cmOutputConverter converter(this->Bottom); - cmListFileContext lfc = *this->Cur; - if (!this->Bottom.GetState()->GetIsInTryCompile()) { + cmListFileContext lfc = this->TopEntry->Context; + cmStateSnapshot bottom = this->GetBottom(); + cmOutputConverter converter(bottom); + if (!bottom.GetState()->GetIsInTryCompile()) { lfc.FilePath = converter.ConvertToRelativePath( - this->Bottom.GetState()->GetSourceDirectory(), lfc.FilePath); + bottom.GetState()->GetSourceDirectory(), lfc.FilePath); } out << (lfc.Line ? " at " : " in ") << lfc; } void cmListFileBacktrace::PrintCallStack(std::ostream& out) const { - if (!this->Cur || !this->Cur->Up) { + // The call stack exists only if we have at least two calls on top + // of the bottom. + if (!this->TopEntry || this->TopEntry->IsBottom() || + this->TopEntry->Parent->IsBottom()) { return; } bool first = true; - cmOutputConverter converter(this->Bottom); - for (Entry* i = this->Cur->Up; i; i = i->Up) { - if (i->Name.empty()) { + cmStateSnapshot bottom = this->GetBottom(); + cmOutputConverter converter(bottom); + for (Entry const* cur = this->TopEntry->Parent.get(); !cur->IsBottom(); + cur = cur->Parent.get()) { + if (cur->Context.Name.empty()) { // Skip this whole-file scope. When we get here we already will // have printed a more-specific context within the file. continue; @@ -436,10 +419,10 @@ void cmListFileBacktrace::PrintCallStack(std::ostream& out) const first = false; out << "Call Stack (most recent call first):\n"; } - cmListFileContext lfc = *i; - if (!this->Bottom.GetState()->GetIsInTryCompile()) { + cmListFileContext lfc = cur->Context; + if (!bottom.GetState()->GetIsInTryCompile()) { lfc.FilePath = converter.ConvertToRelativePath( - this->Bottom.GetState()->GetSourceDirectory(), lfc.FilePath); + bottom.GetState()->GetSourceDirectory(), lfc.FilePath); } out << " " << lfc << "\n"; } @@ -448,16 +431,19 @@ void cmListFileBacktrace::PrintCallStack(std::ostream& out) const size_t cmListFileBacktrace::Depth() const { size_t depth = 0; - if (this->Cur == nullptr) { - return 0; - } - - for (Entry* i = this->Cur->Up; i; i = i->Up) { - depth++; + if (Entry const* cur = this->TopEntry.get()) { + for (; !cur->IsBottom(); cur = cur->Parent.get()) { + ++depth; + } } return depth; } +bool cmListFileBacktrace::Empty() const +{ + return !this->TopEntry || this->TopEntry->IsBottom(); +} + std::ostream& operator<<(std::ostream& os, cmListFileContext const& lfc) { os << lfc.FilePath; diff --git a/Source/cmListFileCache.h b/Source/cmListFileCache.h index 70f7166..2c91f7a 100644 --- a/Source/cmListFileCache.h +++ b/Source/cmListFileCache.h @@ -6,6 +6,7 @@ #include "cmConfigure.h" // IWYU pragma: keep #include +#include // IWYU pragma: keep #include #include #include @@ -115,18 +116,20 @@ public: // Default-constructed backtrace may not be used until after // set via assignment from a backtrace constructed with a // valid snapshot. - cmListFileBacktrace(); + cmListFileBacktrace() = default; // Construct an empty backtrace whose bottom sits in the directory // indicated by the given valid snapshot. cmListFileBacktrace(cmStateSnapshot const& snapshot); - // Backtraces may be copied and assigned as values. - cmListFileBacktrace(cmListFileBacktrace const& r); - cmListFileBacktrace& operator=(cmListFileBacktrace const& r); - ~cmListFileBacktrace(); + // Backtraces may be copied, moved, and assigned as values. + cmListFileBacktrace(cmListFileBacktrace const&) = default; + cmListFileBacktrace(cmListFileBacktrace&&) noexcept = default; + cmListFileBacktrace& operator=(cmListFileBacktrace const&) = default; + cmListFileBacktrace& operator=(cmListFileBacktrace&&) noexcept = default; + ~cmListFileBacktrace() = default; - cmStateSnapshot GetBottom() const { return this->Bottom; } + cmStateSnapshot GetBottom() const; // Get a backtrace with the given file scope added to the top. // May not be called until after construction with a valid snapshot. @@ -153,14 +156,15 @@ public: // Get the number of 'frames' in this backtrace size_t Depth() const; + // Return true if this backtrace is empty. + bool Empty() const; + private: struct Entry; - - cmStateSnapshot Bottom; - Entry* Cur; - cmListFileBacktrace(cmStateSnapshot const& bottom, Entry* up, + std::shared_ptr TopEntry; + cmListFileBacktrace(std::shared_ptr parent, cmListFileContext const& lfc); - cmListFileBacktrace(cmStateSnapshot const& bottom, Entry* cur); + cmListFileBacktrace(std::shared_ptr top); }; struct cmListFile https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=1fe0d72eb6aef12148be0b37d73cf31fbd5f9ca0 commit 1fe0d72eb6aef12148be0b37d73cf31fbd5f9ca0 Author: Brad King AuthorDate: Mon Sep 24 17:28:25 2018 -0400 Commit: Brad King CommitDate: Mon Sep 24 17:29:15 2018 -0400 clang-tidy: exclude 'misc-noexcept-move-constructor' Our installation is producing false positives on move constructors and assignment operators that are clearly marked `noexcept`. diff --git a/.clang-tidy b/.clang-tidy index 8d79b0c..ebe3c20 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -5,6 +5,7 @@ misc-*,\ -misc-incorrect-roundings,\ -misc-macro-parentheses,\ -misc-misplaced-widening-cast,\ +-misc-noexcept-move-constructor,\ -misc-static-assert,\ modernize-*,\ -modernize-deprecated-headers,\ ----------------------------------------------------------------------- Summary of changes: .clang-tidy | 1 + Help/generator/Visual Studio 10 2010.rst | 33 ++++--- Help/generator/Visual Studio 11 2012.rst | 35 ++++--- Help/generator/Visual Studio 12 2013.rst | 33 ++++--- Help/generator/Visual Studio 14 2015.rst | 27 +++-- Help/generator/Visual Studio 15 2017.rst | 34 ++++--- Help/generator/Visual Studio 9 2008.rst | 17 +++- Source/cmListFileCache.cxx | 164 ++++++++++++++----------------- Source/cmListFileCache.h | 26 ++--- 9 files changed, 210 insertions(+), 160 deletions(-) hooks/post-receive -- CMake From kwrobot at kitware.com Wed Sep 26 00:05:04 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Wed, 26 Sep 2018 00:05:04 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-715-g5abe452 Message-ID: <20180926040504.EC190125558@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 5abe45270edd3403c09f279dba2c3adf388e64a6 (commit) from 55a5b56e083c4c2d4e768212422991a22569ecb4 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=5abe45270edd3403c09f279dba2c3adf388e64a6 commit 5abe45270edd3403c09f279dba2c3adf388e64a6 Author: Kitware Robot AuthorDate: Wed Sep 26 00:01:09 2018 -0400 Commit: Kitware Robot CommitDate: Wed Sep 26 00:01:09 2018 -0400 CMake Nightly Date Stamp diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 360b561..1f51aa4 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 12) -set(CMake_VERSION_PATCH 20180925) +set(CMake_VERSION_PATCH 20180926) #set(CMake_VERSION_RC 1) ----------------------------------------------------------------------- Summary of changes: Source/CMakeVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) hooks/post-receive -- CMake From kwrobot at kitware.com Wed Sep 26 06:55:11 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Wed, 26 Sep 2018 06:55:11 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-721-gb16b254 Message-ID: <20180926105512.8EE0A113696@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via b16b25484545e8186eb8d52760386b6ab531b9c2 (commit) via 71a68ece89b10189f6d872b8a075031072ed58bf (commit) via 830d4760db5a2086e8a83b0573a03bf4abe39bbe (commit) via d8a3939aef44f6176ac3ec03fb8cdd396fa96ca3 (commit) via 42fbff45e4529d3cfbeb3cbcef8c5616df3f06f1 (commit) via 66ab24a4c54fcd5956f9eccfdb0fb60bad858ef3 (commit) from 5abe45270edd3403c09f279dba2c3adf388e64a6 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=b16b25484545e8186eb8d52760386b6ab531b9c2 commit b16b25484545e8186eb8d52760386b6ab531b9c2 Merge: 71a68ec d8a3939 Author: Brad King AuthorDate: Wed Sep 26 10:51:59 2018 +0000 Commit: Kitware Robot CommitDate: Wed Sep 26 06:52:06 2018 -0400 Merge topic 'dbgsym-packaging' d8a3939aef CPack/Deb: Add ability to split out debug symbols into .ddeb package 42fbff45e4 CPack/Deb: Use CMAKE_COMMAND to set the environment 66ab24a4c5 Help: Fix typo Acked-by: Kitware Robot Merge-request: !2399 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=71a68ece89b10189f6d872b8a075031072ed58bf commit 71a68ece89b10189f6d872b8a075031072ed58bf Merge: 5abe452 830d476 Author: Brad King AuthorDate: Wed Sep 26 10:49:55 2018 +0000 Commit: Kitware Robot CommitDate: Wed Sep 26 06:50:19 2018 -0400 Merge topic 'rel-linux64' 830d4760db Utilities/Release: Build with gcc 8.2 on Linux Acked-by: Kitware Robot Merge-request: !2414 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=830d4760db5a2086e8a83b0573a03bf4abe39bbe commit 830d4760db5a2086e8a83b0573a03bf4abe39bbe Author: Brad King AuthorDate: Tue Sep 25 14:04:10 2018 -0400 Commit: Brad King CommitDate: Tue Sep 25 16:53:11 2018 -0400 Utilities/Release: Build with gcc 8.2 on Linux Also add a binutils-2.31 to CMAKE_PREFIX_PATH in the environment so that tests that look for them with `find_program` can find a newer version. This is needed for the build id support in readelf. diff --git a/Utilities/Release/linux64_release.cmake b/Utilities/Release/linux64_release.cmake index f2ca2d5..dc34120 100644 --- a/Utilities/Release/linux64_release.cmake +++ b/Utilities/Release/linux64_release.cmake @@ -3,8 +3,8 @@ set(BOOTSTRAP_ARGS "--docdir=doc/cmake") set(HOST linux64) set(MAKE_PROGRAM "make") set(CPACK_BINARY_GENERATORS "STGZ TGZ") -set(CC /opt/gcc-6.1.0/bin/gcc) -set(CXX /opt/gcc-6.1.0/bin/g++) +set(CC /opt/gcc-8.2.0/bin/gcc) +set(CXX /opt/gcc-8.2.0/bin/g++) set(CFLAGS "") set(CXXFLAGS "") set(qt_prefix "/home/kitware/qt-5.7.0") @@ -41,6 +41,9 @@ CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL:STRING=3 CMAKE_PREFIX_PATH:STRING=${qt_prefix} CMake_QT_STATIC_QXcbIntegrationPlugin_LIBRARIES:STRING=${qt_xcb_libs} ") +set(ENV [[ +export CMAKE_PREFIX_PATH=/opt/binutils-2.31 +]]) # Exclude Qt5 tests because our Qt5 is static. set(EXTRA_CTEST_ARGS "-E Qt5") https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=d8a3939aef44f6176ac3ec03fb8cdd396fa96ca3 commit d8a3939aef44f6176ac3ec03fb8cdd396fa96ca3 Author: Andrew Fuller AuthorDate: Tue Sep 18 10:57:27 2018 -0700 Commit: Andrew Fuller CommitDate: Fri Sep 21 20:19:31 2018 +0000 CPack/Deb: Add ability to split out debug symbols into .ddeb package diff --git a/Help/cpack_gen/deb.rst b/Help/cpack_gen/deb.rst index 37d750d..26021cc 100644 --- a/Help/cpack_gen/deb.rst +++ b/Help/cpack_gen/deb.rst @@ -518,6 +518,26 @@ List of CPack Deb generator specific variables: This value is not interpreted. It is possible to pass an optional revision number of the referenced source package as well. +Packaging of debug information +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Dbgsym packages contain debug symbols for debugging packaged binaries. + +Dbgsym packaging has its own set of variables: + +.. variable:: CPACK_DEBIAN_DEBUGINFO_PACKAGE + CPACK_DEBIAN__DEBUGINFO_PACKAGE + + Enable generation of dbgsym .ddeb package(s). + + * Mandatory : NO + * Default : OFF + +.. note:: + + Binaries must contain debug symbols before packaging so use either ``Debug`` + or ``RelWithDebInfo`` for :variable:`CMAKE_BUILD_TYPE` variable value. + Building Debian packages on Windows ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/Help/release/dev/cpack-deb-dbgsym-ddeb.rst b/Help/release/dev/cpack-deb-dbgsym-ddeb.rst new file mode 100644 index 0000000..dc3e96e --- /dev/null +++ b/Help/release/dev/cpack-deb-dbgsym-ddeb.rst @@ -0,0 +1,6 @@ +cpack-deb-dbgsym-ddeb +--------------------- + +* The :cpack_gen:`CPack Deb Generator` learned to split debug symbols into + a corresponding .ddeb package when ``CPACK_DEBIAN_DEBUGINFO_PACKAGE`` is + set. diff --git a/Modules/Internal/CPack/CPackDeb.cmake b/Modules/Internal/CPack/CPackDeb.cmake index 2eb2fdf..3042a16 100644 --- a/Modules/Internal/CPack/CPackDeb.cmake +++ b/Modules/Internal/CPack/CPackDeb.cmake @@ -64,6 +64,8 @@ function(cpack_deb_prepare_package_vars) endif() set(WDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_DEB_PACKAGE_COMPONENT_PART_PATH}") + set(DBGSYMDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_DEB_PACKAGE_COMPONENT_PART_PATH}-dbgsym") + file(REMOVE_RECURSE "${DBGSYMDIR}") # per component automatic discover: some of the component might not have # binaries. @@ -80,7 +82,10 @@ function(cpack_deb_prepare_package_vars) endif() endif() - if(CPACK_DEBIAN_PACKAGE_SHLIBDEPS OR CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS) + cpack_deb_variable_fallback("CPACK_DEBIAN_DEBUGINFO_PACKAGE" + "CPACK_DEBIAN_${_local_component_name}_DEBUGINFO_PACKAGE" + "CPACK_DEBIAN_DEBUGINFO_PACKAGE") + if(CPACK_DEBIAN_PACKAGE_SHLIBDEPS OR CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS OR CPACK_DEBIAN_DEBUGINFO_PACKAGE) # Generating binary list - Get type of all install files file(GLOB_RECURSE FILE_PATHS_ LIST_DIRECTORIES false RELATIVE "${WDIR}" "${WDIR}/*") @@ -114,6 +119,81 @@ function(cpack_deb_prepare_package_vars) string(REGEX MATCH "(^.*):" _FILE_NAME "${_FILE}") list(APPEND CPACK_DEB_SHARED_OBJECT_FILES "${CMAKE_MATCH_1}") endif() + if(_FILE MATCHES "ELF.*not stripped") + string(REGEX MATCH "(^.*):" _FILE_NAME "${_FILE}") + list(APPEND CPACK_DEB_UNSTRIPPED_FILES "${CMAKE_MATCH_1}") + endif() + endforeach() + endif() + + find_program(READELF_EXECUTABLE NAMES readelf) + + if(CPACK_DEBIAN_DEBUGINFO_PACKAGE AND CPACK_DEB_UNSTRIPPED_FILES) + find_program(OBJCOPY_EXECUTABLE NAMES objcopy) + + if(NOT OBJCOPY_EXECUTABLE) + message(FATAL_ERROR "debuginfo packages require the objcopy tool") + endif() + if(NOT READELF_EXECUTABLE) + message(FATAL_ERROR "debuginfo packages require the readelf tool") + endif() + + file(RELATIVE_PATH _DBGSYM_ROOT "${CPACK_TEMPORARY_DIRECTORY}" "${DBGSYMDIR}") + foreach(_FILE IN LISTS CPACK_DEB_UNSTRIPPED_FILES) + + # Get the file's Build ID + execute_process(COMMAND env LC_ALL=C ${READELF_EXECUTABLE} -n "${_FILE}" + WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}" + OUTPUT_VARIABLE READELF_OUTPUT + RESULT_VARIABLE READELF_RESULT + ERROR_VARIABLE READELF_ERROR + OUTPUT_STRIP_TRAILING_WHITESPACE ) + if(NOT READELF_RESULT EQUAL 0) + message(FATAL_ERROR "CPackDeb: readelf: '${READELF_ERROR}';\n" + "executed command: '${READELF_EXECUTABLE} -n ${_FILE}'") + endif() + if(READELF_OUTPUT MATCHES "Build ID: ([0-9a-zA-Z][0-9a-zA-Z])([0-9a-zA-Z]*)") + set(_BUILD_ID_START ${CMAKE_MATCH_1}) + set(_BUILD_ID_REMAINING ${CMAKE_MATCH_2}) + list(APPEND BUILD_IDS ${_BUILD_ID_START}${_BUILD_ID_REMAINING}) + else() + message(FATAL_ERROR "Unable to determine Build ID for ${_FILE}") + endif() + + # Split out the debug symbols from the binaries + set(_FILE_DBGSYM ${_DBGSYM_ROOT}/usr/lib/debug/.build-id/${_BUILD_ID_START}/${_BUILD_ID_REMAINING}.debug) + get_filename_component(_OUT_DIR "${_FILE_DBGSYM}" DIRECTORY) + file(MAKE_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}/${_OUT_DIR}") + execute_process(COMMAND ${OBJCOPY_EXECUTABLE} --only-keep-debug "${_FILE}" "${_FILE_DBGSYM}" + WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}" + OUTPUT_VARIABLE OBJCOPY_OUTPUT + RESULT_VARIABLE OBJCOPY_RESULT + ERROR_VARIABLE OBJCOPY_ERROR + OUTPUT_STRIP_TRAILING_WHITESPACE ) + if(NOT OBJCOPY_RESULT EQUAL 0) + message(FATAL_ERROR "CPackDeb: objcopy: '${OBJCOPY_ERROR}';\n" + "executed command: '${OBJCOPY_EXECUTABLE} --only-keep-debug ${_FILE} ${_FILE_DBGSYM}'") + endif() + execute_process(COMMAND ${OBJCOPY_EXECUTABLE} --strip-unneeded ${_FILE} + WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}" + OUTPUT_VARIABLE OBJCOPY_OUTPUT + RESULT_VARIABLE OBJCOPY_RESULT + ERROR_VARIABLE OBJCOPY_ERROR + OUTPUT_STRIP_TRAILING_WHITESPACE ) + if(NOT OBJCOPY_RESULT EQUAL 0) + message(FATAL_ERROR "CPackDeb: objcopy: '${OBJCOPY_ERROR}';\n" + "executed command: '${OBJCOPY_EXECUTABLE} --strip-debug ${_FILE}'") + endif() + execute_process(COMMAND ${OBJCOPY_EXECUTABLE} --add-gnu-debuglink=${_FILE_DBGSYM} ${_FILE} + WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}" + OUTPUT_VARIABLE OBJCOPY_OUTPUT + RESULT_VARIABLE OBJCOPY_RESULT + ERROR_VARIABLE OBJCOPY_ERROR + OUTPUT_STRIP_TRAILING_WHITESPACE ) + if(NOT OBJCOPY_RESULT EQUAL 0) + message(FATAL_ERROR "CPackDeb: objcopy: '${OBJCOPY_ERROR}';\n" + "executed command: '${OBJCOPY_EXECUTABLE} --add-gnu-debuglink=${_FILE_DBGSYM} ${_FILE}'") + endif() endforeach() endif() @@ -450,8 +530,6 @@ function(cpack_deb_prepare_package_vars) set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS_POLICY "=") endif() - find_program(READELF_EXECUTABLE NAMES readelf) - if(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS) if(READELF_EXECUTABLE) foreach(_FILE IN LISTS CPACK_DEB_SHARED_OBJECT_FILES) @@ -507,18 +585,24 @@ function(cpack_deb_prepare_package_vars) # _-_.deb set(CPACK_OUTPUT_FILE_NAME "${CPACK_DEBIAN_PACKAGE_NAME}_${CPACK_DEBIAN_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}.deb") + set(CPACK_DBGSYM_OUTPUT_FILE_NAME + "${CPACK_DEBIAN_PACKAGE_NAME}-dbgsym_${CPACK_DEBIAN_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}.ddeb") else() if(NOT CPACK_DEBIAN_FILE_NAME MATCHES ".*\\.(deb|ipk)") message(FATAL_ERROR "'${CPACK_DEBIAN_FILE_NAME}' is not a valid DEB package file name as it must end with '.deb' or '.ipk'!") endif() set(CPACK_OUTPUT_FILE_NAME "${CPACK_DEBIAN_FILE_NAME}") + string(REGEX REPLACE "\.deb$" "-dbgsym.ddeb" CPACK_DBGSYM_OUTPUT_FILE_NAME "${CPACK_DEBIAN_FILE_NAME}") endif() set(CPACK_TEMPORARY_PACKAGE_FILE_NAME "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_OUTPUT_FILE_NAME}") get_filename_component(BINARY_DIR "${CPACK_OUTPUT_FILE_PATH}" DIRECTORY) set(CPACK_OUTPUT_FILE_PATH "${BINARY_DIR}/${CPACK_OUTPUT_FILE_NAME}") - endif() # else() back compatibility - don't change the name + else() + # back compatibility - don't change the name + string(REGEX REPLACE "\.deb$" "-dbgsym.ddeb" CPACK_DBGSYM_OUTPUT_FILE_NAME "${CPACK_OUTPUT_FILE_NAME}") + endif() # Print out some debug information if we were asked for that if(CPACK_DEBIAN_PACKAGE_DEBUG) @@ -579,6 +663,14 @@ function(cpack_deb_prepare_package_vars) set(GEN_CPACK_DEBIAN_GENERATE_POSTINST "${CPACK_DEBIAN_GENERATE_POSTINST}" PARENT_SCOPE) set(GEN_CPACK_DEBIAN_GENERATE_POSTRM "${CPACK_DEBIAN_GENERATE_POSTRM}" PARENT_SCOPE) set(GEN_WDIR "${WDIR}" PARENT_SCOPE) + + set(GEN_CPACK_DEBIAN_DEBUGINFO_PACKAGE "${CPACK_DEBIAN_DEBUGINFO_PACKAGE}" PARENT_SCOPE) + if(BUILD_IDS) + set(GEN_DBGSYMDIR "${DBGSYMDIR}" PARENT_SCOPE) + set(GEN_CPACK_DBGSYM_OUTPUT_FILE_NAME "${CPACK_DBGSYM_OUTPUT_FILE_NAME}" PARENT_SCOPE) + string(REPLACE ";" " " BUILD_IDS "${BUILD_IDS}") + set(GEN_BUILD_IDS "${BUILD_IDS}" PARENT_SCOPE) + endif() endfunction() cpack_deb_prepare_package_vars() diff --git a/Source/CPack/cmCPackDebGenerator.cxx b/Source/CPack/cmCPackDebGenerator.cxx index 972fe6f..ea0ee58 100644 --- a/Source/CPack/cmCPackDebGenerator.cxx +++ b/Source/CPack/cmCPackDebGenerator.cxx @@ -12,11 +12,430 @@ #include "cm_sys_stat.h" #include "cmsys/Glob.hxx" +#include #include #include #include #include +namespace { + +class DebGenerator +{ +public: + DebGenerator(cmCPackLog* logger, std::string const& outputName, + std::string const& workDir, std::string const& topLevelDir, + std::string const& temporaryDir, + const char* debianCompressionType, + const char* debianArchiveType, + std::map const& controlValues, + bool genShLibs, std::string const& shLibsFilename, + bool genPostInst, std::string const& postInst, bool genPostRm, + std::string const& postRm, const char* controlExtra, + bool permissionStrctPolicy, + std::vector const& packageFiles); + + bool generate() const; + +private: + void generateDebianBinaryFile() const; + void generateControlFile() const; + bool generateDataTar() const; + std::string generateMD5File() const; + bool generateControlTar(std::string const& md5Filename) const; + bool generateDeb() const; + + cmCPackLog* Logger; + const std::string OutputName; + const std::string WorkDir; + std::string CompressionSuffix; + const std::string TopLevelDir; + const std::string TemporaryDir; + const char* DebianArchiveType; + const std::map ControlValues; + const bool GenShLibs; + const std::string ShLibsFilename; + const bool GenPostInst; + const std::string PostInst; + const bool GenPostRm; + const std::string PostRm; + const char* ControlExtra; + const bool PermissionStrictPolicy; + const std::vector PackageFiles; + cmArchiveWrite::Compress TarCompressionType; +}; + +DebGenerator::DebGenerator( + cmCPackLog* logger, std::string const& outputName, + std::string const& workDir, std::string const& topLevelDir, + std::string const& temporaryDir, const char* debianCompressionType, + const char* debianArchiveType, + std::map const& controlValues, bool genShLibs, + std::string const& shLibsFilename, bool genPostInst, + std::string const& postInst, bool genPostRm, std::string const& postRm, + const char* controlExtra, bool permissionStrictPolicy, + std::vector const& packageFiles) + : Logger(logger) + , OutputName(outputName) + , WorkDir(workDir) + , TopLevelDir(topLevelDir) + , TemporaryDir(temporaryDir) + , DebianArchiveType(debianArchiveType ? debianArchiveType : "paxr") + , ControlValues(controlValues) + , GenShLibs(genShLibs) + , ShLibsFilename(shLibsFilename) + , GenPostInst(genPostInst) + , PostInst(postInst) + , GenPostRm(genPostRm) + , PostRm(postRm) + , ControlExtra(controlExtra) + , PermissionStrictPolicy(permissionStrictPolicy) + , PackageFiles(packageFiles) +{ + if (!debianCompressionType) { + debianCompressionType = "gzip"; + } + + if (!strcmp(debianCompressionType, "lzma")) { + CompressionSuffix = ".lzma"; + TarCompressionType = cmArchiveWrite::CompressLZMA; + } else if (!strcmp(debianCompressionType, "xz")) { + CompressionSuffix = ".xz"; + TarCompressionType = cmArchiveWrite::CompressXZ; + } else if (!strcmp(debianCompressionType, "bzip2")) { + CompressionSuffix = ".bz2"; + TarCompressionType = cmArchiveWrite::CompressBZip2; + } else if (!strcmp(debianCompressionType, "gzip")) { + CompressionSuffix = ".gz"; + TarCompressionType = cmArchiveWrite::CompressGZip; + } else if (!strcmp(debianCompressionType, "none")) { + CompressionSuffix.clear(); + TarCompressionType = cmArchiveWrite::CompressNone; + } else { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Error unrecognized compression type: " + << debianCompressionType << std::endl); + } +} + +bool DebGenerator::generate() const +{ + generateDebianBinaryFile(); + generateControlFile(); + if (!generateDataTar()) { + return false; + } + std::string md5Filename = generateMD5File(); + if (!generateControlTar(md5Filename)) { + return false; + } + return generateDeb(); +} + +void DebGenerator::generateDebianBinaryFile() const +{ + // debian-binary file + const std::string dbfilename = WorkDir + "/debian-binary"; + cmGeneratedFileStream out(dbfilename); + out << "2.0"; + out << std::endl; // required for valid debian package +} + +void DebGenerator::generateControlFile() const +{ + std::string ctlfilename = WorkDir + "/control"; + + cmGeneratedFileStream out(ctlfilename); + for (auto const& kv : ControlValues) { + out << kv.first << ": " << kv.second << "\n"; + } + + unsigned long totalSize = 0; + { + std::string dirName = TemporaryDir; + dirName += '/'; + for (std::string const& file : PackageFiles) { + totalSize += cmSystemTools::FileLength(file); + } + } + out << "Installed-Size: " << (totalSize + 1023) / 1024 << "\n"; + out << std::endl; +} + +bool DebGenerator::generateDataTar() const +{ + std::string filename_data_tar = WorkDir + "/data.tar" + CompressionSuffix; + cmGeneratedFileStream fileStream_data_tar; + fileStream_data_tar.Open(filename_data_tar, false, true); + if (!fileStream_data_tar) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Error opening the file \"" + << filename_data_tar << "\" for writing" << std::endl); + return false; + } + cmArchiveWrite data_tar(fileStream_data_tar, TarCompressionType, + DebianArchiveType); + + // uid/gid should be the one of the root user, and this root user has + // always uid/gid equal to 0. + data_tar.SetUIDAndGID(0u, 0u); + data_tar.SetUNAMEAndGNAME("root", "root"); + + // now add all directories which have to be compressed + // collect all top level install dirs for that + // e.g. /opt/bin/foo, /usr/bin/bar and /usr/bin/baz would + // give /usr and /opt + size_t topLevelLength = WorkDir.length(); + cmCPackLogger(cmCPackLog::LOG_DEBUG, + "WDIR: \"" << WorkDir << "\", length = " << topLevelLength + << std::endl); + std::set orderedFiles; + + // we have to reconstruct the parent folders as well + + for (std::string currentPath : PackageFiles) { + while (currentPath != WorkDir) { + // the last one IS WorkDir, but we do not want this one: + // XXX/application/usr/bin/myprogram with GEN_WDIR=XXX/application + // should not add XXX/application + orderedFiles.insert(currentPath); + currentPath = cmSystemTools::CollapseCombinedPath(currentPath, ".."); + } + } + + for (std::string const& file : orderedFiles) { + cmCPackLogger(cmCPackLog::LOG_DEBUG, + "FILEIT: \"" << file << "\"" << std::endl); + std::string::size_type slashPos = file.find('/', topLevelLength + 1); + std::string relativeDir = + file.substr(topLevelLength, slashPos - topLevelLength); + cmCPackLogger(cmCPackLog::LOG_DEBUG, + "RELATIVEDIR: \"" << relativeDir << "\"" << std::endl); + +#ifdef WIN32 + std::string mode_t_adt_filename = file + ":cmake_mode_t"; + cmsys::ifstream permissionStream(mode_t_adt_filename.c_str()); + + mode_t permissions = 0; + + if (permissionStream) { + permissionStream >> std::oct >> permissions; + } + + if (permissions != 0) { + data_tar.SetPermissions(permissions); + } else if (cmSystemTools::FileIsDirectory(file)) { + data_tar.SetPermissions(0755); + } else { + data_tar.ClearPermissions(); + } +#endif + + // do not recurse because the loop will do it + if (!data_tar.Add(file, topLevelLength, ".", false)) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Problem adding file to tar:" + << std::endl + << "#top level directory: " << WorkDir << std::endl + << "#file: " << file << std::endl + << "#error:" << data_tar.GetError() << std::endl); + return false; + } + } + return true; +} + +std::string DebGenerator::generateMD5File() const +{ + std::string md5filename = WorkDir + "/md5sums"; + + cmGeneratedFileStream out(md5filename); + + std::string topLevelWithTrailingSlash = TemporaryDir; + topLevelWithTrailingSlash += '/'; + for (std::string const& file : PackageFiles) { + // hash only regular files + if (cmSystemTools::FileIsDirectory(file) || + cmSystemTools::FileIsSymlink(file)) { + continue; + } + + std::string output = + cmSystemTools::ComputeFileHash(file, cmCryptoHash::AlgoMD5); + if (output.empty()) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Problem computing the md5 of " << file << std::endl); + } + + output += " " + file + "\n"; + // debian md5sums entries are like this: + // 014f3604694729f3bf19263bac599765 usr/bin/ccmake + // thus strip the full path (with the trailing slash) + cmSystemTools::ReplaceString(output, topLevelWithTrailingSlash.c_str(), + ""); + out << output; + } + // each line contains a eol. + // Do not end the md5sum file with yet another (invalid) + return md5filename; +} + +bool DebGenerator::generateControlTar(std::string const& md5Filename) const +{ + std::string filename_control_tar = WorkDir + "/control.tar.gz"; + + cmGeneratedFileStream fileStream_control_tar; + fileStream_control_tar.Open(filename_control_tar, false, true); + if (!fileStream_control_tar) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Error opening the file \"" + << filename_control_tar << "\" for writing" << std::endl); + return false; + } + cmArchiveWrite control_tar(fileStream_control_tar, + cmArchiveWrite::CompressGZip, DebianArchiveType); + + // sets permissions and uid/gid for the files + control_tar.SetUIDAndGID(0u, 0u); + control_tar.SetUNAMEAndGNAME("root", "root"); + + /* permissions are set according to + https://www.debian.org/doc/debian-policy/ch-files.html#s-permissions-owners + and + https://lintian.debian.org/tags/control-file-has-bad-permissions.html + */ + const mode_t permission644 = 0644; + const mode_t permissionExecute = 0111; + const mode_t permission755 = permission644 | permissionExecute; + + // for md5sum and control (that we have generated here), we use 644 + // (RW-R--R--) + // so that deb lintian doesn't warn about it + control_tar.SetPermissions(permission644); + + // adds control and md5sums + if (!control_tar.Add(md5Filename, WorkDir.length(), ".") || + !control_tar.Add(WorkDir + "/control", WorkDir.length(), ".")) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Error adding file to tar:" + << std::endl + << "#top level directory: " << WorkDir << std::endl + << "#file: \"control\" or \"md5sums\"" << std::endl + << "#error:" << control_tar.GetError() << std::endl); + return false; + } + + // adds generated shlibs file + if (GenShLibs) { + if (!control_tar.Add(ShLibsFilename, WorkDir.length(), ".")) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Error adding file to tar:" + << std::endl + << "#top level directory: " << WorkDir << std::endl + << "#file: \"shlibs\"" << std::endl + << "#error:" << control_tar.GetError() << std::endl); + return false; + } + } + + // adds LDCONFIG related files + if (GenPostInst) { + control_tar.SetPermissions(permission755); + if (!control_tar.Add(PostInst, WorkDir.length(), ".")) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Error adding file to tar:" + << std::endl + << "#top level directory: " << WorkDir << std::endl + << "#file: \"postinst\"" << std::endl + << "#error:" << control_tar.GetError() << std::endl); + return false; + } + control_tar.SetPermissions(permission644); + } + + if (GenPostRm) { + control_tar.SetPermissions(permission755); + if (!control_tar.Add(PostRm, WorkDir.length(), ".")) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Error adding file to tar:" + << std::endl + << "#top level directory: " << WorkDir << std::endl + << "#file: \"postinst\"" << std::endl + << "#error:" << control_tar.GetError() << std::endl); + return false; + } + control_tar.SetPermissions(permission644); + } + + // for the other files, we use + // -either the original permission on the files + // -either a permission strictly defined by the Debian policies + if (ControlExtra) { + // permissions are now controlled by the original file permissions + + static const char* strictFiles[] = { "config", "postinst", "postrm", + "preinst", "prerm" }; + std::set setStrictFiles( + strictFiles, strictFiles + sizeof(strictFiles) / sizeof(strictFiles[0])); + + // default + control_tar.ClearPermissions(); + + std::vector controlExtraList; + cmSystemTools::ExpandListArgument(ControlExtra, controlExtraList); + for (std::string const& i : controlExtraList) { + std::string filenamename = cmsys::SystemTools::GetFilenameName(i); + std::string localcopy = WorkDir + "/" + filenamename; + + if (PermissionStrictPolicy) { + control_tar.SetPermissions( + setStrictFiles.count(filenamename) ? permission755 : permission644); + } + + // if we can copy the file, it means it does exist, let's add it: + if (cmsys::SystemTools::CopyFileIfDifferent(i, localcopy)) { + control_tar.Add(localcopy, WorkDir.length(), "."); + } + } + } + + return true; +} + +bool DebGenerator::generateDeb() const +{ + // ar -r your-package-name.deb debian-binary control.tar.* data.tar.* + // A debian package .deb is simply an 'ar' archive. The only subtle + // difference is that debian uses the BSD ar style archive whereas most + // Linux distro have a GNU ar. + // See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=161593 for more info + std::string const outputPath = TopLevelDir + "/" + OutputName; + std::string const tlDir = WorkDir + "/"; + cmGeneratedFileStream debStream; + debStream.Open(outputPath, false, true); + cmArchiveWrite deb(debStream, cmArchiveWrite::CompressNone, "arbsd"); + + // uid/gid should be the one of the root user, and this root user has + // always uid/gid equal to 0. + deb.SetUIDAndGID(0u, 0u); + deb.SetUNAMEAndGNAME("root", "root"); + + if (!deb.Add(tlDir + "debian-binary", tlDir.length()) || + !deb.Add(tlDir + "control.tar.gz", tlDir.length()) || + !deb.Add(tlDir + "data.tar" + CompressionSuffix, tlDir.length())) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Error creating debian package:" + << std::endl + << "#top level directory: " << TopLevelDir << std::endl + << "#file: " << OutputName << std::endl + << "#error:" << deb.GetError() << std::endl); + return false; + } + return true; +} + +} // end anonymous namespace + cmCPackDebGenerator::cmCPackDebGenerator() { } @@ -68,18 +487,20 @@ int cmCPackDebGenerator::PackageOnePack(std::string const& initialTopLevel, return retval; } - cmsys::Glob gl; - std::string findExpr(this->GetOption("GEN_WDIR")); - findExpr += "/*"; - gl.RecurseOn(); - gl.SetRecurseListDirs(true); - if (!gl.FindFiles(findExpr)) { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Cannot find any files in the installed directory" - << std::endl); - return 0; + { // Isolate globbing of binaries vs. dbgsyms + cmsys::Glob gl; + std::string findExpr(this->GetOption("GEN_WDIR")); + findExpr += "/*"; + gl.RecurseOn(); + gl.SetRecurseListDirs(true); + if (!gl.FindFiles(findExpr)) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Cannot find any files in the installed directory" + << std::endl); + return 0; + } + packageFiles = gl.GetFiles(); } - packageFiles = gl.GetFiles(); int res = createDeb(); if (res != 1) { @@ -90,6 +511,32 @@ int cmCPackDebGenerator::PackageOnePack(std::string const& initialTopLevel, packageFileName += "/"; packageFileName += this->GetOption("GEN_CPACK_OUTPUT_FILE_NAME"); packageFileNames.push_back(std::move(packageFileName)); + + if (this->IsOn("GEN_CPACK_DEBIAN_DEBUGINFO_PACKAGE")) { + cmsys::Glob gl; + std::string findExpr(this->GetOption("GEN_DBGSYMDIR")); + findExpr += "/*"; + gl.RecurseOn(); + gl.SetRecurseListDirs(true); + if (!gl.FindFiles(findExpr)) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Cannot find any files in the installed directory" + << std::endl); + return 0; + } + packageFiles = gl.GetFiles(); + + res = createDbgsymDDeb(); + if (res != 1) { + retval = 0; + } + // add the generated package to package file names list + packageFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); + packageFileName += "/"; + packageFileName += this->GetOption("GEN_CPACK_DBGSYM_OUTPUT_FILE_NAME"); + packageFileNames.push_back(std::move(packageFileName)); + } + return retval; } @@ -234,112 +681,81 @@ int cmCPackDebGenerator::PackageFiles() int cmCPackDebGenerator::createDeb() { - // debian-binary file - const std::string strGenWDIR(this->GetOption("GEN_WDIR")); - const std::string dbfilename = strGenWDIR + "/debian-binary"; - { // the scope is needed for cmGeneratedFileStream - cmGeneratedFileStream out(dbfilename); - out << "2.0"; - out << std::endl; // required for valid debian package - } - - // control file - std::string ctlfilename = strGenWDIR + "/control"; + std::map controlValues; // debian policy enforce lower case for package name - // mandatory entries: - std::string debian_pkg_name = cmsys::SystemTools::LowerCase( + controlValues["Package"] = cmsys::SystemTools::LowerCase( this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_NAME")); - const char* debian_pkg_version = + controlValues["Version"] = this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_VERSION"); - const char* debian_pkg_section = + controlValues["Section"] = this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_SECTION"); - const char* debian_pkg_priority = + controlValues["Priority"] = this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_PRIORITY"); - const char* debian_pkg_arch = + controlValues["Architecture"] = this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_ARCHITECTURE"); - const char* maintainer = + controlValues["Maintainer"] = this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_MAINTAINER"); - const char* desc = this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_DESCRIPTION"); + controlValues["Description"] = + this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_DESCRIPTION"); - // optional entries + const char* debian_pkg_source = + this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_SOURCE"); + if (debian_pkg_source && *debian_pkg_source) { + controlValues["Source"] = debian_pkg_source; + } const char* debian_pkg_dep = this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_DEPENDS"); + if (debian_pkg_dep && *debian_pkg_dep) { + controlValues["Depends"] = debian_pkg_dep; + } const char* debian_pkg_rec = this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_RECOMMENDS"); + if (debian_pkg_rec && *debian_pkg_rec) { + controlValues["Recommends"] = debian_pkg_rec; + } const char* debian_pkg_sug = this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_SUGGESTS"); + if (debian_pkg_sug && *debian_pkg_sug) { + controlValues["Suggests"] = debian_pkg_sug; + } const char* debian_pkg_url = this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_HOMEPAGE"); + if (debian_pkg_url && *debian_pkg_url) { + controlValues["Homepage"] = debian_pkg_url; + } const char* debian_pkg_predep = this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_PREDEPENDS"); + if (debian_pkg_predep && *debian_pkg_predep) { + controlValues["Pre-Depends"] = debian_pkg_predep; + } const char* debian_pkg_enhances = this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_ENHANCES"); + if (debian_pkg_enhances && *debian_pkg_enhances) { + controlValues["Enhances"] = debian_pkg_enhances; + } const char* debian_pkg_breaks = this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_BREAKS"); + if (debian_pkg_breaks && *debian_pkg_breaks) { + controlValues["Breaks"] = debian_pkg_breaks; + } const char* debian_pkg_conflicts = this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_CONFLICTS"); + if (debian_pkg_conflicts && *debian_pkg_conflicts) { + controlValues["Conflicts"] = debian_pkg_conflicts; + } const char* debian_pkg_provides = this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_PROVIDES"); + if (debian_pkg_provides && *debian_pkg_provides) { + controlValues["Provides"] = debian_pkg_provides; + } const char* debian_pkg_replaces = this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_REPLACES"); - const char* debian_pkg_source = - this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_SOURCE"); - - { // the scope is needed for cmGeneratedFileStream - cmGeneratedFileStream out(ctlfilename); - out << "Package: " << debian_pkg_name << "\n"; - out << "Version: " << debian_pkg_version << "\n"; - out << "Section: " << debian_pkg_section << "\n"; - out << "Priority: " << debian_pkg_priority << "\n"; - out << "Architecture: " << debian_pkg_arch << "\n"; - if (debian_pkg_source && *debian_pkg_source) { - out << "Source: " << debian_pkg_source << "\n"; - } - if (debian_pkg_dep && *debian_pkg_dep) { - out << "Depends: " << debian_pkg_dep << "\n"; - } - if (debian_pkg_rec && *debian_pkg_rec) { - out << "Recommends: " << debian_pkg_rec << "\n"; - } - if (debian_pkg_sug && *debian_pkg_sug) { - out << "Suggests: " << debian_pkg_sug << "\n"; - } - if (debian_pkg_url && *debian_pkg_url) { - out << "Homepage: " << debian_pkg_url << "\n"; - } - if (debian_pkg_predep && *debian_pkg_predep) { - out << "Pre-Depends: " << debian_pkg_predep << "\n"; - } - if (debian_pkg_enhances && *debian_pkg_enhances) { - out << "Enhances: " << debian_pkg_enhances << "\n"; - } - if (debian_pkg_breaks && *debian_pkg_breaks) { - out << "Breaks: " << debian_pkg_breaks << "\n"; - } - if (debian_pkg_conflicts && *debian_pkg_conflicts) { - out << "Conflicts: " << debian_pkg_conflicts << "\n"; - } - if (debian_pkg_provides && *debian_pkg_provides) { - out << "Provides: " << debian_pkg_provides << "\n"; - } - if (debian_pkg_replaces && *debian_pkg_replaces) { - out << "Replaces: " << debian_pkg_replaces << "\n"; - } - unsigned long totalSize = 0; - { - std::string dirName = this->GetOption("CPACK_TEMPORARY_DIRECTORY"); - dirName += '/'; - for (std::string const& file : packageFiles) { - totalSize += cmSystemTools::FileLength(file); - } - } - out << "Installed-Size: " << (totalSize + 1023) / 1024 << "\n"; - out << "Maintainer: " << maintainer << "\n"; - out << "Description: " << desc << "\n"; - out << std::endl; + if (debian_pkg_replaces && *debian_pkg_replaces) { + controlValues["Replaces"] = debian_pkg_replaces; } + const std::string strGenWDIR(this->GetOption("GEN_WDIR")); const std::string shlibsfilename = strGenWDIR + "/shlibs"; const char* debian_pkg_shlibs = @@ -371,314 +787,74 @@ int cmCPackDebGenerator::createDeb() "fi\n"; } - cmArchiveWrite::Compress tar_compression_type = cmArchiveWrite::CompressGZip; - const char* debian_compression_type = - this->GetOption("GEN_CPACK_DEBIAN_COMPRESSION_TYPE"); - if (!debian_compression_type) { - debian_compression_type = "gzip"; - } - - std::string compression_suffix; - if (!strcmp(debian_compression_type, "lzma")) { - compression_suffix = ".lzma"; - tar_compression_type = cmArchiveWrite::CompressLZMA; - } else if (!strcmp(debian_compression_type, "xz")) { - compression_suffix = ".xz"; - tar_compression_type = cmArchiveWrite::CompressXZ; - } else if (!strcmp(debian_compression_type, "bzip2")) { - compression_suffix = ".bz2"; - tar_compression_type = cmArchiveWrite::CompressBZip2; - } else if (!strcmp(debian_compression_type, "gzip")) { - compression_suffix = ".gz"; - tar_compression_type = cmArchiveWrite::CompressGZip; - } else if (!strcmp(debian_compression_type, "none")) { - compression_suffix.clear(); - tar_compression_type = cmArchiveWrite::CompressNone; - } else { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Error unrecognized compression type: " - << debian_compression_type << std::endl); - } - - const char* debian_archive_type = - this->GetOption("GEN_CPACK_DEBIAN_ARCHIVE_TYPE"); - if (!debian_archive_type) { - debian_archive_type = "paxr"; + DebGenerator gen( + Logger, this->GetOption("GEN_CPACK_OUTPUT_FILE_NAME"), strGenWDIR, + this->GetOption("CPACK_TOPLEVEL_DIRECTORY"), + this->GetOption("CPACK_TEMPORARY_DIRECTORY"), + this->GetOption("GEN_CPACK_DEBIAN_COMPRESSION_TYPE"), + this->GetOption("GEN_CPACK_DEBIAN_ARCHIVE_TYPE"), controlValues, gen_shibs, + shlibsfilename, this->IsOn("GEN_CPACK_DEBIAN_GENERATE_POSTINST"), postinst, + this->IsOn("GEN_CPACK_DEBIAN_GENERATE_POSTRM"), postrm, + this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA"), + this->IsSet("GEN_CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION"), + packageFiles); + + if (!gen.generate()) { + return 0; } + return 1; +} - std::string filename_data_tar = - strGenWDIR + "/data.tar" + compression_suffix; - - // atomic file generation for data.tar - { - cmGeneratedFileStream fileStream_data_tar; - fileStream_data_tar.Open(filename_data_tar, false, true); - if (!fileStream_data_tar) { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Error opening the file \"" - << filename_data_tar << "\" for writing" << std::endl); - return 0; - } - cmArchiveWrite data_tar(fileStream_data_tar, tar_compression_type, - debian_archive_type); - - // uid/gid should be the one of the root user, and this root user has - // always uid/gid equal to 0. - data_tar.SetUIDAndGID(0u, 0u); - data_tar.SetUNAMEAndGNAME("root", "root"); - - // now add all directories which have to be compressed - // collect all top level install dirs for that - // e.g. /opt/bin/foo, /usr/bin/bar and /usr/bin/baz would - // give /usr and /opt - size_t topLevelLength = strGenWDIR.length(); - cmCPackLogger(cmCPackLog::LOG_DEBUG, - "WDIR: \"" << strGenWDIR << "\", length = " << topLevelLength - << std::endl); - std::set orderedFiles; - - // we have to reconstruct the parent folders as well - - for (std::string currentPath : packageFiles) { - while (currentPath != strGenWDIR) { - // the last one IS strGenWDIR, but we do not want this one: - // XXX/application/usr/bin/myprogram with GEN_WDIR=XXX/application - // should not add XXX/application - orderedFiles.insert(currentPath); - currentPath = cmSystemTools::CollapseCombinedPath(currentPath, ".."); - } - } - - for (std::string const& file : orderedFiles) { - cmCPackLogger(cmCPackLog::LOG_DEBUG, - "FILEIT: \"" << file << "\"" << std::endl); - std::string::size_type slashPos = file.find('/', topLevelLength + 1); - std::string relativeDir = - file.substr(topLevelLength, slashPos - topLevelLength); - cmCPackLogger(cmCPackLog::LOG_DEBUG, - "RELATIVEDIR: \"" << relativeDir << "\"" << std::endl); - -#ifdef WIN32 - std::string mode_t_adt_filename = file + ":cmake_mode_t"; - cmsys::ifstream permissionStream(mode_t_adt_filename.c_str()); - - mode_t permissions = 0; - - if (permissionStream) { - permissionStream >> std::oct >> permissions; - } - - if (permissions != 0) { - data_tar.SetPermissions(permissions); - } else if (cmSystemTools::FileIsDirectory(file)) { - data_tar.SetPermissions(0755); - } else { - data_tar.ClearPermissions(); - } -#endif - - // do not recurse because the loop will do it - if (!data_tar.Add(file, topLevelLength, ".", false)) { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Problem adding file to tar:" - << std::endl - << "#top level directory: " << strGenWDIR << std::endl - << "#file: " << file << std::endl - << "#error:" << data_tar.GetError() << std::endl); - return 0; - } - } - } // scope for file generation +int cmCPackDebGenerator::createDbgsymDDeb() +{ + // Packages containing debug symbols follow the same structure as .debs + // but have different metadata and content. - std::string md5filename = strGenWDIR + "/md5sums"; - { - // the scope is needed for cmGeneratedFileStream - cmGeneratedFileStream out(md5filename); - - std::string topLevelWithTrailingSlash = - this->GetOption("CPACK_TEMPORARY_DIRECTORY"); - topLevelWithTrailingSlash += '/'; - for (std::string const& file : packageFiles) { - // hash only regular files - if (cmSystemTools::FileIsDirectory(file) || - cmSystemTools::FileIsSymlink(file)) { - continue; - } + std::map controlValues; + // debian policy enforce lower case for package name + std::string packageNameLower = cmsys::SystemTools::LowerCase( + this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_NAME")); + const char* debian_pkg_version = + this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_VERSION"); - std::string output = - cmSystemTools::ComputeFileHash(file, cmCryptoHash::AlgoMD5); - if (output.empty()) { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Problem computing the md5 of " << file << std::endl); - } + controlValues["Package"] = packageNameLower + "-dbgsym"; + controlValues["Package-Type"] = "ddeb"; + controlValues["Version"] = debian_pkg_version; + controlValues["Auto-Built-Package"] = "debug-symbols"; + controlValues["Depends"] = this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_NAME") + + std::string(" (= ") + debian_pkg_version + ")"; + controlValues["Section"] = "debug"; + controlValues["Priority"] = "optional"; + controlValues["Architecture"] = + this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_ARCHITECTURE"); + controlValues["Maintainer"] = + this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_MAINTAINER"); + controlValues["Description"] = + std::string("debug symbols for ") + packageNameLower; - output += " " + file + "\n"; - // debian md5sums entries are like this: - // 014f3604694729f3bf19263bac599765 usr/bin/ccmake - // thus strip the full path (with the trailing slash) - cmSystemTools::ReplaceString(output, topLevelWithTrailingSlash.c_str(), - ""); - out << output; - } - // each line contains a eol. - // Do not end the md5sum file with yet another (invalid) + const char* debian_pkg_source = + this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_SOURCE"); + if (debian_pkg_source && *debian_pkg_source) { + controlValues["Source"] = debian_pkg_source; } - - std::string filename_control_tar = strGenWDIR + "/control.tar.gz"; - // atomic file generation for control.tar - { - cmGeneratedFileStream fileStream_control_tar; - fileStream_control_tar.Open(filename_control_tar, false, true); - if (!fileStream_control_tar) { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Error opening the file \"" << filename_control_tar - << "\" for writing" - << std::endl); - return 0; - } - cmArchiveWrite control_tar(fileStream_control_tar, - cmArchiveWrite::CompressGZip, - debian_archive_type); - - // sets permissions and uid/gid for the files - control_tar.SetUIDAndGID(0u, 0u); - control_tar.SetUNAMEAndGNAME("root", "root"); - - /* permissions are set according to - https://www.debian.org/doc/debian-policy/ch-files.html#s-permissions-owners - and - https://lintian.debian.org/tags/control-file-has-bad-permissions.html - */ - const mode_t permission644 = 0644; - const mode_t permissionExecute = 0111; - const mode_t permission755 = permission644 | permissionExecute; - - // for md5sum and control (that we have generated here), we use 644 - // (RW-R--R--) - // so that deb lintian doesn't warn about it - control_tar.SetPermissions(permission644); - - // adds control and md5sums - if (!control_tar.Add(md5filename, strGenWDIR.length(), ".") || - !control_tar.Add(strGenWDIR + "/control", strGenWDIR.length(), ".")) { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Error adding file to tar:" - << std::endl - << "#top level directory: " << strGenWDIR << std::endl - << "#file: \"control\" or \"md5sums\"" << std::endl - << "#error:" << control_tar.GetError() << std::endl); - return 0; - } - - // adds generated shlibs file - if (gen_shibs) { - if (!control_tar.Add(shlibsfilename, strGenWDIR.length(), ".")) { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Error adding file to tar:" - << std::endl - << "#top level directory: " << strGenWDIR << std::endl - << "#file: \"shlibs\"" << std::endl - << "#error:" << control_tar.GetError() << std::endl); - return 0; - } - } - - // adds LDCONFIG related files - if (this->IsOn("GEN_CPACK_DEBIAN_GENERATE_POSTINST")) { - control_tar.SetPermissions(permission755); - if (!control_tar.Add(postinst, strGenWDIR.length(), ".")) { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Error adding file to tar:" - << std::endl - << "#top level directory: " << strGenWDIR << std::endl - << "#file: \"postinst\"" << std::endl - << "#error:" << control_tar.GetError() << std::endl); - return 0; - } - control_tar.SetPermissions(permission644); - } - - if (this->IsOn("GEN_CPACK_DEBIAN_GENERATE_POSTRM")) { - control_tar.SetPermissions(permission755); - if (!control_tar.Add(postrm, strGenWDIR.length(), ".")) { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Error adding file to tar:" - << std::endl - << "#top level directory: " << strGenWDIR << std::endl - << "#file: \"postinst\"" << std::endl - << "#error:" << control_tar.GetError() << std::endl); - return 0; - } - control_tar.SetPermissions(permission644); - } - - // for the other files, we use - // -either the original permission on the files - // -either a permission strictly defined by the Debian policies - const char* controlExtra = - this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA"); - if (controlExtra) { - // permissions are now controlled by the original file permissions - - const bool permissionStrictPolicy = - this->IsSet("GEN_CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION"); - - static const char* strictFiles[] = { "config", "postinst", "postrm", - "preinst", "prerm" }; - std::set setStrictFiles( - strictFiles, - strictFiles + sizeof(strictFiles) / sizeof(strictFiles[0])); - - // default - control_tar.ClearPermissions(); - - std::vector controlExtraList; - cmSystemTools::ExpandListArgument(controlExtra, controlExtraList); - for (std::string const& i : controlExtraList) { - std::string filenamename = cmsys::SystemTools::GetFilenameName(i); - std::string localcopy = strGenWDIR + "/" + filenamename; - - if (permissionStrictPolicy) { - control_tar.SetPermissions(setStrictFiles.count(filenamename) - ? permission755 - : permission644); - } - - // if we can copy the file, it means it does exist, let's add it: - if (cmsys::SystemTools::CopyFileIfDifferent(i, localcopy)) { - control_tar.Add(localcopy, strGenWDIR.length(), "."); - } - } - } + const char* debian_build_ids = this->GetOption("GEN_BUILD_IDS"); + if (debian_build_ids && *debian_build_ids) { + controlValues["Build-Ids"] = debian_build_ids; } - // ar -r your-package-name.deb debian-binary control.tar.* data.tar.* - // A debian package .deb is simply an 'ar' archive. The only subtle - // difference is that debian uses the BSD ar style archive whereas most - // Linux distro have a GNU ar. - // See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=161593 for more info - std::string const outputDir = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); - std::string const outputName = this->GetOption("GEN_CPACK_OUTPUT_FILE_NAME"); - std::string const outputPath = outputDir + "/" + outputName; - std::string const tlDir = strGenWDIR + "/"; - cmGeneratedFileStream debStream; - debStream.Open(outputPath, false, true); - cmArchiveWrite deb(debStream, cmArchiveWrite::CompressNone, "arbsd"); + DebGenerator gen( + Logger, this->GetOption("GEN_CPACK_DBGSYM_OUTPUT_FILE_NAME"), + this->GetOption("GEN_DBGSYMDIR"), - // uid/gid should be the one of the root user, and this root user has - // always uid/gid equal to 0. - deb.SetUIDAndGID(0u, 0u); - deb.SetUNAMEAndGNAME("root", "root"); + this->GetOption("CPACK_TOPLEVEL_DIRECTORY"), + this->GetOption("CPACK_TEMPORARY_DIRECTORY"), + this->GetOption("GEN_CPACK_DEBIAN_COMPRESSION_TYPE"), + this->GetOption("GEN_CPACK_DEBIAN_ARCHIVE_TYPE"), controlValues, false, "", + false, "", false, "", nullptr, + this->IsSet("GEN_CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION"), + packageFiles); - if (!deb.Add(tlDir + "debian-binary", tlDir.length()) || - !deb.Add(tlDir + "control.tar.gz", tlDir.length()) || - !deb.Add(tlDir + "data.tar" + compression_suffix, tlDir.length())) { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Error creating debian package:" - << std::endl - << "#top level directory: " << outputDir << std::endl - << "#file: " << outputName << std::endl - << "#error:" << deb.GetError() << std::endl); + if (!gen.generate()) { return 0; } return 1; diff --git a/Source/CPack/cmCPackDebGenerator.h b/Source/CPack/cmCPackDebGenerator.h index b4f0c79..2244fe7 100644 --- a/Source/CPack/cmCPackDebGenerator.h +++ b/Source/CPack/cmCPackDebGenerator.h @@ -65,6 +65,8 @@ protected: private: int createDeb(); + int createDbgsymDDeb(); + std::vector packageFiles; }; diff --git a/Tests/RunCMake/CPack/DEB/Helpers.cmake b/Tests/RunCMake/CPack/DEB/Helpers.cmake index e01f81d..9b98ed4 100644 --- a/Tests/RunCMake/CPack/DEB/Helpers.cmake +++ b/Tests/RunCMake/CPack/DEB/Helpers.cmake @@ -1,4 +1,4 @@ -set(ALL_FILES_GLOB "*.deb") +set(ALL_FILES_GLOB "*.deb" "*.ddeb") function(getPackageContent FILE RESULT_VAR) execute_process(COMMAND ${CMAKE_COMMAND} -E env TZ=Etc/UTC ${DPKG_EXECUTABLE} -c "${FILE}" diff --git a/Tests/RunCMake/CPack/RunCMakeTest.cmake b/Tests/RunCMake/CPack/RunCMakeTest.cmake index 91fed3e..91d3cb7 100644 --- a/Tests/RunCMake/CPack/RunCMakeTest.cmake +++ b/Tests/RunCMake/CPack/RunCMakeTest.cmake @@ -6,7 +6,7 @@ include("${RunCMake_SOURCE_DIR}/CPackTestHelpers.cmake") # run_cpack_test args: TEST_NAME "GENERATORS" RUN_CMAKE_BUILD_STEP "PACKAGING_TYPES" run_cpack_test(CUSTOM_BINARY_SPEC_FILE "RPM" false "MONOLITHIC;COMPONENT") run_cpack_test(CUSTOM_NAMES "RPM;DEB;TGZ" true "COMPONENT") -run_cpack_test(DEBUGINFO "RPM" true "COMPONENT") +run_cpack_test(DEBUGINFO "RPM;DEB" true "COMPONENT") run_cpack_test_subtests(DEFAULT_PERMISSIONS "CMAKE_var_set;CPACK_var_set;both_set;invalid_CMAKE_var;invalid_CPACK_var" "RPM;DEB" false "MONOLITHIC;COMPONENT") run_cpack_test(DEPENDENCIES "RPM;DEB" true "COMPONENT") run_cpack_test(DIST "RPM" false "MONOLITHIC") diff --git a/Tests/RunCMake/CPack/VerifyResult.cmake b/Tests/RunCMake/CPack/VerifyResult.cmake index af12d37..345b37f 100644 --- a/Tests/RunCMake/CPack/VerifyResult.cmake +++ b/Tests/RunCMake/CPack/VerifyResult.cmake @@ -92,7 +92,7 @@ if(NOT EXPECTED_FILES_COUNT EQUAL 0) # check that there were no extra files generated foreach(all_files_glob_ IN LISTS ALL_FILES_GLOB) file(GLOB foundAll_ RELATIVE "${bin_dir}" "${all_files_glob_}") - list(APPEND allFoundFiles_ "${foundAll_}") + list(APPEND allFoundFiles_ ${foundAll_}) endforeach() list(LENGTH foundFiles_ foundFilesCount_) diff --git a/Tests/RunCMake/CPack/tests/DEBUGINFO/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/DEBUGINFO/ExpectedFiles.cmake index c745828..cf2e8ac 100644 --- a/Tests/RunCMake/CPack/tests/DEBUGINFO/ExpectedFiles.cmake +++ b/Tests/RunCMake/CPack/tests/DEBUGINFO/ExpectedFiles.cmake @@ -3,16 +3,39 @@ set(whitespaces_ "[\t\n\r ]*") set(EXPECTED_FILES_COUNT "5") set(EXPECTED_FILES_NAME_GENERATOR_SPECIFIC_FORMAT TRUE) -set(EXPECTED_FILE_1_NAME "Debuginfo") +if(GENERATOR_TYPE STREQUAL "RPM") + set(NAME "Debuginfo") + set(DEBUG_SUFFIX "debuginfo") + set(PKG "rpm") + set(DEBUG_PKG "rpm") +elseif(GENERATOR_TYPE STREQUAL "DEB") + set(NAME "debuginfo") + set(DEBUG_SUFFIX "dbgsym") + set(PKG "deb") + set(DEBUG_PKG "ddeb") +endif() + +set(EXPECTED_FILE_1_NAME "${NAME}") set(EXPECTED_FILE_1_COMPONENT "applications") set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/test_prog") -set(EXPECTED_FILE_2 "TestDinfo-pkg*-headers.rpm") + +set(EXPECTED_FILE_2 "TestDinfo-pkg*-headers.${PKG}") set(EXPECTED_FILE_CONTENT_2_LIST "/bar;/bar/CMakeLists.txt") -set(EXPECTED_FILE_3 "TestDinfo-pkg*-libs.rpm") + +set(EXPECTED_FILE_3 "TestDinfo-pkg*-libs.${PKG}") set(EXPECTED_FILE_CONTENT_3_LIST "/bas;/bas/libtest_lib.so") -set(EXPECTED_FILE_4_NAME "Debuginfo") -set(EXPECTED_FILE_4_COMPONENT "applications-debuginfo") -set(EXPECTED_FILE_CONTENT_4 ".*/src${whitespaces_}/src/src_1${whitespaces_}/src/src_1/main.cpp.*\.debug.*") -set(EXPECTED_FILE_5 "libs-DebugInfoPackage.rpm") -set(EXPECTED_FILE_CONTENT_5 ".*/src${whitespaces_}/src/src_1${whitespaces_}/src/src_1/test_lib.cpp.*\.debug.*") +set(EXPECTED_FILE_4 "${NAME}-applications-${DEBUG_SUFFIX}*.${DEBUG_PKG}") +if(GENERATOR_TYPE STREQUAL "RPM") + set(EXPECTED_FILE_CONTENT_4 ".*/src${whitespaces_}/src/src_1${whitespaces_}/src/src_1/main.cpp.*\.debug.*") +elseif(GENERATOR_TYPE STREQUAL "DEB") + set(EXPECTED_FILE_CONTENT_4 ".*/usr/lib/debug/.build-id/.*\.debug.*") +endif() + +if(GENERATOR_TYPE STREQUAL "RPM") + set(EXPECTED_FILE_5 "libs-DebugInfoPackage.rpm") + set(EXPECTED_FILE_CONTENT_5 ".*/src${whitespaces_}/src/src_1${whitespaces_}/src/src_1/test_lib.cpp.*\.debug.*") +elseif(GENERATOR_TYPE STREQUAL "DEB") + set(EXPECTED_FILE_5 "TestDinfo-pkg-libs-dbgsym.ddeb") + set(EXPECTED_FILE_CONTENT_5 ".*/usr/lib/debug/.build-id/.*\.debug.*") +endif() diff --git a/Tests/RunCMake/CPack/tests/DEBUGINFO/test.cmake b/Tests/RunCMake/CPack/tests/DEBUGINFO/test.cmake index 71457d4..161a36a 100644 --- a/Tests/RunCMake/CPack/tests/DEBUGINFO/test.cmake +++ b/Tests/RunCMake/CPack/tests/DEBUGINFO/test.cmake @@ -29,12 +29,16 @@ install(TARGETS test_lib DESTINATION bas COMPONENT libs) set(CPACK_RPM_APPLICATIONS_FILE_NAME "RPM-DEFAULT") set(CPACK_RPM_APPLICATIONS_DEBUGINFO_PACKAGE ON) +set(CPACK_DEBIAN_APPLICATIONS_FILE_NAME "DEB-DEFAULT") +set(CPACK_DEBIAN_APPLICATIONS_DEBUGINFO_PACKAGE ON) # test that components with debuginfo enabled still honor # CPACK_PACKAGE_FILE_NAME setting set(CPACK_RPM_PACKAGE_NAME "Debuginfo") set(CPACK_PACKAGE_FILE_NAME "TestDinfo-pkg") set(CPACK_RPM_LIBS_DEBUGINFO_PACKAGE ON) +set(CPACK_DEBIAN_PACKAGE_NAME "Debuginfo") +set(CPACK_DEBIAN_LIBS_DEBUGINFO_PACKAGE ON) # test debuginfo package rename set(CPACK_RPM_DEBUGINFO_FILE_NAME https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=42fbff45e4529d3cfbeb3cbcef8c5616df3f06f1 commit 42fbff45e4529d3cfbeb3cbcef8c5616df3f06f1 Author: Andrew Fuller AuthorDate: Tue Sep 18 11:39:57 2018 -0700 Commit: Andrew Fuller CommitDate: Tue Sep 18 11:41:36 2018 -0700 CPack/Deb: Use CMAKE_COMMAND to set the environment diff --git a/Modules/Internal/CPack/CPackDeb.cmake b/Modules/Internal/CPack/CPackDeb.cmake index ca3a004..2eb2fdf 100644 --- a/Modules/Internal/CPack/CPackDeb.cmake +++ b/Modules/Internal/CPack/CPackDeb.cmake @@ -92,7 +92,7 @@ function(cpack_deb_prepare_package_vars) # get file info so that we can determine if file is executable or not unset(CPACK_DEB_INSTALL_FILES) foreach(FILE_ IN LISTS FILE_PATHS_) - execute_process(COMMAND env LC_ALL=C ${FILE_EXECUTABLE} "./${FILE_}" + execute_process(COMMAND ${CMAKE_COMMAND} -E env LC_ALL=C ${FILE_EXECUTABLE} "./${FILE_}" WORKING_DIRECTORY "${WDIR}" RESULT_VARIABLE FILE_RESULT_ OUTPUT_VARIABLE INSTALL_FILE_) @@ -123,7 +123,7 @@ function(cpack_deb_prepare_package_vars) if(SHLIBDEPS_EXECUTABLE) # Check version of the dpkg-shlibdeps tool using CPackDEB method - execute_process(COMMAND env LC_ALL=C ${SHLIBDEPS_EXECUTABLE} --version + execute_process(COMMAND ${CMAKE_COMMAND} -E env LC_ALL=C ${SHLIBDEPS_EXECUTABLE} --version OUTPUT_VARIABLE _TMP_VERSION ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) @@ -151,7 +151,7 @@ function(cpack_deb_prepare_package_vars) file(MAKE_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}/DEBIAN") # Add --ignore-missing-info if the tool supports it - execute_process(COMMAND env LC_ALL=C ${SHLIBDEPS_EXECUTABLE} --help + execute_process(COMMAND ${CMAKE_COMMAND} -E env LC_ALL=C ${SHLIBDEPS_EXECUTABLE} --help OUTPUT_VARIABLE _TMP_HELP ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=66ab24a4c54fcd5956f9eccfdb0fb60bad858ef3 commit 66ab24a4c54fcd5956f9eccfdb0fb60bad858ef3 Author: Andrew Fuller AuthorDate: Tue Sep 18 10:57:12 2018 -0700 Commit: Andrew Fuller CommitDate: Tue Sep 18 11:41:04 2018 -0700 Help: Fix typo diff --git a/Help/cpack_gen/rpm.rst b/Help/cpack_gen/rpm.rst index 0214766..5c543ff 100644 --- a/Help/cpack_gen/rpm.rst +++ b/Help/cpack_gen/rpm.rst @@ -85,7 +85,7 @@ List of CPack RPM generator specific variables: By using user provided spec file, rpm macro extensions such as for generating debuginfo packages or by simply using multiple components more than one rpm file may be generated, either from a single spec file or from - multiple spec files (each component execution produces it's own spec file). + multiple spec files (each component execution produces its own spec file). In such cases duplicate file names may occur as a result of this variable setting or spec file content structure. Duplicate files get overwritten and it is up to the packager to set the variables in a manner that will @@ -749,7 +749,7 @@ Packaging of debug information Debuginfo packages contain debug symbols and sources for debugging packaged binaries. -Debuginfo RPM packaging has it's own set of variables: +Debuginfo RPM packaging has its own set of variables: .. variable:: CPACK_RPM_DEBUGINFO_PACKAGE CPACK_RPM__DEBUGINFO_PACKAGE @@ -911,7 +911,7 @@ directories. different binary rpm packages on different platforms depending on the platform's packaging rules. -Source RPM packaging has it's own set of variables: +Source RPM packaging has its own set of variables: .. variable:: CPACK_RPM_PACKAGE_SOURCES ----------------------------------------------------------------------- Summary of changes: Help/cpack_gen/deb.rst | 20 + Help/cpack_gen/rpm.rst | 6 +- Help/release/dev/cpack-deb-dbgsym-ddeb.rst | 6 + Modules/Internal/CPack/CPackDeb.cmake | 106 ++- Source/CPack/cmCPackDebGenerator.cxx | 944 ++++++++++++--------- Source/CPack/cmCPackDebGenerator.h | 2 + Tests/RunCMake/CPack/DEB/Helpers.cmake | 2 +- Tests/RunCMake/CPack/RunCMakeTest.cmake | 2 +- Tests/RunCMake/CPack/VerifyResult.cmake | 2 +- .../CPack/tests/DEBUGINFO/ExpectedFiles.cmake | 39 +- Tests/RunCMake/CPack/tests/DEBUGINFO/test.cmake | 4 + Utilities/Release/linux64_release.cmake | 7 +- 12 files changed, 733 insertions(+), 407 deletions(-) create mode 100644 Help/release/dev/cpack-deb-dbgsym-ddeb.rst hooks/post-receive -- CMake From kwrobot at kitware.com Wed Sep 26 08:15:05 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Wed, 26 Sep 2018 08:15:05 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-726-g3181f84 Message-ID: <20180926121505.7CD8FF9FAB@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 3181f8405bc949affb8ea321ec7746b44717fd99 (commit) via f9717725f9d4c7f4a1da52b0184365cd757bc076 (commit) via b5915744ebccd086891f1fab0ae91af54deb3a86 (commit) via a71caab46b205c2b0367c2b11c12a9b55b09bcca (commit) via 5ca130e22394978814a9e59418529a7a3e1a61bd (commit) from b16b25484545e8186eb8d52760386b6ab531b9c2 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=3181f8405bc949affb8ea321ec7746b44717fd99 commit 3181f8405bc949affb8ea321ec7746b44717fd99 Merge: b16b254 f971772 Author: Craig Scott AuthorDate: Wed Sep 26 12:11:28 2018 +0000 Commit: Kitware Robot CommitDate: Wed Sep 26 08:11:40 2018 -0400 Merge topic 'link-directories' f9717725f9 link_directories(): enhance capabilities b5915744eb LINK_DIRECTORIES target property: add policy for absolute paths check. a71caab46b LINK_DIRECTORIES: Add new properties and commands 5ca130e223 Refactoring: introduce function to check if a string is a generator expression Acked-by: Kitware Robot Merge-request: !2403 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=f9717725f9d4c7f4a1da52b0184365cd757bc076 commit f9717725f9d4c7f4a1da52b0184365cd757bc076 Author: Marc Chevrier AuthorDate: Wed Sep 19 14:12:35 2018 +0200 Commit: Craig Scott CommitDate: Tue Sep 25 23:59:59 2018 +1000 link_directories(): enhance capabilities diff --git a/Help/command/link_directories.rst b/Help/command/link_directories.rst index 3efa8e5..1dce9a0 100644 --- a/Help/command/link_directories.rst +++ b/Help/command/link_directories.rst @@ -5,7 +5,7 @@ Add directories in which the linker will look for libraries. :: - link_directories(directory1 [directory2 ...]) + link_directories([AFTER|BEFORE] directory1 [directory2 ...]) Add the paths in which the linker should search for libraries. Relative paths given to this command are interpreted as relative to @@ -16,6 +16,12 @@ property for the current ``CMakeLists.txt`` file, converting relative paths to absolute as needed. The command will apply only to targets created after it is called. +By default the directories specified are appended onto the current list of +directories. This default behavior can be changed by setting +:variable:`CMAKE_LINK_DIRECTORIES_BEFORE` to ``ON``. By using +``AFTER`` or ``BEFORE`` explicitly, you can select between appending and +prepending, independent of the default. + Arguments to ``link_directories`` may use "generator expressions" with the syntax "$<...>". See the :manual:`cmake-generator-expressions(7)` manual for available expressions. See the :manual:`cmake-buildsystem(7)` diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst index 6071999..78353fb 100644 --- a/Help/manual/cmake-variables.7.rst +++ b/Help/manual/cmake-variables.7.rst @@ -179,6 +179,7 @@ Variables that Change Behavior /variable/CMAKE_INSTALL_PREFIX /variable/CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT /variable/CMAKE_LIBRARY_PATH + /variable/CMAKE_LINK_DIRECTORIES_BEFORE /variable/CMAKE_MFC_FLAG /variable/CMAKE_MODULE_PATH /variable/CMAKE_NOT_USING_CONFIG_FLAGS diff --git a/Help/release/dev/link_directories-enhancements.rst b/Help/release/dev/link_directories-enhancements.rst new file mode 100644 index 0000000..2521fa1 --- /dev/null +++ b/Help/release/dev/link_directories-enhancements.rst @@ -0,0 +1,5 @@ +link_directories-enhancements +----------------------------- + +* :command:`link_directories` command gains capability to control directories + insertion position. diff --git a/Help/variable/CMAKE_LINK_DIRECTORIES_BEFORE.rst b/Help/variable/CMAKE_LINK_DIRECTORIES_BEFORE.rst new file mode 100644 index 0000000..026ca35 --- /dev/null +++ b/Help/variable/CMAKE_LINK_DIRECTORIES_BEFORE.rst @@ -0,0 +1,9 @@ +CMAKE_LINK_DIRECTORIES_BEFORE +----------------------------- + +Whether to append or prepend directories by default in +:command:`link_directories`. + +This variable affects the default behavior of the :command:`link_directories` +command. Setting this variable to ``ON`` is equivalent to using the ``BEFORE`` +option in all uses of that command. diff --git a/Source/cmLinkDirectoriesCommand.cxx b/Source/cmLinkDirectoriesCommand.cxx index 5c52c76..10425fd 100644 --- a/Source/cmLinkDirectoriesCommand.cxx +++ b/Source/cmLinkDirectoriesCommand.cxx @@ -4,6 +4,7 @@ #include +#include "cmAlgorithms.h" #include "cmGeneratorExpression.h" #include "cmMakefile.h" #include "cmPolicies.h" @@ -20,13 +21,29 @@ bool cmLinkDirectoriesCommand::InitialPass( return true; } - for (std::string const& i : args) { - this->AddLinkDir(i); + bool before = this->Makefile->IsOn("CMAKE_LINK_DIRECTORIES_BEFORE"); + + auto i = args.cbegin(); + if ((*i) == "BEFORE") { + before = true; + ++i; + } else if ((*i) == "AFTER") { + before = false; + ++i; + } + + std::vector directories; + for (; i != args.cend(); ++i) { + this->AddLinkDir(*i, directories); } + + this->Makefile->AddLinkDirectory(cmJoin(directories, ";"), before); + return true; } -void cmLinkDirectoriesCommand::AddLinkDir(std::string const& dir) +void cmLinkDirectoriesCommand::AddLinkDir( + std::string const& dir, std::vector& directories) { std::string unixPath = dir; cmSystemTools::ConvertToUnixSlashes(unixPath); @@ -64,5 +81,5 @@ void cmLinkDirectoriesCommand::AddLinkDir(std::string const& dir) unixPath = tmp; } } - this->Makefile->AddLinkDirectory(unixPath); + directories.push_back(unixPath); } diff --git a/Source/cmLinkDirectoriesCommand.h b/Source/cmLinkDirectoriesCommand.h index 3fd4e50..ae4fb7f 100644 --- a/Source/cmLinkDirectoriesCommand.h +++ b/Source/cmLinkDirectoriesCommand.h @@ -36,7 +36,8 @@ public: cmExecutionStatus& status) override; private: - void AddLinkDir(std::string const& dir); + void AddLinkDir(std::string const& dir, + std::vector& directories); }; #endif diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 963bb44..8d163b7 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1248,9 +1248,16 @@ void cmMakefile::AddLinkOption(std::string const& option) this->AppendProperty("LINK_OPTIONS", option.c_str()); } -void cmMakefile::AddLinkDirectory(std::string const& directory) +void cmMakefile::AddLinkDirectory(std::string const& directory, bool before) { - this->AppendProperty("LINK_DIRECTORIES", directory.c_str()); + cmListFileBacktrace lfbt = this->GetBacktrace(); + if (before) { + this->StateSnapshot.GetDirectory().PrependLinkDirectoriesEntry(directory, + lfbt); + } else { + this->StateSnapshot.GetDirectory().AppendLinkDirectoriesEntry(directory, + lfbt); + } } bool cmMakefile::ParseDefineFlag(std::string const& def, bool remove) diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index cde661b..b30f281 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -182,7 +182,7 @@ public: void AddCompileDefinition(std::string const& definition); void AddCompileOption(std::string const& option); void AddLinkOption(std::string const& option); - void AddLinkDirectory(std::string const& directory); + void AddLinkDirectory(std::string const& directory, bool before = false); /** Create a new imported target with the name and type given. */ cmTarget* AddImportedTarget(const std::string& name, diff --git a/Source/cmStateDirectory.cxx b/Source/cmStateDirectory.cxx index 5160f51..f94e714 100644 --- a/Source/cmStateDirectory.cxx +++ b/Source/cmStateDirectory.cxx @@ -417,6 +417,33 @@ void cmStateDirectory::AppendLinkDirectoriesEntry( this->DirectoryState->LinkDirectoriesBacktraces, this->Snapshot_.Position->LinkDirectoriesPosition, vec, lfbt); } +void cmStateDirectory::PrependLinkDirectoriesEntry( + const std::string& vec, const cmListFileBacktrace& lfbt) +{ + std::vector::iterator entryEnd = + this->DirectoryState->LinkDirectories.begin() + + this->Snapshot_.Position->LinkDirectoriesPosition; + + std::vector::reverse_iterator rend = + this->DirectoryState->LinkDirectories.rend(); + std::vector::reverse_iterator rbegin = + cmMakeReverseIterator(entryEnd); + rbegin = std::find(rbegin, rend, cmPropertySentinal); + + std::vector::iterator entryIt = rbegin.base(); + std::vector::iterator entryBegin = + this->DirectoryState->LinkDirectories.begin(); + + std::vector::iterator btIt = + this->DirectoryState->LinkDirectoriesBacktraces.begin() + + std::distance(entryBegin, entryIt); + + this->DirectoryState->LinkDirectories.insert(entryIt, vec); + this->DirectoryState->LinkDirectoriesBacktraces.insert(btIt, lfbt); + + this->Snapshot_.Position->LinkDirectoriesPosition = + this->DirectoryState->LinkDirectories.size(); +} void cmStateDirectory::SetLinkDirectories(const std::string& vec, const cmListFileBacktrace& lfbt) diff --git a/Source/cmStateDirectory.h b/Source/cmStateDirectory.h index 06345e2..e5f4d05 100644 --- a/Source/cmStateDirectory.h +++ b/Source/cmStateDirectory.h @@ -62,6 +62,8 @@ public: cmBacktraceRange GetLinkOptionsEntryBacktraces() const; void AppendLinkOptionsEntry(std::string const& vec, cmListFileBacktrace const& lfbt); + void PrependLinkDirectoriesEntry(std::string const& vec, + cmListFileBacktrace const& lfbt); void SetLinkOptions(std::string const& vec, cmListFileBacktrace const& lfbt); void ClearLinkOptions(); diff --git a/Tests/CMakeCommands/link_directories/CMakeLists.txt b/Tests/CMakeCommands/link_directories/CMakeLists.txt new file mode 100644 index 0000000..60c07b6 --- /dev/null +++ b/Tests/CMakeCommands/link_directories/CMakeLists.txt @@ -0,0 +1,30 @@ +cmake_minimum_required(VERSION 3.12) + +project(link_directories LANGUAGES C) + + +link_directories(/A) +link_directories(BEFORE /B) + +set(CMAKE_LINK_DIRECTORIES_BEFORE ON) +link_directories(/C) + +get_directory_property(result LINK_DIRECTORIES) +if (NOT result MATCHES "/C;/B;/A") + message(SEND_ERROR "link_directories not populated the LINK_DIRECTORIES directory property") +endif() + + +add_executable(link_directories EXCLUDE_FROM_ALL LinkDirectoriesExe.c) + +get_target_property(result link_directories LINK_DIRECTORIES) +if (NOT result MATCHES "/C;/B;/A") + message(SEND_ERROR "link_directories not populated the LINK_DIRECTORIES target property") +endif() + + +add_library(imp UNKNOWN IMPORTED) +get_target_property(result imp LINK_DIRECTORIES) +if (result) + message(FATAL_ERROR "link_directories populated the LINK_DIRECTORIES target property") +endif() diff --git a/Tests/CMakeCommands/link_directories/LinkDirectoriesExe.c b/Tests/CMakeCommands/link_directories/LinkDirectoriesExe.c new file mode 100644 index 0000000..8488f4e --- /dev/null +++ b/Tests/CMakeCommands/link_directories/LinkDirectoriesExe.c @@ -0,0 +1,4 @@ +int main(void) +{ + return 0; +} diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 4753aac..83349e3 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -2823,7 +2823,6 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release ADD_TEST_MACRO(CMakeCommands.add_compile_definitions add_compile_definitions) ADD_TEST_MACRO(CMakeCommands.add_compile_options add_compile_options) ADD_TEST_MACRO(CMakeCommands.target_link_libraries target_link_libraries) - ADD_TEST_MACRO(CMakeCommands.target_link_directories) ADD_TEST_MACRO(CMakeCommands.target_include_directories target_include_directories) ADD_TEST_MACRO(CMakeCommands.target_compile_definitions target_compile_definitions) ADD_TEST_MACRO(CMakeCommands.target_compile_options target_compile_options) @@ -2831,6 +2830,8 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release ADD_TEST_MACRO(CMakeCommands.add_link_options) ADD_TEST_MACRO(CMakeCommands.target_link_options) + ADD_TEST_MACRO(CMakeCommands.link_directories) + ADD_TEST_MACRO(CMakeCommands.target_link_directories) # The cmake server-mode test requires python for a simple client. find_package(PythonInterp QUIET) https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=b5915744ebccd086891f1fab0ae91af54deb3a86 commit b5915744ebccd086891f1fab0ae91af54deb3a86 Author: Marc Chevrier AuthorDate: Tue Sep 18 17:23:07 2018 +0200 Commit: Craig Scott CommitDate: Tue Sep 25 23:59:59 2018 +1000 LINK_DIRECTORIES target property: add policy for absolute paths check. diff --git a/Help/manual/cmake-policies.7.rst b/Help/manual/cmake-policies.7.rst index 904ebee..2cc52fe 100644 --- a/Help/manual/cmake-policies.7.rst +++ b/Help/manual/cmake-policies.7.rst @@ -57,6 +57,7 @@ Policies Introduced by CMake 3.13 .. toctree:: :maxdepth: 1 + CMP0081: Relative paths not allowed in LINK_DIRECTORIES target property. CMP0080: BundleUtilities cannot be included at configure time. CMP0079: target_link_libraries allows use with targets in other directories. CMP0078: UseSWIG generates standard target names. diff --git a/Help/policy/CMP0081.rst b/Help/policy/CMP0081.rst new file mode 100644 index 0000000..d3b2872 --- /dev/null +++ b/Help/policy/CMP0081.rst @@ -0,0 +1,22 @@ +CMP0081 +------- + +Relative paths not allowed in :prop_tgt:`LINK_DIRECTORIES` target property. + +CMake 3.12 and lower allowed the :prop_dir:`LINK_DIRECTORIES` directory +property to contain relative paths. The base path for such relative +entries is not well defined. CMake 3.13 and later will issue a +``FATAL_ERROR`` if the :prop_tgt:`LINK_DIRECTORIES` target property +(which is initialized by the :prop_dir:`LINK_DIRECTORIES` directory property) +contains a relative path. + +The ``OLD`` behavior for this policy is not to warn about relative paths +in the :prop_tgt:`LINK_DIRECTORIES` target property. The ``NEW`` behavior for +this policy is to issue a ``FATAL_ERROR`` if :prop_tgt:`LINK_DIRECTORIES` +contains a relative path. + +This policy was introduced in CMake version 3.13. CMake version +|release| warns when the policy is not set and uses ``OLD`` behavior. Use +the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly. + +.. include:: DEPRECATED.txt diff --git a/Help/release/dev/LINK_DIRECTORIES-policy.rst b/Help/release/dev/LINK_DIRECTORIES-policy.rst new file mode 100644 index 0000000..5bbfa51 --- /dev/null +++ b/Help/release/dev/LINK_DIRECTORIES-policy.rst @@ -0,0 +1,5 @@ +LINK_DIRECTORIES-policy +----------------------- + +* The :prop_tgt:`LINK_DIRECTORIES` target property expects absolute paths. + See policy :policy:`CMP0081`. diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 012d77a..29c6058 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -3091,14 +3091,38 @@ void processLinkDirectories( for (std::string& entryDirectory : entryDirectories) { if (!cmSystemTools::FileIsFullPath(entryDirectory)) { std::ostringstream e; + bool noMessage = false; + cmake::MessageType messageType = cmake::FATAL_ERROR; if (!targetName.empty()) { /* clang-format off */ e << "Target \"" << targetName << "\" contains relative " "path in its INTERFACE_LINK_DIRECTORIES:\n" " \"" << entryDirectory << "\""; /* clang-format on */ - tgt->GetLocalGenerator()->IssueMessage(cmake::FATAL_ERROR, e.str()); - return; + } else { + switch (tgt->GetPolicyStatusCMP0081()) { + case cmPolicies::WARN: { + e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0081) << "\n"; + messageType = cmake::AUTHOR_WARNING; + } break; + case cmPolicies::OLD: + noMessage = true; + break; + case cmPolicies::REQUIRED_IF_USED: + case cmPolicies::REQUIRED_ALWAYS: + case cmPolicies::NEW: + // Issue the fatal message. + break; + } + e << "Found relative path while evaluating link directories of " + "\"" + << tgt->GetName() << "\":\n \"" << entryDirectory << "\"\n"; + } + if (!noMessage) { + tgt->GetLocalGenerator()->IssueMessage(messageType, e.str()); + if (messageType == cmake::FATAL_ERROR) { + return; + } } } diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index f99cc0f..a367e47 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -237,7 +237,10 @@ class cmMakefile; 13, 0, cmPolicies::WARN) \ SELECT(POLICY, CMP0080, \ "BundleUtilities cannot be included at configure time", 3, 13, 0, \ - cmPolicies::WARN) + cmPolicies::WARN) \ + SELECT(POLICY, CMP0081, \ + "Relative paths not allowed in LINK_DIRECTORIES target property.", \ + 3, 13, 0, cmPolicies::WARN) #define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1) #define CM_FOR_EACH_POLICY_ID(POLICY) \ @@ -263,7 +266,8 @@ class cmMakefile; F(CMP0068) \ F(CMP0069) \ F(CMP0073) \ - F(CMP0076) + F(CMP0076) \ + F(CMP0081) /** \class cmPolicies * \brief Handles changes in CMake behavior and policies diff --git a/Tests/RunCMake/CMP0081/CMP0081-Common.cmake b/Tests/RunCMake/CMP0081/CMP0081-Common.cmake new file mode 100644 index 0000000..3ea5277 --- /dev/null +++ b/Tests/RunCMake/CMP0081/CMP0081-Common.cmake @@ -0,0 +1,5 @@ + +enable_language(CXX) + +add_library(foo SHARED empty.cpp) +set_target_properties(foo PROPERTIES LINK_DIRECTORIES "../lib") diff --git a/Tests/RunCMake/CMP0081/CMP0081-NEW-result.txt b/Tests/RunCMake/CMP0081/CMP0081-NEW-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CMP0081/CMP0081-NEW-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CMP0081/CMP0081-NEW-stderr.txt b/Tests/RunCMake/CMP0081/CMP0081-NEW-stderr.txt new file mode 100644 index 0000000..d31c149 --- /dev/null +++ b/Tests/RunCMake/CMP0081/CMP0081-NEW-stderr.txt @@ -0,0 +1,4 @@ +CMake Error in CMakeLists.txt: + Found relative path while evaluating link directories of "foo": + + "../lib" diff --git a/Tests/RunCMake/CMP0081/CMP0081-NEW.cmake b/Tests/RunCMake/CMP0081/CMP0081-NEW.cmake new file mode 100644 index 0000000..9b927a2 --- /dev/null +++ b/Tests/RunCMake/CMP0081/CMP0081-NEW.cmake @@ -0,0 +1,4 @@ + +cmake_policy(SET CMP0081 NEW) + +include (CMP0081-Common.cmake) diff --git a/Tests/RunCMake/CMP0081/CMP0081-OLD-result.txt b/Tests/RunCMake/CMP0081/CMP0081-OLD-result.txt new file mode 100644 index 0000000..573541a --- /dev/null +++ b/Tests/RunCMake/CMP0081/CMP0081-OLD-result.txt @@ -0,0 +1 @@ +0 diff --git a/Tests/RunCMake/CMP0081/CMP0081-OLD.cmake b/Tests/RunCMake/CMP0081/CMP0081-OLD.cmake new file mode 100644 index 0000000..2e91bf6 --- /dev/null +++ b/Tests/RunCMake/CMP0081/CMP0081-OLD.cmake @@ -0,0 +1,4 @@ + +cmake_policy(SET CMP0081 OLD) + +include (CMP0081-Common.cmake) diff --git a/Tests/RunCMake/CMP0081/CMP0081-WARN-result.txt b/Tests/RunCMake/CMP0081/CMP0081-WARN-result.txt new file mode 100644 index 0000000..573541a --- /dev/null +++ b/Tests/RunCMake/CMP0081/CMP0081-WARN-result.txt @@ -0,0 +1 @@ +0 diff --git a/Tests/RunCMake/CMP0081/CMP0081-WARN-stderr.txt b/Tests/RunCMake/CMP0081/CMP0081-WARN-stderr.txt new file mode 100644 index 0000000..eac0648 --- /dev/null +++ b/Tests/RunCMake/CMP0081/CMP0081-WARN-stderr.txt @@ -0,0 +1,10 @@ +CMake Warning \(dev\) in CMakeLists.txt: + Policy CMP0081 is not set: Relative paths not allowed in LINK_DIRECTORIES + target property. Run "cmake --help-policy CMP0081" for policy details. + Use the cmake_policy command to set the policy and suppress this warning. + + Found relative path while evaluating link directories of "foo": + + "../lib" + +This warning is for project developers. Use -Wno-dev to suppress it. diff --git a/Tests/RunCMake/CMP0081/CMP0081-WARN.cmake b/Tests/RunCMake/CMP0081/CMP0081-WARN.cmake new file mode 100644 index 0000000..33bb21d --- /dev/null +++ b/Tests/RunCMake/CMP0081/CMP0081-WARN.cmake @@ -0,0 +1,2 @@ + +include (CMP0081-Common.cmake) diff --git a/Tests/RunCMake/CMP0081/CMakeLists.txt b/Tests/RunCMake/CMP0081/CMakeLists.txt new file mode 100644 index 0000000..ef2163c --- /dev/null +++ b/Tests/RunCMake/CMP0081/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.1) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/CMP0081/RunCMakeTest.cmake b/Tests/RunCMake/CMP0081/RunCMakeTest.cmake new file mode 100644 index 0000000..335d8c5 --- /dev/null +++ b/Tests/RunCMake/CMP0081/RunCMakeTest.cmake @@ -0,0 +1,5 @@ +include(RunCMake) + +run_cmake(CMP0081-OLD) +run_cmake(CMP0081-NEW) +run_cmake(CMP0081-WARN) diff --git a/Tests/RunCMake/CMP0081/empty.cpp b/Tests/RunCMake/CMP0081/empty.cpp new file mode 100644 index 0000000..11ec041 --- /dev/null +++ b/Tests/RunCMake/CMP0081/empty.cpp @@ -0,0 +1,7 @@ +#ifdef _WIN32 +__declspec(dllexport) +#endif + int empty() +{ + return 0; +} diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 69cb5b7..080d0d0 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -106,6 +106,7 @@ if(CMAKE_SYSTEM_NAME MATCHES Darwin AND CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG) add_RunCMake_test(CMP0068) endif() add_RunCMake_test(CMP0069) +add_RunCMake_test(CMP0081) # The test for Policy 65 requires the use of the # CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS variable, which both the VS and Xcode diff --git a/Tests/RunCMake/TargetPolicies/PolicyList-stderr.txt b/Tests/RunCMake/TargetPolicies/PolicyList-stderr.txt index 6c861fa..2441a9c 100644 --- a/Tests/RunCMake/TargetPolicies/PolicyList-stderr.txt +++ b/Tests/RunCMake/TargetPolicies/PolicyList-stderr.txt @@ -25,6 +25,7 @@ \* CMP0069 \* CMP0073 \* CMP0076 + \* CMP0081 Call Stack \(most recent call first\): CMakeLists.txt:3 \(include\) https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=a71caab46b205c2b0367c2b11c12a9b55b09bcca commit a71caab46b205c2b0367c2b11c12a9b55b09bcca Author: Marc Chevrier AuthorDate: Fri Sep 14 17:48:20 2018 +0200 Commit: Craig Scott CommitDate: Tue Sep 25 23:59:58 2018 +1000 LINK_DIRECTORIES: Add new properties and commands These new capabilities enable to manage link directories Two new properties: * target properties: LINK_DIRECTORIES and INTERFACE_LINK_DIRECTORIES One new command * target_link_directories(): to populate target properties Fixes: #17215 diff --git a/Help/command/link_directories.rst b/Help/command/link_directories.rst index 5c64bc6..3efa8e5 100644 --- a/Help/command/link_directories.rst +++ b/Help/command/link_directories.rst @@ -1,19 +1,45 @@ link_directories ---------------- -Specify directories in which the linker will look for libraries. +Add directories in which the linker will look for libraries. :: - link_directories(directory1 directory2 ...) + link_directories(directory1 [directory2 ...]) -Specify the paths in which the linker should search for libraries. -The command will apply only to targets created after it is called. +Add the paths in which the linker should search for libraries. Relative paths given to this command are interpreted as relative to the current source directory, see :policy:`CMP0015`. -Note that this command is rarely necessary. Library locations -returned by :command:`find_package` and :command:`find_library` are -absolute paths. Pass these absolute library file paths directly to the -:command:`target_link_libraries` command. CMake will ensure the linker finds -them. +The directories are added to the :prop_dir:`LINK_DIRECTORIES` directory +property for the current ``CMakeLists.txt`` file, converting relative +paths to absolute as needed. +The command will apply only to targets created after it is called. + +Arguments to ``link_directories`` may use "generator expressions" with +the syntax "$<...>". See the :manual:`cmake-generator-expressions(7)` +manual for available expressions. See the :manual:`cmake-buildsystem(7)` +manual for more on defining buildsystem properties. + +.. note:: + + This command is rarely necessary and should be avoided where there are + other choices. Prefer to pass full absolute paths to libraries where + possible, since this ensures the correct library will always be linked. + The :command:`find_library` command provides the full path, which can + generally be used directly in calls to :command:`target_link_libraries`. + Situations where a library search path may be needed include: + + - Project generators like Xcode where the user can switch target + architecture at build time, but a full path to a library cannot + be used because it only provides one architecture (i.e. it is not + a universal binary). + - Libraries may themselves have other private library dependencies + that expect to be found via ``RPATH`` mechanisms, but some linkers + are not able to fully decode those paths (e.g. due to the presence + of things like ``$ORIGIN``). + + If a library search path must be provided, prefer to localize the effect + where possible by using the :command:`target_link_directories` command + rather than ``link_directories()``. The target-specific command can also + control how the search directories propagate to other dependent targets. diff --git a/Help/command/target_link_directories.rst b/Help/command/target_link_directories.rst new file mode 100644 index 0000000..b46aac0 --- /dev/null +++ b/Help/command/target_link_directories.rst @@ -0,0 +1,55 @@ +target_link_directories +----------------------- + +Add link directories to a target. + +:: + + target_link_directories( [BEFORE] + [items1...] + [ [items2...] ...]) + +Specify the paths in which the linker should search for libraries when +linking a given target. Each item can be an absolute or relative path, +with the latter being interpreted as relative to the current source +directory. These items will be added to the link command. + +The named ```` must have been created by a command such as +:command:`add_executable` or :command:`add_library` and must not be an +:ref:`ALIAS target `. + +The ``INTERFACE``, ``PUBLIC`` and ``PRIVATE`` keywords are required to +specify the scope of the items that follow them. ``PRIVATE`` and +``PUBLIC`` items will populate the :prop_tgt:`LINK_DIRECTORIES` property +of ````. ``PUBLIC`` and ``INTERFACE`` items will populate the +:prop_tgt:`INTERFACE_LINK_DIRECTORIES` property of ```` +(:ref:`IMPORTED targets ` only support ``INTERFACE`` items). +Each item specifies a link directory and will be converted to an absolute +path if necessary before adding it to the relevant property. Repeated +calls for the same ```` append items in the order called. + +If ``BEFORE`` is specified, the content will be prepended to the relevant +property instead of being appended. + +Arguments to ``target_link_directories`` may use "generator expressions" +with the syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)` +manual for available expressions. See the :manual:`cmake-buildsystem(7)` +manual for more on defining buildsystem properties. + +.. note:: + + This command is rarely necessary and should be avoided where there are + other choices. Prefer to pass full absolute paths to libraries where + possible, since this ensures the correct library will always be linked. + The :command:`find_library` command provides the full path, which can + generally be used directly in calls to :command:`target_link_libraries`. + Situations where a library search path may be needed include: + + - Project generators like Xcode where the user can switch target + architecture at build time, but a full path to a library cannot + be used because it only provides one architecture (i.e. it is not + a universal binary). + - Libraries may themselves have other private library dependencies + that expect to be found via ``RPATH`` mechanisms, but some linkers + are not able to fully decode those paths (e.g. due to the presence + of things like ``$ORIGIN``). diff --git a/Help/manual/cmake-commands.7.rst b/Help/manual/cmake-commands.7.rst index 753647d..0cc5fca 100644 --- a/Help/manual/cmake-commands.7.rst +++ b/Help/manual/cmake-commands.7.rst @@ -111,6 +111,7 @@ These commands are available only in CMake projects. /command/target_compile_features /command/target_compile_options /command/target_include_directories + /command/target_link_directories /command/target_link_libraries /command/target_link_options /command/target_sources diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst index 8ccd7f6..5c3eb81 100644 --- a/Help/manual/cmake-properties.7.rst +++ b/Help/manual/cmake-properties.7.rst @@ -228,6 +228,7 @@ Properties on Targets /prop_tgt/INTERFACE_COMPILE_OPTIONS /prop_tgt/INTERFACE_INCLUDE_DIRECTORIES /prop_tgt/INTERFACE_LINK_DEPENDS + /prop_tgt/INTERFACE_LINK_DIRECTORIES /prop_tgt/INTERFACE_LINK_LIBRARIES /prop_tgt/INTERFACE_LINK_OPTIONS /prop_tgt/INTERFACE_POSITION_INDEPENDENT_CODE @@ -252,6 +253,7 @@ Properties on Targets /prop_tgt/LINK_DEPENDS_NO_SHARED /prop_tgt/LINK_DEPENDS /prop_tgt/LINKER_LANGUAGE + /prop_tgt/LINK_DIRECTORIES /prop_tgt/LINK_FLAGS_CONFIG /prop_tgt/LINK_FLAGS /prop_tgt/LINK_INTERFACE_LIBRARIES_CONFIG diff --git a/Help/prop_dir/LINK_DIRECTORIES.rst b/Help/prop_dir/LINK_DIRECTORIES.rst index fa37576..f9fb815 100644 --- a/Help/prop_dir/LINK_DIRECTORIES.rst +++ b/Help/prop_dir/LINK_DIRECTORIES.rst @@ -3,6 +3,15 @@ LINK_DIRECTORIES List of linker search directories. -This read-only property specifies the list of directories given so far -to the link_directories command. It is intended for debugging -purposes. +This property holds a :ref:`;-list ` of directories +and is typically populated using the :command:`link_directories` command. +It gets its initial value from its parent directory, if it has one. + +The directory property is used to initialize the :prop_tgt:`LINK_DIRECTORIES` +target property when a target is created. That target property is used +by the generators to set the library search directories for the linker. + +Contents of ``LINK_DIRECTORIES`` may use "generator expressions" with +the syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)` +manual for available expressions. See the :manual:`cmake-buildsystem(7)` +manual for more on defining buildsystem properties. diff --git a/Help/prop_tgt/INTERFACE_LINK_DIRECTORIES.rst b/Help/prop_tgt/INTERFACE_LINK_DIRECTORIES.rst new file mode 100644 index 0000000..56a4ec0 --- /dev/null +++ b/Help/prop_tgt/INTERFACE_LINK_DIRECTORIES.rst @@ -0,0 +1,9 @@ +INTERFACE_LINK_DIRECTORIES +-------------------------- + +.. |property_name| replace:: link directories +.. |command_name| replace:: :command:`target_link_directories` +.. |PROPERTY_INTERFACE_NAME| replace:: ``INTERFACE_LINK_DIRECTORIES`` +.. |PROPERTY_LINK| replace:: :prop_tgt:`LINK_DIRECTORIES` +.. |PROPERTY_GENEX| replace:: ``$`` +.. include:: INTERFACE_BUILD_PROPERTY.txt diff --git a/Help/prop_tgt/LINK_DIRECTORIES.rst b/Help/prop_tgt/LINK_DIRECTORIES.rst new file mode 100644 index 0000000..085a701 --- /dev/null +++ b/Help/prop_tgt/LINK_DIRECTORIES.rst @@ -0,0 +1,18 @@ +LINK_DIRECTORIES +---------------- + +List of directories to use for the link step of shared library, module +and executable targets. + +This property holds a :ref:`;-list ` of directories +specified so far for its target. Use the :command:`target_link_directories` +command to append more search directories. + +This property is initialized by the :prop_dir:`LINK_DIRECTORIES` directory +property when a target is created, and is used by the generators to set +the search directories for the linker. + +Contents of ``LINK_DIRECTORIES`` may use "generator expressions" with the +syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)` manual +for available expressions. See the :manual:`cmake-buildsystem(7)` manual +for more on defining buildsystem properties. diff --git a/Help/release/dev/LINK_DIRECTORIES.rst b/Help/release/dev/LINK_DIRECTORIES.rst new file mode 100644 index 0000000..dc7d609 --- /dev/null +++ b/Help/release/dev/LINK_DIRECTORIES.rst @@ -0,0 +1,9 @@ +LINK_DIRECTORIES +---------------- + +* CMake gained new capabilities to manage link directories: + + * :prop_tgt:`LINK_DIRECTORIES` and :prop_tgt:`INTERFACE_LINK_DIRECTORIES` + target properties. + * :command:`target_link_directories` command to add link directories to + targets. diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index bfddbc6..3cf6c8f 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -579,6 +579,8 @@ set(SRCS cmTargetIncludeDirectoriesCommand.h cmTargetLinkOptionsCommand.cxx cmTargetLinkOptionsCommand.h + cmTargetLinkDirectoriesCommand.cxx + cmTargetLinkDirectoriesCommand.h cmTargetLinkLibrariesCommand.cxx cmTargetLinkLibrariesCommand.h cmTargetPropCommandBase.cxx diff --git a/Source/cmCPluginAPI.cxx b/Source/cmCPluginAPI.cxx index 3aa59d6..22ae340 100644 --- a/Source/cmCPluginAPI.cxx +++ b/Source/cmCPluginAPI.cxx @@ -171,7 +171,7 @@ void CCONV cmAddLinkDirectoryForTarget(void* arg, const char* tgt, " for directory ", d); return; } - t->AddLinkDirectory(d); + t->InsertLinkDirectory(d, mf->GetBacktrace()); } void CCONV cmAddExecutable(void* arg, const char* exename, int numSrcs, diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx index 15fbd40..873372f 100644 --- a/Source/cmCommands.cxx +++ b/Source/cmCommands.cxx @@ -101,6 +101,7 @@ # include "cmRemoveDefinitionsCommand.h" # include "cmSourceGroupCommand.h" # include "cmSubdirDependsCommand.h" +# include "cmTargetLinkDirectoriesCommand.h" # include "cmTargetLinkOptionsCommand.h" # include "cmUseMangledMesaCommand.h" # include "cmUtilitySourceCommand.h" @@ -278,6 +279,8 @@ void GetProjectCommands(cmState* state) state->AddBuiltinCommand("link_libraries", new cmLinkLibrariesCommand); state->AddBuiltinCommand("target_link_options", new cmTargetLinkOptionsCommand); + state->AddBuiltinCommand("target_link_directories", + new cmTargetLinkDirectoriesCommand); state->AddBuiltinCommand("load_cache", new cmLoadCacheCommand); state->AddBuiltinCommand("qt_wrap_cpp", new cmQTWrapCPPCommand); state->AddBuiltinCommand("qt_wrap_ui", new cmQTWrapUICommand); diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx index a3e135f..0e48ca8 100644 --- a/Source/cmComputeLinkInformation.cxx +++ b/Source/cmComputeLinkInformation.cxx @@ -357,10 +357,10 @@ cmComputeLinkInformation::cmComputeLinkInformation( } // Add the search path entries requested by the user to path ordering. - this->OrderLinkerSearchPath->AddUserDirectories( - this->Target->GetLinkDirectories()); - this->OrderRuntimeSearchPath->AddUserDirectories( - this->Target->GetLinkDirectories()); + std::vector directories; + this->Target->GetLinkDirectories(directories, config, this->LinkLanguage); + this->OrderLinkerSearchPath->AddUserDirectories(directories); + this->OrderRuntimeSearchPath->AddUserDirectories(directories); // Set up the implicit link directories. this->LoadImplicitLinkInfo(); @@ -387,8 +387,7 @@ cmComputeLinkInformation::cmComputeLinkInformation( if (this->OldLinkDirMode) { // Construct a mask to not bother with this behavior for link // directories already specified by the user. - std::vector const& dirs = this->Target->GetLinkDirectories(); - this->OldLinkDirMask.insert(dirs.begin(), dirs.end()); + this->OldLinkDirMask.insert(directories.begin(), directories.end()); } this->CMP0060Warn = this->Makefile->PolicyOptionalWarningEnabled( diff --git a/Source/cmExportBuildFileGenerator.cxx b/Source/cmExportBuildFileGenerator.cxx index 7f42035..024e641 100644 --- a/Source/cmExportBuildFileGenerator.cxx +++ b/Source/cmExportBuildFileGenerator.cxx @@ -98,6 +98,9 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os) this->PopulateInterfaceProperty("INTERFACE_LINK_OPTIONS", gte, cmGeneratorExpression::BuildInterface, properties, missingTargets); + this->PopulateInterfaceProperty("INTERFACE_LINK_DIRECTORIES", gte, + cmGeneratorExpression::BuildInterface, + properties, missingTargets); this->PopulateInterfaceProperty("INTERFACE_LINK_DEPENDS", gte, cmGeneratorExpression::BuildInterface, properties, missingTargets); diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index d6573b8..4cf9dd7 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -451,6 +451,37 @@ void cmExportFileGenerator::PopulateLinkDependsInterface( } } +void cmExportFileGenerator::PopulateLinkDirectoriesInterface( + cmTargetExport* tei, cmGeneratorExpression::PreprocessContext preprocessRule, + ImportPropertyMap& properties, std::vector& missingTargets) +{ + cmGeneratorTarget* gt = tei->Target; + assert(preprocessRule == cmGeneratorExpression::InstallInterface); + + const char* propName = "INTERFACE_LINK_DIRECTORIES"; + const char* input = gt->GetProperty(propName); + + if (!input) { + return; + } + + if (!*input) { + properties[propName].clear(); + return; + } + + std::string prepro = + cmGeneratorExpression::Preprocess(input, preprocessRule, true); + if (!prepro.empty()) { + this->ResolveTargetsInGeneratorExpressions(prepro, gt, missingTargets); + + if (!checkInterfaceDirs(prepro, gt, propName)) { + return; + } + properties[propName] = prepro; + } +} + void cmExportFileGenerator::PopulateInterfaceProperty( const std::string& propName, cmGeneratorTarget* target, cmGeneratorExpression::PreprocessContext preprocessRule, diff --git a/Source/cmExportFileGenerator.h b/Source/cmExportFileGenerator.h index 6ca2e07..41c6538 100644 --- a/Source/cmExportFileGenerator.h +++ b/Source/cmExportFileGenerator.h @@ -147,6 +147,10 @@ protected: cmTargetExport* target, cmGeneratorExpression::PreprocessContext preprocessRule, ImportPropertyMap& properties, std::vector& missingTargets); + void PopulateLinkDirectoriesInterface( + cmTargetExport* target, + cmGeneratorExpression::PreprocessContext preprocessRule, + ImportPropertyMap& properties, std::vector& missingTargets); void PopulateLinkDependsInterface( cmTargetExport* target, cmGeneratorExpression::PreprocessContext preprocessRule, diff --git a/Source/cmExportInstallFileGenerator.cxx b/Source/cmExportInstallFileGenerator.cxx index bfb7a05..e444087 100644 --- a/Source/cmExportInstallFileGenerator.cxx +++ b/Source/cmExportInstallFileGenerator.cxx @@ -106,6 +106,8 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os) this->PopulateInterfaceProperty("INTERFACE_LINK_OPTIONS", gt, cmGeneratorExpression::InstallInterface, properties, missingTargets); + this->PopulateLinkDirectoriesInterface( + te, cmGeneratorExpression::InstallInterface, properties, missingTargets); this->PopulateLinkDependsInterface( te, cmGeneratorExpression::InstallInterface, properties, missingTargets); diff --git a/Source/cmGeneratorExpressionDAGChecker.h b/Source/cmGeneratorExpressionDAGChecker.h index 8b1697b..a5134c3 100644 --- a/Source/cmGeneratorExpressionDAGChecker.h +++ b/Source/cmGeneratorExpressionDAGChecker.h @@ -28,6 +28,7 @@ class cmGeneratorTarget; SELECT(F, EvaluatingSources, SOURCES) \ SELECT(F, EvaluatingCompileFeatures, COMPILE_FEATURES) \ SELECT(F, EvaluatingLinkOptions, LINK_OPTIONS) \ + SELECT(F, EvaluatingLinkDirectories, LINK_DIRECTORIES) \ SELECT(F, EvaluatingLinkDepends, LINK_DEPENDS) #define CM_FOR_EACH_TRANSITIVE_PROPERTY(F) \ diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index a58d3cb..012d77a 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -103,6 +103,7 @@ cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg) , DebugCompileFeaturesDone(false) , DebugCompileDefinitionsDone(false) , DebugLinkOptionsDone(false) + , DebugLinkDirectoriesDone(false) , DebugSourcesDone(false) , LinkImplementationLanguageIsContextDependent(true) , UtilityItemsDone(false) @@ -133,6 +134,10 @@ cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg) t->GetLinkOptionsBacktraces(), this->LinkOptionsEntries); + CreatePropertyGeneratorExpressions(t->GetLinkDirectoriesEntries(), + t->GetLinkDirectoriesBacktraces(), + this->LinkDirectoriesEntries); + CreatePropertyGeneratorExpressions(t->GetSourceEntries(), t->GetSourceBacktraces(), this->SourceEntries, true); @@ -150,6 +155,7 @@ cmGeneratorTarget::~cmGeneratorTarget() cmDeleteAll(this->CompileFeaturesEntries); cmDeleteAll(this->CompileDefinitionsEntries); cmDeleteAll(this->LinkOptionsEntries); + cmDeleteAll(this->LinkDirectoriesEntries); cmDeleteAll(this->SourceEntries); cmDeleteAll(this->LinkInformation); } @@ -1704,11 +1710,6 @@ cmListFileBacktrace cmGeneratorTarget::GetBacktrace() const return this->Target->GetBacktrace(); } -const std::vector& cmGeneratorTarget::GetLinkDirectories() const -{ - return this->Target->GetLinkDirectories(); -} - const std::set& cmGeneratorTarget::GetUtilities() const { return this->Target->GetUtilities(); @@ -3068,6 +3069,102 @@ void cmGeneratorTarget::GetStaticLibraryLinkOptions( } namespace { +void processLinkDirectories( + cmGeneratorTarget const* tgt, + const std::vector& entries, + std::vector& directories, + std::unordered_set& uniqueDirectories, + cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config, + bool debugDirectories, std::string const& language) +{ + for (cmGeneratorTarget::TargetPropertyEntry* entry : entries) { + cmLinkImplItem const& item = entry->LinkImplItem; + std::string const& targetName = item.AsStr(); + + std::vector entryDirectories; + cmSystemTools::ExpandListArgument( + entry->ge->Evaluate(tgt->GetLocalGenerator(), config, false, tgt, + dagChecker, language), + entryDirectories); + + std::string usedDirectories; + for (std::string& entryDirectory : entryDirectories) { + if (!cmSystemTools::FileIsFullPath(entryDirectory)) { + std::ostringstream e; + if (!targetName.empty()) { + /* clang-format off */ + e << "Target \"" << targetName << "\" contains relative " + "path in its INTERFACE_LINK_DIRECTORIES:\n" + " \"" << entryDirectory << "\""; + /* clang-format on */ + tgt->GetLocalGenerator()->IssueMessage(cmake::FATAL_ERROR, e.str()); + return; + } + } + + // Sanitize the path the same way the link_directories command does + // in case projects set the LINK_DIRECTORIES property directly. + cmSystemTools::ConvertToUnixSlashes(entryDirectory); + if (uniqueDirectories.insert(entryDirectory).second) { + directories.push_back(entryDirectory); + if (debugDirectories) { + usedDirectories += " * " + entryDirectory + "\n"; + } + } + } + if (!usedDirectories.empty()) { + tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage( + cmake::LOG, + std::string("Used link directories for target ") + tgt->GetName() + + ":\n" + usedDirectories, + entry->ge->GetBacktrace()); + } + } +} +} + +void cmGeneratorTarget::GetLinkDirectories(std::vector& result, + const std::string& config, + const std::string& language) const +{ + std::unordered_set uniqueDirectories; + + cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_DIRECTORIES", nullptr, + nullptr); + + std::vector debugProperties; + const char* debugProp = + this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES"); + if (debugProp) { + cmSystemTools::ExpandListArgument(debugProp, debugProperties); + } + + bool debugDirectories = !this->DebugLinkDirectoriesDone && + std::find(debugProperties.begin(), debugProperties.end(), + "LINK_DIRECTORIES") != debugProperties.end(); + + if (this->GlobalGenerator->GetConfigureDoneCMP0026()) { + this->DebugLinkDirectoriesDone = true; + } + + processLinkDirectories(this, this->LinkDirectoriesEntries, result, + uniqueDirectories, &dagChecker, config, + debugDirectories, language); + + std::vector + linkInterfaceLinkDirectoriesEntries; + + AddInterfaceEntries(this, config, "INTERFACE_LINK_DIRECTORIES", + linkInterfaceLinkDirectoriesEntries); + + processLinkDirectories(this, linkInterfaceLinkDirectoriesEntries, result, + uniqueDirectories, &dagChecker, config, + debugDirectories, language); + + cmDeleteAll(linkInterfaceLinkDirectoriesEntries); +} + +namespace { void processLinkDepends( cmGeneratorTarget const* tgt, const std::vector& entries, diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 9d8c9f5..bfd95ac 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -273,8 +273,6 @@ public: cmListFileBacktrace GetBacktrace() const; - const std::vector& GetLinkDirectories() const; - std::set const& GetUtilities() const; cmListFileBacktrace const* GetUtilityBacktrace(const std::string& u) const; @@ -435,6 +433,10 @@ public: const std::string& config, const std::string& language) const; + void GetLinkDirectories(std::vector& result, + const std::string& config, + const std::string& language) const; + void GetLinkDepends(std::vector& result, const std::string& config, const std::string& language) const; @@ -825,6 +827,7 @@ private: std::vector CompileFeaturesEntries; std::vector CompileDefinitionsEntries; std::vector LinkOptionsEntries; + std::vector LinkDirectoriesEntries; std::vector SourceEntries; mutable std::set LinkImplicitNullProperties; @@ -874,6 +877,7 @@ private: mutable bool DebugCompileFeaturesDone; mutable bool DebugCompileDefinitionsDone; mutable bool DebugLinkOptionsDone; + mutable bool DebugLinkDirectoriesDone; mutable bool DebugSourcesDone; mutable bool LinkImplementationLanguageIsContextDependent; mutable bool UtilityItemsDone; diff --git a/Source/cmLinkDirectoriesCommand.cxx b/Source/cmLinkDirectoriesCommand.cxx index 1371c53..5c52c76 100644 --- a/Source/cmLinkDirectoriesCommand.cxx +++ b/Source/cmLinkDirectoriesCommand.cxx @@ -4,6 +4,7 @@ #include +#include "cmGeneratorExpression.h" #include "cmMakefile.h" #include "cmPolicies.h" #include "cmSystemTools.h" @@ -29,7 +30,8 @@ void cmLinkDirectoriesCommand::AddLinkDir(std::string const& dir) { std::string unixPath = dir; cmSystemTools::ConvertToUnixSlashes(unixPath); - if (!cmSystemTools::FileIsFullPath(unixPath)) { + if (!cmSystemTools::FileIsFullPath(unixPath) && + !cmGeneratorExpression::StartsWithGeneratorExpression(unixPath)) { bool convertToAbsolute = false; std::ostringstream e; /* clang-format off */ @@ -41,6 +43,7 @@ void cmLinkDirectoriesCommand::AddLinkDir(std::string const& dir) case cmPolicies::WARN: e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0015); this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, e.str()); + break; case cmPolicies::OLD: // OLD behavior does not convert break; @@ -61,5 +64,5 @@ void cmLinkDirectoriesCommand::AddLinkDir(std::string const& dir) unixPath = tmp; } } - this->Makefile->AppendProperty("LINK_DIRECTORIES", unixPath.c_str()); + this->Makefile->AddLinkDirectory(unixPath); } diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 354da4e..963bb44 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -243,6 +243,17 @@ cmBacktraceRange cmMakefile::GetLinkOptionsBacktraces() const return this->StateSnapshot.GetDirectory().GetLinkOptionsEntryBacktraces(); } +cmStringRange cmMakefile::GetLinkDirectoriesEntries() const +{ + return this->StateSnapshot.GetDirectory().GetLinkDirectoriesEntries(); +} + +cmBacktraceRange cmMakefile::GetLinkDirectoriesBacktraces() const +{ + return this->StateSnapshot.GetDirectory() + .GetLinkDirectoriesEntryBacktraces(); +} + cmListFileBacktrace cmMakefile::GetBacktrace() const { return this->Backtrace; @@ -1237,6 +1248,11 @@ void cmMakefile::AddLinkOption(std::string const& option) this->AppendProperty("LINK_OPTIONS", option.c_str()); } +void cmMakefile::AddLinkDirectory(std::string const& directory) +{ + this->AppendProperty("LINK_DIRECTORIES", directory.c_str()); +} + bool cmMakefile::ParseDefineFlag(std::string const& def, bool remove) { // Create a regular expression to match valid definitions. @@ -1335,10 +1351,6 @@ void cmMakefile::InitializeFromParent(cmMakefile* parent) // link libraries this->SetProperty("LINK_LIBRARIES", parent->GetProperty("LINK_LIBRARIES")); - // link directories - this->SetProperty("LINK_DIRECTORIES", - parent->GetProperty("LINK_DIRECTORIES")); - // the initial project name this->StateSnapshot.SetProjectName(parent->StateSnapshot.GetProjectName()); @@ -1872,17 +1884,6 @@ void cmMakefile::AddGlobalLinkInformation(cmTarget& target) return; default:; } - if (const char* linkDirsProp = this->GetProperty("LINK_DIRECTORIES")) { - std::vector linkDirs; - cmSystemTools::ExpandListArgument(linkDirsProp, linkDirs); - - for (std::string& linkDir : linkDirs) { - // Sanitize the path the same way the link_directories command does - // in case projects set the LINK_DIRECTORIES property directly. - cmSystemTools::ConvertToUnixSlashes(linkDir); - target.AddLinkDirectory(linkDir); - } - } if (const char* linkLibsProp = this->GetProperty("LINK_LIBRARIES")) { std::vector linkLibs; diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index bb01c0b..cde661b 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -182,6 +182,7 @@ public: void AddCompileDefinition(std::string const& definition); void AddCompileOption(std::string const& option); void AddLinkOption(std::string const& option); + void AddLinkDirectory(std::string const& directory); /** Create a new imported target with the name and type given. */ cmTarget* AddImportedTarget(const std::string& name, @@ -802,6 +803,8 @@ public: cmBacktraceRange GetCompileDefinitionsBacktraces() const; cmStringRange GetLinkOptionsEntries() const; cmBacktraceRange GetLinkOptionsBacktraces() const; + cmStringRange GetLinkDirectoriesEntries() const; + cmBacktraceRange GetLinkDirectoriesBacktraces() const; std::set const& GetSystemIncludeDirectories() const { diff --git a/Source/cmState.cxx b/Source/cmState.cxx index c6667f6..4b65cf1 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -284,6 +284,8 @@ cmStateSnapshot cmState::Reset() it->CompileOptionsBacktraces.clear(); it->LinkOptions.clear(); it->LinkOptionsBacktraces.clear(); + it->LinkDirectories.clear(); + it->LinkDirectoriesBacktraces.clear(); it->DirectoryEnd = pos; it->NormalTargetNames.clear(); it->Properties.clear(); @@ -660,6 +662,7 @@ cmStateSnapshot cmState::CreateBaseSnapshot() pos->CompileDefinitionsPosition = 0; pos->CompileOptionsPosition = 0; pos->LinkOptionsPosition = 0; + pos->LinkDirectoriesPosition = 0; pos->BuildSystemDirectory->DirectoryEnd = pos; pos->Policies = this->PolicyStack.Root(); pos->PolicyRoot = this->PolicyStack.Root(); @@ -813,6 +816,8 @@ cmStateSnapshot cmState::Pop(cmStateSnapshot const& originSnapshot) prevPos->BuildSystemDirectory->CompileOptions.size(); prevPos->LinkOptionsPosition = prevPos->BuildSystemDirectory->LinkOptions.size(); + prevPos->LinkDirectoriesPosition = + prevPos->BuildSystemDirectory->LinkDirectories.size(); prevPos->BuildSystemDirectory->DirectoryEnd = prevPos; if (!pos->Keep && this->SnapshotData.IsLast(pos)) { diff --git a/Source/cmStateDirectory.cxx b/Source/cmStateDirectory.cxx index 925b161..5160f51 100644 --- a/Source/cmStateDirectory.cxx +++ b/Source/cmStateDirectory.cxx @@ -396,6 +396,43 @@ void cmStateDirectory::ClearLinkOptions() this->Snapshot_.Position->LinkOptionsPosition); } +cmStringRange cmStateDirectory::GetLinkDirectoriesEntries() const +{ + return GetPropertyContent(this->DirectoryState->LinkDirectories, + this->Snapshot_.Position->LinkDirectoriesPosition); +} + +cmBacktraceRange cmStateDirectory::GetLinkDirectoriesEntryBacktraces() const +{ + return GetPropertyBacktraces( + this->DirectoryState->LinkDirectories, + this->DirectoryState->LinkDirectoriesBacktraces, + this->Snapshot_.Position->LinkDirectoriesPosition); +} + +void cmStateDirectory::AppendLinkDirectoriesEntry( + const std::string& vec, const cmListFileBacktrace& lfbt) +{ + AppendEntry(this->DirectoryState->LinkDirectories, + this->DirectoryState->LinkDirectoriesBacktraces, + this->Snapshot_.Position->LinkDirectoriesPosition, vec, lfbt); +} + +void cmStateDirectory::SetLinkDirectories(const std::string& vec, + const cmListFileBacktrace& lfbt) +{ + SetContent(this->DirectoryState->LinkDirectories, + this->DirectoryState->LinkDirectoriesBacktraces, + this->Snapshot_.Position->LinkDirectoriesPosition, vec, lfbt); +} + +void cmStateDirectory::ClearLinkDirectories() +{ + ClearContent(this->DirectoryState->LinkDirectories, + this->DirectoryState->LinkDirectoriesBacktraces, + this->Snapshot_.Position->LinkDirectoriesPosition); +} + void cmStateDirectory::SetProperty(const std::string& prop, const char* value, cmListFileBacktrace const& lfbt) { @@ -431,6 +468,14 @@ void cmStateDirectory::SetProperty(const std::string& prop, const char* value, this->SetLinkOptions(value, lfbt); return; } + if (prop == "LINK_DIRECTORIES") { + if (!value) { + this->ClearLinkDirectories(); + return; + } + this->SetLinkDirectories(value, lfbt); + return; + } this->DirectoryState->Properties.SetProperty(prop, value); } @@ -455,6 +500,10 @@ void cmStateDirectory::AppendProperty(const std::string& prop, this->AppendLinkOptionsEntry(value, lfbt); return; } + if (prop == "LINK_DIRECTORIES") { + this->AppendLinkDirectoriesEntry(value, lfbt); + return; + } this->DirectoryState->Properties.AppendProperty(prop, value, asString); } @@ -542,6 +591,10 @@ const char* cmStateDirectory::GetProperty(const std::string& prop, output = cmJoin(this->GetLinkOptionsEntries(), ";"); return output.c_str(); } + if (prop == "LINK_DIRECTORIES") { + output = cmJoin(this->GetLinkDirectoriesEntries(), ";"); + return output.c_str(); + } const char* retVal = this->DirectoryState->Properties.GetPropertyValue(prop); if (!retVal && chain) { diff --git a/Source/cmStateDirectory.h b/Source/cmStateDirectory.h index 412664f..06345e2 100644 --- a/Source/cmStateDirectory.h +++ b/Source/cmStateDirectory.h @@ -65,6 +65,14 @@ public: void SetLinkOptions(std::string const& vec, cmListFileBacktrace const& lfbt); void ClearLinkOptions(); + cmStringRange GetLinkDirectoriesEntries() const; + cmBacktraceRange GetLinkDirectoriesEntryBacktraces() const; + void AppendLinkDirectoriesEntry(std::string const& vec, + cmListFileBacktrace const& lfbt); + void SetLinkDirectories(std::string const& vec, + cmListFileBacktrace const& lfbt); + void ClearLinkDirectories(); + void SetProperty(const std::string& prop, const char* value, cmListFileBacktrace const& lfbt); void AppendProperty(const std::string& prop, const char* value, diff --git a/Source/cmStatePrivate.h b/Source/cmStatePrivate.h index 7177221..e76f2af 100644 --- a/Source/cmStatePrivate.h +++ b/Source/cmStatePrivate.h @@ -43,6 +43,7 @@ struct cmStateDetail::SnapshotDataType std::vector::size_type CompileDefinitionsPosition; std::vector::size_type CompileOptionsPosition; std::vector::size_type LinkOptionsPosition; + std::vector::size_type LinkDirectoriesPosition; }; struct cmStateDetail::PolicyStackEntry : public cmPolicies::PolicyMap @@ -88,6 +89,9 @@ struct cmStateDetail::BuildsystemDirectoryStateType std::vector LinkOptions; std::vector LinkOptionsBacktraces; + std::vector LinkDirectories; + std::vector LinkDirectoriesBacktraces; + std::vector NormalTargetNames; std::string ProjectName; diff --git a/Source/cmStateSnapshot.cxx b/Source/cmStateSnapshot.cxx index 0379e7e..c2510f3 100644 --- a/Source/cmStateSnapshot.cxx +++ b/Source/cmStateSnapshot.cxx @@ -398,6 +398,13 @@ void cmStateSnapshot::InitializeFromParent() this->Position->BuildSystemDirectory->LinkOptionsBacktraces, this->Position->LinkOptionsPosition); + InitializeContentFromParent( + parent->BuildSystemDirectory->LinkDirectories, + this->Position->BuildSystemDirectory->LinkDirectories, + parent->BuildSystemDirectory->LinkDirectoriesBacktraces, + this->Position->BuildSystemDirectory->LinkDirectoriesBacktraces, + this->Position->LinkDirectoriesPosition); + const char* include_regex = parent->BuildSystemDirectory->Properties.GetPropertyValue( "INCLUDE_REGULAR_EXPRESSION"); diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 6cf7c42..c5295f2 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -168,6 +168,8 @@ public: std::vector SourceBacktraces; std::vector LinkOptionsEntries; std::vector LinkOptionsBacktraces; + std::vector LinkDirectoriesEntries; + std::vector LinkDirectoriesBacktraces; std::vector LinkImplementationPropertyEntries; std::vector LinkImplementationPropertyBacktraces; }; @@ -391,6 +393,18 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, this->Internal->LinkOptionsBacktraces.insert( this->Internal->LinkOptionsBacktraces.end(), parentLinkOptionsBts.begin(), parentLinkOptionsBts.end()); + + const cmStringRange parentLinkDirectories = + this->Makefile->GetLinkDirectoriesEntries(); + const cmBacktraceRange parentLinkDirectoriesBts = + this->Makefile->GetLinkDirectoriesBacktraces(); + + this->Internal->LinkDirectoriesEntries.insert( + this->Internal->LinkDirectoriesEntries.end(), + parentLinkDirectories.begin(), parentLinkDirectories.end()); + this->Internal->LinkDirectoriesBacktraces.insert( + this->Internal->LinkDirectoriesBacktraces.end(), + parentLinkDirectoriesBts.begin(), parentLinkDirectoriesBts.end()); } if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY && @@ -654,19 +668,6 @@ cmSourceFile* cmTarget::AddSource(const std::string& src) cmSourceFileLocationKind::Known); } -void cmTarget::AddLinkDirectory(const std::string& d) -{ - // Make sure we don't add unnecessary search directories. - if (this->LinkDirectoriesEmmitted.insert(d).second) { - this->LinkDirectories.push_back(d); - } -} - -const std::vector& cmTarget::GetLinkDirectories() const -{ - return this->LinkDirectories; -} - void cmTarget::ClearDependencyInformation(cmMakefile& mf) { std::string depname = this->GetName(); @@ -874,6 +875,16 @@ cmBacktraceRange cmTarget::GetLinkOptionsBacktraces() const return cmMakeRange(this->Internal->LinkOptionsBacktraces); } +cmStringRange cmTarget::GetLinkDirectoriesEntries() const +{ + return cmMakeRange(this->Internal->LinkDirectoriesEntries); +} + +cmBacktraceRange cmTarget::GetLinkDirectoriesBacktraces() const +{ + return cmMakeRange(this->Internal->LinkDirectoriesBacktraces); +} + cmStringRange cmTarget::GetLinkImplementationEntries() const { return cmMakeRange(this->Internal->LinkImplementationPropertyEntries); @@ -900,6 +911,7 @@ void cmTarget::SetProperty(const std::string& prop, const char* value) MAKE_STATIC_PROP(IMPORTED_GLOBAL); MAKE_STATIC_PROP(INCLUDE_DIRECTORIES); MAKE_STATIC_PROP(LINK_OPTIONS); + MAKE_STATIC_PROP(LINK_DIRECTORIES); MAKE_STATIC_PROP(LINK_LIBRARIES); MAKE_STATIC_PROP(MANUALLY_ADDED_DEPENDENCIES); MAKE_STATIC_PROP(NAME); @@ -986,6 +998,14 @@ void cmTarget::SetProperty(const std::string& prop, const char* value) cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); this->Internal->LinkOptionsBacktraces.push_back(lfbt); } + } else if (prop == propLINK_DIRECTORIES) { + this->Internal->LinkDirectoriesEntries.clear(); + this->Internal->LinkDirectoriesBacktraces.clear(); + if (value) { + this->Internal->LinkDirectoriesEntries.push_back(value); + cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); + this->Internal->LinkDirectoriesBacktraces.push_back(lfbt); + } } else if (prop == propLINK_LIBRARIES) { this->Internal->LinkImplementationPropertyEntries.clear(); this->Internal->LinkImplementationPropertyBacktraces.clear(); @@ -1097,6 +1117,12 @@ void cmTarget::AppendProperty(const std::string& prop, const char* value, cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); this->Internal->LinkOptionsBacktraces.push_back(lfbt); } + } else if (prop == "LINK_DIRECTORIES") { + if (value && *value) { + this->Internal->LinkDirectoriesEntries.push_back(value); + cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); + this->Internal->LinkDirectoriesBacktraces.push_back(lfbt); + } } else if (prop == "LINK_LIBRARIES") { if (value && *value) { cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); @@ -1194,6 +1220,21 @@ void cmTarget::InsertLinkOption(std::string const& entry, this->Internal->LinkOptionsBacktraces.insert(btPosition, bt); } +void cmTarget::InsertLinkDirectory(std::string const& entry, + cmListFileBacktrace const& bt, bool before) +{ + std::vector::iterator position = before + ? this->Internal->LinkDirectoriesEntries.begin() + : this->Internal->LinkDirectoriesEntries.end(); + + std::vector::iterator btPosition = before + ? this->Internal->LinkDirectoriesBacktraces.begin() + : this->Internal->LinkDirectoriesBacktraces.end(); + + this->Internal->LinkDirectoriesEntries.insert(position, entry); + this->Internal->LinkDirectoriesBacktraces.insert(btPosition, bt); +} + static void cmTargetCheckLINK_INTERFACE_LIBRARIES(const std::string& prop, const char* value, cmMakefile* context, @@ -1314,6 +1355,7 @@ const char* cmTarget::GetProperty(const std::string& prop) const MAKE_STATIC_PROP(COMPILE_OPTIONS); MAKE_STATIC_PROP(COMPILE_DEFINITIONS); MAKE_STATIC_PROP(LINK_OPTIONS); + MAKE_STATIC_PROP(LINK_DIRECTORIES); MAKE_STATIC_PROP(IMPORTED); MAKE_STATIC_PROP(IMPORTED_GLOBAL); MAKE_STATIC_PROP(MANUALLY_ADDED_DEPENDENCIES); @@ -1330,6 +1372,7 @@ const char* cmTarget::GetProperty(const std::string& prop) const specialProps.insert(propCOMPILE_OPTIONS); specialProps.insert(propCOMPILE_DEFINITIONS); specialProps.insert(propLINK_OPTIONS); + specialProps.insert(propLINK_DIRECTORIES); specialProps.insert(propIMPORTED); specialProps.insert(propIMPORTED_GLOBAL); specialProps.insert(propMANUALLY_ADDED_DEPENDENCIES); @@ -1397,6 +1440,16 @@ const char* cmTarget::GetProperty(const std::string& prop) const output = cmJoin(this->Internal->LinkOptionsEntries, ";"); return output.c_str(); } + if (prop == propLINK_DIRECTORIES) { + if (this->Internal->LinkDirectoriesEntries.empty()) { + return nullptr; + } + + static std::string output; + output = cmJoin(this->Internal->LinkDirectoriesEntries, ";"); + + return output.c_str(); + } if (prop == propMANUALLY_ADDED_DEPENDENCIES) { if (this->Utilities.empty()) { return nullptr; diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 1f380df..694de1c 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -154,10 +154,6 @@ public: cmListFileContext const& lfc); void GetTllSignatureTraces(std::ostream& s, TLLSignature sig) const; - const std::vector& GetLinkDirectories() const; - - void AddLinkDirectory(const std::string& d); - /** * Set the path where this target should be installed. This is relative to * INSTALL_PREFIX @@ -247,6 +243,8 @@ public: cmListFileBacktrace const& bt); void InsertLinkOption(std::string const& entry, cmListFileBacktrace const& bt, bool before = false); + void InsertLinkDirectory(std::string const& entry, + cmListFileBacktrace const& bt, bool before = false); void AppendBuildInterfaceIncludes(); @@ -277,6 +275,9 @@ public: cmStringRange GetLinkOptionsEntries() const; cmBacktraceRange GetLinkOptionsBacktraces() const; + cmStringRange GetLinkDirectoriesEntries() const; + cmBacktraceRange GetLinkDirectoriesBacktraces() const; + cmStringRange GetLinkImplementationEntries() const; cmBacktraceRange GetLinkImplementationBacktraces() const; @@ -306,14 +307,12 @@ private: bool IsGeneratorProvided; cmPropertyMap Properties; std::set SystemIncludeDirectories; - std::set LinkDirectoriesEmmitted; std::set Utilities; std::map UtilityBacktraces; cmPolicies::PolicyMap PolicyMap; std::string Name; std::string InstallPath; std::string RuntimeInstallPath; - std::vector LinkDirectories; std::vector PreBuildCommands; std::vector PreLinkCommands; std::vector PostBuildCommands; diff --git a/Source/cmTargetLinkDirectoriesCommand.cxx b/Source/cmTargetLinkDirectoriesCommand.cxx new file mode 100644 index 0000000..bca3e45 --- /dev/null +++ b/Source/cmTargetLinkDirectoriesCommand.cxx @@ -0,0 +1,61 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmTargetLinkDirectoriesCommand.h" + +#include + +#include "cmAlgorithms.h" +#include "cmGeneratorExpression.h" +#include "cmListFileCache.h" +#include "cmMakefile.h" +#include "cmSystemTools.h" +#include "cmTarget.h" +#include "cmake.h" + +class cmExecutionStatus; + +bool cmTargetLinkDirectoriesCommand::InitialPass( + std::vector const& args, cmExecutionStatus&) +{ + return this->HandleArguments(args, "LINK_DIRECTORIES", PROCESS_BEFORE); +} + +void cmTargetLinkDirectoriesCommand::HandleMissingTarget( + const std::string& name) +{ + std::ostringstream e; + e << "Cannot specify link directories for target \"" << name + << "\" which is not built by this project."; + this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); +} + +std::string cmTargetLinkDirectoriesCommand::Join( + const std::vector& content) +{ + std::vector directories; + + for (const auto& dir : content) { + auto unixPath = dir; + cmSystemTools::ConvertToUnixSlashes(unixPath); + if (!cmSystemTools::FileIsFullPath(unixPath) && + !cmGeneratorExpression::StartsWithGeneratorExpression(unixPath)) { + auto tmp = this->Makefile->GetCurrentSourceDirectory(); + tmp += "/"; + tmp += unixPath; + unixPath = tmp; + } + directories.push_back(unixPath); + } + + return cmJoin(directories, ";"); +} + +bool cmTargetLinkDirectoriesCommand::HandleDirectContent( + cmTarget* tgt, const std::vector& content, bool prepend, bool) +{ + cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); + + tgt->InsertLinkDirectory(this->Join(content), lfbt, prepend); + + return true; // Successfully handled. +} diff --git a/Source/cmTargetLinkDirectoriesCommand.h b/Source/cmTargetLinkDirectoriesCommand.h new file mode 100644 index 0000000..52c75a0 --- /dev/null +++ b/Source/cmTargetLinkDirectoriesCommand.h @@ -0,0 +1,41 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmTargetLinkDirectoriesCommand_h +#define cmTargetLinkDirectoriesCommand_h + +#include "cmConfigure.h" // IWYU pragma: keep + +#include +#include + +#include "cmTargetPropCommandBase.h" + +class cmCommand; +class cmExecutionStatus; +class cmTarget; + +class cmTargetLinkDirectoriesCommand : public cmTargetPropCommandBase +{ +public: + /** + * This is a virtual constructor for the command. + */ + cmCommand* Clone() override { return new cmTargetLinkDirectoriesCommand; } + + /** + * This is called when the command is first encountered in + * the CMakeLists.txt file. + */ + bool InitialPass(std::vector const& args, + cmExecutionStatus& status) override; + +private: + void HandleMissingTarget(const std::string& name) override; + + std::string Join(const std::vector& content) override; + bool HandleDirectContent(cmTarget* tgt, + const std::vector& content, + bool prepend, bool system) override; +}; + +#endif diff --git a/Tests/CMakeCommands/target_link_directories/CMakeLists.txt b/Tests/CMakeCommands/target_link_directories/CMakeLists.txt new file mode 100644 index 0000000..bc7b9b2 --- /dev/null +++ b/Tests/CMakeCommands/target_link_directories/CMakeLists.txt @@ -0,0 +1,40 @@ + +cmake_minimum_required(VERSION 3.12) + +project(target_link_directories LANGUAGES C) + +add_library(target_link_directories SHARED LinkDirectoriesLib.c) +# Test no items +target_link_directories(target_link_directories PRIVATE) + +add_library(target_link_directories_2 SHARED EXCLUDE_FROM_ALL LinkDirectoriesLib.c) +target_link_directories(target_link_directories_2 PRIVATE /private/dir INTERFACE /interface/dir) +get_target_property(result target_link_directories_2 LINK_DIRECTORIES) +if (NOT result MATCHES "/private/dir") + message(SEND_ERROR "${result} target_link_directories not populated the LINK_DIRECTORIES target property") +endif() +get_target_property(result target_link_directories_2 INTERFACE_LINK_DIRECTORIES) +if (NOT result MATCHES "/interface/dir") + message(SEND_ERROR "target_link_directories not populated the INTERFACE_LINK_DIRECTORIES target property of shared library") +endif() + +add_library(target_link_directories_3 STATIC EXCLUDE_FROM_ALL LinkDirectoriesLib.c) +target_link_directories(target_link_directories_3 INTERFACE /interface/dir) +get_target_property(result target_link_directories_3 INTERFACE_LINK_DIRECTORIES) +if (NOT result MATCHES "/interface/dir") + message(SEND_ERROR "target_link_directories not populated the INTERFACE_LINK_DIRECTORIES target property of static library") +endif() + +add_library(target_link_directories_4 SHARED EXCLUDE_FROM_ALL LinkDirectoriesLib.c) +target_link_directories(target_link_directories_4 PRIVATE relative/dir) +get_target_property(result target_link_directories_4 LINK_DIRECTORIES) +if (NOT result MATCHES "${CMAKE_CURRENT_SOURCE_DIR}/relative/dir") + message(SEND_ERROR "target_link_directories not populated the LINK_DIRECTORIES with relative path") +endif() + +add_subdirectory(subdir) +target_link_directories(target_link_directories_5 PRIVATE relative/dir) +get_target_property(result target_link_directories_5 LINK_DIRECTORIES) +if (NOT result MATCHES "${CMAKE_CURRENT_SOURCE_DIR}/relative/dir") + message(SEND_ERROR "target_link_directories not populated the LINK_DIRECTORIES with relative path") +endif() diff --git a/Tests/CMakeCommands/target_link_directories/LinkDirectoriesLib.c b/Tests/CMakeCommands/target_link_directories/LinkDirectoriesLib.c new file mode 100644 index 0000000..9bbd24c --- /dev/null +++ b/Tests/CMakeCommands/target_link_directories/LinkDirectoriesLib.c @@ -0,0 +1,7 @@ +#if defined(_WIN32) +__declspec(dllexport) +#endif + int flags_lib(void) +{ + return 0; +} diff --git a/Tests/CMakeCommands/target_link_directories/subdir/CMakeLists.txt b/Tests/CMakeCommands/target_link_directories/subdir/CMakeLists.txt new file mode 100644 index 0000000..7e7ad2a --- /dev/null +++ b/Tests/CMakeCommands/target_link_directories/subdir/CMakeLists.txt @@ -0,0 +1,2 @@ + +add_library(target_link_directories_5 SHARED EXCLUDE_FROM_ALL ../LinkDirectoriesLib.c) diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index fb44077..4753aac 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -2823,6 +2823,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release ADD_TEST_MACRO(CMakeCommands.add_compile_definitions add_compile_definitions) ADD_TEST_MACRO(CMakeCommands.add_compile_options add_compile_options) ADD_TEST_MACRO(CMakeCommands.target_link_libraries target_link_libraries) + ADD_TEST_MACRO(CMakeCommands.target_link_directories) ADD_TEST_MACRO(CMakeCommands.target_include_directories target_include_directories) ADD_TEST_MACRO(CMakeCommands.target_compile_definitions target_compile_definitions) ADD_TEST_MACRO(CMakeCommands.target_compile_options target_compile_options) diff --git a/Tests/ExportImport/Export/CMakeLists.txt b/Tests/ExportImport/Export/CMakeLists.txt index cb048be..c6b7dbc 100644 --- a/Tests/ExportImport/Export/CMakeLists.txt +++ b/Tests/ExportImport/Export/CMakeLists.txt @@ -619,6 +619,18 @@ export(TARGETS testLinkOptions NAMESPACE bld_ APPEND FILE ExportBuildTree.cmake) #------------------------------------------------------------------------------ +# test export of INTERFACE_LINK_DIRECTORIES +add_library(testLinkDirectories INTERFACE) +target_link_directories(testLinkDirectories INTERFACE + $ + $) + +install(TARGETS testLinkDirectories + EXPORT RequiredExp DESTINATION lib) +export(TARGETS testLinkDirectories NAMESPACE bld_ APPEND FILE ExportBuildTree.cmake) + + +#------------------------------------------------------------------------------ # test export of INTERFACE_LINK_DEPENDS if(CMAKE_GENERATOR MATCHES "Make|Ninja") add_library(testLinkDepends INTERFACE) diff --git a/Tests/ExportImport/Import/A/CMakeLists.txt b/Tests/ExportImport/Import/A/CMakeLists.txt index 8791a19..67fcc02 100644 --- a/Tests/ExportImport/Import/A/CMakeLists.txt +++ b/Tests/ExportImport/Import/A/CMakeLists.txt @@ -490,6 +490,11 @@ checkForProperty(bld_testLinkOptions "INTERFACE_LINK_OPTIONS" "INTERFACE_FLAG") checkForProperty(Req::testLinkOptions "INTERFACE_LINK_OPTIONS" "INTERFACE_FLAG") #--------------------------------------------------------------------------------- +# check that imported libraries have the expected INTERFACE_LINK_DIRECTORIES property +checkForProperty(bld_testLinkDirectories "INTERFACE_LINK_DIRECTORIES" "/interface/build") +checkForProperty(Req::testLinkDirectories "INTERFACE_LINK_DIRECTORIES" "${CMAKE_INSTALL_PREFIX}/interface/install") + +#--------------------------------------------------------------------------------- # check that imported libraries have the expected INTERFACE_LINK_DEPENDS property if(CMAKE_GENERATOR MATCHES "Make|Ninja") checkForProperty(bld_testLinkDepends "INTERFACE_LINK_DEPENDS" "BUILD_LINK_DEPENDS") diff --git a/Tests/LinkDirectory/External/CMakeLists.txt b/Tests/LinkDirectory/External/CMakeLists.txt index f7c840f..d2a1f9f 100644 --- a/Tests/LinkDirectory/External/CMakeLists.txt +++ b/Tests/LinkDirectory/External/CMakeLists.txt @@ -1,6 +1,20 @@ cmake_minimum_required(VERSION 2.8) project(LinkDirectoryExternal C) + +add_executable(myexe2 myexe.c) +set_property(TARGET myexe2 PROPERTY OUTPUT_NAME LinkDirectory2) +target_link_directories(myexe2 PRIVATE lib "${CMAKE_CURRENT_SOURCE_DIR}/../lib") +target_link_libraries(myexe2 PRIVATE mylibA mylibB) + +add_library (mylibs INTERFACE) +target_link_directories(mylibs INTERFACE lib "${CMAKE_CURRENT_SOURCE_DIR}/../lib") +target_link_libraries(mylibs INTERFACE mylibA mylibB) +add_executable(myexe3 myexe.c) +set_property(TARGET myexe3 PROPERTY OUTPUT_NAME LinkDirectory3) +target_link_libraries(myexe3 PRIVATE mylibs) + + # Test CMP0015 OLD behavior: -L../lib cmake_policy(SET CMP0015 OLD) link_directories(../lib) diff --git a/Tests/RunCMake/set_property/LINK_DIRECTORIES-stdout.txt b/Tests/RunCMake/set_property/LINK_DIRECTORIES-stdout.txt new file mode 100644 index 0000000..580c373 --- /dev/null +++ b/Tests/RunCMake/set_property/LINK_DIRECTORIES-stdout.txt @@ -0,0 +1,2 @@ +-- Target LINK_DIRECTORIES is 'a;b;c;d;;e' +-- Directory LINK_DIRECTORIES is 'a;b;c;d;;e' diff --git a/Tests/RunCMake/set_property/LINK_DIRECTORIES.cmake b/Tests/RunCMake/set_property/LINK_DIRECTORIES.cmake new file mode 100644 index 0000000..8529ef5 --- /dev/null +++ b/Tests/RunCMake/set_property/LINK_DIRECTORIES.cmake @@ -0,0 +1,3 @@ +include(Common.cmake) +test_target_property(LINK_DIRECTORIES) +test_directory_property(LINK_DIRECTORIES) diff --git a/Tests/RunCMake/set_property/RunCMakeTest.cmake b/Tests/RunCMake/set_property/RunCMakeTest.cmake index 77da703..8d4614c 100644 --- a/Tests/RunCMake/set_property/RunCMakeTest.cmake +++ b/Tests/RunCMake/set_property/RunCMakeTest.cmake @@ -6,6 +6,7 @@ run_cmake(COMPILE_OPTIONS) run_cmake(IMPORTED_GLOBAL) run_cmake(INCLUDE_DIRECTORIES) run_cmake(LINK_OPTIONS) +run_cmake(LINK_DIRECTORIES) run_cmake(LINK_LIBRARIES) run_cmake(SOURCES) run_cmake(TYPE) https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=5ca130e22394978814a9e59418529a7a3e1a61bd commit 5ca130e22394978814a9e59418529a7a3e1a61bd Author: Marc Chevrier AuthorDate: Sat Sep 22 14:25:21 2018 +0200 Commit: Craig Scott CommitDate: Tue Sep 25 23:46:56 2018 +1000 Refactoring: introduce function to check if a string is a generator expression diff --git a/Source/cmGeneratorExpression.cxx b/Source/cmGeneratorExpression.cxx index 658e9a7..2727d9a 100644 --- a/Source/cmGeneratorExpression.cxx +++ b/Source/cmGeneratorExpression.cxx @@ -168,7 +168,7 @@ static std::string stripAllGeneratorExpressions(const std::string& input) const char* c = input.c_str() + pos; const char* const cStart = c; for (; *c; ++c) { - if (c[0] == '$' && c[1] == '<') { + if (cmGeneratorExpression::StartsWithGeneratorExpression(c)) { ++nestingLevel; ++c; continue; @@ -243,7 +243,7 @@ static std::string stripExportInterface( const char* c = input.c_str() + pos; const char* const cStart = c; for (; *c; ++c) { - if (c[0] == '$' && c[1] == '<') { + if (cmGeneratorExpression::StartsWithGeneratorExpression(c)) { ++nestingLevel; ++c; continue; @@ -310,7 +310,7 @@ void cmGeneratorExpression::Split(const std::string& input, const char* c = input.c_str() + pos; const char* const cStart = c; for (; *c; ++c) { - if (c[0] == '$' && c[1] == '<') { + if (cmGeneratorExpression::StartsWithGeneratorExpression(c)) { ++nestingLevel; ++c; continue; diff --git a/Source/cmGeneratorExpression.h b/Source/cmGeneratorExpression.h index 8176d5c..9c05f60 100644 --- a/Source/cmGeneratorExpression.h +++ b/Source/cmGeneratorExpression.h @@ -63,6 +63,15 @@ public: static std::string StripEmptyListElements(const std::string& input); + static inline bool StartsWithGeneratorExpression(const std::string& input) + { + return input.length() >= 2 && input[0] == '$' && input[1] == '<'; + } + static inline bool StartsWithGeneratorExpression(const char* input) + { + return input != nullptr && input[0] == '$' && input[1] == '<'; + } + private: cmListFileBacktrace Backtrace; }; diff --git a/Source/cmIncludeDirectoryCommand.cxx b/Source/cmIncludeDirectoryCommand.cxx index eaaf64d..caec67d 100644 --- a/Source/cmIncludeDirectoryCommand.cxx +++ b/Source/cmIncludeDirectoryCommand.cxx @@ -5,6 +5,7 @@ #include #include +#include "cmGeneratorExpression.h" #include "cmMakefile.h" #include "cmSystemTools.h" @@ -69,11 +70,6 @@ bool cmIncludeDirectoryCommand::InitialPass( return true; } -static bool StartsWithGeneratorExpression(const std::string& input) -{ - return input[0] == '$' && input[1] == '<'; -} - // do a lot of cleanup on the arguments because this is one place where folks // sometimes take the output of a program and pass it directly into this // command not thinking that a single argument could be filled with spaces @@ -124,7 +120,7 @@ void cmIncludeDirectoryCommand::NormalizeInclude(std::string& inc) cmSystemTools::ConvertToUnixSlashes(inc); if (!cmSystemTools::FileIsFullPath(inc)) { - if (!StartsWithGeneratorExpression(inc)) { + if (!cmGeneratorExpression::StartsWithGeneratorExpression(inc)) { std::string tmp = this->Makefile->GetCurrentSourceDirectory(); tmp += "/"; tmp += inc; diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 4e353c7..6cf7c42 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -514,9 +514,7 @@ void cmTarget::AddSources(std::vector const& srcs) std::string srcFiles; const char* sep = ""; for (auto filename : srcs) { - const char* src = filename.c_str(); - - if (!(src[0] == '$' && src[1] == '<')) { + if (!cmGeneratorExpression::StartsWithGeneratorExpression(filename)) { if (!filename.empty()) { filename = this->ProcessSourceItemCMP0049(filename); if (filename.empty()) { ----------------------------------------------------------------------- Summary of changes: Help/command/link_directories.rst | 50 ++++++-- Help/command/target_link_directories.rst | 55 +++++++++ Help/manual/cmake-commands.7.rst | 1 + Help/manual/cmake-policies.7.rst | 1 + Help/manual/cmake-properties.7.rst | 2 + Help/manual/cmake-variables.7.rst | 1 + Help/policy/CMP0081.rst | 22 ++++ Help/prop_dir/LINK_DIRECTORIES.rst | 15 ++- Help/prop_tgt/INTERFACE_LINK_DIRECTORIES.rst | 9 ++ Help/prop_tgt/LINK_DIRECTORIES.rst | 18 +++ Help/release/dev/LINK_DIRECTORIES-policy.rst | 5 + Help/release/dev/LINK_DIRECTORIES.rst | 9 ++ Help/release/dev/link_directories-enhancements.rst | 5 + Help/variable/CMAKE_LINK_DIRECTORIES_BEFORE.rst | 9 ++ Source/CMakeLists.txt | 2 + Source/cmCPluginAPI.cxx | 2 +- Source/cmCommands.cxx | 3 + Source/cmComputeLinkInformation.cxx | 11 +- Source/cmExportBuildFileGenerator.cxx | 3 + Source/cmExportFileGenerator.cxx | 31 +++++ Source/cmExportFileGenerator.h | 4 + Source/cmExportInstallFileGenerator.cxx | 2 + Source/cmGeneratorExpression.cxx | 6 +- Source/cmGeneratorExpression.h | 9 ++ Source/cmGeneratorExpressionDAGChecker.h | 1 + Source/cmGeneratorTarget.cxx | 131 ++++++++++++++++++++- Source/cmGeneratorTarget.h | 8 +- Source/cmIncludeDirectoryCommand.cxx | 8 +- Source/cmLinkDirectoriesCommand.cxx | 30 ++++- Source/cmLinkDirectoriesCommand.h | 3 +- Source/cmMakefile.cxx | 38 +++--- Source/cmMakefile.h | 3 + Source/cmPolicies.h | 8 +- Source/cmState.cxx | 5 + Source/cmStateDirectory.cxx | 80 +++++++++++++ Source/cmStateDirectory.h | 10 ++ Source/cmStatePrivate.h | 4 + Source/cmStateSnapshot.cxx | 7 ++ Source/cmTarget.cxx | 83 ++++++++++--- Source/cmTarget.h | 11 +- Source/cmTargetLinkDirectoriesCommand.cxx | 61 ++++++++++ Source/cmTargetLinkDirectoriesCommand.h | 41 +++++++ .../CMakeCommands/link_directories/CMakeLists.txt | 30 +++++ .../link_directories/LinkDirectoriesExe.c} | 0 .../target_link_directories/CMakeLists.txt | 40 +++++++ .../target_link_directories/LinkDirectoriesLib.c} | 0 .../target_link_directories/subdir/CMakeLists.txt | 2 + Tests/CMakeLists.txt | 2 + Tests/ExportImport/Export/CMakeLists.txt | 12 ++ Tests/ExportImport/Import/A/CMakeLists.txt | 5 + Tests/LinkDirectory/External/CMakeLists.txt | 14 +++ Tests/RunCMake/CMP0081/CMP0081-Common.cmake | 5 + .../CMP0081-NEW-result.txt} | 0 Tests/RunCMake/CMP0081/CMP0081-NEW-stderr.txt | 4 + Tests/RunCMake/CMP0081/CMP0081-NEW.cmake | 4 + .../CMP0081-OLD-result.txt} | 0 Tests/RunCMake/CMP0081/CMP0081-OLD.cmake | 4 + .../CMP0081-WARN-result.txt} | 0 Tests/RunCMake/CMP0081/CMP0081-WARN-stderr.txt | 10 ++ Tests/RunCMake/CMP0081/CMP0081-WARN.cmake | 2 + Tests/RunCMake/{return => CMP0081}/CMakeLists.txt | 0 Tests/RunCMake/CMP0081/RunCMakeTest.cmake | 5 + .../{target_link_libraries => CMP0081}/empty.cpp | 0 Tests/RunCMake/CMakeLists.txt | 1 + .../RunCMake/TargetPolicies/PolicyList-stderr.txt | 1 + .../set_property/LINK_DIRECTORIES-stdout.txt | 2 + Tests/RunCMake/set_property/LINK_DIRECTORIES.cmake | 3 + Tests/RunCMake/set_property/RunCMakeTest.cmake | 1 + 68 files changed, 874 insertions(+), 80 deletions(-) create mode 100644 Help/command/target_link_directories.rst create mode 100644 Help/policy/CMP0081.rst create mode 100644 Help/prop_tgt/INTERFACE_LINK_DIRECTORIES.rst create mode 100644 Help/prop_tgt/LINK_DIRECTORIES.rst create mode 100644 Help/release/dev/LINK_DIRECTORIES-policy.rst create mode 100644 Help/release/dev/LINK_DIRECTORIES.rst create mode 100644 Help/release/dev/link_directories-enhancements.rst create mode 100644 Help/variable/CMAKE_LINK_DIRECTORIES_BEFORE.rst create mode 100644 Source/cmTargetLinkDirectoriesCommand.cxx create mode 100644 Source/cmTargetLinkDirectoriesCommand.h create mode 100644 Tests/CMakeCommands/link_directories/CMakeLists.txt copy Tests/{Wrapping/wrapFLTK.cxx => CMakeCommands/link_directories/LinkDirectoriesExe.c} (100%) create mode 100644 Tests/CMakeCommands/target_link_directories/CMakeLists.txt copy Tests/{RunCMake/target_link_options/LinkOptionsLib.c => CMakeCommands/target_link_directories/LinkDirectoriesLib.c} (100%) create mode 100644 Tests/CMakeCommands/target_link_directories/subdir/CMakeLists.txt create mode 100644 Tests/RunCMake/CMP0081/CMP0081-Common.cmake copy Tests/RunCMake/{while/MissingArgument-result.txt => CMP0081/CMP0081-NEW-result.txt} (100%) create mode 100644 Tests/RunCMake/CMP0081/CMP0081-NEW-stderr.txt create mode 100644 Tests/RunCMake/CMP0081/CMP0081-NEW.cmake copy Tests/RunCMake/{target_link_options/LINK_OPTIONS-static-result.txt => CMP0081/CMP0081-OLD-result.txt} (100%) create mode 100644 Tests/RunCMake/CMP0081/CMP0081-OLD.cmake copy Tests/RunCMake/{target_link_options/LINK_OPTIONS-static-result.txt => CMP0081/CMP0081-WARN-result.txt} (100%) create mode 100644 Tests/RunCMake/CMP0081/CMP0081-WARN-stderr.txt create mode 100644 Tests/RunCMake/CMP0081/CMP0081-WARN.cmake copy Tests/RunCMake/{return => CMP0081}/CMakeLists.txt (100%) create mode 100644 Tests/RunCMake/CMP0081/RunCMakeTest.cmake copy Tests/RunCMake/{target_link_libraries => CMP0081}/empty.cpp (100%) create mode 100644 Tests/RunCMake/set_property/LINK_DIRECTORIES-stdout.txt create mode 100644 Tests/RunCMake/set_property/LINK_DIRECTORIES.cmake hooks/post-receive -- CMake From kwrobot at kitware.com Wed Sep 26 10:05:04 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Wed, 26 Sep 2018 10:05:04 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-729-g5f702f9 Message-ID: <20180926140504.B155D11EB9C@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 5f702f97a89129a39bcf1ecf9823d60a2793e35e (commit) via 3c8187f68730b180cd6fad898eb81bdeaf488bb8 (commit) via 6c2af9d302f1c893219f2aad014a2b183bb438a1 (commit) from 3181f8405bc949affb8ea321ec7746b44717fd99 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=5f702f97a89129a39bcf1ecf9823d60a2793e35e commit 5f702f97a89129a39bcf1ecf9823d60a2793e35e Merge: 3181f84 3c8187f Author: Brad King AuthorDate: Wed Sep 26 14:00:45 2018 +0000 Commit: Kitware Robot CommitDate: Wed Sep 26 10:01:09 2018 -0400 Merge topic 'refactor-backtrace' 3c8187f687 clang-tidy: restore 'misc-noexcept-move-constructor' 6c2af9d302 cmListFileCache: Add missing assertion in backtrace Top method Acked-by: Kitware Robot Merge-request: !2415 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=3c8187f68730b180cd6fad898eb81bdeaf488bb8 commit 3c8187f68730b180cd6fad898eb81bdeaf488bb8 Author: Brad King AuthorDate: Wed Sep 26 06:38:52 2018 -0400 Commit: Brad King CommitDate: Wed Sep 26 06:38:52 2018 -0400 clang-tidy: restore 'misc-noexcept-move-constructor' We disabled this in commit 1fe0d72eb6 (clang-tidy: exclude 'misc-noexcept-move-constructor', 2018-09-24) due to false positives. Restore it and use a NOLINT comment to suppress them instead. diff --git a/.clang-tidy b/.clang-tidy index ebe3c20..8d79b0c 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -5,7 +5,6 @@ misc-*,\ -misc-incorrect-roundings,\ -misc-macro-parentheses,\ -misc-misplaced-widening-cast,\ --misc-noexcept-move-constructor,\ -misc-static-assert,\ modernize-*,\ -modernize-deprecated-headers,\ diff --git a/Source/cmListFileCache.h b/Source/cmListFileCache.h index faddec7..3d3afdf 100644 --- a/Source/cmListFileCache.h +++ b/Source/cmListFileCache.h @@ -124,9 +124,11 @@ public: // Backtraces may be copied, moved, and assigned as values. cmListFileBacktrace(cmListFileBacktrace const&) = default; - cmListFileBacktrace(cmListFileBacktrace&&) noexcept = default; + cmListFileBacktrace(cmListFileBacktrace&&) // NOLINT(clang-tidy) + noexcept = default; cmListFileBacktrace& operator=(cmListFileBacktrace const&) = default; - cmListFileBacktrace& operator=(cmListFileBacktrace&&) noexcept = default; + cmListFileBacktrace& operator=(cmListFileBacktrace&&) // NOLINT(clang-tidy) + noexcept = default; ~cmListFileBacktrace() = default; cmStateSnapshot GetBottom() const; https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=6c2af9d302f1c893219f2aad014a2b183bb438a1 commit 6c2af9d302f1c893219f2aad014a2b183bb438a1 Author: Brad King AuthorDate: Tue Sep 25 10:41:29 2018 -0400 Commit: Brad King CommitDate: Wed Sep 26 06:32:21 2018 -0400 cmListFileCache: Add missing assertion in backtrace Top method We can only get the top of a stack that has at least one call. Update the method's comment accordingly. diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx index e465e1a..4d7e1e2 100644 --- a/Source/cmListFileCache.cxx +++ b/Source/cmListFileCache.cxx @@ -377,6 +377,7 @@ cmListFileBacktrace cmListFileBacktrace::Pop() const cmListFileContext const& cmListFileBacktrace::Top() const { assert(this->TopEntry); + assert(!this->TopEntry->IsBottom()); return this->TopEntry->Context; } diff --git a/Source/cmListFileCache.h b/Source/cmListFileCache.h index 2c91f7a..faddec7 100644 --- a/Source/cmListFileCache.h +++ b/Source/cmListFileCache.h @@ -144,7 +144,7 @@ public: cmListFileBacktrace Pop() const; // Get the context at the top of the backtrace. - // Returns an empty context if the backtrace is empty. + // This may be called only if Empty() would return false. cmListFileContext const& Top() const; // Print the top of the backtrace. ----------------------------------------------------------------------- Summary of changes: .clang-tidy | 1 - Source/cmListFileCache.cxx | 1 + Source/cmListFileCache.h | 8 +++++--- 3 files changed, 6 insertions(+), 4 deletions(-) hooks/post-receive -- CMake From kwrobot at kitware.com Wed Sep 26 10:15:05 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Wed, 26 Sep 2018 10:15:05 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-733-ga57225c Message-ID: <20180926141505.4FB0A11394E@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via a57225c4fc5cbbf063d86e0f911c552bc0fabb9d (commit) via c8137850445d180bd5f3b55d4f9e80d9cbcf0baa (commit) via 98dfdab19c07cf795678000c1681ea063843b0ed (commit) via 0da645d4523474093f36d66722dfcd3aa008a40d (commit) from 5f702f97a89129a39bcf1ecf9823d60a2793e35e (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=a57225c4fc5cbbf063d86e0f911c552bc0fabb9d commit a57225c4fc5cbbf063d86e0f911c552bc0fabb9d Merge: c813785 98dfdab Author: Brad King AuthorDate: Wed Sep 26 14:06:29 2018 +0000 Commit: Kitware Robot CommitDate: Wed Sep 26 10:07:01 2018 -0400 Merge topic 'FindLua-names-per-dir' 98dfdab19c FindLua: Search for all library names in each path Acked-by: Kitware Robot Acked-by: Rolf Eike Beer Merge-request: !2412 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=c8137850445d180bd5f3b55d4f9e80d9cbcf0baa commit c8137850445d180bd5f3b55d4f9e80d9cbcf0baa Merge: 5f702f9 0da645d Author: Brad King AuthorDate: Wed Sep 26 14:06:15 2018 +0000 Commit: Kitware Robot CommitDate: Wed Sep 26 10:06:21 2018 -0400 Merge topic 'FindGLUT-windows-debug' 0da645d452 FindGLUT: Find debug/release variants on Windows Acked-by: Kitware Robot Merge-request: !2398 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=98dfdab19c07cf795678000c1681ea063843b0ed commit 98dfdab19c07cf795678000c1681ea063843b0ed Author: Brad King AuthorDate: Tue Sep 25 09:32:45 2018 -0400 Commit: Brad King CommitDate: Tue Sep 25 09:32:45 2018 -0400 FindLua: Search for all library names in each path Add the `NAMES_PER_DIR` option to our `find_library` call so that all names are considered in each path as we proceed through the search. This allows locally-built unversioned libraries to be found before versioned system libraries if they appear earlier in the set of paths to be searched. Suggested-by: Alan W. Irwin diff --git a/Modules/FindLua.cmake b/Modules/FindLua.cmake index e86c15c..68530b3 100644 --- a/Modules/FindLua.cmake +++ b/Modules/FindLua.cmake @@ -198,6 +198,7 @@ endif () find_library(LUA_LIBRARY NAMES ${_lua_library_names} lua + NAMES_PER_DIR HINTS ENV LUA_DIR PATH_SUFFIXES lib https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=0da645d4523474093f36d66722dfcd3aa008a40d commit 0da645d4523474093f36d66722dfcd3aa008a40d Author: Koh?nyi R?bert AuthorDate: Tue Sep 18 11:02:45 2018 +0200 Commit: Brad King CommitDate: Tue Sep 25 09:00:54 2018 -0400 FindGLUT: Find debug/release variants on Windows * Separate find_library calls to find Release and Debug libs. * Using select_library_configurations to properly populate required variables (similar to FindZLIB). * Setting Release and Debug specific properties (IMPORTED_CONFIGURATIONS_ and IMPORTED_LOCATION_). * Falling back to setting just IMPORTED_LOCATION if GLUT_glut_LIBRARY_RELEASE or GLUT_glut_LIBRARY_DEBUG are not defined. This enables proper linking on Windows. Fixes: #17037 diff --git a/Modules/FindGLUT.cmake b/Modules/FindGLUT.cmake index 88d4b29..1779683 100644 --- a/Modules/FindGLUT.cmake +++ b/Modules/FindGLUT.cmake @@ -34,20 +34,30 @@ # GLUT_Xmu_LIBRARY = the full path to the Xmu library. # GLUT_Xi_LIBRARY = the full path to the Xi Library. +include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake) + if (WIN32) find_path( GLUT_INCLUDE_DIR NAMES GL/glut.h PATHS ${GLUT_ROOT_PATH}/include ) - find_library( GLUT_glut_LIBRARY NAMES glut glut32 freeglut + find_library( GLUT_glut_LIBRARY_RELEASE NAMES glut glut32 freeglut PATHS ${OPENGL_LIBRARY_DIR} ${GLUT_ROOT_PATH}/Release ) + find_library( GLUT_glut_LIBRARY_DEBUG NAMES freeglutd + PATHS + ${OPENGL_LIBRARY_DIR} + ${GLUT_ROOT_PATH}/Debug + ) + mark_as_advanced(GLUT_glut_LIBRARY_RELEASE GLUT_glut_LIBRARY_DEBUG) + select_library_configurations(GLUT_glut) else () if (APPLE) find_path(GLUT_INCLUDE_DIR glut.h ${OPENGL_LIBRARY_DIR}) find_library(GLUT_glut_LIBRARY GLUT DOC "GLUT library for OSX") find_library(GLUT_cocoa_LIBRARY Cocoa DOC "Cocoa framework for OSX") + mark_as_advanced(GLUT_glut_LIBRARY GLUT_cocoa_LIBRARY) if(GLUT_cocoa_LIBRARY AND NOT TARGET GLUT::Cocoa) add_library(GLUT::Cocoa UNKNOWN IMPORTED) @@ -72,10 +82,12 @@ else () find_library( GLUT_Xi_LIBRARY Xi /usr/openwin/lib ) + mark_as_advanced(GLUT_Xi_LIBRARY) find_library( GLUT_Xmu_LIBRARY Xmu /usr/openwin/lib ) + mark_as_advanced(GLUT_Xmu_LIBRARY) if(GLUT_Xi_LIBRARY AND NOT TARGET GLUT::Xi) add_library(GLUT::Xi UNKNOWN IMPORTED) @@ -104,6 +116,7 @@ else () /usr/openwin/lib ${_GLUT_glut_LIB_DIR} ) + mark_as_advanced(GLUT_glut_LIBRARY) unset(_GLUT_INC_DIR) unset(_GLUT_glut_LIB_DIR) @@ -135,8 +148,24 @@ if (GLUT_FOUND) set_target_properties(GLUT::GLUT PROPERTIES IMPORTED_LOCATION "${GLUT_glut_LIBRARY}/${CMAKE_MATCH_1}") else() - set_target_properties(GLUT::GLUT PROPERTIES - IMPORTED_LOCATION "${GLUT_glut_LIBRARY}") + if(GLUT_glut_LIBRARY_RELEASE) + set_property(TARGET GLUT::GLUT APPEND PROPERTY + IMPORTED_CONFIGURATIONS RELEASE) + set_target_properties(GLUT::GLUT PROPERTIES + IMPORTED_LOCATION_RELEASE "${GLUT_glut_LIBRARY_RELEASE}") + endif() + + if(GLUT_glut_LIBRARY_DEBUG) + set_property(TARGET GLUT::GLUT APPEND PROPERTY + IMPORTED_CONFIGURATIONS DEBUG) + set_target_properties(GLUT::GLUT PROPERTIES + IMPORTED_LOCATION_DEBUG "${GLUT_glut_LIBRARY_DEBUG}") + endif() + + if(NOT GLUT_glut_LIBRARY_RELEASE AND NOT GLUT_glut_LIBRARY_DEBUG) + set_property(TARGET GLUT::GLUT APPEND PROPERTY + IMPORTED_LOCATION "${GLUT_glut_LIBRARY}") + endif() endif() if(TARGET GLUT::Xmu) @@ -160,9 +189,4 @@ if (GLUT_FOUND) set (GLUT_INCLUDE_PATH ${GLUT_INCLUDE_DIR}) endif() -mark_as_advanced( - GLUT_INCLUDE_DIR - GLUT_glut_LIBRARY - GLUT_Xmu_LIBRARY - GLUT_Xi_LIBRARY - ) +mark_as_advanced(GLUT_INCLUDE_DIR) ----------------------------------------------------------------------- Summary of changes: Modules/FindGLUT.cmake | 42 +++++++++++++++++++++++++++++++++--------- Modules/FindLua.cmake | 1 + 2 files changed, 34 insertions(+), 9 deletions(-) hooks/post-receive -- CMake From kwrobot at kitware.com Thu Sep 27 00:05:04 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Thu, 27 Sep 2018 00:05:04 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-734-gbe1ceda Message-ID: <20180927040504.F12B01138FD@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via be1ceda97f8a034a222e01301cd2b1879c55b29c (commit) from a57225c4fc5cbbf063d86e0f911c552bc0fabb9d (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=be1ceda97f8a034a222e01301cd2b1879c55b29c commit be1ceda97f8a034a222e01301cd2b1879c55b29c Author: Kitware Robot AuthorDate: Thu Sep 27 00:01:09 2018 -0400 Commit: Kitware Robot CommitDate: Thu Sep 27 00:01:09 2018 -0400 CMake Nightly Date Stamp diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 1f51aa4..1a82e2a 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 12) -set(CMake_VERSION_PATCH 20180926) +set(CMake_VERSION_PATCH 20180927) #set(CMake_VERSION_RC 1) ----------------------------------------------------------------------- Summary of changes: Source/CMakeVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) hooks/post-receive -- CMake From kwrobot at kitware.com Thu Sep 27 14:55:06 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Thu, 27 Sep 2018 14:55:06 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-750-g3f7312a Message-ID: <20180927185506.5680EFE4CA@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 3f7312a97800801735a63dd65b17e06a0fc61348 (commit) via abe25dd79f53f70ef99ac0c75f5366d5d7302efa (commit) via 6eea9677f10ea87775385f0f2e8c6065fdbb8259 (commit) via e9f656da8222e23785a0a7912cb59f195eeb2e0b (commit) via acf0627470df1d9ed533eaa437d8ee6ac2717e84 (commit) via 7ab5843c2672c3b6125cbda6c64d5071ac2031bb (commit) via 6744e449702a3f26991af213d06cd94f7882c63f (commit) via 6a4b1006f9561ea126073329216c4815ca731c31 (commit) via 2aaed7a05053c3bcbebbff5ae1beb51e590b3ad1 (commit) via 710f37c47a7df54c39e50d050e790271c547ad80 (commit) via 97e1213a88437835256aba8e9628a5375265978f (commit) via a9694d6538b5a975b08cea89bdd86ebce6166452 (commit) via e7e88e955bc773be792e645ee8558d78b4183a87 (commit) via 62709beff8e9bf786b9c3ec5fbd791ce2d452232 (commit) via 9a56ed3438f652ec526afabeab87e04f330e4724 (commit) via 6c57f6b347f2acf19ef043e38463ac03919594f3 (commit) from be1ceda97f8a034a222e01301cd2b1879c55b29c (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=3f7312a97800801735a63dd65b17e06a0fc61348 commit 3f7312a97800801735a63dd65b17e06a0fc61348 Merge: abe25dd 7ab5843 Author: Brad King AuthorDate: Thu Sep 27 18:51:07 2018 +0000 Commit: Kitware Robot CommitDate: Thu Sep 27 14:51:13 2018 -0400 Merge topic 'asm-path-from-c' 7ab5843c26 ASM: Search for full path even when using C or C++ compiler Acked-by: Kitware Robot Merge-request: !2418 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=abe25dd79f53f70ef99ac0c75f5366d5d7302efa commit abe25dd79f53f70ef99ac0c75f5366d5d7302efa Merge: 6eea967 6744e44 Author: Brad King AuthorDate: Thu Sep 27 18:50:02 2018 +0000 Commit: Kitware Robot CommitDate: Thu Sep 27 14:50:14 2018 -0400 Merge topic 'update-libarchive' 6744e44970 Update CMake pre-cached values for libarchive 3.3.3 6a4b1006f9 Merge branch 'upstream-LibArchive' into update-libarchive 2aaed7a050 LibArchive 2018-09-03 (5fe69dd0) 710f37c47a libarchive: Update script to get 3.3.3 97e1213a88 Merge branch 'libarchive-libressl-2.7' into update-libarchive Acked-by: Kitware Robot Merge-request: !2417 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=6eea9677f10ea87775385f0f2e8c6065fdbb8259 commit 6eea9677f10ea87775385f0f2e8c6065fdbb8259 Merge: e9f656d a9694d6 Author: Brad King AuthorDate: Thu Sep 27 14:49:09 2018 -0400 Commit: Brad King CommitDate: Thu Sep 27 14:49:09 2018 -0400 Merge branch 'release-3.12' https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=e9f656da8222e23785a0a7912cb59f195eeb2e0b commit e9f656da8222e23785a0a7912cb59f195eeb2e0b Merge: acf0627 e7e88e9 Author: Brad King AuthorDate: Thu Sep 27 18:48:44 2018 +0000 Commit: Kitware Robot CommitDate: Thu Sep 27 14:48:50 2018 -0400 Merge topic 'libarchive-libressl-2.7' e7e88e955b libarchive: Backport fix for build with LibreSSL 2.7 Acked-by: Kitware Robot Merge-request: !2416 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=acf0627470df1d9ed533eaa437d8ee6ac2717e84 commit acf0627470df1d9ed533eaa437d8ee6ac2717e84 Merge: be1ceda 62709be Author: Brad King AuthorDate: Thu Sep 27 18:47:50 2018 +0000 Commit: Kitware Robot CommitDate: Thu Sep 27 14:48:03 2018 -0400 Merge topic 'FindMatlab-2018b' 62709beff8 FindMatlab: Add Matlab 2018a,b to version list 9a56ed3438 FindMatlab: Explicitly export mexFunction in MSVC 6c57f6b347 FindMatlab: Optionally allow linking to MatlabEngine and MatlabDataArray Acked-by: Kitware Robot Acked-by: Raffi Enficiaud Merge-request: !2407 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=7ab5843c2672c3b6125cbda6c64d5071ac2031bb commit 7ab5843c2672c3b6125cbda6c64d5071ac2031bb Author: Raul Laasner AuthorDate: Wed Sep 26 11:32:48 2018 -0400 Commit: Brad King CommitDate: Wed Sep 26 14:01:39 2018 -0400 ASM: Search for full path even when using C or C++ compiler When `CMAKE_{C,CXX}_COMPILER` is set but `CMAKE_ASM*_COMPILER` is not, we copy the C or C++ compiler to use as the ASM compiler. In this case we still need to search for the ASM compiler in case the C or C++ compiler is not known as an absolute path. Also do not copy the compiler id setting and let the normal detection take place. The C compiler id may not exist if the language has not been enabled. Fixes: #18406 diff --git a/Modules/CMakeDetermineASMCompiler.cmake b/Modules/CMakeDetermineASMCompiler.cmake index 24048ed..45dea8f 100644 --- a/Modules/CMakeDetermineASMCompiler.cmake +++ b/Modules/CMakeDetermineASMCompiler.cmake @@ -22,11 +22,9 @@ if(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER) if("ASM${ASM_DIALECT}" STREQUAL "ASM") # the generic assembler support if(NOT CMAKE_ASM_COMPILER_INIT) if(CMAKE_C_COMPILER) - set(CMAKE_ASM_COMPILER "${CMAKE_C_COMPILER}" CACHE FILEPATH "The ASM compiler") - set(CMAKE_ASM_COMPILER_ID "${CMAKE_C_COMPILER_ID}") + set(CMAKE_ASM${ASM_DIALECT}_COMPILER_LIST ${CMAKE_C_COMPILER}) elseif(CMAKE_CXX_COMPILER) - set(CMAKE_ASM_COMPILER "${CMAKE_CXX_COMPILER}" CACHE FILEPATH "The ASM compiler") - set(CMAKE_ASM_COMPILER_ID "${CMAKE_CXX_COMPILER_ID}") + set(CMAKE_ASM${ASM_DIALECT}_COMPILER_LIST ${CMAKE_CXX_COMPILER}) else() # List all default C and CXX compilers set(CMAKE_ASM${ASM_DIALECT}_COMPILER_LIST https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=6744e449702a3f26991af213d06cd94f7882c63f commit 6744e449702a3f26991af213d06cd94f7882c63f Author: Brad King AuthorDate: Wed Sep 26 09:55:09 2018 -0400 Commit: Brad King CommitDate: Wed Sep 26 09:55:09 2018 -0400 Update CMake pre-cached values for libarchive 3.3.3 The ENABLE_LZ4 option was added. diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f16e79..e88e925 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -513,6 +513,7 @@ macro (CMAKE_BUILD_UTILITIES) set(ENABLE_NETTLE OFF CACHE INTERNAL "Enable use of Nettle") set(ENABLE_OPENSSL ${CMAKE_USE_OPENSSL} CACHE INTERNAL "Enable use of OpenSSL") set(ENABLE_LZMA ON CACHE INTERNAL "Enable the use of the system LZMA library if found") + set(ENABLE_LZ4 OFF CACHE INTERNAL "Enable the use of the system LZ4 library if found") set(ENABLE_LZO OFF CACHE INTERNAL "Enable the use of the system LZO library if found") set(ENABLE_ZLIB ON CACHE INTERNAL "Enable the use of the system ZLIB library if found") set(ENABLE_BZip2 ON CACHE INTERNAL "Enable the use of the system BZip2 library if found") https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=6a4b1006f9561ea126073329216c4815ca731c31 commit 6a4b1006f9561ea126073329216c4815ca731c31 Merge: 710f37c 2aaed7a Author: Brad King AuthorDate: Wed Sep 26 09:53:15 2018 -0400 Commit: Brad King CommitDate: Wed Sep 26 09:53:15 2018 -0400 Merge branch 'upstream-LibArchive' into update-libarchive * upstream-LibArchive: LibArchive 2018-09-03 (5fe69dd0) diff --cc Utilities/cmlibarchive/CMakeLists.txt index 206f3c6,0000000..d7af6e2 mode 100644,000000..100644 --- a/Utilities/cmlibarchive/CMakeLists.txt +++ b/Utilities/cmlibarchive/CMakeLists.txt @@@ -1,1641 -1,0 +1,1672 @@@ +PROJECT(libarchive C) +# +SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/build/cmake") +if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${libarchive_BINARY_DIR}/bin) +endif() + +# On MacOS, prefer MacPorts libraries to system libraries. +# I haven't come up with a compelling argument for this to be conditional. +list(APPEND CMAKE_PREFIX_PATH /opt/local) +# Enable @rpath in the install name. +# detail in "cmake --help-policy CMP0042" +SET(CMAKE_MACOSX_RPATH ON) + +# +# Version - read from 'version' file. +# +FILE(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/build/version _version) +STRING(REGEX REPLACE + "^([0-9])[0-9][0-9][0-9][0-9][0-9][0-9][a-z]*$" "\\1" _major ${_version}) +STRING(REGEX REPLACE + "^[0-9]([0-9][0-9][0-9])[0-9][0-9][0-9][a-z]*$" "\\1" _minor ${_version}) +STRING(REGEX REPLACE + "^[0-9][0-9][0-9][0-9]([0-9][0-9][0-9])[a-z]*$" "\\1" _revision ${_version}) +STRING(REGEX REPLACE + "^[0-9][0-9][0-9][0-9][0-9][0-9][0-9]([a-z]*)$" "\\1" _quality ${_version}) +SET(_version_number ${_major}${_minor}${_revision}) +STRING(REGEX REPLACE "[0]*([^0]*[0-9])$" "\\1" _trimmed_minor ${_minor}) +STRING(REGEX REPLACE "[0]*([^0]*[0-9])$" "\\1" _trimmed_revision ${_revision}) +# +SET(VERSION "${_major}.${_trimmed_minor}.${_trimmed_revision}${_quality}") +SET(BSDCPIO_VERSION_STRING "${VERSION}") +SET(BSDTAR_VERSION_STRING "${VERSION}") +SET(BSDCAT_VERSION_STRING "${VERSION}") +SET(LIBARCHIVE_VERSION_NUMBER "${_version_number}") +SET(LIBARCHIVE_VERSION_STRING "${VERSION}") + +# INTERFACE_VERSION increments with every release +# libarchive 2.7 == interface version 9 = 2 + 7 +# libarchive 2.8 == interface version 10 = 2 + 8 +# libarchive 2.9 == interface version 11 = 2 + 9 +# libarchive 3.0 == interface version 12 +# libarchive 3.1 == interface version 13 +math(EXPR INTERFACE_VERSION "13 + ${_minor}") + +# Set SOVERSION == Interface version +# ?? Should there be more here ?? +SET(SOVERSION "${INTERFACE_VERSION}") + +# Enalbe CMAKE_PUSH_CHECK_STATE() and CMAKE_POP_CHECK_STATE() macros +# saving and restoring the state of the variables. +INCLUDE(${CMake_SOURCE_DIR}/Modules/CMakePushCheckState.cmake) + +# Initialize the state of the variables. This initialization is not +# necessary but this shows you what value the variables initially have. +SET(CMAKE_REQUIRED_DEFINITIONS) +SET(CMAKE_REQUIRED_INCLUDES) +SET(CMAKE_REQUIRED_LIBRARIES) +SET(CMAKE_REQUIRED_FLAGS) + +# Disable warnings to avoid changing 3rd party code. +IF(CMAKE_C_COMPILER_ID MATCHES + "^(GNU|Clang|AppleClang|XL|VisualAge|SunPro|MIPSpro|HP|Intel)$") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w") +ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "PathScale") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -woffall") +ENDIF() + +# Enable CTest/CDash support +include(CTest) + +OPTION(ENABLE_NETTLE "Enable use of Nettle" ON) +OPTION(ENABLE_OPENSSL "Enable use of OpenSSL" ON) ++OPTION(ENABLE_LZ4 "Enable the use of the system LZ4 library if found" ON) +OPTION(ENABLE_LZO "Enable the use of the system LZO library if found" OFF) +OPTION(ENABLE_LZMA "Enable the use of the system LZMA library if found" ON) + +OPTION(ENABLE_ZLIB "Enable the use of the system ZLIB library if found" ON) +OPTION(ENABLE_BZip2 "Enable the use of the system BZip2 library if found" ON) +OPTION(ENABLE_LIBXML2 "Enable the use of the system libxml2 library if found" ON) +OPTION(ENABLE_EXPAT "Enable the use of the system EXPAT library if found" ON) +OPTION(ENABLE_PCREPOSIX "Enable the use of the system PCREPOSIX library if found" ON) +OPTION(ENABLE_LibGCC "Enable the use of the system LibGCC library if found" ON) +# CNG is used for encrypt/decrypt Zip archives on Windows. +OPTION(ENABLE_CNG "Enable the use of CNG(Crypto Next Generation)" ON) + +OPTION(ENABLE_XATTR "Enable extended attribute support" ON) +OPTION(ENABLE_ACL "Enable ACL support" ON) +OPTION(ENABLE_ICONV "Enable iconv support" ON) + +IF(WIN32) + #ELSEIF(WINDOWS_VERSION STREQUAL "WINXP") + SET(NTDDI_VERSION 0x05010000) + SET(_WIN32_WINNT 0x0501) + SET(WINVER 0x0501) +ENDIF(WIN32) + +set(HAVE_PTHREAD_H 0) # no threads in CMake + +IF("${CMAKE_C_PLATFORM_ID}" MATCHES "^(HP-UX)$") + ADD_DEFINITIONS(-D_XOPEN_SOURCE=500) # Ask wchar.h for mbstate_t +ENDIF() + +# +INCLUDE(CheckCSourceCompiles) +INCLUDE(CheckCSourceRuns) +INCLUDE(CheckFileOffsetBits) +INCLUDE(CheckFuncs) +INCLUDE(CheckHeaderDirent) +INCLUDE(CheckIncludeFile) +INCLUDE(CheckIncludeFiles) +INCLUDE(CheckLibraryExists) +INCLUDE(CheckStructHasMember) +INCLUDE(CheckSymbolExists) +INCLUDE(CheckTypeExists) +INCLUDE(CheckTypeSize) + +# +# Generate list.h +# +MACRO (GENERATE_LIST_H _listfile _cmlist __list_sources) + SET(_argv ${ARGV}) + # Remove _listfile and _cmlist from _argv + LIST(REMOVE_AT _argv 0 1) + IF (NOT EXISTS "${_listfile}" OR + ${_cmlist} IS_NEWER_THAN "${_listfile}") + + MESSAGE(STATUS "Generating ${_listfile}") + FILE(WRITE ${_listfile} "") + FOREACH (testfile ${_argv}) + IF (testfile MATCHES "^test_[^/]+[.]c$") + FILE(STRINGS ${testfile} testvar REGEX "^DEFINE_TEST") + FOREACH (deftest ${testvar}) + FILE(APPEND ${_listfile} "${deftest}\n") + ENDFOREACH (deftest) + ENDIF (testfile MATCHES "^test_[^/]+[.]c$") + ENDFOREACH (testfile) + + ENDIF (NOT EXISTS "${_listfile}" OR + ${_cmlist} IS_NEWER_THAN "${_listfile}") +ENDMACRO (GENERATE_LIST_H) +# +# Generate installation rules for man pages. +# +MACRO (INSTALL_MAN __mans) + FOREACH (_man ${ARGV}) + STRING(REGEX REPLACE "^.+[.]([1-9])" "\\1" _mansect ${_man}) + INSTALL(FILES ${_man} DESTINATION "share/man/man${_mansect}") + ENDFOREACH (_man) +ENDMACRO (INSTALL_MAN __mans) +# +# Find out what macro is needed to use libraries on Windows. +# +MACRO (TRY_MACRO_FOR_LIBRARY INCLUDES LIBRARIES + TRY_TYPE SAMPLE_SOURCE MACRO_LIST) + IF(WIN32 AND NOT CYGWIN) + CMAKE_PUSH_CHECK_STATE() # Save the state of the variables + SET(CMAKE_REQUIRED_INCLUDES ${INCLUDES}) + SET(CMAKE_REQUIRED_LIBRARIES ${LIBRARIES}) + FOREACH(VAR ${MACRO_LIST}) + # Clear ${VAR} from CACHE If the libraries which ${VAR} was + # checked with are changed. + SET(VAR_WITH_LIB "${VAR}_WITH_LIB") + GET_PROPERTY(PREV_VAR_WITH_LIB VARIABLE PROPERTY ${VAR_WITH_LIB}) + IF(NOT "${PREV_VAR_WITH_LIB}" STREQUAL "${LIBRARIES}") + UNSET(${VAR} CACHE) + ENDIF(NOT "${PREV_VAR_WITH_LIB}" STREQUAL "${LIBRARIES}") + # Check if the library can be used with the macro. + IF("${TRY_TYPE}" MATCHES "COMPILES") + CHECK_C_SOURCE_COMPILES("${SAMPLE_SOURCE}" ${VAR}) + ELSEIF("${TRY_TYPE}" MATCHES "RUNS") + CHECK_C_SOURCE_RUNS("${SAMPLE_SOURCE}" ${VAR}) + ELSE("${TRY_TYPE}" MATCHES "COMPILES") + MESSAGE(FATAL_ERROR "UNKNOWN KEYWORD \"${TRY_TYPE}\" FOR TRY_TYPE") + ENDIF("${TRY_TYPE}" MATCHES "COMPILES") + # Save the libraries which ${VAR} is checked with. + SET(${VAR_WITH_LIB} "${LIBRARIES}" CACHE INTERNAL + "Macro ${VAR} is checked with") + ENDFOREACH(VAR) + CMAKE_POP_CHECK_STATE() # Restore the state of the variables + ENDIF(WIN32 AND NOT CYGWIN) +ENDMACRO (TRY_MACRO_FOR_LIBRARY) +# +# Check compress/decompress libraries +# +IF(WIN32 AND NOT CMAKE_CL_64 AND NOT CYGWIN) + # GnuWin32 is only for Win32, not Win64. + SET(__GNUWIN32PATH "C:/Program Files/GnuWin32") +ENDIF(WIN32 AND NOT CMAKE_CL_64 AND NOT CYGWIN) +IF(DEFINED __GNUWIN32PATH AND EXISTS "${__GNUWIN32PATH}") + # You have to add a path availabel DLL file into PATH environment variable. + # Maybe DLL path is "C:/Program Files/GnuWin32/bin". + # The zlib and the bzip2 Setup program have installed programs and DLLs into + # "C:/Program Files/GnuWin32" by default. + # This is convenience setting for Windows. + SET(CMAKE_PREFIX_PATH ${__GNUWIN32PATH} $(CMAKE_PREFIX_PATH)) + # + # If you didn't use Setup program or installed into nonstandard path, + # cmake cannot find out your zlib or bzip2 libraries and include files, + # you should execute cmake with -DCMAKE_PREFIX_PATH option. + # e.g. + # cmake -DCMAKE_PREFIX_PATH= + # + # If compiling error occurred in zconf.h, You may need patch to zconf.h. + #--- zconf.h.orig 2005-07-21 00:40:26.000000000 + #+++ zconf.h 2009-01-19 11:39:10.093750000 + #@@ -286,7 +286,7 @@ + # + # #if 1 /* HAVE_UNISTD_H -- this line is updated by ./configure */ + # # include /* for off_t */ + #-# include /* for SEEK_* and off_t */ + #+# include /* for SEEK_* and off_t */ + # # ifdef VMS + # # include /* for off_t */ + # # endif +ENDIF(DEFINED __GNUWIN32PATH AND EXISTS "${__GNUWIN32PATH}") + +SET(ADDITIONAL_LIBS "") +# +# Find ZLIB +# +IF(ENABLE_ZLIB) + FIND_PACKAGE(ZLIB) +ELSE() + SET(ZLIB_FOUND FALSE) # Override cached value +ENDIF() +IF(ZLIB_FOUND) + SET(HAVE_LIBZ 1) + SET(HAVE_ZLIB_H 1) + INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR}) + LIST(APPEND ADDITIONAL_LIBS ${ZLIB_LIBRARIES}) + IF(WIN32 AND NOT CYGWIN) + # + # Test if ZLIB_WINAPI macro is needed to use. + # + TRY_MACRO_FOR_LIBRARY( + "${ZLIB_INCLUDE_DIR}" "${ZLIB_LIBRARIES}" + RUNS + "#include \nint main() {uLong f = zlibCompileFlags(); return (f&(1U<<10))?0:-1; }" + ZLIB_WINAPI) + IF(ZLIB_WINAPI) + ADD_DEFINITIONS(-DZLIB_WINAPI) + ELSE(ZLIB_WINAPI) + # Test if a macro is needed for the library. + TRY_MACRO_FOR_LIBRARY( + "${ZLIB_INCLUDE_DIR}" "${ZLIB_LIBRARIES}" + COMPILES + "#include \nint main() {return zlibVersion()?1:0; }" + "ZLIB_DLL;WITHOUT_ZLIB_DLL") + IF(ZLIB_DLL) + ADD_DEFINITIONS(-DZLIB_DLL) + ENDIF(ZLIB_DLL) + ENDIF(ZLIB_WINAPI) + ENDIF(WIN32 AND NOT CYGWIN) +ELSE(ZLIB_FOUND) + MESSAGE(FATAL_ERROR "CMake requires zlib to be available to libarchive") +ENDIF(ZLIB_FOUND) +# +# Find BZip2 +# +IF(ENABLE_BZip2) + FIND_PACKAGE(BZip2) +ELSE() + SET(BZIP2_FOUND FALSE) # Override cached value +ENDIF() +IF(BZIP2_FOUND) + SET(HAVE_LIBBZ2 1) + SET(HAVE_BZLIB_H 1) + INCLUDE_DIRECTORIES(${BZIP2_INCLUDE_DIR}) + LIST(APPEND ADDITIONAL_LIBS ${BZIP2_LIBRARIES}) + # Test if a macro is needed for the library. + TRY_MACRO_FOR_LIBRARY( + "${BZIP2_INCLUDE_DIR}" "${BZIP2_LIBRARIES}" + COMPILES + "#include \nint main() {return BZ2_bzlibVersion()?1:0; }" + "USE_BZIP2_DLL;USE_BZIP2_STATIC") + IF(USE_BZIP2_DLL) + ADD_DEFINITIONS(-DUSE_BZIP2_DLL) + ELSEIF(USE_BZIP2_STATIC) + ADD_DEFINITIONS(-DUSE_BZIP2_STATIC) + ENDIF(USE_BZIP2_DLL) +ENDIF(BZIP2_FOUND) +MARK_AS_ADVANCED(CLEAR BZIP2_INCLUDE_DIR) +MARK_AS_ADVANCED(CLEAR BZIP2_LIBRARIES) + + +# +# Find LZMA +# +IF(ENABLE_LZMA) + FIND_PACKAGE(LibLZMA) +ELSE() + SET(LIBZMA_FOUND FALSE) # Override cached value +ENDIF() + +IF(LIBLZMA_FOUND) + SET(HAVE_LIBLZMA 1) + SET(HAVE_LZMA_H 1) + INCLUDE_DIRECTORIES(${LIBLZMA_INCLUDE_DIRS}) + LIST(APPEND ADDITIONAL_LIBS ${LIBLZMA_LIBRARIES}) + IF(CMAKE_USE_SYSTEM_LIBLZMA) + # Test if a macro is needed for the library. + TRY_MACRO_FOR_LIBRARY( + "${LIBLZMA_INCLUDE_DIRS}" "${LIBLZMA_LIBRARIES}" + COMPILES + "#include \nint main() {return (int)lzma_version_number(); }" + "WITHOUT_LZMA_API_STATIC;LZMA_API_STATIC") + IF(NOT WITHOUT_LZMA_API_STATIC AND LZMA_API_STATIC) + ADD_DEFINITIONS(-DLZMA_API_STATIC) + ENDIF(NOT WITHOUT_LZMA_API_STATIC AND LZMA_API_STATIC) + ELSE() + ADD_DEFINITIONS(-DLZMA_API_STATIC) + ENDIF() +ELSE(LIBLZMA_FOUND) +# LZMA not found and will not be used. +ENDIF(LIBLZMA_FOUND) +IF(0) # CMake does not need LZO2 support in libarchive +# +# Find LZO2 +# +IF(ENABLE_LZO) + IF (LZO2_INCLUDE_DIR) + # Already in cache, be silent + SET(LZO2_FIND_QUIETLY TRUE) + ENDIF (LZO2_INCLUDE_DIR) + + FIND_PATH(LZO2_INCLUDE_DIR lzo/lzoconf.h) + FIND_LIBRARY(LZO2_LIBRARY NAMES lzo2 liblzo2) + INCLUDE(FindPackageHandleStandardArgs) + FIND_PACKAGE_HANDLE_STANDARD_ARGS(LZO2 DEFAULT_MSG LZO2_LIBRARY LZO2_INCLUDE_DIR) +ELSE(ENABLE_LZO) - SET(LIBZMA_FOUND FALSE) # Override cached value ++ SET(LZO2_FOUND FALSE) # Override cached value +ENDIF(ENABLE_LZO) +IF(LZO2_FOUND) + SET(HAVE_LIBLZO2 1) + SET(HAVE_LZO_LZOCONF_H 1) + SET(HAVE_LZO_LZO1X_H 1) + INCLUDE_DIRECTORIES(${LZO2_INCLUDE_DIR}) + LIST(APPEND ADDITIONAL_LIBS ${LZO2_LIBRARY}) + # + # TODO: test for static library. + # +ENDIF(LZO2_FOUND) +MARK_AS_ADVANCED(CLEAR LZO2_INCLUDE_DIR) +MARK_AS_ADVANCED(CLEAR LZO2_LIBRARY) +ENDIF() +IF(0) # CMake does not need LZ4 support in libarchive +# +# Find LZ4 +# - IF (LZ4_INCLUDE_DIR) - # Already in cache, be silent - SET(LZ4_FIND_QUIETLY TRUE) - ENDIF (LZ4_INCLUDE_DIR) ++IF(ENABLE_LZ4) ++ IF (LZ4_INCLUDE_DIR) ++ # Already in cache, be silent ++ SET(LZ4_FIND_QUIETLY TRUE) ++ ENDIF (LZ4_INCLUDE_DIR) + - FIND_PATH(LZ4_INCLUDE_DIR lz4.h) - FIND_LIBRARY(LZ4_LIBRARY NAMES lz4 liblz4) - INCLUDE(FindPackageHandleStandardArgs) - FIND_PACKAGE_HANDLE_STANDARD_ARGS(LZ4 DEFAULT_MSG LZ4_LIBRARY LZ4_INCLUDE_DIR) ++ FIND_PATH(LZ4_INCLUDE_DIR lz4.h) ++ FIND_LIBRARY(LZ4_LIBRARY NAMES lz4 liblz4) ++ INCLUDE(FindPackageHandleStandardArgs) ++ FIND_PACKAGE_HANDLE_STANDARD_ARGS(LZ4 DEFAULT_MSG LZ4_LIBRARY LZ4_INCLUDE_DIR) ++ELSE(ENABLE_LZ4) ++ SET(LZ4_FOUND FALSE) # Override cached value ++ENDIF(ENABLE_LZ4) +IF(LZ4_FOUND) + SET(HAVE_LIBLZ4 1) + SET(HAVE_LZ4_H 1) + CMAKE_PUSH_CHECK_STATE() # Save the state of the variables + SET(CMAKE_REQUIRED_INCLUDES ${LZ4_INCLUDE_DIR}) + CHECK_INCLUDE_FILES("lz4hc.h" HAVE_LZ4HC_H) + CMAKE_POP_CHECK_STATE() # Restore the state of the variables + INCLUDE_DIRECTORIES(${LZ4_INCLUDE_DIR}) + LIST(APPEND ADDITIONAL_LIBS ${LZ4_LIBRARY}) + # + # TODO: test for static library. + # +ENDIF(LZ4_FOUND) +MARK_AS_ADVANCED(CLEAR LZ4_INCLUDE_DIR) +MARK_AS_ADVANCED(CLEAR LZ4_LIBRARY) ++# ++# Find Zstd ++# ++IF (ZSTD_INCLUDE_DIR) ++ # Already in cache, be silent ++ SET(ZSTD_FIND_QUIETLY TRUE) ++ENDIF (ZSTD_INCLUDE_DIR) ++ ++FIND_PATH(ZSTD_INCLUDE_DIR zstd.h) ++FIND_LIBRARY(ZSTD_LIBRARY NAMES zstd libzstd) ++INCLUDE(FindPackageHandleStandardArgs) ++FIND_PACKAGE_HANDLE_STANDARD_ARGS(ZSTD DEFAULT_MSG ZSTD_LIBRARY ZSTD_INCLUDE_DIR) ++IF(ZSTD_FOUND) ++ SET(HAVE_ZSTD_H 1) ++ INCLUDE_DIRECTORIES(${ZSTD_INCLUDE_DIR}) ++ LIST(APPEND ADDITIONAL_LIBS ${ZSTD_LIBRARY}) ++ SET(CMAKE_REQUIRED_LIBRARIES ${ZSTD_LIBRARY}) ++ SET(CMAKE_REQUIRED_INCLUDES ${ZSTD_INCLUDE_DIR}) ++ CHECK_FUNCTION_EXISTS(ZSTD_compressStream HAVE_LIBZSTD) ++ # ++ # TODO: test for static library. ++ # ++ENDIF(ZSTD_FOUND) ++MARK_AS_ADVANCED(CLEAR ZSTD_INCLUDE_DIR) ++MARK_AS_ADVANCED(CLEAR ZSTD_LIBRARY) +ENDIF() + +# +# Check headers +# +CHECK_HEADER_DIRENT() + +SET(INCLUDES "") +MACRO (LA_CHECK_INCLUDE_FILE header var) + CHECK_INCLUDE_FILES("${INCLUDES};${header}" ${var}) + IF (${var}) + SET(INCLUDES ${INCLUDES} ${header}) + ENDIF (${var}) +ENDMACRO (LA_CHECK_INCLUDE_FILE) + +# Some FreeBSD headers assume sys/types.h was already included. +LA_CHECK_INCLUDE_FILE("sys/types.h" HAVE_SYS_TYPES_H) + +# Alphabetize the rest unless there's a compelling reason +IF(ENABLE_ACL) + LA_CHECK_INCLUDE_FILE("acl/libacl.h" HAVE_ACL_LIBACL_H) +ELSE(ENABLE_ACL) + SET(HAVE_ACL_LIBACL_H FALSE) +ENDIF(ENABLE_ACL) +LA_CHECK_INCLUDE_FILE("ctype.h" HAVE_CTYPE_H) +LA_CHECK_INCLUDE_FILE("copyfile.h" HAVE_COPYFILE_H) +LA_CHECK_INCLUDE_FILE("direct.h" HAVE_DIRECT_H) +LA_CHECK_INCLUDE_FILE("dlfcn.h" HAVE_DLFCN_H) +LA_CHECK_INCLUDE_FILE("errno.h" HAVE_ERRNO_H) +LA_CHECK_INCLUDE_FILE("ext2fs/ext2_fs.h" HAVE_EXT2FS_EXT2_FS_H) + +CHECK_C_SOURCE_COMPILES("#include +#include +int main(void) { return EXT2_IOC_GETFLAGS; }" HAVE_WORKING_EXT2_IOC_GETFLAGS) + +LA_CHECK_INCLUDE_FILE("fcntl.h" HAVE_FCNTL_H) +LA_CHECK_INCLUDE_FILE("grp.h" HAVE_GRP_H) +LA_CHECK_INCLUDE_FILE("inttypes.h" HAVE_INTTYPES_H) +LA_CHECK_INCLUDE_FILE("io.h" HAVE_IO_H) +LA_CHECK_INCLUDE_FILE("langinfo.h" HAVE_LANGINFO_H) +LA_CHECK_INCLUDE_FILE("limits.h" HAVE_LIMITS_H) +LA_CHECK_INCLUDE_FILE("linux/types.h" HAVE_LINUX_TYPES_H) +LA_CHECK_INCLUDE_FILE("linux/fiemap.h" HAVE_LINUX_FIEMAP_H) +LA_CHECK_INCLUDE_FILE("linux/fs.h" HAVE_LINUX_FS_H) + +CHECK_C_SOURCE_COMPILES("#include +#include +int main(void) { return FS_IOC_GETFLAGS; }" HAVE_WORKING_FS_IOC_GETFLAGS) + +LA_CHECK_INCLUDE_FILE("linux/magic.h" HAVE_LINUX_MAGIC_H) +LA_CHECK_INCLUDE_FILE("locale.h" HAVE_LOCALE_H) +LA_CHECK_INCLUDE_FILE("membership.h" HAVE_MEMBERSHIP_H) +LA_CHECK_INCLUDE_FILE("memory.h" HAVE_MEMORY_H) +LA_CHECK_INCLUDE_FILE("paths.h" HAVE_PATHS_H) +LA_CHECK_INCLUDE_FILE("poll.h" HAVE_POLL_H) +LA_CHECK_INCLUDE_FILE("process.h" HAVE_PROCESS_H) +LA_CHECK_INCLUDE_FILE("pthread.h" HAVE_PTHREAD_H) +LA_CHECK_INCLUDE_FILE("pwd.h" HAVE_PWD_H) +LA_CHECK_INCLUDE_FILE("readpassphrase.h" HAVE_READPASSPHRASE_H) +LA_CHECK_INCLUDE_FILE("regex.h" HAVE_REGEX_H) +LA_CHECK_INCLUDE_FILE("signal.h" HAVE_SIGNAL_H) +LA_CHECK_INCLUDE_FILE("spawn.h" HAVE_SPAWN_H) +LA_CHECK_INCLUDE_FILE("stdarg.h" HAVE_STDARG_H) +LA_CHECK_INCLUDE_FILE("stdint.h" HAVE_STDINT_H) +LA_CHECK_INCLUDE_FILE("stdlib.h" HAVE_STDLIB_H) +LA_CHECK_INCLUDE_FILE("string.h" HAVE_STRING_H) +LA_CHECK_INCLUDE_FILE("strings.h" HAVE_STRINGS_H) +LA_CHECK_INCLUDE_FILE("sys/acl.h" HAVE_SYS_ACL_H) +LA_CHECK_INCLUDE_FILE("sys/cdefs.h" HAVE_SYS_CDEFS_H) +LA_CHECK_INCLUDE_FILE("sys/extattr.h" HAVE_SYS_EXTATTR_H) +LA_CHECK_INCLUDE_FILE("sys/ioctl.h" HAVE_SYS_IOCTL_H) +LA_CHECK_INCLUDE_FILE("sys/mkdev.h" HAVE_SYS_MKDEV_H) +LA_CHECK_INCLUDE_FILE("sys/mount.h" HAVE_SYS_MOUNT_H) +LA_CHECK_INCLUDE_FILE("sys/param.h" HAVE_SYS_PARAM_H) +LA_CHECK_INCLUDE_FILE("sys/poll.h" HAVE_SYS_POLL_H) +LA_CHECK_INCLUDE_FILE("sys/richacl.h" HAVE_SYS_RICHACL_H) +LA_CHECK_INCLUDE_FILE("sys/select.h" HAVE_SYS_SELECT_H) +LA_CHECK_INCLUDE_FILE("sys/stat.h" HAVE_SYS_STAT_H) +LA_CHECK_INCLUDE_FILE("sys/statfs.h" HAVE_SYS_STATFS_H) +LA_CHECK_INCLUDE_FILE("sys/statvfs.h" HAVE_SYS_STATVFS_H) ++LA_CHECK_INCLUDE_FILE("sys/sysmacros.h" HAVE_SYS_SYSMACROS_H) +LA_CHECK_INCLUDE_FILE("sys/time.h" HAVE_SYS_TIME_H) +LA_CHECK_INCLUDE_FILE("sys/utime.h" HAVE_SYS_UTIME_H) +LA_CHECK_INCLUDE_FILE("sys/utsname.h" HAVE_SYS_UTSNAME_H) +LA_CHECK_INCLUDE_FILE("sys/vfs.h" HAVE_SYS_VFS_H) +LA_CHECK_INCLUDE_FILE("sys/wait.h" HAVE_SYS_WAIT_H) +LA_CHECK_INCLUDE_FILE("sys/xattr.h" HAVE_SYS_XATTR_H) +LA_CHECK_INCLUDE_FILE("time.h" HAVE_TIME_H) +LA_CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H) +LA_CHECK_INCLUDE_FILE("utime.h" HAVE_UTIME_H) +LA_CHECK_INCLUDE_FILE("wchar.h" HAVE_WCHAR_H) +LA_CHECK_INCLUDE_FILE("wctype.h" HAVE_WCTYPE_H) +LA_CHECK_INCLUDE_FILE("windows.h" HAVE_WINDOWS_H) +IF(ENABLE_CNG) + LA_CHECK_INCLUDE_FILE("Bcrypt.h" HAVE_BCRYPT_H) + IF(HAVE_BCRYPT_H) + LIST(APPEND ADDITIONAL_LIBS "Bcrypt") + ENDIF(HAVE_BCRYPT_H) +ELSE(ENABLE_CNG) + UNSET(HAVE_BCRYPT_H CACHE) +ENDIF(ENABLE_CNG) +# Following files need windows.h, so we should test it after windows.h test. +LA_CHECK_INCLUDE_FILE("wincrypt.h" HAVE_WINCRYPT_H) +LA_CHECK_INCLUDE_FILE("winioctl.h" HAVE_WINIOCTL_H) + +# +# Check whether use of __EXTENSIONS__ is safe. +# We need some macro such as _GNU_SOURCE to use extension functions. +# +SET(_INCLUDE_FILES) +FOREACH (it ${_HEADER}) + SET(_INCLUDE_FILES "${_INCLUDE_FILES}#include <${it}>\n") +ENDFOREACH (it) + +CHECK_C_SOURCE_COMPILES( + "#define __EXTENSIONS__ 1 + ${_INCLUDE_FILES} + int main() { return 0;}" + SAFE_TO_DEFINE_EXTENSIONS) + +# +# Find Nettle +# +IF(ENABLE_NETTLE) + FIND_PACKAGE(Nettle) + IF(NETTLE_FOUND) + SET(HAVE_LIBNETTLE 1) + LIST(APPEND ADDITIONAL_LIBS ${NETTLE_LIBRARIES}) + INCLUDE_DIRECTORIES(${NETTLE_INCLUDE_DIR}) + + LIST(APPEND CMAKE_REQUIRED_INCLUDES ${NETTLE_INCLUDE_DIR}) + LA_CHECK_INCLUDE_FILE("nettle/aes.h" HAVE_NETTLE_AES_H) + LA_CHECK_INCLUDE_FILE("nettle/hmac.h" HAVE_NETTLE_HMAC_H) + LA_CHECK_INCLUDE_FILE("nettle/md5.h" HAVE_NETTLE_MD5_H) + LA_CHECK_INCLUDE_FILE("nettle/pbkdf2.h" HAVE_NETTLE_PBKDF2_H) + LA_CHECK_INCLUDE_FILE("nettle/ripemd160.h" HAVE_NETTLE_RIPEMD160_H) + LA_CHECK_INCLUDE_FILE("nettle/sha.h" HAVE_NETTLE_SHA_H) + + ENDIF(NETTLE_FOUND) + MARK_AS_ADVANCED(CLEAR NETTLE_INCLUDE_DIR) + MARK_AS_ADVANCED(CLEAR NETTLE_LIBRARIES) +ENDIF(ENABLE_NETTLE) + +# +# Find OpenSSL +# (Except on Mac, where OpenSSL is deprecated.) +# +IF(ENABLE_OPENSSL AND NOT CMAKE_SYSTEM_NAME MATCHES "Darwin") + FIND_PACKAGE(OpenSSL) + IF(OPENSSL_FOUND) + SET(HAVE_LIBCRYPTO 1) + INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR}) + ENDIF(OPENSSL_FOUND) +ELSE() + SET(OPENSSL_FOUND FALSE) # Override cached value +ENDIF() + +# FreeBSD libmd +IF(NOT OPENSSL_FOUND) + CHECK_LIBRARY_EXISTS(md "MD5Init" "" LIBMD_FOUND) + IF(LIBMD_FOUND) + CMAKE_PUSH_CHECK_STATE() # Save the state of the variables + SET(CMAKE_REQUIRED_LIBRARIES "md") + FIND_LIBRARY(LIBMD_LIBRARY NAMES md) + LIST(APPEND ADDITIONAL_LIBS ${LIBMD_LIBRARY}) + CMAKE_POP_CHECK_STATE() # Restore the state of the variables + ENDIF(LIBMD_FOUND) +ENDIF(NOT OPENSSL_FOUND) + +# +# How to prove that CRYPTO functions, which have several names on various +# platforms, just see if archive_digest.c can compile and link against +# required libraries. +# +MACRO(CHECK_CRYPTO ALGORITHMS IMPLEMENTATION) + FOREACH(ALGORITHM ${ALGORITHMS}) + IF(NOT ARCHIVE_CRYPTO_${ALGORITHM}) + STRING(TOLOWER "${ALGORITHM}" lower_algorithm) + STRING(TOUPPER "${ALGORITHM}" algorithm) + IF ("${IMPLEMENTATION}" MATCHES "^OPENSSL$" AND NOT OPENSSL_FOUND) + SET(ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION} FALSE) + ELSEIF("${IMPLEMENTATION}" MATCHES "^NETTLE$" AND NOT NETTLE_FOUND) + SET(ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION} FALSE) + ENDIF("${IMPLEMENTATION}" MATCHES "^OPENSSL$" AND NOT OPENSSL_FOUND) + + IF(NOT DEFINED ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION}) + # Probe the local implementation for whether this + # crypto implementation is available on this platform. + SET(TRY_CRYPTO_REQUIRED_INCLUDES + "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_BINARY_DIR};${CMAKE_CURRENT_SOURCE_DIR}/libarchive;${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp") + SET(TRY_CRYPTO_REQUIRED_LIBS) + IF ("${IMPLEMENTATION}" MATCHES "^OPENSSL$" AND OPENSSL_FOUND) + SET(TRY_CRYPTO_REQUIRED_INCLUDES + "${TRY_CRYPTO_REQUIRED_INCLUDES};${OPENSSL_INCLUDE_DIR}") + SET(TRY_CRYPTO_REQUIRED_LIBS + "-DLINK_LIBRARIES:STRING=${OPENSSL_LIBRARIES}") + ELSEIF("${IMPLEMENTATION}" MATCHES "^NETTLE$" AND NETTLE_FOUND) + SET(TRY_CRYPTO_REQUIRED_INCLUDES + "${TRY_CRYPTO_REQUIRED_INCLUDES};${NETTLE_INCLUDE_DIR}") + SET(TRY_CRYPTO_REQUIRED_LIBS + "-DLINK_LIBRARIES:STRING=${NETTLE_LIBRARY}") + ELSEIF("${IMPLEMENTATION}" MATCHES "^LIBMD$" AND LIBMD_FOUND) + SET(TRY_CRYPTO_REQUIRED_LIBS + "-DLINK_LIBRARIES:STRING=${LIBMD_LIBRARY}") + ENDIF("${IMPLEMENTATION}" MATCHES "^OPENSSL$" AND OPENSSL_FOUND) + + CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/build/cmake/config.h.in + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/confdefs.h) + FILE(READ "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/confdefs.h" + CONFDEFS_H) + FILE(READ "${CMAKE_CURRENT_SOURCE_DIR}/libarchive/archive_digest.c" + ARCHIVE_CRYPTO_C) + + SET(SOURCE "${CONFDEFS_H} + +#define ARCHIVE_${algorithm}_COMPILE_TEST +#define ARCHIVE_CRYPTO_${algorithm}_${IMPLEMENTATION} +#define PLATFORM_CONFIG_H \"check_crypto_md.h\" + +${ARCHIVE_CRYPTO_C} + +int +main(int argc, char **argv) +{ + archive_${lower_algorithm}_ctx ctx; + archive_${lower_algorithm}_init(&ctx); + archive_${lower_algorithm}_update(&ctx, *argv, argc); + archive_${lower_algorithm}_final(&ctx, NULL); + return 0; +} +") + + FILE(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/check_crypto_md.h" "") + FILE(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/check_crypto_md.c" "${SOURCE}") + MESSAGE(STATUS "Checking support for ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION}") + + TRY_COMPILE(ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION} + ${CMAKE_BINARY_DIR} + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/check_crypto_md.c + CMAKE_FLAGS + "${TRY_CRYPTO_REQUIRED_LIBS}" + "${TRY_CRYPTO_REQUIRED_INCLUDES}" + OUTPUT_VARIABLE OUTPUT) + + # Inform user whether or not we found it; if not, log why we didn't. + IF (ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION}) + MESSAGE(STATUS "Checking support for ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION} -- found") + SET(ARCHIVE_CRYPTO_${ALGORITHM} 1) + ELSE (ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION}) + MESSAGE(STATUS "Checking support for ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION} -- not found") + FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Checking support for ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION} failed with the following output:\n" + "${OUTPUT}\n" + "Source file was:\n${SOURCE}\n") + ENDIF (ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION}) + ENDIF(NOT DEFINED ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION}) + + # Add appropriate libs/includes depending on whether the implementation + # was found on this platform. + IF (ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION}) + IF ("${IMPLEMENTATION}" MATCHES "^OPENSSL$" AND OPENSSL_FOUND) + INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR}) + LIST(APPEND ADDITIONAL_LIBS ${OPENSSL_LIBRARIES}) + LIST(REMOVE_DUPLICATES ADDITIONAL_LIBS) + ENDIF ("${IMPLEMENTATION}" MATCHES "^OPENSSL$" AND OPENSSL_FOUND) + ENDIF (ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION}) + ENDIF(NOT ARCHIVE_CRYPTO_${ALGORITHM}) + ENDFOREACH(ALGORITHM ${ALGORITHMS}) +ENDMACRO(CHECK_CRYPTO ALGORITHMS IMPLEMENTATION) + +# +# CRYPTO functions on Windows is defined at archive_windows.c, thus we do not +# need the test what the functions can be mapped to archive_{crypto name}_init, +# archive_{crypto name}_update and archive_{crypto name}_final. +# The functions on Windows use CALG_{crypto name} macro to create a crypt object +# and then we need to know what CALG_{crypto name} macros is available to show +# ARCHIVE_CRYPTO_{crypto name}_WIN macros because Windows 2000 and earlier version +# of Windows XP do not support SHA256, SHA384 and SHA512. +# +MACRO(CHECK_CRYPTO_WIN CRYPTO_LIST) + IF(WIN32 AND NOT CYGWIN) + FOREACH(CRYPTO ${CRYPTO_LIST}) + IF(NOT ARCHIVE_CRYPTO_${CRYPTO}) + IF(NOT DEFINED ARCHIVE_CRYPTO_${CRYPTO}_WIN) + STRING(TOUPPER "${CRYPTO}" crypto) + SET(ALGID "") + IF ("${CRYPTO}" MATCHES "^MD5$") + SET(ALGID "CALG_MD5") + ENDIF ("${CRYPTO}" MATCHES "^MD5$") + IF ("${CRYPTO}" MATCHES "^SHA1$") + SET(ALGID "CALG_SHA1") + ENDIF ("${CRYPTO}" MATCHES "^SHA1$") + IF ("${CRYPTO}" MATCHES "^SHA256$") + SET(ALGID "CALG_SHA_256") + ENDIF ("${CRYPTO}" MATCHES "^SHA256$") + IF ("${CRYPTO}" MATCHES "^SHA384$") + SET(ALGID "CALG_SHA_384") + ENDIF ("${CRYPTO}" MATCHES "^SHA384$") + IF ("${CRYPTO}" MATCHES "^SHA512$") + SET(ALGID "CALG_SHA_512") + ENDIF ("${CRYPTO}" MATCHES "^SHA512$") + + CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/build/cmake/config.h.in + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/confdefs.h) + FILE(READ "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/confdefs.h" + CONFDEFS_H) + + SET(SOURCE "${CONFDEFS_H} + +#define ${crypto}_COMPILE_TEST +#include +#include + +int +main(int argc, char **argv) +{ + return ${ALGID}; +} +") + SET(SOURCE_FILE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/check_crypto_win.c") + + FILE(WRITE "${SOURCE_FILE}" "${SOURCE}") + MESSAGE(STATUS "Checking support for ARCHIVE_CRYPTO_${CRYPTO}_WIN") + + TRY_COMPILE(ARCHIVE_CRYPTO_${CRYPTO}_WIN + ${CMAKE_BINARY_DIR} + ${SOURCE_FILE} + CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_BINARY_DIR};${CMAKE_CURRENT_SOURCE_DIR}/libarchive" + OUTPUT_VARIABLE OUTPUT) + + IF (ARCHIVE_CRYPTO_${CRYPTO}_WIN) + MESSAGE(STATUS + "Checking support for ARCHIVE_CRYPTO_${CRYPTO}_WIN -- found") + SET(ARCHIVE_CRYPTO_${CRYPTO} 1) + ELSE (ARCHIVE_CRYPTO_${CRYPTO}_WIN) + MESSAGE(STATUS + "Checking support for ARCHIVE_CRYPTO_${CRYPTO}_WIN -- not found") + FILE(APPEND + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Checking support for ARCHIVE_CRYPTO_${CRYPTO}_WIN failed with the following output:\n" + "${OUTPUT}\n" + "Source file was:\n${SOURCE}\n") + ENDIF (ARCHIVE_CRYPTO_${CRYPTO}_WIN) + + ENDIF(NOT DEFINED ARCHIVE_CRYPTO_${CRYPTO}_WIN) + ENDIF(NOT ARCHIVE_CRYPTO_${CRYPTO}) + ENDFOREACH(CRYPTO) + ENDIF(WIN32 AND NOT CYGWIN) +ENDMACRO(CHECK_CRYPTO_WIN CRYPTO_LIST) + +# +# Find iconv +# POSIX defines the second arg as const char ** +# and requires it to be in libc. But we can accept +# a non-const argument here and can support iconv() +# being in libiconv. +# +MACRO(CHECK_ICONV LIB TRY_ICONV_CONST) + IF(NOT HAVE_ICONV) + CMAKE_PUSH_CHECK_STATE() # Save the state of the variables + IF (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR + CMAKE_C_COMPILER_ID STREQUAL "Clang") + # + # During checking iconv proto type, we should use -Werror to avoid the + # success of iconv detection with a warnig which success is a miss + # detection. So this needs for all build mode(even it's a release mode). + # + SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror") + ENDIF () + IF (CMAKE_C_COMPILER_ID STREQUAL "XL") + SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -qhalt=w -qflag=w:w") + ENDIF () + IF (MSVC) + # NOTE: /WX option is the same as gcc's -Werror option. + SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} /WX") + ENDIF (MSVC) + # + CHECK_C_SOURCE_COMPILES( + "#include + #include + int main() { + ${TRY_ICONV_CONST} char *ccp; + iconv_t cd = iconv_open(\"\", \"\"); + iconv(cd, &ccp, (size_t *)0, (char **)0, (size_t *)0); + iconv_close(cd); + return 0; + }" + HAVE_ICONV_${LIB}_${TRY_ICONV_CONST}) + IF(HAVE_ICONV_${LIB}_${TRY_ICONV_CONST}) + SET(HAVE_ICONV true) + SET(ICONV_CONST ${TRY_ICONV_CONST}) + ENDIF(HAVE_ICONV_${LIB}_${TRY_ICONV_CONST}) + CMAKE_POP_CHECK_STATE() # Restore the state of the variables + ENDIF(NOT HAVE_ICONV) +ENDMACRO(CHECK_ICONV TRY_ICONV_CONST) + +IF(ENABLE_ICONV) + CMAKE_PUSH_CHECK_STATE() # Save the state of the variables + FIND_PATH(ICONV_INCLUDE_DIR iconv.h) + MARK_AS_ADVANCED(ICONV_INCLUDE_DIR) + IF(ICONV_INCLUDE_DIR) + #SET(INCLUDES ${INCLUDES} "iconv.h") + SET(HAVE_ICONV_H 1) + INCLUDE_DIRECTORIES(${ICONV_INCLUDE_DIR}) + SET(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR}) + CHECK_ICONV("libc" "const") + CHECK_ICONV("libc" "") + + # If iconv isn't in libc and we have a libiconv, try that. + FIND_LIBRARY(LIBICONV_PATH NAMES iconv libiconv) + IF(NOT HAVE_ICONV AND LIBICONV_PATH) + LIST(APPEND CMAKE_REQUIRED_LIBRARIES ${LIBICONV_PATH}) + # Test if a macro is needed for the library. + TRY_MACRO_FOR_LIBRARY( + "${ICONV_INCLUDE_DIR}" "${LIBICONV_PATH}" + COMPILES + "#include \nint main() {return iconv_close((iconv_t)0);}" + "WITHOUT_LIBICONV_STATIC;LIBICONV_STATIC") + IF(NOT WITHOUT_LIBICONV_STATIC AND LIBICONV_STATIC) + ADD_DEFINITIONS(-DLIBICONV_STATIC) + ENDIF(NOT WITHOUT_LIBICONV_STATIC AND LIBICONV_STATIC) + # + # Set up CMAKE_REQUIRED_* for CHECK_ICONV + # + SET(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR}) + SET(CMAKE_REQUIRED_LIBRARIES ${LIBICONV_PATH}) + IF(LIBICONV_STATIC) + # LIBICONV_STATIC is necessary for the success of CHECK_ICONV + # on Windows. + SET(CMAKE_REQUIRED_DEFINITIONS "-DLIBICONV_STATIC") + ELSE(LIBICONV_STATIC) + SET(CMAKE_REQUIRED_DEFINITIONS) + ENDIF(LIBICONV_STATIC) + CHECK_ICONV("libiconv" "const") + CHECK_ICONV("libiconv" "") + IF (HAVE_ICONV) + LIST(APPEND ADDITIONAL_LIBS ${LIBICONV_PATH}) + ENDIF(HAVE_ICONV) + ENDIF(NOT HAVE_ICONV AND LIBICONV_PATH) + ENDIF(ICONV_INCLUDE_DIR) + # + # Find locale_charset() for libiconv. + # + IF(LIBICONV_PATH) + SET(CMAKE_REQUIRED_DEFINITIONS) + SET(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR}) + SET(CMAKE_REQUIRED_LIBRARIES) + CHECK_INCLUDE_FILES("localcharset.h" HAVE_LOCALCHARSET_H) + FIND_LIBRARY(LIBCHARSET_PATH NAMES charset libcharset) + IF(LIBCHARSET_PATH) + SET(CMAKE_REQUIRED_LIBRARIES ${LIBCHARSET_PATH}) + IF(WIN32 AND NOT CYGWIN) + # Test if a macro is needed for the library. + TRY_MACRO_FOR_LIBRARY( + "${ICONV_INCLUDE_DIR}" "${LIBCHARSET_PATH}" + COMPILES + "#include \nint main() {return locale_charset()?1:0;}" + "WITHOUT_LIBCHARSET_STATIC;LIBCHARSET_STATIC") + IF(NOT WITHOUT_LIBCHARSET_STATIC AND LIBCHARSET_STATIC) + ADD_DEFINITIONS(-DLIBCHARSET_STATIC) + ENDIF(NOT WITHOUT_LIBCHARSET_STATIC AND LIBCHARSET_STATIC) + IF(WITHOUT_LIBCHARSET_STATIC OR LIBCHARSET_STATIC) + SET(HAVE_LOCALE_CHARSET ON CACHE INTERNAL + "Have function locale_charset") + ENDIF(WITHOUT_LIBCHARSET_STATIC OR LIBCHARSET_STATIC) + ELSE(WIN32 AND NOT CYGWIN) + CHECK_FUNCTION_EXISTS_GLIBC(locale_charset HAVE_LOCALE_CHARSET) + ENDIF(WIN32 AND NOT CYGWIN) + IF(HAVE_LOCALE_CHARSET) + LIST(APPEND ADDITIONAL_LIBS ${LIBCHARSET_PATH}) + ENDIF(HAVE_LOCALE_CHARSET) + ENDIF(LIBCHARSET_PATH) + ENDIF(LIBICONV_PATH) + CMAKE_POP_CHECK_STATE() # Restore the state of the variables +ELSE(ENABLE_ICONV) + # Make sure ICONV variables are not in CACHE after ENABLE_ICONV disabled + # (once enabled). + UNSET(HAVE_LOCALE_CHARSET CACHE) + UNSET(HAVE_ICONV CACHE) + UNSET(HAVE_ICONV_libc_ CACHE) + UNSET(HAVE_ICONV_libc_const CACHE) + UNSET(HAVE_ICONV_libiconv_ CACHE) + UNSET(HAVE_ICONV_libiconv_const CACHE) + UNSET(ICONV_INCLUDE_DIR CACHE) + UNSET(LIBICONV_PATH CACHE) + UNSET(LIBICONV_DLL CACHE) + UNSET(LIBICONV_STATIC CACHE) + UNSET(LIBCHARSET_DLL CACHE) + UNSET(LIBCHARSET_STATIC CACHE) +ENDIF(ENABLE_ICONV) + +IF(0) # CMake does not need XML support in libarchive +# +# Find Libxml2 +# +IF(ENABLE_LIBXML2) + FIND_PACKAGE(LibXml2) +ELSE() + SET(LIBXML2_FOUND FALSE) +ENDIF() +IF(LIBXML2_FOUND) + CMAKE_PUSH_CHECK_STATE() # Save the state of the variables + INCLUDE_DIRECTORIES(${LIBXML2_INCLUDE_DIR}) + LIST(APPEND ADDITIONAL_LIBS ${LIBXML2_LIBRARIES}) + SET(HAVE_LIBXML2 1) + # libxml2's include files use iconv.h + SET(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR} ${LIBXML2_INCLUDE_DIR}) + CHECK_INCLUDE_FILES("libxml/xmlreader.h" HAVE_LIBXML_XMLREADER_H) + CHECK_INCLUDE_FILES("libxml/xmlwriter.h" HAVE_LIBXML_XMLWRITER_H) + # Test if a macro is needed for the library. + TRY_MACRO_FOR_LIBRARY( + "${ICONV_INCLUDE_DIR};${LIBXML2_INCLUDE_DIR}" + "ws2_32.lib;${ZLIB_LIBRARIES};${LIBICONV_PATH};${LIBXML2_LIBRARIES}" + COMPILES + "#include \n#include \nint main() {return xmlTextReaderRead((xmlTextReaderPtr)(void *)0);}" + "WITHOUT_LIBXML_STATIC;LIBXML_STATIC") + IF(NOT WITHOUT_LIBXML_STATIC AND LIBXML_STATIC) + ADD_DEFINITIONS(-DLIBXML_STATIC) + ENDIF(NOT WITHOUT_LIBXML_STATIC AND LIBXML_STATIC) + CMAKE_POP_CHECK_STATE() # Restore the state of the variables +ELSE(LIBXML2_FOUND) + # + # Find Expat + # + IF(ENABLE_EXPAT) + FIND_PACKAGE(EXPAT) + ELSE() + SET(EXPAT_FOUND FALSE) + ENDIF() + IF(EXPAT_FOUND) + CMAKE_PUSH_CHECK_STATE() # Save the state of the variables + INCLUDE_DIRECTORIES(${EXPAT_INCLUDE_DIR}) + LIST(APPEND ADDITIONAL_LIBS ${EXPAT_LIBRARIES}) + SET(HAVE_LIBEXPAT 1) + LA_CHECK_INCLUDE_FILE("expat.h" HAVE_EXPAT_H) + CMAKE_POP_CHECK_STATE() # Restore the state of the variables + ENDIF(EXPAT_FOUND) +ENDIF(LIBXML2_FOUND) +MARK_AS_ADVANCED(CLEAR LIBXML2_INCLUDE_DIR) +MARK_AS_ADVANCED(CLEAR LIBXML2_LIBRARIES) +ENDIF() + +# +# Check functions +# +CMAKE_PUSH_CHECK_STATE() # Save the state of the variables +IF (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR + CMAKE_C_COMPILER_ID STREQUAL "Clang") + # + # During checking functions, we should use -fno-builtin to avoid the + # failure of function detection which failure is an error "conflicting + # types for built-in function" caused by using -Werror option. + # + SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-builtin") +ENDIF () +CHECK_SYMBOL_EXISTS(_CrtSetReportMode "crtdbg.h" HAVE__CrtSetReportMode) +CHECK_FUNCTION_EXISTS_GLIBC(arc4random_buf HAVE_ARC4RANDOM_BUF) +CHECK_FUNCTION_EXISTS_GLIBC(chflags HAVE_CHFLAGS) +CHECK_FUNCTION_EXISTS_GLIBC(chown HAVE_CHOWN) +CHECK_FUNCTION_EXISTS_GLIBC(chroot HAVE_CHROOT) +CHECK_FUNCTION_EXISTS_GLIBC(ctime_r HAVE_CTIME_R) +CHECK_FUNCTION_EXISTS_GLIBC(fchdir HAVE_FCHDIR) +CHECK_FUNCTION_EXISTS_GLIBC(fchflags HAVE_FCHFLAGS) +CHECK_FUNCTION_EXISTS_GLIBC(fchmod HAVE_FCHMOD) +CHECK_FUNCTION_EXISTS_GLIBC(fchown HAVE_FCHOWN) +CHECK_FUNCTION_EXISTS_GLIBC(fcntl HAVE_FCNTL) +CHECK_FUNCTION_EXISTS_GLIBC(fdopendir HAVE_FDOPENDIR) +CHECK_FUNCTION_EXISTS_GLIBC(fork HAVE_FORK) +CHECK_FUNCTION_EXISTS_GLIBC(fstat HAVE_FSTAT) +CHECK_FUNCTION_EXISTS_GLIBC(fstatat HAVE_FSTATAT) +CHECK_FUNCTION_EXISTS_GLIBC(fstatfs HAVE_FSTATFS) +CHECK_FUNCTION_EXISTS_GLIBC(fstatvfs HAVE_FSTATVFS) +CHECK_FUNCTION_EXISTS_GLIBC(ftruncate HAVE_FTRUNCATE) +CHECK_FUNCTION_EXISTS_GLIBC(futimens HAVE_FUTIMENS) +CHECK_FUNCTION_EXISTS_GLIBC(futimes HAVE_FUTIMES) +CHECK_FUNCTION_EXISTS_GLIBC(futimesat HAVE_FUTIMESAT) +CHECK_FUNCTION_EXISTS_GLIBC(geteuid HAVE_GETEUID) +CHECK_FUNCTION_EXISTS_GLIBC(getgrgid_r HAVE_GETGRGID_R) +CHECK_FUNCTION_EXISTS_GLIBC(getgrnam_r HAVE_GETGRNAM_R) +CHECK_FUNCTION_EXISTS_GLIBC(getpwnam_r HAVE_GETPWNAM_R) +CHECK_FUNCTION_EXISTS_GLIBC(getpwuid_r HAVE_GETPWUID_R) +CHECK_FUNCTION_EXISTS_GLIBC(getpid HAVE_GETPID) +CHECK_FUNCTION_EXISTS_GLIBC(getvfsbyname HAVE_GETVFSBYNAME) +CHECK_FUNCTION_EXISTS_GLIBC(gmtime_r HAVE_GMTIME_R) +CHECK_FUNCTION_EXISTS_GLIBC(lchflags HAVE_LCHFLAGS) +CHECK_FUNCTION_EXISTS_GLIBC(lchmod HAVE_LCHMOD) +CHECK_FUNCTION_EXISTS_GLIBC(lchown HAVE_LCHOWN) +CHECK_FUNCTION_EXISTS_GLIBC(link HAVE_LINK) +CHECK_FUNCTION_EXISTS_GLIBC(localtime_r HAVE_LOCALTIME_R) +CHECK_FUNCTION_EXISTS_GLIBC(lstat HAVE_LSTAT) +CHECK_FUNCTION_EXISTS_GLIBC(lutimes HAVE_LUTIMES) +CHECK_FUNCTION_EXISTS_GLIBC(mbrtowc HAVE_MBRTOWC) +CHECK_FUNCTION_EXISTS_GLIBC(memmove HAVE_MEMMOVE) +CHECK_FUNCTION_EXISTS_GLIBC(mkdir HAVE_MKDIR) +CHECK_FUNCTION_EXISTS_GLIBC(mkfifo HAVE_MKFIFO) +CHECK_FUNCTION_EXISTS_GLIBC(mknod HAVE_MKNOD) +CHECK_FUNCTION_EXISTS_GLIBC(mkstemp HAVE_MKSTEMP) +CHECK_FUNCTION_EXISTS_GLIBC(nl_langinfo HAVE_NL_LANGINFO) +CHECK_FUNCTION_EXISTS_GLIBC(openat HAVE_OPENAT) +CHECK_FUNCTION_EXISTS_GLIBC(pipe HAVE_PIPE) +CHECK_FUNCTION_EXISTS_GLIBC(poll HAVE_POLL) +CHECK_FUNCTION_EXISTS_GLIBC(posix_spawnp HAVE_POSIX_SPAWNP) +CHECK_FUNCTION_EXISTS_GLIBC(readlink HAVE_READLINK) +CHECK_FUNCTION_EXISTS_GLIBC(readpassphrase HAVE_READPASSPHRASE) +CHECK_FUNCTION_EXISTS_GLIBC(select HAVE_SELECT) +CHECK_FUNCTION_EXISTS_GLIBC(setenv HAVE_SETENV) +CHECK_FUNCTION_EXISTS_GLIBC(setlocale HAVE_SETLOCALE) +CHECK_FUNCTION_EXISTS_GLIBC(sigaction HAVE_SIGACTION) +CHECK_FUNCTION_EXISTS_GLIBC(statfs HAVE_STATFS) +CHECK_FUNCTION_EXISTS_GLIBC(statvfs HAVE_STATVFS) +CHECK_FUNCTION_EXISTS_GLIBC(strchr HAVE_STRCHR) +CHECK_FUNCTION_EXISTS_GLIBC(strdup HAVE_STRDUP) +CHECK_FUNCTION_EXISTS_GLIBC(strerror HAVE_STRERROR) +CHECK_FUNCTION_EXISTS_GLIBC(strncpy_s HAVE_STRNCPY_S) +CHECK_FUNCTION_EXISTS_GLIBC(strrchr HAVE_STRRCHR) +CHECK_FUNCTION_EXISTS_GLIBC(symlink HAVE_SYMLINK) +CHECK_FUNCTION_EXISTS_GLIBC(timegm HAVE_TIMEGM) +CHECK_FUNCTION_EXISTS_GLIBC(tzset HAVE_TZSET) +CHECK_FUNCTION_EXISTS_GLIBC(unsetenv HAVE_UNSETENV) +CHECK_FUNCTION_EXISTS_GLIBC(utime HAVE_UTIME) +CHECK_FUNCTION_EXISTS_GLIBC(utimes HAVE_UTIMES) +CHECK_FUNCTION_EXISTS_GLIBC(utimensat HAVE_UTIMENSAT) +CHECK_FUNCTION_EXISTS_GLIBC(vfork HAVE_VFORK) +CHECK_FUNCTION_EXISTS_GLIBC(wcrtomb HAVE_WCRTOMB) +CHECK_FUNCTION_EXISTS_GLIBC(wcscmp HAVE_WCSCMP) +CHECK_FUNCTION_EXISTS_GLIBC(wcscpy HAVE_WCSCPY) +CHECK_FUNCTION_EXISTS_GLIBC(wcslen HAVE_WCSLEN) +CHECK_FUNCTION_EXISTS_GLIBC(wctomb HAVE_WCTOMB) +CHECK_FUNCTION_EXISTS_GLIBC(_ctime64_s HAVE__CTIME64_S) +CHECK_FUNCTION_EXISTS_GLIBC(_fseeki64 HAVE__FSEEKI64) +CHECK_FUNCTION_EXISTS_GLIBC(_get_timezone HAVE__GET_TIMEZONE) +CHECK_FUNCTION_EXISTS_GLIBC(_localtime64_s HAVE__LOCALTIME64_S) +CHECK_FUNCTION_EXISTS_GLIBC(_mkgmtime64 HAVE__MKGMTIME64) + +SET(CMAKE_REQUIRED_LIBRARIES "") +CHECK_FUNCTION_EXISTS(cygwin_conv_path HAVE_CYGWIN_CONV_PATH) +CHECK_FUNCTION_EXISTS(fseeko HAVE_FSEEKO) +CHECK_FUNCTION_EXISTS(strerror_r HAVE_STRERROR_R) +CHECK_FUNCTION_EXISTS(strftime HAVE_STRFTIME) +CHECK_FUNCTION_EXISTS(vprintf HAVE_VPRINTF) +CHECK_FUNCTION_EXISTS(wmemcmp HAVE_WMEMCMP) +CHECK_FUNCTION_EXISTS(wmemcpy HAVE_WMEMCPY) +CHECK_FUNCTION_EXISTS(wmemmove HAVE_WMEMMOVE) + +CMAKE_POP_CHECK_STATE() # Restore the state of the variables + +CHECK_C_SOURCE_COMPILES( + "#include \n#include \nint main(void) { struct vfsconf v; return sizeof(v);}" + HAVE_STRUCT_VFSCONF) + +CHECK_C_SOURCE_COMPILES( + "#include \n#include \nint main(void) { struct xvfsconf v; return sizeof(v);}" + HAVE_STRUCT_XVFSCONF) + +# Make sure we have the POSIX version of readdir_r, not the +# older 2-argument version. +CHECK_C_SOURCE_COMPILES( + "#include \nint main() {DIR *d = opendir(\".\"); struct dirent e,*r; return readdir_r(d,&e,&r);}" + HAVE_READDIR_R) + +# dirfd can be either a function or a macro. +CHECK_C_SOURCE_COMPILES( + "#include \nint main() {DIR *d = opendir(\".\"); return dirfd(d);}" + HAVE_DIRFD) + +# Only detect readlinkat() if we also have AT_FDCWD in unistd.h. +# NOTE: linux requires fcntl.h for AT_FDCWD. +CHECK_C_SOURCE_COMPILES( + "#include \n#include \nint main() {char buf[10]; return readlinkat(AT_FDCWD, \"\", buf, 0);}" + HAVE_READLINKAT) + + +# To verify major(), we need to both include the header +# of interest and verify that the result can be linked. +# CHECK_FUNCTION_EXISTS doesn't accept a header argument, +# CHECK_SYMBOL_EXISTS doesn't test linkage. +CHECK_C_SOURCE_COMPILES( + "#include \nint main() { return major(256); }" + MAJOR_IN_MKDEV) +CHECK_C_SOURCE_COMPILES( + "#include \nint main() { return major(256); }" + MAJOR_IN_SYSMACROS) + +CHECK_C_SOURCE_COMPILES( + "#include \n#if LZMA_VERSION < 50020000\n#error unsupported\n#endif\nint main(void){lzma_stream_encoder_mt(0, 0); return 0;}" + HAVE_LZMA_STREAM_ENCODER_MT) + +IF(HAVE_STRERROR_R) + SET(HAVE_DECL_STRERROR_R 1) +ENDIF(HAVE_STRERROR_R) + +# +# Check defines +# +SET(headers "limits.h") +IF(HAVE_STDINT_H) + LIST(APPEND headers "stdint.h") +ENDIF(HAVE_STDINT_H) +IF(HAVE_INTTYPES_H) + LIST(APPEND headers "inttypes.h") +ENDIF(HAVE_INTTYPES_H) +CHECK_SYMBOL_EXISTS(EFTYPE "errno.h" HAVE_EFTYPE) +CHECK_SYMBOL_EXISTS(EILSEQ "errno.h" HAVE_EILSEQ) +CHECK_SYMBOL_EXISTS(D_MD_ORDER "langinfo.h" HAVE_D_MD_ORDER) +CHECK_SYMBOL_EXISTS(INT32_MAX "${headers}" HAVE_DECL_INT32_MAX) +CHECK_SYMBOL_EXISTS(INT32_MIN "${headers}" HAVE_DECL_INT32_MIN) +CHECK_SYMBOL_EXISTS(INT64_MAX "${headers}" HAVE_DECL_INT64_MAX) +CHECK_SYMBOL_EXISTS(INT64_MIN "${headers}" HAVE_DECL_INT64_MIN) +CHECK_SYMBOL_EXISTS(INTMAX_MAX "${headers}" HAVE_DECL_INTMAX_MAX) +CHECK_SYMBOL_EXISTS(INTMAX_MIN "${headers}" HAVE_DECL_INTMAX_MIN) +CHECK_SYMBOL_EXISTS(UINT32_MAX "${headers}" HAVE_DECL_UINT32_MAX) +CHECK_SYMBOL_EXISTS(UINT64_MAX "${headers}" HAVE_DECL_UINT64_MAX) +CHECK_SYMBOL_EXISTS(UINTMAX_MAX "${headers}" HAVE_DECL_UINTMAX_MAX) +CHECK_SYMBOL_EXISTS(SIZE_MAX "${headers}" HAVE_DECL_SIZE_MAX) +CHECK_SYMBOL_EXISTS(SSIZE_MAX "limits.h" HAVE_DECL_SSIZE_MAX) + +# +# Check struct members +# +# Check for tm_gmtoff in struct tm +CHECK_STRUCT_HAS_MEMBER("struct tm" tm_gmtoff + "time.h" HAVE_STRUCT_TM_TM_GMTOFF) +CHECK_STRUCT_HAS_MEMBER("struct tm" __tm_gmtoff + "time.h" HAVE_STRUCT_TM___TM_GMTOFF) + +# Check for f_namemax in struct statfs +CHECK_STRUCT_HAS_MEMBER("struct statfs" f_namemax + "sys/param.h;sys/mount.h" HAVE_STRUCT_STATFS_F_NAMEMAX) + +# Check for birthtime in struct stat +CHECK_STRUCT_HAS_MEMBER("struct stat" st_birthtime + "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_BIRTHTIME) + +# Check for high-resolution timestamps in struct stat +CHECK_STRUCT_HAS_MEMBER("struct stat" st_birthtimespec.tv_nsec + "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC) +CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtimespec.tv_nsec + "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC) +CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtim.tv_nsec + "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC) +CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtime_n + "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIME_N) +CHECK_STRUCT_HAS_MEMBER("struct stat" st_umtime + "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_UMTIME) +CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtime_usec + "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIME_USEC) +# Check for block size support in struct stat +CHECK_STRUCT_HAS_MEMBER("struct stat" st_blksize + "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_BLKSIZE) +# Check for st_flags in struct stat (BSD fflags) +CHECK_STRUCT_HAS_MEMBER("struct stat" st_flags + "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_FLAGS) + +IF(HAVE_SYS_STATVFS_H) + CHECK_STRUCT_HAS_MEMBER("struct statvfs" f_iosize + "sys/types.h;sys/statvfs.h" HAVE_STRUCT_STATVFS_F_IOSIZE) +ENDIF() + +# +# +CHECK_STRUCT_HAS_MEMBER("struct tm" tm_sec + "sys/types.h;sys/time.h;time.h" TIME_WITH_SYS_TIME) + +# +# Check for integer types +# +# +CHECK_TYPE_SIZE("short" SIZE_OF_SHORT) +CHECK_TYPE_SIZE("int" SIZE_OF_INT) +CHECK_TYPE_SIZE("long" SIZE_OF_LONG) +CHECK_TYPE_SIZE("long long" SIZE_OF_LONG_LONG) + +CHECK_TYPE_SIZE("unsigned short" SIZE_OF_UNSIGNED_SHORT) +CHECK_TYPE_SIZE("unsigned" SIZE_OF_UNSIGNED) +CHECK_TYPE_SIZE("unsigned long" SIZE_OF_UNSIGNED_LONG) +CHECK_TYPE_SIZE("unsigned long long" SIZE_OF_UNSIGNED_LONG_LONG) + +CHECK_TYPE_SIZE("__int64" __INT64) +CHECK_TYPE_SIZE("unsigned __int64" UNSIGNED___INT64) + +CHECK_TYPE_SIZE(int16_t INT16_T) +CHECK_TYPE_SIZE(int32_t INT32_T) +CHECK_TYPE_SIZE(int64_t INT64_T) +CHECK_TYPE_SIZE(intmax_t INTMAX_T) +CHECK_TYPE_SIZE(uint8_t UINT8_T) +CHECK_TYPE_SIZE(uint16_t UINT16_T) +CHECK_TYPE_SIZE(uint32_t UINT32_T) +CHECK_TYPE_SIZE(uint64_t UINT64_T) +CHECK_TYPE_SIZE(uintmax_t UINTMAX_T) + +CHECK_TYPE_SIZE(dev_t DEV_T) +IF(NOT HAVE_DEV_T) + IF(MSVC) + SET(dev_t "unsigned int") + ENDIF(MSVC) +ENDIF(NOT HAVE_DEV_T) +# +CHECK_TYPE_SIZE(gid_t GID_T) +IF(NOT HAVE_GID_T) + IF(WIN32) + SET(gid_t "short") + ELSE(WIN32) + SET(gid_t "unsigned int") + ENDIF(WIN32) +ENDIF(NOT HAVE_GID_T) +# +CHECK_TYPE_SIZE(id_t ID_T) +IF(NOT HAVE_ID_T) + IF(WIN32) + SET(id_t "short") + ELSE(WIN32) + SET(id_t "unsigned int") + ENDIF(WIN32) +ENDIF(NOT HAVE_ID_T) +# +CHECK_TYPE_SIZE(mode_t MODE_T) +IF(NOT HAVE_MODE_T) + IF(WIN32) + SET(mode_t "unsigned short") + ELSE(WIN32) + SET(mode_t "int") + ENDIF(WIN32) +ENDIF(NOT HAVE_MODE_T) +# +CHECK_TYPE_SIZE(off_t OFF_T) +IF(NOT HAVE_OFF_T) + SET(off_t "__int64") +ENDIF(NOT HAVE_OFF_T) +# +CHECK_TYPE_SIZE(size_t SIZE_T) +IF(NOT HAVE_SIZE_T) + IF("${CMAKE_SIZEOF_VOID_P}" EQUAL 8) + SET(size_t "uint64_t") + ELSE("${CMAKE_SIZEOF_VOID_P}" EQUAL 8) + SET(size_t "uint32_t") + ENDIF("${CMAKE_SIZEOF_VOID_P}" EQUAL 8) +ENDIF(NOT HAVE_SIZE_T) +# +CHECK_TYPE_SIZE(ssize_t SSIZE_T) +IF(NOT HAVE_SSIZE_T) + IF("${CMAKE_SIZEOF_VOID_P}" EQUAL 8) + SET(ssize_t "int64_t") + ELSE("${CMAKE_SIZEOF_VOID_P}" EQUAL 8) + SET(ssize_t "long") + ENDIF("${CMAKE_SIZEOF_VOID_P}" EQUAL 8) +ENDIF(NOT HAVE_SSIZE_T) +# +CHECK_TYPE_SIZE(uid_t UID_T) +IF(NOT HAVE_UID_T) + IF(WIN32) + SET(uid_t "short") + ELSE(WIN32) + SET(uid_t "unsigned int") + ENDIF(WIN32) +ENDIF(NOT HAVE_UID_T) +# +CHECK_TYPE_SIZE(pid_t PID_T) +IF(NOT HAVE_PID_T) + IF(WIN32) + SET(pid_t "int") + ELSE(WIN32) + MESSAGE(FATAL_ERROR "pid_t doesn't exist on this platform?") + ENDIF(WIN32) +ENDIF(NOT HAVE_PID_T) +# +CHECK_TYPE_SIZE(intptr_t INTPTR_T) +IF(NOT HAVE_INTPTR_T) + IF("${CMAKE_SIZEOF_VOID_P}" EQUAL 8) + SET(intptr_t "int64_t") + ELSE() + SET(intptr_t "int32_t") + ENDIF() +ENDIF(NOT HAVE_INTPTR_T) +# +CHECK_TYPE_SIZE(uintptr_t UINTPTR_T) +IF(NOT HAVE_UINTPTR_T) + IF("${CMAKE_SIZEOF_VOID_P}" EQUAL 8) + SET(uintptr_t "uint64_t") + ELSE() + SET(uintptr_t "uint32_t") + ENDIF() +ENDIF(NOT HAVE_UINTPTR_T) +# +CHECK_TYPE_SIZE(wchar_t SIZEOF_WCHAR_T) +IF(HAVE_SIZEOF_WCHAR_T) + SET(HAVE_WCHAR_T 1) +ENDIF(HAVE_SIZEOF_WCHAR_T) +# +# Check if _FILE_OFFSET_BITS macro needed for large files +# +CHECK_FILE_OFFSET_BITS() + +# +# Check for Extended Attribute libraries, headers, and functions +# +IF(ENABLE_XATTR) + CHECK_LIBRARY_EXISTS(attr "setxattr" "" HAVE_LIBATTR) + IF(HAVE_LIBATTR) + SET(CMAKE_REQUIRED_LIBRARIES "attr") + ENDIF(HAVE_LIBATTR) + CHECK_SYMBOL_EXISTS(EXTATTR_NAMESPACE_USER "sys/types.h;sys/extattr.h" HAVE_DECL_EXTATTR_NAMESPACE_USER) + CHECK_SYMBOL_EXISTS(XATTR_NOFOLLOW "sys/xattr.h" HAVE_DECL_XATTR_NOFOLLOW) + IF(HAVE_SYS_XATTR_H AND HAVE_DECL_XATTR_NOFOLLOW) + CHECK_FUNCTION_EXISTS(fgetxattr HAVE_FGETXATTR) + CHECK_FUNCTION_EXISTS(flistxattr HAVE_FLISTXATTR) + CHECK_FUNCTION_EXISTS(fsetxattr HAVE_FSETXATTR) + CHECK_FUNCTION_EXISTS(getxattr HAVE_GETXATTR) + CHECK_FUNCTION_EXISTS(listxattr HAVE_LISTXATTR) + CHECK_FUNCTION_EXISTS(setxattr HAVE_SETXATTR) + IF(HAVE_FGETXATTR AND + HAVE_FLISTXATTR AND + HAVE_FSETXATTR AND + HAVE_GETXATTR AND + HAVE_LISTXATTR AND + HAVE_SETXATTR) + SET(ARCHIVE_XATTR_DARWIN TRUE) + ENDIF() + ELSEIF(HAVE_SYS_EXTATTR_H AND HAVE_DECL_EXTATTR_NAMESPACE_USER) + # FreeBSD xattr support + CHECK_FUNCTION_EXISTS(extattr_get_fd HAVE_EXTATTR_GET_FD) + CHECK_FUNCTION_EXISTS(extattr_get_file HAVE_EXTATTR_GET_FILE) + CHECK_FUNCTION_EXISTS(extattr_get_link HAVE_EXTATTR_GET_LINK) + CHECK_FUNCTION_EXISTS(extattr_list_fd HAVE_EXTATTR_LIST_FD) + CHECK_FUNCTION_EXISTS(extattr_list_file HAVE_EXTATTR_LIST_FILE) + CHECK_FUNCTION_EXISTS(extattr_list_link HAVE_EXTATTR_LIST_LINK) + CHECK_FUNCTION_EXISTS(extattr_set_fd HAVE_EXTATTR_SET_FD) + CHECK_FUNCTION_EXISTS(extattr_set_link HAVE_EXTATTR_SET_LINK) + IF(HAVE_EXTATTR_GET_FD AND + HAVE_EXTATTR_GET_FILE AND + HAVE_EXTATTR_GET_LINK AND + HAVE_EXTATTR_LIST_FD AND + HAVE_EXTATTR_LIST_FILE AND + HAVE_EXTATTR_LIST_LINK AND + HAVE_EXTATTR_SET_FD AND + HAVE_EXTATTR_SET_LINK) + SET(ARCHIVE_XATTR_FREEBSD TRUE) + ENDIF() + ELSEIF(HAVE_SYS_XATTR_H OR HAVE_ATTR_XATTR_H) + # Linux xattr support + CHECK_FUNCTION_EXISTS_GLIBC(fgetxattr HAVE_FGETXATTR) + CHECK_FUNCTION_EXISTS_GLIBC(flistxattr HAVE_FLISTXATTR) + CHECK_FUNCTION_EXISTS_GLIBC(fsetxattr HAVE_FSETXATTR) + CHECK_FUNCTION_EXISTS_GLIBC(getxattr HAVE_GETXATTR) + CHECK_FUNCTION_EXISTS_GLIBC(lgetxattr HAVE_LGETXATTR) + CHECK_FUNCTION_EXISTS_GLIBC(listxattr HAVE_LISTXATTR) + CHECK_FUNCTION_EXISTS_GLIBC(llistxattr HAVE_LLISTXATTR) + CHECK_FUNCTION_EXISTS_GLIBC(lsetxattr HAVE_LSETXATTR) + IF(HAVE_FGETXATTR AND + HAVE_FLISTXATTR AND + HAVE_FSETXATTR AND + HAVE_GETXATTR AND + HAVE_LGETXATTR AND + HAVE_LISTXATTR AND + HAVE_LLISTXATTR AND + HAVE_LSETXATTR) + SET(ARCHIVE_XATTR_LINUX TRUE) + ENDIF() + ELSEIF(HAVE_SYS_EA_H) + # AIX xattr support + CHECK_FUNCTION_EXISTS(fgetea HAVE_FGETEA) + CHECK_FUNCTION_EXISTS(flistea HAVE_FLISTEA) + CHECK_FUNCTION_EXISTS(fsetea HAVE_FSETEA) + CHECK_FUNCTION_EXISTS(getea HAVE_GETEA) + CHECK_FUNCTION_EXISTS(lgetea HAVE_LGETEA) + CHECK_FUNCTION_EXISTS(listea HAVE_LISTEA) + CHECK_FUNCTION_EXISTS(llistea HAVE_LLISTEA) + CHECK_FUNCTION_EXISTS(lsetea HAVE_LSETEA) + IF(HAVE_FGETEA AND + HAVE_FLISTEA AND + HAVE_FSETEA AND + HAVE_GETEA AND + HAVE_LGETEA AND + HAVE_LISTEA AND + HAVE_LLISTEA AND + HAVE_LSETEA) + SET(ARCHIVE_XATTR_AIX TRUE) + ENDIF() + ENDIF() + + IF(ARCHIVE_XATTR_DARWIN) + MESSAGE(STATUS "Extended attributes support: Darwin") + ELSEIF(ARCHIVE_XATTR_FREEBSD) + MESSAGE(STATUS "Extended attributes support: FreeBSD") + ELSEIF(ARCHIVE_XATTR_LINUX) + MESSAGE(STATUS "Extended attributes support: Linux") + ELSEIF(ARCHIVE_XATTR_AIX) + MESSAGE(STATUS "Extended attributes support: AIX") + ELSE() + MESSAGE(STATUS "Extended attributes support: none") + ENDIF() +ELSE(ENABLE_XATTR) + SET(ARCHIVE_XATTR_DARWIN FALSE) + SET(ARCHIVE_XATTR_FREEBSD FALSE) + SET(ARCHIVE_XATTR_LINUX FALSE) + SET(ARCHIVE_XATTR_AIX FALSE) +ENDIF(ENABLE_XATTR) + +# +# Check for ACL libraries, headers, and functions +# +# The ACL support in libarchive is written against the POSIX1e draft, +# which was never officially approved and varies quite a bit across +# platforms. Worse, some systems have completely non-POSIX acl functions, +# which makes the following checks rather more complex than I would like. +# +IF(ENABLE_ACL) + # Solaris and derivates ACLs + CHECK_FUNCTION_EXISTS(acl HAVE_ACL) + CHECK_FUNCTION_EXISTS(facl HAVE_FACL) + + # Libacl + CHECK_LIBRARY_EXISTS(acl "acl_get_file" "" HAVE_LIBACL) + IF(HAVE_LIBACL) + SET(CMAKE_REQUIRED_LIBRARIES "acl") + FIND_LIBRARY(ACL_LIBRARY NAMES acl) + LIST(APPEND ADDITIONAL_LIBS ${ACL_LIBRARY}) + ENDIF(HAVE_LIBACL) + + CHECK_TYPE_EXISTS(acl_t "sys/types.h;sys/acl.h" HAVE_ACL_T) + CHECK_TYPE_EXISTS(acl_entry_t "sys/types.h;sys/acl.h" HAVE_ACL_ENTRY_T) + CHECK_TYPE_EXISTS(acl_permset_t "sys/types.h;sys/acl.h" HAVE_ACL_PERMSET_T) + CHECK_TYPE_EXISTS(acl_tag_t "sys/types.h;sys/acl.h" HAVE_ACL_TAG_T) + + IF(HAVE_ACL AND HAVE_FACL) + CHECK_TYPE_EXISTS(aclent_t "sys/acl.h" HAVE_ACLENT_T) + IF(HAVE_ACLENT_T) + CHECK_SYMBOL_EXISTS(GETACL "sys/acl.h" HAVE_DECL_GETACL) + CHECK_SYMBOL_EXISTS(GETACLCNT "sys/acl.h" HAVE_DECL_GETACLCNT) + CHECK_SYMBOL_EXISTS(SETACL "sys/acl.h" HAVE_DECL_SETACL) + IF(HAVE_DECL_GETACL AND + HAVE_DECL_GETACLCNT AND + HAVE_DECL_SETACL) + SET(ARCHIVE_ACL_SUNOS TRUE) + ENDIF() + CHECK_TYPE_EXISTS(ace_t "sys/acl.h" HAVE_ACE_T) + IF(HAVE_ACE_T) + CHECK_SYMBOL_EXISTS(ACE_GETACL "sys/acl.h" HAVE_DECL_ACE_GETACL) + CHECK_SYMBOL_EXISTS(ACE_GETACLCNT "sys/acl.h" HAVE_DECL_ACE_GETACLCNT) + CHECK_SYMBOL_EXISTS(ACE_SETACL "sys/acl.h" HAVE_DECL_ACE_SETACL) + IF(HAVE_DECL_ACE_GETACL AND + HAVE_DECL_ACE_GETACLCNT AND + HAVE_DECL_ACE_SETACL) + SET(ARCHIVE_ACL_SUNOS_NFS4 TRUE) + ENDIF() + ENDIF(HAVE_ACE_T) + ENDIF(HAVE_ACLENT_T) + ENDIF(HAVE_ACL AND HAVE_FACL) + + IF(HAVE_ACL_T AND HAVE_ACL_ENTRY_T AND HAVE_ACL_PERMSET_T AND HAVE_ACL_TAG_T) + CHECK_FUNCTION_EXISTS_GLIBC(acl_add_perm HAVE_ACL_ADD_PERM) + CHECK_FUNCTION_EXISTS_GLIBC(acl_clear_perms HAVE_ACL_CLEAR_PERMS) + CHECK_FUNCTION_EXISTS_GLIBC(acl_create_entry HAVE_ACL_CREATE_ENTRY) + CHECK_FUNCTION_EXISTS_GLIBC(acl_delete_def_file HAVE_ACL_DELETE_DEF_FILE) + CHECK_FUNCTION_EXISTS_GLIBC(acl_free HAVE_ACL_FREE) + CHECK_FUNCTION_EXISTS_GLIBC(acl_get_entry HAVE_ACL_GET_ENTRY) + CHECK_FUNCTION_EXISTS_GLIBC(acl_get_fd HAVE_ACL_GET_FD) + CHECK_FUNCTION_EXISTS_GLIBC(acl_get_file HAVE_ACL_GET_FILE) + CHECK_FUNCTION_EXISTS_GLIBC(acl_get_permset HAVE_ACL_GET_PERMSET) + CHECK_FUNCTION_EXISTS_GLIBC(acl_get_qualifier HAVE_ACL_GET_QUALIFIER) + CHECK_FUNCTION_EXISTS_GLIBC(acl_get_tag_type HAVE_ACL_GET_TAG_TYPE) + CHECK_FUNCTION_EXISTS_GLIBC(acl_init HAVE_ACL_INIT) + CHECK_FUNCTION_EXISTS_GLIBC(acl_set_fd HAVE_ACL_SET_FD) + CHECK_FUNCTION_EXISTS_GLIBC(acl_set_file HAVE_ACL_SET_FILE) + CHECK_FUNCTION_EXISTS_GLIBC(acl_set_qualifier HAVE_ACL_SET_QUALIFIER) + CHECK_FUNCTION_EXISTS_GLIBC(acl_set_tag_type HAVE_ACL_SET_TAG_TYPE) + IF(HAVE_ACL_ADD_PERM AND + HAVE_ACL_CLEAR_PERMS AND + HAVE_ACL_CREATE_ENTRY AND + HAVE_ACL_DELETE_DEF_FILE AND + HAVE_ACL_FREE AND + HAVE_ACL_GET_ENTRY AND + HAVE_ACL_GET_FD AND + HAVE_ACL_GET_FILE AND + HAVE_ACL_GET_PERMSET AND + HAVE_ACL_GET_QUALIFIER AND + HAVE_ACL_GET_TAG_TYPE AND + HAVE_ACL_INIT AND + HAVE_ACL_SET_FD AND + HAVE_ACL_SET_FILE AND + HAVE_ACL_SET_QUALIFIER AND + HAVE_ACL_SET_TAG_TYPE) + SET(HAVE_POSIX_ACL_FUNCS 1) + ENDIF() + + CHECK_FUNCTION_EXISTS_GLIBC(acl_get_perm HAVE_ACL_GET_PERM) + + IF(HAVE_POSIX_ACL_FUNCS AND HAVE_ACL_LIBACL_H AND HAVE_LIBACL AND + HAVE_ACL_GET_PERM) + SET(ARCHIVE_ACL_LIBACL TRUE) + ELSE() + CHECK_FUNCTION_EXISTS(acl_add_flag_np HAVE_ACL_ADD_FLAG_NP) + CHECK_FUNCTION_EXISTS(acl_clear_flags_np HAVE_ACL_CLEAR_FLAGS_NP) + CHECK_FUNCTION_EXISTS(acl_get_brand_np HAVE_ACL_GET_BRAND_NP) + CHECK_FUNCTION_EXISTS(acl_get_entry_type_np HAVE_ACL_GET_ENTRY_TYPE_NP) + CHECK_FUNCTION_EXISTS(acl_get_flag_np HAVE_ACL_GET_FLAG_NP) + CHECK_FUNCTION_EXISTS(acl_get_flagset_np HAVE_ACL_GET_FLAGSET_NP) + CHECK_FUNCTION_EXISTS(acl_get_fd_np HAVE_ACL_GET_FD_NP) + CHECK_FUNCTION_EXISTS(acl_get_link_np HAVE_ACL_GET_LINK_NP) + CHECK_FUNCTION_EXISTS(acl_get_perm_np HAVE_ACL_GET_PERM_NP) + CHECK_FUNCTION_EXISTS(acl_is_trivial_np HAVE_ACL_IS_TRIVIAL_NP) + CHECK_FUNCTION_EXISTS(acl_set_entry_type_np HAVE_ACL_SET_ENTRY_TYPE_NP) + CHECK_FUNCTION_EXISTS(acl_set_fd_np HAVE_ACL_SET_FD_NP) + CHECK_FUNCTION_EXISTS(acl_set_link_np HAVE_ACL_SET_LINK_NP) + CHECK_FUNCTION_EXISTS(mbr_gid_to_uuid HAVE_MBR_GID_TO_UUID) + CHECK_FUNCTION_EXISTS(mbr_uid_to_uuid HAVE_MBR_UID_TO_UUID) + CHECK_FUNCTION_EXISTS(mbr_uuid_to_id HAVE_MBR_UUID_TO_ID) + + CHECK_C_SOURCE_COMPILES("#include +#include +int main(void) { return ACL_TYPE_EXTENDED; }" HAVE_DECL_ACL_TYPE_EXTENDED) + CHECK_C_SOURCE_COMPILES("#include +#include +int main(void) { return ACL_SYNCHRONIZE; }" HAVE_DECL_ACL_SYNCHRONIZE) + CHECK_SYMBOL_EXISTS(ACL_TYPE_NFS4 "sys/acl.h" HAVE_DECL_ACL_TYPE_NFS4) + CHECK_SYMBOL_EXISTS(ACL_USER "sys/acl.h" HAVE_DECL_ACL_USER) + + IF(HAVE_POSIX_ACL_FUNCS AND + HAVE_ACL_GET_FD_NP AND + HAVE_ACL_GET_PERM_NP AND + NOT HAVE_ACL_GET_PERM AND + HAVE_ACL_SET_FD_NP) + IF(HAVE_DECL_ACL_USER) + SET(ARCHIVE_ACL_FREEBSD TRUE) + IF(HAVE_DECL_ACL_TYPE_NFS4 AND + HAVE_ACL_ADD_FLAG_NP AND + HAVE_ACL_CLEAR_FLAGS_NP AND + HAVE_ACL_GET_BRAND_NP AND + HAVE_ACL_GET_ENTRY_TYPE_NP AND + HAVE_ACL_GET_FLAGSET_NP AND + HAVE_ACL_SET_ENTRY_TYPE_NP) + SET(ARCHIVE_ACL_FREEBSD_NFS4 TRUE) + ENDIF() + ELSEIF(HAVE_DECL_ACL_TYPE_EXTENDED AND + HAVE_MEMBERSHIP_H AND + HAVE_ACL_ADD_FLAG_NP AND + HAVE_ACL_CLEAR_FLAGS_NP AND + HAVE_ACL_GET_FLAGSET_NP AND + HAVE_ACL_GET_LINK_NP AND + HAVE_ACL_SET_LINK_NP AND + HAVE_MBR_UID_TO_UUID AND + HAVE_MBR_GID_TO_UUID AND + HAVE_MBR_UUID_TO_ID) + SET(ARCHIVE_ACL_DARWIN TRUE) + ENDIF() + ENDIF() + ENDIF() + ENDIF(HAVE_ACL_T AND HAVE_ACL_ENTRY_T AND HAVE_ACL_PERMSET_T AND + HAVE_ACL_TAG_T) + + # Richacl + CHECK_LIBRARY_EXISTS(richacl "richacl_get_file" "" HAVE_LIBRICHACL) + IF(HAVE_LIBRICHACL) + SET(CMAKE_REQUIRED_LIBRARIES "richacl") + FIND_LIBRARY(RICHACL_LIBRARY NAMES richacl) + LIST(APPEND ADDITIONAL_LIBS ${RICHACL_LIBRARY}) + ENDIF(HAVE_LIBRICHACL) + + CHECK_STRUCT_HAS_MEMBER("struct richace" e_type "sys/richacl.h" + HAVE_STRUCT_RICHACE) + CHECK_STRUCT_HAS_MEMBER("struct richacl" a_flags "sys/richacl.h" + HAVE_STRUCT_RICHACL) + + IF(HAVE_LIBRICHACL AND HAVE_STRUCT_RICHACL AND HAVE_STRUCT_RICHACE) + CHECK_FUNCTION_EXISTS_GLIBC(richacl_alloc HAVE_RICHACL_ALLOC) + CHECK_FUNCTION_EXISTS_GLIBC(richacl_equiv_mode HAVE_RICHACL_EQUIV_MODE) + CHECK_FUNCTION_EXISTS_GLIBC(richacl_free HAVE_RICHACL_FREE) + CHECK_FUNCTION_EXISTS_GLIBC(richacl_get_fd HAVE_RICHACL_GET_FD) + CHECK_FUNCTION_EXISTS_GLIBC(richacl_get_file HAVE_RICHACL_GET_FILE) + CHECK_FUNCTION_EXISTS_GLIBC(richacl_set_fd HAVE_RICHACL_SET_FD) + CHECK_FUNCTION_EXISTS_GLIBC(richacl_set_file HAVE_RICHACL_SET_FILE) + IF(HAVE_RICHACL_ALLOC AND + HAVE_RICHACL_EQUIV_MODE AND + HAVE_RICHACL_FREE AND + HAVE_RICHACL_GET_FD AND + HAVE_RICHACL_GET_FILE AND + HAVE_RICHACL_SET_FD AND + HAVE_RICHACL_SET_FILE) + SET(ARCHIVE_ACL_LIBRICHACL TRUE) + ENDIF() + ENDIF(HAVE_LIBRICHACL AND HAVE_STRUCT_RICHACL AND HAVE_STRUCT_RICHACE) + + IF(ARCHIVE_ACL_DARWIN) + MESSAGE(STATUS "ACL support: Darwin (limited NFSv4)") + ELSEIF(ARCHIVE_ACL_FREEBSD_NFS4) + MESSAGE(STATUS "ACL support: FreeBSD (POSIX.1e and NFSv4)") + ELSEIF(ARCHIVE_ACL_FREEBSD) + MESSAGE(STATUS "ACL support: FreeBSD (POSIX.1e)") + ELSEIF(ARCHIVE_ACL_LIBACL OR ARCHIVE_ACL_LIBRICHACL) + IF(ARCHIVE_ACL_LIBACL AND ARCHIVE_ACL_LIBRICHACL) + MESSAGE(STATUS "ACL support: libacl (POSIX.1e) + librichacl (NFSv4)") + ELSEIF(ARCHIVE_ACL_LIBRICHACL) + MESSAGE(STATUS "ACL support: librichacl (NFSv4)") + ELSE() + MESSAGE(STATUS "ACL support: libacl (POSIX.1e)") + ENDIF() + ELSEIF(ARCHIVE_ACL_SUNOS_NFS4) + MESSAGE(STATUS "ACL support: Solaris (POSIX.1e and NFSv4)") + ELSEIF(ARCHIVE_ACL_SUNOS) + MESSAGE(STATUS "ACL support: Solaris (POSIX.1e)") + ELSE() + MESSAGE(STATUS "ACL support: none") + ENDIF() + +ELSE(ENABLE_ACL) + # If someone runs cmake, then disables ACL support, we need + # to forcibly override the cached values for these. + SET(ARCHIVE_ACL_DARWIN FALSE) + SET(ARCHIVE_ACL_FREEBSD FALSE) + SET(ARCHIVE_ACL_FREEBSD_NFS4 FALSE) + SET(ARCHIVE_ACL_LIBACL FALSE) + SET(ARCHIVE_ACL_SUNOS FALSE) + SET(ARCHIVE_ACL_SUNOS_NFS4 FALSE) +ENDIF(ENABLE_ACL) + +# +# Check MD5/RMD160/SHA support +# NOTE: Crypto checks must be run last before generating config.h +# +CHECK_CRYPTO("MD5;RMD160;SHA1;SHA256;SHA384;SHA512" LIBC) +CHECK_CRYPTO("SHA256;SHA384;SHA512" LIBC2) +CHECK_CRYPTO("SHA256;SHA384;SHA512" LIBC3) +CHECK_CRYPTO("MD5;SHA1;SHA256;SHA384;SHA512" LIBSYSTEM) +CHECK_CRYPTO("MD5;RMD160;SHA1;SHA256;SHA384;SHA512" NETTLE) +CHECK_CRYPTO("MD5;RMD160;SHA1;SHA256;SHA384;SHA512" OPENSSL) + +# Libmd has to be probed after OpenSSL. +CHECK_CRYPTO("MD5;RMD160;SHA1;SHA256;SHA512" LIBMD) + +CHECK_CRYPTO_WIN("MD5;SHA1;SHA256;SHA384;SHA512") + +# Generate "config.h" from "build/cmake/config.h.in" +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/build/cmake/config.h.in + ${CMAKE_CURRENT_BINARY_DIR}/config.h) +INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_BINARY_DIR}) +ADD_DEFINITIONS(-DHAVE_CONFIG_H) + +# +# Register installation of PDF documents. +# +IF(WIN32 AND NOT CYGWIN) + # + # On Windows platform, It's better that we install PDF documents + # on one's computer. + # These PDF documents are available in the release package. + # + IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/doc/pdf) + INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/doc/pdf + DESTINATION share/man + FILES_MATCHING PATTERN "*.pdf" + ) + ENDIF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/doc/pdf) +ENDIF(WIN32 AND NOT CYGWIN) +# +# +# +INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/libarchive) +# +IF(MSVC) + ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE) +ENDIF(MSVC) + +# We need CoreServices on Mac OS. +IF(APPLE) + LIST(APPEND ADDITIONAL_LIBS "-framework CoreServices") +ENDIF(APPLE) + +add_subdirectory(libarchive) + +install(FILES COPYING DESTINATION ${CMAKE_DOC_DIR}/cmlibarchive) diff --cc Utilities/cmlibarchive/build/cmake/config.h.in index 368a451,0000000..1851d81 mode 100644,000000..100644 --- a/Utilities/cmlibarchive/build/cmake/config.h.in +++ b/Utilities/cmlibarchive/build/cmake/config.h.in @@@ -1,1319 -1,0 +1,1329 @@@ +/* config.h. Generated from build/cmake/config.h.in by cmake configure */ +#if defined(__osf__) +# define _OSF_SOURCE +#endif + +/* + * Ensure we have C99-style int64_t, etc, all defined. + */ + +/* First, we need to know if the system has already defined them. */ +#cmakedefine HAVE_INT16_T +#cmakedefine HAVE_INT32_T +#cmakedefine HAVE_INT64_T +#cmakedefine HAVE_INTMAX_T + +#cmakedefine HAVE_UINT8_T +#cmakedefine HAVE_UINT16_T +#cmakedefine HAVE_UINT32_T +#cmakedefine HAVE_UINT64_T +#cmakedefine HAVE_UINTMAX_T + +/* We might have the types we want under other spellings. */ +#cmakedefine HAVE___INT64 +#cmakedefine HAVE_U_INT64_T +#cmakedefine HAVE_UNSIGNED___INT64 + +/* The sizes of various standard integer types. */ + at SIZE_OF_SHORT_CODE@ + at SIZE_OF_INT_CODE@ + at SIZE_OF_LONG_CODE@ + at SIZE_OF_LONG_LONG_CODE@ + at SIZE_OF_UNSIGNED_SHORT_CODE@ + at SIZE_OF_UNSIGNED_CODE@ + at SIZE_OF_UNSIGNED_LONG_CODE@ + at SIZE_OF_UNSIGNED_LONG_LONG_CODE@ + +/* + * If we lack int64_t, define it to the first of __int64, int, long, and long long + * that exists and is the right size. + */ +#if !defined(HAVE_INT64_T) && defined(HAVE___INT64) +typedef __int64 int64_t; +#define HAVE_INT64_T +#endif + +#if !defined(HAVE_INT64_T) && SIZE_OF_INT == 8 +typedef int int64_t; +#define HAVE_INT64_T +#endif + +#if !defined(HAVE_INT64_T) && SIZE_OF_LONG == 8 +typedef long int64_t; +#define HAVE_INT64_T +#endif + +#if !defined(HAVE_INT64_T) && SIZE_OF_LONG_LONG == 8 +typedef long long int64_t; +#define HAVE_INT64_T +#endif + +#if !defined(HAVE_INT64_T) +#error No 64-bit integer type was found. +#endif + +/* + * Similarly for int32_t + */ +#if !defined(HAVE_INT32_T) && SIZE_OF_INT == 4 +typedef int int32_t; +#define HAVE_INT32_T +#endif + +#if !defined(HAVE_INT32_T) && SIZE_OF_LONG == 4 +typedef long int32_t; +#define HAVE_INT32_T +#endif + +#if !defined(HAVE_INT32_T) +#error No 32-bit integer type was found. +#endif + +/* + * Similarly for int16_t + */ +#if !defined(HAVE_INT16_T) && SIZE_OF_INT == 2 +typedef int int16_t; +#define HAVE_INT16_T +#endif + +#if !defined(HAVE_INT16_T) && SIZE_OF_SHORT == 2 +typedef short int16_t; +#define HAVE_INT16_T +#endif + +#if !defined(HAVE_INT16_T) +#error No 16-bit integer type was found. +#endif + +/* + * Similarly for uint64_t + */ +#if !defined(HAVE_UINT64_T) && defined(HAVE_UNSIGNED___INT64) +typedef unsigned __int64 uint64_t; +#define HAVE_UINT64_T +#endif + +#if !defined(HAVE_UINT64_T) && SIZE_OF_UNSIGNED == 8 +typedef unsigned uint64_t; +#define HAVE_UINT64_T +#endif + +#if !defined(HAVE_UINT64_T) && SIZE_OF_UNSIGNED_LONG == 8 +typedef unsigned long uint64_t; +#define HAVE_UINT64_T +#endif + +#if !defined(HAVE_UINT64_T) && SIZE_OF_UNSIGNED_LONG_LONG == 8 +typedef unsigned long long uint64_t; +#define HAVE_UINT64_T +#endif + +#if !defined(HAVE_UINT64_T) +#error No 64-bit unsigned integer type was found. +#endif + + +/* + * Similarly for uint32_t + */ +#if !defined(HAVE_UINT32_T) && SIZE_OF_UNSIGNED == 4 +typedef unsigned uint32_t; +#define HAVE_UINT32_T +#endif + +#if !defined(HAVE_UINT32_T) && SIZE_OF_UNSIGNED_LONG == 4 +typedef unsigned long uint32_t; +#define HAVE_UINT32_T +#endif + +#if !defined(HAVE_UINT32_T) +#error No 32-bit unsigned integer type was found. +#endif + +/* + * Similarly for uint16_t + */ +#if !defined(HAVE_UINT16_T) && SIZE_OF_UNSIGNED == 2 +typedef unsigned uint16_t; +#define HAVE_UINT16_T +#endif + +#if !defined(HAVE_UINT16_T) && SIZE_OF_UNSIGNED_SHORT == 2 +typedef unsigned short uint16_t; +#define HAVE_UINT16_T +#endif + +#if !defined(HAVE_UINT16_T) +#error No 16-bit unsigned integer type was found. +#endif + +/* + * Similarly for uint8_t + */ +#if !defined(HAVE_UINT8_T) +typedef unsigned char uint8_t; +#define HAVE_UINT8_T +#endif + +#if !defined(HAVE_UINT16_T) +#error No 8-bit unsigned integer type was found. +#endif + +/* Define intmax_t and uintmax_t if they are not already defined. */ +#if !defined(HAVE_INTMAX_T) +typedef int64_t intmax_t; +#endif + +#if !defined(HAVE_UINTMAX_T) +typedef uint64_t uintmax_t; +#endif + +/* Define ZLIB_WINAPI if zlib was built on Visual Studio. */ +#cmakedefine ZLIB_WINAPI 1 + +/* Darwin ACL support */ +#cmakedefine ARCHIVE_ACL_DARWIN 1 + +/* FreeBSD ACL support */ +#cmakedefine ARCHIVE_ACL_FREEBSD 1 + +/* FreeBSD NFSv4 ACL support */ +#cmakedefine ARCHIVE_ACL_FREEBSD_NFS4 1 + +/* Linux POSIX.1e ACL support via libacl */ +#cmakedefine ARCHIVE_ACL_LIBACL 1 + +/* Linux NFSv4 ACL support via librichacl */ +#cmakedefine ARCHIVE_ACL_LIBRICHACL 1 + +/* Solaris ACL support */ +#cmakedefine ARCHIVE_ACL_SUNOS 1 + +/* Solaris NFSv4 ACL support */ +#cmakedefine ARCHIVE_ACL_SUNOS_NFS4 1 + +/* MD5 via ARCHIVE_CRYPTO_MD5_LIBC supported. */ +#cmakedefine ARCHIVE_CRYPTO_MD5_LIBC 1 + +/* MD5 via ARCHIVE_CRYPTO_MD5_LIBSYSTEM supported. */ +#cmakedefine ARCHIVE_CRYPTO_MD5_LIBSYSTEM 1 + +/* MD5 via ARCHIVE_CRYPTO_MD5_NETTLE supported. */ +#cmakedefine ARCHIVE_CRYPTO_MD5_NETTLE 1 + +/* MD5 via ARCHIVE_CRYPTO_MD5_OPENSSL supported. */ +#cmakedefine ARCHIVE_CRYPTO_MD5_OPENSSL 1 + +/* MD5 via ARCHIVE_CRYPTO_MD5_WIN supported. */ +#cmakedefine ARCHIVE_CRYPTO_MD5_WIN 1 + +/* RMD160 via ARCHIVE_CRYPTO_RMD160_LIBC supported. */ +#cmakedefine ARCHIVE_CRYPTO_RMD160_LIBC 1 + +/* RMD160 via ARCHIVE_CRYPTO_RMD160_NETTLE supported. */ +#cmakedefine ARCHIVE_CRYPTO_RMD160_NETTLE 1 + +/* RMD160 via ARCHIVE_CRYPTO_RMD160_OPENSSL supported. */ +#cmakedefine ARCHIVE_CRYPTO_RMD160_OPENSSL 1 + +/* SHA1 via ARCHIVE_CRYPTO_SHA1_LIBC supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA1_LIBC 1 + +/* SHA1 via ARCHIVE_CRYPTO_SHA1_LIBSYSTEM supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA1_LIBSYSTEM 1 + +/* SHA1 via ARCHIVE_CRYPTO_SHA1_NETTLE supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA1_NETTLE 1 + +/* SHA1 via ARCHIVE_CRYPTO_SHA1_OPENSSL supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA1_OPENSSL 1 + +/* SHA1 via ARCHIVE_CRYPTO_SHA1_WIN supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA1_WIN 1 + +/* SHA256 via ARCHIVE_CRYPTO_SHA256_LIBC supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA256_LIBC 1 + +/* SHA256 via ARCHIVE_CRYPTO_SHA256_LIBC2 supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA256_LIBC2 1 + +/* SHA256 via ARCHIVE_CRYPTO_SHA256_LIBC3 supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA256_LIBC3 1 + +/* SHA256 via ARCHIVE_CRYPTO_SHA256_LIBSYSTEM supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA256_LIBSYSTEM 1 + +/* SHA256 via ARCHIVE_CRYPTO_SHA256_NETTLE supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA256_NETTLE 1 + +/* SHA256 via ARCHIVE_CRYPTO_SHA256_OPENSSL supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA256_OPENSSL 1 + +/* SHA256 via ARCHIVE_CRYPTO_SHA256_WIN supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA256_WIN 1 + +/* SHA384 via ARCHIVE_CRYPTO_SHA384_LIBC supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA384_LIBC 1 + +/* SHA384 via ARCHIVE_CRYPTO_SHA384_LIBC2 supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA384_LIBC2 1 + +/* SHA384 via ARCHIVE_CRYPTO_SHA384_LIBC3 supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA384_LIBC3 1 + +/* SHA384 via ARCHIVE_CRYPTO_SHA384_LIBSYSTEM supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA384_LIBSYSTEM 1 + +/* SHA384 via ARCHIVE_CRYPTO_SHA384_NETTLE supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA384_NETTLE 1 + +/* SHA384 via ARCHIVE_CRYPTO_SHA384_OPENSSL supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA384_OPENSSL 1 + +/* SHA384 via ARCHIVE_CRYPTO_SHA384_WIN supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA384_WIN 1 + +/* SHA512 via ARCHIVE_CRYPTO_SHA512_LIBC supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA512_LIBC 1 + +/* SHA512 via ARCHIVE_CRYPTO_SHA512_LIBC2 supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA512_LIBC2 1 + +/* SHA512 via ARCHIVE_CRYPTO_SHA512_LIBC3 supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA512_LIBC3 1 + +/* SHA512 via ARCHIVE_CRYPTO_SHA512_LIBSYSTEM supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA512_LIBSYSTEM 1 + +/* SHA512 via ARCHIVE_CRYPTO_SHA512_NETTLE supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA512_NETTLE 1 + +/* SHA512 via ARCHIVE_CRYPTO_SHA512_OPENSSL supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA512_OPENSSL 1 + +/* SHA512 via ARCHIVE_CRYPTO_SHA512_WIN supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA512_WIN 1 + +/* AIX xattr support */ +#cmakedefine ARCHIVE_XATTR_AIX 1 + +/* Darwin xattr support */ +#cmakedefine ARCHIVE_XATTR_DARWIN 1 + +/* FreeBSD xattr support */ +#cmakedefine ARCHIVE_XATTR_FREEBSD 1 + +/* Linux xattr support */ +#cmakedefine ARCHIVE_XATTR_LINUX 1 + +/* Version number of bsdcpio */ +#cmakedefine BSDCPIO_VERSION_STRING "${BSDCPIO_VERSION_STRING}" + +/* Version number of bsdtar */ +#cmakedefine BSDTAR_VERSION_STRING "${BSDTAR_VERSION_STRING}" + +/* Version number of bsdcat */ +#cmakedefine BSDCAT_VERSION_STRING "${BSDCAT_VERSION_STRING}" + +/* Define to 1 if you have the `acl_create_entry' function. */ +#cmakedefine HAVE_ACL_CREATE_ENTRY 1 + +/* Define to 1 if you have the `acl_get_fd_np' function. */ +#cmakedefine HAVE_ACL_GET_FD_NP 1 + +/* Define to 1 if you have the `acl_get_link' function. */ +#cmakedefine HAVE_ACL_GET_LINK 1 + +/* Define to 1 if you have the `acl_get_link_np' function. */ +#cmakedefine HAVE_ACL_GET_LINK_NP 1 + +/* Define to 1 if you have the `acl_get_perm' function. */ +#cmakedefine HAVE_ACL_GET_PERM 1 + +/* Define to 1 if you have the `acl_get_perm_np' function. */ +#cmakedefine HAVE_ACL_GET_PERM_NP 1 + +/* Define to 1 if you have the `acl_init' function. */ +#cmakedefine HAVE_ACL_INIT 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_ACL_LIBACL_H 1 + +/* Define to 1 if the system has the type `acl_permset_t'. */ +#cmakedefine HAVE_ACL_PERMSET_T 1 + +/* Define to 1 if you have the `acl_set_fd' function. */ +#cmakedefine HAVE_ACL_SET_FD 1 + +/* Define to 1 if you have the `acl_set_fd_np' function. */ +#cmakedefine HAVE_ACL_SET_FD_NP 1 + +/* Define to 1 if you have the `acl_set_file' function. */ +#cmakedefine HAVE_ACL_SET_FILE 1 + +/* Define to 1 if you have the `arc4random_buf' function. */ +#cmakedefine HAVE_ARC4RANDOM_BUF 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_ATTR_XATTR_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_BCRYPT_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_BSDXML_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_BZLIB_H 1 + +/* Define to 1 if you have the `chflags' function. */ +#cmakedefine HAVE_CHFLAGS 1 + +/* Define to 1 if you have the `chown' function. */ +#cmakedefine HAVE_CHOWN 1 + +/* Define to 1 if you have the `chroot' function. */ +#cmakedefine HAVE_CHROOT 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_COPYFILE_H 1 + +/* Define to 1 if you have the `ctime_r' function. */ +#cmakedefine HAVE_CTIME_R 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_CTYPE_H 1 + +/* Define to 1 if you have the `cygwin_conv_path' function. */ +#cmakedefine HAVE_CYGWIN_CONV_PATH 1 + +/* Define to 1 if you have the declaration of `ACE_GETACL', and to 0 if you + don't. */ +#cmakedefine HAVE_DECL_ACE_GETACL 1 + +/* Define to 1 if you have the declaration of `ACE_GETACLCNT', and to 0 if you + don't. */ +#cmakedefine HAVE_DECL_ACE_GETACLCNT 1 + +/* Define to 1 if you have the declaration of `ACE_SETACL', and to 0 if you + don't. */ +#cmakedefine HAVE_DECL_ACE_SETACL 1 + +/* Define to 1 if you have the declaration of `ACL_SYNCHRONIZE', and to 0 if + you don't. */ +#cmakedefine HAVE_DECL_ACL_SYNCHRONIZE 1 + +/* Define to 1 if you have the declaration of `ACL_TYPE_EXTENDED', and to 0 if + you don't. */ +#cmakedefine HAVE_DECL_ACL_TYPE_EXTENDED 1 + +/* Define to 1 if you have the declaration of `ACL_TYPE_NFS4', and to 0 if you + don't. */ +#cmakedefine HAVE_DECL_ACL_TYPE_NFS4 1 + +/* Define to 1 if you have the declaration of `ACL_USER', and to 0 if you + don't. */ +#cmakedefine HAVE_DECL_ACL_USER 1 + +/* Define to 1 if you have the declaration of `INT32_MAX', and to 0 if you + don't. */ +#cmakedefine HAVE_DECL_INT32_MAX 1 + +/* Define to 1 if you have the declaration of `INT32_MIN', and to 0 if you + don't. */ +#cmakedefine HAVE_DECL_INT32_MIN 1 + +/* Define to 1 if you have the declaration of `INT64_MAX', and to 0 if you + don't. */ +#cmakedefine HAVE_DECL_INT64_MAX 1 + +/* Define to 1 if you have the declaration of `INT64_MIN', and to 0 if you + don't. */ +#cmakedefine HAVE_DECL_INT64_MIN 1 + +/* Define to 1 if you have the declaration of `INTMAX_MAX', and to 0 if you + don't. */ +#cmakedefine HAVE_DECL_INTMAX_MAX 1 + +/* Define to 1 if you have the declaration of `INTMAX_MIN', and to 0 if you + don't. */ +#cmakedefine HAVE_DECL_INTMAX_MIN 1 + +/* Define to 1 if you have the declaration of `SETACL', and to 0 if you don't. + */ +#cmakedefine HAVE_DECL_SETACL 1 + +/* Define to 1 if you have the declaration of `SIZE_MAX', and to 0 if you + don't. */ +#cmakedefine HAVE_DECL_SIZE_MAX 1 + +/* Define to 1 if you have the declaration of `SSIZE_MAX', and to 0 if you + don't. */ +#cmakedefine HAVE_DECL_SSIZE_MAX 1 + +/* Define to 1 if you have the declaration of `strerror_r', and to 0 if you + don't. */ +#cmakedefine HAVE_DECL_STRERROR_R 1 + +/* Define to 1 if you have the declaration of `UINT32_MAX', and to 0 if you + don't. */ +#cmakedefine HAVE_DECL_UINT32_MAX 1 + +/* Define to 1 if you have the declaration of `UINT64_MAX', and to 0 if you + don't. */ +#cmakedefine HAVE_DECL_UINT64_MAX 1 + +/* Define to 1 if you have the declaration of `UINTMAX_MAX', and to 0 if you + don't. */ +#cmakedefine HAVE_DECL_UINTMAX_MAX 1 + +/* Define to 1 if you have the declaration of `XATTR_NOFOLLOW', and to 0 if + you don't. */ +#cmakedefine HAVE_DECL_XATTR_NOFOLLOW 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_DIRECT_H 1 + +/* Define to 1 if you have the header file, and it defines `DIR'. + */ +#cmakedefine HAVE_DIRENT_H 1 + +/* Define to 1 if you have the `dirfd' function. */ +#cmakedefine HAVE_DIRFD 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_DLFCN_H 1 + +/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */ +#cmakedefine HAVE_DOPRNT 1 + +/* Define to 1 if nl_langinfo supports D_MD_ORDER */ +#cmakedefine HAVE_D_MD_ORDER 1 + +/* A possible errno value for invalid file format errors */ +#cmakedefine HAVE_EFTYPE 1 + +/* A possible errno value for invalid file format errors */ +#cmakedefine HAVE_EILSEQ 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_ERRNO_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_EXPAT_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_EXT2FS_EXT2_FS_H 1 + +/* Define to 1 if you have the `extattr_get_file' function. */ +#cmakedefine HAVE_EXTATTR_GET_FILE 1 + +/* Define to 1 if you have the `extattr_list_file' function. */ +#cmakedefine HAVE_EXTATTR_LIST_FILE 1 + +/* Define to 1 if you have the `extattr_set_fd' function. */ +#cmakedefine HAVE_EXTATTR_SET_FD 1 + +/* Define to 1 if you have the `extattr_set_file' function. */ +#cmakedefine HAVE_EXTATTR_SET_FILE 1 + +/* Define to 1 if EXTATTR_NAMESPACE_USER is defined in sys/extattr.h. */ +#cmakedefine HAVE_DECL_EXTATTR_NAMESPACE_USER 1 + +/* Define to 1 if you have the declaration of `GETACL', and to 0 if you don't. + */ +#cmakedefine HAVE_DECL_GETACL 1 + +/* Define to 1 if you have the declaration of `GETACLCNT', and to 0 if you + don't. */ +#cmakedefine HAVE_DECL_GETACLCNT 1 + +/* Define to 1 if you have the `fchdir' function. */ +#cmakedefine HAVE_FCHDIR 1 + +/* Define to 1 if you have the `fchflags' function. */ +#cmakedefine HAVE_FCHFLAGS 1 + +/* Define to 1 if you have the `fchmod' function. */ +#cmakedefine HAVE_FCHMOD 1 + +/* Define to 1 if you have the `fchown' function. */ +#cmakedefine HAVE_FCHOWN 1 + +/* Define to 1 if you have the `fcntl' function. */ +#cmakedefine HAVE_FCNTL 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_FCNTL_H 1 + +/* Define to 1 if you have the `fdopendir' function. */ +#cmakedefine HAVE_FDOPENDIR 1 + +/* Define to 1 if you have the `fgetea' function. */ +#cmakedefine HAVE_FGETEA 1 + +/* Define to 1 if you have the `fgetxattr' function. */ +#cmakedefine HAVE_FGETXATTR 1 + +/* Define to 1 if you have the `flistea' function. */ +#cmakedefine HAVE_FLISTEA 1 + +/* Define to 1 if you have the `flistxattr' function. */ +#cmakedefine HAVE_FLISTXATTR 1 + +/* Define to 1 if you have the `fork' function. */ +#cmakedefine HAVE_FORK 1 + +/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */ +#cmakedefine HAVE_FSEEKO 1 + +/* Define to 1 if you have the `fsetea' function. */ +#cmakedefine HAVE_FSETEA 1 + +/* Define to 1 if you have the `fsetxattr' function. */ +#cmakedefine HAVE_FSETXATTR 1 + +/* Define to 1 if you have the `fstat' function. */ +#cmakedefine HAVE_FSTAT 1 + +/* Define to 1 if you have the `fstatat' function. */ +#cmakedefine HAVE_FSTATAT 1 + +/* Define to 1 if you have the `fstatfs' function. */ +#cmakedefine HAVE_FSTATFS 1 + +/* Define to 1 if you have the `fstatvfs' function. */ +#cmakedefine HAVE_FSTATVFS 1 + +/* Define to 1 if you have the `ftruncate' function. */ +#cmakedefine HAVE_FTRUNCATE 1 + +/* Define to 1 if you have the `futimens' function. */ +#cmakedefine HAVE_FUTIMENS 1 + +/* Define to 1 if you have the `futimes' function. */ +#cmakedefine HAVE_FUTIMES 1 + +/* Define to 1 if you have the `futimesat' function. */ +#cmakedefine HAVE_FUTIMESAT 1 + +/* Define to 1 if you have the `getea' function. */ +#cmakedefine HAVE_GETEA 1 + +/* Define to 1 if you have the `geteuid' function. */ +#cmakedefine HAVE_GETEUID 1 + +/* Define to 1 if you have the `getgrgid_r' function. */ +#cmakedefine HAVE_GETGRGID_R 1 + +/* Define to 1 if you have the `getgrnam_r' function. */ +#cmakedefine HAVE_GETGRNAM_R 1 + +/* Define to 1 if you have the `getpid' function. */ +#cmakedefine HAVE_GETPID 1 + +/* Define to 1 if you have the `getpwnam_r' function. */ +#cmakedefine HAVE_GETPWNAM_R 1 + +/* Define to 1 if you have the `getpwuid_r' function. */ +#cmakedefine HAVE_GETPWUID_R 1 + +/* Define to 1 if you have the `getvfsbyname' function. */ +#cmakedefine HAVE_GETVFSBYNAME 1 + +/* Define to 1 if you have the `getxattr' function. */ +#cmakedefine HAVE_GETXATTR 1 + +/* Define to 1 if you have the `gmtime_r' function. */ +#cmakedefine HAVE_GMTIME_R 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_GRP_H 1 + +/* Define to 1 if you have the `iconv' function. */ +#cmakedefine HAVE_ICONV 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_ICONV_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_IO_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LANGINFO_H 1 + +/* Define to 1 if you have the `lchflags' function. */ +#cmakedefine HAVE_LCHFLAGS 1 + +/* Define to 1 if you have the `lchmod' function. */ +#cmakedefine HAVE_LCHMOD 1 + +/* Define to 1 if you have the `lchown' function. */ +#cmakedefine HAVE_LCHOWN 1 + +/* Define to 1 if you have the `lgetea' function. */ +#cmakedefine HAVE_LGETEA 1 + +/* Define to 1 if you have the `lgetxattr' function. */ +#cmakedefine HAVE_LGETXATTR 1 + +/* Define to 1 if you have the `acl' library (-lacl). */ +#cmakedefine HAVE_LIBACL 1 + +/* Define to 1 if you have the `attr' library (-lattr). */ +#cmakedefine HAVE_LIBATTR 1 + +/* Define to 1 if you have the `bsdxml' library (-lbsdxml). */ +#cmakedefine HAVE_LIBBSDXML 1 + +/* Define to 1 if you have the `bz2' library (-lbz2). */ +#cmakedefine HAVE_LIBBZ2 1 + +/* Define to 1 if you have the `charset' library (-lcharset). */ +#cmakedefine HAVE_LIBCHARSET 1 + +/* Define to 1 if you have the `crypto' library (-lcrypto). */ +#cmakedefine HAVE_LIBCRYPTO 1 + +/* Define to 1 if you have the `expat' library (-lexpat). */ +#cmakedefine HAVE_LIBEXPAT 1 + +/* Define to 1 if you have the `gcc' library (-lgcc). */ +#cmakedefine HAVE_LIBGCC 1 + +/* Define to 1 if you have the `lz4' library (-llz4). */ +#cmakedefine HAVE_LIBLZ4 1 + +/* Define to 1 if you have the `lzma' library (-llzma). */ +#cmakedefine HAVE_LIBLZMA 1 + +/* Define to 1 if you have the `lzmadec' library (-llzmadec). */ +#cmakedefine HAVE_LIBLZMADEC 1 + +/* Define to 1 if you have the `lzo2' library (-llzo2). */ +#cmakedefine HAVE_LIBLZO2 1 + +/* Define to 1 if you have the `nettle' library (-lnettle). */ +#cmakedefine HAVE_LIBNETTLE 1 + +/* Define to 1 if you have the `pcre' library (-lpcre). */ +#cmakedefine HAVE_LIBPCRE 1 + +/* Define to 1 if you have the `pcreposix' library (-lpcreposix). */ +#cmakedefine HAVE_LIBPCREPOSIX 1 + +/* Define to 1 if you have the `xml2' library (-lxml2). */ +#cmakedefine HAVE_LIBXML2 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LIBXML_XMLREADER_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LIBXML_XMLWRITER_H 1 + +/* Define to 1 if you have the `z' library (-lz). */ +#cmakedefine HAVE_LIBZ 1 + ++/* Define to 1 if you have the `zstd' library (-lzstd). */ ++#cmakedefine HAVE_LIBZSTD 1 ++ +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LIMITS_H 1 + +/* Define to 1 if you have the `link' function. */ +#cmakedefine HAVE_LINK 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LINUX_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LINUX_FIEMAP_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LINUX_FS_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LINUX_MAGIC_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LINUX_TYPES_H 1 + +/* Define to 1 if you have the `listea' function. */ +#cmakedefine HAVE_LISTEA 1 + +/* Define to 1 if you have the `listxattr' function. */ +#cmakedefine HAVE_LISTXATTR 1 + +/* Define to 1 if you have the `llistea' function. */ +#cmakedefine HAVE_LLISTEA 1 + +/* Define to 1 if you have the `llistxattr' function. */ +#cmakedefine HAVE_LLISTXATTR 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LOCALCHARSET_H 1 + +/* Define to 1 if you have the `locale_charset' function. */ +#cmakedefine HAVE_LOCALE_CHARSET 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LOCALE_H 1 + +/* Define to 1 if you have the `localtime_r' function. */ +#cmakedefine HAVE_LOCALTIME_R 1 + +/* Define to 1 if the system has the type `long long int'. */ +#cmakedefine HAVE_LONG_LONG_INT 1 + +/* Define to 1 if you have the `lsetea' function. */ +#cmakedefine HAVE_LSETEA 1 + +/* Define to 1 if you have the `lsetxattr' function. */ +#cmakedefine HAVE_LSETXATTR 1 + +/* Define to 1 if you have the `lstat' function. */ +#cmakedefine HAVE_LSTAT 1 + +/* Define to 1 if `lstat' has the bug that it succeeds when given the + zero-length file name argument. */ +#cmakedefine HAVE_LSTAT_EMPTY_STRING_BUG 1 + +/* Define to 1 if you have the `lutimes' function. */ +#cmakedefine HAVE_LUTIMES 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LZ4HC_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LZ4_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LZMADEC_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LZMA_H 1 + +/* Define to 1 if you have a working `lzma_stream_encoder_mt' function. */ +#cmakedefine HAVE_LZMA_STREAM_ENCODER_MT 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LZO_LZO1X_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LZO_LZOCONF_H 1 + +/* Define to 1 if you have the `mbrtowc' function. */ +#cmakedefine HAVE_MBRTOWC 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_MEMBERSHIP_H 1 + +/* Define to 1 if you have the `memmove' function. */ +#cmakedefine HAVE_MEMMOVE 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_MEMORY_H 1 + +/* Define to 1 if you have the `mkdir' function. */ +#cmakedefine HAVE_MKDIR 1 + +/* Define to 1 if you have the `mkfifo' function. */ +#cmakedefine HAVE_MKFIFO 1 + +/* Define to 1 if you have the `mknod' function. */ +#cmakedefine HAVE_MKNOD 1 + +/* Define to 1 if you have the `mkstemp' function. */ +#cmakedefine HAVE_MKSTEMP 1 + +/* Define to 1 if you have the header file, and it defines `DIR'. */ +#cmakedefine HAVE_NDIR_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_NETTLE_AES_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_NETTLE_HMAC_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_NETTLE_MD5_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_NETTLE_PBKDF2_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_NETTLE_RIPEMD160_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_NETTLE_SHA_H 1 + +/* Define to 1 if you have the `nl_langinfo' function. */ +#cmakedefine HAVE_NL_LANGINFO 1 + +/* Define to 1 if you have the `openat' function. */ +#cmakedefine HAVE_OPENAT 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_PATHS_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_PCREPOSIX_H 1 + +/* Define to 1 if you have the `pipe' function. */ +#cmakedefine HAVE_PIPE 1 + +/* Define to 1 if you have the `PKCS5_PBKDF2_HMAC_SHA1' function. */ +#cmakedefine HAVE_PKCS5_PBKDF2_HMAC_SHA1 1 + +/* Define to 1 if you have the `poll' function. */ +#cmakedefine HAVE_POLL 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_POLL_H 1 + +/* Define to 1 if you have the `posix_spawnp' function. */ +#cmakedefine HAVE_POSIX_SPAWNP 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_PROCESS_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_PTHREAD_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_PWD_H 1 + +/* Define to 1 if you have the `readdir_r' function. */ +#cmakedefine HAVE_READDIR_R 1 + +/* Define to 1 if you have the `readlink' function. */ +#cmakedefine HAVE_READLINK 1 + +/* Define to 1 if you have the `readlinkat' function. */ +#cmakedefine HAVE_READLINKAT 1 + +/* Define to 1 if you have the `readpassphrase' function. */ +#cmakedefine HAVE_READPASSPHRASE 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_READPASSPHRASE_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_REGEX_H 1 + +/* Define to 1 if you have the `select' function. */ +#cmakedefine HAVE_SELECT 1 + +/* Define to 1 if you have the `setenv' function. */ +#cmakedefine HAVE_SETENV 1 + +/* Define to 1 if you have the `setlocale' function. */ +#cmakedefine HAVE_SETLOCALE 1 + +/* Define to 1 if you have the `sigaction' function. */ +#cmakedefine HAVE_SIGACTION 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SIGNAL_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SPAWN_H 1 + +/* Define to 1 if you have the `statfs' function. */ +#cmakedefine HAVE_STATFS 1 + +/* Define to 1 if you have the `statvfs' function. */ +#cmakedefine HAVE_STATVFS 1 + +/* Define to 1 if `stat' has the bug that it succeeds when given the + zero-length file name argument. */ +#cmakedefine HAVE_STAT_EMPTY_STRING_BUG 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDARG_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDLIB_H 1 + +/* Define to 1 if you have the `strchr' function. */ +#cmakedefine HAVE_STRCHR 1 + +/* Define to 1 if you have the `strdup' function. */ +#cmakedefine HAVE_STRDUP 1 + +/* Define to 1 if you have the `strerror' function. */ +#cmakedefine HAVE_STRERROR 1 + +/* Define to 1 if you have the `strerror_r' function. */ +#cmakedefine HAVE_STRERROR_R 1 + +/* Define to 1 if you have the `strftime' function. */ +#cmakedefine HAVE_STRFTIME 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STRING_H 1 + +/* Define to 1 if you have the `strrchr' function. */ +#cmakedefine HAVE_STRRCHR 1 + +/* Define to 1 if `f_namemax' is a member of `struct statfs'. */ +#cmakedefine HAVE_STRUCT_STATFS_F_NAMEMAX 1 + +/* Define to 1 if `f_iosize' is a member of `struct statvfs'. */ +#cmakedefine HAVE_STRUCT_STATVFS_F_IOSIZE 1 + +/* Define to 1 if `st_birthtime' is a member of `struct stat'. */ +#cmakedefine HAVE_STRUCT_STAT_ST_BIRTHTIME 1 + +/* Define to 1 if `st_birthtimespec.tv_nsec' is a member of `struct stat'. */ +#cmakedefine HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC 1 + +/* Define to 1 if `st_blksize' is a member of `struct stat'. */ +#cmakedefine HAVE_STRUCT_STAT_ST_BLKSIZE 1 + +/* Define to 1 if `st_flags' is a member of `struct stat'. */ +#cmakedefine HAVE_STRUCT_STAT_ST_FLAGS 1 + +/* Define to 1 if `st_mtimespec.tv_nsec' is a member of `struct stat'. */ +#cmakedefine HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC 1 + +/* Define to 1 if `st_mtime_n' is a member of `struct stat'. */ +#cmakedefine HAVE_STRUCT_STAT_ST_MTIME_N 1 + +/* Define to 1 if `st_mtime_usec' is a member of `struct stat'. */ +#cmakedefine HAVE_STRUCT_STAT_ST_MTIME_USEC 1 + +/* Define to 1 if `st_mtim.tv_nsec' is a member of `struct stat'. */ +#cmakedefine HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC 1 + +/* Define to 1 if `st_umtime' is a member of `struct stat'. */ +#cmakedefine HAVE_STRUCT_STAT_ST_UMTIME 1 + +/* Define to 1 if `tm_gmtoff' is a member of `struct tm'. */ +#cmakedefine HAVE_STRUCT_TM_TM_GMTOFF 1 + +/* Define to 1 if `__tm_gmtoff' is a member of `struct tm'. */ +#cmakedefine HAVE_STRUCT_TM___TM_GMTOFF 1 + +/* Define to 1 if you have `struct vfsconf'. */ +#cmakedefine HAVE_STRUCT_VFSCONF 1 + +/* Define to 1 if you have `struct xvfsconf'. */ +#cmakedefine HAVE_STRUCT_XVFSCONF 1 + +/* Define to 1 if you have the `symlink' function. */ +#cmakedefine HAVE_SYMLINK 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_ACL_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_CDEFS_H 1 + +/* Define to 1 if you have the header file, and it defines `DIR'. + */ +#cmakedefine HAVE_SYS_DIR_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_EA_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_EXTATTR_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_IOCTL_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_MKDEV_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_MOUNT_H 1 + +/* Define to 1 if you have the header file, and it defines `DIR'. + */ +#cmakedefine HAVE_SYS_NDIR_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_PARAM_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_POLL_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_RICHACL_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_SELECT_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_STATFS_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_STATVFS_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_STAT_H 1 + ++ ++/* Define to 1 if you have the header file. */ ++#cmakedefine HAVE_SYS_SYSMACROS_H 1 ++ +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_UTIME_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_UTSNAME_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_VFS_H 1 + +/* Define to 1 if you have that is POSIX.1 compatible. */ +#cmakedefine HAVE_SYS_WAIT_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_XATTR_H 1 + +/* Define to 1 if you have the `timegm' function. */ +#cmakedefine HAVE_TIMEGM 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_TIME_H 1 + +/* Define to 1 if you have the `tzset' function. */ +#cmakedefine HAVE_TZSET 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_UNISTD_H 1 + +/* Define to 1 if you have the `unsetenv' function. */ +#cmakedefine HAVE_UNSETENV 1 + +/* Define to 1 if the system has the type `unsigned long long'. */ +#cmakedefine HAVE_UNSIGNED_LONG_LONG 1 + +/* Define to 1 if the system has the type `unsigned long long int'. */ +#cmakedefine HAVE_UNSIGNED_LONG_LONG_INT 1 + +/* Define to 1 if you have the `utime' function. */ +#cmakedefine HAVE_UTIME 1 + +/* Define to 1 if you have the `utimensat' function. */ +#cmakedefine HAVE_UTIMENSAT 1 + +/* Define to 1 if you have the `utimes' function. */ +#cmakedefine HAVE_UTIMES 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_UTIME_H 1 + +/* Define to 1 if you have the `vfork' function. */ +#cmakedefine HAVE_VFORK 1 + +/* Define to 1 if you have the `vprintf' function. */ +#cmakedefine HAVE_VPRINTF 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_WCHAR_H 1 + +/* Define to 1 if the system has the type `wchar_t'. */ +#cmakedefine HAVE_WCHAR_T 1 + +/* Define to 1 if you have the `wcrtomb' function. */ +#cmakedefine HAVE_WCRTOMB 1 + +/* Define to 1 if you have the `wcscmp' function. */ +#cmakedefine HAVE_WCSCMP 1 + +/* Define to 1 if you have the `wcscpy' function. */ +#cmakedefine HAVE_WCSCPY 1 + +/* Define to 1 if you have the `wcslen' function. */ +#cmakedefine HAVE_WCSLEN 1 + +/* Define to 1 if you have the `wctomb' function. */ +#cmakedefine HAVE_WCTOMB 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_WCTYPE_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_WINCRYPT_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_WINDOWS_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_WINIOCTL_H 1 + +/* Define to 1 if you have _CrtSetReportMode in */ +#cmakedefine HAVE__CrtSetReportMode 1 + +/* Define to 1 if you have the `wmemcmp' function. */ +#cmakedefine HAVE_WMEMCMP 1 + +/* Define to 1 if you have the `wmemcpy' function. */ +#cmakedefine HAVE_WMEMCPY 1 + +/* Define to 1 if you have the `wmemmove' function. */ +#cmakedefine HAVE_WMEMMOVE 1 + +/* Define to 1 if you have a working EXT2_IOC_GETFLAGS */ +#cmakedefine HAVE_WORKING_EXT2_IOC_GETFLAGS 1 + +/* Define to 1 if you have a working FS_IOC_GETFLAGS */ +#cmakedefine HAVE_WORKING_FS_IOC_GETFLAGS 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_ZLIB_H 1 + ++/* Define to 1 if you have the header file. */ ++#cmakedefine HAVE_ZSTD_H 1 ++ +/* Define to 1 if you have the `_ctime64_s' function. */ +#cmakedefine HAVE__CTIME64_S 1 + +/* Define to 1 if you have the `_fseeki64' function. */ +#cmakedefine HAVE__FSEEKI64 1 + +/* Define to 1 if you have the `_get_timezone' function. */ +#cmakedefine HAVE__GET_TIMEZONE 1 + +/* Define to 1 if you have the `_localtime64_s' function. */ +#cmakedefine HAVE__LOCALTIME64_S 1 + +/* Define to 1 if you have the `_mkgmtime64' function. */ +#cmakedefine HAVE__MKGMTIME64 1 + +/* Define as const if the declaration of iconv() needs const. */ +#define ICONV_CONST ${ICONV_CONST} + +/* Version number of libarchive as a single integer */ +#cmakedefine LIBARCHIVE_VERSION_NUMBER "${LIBARCHIVE_VERSION_NUMBER}" + +/* Version number of libarchive */ +#cmakedefine LIBARCHIVE_VERSION_STRING "${LIBARCHIVE_VERSION_STRING}" + +/* Define to 1 if `lstat' dereferences a symlink specified with a trailing + slash. */ +#cmakedefine LSTAT_FOLLOWS_SLASHED_SYMLINK 1 + +/* Define to 1 if `major', `minor', and `makedev' are declared in . + */ +#cmakedefine MAJOR_IN_MKDEV 1 + +/* Define to 1 if `major', `minor', and `makedev' are declared in + . */ +#cmakedefine MAJOR_IN_SYSMACROS 1 + +/* Define to 1 if your C compiler doesn't accept -c and -o together. */ +#cmakedefine NO_MINUS_C_MINUS_O 1 + +/* The size of `wchar_t', as computed by sizeof. */ +#cmakedefine SIZEOF_WCHAR_T ${SIZEOF_WCHAR_T} + +/* Define to 1 if strerror_r returns char *. */ +#cmakedefine STRERROR_R_CHAR_P 1 + +/* Define to 1 if you can safely include both and . */ +#cmakedefine TIME_WITH_SYS_TIME 1 + +/* + * Some platform requires a macro to use extension functions. + */ +#cmakedefine SAFE_TO_DEFINE_EXTENSIONS 1 +#ifdef SAFE_TO_DEFINE_EXTENSIONS +/* Enable extensions on AIX 3, Interix. */ +#ifndef _ALL_SOURCE +# define _ALL_SOURCE 1 +#endif +/* Enable GNU extensions on systems that have them. */ +#ifndef _GNU_SOURCE +# define _GNU_SOURCE 1 +#endif +/* Enable threading extensions on Solaris. */ +#ifndef _POSIX_PTHREAD_SEMANTICS +# define _POSIX_PTHREAD_SEMANTICS 1 +#endif +/* Enable extensions on HP NonStop. */ +#ifndef _TANDEM_SOURCE +# define _TANDEM_SOURCE 1 +#endif +/* Enable general extensions on Solaris. */ +#ifndef __EXTENSIONS__ +# define __EXTENSIONS__ 1 +#endif +#endif /* SAFE_TO_DEFINE_EXTENSIONS */ + +/* Version number of package */ +#cmakedefine VERSION "${VERSION}" + +/* Number of bits in a file offset, on hosts where this is settable. */ +#cmakedefine _FILE_OFFSET_BITS ${_FILE_OFFSET_BITS} + +/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */ +#cmakedefine _LARGEFILE_SOURCE 1 + +/* Define for large files, on AIX-style hosts. */ +#cmakedefine _LARGE_FILES ${_LARGE_FILES} + +/* Define to control Windows SDK version */ +#ifndef NTDDI_VERSION +#cmakedefine NTDDI_VERSION ${NTDDI_VERSION} +#endif // NTDDI_VERSION + +#ifndef _WIN32_WINNT +#cmakedefine _WIN32_WINNT ${_WIN32_WINNT} +#endif // _WIN32_WINNT + +#ifndef WINVER +#cmakedefine WINVER ${WINVER} +#endif // WINVER + +/* Define to empty if `const' does not conform to ANSI C. */ +#cmakedefine const ${const} + +/* Define to `int' if doesn't define. */ +#cmakedefine gid_t ${gid_t} + +/* Define to `unsigned long' if does not define. */ +#cmakedefine id_t ${id_t} + +/* Define to `int' if does not define. */ +#cmakedefine mode_t ${mode_t} + +/* Define to `long long' if does not define. */ +#cmakedefine off_t ${off_t} + +/* Define to `int' if doesn't define. */ +#cmakedefine pid_t ${pid_t} + +/* Define to `unsigned int' if does not define. */ +#cmakedefine size_t ${size_t} + +/* Define to `int' if does not define. */ +#cmakedefine ssize_t ${ssize_t} + +/* Define to `int' if doesn't define. */ +#cmakedefine uid_t ${uid_t} + +/* Define to `int' if does not define. */ +#cmakedefine intptr_t ${intptr_t} + +/* Define to `unsigned int' if does not define. */ +#cmakedefine uintptr_t ${uintptr_t} diff --cc Utilities/cmlibarchive/libarchive/CMakeLists.txt index b02ae82,0000000..e38d664 mode 100644,000000..100644 --- a/Utilities/cmlibarchive/libarchive/CMakeLists.txt +++ b/Utilities/cmlibarchive/libarchive/CMakeLists.txt @@@ -1,228 -1,0 +1,230 @@@ + +############################################ +# +# How to build libarchive +# +############################################ + +# Public headers +SET(include_HEADERS + archive.h + archive_entry.h +) + +# Sources and private headers +SET(libarchive_SOURCES + archive_acl.c + archive_acl_private.h + archive_check_magic.c + archive_cmdline.c + archive_cmdline_private.h + archive_crc32.h + archive_cryptor.c + archive_cryptor_private.h + archive_digest.c + archive_digest_private.h + archive_endian.h + archive_entry.c + archive_entry.h + archive_entry_copy_stat.c + archive_entry_link_resolver.c + archive_entry_locale.h + archive_entry_private.h + archive_entry_sparse.c + archive_entry_stat.c + archive_entry_strmode.c + archive_entry_xattr.c + archive_getdate.c + archive_getdate.h + archive_hmac.c + archive_hmac_private.h + archive_match.c + archive_openssl_evp_private.h + archive_openssl_hmac_private.h + archive_options.c + archive_options_private.h + archive_pack_dev.h + archive_pack_dev.c + archive_pathmatch.c + archive_pathmatch.h + archive_platform.h + archive_platform_acl.h + archive_platform_xattr.h + archive_ppmd_private.h + archive_ppmd7.c + archive_ppmd7_private.h + archive_private.h + archive_random.c + archive_random_private.h + archive_rb.c + archive_rb.h + archive_read.c + archive_read_add_passphrase.c + archive_read_append_filter.c + archive_read_data_into_fd.c + archive_read_disk_entry_from_file.c + archive_read_disk_posix.c + archive_read_disk_private.h + archive_read_disk_set_standard_lookup.c + archive_read_extract.c + archive_read_extract2.c + archive_read_open_fd.c + archive_read_open_file.c + archive_read_open_filename.c + archive_read_open_memory.c + archive_read_private.h + archive_read_set_format.c + archive_read_set_options.c + archive_read_support_filter_all.c + archive_read_support_filter_bzip2.c + archive_read_support_filter_compress.c + archive_read_support_filter_gzip.c + archive_read_support_filter_grzip.c + archive_read_support_filter_lrzip.c + archive_read_support_filter_lz4.c + archive_read_support_filter_lzop.c + archive_read_support_filter_none.c + archive_read_support_filter_program.c + archive_read_support_filter_rpm.c + archive_read_support_filter_uu.c + archive_read_support_filter_xz.c ++ archive_read_support_filter_zstd.c + archive_read_support_format_7zip.c + archive_read_support_format_all.c + archive_read_support_format_ar.c + archive_read_support_format_by_code.c + archive_read_support_format_cab.c + archive_read_support_format_cpio.c + archive_read_support_format_empty.c + archive_read_support_format_iso9660.c + archive_read_support_format_lha.c + archive_read_support_format_mtree.c + archive_read_support_format_rar.c + archive_read_support_format_raw.c + archive_read_support_format_tar.c + archive_read_support_format_warc.c + archive_read_support_format_xar.c + archive_read_support_format_zip.c + archive_string.c + archive_string.h + archive_string_composition.h + archive_string_sprintf.c + archive_util.c + archive_version_details.c + archive_virtual.c + archive_write.c + archive_write_disk_posix.c + archive_write_disk_private.h + archive_write_disk_set_standard_lookup.c + archive_write_private.h + archive_write_open_fd.c + archive_write_open_file.c + archive_write_open_filename.c + archive_write_open_memory.c + archive_write_add_filter.c + archive_write_add_filter_b64encode.c + archive_write_add_filter_by_name.c + archive_write_add_filter_bzip2.c + archive_write_add_filter_compress.c + archive_write_add_filter_grzip.c + archive_write_add_filter_gzip.c + archive_write_add_filter_lrzip.c + archive_write_add_filter_lz4.c + archive_write_add_filter_lzop.c + archive_write_add_filter_none.c + archive_write_add_filter_program.c + archive_write_add_filter_uuencode.c + archive_write_add_filter_xz.c ++ archive_write_add_filter_zstd.c + archive_write_set_format.c + archive_write_set_format_7zip.c + archive_write_set_format_ar.c + archive_write_set_format_by_name.c + archive_write_set_format_cpio.c + archive_write_set_format_cpio_newc.c + archive_write_set_format_filter_by_ext.c + archive_write_set_format_gnutar.c + archive_write_set_format_iso9660.c + archive_write_set_format_mtree.c + archive_write_set_format_pax.c + archive_write_set_format_raw.c + archive_write_set_format_shar.c + archive_write_set_format_ustar.c + archive_write_set_format_v7tar.c + archive_write_set_format_warc.c + archive_write_set_format_xar.c + archive_write_set_format_zip.c + archive_write_set_options.c + archive_write_set_passphrase.c + archive_xxhash.h + filter_fork_posix.c + filter_fork.h + xxhash.c +) + +# Man pages +SET(libarchive_MANS + archive_entry.3 + archive_entry_acl.3 + archive_entry_linkify.3 + archive_entry_paths.3 + archive_entry_perms.3 + archive_entry_stat.3 + archive_entry_time.3 + archive_read.3 + archive_read_add_passphrase.3 + archive_read_data.3 + archive_read_disk.3 + archive_read_extract.3 + archive_read_filter.3 + archive_read_format.3 + archive_read_free.3 + archive_read_header.3 + archive_read_new.3 + archive_read_open.3 + archive_read_set_options.3 + archive_util.3 + archive_write.3 + archive_write_blocksize.3 + archive_write_data.3 + archive_write_disk.3 + archive_write_filter.3 + archive_write_finish_entry.3 + archive_write_format.3 + archive_write_free.3 + archive_write_header.3 + archive_write_new.3 + archive_write_open.3 + archive_write_set_options.3 + archive_write_set_passphrase.3 + cpio.5 + libarchive.3 + libarchive_changes.3 + libarchive_internals.3 + libarchive-formats.5 + mtree.5 + tar.5 +) + +IF(WIN32 AND NOT CYGWIN) + LIST(APPEND libarchive_SOURCES archive_entry_copy_bhfi.c) + LIST(APPEND libarchive_SOURCES archive_read_disk_windows.c) + LIST(APPEND libarchive_SOURCES archive_windows.c) + LIST(APPEND libarchive_SOURCES archive_windows.h) + LIST(APPEND libarchive_SOURCES archive_write_disk_windows.c) + LIST(APPEND libarchive_SOURCES filter_fork_windows.c) +ENDIF(WIN32 AND NOT CYGWIN) + +IF(ARCHIVE_ACL_DARWIN) + LIST(APPEND libarchive_SOURCES archive_disk_acl_darwin.c) +ELSEIF(ARCHIVE_ACL_FREEBSD) + LIST(APPEND libarchive_SOURCES archive_disk_acl_freebsd.c) +ELSEIF(ARCHIVE_ACL_LIBACL) + LIST(APPEND libarchive_SOURCES archive_disk_acl_linux.c) +ELSEIF(ARCHIVE_ACL_SUNOS) + LIST(APPEND libarchive_SOURCES archive_disk_acl_sunos.c) +ENDIF() + +# CMake needs just one static "cmlibarchive" library. +ADD_LIBRARY(cmlibarchive STATIC ${libarchive_SOURCES} ${include_HEADERS}) +TARGET_LINK_LIBRARIES(cmlibarchive ${ADDITIONAL_LIBS}) diff --cc Utilities/cmlibarchive/libarchive/archive.h index 0f94d2e,0000000..f3ebbfe mode 100644,000000..100644 --- a/Utilities/cmlibarchive/libarchive/archive.h +++ b/Utilities/cmlibarchive/libarchive/archive.h @@@ -1,1184 -1,0 +1,1188 @@@ +/*- + * Copyright (c) 2003-2010 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD: src/lib/libarchive/archive.h.in,v 1.50 2008/05/26 17:00:22 kientzle Exp $ + */ + +#ifndef ARCHIVE_H_INCLUDED +#define ARCHIVE_H_INCLUDED + +/* + * The version number is expressed as a single integer that makes it + * easy to compare versions at build time: for version a.b.c, the + * version number is printf("%d%03d%03d",a,b,c). For example, if you + * know your application requires version 2.12.108 or later, you can + * assert that ARCHIVE_VERSION_NUMBER >= 2012108. + */ +/* Note: Compiler will complain if this does not match archive_entry.h! */ - #define ARCHIVE_VERSION_NUMBER 3003002 ++#define ARCHIVE_VERSION_NUMBER 3003003 + +#include +#include /* for wchar_t */ +#include /* For FILE * */ +#include /* For time_t */ + +/* + * Note: archive.h is for use outside of libarchive; the configuration + * headers (config.h, archive_platform.h, etc.) are purely internal. + * Do NOT use HAVE_XXX configuration macros to control the behavior of + * this header! If you must conditionalize, use predefined compiler and/or + * platform macros. + */ +#if defined(__BORLANDC__) && __BORLANDC__ >= 0x560 +# include +#elif !defined(__WATCOMC__) && !defined(_MSC_VER) && !defined(__INTERIX) && !defined(__BORLANDC__) && !defined(_SCO_DS) && !defined(__osf__) +# include +#endif + +/* Get appropriate definitions of 64-bit integer */ +#if !defined(__LA_INT64_T_DEFINED) +/* Older code relied on the __LA_INT64_T macro; after 4.0 we'll switch to the typedef exclusively. */ +# if ARCHIVE_VERSION_NUMBER < 4000000 +#define __LA_INT64_T la_int64_t +# endif +#define __LA_INT64_T_DEFINED +# if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__WATCOMC__) +typedef __int64 la_int64_t; +# else +# include /* ssize_t */ +# if defined(_SCO_DS) || defined(__osf__) +typedef long long la_int64_t; +# else +typedef int64_t la_int64_t; +# endif +# endif +#endif + +/* The la_ssize_t should match the type used in 'struct stat' */ +#if !defined(__LA_SSIZE_T_DEFINED) +/* Older code relied on the __LA_SSIZE_T macro; after 4.0 we'll switch to the typedef exclusively. */ +# if ARCHIVE_VERSION_NUMBER < 4000000 +#define __LA_SSIZE_T la_ssize_t +# endif +#define __LA_SSIZE_T_DEFINED +# if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__WATCOMC__) +# if defined(_SSIZE_T_DEFINED) || defined(_SSIZE_T_) +typedef ssize_t la_ssize_t; +# elif defined(_WIN64) +typedef __int64 la_ssize_t; +# else +typedef long la_ssize_t; +# endif +# else +# include /* ssize_t */ +typedef ssize_t la_ssize_t; +# endif +#endif + +/* Large file support for Android */ +#ifdef __ANDROID__ +#include "android_lf.h" +#endif + +/* + * On Windows, define LIBARCHIVE_STATIC if you're building or using a + * .lib. The default here assumes you're building a DLL. Only + * libarchive source should ever define __LIBARCHIVE_BUILD. + */ +#if ((defined __WIN32__) || (defined _WIN32) || defined(__CYGWIN__)) && (!defined LIBARCHIVE_STATIC) +# ifdef __LIBARCHIVE_BUILD +# ifdef __GNUC__ +# define __LA_DECL __attribute__((dllexport)) extern +# else +# define __LA_DECL __declspec(dllexport) +# endif +# else +# ifdef __GNUC__ +# define __LA_DECL +# else +# define __LA_DECL __declspec(dllimport) +# endif +# endif +#else +/* Static libraries or non-Windows needs no special declaration. */ +# define __LA_DECL +#endif + +#if defined(__GNUC__) && __GNUC__ >= 3 && !defined(__MINGW32__) +#define __LA_PRINTF(fmtarg, firstvararg) \ + __attribute__((__format__ (__printf__, fmtarg, firstvararg))) +#else +#define __LA_PRINTF(fmtarg, firstvararg) /* nothing */ +#endif + +/* CMake uses some deprecated APIs to build with old libarchive versions. */ +#define __LA_DEPRECATED + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * The version number is provided as both a macro and a function. + * The macro identifies the installed header; the function identifies + * the library version (which may not be the same if you're using a + * dynamically-linked version of the library). Of course, if the + * header and library are very different, you should expect some + * strangeness. Don't do that. + */ +__LA_DECL int archive_version_number(void); + +/* + * Textual name/version of the library, useful for version displays. + */ - #define ARCHIVE_VERSION_ONLY_STRING "3.3.2" ++#define ARCHIVE_VERSION_ONLY_STRING "3.3.3" +#define ARCHIVE_VERSION_STRING "libarchive " ARCHIVE_VERSION_ONLY_STRING +__LA_DECL const char * archive_version_string(void); + +/* + * Detailed textual name/version of the library and its dependencies. + * This has the form: + * "libarchive x.y.z zlib/a.b.c liblzma/d.e.f ... etc ..." + * the list of libraries described here will vary depending on how + * libarchive was compiled. + */ +__LA_DECL const char * archive_version_details(void); + +/* + * Returns NULL if libarchive was compiled without the associated library. + * Otherwise, returns the version number that libarchive was compiled + * against. + */ +__LA_DECL const char * archive_zlib_version(void); +__LA_DECL const char * archive_liblzma_version(void); +__LA_DECL const char * archive_bzlib_version(void); +__LA_DECL const char * archive_liblz4_version(void); ++__LA_DECL const char * archive_libzstd_version(void); + +/* Declare our basic types. */ +struct archive; +struct archive_entry; + +/* + * Error codes: Use archive_errno() and archive_error_string() + * to retrieve details. Unless specified otherwise, all functions + * that return 'int' use these codes. + */ +#define ARCHIVE_EOF 1 /* Found end of archive. */ +#define ARCHIVE_OK 0 /* Operation was successful. */ +#define ARCHIVE_RETRY (-10) /* Retry might succeed. */ +#define ARCHIVE_WARN (-20) /* Partial success. */ +/* For example, if write_header "fails", then you can't push data. */ +#define ARCHIVE_FAILED (-25) /* Current operation cannot complete. */ +/* But if write_header is "fatal," then this archive is dead and useless. */ +#define ARCHIVE_FATAL (-30) /* No more operations are possible. */ + +/* + * As far as possible, archive_errno returns standard platform errno codes. + * Of course, the details vary by platform, so the actual definitions + * here are stored in "archive_platform.h". The symbols are listed here + * for reference; as a rule, clients should not need to know the exact + * platform-dependent error code. + */ +/* Unrecognized or invalid file format. */ +/* #define ARCHIVE_ERRNO_FILE_FORMAT */ +/* Illegal usage of the library. */ +/* #define ARCHIVE_ERRNO_PROGRAMMER_ERROR */ +/* Unknown or unclassified error. */ +/* #define ARCHIVE_ERRNO_MISC */ + +/* + * Callbacks are invoked to automatically read/skip/write/open/close the + * archive. You can provide your own for complex tasks (like breaking + * archives across multiple tapes) or use standard ones built into the + * library. + */ + +/* Returns pointer and size of next block of data from archive. */ +typedef la_ssize_t archive_read_callback(struct archive *, + void *_client_data, const void **_buffer); + +/* Skips at most request bytes from archive and returns the skipped amount. + * This may skip fewer bytes than requested; it may even skip zero bytes. + * If you do skip fewer bytes than requested, libarchive will invoke your + * read callback and discard data as necessary to make up the full skip. + */ +typedef la_int64_t archive_skip_callback(struct archive *, + void *_client_data, la_int64_t request); + +/* Seeks to specified location in the file and returns the position. + * Whence values are SEEK_SET, SEEK_CUR, SEEK_END from stdio.h. + * Return ARCHIVE_FATAL if the seek fails for any reason. + */ +typedef la_int64_t archive_seek_callback(struct archive *, + void *_client_data, la_int64_t offset, int whence); + +/* Returns size actually written, zero on EOF, -1 on error. */ +typedef la_ssize_t archive_write_callback(struct archive *, + void *_client_data, + const void *_buffer, size_t _length); + +typedef int archive_open_callback(struct archive *, void *_client_data); + +typedef int archive_close_callback(struct archive *, void *_client_data); + +/* Switches from one client data object to the next/prev client data object. + * This is useful for reading from different data blocks such as a set of files + * that make up one large file. + */ +typedef int archive_switch_callback(struct archive *, void *_client_data1, + void *_client_data2); + +/* + * Returns a passphrase used for encryption or decryption, NULL on nothing + * to do and give it up. + */ +typedef const char *archive_passphrase_callback(struct archive *, + void *_client_data); + +/* + * Codes to identify various stream filters. + */ +#define ARCHIVE_FILTER_NONE 0 +#define ARCHIVE_FILTER_GZIP 1 +#define ARCHIVE_FILTER_BZIP2 2 +#define ARCHIVE_FILTER_COMPRESS 3 +#define ARCHIVE_FILTER_PROGRAM 4 +#define ARCHIVE_FILTER_LZMA 5 +#define ARCHIVE_FILTER_XZ 6 +#define ARCHIVE_FILTER_UU 7 +#define ARCHIVE_FILTER_RPM 8 +#define ARCHIVE_FILTER_LZIP 9 +#define ARCHIVE_FILTER_LRZIP 10 +#define ARCHIVE_FILTER_LZOP 11 +#define ARCHIVE_FILTER_GRZIP 12 +#define ARCHIVE_FILTER_LZ4 13 ++#define ARCHIVE_FILTER_ZSTD 14 + +#if ARCHIVE_VERSION_NUMBER < 4000000 +#define ARCHIVE_COMPRESSION_NONE ARCHIVE_FILTER_NONE +#define ARCHIVE_COMPRESSION_GZIP ARCHIVE_FILTER_GZIP +#define ARCHIVE_COMPRESSION_BZIP2 ARCHIVE_FILTER_BZIP2 +#define ARCHIVE_COMPRESSION_COMPRESS ARCHIVE_FILTER_COMPRESS +#define ARCHIVE_COMPRESSION_PROGRAM ARCHIVE_FILTER_PROGRAM +#define ARCHIVE_COMPRESSION_LZMA ARCHIVE_FILTER_LZMA +#define ARCHIVE_COMPRESSION_XZ ARCHIVE_FILTER_XZ +#define ARCHIVE_COMPRESSION_UU ARCHIVE_FILTER_UU +#define ARCHIVE_COMPRESSION_RPM ARCHIVE_FILTER_RPM +#define ARCHIVE_COMPRESSION_LZIP ARCHIVE_FILTER_LZIP +#define ARCHIVE_COMPRESSION_LRZIP ARCHIVE_FILTER_LRZIP +#endif + +/* + * Codes returned by archive_format. + * + * Top 16 bits identifies the format family (e.g., "tar"); lower + * 16 bits indicate the variant. This is updated by read_next_header. + * Note that the lower 16 bits will often vary from entry to entry. + * In some cases, this variation occurs as libarchive learns more about + * the archive (for example, later entries might utilize extensions that + * weren't necessary earlier in the archive; in this case, libarchive + * will change the format code to indicate the extended format that + * was used). In other cases, it's because different tools have + * modified the archive and so different parts of the archive + * actually have slightly different formats. (Both tar and cpio store + * format codes in each entry, so it is quite possible for each + * entry to be in a different format.) + */ +#define ARCHIVE_FORMAT_BASE_MASK 0xff0000 +#define ARCHIVE_FORMAT_CPIO 0x10000 +#define ARCHIVE_FORMAT_CPIO_POSIX (ARCHIVE_FORMAT_CPIO | 1) +#define ARCHIVE_FORMAT_CPIO_BIN_LE (ARCHIVE_FORMAT_CPIO | 2) +#define ARCHIVE_FORMAT_CPIO_BIN_BE (ARCHIVE_FORMAT_CPIO | 3) +#define ARCHIVE_FORMAT_CPIO_SVR4_NOCRC (ARCHIVE_FORMAT_CPIO | 4) +#define ARCHIVE_FORMAT_CPIO_SVR4_CRC (ARCHIVE_FORMAT_CPIO | 5) +#define ARCHIVE_FORMAT_CPIO_AFIO_LARGE (ARCHIVE_FORMAT_CPIO | 6) +#define ARCHIVE_FORMAT_SHAR 0x20000 +#define ARCHIVE_FORMAT_SHAR_BASE (ARCHIVE_FORMAT_SHAR | 1) +#define ARCHIVE_FORMAT_SHAR_DUMP (ARCHIVE_FORMAT_SHAR | 2) +#define ARCHIVE_FORMAT_TAR 0x30000 +#define ARCHIVE_FORMAT_TAR_USTAR (ARCHIVE_FORMAT_TAR | 1) +#define ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE (ARCHIVE_FORMAT_TAR | 2) +#define ARCHIVE_FORMAT_TAR_PAX_RESTRICTED (ARCHIVE_FORMAT_TAR | 3) +#define ARCHIVE_FORMAT_TAR_GNUTAR (ARCHIVE_FORMAT_TAR | 4) +#define ARCHIVE_FORMAT_ISO9660 0x40000 +#define ARCHIVE_FORMAT_ISO9660_ROCKRIDGE (ARCHIVE_FORMAT_ISO9660 | 1) +#define ARCHIVE_FORMAT_ZIP 0x50000 +#define ARCHIVE_FORMAT_EMPTY 0x60000 +#define ARCHIVE_FORMAT_AR 0x70000 +#define ARCHIVE_FORMAT_AR_GNU (ARCHIVE_FORMAT_AR | 1) +#define ARCHIVE_FORMAT_AR_BSD (ARCHIVE_FORMAT_AR | 2) +#define ARCHIVE_FORMAT_MTREE 0x80000 +#define ARCHIVE_FORMAT_RAW 0x90000 +#define ARCHIVE_FORMAT_XAR 0xA0000 +#define ARCHIVE_FORMAT_LHA 0xB0000 +#define ARCHIVE_FORMAT_CAB 0xC0000 +#define ARCHIVE_FORMAT_RAR 0xD0000 +#define ARCHIVE_FORMAT_7ZIP 0xE0000 +#define ARCHIVE_FORMAT_WARC 0xF0000 + +/* + * Codes returned by archive_read_format_capabilities(). + * + * This list can be extended with values between 0 and 0xffff. + * The original purpose of this list was to let different archive + * format readers expose their general capabilities in terms of + * encryption. + */ +#define ARCHIVE_READ_FORMAT_CAPS_NONE (0) /* no special capabilities */ +#define ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_DATA (1<<0) /* reader can detect encrypted data */ +#define ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_METADATA (1<<1) /* reader can detect encryptable metadata (pathname, mtime, etc.) */ + +/* + * Codes returned by archive_read_has_encrypted_entries(). + * + * In case the archive does not support encryption detection at all + * ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED is returned. If the reader + * for some other reason (e.g. not enough bytes read) cannot say if + * there are encrypted entries, ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW + * is returned. + */ +#define ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED -2 +#define ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW -1 + +/*- + * Basic outline for reading an archive: + * 1) Ask archive_read_new for an archive reader object. + * 2) Update any global properties as appropriate. + * In particular, you'll certainly want to call appropriate + * archive_read_support_XXX functions. + * 3) Call archive_read_open_XXX to open the archive + * 4) Repeatedly call archive_read_next_header to get information about + * successive archive entries. Call archive_read_data to extract + * data for entries of interest. + * 5) Call archive_read_free to end processing. + */ +__LA_DECL struct archive *archive_read_new(void); + +/* + * The archive_read_support_XXX calls enable auto-detect for this + * archive handle. They also link in the necessary support code. + * For example, if you don't want bzlib linked in, don't invoke + * support_compression_bzip2(). The "all" functions provide the + * obvious shorthand. + */ + +#if ARCHIVE_VERSION_NUMBER < 4000000 +__LA_DECL int archive_read_support_compression_all(struct archive *) + __LA_DEPRECATED; +__LA_DECL int archive_read_support_compression_bzip2(struct archive *) + __LA_DEPRECATED; +__LA_DECL int archive_read_support_compression_compress(struct archive *) + __LA_DEPRECATED; +__LA_DECL int archive_read_support_compression_gzip(struct archive *) + __LA_DEPRECATED; +__LA_DECL int archive_read_support_compression_lzip(struct archive *) + __LA_DEPRECATED; +__LA_DECL int archive_read_support_compression_lzma(struct archive *) + __LA_DEPRECATED; +__LA_DECL int archive_read_support_compression_none(struct archive *) + __LA_DEPRECATED; +__LA_DECL int archive_read_support_compression_program(struct archive *, + const char *command) __LA_DEPRECATED; +__LA_DECL int archive_read_support_compression_program_signature + (struct archive *, const char *, + const void * /* match */, size_t) __LA_DEPRECATED; + +__LA_DECL int archive_read_support_compression_rpm(struct archive *) + __LA_DEPRECATED; +__LA_DECL int archive_read_support_compression_uu(struct archive *) + __LA_DEPRECATED; +__LA_DECL int archive_read_support_compression_xz(struct archive *) + __LA_DEPRECATED; +#endif + +__LA_DECL int archive_read_support_filter_all(struct archive *); +__LA_DECL int archive_read_support_filter_bzip2(struct archive *); +__LA_DECL int archive_read_support_filter_compress(struct archive *); +__LA_DECL int archive_read_support_filter_gzip(struct archive *); +__LA_DECL int archive_read_support_filter_grzip(struct archive *); +__LA_DECL int archive_read_support_filter_lrzip(struct archive *); +__LA_DECL int archive_read_support_filter_lz4(struct archive *); +__LA_DECL int archive_read_support_filter_lzip(struct archive *); +__LA_DECL int archive_read_support_filter_lzma(struct archive *); +__LA_DECL int archive_read_support_filter_lzop(struct archive *); +__LA_DECL int archive_read_support_filter_none(struct archive *); +__LA_DECL int archive_read_support_filter_program(struct archive *, + const char *command); +__LA_DECL int archive_read_support_filter_program_signature + (struct archive *, const char * /* cmd */, + const void * /* match */, size_t); +__LA_DECL int archive_read_support_filter_rpm(struct archive *); +__LA_DECL int archive_read_support_filter_uu(struct archive *); +__LA_DECL int archive_read_support_filter_xz(struct archive *); ++__LA_DECL int archive_read_support_filter_zstd(struct archive *); + +__LA_DECL int archive_read_support_format_7zip(struct archive *); +__LA_DECL int archive_read_support_format_all(struct archive *); +__LA_DECL int archive_read_support_format_ar(struct archive *); +__LA_DECL int archive_read_support_format_by_code(struct archive *, int); +__LA_DECL int archive_read_support_format_cab(struct archive *); +__LA_DECL int archive_read_support_format_cpio(struct archive *); +__LA_DECL int archive_read_support_format_empty(struct archive *); +__LA_DECL int archive_read_support_format_gnutar(struct archive *); +__LA_DECL int archive_read_support_format_iso9660(struct archive *); +__LA_DECL int archive_read_support_format_lha(struct archive *); +__LA_DECL int archive_read_support_format_mtree(struct archive *); +__LA_DECL int archive_read_support_format_rar(struct archive *); +__LA_DECL int archive_read_support_format_raw(struct archive *); +__LA_DECL int archive_read_support_format_tar(struct archive *); +__LA_DECL int archive_read_support_format_warc(struct archive *); +__LA_DECL int archive_read_support_format_xar(struct archive *); +/* archive_read_support_format_zip() enables both streamable and seekable + * zip readers. */ +__LA_DECL int archive_read_support_format_zip(struct archive *); +/* Reads Zip archives as stream from beginning to end. Doesn't + * correctly handle SFX ZIP files or ZIP archives that have been modified + * in-place. */ +__LA_DECL int archive_read_support_format_zip_streamable(struct archive *); +/* Reads starting from central directory; requires seekable input. */ +__LA_DECL int archive_read_support_format_zip_seekable(struct archive *); + +/* Functions to manually set the format and filters to be used. This is + * useful to bypass the bidding process when the format and filters to use + * is known in advance. + */ +__LA_DECL int archive_read_set_format(struct archive *, int); +__LA_DECL int archive_read_append_filter(struct archive *, int); +__LA_DECL int archive_read_append_filter_program(struct archive *, + const char *); +__LA_DECL int archive_read_append_filter_program_signature + (struct archive *, const char *, const void * /* match */, size_t); + +/* Set various callbacks. */ +__LA_DECL int archive_read_set_open_callback(struct archive *, + archive_open_callback *); +__LA_DECL int archive_read_set_read_callback(struct archive *, + archive_read_callback *); +__LA_DECL int archive_read_set_seek_callback(struct archive *, + archive_seek_callback *); +__LA_DECL int archive_read_set_skip_callback(struct archive *, + archive_skip_callback *); +__LA_DECL int archive_read_set_close_callback(struct archive *, + archive_close_callback *); +/* Callback used to switch between one data object to the next */ +__LA_DECL int archive_read_set_switch_callback(struct archive *, + archive_switch_callback *); + +/* This sets the first data object. */ +__LA_DECL int archive_read_set_callback_data(struct archive *, void *); +/* This sets data object at specified index */ +__LA_DECL int archive_read_set_callback_data2(struct archive *, void *, + unsigned int); +/* This adds a data object at the specified index. */ +__LA_DECL int archive_read_add_callback_data(struct archive *, void *, + unsigned int); +/* This appends a data object to the end of list */ +__LA_DECL int archive_read_append_callback_data(struct archive *, void *); +/* This prepends a data object to the beginning of list */ +__LA_DECL int archive_read_prepend_callback_data(struct archive *, void *); + +/* Opening freezes the callbacks. */ +__LA_DECL int archive_read_open1(struct archive *); + +/* Convenience wrappers around the above. */ +__LA_DECL int archive_read_open(struct archive *, void *_client_data, + archive_open_callback *, archive_read_callback *, + archive_close_callback *); +__LA_DECL int archive_read_open2(struct archive *, void *_client_data, + archive_open_callback *, archive_read_callback *, + archive_skip_callback *, archive_close_callback *); + +/* + * A variety of shortcuts that invoke archive_read_open() with + * canned callbacks suitable for common situations. The ones that + * accept a block size handle tape blocking correctly. + */ +/* Use this if you know the filename. Note: NULL indicates stdin. */ +__LA_DECL int archive_read_open_filename(struct archive *, + const char *_filename, size_t _block_size); +/* Use this for reading multivolume files by filenames. + * NOTE: Must be NULL terminated. Sorting is NOT done. */ +__LA_DECL int archive_read_open_filenames(struct archive *, + const char **_filenames, size_t _block_size); +__LA_DECL int archive_read_open_filename_w(struct archive *, + const wchar_t *_filename, size_t _block_size); +/* archive_read_open_file() is a deprecated synonym for ..._open_filename(). */ +__LA_DECL int archive_read_open_file(struct archive *, + const char *_filename, size_t _block_size) __LA_DEPRECATED; +/* Read an archive that's stored in memory. */ +__LA_DECL int archive_read_open_memory(struct archive *, + const void * buff, size_t size); +/* A more involved version that is only used for internal testing. */ +__LA_DECL int archive_read_open_memory2(struct archive *a, const void *buff, + size_t size, size_t read_size); +/* Read an archive that's already open, using the file descriptor. */ +__LA_DECL int archive_read_open_fd(struct archive *, int _fd, + size_t _block_size); +/* Read an archive that's already open, using a FILE *. */ +/* Note: DO NOT use this with tape drives. */ +__LA_DECL int archive_read_open_FILE(struct archive *, FILE *_file); + +/* Parses and returns next entry header. */ +__LA_DECL int archive_read_next_header(struct archive *, + struct archive_entry **); + +/* Parses and returns next entry header using the archive_entry passed in */ +__LA_DECL int archive_read_next_header2(struct archive *, + struct archive_entry *); + +/* + * Retrieve the byte offset in UNCOMPRESSED data where last-read + * header started. + */ +__LA_DECL la_int64_t archive_read_header_position(struct archive *); + +/* + * Returns 1 if the archive contains at least one encrypted entry. + * If the archive format not support encryption at all + * ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED is returned. + * If for any other reason (e.g. not enough data read so far) + * we cannot say whether there are encrypted entries, then + * ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW is returned. + * In general, this function will return values below zero when the + * reader is uncertain or totally incapable of encryption support. + * When this function returns 0 you can be sure that the reader + * supports encryption detection but no encrypted entries have + * been found yet. + * + * NOTE: If the metadata/header of an archive is also encrypted, you + * cannot rely on the number of encrypted entries. That is why this + * function does not return the number of encrypted entries but# + * just shows that there are some. + */ +__LA_DECL int archive_read_has_encrypted_entries(struct archive *); + +/* + * Returns a bitmask of capabilities that are supported by the archive format reader. + * If the reader has no special capabilities, ARCHIVE_READ_FORMAT_CAPS_NONE is returned. + */ +__LA_DECL int archive_read_format_capabilities(struct archive *); + +/* Read data from the body of an entry. Similar to read(2). */ +__LA_DECL la_ssize_t archive_read_data(struct archive *, + void *, size_t); + +/* Seek within the body of an entry. Similar to lseek(2). */ +__LA_DECL la_int64_t archive_seek_data(struct archive *, la_int64_t, int); + +/* + * A zero-copy version of archive_read_data that also exposes the file offset + * of each returned block. Note that the client has no way to specify + * the desired size of the block. The API does guarantee that offsets will + * be strictly increasing and that returned blocks will not overlap. + */ +__LA_DECL int archive_read_data_block(struct archive *a, + const void **buff, size_t *size, la_int64_t *offset); + +/*- + * Some convenience functions that are built on archive_read_data: + * 'skip': skips entire entry + * 'into_buffer': writes data into memory buffer that you provide + * 'into_fd': writes data to specified filedes + */ +__LA_DECL int archive_read_data_skip(struct archive *); +__LA_DECL int archive_read_data_into_fd(struct archive *, int fd); + +/* + * Set read options. + */ +/* Apply option to the format only. */ +__LA_DECL int archive_read_set_format_option(struct archive *_a, + const char *m, const char *o, + const char *v); +/* Apply option to the filter only. */ +__LA_DECL int archive_read_set_filter_option(struct archive *_a, + const char *m, const char *o, + const char *v); +/* Apply option to both the format and the filter. */ +__LA_DECL int archive_read_set_option(struct archive *_a, + const char *m, const char *o, + const char *v); +/* Apply option string to both the format and the filter. */ +__LA_DECL int archive_read_set_options(struct archive *_a, + const char *opts); + +/* + * Add a decryption passphrase. + */ +__LA_DECL int archive_read_add_passphrase(struct archive *, const char *); +__LA_DECL int archive_read_set_passphrase_callback(struct archive *, + void *client_data, archive_passphrase_callback *); + + +/*- + * Convenience function to recreate the current entry (whose header + * has just been read) on disk. + * + * This does quite a bit more than just copy data to disk. It also: + * - Creates intermediate directories as required. + * - Manages directory permissions: non-writable directories will + * be initially created with write permission enabled; when the + * archive is closed, dir permissions are edited to the values specified + * in the archive. + * - Checks hardlinks: hardlinks will not be extracted unless the + * linked-to file was also extracted within the same session. (TODO) + */ + +/* The "flags" argument selects optional behavior, 'OR' the flags you want. */ + +/* Default: Do not try to set owner/group. */ +#define ARCHIVE_EXTRACT_OWNER (0x0001) +/* Default: Do obey umask, do not restore SUID/SGID/SVTX bits. */ +#define ARCHIVE_EXTRACT_PERM (0x0002) +/* Default: Do not restore mtime/atime. */ +#define ARCHIVE_EXTRACT_TIME (0x0004) +/* Default: Replace existing files. */ +#define ARCHIVE_EXTRACT_NO_OVERWRITE (0x0008) +/* Default: Try create first, unlink only if create fails with EEXIST. */ +#define ARCHIVE_EXTRACT_UNLINK (0x0010) +/* Default: Do not restore ACLs. */ +#define ARCHIVE_EXTRACT_ACL (0x0020) +/* Default: Do not restore fflags. */ +#define ARCHIVE_EXTRACT_FFLAGS (0x0040) +/* Default: Do not restore xattrs. */ +#define ARCHIVE_EXTRACT_XATTR (0x0080) +/* Default: Do not try to guard against extracts redirected by symlinks. */ +/* Note: With ARCHIVE_EXTRACT_UNLINK, will remove any intermediate symlink. */ +#define ARCHIVE_EXTRACT_SECURE_SYMLINKS (0x0100) +/* Default: Do not reject entries with '..' as path elements. */ +#define ARCHIVE_EXTRACT_SECURE_NODOTDOT (0x0200) +/* Default: Create parent directories as needed. */ +#define ARCHIVE_EXTRACT_NO_AUTODIR (0x0400) +/* Default: Overwrite files, even if one on disk is newer. */ +#define ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER (0x0800) +/* Detect blocks of 0 and write holes instead. */ +#define ARCHIVE_EXTRACT_SPARSE (0x1000) +/* Default: Do not restore Mac extended metadata. */ +/* This has no effect except on Mac OS. */ +#define ARCHIVE_EXTRACT_MAC_METADATA (0x2000) +/* Default: Use HFS+ compression if it was compressed. */ +/* This has no effect except on Mac OS v10.6 or later. */ +#define ARCHIVE_EXTRACT_NO_HFS_COMPRESSION (0x4000) +/* Default: Do not use HFS+ compression if it was not compressed. */ +/* This has no effect except on Mac OS v10.6 or later. */ +#define ARCHIVE_EXTRACT_HFS_COMPRESSION_FORCED (0x8000) +/* Default: Do not reject entries with absolute paths */ +#define ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS (0x10000) +/* Default: Do not clear no-change flags when unlinking object */ +#define ARCHIVE_EXTRACT_CLEAR_NOCHANGE_FFLAGS (0x20000) + +__LA_DECL int archive_read_extract(struct archive *, struct archive_entry *, + int flags); +__LA_DECL int archive_read_extract2(struct archive *, struct archive_entry *, + struct archive * /* dest */); +__LA_DECL void archive_read_extract_set_progress_callback(struct archive *, + void (*_progress_func)(void *), void *_user_data); + +/* Record the dev/ino of a file that will not be written. This is + * generally set to the dev/ino of the archive being read. */ +__LA_DECL void archive_read_extract_set_skip_file(struct archive *, + la_int64_t, la_int64_t); + +/* Close the file and release most resources. */ +__LA_DECL int archive_read_close(struct archive *); +/* Release all resources and destroy the object. */ +/* Note that archive_read_free will call archive_read_close for you. */ +__LA_DECL int archive_read_free(struct archive *); +#if ARCHIVE_VERSION_NUMBER < 4000000 +/* Synonym for archive_read_free() for backwards compatibility. */ +__LA_DECL int archive_read_finish(struct archive *) __LA_DEPRECATED; +#endif + +/*- + * To create an archive: + * 1) Ask archive_write_new for an archive writer object. + * 2) Set any global properties. In particular, you should set + * the compression and format to use. + * 3) Call archive_write_open to open the file (most people + * will use archive_write_open_file or archive_write_open_fd, + * which provide convenient canned I/O callbacks for you). + * 4) For each entry: + * - construct an appropriate struct archive_entry structure + * - archive_write_header to write the header + * - archive_write_data to write the entry data + * 5) archive_write_close to close the output + * 6) archive_write_free to cleanup the writer and release resources + */ +__LA_DECL struct archive *archive_write_new(void); +__LA_DECL int archive_write_set_bytes_per_block(struct archive *, + int bytes_per_block); +__LA_DECL int archive_write_get_bytes_per_block(struct archive *); +/* XXX This is badly misnamed; suggestions appreciated. XXX */ +__LA_DECL int archive_write_set_bytes_in_last_block(struct archive *, + int bytes_in_last_block); +__LA_DECL int archive_write_get_bytes_in_last_block(struct archive *); + +/* The dev/ino of a file that won't be archived. This is used + * to avoid recursively adding an archive to itself. */ +__LA_DECL int archive_write_set_skip_file(struct archive *, + la_int64_t, la_int64_t); + +#if ARCHIVE_VERSION_NUMBER < 4000000 +__LA_DECL int archive_write_set_compression_bzip2(struct archive *) + __LA_DEPRECATED; +__LA_DECL int archive_write_set_compression_compress(struct archive *) + __LA_DEPRECATED; +__LA_DECL int archive_write_set_compression_gzip(struct archive *) + __LA_DEPRECATED; +__LA_DECL int archive_write_set_compression_lzip(struct archive *) + __LA_DEPRECATED; +__LA_DECL int archive_write_set_compression_lzma(struct archive *) + __LA_DEPRECATED; +__LA_DECL int archive_write_set_compression_none(struct archive *) + __LA_DEPRECATED; +__LA_DECL int archive_write_set_compression_program(struct archive *, + const char *cmd) __LA_DEPRECATED; +__LA_DECL int archive_write_set_compression_xz(struct archive *) + __LA_DEPRECATED; +#endif + +/* A convenience function to set the filter based on the code. */ +__LA_DECL int archive_write_add_filter(struct archive *, int filter_code); +__LA_DECL int archive_write_add_filter_by_name(struct archive *, + const char *name); +__LA_DECL int archive_write_add_filter_b64encode(struct archive *); +__LA_DECL int archive_write_add_filter_bzip2(struct archive *); +__LA_DECL int archive_write_add_filter_compress(struct archive *); +__LA_DECL int archive_write_add_filter_grzip(struct archive *); +__LA_DECL int archive_write_add_filter_gzip(struct archive *); +__LA_DECL int archive_write_add_filter_lrzip(struct archive *); +__LA_DECL int archive_write_add_filter_lz4(struct archive *); +__LA_DECL int archive_write_add_filter_lzip(struct archive *); +__LA_DECL int archive_write_add_filter_lzma(struct archive *); +__LA_DECL int archive_write_add_filter_lzop(struct archive *); +__LA_DECL int archive_write_add_filter_none(struct archive *); +__LA_DECL int archive_write_add_filter_program(struct archive *, + const char *cmd); +__LA_DECL int archive_write_add_filter_uuencode(struct archive *); +__LA_DECL int archive_write_add_filter_xz(struct archive *); ++__LA_DECL int archive_write_add_filter_zstd(struct archive *); + + +/* A convenience function to set the format based on the code or name. */ +__LA_DECL int archive_write_set_format(struct archive *, int format_code); +__LA_DECL int archive_write_set_format_by_name(struct archive *, + const char *name); +/* To minimize link pollution, use one or more of the following. */ +__LA_DECL int archive_write_set_format_7zip(struct archive *); +__LA_DECL int archive_write_set_format_ar_bsd(struct archive *); +__LA_DECL int archive_write_set_format_ar_svr4(struct archive *); +__LA_DECL int archive_write_set_format_cpio(struct archive *); +__LA_DECL int archive_write_set_format_cpio_newc(struct archive *); +__LA_DECL int archive_write_set_format_gnutar(struct archive *); +__LA_DECL int archive_write_set_format_iso9660(struct archive *); +__LA_DECL int archive_write_set_format_mtree(struct archive *); +__LA_DECL int archive_write_set_format_mtree_classic(struct archive *); +/* TODO: int archive_write_set_format_old_tar(struct archive *); */ +__LA_DECL int archive_write_set_format_pax(struct archive *); +__LA_DECL int archive_write_set_format_pax_restricted(struct archive *); +__LA_DECL int archive_write_set_format_raw(struct archive *); +__LA_DECL int archive_write_set_format_shar(struct archive *); +__LA_DECL int archive_write_set_format_shar_dump(struct archive *); +__LA_DECL int archive_write_set_format_ustar(struct archive *); +__LA_DECL int archive_write_set_format_v7tar(struct archive *); +__LA_DECL int archive_write_set_format_warc(struct archive *); +__LA_DECL int archive_write_set_format_xar(struct archive *); +__LA_DECL int archive_write_set_format_zip(struct archive *); +__LA_DECL int archive_write_set_format_filter_by_ext(struct archive *a, const char *filename); +__LA_DECL int archive_write_set_format_filter_by_ext_def(struct archive *a, const char *filename, const char * def_ext); +__LA_DECL int archive_write_zip_set_compression_deflate(struct archive *); +__LA_DECL int archive_write_zip_set_compression_store(struct archive *); +__LA_DECL int archive_write_open(struct archive *, void *, + archive_open_callback *, archive_write_callback *, + archive_close_callback *); +__LA_DECL int archive_write_open_fd(struct archive *, int _fd); +__LA_DECL int archive_write_open_filename(struct archive *, const char *_file); +__LA_DECL int archive_write_open_filename_w(struct archive *, + const wchar_t *_file); +/* A deprecated synonym for archive_write_open_filename() */ +__LA_DECL int archive_write_open_file(struct archive *, const char *_file) + __LA_DEPRECATED; +__LA_DECL int archive_write_open_FILE(struct archive *, FILE *); +/* _buffSize is the size of the buffer, _used refers to a variable that + * will be updated after each write into the buffer. */ +__LA_DECL int archive_write_open_memory(struct archive *, + void *_buffer, size_t _buffSize, size_t *_used); + +/* + * Note that the library will truncate writes beyond the size provided + * to archive_write_header or pad if the provided data is short. + */ +__LA_DECL int archive_write_header(struct archive *, + struct archive_entry *); +__LA_DECL la_ssize_t archive_write_data(struct archive *, + const void *, size_t); + +/* This interface is currently only available for archive_write_disk handles. */ +__LA_DECL la_ssize_t archive_write_data_block(struct archive *, + const void *, size_t, la_int64_t); + +__LA_DECL int archive_write_finish_entry(struct archive *); +__LA_DECL int archive_write_close(struct archive *); +/* Marks the archive as FATAL so that a subsequent free() operation + * won't try to close() cleanly. Provides a fast abort capability + * when the client discovers that things have gone wrong. */ +__LA_DECL int archive_write_fail(struct archive *); +/* This can fail if the archive wasn't already closed, in which case + * archive_write_free() will implicitly call archive_write_close(). */ +__LA_DECL int archive_write_free(struct archive *); +#if ARCHIVE_VERSION_NUMBER < 4000000 +/* Synonym for archive_write_free() for backwards compatibility. */ +__LA_DECL int archive_write_finish(struct archive *) __LA_DEPRECATED; +#endif + +/* + * Set write options. + */ +/* Apply option to the format only. */ +__LA_DECL int archive_write_set_format_option(struct archive *_a, + const char *m, const char *o, + const char *v); +/* Apply option to the filter only. */ +__LA_DECL int archive_write_set_filter_option(struct archive *_a, + const char *m, const char *o, + const char *v); +/* Apply option to both the format and the filter. */ +__LA_DECL int archive_write_set_option(struct archive *_a, + const char *m, const char *o, + const char *v); +/* Apply option string to both the format and the filter. */ +__LA_DECL int archive_write_set_options(struct archive *_a, + const char *opts); + +/* + * Set a encryption passphrase. + */ +__LA_DECL int archive_write_set_passphrase(struct archive *_a, const char *p); +__LA_DECL int archive_write_set_passphrase_callback(struct archive *, + void *client_data, archive_passphrase_callback *); + +/*- + * ARCHIVE_WRITE_DISK API + * + * To create objects on disk: + * 1) Ask archive_write_disk_new for a new archive_write_disk object. + * 2) Set any global properties. In particular, you probably + * want to set the options. + * 3) For each entry: + * - construct an appropriate struct archive_entry structure + * - archive_write_header to create the file/dir/etc on disk + * - archive_write_data to write the entry data + * 4) archive_write_free to cleanup the writer and release resources + * + * In particular, you can use this in conjunction with archive_read() + * to pull entries out of an archive and create them on disk. + */ +__LA_DECL struct archive *archive_write_disk_new(void); +/* This file will not be overwritten. */ +__LA_DECL int archive_write_disk_set_skip_file(struct archive *, + la_int64_t, la_int64_t); +/* Set flags to control how the next item gets created. + * This accepts a bitmask of ARCHIVE_EXTRACT_XXX flags defined above. */ +__LA_DECL int archive_write_disk_set_options(struct archive *, + int flags); +/* + * The lookup functions are given uname/uid (or gname/gid) pairs and + * return a uid (gid) suitable for this system. These are used for + * restoring ownership and for setting ACLs. The default functions + * are naive, they just return the uid/gid. These are small, so reasonable + * for applications that don't need to preserve ownership; they + * are probably also appropriate for applications that are doing + * same-system backup and restore. + */ +/* + * The "standard" lookup functions use common system calls to lookup + * the uname/gname, falling back to the uid/gid if the names can't be + * found. They cache lookups and are reasonably fast, but can be very + * large, so they are not used unless you ask for them. In + * particular, these match the specifications of POSIX "pax" and old + * POSIX "tar". + */ +__LA_DECL int archive_write_disk_set_standard_lookup(struct archive *); +/* + * If neither the default (naive) nor the standard (big) functions suit + * your needs, you can write your own and register them. Be sure to + * include a cleanup function if you have allocated private data. + */ +__LA_DECL int archive_write_disk_set_group_lookup(struct archive *, + void * /* private_data */, + la_int64_t (*)(void *, const char *, la_int64_t), + void (* /* cleanup */)(void *)); +__LA_DECL int archive_write_disk_set_user_lookup(struct archive *, + void * /* private_data */, + la_int64_t (*)(void *, const char *, la_int64_t), + void (* /* cleanup */)(void *)); +__LA_DECL la_int64_t archive_write_disk_gid(struct archive *, const char *, la_int64_t); +__LA_DECL la_int64_t archive_write_disk_uid(struct archive *, const char *, la_int64_t); + +/* + * ARCHIVE_READ_DISK API + * + * This is still evolving and somewhat experimental. + */ +__LA_DECL struct archive *archive_read_disk_new(void); +/* The names for symlink modes here correspond to an old BSD + * command-line argument convention: -L, -P, -H */ +/* Follow all symlinks. */ +__LA_DECL int archive_read_disk_set_symlink_logical(struct archive *); +/* Follow no symlinks. */ +__LA_DECL int archive_read_disk_set_symlink_physical(struct archive *); +/* Follow symlink initially, then not. */ +__LA_DECL int archive_read_disk_set_symlink_hybrid(struct archive *); +/* TODO: Handle Linux stat32/stat64 ugliness. */ +__LA_DECL int archive_read_disk_entry_from_file(struct archive *, + struct archive_entry *, int /* fd */, const struct stat *); +/* Look up gname for gid or uname for uid. */ +/* Default implementations are very, very stupid. */ +__LA_DECL const char *archive_read_disk_gname(struct archive *, la_int64_t); +__LA_DECL const char *archive_read_disk_uname(struct archive *, la_int64_t); +/* "Standard" implementation uses getpwuid_r, getgrgid_r and caches the + * results for performance. */ +__LA_DECL int archive_read_disk_set_standard_lookup(struct archive *); +/* You can install your own lookups if you like. */ +__LA_DECL int archive_read_disk_set_gname_lookup(struct archive *, + void * /* private_data */, + const char *(* /* lookup_fn */)(void *, la_int64_t), + void (* /* cleanup_fn */)(void *)); +__LA_DECL int archive_read_disk_set_uname_lookup(struct archive *, + void * /* private_data */, + const char *(* /* lookup_fn */)(void *, la_int64_t), + void (* /* cleanup_fn */)(void *)); +/* Start traversal. */ +__LA_DECL int archive_read_disk_open(struct archive *, const char *); +__LA_DECL int archive_read_disk_open_w(struct archive *, const wchar_t *); +/* + * Request that current entry be visited. If you invoke it on every + * directory, you'll get a physical traversal. This is ignored if the + * current entry isn't a directory or a link to a directory. So, if + * you invoke this on every returned path, you'll get a full logical + * traversal. + */ +__LA_DECL int archive_read_disk_descend(struct archive *); +__LA_DECL int archive_read_disk_can_descend(struct archive *); +__LA_DECL int archive_read_disk_current_filesystem(struct archive *); +__LA_DECL int archive_read_disk_current_filesystem_is_synthetic(struct archive *); +__LA_DECL int archive_read_disk_current_filesystem_is_remote(struct archive *); +/* Request that the access time of the entry visited by traversal be restored. */ +__LA_DECL int archive_read_disk_set_atime_restored(struct archive *); +/* + * Set behavior. The "flags" argument selects optional behavior. + */ +/* Request that the access time of the entry visited by traversal be restored. + * This is the same as archive_read_disk_set_atime_restored. */ +#define ARCHIVE_READDISK_RESTORE_ATIME (0x0001) +/* Default: Do not skip an entry which has nodump flags. */ +#define ARCHIVE_READDISK_HONOR_NODUMP (0x0002) +/* Default: Skip a mac resource fork file whose prefix is "._" because of + * using copyfile. */ +#define ARCHIVE_READDISK_MAC_COPYFILE (0x0004) +/* Default: Traverse mount points. */ +#define ARCHIVE_READDISK_NO_TRAVERSE_MOUNTS (0x0008) +/* Default: Xattrs are read from disk. */ +#define ARCHIVE_READDISK_NO_XATTR (0x0010) +/* Default: ACLs are read from disk. */ +#define ARCHIVE_READDISK_NO_ACL (0x0020) +/* Default: File flags are read from disk. */ +#define ARCHIVE_READDISK_NO_FFLAGS (0x0040) + +__LA_DECL int archive_read_disk_set_behavior(struct archive *, + int flags); + +/* + * Set archive_match object that will be used in archive_read_disk to + * know whether an entry should be skipped. The callback function + * _excluded_func will be invoked when an entry is skipped by the result + * of archive_match. + */ +__LA_DECL int archive_read_disk_set_matching(struct archive *, + struct archive *_matching, void (*_excluded_func) + (struct archive *, void *, struct archive_entry *), + void *_client_data); +__LA_DECL int archive_read_disk_set_metadata_filter_callback(struct archive *, + int (*_metadata_filter_func)(struct archive *, void *, + struct archive_entry *), void *_client_data); + +/* Simplified cleanup interface; + * This calls archive_read_free() or archive_write_free() as needed. */ +__LA_DECL int archive_free(struct archive *); + +/* + * Accessor functions to read/set various information in + * the struct archive object: + */ + +/* Number of filters in the current filter pipeline. */ +/* Filter #0 is the one closest to the format, -1 is a synonym for the + * last filter, which is always the pseudo-filter that wraps the + * client callbacks. */ +__LA_DECL int archive_filter_count(struct archive *); +__LA_DECL la_int64_t archive_filter_bytes(struct archive *, int); +__LA_DECL int archive_filter_code(struct archive *, int); +__LA_DECL const char * archive_filter_name(struct archive *, int); + +#if ARCHIVE_VERSION_NUMBER < 4000000 +/* These don't properly handle multiple filters, so are deprecated and + * will eventually be removed. */ +/* As of libarchive 3.0, this is an alias for archive_filter_bytes(a, -1); */ +__LA_DECL la_int64_t archive_position_compressed(struct archive *) + __LA_DEPRECATED; +/* As of libarchive 3.0, this is an alias for archive_filter_bytes(a, 0); */ +__LA_DECL la_int64_t archive_position_uncompressed(struct archive *) + __LA_DEPRECATED; +/* As of libarchive 3.0, this is an alias for archive_filter_name(a, 0); */ +__LA_DECL const char *archive_compression_name(struct archive *) + __LA_DEPRECATED; +/* As of libarchive 3.0, this is an alias for archive_filter_code(a, 0); */ +__LA_DECL int archive_compression(struct archive *) + __LA_DEPRECATED; +#endif + +__LA_DECL int archive_errno(struct archive *); +__LA_DECL const char *archive_error_string(struct archive *); +__LA_DECL const char *archive_format_name(struct archive *); +__LA_DECL int archive_format(struct archive *); +__LA_DECL void archive_clear_error(struct archive *); +__LA_DECL void archive_set_error(struct archive *, int _err, + const char *fmt, ...) __LA_PRINTF(3, 4); +__LA_DECL void archive_copy_error(struct archive *dest, + struct archive *src); +__LA_DECL int archive_file_count(struct archive *); + +/* + * ARCHIVE_MATCH API + */ +__LA_DECL struct archive *archive_match_new(void); +__LA_DECL int archive_match_free(struct archive *); + +/* + * Test if archive_entry is excluded. + * This is a convenience function. This is the same as calling all + * archive_match_path_excluded, archive_match_time_excluded + * and archive_match_owner_excluded. + */ +__LA_DECL int archive_match_excluded(struct archive *, + struct archive_entry *); + +/* + * Test if pathname is excluded. The conditions are set by following functions. + */ +__LA_DECL int archive_match_path_excluded(struct archive *, + struct archive_entry *); +/* Add exclusion pathname pattern. */ +__LA_DECL int archive_match_exclude_pattern(struct archive *, const char *); +__LA_DECL int archive_match_exclude_pattern_w(struct archive *, + const wchar_t *); +/* Add exclusion pathname pattern from file. */ +__LA_DECL int archive_match_exclude_pattern_from_file(struct archive *, + const char *, int _nullSeparator); +__LA_DECL int archive_match_exclude_pattern_from_file_w(struct archive *, + const wchar_t *, int _nullSeparator); +/* Add inclusion pathname pattern. */ +__LA_DECL int archive_match_include_pattern(struct archive *, const char *); +__LA_DECL int archive_match_include_pattern_w(struct archive *, + const wchar_t *); +/* Add inclusion pathname pattern from file. */ +__LA_DECL int archive_match_include_pattern_from_file(struct archive *, + const char *, int _nullSeparator); +__LA_DECL int archive_match_include_pattern_from_file_w(struct archive *, + const wchar_t *, int _nullSeparator); +/* + * How to get statistic information for inclusion patterns. + */ +/* Return the amount number of unmatched inclusion patterns. */ +__LA_DECL int archive_match_path_unmatched_inclusions(struct archive *); +/* Return the pattern of unmatched inclusion with ARCHIVE_OK. + * Return ARCHIVE_EOF if there is no inclusion pattern. */ +__LA_DECL int archive_match_path_unmatched_inclusions_next( + struct archive *, const char **); +__LA_DECL int archive_match_path_unmatched_inclusions_next_w( + struct archive *, const wchar_t **); + +/* + * Test if a file is excluded by its time stamp. + * The conditions are set by following functions. + */ +__LA_DECL int archive_match_time_excluded(struct archive *, + struct archive_entry *); + +/* + * Flags to tell a matching type of time stamps. These are used for + * following functions. + */ +/* Time flag: mtime to be tested. */ +#define ARCHIVE_MATCH_MTIME (0x0100) +/* Time flag: ctime to be tested. */ +#define ARCHIVE_MATCH_CTIME (0x0200) +/* Comparison flag: Match the time if it is newer than. */ +#define ARCHIVE_MATCH_NEWER (0x0001) +/* Comparison flag: Match the time if it is older than. */ +#define ARCHIVE_MATCH_OLDER (0x0002) +/* Comparison flag: Match the time if it is equal to. */ +#define ARCHIVE_MATCH_EQUAL (0x0010) +/* Set inclusion time. */ +__LA_DECL int archive_match_include_time(struct archive *, int _flag, + time_t _sec, long _nsec); +/* Set inclusion time by a date string. */ +__LA_DECL int archive_match_include_date(struct archive *, int _flag, + const char *_datestr); +__LA_DECL int archive_match_include_date_w(struct archive *, int _flag, + const wchar_t *_datestr); +/* Set inclusion time by a particular file. */ +__LA_DECL int archive_match_include_file_time(struct archive *, + int _flag, const char *_pathname); +__LA_DECL int archive_match_include_file_time_w(struct archive *, + int _flag, const wchar_t *_pathname); +/* Add exclusion entry. */ +__LA_DECL int archive_match_exclude_entry(struct archive *, + int _flag, struct archive_entry *); + +/* + * Test if a file is excluded by its uid ,gid, uname or gname. + * The conditions are set by following functions. + */ +__LA_DECL int archive_match_owner_excluded(struct archive *, + struct archive_entry *); +/* Add inclusion uid, gid, uname and gname. */ +__LA_DECL int archive_match_include_uid(struct archive *, la_int64_t); +__LA_DECL int archive_match_include_gid(struct archive *, la_int64_t); +__LA_DECL int archive_match_include_uname(struct archive *, const char *); +__LA_DECL int archive_match_include_uname_w(struct archive *, + const wchar_t *); +__LA_DECL int archive_match_include_gname(struct archive *, const char *); +__LA_DECL int archive_match_include_gname_w(struct archive *, + const wchar_t *); + +/* Utility functions */ +/* Convenience function to sort a NULL terminated list of strings */ +__LA_DECL int archive_utility_string_sort(char **); + +#ifdef __cplusplus +} +#endif + +/* These are meaningless outside of this header. */ +#undef __LA_DECL + +#endif /* !ARCHIVE_H_INCLUDED */ diff --cc Utilities/cmlibarchive/libarchive/archive_entry.h index 8c8e75a,0000000..a9134f6 mode 100644,000000..100644 --- a/Utilities/cmlibarchive/libarchive/archive_entry.h +++ b/Utilities/cmlibarchive/libarchive/archive_entry.h @@@ -1,699 -1,0 +1,700 @@@ +/*- + * Copyright (c) 2003-2008 Tim Kientzle + * Copyright (c) 2016 Martin Matuska + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD: head/lib/libarchive/archive_entry.h 201096 2009-12-28 02:41:27Z kientzle $ + */ + +#ifndef ARCHIVE_ENTRY_H_INCLUDED +#define ARCHIVE_ENTRY_H_INCLUDED + +/* Note: Compiler will complain if this does not match archive.h! */ - #define ARCHIVE_VERSION_NUMBER 3003002 ++#define ARCHIVE_VERSION_NUMBER 3003003 + +/* + * Note: archive_entry.h is for use outside of libarchive; the + * configuration headers (config.h, archive_platform.h, etc.) are + * purely internal. Do NOT use HAVE_XXX configuration macros to + * control the behavior of this header! If you must conditionalize, + * use predefined compiler and/or platform macros. + */ + +#include +#include /* for wchar_t */ ++#include +#include + +#if defined(_WIN32) && !defined(__CYGWIN__) +#include +#endif + +/* Get a suitable 64-bit integer type. */ +#if !defined(__LA_INT64_T_DEFINED) +# if ARCHIVE_VERSION_NUMBER < 4000000 +#define __LA_INT64_T la_int64_t +# endif +#define __LA_INT64_T_DEFINED +# if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__WATCOMC__) +typedef __int64 la_int64_t; +# else +#include +# if defined(_SCO_DS) || defined(__osf__) +typedef long long la_int64_t; +# else +typedef int64_t la_int64_t; +# endif +# endif +#endif + +/* The la_ssize_t should match the type used in 'struct stat' */ +#if !defined(__LA_SSIZE_T_DEFINED) +/* Older code relied on the __LA_SSIZE_T macro; after 4.0 we'll switch to the typedef exclusively. */ +# if ARCHIVE_VERSION_NUMBER < 4000000 +#define __LA_SSIZE_T la_ssize_t +# endif +#define __LA_SSIZE_T_DEFINED +# if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__WATCOMC__) +# if defined(_SSIZE_T_DEFINED) || defined(_SSIZE_T_) +typedef ssize_t la_ssize_t; +# elif defined(_WIN64) +typedef __int64 la_ssize_t; +# else +typedef long la_ssize_t; +# endif +# else +# include /* ssize_t */ +typedef ssize_t la_ssize_t; +# endif +#endif + +/* Get a suitable definition for mode_t */ +#if ARCHIVE_VERSION_NUMBER >= 3999000 +/* Switch to plain 'int' for libarchive 4.0. It's less broken than 'mode_t' */ +# define __LA_MODE_T int +#elif defined(_WIN32) && !defined(__CYGWIN__) && !defined(__BORLANDC__) && !defined(__WATCOMC__) +# define __LA_MODE_T unsigned short +#else +# define __LA_MODE_T mode_t +#endif + +/* Large file support for Android */ +#ifdef __ANDROID__ +#include "android_lf.h" +#endif + +/* + * On Windows, define LIBARCHIVE_STATIC if you're building or using a + * .lib. The default here assumes you're building a DLL. Only + * libarchive source should ever define __LIBARCHIVE_BUILD. + */ +#if ((defined __WIN32__) || (defined _WIN32) || defined(__CYGWIN__)) && (!defined LIBARCHIVE_STATIC) +# ifdef __LIBARCHIVE_BUILD +# ifdef __GNUC__ +# define __LA_DECL __attribute__((dllexport)) extern +# else +# define __LA_DECL __declspec(dllexport) +# endif +# else +# ifdef __GNUC__ +# define __LA_DECL +# else +# define __LA_DECL __declspec(dllimport) +# endif +# endif +#else +/* Static libraries on all platforms and shared libraries on non-Windows. */ +# define __LA_DECL +#endif + +/* CMake uses some deprecated APIs to build with old libarchive versions. */ +#define __LA_DEPRECATED + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Description of an archive entry. + * + * You can think of this as "struct stat" with some text fields added in. + * + * TODO: Add "comment", "charset", and possibly other entries that are + * supported by "pax interchange" format. However, GNU, ustar, cpio, + * and other variants don't support these features, so they're not an + * excruciatingly high priority right now. + * + * TODO: "pax interchange" format allows essentially arbitrary + * key/value attributes to be attached to any entry. Supporting + * such extensions may make this library useful for special + * applications (e.g., a package manager could attach special + * package-management attributes to each entry). + */ +struct archive; +struct archive_entry; + +/* + * File-type constants. These are returned from archive_entry_filetype() + * and passed to archive_entry_set_filetype(). + * + * These values match S_XXX defines on every platform I've checked, + * including Windows, AIX, Linux, Solaris, and BSD. They're + * (re)defined here because platforms generally don't define the ones + * they don't support. For example, Windows doesn't define S_IFLNK or + * S_IFBLK. Instead of having a mass of conditional logic and system + * checks to define any S_XXX values that aren't supported locally, + * I've just defined a new set of such constants so that + * libarchive-based applications can manipulate and identify archive + * entries properly even if the hosting platform can't store them on + * disk. + * + * These values are also used directly within some portable formats, + * such as cpio. If you find a platform that varies from these, the + * correct solution is to leave these alone and translate from these + * portable values to platform-native values when entries are read from + * or written to disk. + */ +/* + * In libarchive 4.0, we can drop the casts here. + * They're needed to work around Borland C's broken mode_t. + */ +#define AE_IFMT ((__LA_MODE_T)0170000) +#define AE_IFREG ((__LA_MODE_T)0100000) +#define AE_IFLNK ((__LA_MODE_T)0120000) +#define AE_IFSOCK ((__LA_MODE_T)0140000) +#define AE_IFCHR ((__LA_MODE_T)0020000) +#define AE_IFBLK ((__LA_MODE_T)0060000) +#define AE_IFDIR ((__LA_MODE_T)0040000) +#define AE_IFIFO ((__LA_MODE_T)0010000) + +/* + * Basic object manipulation + */ + +__LA_DECL struct archive_entry *archive_entry_clear(struct archive_entry *); +/* The 'clone' function does a deep copy; all of the strings are copied too. */ +__LA_DECL struct archive_entry *archive_entry_clone(struct archive_entry *); +__LA_DECL void archive_entry_free(struct archive_entry *); +__LA_DECL struct archive_entry *archive_entry_new(void); + +/* + * This form of archive_entry_new2() will pull character-set + * conversion information from the specified archive handle. The + * older archive_entry_new(void) form is equivalent to calling + * archive_entry_new2(NULL) and will result in the use of an internal + * default character-set conversion. + */ +__LA_DECL struct archive_entry *archive_entry_new2(struct archive *); + +/* + * Retrieve fields from an archive_entry. + * + * There are a number of implicit conversions among these fields. For + * example, if a regular string field is set and you read the _w wide + * character field, the entry will implicitly convert narrow-to-wide + * using the current locale. Similarly, dev values are automatically + * updated when you write devmajor or devminor and vice versa. + * + * In addition, fields can be "set" or "unset." Unset string fields + * return NULL, non-string fields have _is_set() functions to test + * whether they've been set. You can "unset" a string field by + * assigning NULL; non-string fields have _unset() functions to + * unset them. + * + * Note: There is one ambiguity in the above; string fields will + * also return NULL when implicit character set conversions fail. + * This is usually what you want. + */ +__LA_DECL time_t archive_entry_atime(struct archive_entry *); +__LA_DECL long archive_entry_atime_nsec(struct archive_entry *); +__LA_DECL int archive_entry_atime_is_set(struct archive_entry *); +__LA_DECL time_t archive_entry_birthtime(struct archive_entry *); +__LA_DECL long archive_entry_birthtime_nsec(struct archive_entry *); +__LA_DECL int archive_entry_birthtime_is_set(struct archive_entry *); +__LA_DECL time_t archive_entry_ctime(struct archive_entry *); +__LA_DECL long archive_entry_ctime_nsec(struct archive_entry *); +__LA_DECL int archive_entry_ctime_is_set(struct archive_entry *); +__LA_DECL dev_t archive_entry_dev(struct archive_entry *); +__LA_DECL int archive_entry_dev_is_set(struct archive_entry *); +__LA_DECL dev_t archive_entry_devmajor(struct archive_entry *); +__LA_DECL dev_t archive_entry_devminor(struct archive_entry *); +__LA_DECL __LA_MODE_T archive_entry_filetype(struct archive_entry *); +__LA_DECL void archive_entry_fflags(struct archive_entry *, + unsigned long * /* set */, + unsigned long * /* clear */); +__LA_DECL const char *archive_entry_fflags_text(struct archive_entry *); +__LA_DECL la_int64_t archive_entry_gid(struct archive_entry *); +__LA_DECL const char *archive_entry_gname(struct archive_entry *); +__LA_DECL const char *archive_entry_gname_utf8(struct archive_entry *); +__LA_DECL const wchar_t *archive_entry_gname_w(struct archive_entry *); +__LA_DECL const char *archive_entry_hardlink(struct archive_entry *); +__LA_DECL const char *archive_entry_hardlink_utf8(struct archive_entry *); +__LA_DECL const wchar_t *archive_entry_hardlink_w(struct archive_entry *); +__LA_DECL la_int64_t archive_entry_ino(struct archive_entry *); +__LA_DECL la_int64_t archive_entry_ino64(struct archive_entry *); +__LA_DECL int archive_entry_ino_is_set(struct archive_entry *); +__LA_DECL __LA_MODE_T archive_entry_mode(struct archive_entry *); +__LA_DECL time_t archive_entry_mtime(struct archive_entry *); +__LA_DECL long archive_entry_mtime_nsec(struct archive_entry *); +__LA_DECL int archive_entry_mtime_is_set(struct archive_entry *); +__LA_DECL unsigned int archive_entry_nlink(struct archive_entry *); +__LA_DECL const char *archive_entry_pathname(struct archive_entry *); +__LA_DECL const char *archive_entry_pathname_utf8(struct archive_entry *); +__LA_DECL const wchar_t *archive_entry_pathname_w(struct archive_entry *); +__LA_DECL __LA_MODE_T archive_entry_perm(struct archive_entry *); +__LA_DECL dev_t archive_entry_rdev(struct archive_entry *); +__LA_DECL dev_t archive_entry_rdevmajor(struct archive_entry *); +__LA_DECL dev_t archive_entry_rdevminor(struct archive_entry *); +__LA_DECL const char *archive_entry_sourcepath(struct archive_entry *); +__LA_DECL const wchar_t *archive_entry_sourcepath_w(struct archive_entry *); +__LA_DECL la_int64_t archive_entry_size(struct archive_entry *); +__LA_DECL int archive_entry_size_is_set(struct archive_entry *); +__LA_DECL const char *archive_entry_strmode(struct archive_entry *); +__LA_DECL const char *archive_entry_symlink(struct archive_entry *); +__LA_DECL const char *archive_entry_symlink_utf8(struct archive_entry *); +__LA_DECL const wchar_t *archive_entry_symlink_w(struct archive_entry *); +__LA_DECL la_int64_t archive_entry_uid(struct archive_entry *); +__LA_DECL const char *archive_entry_uname(struct archive_entry *); +__LA_DECL const char *archive_entry_uname_utf8(struct archive_entry *); +__LA_DECL const wchar_t *archive_entry_uname_w(struct archive_entry *); +__LA_DECL int archive_entry_is_data_encrypted(struct archive_entry *); +__LA_DECL int archive_entry_is_metadata_encrypted(struct archive_entry *); +__LA_DECL int archive_entry_is_encrypted(struct archive_entry *); + +/* + * Set fields in an archive_entry. + * + * Note: Before libarchive 2.4, there were 'set' and 'copy' versions + * of the string setters. 'copy' copied the actual string, 'set' just + * stored the pointer. In libarchive 2.4 and later, strings are + * always copied. + */ + +__LA_DECL void archive_entry_set_atime(struct archive_entry *, time_t, long); +__LA_DECL void archive_entry_unset_atime(struct archive_entry *); +#if defined(_WIN32) && !defined(__CYGWIN__) +__LA_DECL void archive_entry_copy_bhfi(struct archive_entry *, struct _BY_HANDLE_FILE_INFORMATION *); +#endif +__LA_DECL void archive_entry_set_birthtime(struct archive_entry *, time_t, long); +__LA_DECL void archive_entry_unset_birthtime(struct archive_entry *); +__LA_DECL void archive_entry_set_ctime(struct archive_entry *, time_t, long); +__LA_DECL void archive_entry_unset_ctime(struct archive_entry *); +__LA_DECL void archive_entry_set_dev(struct archive_entry *, dev_t); +__LA_DECL void archive_entry_set_devmajor(struct archive_entry *, dev_t); +__LA_DECL void archive_entry_set_devminor(struct archive_entry *, dev_t); +__LA_DECL void archive_entry_set_filetype(struct archive_entry *, unsigned int); +__LA_DECL void archive_entry_set_fflags(struct archive_entry *, + unsigned long /* set */, unsigned long /* clear */); +/* Returns pointer to start of first invalid token, or NULL if none. */ +/* Note that all recognized tokens are processed, regardless. */ +__LA_DECL const char *archive_entry_copy_fflags_text(struct archive_entry *, + const char *); +__LA_DECL const wchar_t *archive_entry_copy_fflags_text_w(struct archive_entry *, + const wchar_t *); +__LA_DECL void archive_entry_set_gid(struct archive_entry *, la_int64_t); +__LA_DECL void archive_entry_set_gname(struct archive_entry *, const char *); +__LA_DECL void archive_entry_set_gname_utf8(struct archive_entry *, const char *); +__LA_DECL void archive_entry_copy_gname(struct archive_entry *, const char *); +__LA_DECL void archive_entry_copy_gname_w(struct archive_entry *, const wchar_t *); +__LA_DECL int archive_entry_update_gname_utf8(struct archive_entry *, const char *); +__LA_DECL void archive_entry_set_hardlink(struct archive_entry *, const char *); +__LA_DECL void archive_entry_set_hardlink_utf8(struct archive_entry *, const char *); +__LA_DECL void archive_entry_copy_hardlink(struct archive_entry *, const char *); +__LA_DECL void archive_entry_copy_hardlink_w(struct archive_entry *, const wchar_t *); +__LA_DECL int archive_entry_update_hardlink_utf8(struct archive_entry *, const char *); +__LA_DECL void archive_entry_set_ino(struct archive_entry *, la_int64_t); +__LA_DECL void archive_entry_set_ino64(struct archive_entry *, la_int64_t); +__LA_DECL void archive_entry_set_link(struct archive_entry *, const char *); +__LA_DECL void archive_entry_set_link_utf8(struct archive_entry *, const char *); +__LA_DECL void archive_entry_copy_link(struct archive_entry *, const char *); +__LA_DECL void archive_entry_copy_link_w(struct archive_entry *, const wchar_t *); +__LA_DECL int archive_entry_update_link_utf8(struct archive_entry *, const char *); +__LA_DECL void archive_entry_set_mode(struct archive_entry *, __LA_MODE_T); +__LA_DECL void archive_entry_set_mtime(struct archive_entry *, time_t, long); +__LA_DECL void archive_entry_unset_mtime(struct archive_entry *); +__LA_DECL void archive_entry_set_nlink(struct archive_entry *, unsigned int); +__LA_DECL void archive_entry_set_pathname(struct archive_entry *, const char *); +__LA_DECL void archive_entry_set_pathname_utf8(struct archive_entry *, const char *); +__LA_DECL void archive_entry_copy_pathname(struct archive_entry *, const char *); +__LA_DECL void archive_entry_copy_pathname_w(struct archive_entry *, const wchar_t *); +__LA_DECL int archive_entry_update_pathname_utf8(struct archive_entry *, const char *); +__LA_DECL void archive_entry_set_perm(struct archive_entry *, __LA_MODE_T); +__LA_DECL void archive_entry_set_rdev(struct archive_entry *, dev_t); +__LA_DECL void archive_entry_set_rdevmajor(struct archive_entry *, dev_t); +__LA_DECL void archive_entry_set_rdevminor(struct archive_entry *, dev_t); +__LA_DECL void archive_entry_set_size(struct archive_entry *, la_int64_t); +__LA_DECL void archive_entry_unset_size(struct archive_entry *); +__LA_DECL void archive_entry_copy_sourcepath(struct archive_entry *, const char *); +__LA_DECL void archive_entry_copy_sourcepath_w(struct archive_entry *, const wchar_t *); +__LA_DECL void archive_entry_set_symlink(struct archive_entry *, const char *); +__LA_DECL void archive_entry_set_symlink_utf8(struct archive_entry *, const char *); +__LA_DECL void archive_entry_copy_symlink(struct archive_entry *, const char *); +__LA_DECL void archive_entry_copy_symlink_w(struct archive_entry *, const wchar_t *); +__LA_DECL int archive_entry_update_symlink_utf8(struct archive_entry *, const char *); +__LA_DECL void archive_entry_set_uid(struct archive_entry *, la_int64_t); +__LA_DECL void archive_entry_set_uname(struct archive_entry *, const char *); +__LA_DECL void archive_entry_set_uname_utf8(struct archive_entry *, const char *); +__LA_DECL void archive_entry_copy_uname(struct archive_entry *, const char *); +__LA_DECL void archive_entry_copy_uname_w(struct archive_entry *, const wchar_t *); +__LA_DECL int archive_entry_update_uname_utf8(struct archive_entry *, const char *); +__LA_DECL void archive_entry_set_is_data_encrypted(struct archive_entry *, char is_encrypted); +__LA_DECL void archive_entry_set_is_metadata_encrypted(struct archive_entry *, char is_encrypted); +/* + * Routines to bulk copy fields to/from a platform-native "struct + * stat." Libarchive used to just store a struct stat inside of each + * archive_entry object, but this created issues when trying to + * manipulate archives on systems different than the ones they were + * created on. + * + * TODO: On Linux and other LFS systems, provide both stat32 and + * stat64 versions of these functions and all of the macro glue so + * that archive_entry_stat is magically defined to + * archive_entry_stat32 or archive_entry_stat64 as appropriate. + */ +__LA_DECL const struct stat *archive_entry_stat(struct archive_entry *); +__LA_DECL void archive_entry_copy_stat(struct archive_entry *, const struct stat *); + +/* + * Storage for Mac OS-specific AppleDouble metadata information. + * Apple-format tar files store a separate binary blob containing + * encoded metadata with ACL, extended attributes, etc. + * This provides a place to store that blob. + */ + +__LA_DECL const void * archive_entry_mac_metadata(struct archive_entry *, size_t *); +__LA_DECL void archive_entry_copy_mac_metadata(struct archive_entry *, const void *, size_t); + +/* + * ACL routines. This used to simply store and return text-format ACL + * strings, but that proved insufficient for a number of reasons: + * = clients need control over uname/uid and gname/gid mappings + * = there are many different ACL text formats + * = would like to be able to read/convert archives containing ACLs + * on platforms that lack ACL libraries + * + * This last point, in particular, forces me to implement a reasonably + * complete set of ACL support routines. + */ + +/* + * Permission bits. + */ +#define ARCHIVE_ENTRY_ACL_EXECUTE 0x00000001 +#define ARCHIVE_ENTRY_ACL_WRITE 0x00000002 +#define ARCHIVE_ENTRY_ACL_READ 0x00000004 +#define ARCHIVE_ENTRY_ACL_READ_DATA 0x00000008 +#define ARCHIVE_ENTRY_ACL_LIST_DIRECTORY 0x00000008 +#define ARCHIVE_ENTRY_ACL_WRITE_DATA 0x00000010 +#define ARCHIVE_ENTRY_ACL_ADD_FILE 0x00000010 +#define ARCHIVE_ENTRY_ACL_APPEND_DATA 0x00000020 +#define ARCHIVE_ENTRY_ACL_ADD_SUBDIRECTORY 0x00000020 +#define ARCHIVE_ENTRY_ACL_READ_NAMED_ATTRS 0x00000040 +#define ARCHIVE_ENTRY_ACL_WRITE_NAMED_ATTRS 0x00000080 +#define ARCHIVE_ENTRY_ACL_DELETE_CHILD 0x00000100 +#define ARCHIVE_ENTRY_ACL_READ_ATTRIBUTES 0x00000200 +#define ARCHIVE_ENTRY_ACL_WRITE_ATTRIBUTES 0x00000400 +#define ARCHIVE_ENTRY_ACL_DELETE 0x00000800 +#define ARCHIVE_ENTRY_ACL_READ_ACL 0x00001000 +#define ARCHIVE_ENTRY_ACL_WRITE_ACL 0x00002000 +#define ARCHIVE_ENTRY_ACL_WRITE_OWNER 0x00004000 +#define ARCHIVE_ENTRY_ACL_SYNCHRONIZE 0x00008000 + +#define ARCHIVE_ENTRY_ACL_PERMS_POSIX1E \ + (ARCHIVE_ENTRY_ACL_EXECUTE \ + | ARCHIVE_ENTRY_ACL_WRITE \ + | ARCHIVE_ENTRY_ACL_READ) + +#define ARCHIVE_ENTRY_ACL_PERMS_NFS4 \ + (ARCHIVE_ENTRY_ACL_EXECUTE \ + | ARCHIVE_ENTRY_ACL_READ_DATA \ + | ARCHIVE_ENTRY_ACL_LIST_DIRECTORY \ + | ARCHIVE_ENTRY_ACL_WRITE_DATA \ + | ARCHIVE_ENTRY_ACL_ADD_FILE \ + | ARCHIVE_ENTRY_ACL_APPEND_DATA \ + | ARCHIVE_ENTRY_ACL_ADD_SUBDIRECTORY \ + | ARCHIVE_ENTRY_ACL_READ_NAMED_ATTRS \ + | ARCHIVE_ENTRY_ACL_WRITE_NAMED_ATTRS \ + | ARCHIVE_ENTRY_ACL_DELETE_CHILD \ + | ARCHIVE_ENTRY_ACL_READ_ATTRIBUTES \ + | ARCHIVE_ENTRY_ACL_WRITE_ATTRIBUTES \ + | ARCHIVE_ENTRY_ACL_DELETE \ + | ARCHIVE_ENTRY_ACL_READ_ACL \ + | ARCHIVE_ENTRY_ACL_WRITE_ACL \ + | ARCHIVE_ENTRY_ACL_WRITE_OWNER \ + | ARCHIVE_ENTRY_ACL_SYNCHRONIZE) + +/* + * Inheritance values (NFS4 ACLs only); included in permset. + */ +#define ARCHIVE_ENTRY_ACL_ENTRY_INHERITED 0x01000000 +#define ARCHIVE_ENTRY_ACL_ENTRY_FILE_INHERIT 0x02000000 +#define ARCHIVE_ENTRY_ACL_ENTRY_DIRECTORY_INHERIT 0x04000000 +#define ARCHIVE_ENTRY_ACL_ENTRY_NO_PROPAGATE_INHERIT 0x08000000 +#define ARCHIVE_ENTRY_ACL_ENTRY_INHERIT_ONLY 0x10000000 +#define ARCHIVE_ENTRY_ACL_ENTRY_SUCCESSFUL_ACCESS 0x20000000 +#define ARCHIVE_ENTRY_ACL_ENTRY_FAILED_ACCESS 0x40000000 + +#define ARCHIVE_ENTRY_ACL_INHERITANCE_NFS4 \ + (ARCHIVE_ENTRY_ACL_ENTRY_FILE_INHERIT \ + | ARCHIVE_ENTRY_ACL_ENTRY_DIRECTORY_INHERIT \ + | ARCHIVE_ENTRY_ACL_ENTRY_NO_PROPAGATE_INHERIT \ + | ARCHIVE_ENTRY_ACL_ENTRY_INHERIT_ONLY \ + | ARCHIVE_ENTRY_ACL_ENTRY_SUCCESSFUL_ACCESS \ + | ARCHIVE_ENTRY_ACL_ENTRY_FAILED_ACCESS \ + | ARCHIVE_ENTRY_ACL_ENTRY_INHERITED) + +/* We need to be able to specify combinations of these. */ +#define ARCHIVE_ENTRY_ACL_TYPE_ACCESS 0x00000100 /* POSIX.1e only */ +#define ARCHIVE_ENTRY_ACL_TYPE_DEFAULT 0x00000200 /* POSIX.1e only */ +#define ARCHIVE_ENTRY_ACL_TYPE_ALLOW 0x00000400 /* NFS4 only */ +#define ARCHIVE_ENTRY_ACL_TYPE_DENY 0x00000800 /* NFS4 only */ +#define ARCHIVE_ENTRY_ACL_TYPE_AUDIT 0x00001000 /* NFS4 only */ +#define ARCHIVE_ENTRY_ACL_TYPE_ALARM 0x00002000 /* NFS4 only */ +#define ARCHIVE_ENTRY_ACL_TYPE_POSIX1E (ARCHIVE_ENTRY_ACL_TYPE_ACCESS \ + | ARCHIVE_ENTRY_ACL_TYPE_DEFAULT) +#define ARCHIVE_ENTRY_ACL_TYPE_NFS4 (ARCHIVE_ENTRY_ACL_TYPE_ALLOW \ + | ARCHIVE_ENTRY_ACL_TYPE_DENY \ + | ARCHIVE_ENTRY_ACL_TYPE_AUDIT \ + | ARCHIVE_ENTRY_ACL_TYPE_ALARM) + +/* Tag values mimic POSIX.1e */ +#define ARCHIVE_ENTRY_ACL_USER 10001 /* Specified user. */ +#define ARCHIVE_ENTRY_ACL_USER_OBJ 10002 /* User who owns the file. */ +#define ARCHIVE_ENTRY_ACL_GROUP 10003 /* Specified group. */ +#define ARCHIVE_ENTRY_ACL_GROUP_OBJ 10004 /* Group who owns the file. */ +#define ARCHIVE_ENTRY_ACL_MASK 10005 /* Modify group access (POSIX.1e only) */ +#define ARCHIVE_ENTRY_ACL_OTHER 10006 /* Public (POSIX.1e only) */ +#define ARCHIVE_ENTRY_ACL_EVERYONE 10107 /* Everyone (NFS4 only) */ + +/* + * Set the ACL by clearing it and adding entries one at a time. + * Unlike the POSIX.1e ACL routines, you must specify the type + * (access/default) for each entry. Internally, the ACL data is just + * a soup of entries. API calls here allow you to retrieve just the + * entries of interest. This design (which goes against the spirit of + * POSIX.1e) is useful for handling archive formats that combine + * default and access information in a single ACL list. + */ +__LA_DECL void archive_entry_acl_clear(struct archive_entry *); +__LA_DECL int archive_entry_acl_add_entry(struct archive_entry *, + int /* type */, int /* permset */, int /* tag */, + int /* qual */, const char * /* name */); +__LA_DECL int archive_entry_acl_add_entry_w(struct archive_entry *, + int /* type */, int /* permset */, int /* tag */, + int /* qual */, const wchar_t * /* name */); + +/* + * To retrieve the ACL, first "reset", then repeatedly ask for the + * "next" entry. The want_type parameter allows you to request only + * certain types of entries. + */ +__LA_DECL int archive_entry_acl_reset(struct archive_entry *, int /* want_type */); +__LA_DECL int archive_entry_acl_next(struct archive_entry *, int /* want_type */, + int * /* type */, int * /* permset */, int * /* tag */, + int * /* qual */, const char ** /* name */); +__LA_DECL int archive_entry_acl_next_w(struct archive_entry *, int /* want_type */, + int * /* type */, int * /* permset */, int * /* tag */, + int * /* qual */, const wchar_t ** /* name */); + +/* + * Construct a text-format ACL. The flags argument is a bitmask that + * can include any of the following: + * + * Flags only for archive entries with POSIX.1e ACL: + * ARCHIVE_ENTRY_ACL_TYPE_ACCESS - Include POSIX.1e "access" entries. + * ARCHIVE_ENTRY_ACL_TYPE_DEFAULT - Include POSIX.1e "default" entries. + * ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT - Include "default:" before each + * default ACL entry. + * ARCHIVE_ENTRY_ACL_STYLE_SOLARIS - Output only one colon after "other" and + * "mask" entries. + * + * Flags only for archive entries with NFSv4 ACL: + * ARCHIVE_ENTRY_ACL_STYLE_COMPACT - Do not output the minus character for + * unset permissions and flags in NFSv4 ACL permission and flag fields + * + * Flags for for archive entries with POSIX.1e ACL or NFSv4 ACL: + * ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID - Include extra numeric ID field in + * each ACL entry. + * ARCHIVE_ENTRY_ACL_STYLE_SEPARATOR_COMMA - Separate entries with comma + * instead of newline. + */ +#define ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID 0x00000001 +#define ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT 0x00000002 +#define ARCHIVE_ENTRY_ACL_STYLE_SOLARIS 0x00000004 +#define ARCHIVE_ENTRY_ACL_STYLE_SEPARATOR_COMMA 0x00000008 +#define ARCHIVE_ENTRY_ACL_STYLE_COMPACT 0x00000010 + +__LA_DECL wchar_t *archive_entry_acl_to_text_w(struct archive_entry *, + la_ssize_t * /* len */, int /* flags */); +__LA_DECL char *archive_entry_acl_to_text(struct archive_entry *, + la_ssize_t * /* len */, int /* flags */); +__LA_DECL int archive_entry_acl_from_text_w(struct archive_entry *, + const wchar_t * /* wtext */, int /* type */); +__LA_DECL int archive_entry_acl_from_text(struct archive_entry *, + const char * /* text */, int /* type */); + +/* Deprecated constants */ +#define OLD_ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID 1024 +#define OLD_ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT 2048 + +/* Deprecated functions */ +__LA_DECL const wchar_t *archive_entry_acl_text_w(struct archive_entry *, + int /* flags */) __LA_DEPRECATED; +__LA_DECL const char *archive_entry_acl_text(struct archive_entry *, + int /* flags */) __LA_DEPRECATED; + +/* Return bitmask of ACL types in an archive entry */ +__LA_DECL int archive_entry_acl_types(struct archive_entry *); + +/* Return a count of entries matching 'want_type' */ +__LA_DECL int archive_entry_acl_count(struct archive_entry *, int /* want_type */); + +/* Return an opaque ACL object. */ +/* There's not yet anything clients can actually do with this... */ +struct archive_acl; +__LA_DECL struct archive_acl *archive_entry_acl(struct archive_entry *); + +/* + * extended attributes + */ + +__LA_DECL void archive_entry_xattr_clear(struct archive_entry *); +__LA_DECL void archive_entry_xattr_add_entry(struct archive_entry *, + const char * /* name */, const void * /* value */, + size_t /* size */); + +/* + * To retrieve the xattr list, first "reset", then repeatedly ask for the + * "next" entry. + */ + +__LA_DECL int archive_entry_xattr_count(struct archive_entry *); +__LA_DECL int archive_entry_xattr_reset(struct archive_entry *); +__LA_DECL int archive_entry_xattr_next(struct archive_entry *, + const char ** /* name */, const void ** /* value */, size_t *); + +/* + * sparse + */ + +__LA_DECL void archive_entry_sparse_clear(struct archive_entry *); +__LA_DECL void archive_entry_sparse_add_entry(struct archive_entry *, + la_int64_t /* offset */, la_int64_t /* length */); + +/* + * To retrieve the xattr list, first "reset", then repeatedly ask for the + * "next" entry. + */ + +__LA_DECL int archive_entry_sparse_count(struct archive_entry *); +__LA_DECL int archive_entry_sparse_reset(struct archive_entry *); +__LA_DECL int archive_entry_sparse_next(struct archive_entry *, + la_int64_t * /* offset */, la_int64_t * /* length */); + +/* + * Utility to match up hardlinks. + * + * The 'struct archive_entry_linkresolver' is a cache of archive entries + * for files with multiple links. Here's how to use it: + * 1. Create a lookup object with archive_entry_linkresolver_new() + * 2. Tell it the archive format you're using. + * 3. Hand each archive_entry to archive_entry_linkify(). + * That function will return 0, 1, or 2 entries that should + * be written. + * 4. Call archive_entry_linkify(resolver, NULL) until + * no more entries are returned. + * 5. Call archive_entry_linkresolver_free(resolver) to free resources. + * + * The entries returned have their hardlink and size fields updated + * appropriately. If an entry is passed in that does not refer to + * a file with multiple links, it is returned unchanged. The intention + * is that you should be able to simply filter all entries through + * this machine. + * + * To make things more efficient, be sure that each entry has a valid + * nlinks value. The hardlink cache uses this to track when all links + * have been found. If the nlinks value is zero, it will keep every + * name in the cache indefinitely, which can use a lot of memory. + * + * Note that archive_entry_size() is reset to zero if the file + * body should not be written to the archive. Pay attention! + */ +struct archive_entry_linkresolver; + +/* + * There are three different strategies for marking hardlinks. + * The descriptions below name them after the best-known + * formats that rely on each strategy: + * + * "Old cpio" is the simplest, it always returns any entry unmodified. + * As far as I know, only cpio formats use this. Old cpio archives + * store every link with the full body; the onus is on the dearchiver + * to detect and properly link the files as they are restored. + * "tar" is also pretty simple; it caches a copy the first time it sees + * any link. Subsequent appearances are modified to be hardlink + * references to the first one without any body. Used by all tar + * formats, although the newest tar formats permit the "old cpio" strategy + * as well. This strategy is very simple for the dearchiver, + * and reasonably straightforward for the archiver. + * "new cpio" is trickier. It stores the body only with the last + * occurrence. The complication is that we might not + * see every link to a particular file in a single session, so + * there's no easy way to know when we've seen the last occurrence. + * The solution here is to queue one link until we see the next. + * At the end of the session, you can enumerate any remaining + * entries by calling archive_entry_linkify(NULL) and store those + * bodies. If you have a file with three links l1, l2, and l3, + * you'll get the following behavior if you see all three links: + * linkify(l1) => NULL (the resolver stores l1 internally) + * linkify(l2) => l1 (resolver stores l2, you write l1) + * linkify(l3) => l2, l3 (all links seen, you can write both). + * If you only see l1 and l2, you'll get this behavior: + * linkify(l1) => NULL + * linkify(l2) => l1 + * linkify(NULL) => l2 (at end, you retrieve remaining links) + * As the name suggests, this strategy is used by newer cpio variants. + * It's noticeably more complex for the archiver, slightly more complex + * for the dearchiver than the tar strategy, but makes it straightforward + * to restore a file using any link by simply continuing to scan until + * you see a link that is stored with a body. In contrast, the tar + * strategy requires you to rescan the archive from the beginning to + * correctly extract an arbitrary link. + */ + +__LA_DECL struct archive_entry_linkresolver *archive_entry_linkresolver_new(void); +__LA_DECL void archive_entry_linkresolver_set_strategy( + struct archive_entry_linkresolver *, int /* format_code */); +__LA_DECL void archive_entry_linkresolver_free(struct archive_entry_linkresolver *); +__LA_DECL void archive_entry_linkify(struct archive_entry_linkresolver *, + struct archive_entry **, struct archive_entry **); +__LA_DECL struct archive_entry *archive_entry_partial_links( + struct archive_entry_linkresolver *res, unsigned int *links); + +#ifdef __cplusplus +} +#endif + +/* This is meaningless outside of this header. */ +#undef __LA_DECL + +#endif /* !ARCHIVE_ENTRY_H_INCLUDED */ diff --cc Utilities/cmlibarchive/libarchive/archive_platform.h index f33208c,0000000..e161e64 mode 100644,000000..100644 --- a/Utilities/cmlibarchive/libarchive/archive_platform.h +++ b/Utilities/cmlibarchive/libarchive/archive_platform.h @@@ -1,199 -1,0 +1,205 @@@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD: head/lib/libarchive/archive_platform.h 201090 2009-12-28 02:22:04Z kientzle $ + */ + +/* !!ONLY FOR USE INTERNALLY TO LIBARCHIVE!! */ + +/* + * This header is the first thing included in any of the libarchive + * source files. As far as possible, platform-specific issues should + * be dealt with here and not within individual source files. I'm + * actively trying to minimize #if blocks within the main source, + * since they obfuscate the code. + */ + +#ifndef ARCHIVE_PLATFORM_H_INCLUDED +#define ARCHIVE_PLATFORM_H_INCLUDED + +/* archive.h and archive_entry.h require this. */ +#define __LIBARCHIVE_BUILD 1 + +#if defined(PLATFORM_CONFIG_H) +/* Use hand-built config.h in environments that need it. */ +#include PLATFORM_CONFIG_H +#elif defined(HAVE_CONFIG_H) +/* Most POSIX platforms use the 'configure' script to build config.h */ +#include "config.h" +#else +/* Warn if the library hasn't been (automatically or manually) configured. */ +#error Oops: No config.h and no pre-built configuration in archive_platform.h. +#endif + +/* On macOS check for some symbols based on the deployment target version. */ +#if defined(__APPLE__) +# undef HAVE_FUTIMENS +# undef HAVE_UTIMENSAT +# include +# if MAC_OS_X_VERSION_MIN_REQUIRED >= 101300 +# define HAVE_FUTIMENS 1 +# define HAVE_UTIMENSAT 1 +# endif +#endif + +/* It should be possible to get rid of this by extending the feature-test + * macros to cover Windows API functions, probably along with non-trivial + * refactoring of code to find structures that sit more cleanly on top of + * either Windows or Posix APIs. */ +#if (defined(__WIN32__) || defined(_WIN32) || defined(__WIN32)) && !defined(__CYGWIN__) +#include "archive_windows.h" +#endif + +/* + * The config files define a lot of feature macros. The following + * uses those macros to select/define replacements and include key + * headers as required. + */ + +/* Get a real definition for __FBSDID or __RCSID if we can */ +#if HAVE_SYS_CDEFS_H +#include +#endif + +/* If not, define them so as to avoid dangling semicolons. */ +#ifndef __FBSDID +#define __FBSDID(a) struct _undefined_hack +#endif +#ifndef __RCSID +#define __RCSID(a) struct _undefined_hack +#endif + +/* Old glibc mbsnrtowcs fails assertions in our use case. */ +#if defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ <= 1 +# undef HAVE_MBSNRTOWCS +#endif + +/* Try to get standard C99-style integer type definitions. */ +#if HAVE_INTTYPES_H +#include +#endif +#if HAVE_STDINT_H +#include +#endif + +/* Borland warns about its own constants! */ +#if defined(__BORLANDC__) +# if HAVE_DECL_UINT64_MAX +# undef UINT64_MAX +# undef HAVE_DECL_UINT64_MAX +# endif +# if HAVE_DECL_UINT64_MIN +# undef UINT64_MIN +# undef HAVE_DECL_UINT64_MIN +# endif +# if HAVE_DECL_INT64_MAX +# undef INT64_MAX +# undef HAVE_DECL_INT64_MAX +# endif +# if HAVE_DECL_INT64_MIN +# undef INT64_MIN +# undef HAVE_DECL_INT64_MIN +# endif +#endif + +/* Some platforms lack the standard *_MAX definitions. */ +#if !HAVE_DECL_SIZE_MAX +#define SIZE_MAX (~(size_t)0) +#endif +#if !HAVE_DECL_SSIZE_MAX +#define SSIZE_MAX ((ssize_t)(SIZE_MAX >> 1)) +#endif +#if !HAVE_DECL_UINT32_MAX +#define UINT32_MAX (~(uint32_t)0) +#endif +#if !HAVE_DECL_INT32_MAX +#define INT32_MAX ((int32_t)(UINT32_MAX >> 1)) +#endif +#if !HAVE_DECL_INT32_MIN +#define INT32_MIN ((int32_t)(~INT32_MAX)) +#endif +#if !HAVE_DECL_UINT64_MAX +#define UINT64_MAX (~(uint64_t)0) +#endif +#if !HAVE_DECL_INT64_MAX +#define INT64_MAX ((int64_t)(UINT64_MAX >> 1)) +#endif +#if !HAVE_DECL_INT64_MIN +#define INT64_MIN ((int64_t)(~INT64_MAX)) +#endif +#if !HAVE_DECL_UINTMAX_MAX +#define UINTMAX_MAX (~(uintmax_t)0) +#endif +#if !HAVE_DECL_INTMAX_MAX +#define INTMAX_MAX ((intmax_t)(UINTMAX_MAX >> 1)) +#endif +#if !HAVE_DECL_INTMAX_MIN +#define INTMAX_MIN ((intmax_t)(~INTMAX_MAX)) +#endif + +/* + * If we can't restore metadata using a file descriptor, then + * for compatibility's sake, close files before trying to restore metadata. + */ +#if defined(HAVE_FCHMOD) || defined(HAVE_FUTIMES) || defined(HAVE_ACL_SET_FD) || defined(HAVE_ACL_SET_FD_NP) || defined(HAVE_FCHOWN) +#define CAN_RESTORE_METADATA_FD +#endif + +/* + * glibc 2.24 deprecates readdir_r + */ +#if defined(HAVE_READDIR_R) && (!defined(__GLIBC__) || !defined(__GLIBC_MINOR__) || __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 24)) +#define USE_READDIR_R 1 +#else +#undef USE_READDIR_R +#endif + +/* Set up defaults for internal error codes. */ +#ifndef ARCHIVE_ERRNO_FILE_FORMAT +#if HAVE_EFTYPE +#define ARCHIVE_ERRNO_FILE_FORMAT EFTYPE +#else +#if HAVE_EILSEQ +#define ARCHIVE_ERRNO_FILE_FORMAT EILSEQ +#else +#define ARCHIVE_ERRNO_FILE_FORMAT EINVAL +#endif +#endif +#endif + +#ifndef ARCHIVE_ERRNO_PROGRAMMER +#define ARCHIVE_ERRNO_PROGRAMMER EINVAL +#endif + +#ifndef ARCHIVE_ERRNO_MISC +#define ARCHIVE_ERRNO_MISC (-1) +#endif + ++#if defined(__GNUC__) && (__GNUC__ >= 7) ++#define __LA_FALLTHROUGH __attribute__((fallthrough)) ++#else ++#define __LA_FALLTHROUGH ++#endif ++ +#endif /* !ARCHIVE_PLATFORM_H_INCLUDED */ diff --cc Utilities/cmlibarchive/libarchive/archive_read_support_filter_zstd.c index 0000000,c8bb36b..c8bb36b mode 000000,100644..100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_zstd.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_zstd.c diff --cc Utilities/cmlibarchive/libarchive/archive_read_support_format_7zip.c index 96774f4,0000000..a885a4c mode 100644,000000..100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_7zip.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_7zip.c @@@ -1,3886 -1,0 +1,3873 @@@ +/*- + * Copyright (c) 2011 Michihiro NAKAJIMA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "archive_platform.h" +__FBSDID("$FreeBSD$"); + +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_BZLIB_H +#include +#endif +#ifdef HAVE_LZMA_H +#include +#endif +#ifdef HAVE_ZLIB_H +#include +#endif + +#include "archive.h" +#include "archive_entry.h" +#include "archive_entry_locale.h" +#include "archive_ppmd7_private.h" +#include "archive_private.h" +#include "archive_read_private.h" +#include "archive_endian.h" + +#ifndef HAVE_ZLIB_H +#include "archive_crc32.h" +#endif + +#define _7ZIP_SIGNATURE "7z\xBC\xAF\x27\x1C" +#define SFX_MIN_ADDR 0x27000 +#define SFX_MAX_ADDR 0x60000 + + +/* + * Codec ID + */ +#define _7Z_COPY 0 +#define _7Z_LZMA 0x030101 +#define _7Z_LZMA2 0x21 +#define _7Z_DEFLATE 0x040108 +#define _7Z_BZ2 0x040202 +#define _7Z_PPMD 0x030401 +#define _7Z_DELTA 0x03 +#define _7Z_CRYPTO_MAIN_ZIP 0x06F10101 /* Main Zip crypto algo */ +#define _7Z_CRYPTO_RAR_29 0x06F10303 /* Rar29 AES-128 + (modified SHA-1) */ +#define _7Z_CRYPTO_AES_256_SHA_256 0x06F10701 /* AES-256 + SHA-256 */ + + +#define _7Z_X86 0x03030103 +#define _7Z_X86_BCJ2 0x0303011B +#define _7Z_POWERPC 0x03030205 +#define _7Z_IA64 0x03030401 +#define _7Z_ARM 0x03030501 +#define _7Z_ARMTHUMB 0x03030701 +#define _7Z_SPARC 0x03030805 + +/* + * 7-Zip header property IDs. + */ +#define kEnd 0x00 +#define kHeader 0x01 +#define kArchiveProperties 0x02 +#define kAdditionalStreamsInfo 0x03 +#define kMainStreamsInfo 0x04 +#define kFilesInfo 0x05 +#define kPackInfo 0x06 +#define kUnPackInfo 0x07 +#define kSubStreamsInfo 0x08 +#define kSize 0x09 +#define kCRC 0x0A +#define kFolder 0x0B +#define kCodersUnPackSize 0x0C +#define kNumUnPackStream 0x0D +#define kEmptyStream 0x0E +#define kEmptyFile 0x0F +#define kAnti 0x10 +#define kName 0x11 +#define kCTime 0x12 +#define kATime 0x13 +#define kMTime 0x14 +#define kAttributes 0x15 +#define kEncodedHeader 0x17 +#define kDummy 0x19 + +struct _7z_digests { + unsigned char *defineds; + uint32_t *digests; +}; + + +struct _7z_folder { + uint64_t numCoders; + struct _7z_coder { + unsigned long codec; + uint64_t numInStreams; + uint64_t numOutStreams; + uint64_t propertiesSize; + unsigned char *properties; + } *coders; + uint64_t numBindPairs; + struct { + uint64_t inIndex; + uint64_t outIndex; + } *bindPairs; + uint64_t numPackedStreams; + uint64_t *packedStreams; + uint64_t numInStreams; + uint64_t numOutStreams; + uint64_t *unPackSize; + unsigned char digest_defined; + uint32_t digest; + uint64_t numUnpackStreams; + uint32_t packIndex; + /* Unoperated bytes. */ + uint64_t skipped_bytes; +}; + +struct _7z_coders_info { + uint64_t numFolders; + struct _7z_folder *folders; + uint64_t dataStreamIndex; +}; + +struct _7z_pack_info { + uint64_t pos; + uint64_t numPackStreams; + uint64_t *sizes; + struct _7z_digests digest; + /* Calculated from pos and numPackStreams. */ + uint64_t *positions; +}; + +struct _7z_substream_info { + size_t unpack_streams; + uint64_t *unpackSizes; + unsigned char *digestsDefined; + uint32_t *digests; +}; + +struct _7z_stream_info { + struct _7z_pack_info pi; + struct _7z_coders_info ci; + struct _7z_substream_info ss; +}; + +struct _7z_header_info { + uint64_t dataIndex; + + unsigned char *emptyStreamBools; + unsigned char *emptyFileBools; + unsigned char *antiBools; + unsigned char *attrBools; +}; + +struct _7zip_entry { + size_t name_len; + unsigned char *utf16name; +#if defined(_WIN32) && !defined(__CYGWIN__) && defined(_DEBUG) + const wchar_t *wname; +#endif + uint32_t folderIndex; + uint32_t ssIndex; + unsigned flg; +#define MTIME_IS_SET (1<<0) +#define ATIME_IS_SET (1<<1) +#define CTIME_IS_SET (1<<2) +#define CRC32_IS_SET (1<<3) +#define HAS_STREAM (1<<4) + + time_t mtime; + time_t atime; + time_t ctime; + long mtime_ns; + long atime_ns; + long ctime_ns; + uint32_t mode; + uint32_t attr; +}; + +struct _7zip { + /* Structural information about the archive. */ + struct _7z_stream_info si; + + int header_is_being_read; + int header_is_encoded; + uint64_t header_bytes_remaining; + unsigned long header_crc32; + /* Header offset to check that reading points of the file contents + * will not exceed the header. */ + uint64_t header_offset; + /* Base offset of the archive file for a seek in case reading SFX. */ + uint64_t seek_base; + + /* List of entries */ + size_t entries_remaining; + uint64_t numFiles; + struct _7zip_entry *entries; + struct _7zip_entry *entry; + unsigned char *entry_names; + + /* entry_bytes_remaining is the number of bytes we expect. */ + int64_t entry_offset; + uint64_t entry_bytes_remaining; + + /* Running CRC32 of the decompressed data */ + unsigned long entry_crc32; + + /* Flags to mark progress of decompression. */ + char end_of_entry; + + /* Uncompressed buffer control. */ +#define UBUFF_SIZE (64 * 1024) + unsigned char *uncompressed_buffer; + unsigned char *uncompressed_buffer_pointer; + size_t uncompressed_buffer_size; + size_t uncompressed_buffer_bytes_remaining; + + /* Offset of the compressed data. */ + int64_t stream_offset; + + /* + * Decompressing control data. + */ + unsigned folder_index; + uint64_t folder_outbytes_remaining; + unsigned pack_stream_index; + unsigned pack_stream_remaining; + uint64_t pack_stream_inbytes_remaining; + size_t pack_stream_bytes_unconsumed; + + /* The codec information of a folder. */ + unsigned long codec; + unsigned long codec2; + + /* + * Decompressor controllers. + */ + /* Decoding LZMA1 and LZMA2 data. */ +#ifdef HAVE_LZMA_H + lzma_stream lzstream; + int lzstream_valid; +#endif + /* Decoding bzip2 data. */ +#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) + bz_stream bzstream; + int bzstream_valid; +#endif + /* Decoding deflate data. */ +#ifdef HAVE_ZLIB_H + z_stream stream; + int stream_valid; +#endif + /* Decoding PPMd data. */ + int ppmd7_stat; + CPpmd7 ppmd7_context; + CPpmd7z_RangeDec range_dec; + IByteIn bytein; + struct { + const unsigned char *next_in; + int64_t avail_in; + int64_t total_in; + unsigned char *next_out; + int64_t avail_out; + int64_t total_out; + int overconsumed; + } ppstream; + int ppmd7_valid; + + /* Decoding BCJ and BCJ2 data. */ + uint32_t bcj_state; + size_t odd_bcj_size; + unsigned char odd_bcj[4]; + /* Decoding BCJ data. */ + size_t bcj_prevPosT; + uint32_t bcj_prevMask; + uint32_t bcj_ip; + + /* Decoding BCJ2 data. */ + size_t main_stream_bytes_remaining; + unsigned char *sub_stream_buff[3]; + size_t sub_stream_size[3]; + size_t sub_stream_bytes_remaining[3]; + unsigned char *tmp_stream_buff; + size_t tmp_stream_buff_size; + size_t tmp_stream_bytes_avail; + size_t tmp_stream_bytes_remaining; +#ifdef _LZMA_PROB32 +#define CProb uint32_t +#else +#define CProb uint16_t +#endif + CProb bcj2_p[256 + 2]; + uint8_t bcj2_prevByte; + uint32_t bcj2_range; + uint32_t bcj2_code; + uint64_t bcj2_outPos; + + /* Filename character-set conversion data. */ + struct archive_string_conv *sconv; + + char format_name[64]; + + /* Custom value that is non-zero if this archive contains encrypted entries. */ + int has_encrypted_entries; +}; + +/* Maximum entry size. This limitation prevents reading intentional + * corrupted 7-zip files on assuming there are not so many entries in + * the files. */ +#define UMAX_ENTRY ARCHIVE_LITERAL_ULL(100000000) + +static int archive_read_format_7zip_has_encrypted_entries(struct archive_read *); +static int archive_read_support_format_7zip_capabilities(struct archive_read *a); +static int archive_read_format_7zip_bid(struct archive_read *, int); +static int archive_read_format_7zip_cleanup(struct archive_read *); +static int archive_read_format_7zip_read_data(struct archive_read *, + const void **, size_t *, int64_t *); +static int archive_read_format_7zip_read_data_skip(struct archive_read *); +static int archive_read_format_7zip_read_header(struct archive_read *, + struct archive_entry *); +static int check_7zip_header_in_sfx(const char *); +static unsigned long decode_codec_id(const unsigned char *, size_t); +static int decode_encoded_header_info(struct archive_read *, + struct _7z_stream_info *); +static int decompress(struct archive_read *, struct _7zip *, + void *, size_t *, const void *, size_t *); +static ssize_t extract_pack_stream(struct archive_read *, size_t); +static void fileTimeToUtc(uint64_t, time_t *, long *); +static uint64_t folder_uncompressed_size(struct _7z_folder *); +static void free_CodersInfo(struct _7z_coders_info *); +static void free_Digest(struct _7z_digests *); +static void free_Folder(struct _7z_folder *); +static void free_Header(struct _7z_header_info *); +static void free_PackInfo(struct _7z_pack_info *); +static void free_StreamsInfo(struct _7z_stream_info *); +static void free_SubStreamsInfo(struct _7z_substream_info *); +static int free_decompression(struct archive_read *, struct _7zip *); +static ssize_t get_uncompressed_data(struct archive_read *, const void **, + size_t, size_t); +static const unsigned char * header_bytes(struct archive_read *, size_t); +static int init_decompression(struct archive_read *, struct _7zip *, + const struct _7z_coder *, const struct _7z_coder *); +static int parse_7zip_uint64(struct archive_read *, uint64_t *); +static int read_Bools(struct archive_read *, unsigned char *, size_t); +static int read_CodersInfo(struct archive_read *, + struct _7z_coders_info *); +static int read_Digests(struct archive_read *, struct _7z_digests *, + size_t); +static int read_Folder(struct archive_read *, struct _7z_folder *); +static int read_Header(struct archive_read *, struct _7z_header_info *, + int); +static int read_PackInfo(struct archive_read *, struct _7z_pack_info *); +static int read_StreamsInfo(struct archive_read *, + struct _7z_stream_info *); +static int read_SubStreamsInfo(struct archive_read *, + struct _7z_substream_info *, struct _7z_folder *, size_t); +static int read_Times(struct archive_read *, struct _7z_header_info *, + int); +static void read_consume(struct archive_read *); +static ssize_t read_stream(struct archive_read *, const void **, size_t, + size_t); +static int seek_pack(struct archive_read *); +static int64_t skip_stream(struct archive_read *, size_t); +static int skip_sfx(struct archive_read *, ssize_t); +static int slurp_central_directory(struct archive_read *, struct _7zip *, + struct _7z_header_info *); +static int setup_decode_folder(struct archive_read *, struct _7z_folder *, + int); +static void x86_Init(struct _7zip *); +static size_t x86_Convert(struct _7zip *, uint8_t *, size_t); +static ssize_t Bcj2_Decode(struct _7zip *, uint8_t *, size_t); + + +int +archive_read_support_format_7zip(struct archive *_a) +{ + struct archive_read *a = (struct archive_read *)_a; + struct _7zip *zip; + int r; + + archive_check_magic(_a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_format_7zip"); + + zip = calloc(1, sizeof(*zip)); + if (zip == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate 7zip data"); + return (ARCHIVE_FATAL); + } + + /* + * Until enough data has been read, we cannot tell about + * any encrypted entries yet. + */ + zip->has_encrypted_entries = ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW; + + + r = __archive_read_register_format(a, + zip, + "7zip", + archive_read_format_7zip_bid, + NULL, + archive_read_format_7zip_read_header, + archive_read_format_7zip_read_data, + archive_read_format_7zip_read_data_skip, + NULL, + archive_read_format_7zip_cleanup, + archive_read_support_format_7zip_capabilities, + archive_read_format_7zip_has_encrypted_entries); + + if (r != ARCHIVE_OK) + free(zip); + return (ARCHIVE_OK); +} + +static int +archive_read_support_format_7zip_capabilities(struct archive_read * a) +{ + (void)a; /* UNUSED */ + return (ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_DATA | + ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_METADATA); +} + + +static int +archive_read_format_7zip_has_encrypted_entries(struct archive_read *_a) +{ + if (_a && _a->format) { + struct _7zip * zip = (struct _7zip *)_a->format->data; + if (zip) { + return zip->has_encrypted_entries; + } + } + return ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW; +} + +static int +archive_read_format_7zip_bid(struct archive_read *a, int best_bid) +{ + const char *p; + + /* If someone has already bid more than 32, then avoid + trashing the look-ahead buffers with a seek. */ + if (best_bid > 32) + return (-1); + + if ((p = __archive_read_ahead(a, 6, NULL)) == NULL) + return (0); + + /* If first six bytes are the 7-Zip signature, + * return the bid right now. */ + if (memcmp(p, _7ZIP_SIGNATURE, 6) == 0) + return (48); + + /* + * It may a 7-Zip SFX archive file. If first two bytes are + * 'M' and 'Z' available on Windows or first four bytes are + * "\x7F\x45LF" available on posix like system, seek the 7-Zip + * signature. Although we will perform a seek when reading + * a header, what we do not use __archive_read_seek() here is + * due to a bidding performance. + */ + if ((p[0] == 'M' && p[1] == 'Z') || memcmp(p, "\x7F\x45LF", 4) == 0) { + ssize_t offset = SFX_MIN_ADDR; + ssize_t window = 4096; + ssize_t bytes_avail; + while (offset + window <= (SFX_MAX_ADDR)) { + const char *buff = __archive_read_ahead(a, + offset + window, &bytes_avail); + if (buff == NULL) { + /* Remaining bytes are less than window. */ + window >>= 1; + if (window < 0x40) + return (0); + continue; + } + p = buff + offset; + while (p + 32 < buff + bytes_avail) { + int step = check_7zip_header_in_sfx(p); + if (step == 0) + return (48); + p += step; + } + offset = p - buff; + } + } + return (0); +} + +static int +check_7zip_header_in_sfx(const char *p) +{ + switch ((unsigned char)p[5]) { + case 0x1C: + if (memcmp(p, _7ZIP_SIGNATURE, 6) != 0) + return (6); + /* + * Test the CRC because its extraction code has 7-Zip + * Magic Code, so we should do this in order not to + * make a mis-detection. + */ + if (crc32(0, (const unsigned char *)p + 12, 20) + != archive_le32dec(p + 8)) + return (6); + /* Hit the header! */ + return (0); + case 0x37: return (5); + case 0x7A: return (4); + case 0xBC: return (3); + case 0xAF: return (2); + case 0x27: return (1); + default: return (6); + } +} + +static int +skip_sfx(struct archive_read *a, ssize_t bytes_avail) +{ + const void *h; + const char *p, *q; + size_t skip, offset; + ssize_t bytes, window; + + /* + * If bytes_avail > SFX_MIN_ADDR we do not have to call + * __archive_read_seek() at this time since we have + * already had enough data. + */ + if (bytes_avail > SFX_MIN_ADDR) + __archive_read_consume(a, SFX_MIN_ADDR); + else if (__archive_read_seek(a, SFX_MIN_ADDR, SEEK_SET) < 0) + return (ARCHIVE_FATAL); + + offset = 0; + window = 1; + while (offset + window <= SFX_MAX_ADDR - SFX_MIN_ADDR) { + h = __archive_read_ahead(a, window, &bytes); + if (h == NULL) { + /* Remaining bytes are less than window. */ + window >>= 1; + if (window < 0x40) + goto fatal; + continue; + } + if (bytes < 6) { + /* This case might happen when window == 1. */ + window = 4096; + continue; + } + p = (const char *)h; + q = p + bytes; + + /* + * Scan ahead until we find something that looks + * like the 7-Zip header. + */ + while (p + 32 < q) { + int step = check_7zip_header_in_sfx(p); + if (step == 0) { + struct _7zip *zip = + (struct _7zip *)a->format->data; + skip = p - (const char *)h; + __archive_read_consume(a, skip); + zip->seek_base = SFX_MIN_ADDR + offset + skip; + return (ARCHIVE_OK); + } + p += step; + } + skip = p - (const char *)h; + __archive_read_consume(a, skip); + offset += skip; + if (window == 1) + window = 4096; + } +fatal: + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Couldn't find out 7-Zip header"); + return (ARCHIVE_FATAL); +} + +static int +archive_read_format_7zip_read_header(struct archive_read *a, + struct archive_entry *entry) +{ + struct _7zip *zip = (struct _7zip *)a->format->data; + struct _7zip_entry *zip_entry; + int r, ret = ARCHIVE_OK; + struct _7z_folder *folder = 0; + uint64_t fidx = 0; + + /* + * It should be sufficient to call archive_read_next_header() for + * a reader to determine if an entry is encrypted or not. If the + * encryption of an entry is only detectable when calling + * archive_read_data(), so be it. We'll do the same check there + * as well. + */ + if (zip->has_encrypted_entries == ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW) { + zip->has_encrypted_entries = 0; + } + + a->archive.archive_format = ARCHIVE_FORMAT_7ZIP; + if (a->archive.archive_format_name == NULL) + a->archive.archive_format_name = "7-Zip"; + + if (zip->entries == NULL) { + struct _7z_header_info header; + + memset(&header, 0, sizeof(header)); + r = slurp_central_directory(a, zip, &header); + free_Header(&header); + if (r != ARCHIVE_OK) + return (r); + zip->entries_remaining = (size_t)zip->numFiles; + zip->entry = zip->entries; + } else { + ++zip->entry; + } + zip_entry = zip->entry; + + if (zip->entries_remaining <= 0 || zip_entry == NULL) + return ARCHIVE_EOF; + --zip->entries_remaining; + + zip->entry_offset = 0; + zip->end_of_entry = 0; + zip->entry_crc32 = crc32(0, NULL, 0); + + /* Setup a string conversion for a filename. */ + if (zip->sconv == NULL) { + zip->sconv = archive_string_conversion_from_charset( + &a->archive, "UTF-16LE", 1); + if (zip->sconv == NULL) + return (ARCHIVE_FATAL); + } + + /* Figure out if the entry is encrypted by looking at the folder + that is associated to the current 7zip entry. If the folder + has a coder with a _7Z_CRYPTO codec then the folder is encrypted. + Hence the entry must also be encrypted. */ + if (zip_entry && zip_entry->folderIndex < zip->si.ci.numFolders) { + folder = &(zip->si.ci.folders[zip_entry->folderIndex]); + for (fidx=0; folder && fidxnumCoders; fidx++) { + switch(folder->coders[fidx].codec) { + case _7Z_CRYPTO_MAIN_ZIP: + case _7Z_CRYPTO_RAR_29: + case _7Z_CRYPTO_AES_256_SHA_256: { + archive_entry_set_is_data_encrypted(entry, 1); + zip->has_encrypted_entries = 1; + break; + } + } + } + } + + /* Now that we've checked for encryption, if there were still no + * encrypted entries found we can say for sure that there are none. + */ + if (zip->has_encrypted_entries == ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW) { + zip->has_encrypted_entries = 0; + } + + if (archive_entry_copy_pathname_l(entry, + (const char *)zip_entry->utf16name, + zip_entry->name_len, zip->sconv) != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Pathname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Pathname cannot be converted " + "from %s to current locale.", + archive_string_conversion_charset_name(zip->sconv)); + ret = ARCHIVE_WARN; + } + + /* Populate some additional entry fields: */ + archive_entry_set_mode(entry, zip_entry->mode); + if (zip_entry->flg & MTIME_IS_SET) + archive_entry_set_mtime(entry, zip_entry->mtime, + zip_entry->mtime_ns); + if (zip_entry->flg & CTIME_IS_SET) + archive_entry_set_ctime(entry, zip_entry->ctime, + zip_entry->ctime_ns); + if (zip_entry->flg & ATIME_IS_SET) + archive_entry_set_atime(entry, zip_entry->atime, + zip_entry->atime_ns); + if (zip_entry->ssIndex != (uint32_t)-1) { + zip->entry_bytes_remaining = + zip->si.ss.unpackSizes[zip_entry->ssIndex]; + archive_entry_set_size(entry, zip->entry_bytes_remaining); + } else { + zip->entry_bytes_remaining = 0; + archive_entry_set_size(entry, 0); + } + + /* If there's no body, force read_data() to return EOF immediately. */ + if (zip->entry_bytes_remaining < 1) + zip->end_of_entry = 1; + + if ((zip_entry->mode & AE_IFMT) == AE_IFLNK) { + unsigned char *symname = NULL; + size_t symsize = 0; + + /* + * Symbolic-name is recorded as its contents. We have to + * read the contents at this time. + */ + while (zip->entry_bytes_remaining > 0) { + const void *buff; + unsigned char *mem; + size_t size; + int64_t offset; + + r = archive_read_format_7zip_read_data(a, &buff, + &size, &offset); + if (r < ARCHIVE_WARN) { + free(symname); + return (r); + } + mem = realloc(symname, symsize + size + 1); + if (mem == NULL) { + free(symname); + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Symname"); + return (ARCHIVE_FATAL); + } + symname = mem; + memcpy(symname+symsize, buff, size); + symsize += size; + } + if (symsize == 0) { + /* If there is no symname, handle it as a regular + * file. */ + zip_entry->mode &= ~AE_IFMT; + zip_entry->mode |= AE_IFREG; + archive_entry_set_mode(entry, zip_entry->mode); + } else { + symname[symsize] = '\0'; + archive_entry_copy_symlink(entry, + (const char *)symname); + } + free(symname); + archive_entry_set_size(entry, 0); + } + + /* Set up a more descriptive format name. */ + sprintf(zip->format_name, "7-Zip"); + a->archive.archive_format_name = zip->format_name; + + return (ret); +} + +static int +archive_read_format_7zip_read_data(struct archive_read *a, + const void **buff, size_t *size, int64_t *offset) +{ + struct _7zip *zip; + ssize_t bytes; + int ret = ARCHIVE_OK; + + zip = (struct _7zip *)(a->format->data); + + if (zip->has_encrypted_entries == ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW) { + zip->has_encrypted_entries = 0; + } + + if (zip->pack_stream_bytes_unconsumed) + read_consume(a); + + *offset = zip->entry_offset; + *size = 0; + *buff = NULL; + /* + * If we hit end-of-entry last time, clean up and return + * ARCHIVE_EOF this time. + */ + if (zip->end_of_entry) + return (ARCHIVE_EOF); + + bytes = read_stream(a, buff, + (size_t)zip->entry_bytes_remaining, 0); + if (bytes < 0) + return ((int)bytes); + if (bytes == 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated 7-Zip file body"); + return (ARCHIVE_FATAL); + } + zip->entry_bytes_remaining -= bytes; + if (zip->entry_bytes_remaining == 0) + zip->end_of_entry = 1; + + /* Update checksum */ + if ((zip->entry->flg & CRC32_IS_SET) && bytes) + zip->entry_crc32 = crc32(zip->entry_crc32, *buff, + (unsigned)bytes); + + /* If we hit the end, swallow any end-of-data marker. */ + if (zip->end_of_entry) { + /* Check computed CRC against file contents. */ + if ((zip->entry->flg & CRC32_IS_SET) && + zip->si.ss.digests[zip->entry->ssIndex] != + zip->entry_crc32) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "7-Zip bad CRC: 0x%lx should be 0x%lx", + (unsigned long)zip->entry_crc32, + (unsigned long)zip->si.ss.digests[ + zip->entry->ssIndex]); + ret = ARCHIVE_WARN; + } + } + + *size = bytes; + *offset = zip->entry_offset; + zip->entry_offset += bytes; + + return (ret); +} + +static int +archive_read_format_7zip_read_data_skip(struct archive_read *a) +{ + struct _7zip *zip; + int64_t bytes_skipped; + + zip = (struct _7zip *)(a->format->data); + + if (zip->pack_stream_bytes_unconsumed) + read_consume(a); + + /* If we've already read to end of data, we're done. */ + if (zip->end_of_entry) + return (ARCHIVE_OK); + + /* + * If the length is at the beginning, we can skip the + * compressed data much more quickly. + */ + bytes_skipped = skip_stream(a, (size_t)zip->entry_bytes_remaining); + if (bytes_skipped < 0) + return (ARCHIVE_FATAL); + zip->entry_bytes_remaining = 0; + + /* This entry is finished and done. */ + zip->end_of_entry = 1; + return (ARCHIVE_OK); +} + +static int +archive_read_format_7zip_cleanup(struct archive_read *a) +{ + struct _7zip *zip; + + zip = (struct _7zip *)(a->format->data); + free_StreamsInfo(&(zip->si)); + free(zip->entries); + free(zip->entry_names); + free_decompression(a, zip); + free(zip->uncompressed_buffer); + free(zip->sub_stream_buff[0]); + free(zip->sub_stream_buff[1]); + free(zip->sub_stream_buff[2]); + free(zip->tmp_stream_buff); + free(zip); + (a->format->data) = NULL; + return (ARCHIVE_OK); +} + +static void +read_consume(struct archive_read *a) +{ + struct _7zip *zip = (struct _7zip *)a->format->data; + + if (zip->pack_stream_bytes_unconsumed) { + __archive_read_consume(a, zip->pack_stream_bytes_unconsumed); + zip->stream_offset += zip->pack_stream_bytes_unconsumed; + zip->pack_stream_bytes_unconsumed = 0; + } +} + +#ifdef HAVE_LZMA_H + +/* + * Set an error code and choose an error message for liblzma. + */ +static void +set_error(struct archive_read *a, int ret) +{ + + switch (ret) { + case LZMA_STREAM_END: /* Found end of stream. */ + case LZMA_OK: /* Decompressor made some progress. */ + break; + case LZMA_MEM_ERROR: + archive_set_error(&a->archive, ENOMEM, + "Lzma library error: Cannot allocate memory"); + break; + case LZMA_MEMLIMIT_ERROR: + archive_set_error(&a->archive, ENOMEM, + "Lzma library error: Out of memory"); + break; + case LZMA_FORMAT_ERROR: + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Lzma library error: format not recognized"); + break; + case LZMA_OPTIONS_ERROR: + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Lzma library error: Invalid options"); + break; + case LZMA_DATA_ERROR: + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Lzma library error: Corrupted input data"); + break; + case LZMA_BUF_ERROR: + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Lzma library error: No progress is possible"); + break; + default: + /* Return an error. */ + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Lzma decompression failed: Unknown error"); + break; + } +} + +#endif + +static unsigned long +decode_codec_id(const unsigned char *codecId, size_t id_size) +{ + unsigned i; + unsigned long id = 0; + + for (i = 0; i < id_size; i++) { + id <<= 8; + id += codecId[i]; + } + return (id); +} + - static void * - ppmd_alloc(void *p, size_t size) - { - (void)p; - return malloc(size); - } - static void - ppmd_free(void *p, void *address) - { - (void)p; - free(address); - } +static Byte +ppmd_read(void *p) +{ + struct archive_read *a = ((IByteIn*)p)->a; + struct _7zip *zip = (struct _7zip *)(a->format->data); + Byte b; + + if (zip->ppstream.avail_in == 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated RAR file data"); + zip->ppstream.overconsumed = 1; + return (0); + } + b = *zip->ppstream.next_in++; + zip->ppstream.avail_in--; + zip->ppstream.total_in++; + return (b); +} + - static ISzAlloc g_szalloc = { ppmd_alloc, ppmd_free }; - +static int +init_decompression(struct archive_read *a, struct _7zip *zip, + const struct _7z_coder *coder1, const struct _7z_coder *coder2) +{ + int r; + + zip->codec = coder1->codec; + zip->codec2 = -1; + + switch (zip->codec) { + case _7Z_COPY: + case _7Z_BZ2: + case _7Z_DEFLATE: + case _7Z_PPMD: + if (coder2 != NULL) { + if (coder2->codec != _7Z_X86 && + coder2->codec != _7Z_X86_BCJ2) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Unsupported filter %lx for %lx", + coder2->codec, coder1->codec); + return (ARCHIVE_FAILED); + } + zip->codec2 = coder2->codec; + zip->bcj_state = 0; + if (coder2->codec == _7Z_X86) + x86_Init(zip); + } + break; + default: + break; + } + + switch (zip->codec) { + case _7Z_COPY: + break; + + case _7Z_LZMA: case _7Z_LZMA2: +#ifdef HAVE_LZMA_H +#if LZMA_VERSION_MAJOR >= 5 +/* Effectively disable the limiter. */ +#define LZMA_MEMLIMIT UINT64_MAX +#else +/* NOTE: This needs to check memory size which running system has. */ +#define LZMA_MEMLIMIT (1U << 30) +#endif + { + lzma_options_delta delta_opt; + lzma_filter filters[LZMA_FILTERS_MAX], *ff; + int fi = 0; + + if (zip->lzstream_valid) { + lzma_end(&(zip->lzstream)); + zip->lzstream_valid = 0; + } + + /* + * NOTE: liblzma incompletely handle the BCJ+LZMA compressed + * data made by 7-Zip because 7-Zip does not add End-Of- + * Payload Marker(EOPM) at the end of LZMA compressed data, + * and so liblzma cannot know the end of the compressed data + * without EOPM. So consequently liblzma will not return last + * three or four bytes of uncompressed data because + * LZMA_FILTER_X86 filter does not handle input data if its + * data size is less than five bytes. If liblzma detect EOPM + * or know the uncompressed data size, liblzma will flush out + * the remaining that three or four bytes of uncompressed + * data. That is why we have to use our converting program + * for BCJ+LZMA. If we were able to tell the uncompressed + * size to liblzma when using lzma_raw_decoder() liblzma + * could correctly deal with BCJ+LZMA. But unfortunately + * there is no way to do that. + * Discussion about this can be found at XZ Utils forum. + */ + if (coder2 != NULL) { + zip->codec2 = coder2->codec; + + filters[fi].options = NULL; + switch (zip->codec2) { + case _7Z_X86: + if (zip->codec == _7Z_LZMA2) { + filters[fi].id = LZMA_FILTER_X86; + fi++; + } else + /* Use our filter. */ + x86_Init(zip); + break; + case _7Z_X86_BCJ2: + /* Use our filter. */ + zip->bcj_state = 0; + break; + case _7Z_DELTA: + filters[fi].id = LZMA_FILTER_DELTA; + memset(&delta_opt, 0, sizeof(delta_opt)); + delta_opt.type = LZMA_DELTA_TYPE_BYTE; + delta_opt.dist = 1; + filters[fi].options = &delta_opt; + fi++; + break; + /* Following filters have not been tested yet. */ + case _7Z_POWERPC: + filters[fi].id = LZMA_FILTER_POWERPC; + fi++; + break; + case _7Z_IA64: + filters[fi].id = LZMA_FILTER_IA64; + fi++; + break; + case _7Z_ARM: + filters[fi].id = LZMA_FILTER_ARM; + fi++; + break; + case _7Z_ARMTHUMB: + filters[fi].id = LZMA_FILTER_ARMTHUMB; + fi++; + break; + case _7Z_SPARC: + filters[fi].id = LZMA_FILTER_SPARC; + fi++; + break; + default: + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Unexpected codec ID: %lX", zip->codec2); + return (ARCHIVE_FAILED); + } + } + + if (zip->codec == _7Z_LZMA2) + filters[fi].id = LZMA_FILTER_LZMA2; + else + filters[fi].id = LZMA_FILTER_LZMA1; + filters[fi].options = NULL; + ff = &filters[fi]; + r = lzma_properties_decode(&filters[fi], NULL, + coder1->properties, (size_t)coder1->propertiesSize); + if (r != LZMA_OK) { + set_error(a, r); + return (ARCHIVE_FAILED); + } + fi++; + + filters[fi].id = LZMA_VLI_UNKNOWN; + filters[fi].options = NULL; + r = lzma_raw_decoder(&(zip->lzstream), filters); + free(ff->options); + if (r != LZMA_OK) { + set_error(a, r); + return (ARCHIVE_FAILED); + } + zip->lzstream_valid = 1; + zip->lzstream.total_in = 0; + zip->lzstream.total_out = 0; + break; + } +#else + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "LZMA codec is unsupported"); + return (ARCHIVE_FAILED); +#endif + case _7Z_BZ2: +#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) + if (zip->bzstream_valid) { + BZ2_bzDecompressEnd(&(zip->bzstream)); + zip->bzstream_valid = 0; + } + r = BZ2_bzDecompressInit(&(zip->bzstream), 0, 0); + if (r == BZ_MEM_ERROR) + r = BZ2_bzDecompressInit(&(zip->bzstream), 0, 1); + if (r != BZ_OK) { + int err = ARCHIVE_ERRNO_MISC; + const char *detail = NULL; + switch (r) { + case BZ_PARAM_ERROR: + detail = "invalid setup parameter"; + break; + case BZ_MEM_ERROR: + err = ENOMEM; + detail = "out of memory"; + break; + case BZ_CONFIG_ERROR: + detail = "mis-compiled library"; + break; + } + archive_set_error(&a->archive, err, + "Internal error initializing decompressor: %s", + detail != NULL ? detail : "??"); + zip->bzstream_valid = 0; + return (ARCHIVE_FAILED); + } + zip->bzstream_valid = 1; + zip->bzstream.total_in_lo32 = 0; + zip->bzstream.total_in_hi32 = 0; + zip->bzstream.total_out_lo32 = 0; + zip->bzstream.total_out_hi32 = 0; + break; +#else + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "BZ2 codec is unsupported"); + return (ARCHIVE_FAILED); +#endif + case _7Z_DEFLATE: +#ifdef HAVE_ZLIB_H + if (zip->stream_valid) + r = inflateReset(&(zip->stream)); + else + r = inflateInit2(&(zip->stream), + -15 /* Don't check for zlib header */); + if (r != Z_OK) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Couldn't initialize zlib stream."); + return (ARCHIVE_FAILED); + } + zip->stream_valid = 1; + zip->stream.total_in = 0; + zip->stream.total_out = 0; + break; +#else + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "DEFLATE codec is unsupported"); + return (ARCHIVE_FAILED); +#endif + case _7Z_PPMD: + { + unsigned order; + uint32_t msize; + + if (zip->ppmd7_valid) { + __archive_ppmd7_functions.Ppmd7_Free( - &zip->ppmd7_context, &g_szalloc); ++ &zip->ppmd7_context); + zip->ppmd7_valid = 0; + } + + if (coder1->propertiesSize < 5) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Malformed PPMd parameter"); + return (ARCHIVE_FAILED); + } + order = coder1->properties[0]; + msize = archive_le32dec(&(coder1->properties[1])); + if (order < PPMD7_MIN_ORDER || order > PPMD7_MAX_ORDER || + msize < PPMD7_MIN_MEM_SIZE || msize > PPMD7_MAX_MEM_SIZE) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Malformed PPMd parameter"); + return (ARCHIVE_FAILED); + } + __archive_ppmd7_functions.Ppmd7_Construct(&zip->ppmd7_context); + r = __archive_ppmd7_functions.Ppmd7_Alloc( - &zip->ppmd7_context, msize, &g_szalloc); ++ &zip->ppmd7_context, msize); + if (r == 0) { + archive_set_error(&a->archive, ENOMEM, + "Coludn't allocate memory for PPMd"); + return (ARCHIVE_FATAL); + } + __archive_ppmd7_functions.Ppmd7_Init( + &zip->ppmd7_context, order); + __archive_ppmd7_functions.Ppmd7z_RangeDec_CreateVTable( + &zip->range_dec); + zip->ppmd7_valid = 1; + zip->ppmd7_stat = 0; + zip->ppstream.overconsumed = 0; + zip->ppstream.total_in = 0; + zip->ppstream.total_out = 0; + break; + } + case _7Z_X86: + case _7Z_X86_BCJ2: + case _7Z_POWERPC: + case _7Z_IA64: + case _7Z_ARM: + case _7Z_ARMTHUMB: + case _7Z_SPARC: + case _7Z_DELTA: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Unexpected codec ID: %lX", zip->codec); + return (ARCHIVE_FAILED); + case _7Z_CRYPTO_MAIN_ZIP: + case _7Z_CRYPTO_RAR_29: + case _7Z_CRYPTO_AES_256_SHA_256: + if (a->entry) { + archive_entry_set_is_metadata_encrypted(a->entry, 1); + archive_entry_set_is_data_encrypted(a->entry, 1); + zip->has_encrypted_entries = 1; + } + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Crypto codec not supported yet (ID: 0x%lX)", zip->codec); + return (ARCHIVE_FAILED); + default: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Unknown codec ID: %lX", zip->codec); + return (ARCHIVE_FAILED); + } + + return (ARCHIVE_OK); +} + +static int +decompress(struct archive_read *a, struct _7zip *zip, + void *buff, size_t *outbytes, const void *b, size_t *used) +{ + const uint8_t *t_next_in; + uint8_t *t_next_out; + size_t o_avail_in, o_avail_out; + size_t t_avail_in, t_avail_out; + uint8_t *bcj2_next_out; + size_t bcj2_avail_out; + int r, ret = ARCHIVE_OK; + + t_avail_in = o_avail_in = *used; + t_avail_out = o_avail_out = *outbytes; + t_next_in = b; + t_next_out = buff; + + if (zip->codec != _7Z_LZMA2 && zip->codec2 == _7Z_X86) { + int i; + + /* Do not copy out the BCJ remaining bytes when the output + * buffer size is less than five bytes. */ + if (o_avail_in != 0 && t_avail_out < 5 && zip->odd_bcj_size) { + *used = 0; + *outbytes = 0; + return (ret); + } + for (i = 0; zip->odd_bcj_size > 0 && t_avail_out; i++) { + *t_next_out++ = zip->odd_bcj[i]; + t_avail_out--; + zip->odd_bcj_size--; + } + if (o_avail_in == 0 || t_avail_out == 0) { + *used = o_avail_in - t_avail_in; + *outbytes = o_avail_out - t_avail_out; + if (o_avail_in == 0) + ret = ARCHIVE_EOF; + return (ret); + } + } + + bcj2_next_out = t_next_out; + bcj2_avail_out = t_avail_out; + if (zip->codec2 == _7Z_X86_BCJ2) { + /* + * Decord a remaining decompressed main stream for BCJ2. + */ + if (zip->tmp_stream_bytes_remaining) { + ssize_t bytes; + size_t remaining = zip->tmp_stream_bytes_remaining; + bytes = Bcj2_Decode(zip, t_next_out, t_avail_out); + if (bytes < 0) { + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "BCJ2 conversion Failed"); + return (ARCHIVE_FAILED); + } + zip->main_stream_bytes_remaining -= + remaining - zip->tmp_stream_bytes_remaining; + t_avail_out -= bytes; + if (o_avail_in == 0 || t_avail_out == 0) { + *used = 0; + *outbytes = o_avail_out - t_avail_out; + if (o_avail_in == 0 && + zip->tmp_stream_bytes_remaining) + ret = ARCHIVE_EOF; + return (ret); + } + t_next_out += bytes; + bcj2_next_out = t_next_out; + bcj2_avail_out = t_avail_out; + } + t_next_out = zip->tmp_stream_buff; + t_avail_out = zip->tmp_stream_buff_size; + } + + switch (zip->codec) { + case _7Z_COPY: + { + size_t bytes = + (t_avail_in > t_avail_out)?t_avail_out:t_avail_in; + + memcpy(t_next_out, t_next_in, bytes); + t_avail_in -= bytes; + t_avail_out -= bytes; + if (o_avail_in == 0) + ret = ARCHIVE_EOF; + break; + } +#ifdef HAVE_LZMA_H + case _7Z_LZMA: case _7Z_LZMA2: + zip->lzstream.next_in = t_next_in; + zip->lzstream.avail_in = t_avail_in; + zip->lzstream.next_out = t_next_out; + zip->lzstream.avail_out = t_avail_out; + + r = lzma_code(&(zip->lzstream), LZMA_RUN); + switch (r) { + case LZMA_STREAM_END: /* Found end of stream. */ + lzma_end(&(zip->lzstream)); + zip->lzstream_valid = 0; + ret = ARCHIVE_EOF; + break; + case LZMA_OK: /* Decompressor made some progress. */ + break; + default: + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "Decompression failed(%d)", + r); + return (ARCHIVE_FAILED); + } + t_avail_in = zip->lzstream.avail_in; + t_avail_out = zip->lzstream.avail_out; + break; +#endif +#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) + case _7Z_BZ2: + zip->bzstream.next_in = (char *)(uintptr_t)t_next_in; + zip->bzstream.avail_in = t_avail_in; + zip->bzstream.next_out = (char *)(uintptr_t)t_next_out; + zip->bzstream.avail_out = t_avail_out; + r = BZ2_bzDecompress(&(zip->bzstream)); + switch (r) { + case BZ_STREAM_END: /* Found end of stream. */ + switch (BZ2_bzDecompressEnd(&(zip->bzstream))) { + case BZ_OK: + break; + default: + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "Failed to clean up decompressor"); + return (ARCHIVE_FAILED); + } + zip->bzstream_valid = 0; + ret = ARCHIVE_EOF; + break; + case BZ_OK: /* Decompressor made some progress. */ + break; + default: + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "bzip decompression failed"); + return (ARCHIVE_FAILED); + } + t_avail_in = zip->bzstream.avail_in; + t_avail_out = zip->bzstream.avail_out; + break; +#endif +#ifdef HAVE_ZLIB_H + case _7Z_DEFLATE: + zip->stream.next_in = (Bytef *)(uintptr_t)t_next_in; + zip->stream.avail_in = (uInt)t_avail_in; + zip->stream.next_out = t_next_out; + zip->stream.avail_out = (uInt)t_avail_out; + r = inflate(&(zip->stream), 0); + switch (r) { + case Z_STREAM_END: /* Found end of stream. */ + ret = ARCHIVE_EOF; + break; + case Z_OK: /* Decompressor made some progress.*/ + break; + default: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "File decompression failed (%d)", r); + return (ARCHIVE_FAILED); + } + t_avail_in = zip->stream.avail_in; + t_avail_out = zip->stream.avail_out; + break; +#endif + case _7Z_PPMD: + { + uint64_t flush_bytes; + + if (!zip->ppmd7_valid || zip->ppmd7_stat < 0 || + t_avail_out <= 0) { + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "Decompression internal error"); + return (ARCHIVE_FAILED); + } + zip->ppstream.next_in = t_next_in; + zip->ppstream.avail_in = t_avail_in; + zip->ppstream.next_out = t_next_out; + zip->ppstream.avail_out = t_avail_out; + if (zip->ppmd7_stat == 0) { + zip->bytein.a = a; + zip->bytein.Read = &ppmd_read; + zip->range_dec.Stream = &zip->bytein; + r = __archive_ppmd7_functions.Ppmd7z_RangeDec_Init( + &(zip->range_dec)); + if (r == 0) { + zip->ppmd7_stat = -1; + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Failed to initialize PPMd range decorder"); + return (ARCHIVE_FAILED); + } + if (zip->ppstream.overconsumed) { + zip->ppmd7_stat = -1; + return (ARCHIVE_FAILED); + } + zip->ppmd7_stat = 1; + } + + if (t_avail_in == 0) + /* XXX Flush out remaining decoded data XXX */ + flush_bytes = zip->folder_outbytes_remaining; + else + flush_bytes = 0; + + do { + int sym; + + sym = __archive_ppmd7_functions.Ppmd7_DecodeSymbol( + &(zip->ppmd7_context), &(zip->range_dec.p)); + if (sym < 0) { + zip->ppmd7_stat = -1; + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Failed to decode PPMd"); + return (ARCHIVE_FAILED); + } + if (zip->ppstream.overconsumed) { + zip->ppmd7_stat = -1; + return (ARCHIVE_FAILED); + } + *zip->ppstream.next_out++ = (unsigned char)sym; + zip->ppstream.avail_out--; + zip->ppstream.total_out++; + if (flush_bytes) + flush_bytes--; + } while (zip->ppstream.avail_out && + (zip->ppstream.avail_in || flush_bytes)); + + t_avail_in = (size_t)zip->ppstream.avail_in; + t_avail_out = (size_t)zip->ppstream.avail_out; + break; + } + default: + archive_set_error(&(a->archive), ARCHIVE_ERRNO_MISC, + "Decompression internal error"); + return (ARCHIVE_FAILED); + } + if (ret != ARCHIVE_OK && ret != ARCHIVE_EOF) + return (ret); + + *used = o_avail_in - t_avail_in; + *outbytes = o_avail_out - t_avail_out; + + /* + * Decord BCJ. + */ + if (zip->codec != _7Z_LZMA2 && zip->codec2 == _7Z_X86) { + size_t l = x86_Convert(zip, buff, *outbytes); + zip->odd_bcj_size = *outbytes - l; + if (zip->odd_bcj_size > 0 && zip->odd_bcj_size <= 4 && + o_avail_in && ret != ARCHIVE_EOF) { + memcpy(zip->odd_bcj, ((unsigned char *)buff) + l, + zip->odd_bcj_size); + *outbytes = l; + } else + zip->odd_bcj_size = 0; + } + + /* + * Decord BCJ2 with a decompressed main stream. + */ + if (zip->codec2 == _7Z_X86_BCJ2) { + ssize_t bytes; + + zip->tmp_stream_bytes_avail = + zip->tmp_stream_buff_size - t_avail_out; + if (zip->tmp_stream_bytes_avail > + zip->main_stream_bytes_remaining) + zip->tmp_stream_bytes_avail = + zip->main_stream_bytes_remaining; + zip->tmp_stream_bytes_remaining = zip->tmp_stream_bytes_avail; + bytes = Bcj2_Decode(zip, bcj2_next_out, bcj2_avail_out); + if (bytes < 0) { + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, "BCJ2 conversion Failed"); + return (ARCHIVE_FAILED); + } + zip->main_stream_bytes_remaining -= + zip->tmp_stream_bytes_avail + - zip->tmp_stream_bytes_remaining; + bcj2_avail_out -= bytes; + *outbytes = o_avail_out - bcj2_avail_out; + } + + return (ret); +} + +static int +free_decompression(struct archive_read *a, struct _7zip *zip) +{ + int r = ARCHIVE_OK; + +#if !defined(HAVE_ZLIB_H) &&\ + !(defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR)) + (void)a;/* UNUSED */ +#endif +#ifdef HAVE_LZMA_H + if (zip->lzstream_valid) + lzma_end(&(zip->lzstream)); +#endif +#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) + if (zip->bzstream_valid) { + if (BZ2_bzDecompressEnd(&(zip->bzstream)) != BZ_OK) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Failed to clean up bzip2 decompressor"); + r = ARCHIVE_FATAL; + } + zip->bzstream_valid = 0; + } +#endif +#ifdef HAVE_ZLIB_H + if (zip->stream_valid) { + if (inflateEnd(&(zip->stream)) != Z_OK) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Failed to clean up zlib decompressor"); + r = ARCHIVE_FATAL; + } + zip->stream_valid = 0; + } +#endif + if (zip->ppmd7_valid) { + __archive_ppmd7_functions.Ppmd7_Free( - &zip->ppmd7_context, &g_szalloc); ++ &zip->ppmd7_context); + zip->ppmd7_valid = 0; + } + return (r); +} + +static int +parse_7zip_uint64(struct archive_read *a, uint64_t *val) +{ + const unsigned char *p; + unsigned char avail, mask; + int i; + + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + avail = *p; + mask = 0x80; + *val = 0; + for (i = 0; i < 8; i++) { + if (avail & mask) { + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + *val |= ((uint64_t)*p) << (8 * i); + mask >>= 1; + continue; + } + *val += ((uint64_t)(avail & (mask -1))) << (8 * i); + break; + } + return (0); +} + +static int +read_Bools(struct archive_read *a, unsigned char *data, size_t num) +{ + const unsigned char *p; + unsigned i, mask = 0, avail = 0; + + for (i = 0; i < num; i++) { + if (mask == 0) { + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + avail = *p; + mask = 0x80; + } + data[i] = (avail & mask)?1:0; + mask >>= 1; + } + return (0); +} + +static void +free_Digest(struct _7z_digests *d) +{ + free(d->defineds); + free(d->digests); +} + +static int +read_Digests(struct archive_read *a, struct _7z_digests *d, size_t num) +{ + const unsigned char *p; + unsigned i; + + if (num == 0) + return (-1); + memset(d, 0, sizeof(*d)); + + d->defineds = malloc(num); + if (d->defineds == NULL) + return (-1); + /* + * Read Bools. + */ + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + if (*p == 0) { + if (read_Bools(a, d->defineds, num) < 0) + return (-1); + } else + /* All are defined */ + memset(d->defineds, 1, num); + + d->digests = calloc(num, sizeof(*d->digests)); + if (d->digests == NULL) + return (-1); + for (i = 0; i < num; i++) { + if (d->defineds[i]) { + if ((p = header_bytes(a, 4)) == NULL) + return (-1); + d->digests[i] = archive_le32dec(p); + } + } + + return (0); +} + +static void +free_PackInfo(struct _7z_pack_info *pi) +{ + free(pi->sizes); + free(pi->positions); + free_Digest(&(pi->digest)); +} + +static int +read_PackInfo(struct archive_read *a, struct _7z_pack_info *pi) +{ + const unsigned char *p; + unsigned i; + + memset(pi, 0, sizeof(*pi)); + + /* + * Read PackPos. + */ + if (parse_7zip_uint64(a, &(pi->pos)) < 0) + return (-1); + + /* + * Read NumPackStreams. + */ + if (parse_7zip_uint64(a, &(pi->numPackStreams)) < 0) + return (-1); + if (pi->numPackStreams == 0) + return (-1); + if (UMAX_ENTRY < pi->numPackStreams) + return (-1); + + /* + * Read PackSizes[num] + */ + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + if (*p == kEnd) + /* PackSizes[num] are not present. */ + return (0); + if (*p != kSize) + return (-1); + pi->sizes = calloc((size_t)pi->numPackStreams, sizeof(uint64_t)); + pi->positions = calloc((size_t)pi->numPackStreams, sizeof(uint64_t)); + if (pi->sizes == NULL || pi->positions == NULL) + return (-1); + + for (i = 0; i < pi->numPackStreams; i++) { + if (parse_7zip_uint64(a, &(pi->sizes[i])) < 0) + return (-1); + } + + /* + * Read PackStreamDigests[num] + */ + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + if (*p == kEnd) { + /* PackStreamDigests[num] are not present. */ + pi->digest.defineds = + calloc((size_t)pi->numPackStreams, sizeof(*pi->digest.defineds)); + pi->digest.digests = + calloc((size_t)pi->numPackStreams, sizeof(*pi->digest.digests)); + if (pi->digest.defineds == NULL || pi->digest.digests == NULL) + return (-1); + return (0); + } + + if (*p != kSize) + return (-1); + + if (read_Digests(a, &(pi->digest), (size_t)pi->numPackStreams) < 0) + return (-1); + + /* + * Must be marked by kEnd. + */ + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + if (*p != kEnd) + return (-1); + return (0); +} + +static void +free_Folder(struct _7z_folder *f) +{ + unsigned i; + + if (f->coders) { + for (i = 0; i< f->numCoders; i++) { + free(f->coders[i].properties); + } + free(f->coders); + } + free(f->bindPairs); + free(f->packedStreams); + free(f->unPackSize); +} + +static int +read_Folder(struct archive_read *a, struct _7z_folder *f) +{ + struct _7zip *zip = (struct _7zip *)a->format->data; + const unsigned char *p; + uint64_t numInStreamsTotal = 0; + uint64_t numOutStreamsTotal = 0; + unsigned i; + + memset(f, 0, sizeof(*f)); + + /* + * Read NumCoders. + */ + if (parse_7zip_uint64(a, &(f->numCoders)) < 0) + return (-1); + if (f->numCoders > 4) + /* Too many coders. */ + return (-1); + + f->coders = calloc((size_t)f->numCoders, sizeof(*f->coders)); + if (f->coders == NULL) + return (-1); + for (i = 0; i< f->numCoders; i++) { + size_t codec_size; + int simple, attr; + + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + /* + * 0:3 CodecIdSize + * 4: 0 - IsSimple + * 1 - Is not Simple + * 5: 0 - No Attributes + * 1 - There are Attributes; + * 7: Must be zero. + */ + codec_size = *p & 0xf; + simple = (*p & 0x10)?0:1; + attr = *p & 0x20; + if (*p & 0x80) + return (-1);/* Not supported. */ + + /* + * Read Decompression Method IDs. + */ + if ((p = header_bytes(a, codec_size)) == NULL) + return (-1); + + f->coders[i].codec = decode_codec_id(p, codec_size); + + if (simple) { + f->coders[i].numInStreams = 1; + f->coders[i].numOutStreams = 1; + } else { + if (parse_7zip_uint64( + a, &(f->coders[i].numInStreams)) < 0) + return (-1); + if (UMAX_ENTRY < f->coders[i].numInStreams) + return (-1); + if (parse_7zip_uint64( + a, &(f->coders[i].numOutStreams)) < 0) + return (-1); + if (UMAX_ENTRY < f->coders[i].numOutStreams) + return (-1); + } + + if (attr) { + if (parse_7zip_uint64( + a, &(f->coders[i].propertiesSize)) < 0) + return (-1); + if ((p = header_bytes( + a, (size_t)f->coders[i].propertiesSize)) == NULL) + return (-1); + f->coders[i].properties = + malloc((size_t)f->coders[i].propertiesSize); + if (f->coders[i].properties == NULL) + return (-1); + memcpy(f->coders[i].properties, p, + (size_t)f->coders[i].propertiesSize); + } + + numInStreamsTotal += f->coders[i].numInStreams; + numOutStreamsTotal += f->coders[i].numOutStreams; + } + + if (numOutStreamsTotal == 0 || + numInStreamsTotal < numOutStreamsTotal-1) + return (-1); + + f->numBindPairs = numOutStreamsTotal - 1; + if (zip->header_bytes_remaining < f->numBindPairs) + return (-1); + if (f->numBindPairs > 0) { + f->bindPairs = + calloc((size_t)f->numBindPairs, sizeof(*f->bindPairs)); + if (f->bindPairs == NULL) + return (-1); + } else + f->bindPairs = NULL; + for (i = 0; i < f->numBindPairs; i++) { + if (parse_7zip_uint64(a, &(f->bindPairs[i].inIndex)) < 0) + return (-1); + if (UMAX_ENTRY < f->bindPairs[i].inIndex) + return (-1); + if (parse_7zip_uint64(a, &(f->bindPairs[i].outIndex)) < 0) + return (-1); + if (UMAX_ENTRY < f->bindPairs[i].outIndex) + return (-1); + } + + f->numPackedStreams = numInStreamsTotal - f->numBindPairs; + f->packedStreams = + calloc((size_t)f->numPackedStreams, sizeof(*f->packedStreams)); + if (f->packedStreams == NULL) + return (-1); + if (f->numPackedStreams == 1) { + for (i = 0; i < numInStreamsTotal; i++) { + unsigned j; + for (j = 0; j < f->numBindPairs; j++) { + if (f->bindPairs[j].inIndex == i) + break; + } + if (j == f->numBindPairs) + break; + } + if (i == numInStreamsTotal) + return (-1); + f->packedStreams[0] = i; + } else { + for (i = 0; i < f->numPackedStreams; i++) { + if (parse_7zip_uint64(a, &(f->packedStreams[i])) < 0) + return (-1); + if (UMAX_ENTRY < f->packedStreams[i]) + return (-1); + } + } + f->numInStreams = numInStreamsTotal; + f->numOutStreams = numOutStreamsTotal; + + return (0); +} + +static void +free_CodersInfo(struct _7z_coders_info *ci) +{ + unsigned i; + + if (ci->folders) { + for (i = 0; i < ci->numFolders; i++) + free_Folder(&(ci->folders[i])); + free(ci->folders); + } +} + +static int +read_CodersInfo(struct archive_read *a, struct _7z_coders_info *ci) +{ + const unsigned char *p; + struct _7z_digests digest; + unsigned i; + + memset(ci, 0, sizeof(*ci)); + memset(&digest, 0, sizeof(digest)); + + if ((p = header_bytes(a, 1)) == NULL) + goto failed; + if (*p != kFolder) + goto failed; + + /* + * Read NumFolders. + */ + if (parse_7zip_uint64(a, &(ci->numFolders)) < 0) + goto failed; + if (UMAX_ENTRY < ci->numFolders) + return (-1); + + /* + * Read External. + */ + if ((p = header_bytes(a, 1)) == NULL) + goto failed; + switch (*p) { + case 0: + ci->folders = + calloc((size_t)ci->numFolders, sizeof(*ci->folders)); + if (ci->folders == NULL) + return (-1); + for (i = 0; i < ci->numFolders; i++) { + if (read_Folder(a, &(ci->folders[i])) < 0) + goto failed; + } + break; + case 1: + if (parse_7zip_uint64(a, &(ci->dataStreamIndex)) < 0) + return (-1); + if (UMAX_ENTRY < ci->dataStreamIndex) + return (-1); + if (ci->numFolders > 0) { + archive_set_error(&a->archive, -1, + "Malformed 7-Zip archive"); + goto failed; + } + break; + default: + archive_set_error(&a->archive, -1, + "Malformed 7-Zip archive"); + goto failed; + } + + if ((p = header_bytes(a, 1)) == NULL) + goto failed; + if (*p != kCodersUnPackSize) + goto failed; + + for (i = 0; i < ci->numFolders; i++) { + struct _7z_folder *folder = &(ci->folders[i]); + unsigned j; + + folder->unPackSize = + calloc((size_t)folder->numOutStreams, sizeof(*folder->unPackSize)); + if (folder->unPackSize == NULL) + goto failed; + for (j = 0; j < folder->numOutStreams; j++) { + if (parse_7zip_uint64(a, &(folder->unPackSize[j])) < 0) + goto failed; + } + } + + /* + * Read CRCs. + */ + if ((p = header_bytes(a, 1)) == NULL) + goto failed; + if (*p == kEnd) + return (0); + if (*p != kCRC) + goto failed; + if (read_Digests(a, &digest, (size_t)ci->numFolders) < 0) + goto failed; + for (i = 0; i < ci->numFolders; i++) { + ci->folders[i].digest_defined = digest.defineds[i]; + ci->folders[i].digest = digest.digests[i]; + } + + /* + * Must be kEnd. + */ + if ((p = header_bytes(a, 1)) == NULL) + goto failed; + if (*p != kEnd) + goto failed; + free_Digest(&digest); + return (0); +failed: + free_Digest(&digest); + return (-1); +} + +static uint64_t +folder_uncompressed_size(struct _7z_folder *f) +{ + int n = (int)f->numOutStreams; + unsigned pairs = (unsigned)f->numBindPairs; + + while (--n >= 0) { + unsigned i; + for (i = 0; i < pairs; i++) { + if (f->bindPairs[i].outIndex == (uint64_t)n) + break; + } + if (i >= pairs) + return (f->unPackSize[n]); + } + return (0); +} + +static void +free_SubStreamsInfo(struct _7z_substream_info *ss) +{ + free(ss->unpackSizes); + free(ss->digestsDefined); + free(ss->digests); +} + +static int +read_SubStreamsInfo(struct archive_read *a, struct _7z_substream_info *ss, + struct _7z_folder *f, size_t numFolders) +{ + const unsigned char *p; + uint64_t *usizes; + size_t unpack_streams; + int type; + unsigned i; + uint32_t numDigests; + + memset(ss, 0, sizeof(*ss)); + + for (i = 0; i < numFolders; i++) + f[i].numUnpackStreams = 1; + + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + type = *p; + + if (type == kNumUnPackStream) { + unpack_streams = 0; + for (i = 0; i < numFolders; i++) { + if (parse_7zip_uint64(a, &(f[i].numUnpackStreams)) < 0) + return (-1); + if (UMAX_ENTRY < f[i].numUnpackStreams) + return (-1); + if (unpack_streams > SIZE_MAX - UMAX_ENTRY) { + return (-1); + } + unpack_streams += (size_t)f[i].numUnpackStreams; + } + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + type = *p; + } else + unpack_streams = numFolders; + + ss->unpack_streams = unpack_streams; + if (unpack_streams) { + ss->unpackSizes = calloc(unpack_streams, + sizeof(*ss->unpackSizes)); + ss->digestsDefined = calloc(unpack_streams, + sizeof(*ss->digestsDefined)); + ss->digests = calloc(unpack_streams, + sizeof(*ss->digests)); + if (ss->unpackSizes == NULL || ss->digestsDefined == NULL || + ss->digests == NULL) + return (-1); + } + + usizes = ss->unpackSizes; + for (i = 0; i < numFolders; i++) { + unsigned pack; + uint64_t sum; + + if (f[i].numUnpackStreams == 0) + continue; + + sum = 0; + if (type == kSize) { + for (pack = 1; pack < f[i].numUnpackStreams; pack++) { + if (parse_7zip_uint64(a, usizes) < 0) + return (-1); + sum += *usizes++; + } + } + *usizes++ = folder_uncompressed_size(&f[i]) - sum; + } + + if (type == kSize) { + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + type = *p; + } + + for (i = 0; i < unpack_streams; i++) { + ss->digestsDefined[i] = 0; + ss->digests[i] = 0; + } + + numDigests = 0; + for (i = 0; i < numFolders; i++) { + if (f[i].numUnpackStreams != 1 || !f[i].digest_defined) + numDigests += (uint32_t)f[i].numUnpackStreams; + } + + if (type == kCRC) { + struct _7z_digests tmpDigests; + unsigned char *digestsDefined = ss->digestsDefined; + uint32_t * digests = ss->digests; + int di = 0; + + memset(&tmpDigests, 0, sizeof(tmpDigests)); + if (read_Digests(a, &(tmpDigests), numDigests) < 0) { + free_Digest(&tmpDigests); + return (-1); + } + for (i = 0; i < numFolders; i++) { + if (f[i].numUnpackStreams == 1 && f[i].digest_defined) { + *digestsDefined++ = 1; + *digests++ = f[i].digest; + } else { + unsigned j; + + for (j = 0; j < f[i].numUnpackStreams; + j++, di++) { + *digestsDefined++ = + tmpDigests.defineds[di]; + *digests++ = + tmpDigests.digests[di]; + } + } + } + free_Digest(&tmpDigests); + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + type = *p; + } + + /* + * Must be kEnd. + */ + if (type != kEnd) + return (-1); + return (0); +} + +static void +free_StreamsInfo(struct _7z_stream_info *si) +{ + free_PackInfo(&(si->pi)); + free_CodersInfo(&(si->ci)); + free_SubStreamsInfo(&(si->ss)); +} + +static int +read_StreamsInfo(struct archive_read *a, struct _7z_stream_info *si) +{ + struct _7zip *zip = (struct _7zip *)a->format->data; + const unsigned char *p; + unsigned i; + + memset(si, 0, sizeof(*si)); + + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + if (*p == kPackInfo) { + uint64_t packPos; + + if (read_PackInfo(a, &(si->pi)) < 0) + return (-1); + + if (si->pi.positions == NULL || si->pi.sizes == NULL) + return (-1); + /* + * Calculate packed stream positions. + */ + packPos = si->pi.pos; + for (i = 0; i < si->pi.numPackStreams; i++) { + si->pi.positions[i] = packPos; + packPos += si->pi.sizes[i]; + if (packPos > zip->header_offset) + return (-1); + } + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + } + if (*p == kUnPackInfo) { + uint32_t packIndex; + struct _7z_folder *f; + + if (read_CodersInfo(a, &(si->ci)) < 0) + return (-1); + + /* + * Calculate packed stream indexes. + */ + packIndex = 0; + f = si->ci.folders; + for (i = 0; i < si->ci.numFolders; i++) { + f[i].packIndex = packIndex; + packIndex += (uint32_t)f[i].numPackedStreams; + if (packIndex > si->pi.numPackStreams) + return (-1); + } + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + } + + if (*p == kSubStreamsInfo) { + if (read_SubStreamsInfo(a, &(si->ss), + si->ci.folders, (size_t)si->ci.numFolders) < 0) + return (-1); + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + } + + /* + * Must be kEnd. + */ + if (*p != kEnd) + return (-1); + return (0); +} + +static void +free_Header(struct _7z_header_info *h) +{ + free(h->emptyStreamBools); + free(h->emptyFileBools); + free(h->antiBools); + free(h->attrBools); +} + +static int +read_Header(struct archive_read *a, struct _7z_header_info *h, + int check_header_id) +{ + struct _7zip *zip = (struct _7zip *)a->format->data; + const unsigned char *p; + struct _7z_folder *folders; + struct _7z_stream_info *si = &(zip->si); + struct _7zip_entry *entries; + uint32_t folderIndex, indexInFolder; + unsigned i; + int eindex, empty_streams, sindex; + + if (check_header_id) { + /* + * Read Header. + */ + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + if (*p != kHeader) + return (-1); + } + + /* + * Read ArchiveProperties. + */ + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + if (*p == kArchiveProperties) { + for (;;) { + uint64_t size; + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + if (*p == 0) + break; + if (parse_7zip_uint64(a, &size) < 0) + return (-1); + } + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + } + + /* + * Read MainStreamsInfo. + */ + if (*p == kMainStreamsInfo) { + if (read_StreamsInfo(a, &(zip->si)) < 0) + return (-1); + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + } + if (*p == kEnd) + return (0); + + /* + * Read FilesInfo. + */ + if (*p != kFilesInfo) + return (-1); + + if (parse_7zip_uint64(a, &(zip->numFiles)) < 0) + return (-1); + if (UMAX_ENTRY < zip->numFiles) + return (-1); + + zip->entries = calloc((size_t)zip->numFiles, sizeof(*zip->entries)); + if (zip->entries == NULL) + return (-1); + entries = zip->entries; + + empty_streams = 0; + for (;;) { + int type; + uint64_t size; + size_t ll; + + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + type = *p; + if (type == kEnd) + break; + + if (parse_7zip_uint64(a, &size) < 0) + return (-1); + if (zip->header_bytes_remaining < size) + return (-1); + ll = (size_t)size; + + switch (type) { + case kEmptyStream: + if (h->emptyStreamBools != NULL) + return (-1); + h->emptyStreamBools = calloc((size_t)zip->numFiles, + sizeof(*h->emptyStreamBools)); + if (h->emptyStreamBools == NULL) + return (-1); + if (read_Bools( + a, h->emptyStreamBools, (size_t)zip->numFiles) < 0) + return (-1); + empty_streams = 0; + for (i = 0; i < zip->numFiles; i++) { + if (h->emptyStreamBools[i]) + empty_streams++; + } + break; + case kEmptyFile: + if (empty_streams <= 0) { + /* Unexcepted sequence. Skip this. */ + if (header_bytes(a, ll) == NULL) + return (-1); + break; + } + if (h->emptyFileBools != NULL) + return (-1); + h->emptyFileBools = calloc(empty_streams, + sizeof(*h->emptyFileBools)); + if (h->emptyFileBools == NULL) + return (-1); + if (read_Bools(a, h->emptyFileBools, empty_streams) < 0) + return (-1); + break; + case kAnti: + if (empty_streams <= 0) { + /* Unexcepted sequence. Skip this. */ + if (header_bytes(a, ll) == NULL) + return (-1); + break; + } + if (h->antiBools != NULL) + return (-1); + h->antiBools = calloc(empty_streams, + sizeof(*h->antiBools)); + if (h->antiBools == NULL) + return (-1); + if (read_Bools(a, h->antiBools, empty_streams) < 0) + return (-1); + break; + case kCTime: + case kATime: + case kMTime: + if (read_Times(a, h, type) < 0) + return (-1); + break; + case kName: + { + unsigned char *np; + size_t nl, nb; + + /* Skip one byte. */ + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + ll--; + + if ((ll & 1) || ll < zip->numFiles * 4) + return (-1); + + if (zip->entry_names != NULL) + return (-1); + zip->entry_names = malloc(ll); + if (zip->entry_names == NULL) + return (-1); + np = zip->entry_names; + nb = ll; + /* + * Copy whole file names. + * NOTE: This loop prevents from expanding + * the uncompressed buffer in order not to + * use extra memory resource. + */ + while (nb) { + size_t b; + if (nb > UBUFF_SIZE) + b = UBUFF_SIZE; + else + b = nb; + if ((p = header_bytes(a, b)) == NULL) + return (-1); + memcpy(np, p, b); + np += b; + nb -= b; + } + np = zip->entry_names; + nl = ll; + + for (i = 0; i < zip->numFiles; i++) { + entries[i].utf16name = np; +#if defined(_WIN32) && !defined(__CYGWIN__) && defined(_DEBUG) + entries[i].wname = (wchar_t *)np; +#endif + + /* Find a terminator. */ + while (nl >= 2 && (np[0] || np[1])) { + np += 2; + nl -= 2; + } + if (nl < 2) + return (-1);/* Terminator not found */ + entries[i].name_len = np - entries[i].utf16name; + np += 2; + nl -= 2; + } + break; + } + case kAttributes: + { + int allAreDefined; + + if ((p = header_bytes(a, 2)) == NULL) + return (-1); + allAreDefined = *p; + if (h->attrBools != NULL) + return (-1); + h->attrBools = calloc((size_t)zip->numFiles, + sizeof(*h->attrBools)); + if (h->attrBools == NULL) + return (-1); + if (allAreDefined) + memset(h->attrBools, 1, (size_t)zip->numFiles); + else { + if (read_Bools(a, h->attrBools, + (size_t)zip->numFiles) < 0) + return (-1); + } + for (i = 0; i < zip->numFiles; i++) { + if (h->attrBools[i]) { + if ((p = header_bytes(a, 4)) == NULL) + return (-1); + entries[i].attr = archive_le32dec(p); + } + } + break; + } + case kDummy: + if (ll == 0) + break; ++ __LA_FALLTHROUGH; + default: + if (header_bytes(a, ll) == NULL) + return (-1); + break; + } + } + + /* + * Set up entry's attributes. + */ + folders = si->ci.folders; + eindex = sindex = 0; + folderIndex = indexInFolder = 0; + for (i = 0; i < zip->numFiles; i++) { + if (h->emptyStreamBools == NULL || h->emptyStreamBools[i] == 0) + entries[i].flg |= HAS_STREAM; + /* The high 16 bits of attributes is a posix file mode. */ + entries[i].mode = entries[i].attr >> 16; + if (entries[i].flg & HAS_STREAM) { + if ((size_t)sindex >= si->ss.unpack_streams) + return (-1); + if (entries[i].mode == 0) + entries[i].mode = AE_IFREG | 0666; + if (si->ss.digestsDefined[sindex]) + entries[i].flg |= CRC32_IS_SET; + entries[i].ssIndex = sindex; + sindex++; + } else { + int dir; + if (h->emptyFileBools == NULL) + dir = 1; + else { + if (h->emptyFileBools[eindex]) + dir = 0; + else + dir = 1; + eindex++; + } + if (entries[i].mode == 0) { + if (dir) + entries[i].mode = AE_IFDIR | 0777; + else + entries[i].mode = AE_IFREG | 0666; + } else if (dir && + (entries[i].mode & AE_IFMT) != AE_IFDIR) { + entries[i].mode &= ~AE_IFMT; + entries[i].mode |= AE_IFDIR; + } + if ((entries[i].mode & AE_IFMT) == AE_IFDIR && + entries[i].name_len >= 2 && + (entries[i].utf16name[entries[i].name_len-2] != '/' || + entries[i].utf16name[entries[i].name_len-1] != 0)) { + entries[i].utf16name[entries[i].name_len] = '/'; + entries[i].utf16name[entries[i].name_len+1] = 0; + entries[i].name_len += 2; + } + entries[i].ssIndex = -1; + } + if (entries[i].attr & 0x01) + entries[i].mode &= ~0222;/* Read only. */ + + if ((entries[i].flg & HAS_STREAM) == 0 && indexInFolder == 0) { + /* + * The entry is an empty file or a directory file, + * those both have no contents. + */ + entries[i].folderIndex = -1; + continue; + } + if (indexInFolder == 0) { + for (;;) { + if (folderIndex >= si->ci.numFolders) + return (-1); + if (folders[folderIndex].numUnpackStreams) + break; + folderIndex++; + } + } + entries[i].folderIndex = folderIndex; + if ((entries[i].flg & HAS_STREAM) == 0) + continue; + indexInFolder++; + if (indexInFolder >= folders[folderIndex].numUnpackStreams) { + folderIndex++; + indexInFolder = 0; + } + } + + return (0); +} + +#define EPOC_TIME ARCHIVE_LITERAL_ULL(116444736000000000) +static void +fileTimeToUtc(uint64_t fileTime, time_t *timep, long *ns) +{ + + if (fileTime >= EPOC_TIME) { + fileTime -= EPOC_TIME; + /* milli seconds base */ + *timep = (time_t)(fileTime / 10000000); + /* nano seconds base */ + *ns = (long)(fileTime % 10000000) * 100; + } else { + *timep = 0; + *ns = 0; + } +} + +static int +read_Times(struct archive_read *a, struct _7z_header_info *h, int type) +{ + struct _7zip *zip = (struct _7zip *)a->format->data; + const unsigned char *p; + struct _7zip_entry *entries = zip->entries; + unsigned char *timeBools; + int allAreDefined; + unsigned i; + + timeBools = calloc((size_t)zip->numFiles, sizeof(*timeBools)); + if (timeBools == NULL) + return (-1); + + /* Read allAreDefined. */ + if ((p = header_bytes(a, 1)) == NULL) + goto failed; + allAreDefined = *p; + if (allAreDefined) + memset(timeBools, 1, (size_t)zip->numFiles); + else { + if (read_Bools(a, timeBools, (size_t)zip->numFiles) < 0) + goto failed; + } + + /* Read external. */ + if ((p = header_bytes(a, 1)) == NULL) + goto failed; + if (*p) { + if (parse_7zip_uint64(a, &(h->dataIndex)) < 0) + goto failed; + if (UMAX_ENTRY < h->dataIndex) + goto failed; + } + + for (i = 0; i < zip->numFiles; i++) { + if (!timeBools[i]) + continue; + if ((p = header_bytes(a, 8)) == NULL) + goto failed; + switch (type) { + case kCTime: + fileTimeToUtc(archive_le64dec(p), + &(entries[i].ctime), + &(entries[i].ctime_ns)); + entries[i].flg |= CTIME_IS_SET; + break; + case kATime: + fileTimeToUtc(archive_le64dec(p), + &(entries[i].atime), + &(entries[i].atime_ns)); + entries[i].flg |= ATIME_IS_SET; + break; + case kMTime: + fileTimeToUtc(archive_le64dec(p), + &(entries[i].mtime), + &(entries[i].mtime_ns)); + entries[i].flg |= MTIME_IS_SET; + break; + } + } + + free(timeBools); + return (0); +failed: + free(timeBools); + return (-1); +} + +static int +decode_encoded_header_info(struct archive_read *a, struct _7z_stream_info *si) +{ + struct _7zip *zip = (struct _7zip *)a->format->data; + + errno = 0; + if (read_StreamsInfo(a, si) < 0) { + if (errno == ENOMEM) + archive_set_error(&a->archive, -1, + "Couldn't allocate memory"); + else + archive_set_error(&a->archive, -1, + "Malformed 7-Zip archive"); + return (ARCHIVE_FATAL); + } + + if (si->pi.numPackStreams == 0 || si->ci.numFolders == 0) { + archive_set_error(&a->archive, -1, "Malformed 7-Zip archive"); + return (ARCHIVE_FATAL); + } + + if (zip->header_offset < si->pi.pos + si->pi.sizes[0] || + (int64_t)(si->pi.pos + si->pi.sizes[0]) < 0 || + si->pi.sizes[0] == 0 || (int64_t)si->pi.pos < 0) { + archive_set_error(&a->archive, -1, "Malformed Header offset"); + return (ARCHIVE_FATAL); + } + + return (ARCHIVE_OK); +} + +static const unsigned char * +header_bytes(struct archive_read *a, size_t rbytes) +{ + struct _7zip *zip = (struct _7zip *)a->format->data; + const unsigned char *p; + + if (zip->header_bytes_remaining < rbytes) + return (NULL); + if (zip->pack_stream_bytes_unconsumed) + read_consume(a); + + if (zip->header_is_encoded == 0) { + p = __archive_read_ahead(a, rbytes, NULL); + if (p == NULL) + return (NULL); + zip->header_bytes_remaining -= rbytes; + zip->pack_stream_bytes_unconsumed = rbytes; + } else { + const void *buff; + ssize_t bytes; + + bytes = read_stream(a, &buff, rbytes, rbytes); + if (bytes <= 0) + return (NULL); + zip->header_bytes_remaining -= bytes; + p = buff; + } + + /* Update checksum */ + zip->header_crc32 = crc32(zip->header_crc32, p, (unsigned)rbytes); + return (p); +} + +static int +slurp_central_directory(struct archive_read *a, struct _7zip *zip, + struct _7z_header_info *header) +{ + const unsigned char *p; + uint64_t next_header_offset; + uint64_t next_header_size; + uint32_t next_header_crc; + ssize_t bytes_avail; + int check_header_crc, r; + + if ((p = __archive_read_ahead(a, 32, &bytes_avail)) == NULL) + return (ARCHIVE_FATAL); + + if ((p[0] == 'M' && p[1] == 'Z') || memcmp(p, "\x7F\x45LF", 4) == 0) { + /* This is an executable ? Must be self-extracting... */ + r = skip_sfx(a, bytes_avail); + if (r < ARCHIVE_WARN) + return (r); + if ((p = __archive_read_ahead(a, 32, &bytes_avail)) == NULL) + return (ARCHIVE_FATAL); + } + zip->seek_base += 32; + + if (memcmp(p, _7ZIP_SIGNATURE, 6) != 0) { + archive_set_error(&a->archive, -1, "Not 7-Zip archive file"); + return (ARCHIVE_FATAL); + } + + /* CRC check. */ + if (crc32(0, (const unsigned char *)p + 12, 20) + != archive_le32dec(p + 8)) { + archive_set_error(&a->archive, -1, "Header CRC error"); + return (ARCHIVE_FATAL); + } + + next_header_offset = archive_le64dec(p + 12); + next_header_size = archive_le64dec(p + 20); + next_header_crc = archive_le32dec(p + 28); + + if (next_header_size == 0) + /* There is no entry in an archive file. */ + return (ARCHIVE_EOF); + + if (((int64_t)next_header_offset) < 0) { + archive_set_error(&a->archive, -1, "Malformed 7-Zip archive"); + return (ARCHIVE_FATAL); + } + __archive_read_consume(a, 32); + if (next_header_offset != 0) { + if (bytes_avail >= (ssize_t)next_header_offset) + __archive_read_consume(a, next_header_offset); + else if (__archive_read_seek(a, + next_header_offset + zip->seek_base, SEEK_SET) < 0) + return (ARCHIVE_FATAL); + } + zip->stream_offset = next_header_offset; + zip->header_offset = next_header_offset; + zip->header_bytes_remaining = next_header_size; + zip->header_crc32 = 0; + zip->header_is_encoded = 0; + zip->header_is_being_read = 1; + zip->has_encrypted_entries = 0; + check_header_crc = 1; + + if ((p = header_bytes(a, 1)) == NULL) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated 7-Zip file body"); + return (ARCHIVE_FATAL); + } + /* Parse ArchiveProperties. */ + switch (p[0]) { + case kEncodedHeader: + /* + * The archive has an encoded header and we have to decode it + * in order to parse the header correctly. + */ + r = decode_encoded_header_info(a, &(zip->si)); + + /* Check the EncodedHeader CRC.*/ + if (r == 0 && zip->header_crc32 != next_header_crc) { + archive_set_error(&a->archive, -1, + "Damaged 7-Zip archive"); + r = -1; + } + if (r == 0) { + if (zip->si.ci.folders[0].digest_defined) + next_header_crc = zip->si.ci.folders[0].digest; + else + check_header_crc = 0; + if (zip->pack_stream_bytes_unconsumed) + read_consume(a); + r = setup_decode_folder(a, zip->si.ci.folders, 1); + if (r == 0) { + zip->header_bytes_remaining = + zip->folder_outbytes_remaining; + r = seek_pack(a); + } + } + /* Clean up StreamsInfo. */ + free_StreamsInfo(&(zip->si)); + memset(&(zip->si), 0, sizeof(zip->si)); + if (r < 0) + return (ARCHIVE_FATAL); + zip->header_is_encoded = 1; + zip->header_crc32 = 0; + /* FALL THROUGH */ + case kHeader: + /* + * Parse the header. + */ + errno = 0; + r = read_Header(a, header, zip->header_is_encoded); + if (r < 0) { + if (errno == ENOMEM) + archive_set_error(&a->archive, -1, + "Couldn't allocate memory"); + else + archive_set_error(&a->archive, -1, + "Damaged 7-Zip archive"); + return (ARCHIVE_FATAL); + } + + /* + * Must be kEnd. + */ + if ((p = header_bytes(a, 1)) == NULL ||*p != kEnd) { + archive_set_error(&a->archive, -1, + "Malformed 7-Zip archive"); + return (ARCHIVE_FATAL); + } + + /* Check the Header CRC.*/ + if (check_header_crc && zip->header_crc32 != next_header_crc) { + archive_set_error(&a->archive, -1, + "Malformed 7-Zip archive"); + return (ARCHIVE_FATAL); + } + break; + default: + archive_set_error(&a->archive, -1, + "Unexpected Property ID = %X", p[0]); + return (ARCHIVE_FATAL); + } + + /* Clean up variables be used for decoding the archive header */ + zip->pack_stream_remaining = 0; + zip->pack_stream_index = 0; + zip->folder_outbytes_remaining = 0; + zip->uncompressed_buffer_bytes_remaining = 0; + zip->pack_stream_bytes_unconsumed = 0; + zip->header_is_being_read = 0; + + return (ARCHIVE_OK); +} + +static ssize_t +get_uncompressed_data(struct archive_read *a, const void **buff, size_t size, + size_t minimum) +{ + struct _7zip *zip = (struct _7zip *)a->format->data; + ssize_t bytes_avail; + + if (zip->codec == _7Z_COPY && zip->codec2 == (unsigned long)-1) { + /* Copy mode. */ + + /* + * Note: '1' here is a performance optimization. + * Recall that the decompression layer returns a count of + * available bytes; asking for more than that forces the + * decompressor to combine reads by copying data. + */ + *buff = __archive_read_ahead(a, 1, &bytes_avail); + if (bytes_avail <= 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated 7-Zip file data"); + return (ARCHIVE_FATAL); + } + if ((size_t)bytes_avail > + zip->uncompressed_buffer_bytes_remaining) + bytes_avail = (ssize_t) + zip->uncompressed_buffer_bytes_remaining; + if ((size_t)bytes_avail > size) + bytes_avail = (ssize_t)size; + + zip->pack_stream_bytes_unconsumed = bytes_avail; + } else if (zip->uncompressed_buffer_pointer == NULL) { + /* Decompression has failed. */ + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, "Damaged 7-Zip archive"); + return (ARCHIVE_FATAL); + } else { + /* Packed mode. */ + if (minimum > zip->uncompressed_buffer_bytes_remaining) { + /* + * If remaining uncompressed data size is less than + * the minimum size, fill the buffer up to the + * minimum size. + */ + if (extract_pack_stream(a, minimum) < 0) + return (ARCHIVE_FATAL); + } + if (size > zip->uncompressed_buffer_bytes_remaining) + bytes_avail = (ssize_t) + zip->uncompressed_buffer_bytes_remaining; + else + bytes_avail = (ssize_t)size; + *buff = zip->uncompressed_buffer_pointer; + zip->uncompressed_buffer_pointer += bytes_avail; + } + zip->uncompressed_buffer_bytes_remaining -= bytes_avail; + return (bytes_avail); +} + +static ssize_t +extract_pack_stream(struct archive_read *a, size_t minimum) +{ + struct _7zip *zip = (struct _7zip *)a->format->data; + ssize_t bytes_avail; + int r; + + if (zip->codec == _7Z_COPY && zip->codec2 == (unsigned long)-1) { + if (minimum == 0) + minimum = 1; + if (__archive_read_ahead(a, minimum, &bytes_avail) == NULL + || bytes_avail <= 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated 7-Zip file body"); + return (ARCHIVE_FATAL); + } + if (bytes_avail > (ssize_t)zip->pack_stream_inbytes_remaining) + bytes_avail = (ssize_t)zip->pack_stream_inbytes_remaining; + zip->pack_stream_inbytes_remaining -= bytes_avail; + if (bytes_avail > (ssize_t)zip->folder_outbytes_remaining) + bytes_avail = (ssize_t)zip->folder_outbytes_remaining; + zip->folder_outbytes_remaining -= bytes_avail; + zip->uncompressed_buffer_bytes_remaining = bytes_avail; + return (ARCHIVE_OK); + } + + /* If the buffer hasn't been allocated, allocate it now. */ + if (zip->uncompressed_buffer == NULL) { + zip->uncompressed_buffer_size = UBUFF_SIZE; + if (zip->uncompressed_buffer_size < minimum) { + zip->uncompressed_buffer_size = minimum + 1023; + zip->uncompressed_buffer_size &= ~0x3ff; + } + zip->uncompressed_buffer = + malloc(zip->uncompressed_buffer_size); + if (zip->uncompressed_buffer == NULL) { + archive_set_error(&a->archive, ENOMEM, + "No memory for 7-Zip decompression"); + return (ARCHIVE_FATAL); + } + zip->uncompressed_buffer_bytes_remaining = 0; + } else if (zip->uncompressed_buffer_size < minimum || + zip->uncompressed_buffer_bytes_remaining < minimum) { + /* + * Make sure the uncompressed buffer can have bytes + * at least `minimum' bytes. + * NOTE: This case happen when reading the header. + */ + size_t used; + if (zip->uncompressed_buffer_pointer != 0) + used = zip->uncompressed_buffer_pointer - + zip->uncompressed_buffer; + else + used = 0; + if (zip->uncompressed_buffer_size < minimum) { + /* + * Expand the uncompressed buffer up to + * the minimum size. + */ + void *p; + size_t new_size; + + new_size = minimum + 1023; + new_size &= ~0x3ff; + p = realloc(zip->uncompressed_buffer, new_size); + if (p == NULL) { + archive_set_error(&a->archive, ENOMEM, + "No memory for 7-Zip decompression"); + return (ARCHIVE_FATAL); + } + zip->uncompressed_buffer = (unsigned char *)p; + zip->uncompressed_buffer_size = new_size; + } + /* + * Move unconsumed bytes to the head. + */ + if (used) { + memmove(zip->uncompressed_buffer, + zip->uncompressed_buffer + used, + zip->uncompressed_buffer_bytes_remaining); + } + } else + zip->uncompressed_buffer_bytes_remaining = 0; + zip->uncompressed_buffer_pointer = NULL; + for (;;) { + size_t bytes_in, bytes_out; + const void *buff_in; + unsigned char *buff_out; + int end_of_data; + + /* + * Note: '1' here is a performance optimization. + * Recall that the decompression layer returns a count of + * available bytes; asking for more than that forces the + * decompressor to combine reads by copying data. + */ + buff_in = __archive_read_ahead(a, 1, &bytes_avail); + if (bytes_avail <= 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated 7-Zip file body"); + return (ARCHIVE_FATAL); + } + + buff_out = zip->uncompressed_buffer + + zip->uncompressed_buffer_bytes_remaining; + bytes_out = zip->uncompressed_buffer_size + - zip->uncompressed_buffer_bytes_remaining; + bytes_in = bytes_avail; + if (bytes_in > zip->pack_stream_inbytes_remaining) + bytes_in = (size_t)zip->pack_stream_inbytes_remaining; + /* Drive decompression. */ + r = decompress(a, zip, buff_out, &bytes_out, + buff_in, &bytes_in); + switch (r) { + case ARCHIVE_OK: + end_of_data = 0; + break; + case ARCHIVE_EOF: + end_of_data = 1; + break; + default: + return (ARCHIVE_FATAL); + } + zip->pack_stream_inbytes_remaining -= bytes_in; + if (bytes_out > zip->folder_outbytes_remaining) + bytes_out = (size_t)zip->folder_outbytes_remaining; + zip->folder_outbytes_remaining -= bytes_out; + zip->uncompressed_buffer_bytes_remaining += bytes_out; + zip->pack_stream_bytes_unconsumed = bytes_in; + + /* + * Continue decompression until uncompressed_buffer is full. + */ + if (zip->uncompressed_buffer_bytes_remaining == + zip->uncompressed_buffer_size) + break; + if (zip->codec2 == _7Z_X86 && zip->odd_bcj_size && + zip->uncompressed_buffer_bytes_remaining + 5 > + zip->uncompressed_buffer_size) + break; + if (zip->pack_stream_inbytes_remaining == 0 && + zip->folder_outbytes_remaining == 0) + break; + if (end_of_data || (bytes_in == 0 && bytes_out == 0)) { + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, "Damaged 7-Zip archive"); + return (ARCHIVE_FATAL); + } + read_consume(a); + } + if (zip->uncompressed_buffer_bytes_remaining < minimum) { + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, "Damaged 7-Zip archive"); + return (ARCHIVE_FATAL); + } + zip->uncompressed_buffer_pointer = zip->uncompressed_buffer; + return (ARCHIVE_OK); +} + +static int +seek_pack(struct archive_read *a) +{ + struct _7zip *zip = (struct _7zip *)a->format->data; + int64_t pack_offset; + + if (zip->pack_stream_remaining <= 0) { + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, "Damaged 7-Zip archive"); + return (ARCHIVE_FATAL); + } + zip->pack_stream_inbytes_remaining = + zip->si.pi.sizes[zip->pack_stream_index]; + pack_offset = zip->si.pi.positions[zip->pack_stream_index]; + if (zip->stream_offset != pack_offset) { + if (0 > __archive_read_seek(a, pack_offset + zip->seek_base, + SEEK_SET)) + return (ARCHIVE_FATAL); + zip->stream_offset = pack_offset; + } + zip->pack_stream_index++; + zip->pack_stream_remaining--; + return (ARCHIVE_OK); +} + +static ssize_t +read_stream(struct archive_read *a, const void **buff, size_t size, + size_t minimum) +{ + struct _7zip *zip = (struct _7zip *)a->format->data; + uint64_t skip_bytes = 0; + ssize_t r; + + if (zip->uncompressed_buffer_bytes_remaining == 0) { + if (zip->pack_stream_inbytes_remaining > 0) { + r = extract_pack_stream(a, 0); + if (r < 0) + return (r); + return (get_uncompressed_data(a, buff, size, minimum)); + } else if (zip->folder_outbytes_remaining > 0) { + /* Extract a remaining pack stream. */ + r = extract_pack_stream(a, 0); + if (r < 0) + return (r); + return (get_uncompressed_data(a, buff, size, minimum)); + } + } else + return (get_uncompressed_data(a, buff, size, minimum)); + + /* + * Current pack stream has been consumed. + */ + if (zip->pack_stream_remaining == 0) { + if (zip->header_is_being_read) { + /* Invalid sequence. This might happen when + * reading a malformed archive. */ + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, "Malformed 7-Zip archive"); + return (ARCHIVE_FATAL); + } + + /* + * All current folder's pack streams have been + * consumed. Switch to next folder. + */ + if (zip->folder_index == 0 && + (zip->si.ci.folders[zip->entry->folderIndex].skipped_bytes + || zip->folder_index != zip->entry->folderIndex)) { + zip->folder_index = zip->entry->folderIndex; + skip_bytes = + zip->si.ci.folders[zip->folder_index].skipped_bytes; + } + + if (zip->folder_index >= zip->si.ci.numFolders) { + /* + * We have consumed all folders and its pack streams. + */ + *buff = NULL; + return (0); + } + r = setup_decode_folder(a, + &(zip->si.ci.folders[zip->folder_index]), 0); + if (r != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + zip->folder_index++; + } + + /* + * Switch to next pack stream. + */ + r = seek_pack(a); + if (r < 0) + return (r); + + /* Extract a new pack stream. */ + r = extract_pack_stream(a, 0); + if (r < 0) + return (r); + + /* + * Skip the bytes we already has skipped in skip_stream(). + */ + while (skip_bytes) { + ssize_t skipped; + + if (zip->uncompressed_buffer_bytes_remaining == 0) { + if (zip->pack_stream_inbytes_remaining > 0) { + r = extract_pack_stream(a, 0); + if (r < 0) + return (r); + } else if (zip->folder_outbytes_remaining > 0) { + /* Extract a remaining pack stream. */ + r = extract_pack_stream(a, 0); + if (r < 0) + return (r); + } else { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated 7-Zip file body"); + return (ARCHIVE_FATAL); + } + } + skipped = get_uncompressed_data( + a, buff, (size_t)skip_bytes, 0); + if (skipped < 0) + return (skipped); + skip_bytes -= skipped; + if (zip->pack_stream_bytes_unconsumed) + read_consume(a); + } + + return (get_uncompressed_data(a, buff, size, minimum)); +} + +static int +setup_decode_folder(struct archive_read *a, struct _7z_folder *folder, + int header) +{ + struct _7zip *zip = (struct _7zip *)a->format->data; + const struct _7z_coder *coder1, *coder2; + const char *cname = (header)?"archive header":"file content"; + unsigned i; + int r, found_bcj2 = 0; + + /* + * Release the memory which the previous folder used for BCJ2. + */ + for (i = 0; i < 3; i++) { + if (zip->sub_stream_buff[i] != NULL) + free(zip->sub_stream_buff[i]); + zip->sub_stream_buff[i] = NULL; + } + + /* + * Initialize a stream reader. + */ + zip->pack_stream_remaining = (unsigned)folder->numPackedStreams; + zip->pack_stream_index = (unsigned)folder->packIndex; + zip->folder_outbytes_remaining = folder_uncompressed_size(folder); + zip->uncompressed_buffer_bytes_remaining = 0; + + /* + * Check coder types. + */ + for (i = 0; i < folder->numCoders; i++) { + switch(folder->coders[i].codec) { + case _7Z_CRYPTO_MAIN_ZIP: + case _7Z_CRYPTO_RAR_29: + case _7Z_CRYPTO_AES_256_SHA_256: { + /* For entry that is associated with this folder, mark + it as encrypted (data+metadata). */ + zip->has_encrypted_entries = 1; + if (a->entry) { + archive_entry_set_is_data_encrypted(a->entry, 1); + archive_entry_set_is_metadata_encrypted(a->entry, 1); + } + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "The %s is encrypted, " + "but currently not supported", cname); + return (ARCHIVE_FATAL); + } + case _7Z_X86_BCJ2: { + found_bcj2++; + break; + } + } + } + /* Now that we've checked for encryption, if there were still no + * encrypted entries found we can say for sure that there are none. + */ + if (zip->has_encrypted_entries == ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW) { + zip->has_encrypted_entries = 0; + } + + if ((folder->numCoders > 2 && !found_bcj2) || found_bcj2 > 1) { + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "The %s is encoded with many filters, " + "but currently not supported", cname); + return (ARCHIVE_FATAL); + } + coder1 = &(folder->coders[0]); + if (folder->numCoders == 2) + coder2 = &(folder->coders[1]); + else + coder2 = NULL; + + if (found_bcj2) { + /* + * Preparation to decode BCJ2. + * Decoding BCJ2 requires four sources. Those are at least, + * as far as I know, two types of the storage form. + */ + const struct _7z_coder *fc = folder->coders; + static const struct _7z_coder coder_copy = {0, 1, 1, 0, NULL}; + const struct _7z_coder *scoder[3] = + {&coder_copy, &coder_copy, &coder_copy}; + const void *buff; + ssize_t bytes; + unsigned char *b[3] = {NULL, NULL, NULL}; + uint64_t sunpack[3] ={-1, -1, -1}; + size_t s[3] = {0, 0, 0}; + int idx[3] = {0, 1, 2}; + + if (folder->numCoders == 4 && fc[3].codec == _7Z_X86_BCJ2 && + folder->numInStreams == 7 && folder->numOutStreams == 4 && + zip->pack_stream_remaining == 4) { + /* Source type 1 made by 7zr or 7z with -m options. */ + if (folder->bindPairs[0].inIndex == 5) { + /* The form made by 7zr */ + idx[0] = 1; idx[1] = 2; idx[2] = 0; + scoder[1] = &(fc[1]); + scoder[2] = &(fc[0]); + sunpack[1] = folder->unPackSize[1]; + sunpack[2] = folder->unPackSize[0]; + coder1 = &(fc[2]); + } else { + /* + * NOTE: Some patterns do not work. + * work: + * 7z a -m0=BCJ2 -m1=COPY -m2=COPY + * -m3=(any) + * 7z a -m0=BCJ2 -m1=COPY -m2=(any) + * -m3=COPY + * 7z a -m0=BCJ2 -m1=(any) -m2=COPY + * -m3=COPY + * not work: + * other patterns. + * + * We have to handle this like `pipe' or + * our libarchive7s filter frame work, + * decoding the BCJ2 main stream sequentially, + * m3 -> m2 -> m1 -> BCJ2. + * + */ + if (fc[0].codec == _7Z_COPY && + fc[1].codec == _7Z_COPY) + coder1 = &(folder->coders[2]); + else if (fc[0].codec == _7Z_COPY && + fc[2].codec == _7Z_COPY) + coder1 = &(folder->coders[1]); + else if (fc[1].codec == _7Z_COPY && + fc[2].codec == _7Z_COPY) + coder1 = &(folder->coders[0]); + else { + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "Unsupported form of " + "BCJ2 streams"); + return (ARCHIVE_FATAL); + } + } + coder2 = &(fc[3]); + zip->main_stream_bytes_remaining = + (size_t)folder->unPackSize[2]; + } else if (coder2 != NULL && coder2->codec == _7Z_X86_BCJ2 && + zip->pack_stream_remaining == 4 && + folder->numInStreams == 5 && folder->numOutStreams == 2) { + /* Source type 0 made by 7z */ + zip->main_stream_bytes_remaining = + (size_t)folder->unPackSize[0]; + } else { + /* We got an unexpected form. */ + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "Unsupported form of BCJ2 streams"); + return (ARCHIVE_FATAL); + } + + /* Skip the main stream at this time. */ + if ((r = seek_pack(a)) < 0) + return (r); + zip->pack_stream_bytes_unconsumed = + (size_t)zip->pack_stream_inbytes_remaining; + read_consume(a); + + /* Read following three sub streams. */ + for (i = 0; i < 3; i++) { + const struct _7z_coder *coder = scoder[i]; + + if ((r = seek_pack(a)) < 0) { + free(b[0]); free(b[1]); free(b[2]); + return (r); + } + + if (sunpack[i] == (uint64_t)-1) + zip->folder_outbytes_remaining = + zip->pack_stream_inbytes_remaining; + else + zip->folder_outbytes_remaining = sunpack[i]; + + r = init_decompression(a, zip, coder, NULL); + if (r != ARCHIVE_OK) { + free(b[0]); free(b[1]); free(b[2]); + return (ARCHIVE_FATAL); + } + + /* Allocate memory for the decoded data of a sub + * stream. */ + b[i] = malloc((size_t)zip->folder_outbytes_remaining); + if (b[i] == NULL) { + free(b[0]); free(b[1]); free(b[2]); + archive_set_error(&a->archive, ENOMEM, + "No memory for 7-Zip decompression"); + return (ARCHIVE_FATAL); + } + + /* Extract a sub stream. */ + while (zip->pack_stream_inbytes_remaining > 0) { + r = (int)extract_pack_stream(a, 0); + if (r < 0) { + free(b[0]); free(b[1]); free(b[2]); + return (r); + } + bytes = get_uncompressed_data(a, &buff, + zip->uncompressed_buffer_bytes_remaining, + 0); + if (bytes < 0) { + free(b[0]); free(b[1]); free(b[2]); + return ((int)bytes); + } + memcpy(b[i]+s[i], buff, bytes); + s[i] += bytes; + if (zip->pack_stream_bytes_unconsumed) + read_consume(a); + } + } + + /* Set the sub streams to the right place. */ + for (i = 0; i < 3; i++) { + zip->sub_stream_buff[i] = b[idx[i]]; + zip->sub_stream_size[i] = s[idx[i]]; + zip->sub_stream_bytes_remaining[i] = s[idx[i]]; + } + + /* Allocate memory used for decoded main stream bytes. */ + if (zip->tmp_stream_buff == NULL) { + zip->tmp_stream_buff_size = 32 * 1024; + zip->tmp_stream_buff = + malloc(zip->tmp_stream_buff_size); + if (zip->tmp_stream_buff == NULL) { + archive_set_error(&a->archive, ENOMEM, + "No memory for 7-Zip decompression"); + return (ARCHIVE_FATAL); + } + } + zip->tmp_stream_bytes_avail = 0; + zip->tmp_stream_bytes_remaining = 0; + zip->odd_bcj_size = 0; + zip->bcj2_outPos = 0; + + /* + * Reset a stream reader in order to read the main stream + * of BCJ2. + */ + zip->pack_stream_remaining = 1; + zip->pack_stream_index = (unsigned)folder->packIndex; + zip->folder_outbytes_remaining = + folder_uncompressed_size(folder); + zip->uncompressed_buffer_bytes_remaining = 0; + } + + /* + * Initialize the decompressor for the new folder's pack streams. + */ + r = init_decompression(a, zip, coder1, coder2); + if (r != ARCHIVE_OK) + return (ARCHIVE_FATAL); + return (ARCHIVE_OK); +} + +static int64_t +skip_stream(struct archive_read *a, size_t skip_bytes) +{ + struct _7zip *zip = (struct _7zip *)a->format->data; + const void *p; + int64_t skipped_bytes; + size_t bytes = skip_bytes; + + if (zip->folder_index == 0) { + /* + * Optimization for a list mode. + * Avoid unnecessary decoding operations. + */ + zip->si.ci.folders[zip->entry->folderIndex].skipped_bytes + += skip_bytes; + return (skip_bytes); + } + + while (bytes) { + skipped_bytes = read_stream(a, &p, bytes, 0); + if (skipped_bytes < 0) + return (skipped_bytes); + if (skipped_bytes == 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated 7-Zip file body"); + return (ARCHIVE_FATAL); + } + bytes -= (size_t)skipped_bytes; + if (zip->pack_stream_bytes_unconsumed) + read_consume(a); + } + return (skip_bytes); +} + +/* + * Brought from LZMA SDK. + * + * Bra86.c -- Converter for x86 code (BCJ) + * 2008-10-04 : Igor Pavlov : Public domain + * + */ + +#define Test86MSByte(b) ((b) == 0 || (b) == 0xFF) + +static void +x86_Init(struct _7zip *zip) +{ + zip->bcj_state = 0; + zip->bcj_prevPosT = (size_t)0 - 1; + zip->bcj_prevMask = 0; + zip->bcj_ip = 5; +} + +static size_t +x86_Convert(struct _7zip *zip, uint8_t *data, size_t size) +{ + static const uint8_t kMaskToAllowedStatus[8] = {1, 1, 1, 0, 1, 0, 0, 0}; + static const uint8_t kMaskToBitNumber[8] = {0, 1, 2, 2, 3, 3, 3, 3}; + size_t bufferPos, prevPosT; + uint32_t ip, prevMask; + + if (size < 5) + return 0; + + bufferPos = 0; + prevPosT = zip->bcj_prevPosT; + prevMask = zip->bcj_prevMask; + ip = zip->bcj_ip; + + for (;;) { + uint8_t *p = data + bufferPos; + uint8_t *limit = data + size - 4; + + for (; p < limit; p++) + if ((*p & 0xFE) == 0xE8) + break; + bufferPos = (size_t)(p - data); + if (p >= limit) + break; + prevPosT = bufferPos - prevPosT; + if (prevPosT > 3) + prevMask = 0; + else { + prevMask = (prevMask << ((int)prevPosT - 1)) & 0x7; + if (prevMask != 0) { + unsigned char b = + p[4 - kMaskToBitNumber[prevMask]]; + if (!kMaskToAllowedStatus[prevMask] || + Test86MSByte(b)) { + prevPosT = bufferPos; + prevMask = ((prevMask << 1) & 0x7) | 1; + bufferPos++; + continue; + } + } + } + prevPosT = bufferPos; + + if (Test86MSByte(p[4])) { + uint32_t src = ((uint32_t)p[4] << 24) | + ((uint32_t)p[3] << 16) | ((uint32_t)p[2] << 8) | + ((uint32_t)p[1]); + uint32_t dest; + for (;;) { + uint8_t b; + int b_index; + + dest = src - (ip + (uint32_t)bufferPos); + if (prevMask == 0) + break; + b_index = kMaskToBitNumber[prevMask] * 8; + b = (uint8_t)(dest >> (24 - b_index)); + if (!Test86MSByte(b)) + break; + src = dest ^ ((1 << (32 - b_index)) - 1); + } + p[4] = (uint8_t)(~(((dest >> 24) & 1) - 1)); + p[3] = (uint8_t)(dest >> 16); + p[2] = (uint8_t)(dest >> 8); + p[1] = (uint8_t)dest; + bufferPos += 5; + } else { + prevMask = ((prevMask << 1) & 0x7) | 1; + bufferPos++; + } + } + zip->bcj_prevPosT = prevPosT; + zip->bcj_prevMask = prevMask; + zip->bcj_ip += (uint32_t)bufferPos; + return (bufferPos); +} + +/* + * Brought from LZMA SDK. + * + * Bcj2.c -- Converter for x86 code (BCJ2) + * 2008-10-04 : Igor Pavlov : Public domain + * + */ + +#define SZ_ERROR_DATA ARCHIVE_FAILED + +#define IsJcc(b0, b1) ((b0) == 0x0F && ((b1) & 0xF0) == 0x80) +#define IsJ(b0, b1) ((b1 & 0xFE) == 0xE8 || IsJcc(b0, b1)) + +#define kNumTopBits 24 +#define kTopValue ((uint32_t)1 << kNumTopBits) + +#define kNumBitModelTotalBits 11 +#define kBitModelTotal (1 << kNumBitModelTotalBits) +#define kNumMoveBits 5 + +#define RC_READ_BYTE (*buffer++) +#define RC_TEST { if (buffer == bufferLim) return SZ_ERROR_DATA; } +#define RC_INIT2 zip->bcj2_code = 0; zip->bcj2_range = 0xFFFFFFFF; \ + { int ii; for (ii = 0; ii < 5; ii++) { RC_TEST; zip->bcj2_code = (zip->bcj2_code << 8) | RC_READ_BYTE; }} + +#define NORMALIZE if (zip->bcj2_range < kTopValue) { RC_TEST; zip->bcj2_range <<= 8; zip->bcj2_code = (zip->bcj2_code << 8) | RC_READ_BYTE; } + +#define IF_BIT_0(p) ttt = *(p); bound = (zip->bcj2_range >> kNumBitModelTotalBits) * ttt; if (zip->bcj2_code < bound) +#define UPDATE_0(p) zip->bcj2_range = bound; *(p) = (CProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits)); NORMALIZE; +#define UPDATE_1(p) zip->bcj2_range -= bound; zip->bcj2_code -= bound; *(p) = (CProb)(ttt - (ttt >> kNumMoveBits)); NORMALIZE; + +static ssize_t +Bcj2_Decode(struct _7zip *zip, uint8_t *outBuf, size_t outSize) +{ + size_t inPos = 0, outPos = 0; + const uint8_t *buf0, *buf1, *buf2, *buf3; + size_t size0, size1, size2, size3; + const uint8_t *buffer, *bufferLim; + unsigned int i, j; + + size0 = zip->tmp_stream_bytes_remaining; + buf0 = zip->tmp_stream_buff + zip->tmp_stream_bytes_avail - size0; + size1 = zip->sub_stream_bytes_remaining[0]; + buf1 = zip->sub_stream_buff[0] + zip->sub_stream_size[0] - size1; + size2 = zip->sub_stream_bytes_remaining[1]; + buf2 = zip->sub_stream_buff[1] + zip->sub_stream_size[1] - size2; + size3 = zip->sub_stream_bytes_remaining[2]; + buf3 = zip->sub_stream_buff[2] + zip->sub_stream_size[2] - size3; + + buffer = buf3; + bufferLim = buffer + size3; + + if (zip->bcj_state == 0) { + /* + * Initialize. + */ + zip->bcj2_prevByte = 0; + for (i = 0; + i < sizeof(zip->bcj2_p) / sizeof(zip->bcj2_p[0]); i++) + zip->bcj2_p[i] = kBitModelTotal >> 1; + RC_INIT2; + zip->bcj_state = 1; + } + + /* + * Gather the odd bytes of a previous call. + */ + for (i = 0; zip->odd_bcj_size > 0 && outPos < outSize; i++) { + outBuf[outPos++] = zip->odd_bcj[i]; + zip->odd_bcj_size--; + } + + if (outSize == 0) { + zip->bcj2_outPos += outPos; + return (outPos); + } + + for (;;) { + uint8_t b; + CProb *prob; + uint32_t bound; + uint32_t ttt; + + size_t limit = size0 - inPos; + if (outSize - outPos < limit) + limit = outSize - outPos; + + if (zip->bcj_state == 1) { + while (limit != 0) { + uint8_t bb = buf0[inPos]; + outBuf[outPos++] = bb; + if (IsJ(zip->bcj2_prevByte, bb)) { + zip->bcj_state = 2; + break; + } + inPos++; + zip->bcj2_prevByte = bb; + limit--; + } + } + + if (limit == 0 || outPos == outSize) + break; + zip->bcj_state = 1; + + b = buf0[inPos++]; + + if (b == 0xE8) + prob = zip->bcj2_p + zip->bcj2_prevByte; + else if (b == 0xE9) + prob = zip->bcj2_p + 256; + else + prob = zip->bcj2_p + 257; + + IF_BIT_0(prob) { + UPDATE_0(prob) + zip->bcj2_prevByte = b; + } else { + uint32_t dest; + const uint8_t *v; + uint8_t out[4]; + + UPDATE_1(prob) + if (b == 0xE8) { + v = buf1; + if (size1 < 4) + return SZ_ERROR_DATA; + buf1 += 4; + size1 -= 4; + } else { + v = buf2; + if (size2 < 4) + return SZ_ERROR_DATA; + buf2 += 4; + size2 -= 4; + } + dest = (((uint32_t)v[0] << 24) | + ((uint32_t)v[1] << 16) | + ((uint32_t)v[2] << 8) | + ((uint32_t)v[3])) - + ((uint32_t)zip->bcj2_outPos + (uint32_t)outPos + 4); + out[0] = (uint8_t)dest; + out[1] = (uint8_t)(dest >> 8); + out[2] = (uint8_t)(dest >> 16); + out[3] = zip->bcj2_prevByte = (uint8_t)(dest >> 24); + + for (i = 0; i < 4 && outPos < outSize; i++) + outBuf[outPos++] = out[i]; + if (i < 4) { + /* + * Save odd bytes which we could not add into + * the output buffer because of out of space. + */ + zip->odd_bcj_size = 4 -i; + for (; i < 4; i++) { + j = i - 4 + (unsigned)zip->odd_bcj_size; + zip->odd_bcj[j] = out[i]; + } + break; + } + } + } + zip->tmp_stream_bytes_remaining -= inPos; + zip->sub_stream_bytes_remaining[0] = size1; + zip->sub_stream_bytes_remaining[1] = size2; + zip->sub_stream_bytes_remaining[2] = bufferLim - buffer; + zip->bcj2_outPos += outPos; + + return ((ssize_t)outPos); +} + diff --cc Utilities/cmlibarchive/libarchive/archive_read_support_format_iso9660.c index 4b436d1,0000000..93649f8 mode 100644,000000..100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_iso9660.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_iso9660.c @@@ -1,3266 -1,0 +1,3271 @@@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * Copyright (c) 2009 Andreas Henriksson + * Copyright (c) 2009-2012 Michihiro NAKAJIMA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "archive_platform.h" +__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_iso9660.c 201246 2009-12-30 05:30:35Z kientzle $"); + +#ifdef HAVE_ERRNO_H +#include +#endif +/* #include */ /* See archive_platform.h */ +#include +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#include +#ifdef HAVE_ZLIB_H +#include +#endif + +#include "archive.h" +#include "archive_endian.h" +#include "archive_entry.h" +#include "archive_entry_locale.h" +#include "archive_private.h" +#include "archive_read_private.h" +#include "archive_string.h" + +/* + * An overview of ISO 9660 format: + * + * Each disk is laid out as follows: + * * 32k reserved for private use + * * Volume descriptor table. Each volume descriptor + * is 2k and specifies basic format information. + * The "Primary Volume Descriptor" (PVD) is defined by the + * standard and should always be present; other volume + * descriptors include various vendor-specific extensions. + * * Files and directories. Each file/dir is specified by + * an "extent" (starting sector and length in bytes). + * Dirs are just files with directory records packed one + * after another. The PVD contains a single dir entry + * specifying the location of the root directory. Everything + * else follows from there. + * + * This module works by first reading the volume descriptors, then + * building a list of directory entries, sorted by starting + * sector. At each step, I look for the earliest dir entry that + * hasn't yet been read, seek forward to that location and read + * that entry. If it's a dir, I slurp in the new dir entries and + * add them to the heap; if it's a regular file, I return the + * corresponding archive_entry and wait for the client to request + * the file body. This strategy allows us to read most compliant + * CDs with a single pass through the data, as required by libarchive. + */ +#define LOGICAL_BLOCK_SIZE 2048 +#define SYSTEM_AREA_BLOCK 16 + +/* Structure of on-disk primary volume descriptor. */ +#define PVD_type_offset 0 +#define PVD_type_size 1 +#define PVD_id_offset (PVD_type_offset + PVD_type_size) +#define PVD_id_size 5 +#define PVD_version_offset (PVD_id_offset + PVD_id_size) +#define PVD_version_size 1 +#define PVD_reserved1_offset (PVD_version_offset + PVD_version_size) +#define PVD_reserved1_size 1 +#define PVD_system_id_offset (PVD_reserved1_offset + PVD_reserved1_size) +#define PVD_system_id_size 32 +#define PVD_volume_id_offset (PVD_system_id_offset + PVD_system_id_size) +#define PVD_volume_id_size 32 +#define PVD_reserved2_offset (PVD_volume_id_offset + PVD_volume_id_size) +#define PVD_reserved2_size 8 +#define PVD_volume_space_size_offset (PVD_reserved2_offset + PVD_reserved2_size) +#define PVD_volume_space_size_size 8 +#define PVD_reserved3_offset (PVD_volume_space_size_offset + PVD_volume_space_size_size) +#define PVD_reserved3_size 32 +#define PVD_volume_set_size_offset (PVD_reserved3_offset + PVD_reserved3_size) +#define PVD_volume_set_size_size 4 +#define PVD_volume_sequence_number_offset (PVD_volume_set_size_offset + PVD_volume_set_size_size) +#define PVD_volume_sequence_number_size 4 +#define PVD_logical_block_size_offset (PVD_volume_sequence_number_offset + PVD_volume_sequence_number_size) +#define PVD_logical_block_size_size 4 +#define PVD_path_table_size_offset (PVD_logical_block_size_offset + PVD_logical_block_size_size) +#define PVD_path_table_size_size 8 +#define PVD_type_1_path_table_offset (PVD_path_table_size_offset + PVD_path_table_size_size) +#define PVD_type_1_path_table_size 4 +#define PVD_opt_type_1_path_table_offset (PVD_type_1_path_table_offset + PVD_type_1_path_table_size) +#define PVD_opt_type_1_path_table_size 4 +#define PVD_type_m_path_table_offset (PVD_opt_type_1_path_table_offset + PVD_opt_type_1_path_table_size) +#define PVD_type_m_path_table_size 4 +#define PVD_opt_type_m_path_table_offset (PVD_type_m_path_table_offset + PVD_type_m_path_table_size) +#define PVD_opt_type_m_path_table_size 4 +#define PVD_root_directory_record_offset (PVD_opt_type_m_path_table_offset + PVD_opt_type_m_path_table_size) +#define PVD_root_directory_record_size 34 +#define PVD_volume_set_id_offset (PVD_root_directory_record_offset + PVD_root_directory_record_size) +#define PVD_volume_set_id_size 128 +#define PVD_publisher_id_offset (PVD_volume_set_id_offset + PVD_volume_set_id_size) +#define PVD_publisher_id_size 128 +#define PVD_preparer_id_offset (PVD_publisher_id_offset + PVD_publisher_id_size) +#define PVD_preparer_id_size 128 +#define PVD_application_id_offset (PVD_preparer_id_offset + PVD_preparer_id_size) +#define PVD_application_id_size 128 +#define PVD_copyright_file_id_offset (PVD_application_id_offset + PVD_application_id_size) +#define PVD_copyright_file_id_size 37 +#define PVD_abstract_file_id_offset (PVD_copyright_file_id_offset + PVD_copyright_file_id_size) +#define PVD_abstract_file_id_size 37 +#define PVD_bibliographic_file_id_offset (PVD_abstract_file_id_offset + PVD_abstract_file_id_size) +#define PVD_bibliographic_file_id_size 37 +#define PVD_creation_date_offset (PVD_bibliographic_file_id_offset + PVD_bibliographic_file_id_size) +#define PVD_creation_date_size 17 +#define PVD_modification_date_offset (PVD_creation_date_offset + PVD_creation_date_size) +#define PVD_modification_date_size 17 +#define PVD_expiration_date_offset (PVD_modification_date_offset + PVD_modification_date_size) +#define PVD_expiration_date_size 17 +#define PVD_effective_date_offset (PVD_expiration_date_offset + PVD_expiration_date_size) +#define PVD_effective_date_size 17 +#define PVD_file_structure_version_offset (PVD_effective_date_offset + PVD_effective_date_size) +#define PVD_file_structure_version_size 1 +#define PVD_reserved4_offset (PVD_file_structure_version_offset + PVD_file_structure_version_size) +#define PVD_reserved4_size 1 +#define PVD_application_data_offset (PVD_reserved4_offset + PVD_reserved4_size) +#define PVD_application_data_size 512 +#define PVD_reserved5_offset (PVD_application_data_offset + PVD_application_data_size) +#define PVD_reserved5_size (2048 - PVD_reserved5_offset) + +/* TODO: It would make future maintenance easier to just hardcode the + * above values. In particular, ECMA119 states the offsets as part of + * the standard. That would eliminate the need for the following check.*/ +#if PVD_reserved5_offset != 1395 +#error PVD offset and size definitions are wrong. +#endif + + +/* Structure of optional on-disk supplementary volume descriptor. */ +#define SVD_type_offset 0 +#define SVD_type_size 1 +#define SVD_id_offset (SVD_type_offset + SVD_type_size) +#define SVD_id_size 5 +#define SVD_version_offset (SVD_id_offset + SVD_id_size) +#define SVD_version_size 1 +/* ... */ +#define SVD_reserved1_offset 72 +#define SVD_reserved1_size 8 +#define SVD_volume_space_size_offset 80 +#define SVD_volume_space_size_size 8 +#define SVD_escape_sequences_offset (SVD_volume_space_size_offset + SVD_volume_space_size_size) +#define SVD_escape_sequences_size 32 +/* ... */ +#define SVD_logical_block_size_offset 128 +#define SVD_logical_block_size_size 4 +#define SVD_type_L_path_table_offset 140 +#define SVD_type_M_path_table_offset 148 +/* ... */ +#define SVD_root_directory_record_offset 156 +#define SVD_root_directory_record_size 34 +#define SVD_file_structure_version_offset 881 +#define SVD_reserved2_offset 882 +#define SVD_reserved2_size 1 +#define SVD_reserved3_offset 1395 +#define SVD_reserved3_size 653 +/* ... */ +/* FIXME: validate correctness of last SVD entry offset. */ + +/* Structure of an on-disk directory record. */ +/* Note: ISO9660 stores each multi-byte integer twice, once in + * each byte order. The sizes here are the size of just one + * of the two integers. (This is why the offset of a field isn't + * the same as the offset+size of the previous field.) */ +#define DR_length_offset 0 +#define DR_length_size 1 +#define DR_ext_attr_length_offset 1 +#define DR_ext_attr_length_size 1 +#define DR_extent_offset 2 +#define DR_extent_size 4 +#define DR_size_offset 10 +#define DR_size_size 4 +#define DR_date_offset 18 +#define DR_date_size 7 +#define DR_flags_offset 25 +#define DR_flags_size 1 +#define DR_file_unit_size_offset 26 +#define DR_file_unit_size_size 1 +#define DR_interleave_offset 27 +#define DR_interleave_size 1 +#define DR_volume_sequence_number_offset 28 +#define DR_volume_sequence_number_size 2 +#define DR_name_len_offset 32 +#define DR_name_len_size 1 +#define DR_name_offset 33 + +#ifdef HAVE_ZLIB_H +static const unsigned char zisofs_magic[8] = { + 0x37, 0xE4, 0x53, 0x96, 0xC9, 0xDB, 0xD6, 0x07 +}; + +struct zisofs { + /* Set 1 if this file compressed by paged zlib */ + int pz; + int pz_log2_bs; /* Log2 of block size */ + uint64_t pz_uncompressed_size; + + int initialized; + unsigned char *uncompressed_buffer; + size_t uncompressed_buffer_size; + + uint32_t pz_offset; + unsigned char header[16]; + size_t header_avail; + int header_passed; + unsigned char *block_pointers; + size_t block_pointers_alloc; + size_t block_pointers_size; + size_t block_pointers_avail; + size_t block_off; + uint32_t block_avail; + + z_stream stream; + int stream_valid; +}; +#else +struct zisofs { + /* Set 1 if this file compressed by paged zlib */ + int pz; +}; +#endif + +struct content { + uint64_t offset;/* Offset on disk. */ + uint64_t size; /* File size in bytes. */ + struct content *next; +}; + +/* In-memory storage for a directory record. */ +struct file_info { + struct file_info *use_next; + struct file_info *parent; + struct file_info *next; + struct file_info *re_next; + int subdirs; + uint64_t key; /* Heap Key. */ + uint64_t offset; /* Offset on disk. */ + uint64_t size; /* File size in bytes. */ + uint32_t ce_offset; /* Offset of CE. */ + uint32_t ce_size; /* Size of CE. */ + char rr_moved; /* Flag to rr_moved. */ + char rr_moved_has_re_only; + char re; /* Having RRIP "RE" extension. */ + char re_descendant; + uint64_t cl_offset; /* Having RRIP "CL" extension. */ + int birthtime_is_set; + time_t birthtime; /* File created time. */ + time_t mtime; /* File last modified time. */ + time_t atime; /* File last accessed time. */ + time_t ctime; /* File attribute change time. */ + uint64_t rdev; /* Device number. */ + mode_t mode; + uid_t uid; + gid_t gid; + int64_t number; + int nlinks; + struct archive_string name; /* Pathname */ + unsigned char *utf16be_name; + size_t utf16be_bytes; + char name_continues; /* Non-zero if name continues */ + struct archive_string symlink; + char symlink_continues; /* Non-zero if link continues */ + /* Set 1 if this file compressed by paged zlib(zisofs) */ + int pz; + int pz_log2_bs; /* Log2 of block size */ + uint64_t pz_uncompressed_size; + /* Set 1 if this file is multi extent. */ + int multi_extent; + struct { + struct content *first; + struct content **last; + } contents; + struct { + struct file_info *first; + struct file_info **last; + } rede_files; +}; + +struct heap_queue { + struct file_info **files; + int allocated; + int used; +}; + +struct iso9660 { + int magic; +#define ISO9660_MAGIC 0x96609660 + + int opt_support_joliet; + int opt_support_rockridge; + + struct archive_string pathname; + char seenRockridge; /* Set true if RR extensions are used. */ + char seenSUSP; /* Set true if SUSP is being used. */ + char seenJoliet; + + unsigned char suspOffset; + struct file_info *rr_moved; + struct read_ce_queue { + struct read_ce_req { + uint64_t offset;/* Offset of CE on disk. */ + struct file_info *file; + } *reqs; + int cnt; + int allocated; + } read_ce_req; + + int64_t previous_number; + struct archive_string previous_pathname; + + struct file_info *use_files; + struct heap_queue pending_files; + struct { + struct file_info *first; + struct file_info **last; + } cache_files; + struct { + struct file_info *first; + struct file_info **last; + } re_files; + + uint64_t current_position; + ssize_t logical_block_size; + uint64_t volume_size; /* Total size of volume in bytes. */ + int32_t volume_block;/* Total size of volume in logical blocks. */ + + struct vd { + int location; /* Location of Extent. */ + uint32_t size; + } primary, joliet; + + int64_t entry_sparse_offset; + int64_t entry_bytes_remaining; + size_t entry_bytes_unconsumed; + struct zisofs entry_zisofs; + struct content *entry_content; + struct archive_string_conv *sconv_utf16be; + /* + * Buffers for a full pathname in UTF-16BE in Joliet extensions. + */ +#define UTF16_NAME_MAX 1024 + unsigned char *utf16be_path; + size_t utf16be_path_len; + unsigned char *utf16be_previous_path; + size_t utf16be_previous_path_len; + /* Null buffer used in bidder to improve its performance. */ + unsigned char null[2048]; +}; + +static int archive_read_format_iso9660_bid(struct archive_read *, int); +static int archive_read_format_iso9660_options(struct archive_read *, + const char *, const char *); +static int archive_read_format_iso9660_cleanup(struct archive_read *); +static int archive_read_format_iso9660_read_data(struct archive_read *, + const void **, size_t *, int64_t *); +static int archive_read_format_iso9660_read_data_skip(struct archive_read *); +static int archive_read_format_iso9660_read_header(struct archive_read *, + struct archive_entry *); +static const char *build_pathname(struct archive_string *, struct file_info *, int); +static int build_pathname_utf16be(unsigned char *, size_t, size_t *, + struct file_info *); +#if DEBUG +static void dump_isodirrec(FILE *, const unsigned char *isodirrec); +#endif +static time_t time_from_tm(struct tm *); +static time_t isodate17(const unsigned char *); +static time_t isodate7(const unsigned char *); +static int isBootRecord(struct iso9660 *, const unsigned char *); +static int isVolumePartition(struct iso9660 *, const unsigned char *); +static int isVDSetTerminator(struct iso9660 *, const unsigned char *); +static int isJolietSVD(struct iso9660 *, const unsigned char *); +static int isSVD(struct iso9660 *, const unsigned char *); +static int isEVD(struct iso9660 *, const unsigned char *); +static int isPVD(struct iso9660 *, const unsigned char *); +static int next_cache_entry(struct archive_read *, struct iso9660 *, + struct file_info **); +static int next_entry_seek(struct archive_read *, struct iso9660 *, + struct file_info **); +static struct file_info * + parse_file_info(struct archive_read *a, - struct file_info *parent, const unsigned char *isodirrec); ++ struct file_info *parent, const unsigned char *isodirrec, ++ size_t reclen); +static int parse_rockridge(struct archive_read *a, + struct file_info *file, const unsigned char *start, + const unsigned char *end); +static int register_CE(struct archive_read *a, int32_t location, + struct file_info *file); +static int read_CE(struct archive_read *a, struct iso9660 *iso9660); +static void parse_rockridge_NM1(struct file_info *, + const unsigned char *, int); +static void parse_rockridge_SL1(struct file_info *, + const unsigned char *, int); +static void parse_rockridge_TF1(struct file_info *, + const unsigned char *, int); +static void parse_rockridge_ZF1(struct file_info *, + const unsigned char *, int); +static void register_file(struct iso9660 *, struct file_info *); +static void release_files(struct iso9660 *); +static unsigned toi(const void *p, int n); +static inline void re_add_entry(struct iso9660 *, struct file_info *); +static inline struct file_info * re_get_entry(struct iso9660 *); +static inline int rede_add_entry(struct file_info *); +static inline struct file_info * rede_get_entry(struct file_info *); +static inline void cache_add_entry(struct iso9660 *iso9660, + struct file_info *file); +static inline struct file_info *cache_get_entry(struct iso9660 *iso9660); +static int heap_add_entry(struct archive_read *a, struct heap_queue *heap, + struct file_info *file, uint64_t key); +static struct file_info *heap_get_entry(struct heap_queue *heap); + +#define add_entry(arch, iso9660, file) \ + heap_add_entry(arch, &((iso9660)->pending_files), file, file->offset) +#define next_entry(iso9660) \ + heap_get_entry(&((iso9660)->pending_files)) + +int +archive_read_support_format_iso9660(struct archive *_a) +{ + struct archive_read *a = (struct archive_read *)_a; + struct iso9660 *iso9660; + int r; + + archive_check_magic(_a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_format_iso9660"); + + iso9660 = (struct iso9660 *)calloc(1, sizeof(*iso9660)); + if (iso9660 == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate iso9660 data"); + return (ARCHIVE_FATAL); + } + iso9660->magic = ISO9660_MAGIC; + iso9660->cache_files.first = NULL; + iso9660->cache_files.last = &(iso9660->cache_files.first); + iso9660->re_files.first = NULL; + iso9660->re_files.last = &(iso9660->re_files.first); + /* Enable to support Joliet extensions by default. */ + iso9660->opt_support_joliet = 1; + /* Enable to support Rock Ridge extensions by default. */ + iso9660->opt_support_rockridge = 1; + + r = __archive_read_register_format(a, + iso9660, + "iso9660", + archive_read_format_iso9660_bid, + archive_read_format_iso9660_options, + archive_read_format_iso9660_read_header, + archive_read_format_iso9660_read_data, + archive_read_format_iso9660_read_data_skip, + NULL, + archive_read_format_iso9660_cleanup, + NULL, + NULL); + + if (r != ARCHIVE_OK) { + free(iso9660); + return (r); + } + return (ARCHIVE_OK); +} + + +static int +archive_read_format_iso9660_bid(struct archive_read *a, int best_bid) +{ + struct iso9660 *iso9660; + ssize_t bytes_read; + const unsigned char *p; + int seenTerminator; + + /* If there's already a better bid than we can ever + make, don't bother testing. */ + if (best_bid > 48) + return (-1); + + iso9660 = (struct iso9660 *)(a->format->data); + + /* + * Skip the first 32k (reserved area) and get the first + * 8 sectors of the volume descriptor table. Of course, + * if the I/O layer gives us more, we'll take it. + */ +#define RESERVED_AREA (SYSTEM_AREA_BLOCK * LOGICAL_BLOCK_SIZE) + p = __archive_read_ahead(a, + RESERVED_AREA + 8 * LOGICAL_BLOCK_SIZE, + &bytes_read); + if (p == NULL) + return (-1); + + /* Skip the reserved area. */ + bytes_read -= RESERVED_AREA; + p += RESERVED_AREA; + + /* Check each volume descriptor. */ + seenTerminator = 0; + for (; bytes_read > LOGICAL_BLOCK_SIZE; + bytes_read -= LOGICAL_BLOCK_SIZE, p += LOGICAL_BLOCK_SIZE) { + /* Do not handle undefined Volume Descriptor Type. */ + if (p[0] >= 4 && p[0] <= 254) + return (0); + /* Standard Identifier must be "CD001" */ + if (memcmp(p + 1, "CD001", 5) != 0) + return (0); + if (isPVD(iso9660, p)) + continue; + if (!iso9660->joliet.location) { + if (isJolietSVD(iso9660, p)) + continue; + } + if (isBootRecord(iso9660, p)) + continue; + if (isEVD(iso9660, p)) + continue; + if (isSVD(iso9660, p)) + continue; + if (isVolumePartition(iso9660, p)) + continue; + if (isVDSetTerminator(iso9660, p)) { + seenTerminator = 1; + break; + } + return (0); + } + /* + * ISO 9660 format must have Primary Volume Descriptor and + * Volume Descriptor Set Terminator. + */ + if (seenTerminator && iso9660->primary.location > 16) + return (48); + + /* We didn't find a valid PVD; return a bid of zero. */ + return (0); +} + +static int +archive_read_format_iso9660_options(struct archive_read *a, + const char *key, const char *val) +{ + struct iso9660 *iso9660; + + iso9660 = (struct iso9660 *)(a->format->data); + + if (strcmp(key, "joliet") == 0) { + if (val == NULL || strcmp(val, "off") == 0 || + strcmp(val, "ignore") == 0 || + strcmp(val, "disable") == 0 || + strcmp(val, "0") == 0) + iso9660->opt_support_joliet = 0; + else + iso9660->opt_support_joliet = 1; + return (ARCHIVE_OK); + } + if (strcmp(key, "rockridge") == 0 || + strcmp(key, "Rockridge") == 0) { + iso9660->opt_support_rockridge = val != NULL; + return (ARCHIVE_OK); + } + + /* Note: The "warn" return is just to inform the options + * supervisor that we didn't handle it. It will generate + * a suitable error if no one used this option. */ + return (ARCHIVE_WARN); +} + +static int +isNull(struct iso9660 *iso9660, const unsigned char *h, unsigned offset, +unsigned bytes) +{ + + while (bytes >= sizeof(iso9660->null)) { + if (!memcmp(iso9660->null, h + offset, sizeof(iso9660->null))) + return (0); + offset += sizeof(iso9660->null); + bytes -= sizeof(iso9660->null); + } + if (bytes) + return memcmp(iso9660->null, h + offset, bytes) == 0; + else + return (1); +} + +static int +isBootRecord(struct iso9660 *iso9660, const unsigned char *h) +{ + (void)iso9660; /* UNUSED */ + + /* Type of the Volume Descriptor Boot Record must be 0. */ + if (h[0] != 0) + return (0); + + /* Volume Descriptor Version must be 1. */ + if (h[6] != 1) + return (0); + + return (1); +} + +static int +isVolumePartition(struct iso9660 *iso9660, const unsigned char *h) +{ + int32_t location; + + /* Type of the Volume Partition Descriptor must be 3. */ + if (h[0] != 3) + return (0); + + /* Volume Descriptor Version must be 1. */ + if (h[6] != 1) + return (0); + /* Unused Field */ + if (h[7] != 0) + return (0); + + location = archive_le32dec(h + 72); + if (location <= SYSTEM_AREA_BLOCK || + location >= iso9660->volume_block) + return (0); + if ((uint32_t)location != archive_be32dec(h + 76)) + return (0); + + return (1); +} + +static int +isVDSetTerminator(struct iso9660 *iso9660, const unsigned char *h) +{ + (void)iso9660; /* UNUSED */ + + /* Type of the Volume Descriptor Set Terminator must be 255. */ + if (h[0] != 255) + return (0); + + /* Volume Descriptor Version must be 1. */ + if (h[6] != 1) + return (0); + + /* Reserved field must be 0. */ + if (!isNull(iso9660, h, 7, 2048-7)) + return (0); + + return (1); +} + +static int +isJolietSVD(struct iso9660 *iso9660, const unsigned char *h) +{ + const unsigned char *p; + ssize_t logical_block_size; + int32_t volume_block; + + /* Check if current sector is a kind of Supplementary Volume + * Descriptor. */ + if (!isSVD(iso9660, h)) + return (0); + + /* FIXME: do more validations according to joliet spec. */ + + /* check if this SVD contains joliet extension! */ + p = h + SVD_escape_sequences_offset; + /* N.B. Joliet spec says p[1] == '\\', but.... */ + if (p[0] == '%' && p[1] == '/') { + int level = 0; + + if (p[2] == '@') + level = 1; + else if (p[2] == 'C') + level = 2; + else if (p[2] == 'E') + level = 3; + else /* not joliet */ + return (0); + + iso9660->seenJoliet = level; + + } else /* not joliet */ + return (0); + + logical_block_size = + archive_le16dec(h + SVD_logical_block_size_offset); + volume_block = archive_le32dec(h + SVD_volume_space_size_offset); + + iso9660->logical_block_size = logical_block_size; + iso9660->volume_block = volume_block; + iso9660->volume_size = logical_block_size * (uint64_t)volume_block; + /* Read Root Directory Record in Volume Descriptor. */ + p = h + SVD_root_directory_record_offset; + iso9660->joliet.location = archive_le32dec(p + DR_extent_offset); + iso9660->joliet.size = archive_le32dec(p + DR_size_offset); + + return (48); +} + +static int +isSVD(struct iso9660 *iso9660, const unsigned char *h) +{ + const unsigned char *p; + ssize_t logical_block_size; + int32_t volume_block; + int32_t location; + + (void)iso9660; /* UNUSED */ + + /* Type 2 means it's a SVD. */ + if (h[SVD_type_offset] != 2) + return (0); + + /* Reserved field must be 0. */ + if (!isNull(iso9660, h, SVD_reserved1_offset, SVD_reserved1_size)) + return (0); + if (!isNull(iso9660, h, SVD_reserved2_offset, SVD_reserved2_size)) + return (0); + if (!isNull(iso9660, h, SVD_reserved3_offset, SVD_reserved3_size)) + return (0); + + /* File structure version must be 1 for ISO9660/ECMA119. */ + if (h[SVD_file_structure_version_offset] != 1) + return (0); + + logical_block_size = + archive_le16dec(h + SVD_logical_block_size_offset); + if (logical_block_size <= 0) + return (0); + + volume_block = archive_le32dec(h + SVD_volume_space_size_offset); + if (volume_block <= SYSTEM_AREA_BLOCK+4) + return (0); + + /* Location of Occurrence of Type L Path Table must be + * available location, + * >= SYSTEM_AREA_BLOCK(16) + 2 and < Volume Space Size. */ + location = archive_le32dec(h+SVD_type_L_path_table_offset); + if (location < SYSTEM_AREA_BLOCK+2 || location >= volume_block) + return (0); + + /* The Type M Path Table must be at a valid location (WinISO + * and probably other programs omit this, so we allow zero) + * + * >= SYSTEM_AREA_BLOCK(16) + 2 and < Volume Space Size. */ + location = archive_be32dec(h+SVD_type_M_path_table_offset); + if ((location > 0 && location < SYSTEM_AREA_BLOCK+2) + || location >= volume_block) + return (0); + + /* Read Root Directory Record in Volume Descriptor. */ + p = h + SVD_root_directory_record_offset; + if (p[DR_length_offset] != 34) + return (0); + + return (48); +} + +static int +isEVD(struct iso9660 *iso9660, const unsigned char *h) +{ + const unsigned char *p; + ssize_t logical_block_size; + int32_t volume_block; + int32_t location; + + (void)iso9660; /* UNUSED */ + + /* Type of the Enhanced Volume Descriptor must be 2. */ + if (h[PVD_type_offset] != 2) + return (0); + + /* EVD version must be 2. */ + if (h[PVD_version_offset] != 2) + return (0); + + /* Reserved field must be 0. */ + if (h[PVD_reserved1_offset] != 0) + return (0); + + /* Reserved field must be 0. */ + if (!isNull(iso9660, h, PVD_reserved2_offset, PVD_reserved2_size)) + return (0); + + /* Reserved field must be 0. */ + if (!isNull(iso9660, h, PVD_reserved3_offset, PVD_reserved3_size)) + return (0); + + /* Logical block size must be > 0. */ + /* I've looked at Ecma 119 and can't find any stronger + * restriction on this field. */ + logical_block_size = + archive_le16dec(h + PVD_logical_block_size_offset); + if (logical_block_size <= 0) + return (0); + + volume_block = + archive_le32dec(h + PVD_volume_space_size_offset); + if (volume_block <= SYSTEM_AREA_BLOCK+4) + return (0); + + /* File structure version must be 2 for ISO9660:1999. */ + if (h[PVD_file_structure_version_offset] != 2) + return (0); + + /* Location of Occurrence of Type L Path Table must be + * available location, + * >= SYSTEM_AREA_BLOCK(16) + 2 and < Volume Space Size. */ + location = archive_le32dec(h+PVD_type_1_path_table_offset); + if (location < SYSTEM_AREA_BLOCK+2 || location >= volume_block) + return (0); + + /* Location of Occurrence of Type M Path Table must be + * available location, + * >= SYSTEM_AREA_BLOCK(16) + 2 and < Volume Space Size. */ + location = archive_be32dec(h+PVD_type_m_path_table_offset); + if ((location > 0 && location < SYSTEM_AREA_BLOCK+2) + || location >= volume_block) + return (0); + + /* Reserved field must be 0. */ + if (!isNull(iso9660, h, PVD_reserved4_offset, PVD_reserved4_size)) + return (0); + + /* Reserved field must be 0. */ + if (!isNull(iso9660, h, PVD_reserved5_offset, PVD_reserved5_size)) + return (0); + + /* Read Root Directory Record in Volume Descriptor. */ + p = h + PVD_root_directory_record_offset; + if (p[DR_length_offset] != 34) + return (0); + + return (48); +} + +static int +isPVD(struct iso9660 *iso9660, const unsigned char *h) +{ + const unsigned char *p; + ssize_t logical_block_size; + int32_t volume_block; + int32_t location; + int i; + + /* Type of the Primary Volume Descriptor must be 1. */ + if (h[PVD_type_offset] != 1) + return (0); + + /* PVD version must be 1. */ + if (h[PVD_version_offset] != 1) + return (0); + + /* Reserved field must be 0. */ + if (h[PVD_reserved1_offset] != 0) + return (0); + + /* Reserved field must be 0. */ + if (!isNull(iso9660, h, PVD_reserved2_offset, PVD_reserved2_size)) + return (0); + + /* Reserved field must be 0. */ + if (!isNull(iso9660, h, PVD_reserved3_offset, PVD_reserved3_size)) + return (0); + + /* Logical block size must be > 0. */ + /* I've looked at Ecma 119 and can't find any stronger + * restriction on this field. */ + logical_block_size = + archive_le16dec(h + PVD_logical_block_size_offset); + if (logical_block_size <= 0) + return (0); + + volume_block = archive_le32dec(h + PVD_volume_space_size_offset); + if (volume_block <= SYSTEM_AREA_BLOCK+4) + return (0); + + /* File structure version must be 1 for ISO9660/ECMA119. */ + if (h[PVD_file_structure_version_offset] != 1) + return (0); + + /* Location of Occurrence of Type L Path Table must be + * available location, + * > SYSTEM_AREA_BLOCK(16) + 2 and < Volume Space Size. */ + location = archive_le32dec(h+PVD_type_1_path_table_offset); + if (location < SYSTEM_AREA_BLOCK+2 || location >= volume_block) + return (0); + + /* The Type M Path Table must also be at a valid location + * (although ECMA 119 requires a Type M Path Table, WinISO and + * probably other programs omit it, so we permit a zero here) + * + * >= SYSTEM_AREA_BLOCK(16) + 2 and < Volume Space Size. */ + location = archive_be32dec(h+PVD_type_m_path_table_offset); + if ((location > 0 && location < SYSTEM_AREA_BLOCK+2) + || location >= volume_block) + return (0); + + /* Reserved field must be 0. */ + /* But accept NetBSD/FreeBSD "makefs" images with 0x20 here. */ + for (i = 0; i < PVD_reserved4_size; ++i) + if (h[PVD_reserved4_offset + i] != 0 + && h[PVD_reserved4_offset + i] != 0x20) + return (0); + + /* Reserved field must be 0. */ + if (!isNull(iso9660, h, PVD_reserved5_offset, PVD_reserved5_size)) + return (0); + + /* XXX TODO: Check other values for sanity; reject more + * malformed PVDs. XXX */ + + /* Read Root Directory Record in Volume Descriptor. */ + p = h + PVD_root_directory_record_offset; + if (p[DR_length_offset] != 34) + return (0); + + if (!iso9660->primary.location) { + iso9660->logical_block_size = logical_block_size; + iso9660->volume_block = volume_block; + iso9660->volume_size = + logical_block_size * (uint64_t)volume_block; + iso9660->primary.location = + archive_le32dec(p + DR_extent_offset); + iso9660->primary.size = archive_le32dec(p + DR_size_offset); + } + + return (48); +} + +static int +read_children(struct archive_read *a, struct file_info *parent) +{ + struct iso9660 *iso9660; + const unsigned char *b, *p; + struct file_info *multi; + size_t step, skip_size; + + iso9660 = (struct iso9660 *)(a->format->data); + /* flush any remaining bytes from the last round to ensure + * we're positioned */ + if (iso9660->entry_bytes_unconsumed) { + __archive_read_consume(a, iso9660->entry_bytes_unconsumed); + iso9660->entry_bytes_unconsumed = 0; + } + if (iso9660->current_position > parent->offset) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Ignoring out-of-order directory (%s) %jd > %jd", + parent->name.s, + (intmax_t)iso9660->current_position, + (intmax_t)parent->offset); + return (ARCHIVE_WARN); + } + if (parent->offset + parent->size > iso9660->volume_size) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Directory is beyond end-of-media: %s", + parent->name.s); + return (ARCHIVE_WARN); + } + if (iso9660->current_position < parent->offset) { + int64_t skipsize; + + skipsize = parent->offset - iso9660->current_position; + skipsize = __archive_read_consume(a, skipsize); + if (skipsize < 0) + return ((int)skipsize); + iso9660->current_position = parent->offset; + } + + step = (size_t)(((parent->size + iso9660->logical_block_size -1) / + iso9660->logical_block_size) * iso9660->logical_block_size); + b = __archive_read_ahead(a, step, NULL); + if (b == NULL) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Failed to read full block when scanning " + "ISO9660 directory list"); + return (ARCHIVE_FATAL); + } + iso9660->current_position += step; + multi = NULL; + skip_size = step; + while (step) { + p = b; + b += iso9660->logical_block_size; + step -= iso9660->logical_block_size; + for (; *p != 0 && p < b && p + *p <= b; p += *p) { + struct file_info *child; + + /* N.B.: these special directory identifiers + * are 8 bit "values" even on a + * Joliet CD with UCS-2 (16bit) encoding. + */ + + /* Skip '.' entry. */ + if (*(p + DR_name_len_offset) == 1 + && *(p + DR_name_offset) == '\0') + continue; + /* Skip '..' entry. */ + if (*(p + DR_name_len_offset) == 1 + && *(p + DR_name_offset) == '\001') + continue; - child = parse_file_info(a, parent, p); ++ child = parse_file_info(a, parent, p, b - p); + if (child == NULL) { + __archive_read_consume(a, skip_size); + return (ARCHIVE_FATAL); + } + if (child->cl_offset == 0 && + (child->multi_extent || multi != NULL)) { + struct content *con; + + if (multi == NULL) { + multi = child; + multi->contents.first = NULL; + multi->contents.last = + &(multi->contents.first); + } + con = malloc(sizeof(struct content)); + if (con == NULL) { + archive_set_error( + &a->archive, ENOMEM, + "No memory for multi extent"); + __archive_read_consume(a, skip_size); + return (ARCHIVE_FATAL); + } + con->offset = child->offset; + con->size = child->size; + con->next = NULL; + *multi->contents.last = con; + multi->contents.last = &(con->next); + if (multi == child) { + if (add_entry(a, iso9660, child) + != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } else { + multi->size += child->size; + if (!child->multi_extent) + multi = NULL; + } + } else + if (add_entry(a, iso9660, child) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } + } + + __archive_read_consume(a, skip_size); + + /* Read data which recorded by RRIP "CE" extension. */ + if (read_CE(a, iso9660) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + return (ARCHIVE_OK); +} + +static int +choose_volume(struct archive_read *a, struct iso9660 *iso9660) +{ + struct file_info *file; + int64_t skipsize; + struct vd *vd; + const void *block; + char seenJoliet; + + vd = &(iso9660->primary); + if (!iso9660->opt_support_joliet) + iso9660->seenJoliet = 0; + if (iso9660->seenJoliet && + vd->location > iso9660->joliet.location) + /* This condition is unlikely; by way of caution. */ + vd = &(iso9660->joliet); + + skipsize = LOGICAL_BLOCK_SIZE * (int64_t)vd->location; + skipsize = __archive_read_consume(a, skipsize); + if (skipsize < 0) + return ((int)skipsize); + iso9660->current_position = skipsize; + + block = __archive_read_ahead(a, vd->size, NULL); + if (block == NULL) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Failed to read full block when scanning " + "ISO9660 directory list"); + return (ARCHIVE_FATAL); + } + + /* + * While reading Root Directory, flag seenJoliet must be zero to + * avoid converting special name 0x00(Current Directory) and + * next byte to UCS2. + */ + seenJoliet = iso9660->seenJoliet;/* Save flag. */ + iso9660->seenJoliet = 0; - file = parse_file_info(a, NULL, block); ++ file = parse_file_info(a, NULL, block, vd->size); + if (file == NULL) + return (ARCHIVE_FATAL); + iso9660->seenJoliet = seenJoliet; + + /* + * If the iso image has both RockRidge and Joliet, we preferentially + * use RockRidge Extensions rather than Joliet ones. + */ + if (vd == &(iso9660->primary) && iso9660->seenRockridge + && iso9660->seenJoliet) + iso9660->seenJoliet = 0; + + if (vd == &(iso9660->primary) && !iso9660->seenRockridge + && iso9660->seenJoliet) { + /* Switch reading data from primary to joliet. */ + vd = &(iso9660->joliet); + skipsize = LOGICAL_BLOCK_SIZE * (int64_t)vd->location; + skipsize -= iso9660->current_position; + skipsize = __archive_read_consume(a, skipsize); + if (skipsize < 0) + return ((int)skipsize); + iso9660->current_position += skipsize; + + block = __archive_read_ahead(a, vd->size, NULL); + if (block == NULL) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Failed to read full block when scanning " + "ISO9660 directory list"); + return (ARCHIVE_FATAL); + } + iso9660->seenJoliet = 0; - file = parse_file_info(a, NULL, block); ++ file = parse_file_info(a, NULL, block, vd->size); + if (file == NULL) + return (ARCHIVE_FATAL); + iso9660->seenJoliet = seenJoliet; + } + + /* Store the root directory in the pending list. */ + if (add_entry(a, iso9660, file) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + if (iso9660->seenRockridge) { + a->archive.archive_format = ARCHIVE_FORMAT_ISO9660_ROCKRIDGE; + a->archive.archive_format_name = + "ISO9660 with Rockridge extensions"; + } + + return (ARCHIVE_OK); +} + +static int +archive_read_format_iso9660_read_header(struct archive_read *a, + struct archive_entry *entry) +{ + struct iso9660 *iso9660; + struct file_info *file; + int r, rd_r = ARCHIVE_OK; + + iso9660 = (struct iso9660 *)(a->format->data); + + if (!a->archive.archive_format) { + a->archive.archive_format = ARCHIVE_FORMAT_ISO9660; + a->archive.archive_format_name = "ISO9660"; + } + + if (iso9660->current_position == 0) { + r = choose_volume(a, iso9660); + if (r != ARCHIVE_OK) + return (r); + } + + file = NULL;/* Eliminate a warning. */ + /* Get the next entry that appears after the current offset. */ + r = next_entry_seek(a, iso9660, &file); + if (r != ARCHIVE_OK) + return (r); + + if (iso9660->seenJoliet) { + /* + * Convert UTF-16BE of a filename to local locale MBS + * and store the result into a filename field. + */ + if (iso9660->sconv_utf16be == NULL) { + iso9660->sconv_utf16be = + archive_string_conversion_from_charset( + &(a->archive), "UTF-16BE", 1); + if (iso9660->sconv_utf16be == NULL) + /* Couldn't allocate memory */ + return (ARCHIVE_FATAL); + } + if (iso9660->utf16be_path == NULL) { + iso9660->utf16be_path = malloc(UTF16_NAME_MAX); + if (iso9660->utf16be_path == NULL) { + archive_set_error(&a->archive, ENOMEM, + "No memory"); + return (ARCHIVE_FATAL); + } + } + if (iso9660->utf16be_previous_path == NULL) { + iso9660->utf16be_previous_path = malloc(UTF16_NAME_MAX); + if (iso9660->utf16be_previous_path == NULL) { + archive_set_error(&a->archive, ENOMEM, + "No memory"); + return (ARCHIVE_FATAL); + } + } + + iso9660->utf16be_path_len = 0; + if (build_pathname_utf16be(iso9660->utf16be_path, + UTF16_NAME_MAX, &(iso9660->utf16be_path_len), file) != 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Pathname is too long"); + return (ARCHIVE_FATAL); + } + + r = archive_entry_copy_pathname_l(entry, + (const char *)iso9660->utf16be_path, + iso9660->utf16be_path_len, + iso9660->sconv_utf16be); + if (r != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "No memory for Pathname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Pathname cannot be converted " + "from %s to current locale.", + archive_string_conversion_charset_name( + iso9660->sconv_utf16be)); + + rd_r = ARCHIVE_WARN; + } + } else { + const char *path = build_pathname(&iso9660->pathname, file, 0); + if (path == NULL) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Pathname is too long"); + return (ARCHIVE_FATAL); + } else { + archive_string_empty(&iso9660->pathname); + archive_entry_set_pathname(entry, path); + } + } + + iso9660->entry_bytes_remaining = file->size; + /* Offset for sparse-file-aware clients. */ + iso9660->entry_sparse_offset = 0; + + if (file->offset + file->size > iso9660->volume_size) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "File is beyond end-of-media: %s", + archive_entry_pathname(entry)); + iso9660->entry_bytes_remaining = 0; + return (ARCHIVE_WARN); + } + + /* Set up the entry structure with information about this entry. */ + archive_entry_set_mode(entry, file->mode); + archive_entry_set_uid(entry, file->uid); + archive_entry_set_gid(entry, file->gid); + archive_entry_set_nlink(entry, file->nlinks); + if (file->birthtime_is_set) + archive_entry_set_birthtime(entry, file->birthtime, 0); + else + archive_entry_unset_birthtime(entry); + archive_entry_set_mtime(entry, file->mtime, 0); + archive_entry_set_ctime(entry, file->ctime, 0); + archive_entry_set_atime(entry, file->atime, 0); + /* N.B.: Rock Ridge supports 64-bit device numbers. */ + archive_entry_set_rdev(entry, (dev_t)file->rdev); + archive_entry_set_size(entry, iso9660->entry_bytes_remaining); + if (file->symlink.s != NULL) + archive_entry_copy_symlink(entry, file->symlink.s); + + /* Note: If the input isn't seekable, we can't rewind to + * return the same body again, so if the next entry refers to + * the same data, we have to return it as a hardlink to the + * original entry. */ + if (file->number != -1 && + file->number == iso9660->previous_number) { + if (iso9660->seenJoliet) { + r = archive_entry_copy_hardlink_l(entry, + (const char *)iso9660->utf16be_previous_path, + iso9660->utf16be_previous_path_len, + iso9660->sconv_utf16be); + if (r != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "No memory for Linkname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Linkname cannot be converted " + "from %s to current locale.", + archive_string_conversion_charset_name( + iso9660->sconv_utf16be)); + rd_r = ARCHIVE_WARN; + } + } else + archive_entry_set_hardlink(entry, + iso9660->previous_pathname.s); + archive_entry_unset_size(entry); + iso9660->entry_bytes_remaining = 0; + return (rd_r); + } + + if ((file->mode & AE_IFMT) != AE_IFDIR && + file->offset < iso9660->current_position) { + int64_t r64; + + r64 = __archive_read_seek(a, file->offset, SEEK_SET); + if (r64 != (int64_t)file->offset) { + /* We can't seek backwards to extract it, so issue + * a warning. Note that this can only happen if + * this entry was added to the heap after we passed + * this offset, that is, only if the directory + * mentioning this entry is later than the body of + * the entry. Such layouts are very unusual; most + * ISO9660 writers lay out and record all directory + * information first, then store all file bodies. */ + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Ignoring out-of-order file @%jx (%s) %jd < %jd", + (intmax_t)file->number, + iso9660->pathname.s, + (intmax_t)file->offset, + (intmax_t)iso9660->current_position); + iso9660->entry_bytes_remaining = 0; + return (ARCHIVE_WARN); + } + iso9660->current_position = (uint64_t)r64; + } + + /* Initialize zisofs variables. */ + iso9660->entry_zisofs.pz = file->pz; + if (file->pz) { +#ifdef HAVE_ZLIB_H + struct zisofs *zisofs; + + zisofs = &iso9660->entry_zisofs; + zisofs->initialized = 0; + zisofs->pz_log2_bs = file->pz_log2_bs; + zisofs->pz_uncompressed_size = file->pz_uncompressed_size; + zisofs->pz_offset = 0; + zisofs->header_avail = 0; + zisofs->header_passed = 0; + zisofs->block_pointers_avail = 0; +#endif + archive_entry_set_size(entry, file->pz_uncompressed_size); + } + + iso9660->previous_number = file->number; + if (iso9660->seenJoliet) { + memcpy(iso9660->utf16be_previous_path, iso9660->utf16be_path, + iso9660->utf16be_path_len); + iso9660->utf16be_previous_path_len = iso9660->utf16be_path_len; + } else + archive_strcpy( + &iso9660->previous_pathname, iso9660->pathname.s); + + /* Reset entry_bytes_remaining if the file is multi extent. */ + iso9660->entry_content = file->contents.first; + if (iso9660->entry_content != NULL) + iso9660->entry_bytes_remaining = iso9660->entry_content->size; + + if (archive_entry_filetype(entry) == AE_IFDIR) { + /* Overwrite nlinks by proper link number which is + * calculated from number of sub directories. */ + archive_entry_set_nlink(entry, 2 + file->subdirs); + /* Directory data has been read completely. */ + iso9660->entry_bytes_remaining = 0; + } + + if (rd_r != ARCHIVE_OK) + return (rd_r); + return (ARCHIVE_OK); +} + +static int +archive_read_format_iso9660_read_data_skip(struct archive_read *a) +{ + /* Because read_next_header always does an explicit skip + * to the next entry, we don't need to do anything here. */ + (void)a; /* UNUSED */ + return (ARCHIVE_OK); +} + +#ifdef HAVE_ZLIB_H + +static int +zisofs_read_data(struct archive_read *a, + const void **buff, size_t *size, int64_t *offset) +{ + struct iso9660 *iso9660; + struct zisofs *zisofs; + const unsigned char *p; + size_t avail; + ssize_t bytes_read; + size_t uncompressed_size; + int r; + + iso9660 = (struct iso9660 *)(a->format->data); + zisofs = &iso9660->entry_zisofs; + + p = __archive_read_ahead(a, 1, &bytes_read); + if (bytes_read <= 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated zisofs file body"); + return (ARCHIVE_FATAL); + } + if (bytes_read > iso9660->entry_bytes_remaining) + bytes_read = (ssize_t)iso9660->entry_bytes_remaining; + avail = bytes_read; + uncompressed_size = 0; + + if (!zisofs->initialized) { + size_t ceil, xsize; + + /* Allocate block pointers buffer. */ + ceil = (size_t)((zisofs->pz_uncompressed_size + + (((int64_t)1) << zisofs->pz_log2_bs) - 1) + >> zisofs->pz_log2_bs); + xsize = (ceil + 1) * 4; + if (zisofs->block_pointers_alloc < xsize) { + size_t alloc; + + if (zisofs->block_pointers != NULL) + free(zisofs->block_pointers); + alloc = ((xsize >> 10) + 1) << 10; + zisofs->block_pointers = malloc(alloc); + if (zisofs->block_pointers == NULL) { + archive_set_error(&a->archive, ENOMEM, + "No memory for zisofs decompression"); + return (ARCHIVE_FATAL); + } + zisofs->block_pointers_alloc = alloc; + } + zisofs->block_pointers_size = xsize; + + /* Allocate uncompressed data buffer. */ + xsize = (size_t)1UL << zisofs->pz_log2_bs; + if (zisofs->uncompressed_buffer_size < xsize) { + if (zisofs->uncompressed_buffer != NULL) + free(zisofs->uncompressed_buffer); + zisofs->uncompressed_buffer = malloc(xsize); + if (zisofs->uncompressed_buffer == NULL) { + archive_set_error(&a->archive, ENOMEM, + "No memory for zisofs decompression"); + return (ARCHIVE_FATAL); + } + } + zisofs->uncompressed_buffer_size = xsize; + + /* + * Read the file header, and check the magic code of zisofs. + */ + if (zisofs->header_avail < sizeof(zisofs->header)) { + xsize = sizeof(zisofs->header) - zisofs->header_avail; + if (avail < xsize) + xsize = avail; + memcpy(zisofs->header + zisofs->header_avail, p, xsize); + zisofs->header_avail += xsize; + avail -= xsize; + p += xsize; + } + if (!zisofs->header_passed && + zisofs->header_avail == sizeof(zisofs->header)) { + int err = 0; + + if (memcmp(zisofs->header, zisofs_magic, + sizeof(zisofs_magic)) != 0) + err = 1; + if (archive_le32dec(zisofs->header + 8) + != zisofs->pz_uncompressed_size) + err = 1; + if (zisofs->header[12] != 4) + err = 1; + if (zisofs->header[13] != zisofs->pz_log2_bs) + err = 1; + if (err) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Illegal zisofs file body"); + return (ARCHIVE_FATAL); + } + zisofs->header_passed = 1; + } + /* + * Read block pointers. + */ + if (zisofs->header_passed && + zisofs->block_pointers_avail < zisofs->block_pointers_size) { + xsize = zisofs->block_pointers_size + - zisofs->block_pointers_avail; + if (avail < xsize) + xsize = avail; + memcpy(zisofs->block_pointers + + zisofs->block_pointers_avail, p, xsize); + zisofs->block_pointers_avail += xsize; + avail -= xsize; + p += xsize; + if (zisofs->block_pointers_avail + == zisofs->block_pointers_size) { + /* We've got all block pointers and initialize + * related variables. */ + zisofs->block_off = 0; + zisofs->block_avail = 0; + /* Complete a initialization */ + zisofs->initialized = 1; + } + } + + if (!zisofs->initialized) + goto next_data; /* We need more data. */ + } + + /* + * Get block offsets from block pointers. + */ + if (zisofs->block_avail == 0) { + uint32_t bst, bed; + + if (zisofs->block_off + 4 >= zisofs->block_pointers_size) { + /* There isn't a pair of offsets. */ + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Illegal zisofs block pointers"); + return (ARCHIVE_FATAL); + } + bst = archive_le32dec( + zisofs->block_pointers + zisofs->block_off); + if (bst != zisofs->pz_offset + (bytes_read - avail)) { + /* TODO: Should we seek offset of current file + * by bst ? */ + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Illegal zisofs block pointers(cannot seek)"); + return (ARCHIVE_FATAL); + } + bed = archive_le32dec( + zisofs->block_pointers + zisofs->block_off + 4); + if (bed < bst) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Illegal zisofs block pointers"); + return (ARCHIVE_FATAL); + } + zisofs->block_avail = bed - bst; + zisofs->block_off += 4; + + /* Initialize compression library for new block. */ + if (zisofs->stream_valid) + r = inflateReset(&zisofs->stream); + else + r = inflateInit(&zisofs->stream); + if (r != Z_OK) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Can't initialize zisofs decompression."); + return (ARCHIVE_FATAL); + } + zisofs->stream_valid = 1; + zisofs->stream.total_in = 0; + zisofs->stream.total_out = 0; + } + + /* + * Make uncompressed data. + */ + if (zisofs->block_avail == 0) { + memset(zisofs->uncompressed_buffer, 0, + zisofs->uncompressed_buffer_size); + uncompressed_size = zisofs->uncompressed_buffer_size; + } else { + zisofs->stream.next_in = (Bytef *)(uintptr_t)(const void *)p; + if (avail > zisofs->block_avail) + zisofs->stream.avail_in = zisofs->block_avail; + else + zisofs->stream.avail_in = (uInt)avail; + zisofs->stream.next_out = zisofs->uncompressed_buffer; + zisofs->stream.avail_out = + (uInt)zisofs->uncompressed_buffer_size; + + r = inflate(&zisofs->stream, 0); + switch (r) { + case Z_OK: /* Decompressor made some progress.*/ + case Z_STREAM_END: /* Found end of stream. */ + break; + default: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "zisofs decompression failed (%d)", r); + return (ARCHIVE_FATAL); + } + uncompressed_size = + zisofs->uncompressed_buffer_size - zisofs->stream.avail_out; + avail -= zisofs->stream.next_in - p; + zisofs->block_avail -= (uint32_t)(zisofs->stream.next_in - p); + } +next_data: + bytes_read -= avail; + *buff = zisofs->uncompressed_buffer; + *size = uncompressed_size; + *offset = iso9660->entry_sparse_offset; + iso9660->entry_sparse_offset += uncompressed_size; + iso9660->entry_bytes_remaining -= bytes_read; + iso9660->current_position += bytes_read; + zisofs->pz_offset += (uint32_t)bytes_read; + iso9660->entry_bytes_unconsumed += bytes_read; + + return (ARCHIVE_OK); +} + +#else /* HAVE_ZLIB_H */ + +static int +zisofs_read_data(struct archive_read *a, + const void **buff, size_t *size, int64_t *offset) +{ + + (void)buff;/* UNUSED */ + (void)size;/* UNUSED */ + (void)offset;/* UNUSED */ + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "zisofs is not supported on this platform."); + return (ARCHIVE_FAILED); +} + +#endif /* HAVE_ZLIB_H */ + +static int +archive_read_format_iso9660_read_data(struct archive_read *a, + const void **buff, size_t *size, int64_t *offset) +{ + ssize_t bytes_read; + struct iso9660 *iso9660; + + iso9660 = (struct iso9660 *)(a->format->data); + + if (iso9660->entry_bytes_unconsumed) { + __archive_read_consume(a, iso9660->entry_bytes_unconsumed); + iso9660->entry_bytes_unconsumed = 0; + } + + if (iso9660->entry_bytes_remaining <= 0) { + if (iso9660->entry_content != NULL) + iso9660->entry_content = iso9660->entry_content->next; + if (iso9660->entry_content == NULL) { + *buff = NULL; + *size = 0; + *offset = iso9660->entry_sparse_offset; + return (ARCHIVE_EOF); + } + /* Seek forward to the start of the entry. */ + if (iso9660->current_position < iso9660->entry_content->offset) { + int64_t step; + + step = iso9660->entry_content->offset - + iso9660->current_position; + step = __archive_read_consume(a, step); + if (step < 0) + return ((int)step); + iso9660->current_position = + iso9660->entry_content->offset; + } + if (iso9660->entry_content->offset < iso9660->current_position) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Ignoring out-of-order file (%s) %jd < %jd", + iso9660->pathname.s, + (intmax_t)iso9660->entry_content->offset, + (intmax_t)iso9660->current_position); + *buff = NULL; + *size = 0; + *offset = iso9660->entry_sparse_offset; + return (ARCHIVE_WARN); + } + iso9660->entry_bytes_remaining = iso9660->entry_content->size; + } + if (iso9660->entry_zisofs.pz) + return (zisofs_read_data(a, buff, size, offset)); + + *buff = __archive_read_ahead(a, 1, &bytes_read); + if (bytes_read == 0) + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Truncated input file"); + if (*buff == NULL) + return (ARCHIVE_FATAL); + if (bytes_read > iso9660->entry_bytes_remaining) + bytes_read = (ssize_t)iso9660->entry_bytes_remaining; + *size = bytes_read; + *offset = iso9660->entry_sparse_offset; + iso9660->entry_sparse_offset += bytes_read; + iso9660->entry_bytes_remaining -= bytes_read; + iso9660->entry_bytes_unconsumed = bytes_read; + iso9660->current_position += bytes_read; + return (ARCHIVE_OK); +} + +static int +archive_read_format_iso9660_cleanup(struct archive_read *a) +{ + struct iso9660 *iso9660; + int r = ARCHIVE_OK; + + iso9660 = (struct iso9660 *)(a->format->data); + release_files(iso9660); + free(iso9660->read_ce_req.reqs); + archive_string_free(&iso9660->pathname); + archive_string_free(&iso9660->previous_pathname); + if (iso9660->pending_files.files) + free(iso9660->pending_files.files); +#ifdef HAVE_ZLIB_H + free(iso9660->entry_zisofs.uncompressed_buffer); + free(iso9660->entry_zisofs.block_pointers); + if (iso9660->entry_zisofs.stream_valid) { + if (inflateEnd(&iso9660->entry_zisofs.stream) != Z_OK) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Failed to clean up zlib decompressor"); + r = ARCHIVE_FATAL; + } + } +#endif + free(iso9660->utf16be_path); + free(iso9660->utf16be_previous_path); + free(iso9660); + (a->format->data) = NULL; + return (r); +} + +/* + * This routine parses a single ISO directory record, makes sense + * of any extensions, and stores the result in memory. + */ +static struct file_info * +parse_file_info(struct archive_read *a, struct file_info *parent, - const unsigned char *isodirrec) ++ const unsigned char *isodirrec, size_t reclen) +{ + struct iso9660 *iso9660; + struct file_info *file, *filep; + size_t name_len; + const unsigned char *rr_start, *rr_end; + const unsigned char *p; + size_t dr_len; + uint64_t fsize, offset; + int32_t location; + int flags; + + iso9660 = (struct iso9660 *)(a->format->data); + - dr_len = (size_t)isodirrec[DR_length_offset]; - name_len = (size_t)isodirrec[DR_name_len_offset]; - location = archive_le32dec(isodirrec + DR_extent_offset); - fsize = toi(isodirrec + DR_size_offset, DR_size_size); - /* Sanity check that dr_len needs at least 34. */ - if (dr_len < 34) { ++ if (reclen != 0) ++ dr_len = (size_t)isodirrec[DR_length_offset]; ++ /* ++ * Sanity check that reclen is not zero and dr_len is greater than ++ * reclen but at least 34 ++ */ ++ if (reclen == 0 || reclen < dr_len || dr_len < 34) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Invalid length of directory record"); ++ "Invalid length of directory record"); + return (NULL); + } ++ name_len = (size_t)isodirrec[DR_name_len_offset]; ++ location = archive_le32dec(isodirrec + DR_extent_offset); ++ fsize = toi(isodirrec + DR_size_offset, DR_size_size); + /* Sanity check that name_len doesn't exceed dr_len. */ + if (dr_len - 33 < name_len || name_len == 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Invalid length of file identifier"); + return (NULL); + } + /* Sanity check that location doesn't exceed volume block. + * Don't check lower limit of location; it's possibility + * the location has negative value when file type is symbolic + * link or file size is zero. As far as I know latest mkisofs + * do that. + */ + if (location > 0 && + (location + ((fsize + iso9660->logical_block_size -1) + / iso9660->logical_block_size)) + > (uint32_t)iso9660->volume_block) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Invalid location of extent of file"); + return (NULL); + } + /* Sanity check that location doesn't have a negative value + * when the file is not empty. it's too large. */ + if (fsize != 0 && location < 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Invalid location of extent of file"); + return (NULL); + } + + /* Sanity check that this entry does not create a cycle. */ + offset = iso9660->logical_block_size * (uint64_t)location; + for (filep = parent; filep != NULL; filep = filep->parent) { + if (filep->offset == offset) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Directory structure contains loop"); + return (NULL); + } + } + + /* Create a new file entry and copy data from the ISO dir record. */ + file = (struct file_info *)calloc(1, sizeof(*file)); + if (file == NULL) { + archive_set_error(&a->archive, ENOMEM, + "No memory for file entry"); + return (NULL); + } + file->parent = parent; + file->offset = offset; + file->size = fsize; + file->mtime = isodate7(isodirrec + DR_date_offset); + file->ctime = file->atime = file->mtime; + file->rede_files.first = NULL; + file->rede_files.last = &(file->rede_files.first); + + p = isodirrec + DR_name_offset; + /* Rockridge extensions (if any) follow name. Compute this + * before fidgeting the name_len below. */ + rr_start = p + name_len + (name_len & 1 ? 0 : 1); + rr_end = isodirrec + dr_len; + + if (iso9660->seenJoliet) { + /* Joliet names are max 64 chars (128 bytes) according to spec, + * but genisoimage/mkisofs allows recording longer Joliet + * names which are 103 UCS2 characters(206 bytes) by their + * option '-joliet-long'. + */ + if (name_len > 206) + name_len = 206; + name_len &= ~1; + + /* trim trailing first version and dot from filename. + * + * Remember we were in UTF-16BE land! + * SEPARATOR 1 (.) and SEPARATOR 2 (;) are both + * 16 bits big endian characters on Joliet. + * + * TODO: sanitize filename? + * Joliet allows any UCS-2 char except: + * *, /, :, ;, ? and \. + */ + /* Chop off trailing ';1' from files. */ + if (name_len > 4 && p[name_len-4] == 0 && p[name_len-3] == ';' + && p[name_len-2] == 0 && p[name_len-1] == '1') + name_len -= 4; +#if 0 /* XXX: this somehow manages to strip of single-character file extensions, like '.c'. */ + /* Chop off trailing '.' from filenames. */ + if (name_len > 2 && p[name_len-2] == 0 && p[name_len-1] == '.') + name_len -= 2; +#endif + if ((file->utf16be_name = malloc(name_len)) == NULL) { + archive_set_error(&a->archive, ENOMEM, + "No memory for file name"); + goto fail; + } + memcpy(file->utf16be_name, p, name_len); + file->utf16be_bytes = name_len; + } else { + /* Chop off trailing ';1' from files. */ + if (name_len > 2 && p[name_len - 2] == ';' && + p[name_len - 1] == '1') + name_len -= 2; + /* Chop off trailing '.' from filenames. */ + if (name_len > 1 && p[name_len - 1] == '.') + --name_len; + + archive_strncpy(&file->name, (const char *)p, name_len); + } + + flags = isodirrec[DR_flags_offset]; + if (flags & 0x02) + file->mode = AE_IFDIR | 0700; + else + file->mode = AE_IFREG | 0400; + if (flags & 0x80) + file->multi_extent = 1; + else + file->multi_extent = 0; + /* + * Use a location for the file number, which is treated as an inode + * number to find out hardlink target. If Rockridge extensions is + * being used, the file number will be overwritten by FILE SERIAL + * NUMBER of RRIP "PX" extension. + * Note: Old mkisofs did not record that FILE SERIAL NUMBER + * in ISO images. + * Note2: xorriso set 0 to the location of a symlink file. + */ + if (file->size == 0 && location >= 0) { + /* If file->size is zero, its location points wrong place, + * and so we should not use it for the file number. + * When the location has negative value, it can be used + * for the file number. + */ + file->number = -1; + /* Do not appear before any directory entries. */ + file->offset = -1; + } else + file->number = (int64_t)(uint32_t)location; + + /* Rockridge extensions overwrite information from above. */ + if (iso9660->opt_support_rockridge) { + if (parent == NULL && rr_end - rr_start >= 7) { + p = rr_start; + if (memcmp(p, "SP\x07\x01\xbe\xef", 6) == 0) { + /* + * SP extension stores the suspOffset + * (Number of bytes to skip between + * filename and SUSP records.) + * It is mandatory by the SUSP standard + * (IEEE 1281). + * + * It allows SUSP to coexist with + * non-SUSP uses of the System + * Use Area by placing non-SUSP data + * before SUSP data. + * + * SP extension must be in the root + * directory entry, disable all SUSP + * processing if not found. + */ + iso9660->suspOffset = p[6]; + iso9660->seenSUSP = 1; + rr_start += 7; + } + } + if (iso9660->seenSUSP) { + int r; + + file->name_continues = 0; + file->symlink_continues = 0; + rr_start += iso9660->suspOffset; + r = parse_rockridge(a, file, rr_start, rr_end); + if (r != ARCHIVE_OK) + goto fail; + /* + * A file size of symbolic link files in ISO images + * made by makefs is not zero and its location is + * the same as those of next regular file. That is + * the same as hard like file and it causes unexpected + * error. + */ + if (file->size > 0 && + (file->mode & AE_IFMT) == AE_IFLNK) { + file->size = 0; + file->number = -1; + file->offset = -1; + } + } else + /* If there isn't SUSP, disable parsing + * rock ridge extensions. */ + iso9660->opt_support_rockridge = 0; + } + + file->nlinks = 1;/* Reset nlink. we'll calculate it later. */ + /* Tell file's parent how many children that parent has. */ + if (parent != NULL && (flags & 0x02)) + parent->subdirs++; + + if (iso9660->seenRockridge) { + if (parent != NULL && parent->parent == NULL && + (flags & 0x02) && iso9660->rr_moved == NULL && + file->name.s && + (strcmp(file->name.s, "rr_moved") == 0 || + strcmp(file->name.s, ".rr_moved") == 0)) { + iso9660->rr_moved = file; + file->rr_moved = 1; + file->rr_moved_has_re_only = 1; + file->re = 0; + parent->subdirs--; + } else if (file->re) { + /* + * Sanity check: file's parent is rr_moved. + */ + if (parent == NULL || parent->rr_moved == 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Invalid Rockridge RE"); + goto fail; + } + /* + * Sanity check: file does not have "CL" extension. + */ + if (file->cl_offset) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Invalid Rockridge RE and CL"); + goto fail; + } + /* + * Sanity check: The file type must be a directory. + */ + if ((flags & 0x02) == 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Invalid Rockridge RE"); + goto fail; + } + } else if (parent != NULL && parent->rr_moved) + file->rr_moved_has_re_only = 0; + else if (parent != NULL && (flags & 0x02) && + (parent->re || parent->re_descendant)) + file->re_descendant = 1; + if (file->cl_offset) { + struct file_info *r; + + if (parent == NULL || parent->parent == NULL) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Invalid Rockridge CL"); + goto fail; + } + /* + * Sanity check: The file type must be a regular file. + */ + if ((flags & 0x02) != 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Invalid Rockridge CL"); + goto fail; + } + parent->subdirs++; + /* Overwrite an offset and a number of this "CL" entry + * to appear before other dirs. "+1" to those is to + * make sure to appear after "RE" entry which this + * "CL" entry should be connected with. */ + file->offset = file->number = file->cl_offset + 1; + + /* + * Sanity check: cl_offset does not point at its + * the parents or itself. + */ + for (r = parent; r; r = r->parent) { + if (r->offset == file->cl_offset) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Invalid Rockridge CL"); + goto fail; + } + } + if (file->cl_offset == file->offset || + parent->rr_moved) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Invalid Rockridge CL"); + goto fail; + } + } + } + +#if DEBUG + /* DEBUGGING: Warn about attributes I don't yet fully support. */ + if ((flags & ~0x02) != 0) { + fprintf(stderr, "\n ** Unrecognized flag: "); + dump_isodirrec(stderr, isodirrec); + fprintf(stderr, "\n"); + } else if (toi(isodirrec + DR_volume_sequence_number_offset, 2) != 1) { + fprintf(stderr, "\n ** Unrecognized sequence number: "); + dump_isodirrec(stderr, isodirrec); + fprintf(stderr, "\n"); + } else if (*(isodirrec + DR_file_unit_size_offset) != 0) { + fprintf(stderr, "\n ** Unexpected file unit size: "); + dump_isodirrec(stderr, isodirrec); + fprintf(stderr, "\n"); + } else if (*(isodirrec + DR_interleave_offset) != 0) { + fprintf(stderr, "\n ** Unexpected interleave: "); + dump_isodirrec(stderr, isodirrec); + fprintf(stderr, "\n"); + } else if (*(isodirrec + DR_ext_attr_length_offset) != 0) { + fprintf(stderr, "\n ** Unexpected extended attribute length: "); + dump_isodirrec(stderr, isodirrec); + fprintf(stderr, "\n"); + } +#endif + register_file(iso9660, file); + return (file); +fail: + archive_string_free(&file->name); + free(file); + return (NULL); +} + +static int +parse_rockridge(struct archive_read *a, struct file_info *file, + const unsigned char *p, const unsigned char *end) +{ + struct iso9660 *iso9660; + + iso9660 = (struct iso9660 *)(a->format->data); + + while (p + 4 <= end /* Enough space for another entry. */ + && p[0] >= 'A' && p[0] <= 'Z' /* Sanity-check 1st char of name. */ + && p[1] >= 'A' && p[1] <= 'Z' /* Sanity-check 2nd char of name. */ + && p[2] >= 4 /* Sanity-check length. */ + && p + p[2] <= end) { /* Sanity-check length. */ + const unsigned char *data = p + 4; + int data_length = p[2] - 4; + int version = p[3]; + + switch(p[0]) { + case 'C': + if (p[1] == 'E') { + if (version == 1 && data_length == 24) { + /* + * CE extension comprises: + * 8 byte sector containing extension + * 8 byte offset w/in above sector + * 8 byte length of continuation + */ + int32_t location = + archive_le32dec(data); + file->ce_offset = + archive_le32dec(data+8); + file->ce_size = + archive_le32dec(data+16); + if (register_CE(a, location, file) + != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } + } + else if (p[1] == 'L') { + if (version == 1 && data_length == 8) { + file->cl_offset = (uint64_t) + iso9660->logical_block_size * + (uint64_t)archive_le32dec(data); + iso9660->seenRockridge = 1; + } + } + break; + case 'N': + if (p[1] == 'M') { + if (version == 1) { + parse_rockridge_NM1(file, + data, data_length); + iso9660->seenRockridge = 1; + } + } + break; + case 'P': + /* + * PD extension is padding; + * contents are always ignored. + * + * PL extension won't appear; + * contents are always ignored. + */ + if (p[1] == 'N') { + if (version == 1 && data_length == 16) { + file->rdev = toi(data,4); + file->rdev <<= 32; + file->rdev |= toi(data + 8, 4); + iso9660->seenRockridge = 1; + } + } + else if (p[1] == 'X') { + /* + * PX extension comprises: + * 8 bytes for mode, + * 8 bytes for nlinks, + * 8 bytes for uid, + * 8 bytes for gid, + * 8 bytes for inode. + */ + if (version == 1) { + if (data_length >= 8) + file->mode + = toi(data, 4); + if (data_length >= 16) + file->nlinks + = toi(data + 8, 4); + if (data_length >= 24) + file->uid + = toi(data + 16, 4); + if (data_length >= 32) + file->gid + = toi(data + 24, 4); + if (data_length >= 40) + file->number + = toi(data + 32, 4); + iso9660->seenRockridge = 1; + } + } + break; + case 'R': + if (p[1] == 'E' && version == 1) { + file->re = 1; + iso9660->seenRockridge = 1; + } + else if (p[1] == 'R' && version == 1) { + /* + * RR extension comprises: + * one byte flag value + * This extension is obsolete, + * so contents are always ignored. + */ + } + break; + case 'S': + if (p[1] == 'L') { + if (version == 1) { + parse_rockridge_SL1(file, + data, data_length); + iso9660->seenRockridge = 1; + } + } + else if (p[1] == 'T' + && data_length == 0 && version == 1) { + /* + * ST extension marks end of this + * block of SUSP entries. + * + * It allows SUSP to coexist with + * non-SUSP uses of the System + * Use Area by placing non-SUSP data + * after SUSP data. + */ + iso9660->seenSUSP = 0; + iso9660->seenRockridge = 0; + return (ARCHIVE_OK); + } + break; + case 'T': + if (p[1] == 'F') { + if (version == 1) { + parse_rockridge_TF1(file, + data, data_length); + iso9660->seenRockridge = 1; + } + } + break; + case 'Z': + if (p[1] == 'F') { + if (version == 1) + parse_rockridge_ZF1(file, + data, data_length); + } + break; + default: + break; + } + + p += p[2]; + } + return (ARCHIVE_OK); +} + +static int +register_CE(struct archive_read *a, int32_t location, + struct file_info *file) +{ + struct iso9660 *iso9660; + struct read_ce_queue *heap; + struct read_ce_req *p; + uint64_t offset, parent_offset; + int hole, parent; + + iso9660 = (struct iso9660 *)(a->format->data); + offset = ((uint64_t)location) * (uint64_t)iso9660->logical_block_size; + if (((file->mode & AE_IFMT) == AE_IFREG && + offset >= file->offset) || + offset < iso9660->current_position || + (((uint64_t)file->ce_offset) + file->ce_size) + > (uint64_t)iso9660->logical_block_size || + offset + file->ce_offset + file->ce_size + > iso9660->volume_size) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Invalid parameter in SUSP \"CE\" extension"); + return (ARCHIVE_FATAL); + } + + /* Expand our CE list as necessary. */ + heap = &(iso9660->read_ce_req); + if (heap->cnt >= heap->allocated) { + int new_size; + + if (heap->allocated < 16) + new_size = 16; + else + new_size = heap->allocated * 2; + /* Overflow might keep us from growing the list. */ + if (new_size <= heap->allocated) { + archive_set_error(&a->archive, ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + p = calloc(new_size, sizeof(p[0])); + if (p == NULL) { + archive_set_error(&a->archive, ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + if (heap->reqs != NULL) { + memcpy(p, heap->reqs, heap->cnt * sizeof(*p)); + free(heap->reqs); + } + heap->reqs = p; + heap->allocated = new_size; + } + + /* + * Start with hole at end, walk it up tree to find insertion point. + */ + hole = heap->cnt++; + while (hole > 0) { + parent = (hole - 1)/2; + parent_offset = heap->reqs[parent].offset; + if (offset >= parent_offset) { + heap->reqs[hole].offset = offset; + heap->reqs[hole].file = file; + return (ARCHIVE_OK); + } + /* Move parent into hole <==> move hole up tree. */ + heap->reqs[hole] = heap->reqs[parent]; + hole = parent; + } + heap->reqs[0].offset = offset; + heap->reqs[0].file = file; + return (ARCHIVE_OK); +} + +static void +next_CE(struct read_ce_queue *heap) +{ + uint64_t a_offset, b_offset, c_offset; + int a, b, c; + struct read_ce_req tmp; + + if (heap->cnt < 1) + return; + + /* + * Move the last item in the heap to the root of the tree + */ + heap->reqs[0] = heap->reqs[--(heap->cnt)]; + + /* + * Rebalance the heap. + */ + a = 0; /* Starting element and its offset */ + a_offset = heap->reqs[a].offset; + for (;;) { + b = a + a + 1; /* First child */ + if (b >= heap->cnt) + return; + b_offset = heap->reqs[b].offset; + c = b + 1; /* Use second child if it is smaller. */ + if (c < heap->cnt) { + c_offset = heap->reqs[c].offset; + if (c_offset < b_offset) { + b = c; + b_offset = c_offset; + } + } + if (a_offset <= b_offset) + return; + tmp = heap->reqs[a]; + heap->reqs[a] = heap->reqs[b]; + heap->reqs[b] = tmp; + a = b; + } +} + + +static int +read_CE(struct archive_read *a, struct iso9660 *iso9660) +{ + struct read_ce_queue *heap; + const unsigned char *b, *p, *end; + struct file_info *file; + size_t step; + int r; + + /* Read data which RRIP "CE" extension points. */ + heap = &(iso9660->read_ce_req); + step = iso9660->logical_block_size; + while (heap->cnt && + heap->reqs[0].offset == iso9660->current_position) { + b = __archive_read_ahead(a, step, NULL); + if (b == NULL) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Failed to read full block when scanning " + "ISO9660 directory list"); + return (ARCHIVE_FATAL); + } + do { + file = heap->reqs[0].file; + if (file->ce_offset + file->ce_size > step) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Malformed CE information"); + return (ARCHIVE_FATAL); + } + p = b + file->ce_offset; + end = p + file->ce_size; + next_CE(heap); + r = parse_rockridge(a, file, p, end); + if (r != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } while (heap->cnt && + heap->reqs[0].offset == iso9660->current_position); + /* NOTE: Do not move this consume's code to front of + * do-while loop. Registration of nested CE extension + * might cause error because of current position. */ + __archive_read_consume(a, step); + iso9660->current_position += step; + } + return (ARCHIVE_OK); +} + +static void +parse_rockridge_NM1(struct file_info *file, + const unsigned char *data, int data_length) +{ + if (!file->name_continues) + archive_string_empty(&file->name); + file->name_continues = 0; + if (data_length < 1) + return; + /* + * NM version 1 extension comprises: + * 1 byte flag, value is one of: + * = 0: remainder is name + * = 1: remainder is name, next NM entry continues name + * = 2: "." + * = 4: ".." + * = 32: Implementation specific + * All other values are reserved. + */ + switch(data[0]) { + case 0: + if (data_length < 2) + return; + archive_strncat(&file->name, + (const char *)data + 1, data_length - 1); + break; + case 1: + if (data_length < 2) + return; + archive_strncat(&file->name, + (const char *)data + 1, data_length - 1); + file->name_continues = 1; + break; + case 2: + archive_strcat(&file->name, "."); + break; + case 4: + archive_strcat(&file->name, ".."); + break; + default: + return; + } + +} + +static void +parse_rockridge_TF1(struct file_info *file, const unsigned char *data, + int data_length) +{ + char flag; + /* + * TF extension comprises: + * one byte flag + * create time (optional) + * modify time (optional) + * access time (optional) + * attribute time (optional) + * Time format and presence of fields + * is controlled by flag bits. + */ + if (data_length < 1) + return; + flag = data[0]; + ++data; + --data_length; + if (flag & 0x80) { + /* Use 17-byte time format. */ + if ((flag & 1) && data_length >= 17) { + /* Create time. */ + file->birthtime_is_set = 1; + file->birthtime = isodate17(data); + data += 17; + data_length -= 17; + } + if ((flag & 2) && data_length >= 17) { + /* Modify time. */ + file->mtime = isodate17(data); + data += 17; + data_length -= 17; + } + if ((flag & 4) && data_length >= 17) { + /* Access time. */ + file->atime = isodate17(data); + data += 17; + data_length -= 17; + } + if ((flag & 8) && data_length >= 17) { + /* Attribute change time. */ + file->ctime = isodate17(data); + } + } else { + /* Use 7-byte time format. */ + if ((flag & 1) && data_length >= 7) { + /* Create time. */ + file->birthtime_is_set = 1; + file->birthtime = isodate7(data); + data += 7; + data_length -= 7; + } + if ((flag & 2) && data_length >= 7) { + /* Modify time. */ + file->mtime = isodate7(data); + data += 7; + data_length -= 7; + } + if ((flag & 4) && data_length >= 7) { + /* Access time. */ + file->atime = isodate7(data); + data += 7; + data_length -= 7; + } + if ((flag & 8) && data_length >= 7) { + /* Attribute change time. */ + file->ctime = isodate7(data); + } + } +} + +static void +parse_rockridge_SL1(struct file_info *file, const unsigned char *data, + int data_length) +{ + const char *separator = ""; + + if (!file->symlink_continues || file->symlink.length < 1) + archive_string_empty(&file->symlink); + file->symlink_continues = 0; + + /* + * Defined flag values: + * 0: This is the last SL record for this symbolic link + * 1: this symbolic link field continues in next SL entry + * All other values are reserved. + */ + if (data_length < 1) + return; + switch(*data) { + case 0: + break; + case 1: + file->symlink_continues = 1; + break; + default: + return; + } + ++data; /* Skip flag byte. */ + --data_length; + + /* + * SL extension body stores "components". + * Basically, this is a complicated way of storing + * a POSIX path. It also interferes with using + * symlinks for storing non-path data. + * + * Each component is 2 bytes (flag and length) + * possibly followed by name data. + */ + while (data_length >= 2) { + unsigned char flag = *data++; + unsigned char nlen = *data++; + data_length -= 2; + + archive_strcat(&file->symlink, separator); + separator = "/"; + + switch(flag) { + case 0: /* Usual case, this is text. */ + if (data_length < nlen) + return; + archive_strncat(&file->symlink, + (const char *)data, nlen); + break; + case 0x01: /* Text continues in next component. */ + if (data_length < nlen) + return; + archive_strncat(&file->symlink, + (const char *)data, nlen); + separator = ""; + break; + case 0x02: /* Current dir. */ + archive_strcat(&file->symlink, "."); + break; + case 0x04: /* Parent dir. */ + archive_strcat(&file->symlink, ".."); + break; + case 0x08: /* Root of filesystem. */ + archive_strcat(&file->symlink, "/"); + separator = ""; + break; + case 0x10: /* Undefined (historically "volume root" */ + archive_string_empty(&file->symlink); + archive_strcat(&file->symlink, "ROOT"); + break; + case 0x20: /* Undefined (historically "hostname") */ + archive_strcat(&file->symlink, "hostname"); + break; + default: + /* TODO: issue a warning ? */ + return; + } + data += nlen; + data_length -= nlen; + } +} + +static void +parse_rockridge_ZF1(struct file_info *file, const unsigned char *data, + int data_length) +{ + + if (data[0] == 0x70 && data[1] == 0x7a && data_length == 12) { + /* paged zlib */ + file->pz = 1; + file->pz_log2_bs = data[3]; + file->pz_uncompressed_size = archive_le32dec(&data[4]); + } +} + +static void +register_file(struct iso9660 *iso9660, struct file_info *file) +{ + + file->use_next = iso9660->use_files; + iso9660->use_files = file; +} + +static void +release_files(struct iso9660 *iso9660) +{ + struct content *con, *connext; + struct file_info *file; + + file = iso9660->use_files; + while (file != NULL) { + struct file_info *next = file->use_next; + + archive_string_free(&file->name); + archive_string_free(&file->symlink); + free(file->utf16be_name); + con = file->contents.first; + while (con != NULL) { + connext = con->next; + free(con); + con = connext; + } + free(file); + file = next; + } +} + +static int +next_entry_seek(struct archive_read *a, struct iso9660 *iso9660, + struct file_info **pfile) +{ + struct file_info *file; + int r; + + r = next_cache_entry(a, iso9660, pfile); + if (r != ARCHIVE_OK) + return (r); + file = *pfile; + + /* Don't waste time seeking for zero-length bodies. */ + if (file->size == 0) + file->offset = iso9660->current_position; + + /* flush any remaining bytes from the last round to ensure + * we're positioned */ + if (iso9660->entry_bytes_unconsumed) { + __archive_read_consume(a, iso9660->entry_bytes_unconsumed); + iso9660->entry_bytes_unconsumed = 0; + } + + /* Seek forward to the start of the entry. */ + if (iso9660->current_position < file->offset) { + int64_t step; + + step = file->offset - iso9660->current_position; + step = __archive_read_consume(a, step); + if (step < 0) + return ((int)step); + iso9660->current_position = file->offset; + } + + /* We found body of file; handle it now. */ + return (ARCHIVE_OK); +} + +static int +next_cache_entry(struct archive_read *a, struct iso9660 *iso9660, + struct file_info **pfile) +{ + struct file_info *file; + struct { + struct file_info *first; + struct file_info **last; + } empty_files; + int64_t number; + int count; + + file = cache_get_entry(iso9660); + if (file != NULL) { + *pfile = file; + return (ARCHIVE_OK); + } + + for (;;) { + struct file_info *re, *d; + + *pfile = file = next_entry(iso9660); + if (file == NULL) { + /* + * If directory entries all which are descendant of + * rr_moved are still remaining, expose their. + */ + if (iso9660->re_files.first != NULL && + iso9660->rr_moved != NULL && + iso9660->rr_moved->rr_moved_has_re_only) + /* Expose "rr_moved" entry. */ + cache_add_entry(iso9660, iso9660->rr_moved); + while ((re = re_get_entry(iso9660)) != NULL) { + /* Expose its descendant dirs. */ + while ((d = rede_get_entry(re)) != NULL) + cache_add_entry(iso9660, d); + } + if (iso9660->cache_files.first != NULL) + return (next_cache_entry(a, iso9660, pfile)); + return (ARCHIVE_EOF); + } + + if (file->cl_offset) { + struct file_info *first_re = NULL; + int nexted_re = 0; + + /* + * Find "RE" dir for the current file, which + * has "CL" flag. + */ + while ((re = re_get_entry(iso9660)) + != first_re) { + if (first_re == NULL) + first_re = re; + if (re->offset == file->cl_offset) { + re->parent->subdirs--; + re->parent = file->parent; + re->re = 0; + if (re->parent->re_descendant) { + nexted_re = 1; + re->re_descendant = 1; + if (rede_add_entry(re) < 0) + goto fatal_rr; + /* Move a list of descendants + * to a new ancestor. */ + while ((d = rede_get_entry( + re)) != NULL) + if (rede_add_entry(d) + < 0) + goto fatal_rr; + break; + } + /* Replace the current file + * with "RE" dir */ + *pfile = file = re; + /* Expose its descendant */ + while ((d = rede_get_entry( + file)) != NULL) + cache_add_entry( + iso9660, d); + break; + } else + re_add_entry(iso9660, re); + } + if (nexted_re) { + /* + * Do not expose this at this time + * because we have not gotten its full-path + * name yet. + */ + continue; + } + } else if ((file->mode & AE_IFMT) == AE_IFDIR) { + int r; + + /* Read file entries in this dir. */ + r = read_children(a, file); + if (r != ARCHIVE_OK) + return (r); + + /* + * Handle a special dir of Rockridge extensions, + * "rr_moved". + */ + if (file->rr_moved) { + /* + * If this has only the subdirectories which + * have "RE" flags, do not expose at this time. + */ + if (file->rr_moved_has_re_only) + continue; + /* Otherwise expose "rr_moved" entry. */ + } else if (file->re) { + /* + * Do not expose this at this time + * because we have not gotten its full-path + * name yet. + */ + re_add_entry(iso9660, file); + continue; + } else if (file->re_descendant) { + /* + * If the top level "RE" entry of this entry + * is not exposed, we, accordingly, should not + * expose this entry at this time because + * we cannot make its proper full-path name. + */ + if (rede_add_entry(file) == 0) + continue; + /* Otherwise we can expose this entry because + * it seems its top level "RE" has already been + * exposed. */ + } + } + break; + } + + if ((file->mode & AE_IFMT) != AE_IFREG || file->number == -1) + return (ARCHIVE_OK); + + count = 0; + number = file->number; + iso9660->cache_files.first = NULL; + iso9660->cache_files.last = &(iso9660->cache_files.first); + empty_files.first = NULL; + empty_files.last = &empty_files.first; + /* Collect files which has the same file serial number. + * Peek pending_files so that file which number is different + * is not put back. */ + while (iso9660->pending_files.used > 0 && + (iso9660->pending_files.files[0]->number == -1 || + iso9660->pending_files.files[0]->number == number)) { + if (file->number == -1) { + /* This file has the same offset + * but it's wrong offset which empty files + * and symlink files have. + * NOTE: This wrong offset was recorded by + * old mkisofs utility. If ISO images is + * created by latest mkisofs, this does not + * happen. + */ + file->next = NULL; + *empty_files.last = file; + empty_files.last = &(file->next); + } else { + count++; + cache_add_entry(iso9660, file); + } + file = next_entry(iso9660); + } + + if (count == 0) { + *pfile = file; + return ((file == NULL)?ARCHIVE_EOF:ARCHIVE_OK); + } + if (file->number == -1) { + file->next = NULL; + *empty_files.last = file; + empty_files.last = &(file->next); + } else { + count++; + cache_add_entry(iso9660, file); + } + + if (count > 1) { + /* The count is the same as number of hardlink, + * so much so that each nlinks of files in cache_file + * is overwritten by value of the count. + */ + for (file = iso9660->cache_files.first; + file != NULL; file = file->next) + file->nlinks = count; + } + /* If there are empty files, that files are added + * to the tail of the cache_files. */ + if (empty_files.first != NULL) { + *iso9660->cache_files.last = empty_files.first; + iso9660->cache_files.last = empty_files.last; + } + *pfile = cache_get_entry(iso9660); + return ((*pfile == NULL)?ARCHIVE_EOF:ARCHIVE_OK); + +fatal_rr: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Failed to connect 'CL' pointer to 'RE' rr_moved pointer of " + "Rockridge extensions: current position = %jd, CL offset = %jd", + (intmax_t)iso9660->current_position, (intmax_t)file->cl_offset); + return (ARCHIVE_FATAL); +} + +static inline void +re_add_entry(struct iso9660 *iso9660, struct file_info *file) +{ + file->re_next = NULL; + *iso9660->re_files.last = file; + iso9660->re_files.last = &(file->re_next); +} + +static inline struct file_info * +re_get_entry(struct iso9660 *iso9660) +{ + struct file_info *file; + + if ((file = iso9660->re_files.first) != NULL) { + iso9660->re_files.first = file->re_next; + if (iso9660->re_files.first == NULL) + iso9660->re_files.last = + &(iso9660->re_files.first); + } + return (file); +} + +static inline int +rede_add_entry(struct file_info *file) +{ + struct file_info *re; + + /* + * Find "RE" entry. + */ + re = file->parent; + while (re != NULL && !re->re) + re = re->parent; + if (re == NULL) + return (-1); + + file->re_next = NULL; + *re->rede_files.last = file; + re->rede_files.last = &(file->re_next); + return (0); +} + +static inline struct file_info * +rede_get_entry(struct file_info *re) +{ + struct file_info *file; + + if ((file = re->rede_files.first) != NULL) { + re->rede_files.first = file->re_next; + if (re->rede_files.first == NULL) + re->rede_files.last = + &(re->rede_files.first); + } + return (file); +} + +static inline void +cache_add_entry(struct iso9660 *iso9660, struct file_info *file) +{ + file->next = NULL; + *iso9660->cache_files.last = file; + iso9660->cache_files.last = &(file->next); +} + +static inline struct file_info * +cache_get_entry(struct iso9660 *iso9660) +{ + struct file_info *file; + + if ((file = iso9660->cache_files.first) != NULL) { + iso9660->cache_files.first = file->next; + if (iso9660->cache_files.first == NULL) + iso9660->cache_files.last = + &(iso9660->cache_files.first); + } + return (file); +} + +static int +heap_add_entry(struct archive_read *a, struct heap_queue *heap, + struct file_info *file, uint64_t key) +{ + uint64_t file_key, parent_key; + int hole, parent; + + /* Expand our pending files list as necessary. */ + if (heap->used >= heap->allocated) { + struct file_info **new_pending_files; + int new_size = heap->allocated * 2; + + if (heap->allocated < 1024) + new_size = 1024; + /* Overflow might keep us from growing the list. */ + if (new_size <= heap->allocated) { + archive_set_error(&a->archive, + ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + new_pending_files = (struct file_info **) + malloc(new_size * sizeof(new_pending_files[0])); + if (new_pending_files == NULL) { + archive_set_error(&a->archive, + ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + if (heap->allocated) + memcpy(new_pending_files, heap->files, + heap->allocated * sizeof(new_pending_files[0])); + if (heap->files != NULL) + free(heap->files); + heap->files = new_pending_files; + heap->allocated = new_size; + } + + file_key = file->key = key; + + /* + * Start with hole at end, walk it up tree to find insertion point. + */ + hole = heap->used++; + while (hole > 0) { + parent = (hole - 1)/2; + parent_key = heap->files[parent]->key; + if (file_key >= parent_key) { + heap->files[hole] = file; + return (ARCHIVE_OK); + } + /* Move parent into hole <==> move hole up tree. */ + heap->files[hole] = heap->files[parent]; + hole = parent; + } + heap->files[0] = file; + + return (ARCHIVE_OK); +} + +static struct file_info * +heap_get_entry(struct heap_queue *heap) +{ + uint64_t a_key, b_key, c_key; + int a, b, c; + struct file_info *r, *tmp; + + if (heap->used < 1) + return (NULL); + + /* + * The first file in the list is the earliest; we'll return this. + */ + r = heap->files[0]; + + /* + * Move the last item in the heap to the root of the tree + */ + heap->files[0] = heap->files[--(heap->used)]; + + /* + * Rebalance the heap. + */ + a = 0; /* Starting element and its heap key */ + a_key = heap->files[a]->key; + for (;;) { + b = a + a + 1; /* First child */ + if (b >= heap->used) + return (r); + b_key = heap->files[b]->key; + c = b + 1; /* Use second child if it is smaller. */ + if (c < heap->used) { + c_key = heap->files[c]->key; + if (c_key < b_key) { + b = c; + b_key = c_key; + } + } + if (a_key <= b_key) + return (r); + tmp = heap->files[a]; + heap->files[a] = heap->files[b]; + heap->files[b] = tmp; + a = b; + } +} + +static unsigned int +toi(const void *p, int n) +{ + const unsigned char *v = (const unsigned char *)p; + if (n > 1) + return v[0] + 256 * toi(v + 1, n - 1); + if (n == 1) + return v[0]; + return (0); +} + +static time_t +isodate7(const unsigned char *v) +{ + struct tm tm; + int offset; + time_t t; + + memset(&tm, 0, sizeof(tm)); + tm.tm_year = v[0]; + tm.tm_mon = v[1] - 1; + tm.tm_mday = v[2]; + tm.tm_hour = v[3]; + tm.tm_min = v[4]; + tm.tm_sec = v[5]; + /* v[6] is the signed timezone offset, in 1/4-hour increments. */ + offset = ((const signed char *)v)[6]; + if (offset > -48 && offset < 52) { + tm.tm_hour -= offset / 4; + tm.tm_min -= (offset % 4) * 15; + } + t = time_from_tm(&tm); + if (t == (time_t)-1) + return ((time_t)0); + return (t); +} + +static time_t +isodate17(const unsigned char *v) +{ + struct tm tm; + int offset; + time_t t; + + memset(&tm, 0, sizeof(tm)); + tm.tm_year = (v[0] - '0') * 1000 + (v[1] - '0') * 100 + + (v[2] - '0') * 10 + (v[3] - '0') + - 1900; + tm.tm_mon = (v[4] - '0') * 10 + (v[5] - '0'); + tm.tm_mday = (v[6] - '0') * 10 + (v[7] - '0'); + tm.tm_hour = (v[8] - '0') * 10 + (v[9] - '0'); + tm.tm_min = (v[10] - '0') * 10 + (v[11] - '0'); + tm.tm_sec = (v[12] - '0') * 10 + (v[13] - '0'); + /* v[16] is the signed timezone offset, in 1/4-hour increments. */ + offset = ((const signed char *)v)[16]; + if (offset > -48 && offset < 52) { + tm.tm_hour -= offset / 4; + tm.tm_min -= (offset % 4) * 15; + } + t = time_from_tm(&tm); + if (t == (time_t)-1) + return ((time_t)0); + return (t); +} + +static time_t +time_from_tm(struct tm *t) +{ +#if HAVE_TIMEGM + /* Use platform timegm() if available. */ + return (timegm(t)); +#elif HAVE__MKGMTIME64 + return (_mkgmtime64(t)); +#else + /* Else use direct calculation using POSIX assumptions. */ + /* First, fix up tm_yday based on the year/month/day. */ + if (mktime(t) == (time_t)-1) + return ((time_t)-1); + /* Then we can compute timegm() from first principles. */ + return (t->tm_sec + + t->tm_min * 60 + + t->tm_hour * 3600 + + t->tm_yday * 86400 + + (t->tm_year - 70) * 31536000 + + ((t->tm_year - 69) / 4) * 86400 + - ((t->tm_year - 1) / 100) * 86400 + + ((t->tm_year + 299) / 400) * 86400); +#endif +} + +static const char * +build_pathname(struct archive_string *as, struct file_info *file, int depth) +{ + // Plain ISO9660 only allows 8 dir levels; if we get + // to 1000, then something is very, very wrong. + if (depth > 1000) { + return NULL; + } + if (file->parent != NULL && archive_strlen(&file->parent->name) > 0) { + if (build_pathname(as, file->parent, depth + 1) == NULL) { + return NULL; + } + archive_strcat(as, "/"); + } + if (archive_strlen(&file->name) == 0) + archive_strcat(as, "."); + else + archive_string_concat(as, &file->name); + return (as->s); +} + +static int +build_pathname_utf16be(unsigned char *p, size_t max, size_t *len, + struct file_info *file) +{ + if (file->parent != NULL && file->parent->utf16be_bytes > 0) { + if (build_pathname_utf16be(p, max, len, file->parent) != 0) + return (-1); + p[*len] = 0; + p[*len + 1] = '/'; + *len += 2; + } + if (file->utf16be_bytes == 0) { + if (*len + 2 > max) + return (-1);/* Path is too long! */ + p[*len] = 0; + p[*len + 1] = '.'; + *len += 2; + } else { + if (*len + file->utf16be_bytes > max) + return (-1);/* Path is too long! */ + memcpy(p + *len, file->utf16be_name, file->utf16be_bytes); + *len += file->utf16be_bytes; + } + return (0); +} + +#if DEBUG +static void +dump_isodirrec(FILE *out, const unsigned char *isodirrec) +{ + fprintf(out, " l %d,", + toi(isodirrec + DR_length_offset, DR_length_size)); + fprintf(out, " a %d,", + toi(isodirrec + DR_ext_attr_length_offset, DR_ext_attr_length_size)); + fprintf(out, " ext 0x%x,", + toi(isodirrec + DR_extent_offset, DR_extent_size)); + fprintf(out, " s %d,", + toi(isodirrec + DR_size_offset, DR_extent_size)); + fprintf(out, " f 0x%x,", + toi(isodirrec + DR_flags_offset, DR_flags_size)); + fprintf(out, " u %d,", + toi(isodirrec + DR_file_unit_size_offset, DR_file_unit_size_size)); + fprintf(out, " ilv %d,", + toi(isodirrec + DR_interleave_offset, DR_interleave_size)); + fprintf(out, " seq %d,", + toi(isodirrec + DR_volume_sequence_number_offset, + DR_volume_sequence_number_size)); + fprintf(out, " nl %d:", + toi(isodirrec + DR_name_len_offset, DR_name_len_size)); + fprintf(out, " `%.*s'", + toi(isodirrec + DR_name_len_offset, DR_name_len_size), + isodirrec + DR_name_offset); +} +#endif diff --cc Utilities/cmlibarchive/libarchive/archive_read_support_format_lha.c index 1995e9c,0000000..98d02c6 mode 100644,000000..100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_lha.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_lha.c @@@ -1,2817 -1,0 +1,2823 @@@ +/*- + * Copyright (c) 2008-2014 Michihiro NAKAJIMA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "archive_platform.h" + +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_LIMITS_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif + +#include "archive.h" +#include "archive_entry.h" +#include "archive_entry_locale.h" +#include "archive_private.h" +#include "archive_read_private.h" +#include "archive_endian.h" + + +#define MAXMATCH 256 /* Maximum match length. */ +#define MINMATCH 3 /* Minimum match length. */ +/* + * Literal table format: + * +0 +256 +510 + * +---------------+-------------------------+ + * | literal code | match length | + * | 0 ... 255 | MINMATCH ... MAXMATCH | + * +---------------+-------------------------+ + * <--- LT_BITLEN_SIZE ---> + */ +/* Literal table size. */ +#define LT_BITLEN_SIZE (UCHAR_MAX + 1 + MAXMATCH - MINMATCH + 1) +/* Position table size. + * Note: this used for both position table and pre literal table.*/ +#define PT_BITLEN_SIZE (3 + 16) + +struct lzh_dec { + /* Decoding status. */ + int state; + + /* + * Window to see last 8Ki(lh5),32Ki(lh6),64Ki(lh7) bytes of decoded + * data. + */ + int w_size; + int w_mask; + /* Window buffer, which is a loop buffer. */ + unsigned char *w_buff; + /* The insert position to the window. */ + int w_pos; + /* The position where we can copy decoded code from the window. */ + int copy_pos; + /* The length how many bytes we can copy decoded code from + * the window. */ + int copy_len; + + /* + * Bit stream reader. + */ + struct lzh_br { +#define CACHE_TYPE uint64_t +#define CACHE_BITS (8 * sizeof(CACHE_TYPE)) + /* Cache buffer. */ + CACHE_TYPE cache_buffer; + /* Indicates how many bits avail in cache_buffer. */ + int cache_avail; + } br; + + /* + * Huffman coding. + */ + struct huffman { + int len_size; + int len_avail; + int len_bits; + int freq[17]; + unsigned char *bitlen; + + /* + * Use a index table. It's faster than searching a huffman + * coding tree, which is a binary tree. But a use of a large + * index table causes L1 cache read miss many times. + */ +#define HTBL_BITS 10 + int max_bits; + int shift_bits; + int tbl_bits; + int tree_used; + int tree_avail; + /* Direct access table. */ + uint16_t *tbl; + /* Binary tree table for extra bits over the direct access. */ + struct htree_t { + uint16_t left; + uint16_t right; + } *tree; + } lt, pt; + + int blocks_avail; + int pos_pt_len_size; + int pos_pt_len_bits; + int literal_pt_len_size; + int literal_pt_len_bits; + int reading_position; + int loop; + int error; +}; + +struct lzh_stream { + const unsigned char *next_in; + int avail_in; + int64_t total_in; + const unsigned char *ref_ptr; + int avail_out; + int64_t total_out; + struct lzh_dec *ds; +}; + +struct lha { + /* entry_bytes_remaining is the number of bytes we expect. */ + int64_t entry_offset; + int64_t entry_bytes_remaining; + int64_t entry_unconsumed; + uint16_t entry_crc_calculated; + + size_t header_size; /* header size */ + unsigned char level; /* header level */ + char method[3]; /* compress type */ + int64_t compsize; /* compressed data size */ + int64_t origsize; /* original file size */ + int setflag; +#define BIRTHTIME_IS_SET 1 +#define ATIME_IS_SET 2 +#define UNIX_MODE_IS_SET 4 +#define CRC_IS_SET 8 + time_t birthtime; + long birthtime_tv_nsec; + time_t mtime; + long mtime_tv_nsec; + time_t atime; + long atime_tv_nsec; + mode_t mode; + int64_t uid; + int64_t gid; + struct archive_string uname; + struct archive_string gname; + uint16_t header_crc; + uint16_t crc; + struct archive_string_conv *sconv; + struct archive_string_conv *opt_sconv; + + struct archive_string dirname; + struct archive_string filename; + struct archive_wstring ws; + + unsigned char dos_attr; + + /* Flag to mark progress that an archive was read their first header.*/ + char found_first_header; + /* Flag to mark that indicates an empty directory. */ + char directory; + + /* Flags to mark progress of decompression. */ + char decompress_init; + char end_of_entry; + char end_of_entry_cleanup; + char entry_is_compressed; + + char format_name[64]; + + struct lzh_stream strm; +}; + +/* + * LHA header common member offset. + */ +#define H_METHOD_OFFSET 2 /* Compress type. */ +#define H_ATTR_OFFSET 19 /* DOS attribute. */ +#define H_LEVEL_OFFSET 20 /* Header Level. */ +#define H_SIZE 22 /* Minimum header size. */ + +static int archive_read_format_lha_bid(struct archive_read *, int); +static int archive_read_format_lha_options(struct archive_read *, + const char *, const char *); +static int archive_read_format_lha_read_header(struct archive_read *, + struct archive_entry *); +static int archive_read_format_lha_read_data(struct archive_read *, + const void **, size_t *, int64_t *); +static int archive_read_format_lha_read_data_skip(struct archive_read *); +static int archive_read_format_lha_cleanup(struct archive_read *); + +static void lha_replace_path_separator(struct lha *, + struct archive_entry *); +static int lha_read_file_header_0(struct archive_read *, struct lha *); +static int lha_read_file_header_1(struct archive_read *, struct lha *); +static int lha_read_file_header_2(struct archive_read *, struct lha *); +static int lha_read_file_header_3(struct archive_read *, struct lha *); +static int lha_read_file_extended_header(struct archive_read *, + struct lha *, uint16_t *, int, size_t, size_t *); +static size_t lha_check_header_format(const void *); +static int lha_skip_sfx(struct archive_read *); +static time_t lha_dos_time(const unsigned char *); +static time_t lha_win_time(uint64_t, long *); +static unsigned char lha_calcsum(unsigned char, const void *, + int, size_t); +static int lha_parse_linkname(struct archive_string *, + struct archive_string *); +static int lha_read_data_none(struct archive_read *, const void **, + size_t *, int64_t *); +static int lha_read_data_lzh(struct archive_read *, const void **, + size_t *, int64_t *); +static void lha_crc16_init(void); +static uint16_t lha_crc16(uint16_t, const void *, size_t); +static int lzh_decode_init(struct lzh_stream *, const char *); +static void lzh_decode_free(struct lzh_stream *); +static int lzh_decode(struct lzh_stream *, int); +static int lzh_br_fillup(struct lzh_stream *, struct lzh_br *); +static int lzh_huffman_init(struct huffman *, size_t, int); +static void lzh_huffman_free(struct huffman *); +static int lzh_read_pt_bitlen(struct lzh_stream *, int start, int end); +static int lzh_make_fake_table(struct huffman *, uint16_t); +static int lzh_make_huffman_table(struct huffman *); +static inline int lzh_decode_huffman(struct huffman *, unsigned); +static int lzh_decode_huffman_tree(struct huffman *, unsigned, int); + + +int +archive_read_support_format_lha(struct archive *_a) +{ + struct archive_read *a = (struct archive_read *)_a; + struct lha *lha; + int r; + + archive_check_magic(_a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_format_lha"); + + lha = (struct lha *)calloc(1, sizeof(*lha)); + if (lha == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate lha data"); + return (ARCHIVE_FATAL); + } + archive_string_init(&lha->ws); + + r = __archive_read_register_format(a, + lha, + "lha", + archive_read_format_lha_bid, + archive_read_format_lha_options, + archive_read_format_lha_read_header, + archive_read_format_lha_read_data, + archive_read_format_lha_read_data_skip, + NULL, + archive_read_format_lha_cleanup, + NULL, + NULL); + + if (r != ARCHIVE_OK) + free(lha); + return (ARCHIVE_OK); +} + +static size_t +lha_check_header_format(const void *h) +{ + const unsigned char *p = h; + size_t next_skip_bytes; + + switch (p[H_METHOD_OFFSET+3]) { + /* + * "-lh0-" ... "-lh7-" "-lhd-" + * "-lzs-" "-lz5-" + */ + case '0': case '1': case '2': case '3': + case '4': case '5': case '6': case '7': + case 'd': + case 's': + next_skip_bytes = 4; + + /* b0 == 0 means the end of an LHa archive file. */ + if (p[0] == 0) + break; + if (p[H_METHOD_OFFSET] != '-' || p[H_METHOD_OFFSET+1] != 'l' + || p[H_METHOD_OFFSET+4] != '-') + break; + + if (p[H_METHOD_OFFSET+2] == 'h') { + /* "-lh?-" */ + if (p[H_METHOD_OFFSET+3] == 's') + break; + if (p[H_LEVEL_OFFSET] == 0) + return (0); + if (p[H_LEVEL_OFFSET] <= 3 && p[H_ATTR_OFFSET] == 0x20) + return (0); + } + if (p[H_METHOD_OFFSET+2] == 'z') { + /* LArc extensions: -lzs-,-lz4- and -lz5- */ + if (p[H_LEVEL_OFFSET] != 0) + break; + if (p[H_METHOD_OFFSET+3] == 's' + || p[H_METHOD_OFFSET+3] == '4' + || p[H_METHOD_OFFSET+3] == '5') + return (0); + } + break; + case 'h': next_skip_bytes = 1; break; + case 'z': next_skip_bytes = 1; break; + case 'l': next_skip_bytes = 2; break; + case '-': next_skip_bytes = 3; break; + default : next_skip_bytes = 4; break; + } + + return (next_skip_bytes); +} + +static int +archive_read_format_lha_bid(struct archive_read *a, int best_bid) +{ + const char *p; + const void *buff; + ssize_t bytes_avail, offset, window; + size_t next; + + /* If there's already a better bid than we can ever + make, don't bother testing. */ + if (best_bid > 30) + return (-1); + + if ((p = __archive_read_ahead(a, H_SIZE, NULL)) == NULL) + return (-1); + + if (lha_check_header_format(p) == 0) + return (30); + + if (p[0] == 'M' && p[1] == 'Z') { + /* PE file */ + offset = 0; + window = 4096; + while (offset < (1024 * 20)) { + buff = __archive_read_ahead(a, offset + window, + &bytes_avail); + if (buff == NULL) { + /* Remaining bytes are less than window. */ + window >>= 1; + if (window < (H_SIZE + 3)) + return (0); + continue; + } + p = (const char *)buff + offset; + while (p + H_SIZE < (const char *)buff + bytes_avail) { + if ((next = lha_check_header_format(p)) == 0) + return (30); + p += next; + } + offset = p - (const char *)buff; + } + } + return (0); +} + +static int +archive_read_format_lha_options(struct archive_read *a, + const char *key, const char *val) +{ + struct lha *lha; + int ret = ARCHIVE_FAILED; + + lha = (struct lha *)(a->format->data); + if (strcmp(key, "hdrcharset") == 0) { + if (val == NULL || val[0] == 0) + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "lha: hdrcharset option needs a character-set name"); + else { + lha->opt_sconv = + archive_string_conversion_from_charset( + &a->archive, val, 0); + if (lha->opt_sconv != NULL) + ret = ARCHIVE_OK; + else + ret = ARCHIVE_FATAL; + } + return (ret); + } + + /* Note: The "warn" return is just to inform the options + * supervisor that we didn't handle it. It will generate + * a suitable error if no one used this option. */ + return (ARCHIVE_WARN); +} + +static int +lha_skip_sfx(struct archive_read *a) +{ + const void *h; + const char *p, *q; + size_t next, skip; + ssize_t bytes, window; + + window = 4096; + for (;;) { + h = __archive_read_ahead(a, window, &bytes); + if (h == NULL) { + /* Remaining bytes are less than window. */ + window >>= 1; + if (window < (H_SIZE + 3)) + goto fatal; + continue; + } + if (bytes < H_SIZE) + goto fatal; + p = h; + q = p + bytes; + + /* + * Scan ahead until we find something that looks + * like the lha header. + */ + while (p + H_SIZE < q) { + if ((next = lha_check_header_format(p)) == 0) { + skip = p - (const char *)h; + __archive_read_consume(a, skip); + return (ARCHIVE_OK); + } + p += next; + } + skip = p - (const char *)h; + __archive_read_consume(a, skip); + } +fatal: + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Couldn't find out LHa header"); + return (ARCHIVE_FATAL); +} + +static int +truncated_error(struct archive_read *a) +{ + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated LHa header"); + return (ARCHIVE_FATAL); +} + +static int +archive_read_format_lha_read_header(struct archive_read *a, + struct archive_entry *entry) +{ + struct archive_string linkname; + struct archive_string pathname; + struct lha *lha; + const unsigned char *p; + const char *signature; + int err; + + lha_crc16_init(); + + a->archive.archive_format = ARCHIVE_FORMAT_LHA; + if (a->archive.archive_format_name == NULL) + a->archive.archive_format_name = "lha"; + + lha = (struct lha *)(a->format->data); + lha->decompress_init = 0; + lha->end_of_entry = 0; + lha->end_of_entry_cleanup = 0; + lha->entry_unconsumed = 0; + + if ((p = __archive_read_ahead(a, H_SIZE, NULL)) == NULL) { + /* + * LHa archiver added 0 to the tail of its archive file as + * the mark of the end of the archive. + */ + signature = __archive_read_ahead(a, sizeof(signature[0]), NULL); + if (signature == NULL || signature[0] == 0) + return (ARCHIVE_EOF); + return (truncated_error(a)); + } + + signature = (const char *)p; + if (lha->found_first_header == 0 && + signature[0] == 'M' && signature[1] == 'Z') { + /* This is an executable? Must be self-extracting... */ + err = lha_skip_sfx(a); + if (err < ARCHIVE_WARN) + return (err); + + if ((p = __archive_read_ahead(a, sizeof(*p), NULL)) == NULL) + return (truncated_error(a)); + signature = (const char *)p; + } + /* signature[0] == 0 means the end of an LHa archive file. */ + if (signature[0] == 0) + return (ARCHIVE_EOF); + + /* + * Check the header format and method type. + */ + if (lha_check_header_format(p) != 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Bad LHa file"); + return (ARCHIVE_FATAL); + } + + /* We've found the first header. */ + lha->found_first_header = 1; + /* Set a default value and common data */ + lha->header_size = 0; + lha->level = p[H_LEVEL_OFFSET]; + lha->method[0] = p[H_METHOD_OFFSET+1]; + lha->method[1] = p[H_METHOD_OFFSET+2]; + lha->method[2] = p[H_METHOD_OFFSET+3]; + if (memcmp(lha->method, "lhd", 3) == 0) + lha->directory = 1; + else + lha->directory = 0; + if (memcmp(lha->method, "lh0", 3) == 0 || + memcmp(lha->method, "lz4", 3) == 0) + lha->entry_is_compressed = 0; + else + lha->entry_is_compressed = 1; + + lha->compsize = 0; + lha->origsize = 0; + lha->setflag = 0; + lha->birthtime = 0; + lha->birthtime_tv_nsec = 0; + lha->mtime = 0; + lha->mtime_tv_nsec = 0; + lha->atime = 0; + lha->atime_tv_nsec = 0; + lha->mode = (lha->directory)? 0777 : 0666; + lha->uid = 0; + lha->gid = 0; + archive_string_empty(&lha->dirname); + archive_string_empty(&lha->filename); + lha->dos_attr = 0; + if (lha->opt_sconv != NULL) + lha->sconv = lha->opt_sconv; + else + lha->sconv = NULL; + + switch (p[H_LEVEL_OFFSET]) { + case 0: + err = lha_read_file_header_0(a, lha); + break; + case 1: + err = lha_read_file_header_1(a, lha); + break; + case 2: + err = lha_read_file_header_2(a, lha); + break; + case 3: + err = lha_read_file_header_3(a, lha); + break; + default: + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Unsupported LHa header level %d", p[H_LEVEL_OFFSET]); + err = ARCHIVE_FATAL; + break; + } + if (err < ARCHIVE_WARN) + return (err); + + + if (!lha->directory && archive_strlen(&lha->filename) == 0) + /* The filename has not been set */ + return (truncated_error(a)); + + /* + * Make a pathname from a dirname and a filename. + */ + archive_string_concat(&lha->dirname, &lha->filename); + archive_string_init(&pathname); + archive_string_init(&linkname); + archive_string_copy(&pathname, &lha->dirname); + + if ((lha->mode & AE_IFMT) == AE_IFLNK) { + /* + * Extract the symlink-name if it's included in the pathname. + */ + if (!lha_parse_linkname(&linkname, &pathname)) { + /* We couldn't get the symlink-name. */ + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Unknown symlink-name"); + archive_string_free(&pathname); + archive_string_free(&linkname); + return (ARCHIVE_FAILED); + } + } else { + /* + * Make sure a file-type is set. + * The mode has been overridden if it is in the extended data. + */ + lha->mode = (lha->mode & ~AE_IFMT) | + ((lha->directory)? AE_IFDIR: AE_IFREG); + } + if ((lha->setflag & UNIX_MODE_IS_SET) == 0 && + (lha->dos_attr & 1) != 0) + lha->mode &= ~(0222);/* read only. */ + + /* + * Set basic file parameters. + */ + if (archive_entry_copy_pathname_l(entry, pathname.s, + pathname.length, lha->sconv) != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Pathname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Pathname cannot be converted " + "from %s to current locale.", + archive_string_conversion_charset_name(lha->sconv)); + err = ARCHIVE_WARN; + } + archive_string_free(&pathname); + if (archive_strlen(&linkname) > 0) { + if (archive_entry_copy_symlink_l(entry, linkname.s, + linkname.length, lha->sconv) != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Linkname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Linkname cannot be converted " + "from %s to current locale.", + archive_string_conversion_charset_name(lha->sconv)); + err = ARCHIVE_WARN; + } + } else + archive_entry_set_symlink(entry, NULL); + archive_string_free(&linkname); + /* + * When a header level is 0, there is a possibility that + * a pathname and a symlink has '\' character, a directory + * separator in DOS/Windows. So we should convert it to '/'. + */ + if (p[H_LEVEL_OFFSET] == 0) + lha_replace_path_separator(lha, entry); + + archive_entry_set_mode(entry, lha->mode); + archive_entry_set_uid(entry, lha->uid); + archive_entry_set_gid(entry, lha->gid); + if (archive_strlen(&lha->uname) > 0) + archive_entry_set_uname(entry, lha->uname.s); + if (archive_strlen(&lha->gname) > 0) + archive_entry_set_gname(entry, lha->gname.s); + if (lha->setflag & BIRTHTIME_IS_SET) { + archive_entry_set_birthtime(entry, lha->birthtime, + lha->birthtime_tv_nsec); + archive_entry_set_ctime(entry, lha->birthtime, + lha->birthtime_tv_nsec); + } else { + archive_entry_unset_birthtime(entry); + archive_entry_unset_ctime(entry); + } + archive_entry_set_mtime(entry, lha->mtime, lha->mtime_tv_nsec); + if (lha->setflag & ATIME_IS_SET) + archive_entry_set_atime(entry, lha->atime, + lha->atime_tv_nsec); + else + archive_entry_unset_atime(entry); + if (lha->directory || archive_entry_symlink(entry) != NULL) + archive_entry_unset_size(entry); + else + archive_entry_set_size(entry, lha->origsize); + + /* + * Prepare variables used to read a file content. + */ + lha->entry_bytes_remaining = lha->compsize; ++ if (lha->entry_bytes_remaining < 0) { ++ archive_set_error(&a->archive, ++ ARCHIVE_ERRNO_FILE_FORMAT, ++ "Invalid LHa entry size"); ++ return (ARCHIVE_FATAL); ++ } + lha->entry_offset = 0; + lha->entry_crc_calculated = 0; + + /* + * This file does not have a content. + */ + if (lha->directory || lha->compsize == 0) + lha->end_of_entry = 1; + + sprintf(lha->format_name, "lha -%c%c%c-", + lha->method[0], lha->method[1], lha->method[2]); + a->archive.archive_format_name = lha->format_name; + + return (err); +} + +/* + * Replace a DOS path separator '\' by a character '/'. + * Some multi-byte character set have a character '\' in its second byte. + */ +static void +lha_replace_path_separator(struct lha *lha, struct archive_entry *entry) +{ + const wchar_t *wp; + size_t i; + + if ((wp = archive_entry_pathname_w(entry)) != NULL) { + archive_wstrcpy(&(lha->ws), wp); + for (i = 0; i < archive_strlen(&(lha->ws)); i++) { + if (lha->ws.s[i] == L'\\') + lha->ws.s[i] = L'/'; + } + archive_entry_copy_pathname_w(entry, lha->ws.s); + } + + if ((wp = archive_entry_symlink_w(entry)) != NULL) { + archive_wstrcpy(&(lha->ws), wp); + for (i = 0; i < archive_strlen(&(lha->ws)); i++) { + if (lha->ws.s[i] == L'\\') + lha->ws.s[i] = L'/'; + } + archive_entry_copy_symlink_w(entry, lha->ws.s); + } +} + +/* + * Header 0 format + * + * +0 +1 +2 +7 +11 + * +---------------+----------+----------------+-------------------+ + * |header size(*1)|header sum|compression type|compressed size(*2)| + * +---------------+----------+----------------+-------------------+ + * <---------------------(*1)----------* + * + * +11 +15 +17 +19 +20 +21 + * +-----------------+---------+---------+--------------+----------------+ + * |uncompressed size|time(DOS)|date(DOS)|attribute(DOS)|header level(=0)| + * +-----------------+---------+---------+--------------+----------------+ + * *--------------------------------(*1)---------------------------------* + * + * +21 +22 +22+(*3) +22+(*3)+2 +22+(*3)+2+(*4) + * +---------------+---------+----------+----------------+------------------+ + * |name length(*3)|file name|file CRC16|extra header(*4)| compressed data | + * +---------------+---------+----------+----------------+------------------+ + * <--(*3)-> <------(*2)------> + * *----------------------(*1)--------------------------> + * + */ +#define H0_HEADER_SIZE_OFFSET 0 +#define H0_HEADER_SUM_OFFSET 1 +#define H0_COMP_SIZE_OFFSET 7 +#define H0_ORIG_SIZE_OFFSET 11 +#define H0_DOS_TIME_OFFSET 15 +#define H0_NAME_LEN_OFFSET 21 +#define H0_FILE_NAME_OFFSET 22 +#define H0_FIXED_SIZE 24 +static int +lha_read_file_header_0(struct archive_read *a, struct lha *lha) +{ + const unsigned char *p; + int extdsize, namelen; + unsigned char headersum, sum_calculated; + + if ((p = __archive_read_ahead(a, H0_FIXED_SIZE, NULL)) == NULL) + return (truncated_error(a)); + lha->header_size = p[H0_HEADER_SIZE_OFFSET] + 2; + headersum = p[H0_HEADER_SUM_OFFSET]; + lha->compsize = archive_le32dec(p + H0_COMP_SIZE_OFFSET); + lha->origsize = archive_le32dec(p + H0_ORIG_SIZE_OFFSET); + lha->mtime = lha_dos_time(p + H0_DOS_TIME_OFFSET); + namelen = p[H0_NAME_LEN_OFFSET]; + extdsize = (int)lha->header_size - H0_FIXED_SIZE - namelen; + if ((namelen > 221 || extdsize < 0) && extdsize != -2) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid LHa header"); + return (ARCHIVE_FATAL); + } + if ((p = __archive_read_ahead(a, lha->header_size, NULL)) == NULL) + return (truncated_error(a)); + + archive_strncpy(&lha->filename, p + H0_FILE_NAME_OFFSET, namelen); + /* When extdsize == -2, A CRC16 value is not present in the header. */ + if (extdsize >= 0) { + lha->crc = archive_le16dec(p + H0_FILE_NAME_OFFSET + namelen); + lha->setflag |= CRC_IS_SET; + } + sum_calculated = lha_calcsum(0, p, 2, lha->header_size - 2); + + /* Read an extended header */ + if (extdsize > 0) { + /* This extended data is set by 'LHa for UNIX' only. + * Maybe fixed size. + */ + p += H0_FILE_NAME_OFFSET + namelen + 2; + if (p[0] == 'U' && extdsize == 12) { + /* p[1] is a minor version. */ + lha->mtime = archive_le32dec(&p[2]); + lha->mode = archive_le16dec(&p[6]); + lha->uid = archive_le16dec(&p[8]); + lha->gid = archive_le16dec(&p[10]); + lha->setflag |= UNIX_MODE_IS_SET; + } + } + __archive_read_consume(a, lha->header_size); + + if (sum_calculated != headersum) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "LHa header sum error"); + return (ARCHIVE_FATAL); + } + + return (ARCHIVE_OK); +} + +/* + * Header 1 format + * + * +0 +1 +2 +7 +11 + * +---------------+----------+----------------+-------------+ + * |header size(*1)|header sum|compression type|skip size(*2)| + * +---------------+----------+----------------+-------------+ + * <---------------(*1)----------* + * + * +11 +15 +17 +19 +20 +21 + * +-----------------+---------+---------+--------------+----------------+ + * |uncompressed size|time(DOS)|date(DOS)|attribute(DOS)|header level(=1)| + * +-----------------+---------+---------+--------------+----------------+ + * *-------------------------------(*1)----------------------------------* + * + * +21 +22 +22+(*3) +22+(*3)+2 +22+(*3)+3 +22+(*3)+3+(*4) + * +---------------+---------+----------+-----------+-----------+ + * |name length(*3)|file name|file CRC16| creator |padding(*4)| + * +---------------+---------+----------+-----------+-----------+ + * <--(*3)-> + * *----------------------------(*1)----------------------------* + * + * +22+(*3)+3+(*4) +22+(*3)+3+(*4)+2 +22+(*3)+3+(*4)+2+(*5) + * +----------------+---------------------+------------------------+ + * |next header size| extended header(*5) | compressed data | + * +----------------+---------------------+------------------------+ + * *------(*1)-----> <--------------------(*2)--------------------> + */ +#define H1_HEADER_SIZE_OFFSET 0 +#define H1_HEADER_SUM_OFFSET 1 +#define H1_COMP_SIZE_OFFSET 7 +#define H1_ORIG_SIZE_OFFSET 11 +#define H1_DOS_TIME_OFFSET 15 +#define H1_NAME_LEN_OFFSET 21 +#define H1_FILE_NAME_OFFSET 22 +#define H1_FIXED_SIZE 27 +static int +lha_read_file_header_1(struct archive_read *a, struct lha *lha) +{ + const unsigned char *p; + size_t extdsize; + int i, err, err2; + int namelen, padding; + unsigned char headersum, sum_calculated; + + err = ARCHIVE_OK; + + if ((p = __archive_read_ahead(a, H1_FIXED_SIZE, NULL)) == NULL) + return (truncated_error(a)); + + lha->header_size = p[H1_HEADER_SIZE_OFFSET] + 2; + headersum = p[H1_HEADER_SUM_OFFSET]; + /* Note: An extended header size is included in a compsize. */ + lha->compsize = archive_le32dec(p + H1_COMP_SIZE_OFFSET); + lha->origsize = archive_le32dec(p + H1_ORIG_SIZE_OFFSET); + lha->mtime = lha_dos_time(p + H1_DOS_TIME_OFFSET); + namelen = p[H1_NAME_LEN_OFFSET]; + /* Calculate a padding size. The result will be normally 0 only(?) */ + padding = ((int)lha->header_size) - H1_FIXED_SIZE - namelen; + + if (namelen > 230 || padding < 0) + goto invalid; + + if ((p = __archive_read_ahead(a, lha->header_size, NULL)) == NULL) + return (truncated_error(a)); + + for (i = 0; i < namelen; i++) { + if (p[i + H1_FILE_NAME_OFFSET] == 0xff) + goto invalid;/* Invalid filename. */ + } + archive_strncpy(&lha->filename, p + H1_FILE_NAME_OFFSET, namelen); + lha->crc = archive_le16dec(p + H1_FILE_NAME_OFFSET + namelen); + lha->setflag |= CRC_IS_SET; + + sum_calculated = lha_calcsum(0, p, 2, lha->header_size - 2); + /* Consume used bytes but not include `next header size' data + * since it will be consumed in lha_read_file_extended_header(). */ + __archive_read_consume(a, lha->header_size - 2); + + /* Read extended headers */ + err2 = lha_read_file_extended_header(a, lha, NULL, 2, + (size_t)(lha->compsize + 2), &extdsize); + if (err2 < ARCHIVE_WARN) + return (err2); + if (err2 < err) + err = err2; + /* Get a real compressed file size. */ + lha->compsize -= extdsize - 2; + + if (lha->compsize < 0) + goto invalid; /* Invalid compressed file size */ + + if (sum_calculated != headersum) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "LHa header sum error"); + return (ARCHIVE_FATAL); + } + return (err); +invalid: + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid LHa header"); + return (ARCHIVE_FATAL); +} + +/* + * Header 2 format + * + * +0 +2 +7 +11 +15 + * +---------------+----------------+-------------------+-----------------+ + * |header size(*1)|compression type|compressed size(*2)|uncompressed size| + * +---------------+----------------+-------------------+-----------------+ + * <--------------------------------(*1)---------------------------------* + * + * +15 +19 +20 +21 +23 +24 + * +-----------------+------------+----------------+----------+-----------+ + * |data/time(time_t)| 0x20 fixed |header level(=2)|file CRC16| creator | + * +-----------------+------------+----------------+----------+-----------+ + * *---------------------------------(*1)---------------------------------* + * + * +24 +26 +26+(*3) +26+(*3)+(*4) + * +----------------+-------------------+-------------+-------------------+ + * |next header size|extended header(*3)| padding(*4) | compressed data | + * +----------------+-------------------+-------------+-------------------+ + * *--------------------------(*1)-------------------> <------(*2)-------> + * + */ +#define H2_HEADER_SIZE_OFFSET 0 +#define H2_COMP_SIZE_OFFSET 7 +#define H2_ORIG_SIZE_OFFSET 11 +#define H2_TIME_OFFSET 15 +#define H2_CRC_OFFSET 21 +#define H2_FIXED_SIZE 24 +static int +lha_read_file_header_2(struct archive_read *a, struct lha *lha) +{ + const unsigned char *p; + size_t extdsize; + int err, padding; + uint16_t header_crc; + + if ((p = __archive_read_ahead(a, H2_FIXED_SIZE, NULL)) == NULL) + return (truncated_error(a)); + + lha->header_size =archive_le16dec(p + H2_HEADER_SIZE_OFFSET); + lha->compsize = archive_le32dec(p + H2_COMP_SIZE_OFFSET); + lha->origsize = archive_le32dec(p + H2_ORIG_SIZE_OFFSET); + lha->mtime = archive_le32dec(p + H2_TIME_OFFSET); + lha->crc = archive_le16dec(p + H2_CRC_OFFSET); + lha->setflag |= CRC_IS_SET; + + if (lha->header_size < H2_FIXED_SIZE) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid LHa header size"); + return (ARCHIVE_FATAL); + } + + header_crc = lha_crc16(0, p, H2_FIXED_SIZE); + __archive_read_consume(a, H2_FIXED_SIZE); + + /* Read extended headers */ + err = lha_read_file_extended_header(a, lha, &header_crc, 2, + lha->header_size - H2_FIXED_SIZE, &extdsize); + if (err < ARCHIVE_WARN) + return (err); + + /* Calculate a padding size. The result will be normally 0 or 1. */ + padding = (int)lha->header_size - (int)(H2_FIXED_SIZE + extdsize); + if (padding > 0) { + if ((p = __archive_read_ahead(a, padding, NULL)) == NULL) + return (truncated_error(a)); + header_crc = lha_crc16(header_crc, p, padding); + __archive_read_consume(a, padding); + } + + if (header_crc != lha->header_crc) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "LHa header CRC error"); + return (ARCHIVE_FATAL); + } + return (err); +} + +/* + * Header 3 format + * + * +0 +2 +7 +11 +15 + * +------------+----------------+-------------------+-----------------+ + * | 0x04 fixed |compression type|compressed size(*2)|uncompressed size| + * +------------+----------------+-------------------+-----------------+ + * <-------------------------------(*1)-------------------------------* + * + * +15 +19 +20 +21 +23 +24 + * +-----------------+------------+----------------+----------+-----------+ + * |date/time(time_t)| 0x20 fixed |header level(=3)|file CRC16| creator | + * +-----------------+------------+----------------+----------+-----------+ + * *--------------------------------(*1)----------------------------------* + * + * +24 +28 +32 +32+(*3) + * +---------------+----------------+-------------------+-----------------+ + * |header size(*1)|next header size|extended header(*3)| compressed data | + * +---------------+----------------+-------------------+-----------------+ + * *------------------------(*1)-----------------------> <------(*2)-----> + * + */ +#define H3_FIELD_LEN_OFFSET 0 +#define H3_COMP_SIZE_OFFSET 7 +#define H3_ORIG_SIZE_OFFSET 11 +#define H3_TIME_OFFSET 15 +#define H3_CRC_OFFSET 21 +#define H3_HEADER_SIZE_OFFSET 24 +#define H3_FIXED_SIZE 28 +static int +lha_read_file_header_3(struct archive_read *a, struct lha *lha) +{ + const unsigned char *p; + size_t extdsize; + int err; + uint16_t header_crc; + + if ((p = __archive_read_ahead(a, H3_FIXED_SIZE, NULL)) == NULL) + return (truncated_error(a)); + + if (archive_le16dec(p + H3_FIELD_LEN_OFFSET) != 4) + goto invalid; + lha->header_size =archive_le32dec(p + H3_HEADER_SIZE_OFFSET); + lha->compsize = archive_le32dec(p + H3_COMP_SIZE_OFFSET); + lha->origsize = archive_le32dec(p + H3_ORIG_SIZE_OFFSET); + lha->mtime = archive_le32dec(p + H3_TIME_OFFSET); + lha->crc = archive_le16dec(p + H3_CRC_OFFSET); + lha->setflag |= CRC_IS_SET; + + if (lha->header_size < H3_FIXED_SIZE + 4) + goto invalid; + header_crc = lha_crc16(0, p, H3_FIXED_SIZE); + __archive_read_consume(a, H3_FIXED_SIZE); + + /* Read extended headers */ + err = lha_read_file_extended_header(a, lha, &header_crc, 4, + lha->header_size - H3_FIXED_SIZE, &extdsize); + if (err < ARCHIVE_WARN) + return (err); + + if (header_crc != lha->header_crc) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "LHa header CRC error"); + return (ARCHIVE_FATAL); + } + return (err); +invalid: + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid LHa header"); + return (ARCHIVE_FATAL); +} + +/* + * Extended header format + * + * +0 +2 +3 -- used in header 1 and 2 + * +0 +4 +5 -- used in header 3 + * +--------------+---------+-------------------+--------------+-- + * |ex-header size|header id| data |ex-header size| ....... + * +--------------+---------+-------------------+--------------+-- + * <-------------( ex-header size)------------> <-- next extended header --* + * + * If the ex-header size is zero, it is the make of the end of extended + * headers. + * + */ +static int +lha_read_file_extended_header(struct archive_read *a, struct lha *lha, + uint16_t *crc, int sizefield_length, size_t limitsize, size_t *total_size) +{ + const void *h; + const unsigned char *extdheader; + size_t extdsize; + size_t datasize; + unsigned int i; + unsigned char extdtype; + +#define EXT_HEADER_CRC 0x00 /* Header CRC and information*/ +#define EXT_FILENAME 0x01 /* Filename */ +#define EXT_DIRECTORY 0x02 /* Directory name */ +#define EXT_DOS_ATTR 0x40 /* MS-DOS attribute */ +#define EXT_TIMESTAMP 0x41 /* Windows time stamp */ +#define EXT_FILESIZE 0x42 /* Large file size */ +#define EXT_TIMEZONE 0x43 /* Time zone */ +#define EXT_UTF16_FILENAME 0x44 /* UTF-16 filename */ +#define EXT_UTF16_DIRECTORY 0x45 /* UTF-16 directory name */ +#define EXT_CODEPAGE 0x46 /* Codepage */ +#define EXT_UNIX_MODE 0x50 /* File permission */ +#define EXT_UNIX_GID_UID 0x51 /* gid,uid */ +#define EXT_UNIX_GNAME 0x52 /* Group name */ +#define EXT_UNIX_UNAME 0x53 /* User name */ +#define EXT_UNIX_MTIME 0x54 /* Modified time */ +#define EXT_OS2_NEW_ATTR 0x7f /* new attribute(OS/2 only) */ +#define EXT_NEW_ATTR 0xff /* new attribute */ + + *total_size = sizefield_length; + + for (;;) { + /* Read an extended header size. */ + if ((h = + __archive_read_ahead(a, sizefield_length, NULL)) == NULL) + return (truncated_error(a)); + /* Check if the size is the zero indicates the end of the + * extended header. */ + if (sizefield_length == sizeof(uint16_t)) + extdsize = archive_le16dec(h); + else + extdsize = archive_le32dec(h); + if (extdsize == 0) { + /* End of extended header */ + if (crc != NULL) + *crc = lha_crc16(*crc, h, sizefield_length); + __archive_read_consume(a, sizefield_length); + return (ARCHIVE_OK); + } + + /* Sanity check to the extended header size. */ + if (((uint64_t)*total_size + extdsize) > + (uint64_t)limitsize || + extdsize <= (size_t)sizefield_length) + goto invalid; + + /* Read the extended header. */ + if ((h = __archive_read_ahead(a, extdsize, NULL)) == NULL) + return (truncated_error(a)); + *total_size += extdsize; + + extdheader = (const unsigned char *)h; + /* Get the extended header type. */ + extdtype = extdheader[sizefield_length]; + /* Calculate an extended data size. */ + datasize = extdsize - (1 + sizefield_length); + /* Skip an extended header size field and type field. */ + extdheader += sizefield_length + 1; + + if (crc != NULL && extdtype != EXT_HEADER_CRC) + *crc = lha_crc16(*crc, h, extdsize); + switch (extdtype) { + case EXT_HEADER_CRC: + /* We only use a header CRC. Following data will not + * be used. */ + if (datasize >= 2) { + lha->header_crc = archive_le16dec(extdheader); + if (crc != NULL) { + static const char zeros[2] = {0, 0}; + *crc = lha_crc16(*crc, h, + extdsize - datasize); + /* CRC value itself as zero */ + *crc = lha_crc16(*crc, zeros, 2); + *crc = lha_crc16(*crc, + extdheader+2, datasize - 2); + } + } + break; + case EXT_FILENAME: + if (datasize == 0) { + /* maybe directory header */ + archive_string_empty(&lha->filename); + break; + } + if (extdheader[0] == '\0') + goto invalid; + archive_strncpy(&lha->filename, + (const char *)extdheader, datasize); + break; + case EXT_DIRECTORY: + if (datasize == 0 || extdheader[0] == '\0') + /* no directory name data. exit this case. */ + goto invalid; + + archive_strncpy(&lha->dirname, + (const char *)extdheader, datasize); + /* + * Convert directory delimiter from 0xFF + * to '/' for local system. + */ + for (i = 0; i < lha->dirname.length; i++) { + if ((unsigned char)lha->dirname.s[i] == 0xFF) + lha->dirname.s[i] = '/'; + } + /* Is last character directory separator? */ + if (lha->dirname.s[lha->dirname.length-1] != '/') + /* invalid directory data */ + goto invalid; + break; + case EXT_DOS_ATTR: + if (datasize == 2) + lha->dos_attr = (unsigned char) + (archive_le16dec(extdheader) & 0xff); + break; + case EXT_TIMESTAMP: + if (datasize == (sizeof(uint64_t) * 3)) { + lha->birthtime = lha_win_time( + archive_le64dec(extdheader), + &lha->birthtime_tv_nsec); + extdheader += sizeof(uint64_t); + lha->mtime = lha_win_time( + archive_le64dec(extdheader), + &lha->mtime_tv_nsec); + extdheader += sizeof(uint64_t); + lha->atime = lha_win_time( + archive_le64dec(extdheader), + &lha->atime_tv_nsec); + lha->setflag |= BIRTHTIME_IS_SET | + ATIME_IS_SET; + } + break; + case EXT_FILESIZE: + if (datasize == sizeof(uint64_t) * 2) { + lha->compsize = archive_le64dec(extdheader); + extdheader += sizeof(uint64_t); + lha->origsize = archive_le64dec(extdheader); + } + break; + case EXT_CODEPAGE: + /* Get an archived filename charset from codepage. + * This overwrites the charset specified by + * hdrcharset option. */ + if (datasize == sizeof(uint32_t)) { + struct archive_string cp; + const char *charset; + + archive_string_init(&cp); + switch (archive_le32dec(extdheader)) { + case 65001: /* UTF-8 */ + charset = "UTF-8"; + break; + default: + archive_string_sprintf(&cp, "CP%d", + (int)archive_le32dec(extdheader)); + charset = cp.s; + break; + } + lha->sconv = + archive_string_conversion_from_charset( + &(a->archive), charset, 1); + archive_string_free(&cp); + if (lha->sconv == NULL) + return (ARCHIVE_FATAL); + } + break; + case EXT_UNIX_MODE: + if (datasize == sizeof(uint16_t)) { + lha->mode = archive_le16dec(extdheader); + lha->setflag |= UNIX_MODE_IS_SET; + } + break; + case EXT_UNIX_GID_UID: + if (datasize == (sizeof(uint16_t) * 2)) { + lha->gid = archive_le16dec(extdheader); + lha->uid = archive_le16dec(extdheader+2); + } + break; + case EXT_UNIX_GNAME: + if (datasize > 0) + archive_strncpy(&lha->gname, + (const char *)extdheader, datasize); + break; + case EXT_UNIX_UNAME: + if (datasize > 0) + archive_strncpy(&lha->uname, + (const char *)extdheader, datasize); + break; + case EXT_UNIX_MTIME: + if (datasize == sizeof(uint32_t)) + lha->mtime = archive_le32dec(extdheader); + break; + case EXT_OS2_NEW_ATTR: + /* This extended header is OS/2 depend. */ + if (datasize == 16) { + lha->dos_attr = (unsigned char) + (archive_le16dec(extdheader) & 0xff); + lha->mode = archive_le16dec(extdheader+2); + lha->gid = archive_le16dec(extdheader+4); + lha->uid = archive_le16dec(extdheader+6); + lha->birthtime = archive_le32dec(extdheader+8); + lha->atime = archive_le32dec(extdheader+12); + lha->setflag |= UNIX_MODE_IS_SET + | BIRTHTIME_IS_SET | ATIME_IS_SET; + } + break; + case EXT_NEW_ATTR: + if (datasize == 20) { + lha->mode = (mode_t)archive_le32dec(extdheader); + lha->gid = archive_le32dec(extdheader+4); + lha->uid = archive_le32dec(extdheader+8); + lha->birthtime = archive_le32dec(extdheader+12); + lha->atime = archive_le32dec(extdheader+16); + lha->setflag |= UNIX_MODE_IS_SET + | BIRTHTIME_IS_SET | ATIME_IS_SET; + } + break; + case EXT_TIMEZONE: /* Not supported */ + case EXT_UTF16_FILENAME: /* Not supported */ + case EXT_UTF16_DIRECTORY: /* Not supported */ + default: + break; + } + + __archive_read_consume(a, extdsize); + } +invalid: + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid extended LHa header"); + return (ARCHIVE_FATAL); +} + +static int +lha_end_of_entry(struct archive_read *a) +{ + struct lha *lha = (struct lha *)(a->format->data); + int r = ARCHIVE_EOF; + + if (!lha->end_of_entry_cleanup) { + if ((lha->setflag & CRC_IS_SET) && + lha->crc != lha->entry_crc_calculated) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "LHa data CRC error"); + r = ARCHIVE_WARN; + } + + /* End-of-entry cleanup done. */ + lha->end_of_entry_cleanup = 1; + } + return (r); +} + +static int +archive_read_format_lha_read_data(struct archive_read *a, + const void **buff, size_t *size, int64_t *offset) +{ + struct lha *lha = (struct lha *)(a->format->data); + int r; + + if (lha->entry_unconsumed) { + /* Consume as much as the decompressor actually used. */ + __archive_read_consume(a, lha->entry_unconsumed); + lha->entry_unconsumed = 0; + } + if (lha->end_of_entry) { + *offset = lha->entry_offset; + *size = 0; + *buff = NULL; + return (lha_end_of_entry(a)); + } + + if (lha->entry_is_compressed) + r = lha_read_data_lzh(a, buff, size, offset); + else + /* No compression. */ + r = lha_read_data_none(a, buff, size, offset); + return (r); +} + +/* + * Read a file content in no compression. + * + * Returns ARCHIVE_OK if successful, ARCHIVE_FATAL otherwise, sets + * lha->end_of_entry if it consumes all of the data. + */ +static int +lha_read_data_none(struct archive_read *a, const void **buff, + size_t *size, int64_t *offset) +{ + struct lha *lha = (struct lha *)(a->format->data); + ssize_t bytes_avail; + + if (lha->entry_bytes_remaining == 0) { + *buff = NULL; + *size = 0; + *offset = lha->entry_offset; + lha->end_of_entry = 1; + return (ARCHIVE_OK); + } + /* + * Note: '1' here is a performance optimization. + * Recall that the decompression layer returns a count of + * available bytes; asking for more than that forces the + * decompressor to combine reads by copying data. + */ + *buff = __archive_read_ahead(a, 1, &bytes_avail); + if (bytes_avail <= 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated LHa file data"); + return (ARCHIVE_FATAL); + } + if (bytes_avail > lha->entry_bytes_remaining) + bytes_avail = (ssize_t)lha->entry_bytes_remaining; + lha->entry_crc_calculated = + lha_crc16(lha->entry_crc_calculated, *buff, bytes_avail); + *size = bytes_avail; + *offset = lha->entry_offset; + lha->entry_offset += bytes_avail; + lha->entry_bytes_remaining -= bytes_avail; + if (lha->entry_bytes_remaining == 0) + lha->end_of_entry = 1; + lha->entry_unconsumed = bytes_avail; + return (ARCHIVE_OK); +} + +/* + * Read a file content in LZHUFF encoding. + * + * Returns ARCHIVE_OK if successful, returns ARCHIVE_WARN if compression is + * unsupported, ARCHIVE_FATAL otherwise, sets lha->end_of_entry if it consumes + * all of the data. + */ +static int +lha_read_data_lzh(struct archive_read *a, const void **buff, + size_t *size, int64_t *offset) +{ + struct lha *lha = (struct lha *)(a->format->data); + ssize_t bytes_avail; + int r; + + /* If we haven't yet read any data, initialize the decompressor. */ + if (!lha->decompress_init) { + r = lzh_decode_init(&(lha->strm), lha->method); + switch (r) { + case ARCHIVE_OK: + break; + case ARCHIVE_FAILED: + /* Unsupported compression. */ + *buff = NULL; + *size = 0; + *offset = 0; + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Unsupported lzh compression method -%c%c%c-", + lha->method[0], lha->method[1], lha->method[2]); + /* We know compressed size; just skip it. */ + archive_read_format_lha_read_data_skip(a); + return (ARCHIVE_WARN); + default: + archive_set_error(&a->archive, ENOMEM, + "Couldn't allocate memory " + "for lzh decompression"); + return (ARCHIVE_FATAL); + } + /* We've initialized decompression for this stream. */ + lha->decompress_init = 1; + lha->strm.avail_out = 0; + lha->strm.total_out = 0; + } + + /* + * Note: '1' here is a performance optimization. + * Recall that the decompression layer returns a count of + * available bytes; asking for more than that forces the + * decompressor to combine reads by copying data. + */ + lha->strm.next_in = __archive_read_ahead(a, 1, &bytes_avail); + if (bytes_avail <= 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated LHa file body"); + return (ARCHIVE_FATAL); + } + if (bytes_avail > lha->entry_bytes_remaining) + bytes_avail = (ssize_t)lha->entry_bytes_remaining; + + lha->strm.avail_in = (int)bytes_avail; + lha->strm.total_in = 0; + lha->strm.avail_out = 0; + + r = lzh_decode(&(lha->strm), bytes_avail == lha->entry_bytes_remaining); + switch (r) { + case ARCHIVE_OK: + break; + case ARCHIVE_EOF: + lha->end_of_entry = 1; + break; + default: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Bad lzh data"); + return (ARCHIVE_FAILED); + } + lha->entry_unconsumed = lha->strm.total_in; + lha->entry_bytes_remaining -= lha->strm.total_in; + + if (lha->strm.avail_out) { + *offset = lha->entry_offset; + *size = lha->strm.avail_out; + *buff = lha->strm.ref_ptr; + lha->entry_crc_calculated = + lha_crc16(lha->entry_crc_calculated, *buff, *size); + lha->entry_offset += *size; + } else { + *offset = lha->entry_offset; + *size = 0; + *buff = NULL; + if (lha->end_of_entry) + return (lha_end_of_entry(a)); + } + return (ARCHIVE_OK); +} + +/* + * Skip a file content. + */ +static int +archive_read_format_lha_read_data_skip(struct archive_read *a) +{ + struct lha *lha; + int64_t bytes_skipped; + + lha = (struct lha *)(a->format->data); + + if (lha->entry_unconsumed) { + /* Consume as much as the decompressor actually used. */ + __archive_read_consume(a, lha->entry_unconsumed); + lha->entry_unconsumed = 0; + } + + /* if we've already read to end of data, we're done. */ + if (lha->end_of_entry_cleanup) + return (ARCHIVE_OK); + + /* + * If the length is at the beginning, we can skip the + * compressed data much more quickly. + */ + bytes_skipped = __archive_read_consume(a, lha->entry_bytes_remaining); + if (bytes_skipped < 0) + return (ARCHIVE_FATAL); + + /* This entry is finished and done. */ + lha->end_of_entry_cleanup = lha->end_of_entry = 1; + return (ARCHIVE_OK); +} + +static int +archive_read_format_lha_cleanup(struct archive_read *a) +{ + struct lha *lha = (struct lha *)(a->format->data); + + lzh_decode_free(&(lha->strm)); + archive_string_free(&(lha->dirname)); + archive_string_free(&(lha->filename)); + archive_string_free(&(lha->uname)); + archive_string_free(&(lha->gname)); + archive_wstring_free(&(lha->ws)); + free(lha); + (a->format->data) = NULL; + return (ARCHIVE_OK); +} + +/* + * 'LHa for UNIX' utility has archived a symbolic-link name after + * a pathname with '|' character. + * This function extracts the symbolic-link name from the pathname. + * + * example. + * 1. a symbolic-name is 'aaa/bb/cc' + * 2. a filename is 'xxx/bbb' + * then a archived pathname is 'xxx/bbb|aaa/bb/cc' + */ +static int +lha_parse_linkname(struct archive_string *linkname, + struct archive_string *pathname) +{ + char * linkptr; + size_t symlen; + + linkptr = strchr(pathname->s, '|'); + if (linkptr != NULL) { + symlen = strlen(linkptr + 1); + archive_strncpy(linkname, linkptr+1, symlen); + + *linkptr = 0; + pathname->length = strlen(pathname->s); + + return (1); + } + return (0); +} + +/* Convert an MSDOS-style date/time into Unix-style time. */ +static time_t +lha_dos_time(const unsigned char *p) +{ + int msTime, msDate; + struct tm ts; + + msTime = archive_le16dec(p); + msDate = archive_le16dec(p+2); + + memset(&ts, 0, sizeof(ts)); + ts.tm_year = ((msDate >> 9) & 0x7f) + 80; /* Years since 1900. */ + ts.tm_mon = ((msDate >> 5) & 0x0f) - 1; /* Month number. */ + ts.tm_mday = msDate & 0x1f; /* Day of month. */ + ts.tm_hour = (msTime >> 11) & 0x1f; + ts.tm_min = (msTime >> 5) & 0x3f; + ts.tm_sec = (msTime << 1) & 0x3e; + ts.tm_isdst = -1; + return (mktime(&ts)); +} + +/* Convert an MS-Windows-style date/time into Unix-style time. */ +static time_t +lha_win_time(uint64_t wintime, long *ns) +{ +#define EPOC_TIME ARCHIVE_LITERAL_ULL(116444736000000000) + + if (wintime >= EPOC_TIME) { + wintime -= EPOC_TIME; /* 1970-01-01 00:00:00 (UTC) */ + if (ns != NULL) + *ns = (long)(wintime % 10000000) * 100; + return (wintime / 10000000); + } else { + if (ns != NULL) + *ns = 0; + return (0); + } +} + +static unsigned char +lha_calcsum(unsigned char sum, const void *pp, int offset, size_t size) +{ + unsigned char const *p = (unsigned char const *)pp; + + p += offset; + for (;size > 0; --size) + sum += *p++; + return (sum); +} + +static uint16_t crc16tbl[2][256]; +static void +lha_crc16_init(void) +{ + unsigned int i; + static int crc16init = 0; + + if (crc16init) + return; + crc16init = 1; + + for (i = 0; i < 256; i++) { + unsigned int j; + uint16_t crc = (uint16_t)i; + for (j = 8; j; j--) + crc = (crc >> 1) ^ ((crc & 1) * 0xA001); + crc16tbl[0][i] = crc; + } + + for (i = 0; i < 256; i++) { + crc16tbl[1][i] = (crc16tbl[0][i] >> 8) + ^ crc16tbl[0][crc16tbl[0][i] & 0xff]; + } +} + +static uint16_t +lha_crc16(uint16_t crc, const void *pp, size_t len) +{ + const unsigned char *p = (const unsigned char *)pp; + const uint16_t *buff; + const union { + uint32_t i; + char c[4]; + } u = { 0x01020304 }; + + if (len == 0) + return crc; + + /* Process unaligned address. */ + if (((uintptr_t)p) & (uintptr_t)0x1) { + crc = (crc >> 8) ^ crc16tbl[0][(crc ^ *p++) & 0xff]; + len--; + } + buff = (const uint16_t *)p; + /* + * Modern C compiler such as GCC does not unroll automatically yet + * without unrolling pragma, and Clang is so. So we should + * unroll this loop for its performance. + */ + for (;len >= 8; len -= 8) { + /* This if statement expects compiler optimization will + * remove the statement which will not be executed. */ +#undef bswap16 +#ifndef __has_builtin +# define __has_builtin(x) 0 +#endif +#if defined(_MSC_VER) && _MSC_VER >= 1400 /* Visual Studio */ +# define bswap16(x) _byteswap_ushort(x) +#elif defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 8) || __GNUC__ > 4) +/* GCC 4.8 and later has __builtin_bswap16() */ +# define bswap16(x) __builtin_bswap16(x) +#elif defined(__clang__) && __has_builtin(__builtin_bswap16) +/* All clang versions have __builtin_bswap16() */ +# define bswap16(x) __builtin_bswap16(x) +#else +# define bswap16(x) ((((x) >> 8) & 0xff) | ((x) << 8)) +#endif +#define CRC16W do { \ + if(u.c[0] == 1) { /* Big endian */ \ + crc ^= bswap16(*buff); buff++; \ + } else \ + crc ^= *buff++; \ + crc = crc16tbl[1][crc & 0xff] ^ crc16tbl[0][crc >> 8];\ +} while (0) + CRC16W; + CRC16W; + CRC16W; + CRC16W; +#undef CRC16W +#undef bswap16 + } + + p = (const unsigned char *)buff; + for (;len; len--) { + crc = (crc >> 8) ^ crc16tbl[0][(crc ^ *p++) & 0xff]; + } + return crc; +} + +/* + * Initialize LZHUF decoder. + * + * Returns ARCHIVE_OK if initialization was successful. + * Returns ARCHIVE_FAILED if method is unsupported. + * Returns ARCHIVE_FATAL if initialization failed; memory allocation + * error occurred. + */ +static int +lzh_decode_init(struct lzh_stream *strm, const char *method) +{ + struct lzh_dec *ds; + int w_bits, w_size; + + if (strm->ds == NULL) { + strm->ds = calloc(1, sizeof(*strm->ds)); + if (strm->ds == NULL) + return (ARCHIVE_FATAL); + } + ds = strm->ds; + ds->error = ARCHIVE_FAILED; + if (method == NULL || method[0] != 'l' || method[1] != 'h') + return (ARCHIVE_FAILED); + switch (method[2]) { + case '5': + w_bits = 13;/* 8KiB for window */ + break; + case '6': + w_bits = 15;/* 32KiB for window */ + break; + case '7': + w_bits = 16;/* 64KiB for window */ + break; + default: + return (ARCHIVE_FAILED);/* Not supported. */ + } + ds->error = ARCHIVE_FATAL; + /* Expand a window size up to 128 KiB for decompressing process + * performance whatever its original window size is. */ + ds->w_size = 1U << 17; + ds->w_mask = ds->w_size -1; + if (ds->w_buff == NULL) { + ds->w_buff = malloc(ds->w_size); + if (ds->w_buff == NULL) + return (ARCHIVE_FATAL); + } + w_size = 1U << w_bits; + memset(ds->w_buff + ds->w_size - w_size, 0x20, w_size); + ds->w_pos = 0; + ds->state = 0; + ds->pos_pt_len_size = w_bits + 1; + ds->pos_pt_len_bits = (w_bits == 15 || w_bits == 16)? 5: 4; + ds->literal_pt_len_size = PT_BITLEN_SIZE; + ds->literal_pt_len_bits = 5; + ds->br.cache_buffer = 0; + ds->br.cache_avail = 0; + + if (lzh_huffman_init(&(ds->lt), LT_BITLEN_SIZE, 16) + != ARCHIVE_OK) + return (ARCHIVE_FATAL); + ds->lt.len_bits = 9; + if (lzh_huffman_init(&(ds->pt), PT_BITLEN_SIZE, 16) + != ARCHIVE_OK) + return (ARCHIVE_FATAL); + ds->error = 0; + + return (ARCHIVE_OK); +} + +/* + * Release LZHUF decoder. + */ +static void +lzh_decode_free(struct lzh_stream *strm) +{ + + if (strm->ds == NULL) + return; + free(strm->ds->w_buff); + lzh_huffman_free(&(strm->ds->lt)); + lzh_huffman_free(&(strm->ds->pt)); + free(strm->ds); + strm->ds = NULL; +} + +/* + * Bit stream reader. + */ +/* Check that the cache buffer has enough bits. */ +#define lzh_br_has(br, n) ((br)->cache_avail >= n) +/* Get compressed data by bit. */ +#define lzh_br_bits(br, n) \ + (((uint16_t)((br)->cache_buffer >> \ + ((br)->cache_avail - (n)))) & cache_masks[n]) +#define lzh_br_bits_forced(br, n) \ + (((uint16_t)((br)->cache_buffer << \ + ((n) - (br)->cache_avail))) & cache_masks[n]) +/* Read ahead to make sure the cache buffer has enough compressed data we + * will use. + * True : completed, there is enough data in the cache buffer. + * False : we met that strm->next_in is empty, we have to get following + * bytes. */ +#define lzh_br_read_ahead_0(strm, br, n) \ + (lzh_br_has(br, (n)) || lzh_br_fillup(strm, br)) +/* True : the cache buffer has some bits as much as we need. + * False : there are no enough bits in the cache buffer to be used, + * we have to get following bytes if we could. */ +#define lzh_br_read_ahead(strm, br, n) \ + (lzh_br_read_ahead_0((strm), (br), (n)) || lzh_br_has((br), (n))) + +/* Notify how many bits we consumed. */ +#define lzh_br_consume(br, n) ((br)->cache_avail -= (n)) +#define lzh_br_unconsume(br, n) ((br)->cache_avail += (n)) + +static const uint16_t cache_masks[] = { + 0x0000, 0x0001, 0x0003, 0x0007, + 0x000F, 0x001F, 0x003F, 0x007F, + 0x00FF, 0x01FF, 0x03FF, 0x07FF, + 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF +}; + +/* + * Shift away used bits in the cache data and fill it up with following bits. + * Call this when cache buffer does not have enough bits you need. + * + * Returns 1 if the cache buffer is full. + * Returns 0 if the cache buffer is not full; input buffer is empty. + */ +static int +lzh_br_fillup(struct lzh_stream *strm, struct lzh_br *br) +{ + int n = CACHE_BITS - br->cache_avail; + + for (;;) { + const int x = n >> 3; + if (strm->avail_in >= x) { + switch (x) { + case 8: + br->cache_buffer = + ((uint64_t)strm->next_in[0]) << 56 | + ((uint64_t)strm->next_in[1]) << 48 | + ((uint64_t)strm->next_in[2]) << 40 | + ((uint64_t)strm->next_in[3]) << 32 | + ((uint32_t)strm->next_in[4]) << 24 | + ((uint32_t)strm->next_in[5]) << 16 | + ((uint32_t)strm->next_in[6]) << 8 | + (uint32_t)strm->next_in[7]; + strm->next_in += 8; + strm->avail_in -= 8; + br->cache_avail += 8 * 8; + return (1); + case 7: + br->cache_buffer = + (br->cache_buffer << 56) | + ((uint64_t)strm->next_in[0]) << 48 | + ((uint64_t)strm->next_in[1]) << 40 | + ((uint64_t)strm->next_in[2]) << 32 | + ((uint32_t)strm->next_in[3]) << 24 | + ((uint32_t)strm->next_in[4]) << 16 | + ((uint32_t)strm->next_in[5]) << 8 | + (uint32_t)strm->next_in[6]; + strm->next_in += 7; + strm->avail_in -= 7; + br->cache_avail += 7 * 8; + return (1); + case 6: + br->cache_buffer = + (br->cache_buffer << 48) | + ((uint64_t)strm->next_in[0]) << 40 | + ((uint64_t)strm->next_in[1]) << 32 | + ((uint32_t)strm->next_in[2]) << 24 | + ((uint32_t)strm->next_in[3]) << 16 | + ((uint32_t)strm->next_in[4]) << 8 | + (uint32_t)strm->next_in[5]; + strm->next_in += 6; + strm->avail_in -= 6; + br->cache_avail += 6 * 8; + return (1); + case 0: + /* We have enough compressed data in + * the cache buffer.*/ + return (1); + default: + break; + } + } + if (strm->avail_in == 0) { + /* There is not enough compressed data to fill up the + * cache buffer. */ + return (0); + } + br->cache_buffer = + (br->cache_buffer << 8) | *strm->next_in++; + strm->avail_in--; + br->cache_avail += 8; + n -= 8; + } +} + +/* + * Decode LZHUF. + * + * 1. Returns ARCHIVE_OK if output buffer or input buffer are empty. + * Please set available buffer and call this function again. + * 2. Returns ARCHIVE_EOF if decompression has been completed. + * 3. Returns ARCHIVE_FAILED if an error occurred; compressed data + * is broken or you do not set 'last' flag properly. + * 4. 'last' flag is very important, you must set 1 to the flag if there + * is no input data. The lha compressed data format does not provide how + * to know the compressed data is really finished. + * Note: lha command utility check if the total size of output bytes is + * reached the uncompressed size recorded in its header. it does not mind + * that the decoding process is properly finished. + * GNU ZIP can decompress another compressed file made by SCO LZH compress. + * it handles EOF as null to fill read buffer with zero until the decoding + * process meet 2 bytes of zeros at reading a size of a next chunk, so the + * zeros are treated as the mark of the end of the data although the zeros + * is dummy, not the file data. + */ +static int lzh_read_blocks(struct lzh_stream *, int); +static int lzh_decode_blocks(struct lzh_stream *, int); +#define ST_RD_BLOCK 0 +#define ST_RD_PT_1 1 +#define ST_RD_PT_2 2 +#define ST_RD_PT_3 3 +#define ST_RD_PT_4 4 +#define ST_RD_LITERAL_1 5 +#define ST_RD_LITERAL_2 6 +#define ST_RD_LITERAL_3 7 +#define ST_RD_POS_DATA_1 8 +#define ST_GET_LITERAL 9 +#define ST_GET_POS_1 10 +#define ST_GET_POS_2 11 +#define ST_COPY_DATA 12 + +static int +lzh_decode(struct lzh_stream *strm, int last) +{ + struct lzh_dec *ds = strm->ds; + int avail_in; + int r; + + if (ds->error) + return (ds->error); + + avail_in = strm->avail_in; + do { + if (ds->state < ST_GET_LITERAL) + r = lzh_read_blocks(strm, last); + else + r = lzh_decode_blocks(strm, last); + } while (r == 100); + strm->total_in += avail_in - strm->avail_in; + return (r); +} + +static void +lzh_emit_window(struct lzh_stream *strm, size_t s) +{ + strm->ref_ptr = strm->ds->w_buff; + strm->avail_out = (int)s; + strm->total_out += s; +} + +static int +lzh_read_blocks(struct lzh_stream *strm, int last) +{ + struct lzh_dec *ds = strm->ds; + struct lzh_br *br = &(ds->br); + int c = 0, i; + unsigned rbits; + + for (;;) { + switch (ds->state) { + case ST_RD_BLOCK: + /* + * Read a block number indicates how many blocks + * we will handle. The block is composed of a + * literal and a match, sometimes a literal only + * in particular, there are no reference data at + * the beginning of the decompression. + */ + if (!lzh_br_read_ahead_0(strm, br, 16)) { + if (!last) + /* We need following data. */ + return (ARCHIVE_OK); + if (lzh_br_has(br, 8)) { + /* + * It seems there are extra bits. + * 1. Compressed data is broken. + * 2. `last' flag does not properly + * set. + */ + goto failed; + } + if (ds->w_pos > 0) { + lzh_emit_window(strm, ds->w_pos); + ds->w_pos = 0; + return (ARCHIVE_OK); + } + /* End of compressed data; we have completely + * handled all compressed data. */ + return (ARCHIVE_EOF); + } + ds->blocks_avail = lzh_br_bits(br, 16); + if (ds->blocks_avail == 0) + goto failed; + lzh_br_consume(br, 16); + /* + * Read a literal table compressed in huffman + * coding. + */ + ds->pt.len_size = ds->literal_pt_len_size; + ds->pt.len_bits = ds->literal_pt_len_bits; + ds->reading_position = 0; + /* FALL THROUGH */ + case ST_RD_PT_1: + /* Note: ST_RD_PT_1, ST_RD_PT_2 and ST_RD_PT_4 are + * used in reading both a literal table and a + * position table. */ + if (!lzh_br_read_ahead(strm, br, ds->pt.len_bits)) { + if (last) + goto failed;/* Truncated data. */ + ds->state = ST_RD_PT_1; + return (ARCHIVE_OK); + } + ds->pt.len_avail = lzh_br_bits(br, ds->pt.len_bits); + lzh_br_consume(br, ds->pt.len_bits); + /* FALL THROUGH */ + case ST_RD_PT_2: + if (ds->pt.len_avail == 0) { + /* There is no bitlen. */ + if (!lzh_br_read_ahead(strm, br, + ds->pt.len_bits)) { + if (last) + goto failed;/* Truncated data.*/ + ds->state = ST_RD_PT_2; + return (ARCHIVE_OK); + } + if (!lzh_make_fake_table(&(ds->pt), + lzh_br_bits(br, ds->pt.len_bits))) + goto failed;/* Invalid data. */ + lzh_br_consume(br, ds->pt.len_bits); + if (ds->reading_position) + ds->state = ST_GET_LITERAL; + else + ds->state = ST_RD_LITERAL_1; + break; + } else if (ds->pt.len_avail > ds->pt.len_size) + goto failed;/* Invalid data. */ + ds->loop = 0; + memset(ds->pt.freq, 0, sizeof(ds->pt.freq)); + if (ds->pt.len_avail < 3 || + ds->pt.len_size == ds->pos_pt_len_size) { + ds->state = ST_RD_PT_4; + break; + } + /* FALL THROUGH */ + case ST_RD_PT_3: + ds->loop = lzh_read_pt_bitlen(strm, ds->loop, 3); + if (ds->loop < 3) { + if (ds->loop < 0 || last) + goto failed;/* Invalid data. */ + /* Not completed, get following data. */ + ds->state = ST_RD_PT_3; + return (ARCHIVE_OK); + } + /* There are some null in bitlen of the literal. */ + if (!lzh_br_read_ahead(strm, br, 2)) { + if (last) + goto failed;/* Truncated data. */ + ds->state = ST_RD_PT_3; + return (ARCHIVE_OK); + } + c = lzh_br_bits(br, 2); + lzh_br_consume(br, 2); + if (c > ds->pt.len_avail - 3) + goto failed;/* Invalid data. */ + for (i = 3; c-- > 0 ;) + ds->pt.bitlen[i++] = 0; + ds->loop = i; + /* FALL THROUGH */ + case ST_RD_PT_4: + ds->loop = lzh_read_pt_bitlen(strm, ds->loop, + ds->pt.len_avail); + if (ds->loop < ds->pt.len_avail) { + if (ds->loop < 0 || last) + goto failed;/* Invalid data. */ + /* Not completed, get following data. */ + ds->state = ST_RD_PT_4; + return (ARCHIVE_OK); + } + if (!lzh_make_huffman_table(&(ds->pt))) + goto failed;/* Invalid data */ + if (ds->reading_position) { + ds->state = ST_GET_LITERAL; + break; + } + /* FALL THROUGH */ + case ST_RD_LITERAL_1: + if (!lzh_br_read_ahead(strm, br, ds->lt.len_bits)) { + if (last) + goto failed;/* Truncated data. */ + ds->state = ST_RD_LITERAL_1; + return (ARCHIVE_OK); + } + ds->lt.len_avail = lzh_br_bits(br, ds->lt.len_bits); + lzh_br_consume(br, ds->lt.len_bits); + /* FALL THROUGH */ + case ST_RD_LITERAL_2: + if (ds->lt.len_avail == 0) { + /* There is no bitlen. */ + if (!lzh_br_read_ahead(strm, br, + ds->lt.len_bits)) { + if (last) + goto failed;/* Truncated data.*/ + ds->state = ST_RD_LITERAL_2; + return (ARCHIVE_OK); + } + if (!lzh_make_fake_table(&(ds->lt), + lzh_br_bits(br, ds->lt.len_bits))) + goto failed;/* Invalid data */ + lzh_br_consume(br, ds->lt.len_bits); + ds->state = ST_RD_POS_DATA_1; + break; + } else if (ds->lt.len_avail > ds->lt.len_size) + goto failed;/* Invalid data */ + ds->loop = 0; + memset(ds->lt.freq, 0, sizeof(ds->lt.freq)); + /* FALL THROUGH */ + case ST_RD_LITERAL_3: + i = ds->loop; + while (i < ds->lt.len_avail) { + if (!lzh_br_read_ahead(strm, br, + ds->pt.max_bits)) { + if (last) + goto failed;/* Truncated data.*/ + ds->loop = i; + ds->state = ST_RD_LITERAL_3; + return (ARCHIVE_OK); + } + rbits = lzh_br_bits(br, ds->pt.max_bits); + c = lzh_decode_huffman(&(ds->pt), rbits); + if (c > 2) { + /* Note: 'c' will never be more than + * eighteen since it's limited by + * PT_BITLEN_SIZE, which is being set + * to ds->pt.len_size through + * ds->literal_pt_len_size. */ + lzh_br_consume(br, ds->pt.bitlen[c]); + c -= 2; + ds->lt.freq[c]++; + ds->lt.bitlen[i++] = c; + } else if (c == 0) { + lzh_br_consume(br, ds->pt.bitlen[c]); + ds->lt.bitlen[i++] = 0; + } else { + /* c == 1 or c == 2 */ + int n = (c == 1)?4:9; + if (!lzh_br_read_ahead(strm, br, + ds->pt.bitlen[c] + n)) { + if (last) /* Truncated data. */ + goto failed; + ds->loop = i; + ds->state = ST_RD_LITERAL_3; + return (ARCHIVE_OK); + } + lzh_br_consume(br, ds->pt.bitlen[c]); + c = lzh_br_bits(br, n); + lzh_br_consume(br, n); + c += (n == 4)?3:20; + if (i + c > ds->lt.len_avail) + goto failed;/* Invalid data */ + memset(&(ds->lt.bitlen[i]), 0, c); + i += c; + } + } + if (i > ds->lt.len_avail || + !lzh_make_huffman_table(&(ds->lt))) + goto failed;/* Invalid data */ + /* FALL THROUGH */ + case ST_RD_POS_DATA_1: + /* + * Read a position table compressed in huffman + * coding. + */ + ds->pt.len_size = ds->pos_pt_len_size; + ds->pt.len_bits = ds->pos_pt_len_bits; + ds->reading_position = 1; + ds->state = ST_RD_PT_1; + break; + case ST_GET_LITERAL: + return (100); + } + } +failed: + return (ds->error = ARCHIVE_FAILED); +} + +static int +lzh_decode_blocks(struct lzh_stream *strm, int last) +{ + struct lzh_dec *ds = strm->ds; + struct lzh_br bre = ds->br; + struct huffman *lt = &(ds->lt); + struct huffman *pt = &(ds->pt); + unsigned char *w_buff = ds->w_buff; + unsigned char *lt_bitlen = lt->bitlen; + unsigned char *pt_bitlen = pt->bitlen; + int blocks_avail = ds->blocks_avail, c = 0; + int copy_len = ds->copy_len, copy_pos = ds->copy_pos; + int w_pos = ds->w_pos, w_mask = ds->w_mask, w_size = ds->w_size; + int lt_max_bits = lt->max_bits, pt_max_bits = pt->max_bits; + int state = ds->state; + + for (;;) { + switch (state) { + case ST_GET_LITERAL: + for (;;) { + if (blocks_avail == 0) { + /* We have decoded all blocks. + * Let's handle next blocks. */ + ds->state = ST_RD_BLOCK; + ds->br = bre; + ds->blocks_avail = 0; + ds->w_pos = w_pos; + ds->copy_pos = 0; + return (100); + } + + /* lzh_br_read_ahead() always try to fill the + * cache buffer up. In specific situation we + * are close to the end of the data, the cache + * buffer will not be full and thus we have to + * determine if the cache buffer has some bits + * as much as we need after lzh_br_read_ahead() + * failed. */ + if (!lzh_br_read_ahead(strm, &bre, + lt_max_bits)) { + if (!last) + goto next_data; + /* Remaining bits are less than + * maximum bits(lt.max_bits) but maybe + * it still remains as much as we need, + * so we should try to use it with + * dummy bits. */ + c = lzh_decode_huffman(lt, + lzh_br_bits_forced(&bre, + lt_max_bits)); + lzh_br_consume(&bre, lt_bitlen[c]); + if (!lzh_br_has(&bre, 0)) + goto failed;/* Over read. */ + } else { + c = lzh_decode_huffman(lt, + lzh_br_bits(&bre, lt_max_bits)); + lzh_br_consume(&bre, lt_bitlen[c]); + } + blocks_avail--; + if (c > UCHAR_MAX) + /* Current block is a match data. */ + break; + /* + * 'c' is exactly a literal code. + */ + /* Save a decoded code to reference it + * afterward. */ + w_buff[w_pos] = c; + if (++w_pos >= w_size) { + w_pos = 0; + lzh_emit_window(strm, w_size); + goto next_data; + } + } + /* 'c' is the length of a match pattern we have + * already extracted, which has be stored in + * window(ds->w_buff). */ + copy_len = c - (UCHAR_MAX + 1) + MINMATCH; + /* FALL THROUGH */ + case ST_GET_POS_1: + /* + * Get a reference position. + */ + if (!lzh_br_read_ahead(strm, &bre, pt_max_bits)) { + if (!last) { + state = ST_GET_POS_1; + ds->copy_len = copy_len; + goto next_data; + } + copy_pos = lzh_decode_huffman(pt, + lzh_br_bits_forced(&bre, pt_max_bits)); + lzh_br_consume(&bre, pt_bitlen[copy_pos]); + if (!lzh_br_has(&bre, 0)) + goto failed;/* Over read. */ + } else { + copy_pos = lzh_decode_huffman(pt, + lzh_br_bits(&bre, pt_max_bits)); + lzh_br_consume(&bre, pt_bitlen[copy_pos]); + } + /* FALL THROUGH */ + case ST_GET_POS_2: + if (copy_pos > 1) { + /* We need an additional adjustment number to + * the position. */ + int p = copy_pos - 1; + if (!lzh_br_read_ahead(strm, &bre, p)) { + if (last) + goto failed;/* Truncated data.*/ + state = ST_GET_POS_2; + ds->copy_len = copy_len; + ds->copy_pos = copy_pos; + goto next_data; + } + copy_pos = (1 << p) + lzh_br_bits(&bre, p); + lzh_br_consume(&bre, p); + } + /* The position is actually a distance from the last + * code we had extracted and thus we have to convert + * it to a position of the window. */ + copy_pos = (w_pos - copy_pos - 1) & w_mask; + /* FALL THROUGH */ + case ST_COPY_DATA: + /* + * Copy `copy_len' bytes as extracted data from + * the window into the output buffer. + */ + for (;;) { + int l; + + l = copy_len; + if (copy_pos > w_pos) { + if (l > w_size - copy_pos) + l = w_size - copy_pos; + } else { + if (l > w_size - w_pos) + l = w_size - w_pos; + } + if ((copy_pos + l < w_pos) + || (w_pos + l < copy_pos)) { + /* No overlap. */ + memcpy(w_buff + w_pos, + w_buff + copy_pos, l); + } else { + const unsigned char *s; + unsigned char *d; + int li; + + d = w_buff + w_pos; + s = w_buff + copy_pos; + for (li = 0; li < l-1;) { + d[li] = s[li];li++; + d[li] = s[li];li++; + } + if (li < l) + d[li] = s[li]; + } + w_pos += l; + if (w_pos == w_size) { + w_pos = 0; + lzh_emit_window(strm, w_size); + if (copy_len <= l) + state = ST_GET_LITERAL; + else { + state = ST_COPY_DATA; + ds->copy_len = copy_len - l; + ds->copy_pos = + (copy_pos + l) & w_mask; + } + goto next_data; + } + if (copy_len <= l) + /* A copy of current pattern ended. */ + break; + copy_len -= l; + copy_pos = (copy_pos + l) & w_mask; + } + state = ST_GET_LITERAL; + break; + } + } +failed: + return (ds->error = ARCHIVE_FAILED); +next_data: + ds->br = bre; + ds->blocks_avail = blocks_avail; + ds->state = state; + ds->w_pos = w_pos; + return (ARCHIVE_OK); +} + +static int +lzh_huffman_init(struct huffman *hf, size_t len_size, int tbl_bits) +{ + int bits; + + if (hf->bitlen == NULL) { + hf->bitlen = malloc(len_size * sizeof(hf->bitlen[0])); + if (hf->bitlen == NULL) + return (ARCHIVE_FATAL); + } + if (hf->tbl == NULL) { + if (tbl_bits < HTBL_BITS) + bits = tbl_bits; + else + bits = HTBL_BITS; + hf->tbl = malloc(((size_t)1 << bits) * sizeof(hf->tbl[0])); + if (hf->tbl == NULL) + return (ARCHIVE_FATAL); + } + if (hf->tree == NULL && tbl_bits > HTBL_BITS) { + hf->tree_avail = 1 << (tbl_bits - HTBL_BITS + 4); + hf->tree = malloc(hf->tree_avail * sizeof(hf->tree[0])); + if (hf->tree == NULL) + return (ARCHIVE_FATAL); + } + hf->len_size = (int)len_size; + hf->tbl_bits = tbl_bits; + return (ARCHIVE_OK); +} + +static void +lzh_huffman_free(struct huffman *hf) +{ + free(hf->bitlen); + free(hf->tbl); + free(hf->tree); +} + +static const char bitlen_tbl[0x400] = { + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, + 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, + 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, + 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, + 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, + 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, + 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, + 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 16, 0 +}; +static int +lzh_read_pt_bitlen(struct lzh_stream *strm, int start, int end) +{ + struct lzh_dec *ds = strm->ds; + struct lzh_br *br = &(ds->br); + int c, i; + + for (i = start; i < end; ) { + /* + * bit pattern the number we need + * 000 -> 0 + * 001 -> 1 + * 010 -> 2 + * ... + * 110 -> 6 + * 1110 -> 7 + * 11110 -> 8 + * ... + * 1111111111110 -> 16 + */ + if (!lzh_br_read_ahead(strm, br, 3)) + return (i); + if ((c = lzh_br_bits(br, 3)) == 7) { + if (!lzh_br_read_ahead(strm, br, 13)) + return (i); + c = bitlen_tbl[lzh_br_bits(br, 13) & 0x3FF]; + if (c) + lzh_br_consume(br, c - 3); + else + return (-1);/* Invalid data. */ + } else + lzh_br_consume(br, 3); + ds->pt.bitlen[i++] = c; + ds->pt.freq[c]++; + } + return (i); +} + +static int +lzh_make_fake_table(struct huffman *hf, uint16_t c) +{ + if (c >= hf->len_size) + return (0); + hf->tbl[0] = c; + hf->max_bits = 0; + hf->shift_bits = 0; + hf->bitlen[hf->tbl[0]] = 0; + return (1); +} + +/* + * Make a huffman coding table. + */ +static int +lzh_make_huffman_table(struct huffman *hf) +{ + uint16_t *tbl; + const unsigned char *bitlen; + int bitptn[17], weight[17]; + int i, maxbits = 0, ptn, tbl_size, w; + int diffbits, len_avail; + + /* + * Initialize bit patterns. + */ + ptn = 0; + for (i = 1, w = 1 << 15; i <= 16; i++, w >>= 1) { + bitptn[i] = ptn; + weight[i] = w; + if (hf->freq[i]) { + ptn += hf->freq[i] * w; + maxbits = i; + } + } + if (ptn != 0x10000 || maxbits > hf->tbl_bits) + return (0);/* Invalid */ + + hf->max_bits = maxbits; + + /* + * Cut out extra bits which we won't house in the table. + * This preparation reduces the same calculation in the for-loop + * making the table. + */ + if (maxbits < 16) { + int ebits = 16 - maxbits; + for (i = 1; i <= maxbits; i++) { + bitptn[i] >>= ebits; + weight[i] >>= ebits; + } + } + if (maxbits > HTBL_BITS) { + unsigned htbl_max; + uint16_t *p; + + diffbits = maxbits - HTBL_BITS; + for (i = 1; i <= HTBL_BITS; i++) { + bitptn[i] >>= diffbits; + weight[i] >>= diffbits; + } + htbl_max = bitptn[HTBL_BITS] + + weight[HTBL_BITS] * hf->freq[HTBL_BITS]; + p = &(hf->tbl[htbl_max]); + while (p < &hf->tbl[1U<shift_bits = diffbits; + + /* + * Make the table. + */ + tbl_size = 1 << HTBL_BITS; + tbl = hf->tbl; + bitlen = hf->bitlen; + len_avail = hf->len_avail; + hf->tree_used = 0; + for (i = 0; i < len_avail; i++) { + uint16_t *p; + int len, cnt; + uint16_t bit; + int extlen; + struct htree_t *ht; + + if (bitlen[i] == 0) + continue; + /* Get a bit pattern */ + len = bitlen[i]; + ptn = bitptn[len]; + cnt = weight[len]; + if (len <= HTBL_BITS) { + /* Calculate next bit pattern */ + if ((bitptn[len] = ptn + cnt) > tbl_size) + return (0);/* Invalid */ + /* Update the table */ + p = &(tbl[ptn]); + if (cnt > 7) { + uint16_t *pc; + + cnt -= 8; + pc = &p[cnt]; + pc[0] = (uint16_t)i; + pc[1] = (uint16_t)i; + pc[2] = (uint16_t)i; + pc[3] = (uint16_t)i; + pc[4] = (uint16_t)i; + pc[5] = (uint16_t)i; + pc[6] = (uint16_t)i; + pc[7] = (uint16_t)i; + if (cnt > 7) { + cnt -= 8; + memcpy(&p[cnt], pc, + 8 * sizeof(uint16_t)); + pc = &p[cnt]; + while (cnt > 15) { + cnt -= 16; + memcpy(&p[cnt], pc, + 16 * sizeof(uint16_t)); + } + } + if (cnt) + memcpy(p, pc, cnt * sizeof(uint16_t)); + } else { + while (cnt > 1) { + p[--cnt] = (uint16_t)i; + p[--cnt] = (uint16_t)i; + } + if (cnt) + p[--cnt] = (uint16_t)i; + } + continue; + } + + /* + * A bit length is too big to be housed to a direct table, + * so we use a tree model for its extra bits. + */ + bitptn[len] = ptn + cnt; + bit = 1U << (diffbits -1); + extlen = len - HTBL_BITS; + + p = &(tbl[ptn >> diffbits]); + if (*p == 0) { + *p = len_avail + hf->tree_used; + ht = &(hf->tree[hf->tree_used++]); + if (hf->tree_used > hf->tree_avail) + return (0);/* Invalid */ + ht->left = 0; + ht->right = 0; + } else { + if (*p < len_avail || + *p >= (len_avail + hf->tree_used)) + return (0);/* Invalid */ + ht = &(hf->tree[*p - len_avail]); + } + while (--extlen > 0) { + if (ptn & bit) { + if (ht->left < len_avail) { + ht->left = len_avail + hf->tree_used; + ht = &(hf->tree[hf->tree_used++]); + if (hf->tree_used > hf->tree_avail) + return (0);/* Invalid */ + ht->left = 0; + ht->right = 0; + } else { + ht = &(hf->tree[ht->left - len_avail]); + } + } else { + if (ht->right < len_avail) { + ht->right = len_avail + hf->tree_used; + ht = &(hf->tree[hf->tree_used++]); + if (hf->tree_used > hf->tree_avail) + return (0);/* Invalid */ + ht->left = 0; + ht->right = 0; + } else { + ht = &(hf->tree[ht->right - len_avail]); + } + } + bit >>= 1; + } + if (ptn & bit) { + if (ht->left != 0) + return (0);/* Invalid */ + ht->left = (uint16_t)i; + } else { + if (ht->right != 0) + return (0);/* Invalid */ + ht->right = (uint16_t)i; + } + } + return (1); +} + +static int +lzh_decode_huffman_tree(struct huffman *hf, unsigned rbits, int c) +{ + struct htree_t *ht; + int extlen; + + ht = hf->tree; + extlen = hf->shift_bits; + while (c >= hf->len_avail) { + c -= hf->len_avail; + if (extlen-- <= 0 || c >= hf->tree_used) + return (0); + if (rbits & (1U << extlen)) + c = ht[c].left; + else + c = ht[c].right; + } + return (c); +} + +static inline int +lzh_decode_huffman(struct huffman *hf, unsigned rbits) +{ + int c; + /* + * At first search an index table for a bit pattern. + * If it fails, search a huffman tree for. + */ + c = hf->tbl[rbits >> hf->shift_bits]; + if (c < hf->len_avail || hf->len_avail == 0) + return (c); + /* This bit pattern needs to be found out at a huffman tree. */ + return (lzh_decode_huffman_tree(hf, rbits, c)); +} + diff --cc Utilities/cmlibarchive/libarchive/archive_read_support_format_rar.c index a0e641e,0000000..c68d77b mode 100644,000000..100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_rar.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_rar.c @@@ -1,2953 -1,0 +1,2943 @@@ +/*- +* Copyright (c) 2003-2007 Tim Kientzle +* Copyright (c) 2011 Andres Mejia +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR +* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "archive_platform.h" + +#ifdef HAVE_ERRNO_H +#include +#endif +#include +#include +#ifdef HAVE_ZLIB_H +#include /* crc32 */ +#endif + +#include "archive.h" +#ifndef HAVE_ZLIB_H +#include "archive_crc32.h" +#endif +#include "archive_endian.h" +#include "archive_entry.h" +#include "archive_entry_locale.h" +#include "archive_ppmd7_private.h" +#include "archive_private.h" +#include "archive_read_private.h" + +/* RAR signature, also known as the mark header */ +#define RAR_SIGNATURE "\x52\x61\x72\x21\x1A\x07\x00" + +/* Header types */ +#define MARK_HEAD 0x72 +#define MAIN_HEAD 0x73 +#define FILE_HEAD 0x74 +#define COMM_HEAD 0x75 +#define AV_HEAD 0x76 +#define SUB_HEAD 0x77 +#define PROTECT_HEAD 0x78 +#define SIGN_HEAD 0x79 +#define NEWSUB_HEAD 0x7a +#define ENDARC_HEAD 0x7b + +/* Main Header Flags */ +#define MHD_VOLUME 0x0001 +#define MHD_COMMENT 0x0002 +#define MHD_LOCK 0x0004 +#define MHD_SOLID 0x0008 +#define MHD_NEWNUMBERING 0x0010 +#define MHD_AV 0x0020 +#define MHD_PROTECT 0x0040 +#define MHD_PASSWORD 0x0080 +#define MHD_FIRSTVOLUME 0x0100 +#define MHD_ENCRYPTVER 0x0200 + +/* Flags common to all headers */ +#define HD_MARKDELETION 0x4000 +#define HD_ADD_SIZE_PRESENT 0x8000 + +/* File Header Flags */ +#define FHD_SPLIT_BEFORE 0x0001 +#define FHD_SPLIT_AFTER 0x0002 +#define FHD_PASSWORD 0x0004 +#define FHD_COMMENT 0x0008 +#define FHD_SOLID 0x0010 +#define FHD_LARGE 0x0100 +#define FHD_UNICODE 0x0200 +#define FHD_SALT 0x0400 +#define FHD_VERSION 0x0800 +#define FHD_EXTTIME 0x1000 +#define FHD_EXTFLAGS 0x2000 + +/* File dictionary sizes */ +#define DICTIONARY_SIZE_64 0x00 +#define DICTIONARY_SIZE_128 0x20 +#define DICTIONARY_SIZE_256 0x40 +#define DICTIONARY_SIZE_512 0x60 +#define DICTIONARY_SIZE_1024 0x80 +#define DICTIONARY_SIZE_2048 0xA0 +#define DICTIONARY_SIZE_4096 0xC0 +#define FILE_IS_DIRECTORY 0xE0 +#define DICTIONARY_MASK FILE_IS_DIRECTORY + +/* OS Flags */ +#define OS_MSDOS 0 +#define OS_OS2 1 +#define OS_WIN32 2 +#define OS_UNIX 3 +#define OS_MAC_OS 4 +#define OS_BEOS 5 + +/* Compression Methods */ +#define COMPRESS_METHOD_STORE 0x30 +/* LZSS */ +#define COMPRESS_METHOD_FASTEST 0x31 +#define COMPRESS_METHOD_FAST 0x32 +#define COMPRESS_METHOD_NORMAL 0x33 +/* PPMd Variant H */ +#define COMPRESS_METHOD_GOOD 0x34 +#define COMPRESS_METHOD_BEST 0x35 + +#define CRC_POLYNOMIAL 0xEDB88320 + +#define NS_UNIT 10000000 + +#define DICTIONARY_MAX_SIZE 0x400000 + +#define MAINCODE_SIZE 299 +#define OFFSETCODE_SIZE 60 +#define LOWOFFSETCODE_SIZE 17 +#define LENGTHCODE_SIZE 28 +#define HUFFMAN_TABLE_SIZE \ + MAINCODE_SIZE + OFFSETCODE_SIZE + LOWOFFSETCODE_SIZE + LENGTHCODE_SIZE + +#define MAX_SYMBOL_LENGTH 0xF +#define MAX_SYMBOLS 20 + +/* + * Considering L1,L2 cache miss and a calling of write system-call, + * the best size of the output buffer(uncompressed buffer) is 128K. + * If the structure of extracting process is changed, this value + * might be researched again. + */ +#define UNP_BUFFER_SIZE (128 * 1024) + +/* Define this here for non-Windows platforms */ +#if !((defined(__WIN32__) || defined(_WIN32) || defined(__WIN32)) && !defined(__CYGWIN__)) +#define FILE_ATTRIBUTE_DIRECTORY 0x10 +#endif + +/* Fields common to all headers */ +struct rar_header +{ + char crc[2]; + char type; + char flags[2]; + char size[2]; +}; + +/* Fields common to all file headers */ +struct rar_file_header +{ + char pack_size[4]; + char unp_size[4]; + char host_os; + char file_crc[4]; + char file_time[4]; + char unp_ver; + char method; + char name_size[2]; + char file_attr[4]; +}; + +struct huffman_tree_node +{ + int branches[2]; +}; + +struct huffman_table_entry +{ + unsigned int length; + int value; +}; + +struct huffman_code +{ + struct huffman_tree_node *tree; + int numentries; + int numallocatedentries; + int minlength; + int maxlength; + int tablesize; + struct huffman_table_entry *table; +}; + +struct lzss +{ + unsigned char *window; + int mask; + int64_t position; +}; + +struct data_block_offsets +{ + int64_t header_size; + int64_t start_offset; + int64_t end_offset; +}; + +struct rar +{ + /* Entries from main RAR header */ + unsigned main_flags; + unsigned long file_crc; + char reserved1[2]; + char reserved2[4]; + char encryptver; + + /* File header entries */ + char compression_method; + unsigned file_flags; + int64_t packed_size; + int64_t unp_size; + time_t mtime; + long mnsec; + mode_t mode; + char *filename; + char *filename_save; + size_t filename_save_size; + size_t filename_allocated; + + /* File header optional entries */ + char salt[8]; + time_t atime; + long ansec; + time_t ctime; + long cnsec; + time_t arctime; + long arcnsec; + + /* Fields to help with tracking decompression of files. */ + int64_t bytes_unconsumed; + int64_t bytes_remaining; + int64_t bytes_uncopied; + int64_t offset; + int64_t offset_outgoing; + int64_t offset_seek; + char valid; + unsigned int unp_offset; + unsigned int unp_buffer_size; + unsigned char *unp_buffer; + unsigned int dictionary_size; + char start_new_block; + char entry_eof; + unsigned long crc_calculated; + int found_first_header; + char has_endarc_header; + struct data_block_offsets *dbo; + unsigned int cursor; + unsigned int nodes; + + /* LZSS members */ + struct huffman_code maincode; + struct huffman_code offsetcode; + struct huffman_code lowoffsetcode; + struct huffman_code lengthcode; + unsigned char lengthtable[HUFFMAN_TABLE_SIZE]; + struct lzss lzss; + char output_last_match; + unsigned int lastlength; + unsigned int lastoffset; + unsigned int oldoffset[4]; + unsigned int lastlowoffset; + unsigned int numlowoffsetrepeats; + int64_t filterstart; + char start_new_table; + + /* PPMd Variant H members */ + char ppmd_valid; + char ppmd_eod; + char is_ppmd_block; + int ppmd_escape; + CPpmd7 ppmd7_context; + CPpmd7z_RangeDec range_dec; + IByteIn bytein; + + /* + * String conversion object. + */ + int init_default_conversion; + struct archive_string_conv *sconv_default; + struct archive_string_conv *opt_sconv; + struct archive_string_conv *sconv_utf8; + struct archive_string_conv *sconv_utf16be; + + /* + * Bit stream reader. + */ + struct rar_br { +#define CACHE_TYPE uint64_t +#define CACHE_BITS (8 * sizeof(CACHE_TYPE)) + /* Cache buffer. */ + CACHE_TYPE cache_buffer; + /* Indicates how many bits avail in cache_buffer. */ + int cache_avail; + ssize_t avail_in; + const unsigned char *next_in; + } br; + + /* + * Custom field to denote that this archive contains encrypted entries + */ + int has_encrypted_entries; +}; + +static int archive_read_support_format_rar_capabilities(struct archive_read *); +static int archive_read_format_rar_has_encrypted_entries(struct archive_read *); +static int archive_read_format_rar_bid(struct archive_read *, int); +static int archive_read_format_rar_options(struct archive_read *, + const char *, const char *); +static int archive_read_format_rar_read_header(struct archive_read *, + struct archive_entry *); +static int archive_read_format_rar_read_data(struct archive_read *, + const void **, size_t *, int64_t *); +static int archive_read_format_rar_read_data_skip(struct archive_read *a); +static int64_t archive_read_format_rar_seek_data(struct archive_read *, int64_t, + int); +static int archive_read_format_rar_cleanup(struct archive_read *); + +/* Support functions */ +static int read_header(struct archive_read *, struct archive_entry *, char); +static time_t get_time(int); +static int read_exttime(const char *, struct rar *, const char *); +static int read_symlink_stored(struct archive_read *, struct archive_entry *, + struct archive_string_conv *); +static int read_data_stored(struct archive_read *, const void **, size_t *, + int64_t *); +static int read_data_compressed(struct archive_read *, const void **, size_t *, + int64_t *); +static int rar_br_preparation(struct archive_read *, struct rar_br *); +static int parse_codes(struct archive_read *); +static void free_codes(struct archive_read *); +static int read_next_symbol(struct archive_read *, struct huffman_code *); +static int create_code(struct archive_read *, struct huffman_code *, + unsigned char *, int, char); +static int add_value(struct archive_read *, struct huffman_code *, int, int, + int); +static int new_node(struct huffman_code *); +static int make_table(struct archive_read *, struct huffman_code *); +static int make_table_recurse(struct archive_read *, struct huffman_code *, int, + struct huffman_table_entry *, int, int); +static int64_t expand(struct archive_read *, int64_t); +static int copy_from_lzss_window(struct archive_read *, const void **, + int64_t, int); +static const void *rar_read_ahead(struct archive_read *, size_t, ssize_t *); + +/* + * Bit stream reader. + */ +/* Check that the cache buffer has enough bits. */ +#define rar_br_has(br, n) ((br)->cache_avail >= n) +/* Get compressed data by bit. */ +#define rar_br_bits(br, n) \ + (((uint32_t)((br)->cache_buffer >> \ + ((br)->cache_avail - (n)))) & cache_masks[n]) +#define rar_br_bits_forced(br, n) \ + (((uint32_t)((br)->cache_buffer << \ + ((n) - (br)->cache_avail))) & cache_masks[n]) +/* Read ahead to make sure the cache buffer has enough compressed data we + * will use. + * True : completed, there is enough data in the cache buffer. + * False : there is no data in the stream. */ +#define rar_br_read_ahead(a, br, n) \ + ((rar_br_has(br, (n)) || rar_br_fillup(a, br)) || rar_br_has(br, (n))) +/* Notify how many bits we consumed. */ +#define rar_br_consume(br, n) ((br)->cache_avail -= (n)) +#define rar_br_consume_unalined_bits(br) ((br)->cache_avail &= ~7) + +static const uint32_t cache_masks[] = { + 0x00000000, 0x00000001, 0x00000003, 0x00000007, + 0x0000000F, 0x0000001F, 0x0000003F, 0x0000007F, + 0x000000FF, 0x000001FF, 0x000003FF, 0x000007FF, + 0x00000FFF, 0x00001FFF, 0x00003FFF, 0x00007FFF, + 0x0000FFFF, 0x0001FFFF, 0x0003FFFF, 0x0007FFFF, + 0x000FFFFF, 0x001FFFFF, 0x003FFFFF, 0x007FFFFF, + 0x00FFFFFF, 0x01FFFFFF, 0x03FFFFFF, 0x07FFFFFF, + 0x0FFFFFFF, 0x1FFFFFFF, 0x3FFFFFFF, 0x7FFFFFFF, + 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF +}; + +/* + * Shift away used bits in the cache data and fill it up with following bits. + * Call this when cache buffer does not have enough bits you need. + * + * Returns 1 if the cache buffer is full. + * Returns 0 if the cache buffer is not full; input buffer is empty. + */ +static int +rar_br_fillup(struct archive_read *a, struct rar_br *br) +{ + struct rar *rar = (struct rar *)(a->format->data); + int n = CACHE_BITS - br->cache_avail; + + for (;;) { + switch (n >> 3) { + case 8: + if (br->avail_in >= 8) { + br->cache_buffer = + ((uint64_t)br->next_in[0]) << 56 | + ((uint64_t)br->next_in[1]) << 48 | + ((uint64_t)br->next_in[2]) << 40 | + ((uint64_t)br->next_in[3]) << 32 | + ((uint32_t)br->next_in[4]) << 24 | + ((uint32_t)br->next_in[5]) << 16 | + ((uint32_t)br->next_in[6]) << 8 | + (uint32_t)br->next_in[7]; + br->next_in += 8; + br->avail_in -= 8; + br->cache_avail += 8 * 8; + rar->bytes_unconsumed += 8; + rar->bytes_remaining -= 8; + return (1); + } + break; + case 7: + if (br->avail_in >= 7) { + br->cache_buffer = + (br->cache_buffer << 56) | + ((uint64_t)br->next_in[0]) << 48 | + ((uint64_t)br->next_in[1]) << 40 | + ((uint64_t)br->next_in[2]) << 32 | + ((uint32_t)br->next_in[3]) << 24 | + ((uint32_t)br->next_in[4]) << 16 | + ((uint32_t)br->next_in[5]) << 8 | + (uint32_t)br->next_in[6]; + br->next_in += 7; + br->avail_in -= 7; + br->cache_avail += 7 * 8; + rar->bytes_unconsumed += 7; + rar->bytes_remaining -= 7; + return (1); + } + break; + case 6: + if (br->avail_in >= 6) { + br->cache_buffer = + (br->cache_buffer << 48) | + ((uint64_t)br->next_in[0]) << 40 | + ((uint64_t)br->next_in[1]) << 32 | + ((uint32_t)br->next_in[2]) << 24 | + ((uint32_t)br->next_in[3]) << 16 | + ((uint32_t)br->next_in[4]) << 8 | + (uint32_t)br->next_in[5]; + br->next_in += 6; + br->avail_in -= 6; + br->cache_avail += 6 * 8; + rar->bytes_unconsumed += 6; + rar->bytes_remaining -= 6; + return (1); + } + break; + case 0: + /* We have enough compressed data in + * the cache buffer.*/ + return (1); + default: + break; + } + if (br->avail_in <= 0) { + + if (rar->bytes_unconsumed > 0) { + /* Consume as much as the decompressor + * actually used. */ + __archive_read_consume(a, rar->bytes_unconsumed); + rar->bytes_unconsumed = 0; + } + br->next_in = rar_read_ahead(a, 1, &(br->avail_in)); + if (br->next_in == NULL) + return (0); + if (br->avail_in == 0) + return (0); + } + br->cache_buffer = + (br->cache_buffer << 8) | *br->next_in++; + br->avail_in--; + br->cache_avail += 8; + n -= 8; + rar->bytes_unconsumed++; + rar->bytes_remaining--; + } +} + +static int +rar_br_preparation(struct archive_read *a, struct rar_br *br) +{ + struct rar *rar = (struct rar *)(a->format->data); + + if (rar->bytes_remaining > 0) { + br->next_in = rar_read_ahead(a, 1, &(br->avail_in)); + if (br->next_in == NULL) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated RAR file data"); + return (ARCHIVE_FATAL); + } + if (br->cache_avail == 0) + (void)rar_br_fillup(a, br); + } + return (ARCHIVE_OK); +} + +/* Find last bit set */ +static inline int +rar_fls(unsigned int word) +{ + word |= (word >> 1); + word |= (word >> 2); + word |= (word >> 4); + word |= (word >> 8); + word |= (word >> 16); + return word - (word >> 1); +} + +/* LZSS functions */ +static inline int64_t +lzss_position(struct lzss *lzss) +{ + return lzss->position; +} + +static inline int +lzss_mask(struct lzss *lzss) +{ + return lzss->mask; +} + +static inline int +lzss_size(struct lzss *lzss) +{ + return lzss->mask + 1; +} + +static inline int +lzss_offset_for_position(struct lzss *lzss, int64_t pos) +{ + return (int)(pos & lzss->mask); +} + +static inline unsigned char * +lzss_pointer_for_position(struct lzss *lzss, int64_t pos) +{ + return &lzss->window[lzss_offset_for_position(lzss, pos)]; +} + +static inline int +lzss_current_offset(struct lzss *lzss) +{ + return lzss_offset_for_position(lzss, lzss->position); +} + +static inline uint8_t * +lzss_current_pointer(struct lzss *lzss) +{ + return lzss_pointer_for_position(lzss, lzss->position); +} + +static inline void +lzss_emit_literal(struct rar *rar, uint8_t literal) +{ + *lzss_current_pointer(&rar->lzss) = literal; + rar->lzss.position++; +} + +static inline void +lzss_emit_match(struct rar *rar, int offset, int length) +{ + int dstoffs = lzss_current_offset(&rar->lzss); + int srcoffs = (dstoffs - offset) & lzss_mask(&rar->lzss); + int l, li, remaining; + unsigned char *d, *s; + + remaining = length; + while (remaining > 0) { + l = remaining; + if (dstoffs > srcoffs) { + if (l > lzss_size(&rar->lzss) - dstoffs) + l = lzss_size(&rar->lzss) - dstoffs; + } else { + if (l > lzss_size(&rar->lzss) - srcoffs) + l = lzss_size(&rar->lzss) - srcoffs; + } + d = &(rar->lzss.window[dstoffs]); + s = &(rar->lzss.window[srcoffs]); + if ((dstoffs + l < srcoffs) || (srcoffs + l < dstoffs)) + memcpy(d, s, l); + else { + for (li = 0; li < l; li++) + d[li] = s[li]; + } + remaining -= l; + dstoffs = (dstoffs + l) & lzss_mask(&(rar->lzss)); + srcoffs = (srcoffs + l) & lzss_mask(&(rar->lzss)); + } + rar->lzss.position += length; +} + - static void * - ppmd_alloc(void *p, size_t size) - { - (void)p; - return malloc(size); - } - static void - ppmd_free(void *p, void *address) - { - (void)p; - free(address); - } - static ISzAlloc g_szalloc = { ppmd_alloc, ppmd_free }; - +static Byte +ppmd_read(void *p) +{ + struct archive_read *a = ((IByteIn*)p)->a; + struct rar *rar = (struct rar *)(a->format->data); + struct rar_br *br = &(rar->br); + Byte b; + if (!rar_br_read_ahead(a, br, 8)) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated RAR file data"); + rar->valid = 0; + return 0; + } + b = rar_br_bits(br, 8); + rar_br_consume(br, 8); + return b; +} + +int +archive_read_support_format_rar(struct archive *_a) +{ + struct archive_read *a = (struct archive_read *)_a; + struct rar *rar; + int r; + + archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, + "archive_read_support_format_rar"); + + rar = (struct rar *)calloc(sizeof(*rar), 1); + if (rar == NULL) + { + archive_set_error(&a->archive, ENOMEM, "Can't allocate rar data"); + return (ARCHIVE_FATAL); + } + + /* + * Until enough data has been read, we cannot tell about + * any encrypted entries yet. + */ + rar->has_encrypted_entries = ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW; + + r = __archive_read_register_format(a, + rar, + "rar", + archive_read_format_rar_bid, + archive_read_format_rar_options, + archive_read_format_rar_read_header, + archive_read_format_rar_read_data, + archive_read_format_rar_read_data_skip, + archive_read_format_rar_seek_data, + archive_read_format_rar_cleanup, + archive_read_support_format_rar_capabilities, + archive_read_format_rar_has_encrypted_entries); + + if (r != ARCHIVE_OK) + free(rar); + return (r); +} + +static int +archive_read_support_format_rar_capabilities(struct archive_read * a) +{ + (void)a; /* UNUSED */ + return (ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_DATA + | ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_METADATA); +} + +static int +archive_read_format_rar_has_encrypted_entries(struct archive_read *_a) +{ + if (_a && _a->format) { + struct rar * rar = (struct rar *)_a->format->data; + if (rar) { + return rar->has_encrypted_entries; + } + } + return ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW; +} + + +static int +archive_read_format_rar_bid(struct archive_read *a, int best_bid) +{ + const char *p; + + /* If there's already a bid > 30, we'll never win. */ + if (best_bid > 30) + return (-1); + + if ((p = __archive_read_ahead(a, 7, NULL)) == NULL) + return (-1); + + if (memcmp(p, RAR_SIGNATURE, 7) == 0) + return (30); + + if ((p[0] == 'M' && p[1] == 'Z') || memcmp(p, "\x7F\x45LF", 4) == 0) { + /* This is a PE file */ + ssize_t offset = 0x10000; + ssize_t window = 4096; + ssize_t bytes_avail; + while (offset + window <= (1024 * 128)) { + const char *buff = __archive_read_ahead(a, offset + window, &bytes_avail); + if (buff == NULL) { + /* Remaining bytes are less than window. */ + window >>= 1; + if (window < 0x40) + return (0); + continue; + } + p = buff + offset; + while (p + 7 < buff + bytes_avail) { + if (memcmp(p, RAR_SIGNATURE, 7) == 0) + return (30); + p += 0x10; + } + offset = p - buff; + } + } + return (0); +} + +static int +skip_sfx(struct archive_read *a) +{ + const void *h; + const char *p, *q; + size_t skip, total; + ssize_t bytes, window; + + total = 0; + window = 4096; + while (total + window <= (1024 * 128)) { + h = __archive_read_ahead(a, window, &bytes); + if (h == NULL) { + /* Remaining bytes are less than window. */ + window >>= 1; + if (window < 0x40) + goto fatal; + continue; + } + if (bytes < 0x40) + goto fatal; + p = h; + q = p + bytes; + + /* + * Scan ahead until we find something that looks + * like the RAR header. + */ + while (p + 7 < q) { + if (memcmp(p, RAR_SIGNATURE, 7) == 0) { + skip = p - (const char *)h; + __archive_read_consume(a, skip); + return (ARCHIVE_OK); + } + p += 0x10; + } + skip = p - (const char *)h; + __archive_read_consume(a, skip); + total += skip; + } +fatal: + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Couldn't find out RAR header"); + return (ARCHIVE_FATAL); +} + +static int +archive_read_format_rar_options(struct archive_read *a, + const char *key, const char *val) +{ + struct rar *rar; + int ret = ARCHIVE_FAILED; + + rar = (struct rar *)(a->format->data); + if (strcmp(key, "hdrcharset") == 0) { + if (val == NULL || val[0] == 0) + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "rar: hdrcharset option needs a character-set name"); + else { + rar->opt_sconv = + archive_string_conversion_from_charset( + &a->archive, val, 0); + if (rar->opt_sconv != NULL) + ret = ARCHIVE_OK; + else + ret = ARCHIVE_FATAL; + } + return (ret); + } + + /* Note: The "warn" return is just to inform the options + * supervisor that we didn't handle it. It will generate + * a suitable error if no one used this option. */ + return (ARCHIVE_WARN); +} + +static int +archive_read_format_rar_read_header(struct archive_read *a, + struct archive_entry *entry) +{ + const void *h; + const char *p; + struct rar *rar; + size_t skip; + char head_type; + int ret; + unsigned flags; + unsigned long crc32_expected; + + a->archive.archive_format = ARCHIVE_FORMAT_RAR; + if (a->archive.archive_format_name == NULL) + a->archive.archive_format_name = "RAR"; + + rar = (struct rar *)(a->format->data); + + /* + * It should be sufficient to call archive_read_next_header() for + * a reader to determine if an entry is encrypted or not. If the + * encryption of an entry is only detectable when calling + * archive_read_data(), so be it. We'll do the same check there + * as well. + */ + if (rar->has_encrypted_entries == ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW) { + rar->has_encrypted_entries = 0; + } + + /* RAR files can be generated without EOF headers, so return ARCHIVE_EOF if + * this fails. + */ + if ((h = __archive_read_ahead(a, 7, NULL)) == NULL) + return (ARCHIVE_EOF); + + p = h; + if (rar->found_first_header == 0 && + ((p[0] == 'M' && p[1] == 'Z') || memcmp(p, "\x7F\x45LF", 4) == 0)) { + /* This is an executable ? Must be self-extracting... */ + ret = skip_sfx(a); + if (ret < ARCHIVE_WARN) + return (ret); + } + rar->found_first_header = 1; + + while (1) + { + unsigned long crc32_val; + + if ((h = __archive_read_ahead(a, 7, NULL)) == NULL) + return (ARCHIVE_FATAL); + p = h; + + head_type = p[2]; + switch(head_type) + { + case MARK_HEAD: + if (memcmp(p, RAR_SIGNATURE, 7) != 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid marker header"); + return (ARCHIVE_FATAL); + } + __archive_read_consume(a, 7); + break; + + case MAIN_HEAD: + rar->main_flags = archive_le16dec(p + 3); + skip = archive_le16dec(p + 5); + if (skip < 7 + sizeof(rar->reserved1) + sizeof(rar->reserved2)) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid header size"); + return (ARCHIVE_FATAL); + } + if ((h = __archive_read_ahead(a, skip, NULL)) == NULL) + return (ARCHIVE_FATAL); + p = h; + memcpy(rar->reserved1, p + 7, sizeof(rar->reserved1)); + memcpy(rar->reserved2, p + 7 + sizeof(rar->reserved1), + sizeof(rar->reserved2)); + if (rar->main_flags & MHD_ENCRYPTVER) { + if (skip < 7 + sizeof(rar->reserved1) + sizeof(rar->reserved2)+1) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid header size"); + return (ARCHIVE_FATAL); + } + rar->encryptver = *(p + 7 + sizeof(rar->reserved1) + + sizeof(rar->reserved2)); + } + + /* Main header is password encrypted, so we cannot read any + file names or any other info about files from the header. */ + if (rar->main_flags & MHD_PASSWORD) + { + archive_entry_set_is_metadata_encrypted(entry, 1); + archive_entry_set_is_data_encrypted(entry, 1); + rar->has_encrypted_entries = 1; + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "RAR encryption support unavailable."); + return (ARCHIVE_FATAL); + } + + crc32_val = crc32(0, (const unsigned char *)p + 2, (unsigned)skip - 2); + if ((crc32_val & 0xffff) != archive_le16dec(p)) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Header CRC error"); + return (ARCHIVE_FATAL); + } + __archive_read_consume(a, skip); + break; + + case FILE_HEAD: + return read_header(a, entry, head_type); + + case COMM_HEAD: + case AV_HEAD: + case SUB_HEAD: + case PROTECT_HEAD: + case SIGN_HEAD: + case ENDARC_HEAD: + flags = archive_le16dec(p + 3); + skip = archive_le16dec(p + 5); + if (skip < 7) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid header size too small"); + return (ARCHIVE_FATAL); + } + if (flags & HD_ADD_SIZE_PRESENT) + { + if (skip < 7 + 4) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid header size too small"); + return (ARCHIVE_FATAL); + } + if ((h = __archive_read_ahead(a, skip, NULL)) == NULL) + return (ARCHIVE_FATAL); + p = h; + skip += archive_le32dec(p + 7); + } + + /* Skip over the 2-byte CRC at the beginning of the header. */ + crc32_expected = archive_le16dec(p); + __archive_read_consume(a, 2); + skip -= 2; + + /* Skim the entire header and compute the CRC. */ + crc32_val = 0; + while (skip > 0) { + size_t to_read = skip; + ssize_t did_read; + if (to_read > 32 * 1024) { + to_read = 32 * 1024; + } + if ((h = __archive_read_ahead(a, to_read, &did_read)) == NULL) { + return (ARCHIVE_FATAL); + } + p = h; + crc32_val = crc32(crc32_val, (const unsigned char *)p, (unsigned)did_read); + __archive_read_consume(a, did_read); + skip -= did_read; + } + if ((crc32_val & 0xffff) != crc32_expected) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Header CRC error"); + return (ARCHIVE_FATAL); + } + if (head_type == ENDARC_HEAD) + return (ARCHIVE_EOF); + break; + + case NEWSUB_HEAD: + if ((ret = read_header(a, entry, head_type)) < ARCHIVE_WARN) + return ret; + break; + + default: + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Bad RAR file"); + return (ARCHIVE_FATAL); + } + } +} + +static int +archive_read_format_rar_read_data(struct archive_read *a, const void **buff, + size_t *size, int64_t *offset) +{ + struct rar *rar = (struct rar *)(a->format->data); + int ret; + + if (rar->has_encrypted_entries == ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW) { + rar->has_encrypted_entries = 0; + } + + if (rar->bytes_unconsumed > 0) { + /* Consume as much as the decompressor actually used. */ + __archive_read_consume(a, rar->bytes_unconsumed); + rar->bytes_unconsumed = 0; + } + + *buff = NULL; + if (rar->entry_eof || rar->offset_seek >= rar->unp_size) { + *size = 0; + *offset = rar->offset; + if (*offset < rar->unp_size) + *offset = rar->unp_size; + return (ARCHIVE_EOF); + } + + switch (rar->compression_method) + { + case COMPRESS_METHOD_STORE: + ret = read_data_stored(a, buff, size, offset); + break; + + case COMPRESS_METHOD_FASTEST: + case COMPRESS_METHOD_FAST: + case COMPRESS_METHOD_NORMAL: + case COMPRESS_METHOD_GOOD: + case COMPRESS_METHOD_BEST: + ret = read_data_compressed(a, buff, size, offset); + if (ret != ARCHIVE_OK && ret != ARCHIVE_WARN) - __archive_ppmd7_functions.Ppmd7_Free(&rar->ppmd7_context, &g_szalloc); ++ __archive_ppmd7_functions.Ppmd7_Free(&rar->ppmd7_context); + break; + + default: + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Unsupported compression method for RAR file."); + ret = ARCHIVE_FATAL; + break; + } + return (ret); +} + +static int +archive_read_format_rar_read_data_skip(struct archive_read *a) +{ + struct rar *rar; + int64_t bytes_skipped; + int ret; + + rar = (struct rar *)(a->format->data); + + if (rar->bytes_unconsumed > 0) { + /* Consume as much as the decompressor actually used. */ + __archive_read_consume(a, rar->bytes_unconsumed); + rar->bytes_unconsumed = 0; + } + + if (rar->bytes_remaining > 0) { + bytes_skipped = __archive_read_consume(a, rar->bytes_remaining); + if (bytes_skipped < 0) + return (ARCHIVE_FATAL); + } + + /* Compressed data to skip must be read from each header in a multivolume + * archive. + */ + if (rar->main_flags & MHD_VOLUME && rar->file_flags & FHD_SPLIT_AFTER) + { + ret = archive_read_format_rar_read_header(a, a->entry); + if (ret == (ARCHIVE_EOF)) + ret = archive_read_format_rar_read_header(a, a->entry); + if (ret != (ARCHIVE_OK)) + return ret; + return archive_read_format_rar_read_data_skip(a); + } + + return (ARCHIVE_OK); +} + +static int64_t +archive_read_format_rar_seek_data(struct archive_read *a, int64_t offset, + int whence) +{ + int64_t client_offset, ret; + unsigned int i; + struct rar *rar = (struct rar *)(a->format->data); + + if (rar->compression_method == COMPRESS_METHOD_STORE) + { + /* Modify the offset for use with SEEK_SET */ + switch (whence) + { + case SEEK_CUR: + client_offset = rar->offset_seek; + break; + case SEEK_END: + client_offset = rar->unp_size; + break; + case SEEK_SET: + default: + client_offset = 0; + } + client_offset += offset; + if (client_offset < 0) + { + /* Can't seek past beginning of data block */ + return -1; + } + else if (client_offset > rar->unp_size) + { + /* + * Set the returned offset but only seek to the end of + * the data block. + */ + rar->offset_seek = client_offset; + client_offset = rar->unp_size; + } + + client_offset += rar->dbo[0].start_offset; + i = 0; + while (i < rar->cursor) + { + i++; + client_offset += rar->dbo[i].start_offset - rar->dbo[i-1].end_offset; + } + if (rar->main_flags & MHD_VOLUME) + { + /* Find the appropriate offset among the multivolume archive */ + while (1) + { + if (client_offset < rar->dbo[rar->cursor].start_offset && + rar->file_flags & FHD_SPLIT_BEFORE) + { + /* Search backwards for the correct data block */ + if (rar->cursor == 0) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Attempt to seek past beginning of RAR data block"); + return (ARCHIVE_FAILED); + } + rar->cursor--; + client_offset -= rar->dbo[rar->cursor+1].start_offset - + rar->dbo[rar->cursor].end_offset; + if (client_offset < rar->dbo[rar->cursor].start_offset) + continue; + ret = __archive_read_seek(a, rar->dbo[rar->cursor].start_offset - + rar->dbo[rar->cursor].header_size, SEEK_SET); + if (ret < (ARCHIVE_OK)) + return ret; + ret = archive_read_format_rar_read_header(a, a->entry); + if (ret != (ARCHIVE_OK)) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Error during seek of RAR file"); + return (ARCHIVE_FAILED); + } + rar->cursor--; + break; + } + else if (client_offset > rar->dbo[rar->cursor].end_offset && + rar->file_flags & FHD_SPLIT_AFTER) + { + /* Search forward for the correct data block */ + rar->cursor++; + if (rar->cursor < rar->nodes && + client_offset > rar->dbo[rar->cursor].end_offset) + { + client_offset += rar->dbo[rar->cursor].start_offset - + rar->dbo[rar->cursor-1].end_offset; + continue; + } + rar->cursor--; + ret = __archive_read_seek(a, rar->dbo[rar->cursor].end_offset, + SEEK_SET); + if (ret < (ARCHIVE_OK)) + return ret; + ret = archive_read_format_rar_read_header(a, a->entry); + if (ret == (ARCHIVE_EOF)) + { + rar->has_endarc_header = 1; + ret = archive_read_format_rar_read_header(a, a->entry); + } + if (ret != (ARCHIVE_OK)) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Error during seek of RAR file"); + return (ARCHIVE_FAILED); + } + client_offset += rar->dbo[rar->cursor].start_offset - + rar->dbo[rar->cursor-1].end_offset; + continue; + } + break; + } + } + + ret = __archive_read_seek(a, client_offset, SEEK_SET); + if (ret < (ARCHIVE_OK)) + return ret; + rar->bytes_remaining = rar->dbo[rar->cursor].end_offset - ret; + i = rar->cursor; + while (i > 0) + { + i--; + ret -= rar->dbo[i+1].start_offset - rar->dbo[i].end_offset; + } + ret -= rar->dbo[0].start_offset; + + /* Always restart reading the file after a seek */ + __archive_reset_read_data(&a->archive); + + rar->bytes_unconsumed = 0; + rar->offset = 0; + + /* + * If a seek past the end of file was requested, return the requested + * offset. + */ + if (ret == rar->unp_size && rar->offset_seek > rar->unp_size) + return rar->offset_seek; + + /* Return the new offset */ + rar->offset_seek = ret; + return rar->offset_seek; + } + else + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Seeking of compressed RAR files is unsupported"); + } + return (ARCHIVE_FAILED); +} + +static int +archive_read_format_rar_cleanup(struct archive_read *a) +{ + struct rar *rar; + + rar = (struct rar *)(a->format->data); + free_codes(a); + free(rar->filename); + free(rar->filename_save); + free(rar->dbo); + free(rar->unp_buffer); + free(rar->lzss.window); - __archive_ppmd7_functions.Ppmd7_Free(&rar->ppmd7_context, &g_szalloc); ++ __archive_ppmd7_functions.Ppmd7_Free(&rar->ppmd7_context); + free(rar); + (a->format->data) = NULL; + return (ARCHIVE_OK); +} + +static int +read_header(struct archive_read *a, struct archive_entry *entry, + char head_type) +{ + const void *h; + const char *p, *endp; + struct rar *rar; + struct rar_header rar_header; + struct rar_file_header file_header; + int64_t header_size; + unsigned filename_size, end; + char *filename; + char *strp; + char packed_size[8]; + char unp_size[8]; + int ttime; + struct archive_string_conv *sconv, *fn_sconv; + unsigned long crc32_val; + int ret = (ARCHIVE_OK), ret2; + + rar = (struct rar *)(a->format->data); + + /* Setup a string conversion object for non-rar-unicode filenames. */ + sconv = rar->opt_sconv; + if (sconv == NULL) { + if (!rar->init_default_conversion) { + rar->sconv_default = + archive_string_default_conversion_for_read( + &(a->archive)); + rar->init_default_conversion = 1; + } + sconv = rar->sconv_default; + } + + + if ((h = __archive_read_ahead(a, 7, NULL)) == NULL) + return (ARCHIVE_FATAL); + p = h; + memcpy(&rar_header, p, sizeof(rar_header)); + rar->file_flags = archive_le16dec(rar_header.flags); + header_size = archive_le16dec(rar_header.size); + if (header_size < (int64_t)sizeof(file_header) + 7) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid header size"); + return (ARCHIVE_FATAL); + } + crc32_val = crc32(0, (const unsigned char *)p + 2, 7 - 2); + __archive_read_consume(a, 7); + + if (!(rar->file_flags & FHD_SOLID)) + { + rar->compression_method = 0; + rar->packed_size = 0; + rar->unp_size = 0; + rar->mtime = 0; + rar->ctime = 0; + rar->atime = 0; + rar->arctime = 0; + rar->mode = 0; + memset(&rar->salt, 0, sizeof(rar->salt)); + rar->atime = 0; + rar->ansec = 0; + rar->ctime = 0; + rar->cnsec = 0; + rar->mtime = 0; + rar->mnsec = 0; + rar->arctime = 0; + rar->arcnsec = 0; + } + else + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "RAR solid archive support unavailable."); + return (ARCHIVE_FATAL); + } + + if ((h = __archive_read_ahead(a, (size_t)header_size - 7, NULL)) == NULL) + return (ARCHIVE_FATAL); + + /* File Header CRC check. */ + crc32_val = crc32(crc32_val, h, (unsigned)(header_size - 7)); + if ((crc32_val & 0xffff) != archive_le16dec(rar_header.crc)) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Header CRC error"); + return (ARCHIVE_FATAL); + } + /* If no CRC error, Go on parsing File Header. */ + p = h; + endp = p + header_size - 7; + memcpy(&file_header, p, sizeof(file_header)); + p += sizeof(file_header); + + rar->compression_method = file_header.method; + + ttime = archive_le32dec(file_header.file_time); + rar->mtime = get_time(ttime); + + rar->file_crc = archive_le32dec(file_header.file_crc); + + if (rar->file_flags & FHD_PASSWORD) + { + archive_entry_set_is_data_encrypted(entry, 1); + rar->has_encrypted_entries = 1; + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "RAR encryption support unavailable."); + /* Since it is only the data part itself that is encrypted we can at least + extract information about the currently processed entry and don't need + to return ARCHIVE_FATAL here. */ + /*return (ARCHIVE_FATAL);*/ + } + + if (rar->file_flags & FHD_LARGE) + { + memcpy(packed_size, file_header.pack_size, 4); + memcpy(packed_size + 4, p, 4); /* High pack size */ + p += 4; + memcpy(unp_size, file_header.unp_size, 4); + memcpy(unp_size + 4, p, 4); /* High unpack size */ + p += 4; + rar->packed_size = archive_le64dec(&packed_size); + rar->unp_size = archive_le64dec(&unp_size); + } + else + { + rar->packed_size = archive_le32dec(file_header.pack_size); + rar->unp_size = archive_le32dec(file_header.unp_size); + } + + if (rar->packed_size < 0 || rar->unp_size < 0) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid sizes specified."); + return (ARCHIVE_FATAL); + } + + rar->bytes_remaining = rar->packed_size; + + /* TODO: RARv3 subblocks contain comments. For now the complete block is + * consumed at the end. + */ + if (head_type == NEWSUB_HEAD) { + size_t distance = p - (const char *)h; + header_size += rar->packed_size; + /* Make sure we have the extended data. */ + if ((h = __archive_read_ahead(a, (size_t)header_size - 7, NULL)) == NULL) + return (ARCHIVE_FATAL); + p = h; + endp = p + header_size - 7; + p += distance; + } + + filename_size = archive_le16dec(file_header.name_size); + if (p + filename_size > endp) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid filename size"); + return (ARCHIVE_FATAL); + } + if (rar->filename_allocated < filename_size * 2 + 2) { + char *newptr; + size_t newsize = filename_size * 2 + 2; + newptr = realloc(rar->filename, newsize); + if (newptr == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Couldn't allocate memory."); + return (ARCHIVE_FATAL); + } + rar->filename = newptr; + rar->filename_allocated = newsize; + } + filename = rar->filename; + memcpy(filename, p, filename_size); + filename[filename_size] = '\0'; + if (rar->file_flags & FHD_UNICODE) + { + if (filename_size != strlen(filename)) + { + unsigned char highbyte, flagbits, flagbyte; + unsigned fn_end, offset; + + end = filename_size; + fn_end = filename_size * 2; + filename_size = 0; + offset = (unsigned)strlen(filename) + 1; + highbyte = *(p + offset++); + flagbits = 0; + flagbyte = 0; + while (offset < end && filename_size < fn_end) + { + if (!flagbits) + { + flagbyte = *(p + offset++); + flagbits = 8; + } + + flagbits -= 2; + switch((flagbyte >> flagbits) & 3) + { + case 0: + filename[filename_size++] = '\0'; + filename[filename_size++] = *(p + offset++); + break; + case 1: + filename[filename_size++] = highbyte; + filename[filename_size++] = *(p + offset++); + break; + case 2: + filename[filename_size++] = *(p + offset + 1); + filename[filename_size++] = *(p + offset); + offset += 2; + break; + case 3: + { + char extra, high; + uint8_t length = *(p + offset++); + + if (length & 0x80) { + extra = *(p + offset++); + high = (char)highbyte; + } else + extra = high = 0; + length = (length & 0x7f) + 2; + while (length && filename_size < fn_end) { + unsigned cp = filename_size >> 1; + filename[filename_size++] = high; + filename[filename_size++] = p[cp] + extra; + length--; + } + } + break; + } + } + if (filename_size > fn_end) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid filename"); + return (ARCHIVE_FATAL); + } + filename[filename_size++] = '\0'; - filename[filename_size++] = '\0'; ++ /* ++ * Do not increment filename_size here as the computations below ++ * add the space for the terminating NUL explicitly. ++ */ ++ filename[filename_size] = '\0'; + + /* Decoded unicode form is UTF-16BE, so we have to update a string + * conversion object for it. */ + if (rar->sconv_utf16be == NULL) { + rar->sconv_utf16be = archive_string_conversion_from_charset( + &a->archive, "UTF-16BE", 1); + if (rar->sconv_utf16be == NULL) + return (ARCHIVE_FATAL); + } + fn_sconv = rar->sconv_utf16be; + + strp = filename; + while (memcmp(strp, "\x00\x00", 2)) + { + if (!memcmp(strp, "\x00\\", 2)) + *(strp + 1) = '/'; + strp += 2; + } + p += offset; + } else { + /* + * If FHD_UNICODE is set but no unicode data, this file name form + * is UTF-8, so we have to update a string conversion object for + * it accordingly. + */ + if (rar->sconv_utf8 == NULL) { + rar->sconv_utf8 = archive_string_conversion_from_charset( + &a->archive, "UTF-8", 1); + if (rar->sconv_utf8 == NULL) + return (ARCHIVE_FATAL); + } + fn_sconv = rar->sconv_utf8; + while ((strp = strchr(filename, '\\')) != NULL) + *strp = '/'; + p += filename_size; + } + } + else + { + fn_sconv = sconv; + while ((strp = strchr(filename, '\\')) != NULL) + *strp = '/'; + p += filename_size; + } + + /* Split file in multivolume RAR. No more need to process header. */ + if (rar->filename_save && + filename_size == rar->filename_save_size && + !memcmp(rar->filename, rar->filename_save, filename_size + 1)) + { + __archive_read_consume(a, header_size - 7); + rar->cursor++; + if (rar->cursor >= rar->nodes) + { + rar->nodes++; + if ((rar->dbo = + realloc(rar->dbo, sizeof(*rar->dbo) * rar->nodes)) == NULL) + { + archive_set_error(&a->archive, ENOMEM, "Couldn't allocate memory."); + return (ARCHIVE_FATAL); + } + rar->dbo[rar->cursor].header_size = header_size; + rar->dbo[rar->cursor].start_offset = -1; + rar->dbo[rar->cursor].end_offset = -1; + } + if (rar->dbo[rar->cursor].start_offset < 0) + { + rar->dbo[rar->cursor].start_offset = a->filter->position; + rar->dbo[rar->cursor].end_offset = rar->dbo[rar->cursor].start_offset + + rar->packed_size; + } + return ret; + } + + rar->filename_save = (char*)realloc(rar->filename_save, + filename_size + 1); + memcpy(rar->filename_save, rar->filename, filename_size + 1); + rar->filename_save_size = filename_size; + + /* Set info for seeking */ + free(rar->dbo); + if ((rar->dbo = calloc(1, sizeof(*rar->dbo))) == NULL) + { + archive_set_error(&a->archive, ENOMEM, "Couldn't allocate memory."); + return (ARCHIVE_FATAL); + } + rar->dbo[0].header_size = header_size; + rar->dbo[0].start_offset = -1; + rar->dbo[0].end_offset = -1; + rar->cursor = 0; + rar->nodes = 1; + + if (rar->file_flags & FHD_SALT) + { + if (p + 8 > endp) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid header size"); + return (ARCHIVE_FATAL); + } + memcpy(rar->salt, p, 8); + p += 8; + } + + if (rar->file_flags & FHD_EXTTIME) { + if (read_exttime(p, rar, endp) < 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid header size"); + return (ARCHIVE_FATAL); + } + } + + __archive_read_consume(a, header_size - 7); + rar->dbo[0].start_offset = a->filter->position; + rar->dbo[0].end_offset = rar->dbo[0].start_offset + rar->packed_size; + + switch(file_header.host_os) + { + case OS_MSDOS: + case OS_OS2: + case OS_WIN32: + rar->mode = archive_le32dec(file_header.file_attr); + if (rar->mode & FILE_ATTRIBUTE_DIRECTORY) + rar->mode = AE_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH; + else + rar->mode = AE_IFREG; + rar->mode |= S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; + break; + + case OS_UNIX: + case OS_MAC_OS: + case OS_BEOS: + rar->mode = archive_le32dec(file_header.file_attr); + break; + + default: + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Unknown file attributes from RAR file's host OS"); + return (ARCHIVE_FATAL); + } + + rar->bytes_uncopied = rar->bytes_unconsumed = 0; + rar->lzss.position = rar->offset = 0; + rar->offset_seek = 0; + rar->dictionary_size = 0; + rar->offset_outgoing = 0; + rar->br.cache_avail = 0; + rar->br.avail_in = 0; + rar->crc_calculated = 0; + rar->entry_eof = 0; + rar->valid = 1; + rar->is_ppmd_block = 0; + rar->start_new_table = 1; + free(rar->unp_buffer); + rar->unp_buffer = NULL; + rar->unp_offset = 0; + rar->unp_buffer_size = UNP_BUFFER_SIZE; + memset(rar->lengthtable, 0, sizeof(rar->lengthtable)); - __archive_ppmd7_functions.Ppmd7_Free(&rar->ppmd7_context, &g_szalloc); ++ __archive_ppmd7_functions.Ppmd7_Free(&rar->ppmd7_context); + rar->ppmd_valid = rar->ppmd_eod = 0; + + /* Don't set any archive entries for non-file header types */ + if (head_type == NEWSUB_HEAD) + return ret; + + archive_entry_set_mtime(entry, rar->mtime, rar->mnsec); + archive_entry_set_ctime(entry, rar->ctime, rar->cnsec); + archive_entry_set_atime(entry, rar->atime, rar->ansec); + archive_entry_set_size(entry, rar->unp_size); + archive_entry_set_mode(entry, rar->mode); + + if (archive_entry_copy_pathname_l(entry, filename, filename_size, fn_sconv)) + { + if (errno == ENOMEM) + { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Pathname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Pathname cannot be converted from %s to current locale.", + archive_string_conversion_charset_name(fn_sconv)); + ret = (ARCHIVE_WARN); + } + + if (((rar->mode) & AE_IFMT) == AE_IFLNK) + { + /* Make sure a symbolic-link file does not have its body. */ + rar->bytes_remaining = 0; + archive_entry_set_size(entry, 0); + + /* Read a symbolic-link name. */ + if ((ret2 = read_symlink_stored(a, entry, sconv)) < (ARCHIVE_WARN)) + return ret2; + if (ret > ret2) + ret = ret2; + } + + if (rar->bytes_remaining == 0) + rar->entry_eof = 1; + + return ret; +} + +static time_t +get_time(int ttime) +{ + struct tm tm; + tm.tm_sec = 2 * (ttime & 0x1f); + tm.tm_min = (ttime >> 5) & 0x3f; + tm.tm_hour = (ttime >> 11) & 0x1f; + tm.tm_mday = (ttime >> 16) & 0x1f; + tm.tm_mon = ((ttime >> 21) & 0x0f) - 1; + tm.tm_year = ((ttime >> 25) & 0x7f) + 80; + tm.tm_isdst = -1; + return mktime(&tm); +} + +static int +read_exttime(const char *p, struct rar *rar, const char *endp) +{ + unsigned rmode, flags, rem, j, count; + int ttime, i; + struct tm *tm; + time_t t; + long nsec; + + if (p + 2 > endp) + return (-1); + flags = archive_le16dec(p); + p += 2; + + for (i = 3; i >= 0; i--) + { + t = 0; + if (i == 3) + t = rar->mtime; + rmode = flags >> i * 4; + if (rmode & 8) + { + if (!t) + { + if (p + 4 > endp) + return (-1); + ttime = archive_le32dec(p); + t = get_time(ttime); + p += 4; + } + rem = 0; + count = rmode & 3; + if (p + count > endp) + return (-1); + for (j = 0; j < count; j++) + { + rem = (((unsigned)(unsigned char)*p) << 16) | (rem >> 8); + p++; + } + tm = localtime(&t); + nsec = tm->tm_sec + rem / NS_UNIT; + if (rmode & 4) + { + tm->tm_sec++; + t = mktime(tm); + } + if (i == 3) + { + rar->mtime = t; + rar->mnsec = nsec; + } + else if (i == 2) + { + rar->ctime = t; + rar->cnsec = nsec; + } + else if (i == 1) + { + rar->atime = t; + rar->ansec = nsec; + } + else + { + rar->arctime = t; + rar->arcnsec = nsec; + } + } + } + return (0); +} + +static int +read_symlink_stored(struct archive_read *a, struct archive_entry *entry, + struct archive_string_conv *sconv) +{ + const void *h; + const char *p; + struct rar *rar; + int ret = (ARCHIVE_OK); + + rar = (struct rar *)(a->format->data); + if ((h = rar_read_ahead(a, (size_t)rar->packed_size, NULL)) == NULL) + return (ARCHIVE_FATAL); + p = h; + + if (archive_entry_copy_symlink_l(entry, + p, (size_t)rar->packed_size, sconv)) + { + if (errno == ENOMEM) + { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for link"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "link cannot be converted from %s to current locale.", + archive_string_conversion_charset_name(sconv)); + ret = (ARCHIVE_WARN); + } + __archive_read_consume(a, rar->packed_size); + return ret; +} + +static int +read_data_stored(struct archive_read *a, const void **buff, size_t *size, + int64_t *offset) +{ + struct rar *rar; + ssize_t bytes_avail; + + rar = (struct rar *)(a->format->data); + if (rar->bytes_remaining == 0 && + !(rar->main_flags & MHD_VOLUME && rar->file_flags & FHD_SPLIT_AFTER)) + { + *buff = NULL; + *size = 0; + *offset = rar->offset; + if (rar->file_crc != rar->crc_calculated) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "File CRC error"); + return (ARCHIVE_FATAL); + } + rar->entry_eof = 1; + return (ARCHIVE_EOF); + } + + *buff = rar_read_ahead(a, 1, &bytes_avail); + if (bytes_avail <= 0) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated RAR file data"); + return (ARCHIVE_FATAL); + } + + *size = bytes_avail; + *offset = rar->offset; + rar->offset += bytes_avail; + rar->offset_seek += bytes_avail; + rar->bytes_remaining -= bytes_avail; + rar->bytes_unconsumed = bytes_avail; + /* Calculate File CRC. */ + rar->crc_calculated = crc32(rar->crc_calculated, *buff, + (unsigned)bytes_avail); + return (ARCHIVE_OK); +} + +static int +read_data_compressed(struct archive_read *a, const void **buff, size_t *size, + int64_t *offset) +{ + struct rar *rar; + int64_t start, end, actualend; + size_t bs; + int ret = (ARCHIVE_OK), sym, code, lzss_offset, length, i; + + rar = (struct rar *)(a->format->data); + + do { + if (!rar->valid) + return (ARCHIVE_FATAL); + if (rar->ppmd_eod || + (rar->dictionary_size && rar->offset >= rar->unp_size)) + { + if (rar->unp_offset > 0) { + /* + * We have unprocessed extracted data. write it out. + */ + *buff = rar->unp_buffer; + *size = rar->unp_offset; + *offset = rar->offset_outgoing; + rar->offset_outgoing += *size; + /* Calculate File CRC. */ + rar->crc_calculated = crc32(rar->crc_calculated, *buff, + (unsigned)*size); + rar->unp_offset = 0; + return (ARCHIVE_OK); + } + *buff = NULL; + *size = 0; + *offset = rar->offset; + if (rar->file_crc != rar->crc_calculated) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "File CRC error"); + return (ARCHIVE_FATAL); + } + rar->entry_eof = 1; + return (ARCHIVE_EOF); + } + + if (!rar->is_ppmd_block && rar->dictionary_size && rar->bytes_uncopied > 0) + { + if (rar->bytes_uncopied > (rar->unp_buffer_size - rar->unp_offset)) + bs = rar->unp_buffer_size - rar->unp_offset; + else + bs = (size_t)rar->bytes_uncopied; + ret = copy_from_lzss_window(a, buff, rar->offset, (int)bs); + if (ret != ARCHIVE_OK) + return (ret); + rar->offset += bs; + rar->bytes_uncopied -= bs; + if (*buff != NULL) { + rar->unp_offset = 0; + *size = rar->unp_buffer_size; + *offset = rar->offset_outgoing; + rar->offset_outgoing += *size; + /* Calculate File CRC. */ + rar->crc_calculated = crc32(rar->crc_calculated, *buff, + (unsigned)*size); + return (ret); + } + continue; + } + + if (!rar->br.next_in && + (ret = rar_br_preparation(a, &(rar->br))) < ARCHIVE_WARN) + return (ret); + if (rar->start_new_table && ((ret = parse_codes(a)) < (ARCHIVE_WARN))) + return (ret); + + if (rar->is_ppmd_block) + { + if ((sym = __archive_ppmd7_functions.Ppmd7_DecodeSymbol( + &rar->ppmd7_context, &rar->range_dec.p)) < 0) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid symbol"); + return (ARCHIVE_FATAL); + } + if(sym != rar->ppmd_escape) + { + lzss_emit_literal(rar, sym); + rar->bytes_uncopied++; + } + else + { + if ((code = __archive_ppmd7_functions.Ppmd7_DecodeSymbol( + &rar->ppmd7_context, &rar->range_dec.p)) < 0) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid symbol"); + return (ARCHIVE_FATAL); + } + + switch(code) + { + case 0: + rar->start_new_table = 1; + return read_data_compressed(a, buff, size, offset); + + case 2: + rar->ppmd_eod = 1;/* End Of ppmd Data. */ + continue; + + case 3: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Parsing filters is unsupported."); + return (ARCHIVE_FAILED); + + case 4: + lzss_offset = 0; + for (i = 2; i >= 0; i--) + { + if ((code = __archive_ppmd7_functions.Ppmd7_DecodeSymbol( + &rar->ppmd7_context, &rar->range_dec.p)) < 0) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid symbol"); + return (ARCHIVE_FATAL); + } + lzss_offset |= code << (i * 8); + } + if ((length = __archive_ppmd7_functions.Ppmd7_DecodeSymbol( + &rar->ppmd7_context, &rar->range_dec.p)) < 0) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid symbol"); + return (ARCHIVE_FATAL); + } + lzss_emit_match(rar, lzss_offset + 2, length + 32); + rar->bytes_uncopied += length + 32; + break; + + case 5: + if ((length = __archive_ppmd7_functions.Ppmd7_DecodeSymbol( + &rar->ppmd7_context, &rar->range_dec.p)) < 0) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid symbol"); + return (ARCHIVE_FATAL); + } + lzss_emit_match(rar, 1, length + 4); + rar->bytes_uncopied += length + 4; + break; + + default: + lzss_emit_literal(rar, sym); + rar->bytes_uncopied++; + } + } + } + else + { + start = rar->offset; + end = start + rar->dictionary_size; + rar->filterstart = INT64_MAX; + + if ((actualend = expand(a, end)) < 0) + return ((int)actualend); + + rar->bytes_uncopied = actualend - start; + if (rar->bytes_uncopied == 0) { + /* Broken RAR files cause this case. + * NOTE: If this case were possible on a normal RAR file + * we would find out where it was actually bad and + * what we would do to solve it. */ + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Internal error extracting RAR file"); + return (ARCHIVE_FATAL); + } + } + if (rar->bytes_uncopied > (rar->unp_buffer_size - rar->unp_offset)) + bs = rar->unp_buffer_size - rar->unp_offset; + else + bs = (size_t)rar->bytes_uncopied; + ret = copy_from_lzss_window(a, buff, rar->offset, (int)bs); + if (ret != ARCHIVE_OK) + return (ret); + rar->offset += bs; + rar->bytes_uncopied -= bs; + /* + * If *buff is NULL, it means unp_buffer is not full. + * So we have to continue extracting a RAR file. + */ + } while (*buff == NULL); + + rar->unp_offset = 0; + *size = rar->unp_buffer_size; + *offset = rar->offset_outgoing; + rar->offset_outgoing += *size; + /* Calculate File CRC. */ + rar->crc_calculated = crc32(rar->crc_calculated, *buff, (unsigned)*size); + return ret; +} + +static int +parse_codes(struct archive_read *a) +{ + int i, j, val, n, r; + unsigned char bitlengths[MAX_SYMBOLS], zerocount, ppmd_flags; + unsigned int maxorder; + struct huffman_code precode; + struct rar *rar = (struct rar *)(a->format->data); + struct rar_br *br = &(rar->br); + + free_codes(a); + + /* Skip to the next byte */ + rar_br_consume_unalined_bits(br); + + /* PPMd block flag */ + if (!rar_br_read_ahead(a, br, 1)) + goto truncated_data; + if ((rar->is_ppmd_block = rar_br_bits(br, 1)) != 0) + { + rar_br_consume(br, 1); + if (!rar_br_read_ahead(a, br, 7)) + goto truncated_data; + ppmd_flags = rar_br_bits(br, 7); + rar_br_consume(br, 7); + + /* Memory is allocated in MB */ + if (ppmd_flags & 0x20) + { + if (!rar_br_read_ahead(a, br, 8)) + goto truncated_data; + rar->dictionary_size = (rar_br_bits(br, 8) + 1) << 20; + rar_br_consume(br, 8); + } + + if (ppmd_flags & 0x40) + { + if (!rar_br_read_ahead(a, br, 8)) + goto truncated_data; + rar->ppmd_escape = rar->ppmd7_context.InitEsc = rar_br_bits(br, 8); + rar_br_consume(br, 8); + } + else + rar->ppmd_escape = 2; + + if (ppmd_flags & 0x20) + { + maxorder = (ppmd_flags & 0x1F) + 1; + if(maxorder > 16) + maxorder = 16 + (maxorder - 16) * 3; + + if (maxorder == 1) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated RAR file data"); + return (ARCHIVE_FATAL); + } + + /* Make sure ppmd7_contest is freed before Ppmd7_Construct + * because reading a broken file cause this abnormal sequence. */ - __archive_ppmd7_functions.Ppmd7_Free(&rar->ppmd7_context, &g_szalloc); ++ __archive_ppmd7_functions.Ppmd7_Free(&rar->ppmd7_context); + + rar->bytein.a = a; + rar->bytein.Read = &ppmd_read; + __archive_ppmd7_functions.PpmdRAR_RangeDec_CreateVTable(&rar->range_dec); + rar->range_dec.Stream = &rar->bytein; + __archive_ppmd7_functions.Ppmd7_Construct(&rar->ppmd7_context); + + if (rar->dictionary_size == 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid zero dictionary size"); + return (ARCHIVE_FATAL); + } + + if (!__archive_ppmd7_functions.Ppmd7_Alloc(&rar->ppmd7_context, - rar->dictionary_size, &g_szalloc)) ++ rar->dictionary_size)) + { + archive_set_error(&a->archive, ENOMEM, + "Out of memory"); + return (ARCHIVE_FATAL); + } + if (!__archive_ppmd7_functions.PpmdRAR_RangeDec_Init(&rar->range_dec)) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Unable to initialize PPMd range decoder"); + return (ARCHIVE_FATAL); + } + __archive_ppmd7_functions.Ppmd7_Init(&rar->ppmd7_context, maxorder); + rar->ppmd_valid = 1; + } + else + { + if (!rar->ppmd_valid) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid PPMd sequence"); + return (ARCHIVE_FATAL); + } + if (!__archive_ppmd7_functions.PpmdRAR_RangeDec_Init(&rar->range_dec)) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Unable to initialize PPMd range decoder"); + return (ARCHIVE_FATAL); + } + } + } + else + { + rar_br_consume(br, 1); + + /* Keep existing table flag */ + if (!rar_br_read_ahead(a, br, 1)) + goto truncated_data; + if (!rar_br_bits(br, 1)) + memset(rar->lengthtable, 0, sizeof(rar->lengthtable)); + rar_br_consume(br, 1); + + memset(&bitlengths, 0, sizeof(bitlengths)); + for (i = 0; i < MAX_SYMBOLS;) + { + if (!rar_br_read_ahead(a, br, 4)) + goto truncated_data; + bitlengths[i++] = rar_br_bits(br, 4); + rar_br_consume(br, 4); + if (bitlengths[i-1] == 0xF) + { + if (!rar_br_read_ahead(a, br, 4)) + goto truncated_data; + zerocount = rar_br_bits(br, 4); + rar_br_consume(br, 4); + if (zerocount) + { + i--; + for (j = 0; j < zerocount + 2 && i < MAX_SYMBOLS; j++) + bitlengths[i++] = 0; + } + } + } + + memset(&precode, 0, sizeof(precode)); + r = create_code(a, &precode, bitlengths, MAX_SYMBOLS, MAX_SYMBOL_LENGTH); + if (r != ARCHIVE_OK) { + free(precode.tree); + free(precode.table); + return (r); + } + + for (i = 0; i < HUFFMAN_TABLE_SIZE;) + { + if ((val = read_next_symbol(a, &precode)) < 0) { + free(precode.tree); + free(precode.table); + return (ARCHIVE_FATAL); + } + if (val < 16) + { + rar->lengthtable[i] = (rar->lengthtable[i] + val) & 0xF; + i++; + } + else if (val < 18) + { + if (i == 0) + { + free(precode.tree); + free(precode.table); + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Internal error extracting RAR file."); + return (ARCHIVE_FATAL); + } + + if(val == 16) { + if (!rar_br_read_ahead(a, br, 3)) { + free(precode.tree); + free(precode.table); + goto truncated_data; + } + n = rar_br_bits(br, 3) + 3; + rar_br_consume(br, 3); + } else { + if (!rar_br_read_ahead(a, br, 7)) { + free(precode.tree); + free(precode.table); + goto truncated_data; + } + n = rar_br_bits(br, 7) + 11; + rar_br_consume(br, 7); + } + + for (j = 0; j < n && i < HUFFMAN_TABLE_SIZE; j++) + { + rar->lengthtable[i] = rar->lengthtable[i-1]; + i++; + } + } + else + { + if(val == 18) { + if (!rar_br_read_ahead(a, br, 3)) { + free(precode.tree); + free(precode.table); + goto truncated_data; + } + n = rar_br_bits(br, 3) + 3; + rar_br_consume(br, 3); + } else { + if (!rar_br_read_ahead(a, br, 7)) { + free(precode.tree); + free(precode.table); + goto truncated_data; + } + n = rar_br_bits(br, 7) + 11; + rar_br_consume(br, 7); + } + + for(j = 0; j < n && i < HUFFMAN_TABLE_SIZE; j++) + rar->lengthtable[i++] = 0; + } + } + free(precode.tree); + free(precode.table); + + r = create_code(a, &rar->maincode, &rar->lengthtable[0], MAINCODE_SIZE, + MAX_SYMBOL_LENGTH); + if (r != ARCHIVE_OK) + return (r); + r = create_code(a, &rar->offsetcode, &rar->lengthtable[MAINCODE_SIZE], + OFFSETCODE_SIZE, MAX_SYMBOL_LENGTH); + if (r != ARCHIVE_OK) + return (r); + r = create_code(a, &rar->lowoffsetcode, + &rar->lengthtable[MAINCODE_SIZE + OFFSETCODE_SIZE], + LOWOFFSETCODE_SIZE, MAX_SYMBOL_LENGTH); + if (r != ARCHIVE_OK) + return (r); + r = create_code(a, &rar->lengthcode, + &rar->lengthtable[MAINCODE_SIZE + OFFSETCODE_SIZE + + LOWOFFSETCODE_SIZE], LENGTHCODE_SIZE, MAX_SYMBOL_LENGTH); + if (r != ARCHIVE_OK) + return (r); + } + + if (!rar->dictionary_size || !rar->lzss.window) + { + /* Seems as though dictionary sizes are not used. Even so, minimize + * memory usage as much as possible. + */ + void *new_window; + unsigned int new_size; + + if (rar->unp_size >= DICTIONARY_MAX_SIZE) + new_size = DICTIONARY_MAX_SIZE; + else + new_size = rar_fls((unsigned int)rar->unp_size) << 1; + new_window = realloc(rar->lzss.window, new_size); + if (new_window == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Unable to allocate memory for uncompressed data."); + return (ARCHIVE_FATAL); + } + rar->lzss.window = (unsigned char *)new_window; + rar->dictionary_size = new_size; + memset(rar->lzss.window, 0, rar->dictionary_size); + rar->lzss.mask = rar->dictionary_size - 1; + } + + rar->start_new_table = 0; + return (ARCHIVE_OK); +truncated_data: + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated RAR file data"); + rar->valid = 0; + return (ARCHIVE_FATAL); +} + +static void +free_codes(struct archive_read *a) +{ + struct rar *rar = (struct rar *)(a->format->data); + free(rar->maincode.tree); + free(rar->offsetcode.tree); + free(rar->lowoffsetcode.tree); + free(rar->lengthcode.tree); + free(rar->maincode.table); + free(rar->offsetcode.table); + free(rar->lowoffsetcode.table); + free(rar->lengthcode.table); + memset(&rar->maincode, 0, sizeof(rar->maincode)); + memset(&rar->offsetcode, 0, sizeof(rar->offsetcode)); + memset(&rar->lowoffsetcode, 0, sizeof(rar->lowoffsetcode)); + memset(&rar->lengthcode, 0, sizeof(rar->lengthcode)); +} + + +static int +read_next_symbol(struct archive_read *a, struct huffman_code *code) +{ + unsigned char bit; + unsigned int bits; + int length, value, node; + struct rar *rar; + struct rar_br *br; + + if (!code->table) + { + if (make_table(a, code) != (ARCHIVE_OK)) + return -1; + } + + rar = (struct rar *)(a->format->data); + br = &(rar->br); + + /* Look ahead (peek) at bits */ + if (!rar_br_read_ahead(a, br, code->tablesize)) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated RAR file data"); + rar->valid = 0; + return -1; + } + bits = rar_br_bits(br, code->tablesize); + + length = code->table[bits].length; + value = code->table[bits].value; + + if (length < 0) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid prefix code in bitstream"); + return -1; + } + + if (length <= code->tablesize) + { + /* Skip length bits */ + rar_br_consume(br, length); + return value; + } + + /* Skip tablesize bits */ + rar_br_consume(br, code->tablesize); + + node = value; + while (!(code->tree[node].branches[0] == + code->tree[node].branches[1])) + { + if (!rar_br_read_ahead(a, br, 1)) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated RAR file data"); + rar->valid = 0; + return -1; + } + bit = rar_br_bits(br, 1); + rar_br_consume(br, 1); + + if (code->tree[node].branches[bit] < 0) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid prefix code in bitstream"); + return -1; + } + node = code->tree[node].branches[bit]; + } + + return code->tree[node].branches[0]; +} + +static int +create_code(struct archive_read *a, struct huffman_code *code, + unsigned char *lengths, int numsymbols, char maxlength) +{ + int i, j, codebits = 0, symbolsleft = numsymbols; + + code->numentries = 0; + code->numallocatedentries = 0; + if (new_node(code) < 0) { + archive_set_error(&a->archive, ENOMEM, + "Unable to allocate memory for node data."); + return (ARCHIVE_FATAL); + } + code->numentries = 1; + code->minlength = INT_MAX; + code->maxlength = INT_MIN; + codebits = 0; + for(i = 1; i <= maxlength; i++) + { + for(j = 0; j < numsymbols; j++) + { + if (lengths[j] != i) continue; + if (add_value(a, code, j, codebits, i) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + codebits++; + if (--symbolsleft <= 0) { break; break; } + } + codebits <<= 1; + } + return (ARCHIVE_OK); +} + +static int +add_value(struct archive_read *a, struct huffman_code *code, int value, + int codebits, int length) +{ + int repeatpos, lastnode, bitpos, bit, repeatnode, nextnode; + + free(code->table); + code->table = NULL; + + if(length > code->maxlength) + code->maxlength = length; + if(length < code->minlength) + code->minlength = length; + + repeatpos = -1; + if (repeatpos == 0 || (repeatpos >= 0 + && (((codebits >> (repeatpos - 1)) & 3) == 0 + || ((codebits >> (repeatpos - 1)) & 3) == 3))) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid repeat position"); + return (ARCHIVE_FATAL); + } + + lastnode = 0; + for (bitpos = length - 1; bitpos >= 0; bitpos--) + { + bit = (codebits >> bitpos) & 1; + + /* Leaf node check */ + if (code->tree[lastnode].branches[0] == + code->tree[lastnode].branches[1]) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Prefix found"); + return (ARCHIVE_FATAL); + } + + if (bitpos == repeatpos) + { + /* Open branch check */ + if (!(code->tree[lastnode].branches[bit] < 0)) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid repeating code"); + return (ARCHIVE_FATAL); + } + + if ((repeatnode = new_node(code)) < 0) { + archive_set_error(&a->archive, ENOMEM, + "Unable to allocate memory for node data."); + return (ARCHIVE_FATAL); + } + if ((nextnode = new_node(code)) < 0) { + archive_set_error(&a->archive, ENOMEM, + "Unable to allocate memory for node data."); + return (ARCHIVE_FATAL); + } + + /* Set branches */ + code->tree[lastnode].branches[bit] = repeatnode; + code->tree[repeatnode].branches[bit] = repeatnode; + code->tree[repeatnode].branches[bit^1] = nextnode; + lastnode = nextnode; + + bitpos++; /* terminating bit already handled, skip it */ + } + else + { + /* Open branch check */ + if (code->tree[lastnode].branches[bit] < 0) + { + if (new_node(code) < 0) { + archive_set_error(&a->archive, ENOMEM, + "Unable to allocate memory for node data."); + return (ARCHIVE_FATAL); + } + code->tree[lastnode].branches[bit] = code->numentries++; + } + + /* set to branch */ + lastnode = code->tree[lastnode].branches[bit]; + } + } + + if (!(code->tree[lastnode].branches[0] == -1 + && code->tree[lastnode].branches[1] == -2)) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Prefix found"); + return (ARCHIVE_FATAL); + } + + /* Set leaf value */ + code->tree[lastnode].branches[0] = value; + code->tree[lastnode].branches[1] = value; + + return (ARCHIVE_OK); +} + +static int +new_node(struct huffman_code *code) +{ + void *new_tree; + if (code->numallocatedentries == code->numentries) { + int new_num_entries = 256; + if (code->numentries > 0) { + new_num_entries = code->numentries * 2; + } + new_tree = realloc(code->tree, new_num_entries * sizeof(*code->tree)); + if (new_tree == NULL) + return (-1); + code->tree = (struct huffman_tree_node *)new_tree; + code->numallocatedentries = new_num_entries; + } + code->tree[code->numentries].branches[0] = -1; + code->tree[code->numentries].branches[1] = -2; + return 1; +} + +static int +make_table(struct archive_read *a, struct huffman_code *code) +{ + if (code->maxlength < code->minlength || code->maxlength > 10) + code->tablesize = 10; + else + code->tablesize = code->maxlength; + + code->table = + (struct huffman_table_entry *)calloc(1, sizeof(*code->table) + * ((size_t)1 << code->tablesize)); + + return make_table_recurse(a, code, 0, code->table, 0, code->tablesize); +} + +static int +make_table_recurse(struct archive_read *a, struct huffman_code *code, int node, + struct huffman_table_entry *table, int depth, + int maxdepth) +{ + int currtablesize, i, ret = (ARCHIVE_OK); + + if (!code->tree) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Huffman tree was not created."); + return (ARCHIVE_FATAL); + } + if (node < 0 || node >= code->numentries) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid location to Huffman tree specified."); + return (ARCHIVE_FATAL); + } + + currtablesize = 1 << (maxdepth - depth); + + if (code->tree[node].branches[0] == + code->tree[node].branches[1]) + { + for(i = 0; i < currtablesize; i++) + { + table[i].length = depth; + table[i].value = code->tree[node].branches[0]; + } + } + else if (node < 0) + { + for(i = 0; i < currtablesize; i++) + table[i].length = -1; + } + else + { + if(depth == maxdepth) + { + table[0].length = maxdepth + 1; + table[0].value = node; + } + else + { + ret |= make_table_recurse(a, code, code->tree[node].branches[0], table, + depth + 1, maxdepth); + ret |= make_table_recurse(a, code, code->tree[node].branches[1], + table + currtablesize / 2, depth + 1, maxdepth); + } + } + return ret; +} + +static int64_t +expand(struct archive_read *a, int64_t end) +{ + static const unsigned char lengthbases[] = + { 0, 1, 2, 3, 4, 5, 6, + 7, 8, 10, 12, 14, 16, 20, + 24, 28, 32, 40, 48, 56, 64, + 80, 96, 112, 128, 160, 192, 224 }; + static const unsigned char lengthbits[] = + { 0, 0, 0, 0, 0, 0, 0, + 0, 1, 1, 1, 1, 2, 2, + 2, 2, 3, 3, 3, 3, 4, + 4, 4, 4, 5, 5, 5, 5 }; + static const unsigned int offsetbases[] = + { 0, 1, 2, 3, 4, 6, + 8, 12, 16, 24, 32, 48, + 64, 96, 128, 192, 256, 384, + 512, 768, 1024, 1536, 2048, 3072, + 4096, 6144, 8192, 12288, 16384, 24576, + 32768, 49152, 65536, 98304, 131072, 196608, + 262144, 327680, 393216, 458752, 524288, 589824, + 655360, 720896, 786432, 851968, 917504, 983040, + 1048576, 1310720, 1572864, 1835008, 2097152, 2359296, + 2621440, 2883584, 3145728, 3407872, 3670016, 3932160 }; + static const unsigned char offsetbits[] = + { 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, + 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, + 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18 }; + static const unsigned char shortbases[] = + { 0, 4, 8, 16, 32, 64, 128, 192 }; + static const unsigned char shortbits[] = + { 2, 2, 3, 4, 5, 6, 6, 6 }; + + int symbol, offs, len, offsindex, lensymbol, i, offssymbol, lowoffsetsymbol; + unsigned char newfile; + struct rar *rar = (struct rar *)(a->format->data); + struct rar_br *br = &(rar->br); + + if (rar->filterstart < end) + end = rar->filterstart; + + while (1) + { + if (rar->output_last_match && + lzss_position(&rar->lzss) + rar->lastlength <= end) + { + lzss_emit_match(rar, rar->lastoffset, rar->lastlength); + rar->output_last_match = 0; + } + + if(rar->is_ppmd_block || rar->output_last_match || + lzss_position(&rar->lzss) >= end) + return lzss_position(&rar->lzss); + + if ((symbol = read_next_symbol(a, &rar->maincode)) < 0) + return (ARCHIVE_FATAL); + rar->output_last_match = 0; + + if (symbol < 256) + { + lzss_emit_literal(rar, symbol); + continue; + } + else if (symbol == 256) + { + if (!rar_br_read_ahead(a, br, 1)) + goto truncated_data; + newfile = !rar_br_bits(br, 1); + rar_br_consume(br, 1); + + if(newfile) + { + rar->start_new_block = 1; + if (!rar_br_read_ahead(a, br, 1)) + goto truncated_data; + rar->start_new_table = rar_br_bits(br, 1); + rar_br_consume(br, 1); + return lzss_position(&rar->lzss); + } + else + { + if (parse_codes(a) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + continue; + } + } + else if(symbol==257) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Parsing filters is unsupported."); + return (ARCHIVE_FAILED); + } + else if(symbol==258) + { + if(rar->lastlength == 0) + continue; + + offs = rar->lastoffset; + len = rar->lastlength; + } + else if (symbol <= 262) + { + offsindex = symbol - 259; + offs = rar->oldoffset[offsindex]; + + if ((lensymbol = read_next_symbol(a, &rar->lengthcode)) < 0) + goto bad_data; + if (lensymbol > (int)(sizeof(lengthbases)/sizeof(lengthbases[0]))) + goto bad_data; + if (lensymbol > (int)(sizeof(lengthbits)/sizeof(lengthbits[0]))) + goto bad_data; + len = lengthbases[lensymbol] + 2; + if (lengthbits[lensymbol] > 0) { + if (!rar_br_read_ahead(a, br, lengthbits[lensymbol])) + goto truncated_data; + len += rar_br_bits(br, lengthbits[lensymbol]); + rar_br_consume(br, lengthbits[lensymbol]); + } + + for (i = offsindex; i > 0; i--) + rar->oldoffset[i] = rar->oldoffset[i-1]; + rar->oldoffset[0] = offs; + } + else if(symbol<=270) + { + offs = shortbases[symbol-263] + 1; + if(shortbits[symbol-263] > 0) { + if (!rar_br_read_ahead(a, br, shortbits[symbol-263])) + goto truncated_data; + offs += rar_br_bits(br, shortbits[symbol-263]); + rar_br_consume(br, shortbits[symbol-263]); + } + + len = 2; + + for(i = 3; i > 0; i--) + rar->oldoffset[i] = rar->oldoffset[i-1]; + rar->oldoffset[0] = offs; + } + else + { + if (symbol-271 > (int)(sizeof(lengthbases)/sizeof(lengthbases[0]))) + goto bad_data; + if (symbol-271 > (int)(sizeof(lengthbits)/sizeof(lengthbits[0]))) + goto bad_data; + len = lengthbases[symbol-271]+3; + if(lengthbits[symbol-271] > 0) { + if (!rar_br_read_ahead(a, br, lengthbits[symbol-271])) + goto truncated_data; + len += rar_br_bits(br, lengthbits[symbol-271]); + rar_br_consume(br, lengthbits[symbol-271]); + } + + if ((offssymbol = read_next_symbol(a, &rar->offsetcode)) < 0) + goto bad_data; + if (offssymbol > (int)(sizeof(offsetbases)/sizeof(offsetbases[0]))) + goto bad_data; + if (offssymbol > (int)(sizeof(offsetbits)/sizeof(offsetbits[0]))) + goto bad_data; + offs = offsetbases[offssymbol]+1; + if(offsetbits[offssymbol] > 0) + { + if(offssymbol > 9) + { + if(offsetbits[offssymbol] > 4) { + if (!rar_br_read_ahead(a, br, offsetbits[offssymbol] - 4)) + goto truncated_data; + offs += rar_br_bits(br, offsetbits[offssymbol] - 4) << 4; + rar_br_consume(br, offsetbits[offssymbol] - 4); + } + + if(rar->numlowoffsetrepeats > 0) + { + rar->numlowoffsetrepeats--; + offs += rar->lastlowoffset; + } + else + { + if ((lowoffsetsymbol = + read_next_symbol(a, &rar->lowoffsetcode)) < 0) + return (ARCHIVE_FATAL); + if(lowoffsetsymbol == 16) + { + rar->numlowoffsetrepeats = 15; + offs += rar->lastlowoffset; + } + else + { + offs += lowoffsetsymbol; + rar->lastlowoffset = lowoffsetsymbol; + } + } + } + else { + if (!rar_br_read_ahead(a, br, offsetbits[offssymbol])) + goto truncated_data; + offs += rar_br_bits(br, offsetbits[offssymbol]); + rar_br_consume(br, offsetbits[offssymbol]); + } + } + + if (offs >= 0x40000) + len++; + if (offs >= 0x2000) + len++; + + for(i = 3; i > 0; i--) + rar->oldoffset[i] = rar->oldoffset[i-1]; + rar->oldoffset[0] = offs; + } + + rar->lastoffset = offs; + rar->lastlength = len; + rar->output_last_match = 1; + } +truncated_data: + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated RAR file data"); + rar->valid = 0; + return (ARCHIVE_FATAL); +bad_data: + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Bad RAR file data"); + return (ARCHIVE_FATAL); +} + +static int +copy_from_lzss_window(struct archive_read *a, const void **buffer, + int64_t startpos, int length) +{ + int windowoffs, firstpart; + struct rar *rar = (struct rar *)(a->format->data); + + if (!rar->unp_buffer) + { + if ((rar->unp_buffer = malloc(rar->unp_buffer_size)) == NULL) + { + archive_set_error(&a->archive, ENOMEM, + "Unable to allocate memory for uncompressed data."); + return (ARCHIVE_FATAL); + } + } + + windowoffs = lzss_offset_for_position(&rar->lzss, startpos); + if(windowoffs + length <= lzss_size(&rar->lzss)) { + memcpy(&rar->unp_buffer[rar->unp_offset], &rar->lzss.window[windowoffs], + length); + } else if (length <= lzss_size(&rar->lzss)) { + firstpart = lzss_size(&rar->lzss) - windowoffs; + if (firstpart < 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Bad RAR file data"); + return (ARCHIVE_FATAL); + } + if (firstpart < length) { + memcpy(&rar->unp_buffer[rar->unp_offset], + &rar->lzss.window[windowoffs], firstpart); + memcpy(&rar->unp_buffer[rar->unp_offset + firstpart], + &rar->lzss.window[0], length - firstpart); + } else { + memcpy(&rar->unp_buffer[rar->unp_offset], + &rar->lzss.window[windowoffs], length); + } + } else { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Bad RAR file data"); + return (ARCHIVE_FATAL); + } + rar->unp_offset += length; + if (rar->unp_offset >= rar->unp_buffer_size) + *buffer = rar->unp_buffer; + else + *buffer = NULL; + return (ARCHIVE_OK); +} + +static const void * +rar_read_ahead(struct archive_read *a, size_t min, ssize_t *avail) +{ + struct rar *rar = (struct rar *)(a->format->data); + const void *h = __archive_read_ahead(a, min, avail); + int ret; + if (avail) + { + if (a->archive.read_data_is_posix_read && *avail > (ssize_t)a->archive.read_data_requested) + *avail = a->archive.read_data_requested; + if (*avail > rar->bytes_remaining) + *avail = (ssize_t)rar->bytes_remaining; + if (*avail < 0) + return NULL; + else if (*avail == 0 && rar->main_flags & MHD_VOLUME && + rar->file_flags & FHD_SPLIT_AFTER) + { + ret = archive_read_format_rar_read_header(a, a->entry); + if (ret == (ARCHIVE_EOF)) + { + rar->has_endarc_header = 1; + ret = archive_read_format_rar_read_header(a, a->entry); + } + if (ret != (ARCHIVE_OK)) + return NULL; + return rar_read_ahead(a, min, avail); + } + } + return h; +} diff --cc Utilities/cmlibarchive/libarchive/archive_read_support_format_xar.c index eeac1c8,0000000..9292ed7 mode 100644,000000..100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_xar.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_xar.c @@@ -1,3287 -1,0 +1,3301 @@@ +/*- + * Copyright (c) 2009 Michihiro NAKAJIMA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "archive_platform.h" +__FBSDID("$FreeBSD$"); + +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#if HAVE_LIBXML_XMLREADER_H +#include +#elif HAVE_BSDXML_H +#include +#elif HAVE_EXPAT_H +#include +#endif +#ifdef HAVE_BZLIB_H +#include +#endif +#if HAVE_LZMA_H +#include +#endif +#ifdef HAVE_ZLIB_H +#include +#endif + +#include "archive.h" +#include "archive_digest_private.h" +#include "archive_endian.h" +#include "archive_entry.h" +#include "archive_entry_locale.h" +#include "archive_private.h" +#include "archive_read_private.h" + +#if (!defined(HAVE_LIBXML_XMLREADER_H) && \ + !defined(HAVE_BSDXML_H) && !defined(HAVE_EXPAT_H)) ||\ + !defined(HAVE_ZLIB_H) || \ + !defined(ARCHIVE_HAS_MD5) || !defined(ARCHIVE_HAS_SHA1) +/* + * xar needs several external libraries. + * o libxml2 or expat --- XML parser + * o openssl or MD5/SHA1 hash function + * o zlib + * o bzlib2 (option) + * o liblzma (option) + */ +int +archive_read_support_format_xar(struct archive *_a) +{ + struct archive_read *a = (struct archive_read *)_a; + archive_check_magic(_a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_format_xar"); + + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Xar not supported on this platform"); + return (ARCHIVE_WARN); +} + +#else /* Support xar format */ + +/* #define DEBUG 1 */ +/* #define DEBUG_PRINT_TOC 1 */ +#if DEBUG_PRINT_TOC +#define PRINT_TOC(d, outbytes) do { \ + unsigned char *x = (unsigned char *)(uintptr_t)d; \ + unsigned char c = x[outbytes-1]; \ + x[outbytes - 1] = 0; \ + fprintf(stderr, "%s", x); \ + fprintf(stderr, "%c", c); \ + x[outbytes - 1] = c; \ +} while (0) +#else +#define PRINT_TOC(d, outbytes) +#endif + +#define HEADER_MAGIC 0x78617221 +#define HEADER_SIZE 28 +#define HEADER_VERSION 1 +#define CKSUM_NONE 0 +#define CKSUM_SHA1 1 +#define CKSUM_MD5 2 + +#define MD5_SIZE 16 +#define SHA1_SIZE 20 +#define MAX_SUM_SIZE 20 + +enum enctype { + NONE, + GZIP, + BZIP2, + LZMA, + XZ, +}; + +struct chksumval { + int alg; + size_t len; + unsigned char val[MAX_SUM_SIZE]; +}; + +struct chksumwork { + int alg; +#ifdef ARCHIVE_HAS_MD5 + archive_md5_ctx md5ctx; +#endif +#ifdef ARCHIVE_HAS_SHA1 + archive_sha1_ctx sha1ctx; +#endif +}; + +struct xattr { + struct xattr *next; + struct archive_string name; + uint64_t id; + uint64_t length; + uint64_t offset; + uint64_t size; + enum enctype encoding; + struct chksumval a_sum; + struct chksumval e_sum; + struct archive_string fstype; +}; + +struct xar_file { + struct xar_file *next; + struct xar_file *hdnext; + struct xar_file *parent; + int subdirs; + + unsigned int has; +#define HAS_DATA 0x00001 +#define HAS_PATHNAME 0x00002 +#define HAS_SYMLINK 0x00004 +#define HAS_TIME 0x00008 +#define HAS_UID 0x00010 +#define HAS_GID 0x00020 +#define HAS_MODE 0x00040 +#define HAS_TYPE 0x00080 +#define HAS_DEV 0x00100 +#define HAS_DEVMAJOR 0x00200 +#define HAS_DEVMINOR 0x00400 +#define HAS_INO 0x00800 +#define HAS_FFLAGS 0x01000 +#define HAS_XATTR 0x02000 +#define HAS_ACL 0x04000 + + uint64_t id; + uint64_t length; + uint64_t offset; + uint64_t size; + enum enctype encoding; + struct chksumval a_sum; + struct chksumval e_sum; + struct archive_string pathname; + struct archive_string symlink; + time_t ctime; + time_t mtime; + time_t atime; + struct archive_string uname; + int64_t uid; + struct archive_string gname; + int64_t gid; + mode_t mode; + dev_t dev; + dev_t devmajor; + dev_t devminor; + int64_t ino64; + struct archive_string fflags_text; + unsigned int link; + unsigned int nlink; + struct archive_string hardlink; + struct xattr *xattr_list; +}; + +struct hdlink { + struct hdlink *next; + + unsigned int id; + int cnt; + struct xar_file *files; +}; + +struct heap_queue { + struct xar_file **files; + int allocated; + int used; +}; + +enum xmlstatus { + INIT, + XAR, + TOC, + TOC_CREATION_TIME, + TOC_CHECKSUM, + TOC_CHECKSUM_OFFSET, + TOC_CHECKSUM_SIZE, + TOC_FILE, + FILE_DATA, + FILE_DATA_LENGTH, + FILE_DATA_OFFSET, + FILE_DATA_SIZE, + FILE_DATA_ENCODING, + FILE_DATA_A_CHECKSUM, + FILE_DATA_E_CHECKSUM, + FILE_DATA_CONTENT, + FILE_EA, + FILE_EA_LENGTH, + FILE_EA_OFFSET, + FILE_EA_SIZE, + FILE_EA_ENCODING, + FILE_EA_A_CHECKSUM, + FILE_EA_E_CHECKSUM, + FILE_EA_NAME, + FILE_EA_FSTYPE, + FILE_CTIME, + FILE_MTIME, + FILE_ATIME, + FILE_GROUP, + FILE_GID, + FILE_USER, + FILE_UID, + FILE_MODE, + FILE_DEVICE, + FILE_DEVICE_MAJOR, + FILE_DEVICE_MINOR, + FILE_DEVICENO, + FILE_INODE, + FILE_LINK, + FILE_TYPE, + FILE_NAME, + FILE_ACL, + FILE_ACL_DEFAULT, + FILE_ACL_ACCESS, + FILE_ACL_APPLEEXTENDED, + /* BSD file flags. */ + FILE_FLAGS, + FILE_FLAGS_USER_NODUMP, + FILE_FLAGS_USER_IMMUTABLE, + FILE_FLAGS_USER_APPEND, + FILE_FLAGS_USER_OPAQUE, + FILE_FLAGS_USER_NOUNLINK, + FILE_FLAGS_SYS_ARCHIVED, + FILE_FLAGS_SYS_IMMUTABLE, + FILE_FLAGS_SYS_APPEND, + FILE_FLAGS_SYS_NOUNLINK, + FILE_FLAGS_SYS_SNAPSHOT, + /* Linux file flags. */ + FILE_EXT2, + FILE_EXT2_SecureDeletion, + FILE_EXT2_Undelete, + FILE_EXT2_Compress, + FILE_EXT2_Synchronous, + FILE_EXT2_Immutable, + FILE_EXT2_AppendOnly, + FILE_EXT2_NoDump, + FILE_EXT2_NoAtime, + FILE_EXT2_CompDirty, + FILE_EXT2_CompBlock, + FILE_EXT2_NoCompBlock, + FILE_EXT2_CompError, + FILE_EXT2_BTree, + FILE_EXT2_HashIndexed, + FILE_EXT2_iMagic, + FILE_EXT2_Journaled, + FILE_EXT2_NoTail, + FILE_EXT2_DirSync, + FILE_EXT2_TopDir, + FILE_EXT2_Reserved, + UNKNOWN, +}; + +struct unknown_tag { + struct unknown_tag *next; + struct archive_string name; +}; + +struct xar { + uint64_t offset; /* Current position in the file. */ + int64_t total; + uint64_t h_base; + int end_of_file; +#define OUTBUFF_SIZE (1024 * 64) + unsigned char *outbuff; + + enum xmlstatus xmlsts; + enum xmlstatus xmlsts_unknown; + struct unknown_tag *unknowntags; + int base64text; + + /* + * TOC + */ + uint64_t toc_remaining; + uint64_t toc_total; + uint64_t toc_chksum_offset; + uint64_t toc_chksum_size; + + /* + * For Decoding data. + */ + enum enctype rd_encoding; + z_stream stream; + int stream_valid; +#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) + bz_stream bzstream; + int bzstream_valid; +#endif +#if HAVE_LZMA_H && HAVE_LIBLZMA + lzma_stream lzstream; + int lzstream_valid; +#endif + /* + * For Checksum data. + */ + struct chksumwork a_sumwrk; + struct chksumwork e_sumwrk; + + struct xar_file *file; /* current reading file. */ + struct xattr *xattr; /* current reading extended attribute. */ + struct heap_queue file_queue; + struct xar_file *hdlink_orgs; + struct hdlink *hdlink_list; + + int entry_init; + uint64_t entry_total; + uint64_t entry_remaining; + size_t entry_unconsumed; + uint64_t entry_size; + enum enctype entry_encoding; + struct chksumval entry_a_sum; + struct chksumval entry_e_sum; + + struct archive_string_conv *sconv; +}; + +struct xmlattr { + struct xmlattr *next; + char *name; + char *value; +}; + +struct xmlattr_list { + struct xmlattr *first; + struct xmlattr **last; +}; + +static int xar_bid(struct archive_read *, int); +static int xar_read_header(struct archive_read *, + struct archive_entry *); +static int xar_read_data(struct archive_read *, + const void **, size_t *, int64_t *); +static int xar_read_data_skip(struct archive_read *); +static int xar_cleanup(struct archive_read *); +static int move_reading_point(struct archive_read *, uint64_t); +static int rd_contents_init(struct archive_read *, + enum enctype, int, int); +static int rd_contents(struct archive_read *, const void **, + size_t *, size_t *, uint64_t); +static uint64_t atol10(const char *, size_t); +static int64_t atol8(const char *, size_t); +static size_t atohex(unsigned char *, size_t, const char *, size_t); +static time_t parse_time(const char *p, size_t n); +static int heap_add_entry(struct archive_read *a, + struct heap_queue *, struct xar_file *); +static struct xar_file *heap_get_entry(struct heap_queue *); +static int add_link(struct archive_read *, + struct xar *, struct xar_file *); +static void checksum_init(struct archive_read *, int, int); +static void checksum_update(struct archive_read *, const void *, + size_t, const void *, size_t); +static int checksum_final(struct archive_read *, const void *, + size_t, const void *, size_t); +static void checksum_cleanup(struct archive_read *); +static int decompression_init(struct archive_read *, enum enctype); +static int decompress(struct archive_read *, const void **, + size_t *, const void *, size_t *); +static int decompression_cleanup(struct archive_read *); +static void xmlattr_cleanup(struct xmlattr_list *); +static int file_new(struct archive_read *, + struct xar *, struct xmlattr_list *); +static void file_free(struct xar_file *); +static int xattr_new(struct archive_read *, + struct xar *, struct xmlattr_list *); +static void xattr_free(struct xattr *); +static int getencoding(struct xmlattr_list *); +static int getsumalgorithm(struct xmlattr_list *); +static int unknowntag_start(struct archive_read *, + struct xar *, const char *); +static void unknowntag_end(struct xar *, const char *); +static int xml_start(struct archive_read *, + const char *, struct xmlattr_list *); +static void xml_end(void *, const char *); +static void xml_data(void *, const char *, int); +static int xml_parse_file_flags(struct xar *, const char *); +static int xml_parse_file_ext2(struct xar *, const char *); +#if defined(HAVE_LIBXML_XMLREADER_H) +static int xml2_xmlattr_setup(struct archive_read *, + struct xmlattr_list *, xmlTextReaderPtr); +static int xml2_read_cb(void *, char *, int); +static int xml2_close_cb(void *); +static void xml2_error_hdr(void *, const char *, xmlParserSeverities, + xmlTextReaderLocatorPtr); +static int xml2_read_toc(struct archive_read *); +#elif defined(HAVE_BSDXML_H) || defined(HAVE_EXPAT_H) +struct expat_userData { + int state; + struct archive_read *archive; +}; +static int expat_xmlattr_setup(struct archive_read *, + struct xmlattr_list *, const XML_Char **); +static void expat_start_cb(void *, const XML_Char *, const XML_Char **); +static void expat_end_cb(void *, const XML_Char *); +static void expat_data_cb(void *, const XML_Char *, int); +static int expat_read_toc(struct archive_read *); +#endif + +int +archive_read_support_format_xar(struct archive *_a) +{ + struct xar *xar; + struct archive_read *a = (struct archive_read *)_a; + int r; + + archive_check_magic(_a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_format_xar"); + + xar = (struct xar *)calloc(1, sizeof(*xar)); + if (xar == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate xar data"); + return (ARCHIVE_FATAL); + } + + r = __archive_read_register_format(a, + xar, + "xar", + xar_bid, + NULL, + xar_read_header, + xar_read_data, + xar_read_data_skip, + NULL, + xar_cleanup, + NULL, + NULL); + if (r != ARCHIVE_OK) + free(xar); + return (r); +} + +static int +xar_bid(struct archive_read *a, int best_bid) +{ + const unsigned char *b; + int bid; + + (void)best_bid; /* UNUSED */ + + b = __archive_read_ahead(a, HEADER_SIZE, NULL); + if (b == NULL) + return (-1); + + bid = 0; + /* + * Verify magic code + */ + if (archive_be32dec(b) != HEADER_MAGIC) + return (0); + bid += 32; + /* + * Verify header size + */ + if (archive_be16dec(b+4) != HEADER_SIZE) + return (0); + bid += 16; + /* + * Verify header version + */ + if (archive_be16dec(b+6) != HEADER_VERSION) + return (0); + bid += 16; + /* + * Verify type of checksum + */ + switch (archive_be32dec(b+24)) { + case CKSUM_NONE: + case CKSUM_SHA1: + case CKSUM_MD5: + bid += 32; + break; + default: + return (0); + } + + return (bid); +} + +static int +read_toc(struct archive_read *a) +{ + struct xar *xar; + struct xar_file *file; + const unsigned char *b; + uint64_t toc_compressed_size; + uint64_t toc_uncompressed_size; + uint32_t toc_chksum_alg; + ssize_t bytes; + int r; + + xar = (struct xar *)(a->format->data); + + /* + * Read xar header. + */ + b = __archive_read_ahead(a, HEADER_SIZE, &bytes); + if (bytes < 0) + return ((int)bytes); + if (bytes < HEADER_SIZE) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated archive header"); + return (ARCHIVE_FATAL); + } + + if (archive_be32dec(b) != HEADER_MAGIC) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid header magic"); + return (ARCHIVE_FATAL); + } + if (archive_be16dec(b+6) != HEADER_VERSION) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Unsupported header version(%d)", + archive_be16dec(b+6)); + return (ARCHIVE_FATAL); + } + toc_compressed_size = archive_be64dec(b+8); + xar->toc_remaining = toc_compressed_size; + toc_uncompressed_size = archive_be64dec(b+16); + toc_chksum_alg = archive_be32dec(b+24); + __archive_read_consume(a, HEADER_SIZE); + xar->offset += HEADER_SIZE; + xar->toc_total = 0; + + /* + * Read TOC(Table of Contents). + */ + /* Initialize reading contents. */ + r = move_reading_point(a, HEADER_SIZE); + if (r != ARCHIVE_OK) + return (r); + r = rd_contents_init(a, GZIP, toc_chksum_alg, CKSUM_NONE); + if (r != ARCHIVE_OK) + return (r); + +#ifdef HAVE_LIBXML_XMLREADER_H + r = xml2_read_toc(a); +#elif defined(HAVE_BSDXML_H) || defined(HAVE_EXPAT_H) + r = expat_read_toc(a); +#endif + if (r != ARCHIVE_OK) + return (r); + + /* Set 'The HEAP' base. */ + xar->h_base = xar->offset; + if (xar->toc_total != toc_uncompressed_size) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "TOC uncompressed size error"); + return (ARCHIVE_FATAL); + } + + /* + * Checksum TOC + */ + if (toc_chksum_alg != CKSUM_NONE) { + r = move_reading_point(a, xar->toc_chksum_offset); + if (r != ARCHIVE_OK) + return (r); + b = __archive_read_ahead(a, + (size_t)xar->toc_chksum_size, &bytes); + if (bytes < 0) + return ((int)bytes); + if ((uint64_t)bytes < xar->toc_chksum_size) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated archive file"); + return (ARCHIVE_FATAL); + } + r = checksum_final(a, b, + (size_t)xar->toc_chksum_size, NULL, 0); + __archive_read_consume(a, xar->toc_chksum_size); + xar->offset += xar->toc_chksum_size; + if (r != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } + + /* + * Connect hardlinked files. + */ + for (file = xar->hdlink_orgs; file != NULL; file = file->hdnext) { + struct hdlink **hdlink; + + for (hdlink = &(xar->hdlink_list); *hdlink != NULL; + hdlink = &((*hdlink)->next)) { + if ((*hdlink)->id == file->id) { + struct hdlink *hltmp; + struct xar_file *f2; + int nlink = (*hdlink)->cnt + 1; + + file->nlink = nlink; + for (f2 = (*hdlink)->files; f2 != NULL; + f2 = f2->hdnext) { + f2->nlink = nlink; + archive_string_copy( + &(f2->hardlink), &(file->pathname)); + } + /* Remove resolved files from hdlist_list. */ + hltmp = *hdlink; + *hdlink = hltmp->next; + free(hltmp); + break; + } + } + } + a->archive.archive_format = ARCHIVE_FORMAT_XAR; + a->archive.archive_format_name = "xar"; + + return (ARCHIVE_OK); +} + +static int +xar_read_header(struct archive_read *a, struct archive_entry *entry) +{ + struct xar *xar; + struct xar_file *file; + struct xattr *xattr; + int r; + + xar = (struct xar *)(a->format->data); + r = ARCHIVE_OK; + + if (xar->offset == 0) { + /* Create a character conversion object. */ + if (xar->sconv == NULL) { + xar->sconv = archive_string_conversion_from_charset( + &(a->archive), "UTF-8", 1); + if (xar->sconv == NULL) + return (ARCHIVE_FATAL); + } + + /* Read TOC. */ + r = read_toc(a); + if (r != ARCHIVE_OK) + return (r); + } + + for (;;) { + file = xar->file = heap_get_entry(&(xar->file_queue)); + if (file == NULL) { + xar->end_of_file = 1; + return (ARCHIVE_EOF); + } + if ((file->mode & AE_IFMT) != AE_IFDIR) + break; + if (file->has != (HAS_PATHNAME | HAS_TYPE)) + break; + /* + * If a file type is a directory and it does not have + * any metadata, do not export. + */ + file_free(file); + } + archive_entry_set_atime(entry, file->atime, 0); + archive_entry_set_ctime(entry, file->ctime, 0); + archive_entry_set_mtime(entry, file->mtime, 0); + archive_entry_set_gid(entry, file->gid); + if (file->gname.length > 0 && + archive_entry_copy_gname_l(entry, file->gname.s, + archive_strlen(&(file->gname)), xar->sconv) != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Gname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Gname cannot be converted from %s to current locale.", + archive_string_conversion_charset_name(xar->sconv)); + r = ARCHIVE_WARN; + } + archive_entry_set_uid(entry, file->uid); + if (file->uname.length > 0 && + archive_entry_copy_uname_l(entry, file->uname.s, + archive_strlen(&(file->uname)), xar->sconv) != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Uname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Uname cannot be converted from %s to current locale.", + archive_string_conversion_charset_name(xar->sconv)); + r = ARCHIVE_WARN; + } + archive_entry_set_mode(entry, file->mode); + if (archive_entry_copy_pathname_l(entry, file->pathname.s, + archive_strlen(&(file->pathname)), xar->sconv) != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Pathname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Pathname cannot be converted from %s to current locale.", + archive_string_conversion_charset_name(xar->sconv)); + r = ARCHIVE_WARN; + } + + + if (file->symlink.length > 0 && + archive_entry_copy_symlink_l(entry, file->symlink.s, + archive_strlen(&(file->symlink)), xar->sconv) != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Linkname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Linkname cannot be converted from %s to current locale.", + archive_string_conversion_charset_name(xar->sconv)); + r = ARCHIVE_WARN; + } + /* Set proper nlink. */ + if ((file->mode & AE_IFMT) == AE_IFDIR) + archive_entry_set_nlink(entry, file->subdirs + 2); + else + archive_entry_set_nlink(entry, file->nlink); + archive_entry_set_size(entry, file->size); + if (archive_strlen(&(file->hardlink)) > 0) + archive_entry_set_hardlink(entry, file->hardlink.s); + archive_entry_set_ino64(entry, file->ino64); + if (file->has & HAS_DEV) + archive_entry_set_dev(entry, file->dev); + if (file->has & HAS_DEVMAJOR) + archive_entry_set_devmajor(entry, file->devmajor); + if (file->has & HAS_DEVMINOR) + archive_entry_set_devminor(entry, file->devminor); + if (archive_strlen(&(file->fflags_text)) > 0) + archive_entry_copy_fflags_text(entry, file->fflags_text.s); + + xar->entry_init = 1; + xar->entry_total = 0; + xar->entry_remaining = file->length; + xar->entry_size = file->size; + xar->entry_encoding = file->encoding; + xar->entry_a_sum = file->a_sum; + xar->entry_e_sum = file->e_sum; + /* + * Read extended attributes. + */ + xattr = file->xattr_list; + while (xattr != NULL) { + const void *d; + size_t outbytes, used; + + r = move_reading_point(a, xattr->offset); + if (r != ARCHIVE_OK) + break; + r = rd_contents_init(a, xattr->encoding, + xattr->a_sum.alg, xattr->e_sum.alg); + if (r != ARCHIVE_OK) + break; + d = NULL; + r = rd_contents(a, &d, &outbytes, &used, xattr->length); + if (r != ARCHIVE_OK) + break; + if (outbytes != xattr->size) { + archive_set_error(&(a->archive), ARCHIVE_ERRNO_MISC, + "Decompressed size error"); + r = ARCHIVE_FATAL; + break; + } + r = checksum_final(a, + xattr->a_sum.val, xattr->a_sum.len, + xattr->e_sum.val, xattr->e_sum.len); + if (r != ARCHIVE_OK) + break; + archive_entry_xattr_add_entry(entry, + xattr->name.s, d, outbytes); + xattr = xattr->next; + } + if (r != ARCHIVE_OK) { + file_free(file); + return (r); + } + + if (xar->entry_remaining > 0) + /* Move reading point to the beginning of current + * file contents. */ + r = move_reading_point(a, file->offset); + else + r = ARCHIVE_OK; + + file_free(file); + return (r); +} + +static int +xar_read_data(struct archive_read *a, + const void **buff, size_t *size, int64_t *offset) +{ + struct xar *xar; + size_t used; + int r; + + xar = (struct xar *)(a->format->data); + + if (xar->entry_unconsumed) { + __archive_read_consume(a, xar->entry_unconsumed); + xar->entry_unconsumed = 0; + } + + if (xar->end_of_file || xar->entry_remaining <= 0) { + r = ARCHIVE_EOF; + goto abort_read_data; + } + + if (xar->entry_init) { + r = rd_contents_init(a, xar->entry_encoding, + xar->entry_a_sum.alg, xar->entry_e_sum.alg); + if (r != ARCHIVE_OK) { + xar->entry_remaining = 0; + return (r); + } + xar->entry_init = 0; + } + + *buff = NULL; + r = rd_contents(a, buff, size, &used, xar->entry_remaining); + if (r != ARCHIVE_OK) + goto abort_read_data; + + *offset = xar->entry_total; + xar->entry_total += *size; + xar->total += *size; + xar->offset += used; + xar->entry_remaining -= used; + xar->entry_unconsumed = used; + + if (xar->entry_remaining == 0) { + if (xar->entry_total != xar->entry_size) { + archive_set_error(&(a->archive), ARCHIVE_ERRNO_MISC, + "Decompressed size error"); + r = ARCHIVE_FATAL; + goto abort_read_data; + } + r = checksum_final(a, + xar->entry_a_sum.val, xar->entry_a_sum.len, + xar->entry_e_sum.val, xar->entry_e_sum.len); + if (r != ARCHIVE_OK) + goto abort_read_data; + } + + return (ARCHIVE_OK); +abort_read_data: + *buff = NULL; + *size = 0; + *offset = xar->total; + return (r); +} + +static int +xar_read_data_skip(struct archive_read *a) +{ + struct xar *xar; + int64_t bytes_skipped; + + xar = (struct xar *)(a->format->data); + if (xar->end_of_file) + return (ARCHIVE_EOF); + bytes_skipped = __archive_read_consume(a, xar->entry_remaining + + xar->entry_unconsumed); + if (bytes_skipped < 0) + return (ARCHIVE_FATAL); + xar->offset += bytes_skipped; + xar->entry_unconsumed = 0; + return (ARCHIVE_OK); +} + +static int +xar_cleanup(struct archive_read *a) +{ + struct xar *xar; + struct hdlink *hdlink; + int i; + int r; + + xar = (struct xar *)(a->format->data); + checksum_cleanup(a); + r = decompression_cleanup(a); + hdlink = xar->hdlink_list; + while (hdlink != NULL) { + struct hdlink *next = hdlink->next; + + free(hdlink); + hdlink = next; + } + for (i = 0; i < xar->file_queue.used; i++) + file_free(xar->file_queue.files[i]); + free(xar->file_queue.files); + while (xar->unknowntags != NULL) { + struct unknown_tag *tag; + + tag = xar->unknowntags; + xar->unknowntags = tag->next; + archive_string_free(&(tag->name)); + free(tag); + } + free(xar->outbuff); + free(xar); + a->format->data = NULL; + return (r); +} + +static int +move_reading_point(struct archive_read *a, uint64_t offset) +{ + struct xar *xar; + + xar = (struct xar *)(a->format->data); + if (xar->offset - xar->h_base != offset) { + /* Seek forward to the start of file contents. */ + int64_t step; + + step = offset - (xar->offset - xar->h_base); + if (step > 0) { + step = __archive_read_consume(a, step); + if (step < 0) + return ((int)step); + xar->offset += step; + } else { + int64_t pos = __archive_read_seek(a, offset, SEEK_SET); + if (pos == ARCHIVE_FAILED) { + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "Cannot seek."); + return (ARCHIVE_FAILED); + } + xar->offset = pos; + } + } + return (ARCHIVE_OK); +} + +static int +rd_contents_init(struct archive_read *a, enum enctype encoding, + int a_sum_alg, int e_sum_alg) +{ + int r; + + /* Init decompress library. */ + if ((r = decompression_init(a, encoding)) != ARCHIVE_OK) + return (r); + /* Init checksum library. */ + checksum_init(a, a_sum_alg, e_sum_alg); + return (ARCHIVE_OK); +} + +static int +rd_contents(struct archive_read *a, const void **buff, size_t *size, + size_t *used, uint64_t remaining) +{ + const unsigned char *b; + ssize_t bytes; + + /* Get whatever bytes are immediately available. */ + b = __archive_read_ahead(a, 1, &bytes); + if (bytes < 0) + return ((int)bytes); + if (bytes == 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Truncated archive file"); + return (ARCHIVE_FATAL); + } + if ((uint64_t)bytes > remaining) + bytes = (ssize_t)remaining; + + /* + * Decompress contents of file. + */ + *used = bytes; + if (decompress(a, buff, size, b, used) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + /* + * Update checksum of a compressed data and a extracted data. + */ + checksum_update(a, b, *used, *buff, *size); + + return (ARCHIVE_OK); +} + +/* + * Note that this implementation does not (and should not!) obey + * locale settings; you cannot simply substitute strtol here, since + * it does obey locale. + */ + +static uint64_t +atol10(const char *p, size_t char_cnt) +{ + uint64_t l; + int digit; + ++ if (char_cnt == 0) ++ return (0); ++ + l = 0; + digit = *p - '0'; + while (digit >= 0 && digit < 10 && char_cnt-- > 0) { + l = (l * 10) + digit; + digit = *++p - '0'; + } + return (l); +} + +static int64_t +atol8(const char *p, size_t char_cnt) +{ + int64_t l; + int digit; - ++ ++ if (char_cnt == 0) ++ return (0); ++ + l = 0; + while (char_cnt-- > 0) { + if (*p >= '0' && *p <= '7') + digit = *p - '0'; + else + break; + p++; + l <<= 3; + l |= digit; + } + return (l); +} + +static size_t +atohex(unsigned char *b, size_t bsize, const char *p, size_t psize) +{ + size_t fbsize = bsize; + + while (bsize && psize > 1) { + unsigned char x; + + if (p[0] >= 'a' && p[0] <= 'z') + x = (p[0] - 'a' + 0x0a) << 4; + else if (p[0] >= 'A' && p[0] <= 'Z') + x = (p[0] - 'A' + 0x0a) << 4; + else if (p[0] >= '0' && p[0] <= '9') + x = (p[0] - '0') << 4; + else + return (-1); + if (p[1] >= 'a' && p[1] <= 'z') + x |= p[1] - 'a' + 0x0a; + else if (p[1] >= 'A' && p[1] <= 'Z') + x |= p[1] - 'A' + 0x0a; + else if (p[1] >= '0' && p[1] <= '9') + x |= p[1] - '0'; + else + return (-1); + + *b++ = x; + bsize--; + p += 2; + psize -= 2; + } + return (fbsize - bsize); +} + +static time_t +time_from_tm(struct tm *t) +{ +#if HAVE_TIMEGM + /* Use platform timegm() if available. */ + return (timegm(t)); +#elif HAVE__MKGMTIME64 + return (_mkgmtime64(t)); +#else + /* Else use direct calculation using POSIX assumptions. */ + /* First, fix up tm_yday based on the year/month/day. */ + mktime(t); + /* Then we can compute timegm() from first principles. */ + return (t->tm_sec + + t->tm_min * 60 + + t->tm_hour * 3600 + + t->tm_yday * 86400 + + (t->tm_year - 70) * 31536000 + + ((t->tm_year - 69) / 4) * 86400 + - ((t->tm_year - 1) / 100) * 86400 + + ((t->tm_year + 299) / 400) * 86400); +#endif +} + +static time_t +parse_time(const char *p, size_t n) +{ + struct tm tm; + time_t t = 0; + int64_t data; + + memset(&tm, 0, sizeof(tm)); + if (n != 20) + return (t); + data = atol10(p, 4); + if (data < 1900) + return (t); + tm.tm_year = (int)data - 1900; + p += 4; + if (*p++ != '-') + return (t); + data = atol10(p, 2); + if (data < 1 || data > 12) + return (t); + tm.tm_mon = (int)data -1; + p += 2; + if (*p++ != '-') + return (t); + data = atol10(p, 2); + if (data < 1 || data > 31) + return (t); + tm.tm_mday = (int)data; + p += 2; + if (*p++ != 'T') + return (t); + data = atol10(p, 2); + if (data < 0 || data > 23) + return (t); + tm.tm_hour = (int)data; + p += 2; + if (*p++ != ':') + return (t); + data = atol10(p, 2); + if (data < 0 || data > 59) + return (t); + tm.tm_min = (int)data; + p += 2; + if (*p++ != ':') + return (t); + data = atol10(p, 2); + if (data < 0 || data > 60) + return (t); + tm.tm_sec = (int)data; +#if 0 + p += 2; + if (*p != 'Z') + return (t); +#endif + + t = time_from_tm(&tm); + + return (t); +} + +static int +heap_add_entry(struct archive_read *a, + struct heap_queue *heap, struct xar_file *file) +{ + uint64_t file_id, parent_id; + int hole, parent; + + /* Expand our pending files list as necessary. */ + if (heap->used >= heap->allocated) { + struct xar_file **new_pending_files; + int new_size = heap->allocated * 2; + + if (heap->allocated < 1024) + new_size = 1024; + /* Overflow might keep us from growing the list. */ + if (new_size <= heap->allocated) { + archive_set_error(&a->archive, + ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + new_pending_files = (struct xar_file **) + malloc(new_size * sizeof(new_pending_files[0])); + if (new_pending_files == NULL) { + archive_set_error(&a->archive, + ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + memcpy(new_pending_files, heap->files, + heap->allocated * sizeof(new_pending_files[0])); + if (heap->files != NULL) + free(heap->files); + heap->files = new_pending_files; + heap->allocated = new_size; + } + + file_id = file->id; + + /* + * Start with hole at end, walk it up tree to find insertion point. + */ + hole = heap->used++; + while (hole > 0) { + parent = (hole - 1)/2; + parent_id = heap->files[parent]->id; + if (file_id >= parent_id) { + heap->files[hole] = file; + return (ARCHIVE_OK); + } + /* Move parent into hole <==> move hole up tree. */ + heap->files[hole] = heap->files[parent]; + hole = parent; + } + heap->files[0] = file; + + return (ARCHIVE_OK); +} + +static struct xar_file * +heap_get_entry(struct heap_queue *heap) +{ + uint64_t a_id, b_id, c_id; + int a, b, c; + struct xar_file *r, *tmp; + + if (heap->used < 1) + return (NULL); + + /* + * The first file in the list is the earliest; we'll return this. + */ + r = heap->files[0]; + + /* + * Move the last item in the heap to the root of the tree + */ + heap->files[0] = heap->files[--(heap->used)]; + + /* + * Rebalance the heap. + */ + a = 0; /* Starting element and its heap key */ + a_id = heap->files[a]->id; + for (;;) { + b = a + a + 1; /* First child */ + if (b >= heap->used) + return (r); + b_id = heap->files[b]->id; + c = b + 1; /* Use second child if it is smaller. */ + if (c < heap->used) { + c_id = heap->files[c]->id; + if (c_id < b_id) { + b = c; + b_id = c_id; + } + } + if (a_id <= b_id) + return (r); + tmp = heap->files[a]; + heap->files[a] = heap->files[b]; + heap->files[b] = tmp; + a = b; + } +} + +static int +add_link(struct archive_read *a, struct xar *xar, struct xar_file *file) +{ + struct hdlink *hdlink; + + for (hdlink = xar->hdlink_list; hdlink != NULL; hdlink = hdlink->next) { + if (hdlink->id == file->link) { + file->hdnext = hdlink->files; + hdlink->cnt++; + hdlink->files = file; + return (ARCHIVE_OK); + } + } + hdlink = malloc(sizeof(*hdlink)); + if (hdlink == NULL) { + archive_set_error(&a->archive, ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + file->hdnext = NULL; + hdlink->id = file->link; + hdlink->cnt = 1; + hdlink->files = file; + hdlink->next = xar->hdlink_list; + xar->hdlink_list = hdlink; + return (ARCHIVE_OK); +} + +static void +_checksum_init(struct chksumwork *sumwrk, int sum_alg) +{ + sumwrk->alg = sum_alg; + switch (sum_alg) { + case CKSUM_NONE: + break; + case CKSUM_SHA1: + archive_sha1_init(&(sumwrk->sha1ctx)); + break; + case CKSUM_MD5: + archive_md5_init(&(sumwrk->md5ctx)); + break; + } +} + +static void +_checksum_update(struct chksumwork *sumwrk, const void *buff, size_t size) +{ + + switch (sumwrk->alg) { + case CKSUM_NONE: + break; + case CKSUM_SHA1: + archive_sha1_update(&(sumwrk->sha1ctx), buff, size); + break; + case CKSUM_MD5: + archive_md5_update(&(sumwrk->md5ctx), buff, size); + break; + } +} + +static int +_checksum_final(struct chksumwork *sumwrk, const void *val, size_t len) +{ + unsigned char sum[MAX_SUM_SIZE]; + int r = ARCHIVE_OK; + + switch (sumwrk->alg) { + case CKSUM_NONE: + break; + case CKSUM_SHA1: + archive_sha1_final(&(sumwrk->sha1ctx), sum); + if (len != SHA1_SIZE || + memcmp(val, sum, SHA1_SIZE) != 0) + r = ARCHIVE_FAILED; + break; + case CKSUM_MD5: + archive_md5_final(&(sumwrk->md5ctx), sum); + if (len != MD5_SIZE || + memcmp(val, sum, MD5_SIZE) != 0) + r = ARCHIVE_FAILED; + break; + } + return (r); +} + +static void +checksum_init(struct archive_read *a, int a_sum_alg, int e_sum_alg) +{ + struct xar *xar; + + xar = (struct xar *)(a->format->data); + _checksum_init(&(xar->a_sumwrk), a_sum_alg); + _checksum_init(&(xar->e_sumwrk), e_sum_alg); +} + +static void +checksum_update(struct archive_read *a, const void *abuff, size_t asize, + const void *ebuff, size_t esize) +{ + struct xar *xar; + + xar = (struct xar *)(a->format->data); + _checksum_update(&(xar->a_sumwrk), abuff, asize); + _checksum_update(&(xar->e_sumwrk), ebuff, esize); +} + +static int +checksum_final(struct archive_read *a, const void *a_sum_val, + size_t a_sum_len, const void *e_sum_val, size_t e_sum_len) +{ + struct xar *xar; + int r; + + xar = (struct xar *)(a->format->data); + r = _checksum_final(&(xar->a_sumwrk), a_sum_val, a_sum_len); + if (r == ARCHIVE_OK) + r = _checksum_final(&(xar->e_sumwrk), e_sum_val, e_sum_len); + if (r != ARCHIVE_OK) + archive_set_error(&(a->archive), ARCHIVE_ERRNO_MISC, + "Sumcheck error"); + return (r); +} + +static int +decompression_init(struct archive_read *a, enum enctype encoding) +{ + struct xar *xar; + const char *detail; + int r; + + xar = (struct xar *)(a->format->data); + xar->rd_encoding = encoding; + switch (encoding) { + case NONE: + break; + case GZIP: + if (xar->stream_valid) + r = inflateReset(&(xar->stream)); + else + r = inflateInit(&(xar->stream)); + if (r != Z_OK) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Couldn't initialize zlib stream."); + return (ARCHIVE_FATAL); + } + xar->stream_valid = 1; + xar->stream.total_in = 0; + xar->stream.total_out = 0; + break; +#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) + case BZIP2: + if (xar->bzstream_valid) { + BZ2_bzDecompressEnd(&(xar->bzstream)); + xar->bzstream_valid = 0; + } + r = BZ2_bzDecompressInit(&(xar->bzstream), 0, 0); + if (r == BZ_MEM_ERROR) + r = BZ2_bzDecompressInit(&(xar->bzstream), 0, 1); + if (r != BZ_OK) { + int err = ARCHIVE_ERRNO_MISC; + detail = NULL; + switch (r) { + case BZ_PARAM_ERROR: + detail = "invalid setup parameter"; + break; + case BZ_MEM_ERROR: + err = ENOMEM; + detail = "out of memory"; + break; + case BZ_CONFIG_ERROR: + detail = "mis-compiled library"; + break; + } + archive_set_error(&a->archive, err, + "Internal error initializing decompressor: %s", + detail == NULL ? "??" : detail); + xar->bzstream_valid = 0; + return (ARCHIVE_FATAL); + } + xar->bzstream_valid = 1; + xar->bzstream.total_in_lo32 = 0; + xar->bzstream.total_in_hi32 = 0; + xar->bzstream.total_out_lo32 = 0; + xar->bzstream.total_out_hi32 = 0; + break; +#endif +#if defined(HAVE_LZMA_H) && defined(HAVE_LIBLZMA) +#if LZMA_VERSION_MAJOR >= 5 +/* Effectively disable the limiter. */ +#define LZMA_MEMLIMIT UINT64_MAX +#else +/* NOTE: This needs to check memory size which running system has. */ +#define LZMA_MEMLIMIT (1U << 30) +#endif + case XZ: + case LZMA: + if (xar->lzstream_valid) { + lzma_end(&(xar->lzstream)); + xar->lzstream_valid = 0; + } + if (xar->entry_encoding == XZ) + r = lzma_stream_decoder(&(xar->lzstream), + LZMA_MEMLIMIT,/* memlimit */ + LZMA_CONCATENATED); + else + r = lzma_alone_decoder(&(xar->lzstream), + LZMA_MEMLIMIT);/* memlimit */ + if (r != LZMA_OK) { + switch (r) { + case LZMA_MEM_ERROR: + archive_set_error(&a->archive, + ENOMEM, + "Internal error initializing " + "compression library: " + "Cannot allocate memory"); + break; + case LZMA_OPTIONS_ERROR: + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Internal error initializing " + "compression library: " + "Invalid or unsupported options"); + break; + default: + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Internal error initializing " + "lzma library"); + break; + } + return (ARCHIVE_FATAL); + } + xar->lzstream_valid = 1; + xar->lzstream.total_in = 0; + xar->lzstream.total_out = 0; + break; +#endif + /* + * Unsupported compression. + */ + default: +#if !defined(HAVE_BZLIB_H) || !defined(BZ_CONFIG_ERROR) + case BZIP2: +#endif +#if !defined(HAVE_LZMA_H) || !defined(HAVE_LIBLZMA) + case LZMA: + case XZ: +#endif + switch (xar->entry_encoding) { + case BZIP2: detail = "bzip2"; break; + case LZMA: detail = "lzma"; break; + case XZ: detail = "xz"; break; + default: detail = "??"; break; + } + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "%s compression not supported on this platform", + detail); + return (ARCHIVE_FAILED); + } + return (ARCHIVE_OK); +} + +static int +decompress(struct archive_read *a, const void **buff, size_t *outbytes, + const void *b, size_t *used) +{ + struct xar *xar; + void *outbuff; + size_t avail_in, avail_out; + int r; + + xar = (struct xar *)(a->format->data); + avail_in = *used; + outbuff = (void *)(uintptr_t)*buff; + if (outbuff == NULL) { + if (xar->outbuff == NULL) { + xar->outbuff = malloc(OUTBUFF_SIZE); + if (xar->outbuff == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Couldn't allocate memory for out buffer"); + return (ARCHIVE_FATAL); + } + } + outbuff = xar->outbuff; + *buff = outbuff; + avail_out = OUTBUFF_SIZE; + } else + avail_out = *outbytes; + switch (xar->rd_encoding) { + case GZIP: + xar->stream.next_in = (Bytef *)(uintptr_t)b; + xar->stream.avail_in = avail_in; + xar->stream.next_out = (unsigned char *)outbuff; + xar->stream.avail_out = avail_out; + r = inflate(&(xar->stream), 0); + switch (r) { + case Z_OK: /* Decompressor made some progress.*/ + case Z_STREAM_END: /* Found end of stream. */ + break; + default: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "File decompression failed (%d)", r); + return (ARCHIVE_FATAL); + } + *used = avail_in - xar->stream.avail_in; + *outbytes = avail_out - xar->stream.avail_out; + break; +#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) + case BZIP2: + xar->bzstream.next_in = (char *)(uintptr_t)b; + xar->bzstream.avail_in = avail_in; + xar->bzstream.next_out = (char *)outbuff; + xar->bzstream.avail_out = avail_out; + r = BZ2_bzDecompress(&(xar->bzstream)); + switch (r) { + case BZ_STREAM_END: /* Found end of stream. */ + switch (BZ2_bzDecompressEnd(&(xar->bzstream))) { + case BZ_OK: + break; + default: + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "Failed to clean up decompressor"); + return (ARCHIVE_FATAL); + } + xar->bzstream_valid = 0; + /* FALLTHROUGH */ + case BZ_OK: /* Decompressor made some progress. */ + break; + default: + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "bzip decompression failed"); + return (ARCHIVE_FATAL); + } + *used = avail_in - xar->bzstream.avail_in; + *outbytes = avail_out - xar->bzstream.avail_out; + break; +#endif +#if defined(HAVE_LZMA_H) && defined(HAVE_LIBLZMA) + case LZMA: + case XZ: + xar->lzstream.next_in = b; + xar->lzstream.avail_in = avail_in; + xar->lzstream.next_out = (unsigned char *)outbuff; + xar->lzstream.avail_out = avail_out; + r = lzma_code(&(xar->lzstream), LZMA_RUN); + switch (r) { + case LZMA_STREAM_END: /* Found end of stream. */ + lzma_end(&(xar->lzstream)); + xar->lzstream_valid = 0; + /* FALLTHROUGH */ + case LZMA_OK: /* Decompressor made some progress. */ + break; + default: + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "%s decompression failed(%d)", + (xar->entry_encoding == XZ)?"xz":"lzma", + r); + return (ARCHIVE_FATAL); + } + *used = avail_in - xar->lzstream.avail_in; + *outbytes = avail_out - xar->lzstream.avail_out; + break; +#endif +#if !defined(HAVE_BZLIB_H) || !defined(BZ_CONFIG_ERROR) + case BZIP2: +#endif +#if !defined(HAVE_LZMA_H) || !defined(HAVE_LIBLZMA) + case LZMA: + case XZ: +#endif + case NONE: + default: + if (outbuff == xar->outbuff) { + *buff = b; + *used = avail_in; + *outbytes = avail_in; + } else { + if (avail_out > avail_in) + avail_out = avail_in; + memcpy(outbuff, b, avail_out); + *used = avail_out; + *outbytes = avail_out; + } + break; + } + return (ARCHIVE_OK); +} + +static int +decompression_cleanup(struct archive_read *a) +{ + struct xar *xar; + int r; + + xar = (struct xar *)(a->format->data); + r = ARCHIVE_OK; + if (xar->stream_valid) { + if (inflateEnd(&(xar->stream)) != Z_OK) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Failed to clean up zlib decompressor"); + r = ARCHIVE_FATAL; + } + } +#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) + if (xar->bzstream_valid) { + if (BZ2_bzDecompressEnd(&(xar->bzstream)) != BZ_OK) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Failed to clean up bzip2 decompressor"); + r = ARCHIVE_FATAL; + } + } +#endif +#if defined(HAVE_LZMA_H) && defined(HAVE_LIBLZMA) + if (xar->lzstream_valid) + lzma_end(&(xar->lzstream)); +#elif defined(HAVE_LZMA_H) && defined(HAVE_LIBLZMA) + if (xar->lzstream_valid) { + if (lzmadec_end(&(xar->lzstream)) != LZMADEC_OK) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Failed to clean up lzmadec decompressor"); + r = ARCHIVE_FATAL; + } + } +#endif + return (r); +} + +static void +checksum_cleanup(struct archive_read *a) { + struct xar *xar; + + xar = (struct xar *)(a->format->data); + + _checksum_final(&(xar->a_sumwrk), NULL, 0); + _checksum_final(&(xar->e_sumwrk), NULL, 0); +} + +static void +xmlattr_cleanup(struct xmlattr_list *list) +{ + struct xmlattr *attr, *next; + + attr = list->first; + while (attr != NULL) { + next = attr->next; + free(attr->name); + free(attr->value); + free(attr); + attr = next; + } + list->first = NULL; + list->last = &(list->first); +} + +static int +file_new(struct archive_read *a, struct xar *xar, struct xmlattr_list *list) +{ + struct xar_file *file; + struct xmlattr *attr; + + file = calloc(1, sizeof(*file)); + if (file == NULL) { + archive_set_error(&a->archive, ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + file->parent = xar->file; + file->mode = 0777 | AE_IFREG; + file->atime = time(NULL); + file->mtime = time(NULL); + xar->file = file; + xar->xattr = NULL; + for (attr = list->first; attr != NULL; attr = attr->next) { + if (strcmp(attr->name, "id") == 0) + file->id = atol10(attr->value, strlen(attr->value)); + } + file->nlink = 1; + if (heap_add_entry(a, &(xar->file_queue), file) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + return (ARCHIVE_OK); +} + +static void +file_free(struct xar_file *file) +{ + struct xattr *xattr; + + archive_string_free(&(file->pathname)); + archive_string_free(&(file->symlink)); + archive_string_free(&(file->uname)); + archive_string_free(&(file->gname)); + archive_string_free(&(file->hardlink)); + xattr = file->xattr_list; + while (xattr != NULL) { + struct xattr *next; + + next = xattr->next; + xattr_free(xattr); + xattr = next; + } + + free(file); +} + +static int +xattr_new(struct archive_read *a, struct xar *xar, struct xmlattr_list *list) +{ + struct xattr *xattr, **nx; + struct xmlattr *attr; + + xattr = calloc(1, sizeof(*xattr)); + if (xattr == NULL) { + archive_set_error(&a->archive, ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + xar->xattr = xattr; + for (attr = list->first; attr != NULL; attr = attr->next) { + if (strcmp(attr->name, "id") == 0) + xattr->id = atol10(attr->value, strlen(attr->value)); + } + /* Chain to xattr list. */ + for (nx = &(xar->file->xattr_list); + *nx != NULL; nx = &((*nx)->next)) { + if (xattr->id < (*nx)->id) + break; + } + xattr->next = *nx; + *nx = xattr; + + return (ARCHIVE_OK); +} + +static void +xattr_free(struct xattr *xattr) +{ + archive_string_free(&(xattr->name)); + free(xattr); +} + +static int +getencoding(struct xmlattr_list *list) +{ + struct xmlattr *attr; + enum enctype encoding = NONE; + + for (attr = list->first; attr != NULL; attr = attr->next) { + if (strcmp(attr->name, "style") == 0) { + if (strcmp(attr->value, "application/octet-stream") == 0) + encoding = NONE; + else if (strcmp(attr->value, "application/x-gzip") == 0) + encoding = GZIP; + else if (strcmp(attr->value, "application/x-bzip2") == 0) + encoding = BZIP2; + else if (strcmp(attr->value, "application/x-lzma") == 0) + encoding = LZMA; + else if (strcmp(attr->value, "application/x-xz") == 0) + encoding = XZ; + } + } + return (encoding); +} + +static int +getsumalgorithm(struct xmlattr_list *list) +{ + struct xmlattr *attr; + int alg = CKSUM_NONE; + + for (attr = list->first; attr != NULL; attr = attr->next) { + if (strcmp(attr->name, "style") == 0) { + const char *v = attr->value; + if ((v[0] == 'S' || v[0] == 's') && + (v[1] == 'H' || v[1] == 'h') && + (v[2] == 'A' || v[2] == 'a') && + v[3] == '1' && v[4] == '\0') + alg = CKSUM_SHA1; + if ((v[0] == 'M' || v[0] == 'm') && + (v[1] == 'D' || v[1] == 'd') && + v[2] == '5' && v[3] == '\0') + alg = CKSUM_MD5; + } + } + return (alg); +} + +static int +unknowntag_start(struct archive_read *a, struct xar *xar, const char *name) +{ + struct unknown_tag *tag; + + tag = malloc(sizeof(*tag)); + if (tag == NULL) { + archive_set_error(&a->archive, ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + tag->next = xar->unknowntags; + archive_string_init(&(tag->name)); + archive_strcpy(&(tag->name), name); + if (xar->unknowntags == NULL) { +#if DEBUG + fprintf(stderr, "UNKNOWNTAG_START:%s\n", name); +#endif + xar->xmlsts_unknown = xar->xmlsts; + xar->xmlsts = UNKNOWN; + } + xar->unknowntags = tag; + return (ARCHIVE_OK); +} + +static void +unknowntag_end(struct xar *xar, const char *name) +{ + struct unknown_tag *tag; + + tag = xar->unknowntags; + if (tag == NULL || name == NULL) + return; + if (strcmp(tag->name.s, name) == 0) { + xar->unknowntags = tag->next; + archive_string_free(&(tag->name)); + free(tag); + if (xar->unknowntags == NULL) { +#if DEBUG + fprintf(stderr, "UNKNOWNTAG_END:%s\n", name); +#endif + xar->xmlsts = xar->xmlsts_unknown; + } + } +} + +static int +xml_start(struct archive_read *a, const char *name, struct xmlattr_list *list) +{ + struct xar *xar; + struct xmlattr *attr; + + xar = (struct xar *)(a->format->data); + +#if DEBUG + fprintf(stderr, "xml_sta:[%s]\n", name); + for (attr = list->first; attr != NULL; attr = attr->next) + fprintf(stderr, " attr:\"%s\"=\"%s\"\n", + attr->name, attr->value); +#endif + xar->base64text = 0; + switch (xar->xmlsts) { + case INIT: + if (strcmp(name, "xar") == 0) + xar->xmlsts = XAR; + else + if (unknowntag_start(a, xar, name) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + break; + case XAR: + if (strcmp(name, "toc") == 0) + xar->xmlsts = TOC; + else + if (unknowntag_start(a, xar, name) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + break; + case TOC: + if (strcmp(name, "creation-time") == 0) + xar->xmlsts = TOC_CREATION_TIME; + else if (strcmp(name, "checksum") == 0) + xar->xmlsts = TOC_CHECKSUM; + else if (strcmp(name, "file") == 0) { + if (file_new(a, xar, list) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + xar->xmlsts = TOC_FILE; + } + else + if (unknowntag_start(a, xar, name) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + break; + case TOC_CHECKSUM: + if (strcmp(name, "offset") == 0) + xar->xmlsts = TOC_CHECKSUM_OFFSET; + else if (strcmp(name, "size") == 0) + xar->xmlsts = TOC_CHECKSUM_SIZE; + else + if (unknowntag_start(a, xar, name) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + break; + case TOC_FILE: + if (strcmp(name, "file") == 0) { + if (file_new(a, xar, list) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } + else if (strcmp(name, "data") == 0) + xar->xmlsts = FILE_DATA; + else if (strcmp(name, "ea") == 0) { + if (xattr_new(a, xar, list) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + xar->xmlsts = FILE_EA; + } + else if (strcmp(name, "ctime") == 0) + xar->xmlsts = FILE_CTIME; + else if (strcmp(name, "mtime") == 0) + xar->xmlsts = FILE_MTIME; + else if (strcmp(name, "atime") == 0) + xar->xmlsts = FILE_ATIME; + else if (strcmp(name, "group") == 0) + xar->xmlsts = FILE_GROUP; + else if (strcmp(name, "gid") == 0) + xar->xmlsts = FILE_GID; + else if (strcmp(name, "user") == 0) + xar->xmlsts = FILE_USER; + else if (strcmp(name, "uid") == 0) + xar->xmlsts = FILE_UID; + else if (strcmp(name, "mode") == 0) + xar->xmlsts = FILE_MODE; + else if (strcmp(name, "device") == 0) + xar->xmlsts = FILE_DEVICE; + else if (strcmp(name, "deviceno") == 0) + xar->xmlsts = FILE_DEVICENO; + else if (strcmp(name, "inode") == 0) + xar->xmlsts = FILE_INODE; + else if (strcmp(name, "link") == 0) + xar->xmlsts = FILE_LINK; + else if (strcmp(name, "type") == 0) { + xar->xmlsts = FILE_TYPE; + for (attr = list->first; attr != NULL; + attr = attr->next) { + if (strcmp(attr->name, "link") != 0) + continue; + if (strcmp(attr->value, "original") == 0) { + xar->file->hdnext = xar->hdlink_orgs; + xar->hdlink_orgs = xar->file; + } else { + xar->file->link = (unsigned)atol10(attr->value, + strlen(attr->value)); + if (xar->file->link > 0) + if (add_link(a, xar, xar->file) != ARCHIVE_OK) { + return (ARCHIVE_FATAL); + }; + } + } + } + else if (strcmp(name, "name") == 0) { + xar->xmlsts = FILE_NAME; + for (attr = list->first; attr != NULL; + attr = attr->next) { + if (strcmp(attr->name, "enctype") == 0 && + strcmp(attr->value, "base64") == 0) + xar->base64text = 1; + } + } + else if (strcmp(name, "acl") == 0) + xar->xmlsts = FILE_ACL; + else if (strcmp(name, "flags") == 0) + xar->xmlsts = FILE_FLAGS; + else if (strcmp(name, "ext2") == 0) + xar->xmlsts = FILE_EXT2; + else + if (unknowntag_start(a, xar, name) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + break; + case FILE_DATA: + if (strcmp(name, "length") == 0) + xar->xmlsts = FILE_DATA_LENGTH; + else if (strcmp(name, "offset") == 0) + xar->xmlsts = FILE_DATA_OFFSET; + else if (strcmp(name, "size") == 0) + xar->xmlsts = FILE_DATA_SIZE; + else if (strcmp(name, "encoding") == 0) { + xar->xmlsts = FILE_DATA_ENCODING; + xar->file->encoding = getencoding(list); + } + else if (strcmp(name, "archived-checksum") == 0) { + xar->xmlsts = FILE_DATA_A_CHECKSUM; + xar->file->a_sum.alg = getsumalgorithm(list); + } + else if (strcmp(name, "extracted-checksum") == 0) { + xar->xmlsts = FILE_DATA_E_CHECKSUM; + xar->file->e_sum.alg = getsumalgorithm(list); + } + else if (strcmp(name, "content") == 0) + xar->xmlsts = FILE_DATA_CONTENT; + else + if (unknowntag_start(a, xar, name) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + break; + case FILE_DEVICE: + if (strcmp(name, "major") == 0) + xar->xmlsts = FILE_DEVICE_MAJOR; + else if (strcmp(name, "minor") == 0) + xar->xmlsts = FILE_DEVICE_MINOR; + else + if (unknowntag_start(a, xar, name) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + break; + case FILE_DATA_CONTENT: + if (unknowntag_start(a, xar, name) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + break; + case FILE_EA: + if (strcmp(name, "length") == 0) + xar->xmlsts = FILE_EA_LENGTH; + else if (strcmp(name, "offset") == 0) + xar->xmlsts = FILE_EA_OFFSET; + else if (strcmp(name, "size") == 0) + xar->xmlsts = FILE_EA_SIZE; + else if (strcmp(name, "encoding") == 0) { + xar->xmlsts = FILE_EA_ENCODING; + xar->xattr->encoding = getencoding(list); + } else if (strcmp(name, "archived-checksum") == 0) + xar->xmlsts = FILE_EA_A_CHECKSUM; + else if (strcmp(name, "extracted-checksum") == 0) + xar->xmlsts = FILE_EA_E_CHECKSUM; + else if (strcmp(name, "name") == 0) + xar->xmlsts = FILE_EA_NAME; + else if (strcmp(name, "fstype") == 0) + xar->xmlsts = FILE_EA_FSTYPE; + else + if (unknowntag_start(a, xar, name) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + break; + case FILE_ACL: + if (strcmp(name, "appleextended") == 0) + xar->xmlsts = FILE_ACL_APPLEEXTENDED; + else if (strcmp(name, "default") == 0) + xar->xmlsts = FILE_ACL_DEFAULT; + else if (strcmp(name, "access") == 0) + xar->xmlsts = FILE_ACL_ACCESS; + else + if (unknowntag_start(a, xar, name) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + break; + case FILE_FLAGS: + if (!xml_parse_file_flags(xar, name)) + if (unknowntag_start(a, xar, name) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + break; + case FILE_EXT2: + if (!xml_parse_file_ext2(xar, name)) + if (unknowntag_start(a, xar, name) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + break; + case TOC_CREATION_TIME: + case TOC_CHECKSUM_OFFSET: + case TOC_CHECKSUM_SIZE: + case FILE_DATA_LENGTH: + case FILE_DATA_OFFSET: + case FILE_DATA_SIZE: + case FILE_DATA_ENCODING: + case FILE_DATA_A_CHECKSUM: + case FILE_DATA_E_CHECKSUM: + case FILE_EA_LENGTH: + case FILE_EA_OFFSET: + case FILE_EA_SIZE: + case FILE_EA_ENCODING: + case FILE_EA_A_CHECKSUM: + case FILE_EA_E_CHECKSUM: + case FILE_EA_NAME: + case FILE_EA_FSTYPE: + case FILE_CTIME: + case FILE_MTIME: + case FILE_ATIME: + case FILE_GROUP: + case FILE_GID: + case FILE_USER: + case FILE_UID: + case FILE_INODE: + case FILE_DEVICE_MAJOR: + case FILE_DEVICE_MINOR: + case FILE_DEVICENO: + case FILE_MODE: + case FILE_TYPE: + case FILE_LINK: + case FILE_NAME: + case FILE_ACL_DEFAULT: + case FILE_ACL_ACCESS: + case FILE_ACL_APPLEEXTENDED: + case FILE_FLAGS_USER_NODUMP: + case FILE_FLAGS_USER_IMMUTABLE: + case FILE_FLAGS_USER_APPEND: + case FILE_FLAGS_USER_OPAQUE: + case FILE_FLAGS_USER_NOUNLINK: + case FILE_FLAGS_SYS_ARCHIVED: + case FILE_FLAGS_SYS_IMMUTABLE: + case FILE_FLAGS_SYS_APPEND: + case FILE_FLAGS_SYS_NOUNLINK: + case FILE_FLAGS_SYS_SNAPSHOT: + case FILE_EXT2_SecureDeletion: + case FILE_EXT2_Undelete: + case FILE_EXT2_Compress: + case FILE_EXT2_Synchronous: + case FILE_EXT2_Immutable: + case FILE_EXT2_AppendOnly: + case FILE_EXT2_NoDump: + case FILE_EXT2_NoAtime: + case FILE_EXT2_CompDirty: + case FILE_EXT2_CompBlock: + case FILE_EXT2_NoCompBlock: + case FILE_EXT2_CompError: + case FILE_EXT2_BTree: + case FILE_EXT2_HashIndexed: + case FILE_EXT2_iMagic: + case FILE_EXT2_Journaled: + case FILE_EXT2_NoTail: + case FILE_EXT2_DirSync: + case FILE_EXT2_TopDir: + case FILE_EXT2_Reserved: + case UNKNOWN: + if (unknowntag_start(a, xar, name) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + break; + } + return (ARCHIVE_OK); +} + +static void +xml_end(void *userData, const char *name) +{ + struct archive_read *a; + struct xar *xar; + + a = (struct archive_read *)userData; + xar = (struct xar *)(a->format->data); + +#if DEBUG + fprintf(stderr, "xml_end:[%s]\n", name); +#endif + switch (xar->xmlsts) { + case INIT: + break; + case XAR: + if (strcmp(name, "xar") == 0) + xar->xmlsts = INIT; + break; + case TOC: + if (strcmp(name, "toc") == 0) + xar->xmlsts = XAR; + break; + case TOC_CREATION_TIME: + if (strcmp(name, "creation-time") == 0) + xar->xmlsts = TOC; + break; + case TOC_CHECKSUM: + if (strcmp(name, "checksum") == 0) + xar->xmlsts = TOC; + break; + case TOC_CHECKSUM_OFFSET: + if (strcmp(name, "offset") == 0) + xar->xmlsts = TOC_CHECKSUM; + break; + case TOC_CHECKSUM_SIZE: + if (strcmp(name, "size") == 0) + xar->xmlsts = TOC_CHECKSUM; + break; + case TOC_FILE: + if (strcmp(name, "file") == 0) { + if (xar->file->parent != NULL && + ((xar->file->mode & AE_IFMT) == AE_IFDIR)) + xar->file->parent->subdirs++; + xar->file = xar->file->parent; + if (xar->file == NULL) + xar->xmlsts = TOC; + } + break; + case FILE_DATA: + if (strcmp(name, "data") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_DATA_LENGTH: + if (strcmp(name, "length") == 0) + xar->xmlsts = FILE_DATA; + break; + case FILE_DATA_OFFSET: + if (strcmp(name, "offset") == 0) + xar->xmlsts = FILE_DATA; + break; + case FILE_DATA_SIZE: + if (strcmp(name, "size") == 0) + xar->xmlsts = FILE_DATA; + break; + case FILE_DATA_ENCODING: + if (strcmp(name, "encoding") == 0) + xar->xmlsts = FILE_DATA; + break; + case FILE_DATA_A_CHECKSUM: + if (strcmp(name, "archived-checksum") == 0) + xar->xmlsts = FILE_DATA; + break; + case FILE_DATA_E_CHECKSUM: + if (strcmp(name, "extracted-checksum") == 0) + xar->xmlsts = FILE_DATA; + break; + case FILE_DATA_CONTENT: + if (strcmp(name, "content") == 0) + xar->xmlsts = FILE_DATA; + break; + case FILE_EA: + if (strcmp(name, "ea") == 0) { + xar->xmlsts = TOC_FILE; + xar->xattr = NULL; + } + break; + case FILE_EA_LENGTH: + if (strcmp(name, "length") == 0) + xar->xmlsts = FILE_EA; + break; + case FILE_EA_OFFSET: + if (strcmp(name, "offset") == 0) + xar->xmlsts = FILE_EA; + break; + case FILE_EA_SIZE: + if (strcmp(name, "size") == 0) + xar->xmlsts = FILE_EA; + break; + case FILE_EA_ENCODING: + if (strcmp(name, "encoding") == 0) + xar->xmlsts = FILE_EA; + break; + case FILE_EA_A_CHECKSUM: + if (strcmp(name, "archived-checksum") == 0) + xar->xmlsts = FILE_EA; + break; + case FILE_EA_E_CHECKSUM: + if (strcmp(name, "extracted-checksum") == 0) + xar->xmlsts = FILE_EA; + break; + case FILE_EA_NAME: + if (strcmp(name, "name") == 0) + xar->xmlsts = FILE_EA; + break; + case FILE_EA_FSTYPE: + if (strcmp(name, "fstype") == 0) + xar->xmlsts = FILE_EA; + break; + case FILE_CTIME: + if (strcmp(name, "ctime") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_MTIME: + if (strcmp(name, "mtime") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_ATIME: + if (strcmp(name, "atime") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_GROUP: + if (strcmp(name, "group") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_GID: + if (strcmp(name, "gid") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_USER: + if (strcmp(name, "user") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_UID: + if (strcmp(name, "uid") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_MODE: + if (strcmp(name, "mode") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_DEVICE: + if (strcmp(name, "device") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_DEVICE_MAJOR: + if (strcmp(name, "major") == 0) + xar->xmlsts = FILE_DEVICE; + break; + case FILE_DEVICE_MINOR: + if (strcmp(name, "minor") == 0) + xar->xmlsts = FILE_DEVICE; + break; + case FILE_DEVICENO: + if (strcmp(name, "deviceno") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_INODE: + if (strcmp(name, "inode") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_LINK: + if (strcmp(name, "link") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_TYPE: + if (strcmp(name, "type") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_NAME: + if (strcmp(name, "name") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_ACL: + if (strcmp(name, "acl") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_ACL_DEFAULT: + if (strcmp(name, "default") == 0) + xar->xmlsts = FILE_ACL; + break; + case FILE_ACL_ACCESS: + if (strcmp(name, "access") == 0) + xar->xmlsts = FILE_ACL; + break; + case FILE_ACL_APPLEEXTENDED: + if (strcmp(name, "appleextended") == 0) + xar->xmlsts = FILE_ACL; + break; + case FILE_FLAGS: + if (strcmp(name, "flags") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_FLAGS_USER_NODUMP: + if (strcmp(name, "UserNoDump") == 0) + xar->xmlsts = FILE_FLAGS; + break; + case FILE_FLAGS_USER_IMMUTABLE: + if (strcmp(name, "UserImmutable") == 0) + xar->xmlsts = FILE_FLAGS; + break; + case FILE_FLAGS_USER_APPEND: + if (strcmp(name, "UserAppend") == 0) + xar->xmlsts = FILE_FLAGS; + break; + case FILE_FLAGS_USER_OPAQUE: + if (strcmp(name, "UserOpaque") == 0) + xar->xmlsts = FILE_FLAGS; + break; + case FILE_FLAGS_USER_NOUNLINK: + if (strcmp(name, "UserNoUnlink") == 0) + xar->xmlsts = FILE_FLAGS; + break; + case FILE_FLAGS_SYS_ARCHIVED: + if (strcmp(name, "SystemArchived") == 0) + xar->xmlsts = FILE_FLAGS; + break; + case FILE_FLAGS_SYS_IMMUTABLE: + if (strcmp(name, "SystemImmutable") == 0) + xar->xmlsts = FILE_FLAGS; + break; + case FILE_FLAGS_SYS_APPEND: + if (strcmp(name, "SystemAppend") == 0) + xar->xmlsts = FILE_FLAGS; + break; + case FILE_FLAGS_SYS_NOUNLINK: + if (strcmp(name, "SystemNoUnlink") == 0) + xar->xmlsts = FILE_FLAGS; + break; + case FILE_FLAGS_SYS_SNAPSHOT: + if (strcmp(name, "SystemSnapshot") == 0) + xar->xmlsts = FILE_FLAGS; + break; + case FILE_EXT2: + if (strcmp(name, "ext2") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_EXT2_SecureDeletion: + if (strcmp(name, "SecureDeletion") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_Undelete: + if (strcmp(name, "Undelete") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_Compress: + if (strcmp(name, "Compress") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_Synchronous: + if (strcmp(name, "Synchronous") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_Immutable: + if (strcmp(name, "Immutable") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_AppendOnly: + if (strcmp(name, "AppendOnly") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_NoDump: + if (strcmp(name, "NoDump") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_NoAtime: + if (strcmp(name, "NoAtime") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_CompDirty: + if (strcmp(name, "CompDirty") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_CompBlock: + if (strcmp(name, "CompBlock") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_NoCompBlock: + if (strcmp(name, "NoCompBlock") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_CompError: + if (strcmp(name, "CompError") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_BTree: + if (strcmp(name, "BTree") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_HashIndexed: + if (strcmp(name, "HashIndexed") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_iMagic: + if (strcmp(name, "iMagic") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_Journaled: + if (strcmp(name, "Journaled") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_NoTail: + if (strcmp(name, "NoTail") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_DirSync: + if (strcmp(name, "DirSync") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_TopDir: + if (strcmp(name, "TopDir") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_Reserved: + if (strcmp(name, "Reserved") == 0) + xar->xmlsts = FILE_EXT2; + break; + case UNKNOWN: + unknowntag_end(xar, name); + break; + } +} + +static const int base64[256] = { + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, /* 00 - 0F */ + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, /* 10 - 1F */ + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 62, -1, -1, -1, 63, /* 20 - 2F */ + 52, 53, 54, 55, 56, 57, 58, 59, + 60, 61, -1, -1, -1, -1, -1, -1, /* 30 - 3F */ + -1, 0, 1, 2, 3, 4, 5, 6, + 7, 8, 9, 10, 11, 12, 13, 14, /* 40 - 4F */ + 15, 16, 17, 18, 19, 20, 21, 22, + 23, 24, 25, -1, -1, -1, -1, -1, /* 50 - 5F */ + -1, 26, 27, 28, 29, 30, 31, 32, + 33, 34, 35, 36, 37, 38, 39, 40, /* 60 - 6F */ + 41, 42, 43, 44, 45, 46, 47, 48, + 49, 50, 51, -1, -1, -1, -1, -1, /* 70 - 7F */ + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, /* 80 - 8F */ + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, /* 90 - 9F */ + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, /* A0 - AF */ + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, /* B0 - BF */ + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, /* C0 - CF */ + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, /* D0 - DF */ + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, /* E0 - EF */ + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, /* F0 - FF */ +}; + +static void +strappend_base64(struct xar *xar, + struct archive_string *as, const char *s, size_t l) +{ + unsigned char buff[256]; + unsigned char *out; + const unsigned char *b; + size_t len; + + (void)xar; /* UNUSED */ + len = 0; + out = buff; + b = (const unsigned char *)s; + while (l > 0) { + int n = 0; + + if (l > 0) { + if (base64[b[0]] < 0 || base64[b[1]] < 0) + break; + n = base64[*b++] << 18; + n |= base64[*b++] << 12; + *out++ = n >> 16; + len++; + l -= 2; + } + if (l > 0) { + if (base64[*b] < 0) + break; + n |= base64[*b++] << 6; + *out++ = (n >> 8) & 0xFF; + len++; + --l; + } + if (l > 0) { + if (base64[*b] < 0) + break; + n |= base64[*b++]; + *out++ = n & 0xFF; + len++; + --l; + } + if (len+3 >= sizeof(buff)) { + archive_strncat(as, (const char *)buff, len); + len = 0; + out = buff; + } + } + if (len > 0) + archive_strncat(as, (const char *)buff, len); +} + ++static int ++is_string(const char *known, const char *data, size_t len) ++{ ++ if (strlen(known) != len) ++ return -1; ++ return memcmp(data, known, len); ++} ++ +static void +xml_data(void *userData, const char *s, int len) +{ + struct archive_read *a; + struct xar *xar; + + a = (struct archive_read *)userData; + xar = (struct xar *)(a->format->data); + +#if DEBUG + { + char buff[1024]; + if (len > (int)(sizeof(buff)-1)) + len = (int)(sizeof(buff)-1); + strncpy(buff, s, len); + buff[len] = 0; + fprintf(stderr, "\tlen=%d:\"%s\"\n", len, buff); + } +#endif + switch (xar->xmlsts) { + case TOC_CHECKSUM_OFFSET: + xar->toc_chksum_offset = atol10(s, len); + break; + case TOC_CHECKSUM_SIZE: + xar->toc_chksum_size = atol10(s, len); + break; + default: + break; + } + if (xar->file == NULL) + return; + + switch (xar->xmlsts) { + case FILE_NAME: + if (xar->file->parent != NULL) { + archive_string_concat(&(xar->file->pathname), + &(xar->file->parent->pathname)); + archive_strappend_char(&(xar->file->pathname), '/'); + } + xar->file->has |= HAS_PATHNAME; + if (xar->base64text) { + strappend_base64(xar, + &(xar->file->pathname), s, len); + } else + archive_strncat(&(xar->file->pathname), s, len); + break; + case FILE_LINK: + xar->file->has |= HAS_SYMLINK; + archive_strncpy(&(xar->file->symlink), s, len); + break; + case FILE_TYPE: - if (strncmp("file", s, len) == 0 || - strncmp("hardlink", s, len) == 0) ++ if (is_string("file", s, len) == 0 || ++ is_string("hardlink", s, len) == 0) + xar->file->mode = + (xar->file->mode & ~AE_IFMT) | AE_IFREG; - if (strncmp("directory", s, len) == 0) ++ if (is_string("directory", s, len) == 0) + xar->file->mode = + (xar->file->mode & ~AE_IFMT) | AE_IFDIR; - if (strncmp("symlink", s, len) == 0) ++ if (is_string("symlink", s, len) == 0) + xar->file->mode = + (xar->file->mode & ~AE_IFMT) | AE_IFLNK; - if (strncmp("character special", s, len) == 0) ++ if (is_string("character special", s, len) == 0) + xar->file->mode = + (xar->file->mode & ~AE_IFMT) | AE_IFCHR; - if (strncmp("block special", s, len) == 0) ++ if (is_string("block special", s, len) == 0) + xar->file->mode = + (xar->file->mode & ~AE_IFMT) | AE_IFBLK; - if (strncmp("socket", s, len) == 0) ++ if (is_string("socket", s, len) == 0) + xar->file->mode = + (xar->file->mode & ~AE_IFMT) | AE_IFSOCK; - if (strncmp("fifo", s, len) == 0) ++ if (is_string("fifo", s, len) == 0) + xar->file->mode = + (xar->file->mode & ~AE_IFMT) | AE_IFIFO; + xar->file->has |= HAS_TYPE; + break; + case FILE_INODE: + xar->file->has |= HAS_INO; + xar->file->ino64 = atol10(s, len); + break; + case FILE_DEVICE_MAJOR: + xar->file->has |= HAS_DEVMAJOR; + xar->file->devmajor = (dev_t)atol10(s, len); + break; + case FILE_DEVICE_MINOR: + xar->file->has |= HAS_DEVMINOR; + xar->file->devminor = (dev_t)atol10(s, len); + break; + case FILE_DEVICENO: + xar->file->has |= HAS_DEV; + xar->file->dev = (dev_t)atol10(s, len); + break; + case FILE_MODE: + xar->file->has |= HAS_MODE; + xar->file->mode = + (xar->file->mode & AE_IFMT) | + ((mode_t)(atol8(s, len)) & ~AE_IFMT); + break; + case FILE_GROUP: + xar->file->has |= HAS_GID; + archive_strncpy(&(xar->file->gname), s, len); + break; + case FILE_GID: + xar->file->has |= HAS_GID; + xar->file->gid = atol10(s, len); + break; + case FILE_USER: + xar->file->has |= HAS_UID; + archive_strncpy(&(xar->file->uname), s, len); + break; + case FILE_UID: + xar->file->has |= HAS_UID; + xar->file->uid = atol10(s, len); + break; + case FILE_CTIME: + xar->file->has |= HAS_TIME; + xar->file->ctime = parse_time(s, len); + break; + case FILE_MTIME: + xar->file->has |= HAS_TIME; + xar->file->mtime = parse_time(s, len); + break; + case FILE_ATIME: + xar->file->has |= HAS_TIME; + xar->file->atime = parse_time(s, len); + break; + case FILE_DATA_LENGTH: + xar->file->has |= HAS_DATA; + xar->file->length = atol10(s, len); + break; + case FILE_DATA_OFFSET: + xar->file->has |= HAS_DATA; + xar->file->offset = atol10(s, len); + break; + case FILE_DATA_SIZE: + xar->file->has |= HAS_DATA; + xar->file->size = atol10(s, len); + break; + case FILE_DATA_A_CHECKSUM: + xar->file->a_sum.len = atohex(xar->file->a_sum.val, + sizeof(xar->file->a_sum.val), s, len); + break; + case FILE_DATA_E_CHECKSUM: + xar->file->e_sum.len = atohex(xar->file->e_sum.val, + sizeof(xar->file->e_sum.val), s, len); + break; + case FILE_EA_LENGTH: + xar->file->has |= HAS_XATTR; + xar->xattr->length = atol10(s, len); + break; + case FILE_EA_OFFSET: + xar->file->has |= HAS_XATTR; + xar->xattr->offset = atol10(s, len); + break; + case FILE_EA_SIZE: + xar->file->has |= HAS_XATTR; + xar->xattr->size = atol10(s, len); + break; + case FILE_EA_A_CHECKSUM: + xar->file->has |= HAS_XATTR; + xar->xattr->a_sum.len = atohex(xar->xattr->a_sum.val, + sizeof(xar->xattr->a_sum.val), s, len); + break; + case FILE_EA_E_CHECKSUM: + xar->file->has |= HAS_XATTR; + xar->xattr->e_sum.len = atohex(xar->xattr->e_sum.val, + sizeof(xar->xattr->e_sum.val), s, len); + break; + case FILE_EA_NAME: + xar->file->has |= HAS_XATTR; + archive_strncpy(&(xar->xattr->name), s, len); + break; + case FILE_EA_FSTYPE: + xar->file->has |= HAS_XATTR; + archive_strncpy(&(xar->xattr->fstype), s, len); + break; + break; + case FILE_ACL_DEFAULT: + case FILE_ACL_ACCESS: + case FILE_ACL_APPLEEXTENDED: + xar->file->has |= HAS_ACL; + /* TODO */ + break; + case INIT: + case XAR: + case TOC: + case TOC_CREATION_TIME: + case TOC_CHECKSUM: + case TOC_CHECKSUM_OFFSET: + case TOC_CHECKSUM_SIZE: + case TOC_FILE: + case FILE_DATA: + case FILE_DATA_ENCODING: + case FILE_DATA_CONTENT: + case FILE_DEVICE: + case FILE_EA: + case FILE_EA_ENCODING: + case FILE_ACL: + case FILE_FLAGS: + case FILE_FLAGS_USER_NODUMP: + case FILE_FLAGS_USER_IMMUTABLE: + case FILE_FLAGS_USER_APPEND: + case FILE_FLAGS_USER_OPAQUE: + case FILE_FLAGS_USER_NOUNLINK: + case FILE_FLAGS_SYS_ARCHIVED: + case FILE_FLAGS_SYS_IMMUTABLE: + case FILE_FLAGS_SYS_APPEND: + case FILE_FLAGS_SYS_NOUNLINK: + case FILE_FLAGS_SYS_SNAPSHOT: + case FILE_EXT2: + case FILE_EXT2_SecureDeletion: + case FILE_EXT2_Undelete: + case FILE_EXT2_Compress: + case FILE_EXT2_Synchronous: + case FILE_EXT2_Immutable: + case FILE_EXT2_AppendOnly: + case FILE_EXT2_NoDump: + case FILE_EXT2_NoAtime: + case FILE_EXT2_CompDirty: + case FILE_EXT2_CompBlock: + case FILE_EXT2_NoCompBlock: + case FILE_EXT2_CompError: + case FILE_EXT2_BTree: + case FILE_EXT2_HashIndexed: + case FILE_EXT2_iMagic: + case FILE_EXT2_Journaled: + case FILE_EXT2_NoTail: + case FILE_EXT2_DirSync: + case FILE_EXT2_TopDir: + case FILE_EXT2_Reserved: + case UNKNOWN: + break; + } +} + +/* + * BSD file flags. + */ +static int +xml_parse_file_flags(struct xar *xar, const char *name) +{ + const char *flag = NULL; + + if (strcmp(name, "UserNoDump") == 0) { + xar->xmlsts = FILE_FLAGS_USER_NODUMP; + flag = "nodump"; + } + else if (strcmp(name, "UserImmutable") == 0) { + xar->xmlsts = FILE_FLAGS_USER_IMMUTABLE; + flag = "uimmutable"; + } + else if (strcmp(name, "UserAppend") == 0) { + xar->xmlsts = FILE_FLAGS_USER_APPEND; + flag = "uappend"; + } + else if (strcmp(name, "UserOpaque") == 0) { + xar->xmlsts = FILE_FLAGS_USER_OPAQUE; + flag = "opaque"; + } + else if (strcmp(name, "UserNoUnlink") == 0) { + xar->xmlsts = FILE_FLAGS_USER_NOUNLINK; + flag = "nouunlink"; + } + else if (strcmp(name, "SystemArchived") == 0) { + xar->xmlsts = FILE_FLAGS_SYS_ARCHIVED; + flag = "archived"; + } + else if (strcmp(name, "SystemImmutable") == 0) { + xar->xmlsts = FILE_FLAGS_SYS_IMMUTABLE; + flag = "simmutable"; + } + else if (strcmp(name, "SystemAppend") == 0) { + xar->xmlsts = FILE_FLAGS_SYS_APPEND; + flag = "sappend"; + } + else if (strcmp(name, "SystemNoUnlink") == 0) { + xar->xmlsts = FILE_FLAGS_SYS_NOUNLINK; + flag = "nosunlink"; + } + else if (strcmp(name, "SystemSnapshot") == 0) { + xar->xmlsts = FILE_FLAGS_SYS_SNAPSHOT; + flag = "snapshot"; + } + + if (flag == NULL) + return (0); + xar->file->has |= HAS_FFLAGS; + if (archive_strlen(&(xar->file->fflags_text)) > 0) + archive_strappend_char(&(xar->file->fflags_text), ','); + archive_strcat(&(xar->file->fflags_text), flag); + return (1); +} + +/* + * Linux file flags. + */ +static int +xml_parse_file_ext2(struct xar *xar, const char *name) +{ + const char *flag = NULL; + + if (strcmp(name, "SecureDeletion") == 0) { + xar->xmlsts = FILE_EXT2_SecureDeletion; + flag = "securedeletion"; + } + else if (strcmp(name, "Undelete") == 0) { + xar->xmlsts = FILE_EXT2_Undelete; + flag = "nouunlink"; + } + else if (strcmp(name, "Compress") == 0) { + xar->xmlsts = FILE_EXT2_Compress; + flag = "compress"; + } + else if (strcmp(name, "Synchronous") == 0) { + xar->xmlsts = FILE_EXT2_Synchronous; + flag = "sync"; + } + else if (strcmp(name, "Immutable") == 0) { + xar->xmlsts = FILE_EXT2_Immutable; + flag = "simmutable"; + } + else if (strcmp(name, "AppendOnly") == 0) { + xar->xmlsts = FILE_EXT2_AppendOnly; + flag = "sappend"; + } + else if (strcmp(name, "NoDump") == 0) { + xar->xmlsts = FILE_EXT2_NoDump; + flag = "nodump"; + } + else if (strcmp(name, "NoAtime") == 0) { + xar->xmlsts = FILE_EXT2_NoAtime; + flag = "noatime"; + } + else if (strcmp(name, "CompDirty") == 0) { + xar->xmlsts = FILE_EXT2_CompDirty; + flag = "compdirty"; + } + else if (strcmp(name, "CompBlock") == 0) { + xar->xmlsts = FILE_EXT2_CompBlock; + flag = "comprblk"; + } + else if (strcmp(name, "NoCompBlock") == 0) { + xar->xmlsts = FILE_EXT2_NoCompBlock; + flag = "nocomprblk"; + } + else if (strcmp(name, "CompError") == 0) { + xar->xmlsts = FILE_EXT2_CompError; + flag = "comperr"; + } + else if (strcmp(name, "BTree") == 0) { + xar->xmlsts = FILE_EXT2_BTree; + flag = "btree"; + } + else if (strcmp(name, "HashIndexed") == 0) { + xar->xmlsts = FILE_EXT2_HashIndexed; + flag = "hashidx"; + } + else if (strcmp(name, "iMagic") == 0) { + xar->xmlsts = FILE_EXT2_iMagic; + flag = "imagic"; + } + else if (strcmp(name, "Journaled") == 0) { + xar->xmlsts = FILE_EXT2_Journaled; + flag = "journal"; + } + else if (strcmp(name, "NoTail") == 0) { + xar->xmlsts = FILE_EXT2_NoTail; + flag = "notail"; + } + else if (strcmp(name, "DirSync") == 0) { + xar->xmlsts = FILE_EXT2_DirSync; + flag = "dirsync"; + } + else if (strcmp(name, "TopDir") == 0) { + xar->xmlsts = FILE_EXT2_TopDir; + flag = "topdir"; + } + else if (strcmp(name, "Reserved") == 0) { + xar->xmlsts = FILE_EXT2_Reserved; + flag = "reserved"; + } + + if (flag == NULL) + return (0); + if (archive_strlen(&(xar->file->fflags_text)) > 0) + archive_strappend_char(&(xar->file->fflags_text), ','); + archive_strcat(&(xar->file->fflags_text), flag); + return (1); +} + +#ifdef HAVE_LIBXML_XMLREADER_H + +static int +xml2_xmlattr_setup(struct archive_read *a, + struct xmlattr_list *list, xmlTextReaderPtr reader) +{ + struct xmlattr *attr; + int r; + + list->first = NULL; + list->last = &(list->first); + r = xmlTextReaderMoveToFirstAttribute(reader); + while (r == 1) { + attr = malloc(sizeof*(attr)); + if (attr == NULL) { + archive_set_error(&a->archive, ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + attr->name = strdup( + (const char *)xmlTextReaderConstLocalName(reader)); + if (attr->name == NULL) { + free(attr); + archive_set_error(&a->archive, ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + attr->value = strdup( + (const char *)xmlTextReaderConstValue(reader)); + if (attr->value == NULL) { + free(attr->name); + free(attr); + archive_set_error(&a->archive, ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + attr->next = NULL; + *list->last = attr; + list->last = &(attr->next); + r = xmlTextReaderMoveToNextAttribute(reader); + } + return (r); +} + +static int +xml2_read_cb(void *context, char *buffer, int len) +{ + struct archive_read *a; + struct xar *xar; + const void *d; + size_t outbytes; + size_t used = 0; + int r; + + a = (struct archive_read *)context; + xar = (struct xar *)(a->format->data); + + if (xar->toc_remaining <= 0) + return (0); + d = buffer; + outbytes = len; + r = rd_contents(a, &d, &outbytes, &used, xar->toc_remaining); + if (r != ARCHIVE_OK) + return (r); + __archive_read_consume(a, used); + xar->toc_remaining -= used; + xar->offset += used; + xar->toc_total += outbytes; + PRINT_TOC(buffer, len); + + return ((int)outbytes); +} + +static int +xml2_close_cb(void *context) +{ + + (void)context; /* UNUSED */ + return (0); +} + +static void +xml2_error_hdr(void *arg, const char *msg, xmlParserSeverities severity, + xmlTextReaderLocatorPtr locator) +{ + struct archive_read *a; + + (void)locator; /* UNUSED */ + a = (struct archive_read *)arg; + switch (severity) { + case XML_PARSER_SEVERITY_VALIDITY_WARNING: + case XML_PARSER_SEVERITY_WARNING: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "XML Parsing error: %s", msg); + break; + case XML_PARSER_SEVERITY_VALIDITY_ERROR: + case XML_PARSER_SEVERITY_ERROR: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "XML Parsing error: %s", msg); + break; + } +} + +static int +xml2_read_toc(struct archive_read *a) +{ + xmlTextReaderPtr reader; + struct xmlattr_list list; + int r; + + reader = xmlReaderForIO(xml2_read_cb, xml2_close_cb, a, NULL, NULL, 0); + if (reader == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Couldn't allocate memory for xml parser"); + return (ARCHIVE_FATAL); + } + xmlTextReaderSetErrorHandler(reader, xml2_error_hdr, a); + + while ((r = xmlTextReaderRead(reader)) == 1) { + const char *name, *value; + int type, empty; + + type = xmlTextReaderNodeType(reader); + name = (const char *)xmlTextReaderConstLocalName(reader); + switch (type) { + case XML_READER_TYPE_ELEMENT: + empty = xmlTextReaderIsEmptyElement(reader); + r = xml2_xmlattr_setup(a, &list, reader); + if (r == ARCHIVE_OK) + r = xml_start(a, name, &list); + xmlattr_cleanup(&list); + if (r != ARCHIVE_OK) + return (r); + if (empty) + xml_end(a, name); + break; + case XML_READER_TYPE_END_ELEMENT: + xml_end(a, name); + break; + case XML_READER_TYPE_TEXT: + value = (const char *)xmlTextReaderConstValue(reader); + xml_data(a, value, strlen(value)); + break; + case XML_READER_TYPE_SIGNIFICANT_WHITESPACE: + default: + break; + } + if (r < 0) + break; + } + xmlFreeTextReader(reader); + xmlCleanupParser(); + + return ((r == 0)?ARCHIVE_OK:ARCHIVE_FATAL); +} + +#elif defined(HAVE_BSDXML_H) || defined(HAVE_EXPAT_H) + +static int +expat_xmlattr_setup(struct archive_read *a, + struct xmlattr_list *list, const XML_Char **atts) +{ + struct xmlattr *attr; + char *name, *value; + + list->first = NULL; + list->last = &(list->first); + if (atts == NULL) + return (ARCHIVE_OK); + while (atts[0] != NULL && atts[1] != NULL) { + attr = malloc(sizeof*(attr)); + name = strdup(atts[0]); + value = strdup(atts[1]); + if (attr == NULL || name == NULL || value == NULL) { + archive_set_error(&a->archive, ENOMEM, "Out of memory"); + free(attr); + free(name); + free(value); + return (ARCHIVE_FATAL); + } + attr->name = name; + attr->value = value; + attr->next = NULL; + *list->last = attr; + list->last = &(attr->next); + atts += 2; + } + return (ARCHIVE_OK); +} + +static void +expat_start_cb(void *userData, const XML_Char *name, const XML_Char **atts) +{ + struct expat_userData *ud = (struct expat_userData *)userData; + struct archive_read *a = ud->archive; + struct xmlattr_list list; + int r; + + r = expat_xmlattr_setup(a, &list, atts); + if (r == ARCHIVE_OK) + r = xml_start(a, (const char *)name, &list); + xmlattr_cleanup(&list); + ud->state = r; +} + +static void +expat_end_cb(void *userData, const XML_Char *name) +{ + struct expat_userData *ud = (struct expat_userData *)userData; + + xml_end(ud->archive, (const char *)name); +} + +static void +expat_data_cb(void *userData, const XML_Char *s, int len) +{ + struct expat_userData *ud = (struct expat_userData *)userData; + + xml_data(ud->archive, s, len); +} + +static int +expat_read_toc(struct archive_read *a) +{ + struct xar *xar; + XML_Parser parser; + struct expat_userData ud; + + ud.state = ARCHIVE_OK; + ud.archive = a; + + xar = (struct xar *)(a->format->data); + + /* Initialize XML Parser library. */ + parser = XML_ParserCreate(NULL); + if (parser == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Couldn't allocate memory for xml parser"); + return (ARCHIVE_FATAL); + } + XML_SetUserData(parser, &ud); + XML_SetElementHandler(parser, expat_start_cb, expat_end_cb); + XML_SetCharacterDataHandler(parser, expat_data_cb); + xar->xmlsts = INIT; + + while (xar->toc_remaining && ud.state == ARCHIVE_OK) { + enum XML_Status xr; + const void *d; + size_t outbytes; + size_t used; + int r; + + d = NULL; + r = rd_contents(a, &d, &outbytes, &used, xar->toc_remaining); + if (r != ARCHIVE_OK) + return (r); + xar->toc_remaining -= used; + xar->offset += used; + xar->toc_total += outbytes; + PRINT_TOC(d, outbytes); + + xr = XML_Parse(parser, d, outbytes, xar->toc_remaining == 0); + __archive_read_consume(a, used); + if (xr == XML_STATUS_ERROR) { + XML_ParserFree(parser); + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "XML Parsing failed"); + return (ARCHIVE_FATAL); + } + } + XML_ParserFree(parser); + return (ud.state); +} +#endif /* defined(HAVE_BSDXML_H) || defined(HAVE_EXPAT_H) */ + +#endif /* Support xar format */ diff --cc Utilities/cmlibarchive/libarchive/archive_read_support_format_zip.c index ddd4458,0000000..7e99b12 mode 100644,000000..100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_zip.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_zip.c @@@ -1,3113 -1,0 +1,3143 @@@ +/*- + * Copyright (c) 2004-2013 Tim Kientzle + * Copyright (c) 2011-2012,2014 Michihiro NAKAJIMA + * Copyright (c) 2013 Konrad Kleine + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "archive_platform.h" +__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_zip.c 201102 2009-12-28 03:11:36Z kientzle $"); + +/* + * The definitive documentation of the Zip file format is: + * http://www.pkware.com/documents/casestudies/APPNOTE.TXT + * + * The Info-Zip project has pioneered various extensions to better + * support Zip on Unix, including the 0x5455 "UT", 0x5855 "UX", 0x7855 + * "Ux", and 0x7875 "ux" extensions for time and ownership + * information. + * + * History of this code: The streaming Zip reader was first added to + * libarchive in January 2005. Support for seekable input sources was + * added in Nov 2011. Zip64 support (including a significant code + * refactoring) was added in 2014. + */ + +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_ZLIB_H +#include +#endif + +#include "archive.h" +#include "archive_digest_private.h" +#include "archive_cryptor_private.h" +#include "archive_endian.h" +#include "archive_entry.h" +#include "archive_entry_locale.h" +#include "archive_hmac_private.h" +#include "archive_private.h" +#include "archive_rb.h" +#include "archive_read_private.h" + +#ifndef HAVE_ZLIB_H +#include "archive_crc32.h" +#endif + +struct zip_entry { + struct archive_rb_node node; + struct zip_entry *next; + int64_t local_header_offset; + int64_t compressed_size; + int64_t uncompressed_size; + int64_t gid; + int64_t uid; + struct archive_string rsrcname; + time_t mtime; + time_t atime; + time_t ctime; + uint32_t crc32; + uint16_t mode; + uint16_t zip_flags; /* From GP Flags Field */ + unsigned char compression; + unsigned char system; /* From "version written by" */ + unsigned char flags; /* Our extra markers. */ + unsigned char decdat;/* Used for Decryption check */ + + /* WinZip AES encryption extra field should be available + * when compression is 99. */ + struct { + /* Vendor version: AE-1 - 0x0001, AE-2 - 0x0002 */ + unsigned vendor; +#define AES_VENDOR_AE_1 0x0001 +#define AES_VENDOR_AE_2 0x0002 + /* AES encryption strength: + * 1 - 128 bits, 2 - 192 bits, 2 - 256 bits. */ + unsigned strength; + /* Actual compression method. */ + unsigned char compression; + } aes_extra; +}; + +struct trad_enc_ctx { + uint32_t keys[3]; +}; + +/* Bits used in zip_flags. */ +#define ZIP_ENCRYPTED (1 << 0) +#define ZIP_LENGTH_AT_END (1 << 3) +#define ZIP_STRONG_ENCRYPTED (1 << 6) +#define ZIP_UTF8_NAME (1 << 11) +/* See "7.2 Single Password Symmetric Encryption Method" + in http://www.pkware.com/documents/casestudies/APPNOTE.TXT */ +#define ZIP_CENTRAL_DIRECTORY_ENCRYPTED (1 << 13) + +/* Bits used in flags. */ +#define LA_USED_ZIP64 (1 << 0) +#define LA_FROM_CENTRAL_DIRECTORY (1 << 1) + +/* + * See "WinZip - AES Encryption Information" + * http://www.winzip.com/aes_info.htm + */ +/* Value used in compression method. */ +#define WINZIP_AES_ENCRYPTION 99 +/* Authentication code size. */ +#define AUTH_CODE_SIZE 10 +/**/ +#define MAX_DERIVED_KEY_BUF_SIZE (AES_MAX_KEY_SIZE * 2 + 2) + +struct zip { + /* Structural information about the archive. */ + struct archive_string format_name; + int64_t central_directory_offset; + size_t central_directory_entries_total; + size_t central_directory_entries_on_this_disk; + int has_encrypted_entries; + + /* List of entries (seekable Zip only) */ + struct zip_entry *zip_entries; + struct archive_rb_tree tree; + struct archive_rb_tree tree_rsrc; + + /* Bytes read but not yet consumed via __archive_read_consume() */ + size_t unconsumed; + + /* Information about entry we're currently reading. */ + struct zip_entry *entry; + int64_t entry_bytes_remaining; + + /* These count the number of bytes actually read for the entry. */ + int64_t entry_compressed_bytes_read; + int64_t entry_uncompressed_bytes_read; + + /* Running CRC32 of the decompressed data */ + unsigned long entry_crc32; + unsigned long (*crc32func)(unsigned long, const void *, + size_t); + char ignore_crc32; + + /* Flags to mark progress of decompression. */ + char decompress_init; + char end_of_entry; + +#ifdef HAVE_ZLIB_H + unsigned char *uncompressed_buffer; + size_t uncompressed_buffer_size; + z_stream stream; + char stream_valid; +#endif + + struct archive_string_conv *sconv; + struct archive_string_conv *sconv_default; + struct archive_string_conv *sconv_utf8; + int init_default_conversion; + int process_mac_extensions; + + char init_decryption; + + /* Decryption buffer. */ + /* + * The decrypted data starts at decrypted_ptr and + * extends for decrypted_bytes_remaining. Decryption + * adds new data to the end of this block, data is returned + * to clients from the beginning. When the block hits the + * end of decrypted_buffer, it has to be shuffled back to + * the beginning of the buffer. + */ + unsigned char *decrypted_buffer; + unsigned char *decrypted_ptr; + size_t decrypted_buffer_size; + size_t decrypted_bytes_remaining; + size_t decrypted_unconsumed_bytes; + + /* Traditional PKWARE decryption. */ + struct trad_enc_ctx tctx; + char tctx_valid; + + /* WinZip AES decryption. */ + /* Contexts used for AES decryption. */ + archive_crypto_ctx cctx; + char cctx_valid; + archive_hmac_sha1_ctx hctx; + char hctx_valid; + + /* Strong encryption's decryption header information. */ + unsigned iv_size; + unsigned alg_id; + unsigned bit_len; + unsigned flags; + unsigned erd_size; + unsigned v_size; + unsigned v_crc32; + uint8_t *iv; + uint8_t *erd; + uint8_t *v_data; +}; + +/* Many systems define min or MIN, but not all. */ +#define zipmin(a,b) ((a) < (b) ? (a) : (b)) + +/* ------------------------------------------------------------------------ */ + +/* + Traditional PKWARE Decryption functions. + */ + +static void +trad_enc_update_keys(struct trad_enc_ctx *ctx, uint8_t c) +{ + uint8_t t; +#define CRC32(c, b) (crc32(c ^ 0xffffffffUL, &b, 1) ^ 0xffffffffUL) + + ctx->keys[0] = CRC32(ctx->keys[0], c); + ctx->keys[1] = (ctx->keys[1] + (ctx->keys[0] & 0xff)) * 134775813L + 1; + t = (ctx->keys[1] >> 24) & 0xff; + ctx->keys[2] = CRC32(ctx->keys[2], t); +#undef CRC32 +} + +static uint8_t +trad_enc_decrypt_byte(struct trad_enc_ctx *ctx) +{ + unsigned temp = ctx->keys[2] | 2; + return (uint8_t)((temp * (temp ^ 1)) >> 8) & 0xff; +} + +static void +trad_enc_decrypt_update(struct trad_enc_ctx *ctx, const uint8_t *in, + size_t in_len, uint8_t *out, size_t out_len) +{ + unsigned i, max; + + max = (unsigned)((in_len < out_len)? in_len: out_len); + + for (i = 0; i < max; i++) { + uint8_t t = in[i] ^ trad_enc_decrypt_byte(ctx); + out[i] = t; + trad_enc_update_keys(ctx, t); + } +} + +static int +trad_enc_init(struct trad_enc_ctx *ctx, const char *pw, size_t pw_len, + const uint8_t *key, size_t key_len, uint8_t *crcchk) +{ + uint8_t header[12]; + + if (key_len < 12) { + *crcchk = 0xff; + return -1; + } + + ctx->keys[0] = 305419896L; + ctx->keys[1] = 591751049L; + ctx->keys[2] = 878082192L; + + for (;pw_len; --pw_len) + trad_enc_update_keys(ctx, *pw++); + + trad_enc_decrypt_update(ctx, key, 12, header, 12); + /* Return the last byte for CRC check. */ + *crcchk = header[11]; + return 0; +} + +#if 0 +static void +crypt_derive_key_sha1(const void *p, int size, unsigned char *key, + int key_size) +{ +#define MD_SIZE 20 + archive_sha1_ctx ctx; + unsigned char md1[MD_SIZE]; + unsigned char md2[MD_SIZE * 2]; + unsigned char mkb[64]; + int i; + + archive_sha1_init(&ctx); + archive_sha1_update(&ctx, p, size); + archive_sha1_final(&ctx, md1); + + memset(mkb, 0x36, sizeof(mkb)); + for (i = 0; i < MD_SIZE; i++) + mkb[i] ^= md1[i]; + archive_sha1_init(&ctx); + archive_sha1_update(&ctx, mkb, sizeof(mkb)); + archive_sha1_final(&ctx, md2); + + memset(mkb, 0x5C, sizeof(mkb)); + for (i = 0; i < MD_SIZE; i++) + mkb[i] ^= md1[i]; + archive_sha1_init(&ctx); + archive_sha1_update(&ctx, mkb, sizeof(mkb)); + archive_sha1_final(&ctx, md2 + MD_SIZE); + + if (key_size > 32) + key_size = 32; + memcpy(key, md2, key_size); +#undef MD_SIZE +} +#endif + +/* + * Common code for streaming or seeking modes. + * + * Includes code to read local file headers, decompress data + * from entry bodies, and common API. + */ + +static unsigned long +real_crc32(unsigned long crc, const void *buff, size_t len) +{ + return crc32(crc, buff, (unsigned int)len); +} + +/* Used by "ignorecrc32" option to speed up tests. */ +static unsigned long +fake_crc32(unsigned long crc, const void *buff, size_t len) +{ + (void)crc; /* UNUSED */ + (void)buff; /* UNUSED */ + (void)len; /* UNUSED */ + return 0; +} + +static const struct { + int id; + const char * name; +} compression_methods[] = { + {0, "uncompressed"}, /* The file is stored (no compression) */ + {1, "shrinking"}, /* The file is Shrunk */ + {2, "reduced-1"}, /* The file is Reduced with compression factor 1 */ + {3, "reduced-2"}, /* The file is Reduced with compression factor 2 */ + {4, "reduced-3"}, /* The file is Reduced with compression factor 3 */ + {5, "reduced-4"}, /* The file is Reduced with compression factor 4 */ + {6, "imploded"}, /* The file is Imploded */ + {7, "reserved"}, /* Reserved for Tokenizing compression algorithm */ + {8, "deflation"}, /* The file is Deflated */ + {9, "deflation-64-bit"}, /* Enhanced Deflating using Deflate64(tm) */ + {10, "ibm-terse"},/* PKWARE Data Compression Library Imploding + * (old IBM TERSE) */ + {11, "reserved"}, /* Reserved by PKWARE */ + {12, "bzip"}, /* File is compressed using BZIP2 algorithm */ + {13, "reserved"}, /* Reserved by PKWARE */ + {14, "lzma"}, /* LZMA (EFS) */ + {15, "reserved"}, /* Reserved by PKWARE */ + {16, "reserved"}, /* Reserved by PKWARE */ + {17, "reserved"}, /* Reserved by PKWARE */ + {18, "ibm-terse-new"}, /* File is compressed using IBM TERSE (new) */ + {19, "ibm-lz777"},/* IBM LZ77 z Architecture (PFS) */ + {97, "wav-pack"}, /* WavPack compressed data */ + {98, "ppmd-1"}, /* PPMd version I, Rev 1 */ + {99, "aes"} /* WinZip AES encryption */ +}; + +static const char * +compression_name(const int compression) +{ + static const int num_compression_methods = + sizeof(compression_methods)/sizeof(compression_methods[0]); + int i=0; + + while(compression >= 0 && i < num_compression_methods) { + if (compression_methods[i].id == compression) + return compression_methods[i].name; + i++; + } + return "??"; +} + +/* Convert an MSDOS-style date/time into Unix-style time. */ +static time_t +zip_time(const char *p) +{ + int msTime, msDate; + struct tm ts; + + msTime = (0xff & (unsigned)p[0]) + 256 * (0xff & (unsigned)p[1]); + msDate = (0xff & (unsigned)p[2]) + 256 * (0xff & (unsigned)p[3]); + + memset(&ts, 0, sizeof(ts)); + ts.tm_year = ((msDate >> 9) & 0x7f) + 80; /* Years since 1900. */ + ts.tm_mon = ((msDate >> 5) & 0x0f) - 1; /* Month number. */ + ts.tm_mday = msDate & 0x1f; /* Day of month. */ + ts.tm_hour = (msTime >> 11) & 0x1f; + ts.tm_min = (msTime >> 5) & 0x3f; + ts.tm_sec = (msTime << 1) & 0x3e; + ts.tm_isdst = -1; + return mktime(&ts); +} + +/* + * The extra data is stored as a list of + * id1+size1+data1 + id2+size2+data2 ... + * triplets. id and size are 2 bytes each. + */ +static int +process_extra(struct archive_read *a, const char *p, size_t extra_length, struct zip_entry* zip_entry) +{ + unsigned offset = 0; + + if (extra_length == 0) { + return ARCHIVE_OK; + } + + if (extra_length < 4) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Too-small extra data: Need at least 4 bytes, but only found %d bytes", (int)extra_length); + return ARCHIVE_FAILED; + } + while (offset <= extra_length - 4) { + unsigned short headerid = archive_le16dec(p + offset); + unsigned short datasize = archive_le16dec(p + offset + 2); + + offset += 4; + if (offset + datasize > extra_length) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Extra data overflow: Need %d bytes but only found %d bytes", + (int)datasize, (int)(extra_length - offset)); + return ARCHIVE_FAILED; + } +#ifdef DEBUG + fprintf(stderr, "Header id 0x%04x, length %d\n", + headerid, datasize); +#endif + switch (headerid) { + case 0x0001: + /* Zip64 extended information extra field. */ + zip_entry->flags |= LA_USED_ZIP64; + if (zip_entry->uncompressed_size == 0xffffffff) { + uint64_t t = 0; + if (datasize < 8 + || (t = archive_le64dec(p + offset)) > INT64_MAX) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Malformed 64-bit uncompressed size"); + return ARCHIVE_FAILED; + } + zip_entry->uncompressed_size = t; + offset += 8; + datasize -= 8; + } + if (zip_entry->compressed_size == 0xffffffff) { + uint64_t t = 0; + if (datasize < 8 + || (t = archive_le64dec(p + offset)) > INT64_MAX) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Malformed 64-bit compressed size"); + return ARCHIVE_FAILED; + } + zip_entry->compressed_size = t; + offset += 8; + datasize -= 8; + } + if (zip_entry->local_header_offset == 0xffffffff) { + uint64_t t = 0; + if (datasize < 8 + || (t = archive_le64dec(p + offset)) > INT64_MAX) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Malformed 64-bit local header offset"); + return ARCHIVE_FAILED; + } + zip_entry->local_header_offset = t; + offset += 8; + datasize -= 8; + } + /* archive_le32dec(p + offset) gives disk + * on which file starts, but we don't handle + * multi-volume Zip files. */ + break; +#ifdef DEBUG + case 0x0017: + { + /* Strong encryption field. */ + if (archive_le16dec(p + offset) == 2) { + unsigned algId = + archive_le16dec(p + offset + 2); + unsigned bitLen = + archive_le16dec(p + offset + 4); + int flags = + archive_le16dec(p + offset + 6); + fprintf(stderr, "algId=0x%04x, bitLen=%u, " + "flgas=%d\n", algId, bitLen,flags); + } + break; + } +#endif + case 0x5455: + { + /* Extended time field "UT". */ - int flags = p[offset]; ++ int flags; ++ if (datasize == 0) { ++ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, ++ "Incomplete extended time field"); ++ return ARCHIVE_FAILED; ++ } ++ flags = p[offset]; + offset++; + datasize--; + /* Flag bits indicate which dates are present. */ + if (flags & 0x01) + { +#ifdef DEBUG + fprintf(stderr, "mtime: %lld -> %d\n", + (long long)zip_entry->mtime, + archive_le32dec(p + offset)); +#endif + if (datasize < 4) + break; + zip_entry->mtime = archive_le32dec(p + offset); + offset += 4; + datasize -= 4; + } + if (flags & 0x02) + { + if (datasize < 4) + break; + zip_entry->atime = archive_le32dec(p + offset); + offset += 4; + datasize -= 4; + } + if (flags & 0x04) + { + if (datasize < 4) + break; + zip_entry->ctime = archive_le32dec(p + offset); + offset += 4; + datasize -= 4; + } + break; + } + case 0x5855: + { + /* Info-ZIP Unix Extra Field (old version) "UX". */ + if (datasize >= 8) { + zip_entry->atime = archive_le32dec(p + offset); + zip_entry->mtime = + archive_le32dec(p + offset + 4); + } + if (datasize >= 12) { + zip_entry->uid = + archive_le16dec(p + offset + 8); + zip_entry->gid = + archive_le16dec(p + offset + 10); + } + break; + } + case 0x6c78: + { + /* Experimental 'xl' field */ + /* + * Introduced Dec 2013 to provide a way to + * include external file attributes (and other + * fields that ordinarily appear only in + * central directory) in local file header. + * This provides file type and permission + * information necessary to support full + * streaming extraction. Currently being + * discussed with other Zip developers + * ... subject to change. + * + * Format: + * The field starts with a bitmap that specifies + * which additional fields are included. The + * bitmap is variable length and can be extended in + * the future. + * + * n bytes - feature bitmap: first byte has low-order + * 7 bits. If high-order bit is set, a subsequent + * byte holds the next 7 bits, etc. + * + * if bitmap & 1, 2 byte "version made by" + * if bitmap & 2, 2 byte "internal file attributes" + * if bitmap & 4, 4 byte "external file attributes" + * if bitmap & 8, 2 byte comment length + n byte comment + */ + int bitmap, bitmap_last; + + if (datasize < 1) + break; + bitmap_last = bitmap = 0xff & p[offset]; + offset += 1; + datasize -= 1; + + /* We only support first 7 bits of bitmap; skip rest. */ + while ((bitmap_last & 0x80) != 0 + && datasize >= 1) { + bitmap_last = p[offset]; + offset += 1; + datasize -= 1; + } + + if (bitmap & 1) { + /* 2 byte "version made by" */ + if (datasize < 2) + break; + zip_entry->system + = archive_le16dec(p + offset) >> 8; + offset += 2; + datasize -= 2; + } + if (bitmap & 2) { + /* 2 byte "internal file attributes" */ + uint32_t internal_attributes; + if (datasize < 2) + break; + internal_attributes + = archive_le16dec(p + offset); + /* Not used by libarchive at present. */ + (void)internal_attributes; /* UNUSED */ + offset += 2; + datasize -= 2; + } + if (bitmap & 4) { + /* 4 byte "external file attributes" */ + uint32_t external_attributes; + if (datasize < 4) + break; + external_attributes + = archive_le32dec(p + offset); + if (zip_entry->system == 3) { + zip_entry->mode + = external_attributes >> 16; + } else if (zip_entry->system == 0) { + // Interpret MSDOS directory bit + if (0x10 == (external_attributes & 0x10)) { + zip_entry->mode = AE_IFDIR | 0775; + } else { + zip_entry->mode = AE_IFREG | 0664; + } + if (0x01 == (external_attributes & 0x01)) { + // Read-only bit; strip write permissions + zip_entry->mode &= 0555; + } + } else { + zip_entry->mode = 0; + } + offset += 4; + datasize -= 4; + } + if (bitmap & 8) { + /* 2 byte comment length + comment */ + uint32_t comment_length; + if (datasize < 2) + break; + comment_length + = archive_le16dec(p + offset); + offset += 2; + datasize -= 2; + + if (datasize < comment_length) + break; + /* Comment is not supported by libarchive */ + offset += comment_length; + datasize -= comment_length; + } + break; + } + case 0x7855: + /* Info-ZIP Unix Extra Field (type 2) "Ux". */ +#ifdef DEBUG + fprintf(stderr, "uid %d gid %d\n", + archive_le16dec(p + offset), + archive_le16dec(p + offset + 2)); +#endif + if (datasize >= 2) + zip_entry->uid = archive_le16dec(p + offset); + if (datasize >= 4) + zip_entry->gid = + archive_le16dec(p + offset + 2); + break; + case 0x7875: + { + /* Info-Zip Unix Extra Field (type 3) "ux". */ + int uidsize = 0, gidsize = 0; + + /* TODO: support arbitrary uidsize/gidsize. */ + if (datasize >= 1 && p[offset] == 1) {/* version=1 */ + if (datasize >= 4) { + /* get a uid size. */ + uidsize = 0xff & (int)p[offset+1]; + if (uidsize == 2) + zip_entry->uid = + archive_le16dec( + p + offset + 2); + else if (uidsize == 4 && datasize >= 6) + zip_entry->uid = + archive_le32dec( + p + offset + 2); + } + if (datasize >= (2 + uidsize + 3)) { + /* get a gid size. */ + gidsize = 0xff & (int)p[offset+2+uidsize]; + if (gidsize == 2) + zip_entry->gid = + archive_le16dec( + p+offset+2+uidsize+1); + else if (gidsize == 4 && + datasize >= (2 + uidsize + 5)) + zip_entry->gid = + archive_le32dec( + p+offset+2+uidsize+1); + } + } + break; + } + case 0x9901: + /* WinZip AES extra data field. */ ++ if (datasize < 6) { ++ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, ++ "Incomplete AES field"); ++ return ARCHIVE_FAILED; ++ } + if (p[offset + 2] == 'A' && p[offset + 3] == 'E') { + /* Vendor version. */ + zip_entry->aes_extra.vendor = + archive_le16dec(p + offset); + /* AES encryption strength. */ + zip_entry->aes_extra.strength = p[offset + 4]; + /* Actual compression method. */ + zip_entry->aes_extra.compression = + p[offset + 5]; + } + break; + default: + break; + } + offset += datasize; + } + if (offset != extra_length) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Malformed extra data: Consumed %d bytes of %d bytes", + (int)offset, (int)extra_length); + return ARCHIVE_FAILED; + } + return ARCHIVE_OK; +} + +/* + * Assumes file pointer is at beginning of local file header. + */ +static int +zip_read_local_file_header(struct archive_read *a, struct archive_entry *entry, + struct zip *zip) +{ + const char *p; + const void *h; + const wchar_t *wp; + const char *cp; + size_t len, filename_length, extra_length; + struct archive_string_conv *sconv; + struct zip_entry *zip_entry = zip->entry; + struct zip_entry zip_entry_central_dir; + int ret = ARCHIVE_OK; + char version; + + /* Save a copy of the original for consistency checks. */ + zip_entry_central_dir = *zip_entry; + + zip->decompress_init = 0; + zip->end_of_entry = 0; + zip->entry_uncompressed_bytes_read = 0; + zip->entry_compressed_bytes_read = 0; + zip->entry_crc32 = zip->crc32func(0, NULL, 0); + + /* Setup default conversion. */ + if (zip->sconv == NULL && !zip->init_default_conversion) { + zip->sconv_default = + archive_string_default_conversion_for_read(&(a->archive)); + zip->init_default_conversion = 1; + } + + if ((p = __archive_read_ahead(a, 30, NULL)) == NULL) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated ZIP file header"); + return (ARCHIVE_FATAL); + } + + if (memcmp(p, "PK\003\004", 4) != 0) { + archive_set_error(&a->archive, -1, "Damaged Zip archive"); + return ARCHIVE_FATAL; + } + version = p[4]; + zip_entry->system = p[5]; + zip_entry->zip_flags = archive_le16dec(p + 6); + if (zip_entry->zip_flags & (ZIP_ENCRYPTED | ZIP_STRONG_ENCRYPTED)) { + zip->has_encrypted_entries = 1; + archive_entry_set_is_data_encrypted(entry, 1); + if (zip_entry->zip_flags & ZIP_CENTRAL_DIRECTORY_ENCRYPTED && + zip_entry->zip_flags & ZIP_ENCRYPTED && + zip_entry->zip_flags & ZIP_STRONG_ENCRYPTED) { + archive_entry_set_is_metadata_encrypted(entry, 1); + return ARCHIVE_FATAL; + } + } + zip->init_decryption = (zip_entry->zip_flags & ZIP_ENCRYPTED); + zip_entry->compression = (char)archive_le16dec(p + 8); + zip_entry->mtime = zip_time(p + 10); + zip_entry->crc32 = archive_le32dec(p + 14); + if (zip_entry->zip_flags & ZIP_LENGTH_AT_END) + zip_entry->decdat = p[11]; + else + zip_entry->decdat = p[17]; + zip_entry->compressed_size = archive_le32dec(p + 18); + zip_entry->uncompressed_size = archive_le32dec(p + 22); + filename_length = archive_le16dec(p + 26); + extra_length = archive_le16dec(p + 28); + + __archive_read_consume(a, 30); + + /* Read the filename. */ + if ((h = __archive_read_ahead(a, filename_length, NULL)) == NULL) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated ZIP file header"); + return (ARCHIVE_FATAL); + } + if (zip_entry->zip_flags & ZIP_UTF8_NAME) { + /* The filename is stored to be UTF-8. */ + if (zip->sconv_utf8 == NULL) { + zip->sconv_utf8 = + archive_string_conversion_from_charset( + &a->archive, "UTF-8", 1); + if (zip->sconv_utf8 == NULL) + return (ARCHIVE_FATAL); + } + sconv = zip->sconv_utf8; + } else if (zip->sconv != NULL) + sconv = zip->sconv; + else + sconv = zip->sconv_default; + + if (archive_entry_copy_pathname_l(entry, + h, filename_length, sconv) != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Pathname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Pathname cannot be converted " + "from %s to current locale.", + archive_string_conversion_charset_name(sconv)); + ret = ARCHIVE_WARN; + } + __archive_read_consume(a, filename_length); + + /* Read the extra data. */ + if ((h = __archive_read_ahead(a, extra_length, NULL)) == NULL) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated ZIP file header"); + return (ARCHIVE_FATAL); + } + + if (ARCHIVE_OK != process_extra(a, h, extra_length, zip_entry)) { + return ARCHIVE_FATAL; + } + __archive_read_consume(a, extra_length); + + /* Work around a bug in Info-Zip: When reading from a pipe, it + * stats the pipe instead of synthesizing a file entry. */ + if ((zip_entry->mode & AE_IFMT) == AE_IFIFO) { + zip_entry->mode &= ~ AE_IFMT; + zip_entry->mode |= AE_IFREG; + } + + /* If the mode is totally empty, set some sane default. */ + if (zip_entry->mode == 0) { + zip_entry->mode |= 0664; + } + ++ /* Windows archivers sometimes use backslash as the directory separator. ++ Normalize to slash. */ ++ if (zip_entry->system == 0 && ++ (wp = archive_entry_pathname_w(entry)) != NULL) { ++ if (wcschr(wp, L'/') == NULL && wcschr(wp, L'\\') != NULL) { ++ size_t i; ++ struct archive_wstring s; ++ archive_string_init(&s); ++ archive_wstrcpy(&s, wp); ++ for (i = 0; i < archive_strlen(&s); i++) { ++ if (s.s[i] == '\\') ++ s.s[i] = '/'; ++ } ++ archive_entry_copy_pathname_w(entry, s.s); ++ archive_wstring_free(&s); ++ } ++ } ++ + /* Make sure that entries with a trailing '/' are marked as directories + * even if the External File Attributes contains bogus values. If this + * is not a directory and there is no type, assume regularfile. */ + if ((zip_entry->mode & AE_IFMT) != AE_IFDIR) { + int has_slash; + + wp = archive_entry_pathname_w(entry); + if (wp != NULL) { + len = wcslen(wp); + has_slash = len > 0 && wp[len - 1] == L'/'; + } else { + cp = archive_entry_pathname(entry); + len = (cp != NULL)?strlen(cp):0; + has_slash = len > 0 && cp[len - 1] == '/'; + } + /* Correct file type as needed. */ + if (has_slash) { + zip_entry->mode &= ~AE_IFMT; + zip_entry->mode |= AE_IFDIR; + zip_entry->mode |= 0111; + } else if ((zip_entry->mode & AE_IFMT) == 0) { + zip_entry->mode |= AE_IFREG; + } + } + + /* Make sure directories end in '/' */ + if ((zip_entry->mode & AE_IFMT) == AE_IFDIR) { + wp = archive_entry_pathname_w(entry); + if (wp != NULL) { + len = wcslen(wp); + if (len > 0 && wp[len - 1] != L'/') { + struct archive_wstring s; + archive_string_init(&s); + archive_wstrcat(&s, wp); + archive_wstrappend_wchar(&s, L'/'); + archive_entry_copy_pathname_w(entry, s.s); + archive_wstring_free(&s); + } + } else { + cp = archive_entry_pathname(entry); + len = (cp != NULL)?strlen(cp):0; + if (len > 0 && cp[len - 1] != '/') { + struct archive_string s; + archive_string_init(&s); + archive_strcat(&s, cp); + archive_strappend_char(&s, '/'); + archive_entry_set_pathname(entry, s.s); + archive_string_free(&s); + } + } + } + + if (zip_entry->flags & LA_FROM_CENTRAL_DIRECTORY) { + /* If this came from the central dir, it's size info + * is definitive, so ignore the length-at-end flag. */ + zip_entry->zip_flags &= ~ZIP_LENGTH_AT_END; + /* If local header is missing a value, use the one from + the central directory. If both have it, warn about + mismatches. */ + if (zip_entry->crc32 == 0) { + zip_entry->crc32 = zip_entry_central_dir.crc32; + } else if (!zip->ignore_crc32 + && zip_entry->crc32 != zip_entry_central_dir.crc32) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Inconsistent CRC32 values"); + ret = ARCHIVE_WARN; + } + if (zip_entry->compressed_size == 0) { + zip_entry->compressed_size + = zip_entry_central_dir.compressed_size; + } else if (zip_entry->compressed_size + != zip_entry_central_dir.compressed_size) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Inconsistent compressed size: " + "%jd in central directory, %jd in local header", + (intmax_t)zip_entry_central_dir.compressed_size, + (intmax_t)zip_entry->compressed_size); + ret = ARCHIVE_WARN; + } + if (zip_entry->uncompressed_size == 0) { + zip_entry->uncompressed_size + = zip_entry_central_dir.uncompressed_size; + } else if (zip_entry->uncompressed_size + != zip_entry_central_dir.uncompressed_size) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Inconsistent uncompressed size: " + "%jd in central directory, %jd in local header", + (intmax_t)zip_entry_central_dir.uncompressed_size, + (intmax_t)zip_entry->uncompressed_size); + ret = ARCHIVE_WARN; + } + } + + /* Populate some additional entry fields: */ + archive_entry_set_mode(entry, zip_entry->mode); + archive_entry_set_uid(entry, zip_entry->uid); + archive_entry_set_gid(entry, zip_entry->gid); + archive_entry_set_mtime(entry, zip_entry->mtime, 0); + archive_entry_set_ctime(entry, zip_entry->ctime, 0); + archive_entry_set_atime(entry, zip_entry->atime, 0); + + if ((zip->entry->mode & AE_IFMT) == AE_IFLNK) { + size_t linkname_length; + + if (zip_entry->compressed_size > 64 * 1024) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Zip file with oversized link entry"); + return ARCHIVE_FATAL; + } + + linkname_length = (size_t)zip_entry->compressed_size; + + archive_entry_set_size(entry, 0); + p = __archive_read_ahead(a, linkname_length, NULL); + if (p == NULL) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Truncated Zip file"); + return ARCHIVE_FATAL; + } + + sconv = zip->sconv; + if (sconv == NULL && (zip->entry->zip_flags & ZIP_UTF8_NAME)) + sconv = zip->sconv_utf8; + if (sconv == NULL) + sconv = zip->sconv_default; + if (archive_entry_copy_symlink_l(entry, p, linkname_length, + sconv) != 0) { + if (errno != ENOMEM && sconv == zip->sconv_utf8 && + (zip->entry->zip_flags & ZIP_UTF8_NAME)) + archive_entry_copy_symlink_l(entry, p, + linkname_length, NULL); + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Symlink"); + return (ARCHIVE_FATAL); + } + /* + * Since there is no character-set regulation for + * symlink name, do not report the conversion error + * in an automatic conversion. + */ + if (sconv != zip->sconv_utf8 || + (zip->entry->zip_flags & ZIP_UTF8_NAME) == 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Symlink cannot be converted " + "from %s to current locale.", + archive_string_conversion_charset_name( + sconv)); + ret = ARCHIVE_WARN; + } + } + zip_entry->uncompressed_size = zip_entry->compressed_size = 0; + + if (__archive_read_consume(a, linkname_length) < 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Read error skipping symlink target name"); + return ARCHIVE_FATAL; + } + } else if (0 == (zip_entry->zip_flags & ZIP_LENGTH_AT_END) + || zip_entry->uncompressed_size > 0) { + /* Set the size only if it's meaningful. */ + archive_entry_set_size(entry, zip_entry->uncompressed_size); + } + zip->entry_bytes_remaining = zip_entry->compressed_size; + + /* If there's no body, force read_data() to return EOF immediately. */ + if (0 == (zip_entry->zip_flags & ZIP_LENGTH_AT_END) + && zip->entry_bytes_remaining < 1) + zip->end_of_entry = 1; + + /* Set up a more descriptive format name. */ ++ archive_string_empty(&zip->format_name); + archive_string_sprintf(&zip->format_name, "ZIP %d.%d (%s)", + version / 10, version % 10, + compression_name(zip->entry->compression)); + a->archive.archive_format_name = zip->format_name.s; + + return (ret); +} + +static int +check_authentication_code(struct archive_read *a, const void *_p) +{ + struct zip *zip = (struct zip *)(a->format->data); + + /* Check authentication code. */ + if (zip->hctx_valid) { + const void *p; + uint8_t hmac[20]; + size_t hmac_len = 20; + int cmp; + + archive_hmac_sha1_final(&zip->hctx, hmac, &hmac_len); + if (_p == NULL) { + /* Read authentication code. */ + p = __archive_read_ahead(a, AUTH_CODE_SIZE, NULL); + if (p == NULL) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated ZIP file data"); + return (ARCHIVE_FATAL); + } + } else { + p = _p; + } + cmp = memcmp(hmac, p, AUTH_CODE_SIZE); + __archive_read_consume(a, AUTH_CODE_SIZE); + if (cmp != 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "ZIP bad Authentication code"); + return (ARCHIVE_WARN); + } + } + return (ARCHIVE_OK); +} + +/* + * Read "uncompressed" data. There are three cases: + * 1) We know the size of the data. This is always true for the + * seeking reader (we've examined the Central Directory already). + * 2) ZIP_LENGTH_AT_END was set, but only the CRC was deferred. + * Info-ZIP seems to do this; we know the size but have to grab + * the CRC from the data descriptor afterwards. + * 3) We're streaming and ZIP_LENGTH_AT_END was specified and + * we have no size information. In this case, we can do pretty + * well by watching for the data descriptor record. The data + * descriptor is 16 bytes and includes a computed CRC that should + * provide a strong check. + * + * TODO: Technically, the PK\007\010 signature is optional. + * In the original spec, the data descriptor contained CRC + * and size fields but had no leading signature. In practice, + * newer writers seem to provide the signature pretty consistently. + * + * For uncompressed data, the PK\007\010 marker seems essential + * to be sure we've actually seen the end of the entry. + * + * Returns ARCHIVE_OK if successful, ARCHIVE_FATAL otherwise, sets + * zip->end_of_entry if it consumes all of the data. + */ +static int +zip_read_data_none(struct archive_read *a, const void **_buff, + size_t *size, int64_t *offset) +{ + struct zip *zip; + const char *buff; + ssize_t bytes_avail; + int r; + + (void)offset; /* UNUSED */ + + zip = (struct zip *)(a->format->data); + + if (zip->entry->zip_flags & ZIP_LENGTH_AT_END) { + const char *p; + ssize_t grabbing_bytes = 24; + + if (zip->hctx_valid) + grabbing_bytes += AUTH_CODE_SIZE; + /* Grab at least 24 bytes. */ + buff = __archive_read_ahead(a, grabbing_bytes, &bytes_avail); + if (bytes_avail < grabbing_bytes) { + /* Zip archives have end-of-archive markers + that are longer than this, so a failure to get at + least 24 bytes really does indicate a truncated + file. */ + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated ZIP file data"); + return (ARCHIVE_FATAL); + } + /* Check for a complete PK\007\010 signature, followed + * by the correct 4-byte CRC. */ + p = buff; + if (zip->hctx_valid) + p += AUTH_CODE_SIZE; + if (p[0] == 'P' && p[1] == 'K' + && p[2] == '\007' && p[3] == '\010' + && (archive_le32dec(p + 4) == zip->entry_crc32 + || zip->ignore_crc32 + || (zip->hctx_valid + && zip->entry->aes_extra.vendor == AES_VENDOR_AE_2))) { + if (zip->entry->flags & LA_USED_ZIP64) { + uint64_t compressed, uncompressed; + zip->entry->crc32 = archive_le32dec(p + 4); + compressed = archive_le64dec(p + 8); + uncompressed = archive_le64dec(p + 16); + if (compressed > INT64_MAX || uncompressed > INT64_MAX) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Overflow of 64-bit file sizes"); + return ARCHIVE_FAILED; + } + zip->entry->compressed_size = compressed; + zip->entry->uncompressed_size = uncompressed; + zip->unconsumed = 24; + } else { + zip->entry->crc32 = archive_le32dec(p + 4); + zip->entry->compressed_size = + archive_le32dec(p + 8); + zip->entry->uncompressed_size = + archive_le32dec(p + 12); + zip->unconsumed = 16; + } + if (zip->hctx_valid) { + r = check_authentication_code(a, buff); + if (r != ARCHIVE_OK) + return (r); + } + zip->end_of_entry = 1; + return (ARCHIVE_OK); + } + /* If not at EOF, ensure we consume at least one byte. */ + ++p; + + /* Scan forward until we see where a PK\007\010 signature + * might be. */ + /* Return bytes up until that point. On the next call, + * the code above will verify the data descriptor. */ + while (p < buff + bytes_avail - 4) { + if (p[3] == 'P') { p += 3; } + else if (p[3] == 'K') { p += 2; } + else if (p[3] == '\007') { p += 1; } + else if (p[3] == '\010' && p[2] == '\007' + && p[1] == 'K' && p[0] == 'P') { + if (zip->hctx_valid) + p -= AUTH_CODE_SIZE; + break; + } else { p += 4; } + } + bytes_avail = p - buff; + } else { + if (zip->entry_bytes_remaining == 0) { + zip->end_of_entry = 1; + if (zip->hctx_valid) { + r = check_authentication_code(a, NULL); + if (r != ARCHIVE_OK) + return (r); + } + return (ARCHIVE_OK); + } + /* Grab a bunch of bytes. */ + buff = __archive_read_ahead(a, 1, &bytes_avail); + if (bytes_avail <= 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated ZIP file data"); + return (ARCHIVE_FATAL); + } + if (bytes_avail > zip->entry_bytes_remaining) + bytes_avail = (ssize_t)zip->entry_bytes_remaining; + } + if (zip->tctx_valid || zip->cctx_valid) { + size_t dec_size = bytes_avail; + + if (dec_size > zip->decrypted_buffer_size) + dec_size = zip->decrypted_buffer_size; + if (zip->tctx_valid) { + trad_enc_decrypt_update(&zip->tctx, + (const uint8_t *)buff, dec_size, + zip->decrypted_buffer, dec_size); + } else { + size_t dsize = dec_size; + archive_hmac_sha1_update(&zip->hctx, + (const uint8_t *)buff, dec_size); + archive_decrypto_aes_ctr_update(&zip->cctx, + (const uint8_t *)buff, dec_size, + zip->decrypted_buffer, &dsize); + } + bytes_avail = dec_size; + buff = (const char *)zip->decrypted_buffer; + } + *size = bytes_avail; + zip->entry_bytes_remaining -= bytes_avail; + zip->entry_uncompressed_bytes_read += bytes_avail; + zip->entry_compressed_bytes_read += bytes_avail; + zip->unconsumed += bytes_avail; + *_buff = buff; + return (ARCHIVE_OK); +} + +#ifdef HAVE_ZLIB_H +static int +zip_deflate_init(struct archive_read *a, struct zip *zip) +{ + int r; + + /* If we haven't yet read any data, initialize the decompressor. */ + if (!zip->decompress_init) { + if (zip->stream_valid) + r = inflateReset(&zip->stream); + else + r = inflateInit2(&zip->stream, + -15 /* Don't check for zlib header */); + if (r != Z_OK) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Can't initialize ZIP decompression."); + return (ARCHIVE_FATAL); + } + /* Stream structure has been set up. */ + zip->stream_valid = 1; + /* We've initialized decompression for this stream. */ + zip->decompress_init = 1; + } + return (ARCHIVE_OK); +} + +static int +zip_read_data_deflate(struct archive_read *a, const void **buff, + size_t *size, int64_t *offset) +{ + struct zip *zip; + ssize_t bytes_avail; + const void *compressed_buff, *sp; + int r; + + (void)offset; /* UNUSED */ + + zip = (struct zip *)(a->format->data); + + /* If the buffer hasn't been allocated, allocate it now. */ + if (zip->uncompressed_buffer == NULL) { + zip->uncompressed_buffer_size = 256 * 1024; + zip->uncompressed_buffer + = (unsigned char *)malloc(zip->uncompressed_buffer_size); + if (zip->uncompressed_buffer == NULL) { + archive_set_error(&a->archive, ENOMEM, + "No memory for ZIP decompression"); + return (ARCHIVE_FATAL); + } + } + + r = zip_deflate_init(a, zip); + if (r != ARCHIVE_OK) + return (r); + + /* + * Note: '1' here is a performance optimization. + * Recall that the decompression layer returns a count of + * available bytes; asking for more than that forces the + * decompressor to combine reads by copying data. + */ + compressed_buff = sp = __archive_read_ahead(a, 1, &bytes_avail); + if (0 == (zip->entry->zip_flags & ZIP_LENGTH_AT_END) + && bytes_avail > zip->entry_bytes_remaining) { + bytes_avail = (ssize_t)zip->entry_bytes_remaining; + } + if (bytes_avail < 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated ZIP file body"); + return (ARCHIVE_FATAL); + } + + if (zip->tctx_valid || zip->cctx_valid) { + if (zip->decrypted_bytes_remaining < (size_t)bytes_avail) { + size_t buff_remaining = + (zip->decrypted_buffer + zip->decrypted_buffer_size) + - (zip->decrypted_ptr + zip->decrypted_bytes_remaining); + + if (buff_remaining > (size_t)bytes_avail) + buff_remaining = (size_t)bytes_avail; + + if (0 == (zip->entry->zip_flags & ZIP_LENGTH_AT_END) && + zip->entry_bytes_remaining > 0) { + if ((int64_t)(zip->decrypted_bytes_remaining + + buff_remaining) + > zip->entry_bytes_remaining) { + if (zip->entry_bytes_remaining < + (int64_t)zip->decrypted_bytes_remaining) + buff_remaining = 0; + else + buff_remaining = + (size_t)zip->entry_bytes_remaining + - zip->decrypted_bytes_remaining; + } + } + if (buff_remaining > 0) { + if (zip->tctx_valid) { + trad_enc_decrypt_update(&zip->tctx, + compressed_buff, buff_remaining, + zip->decrypted_ptr + + zip->decrypted_bytes_remaining, + buff_remaining); + } else { + size_t dsize = buff_remaining; + archive_decrypto_aes_ctr_update( + &zip->cctx, + compressed_buff, buff_remaining, + zip->decrypted_ptr + + zip->decrypted_bytes_remaining, + &dsize); + } + zip->decrypted_bytes_remaining += buff_remaining; + } + } + bytes_avail = zip->decrypted_bytes_remaining; + compressed_buff = (const char *)zip->decrypted_ptr; + } + + /* + * A bug in zlib.h: stream.next_in should be marked 'const' + * but isn't (the library never alters data through the + * next_in pointer, only reads it). The result: this ugly + * cast to remove 'const'. + */ + zip->stream.next_in = (Bytef *)(uintptr_t)(const void *)compressed_buff; + zip->stream.avail_in = (uInt)bytes_avail; + zip->stream.total_in = 0; + zip->stream.next_out = zip->uncompressed_buffer; + zip->stream.avail_out = (uInt)zip->uncompressed_buffer_size; + zip->stream.total_out = 0; + + r = inflate(&zip->stream, 0); + switch (r) { + case Z_OK: + break; + case Z_STREAM_END: + zip->end_of_entry = 1; + break; + case Z_MEM_ERROR: + archive_set_error(&a->archive, ENOMEM, + "Out of memory for ZIP decompression"); + return (ARCHIVE_FATAL); + default: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "ZIP decompression failed (%d)", r); + return (ARCHIVE_FATAL); + } + + /* Consume as much as the compressor actually used. */ + bytes_avail = zip->stream.total_in; + if (zip->tctx_valid || zip->cctx_valid) { + zip->decrypted_bytes_remaining -= bytes_avail; + if (zip->decrypted_bytes_remaining == 0) + zip->decrypted_ptr = zip->decrypted_buffer; + else + zip->decrypted_ptr += bytes_avail; + } + /* Calculate compressed data as much as we used.*/ + if (zip->hctx_valid) + archive_hmac_sha1_update(&zip->hctx, sp, bytes_avail); + __archive_read_consume(a, bytes_avail); + zip->entry_bytes_remaining -= bytes_avail; + zip->entry_compressed_bytes_read += bytes_avail; + + *size = zip->stream.total_out; + zip->entry_uncompressed_bytes_read += zip->stream.total_out; + *buff = zip->uncompressed_buffer; + + if (zip->end_of_entry && zip->hctx_valid) { + r = check_authentication_code(a, NULL); + if (r != ARCHIVE_OK) + return (r); + } + + if (zip->end_of_entry && (zip->entry->zip_flags & ZIP_LENGTH_AT_END)) { + const char *p; + + if (NULL == (p = __archive_read_ahead(a, 24, NULL))) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated ZIP end-of-file record"); + return (ARCHIVE_FATAL); + } + /* Consume the optional PK\007\010 marker. */ + if (p[0] == 'P' && p[1] == 'K' && + p[2] == '\007' && p[3] == '\010') { + p += 4; + zip->unconsumed = 4; + } + if (zip->entry->flags & LA_USED_ZIP64) { + uint64_t compressed, uncompressed; + zip->entry->crc32 = archive_le32dec(p); + compressed = archive_le64dec(p + 4); + uncompressed = archive_le64dec(p + 12); + if (compressed > INT64_MAX || uncompressed > INT64_MAX) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Overflow of 64-bit file sizes"); + return ARCHIVE_FAILED; + } + zip->entry->compressed_size = compressed; + zip->entry->uncompressed_size = uncompressed; + zip->unconsumed += 20; + } else { + zip->entry->crc32 = archive_le32dec(p); + zip->entry->compressed_size = archive_le32dec(p + 4); + zip->entry->uncompressed_size = archive_le32dec(p + 8); + zip->unconsumed += 12; + } + } + + return (ARCHIVE_OK); +} +#endif + +static int +read_decryption_header(struct archive_read *a) +{ + struct zip *zip = (struct zip *)(a->format->data); + const char *p; + unsigned int remaining_size; + unsigned int ts; + + /* + * Read an initialization vector data field. + */ + p = __archive_read_ahead(a, 2, NULL); + if (p == NULL) + goto truncated; + ts = zip->iv_size; + zip->iv_size = archive_le16dec(p); + __archive_read_consume(a, 2); + if (ts < zip->iv_size) { + free(zip->iv); + zip->iv = NULL; + } + p = __archive_read_ahead(a, zip->iv_size, NULL); + if (p == NULL) + goto truncated; + if (zip->iv == NULL) { + zip->iv = malloc(zip->iv_size); + if (zip->iv == NULL) + goto nomem; + } + memcpy(zip->iv, p, zip->iv_size); + __archive_read_consume(a, zip->iv_size); + + /* + * Read a size of remaining decryption header field. + */ + p = __archive_read_ahead(a, 14, NULL); + if (p == NULL) + goto truncated; + remaining_size = archive_le32dec(p); + if (remaining_size < 16 || remaining_size > (1 << 18)) + goto corrupted; + + /* Check if format version is supported. */ + if (archive_le16dec(p+4) != 3) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Unsupported encryption format version: %u", + archive_le16dec(p+4)); + return (ARCHIVE_FAILED); + } + + /* + * Read an encryption algorithm field. + */ + zip->alg_id = archive_le16dec(p+6); + switch (zip->alg_id) { + case 0x6601:/* DES */ + case 0x6602:/* RC2 */ + case 0x6603:/* 3DES 168 */ + case 0x6609:/* 3DES 112 */ + case 0x660E:/* AES 128 */ + case 0x660F:/* AES 192 */ + case 0x6610:/* AES 256 */ + case 0x6702:/* RC2 (version >= 5.2) */ + case 0x6720:/* Blowfish */ + case 0x6721:/* Twofish */ + case 0x6801:/* RC4 */ + /* Supported encryption algorithm. */ + break; + default: + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Unknown encryption algorithm: %u", zip->alg_id); + return (ARCHIVE_FAILED); + } + + /* + * Read a bit length field. + */ + zip->bit_len = archive_le16dec(p+8); + + /* + * Read a flags field. + */ + zip->flags = archive_le16dec(p+10); + switch (zip->flags & 0xf000) { + case 0x0001: /* Password is required to decrypt. */ + case 0x0002: /* Certificates only. */ + case 0x0003: /* Password or certificate required to decrypt. */ + break; + default: + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Unknown encryption flag: %u", zip->flags); + return (ARCHIVE_FAILED); + } + if ((zip->flags & 0xf000) == 0 || + (zip->flags & 0xf000) == 0x4000) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Unknown encryption flag: %u", zip->flags); + return (ARCHIVE_FAILED); + } + + /* + * Read an encrypted random data field. + */ + ts = zip->erd_size; + zip->erd_size = archive_le16dec(p+12); + __archive_read_consume(a, 14); + if ((zip->erd_size & 0xf) != 0 || + (zip->erd_size + 16) > remaining_size || + (zip->erd_size + 16) < zip->erd_size) + goto corrupted; + + if (ts < zip->erd_size) { + free(zip->erd); + zip->erd = NULL; + } + p = __archive_read_ahead(a, zip->erd_size, NULL); + if (p == NULL) + goto truncated; + if (zip->erd == NULL) { + zip->erd = malloc(zip->erd_size); + if (zip->erd == NULL) + goto nomem; + } + memcpy(zip->erd, p, zip->erd_size); + __archive_read_consume(a, zip->erd_size); + + /* + * Read a reserved data field. + */ + p = __archive_read_ahead(a, 4, NULL); + if (p == NULL) + goto truncated; + /* Reserved data size should be zero. */ + if (archive_le32dec(p) != 0) + goto corrupted; + __archive_read_consume(a, 4); + + /* + * Read a password validation data field. + */ + p = __archive_read_ahead(a, 2, NULL); + if (p == NULL) + goto truncated; + ts = zip->v_size; + zip->v_size = archive_le16dec(p); + __archive_read_consume(a, 2); + if ((zip->v_size & 0x0f) != 0 || + (zip->erd_size + zip->v_size + 16) > remaining_size || + (zip->erd_size + zip->v_size + 16) < (zip->erd_size + zip->v_size)) + goto corrupted; + if (ts < zip->v_size) { + free(zip->v_data); + zip->v_data = NULL; + } + p = __archive_read_ahead(a, zip->v_size, NULL); + if (p == NULL) + goto truncated; + if (zip->v_data == NULL) { + zip->v_data = malloc(zip->v_size); + if (zip->v_data == NULL) + goto nomem; + } + memcpy(zip->v_data, p, zip->v_size); + __archive_read_consume(a, zip->v_size); + + p = __archive_read_ahead(a, 4, NULL); + if (p == NULL) + goto truncated; + zip->v_crc32 = archive_le32dec(p); + __archive_read_consume(a, 4); + + /*return (ARCHIVE_OK); + * This is not fully implemented yet.*/ + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Encrypted file is unsupported"); + return (ARCHIVE_FAILED); +truncated: + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated ZIP file data"); + return (ARCHIVE_FATAL); +corrupted: + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Corrupted ZIP file data"); + return (ARCHIVE_FATAL); +nomem: + archive_set_error(&a->archive, ENOMEM, + "No memory for ZIP decryption"); + return (ARCHIVE_FATAL); +} + +static int +zip_alloc_decryption_buffer(struct archive_read *a) +{ + struct zip *zip = (struct zip *)(a->format->data); + size_t bs = 256 * 1024; + + if (zip->decrypted_buffer == NULL) { + zip->decrypted_buffer_size = bs; + zip->decrypted_buffer = malloc(bs); + if (zip->decrypted_buffer == NULL) { + archive_set_error(&a->archive, ENOMEM, + "No memory for ZIP decryption"); + return (ARCHIVE_FATAL); + } + } + zip->decrypted_ptr = zip->decrypted_buffer; + return (ARCHIVE_OK); +} + +static int +init_traditional_PKWARE_decryption(struct archive_read *a) +{ + struct zip *zip = (struct zip *)(a->format->data); + const void *p; + int retry; + int r; + + if (zip->tctx_valid) + return (ARCHIVE_OK); + + /* + Read the 12 bytes encryption header stored at + the start of the data area. + */ +#define ENC_HEADER_SIZE 12 + if (0 == (zip->entry->zip_flags & ZIP_LENGTH_AT_END) + && zip->entry_bytes_remaining < ENC_HEADER_SIZE) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated Zip encrypted body: only %jd bytes available", + (intmax_t)zip->entry_bytes_remaining); + return (ARCHIVE_FATAL); + } + + p = __archive_read_ahead(a, ENC_HEADER_SIZE, NULL); + if (p == NULL) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated ZIP file data"); + return (ARCHIVE_FATAL); + } + + for (retry = 0;; retry++) { + const char *passphrase; + uint8_t crcchk; + + passphrase = __archive_read_next_passphrase(a); + if (passphrase == NULL) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + (retry > 0)? + "Incorrect passphrase": + "Passphrase required for this entry"); + return (ARCHIVE_FAILED); + } + + /* + * Initialize ctx for Traditional PKWARE Decryption. + */ + r = trad_enc_init(&zip->tctx, passphrase, strlen(passphrase), + p, ENC_HEADER_SIZE, &crcchk); + if (r == 0 && crcchk == zip->entry->decdat) + break;/* The passphrase is OK. */ + if (retry > 10000) { + /* Avoid infinity loop. */ + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Too many incorrect passphrases"); + return (ARCHIVE_FAILED); + } + } + + __archive_read_consume(a, ENC_HEADER_SIZE); + zip->tctx_valid = 1; + if (0 == (zip->entry->zip_flags & ZIP_LENGTH_AT_END)) { + zip->entry_bytes_remaining -= ENC_HEADER_SIZE; + } + /*zip->entry_uncompressed_bytes_read += ENC_HEADER_SIZE;*/ + zip->entry_compressed_bytes_read += ENC_HEADER_SIZE; + zip->decrypted_bytes_remaining = 0; + + return (zip_alloc_decryption_buffer(a)); +#undef ENC_HEADER_SIZE +} + +static int +init_WinZip_AES_decryption(struct archive_read *a) +{ + struct zip *zip = (struct zip *)(a->format->data); + const void *p; + const uint8_t *pv; + size_t key_len, salt_len; + uint8_t derived_key[MAX_DERIVED_KEY_BUF_SIZE]; + int retry; + int r; + + if (zip->cctx_valid || zip->hctx_valid) + return (ARCHIVE_OK); + + switch (zip->entry->aes_extra.strength) { + case 1: salt_len = 8; key_len = 16; break; + case 2: salt_len = 12; key_len = 24; break; + case 3: salt_len = 16; key_len = 32; break; + default: goto corrupted; + } + p = __archive_read_ahead(a, salt_len + 2, NULL); + if (p == NULL) + goto truncated; + + for (retry = 0;; retry++) { + const char *passphrase; + + passphrase = __archive_read_next_passphrase(a); + if (passphrase == NULL) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + (retry > 0)? + "Incorrect passphrase": + "Passphrase required for this entry"); + return (ARCHIVE_FAILED); + } + memset(derived_key, 0, sizeof(derived_key)); + r = archive_pbkdf2_sha1(passphrase, strlen(passphrase), + p, salt_len, 1000, derived_key, key_len * 2 + 2); + if (r != 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Decryption is unsupported due to lack of " + "crypto library"); + return (ARCHIVE_FAILED); + } + + /* Check password verification value. */ + pv = ((const uint8_t *)p) + salt_len; + if (derived_key[key_len * 2] == pv[0] && + derived_key[key_len * 2 + 1] == pv[1]) + break;/* The passphrase is OK. */ + if (retry > 10000) { + /* Avoid infinity loop. */ + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Too many incorrect passphrases"); + return (ARCHIVE_FAILED); + } + } + + r = archive_decrypto_aes_ctr_init(&zip->cctx, derived_key, key_len); + if (r != 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Decryption is unsupported due to lack of crypto library"); + return (ARCHIVE_FAILED); + } + r = archive_hmac_sha1_init(&zip->hctx, derived_key + key_len, key_len); + if (r != 0) { + archive_decrypto_aes_ctr_release(&zip->cctx); + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Failed to initialize HMAC-SHA1"); + return (ARCHIVE_FAILED); + } + zip->cctx_valid = zip->hctx_valid = 1; + __archive_read_consume(a, salt_len + 2); + zip->entry_bytes_remaining -= salt_len + 2 + AUTH_CODE_SIZE; + if (0 == (zip->entry->zip_flags & ZIP_LENGTH_AT_END) + && zip->entry_bytes_remaining < 0) + goto corrupted; + zip->entry_compressed_bytes_read += salt_len + 2 + AUTH_CODE_SIZE; + zip->decrypted_bytes_remaining = 0; + + zip->entry->compression = zip->entry->aes_extra.compression; + return (zip_alloc_decryption_buffer(a)); + +truncated: + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated ZIP file data"); + return (ARCHIVE_FATAL); +corrupted: + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Corrupted ZIP file data"); + return (ARCHIVE_FATAL); +} + +static int +archive_read_format_zip_read_data(struct archive_read *a, + const void **buff, size_t *size, int64_t *offset) +{ + int r; + struct zip *zip = (struct zip *)(a->format->data); + + if (zip->has_encrypted_entries == + ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW) { + zip->has_encrypted_entries = 0; + } + + *offset = zip->entry_uncompressed_bytes_read; + *size = 0; + *buff = NULL; + + /* If we hit end-of-entry last time, return ARCHIVE_EOF. */ + if (zip->end_of_entry) + return (ARCHIVE_EOF); + + /* Return EOF immediately if this is a non-regular file. */ + if (AE_IFREG != (zip->entry->mode & AE_IFMT)) + return (ARCHIVE_EOF); + + __archive_read_consume(a, zip->unconsumed); + zip->unconsumed = 0; + + if (zip->init_decryption) { + zip->has_encrypted_entries = 1; + if (zip->entry->zip_flags & ZIP_STRONG_ENCRYPTED) + r = read_decryption_header(a); + else if (zip->entry->compression == WINZIP_AES_ENCRYPTION) + r = init_WinZip_AES_decryption(a); + else + r = init_traditional_PKWARE_decryption(a); + if (r != ARCHIVE_OK) + return (r); + zip->init_decryption = 0; + } + + switch(zip->entry->compression) { + case 0: /* No compression. */ + r = zip_read_data_none(a, buff, size, offset); + break; +#ifdef HAVE_ZLIB_H + case 8: /* Deflate compression. */ + r = zip_read_data_deflate(a, buff, size, offset); + break; +#endif + default: /* Unsupported compression. */ + /* Return a warning. */ + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Unsupported ZIP compression method (%s)", + compression_name(zip->entry->compression)); + /* We can't decompress this entry, but we will + * be able to skip() it and try the next entry. */ + return (ARCHIVE_FAILED); + break; + } + if (r != ARCHIVE_OK) + return (r); + /* Update checksum */ + if (*size) + zip->entry_crc32 = zip->crc32func(zip->entry_crc32, *buff, + (unsigned)*size); + /* If we hit the end, swallow any end-of-data marker. */ + if (zip->end_of_entry) { + /* Check file size, CRC against these values. */ + if (zip->entry->compressed_size != + zip->entry_compressed_bytes_read) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "ZIP compressed data is wrong size " + "(read %jd, expected %jd)", + (intmax_t)zip->entry_compressed_bytes_read, + (intmax_t)zip->entry->compressed_size); + return (ARCHIVE_WARN); + } + /* Size field only stores the lower 32 bits of the actual + * size. */ + if ((zip->entry->uncompressed_size & UINT32_MAX) + != (zip->entry_uncompressed_bytes_read & UINT32_MAX)) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "ZIP uncompressed data is wrong size " + "(read %jd, expected %jd)\n", + (intmax_t)zip->entry_uncompressed_bytes_read, + (intmax_t)zip->entry->uncompressed_size); + return (ARCHIVE_WARN); + } + /* Check computed CRC against header */ + if ((!zip->hctx_valid || + zip->entry->aes_extra.vendor != AES_VENDOR_AE_2) && + zip->entry->crc32 != zip->entry_crc32 + && !zip->ignore_crc32) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "ZIP bad CRC: 0x%lx should be 0x%lx", + (unsigned long)zip->entry_crc32, + (unsigned long)zip->entry->crc32); + return (ARCHIVE_WARN); + } + } + + return (ARCHIVE_OK); +} + +static int +archive_read_format_zip_cleanup(struct archive_read *a) +{ + struct zip *zip; + struct zip_entry *zip_entry, *next_zip_entry; + + zip = (struct zip *)(a->format->data); +#ifdef HAVE_ZLIB_H + if (zip->stream_valid) + inflateEnd(&zip->stream); + free(zip->uncompressed_buffer); +#endif + if (zip->zip_entries) { + zip_entry = zip->zip_entries; + while (zip_entry != NULL) { + next_zip_entry = zip_entry->next; + archive_string_free(&zip_entry->rsrcname); + free(zip_entry); + zip_entry = next_zip_entry; + } + } + free(zip->decrypted_buffer); + if (zip->cctx_valid) + archive_decrypto_aes_ctr_release(&zip->cctx); + if (zip->hctx_valid) + archive_hmac_sha1_cleanup(&zip->hctx); + free(zip->iv); + free(zip->erd); + free(zip->v_data); + archive_string_free(&zip->format_name); + free(zip); + (a->format->data) = NULL; + return (ARCHIVE_OK); +} + +static int +archive_read_format_zip_has_encrypted_entries(struct archive_read *_a) +{ + if (_a && _a->format) { + struct zip * zip = (struct zip *)_a->format->data; + if (zip) { + return zip->has_encrypted_entries; + } + } + return ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW; +} + +static int +archive_read_format_zip_options(struct archive_read *a, + const char *key, const char *val) +{ + struct zip *zip; + int ret = ARCHIVE_FAILED; + + zip = (struct zip *)(a->format->data); + if (strcmp(key, "compat-2x") == 0) { + /* Handle filenames as libarchive 2.x */ + zip->init_default_conversion = (val != NULL) ? 1 : 0; + return (ARCHIVE_OK); + } else if (strcmp(key, "hdrcharset") == 0) { + if (val == NULL || val[0] == 0) + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "zip: hdrcharset option needs a character-set name" + ); + else { + zip->sconv = archive_string_conversion_from_charset( + &a->archive, val, 0); + if (zip->sconv != NULL) { + if (strcmp(val, "UTF-8") == 0) + zip->sconv_utf8 = zip->sconv; + ret = ARCHIVE_OK; + } else + ret = ARCHIVE_FATAL; + } + return (ret); + } else if (strcmp(key, "ignorecrc32") == 0) { + /* Mostly useful for testing. */ + if (val == NULL || val[0] == 0) { + zip->crc32func = real_crc32; + zip->ignore_crc32 = 0; + } else { + zip->crc32func = fake_crc32; + zip->ignore_crc32 = 1; + } + return (ARCHIVE_OK); + } else if (strcmp(key, "mac-ext") == 0) { + zip->process_mac_extensions = (val != NULL && val[0] != 0); + return (ARCHIVE_OK); + } + + /* Note: The "warn" return is just to inform the options + * supervisor that we didn't handle it. It will generate + * a suitable error if no one used this option. */ + return (ARCHIVE_WARN); +} + +int +archive_read_support_format_zip(struct archive *a) +{ + int r; + r = archive_read_support_format_zip_streamable(a); + if (r != ARCHIVE_OK) + return r; + return (archive_read_support_format_zip_seekable(a)); +} + +/* ------------------------------------------------------------------------ */ + +/* + * Streaming-mode support + */ + + +static int +archive_read_support_format_zip_capabilities_streamable(struct archive_read * a) +{ + (void)a; /* UNUSED */ + return (ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_DATA | + ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_METADATA); +} + +static int +archive_read_format_zip_streamable_bid(struct archive_read *a, int best_bid) +{ + const char *p; + + (void)best_bid; /* UNUSED */ + + if ((p = __archive_read_ahead(a, 4, NULL)) == NULL) + return (-1); + + /* + * Bid of 29 here comes from: + * + 16 bits for "PK", + * + next 16-bit field has 6 options so contributes + * about 16 - log_2(6) ~= 16 - 2.6 ~= 13 bits + * + * So we've effectively verified ~29 total bits of check data. + */ + if (p[0] == 'P' && p[1] == 'K') { + if ((p[2] == '\001' && p[3] == '\002') + || (p[2] == '\003' && p[3] == '\004') + || (p[2] == '\005' && p[3] == '\006') + || (p[2] == '\006' && p[3] == '\006') + || (p[2] == '\007' && p[3] == '\010') + || (p[2] == '0' && p[3] == '0')) + return (29); + } + + /* TODO: It's worth looking ahead a little bit for a valid + * PK signature. In particular, that would make it possible + * to read some UUEncoded SFX files or SFX files coming from + * a network socket. */ + + return (0); +} + +static int +archive_read_format_zip_streamable_read_header(struct archive_read *a, + struct archive_entry *entry) +{ + struct zip *zip; + + a->archive.archive_format = ARCHIVE_FORMAT_ZIP; + if (a->archive.archive_format_name == NULL) + a->archive.archive_format_name = "ZIP"; + + zip = (struct zip *)(a->format->data); + + /* + * It should be sufficient to call archive_read_next_header() for + * a reader to determine if an entry is encrypted or not. If the + * encryption of an entry is only detectable when calling + * archive_read_data(), so be it. We'll do the same check there + * as well. + */ + if (zip->has_encrypted_entries == + ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW) + zip->has_encrypted_entries = 0; + + /* Make sure we have a zip_entry structure to use. */ + if (zip->zip_entries == NULL) { + zip->zip_entries = malloc(sizeof(struct zip_entry)); + if (zip->zip_entries == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Out of memory"); + return ARCHIVE_FATAL; + } + } + zip->entry = zip->zip_entries; + memset(zip->entry, 0, sizeof(struct zip_entry)); + + if (zip->cctx_valid) + archive_decrypto_aes_ctr_release(&zip->cctx); + if (zip->hctx_valid) + archive_hmac_sha1_cleanup(&zip->hctx); + zip->tctx_valid = zip->cctx_valid = zip->hctx_valid = 0; + __archive_read_reset_passphrase(a); + + /* Search ahead for the next local file header. */ + __archive_read_consume(a, zip->unconsumed); + zip->unconsumed = 0; + for (;;) { + int64_t skipped = 0; + const char *p, *end; + ssize_t bytes; + + p = __archive_read_ahead(a, 4, &bytes); + if (p == NULL) + return (ARCHIVE_FATAL); + end = p + bytes; + + while (p + 4 <= end) { + if (p[0] == 'P' && p[1] == 'K') { + if (p[2] == '\003' && p[3] == '\004') { + /* Regular file entry. */ + __archive_read_consume(a, skipped); + return zip_read_local_file_header(a, + entry, zip); + } + + /* + * TODO: We cannot restore permissions + * based only on the local file headers. + * Consider scanning the central + * directory and returning additional + * entries for at least directories. + * This would allow us to properly set + * directory permissions. + * + * This won't help us fix symlinks + * and may not help with regular file + * permissions, either. + */ + if (p[2] == '\001' && p[3] == '\002') { + return (ARCHIVE_EOF); + } + + /* End of central directory? Must be an + * empty archive. */ + if ((p[2] == '\005' && p[3] == '\006') + || (p[2] == '\006' && p[3] == '\006')) + return (ARCHIVE_EOF); + } + ++p; + ++skipped; + } + __archive_read_consume(a, skipped); + } +} + +static int +archive_read_format_zip_read_data_skip_streamable(struct archive_read *a) +{ + struct zip *zip; + int64_t bytes_skipped; + + zip = (struct zip *)(a->format->data); + bytes_skipped = __archive_read_consume(a, zip->unconsumed); + zip->unconsumed = 0; + if (bytes_skipped < 0) + return (ARCHIVE_FATAL); + + /* If we've already read to end of data, we're done. */ + if (zip->end_of_entry) + return (ARCHIVE_OK); + + /* So we know we're streaming... */ + if (0 == (zip->entry->zip_flags & ZIP_LENGTH_AT_END) + || zip->entry->compressed_size > 0) { + /* We know the compressed length, so we can just skip. */ + bytes_skipped = __archive_read_consume(a, + zip->entry_bytes_remaining); + if (bytes_skipped < 0) + return (ARCHIVE_FATAL); + return (ARCHIVE_OK); + } + + if (zip->init_decryption) { + int r; + + zip->has_encrypted_entries = 1; + if (zip->entry->zip_flags & ZIP_STRONG_ENCRYPTED) + r = read_decryption_header(a); + else if (zip->entry->compression == WINZIP_AES_ENCRYPTION) + r = init_WinZip_AES_decryption(a); + else + r = init_traditional_PKWARE_decryption(a); + if (r != ARCHIVE_OK) + return (r); + zip->init_decryption = 0; + } + + /* We're streaming and we don't know the length. */ + /* If the body is compressed and we know the format, we can + * find an exact end-of-entry by decompressing it. */ + switch (zip->entry->compression) { +#ifdef HAVE_ZLIB_H + case 8: /* Deflate compression. */ + while (!zip->end_of_entry) { + int64_t offset = 0; + const void *buff = NULL; + size_t size = 0; + int r; + r = zip_read_data_deflate(a, &buff, &size, &offset); + if (r != ARCHIVE_OK) + return (r); + } + return ARCHIVE_OK; +#endif + default: /* Uncompressed or unknown. */ + /* Scan for a PK\007\010 signature. */ + for (;;) { + const char *p, *buff; + ssize_t bytes_avail; + buff = __archive_read_ahead(a, 16, &bytes_avail); + if (bytes_avail < 16) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated ZIP file data"); + return (ARCHIVE_FATAL); + } + p = buff; + while (p <= buff + bytes_avail - 16) { + if (p[3] == 'P') { p += 3; } + else if (p[3] == 'K') { p += 2; } + else if (p[3] == '\007') { p += 1; } + else if (p[3] == '\010' && p[2] == '\007' + && p[1] == 'K' && p[0] == 'P') { + if (zip->entry->flags & LA_USED_ZIP64) + __archive_read_consume(a, + p - buff + 24); + else + __archive_read_consume(a, + p - buff + 16); + return ARCHIVE_OK; + } else { p += 4; } + } + __archive_read_consume(a, p - buff); + } + } +} + +int +archive_read_support_format_zip_streamable(struct archive *_a) +{ + struct archive_read *a = (struct archive_read *)_a; + struct zip *zip; + int r; + + archive_check_magic(_a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_format_zip"); + + zip = (struct zip *)calloc(1, sizeof(*zip)); + if (zip == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate zip data"); + return (ARCHIVE_FATAL); + } + + /* Streamable reader doesn't support mac extensions. */ + zip->process_mac_extensions = 0; + + /* + * Until enough data has been read, we cannot tell about + * any encrypted entries yet. + */ + zip->has_encrypted_entries = ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW; + zip->crc32func = real_crc32; + + r = __archive_read_register_format(a, + zip, + "zip", + archive_read_format_zip_streamable_bid, + archive_read_format_zip_options, + archive_read_format_zip_streamable_read_header, + archive_read_format_zip_read_data, + archive_read_format_zip_read_data_skip_streamable, + NULL, + archive_read_format_zip_cleanup, + archive_read_support_format_zip_capabilities_streamable, + archive_read_format_zip_has_encrypted_entries); + + if (r != ARCHIVE_OK) + free(zip); + return (ARCHIVE_OK); +} + +/* ------------------------------------------------------------------------ */ + +/* + * Seeking-mode support + */ + +static int +archive_read_support_format_zip_capabilities_seekable(struct archive_read * a) +{ + (void)a; /* UNUSED */ + return (ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_DATA | + ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_METADATA); +} + +/* + * TODO: This is a performance sink because it forces the read core to + * drop buffered data from the start of file, which will then have to + * be re-read again if this bidder loses. + * + * We workaround this a little by passing in the best bid so far so + * that later bidders can do nothing if they know they'll never + * outbid. But we can certainly do better... + */ +static int +read_eocd(struct zip *zip, const char *p, int64_t current_offset) +{ + /* Sanity-check the EOCD we've found. */ + + /* This must be the first volume. */ + if (archive_le16dec(p + 4) != 0) + return 0; + /* Central directory must be on this volume. */ + if (archive_le16dec(p + 4) != archive_le16dec(p + 6)) + return 0; + /* All central directory entries must be on this volume. */ + if (archive_le16dec(p + 10) != archive_le16dec(p + 8)) + return 0; + /* Central directory can't extend beyond start of EOCD record. */ + if (archive_le32dec(p + 16) + archive_le32dec(p + 12) + > current_offset) + return 0; + + /* Save the central directory location for later use. */ + zip->central_directory_offset = archive_le32dec(p + 16); + + /* This is just a tiny bit higher than the maximum + returned by the streaming Zip bidder. This ensures + that the more accurate seeking Zip parser wins + whenever seek is available. */ + return 32; +} + +/* + * Examine Zip64 EOCD locator: If it's valid, store the information + * from it. + */ +static int +read_zip64_eocd(struct archive_read *a, struct zip *zip, const char *p) +{ + int64_t eocd64_offset; + int64_t eocd64_size; + + /* Sanity-check the locator record. */ + + /* Central dir must be on first volume. */ + if (archive_le32dec(p + 4) != 0) + return 0; + /* Must be only a single volume. */ + if (archive_le32dec(p + 16) != 1) + return 0; + + /* Find the Zip64 EOCD record. */ + eocd64_offset = archive_le64dec(p + 8); + if (__archive_read_seek(a, eocd64_offset, SEEK_SET) < 0) + return 0; + if ((p = __archive_read_ahead(a, 56, NULL)) == NULL) + return 0; + /* Make sure we can read all of it. */ + eocd64_size = archive_le64dec(p + 4) + 12; + if (eocd64_size < 56 || eocd64_size > 16384) + return 0; + if ((p = __archive_read_ahead(a, (size_t)eocd64_size, NULL)) == NULL) + return 0; + + /* Sanity-check the EOCD64 */ + if (archive_le32dec(p + 16) != 0) /* Must be disk #0 */ + return 0; + if (archive_le32dec(p + 20) != 0) /* CD must be on disk #0 */ + return 0; + /* CD can't be split. */ + if (archive_le64dec(p + 24) != archive_le64dec(p + 32)) + return 0; + + /* Save the central directory offset for later use. */ + zip->central_directory_offset = archive_le64dec(p + 48); + + return 32; +} + +static int +archive_read_format_zip_seekable_bid(struct archive_read *a, int best_bid) +{ + struct zip *zip = (struct zip *)a->format->data; + int64_t file_size, current_offset; + const char *p; + int i, tail; + + /* If someone has already bid more than 32, then avoid + trashing the look-ahead buffers with a seek. */ + if (best_bid > 32) + return (-1); + + file_size = __archive_read_seek(a, 0, SEEK_END); + if (file_size <= 0) + return 0; + + /* Search last 16k of file for end-of-central-directory + * record (which starts with PK\005\006) */ + tail = (int)zipmin(1024 * 16, file_size); + current_offset = __archive_read_seek(a, -tail, SEEK_END); + if (current_offset < 0) + return 0; + if ((p = __archive_read_ahead(a, (size_t)tail, NULL)) == NULL) + return 0; + /* Boyer-Moore search backwards from the end, since we want + * to match the last EOCD in the file (there can be more than + * one if there is an uncompressed Zip archive as a member + * within this Zip archive). */ + for (i = tail - 22; i > 0;) { + switch (p[i]) { + case 'P': + if (memcmp(p + i, "PK\005\006", 4) == 0) { + int ret = read_eocd(zip, p + i, + current_offset + i); + /* Zip64 EOCD locator precedes + * regular EOCD if present. */ + if (i >= 20 && memcmp(p + i - 20, "PK\006\007", 4) == 0) { + int ret_zip64 = read_zip64_eocd(a, zip, p + i - 20); + if (ret_zip64 > ret) + ret = ret_zip64; + } + return (ret); + } + i -= 4; + break; + case 'K': i -= 1; break; + case 005: i -= 2; break; + case 006: i -= 3; break; + default: i -= 4; break; + } + } + return 0; +} + +/* The red-black trees are only used in seeking mode to manage + * the in-memory copy of the central directory. */ + +static int +cmp_node(const struct archive_rb_node *n1, const struct archive_rb_node *n2) +{ + const struct zip_entry *e1 = (const struct zip_entry *)n1; + const struct zip_entry *e2 = (const struct zip_entry *)n2; + + if (e1->local_header_offset > e2->local_header_offset) + return -1; + if (e1->local_header_offset < e2->local_header_offset) + return 1; + return 0; +} + +static int +cmp_key(const struct archive_rb_node *n, const void *key) +{ + /* This function won't be called */ + (void)n; /* UNUSED */ + (void)key; /* UNUSED */ + return 1; +} + +static const struct archive_rb_tree_ops rb_ops = { + &cmp_node, &cmp_key +}; + +static int +rsrc_cmp_node(const struct archive_rb_node *n1, + const struct archive_rb_node *n2) +{ + const struct zip_entry *e1 = (const struct zip_entry *)n1; + const struct zip_entry *e2 = (const struct zip_entry *)n2; + + return (strcmp(e2->rsrcname.s, e1->rsrcname.s)); +} + +static int +rsrc_cmp_key(const struct archive_rb_node *n, const void *key) +{ + const struct zip_entry *e = (const struct zip_entry *)n; + return (strcmp((const char *)key, e->rsrcname.s)); +} + +static const struct archive_rb_tree_ops rb_rsrc_ops = { + &rsrc_cmp_node, &rsrc_cmp_key +}; + +static const char * +rsrc_basename(const char *name, size_t name_length) +{ + const char *s, *r; + + r = s = name; + for (;;) { + s = memchr(s, '/', name_length - (s - name)); + if (s == NULL) + break; + r = ++s; + } + return (r); +} + +static void +expose_parent_dirs(struct zip *zip, const char *name, size_t name_length) +{ + struct archive_string str; + struct zip_entry *dir; + char *s; + + archive_string_init(&str); + archive_strncpy(&str, name, name_length); + for (;;) { + s = strrchr(str.s, '/'); + if (s == NULL) + break; + *s = '\0'; + /* Transfer the parent directory from zip->tree_rsrc RB + * tree to zip->tree RB tree to expose. */ + dir = (struct zip_entry *) + __archive_rb_tree_find_node(&zip->tree_rsrc, str.s); + if (dir == NULL) + break; + __archive_rb_tree_remove_node(&zip->tree_rsrc, &dir->node); + archive_string_free(&dir->rsrcname); + __archive_rb_tree_insert_node(&zip->tree, &dir->node); + } + archive_string_free(&str); +} + +static int +slurp_central_directory(struct archive_read *a, struct zip *zip) +{ + ssize_t i; + unsigned found; + int64_t correction; + ssize_t bytes_avail; + const char *p; + + /* + * Find the start of the central directory. The end-of-CD + * record has our starting point, but there are lots of + * Zip archives which have had other data prepended to the + * file, which makes the recorded offsets all too small. + * So we search forward from the specified offset until we + * find the real start of the central directory. Then we + * know the correction we need to apply to account for leading + * padding. + */ + if (__archive_read_seek(a, zip->central_directory_offset, SEEK_SET) < 0) + return ARCHIVE_FATAL; + + found = 0; + while (!found) { + if ((p = __archive_read_ahead(a, 20, &bytes_avail)) == NULL) + return ARCHIVE_FATAL; + for (found = 0, i = 0; !found && i < bytes_avail - 4;) { + switch (p[i + 3]) { + case 'P': i += 3; break; + case 'K': i += 2; break; + case 001: i += 1; break; + case 002: + if (memcmp(p + i, "PK\001\002", 4) == 0) { + p += i; + found = 1; + } else + i += 4; + break; + case 005: i += 1; break; + case 006: + if (memcmp(p + i, "PK\005\006", 4) == 0) { + p += i; + found = 1; + } else if (memcmp(p + i, "PK\006\006", 4) == 0) { + p += i; + found = 1; + } else + i += 1; + break; + default: i += 4; break; + } + } + __archive_read_consume(a, i); + } + correction = archive_filter_bytes(&a->archive, 0) + - zip->central_directory_offset; + + __archive_rb_tree_init(&zip->tree, &rb_ops); + __archive_rb_tree_init(&zip->tree_rsrc, &rb_rsrc_ops); + + zip->central_directory_entries_total = 0; + while (1) { + struct zip_entry *zip_entry; + size_t filename_length, extra_length, comment_length; + uint32_t external_attributes; + const char *name, *r; + + if ((p = __archive_read_ahead(a, 4, NULL)) == NULL) + return ARCHIVE_FATAL; + if (memcmp(p, "PK\006\006", 4) == 0 + || memcmp(p, "PK\005\006", 4) == 0) { + break; + } else if (memcmp(p, "PK\001\002", 4) != 0) { + archive_set_error(&a->archive, + -1, "Invalid central directory signature"); + return ARCHIVE_FATAL; + } + if ((p = __archive_read_ahead(a, 46, NULL)) == NULL) + return ARCHIVE_FATAL; + + zip_entry = calloc(1, sizeof(struct zip_entry)); + zip_entry->next = zip->zip_entries; + zip_entry->flags |= LA_FROM_CENTRAL_DIRECTORY; + zip->zip_entries = zip_entry; + zip->central_directory_entries_total++; + + /* version = p[4]; */ + zip_entry->system = p[5]; + /* version_required = archive_le16dec(p + 6); */ + zip_entry->zip_flags = archive_le16dec(p + 8); + if (zip_entry->zip_flags + & (ZIP_ENCRYPTED | ZIP_STRONG_ENCRYPTED)){ + zip->has_encrypted_entries = 1; + } + zip_entry->compression = (char)archive_le16dec(p + 10); + zip_entry->mtime = zip_time(p + 12); + zip_entry->crc32 = archive_le32dec(p + 16); + if (zip_entry->zip_flags & ZIP_LENGTH_AT_END) + zip_entry->decdat = p[13]; + else + zip_entry->decdat = p[19]; + zip_entry->compressed_size = archive_le32dec(p + 20); + zip_entry->uncompressed_size = archive_le32dec(p + 24); + filename_length = archive_le16dec(p + 28); + extra_length = archive_le16dec(p + 30); + comment_length = archive_le16dec(p + 32); + /* disk_start = archive_le16dec(p + 34); */ /* Better be zero. */ + /* internal_attributes = archive_le16dec(p + 36); */ /* text bit */ + external_attributes = archive_le32dec(p + 38); + zip_entry->local_header_offset = + archive_le32dec(p + 42) + correction; + + /* If we can't guess the mode, leave it zero here; + when we read the local file header we might get + more information. */ + if (zip_entry->system == 3) { + zip_entry->mode = external_attributes >> 16; + } else if (zip_entry->system == 0) { + // Interpret MSDOS directory bit + if (0x10 == (external_attributes & 0x10)) { + zip_entry->mode = AE_IFDIR | 0775; + } else { + zip_entry->mode = AE_IFREG | 0664; + } + if (0x01 == (external_attributes & 0x01)) { + // Read-only bit; strip write permissions + zip_entry->mode &= 0555; + } + } else { + zip_entry->mode = 0; + } + + /* We're done with the regular data; get the filename and + * extra data. */ + __archive_read_consume(a, 46); + p = __archive_read_ahead(a, filename_length + extra_length, + NULL); + if (p == NULL) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated ZIP file header"); + return ARCHIVE_FATAL; + } + if (ARCHIVE_OK != process_extra(a, p + filename_length, extra_length, zip_entry)) { + return ARCHIVE_FATAL; + } + + /* + * Mac resource fork files are stored under the + * "__MACOSX/" directory, so we should check if + * it is. + */ + if (!zip->process_mac_extensions) { + /* Treat every entry as a regular entry. */ + __archive_rb_tree_insert_node(&zip->tree, + &zip_entry->node); + } else { + name = p; + r = rsrc_basename(name, filename_length); + if (filename_length >= 9 && + strncmp("__MACOSX/", name, 9) == 0) { + /* If this file is not a resource fork nor + * a directory. We should treat it as a non + * resource fork file to expose it. */ + if (name[filename_length-1] != '/' && + (r - name < 3 || r[0] != '.' || r[1] != '_')) { + __archive_rb_tree_insert_node( + &zip->tree, &zip_entry->node); + /* Expose its parent directories. */ + expose_parent_dirs(zip, name, + filename_length); + } else { + /* This file is a resource fork file or + * a directory. */ + archive_strncpy(&(zip_entry->rsrcname), + name, filename_length); + __archive_rb_tree_insert_node( + &zip->tree_rsrc, &zip_entry->node); + } + } else { + /* Generate resource fork name to find its + * resource file at zip->tree_rsrc. */ + archive_strcpy(&(zip_entry->rsrcname), + "__MACOSX/"); + archive_strncat(&(zip_entry->rsrcname), + name, r - name); + archive_strcat(&(zip_entry->rsrcname), "._"); + archive_strncat(&(zip_entry->rsrcname), + name + (r - name), + filename_length - (r - name)); + /* Register an entry to RB tree to sort it by + * file offset. */ + __archive_rb_tree_insert_node(&zip->tree, + &zip_entry->node); + } + } + + /* Skip the comment too ... */ + __archive_read_consume(a, + filename_length + extra_length + comment_length); + } + + return ARCHIVE_OK; +} + +static ssize_t +zip_get_local_file_header_size(struct archive_read *a, size_t extra) +{ + const char *p; + ssize_t filename_length, extra_length; + + if ((p = __archive_read_ahead(a, extra + 30, NULL)) == NULL) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated ZIP file header"); + return (ARCHIVE_WARN); + } + p += extra; + + if (memcmp(p, "PK\003\004", 4) != 0) { + archive_set_error(&a->archive, -1, "Damaged Zip archive"); + return ARCHIVE_WARN; + } + filename_length = archive_le16dec(p + 26); + extra_length = archive_le16dec(p + 28); + + return (30 + filename_length + extra_length); +} + +static int +zip_read_mac_metadata(struct archive_read *a, struct archive_entry *entry, + struct zip_entry *rsrc) +{ + struct zip *zip = (struct zip *)a->format->data; + unsigned char *metadata, *mp; + int64_t offset = archive_filter_bytes(&a->archive, 0); + size_t remaining_bytes, metadata_bytes; + ssize_t hsize; + int ret = ARCHIVE_OK, eof; + + switch(rsrc->compression) { + case 0: /* No compression. */ + if (rsrc->uncompressed_size != rsrc->compressed_size) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Malformed OS X metadata entry: inconsistent size"); + return (ARCHIVE_FATAL); + } +#ifdef HAVE_ZLIB_H + case 8: /* Deflate compression. */ +#endif + break; + default: /* Unsupported compression. */ + /* Return a warning. */ + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Unsupported ZIP compression method (%s)", + compression_name(rsrc->compression)); + /* We can't decompress this entry, but we will + * be able to skip() it and try the next entry. */ + return (ARCHIVE_WARN); + } + + if (rsrc->uncompressed_size > (4 * 1024 * 1024)) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Mac metadata is too large: %jd > 4M bytes", + (intmax_t)rsrc->uncompressed_size); + return (ARCHIVE_WARN); + } + if (rsrc->compressed_size > (4 * 1024 * 1024)) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Mac metadata is too large: %jd > 4M bytes", + (intmax_t)rsrc->compressed_size); + return (ARCHIVE_WARN); + } + + metadata = malloc((size_t)rsrc->uncompressed_size); + if (metadata == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Mac metadata"); + return (ARCHIVE_FATAL); + } + + if (offset < rsrc->local_header_offset) + __archive_read_consume(a, rsrc->local_header_offset - offset); + else if (offset != rsrc->local_header_offset) { + __archive_read_seek(a, rsrc->local_header_offset, SEEK_SET); + } + + hsize = zip_get_local_file_header_size(a, 0); + __archive_read_consume(a, hsize); + + remaining_bytes = (size_t)rsrc->compressed_size; + metadata_bytes = (size_t)rsrc->uncompressed_size; + mp = metadata; + eof = 0; + while (!eof && remaining_bytes) { + const unsigned char *p; + ssize_t bytes_avail; + size_t bytes_used; + + p = __archive_read_ahead(a, 1, &bytes_avail); + if (p == NULL) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated ZIP file header"); + ret = ARCHIVE_WARN; + goto exit_mac_metadata; + } + if ((size_t)bytes_avail > remaining_bytes) + bytes_avail = remaining_bytes; + switch(rsrc->compression) { + case 0: /* No compression. */ + if ((size_t)bytes_avail > metadata_bytes) + bytes_avail = metadata_bytes; + memcpy(mp, p, bytes_avail); + bytes_used = (size_t)bytes_avail; + metadata_bytes -= bytes_used; + mp += bytes_used; + if (metadata_bytes == 0) + eof = 1; + break; +#ifdef HAVE_ZLIB_H + case 8: /* Deflate compression. */ + { + int r; + + ret = zip_deflate_init(a, zip); + if (ret != ARCHIVE_OK) + goto exit_mac_metadata; + zip->stream.next_in = + (Bytef *)(uintptr_t)(const void *)p; + zip->stream.avail_in = (uInt)bytes_avail; + zip->stream.total_in = 0; + zip->stream.next_out = mp; + zip->stream.avail_out = (uInt)metadata_bytes; + zip->stream.total_out = 0; + + r = inflate(&zip->stream, 0); + switch (r) { + case Z_OK: + break; + case Z_STREAM_END: + eof = 1; + break; + case Z_MEM_ERROR: + archive_set_error(&a->archive, ENOMEM, + "Out of memory for ZIP decompression"); + ret = ARCHIVE_FATAL; + goto exit_mac_metadata; + default: + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "ZIP decompression failed (%d)", r); + ret = ARCHIVE_FATAL; + goto exit_mac_metadata; + } + bytes_used = zip->stream.total_in; + metadata_bytes -= zip->stream.total_out; + mp += zip->stream.total_out; + break; + } +#endif + default: + bytes_used = 0; + break; + } + __archive_read_consume(a, bytes_used); + remaining_bytes -= bytes_used; + } + archive_entry_copy_mac_metadata(entry, metadata, + (size_t)rsrc->uncompressed_size - metadata_bytes); + +exit_mac_metadata: + __archive_read_seek(a, offset, SEEK_SET); + zip->decompress_init = 0; + free(metadata); + return (ret); +} + +static int +archive_read_format_zip_seekable_read_header(struct archive_read *a, + struct archive_entry *entry) +{ + struct zip *zip = (struct zip *)a->format->data; + struct zip_entry *rsrc; + int64_t offset; + int r, ret = ARCHIVE_OK; + + /* + * It should be sufficient to call archive_read_next_header() for + * a reader to determine if an entry is encrypted or not. If the + * encryption of an entry is only detectable when calling + * archive_read_data(), so be it. We'll do the same check there + * as well. + */ + if (zip->has_encrypted_entries == + ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW) + zip->has_encrypted_entries = 0; + + a->archive.archive_format = ARCHIVE_FORMAT_ZIP; + if (a->archive.archive_format_name == NULL) + a->archive.archive_format_name = "ZIP"; + + if (zip->zip_entries == NULL) { + r = slurp_central_directory(a, zip); + if (r != ARCHIVE_OK) + return r; + /* Get first entry whose local header offset is lower than + * other entries in the archive file. */ + zip->entry = + (struct zip_entry *)ARCHIVE_RB_TREE_MIN(&zip->tree); + } else if (zip->entry != NULL) { + /* Get next entry in local header offset order. */ + zip->entry = (struct zip_entry *)__archive_rb_tree_iterate( + &zip->tree, &zip->entry->node, ARCHIVE_RB_DIR_RIGHT); + } + + if (zip->entry == NULL) + return ARCHIVE_EOF; + + if (zip->entry->rsrcname.s) + rsrc = (struct zip_entry *)__archive_rb_tree_find_node( + &zip->tree_rsrc, zip->entry->rsrcname.s); + else + rsrc = NULL; + + if (zip->cctx_valid) + archive_decrypto_aes_ctr_release(&zip->cctx); + if (zip->hctx_valid) + archive_hmac_sha1_cleanup(&zip->hctx); + zip->tctx_valid = zip->cctx_valid = zip->hctx_valid = 0; + __archive_read_reset_passphrase(a); + + /* File entries are sorted by the header offset, we should mostly + * use __archive_read_consume to advance a read point to avoid redundant + * data reading. */ + offset = archive_filter_bytes(&a->archive, 0); + if (offset < zip->entry->local_header_offset) + __archive_read_consume(a, + zip->entry->local_header_offset - offset); + else if (offset != zip->entry->local_header_offset) { + __archive_read_seek(a, zip->entry->local_header_offset, + SEEK_SET); + } + zip->unconsumed = 0; + r = zip_read_local_file_header(a, entry, zip); + if (r != ARCHIVE_OK) + return r; + if (rsrc) { + int ret2 = zip_read_mac_metadata(a, entry, rsrc); + if (ret2 < ret) + ret = ret2; + } + return (ret); +} + +/* + * We're going to seek for the next header anyway, so we don't + * need to bother doing anything here. + */ +static int +archive_read_format_zip_read_data_skip_seekable(struct archive_read *a) +{ + struct zip *zip; + zip = (struct zip *)(a->format->data); + + zip->unconsumed = 0; + return (ARCHIVE_OK); +} + +int +archive_read_support_format_zip_seekable(struct archive *_a) +{ + struct archive_read *a = (struct archive_read *)_a; + struct zip *zip; + int r; + + archive_check_magic(_a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_format_zip_seekable"); + + zip = (struct zip *)calloc(1, sizeof(*zip)); + if (zip == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate zip data"); + return (ARCHIVE_FATAL); + } + +#ifdef HAVE_COPYFILE_H + /* Set this by default on Mac OS. */ + zip->process_mac_extensions = 1; +#endif + + /* + * Until enough data has been read, we cannot tell about + * any encrypted entries yet. + */ + zip->has_encrypted_entries = ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW; + zip->crc32func = real_crc32; + + r = __archive_read_register_format(a, + zip, + "zip", + archive_read_format_zip_seekable_bid, + archive_read_format_zip_options, + archive_read_format_zip_seekable_read_header, + archive_read_format_zip_read_data, + archive_read_format_zip_read_data_skip_seekable, + NULL, + archive_read_format_zip_cleanup, + archive_read_support_format_zip_capabilities_seekable, + archive_read_format_zip_has_encrypted_entries); + + if (r != ARCHIVE_OK) + free(zip); + return (ARCHIVE_OK); +} diff --cc Utilities/cmlibarchive/libarchive/archive_util.c index 1e36ad7,0000000..e5c6e3b mode 100644,000000..100644 --- a/Utilities/cmlibarchive/libarchive/archive_util.c +++ b/Utilities/cmlibarchive/libarchive/archive_util.c @@@ -1,585 -1,0 +1,585 @@@ +/*- + * Copyright (c) 2009-2012,2014 Michihiro NAKAJIMA + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "archive_platform.h" +__FBSDID("$FreeBSD: head/lib/libarchive/archive_util.c 201098 2009-12-28 02:58:14Z kientzle $"); + +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_FCNTL_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#if defined(HAVE_WINCRYPT_H) && !defined(__CYGWIN__) +#include +#endif +#ifdef HAVE_ZLIB_H +#include +#endif +#ifdef HAVE_LZMA_H +#include +#endif +#ifdef HAVE_BZLIB_H +#include +#endif +#ifdef HAVE_LZ4_H +#include +#endif + +#include "archive.h" +#include "archive_private.h" +#include "archive_random_private.h" +#include "archive_string.h" + +#ifndef O_CLOEXEC +#define O_CLOEXEC 0 +#endif + +static int archive_utility_string_sort_helper(char **, unsigned int); + +/* Generic initialization of 'struct archive' objects. */ +int +__archive_clean(struct archive *a) +{ + archive_string_conversion_free(a); + return (ARCHIVE_OK); +} + +int +archive_version_number(void) +{ + return (ARCHIVE_VERSION_NUMBER); +} + +const char * +archive_version_string(void) +{ + return (ARCHIVE_VERSION_STRING); +} + +int +archive_errno(struct archive *a) +{ + return (a->archive_error_number); +} + +const char * +archive_error_string(struct archive *a) +{ + + if (a->error != NULL && *a->error != '\0') + return (a->error); + else + return (NULL); +} + +int +archive_file_count(struct archive *a) +{ + return (a->file_count); +} + +int +archive_format(struct archive *a) +{ + return (a->archive_format); +} + +const char * +archive_format_name(struct archive *a) +{ + return (a->archive_format_name); +} + + +int +archive_compression(struct archive *a) +{ + return archive_filter_code(a, 0); +} + +const char * +archive_compression_name(struct archive *a) +{ + return archive_filter_name(a, 0); +} + + +/* + * Return a count of the number of compressed bytes processed. + */ - int64_t ++la_int64_t +archive_position_compressed(struct archive *a) +{ + return archive_filter_bytes(a, -1); +} + +/* + * Return a count of the number of uncompressed bytes processed. + */ - int64_t ++la_int64_t +archive_position_uncompressed(struct archive *a) +{ + return archive_filter_bytes(a, 0); +} + +void +archive_clear_error(struct archive *a) +{ + archive_string_empty(&a->error_string); + a->error = NULL; + a->archive_error_number = 0; +} + +void +archive_set_error(struct archive *a, int error_number, const char *fmt, ...) +{ + va_list ap; + + a->archive_error_number = error_number; + if (fmt == NULL) { + a->error = NULL; + return; + } + + archive_string_empty(&(a->error_string)); + va_start(ap, fmt); + archive_string_vsprintf(&(a->error_string), fmt, ap); + va_end(ap); + a->error = a->error_string.s; +} + +void +archive_copy_error(struct archive *dest, struct archive *src) +{ + dest->archive_error_number = src->archive_error_number; + + archive_string_copy(&dest->error_string, &src->error_string); + dest->error = dest->error_string.s; +} + +void +__archive_errx(int retvalue, const char *msg) +{ + static const char msg1[] = "Fatal Internal Error in libarchive: "; + size_t s; + + s = write(2, msg1, strlen(msg1)); + (void)s; /* UNUSED */ + s = write(2, msg, strlen(msg)); + (void)s; /* UNUSED */ + s = write(2, "\n", 1); + (void)s; /* UNUSED */ + exit(retvalue); +} + +/* + * Create a temporary file + */ +#if defined(_WIN32) && !defined(__CYGWIN__) + +/* + * Do not use Windows tmpfile() function. + * It will make a temporary file under the root directory + * and it'll cause permission error if a user who is + * non-Administrator creates temporary files. + * Also Windows version of mktemp family including _mktemp_s + * are not secure. + */ +int +__archive_mktemp(const char *tmpdir) +{ + static const wchar_t prefix[] = L"libarchive_"; + static const wchar_t suffix[] = L"XXXXXXXXXX"; + static const wchar_t num[] = { + L'0', L'1', L'2', L'3', L'4', L'5', L'6', L'7', + L'8', L'9', L'A', L'B', L'C', L'D', L'E', L'F', + L'G', L'H', L'I', L'J', L'K', L'L', L'M', L'N', + L'O', L'P', L'Q', L'R', L'S', L'T', L'U', L'V', + L'W', L'X', L'Y', L'Z', L'a', L'b', L'c', L'd', + L'e', L'f', L'g', L'h', L'i', L'j', L'k', L'l', + L'm', L'n', L'o', L'p', L'q', L'r', L's', L't', + L'u', L'v', L'w', L'x', L'y', L'z' + }; + HCRYPTPROV hProv; + struct archive_wstring temp_name; + wchar_t *ws; + DWORD attr; + wchar_t *xp, *ep; + int fd; + + hProv = (HCRYPTPROV)NULL; + fd = -1; + ws = NULL; + archive_string_init(&temp_name); + + /* Get a temporary directory. */ + if (tmpdir == NULL) { + size_t l; + wchar_t *tmp; + + l = GetTempPathW(0, NULL); + if (l == 0) { + la_dosmaperr(GetLastError()); + goto exit_tmpfile; + } + tmp = malloc(l*sizeof(wchar_t)); + if (tmp == NULL) { + errno = ENOMEM; + goto exit_tmpfile; + } + GetTempPathW((DWORD)l, tmp); + archive_wstrcpy(&temp_name, tmp); + free(tmp); + } else { + if (archive_wstring_append_from_mbs(&temp_name, tmpdir, + strlen(tmpdir)) < 0) + goto exit_tmpfile; + if (temp_name.s[temp_name.length-1] != L'/') + archive_wstrappend_wchar(&temp_name, L'/'); + } + + /* Check if temp_name is a directory. */ + attr = GetFileAttributesW(temp_name.s); + if (attr == (DWORD)-1) { + if (GetLastError() != ERROR_FILE_NOT_FOUND) { + la_dosmaperr(GetLastError()); + goto exit_tmpfile; + } + ws = __la_win_permissive_name_w(temp_name.s); + if (ws == NULL) { + errno = EINVAL; + goto exit_tmpfile; + } + attr = GetFileAttributesW(ws); + if (attr == (DWORD)-1) { + la_dosmaperr(GetLastError()); + goto exit_tmpfile; + } + } + if (!(attr & FILE_ATTRIBUTE_DIRECTORY)) { + errno = ENOTDIR; + goto exit_tmpfile; + } + + /* + * Create a temporary file. + */ + archive_wstrcat(&temp_name, prefix); + archive_wstrcat(&temp_name, suffix); + ep = temp_name.s + archive_strlen(&temp_name); + xp = ep - wcslen(suffix); + + if (!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, + CRYPT_VERIFYCONTEXT)) { + la_dosmaperr(GetLastError()); + goto exit_tmpfile; + } + + for (;;) { + wchar_t *p; + HANDLE h; + + /* Generate a random file name through CryptGenRandom(). */ + p = xp; + if (!CryptGenRandom(hProv, (DWORD)(ep - p)*sizeof(wchar_t), + (BYTE*)p)) { + la_dosmaperr(GetLastError()); + goto exit_tmpfile; + } + for (; p < ep; p++) + *p = num[((DWORD)*p) % (sizeof(num)/sizeof(num[0]))]; + + free(ws); + ws = __la_win_permissive_name_w(temp_name.s); + if (ws == NULL) { + errno = EINVAL; + goto exit_tmpfile; + } + /* Specifies FILE_FLAG_DELETE_ON_CLOSE flag is to + * delete this temporary file immediately when this + * file closed. */ + h = CreateFileW(ws, + GENERIC_READ | GENERIC_WRITE | DELETE, + 0,/* Not share */ + NULL, + CREATE_NEW,/* Create a new file only */ + FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE, + NULL); + if (h == INVALID_HANDLE_VALUE) { + /* The same file already exists. retry with + * a new filename. */ + if (GetLastError() == ERROR_FILE_EXISTS) + continue; + /* Otherwise, fail creation temporary file. */ + la_dosmaperr(GetLastError()); + goto exit_tmpfile; + } + fd = _open_osfhandle((intptr_t)h, _O_BINARY | _O_RDWR); + if (fd == -1) { + CloseHandle(h); + goto exit_tmpfile; + } else + break;/* success! */ + } +exit_tmpfile: + if (hProv != (HCRYPTPROV)NULL) + CryptReleaseContext(hProv, 0); + free(ws); + archive_wstring_free(&temp_name); + return (fd); +} + +#else + +static int +get_tempdir(struct archive_string *temppath) +{ + const char *tmp; + + tmp = getenv("TMPDIR"); + if (tmp == NULL) +#ifdef _PATH_TMP + tmp = _PATH_TMP; +#else + tmp = "/tmp"; +#endif + archive_strcpy(temppath, tmp); + if (temppath->s[temppath->length-1] != '/') + archive_strappend_char(temppath, '/'); + return (ARCHIVE_OK); +} + +#if defined(HAVE_MKSTEMP) + +/* + * We can use mkstemp(). + */ + +int +__archive_mktemp(const char *tmpdir) +{ + struct archive_string temp_name; + int fd = -1; + + archive_string_init(&temp_name); + if (tmpdir == NULL) { + if (get_tempdir(&temp_name) != ARCHIVE_OK) + goto exit_tmpfile; + } else { + archive_strcpy(&temp_name, tmpdir); + if (temp_name.s[temp_name.length-1] != '/') + archive_strappend_char(&temp_name, '/'); + } + archive_strcat(&temp_name, "libarchive_XXXXXX"); + fd = mkstemp(temp_name.s); + if (fd < 0) + goto exit_tmpfile; + __archive_ensure_cloexec_flag(fd); + unlink(temp_name.s); +exit_tmpfile: + archive_string_free(&temp_name); + return (fd); +} + +#else + +/* + * We use a private routine. + */ + +int +__archive_mktemp(const char *tmpdir) +{ + static const char num[] = { + '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', + 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', + 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', + 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', + 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', + 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', + 'u', 'v', 'w', 'x', 'y', 'z' + }; + struct archive_string temp_name; + struct stat st; + int fd; + char *tp, *ep; + + fd = -1; + archive_string_init(&temp_name); + if (tmpdir == NULL) { + if (get_tempdir(&temp_name) != ARCHIVE_OK) + goto exit_tmpfile; + } else + archive_strcpy(&temp_name, tmpdir); + if (temp_name.s[temp_name.length-1] == '/') { + temp_name.s[temp_name.length-1] = '\0'; + temp_name.length --; + } + if (stat(temp_name.s, &st) < 0) + goto exit_tmpfile; + if (!S_ISDIR(st.st_mode)) { + errno = ENOTDIR; + goto exit_tmpfile; + } + archive_strcat(&temp_name, "/libarchive_"); + tp = temp_name.s + archive_strlen(&temp_name); + archive_strcat(&temp_name, "XXXXXXXXXX"); + ep = temp_name.s + archive_strlen(&temp_name); + + do { + char *p; + + p = tp; + archive_random(p, ep - p); + while (p < ep) { + int d = *((unsigned char *)p) % sizeof(num); + *p++ = num[d]; + } + fd = open(temp_name.s, O_CREAT | O_EXCL | O_RDWR | O_CLOEXEC, + 0600); + } while (fd < 0 && errno == EEXIST); + if (fd < 0) + goto exit_tmpfile; + __archive_ensure_cloexec_flag(fd); + unlink(temp_name.s); +exit_tmpfile: + archive_string_free(&temp_name); + return (fd); +} + +#endif /* HAVE_MKSTEMP */ +#endif /* !_WIN32 || __CYGWIN__ */ + +/* + * Set FD_CLOEXEC flag to a file descriptor if it is not set. + * We have to set the flag if the platform does not provide O_CLOEXEC + * or F_DUPFD_CLOEXEC flags. + * + * Note: This function is absolutely called after creating a new file + * descriptor even if the platform seemingly provides O_CLOEXEC or + * F_DUPFD_CLOEXEC macros because it is possible that the platform + * merely declares those macros, especially Linux 2.6.18 - 2.6.24 do it. + */ +void +__archive_ensure_cloexec_flag(int fd) +{ +#if defined(_WIN32) && !defined(__CYGWIN__) + (void)fd; /* UNUSED */ +#else + int flags; + + if (fd >= 0) { + flags = fcntl(fd, F_GETFD); + if (flags != -1 && (flags & FD_CLOEXEC) == 0) + fcntl(fd, F_SETFD, flags | FD_CLOEXEC); + } +#endif +} + +/* + * Utility function to sort a group of strings using quicksort. + */ +static int +archive_utility_string_sort_helper(char **strings, unsigned int n) +{ + unsigned int i, lesser_count, greater_count; + char **lesser, **greater, **tmp, *pivot; + int retval1, retval2; + + /* A list of 0 or 1 elements is already sorted */ + if (n <= 1) + return (ARCHIVE_OK); + + lesser_count = greater_count = 0; + lesser = greater = NULL; + pivot = strings[0]; + for (i = 1; i < n; i++) + { + if (strcmp(strings[i], pivot) < 0) + { + lesser_count++; + tmp = (char **)realloc(lesser, + lesser_count * sizeof(char *)); + if (!tmp) { + free(greater); + free(lesser); + return (ARCHIVE_FATAL); + } + lesser = tmp; + lesser[lesser_count - 1] = strings[i]; + } + else + { + greater_count++; + tmp = (char **)realloc(greater, + greater_count * sizeof(char *)); + if (!tmp) { + free(greater); + free(lesser); + return (ARCHIVE_FATAL); + } + greater = tmp; + greater[greater_count - 1] = strings[i]; + } + } + + /* quicksort(lesser) */ + retval1 = archive_utility_string_sort_helper(lesser, lesser_count); + for (i = 0; i < lesser_count; i++) + strings[i] = lesser[i]; + free(lesser); + + /* pivot */ + strings[lesser_count] = pivot; + + /* quicksort(greater) */ + retval2 = archive_utility_string_sort_helper(greater, greater_count); + for (i = 0; i < greater_count; i++) + strings[lesser_count + 1 + i] = greater[i]; + free(greater); + + return (retval1 < retval2) ? retval1 : retval2; +} + +int +archive_utility_string_sort(char **strings) +{ + unsigned int size = 0; + while (strings[size] != NULL) + size++; + return archive_utility_string_sort_helper(strings, size); +} diff --cc Utilities/cmlibarchive/libarchive/archive_version_details.c index 9289bf1,0000000..e773e5e mode 100644,000000..100644 --- a/Utilities/cmlibarchive/libarchive/archive_version_details.c +++ b/Utilities/cmlibarchive/libarchive/archive_version_details.c @@@ -1,133 -1,0 +1,151 @@@ +/*- + * Copyright (c) 2009-2012,2014 Michihiro NAKAJIMA + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "archive_platform.h" +__FBSDID("$FreeBSD: head/lib/libarchive/archive_util.c 201098 2009-12-28 02:58:14Z kientzle $"); + +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_ZLIB_H +#include +#endif +#ifdef HAVE_LZMA_H +#include +#endif +#ifdef HAVE_BZLIB_H +#include +#endif +#ifdef HAVE_LZ4_H +#include +#endif ++#ifdef HAVE_ZSTD_H ++#include ++#endif + +#include "archive.h" +#include "archive_private.h" +#include "archive_string.h" + +const char * +archive_version_details(void) +{ + static struct archive_string str; + static int init = 0; + const char *zlib = archive_zlib_version(); + const char *liblzma = archive_liblzma_version(); + const char *bzlib = archive_bzlib_version(); + const char *liblz4 = archive_liblz4_version(); ++ const char *libzstd = archive_libzstd_version(); + + if (!init) { + archive_string_init(&str); + + archive_strcat(&str, ARCHIVE_VERSION_STRING); + if (zlib != NULL) { + archive_strcat(&str, " zlib/"); + archive_strcat(&str, zlib); + } + if (liblzma) { + archive_strcat(&str, " liblzma/"); + archive_strcat(&str, liblzma); + } + if (bzlib) { + const char *p = bzlib; + const char *sep = strchr(p, ','); + if (sep == NULL) + sep = p + strlen(p); + archive_strcat(&str, " bz2lib/"); + archive_strncat(&str, p, sep - p); + } + if (liblz4) { + archive_strcat(&str, " liblz4/"); + archive_strcat(&str, liblz4); + } ++ if (libzstd) { ++ archive_strcat(&str, " libzstd/"); ++ archive_strcat(&str, libzstd); ++ } + } + return str.s; +} + +const char * +archive_zlib_version(void) +{ +#ifdef HAVE_ZLIB_H + return ZLIB_VERSION; +#else + return NULL; +#endif +} + +const char * +archive_liblzma_version(void) +{ +#ifdef HAVE_LZMA_H + return LZMA_VERSION_STRING; +#else + return NULL; +#endif +} + +const char * +archive_bzlib_version(void) +{ +#ifdef HAVE_BZLIB_H + return BZ2_bzlibVersion(); +#else + return NULL; +#endif +} + +const char * +archive_liblz4_version(void) +{ +#if defined(HAVE_LZ4_H) && defined(HAVE_LIBLZ4) +#define str(s) #s +#define NUMBER(x) str(x) + return NUMBER(LZ4_VERSION_MAJOR) "." NUMBER(LZ4_VERSION_MINOR) "." NUMBER(LZ4_VERSION_RELEASE); +#undef NUMBER +#undef str +#else + return NULL; +#endif +} ++ ++const char * ++archive_libzstd_version(void) ++{ ++#if HAVE_ZSTD_H && HAVE_LIBZSTD ++ return ZSTD_VERSION_STRING; ++#else ++ return NULL; ++#endif ++} diff --cc Utilities/cmlibarchive/libarchive/archive_write_add_filter_gzip.c index bbcc178,0000000..986123a mode 100644,000000..100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_gzip.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_gzip.c @@@ -1,442 -1,0 +1,447 @@@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "archive_platform.h" + +__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_compression_gzip.c 201081 2009-12-28 02:04:42Z kientzle $"); + +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#include +#ifdef HAVE_ZLIB_H +#include +#endif + +#include "archive.h" +#include "archive_private.h" +#include "archive_string.h" +#include "archive_write_private.h" + +#if ARCHIVE_VERSION_NUMBER < 4000000 +int +archive_write_set_compression_gzip(struct archive *a) +{ + __archive_write_filters_free(a); + return (archive_write_add_filter_gzip(a)); +} +#endif + +/* Don't compile this if we don't have zlib. */ + +struct private_data { + int compression_level; + int timestamp; +#ifdef HAVE_ZLIB_H + z_stream stream; + int64_t total_in; + unsigned char *compressed; + size_t compressed_buffer_size; + unsigned long crc; +#else + struct archive_write_program_data *pdata; +#endif +}; + +/* + * Yuck. zlib.h is not const-correct, so I need this one bit + * of ugly hackery to convert a const * pointer to a non-const pointer. + */ +#define SET_NEXT_IN(st,src) \ + (st)->stream.next_in = (Bytef *)(uintptr_t)(const void *)(src) + +static int archive_compressor_gzip_options(struct archive_write_filter *, + const char *, const char *); +static int archive_compressor_gzip_open(struct archive_write_filter *); +static int archive_compressor_gzip_write(struct archive_write_filter *, + const void *, size_t); +static int archive_compressor_gzip_close(struct archive_write_filter *); +static int archive_compressor_gzip_free(struct archive_write_filter *); +#ifdef HAVE_ZLIB_H +static int drive_compressor(struct archive_write_filter *, + struct private_data *, int finishing); +#endif + + +/* + * Add a gzip compression filter to this write handle. + */ +int +archive_write_add_filter_gzip(struct archive *_a) +{ + struct archive_write *a = (struct archive_write *)_a; + struct archive_write_filter *f = __archive_write_allocate_filter(_a); + struct private_data *data; + archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_NEW, "archive_write_add_filter_gzip"); + + data = calloc(1, sizeof(*data)); + if (data == NULL) { + archive_set_error(&a->archive, ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + f->data = data; + f->open = &archive_compressor_gzip_open; + f->options = &archive_compressor_gzip_options; + f->close = &archive_compressor_gzip_close; + f->free = &archive_compressor_gzip_free; + f->code = ARCHIVE_FILTER_GZIP; + f->name = "gzip"; +#ifdef HAVE_ZLIB_H + data->compression_level = Z_DEFAULT_COMPRESSION; + return (ARCHIVE_OK); +#else + data->pdata = __archive_write_program_allocate("gzip"); + if (data->pdata == NULL) { + free(data); + archive_set_error(&a->archive, ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + data->compression_level = 0; + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Using external gzip program"); + return (ARCHIVE_WARN); +#endif +} + +static int +archive_compressor_gzip_free(struct archive_write_filter *f) +{ + struct private_data *data = (struct private_data *)f->data; + +#ifdef HAVE_ZLIB_H + free(data->compressed); +#else + __archive_write_program_free(data->pdata); +#endif + free(data); + f->data = NULL; + return (ARCHIVE_OK); +} + +/* + * Set write options. + */ +static int +archive_compressor_gzip_options(struct archive_write_filter *f, const char *key, + const char *value) +{ + struct private_data *data = (struct private_data *)f->data; + + if (strcmp(key, "compression-level") == 0) { + if (value == NULL || !(value[0] >= '0' && value[0] <= '9') || + value[1] != '\0') + return (ARCHIVE_WARN); + data->compression_level = value[0] - '0'; + return (ARCHIVE_OK); + } + if (strcmp(key, "timestamp") == 0) { + data->timestamp = (value == NULL)?-1:1; + return (ARCHIVE_OK); + } + + /* Note: The "warn" return is just to inform the options + * supervisor that we didn't handle it. It will generate + * a suitable error if no one used this option. */ + return (ARCHIVE_WARN); +} + +#ifdef HAVE_ZLIB_H +/* + * Setup callback. + */ +static int +archive_compressor_gzip_open(struct archive_write_filter *f) +{ + struct private_data *data = (struct private_data *)f->data; + int ret; + + ret = __archive_write_open_filter(f->next_filter); + if (ret != ARCHIVE_OK) + return (ret); + + if (data->compressed == NULL) { + size_t bs = 65536, bpb; + if (f->archive->magic == ARCHIVE_WRITE_MAGIC) { + /* Buffer size should be a multiple number of + * the of bytes per block for performance. */ + bpb = archive_write_get_bytes_per_block(f->archive); + if (bpb > bs) + bs = bpb; + else if (bpb != 0) + bs -= bs % bpb; + } + data->compressed_buffer_size = bs; + data->compressed + = (unsigned char *)malloc(data->compressed_buffer_size); + if (data->compressed == NULL) { + archive_set_error(f->archive, ENOMEM, + "Can't allocate data for compression buffer"); + return (ARCHIVE_FATAL); + } + } + + data->crc = crc32(0L, NULL, 0); + data->stream.next_out = data->compressed; + data->stream.avail_out = (uInt)data->compressed_buffer_size; + + /* Prime output buffer with a gzip header. */ + data->compressed[0] = 0x1f; /* GZip signature bytes */ + data->compressed[1] = 0x8b; + data->compressed[2] = 0x08; /* "Deflate" compression */ + data->compressed[3] = 0; /* No options */ + if (data->timestamp >= 0) { + time_t t = time(NULL); + data->compressed[4] = (uint8_t)(t)&0xff; /* Timestamp */ + data->compressed[5] = (uint8_t)(t>>8)&0xff; + data->compressed[6] = (uint8_t)(t>>16)&0xff; + data->compressed[7] = (uint8_t)(t>>24)&0xff; + } else + memset(&data->compressed[4], 0, 4); - data->compressed[8] = 0; /* No deflate options */ ++ if (data->compression_level == 9) ++ data->compressed[8] = 2; ++ else if(data->compression_level == 1) ++ data->compressed[8] = 4; ++ else ++ data->compressed[8] = 0; + data->compressed[9] = 3; /* OS=Unix */ + data->stream.next_out += 10; + data->stream.avail_out -= 10; + + f->write = archive_compressor_gzip_write; + + /* Initialize compression library. */ + ret = deflateInit2(&(data->stream), + data->compression_level, + Z_DEFLATED, + -15 /* < 0 to suppress zlib header */, + 8, + Z_DEFAULT_STRATEGY); + + if (ret == Z_OK) { + f->data = data; + return (ARCHIVE_OK); + } + + /* Library setup failed: clean up. */ + archive_set_error(f->archive, ARCHIVE_ERRNO_MISC, "Internal error " + "initializing compression library"); + + /* Override the error message if we know what really went wrong. */ + switch (ret) { + case Z_STREAM_ERROR: + archive_set_error(f->archive, ARCHIVE_ERRNO_MISC, + "Internal error initializing " + "compression library: invalid setup parameter"); + break; + case Z_MEM_ERROR: + archive_set_error(f->archive, ENOMEM, + "Internal error initializing compression library"); + break; + case Z_VERSION_ERROR: + archive_set_error(f->archive, ARCHIVE_ERRNO_MISC, + "Internal error initializing " + "compression library: invalid library version"); + break; + } + + return (ARCHIVE_FATAL); +} + +/* + * Write data to the compressed stream. + */ +static int +archive_compressor_gzip_write(struct archive_write_filter *f, const void *buff, + size_t length) +{ + struct private_data *data = (struct private_data *)f->data; + int ret; + + /* Update statistics */ + data->crc = crc32(data->crc, (const Bytef *)buff, (uInt)length); + data->total_in += length; + + /* Compress input data to output buffer */ + SET_NEXT_IN(data, buff); + data->stream.avail_in = (uInt)length; + if ((ret = drive_compressor(f, data, 0)) != ARCHIVE_OK) + return (ret); + + return (ARCHIVE_OK); +} + +/* + * Finish the compression... + */ +static int +archive_compressor_gzip_close(struct archive_write_filter *f) +{ + unsigned char trailer[8]; + struct private_data *data = (struct private_data *)f->data; + int ret, r1; + + /* Finish compression cycle */ + ret = drive_compressor(f, data, 1); + if (ret == ARCHIVE_OK) { + /* Write the last compressed data. */ + ret = __archive_write_filter(f->next_filter, + data->compressed, + data->compressed_buffer_size - data->stream.avail_out); + } + if (ret == ARCHIVE_OK) { + /* Build and write out 8-byte trailer. */ + trailer[0] = (uint8_t)(data->crc)&0xff; + trailer[1] = (uint8_t)(data->crc >> 8)&0xff; + trailer[2] = (uint8_t)(data->crc >> 16)&0xff; + trailer[3] = (uint8_t)(data->crc >> 24)&0xff; + trailer[4] = (uint8_t)(data->total_in)&0xff; + trailer[5] = (uint8_t)(data->total_in >> 8)&0xff; + trailer[6] = (uint8_t)(data->total_in >> 16)&0xff; + trailer[7] = (uint8_t)(data->total_in >> 24)&0xff; + ret = __archive_write_filter(f->next_filter, trailer, 8); + } + + switch (deflateEnd(&(data->stream))) { + case Z_OK: + break; + default: + archive_set_error(f->archive, ARCHIVE_ERRNO_MISC, + "Failed to clean up compressor"); + ret = ARCHIVE_FATAL; + } + r1 = __archive_write_close_filter(f->next_filter); + return (r1 < ret ? r1 : ret); +} + +/* + * Utility function to push input data through compressor, + * writing full output blocks as necessary. + * + * Note that this handles both the regular write case (finishing == + * false) and the end-of-archive case (finishing == true). + */ +static int +drive_compressor(struct archive_write_filter *f, + struct private_data *data, int finishing) +{ + int ret; + + for (;;) { + if (data->stream.avail_out == 0) { + ret = __archive_write_filter(f->next_filter, + data->compressed, + data->compressed_buffer_size); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + data->stream.next_out = data->compressed; + data->stream.avail_out = + (uInt)data->compressed_buffer_size; + } + + /* If there's nothing to do, we're done. */ + if (!finishing && data->stream.avail_in == 0) + return (ARCHIVE_OK); + + ret = deflate(&(data->stream), + finishing ? Z_FINISH : Z_NO_FLUSH ); + + switch (ret) { + case Z_OK: + /* In non-finishing case, check if compressor + * consumed everything */ + if (!finishing && data->stream.avail_in == 0) + return (ARCHIVE_OK); + /* In finishing case, this return always means + * there's more work */ + break; + case Z_STREAM_END: + /* This return can only occur in finishing case. */ + return (ARCHIVE_OK); + default: + /* Any other return value indicates an error. */ + archive_set_error(f->archive, ARCHIVE_ERRNO_MISC, + "GZip compression failed:" + " deflate() call returned status %d", + ret); + return (ARCHIVE_FATAL); + } + } +} + +#else /* HAVE_ZLIB_H */ + +static int +archive_compressor_gzip_open(struct archive_write_filter *f) +{ + struct private_data *data = (struct private_data *)f->data; + struct archive_string as; + int r; + + archive_string_init(&as); + archive_strcpy(&as, "gzip"); + + /* Specify compression level. */ + if (data->compression_level > 0) { + archive_strcat(&as, " -"); + archive_strappend_char(&as, '0' + data->compression_level); + } + if (data->timestamp < 0) + /* Do not save timestamp. */ + archive_strcat(&as, " -n"); + else if (data->timestamp > 0) + /* Save timestamp. */ + archive_strcat(&as, " -N"); + + f->write = archive_compressor_gzip_write; + r = __archive_write_program_open(f, data->pdata, as.s); + archive_string_free(&as); + return (r); +} + +static int +archive_compressor_gzip_write(struct archive_write_filter *f, const void *buff, + size_t length) +{ + struct private_data *data = (struct private_data *)f->data; + + return __archive_write_program_write(f, data->pdata, buff, length); +} + +static int +archive_compressor_gzip_close(struct archive_write_filter *f) +{ + struct private_data *data = (struct private_data *)f->data; + + return __archive_write_program_close(f, data->pdata); +} + +#endif /* HAVE_ZLIB_H */ diff --cc Utilities/cmlibarchive/libarchive/archive_write_add_filter_zstd.c index 0000000,671fc6a..671fc6a mode 000000,100644..100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_zstd.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_zstd.c diff --cc Utilities/cmlibarchive/libarchive/archive_write_disk_posix.c index 4a42a3b,0000000..affa503 mode 100644,000000..100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_disk_posix.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_disk_posix.c @@@ -1,4327 -1,0 +1,4331 @@@ +/*- + * Copyright (c) 2003-2010 Tim Kientzle + * Copyright (c) 2012 Michihiro NAKAJIMA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "archive_platform.h" +__FBSDID("$FreeBSD$"); + +#if !defined(_WIN32) || defined(__CYGWIN__) + +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#ifdef HAVE_SYS_ACL_H +#include +#endif +#ifdef HAVE_SYS_EXTATTR_H +#include +#endif +#if HAVE_SYS_XATTR_H +#include +#elif HAVE_ATTR_XATTR_H +#include +#endif +#ifdef HAVE_SYS_EA_H +#include +#endif +#ifdef HAVE_SYS_IOCTL_H +#include +#endif +#ifdef HAVE_SYS_STAT_H +#include +#endif +#ifdef HAVE_SYS_TIME_H +#include +#endif +#ifdef HAVE_SYS_UTIME_H +#include +#endif +#ifdef HAVE_COPYFILE_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_FCNTL_H +#include +#endif +#ifdef HAVE_GRP_H +#include +#endif +#ifdef HAVE_LANGINFO_H +#include +#endif +#ifdef HAVE_LINUX_FS_H +#include /* for Linux file flags */ +#endif +/* + * Some Linux distributions have both linux/ext2_fs.h and ext2fs/ext2_fs.h. + * As the include guards don't agree, the order of include is important. + */ +#ifdef HAVE_LINUX_EXT2_FS_H +#include /* for Linux file flags */ +#endif +#if defined(HAVE_EXT2FS_EXT2_FS_H) && !defined(__CYGWIN__) +#include /* Linux file flags, broken on Cygwin */ +#endif +#ifdef HAVE_LIMITS_H +#include +#endif +#ifdef HAVE_PWD_H +#include +#endif +#include +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_UNISTD_H +#include +#endif +#ifdef HAVE_UTIME_H +#include +#endif +#ifdef F_GETTIMES /* Tru64 specific */ +#include +#endif + +/* + * Macro to cast st_mtime and time_t to an int64 so that 2 numbers can reliably be compared. + * + * It assumes that the input is an integer type of no more than 64 bits. + * If the number is less than zero, t must be a signed type, so it fits in + * int64_t. Otherwise, it's a nonnegative value so we can cast it to uint64_t + * without loss. But it could be a large unsigned value, so we have to clip it + * to INT64_MAX.* + */ +#define to_int64_time(t) \ + ((t) < 0 ? (int64_t)(t) : (uint64_t)(t) > (uint64_t)INT64_MAX ? INT64_MAX : (int64_t)(t)) + +#if __APPLE__ +#include +#if TARGET_OS_MAC && !TARGET_OS_EMBEDDED && HAVE_QUARANTINE_H +#include +#define HAVE_QUARANTINE 1 +#endif +#endif + +#ifdef HAVE_ZLIB_H +#include +#endif + +/* TODO: Support Mac OS 'quarantine' feature. This is really just a + * standard tag to mark files that have been downloaded as "tainted". + * On Mac OS, we should mark the extracted files as tainted if the + * archive being read was tainted. Windows has a similar feature; we + * should investigate ways to support this generically. */ + +#include "archive.h" +#include "archive_acl_private.h" +#include "archive_string.h" +#include "archive_endian.h" +#include "archive_entry.h" +#include "archive_private.h" +#include "archive_write_disk_private.h" + +#ifndef O_BINARY +#define O_BINARY 0 +#endif +#ifndef O_CLOEXEC +#define O_CLOEXEC 0 +#endif + +/* Ignore non-int O_NOFOLLOW constant. */ +/* gnulib's fcntl.h does this on AIX, but it seems practical everywhere */ +#if defined O_NOFOLLOW && !(INT_MIN <= O_NOFOLLOW && O_NOFOLLOW <= INT_MAX) +#undef O_NOFOLLOW +#endif + +#ifndef O_NOFOLLOW +#define O_NOFOLLOW 0 +#endif + +struct fixup_entry { + struct fixup_entry *next; + struct archive_acl acl; + mode_t mode; + int64_t atime; + int64_t birthtime; + int64_t mtime; + int64_t ctime; + unsigned long atime_nanos; + unsigned long birthtime_nanos; + unsigned long mtime_nanos; + unsigned long ctime_nanos; + unsigned long fflags_set; + size_t mac_metadata_size; + void *mac_metadata; + int fixup; /* bitmask of what needs fixing */ + char *name; +}; + +/* + * We use a bitmask to track which operations remain to be done for + * this file. In particular, this helps us avoid unnecessary + * operations when it's possible to take care of one step as a + * side-effect of another. For example, mkdir() can specify the mode + * for the newly-created object but symlink() cannot. This means we + * can skip chmod() if mkdir() succeeded, but we must explicitly + * chmod() if we're trying to create a directory that already exists + * (mkdir() failed) or if we're restoring a symlink. Similarly, we + * need to verify UID/GID before trying to restore SUID/SGID bits; + * that verification can occur explicitly through a stat() call or + * implicitly because of a successful chown() call. + */ +#define TODO_MODE_FORCE 0x40000000 +#define TODO_MODE_BASE 0x20000000 +#define TODO_SUID 0x10000000 +#define TODO_SUID_CHECK 0x08000000 +#define TODO_SGID 0x04000000 +#define TODO_SGID_CHECK 0x02000000 +#define TODO_APPLEDOUBLE 0x01000000 +#define TODO_MODE (TODO_MODE_BASE|TODO_SUID|TODO_SGID) +#define TODO_TIMES ARCHIVE_EXTRACT_TIME +#define TODO_OWNER ARCHIVE_EXTRACT_OWNER +#define TODO_FFLAGS ARCHIVE_EXTRACT_FFLAGS +#define TODO_ACLS ARCHIVE_EXTRACT_ACL +#define TODO_XATTR ARCHIVE_EXTRACT_XATTR +#define TODO_MAC_METADATA ARCHIVE_EXTRACT_MAC_METADATA +#define TODO_HFS_COMPRESSION ARCHIVE_EXTRACT_HFS_COMPRESSION_FORCED + +struct archive_write_disk { + struct archive archive; + + mode_t user_umask; + struct fixup_entry *fixup_list; + struct fixup_entry *current_fixup; + int64_t user_uid; + int skip_file_set; + int64_t skip_file_dev; + int64_t skip_file_ino; + time_t start_time; + + int64_t (*lookup_gid)(void *private, const char *gname, int64_t gid); + void (*cleanup_gid)(void *private); + void *lookup_gid_data; + int64_t (*lookup_uid)(void *private, const char *uname, int64_t uid); + void (*cleanup_uid)(void *private); + void *lookup_uid_data; + + /* + * Full path of last file to satisfy symlink checks. + */ + struct archive_string path_safe; + + /* + * Cached stat data from disk for the current entry. + * If this is valid, pst points to st. Otherwise, + * pst is null. + */ + struct stat st; + struct stat *pst; + + /* Information about the object being restored right now. */ + struct archive_entry *entry; /* Entry being extracted. */ + char *name; /* Name of entry, possibly edited. */ + struct archive_string _name_data; /* backing store for 'name' */ + /* Tasks remaining for this object. */ + int todo; + /* Tasks deferred until end-of-archive. */ + int deferred; + /* Options requested by the client. */ + int flags; + /* Handle for the file we're restoring. */ + int fd; + /* Current offset for writing data to the file. */ + int64_t offset; + /* Last offset actually written to disk. */ + int64_t fd_offset; + /* Total bytes actually written to files. */ + int64_t total_bytes_written; + /* Maximum size of file, -1 if unknown. */ + int64_t filesize; + /* Dir we were in before this restore; only for deep paths. */ + int restore_pwd; + /* Mode we should use for this entry; affected by _PERM and umask. */ + mode_t mode; + /* UID/GID to use in restoring this entry. */ + int64_t uid; + int64_t gid; + /* + * HFS+ Compression. + */ + /* Xattr "com.apple.decmpfs". */ + uint32_t decmpfs_attr_size; + unsigned char *decmpfs_header_p; + /* ResourceFork set options used for fsetxattr. */ + int rsrc_xattr_options; + /* Xattr "com.apple.ResourceFork". */ + unsigned char *resource_fork; + size_t resource_fork_allocated_size; + unsigned int decmpfs_block_count; + uint32_t *decmpfs_block_info; + /* Buffer for compressed data. */ + unsigned char *compressed_buffer; + size_t compressed_buffer_size; + size_t compressed_buffer_remaining; + /* The offset of the ResourceFork where compressed data will + * be placed. */ + uint32_t compressed_rsrc_position; + uint32_t compressed_rsrc_position_v; + /* Buffer for uncompressed data. */ + char *uncompressed_buffer; + size_t block_remaining_bytes; + size_t file_remaining_bytes; +#ifdef HAVE_ZLIB_H + z_stream stream; + int stream_valid; + int decmpfs_compression_level; +#endif +}; + +/* + * Default mode for dirs created automatically (will be modified by umask). + * Note that POSIX specifies 0777 for implicitly-created dirs, "modified + * by the process' file creation mask." + */ +#define DEFAULT_DIR_MODE 0777 +/* + * Dir modes are restored in two steps: During the extraction, the permissions + * in the archive are modified to match the following limits. During + * the post-extract fixup pass, the permissions from the archive are + * applied. + */ +#define MINIMUM_DIR_MODE 0700 +#define MAXIMUM_DIR_MODE 0775 + +/* + * Maximum uncompressed size of a decmpfs block. + */ +#define MAX_DECMPFS_BLOCK_SIZE (64 * 1024) +/* + * HFS+ compression type. + */ +#define CMP_XATTR 3/* Compressed data in xattr. */ +#define CMP_RESOURCE_FORK 4/* Compressed data in resource fork. */ +/* + * HFS+ compression resource fork. + */ +#define RSRC_H_SIZE 260 /* Base size of Resource fork header. */ +#define RSRC_F_SIZE 50 /* Size of Resource fork footer. */ +/* Size to write compressed data to resource fork. */ +#define COMPRESSED_W_SIZE (64 * 1024) +/* decmpfs definitions. */ +#define MAX_DECMPFS_XATTR_SIZE 3802 +#ifndef DECMPFS_XATTR_NAME +#define DECMPFS_XATTR_NAME "com.apple.decmpfs" +#endif +#define DECMPFS_MAGIC 0x636d7066 +#define DECMPFS_COMPRESSION_MAGIC 0 +#define DECMPFS_COMPRESSION_TYPE 4 +#define DECMPFS_UNCOMPRESSED_SIZE 8 +#define DECMPFS_HEADER_SIZE 16 + +#define HFS_BLOCKS(s) ((s) >> 12) + +static void fsobj_error(int *, struct archive_string *, int, const char *, + const char *); +static int check_symlinks_fsobj(char *, int *, struct archive_string *, + int); +static int check_symlinks(struct archive_write_disk *); +static int create_filesystem_object(struct archive_write_disk *); +static struct fixup_entry *current_fixup(struct archive_write_disk *, + const char *pathname); +#if defined(HAVE_FCHDIR) && defined(PATH_MAX) +static void edit_deep_directories(struct archive_write_disk *ad); +#endif +static int cleanup_pathname_fsobj(char *, int *, struct archive_string *, + int); +static int cleanup_pathname(struct archive_write_disk *); +static int create_dir(struct archive_write_disk *, char *); +static int create_parent_dir(struct archive_write_disk *, char *); +static ssize_t hfs_write_data_block(struct archive_write_disk *, + const char *, size_t); +static int fixup_appledouble(struct archive_write_disk *, const char *); +static int older(struct stat *, struct archive_entry *); +static int restore_entry(struct archive_write_disk *); +static int set_mac_metadata(struct archive_write_disk *, const char *, + const void *, size_t); +static int set_xattrs(struct archive_write_disk *); +static int clear_nochange_fflags(struct archive_write_disk *); +static int set_fflags(struct archive_write_disk *); +static int set_fflags_platform(struct archive_write_disk *, int fd, + const char *name, mode_t mode, + unsigned long fflags_set, unsigned long fflags_clear); +static int set_ownership(struct archive_write_disk *); +static int set_mode(struct archive_write_disk *, int mode); +static int set_time(int, int, const char *, time_t, long, time_t, long); +static int set_times(struct archive_write_disk *, int, int, const char *, + time_t, long, time_t, long, time_t, long, time_t, long); +static int set_times_from_entry(struct archive_write_disk *); +static struct fixup_entry *sort_dir_list(struct fixup_entry *p); +static ssize_t write_data_block(struct archive_write_disk *, + const char *, size_t); + +static struct archive_vtable *archive_write_disk_vtable(void); + +static int _archive_write_disk_close(struct archive *); +static int _archive_write_disk_free(struct archive *); +static int _archive_write_disk_header(struct archive *, + struct archive_entry *); +static int64_t _archive_write_disk_filter_bytes(struct archive *, int); +static int _archive_write_disk_finish_entry(struct archive *); +static ssize_t _archive_write_disk_data(struct archive *, const void *, + size_t); +static ssize_t _archive_write_disk_data_block(struct archive *, const void *, + size_t, int64_t); + +static int +lazy_stat(struct archive_write_disk *a) +{ + if (a->pst != NULL) { + /* Already have stat() data available. */ + return (ARCHIVE_OK); + } +#ifdef HAVE_FSTAT + if (a->fd >= 0 && fstat(a->fd, &a->st) == 0) { + a->pst = &a->st; + return (ARCHIVE_OK); + } +#endif + /* + * XXX At this point, symlinks should not be hit, otherwise + * XXX a race occurred. Do we want to check explicitly for that? + */ + if (lstat(a->name, &a->st) == 0) { + a->pst = &a->st; + return (ARCHIVE_OK); + } + archive_set_error(&a->archive, errno, "Couldn't stat file"); + return (ARCHIVE_WARN); +} + +static struct archive_vtable * +archive_write_disk_vtable(void) +{ + static struct archive_vtable av; + static int inited = 0; + + if (!inited) { + av.archive_close = _archive_write_disk_close; + av.archive_filter_bytes = _archive_write_disk_filter_bytes; + av.archive_free = _archive_write_disk_free; + av.archive_write_header = _archive_write_disk_header; + av.archive_write_finish_entry + = _archive_write_disk_finish_entry; + av.archive_write_data = _archive_write_disk_data; + av.archive_write_data_block = _archive_write_disk_data_block; + inited = 1; + } + return (&av); +} + +static int64_t +_archive_write_disk_filter_bytes(struct archive *_a, int n) +{ + struct archive_write_disk *a = (struct archive_write_disk *)_a; + (void)n; /* UNUSED */ + if (n == -1 || n == 0) + return (a->total_bytes_written); + return (-1); +} + + +int +archive_write_disk_set_options(struct archive *_a, int flags) +{ + struct archive_write_disk *a = (struct archive_write_disk *)_a; + + a->flags = flags; + return (ARCHIVE_OK); +} + + +/* + * Extract this entry to disk. + * + * TODO: Validate hardlinks. According to the standards, we're + * supposed to check each extracted hardlink and squawk if it refers + * to a file that we didn't restore. I'm not entirely convinced this + * is a good idea, but more importantly: Is there any way to validate + * hardlinks without keeping a complete list of filenames from the + * entire archive?? Ugh. + * + */ +static int +_archive_write_disk_header(struct archive *_a, struct archive_entry *entry) +{ + struct archive_write_disk *a = (struct archive_write_disk *)_a; + struct fixup_entry *fe; + int ret, r; + + archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, + ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA, + "archive_write_disk_header"); + archive_clear_error(&a->archive); + if (a->archive.state & ARCHIVE_STATE_DATA) { + r = _archive_write_disk_finish_entry(&a->archive); + if (r == ARCHIVE_FATAL) + return (r); + } + + /* Set up for this particular entry. */ + a->pst = NULL; + a->current_fixup = NULL; + a->deferred = 0; + if (a->entry) { + archive_entry_free(a->entry); + a->entry = NULL; + } + a->entry = archive_entry_clone(entry); + a->fd = -1; + a->fd_offset = 0; + a->offset = 0; + a->restore_pwd = -1; + a->uid = a->user_uid; + a->mode = archive_entry_mode(a->entry); + if (archive_entry_size_is_set(a->entry)) + a->filesize = archive_entry_size(a->entry); + else + a->filesize = -1; + archive_strcpy(&(a->_name_data), archive_entry_pathname(a->entry)); + a->name = a->_name_data.s; + archive_clear_error(&a->archive); + + /* + * Clean up the requested path. This is necessary for correct + * dir restores; the dir restore logic otherwise gets messed + * up by nonsense like "dir/.". + */ + ret = cleanup_pathname(a); + if (ret != ARCHIVE_OK) + return (ret); + + /* + * Query the umask so we get predictable mode settings. + * This gets done on every call to _write_header in case the + * user edits their umask during the extraction for some + * reason. + */ + umask(a->user_umask = umask(0)); + + /* Figure out what we need to do for this entry. */ + a->todo = TODO_MODE_BASE; + if (a->flags & ARCHIVE_EXTRACT_PERM) { + a->todo |= TODO_MODE_FORCE; /* Be pushy about permissions. */ + /* + * SGID requires an extra "check" step because we + * cannot easily predict the GID that the system will + * assign. (Different systems assign GIDs to files + * based on a variety of criteria, including process + * credentials and the gid of the enclosing + * directory.) We can only restore the SGID bit if + * the file has the right GID, and we only know the + * GID if we either set it (see set_ownership) or if + * we've actually called stat() on the file after it + * was restored. Since there are several places at + * which we might verify the GID, we need a TODO bit + * to keep track. + */ + if (a->mode & S_ISGID) + a->todo |= TODO_SGID | TODO_SGID_CHECK; + /* + * Verifying the SUID is simpler, but can still be + * done in multiple ways, hence the separate "check" bit. + */ + if (a->mode & S_ISUID) + a->todo |= TODO_SUID | TODO_SUID_CHECK; + } else { + /* + * User didn't request full permissions, so don't + * restore SUID, SGID bits and obey umask. + */ + a->mode &= ~S_ISUID; + a->mode &= ~S_ISGID; + a->mode &= ~S_ISVTX; + a->mode &= ~a->user_umask; + } + if (a->flags & ARCHIVE_EXTRACT_OWNER) + a->todo |= TODO_OWNER; + if (a->flags & ARCHIVE_EXTRACT_TIME) + a->todo |= TODO_TIMES; + if (a->flags & ARCHIVE_EXTRACT_ACL) { +#if ARCHIVE_ACL_DARWIN + /* + * On MacOS, platform ACLs get stored in mac_metadata, too. + * If we intend to extract mac_metadata and it is present + * we skip extracting libarchive NFSv4 ACLs. + */ + size_t metadata_size; + + if ((a->flags & ARCHIVE_EXTRACT_MAC_METADATA) == 0 || + archive_entry_mac_metadata(a->entry, + &metadata_size) == NULL || metadata_size == 0) +#endif +#if ARCHIVE_ACL_LIBRICHACL + /* + * RichACLs are stored in an extended attribute. + * If we intend to extract extended attributes and have this + * attribute we skip extracting libarchive NFSv4 ACLs. + */ + short extract_acls = 1; + if (a->flags & ARCHIVE_EXTRACT_XATTR && ( + archive_entry_acl_types(a->entry) & + ARCHIVE_ENTRY_ACL_TYPE_NFS4)) { + const char *attr_name; + const void *attr_value; + size_t attr_size; + int i = archive_entry_xattr_reset(a->entry); + while (i--) { + archive_entry_xattr_next(a->entry, &attr_name, + &attr_value, &attr_size); + if (attr_name != NULL && attr_value != NULL && + attr_size > 0 && strcmp(attr_name, + "trusted.richacl") == 0) { + extract_acls = 0; + break; + } + } + } + if (extract_acls) +#endif +#if ARCHIVE_ACL_DARWIN || ARCHIVE_ACL_LIBRICHACL + { +#endif + if (archive_entry_filetype(a->entry) == AE_IFDIR) + a->deferred |= TODO_ACLS; + else + a->todo |= TODO_ACLS; +#if ARCHIVE_ACL_DARWIN || ARCHIVE_ACL_LIBRICHACL + } +#endif + } + if (a->flags & ARCHIVE_EXTRACT_MAC_METADATA) { + if (archive_entry_filetype(a->entry) == AE_IFDIR) + a->deferred |= TODO_MAC_METADATA; + else + a->todo |= TODO_MAC_METADATA; + } +#if defined(__APPLE__) && defined(UF_COMPRESSED) && defined(HAVE_ZLIB_H) + if ((a->flags & ARCHIVE_EXTRACT_NO_HFS_COMPRESSION) == 0) { + unsigned long set, clear; + archive_entry_fflags(a->entry, &set, &clear); + if ((set & ~clear) & UF_COMPRESSED) { + a->todo |= TODO_HFS_COMPRESSION; + a->decmpfs_block_count = (unsigned)-1; + } + } + if ((a->flags & ARCHIVE_EXTRACT_HFS_COMPRESSION_FORCED) != 0 && + (a->mode & AE_IFMT) == AE_IFREG && a->filesize > 0) { + a->todo |= TODO_HFS_COMPRESSION; + a->decmpfs_block_count = (unsigned)-1; + } + { + const char *p; + + /* Check if the current file name is a type of the + * resource fork file. */ + p = strrchr(a->name, '/'); + if (p == NULL) + p = a->name; + else + p++; + if (p[0] == '.' && p[1] == '_') { + /* Do not compress "._XXX" files. */ + a->todo &= ~TODO_HFS_COMPRESSION; + if (a->filesize > 0) + a->todo |= TODO_APPLEDOUBLE; + } + } +#endif + + if (a->flags & ARCHIVE_EXTRACT_XATTR) { +#if ARCHIVE_XATTR_DARWIN + /* + * On MacOS, extended attributes get stored in mac_metadata, + * too. If we intend to extract mac_metadata and it is present + * we skip extracting extended attributes. + */ + size_t metadata_size; + + if ((a->flags & ARCHIVE_EXTRACT_MAC_METADATA) == 0 || + archive_entry_mac_metadata(a->entry, + &metadata_size) == NULL || metadata_size == 0) +#endif + a->todo |= TODO_XATTR; + } + if (a->flags & ARCHIVE_EXTRACT_FFLAGS) + a->todo |= TODO_FFLAGS; + if (a->flags & ARCHIVE_EXTRACT_SECURE_SYMLINKS) { + ret = check_symlinks(a); + if (ret != ARCHIVE_OK) + return (ret); + } +#if defined(HAVE_FCHDIR) && defined(PATH_MAX) + /* If path exceeds PATH_MAX, shorten the path. */ + edit_deep_directories(a); +#endif + + ret = restore_entry(a); + +#if defined(__APPLE__) && defined(UF_COMPRESSED) && defined(HAVE_ZLIB_H) + /* + * Check if the filesystem the file is restoring on supports + * HFS+ Compression. If not, cancel HFS+ Compression. + */ + if (a->todo | TODO_HFS_COMPRESSION) { + /* + * NOTE: UF_COMPRESSED is ignored even if the filesystem + * supports HFS+ Compression because the file should + * have at least an extended attribute "com.apple.decmpfs" + * before the flag is set to indicate that the file have + * been compressed. If the filesystem does not support + * HFS+ Compression the system call will fail. + */ + if (a->fd < 0 || fchflags(a->fd, UF_COMPRESSED) != 0) + a->todo &= ~TODO_HFS_COMPRESSION; + } +#endif + + /* + * TODO: There are rumours that some extended attributes must + * be restored before file data is written. If this is true, + * then we either need to write all extended attributes both + * before and after restoring the data, or find some rule for + * determining which must go first and which last. Due to the + * many ways people are using xattrs, this may prove to be an + * intractable problem. + */ + +#ifdef HAVE_FCHDIR + /* If we changed directory above, restore it here. */ + if (a->restore_pwd >= 0) { + r = fchdir(a->restore_pwd); + if (r != 0) { + archive_set_error(&a->archive, errno, + "chdir() failure"); + ret = ARCHIVE_FATAL; + } + close(a->restore_pwd); + a->restore_pwd = -1; + } +#endif + + /* + * Fixup uses the unedited pathname from archive_entry_pathname(), + * because it is relative to the base dir and the edited path + * might be relative to some intermediate dir as a result of the + * deep restore logic. + */ + if (a->deferred & TODO_MODE) { + fe = current_fixup(a, archive_entry_pathname(entry)); + if (fe == NULL) + return (ARCHIVE_FATAL); + fe->fixup |= TODO_MODE_BASE; + fe->mode = a->mode; + } + + if ((a->deferred & TODO_TIMES) + && (archive_entry_mtime_is_set(entry) + || archive_entry_atime_is_set(entry))) { + fe = current_fixup(a, archive_entry_pathname(entry)); + if (fe == NULL) + return (ARCHIVE_FATAL); + fe->mode = a->mode; + fe->fixup |= TODO_TIMES; + if (archive_entry_atime_is_set(entry)) { + fe->atime = archive_entry_atime(entry); + fe->atime_nanos = archive_entry_atime_nsec(entry); + } else { + /* If atime is unset, use start time. */ + fe->atime = a->start_time; + fe->atime_nanos = 0; + } + if (archive_entry_mtime_is_set(entry)) { + fe->mtime = archive_entry_mtime(entry); + fe->mtime_nanos = archive_entry_mtime_nsec(entry); + } else { + /* If mtime is unset, use start time. */ + fe->mtime = a->start_time; + fe->mtime_nanos = 0; + } + if (archive_entry_birthtime_is_set(entry)) { + fe->birthtime = archive_entry_birthtime(entry); + fe->birthtime_nanos = archive_entry_birthtime_nsec( + entry); + } else { + /* If birthtime is unset, use mtime. */ + fe->birthtime = fe->mtime; + fe->birthtime_nanos = fe->mtime_nanos; + } + } + + if (a->deferred & TODO_ACLS) { + fe = current_fixup(a, archive_entry_pathname(entry)); + if (fe == NULL) + return (ARCHIVE_FATAL); + fe->fixup |= TODO_ACLS; + archive_acl_copy(&fe->acl, archive_entry_acl(entry)); + } + + if (a->deferred & TODO_MAC_METADATA) { + const void *metadata; + size_t metadata_size; + metadata = archive_entry_mac_metadata(a->entry, &metadata_size); + if (metadata != NULL && metadata_size > 0) { + fe = current_fixup(a, archive_entry_pathname(entry)); + if (fe == NULL) + return (ARCHIVE_FATAL); + fe->mac_metadata = malloc(metadata_size); + if (fe->mac_metadata != NULL) { + memcpy(fe->mac_metadata, metadata, + metadata_size); + fe->mac_metadata_size = metadata_size; + fe->fixup |= TODO_MAC_METADATA; + } + } + } + + if (a->deferred & TODO_FFLAGS) { + fe = current_fixup(a, archive_entry_pathname(entry)); + if (fe == NULL) + return (ARCHIVE_FATAL); + fe->fixup |= TODO_FFLAGS; + /* TODO: Complete this.. defer fflags from below. */ + } + + /* We've created the object and are ready to pour data into it. */ + if (ret >= ARCHIVE_WARN) + a->archive.state = ARCHIVE_STATE_DATA; + /* + * If it's not open, tell our client not to try writing. + * In particular, dirs, links, etc, don't get written to. + */ + if (a->fd < 0) { + archive_entry_set_size(entry, 0); + a->filesize = 0; + } + + return (ret); +} + +int - archive_write_disk_set_skip_file(struct archive *_a, int64_t d, int64_t i) ++archive_write_disk_set_skip_file(struct archive *_a, la_int64_t d, la_int64_t i) +{ + struct archive_write_disk *a = (struct archive_write_disk *)_a; + archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, + ARCHIVE_STATE_ANY, "archive_write_disk_set_skip_file"); + a->skip_file_set = 1; + a->skip_file_dev = d; + a->skip_file_ino = i; + return (ARCHIVE_OK); +} + +static ssize_t +write_data_block(struct archive_write_disk *a, const char *buff, size_t size) +{ + uint64_t start_size = size; + ssize_t bytes_written = 0; + ssize_t block_size = 0, bytes_to_write; + + if (size == 0) + return (ARCHIVE_OK); + + if (a->filesize == 0 || a->fd < 0) { + archive_set_error(&a->archive, 0, + "Attempt to write to an empty file"); + return (ARCHIVE_WARN); + } + + if (a->flags & ARCHIVE_EXTRACT_SPARSE) { +#if HAVE_STRUCT_STAT_ST_BLKSIZE + int r; + if ((r = lazy_stat(a)) != ARCHIVE_OK) + return (r); + block_size = a->pst->st_blksize; +#else + /* XXX TODO XXX Is there a more appropriate choice here ? */ + /* This needn't match the filesystem allocation size. */ + block_size = 16*1024; +#endif + } + + /* If this write would run beyond the file size, truncate it. */ + if (a->filesize >= 0 && (int64_t)(a->offset + size) > a->filesize) + start_size = size = (size_t)(a->filesize - a->offset); + + /* Write the data. */ + while (size > 0) { + if (block_size == 0) { + bytes_to_write = size; + } else { + /* We're sparsifying the file. */ + const char *p, *end; + int64_t block_end; + + /* Skip leading zero bytes. */ + for (p = buff, end = buff + size; p < end; ++p) { + if (*p != '\0') + break; + } + a->offset += p - buff; + size -= p - buff; + buff = p; + if (size == 0) + break; + + /* Calculate next block boundary after offset. */ + block_end + = (a->offset / block_size + 1) * block_size; + + /* If the adjusted write would cross block boundary, + * truncate it to the block boundary. */ + bytes_to_write = size; + if (a->offset + bytes_to_write > block_end) + bytes_to_write = block_end - a->offset; + } + /* Seek if necessary to the specified offset. */ + if (a->offset != a->fd_offset) { + if (lseek(a->fd, a->offset, SEEK_SET) < 0) { + archive_set_error(&a->archive, errno, + "Seek failed"); + return (ARCHIVE_FATAL); + } + a->fd_offset = a->offset; + } + bytes_written = write(a->fd, buff, bytes_to_write); + if (bytes_written < 0) { + archive_set_error(&a->archive, errno, "Write failed"); + return (ARCHIVE_WARN); + } + buff += bytes_written; + size -= bytes_written; + a->total_bytes_written += bytes_written; + a->offset += bytes_written; + a->fd_offset = a->offset; + } + return (start_size - size); +} + +#if defined(__APPLE__) && defined(UF_COMPRESSED) && defined(HAVE_SYS_XATTR_H)\ + && defined(HAVE_ZLIB_H) + +/* + * Set UF_COMPRESSED file flag. + * This have to be called after hfs_write_decmpfs() because if the + * file does not have "com.apple.decmpfs" xattr the flag is ignored. + */ +static int +hfs_set_compressed_fflag(struct archive_write_disk *a) +{ + int r; + + if ((r = lazy_stat(a)) != ARCHIVE_OK) + return (r); + + a->st.st_flags |= UF_COMPRESSED; + if (fchflags(a->fd, a->st.st_flags) != 0) { + archive_set_error(&a->archive, errno, + "Failed to set UF_COMPRESSED file flag"); + return (ARCHIVE_WARN); + } + return (ARCHIVE_OK); +} + +/* + * HFS+ Compression decmpfs + * + * +------------------------------+ +0 + * | Magic(LE 4 bytes) | + * +------------------------------+ + * | Type(LE 4 bytes) | + * +------------------------------+ + * | Uncompressed size(LE 8 bytes)| + * +------------------------------+ +16 + * | | + * | Compressed data | + * | (Placed only if Type == 3) | + * | | + * +------------------------------+ +3802 = MAX_DECMPFS_XATTR_SIZE + * + * Type is 3: decmpfs has compressed data. + * Type is 4: Resource Fork has compressed data. + */ +/* + * Write "com.apple.decmpfs" + */ +static int +hfs_write_decmpfs(struct archive_write_disk *a) +{ + int r; + uint32_t compression_type; + + r = fsetxattr(a->fd, DECMPFS_XATTR_NAME, a->decmpfs_header_p, + a->decmpfs_attr_size, 0, 0); + if (r < 0) { + archive_set_error(&a->archive, errno, + "Cannot restore xattr:%s", DECMPFS_XATTR_NAME); + compression_type = archive_le32dec( + &a->decmpfs_header_p[DECMPFS_COMPRESSION_TYPE]); + if (compression_type == CMP_RESOURCE_FORK) + fremovexattr(a->fd, XATTR_RESOURCEFORK_NAME, + XATTR_SHOWCOMPRESSION); + return (ARCHIVE_WARN); + } + return (ARCHIVE_OK); +} + +/* + * HFS+ Compression Resource Fork + * + * +-----------------------------+ + * | Header(260 bytes) | + * +-----------------------------+ + * | Block count(LE 4 bytes) | + * +-----------------------------+ --+ + * +-- | Offset (LE 4 bytes) | | + * | | [distance from Block count] | | Block 0 + * | +-----------------------------+ | + * | | Compressed size(LE 4 bytes) | | + * | +-----------------------------+ --+ + * | | | + * | | .................. | + * | | | + * | +-----------------------------+ --+ + * | | Offset (LE 4 bytes) | | + * | +-----------------------------+ | Block (Block count -1) + * | | Compressed size(LE 4 bytes) | | + * +-> +-----------------------------+ --+ + * | Compressed data(n bytes) | Block 0 + * +-----------------------------+ + * | | + * | .................. | + * | | + * +-----------------------------+ + * | Compressed data(n bytes) | Block (Block count -1) + * +-----------------------------+ + * | Footer(50 bytes) | + * +-----------------------------+ + * + */ +/* + * Write the header of "com.apple.ResourceFork" + */ +static int +hfs_write_resource_fork(struct archive_write_disk *a, unsigned char *buff, + size_t bytes, uint32_t position) +{ + int ret; + + ret = fsetxattr(a->fd, XATTR_RESOURCEFORK_NAME, buff, bytes, + position, a->rsrc_xattr_options); + if (ret < 0) { + archive_set_error(&a->archive, errno, + "Cannot restore xattr: %s at %u pos %u bytes", + XATTR_RESOURCEFORK_NAME, + (unsigned)position, + (unsigned)bytes); + return (ARCHIVE_WARN); + } + a->rsrc_xattr_options &= ~XATTR_CREATE; + return (ARCHIVE_OK); +} + +static int +hfs_write_compressed_data(struct archive_write_disk *a, size_t bytes_compressed) +{ + int ret; + + ret = hfs_write_resource_fork(a, a->compressed_buffer, + bytes_compressed, a->compressed_rsrc_position); + if (ret == ARCHIVE_OK) + a->compressed_rsrc_position += bytes_compressed; + return (ret); +} + +static int +hfs_write_resource_fork_header(struct archive_write_disk *a) +{ + unsigned char *buff; + uint32_t rsrc_bytes; + uint32_t rsrc_header_bytes; + + /* + * Write resource fork header + block info. + */ + buff = a->resource_fork; + rsrc_bytes = a->compressed_rsrc_position - RSRC_F_SIZE; + rsrc_header_bytes = + RSRC_H_SIZE + /* Header base size. */ + 4 + /* Block count. */ + (a->decmpfs_block_count * 8);/* Block info */ + archive_be32enc(buff, 0x100); + archive_be32enc(buff + 4, rsrc_bytes); + archive_be32enc(buff + 8, rsrc_bytes - 256); + archive_be32enc(buff + 12, 0x32); + memset(buff + 16, 0, 240); + archive_be32enc(buff + 256, rsrc_bytes - 260); + return hfs_write_resource_fork(a, buff, rsrc_header_bytes, 0); +} + +static size_t +hfs_set_resource_fork_footer(unsigned char *buff, size_t buff_size) +{ + static const char rsrc_footer[RSRC_F_SIZE] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x1c, 0x00, 0x32, 0x00, 0x00, 'c', 'm', + 'p', 'f', 0x00, 0x00, 0x00, 0x0a, 0x00, 0x01, + 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00 + }; + if (buff_size < sizeof(rsrc_footer)) + return (0); + memcpy(buff, rsrc_footer, sizeof(rsrc_footer)); + return (sizeof(rsrc_footer)); +} + +static int +hfs_reset_compressor(struct archive_write_disk *a) +{ + int ret; + + if (a->stream_valid) + ret = deflateReset(&a->stream); + else + ret = deflateInit(&a->stream, a->decmpfs_compression_level); + + if (ret != Z_OK) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Failed to initialize compressor"); + return (ARCHIVE_FATAL); + } else + a->stream_valid = 1; + + return (ARCHIVE_OK); +} + +static int +hfs_decompress(struct archive_write_disk *a) +{ + uint32_t *block_info; + unsigned int block_count; + uint32_t data_pos, data_size; + ssize_t r; + ssize_t bytes_written, bytes_to_write; + unsigned char *b; + + block_info = (uint32_t *)(a->resource_fork + RSRC_H_SIZE); + block_count = archive_le32dec(block_info++); + while (block_count--) { + data_pos = RSRC_H_SIZE + archive_le32dec(block_info++); + data_size = archive_le32dec(block_info++); + r = fgetxattr(a->fd, XATTR_RESOURCEFORK_NAME, + a->compressed_buffer, data_size, data_pos, 0); + if (r != data_size) { + archive_set_error(&a->archive, + (r < 0)?errno:ARCHIVE_ERRNO_MISC, + "Failed to read resource fork"); + return (ARCHIVE_WARN); + } + if (a->compressed_buffer[0] == 0xff) { + bytes_to_write = data_size -1; + b = a->compressed_buffer + 1; + } else { + uLong dest_len = MAX_DECMPFS_BLOCK_SIZE; + int zr; + + zr = uncompress((Bytef *)a->uncompressed_buffer, + &dest_len, a->compressed_buffer, data_size); + if (zr != Z_OK) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Failed to decompress resource fork"); + return (ARCHIVE_WARN); + } + bytes_to_write = dest_len; + b = (unsigned char *)a->uncompressed_buffer; + } + do { + bytes_written = write(a->fd, b, bytes_to_write); + if (bytes_written < 0) { + archive_set_error(&a->archive, errno, + "Write failed"); + return (ARCHIVE_WARN); + } + bytes_to_write -= bytes_written; + b += bytes_written; + } while (bytes_to_write > 0); + } + r = fremovexattr(a->fd, XATTR_RESOURCEFORK_NAME, 0); + if (r == -1) { + archive_set_error(&a->archive, errno, + "Failed to remove resource fork"); + return (ARCHIVE_WARN); + } + return (ARCHIVE_OK); +} + +static int +hfs_drive_compressor(struct archive_write_disk *a, const char *buff, + size_t size) +{ + unsigned char *buffer_compressed; + size_t bytes_compressed; + size_t bytes_used; + int ret; + + ret = hfs_reset_compressor(a); + if (ret != ARCHIVE_OK) + return (ret); + + if (a->compressed_buffer == NULL) { + size_t block_size; + + block_size = COMPRESSED_W_SIZE + RSRC_F_SIZE + + + compressBound(MAX_DECMPFS_BLOCK_SIZE); + a->compressed_buffer = malloc(block_size); + if (a->compressed_buffer == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Resource Fork"); + return (ARCHIVE_FATAL); + } + a->compressed_buffer_size = block_size; + a->compressed_buffer_remaining = block_size; + } + + buffer_compressed = a->compressed_buffer + + a->compressed_buffer_size - a->compressed_buffer_remaining; + a->stream.next_in = (Bytef *)(uintptr_t)(const void *)buff; + a->stream.avail_in = size; + a->stream.next_out = buffer_compressed; + a->stream.avail_out = a->compressed_buffer_remaining; + do { + ret = deflate(&a->stream, Z_FINISH); + switch (ret) { + case Z_OK: + case Z_STREAM_END: + break; + default: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Failed to compress data"); + return (ARCHIVE_FAILED); + } + } while (ret == Z_OK); + bytes_compressed = a->compressed_buffer_remaining - a->stream.avail_out; + + /* + * If the compressed size is larger than the original size, + * throw away compressed data, use uncompressed data instead. + */ + if (bytes_compressed > size) { + buffer_compressed[0] = 0xFF;/* uncompressed marker. */ + memcpy(buffer_compressed + 1, buff, size); + bytes_compressed = size + 1; + } + a->compressed_buffer_remaining -= bytes_compressed; + + /* + * If the compressed size is smaller than MAX_DECMPFS_XATTR_SIZE + * and the block count in the file is only one, store compressed + * data to decmpfs xattr instead of the resource fork. + */ + if (a->decmpfs_block_count == 1 && + (a->decmpfs_attr_size + bytes_compressed) + <= MAX_DECMPFS_XATTR_SIZE) { + archive_le32enc(&a->decmpfs_header_p[DECMPFS_COMPRESSION_TYPE], + CMP_XATTR); + memcpy(a->decmpfs_header_p + DECMPFS_HEADER_SIZE, + buffer_compressed, bytes_compressed); + a->decmpfs_attr_size += bytes_compressed; + a->compressed_buffer_remaining = a->compressed_buffer_size; + /* + * Finish HFS+ Compression. + * - Write the decmpfs xattr. + * - Set the UF_COMPRESSED file flag. + */ + ret = hfs_write_decmpfs(a); + if (ret == ARCHIVE_OK) + ret = hfs_set_compressed_fflag(a); + return (ret); + } + + /* Update block info. */ + archive_le32enc(a->decmpfs_block_info++, + a->compressed_rsrc_position_v - RSRC_H_SIZE); + archive_le32enc(a->decmpfs_block_info++, bytes_compressed); + a->compressed_rsrc_position_v += bytes_compressed; + + /* + * Write the compressed data to the resource fork. + */ + bytes_used = a->compressed_buffer_size - a->compressed_buffer_remaining; + while (bytes_used >= COMPRESSED_W_SIZE) { + ret = hfs_write_compressed_data(a, COMPRESSED_W_SIZE); + if (ret != ARCHIVE_OK) + return (ret); + bytes_used -= COMPRESSED_W_SIZE; + if (bytes_used > COMPRESSED_W_SIZE) + memmove(a->compressed_buffer, + a->compressed_buffer + COMPRESSED_W_SIZE, + bytes_used); + else + memcpy(a->compressed_buffer, + a->compressed_buffer + COMPRESSED_W_SIZE, + bytes_used); + } + a->compressed_buffer_remaining = a->compressed_buffer_size - bytes_used; + + /* + * If the current block is the last block, write the remaining + * compressed data and the resource fork footer. + */ + if (a->file_remaining_bytes == 0) { + size_t rsrc_size; + int64_t bk; + + /* Append the resource footer. */ + rsrc_size = hfs_set_resource_fork_footer( + a->compressed_buffer + bytes_used, + a->compressed_buffer_remaining); + ret = hfs_write_compressed_data(a, bytes_used + rsrc_size); + a->compressed_buffer_remaining = a->compressed_buffer_size; + + /* If the compressed size is not enough smaller than + * the uncompressed size. cancel HFS+ compression. + * TODO: study a behavior of ditto utility and improve + * the condition to fall back into no HFS+ compression. */ + bk = HFS_BLOCKS(a->compressed_rsrc_position); + bk += bk >> 7; + if (bk > HFS_BLOCKS(a->filesize)) + return hfs_decompress(a); + /* + * Write the resourcefork header. + */ + if (ret == ARCHIVE_OK) + ret = hfs_write_resource_fork_header(a); + /* + * Finish HFS+ Compression. + * - Write the decmpfs xattr. + * - Set the UF_COMPRESSED file flag. + */ + if (ret == ARCHIVE_OK) + ret = hfs_write_decmpfs(a); + if (ret == ARCHIVE_OK) + ret = hfs_set_compressed_fflag(a); + } + return (ret); +} + +static ssize_t +hfs_write_decmpfs_block(struct archive_write_disk *a, const char *buff, + size_t size) +{ + const char *buffer_to_write; + size_t bytes_to_write; + int ret; + + if (a->decmpfs_block_count == (unsigned)-1) { + void *new_block; + size_t new_size; + unsigned int block_count; + + if (a->decmpfs_header_p == NULL) { + new_block = malloc(MAX_DECMPFS_XATTR_SIZE + + sizeof(uint32_t)); + if (new_block == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for decmpfs"); + return (ARCHIVE_FATAL); + } + a->decmpfs_header_p = new_block; + } + a->decmpfs_attr_size = DECMPFS_HEADER_SIZE; + archive_le32enc(&a->decmpfs_header_p[DECMPFS_COMPRESSION_MAGIC], + DECMPFS_MAGIC); + archive_le32enc(&a->decmpfs_header_p[DECMPFS_COMPRESSION_TYPE], + CMP_RESOURCE_FORK); + archive_le64enc(&a->decmpfs_header_p[DECMPFS_UNCOMPRESSED_SIZE], + a->filesize); + + /* Calculate a block count of the file. */ + block_count = + (a->filesize + MAX_DECMPFS_BLOCK_SIZE -1) / + MAX_DECMPFS_BLOCK_SIZE; + /* + * Allocate buffer for resource fork. + * Set up related pointers; + */ + new_size = + RSRC_H_SIZE + /* header */ + 4 + /* Block count */ + (block_count * sizeof(uint32_t) * 2) + + RSRC_F_SIZE; /* footer */ + if (new_size > a->resource_fork_allocated_size) { + new_block = realloc(a->resource_fork, new_size); + if (new_block == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for ResourceFork"); + return (ARCHIVE_FATAL); + } + a->resource_fork_allocated_size = new_size; + a->resource_fork = new_block; + } + + /* Allocate uncompressed buffer */ + if (a->uncompressed_buffer == NULL) { + new_block = malloc(MAX_DECMPFS_BLOCK_SIZE); + if (new_block == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for decmpfs"); + return (ARCHIVE_FATAL); + } + a->uncompressed_buffer = new_block; + } + a->block_remaining_bytes = MAX_DECMPFS_BLOCK_SIZE; + a->file_remaining_bytes = a->filesize; + a->compressed_buffer_remaining = a->compressed_buffer_size; + + /* + * Set up a resource fork. + */ + a->rsrc_xattr_options = XATTR_CREATE; + /* Get the position where we are going to set a bunch + * of block info. */ + a->decmpfs_block_info = + (uint32_t *)(a->resource_fork + RSRC_H_SIZE); + /* Set the block count to the resource fork. */ + archive_le32enc(a->decmpfs_block_info++, block_count); + /* Get the position where we are going to set compressed + * data. */ + a->compressed_rsrc_position = + RSRC_H_SIZE + 4 + (block_count * 8); + a->compressed_rsrc_position_v = a->compressed_rsrc_position; + a->decmpfs_block_count = block_count; + } + + /* Ignore redundant bytes. */ + if (a->file_remaining_bytes == 0) + return ((ssize_t)size); + + /* Do not overrun a block size. */ + if (size > a->block_remaining_bytes) + bytes_to_write = a->block_remaining_bytes; + else + bytes_to_write = size; + /* Do not overrun the file size. */ + if (bytes_to_write > a->file_remaining_bytes) + bytes_to_write = a->file_remaining_bytes; + + /* For efficiency, if a copy length is full of the uncompressed + * buffer size, do not copy writing data to it. */ + if (bytes_to_write == MAX_DECMPFS_BLOCK_SIZE) + buffer_to_write = buff; + else { + memcpy(a->uncompressed_buffer + + MAX_DECMPFS_BLOCK_SIZE - a->block_remaining_bytes, + buff, bytes_to_write); + buffer_to_write = a->uncompressed_buffer; + } + a->block_remaining_bytes -= bytes_to_write; + a->file_remaining_bytes -= bytes_to_write; + + if (a->block_remaining_bytes == 0 || a->file_remaining_bytes == 0) { + ret = hfs_drive_compressor(a, buffer_to_write, + MAX_DECMPFS_BLOCK_SIZE - a->block_remaining_bytes); + if (ret < 0) + return (ret); + a->block_remaining_bytes = MAX_DECMPFS_BLOCK_SIZE; + } + /* Ignore redundant bytes. */ + if (a->file_remaining_bytes == 0) + return ((ssize_t)size); + return (bytes_to_write); +} + +static ssize_t +hfs_write_data_block(struct archive_write_disk *a, const char *buff, + size_t size) +{ + uint64_t start_size = size; + ssize_t bytes_written = 0; + ssize_t bytes_to_write; + + if (size == 0) + return (ARCHIVE_OK); + + if (a->filesize == 0 || a->fd < 0) { + archive_set_error(&a->archive, 0, + "Attempt to write to an empty file"); + return (ARCHIVE_WARN); + } + + /* If this write would run beyond the file size, truncate it. */ + if (a->filesize >= 0 && (int64_t)(a->offset + size) > a->filesize) + start_size = size = (size_t)(a->filesize - a->offset); + + /* Write the data. */ + while (size > 0) { + bytes_to_write = size; + /* Seek if necessary to the specified offset. */ + if (a->offset < a->fd_offset) { + /* Can't support backward move. */ + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Seek failed"); + return (ARCHIVE_FATAL); + } else if (a->offset > a->fd_offset) { + int64_t skip = a->offset - a->fd_offset; + char nullblock[1024]; + + memset(nullblock, 0, sizeof(nullblock)); + while (skip > 0) { + if (skip > (int64_t)sizeof(nullblock)) + bytes_written = hfs_write_decmpfs_block( + a, nullblock, sizeof(nullblock)); + else + bytes_written = hfs_write_decmpfs_block( + a, nullblock, skip); + if (bytes_written < 0) { + archive_set_error(&a->archive, errno, + "Write failed"); + return (ARCHIVE_WARN); + } + skip -= bytes_written; + } + + a->fd_offset = a->offset; + } + bytes_written = + hfs_write_decmpfs_block(a, buff, bytes_to_write); + if (bytes_written < 0) + return (bytes_written); + buff += bytes_written; + size -= bytes_written; + a->total_bytes_written += bytes_written; + a->offset += bytes_written; + a->fd_offset = a->offset; + } + return (start_size - size); +} +#else +static ssize_t +hfs_write_data_block(struct archive_write_disk *a, const char *buff, + size_t size) +{ + return (write_data_block(a, buff, size)); +} +#endif + +static ssize_t +_archive_write_disk_data_block(struct archive *_a, + const void *buff, size_t size, int64_t offset) +{ + struct archive_write_disk *a = (struct archive_write_disk *)_a; + ssize_t r; + + archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, + ARCHIVE_STATE_DATA, "archive_write_data_block"); + + a->offset = offset; + if (a->todo & TODO_HFS_COMPRESSION) + r = hfs_write_data_block(a, buff, size); + else + r = write_data_block(a, buff, size); + if (r < ARCHIVE_OK) + return (r); + if ((size_t)r < size) { + archive_set_error(&a->archive, 0, + "Too much data: Truncating file at %ju bytes", + (uintmax_t)a->filesize); + return (ARCHIVE_WARN); + } +#if ARCHIVE_VERSION_NUMBER < 3999000 + return (ARCHIVE_OK); +#else + return (size); +#endif +} + +static ssize_t +_archive_write_disk_data(struct archive *_a, const void *buff, size_t size) +{ + struct archive_write_disk *a = (struct archive_write_disk *)_a; + + archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, + ARCHIVE_STATE_DATA, "archive_write_data"); + + if (a->todo & TODO_HFS_COMPRESSION) + return (hfs_write_data_block(a, buff, size)); + return (write_data_block(a, buff, size)); +} + +static int +_archive_write_disk_finish_entry(struct archive *_a) +{ + struct archive_write_disk *a = (struct archive_write_disk *)_a; + int ret = ARCHIVE_OK; + + archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, + ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA, + "archive_write_finish_entry"); + if (a->archive.state & ARCHIVE_STATE_HEADER) + return (ARCHIVE_OK); + archive_clear_error(&a->archive); + + /* Pad or truncate file to the right size. */ + if (a->fd < 0) { + /* There's no file. */ + } else if (a->filesize < 0) { + /* File size is unknown, so we can't set the size. */ + } else if (a->fd_offset == a->filesize) { + /* Last write ended at exactly the filesize; we're done. */ + /* Hopefully, this is the common case. */ +#if defined(__APPLE__) && defined(UF_COMPRESSED) && defined(HAVE_ZLIB_H) + } else if (a->todo & TODO_HFS_COMPRESSION) { + char null_d[1024]; + ssize_t r; + + if (a->file_remaining_bytes) + memset(null_d, 0, sizeof(null_d)); + while (a->file_remaining_bytes) { + if (a->file_remaining_bytes > sizeof(null_d)) + r = hfs_write_data_block( + a, null_d, sizeof(null_d)); + else + r = hfs_write_data_block( + a, null_d, a->file_remaining_bytes); + if (r < 0) + return ((int)r); + } +#endif + } else { +#if HAVE_FTRUNCATE + if (ftruncate(a->fd, a->filesize) == -1 && + a->filesize == 0) { + archive_set_error(&a->archive, errno, + "File size could not be restored"); + return (ARCHIVE_FAILED); + } +#endif + /* + * Not all platforms implement the XSI option to + * extend files via ftruncate. Stat() the file again + * to see what happened. + */ + a->pst = NULL; + if ((ret = lazy_stat(a)) != ARCHIVE_OK) + return (ret); + /* We can use lseek()/write() to extend the file if + * ftruncate didn't work or isn't available. */ + if (a->st.st_size < a->filesize) { + const char nul = '\0'; + if (lseek(a->fd, a->filesize - 1, SEEK_SET) < 0) { + archive_set_error(&a->archive, errno, + "Seek failed"); + return (ARCHIVE_FATAL); + } + if (write(a->fd, &nul, 1) < 0) { + archive_set_error(&a->archive, errno, + "Write to restore size failed"); + return (ARCHIVE_FATAL); + } + a->pst = NULL; + } + } + + /* Restore metadata. */ + + /* + * This is specific to Mac OS X. + * If the current file is an AppleDouble file, it should be + * linked with the data fork file and remove it. + */ + if (a->todo & TODO_APPLEDOUBLE) { + int r2 = fixup_appledouble(a, a->name); + if (r2 == ARCHIVE_EOF) { + /* The current file has been successfully linked + * with the data fork file and removed. So there + * is nothing to do on the current file. */ + goto finish_metadata; + } + if (r2 < ret) ret = r2; + } + + /* + * Look up the "real" UID only if we're going to need it. + * TODO: the TODO_SGID condition can be dropped here, can't it? + */ + if (a->todo & (TODO_OWNER | TODO_SUID | TODO_SGID)) { + a->uid = archive_write_disk_uid(&a->archive, + archive_entry_uname(a->entry), + archive_entry_uid(a->entry)); + } + /* Look up the "real" GID only if we're going to need it. */ + /* TODO: the TODO_SUID condition can be dropped here, can't it? */ + if (a->todo & (TODO_OWNER | TODO_SGID | TODO_SUID)) { + a->gid = archive_write_disk_gid(&a->archive, + archive_entry_gname(a->entry), + archive_entry_gid(a->entry)); + } + + /* + * Restore ownership before set_mode tries to restore suid/sgid + * bits. If we set the owner, we know what it is and can skip + * a stat() call to examine the ownership of the file on disk. + */ + if (a->todo & TODO_OWNER) { + int r2 = set_ownership(a); + if (r2 < ret) ret = r2; + } + + /* + * set_mode must precede ACLs on systems such as Solaris and + * FreeBSD where setting the mode implicitly clears extended ACLs + */ + if (a->todo & TODO_MODE) { + int r2 = set_mode(a, a->mode); + if (r2 < ret) ret = r2; + } + + /* + * Security-related extended attributes (such as + * security.capability on Linux) have to be restored last, + * since they're implicitly removed by other file changes. + */ + if (a->todo & TODO_XATTR) { + int r2 = set_xattrs(a); + if (r2 < ret) ret = r2; + } + + /* + * Some flags prevent file modification; they must be restored after + * file contents are written. + */ + if (a->todo & TODO_FFLAGS) { + int r2 = set_fflags(a); + if (r2 < ret) ret = r2; + } + + /* + * Time must follow most other metadata; + * otherwise atime will get changed. + */ + if (a->todo & TODO_TIMES) { + int r2 = set_times_from_entry(a); + if (r2 < ret) ret = r2; + } + + /* + * Mac extended metadata includes ACLs. + */ + if (a->todo & TODO_MAC_METADATA) { + const void *metadata; + size_t metadata_size; + metadata = archive_entry_mac_metadata(a->entry, &metadata_size); + if (metadata != NULL && metadata_size > 0) { + int r2 = set_mac_metadata(a, archive_entry_pathname( + a->entry), metadata, metadata_size); + if (r2 < ret) ret = r2; + } + } + + /* + * ACLs must be restored after timestamps because there are + * ACLs that prevent attribute changes (including time). + */ + if (a->todo & TODO_ACLS) { + int r2; + r2 = archive_write_disk_set_acls(&a->archive, a->fd, + archive_entry_pathname(a->entry), + archive_entry_acl(a->entry), + archive_entry_mode(a->entry)); + if (r2 < ret) ret = r2; + } + +finish_metadata: + /* If there's an fd, we can close it now. */ + if (a->fd >= 0) { + close(a->fd); + a->fd = -1; + } + /* If there's an entry, we can release it now. */ + if (a->entry) { + archive_entry_free(a->entry); + a->entry = NULL; + } + a->archive.state = ARCHIVE_STATE_HEADER; + return (ret); +} + +int +archive_write_disk_set_group_lookup(struct archive *_a, + void *private_data, - int64_t (*lookup_gid)(void *private, const char *gname, int64_t gid), ++ la_int64_t (*lookup_gid)(void *private, const char *gname, la_int64_t gid), + void (*cleanup_gid)(void *private)) +{ + struct archive_write_disk *a = (struct archive_write_disk *)_a; + archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, + ARCHIVE_STATE_ANY, "archive_write_disk_set_group_lookup"); + + if (a->cleanup_gid != NULL && a->lookup_gid_data != NULL) + (a->cleanup_gid)(a->lookup_gid_data); + + a->lookup_gid = lookup_gid; + a->cleanup_gid = cleanup_gid; + a->lookup_gid_data = private_data; + return (ARCHIVE_OK); +} + +int +archive_write_disk_set_user_lookup(struct archive *_a, + void *private_data, + int64_t (*lookup_uid)(void *private, const char *uname, int64_t uid), + void (*cleanup_uid)(void *private)) +{ + struct archive_write_disk *a = (struct archive_write_disk *)_a; + archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, + ARCHIVE_STATE_ANY, "archive_write_disk_set_user_lookup"); + + if (a->cleanup_uid != NULL && a->lookup_uid_data != NULL) + (a->cleanup_uid)(a->lookup_uid_data); + + a->lookup_uid = lookup_uid; + a->cleanup_uid = cleanup_uid; + a->lookup_uid_data = private_data; + return (ARCHIVE_OK); +} + +int64_t - archive_write_disk_gid(struct archive *_a, const char *name, int64_t id) ++archive_write_disk_gid(struct archive *_a, const char *name, la_int64_t id) +{ + struct archive_write_disk *a = (struct archive_write_disk *)_a; + archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, + ARCHIVE_STATE_ANY, "archive_write_disk_gid"); + if (a->lookup_gid) + return (a->lookup_gid)(a->lookup_gid_data, name, id); + return (id); +} + +int64_t - archive_write_disk_uid(struct archive *_a, const char *name, int64_t id) ++archive_write_disk_uid(struct archive *_a, const char *name, la_int64_t id) +{ + struct archive_write_disk *a = (struct archive_write_disk *)_a; + archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, + ARCHIVE_STATE_ANY, "archive_write_disk_uid"); + if (a->lookup_uid) + return (a->lookup_uid)(a->lookup_uid_data, name, id); + return (id); +} + +/* + * Create a new archive_write_disk object and initialize it with global state. + */ +struct archive * +archive_write_disk_new(void) +{ + struct archive_write_disk *a; + + a = (struct archive_write_disk *)calloc(1, sizeof(*a)); + if (a == NULL) + return (NULL); + a->archive.magic = ARCHIVE_WRITE_DISK_MAGIC; + /* We're ready to write a header immediately. */ + a->archive.state = ARCHIVE_STATE_HEADER; + a->archive.vtable = archive_write_disk_vtable(); + a->start_time = time(NULL); + /* Query and restore the umask. */ + umask(a->user_umask = umask(0)); +#ifdef HAVE_GETEUID + a->user_uid = geteuid(); +#endif /* HAVE_GETEUID */ + if (archive_string_ensure(&a->path_safe, 512) == NULL) { + free(a); + return (NULL); + } +#ifdef HAVE_ZLIB_H + a->decmpfs_compression_level = 5; +#endif + return (&a->archive); +} + + +/* + * If pathname is longer than PATH_MAX, chdir to a suitable + * intermediate dir and edit the path down to a shorter suffix. Note + * that this routine never returns an error; if the chdir() attempt + * fails for any reason, we just go ahead with the long pathname. The + * object creation is likely to fail, but any error will get handled + * at that time. + */ +#if defined(HAVE_FCHDIR) && defined(PATH_MAX) +static void +edit_deep_directories(struct archive_write_disk *a) +{ + int ret; + char *tail = a->name; + + /* If path is short, avoid the open() below. */ + if (strlen(tail) < PATH_MAX) + return; + + /* Try to record our starting dir. */ + a->restore_pwd = open(".", O_RDONLY | O_BINARY | O_CLOEXEC); + __archive_ensure_cloexec_flag(a->restore_pwd); + if (a->restore_pwd < 0) + return; + + /* As long as the path is too long... */ + while (strlen(tail) >= PATH_MAX) { + /* Locate a dir prefix shorter than PATH_MAX. */ + tail += PATH_MAX - 8; + while (tail > a->name && *tail != '/') + tail--; + /* Exit if we find a too-long path component. */ + if (tail <= a->name) + return; + /* Create the intermediate dir and chdir to it. */ + *tail = '\0'; /* Terminate dir portion */ + ret = create_dir(a, a->name); + if (ret == ARCHIVE_OK && chdir(a->name) != 0) + ret = ARCHIVE_FAILED; + *tail = '/'; /* Restore the / we removed. */ + if (ret != ARCHIVE_OK) + return; + tail++; + /* The chdir() succeeded; we've now shortened the path. */ + a->name = tail; + } + return; +} +#endif + +/* + * The main restore function. + */ +static int +restore_entry(struct archive_write_disk *a) +{ + int ret = ARCHIVE_OK, en; + + if (a->flags & ARCHIVE_EXTRACT_UNLINK && !S_ISDIR(a->mode)) { + /* + * TODO: Fix this. Apparently, there are platforms + * that still allow root to hose the entire filesystem + * by unlinking a dir. The S_ISDIR() test above + * prevents us from using unlink() here if the new + * object is a dir, but that doesn't mean the old + * object isn't a dir. + */ + if (a->flags & ARCHIVE_EXTRACT_CLEAR_NOCHANGE_FFLAGS) + (void)clear_nochange_fflags(a); + if (unlink(a->name) == 0) { + /* We removed it, reset cached stat. */ + a->pst = NULL; + } else if (errno == ENOENT) { + /* File didn't exist, that's just as good. */ + } else if (rmdir(a->name) == 0) { + /* It was a dir, but now it's gone. */ + a->pst = NULL; + } else { + /* We tried, but couldn't get rid of it. */ + archive_set_error(&a->archive, errno, + "Could not unlink"); + return(ARCHIVE_FAILED); + } + } + + /* Try creating it first; if this fails, we'll try to recover. */ + en = create_filesystem_object(a); + + if ((en == ENOTDIR || en == ENOENT) + && !(a->flags & ARCHIVE_EXTRACT_NO_AUTODIR)) { + /* If the parent dir doesn't exist, try creating it. */ + create_parent_dir(a, a->name); + /* Now try to create the object again. */ + en = create_filesystem_object(a); + } + + if ((en == ENOENT) && (archive_entry_hardlink(a->entry) != NULL)) { + archive_set_error(&a->archive, en, + "Hard-link target '%s' does not exist.", + archive_entry_hardlink(a->entry)); + return (ARCHIVE_FAILED); + } + + if ((en == EISDIR || en == EEXIST) + && (a->flags & ARCHIVE_EXTRACT_NO_OVERWRITE)) { + /* If we're not overwriting, we're done. */ ++ if (S_ISDIR(a->mode)) { ++ /* Don't overwrite any settings on existing directories. */ ++ a->todo = 0; ++ } + archive_entry_unset_size(a->entry); + return (ARCHIVE_OK); + } + + /* + * Some platforms return EISDIR if you call + * open(O_WRONLY | O_EXCL | O_CREAT) on a directory, some + * return EEXIST. POSIX is ambiguous, requiring EISDIR + * for open(O_WRONLY) on a dir and EEXIST for open(O_EXCL | O_CREAT) + * on an existing item. + */ + if (en == EISDIR) { + /* A dir is in the way of a non-dir, rmdir it. */ + if (rmdir(a->name) != 0) { + archive_set_error(&a->archive, errno, + "Can't remove already-existing dir"); + return (ARCHIVE_FAILED); + } + a->pst = NULL; + /* Try again. */ + en = create_filesystem_object(a); + } else if (en == EEXIST) { + /* + * We know something is in the way, but we don't know what; + * we need to find out before we go any further. + */ + int r = 0; + /* + * The SECURE_SYMLINKS logic has already removed a + * symlink to a dir if the client wants that. So + * follow the symlink if we're creating a dir. + */ + if (S_ISDIR(a->mode)) + r = stat(a->name, &a->st); + /* + * If it's not a dir (or it's a broken symlink), + * then don't follow it. + */ + if (r != 0 || !S_ISDIR(a->mode)) + r = lstat(a->name, &a->st); + if (r != 0) { + archive_set_error(&a->archive, errno, + "Can't stat existing object"); + return (ARCHIVE_FAILED); + } + + /* + * NO_OVERWRITE_NEWER doesn't apply to directories. + */ + if ((a->flags & ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER) + && !S_ISDIR(a->st.st_mode)) { + if (!older(&(a->st), a->entry)) { + archive_entry_unset_size(a->entry); + return (ARCHIVE_OK); + } + } + + /* If it's our archive, we're done. */ + if (a->skip_file_set && + a->st.st_dev == (dev_t)a->skip_file_dev && + a->st.st_ino == (ino_t)a->skip_file_ino) { + archive_set_error(&a->archive, 0, + "Refusing to overwrite archive"); + return (ARCHIVE_FAILED); + } + + if (!S_ISDIR(a->st.st_mode)) { + /* A non-dir is in the way, unlink it. */ + if (a->flags & ARCHIVE_EXTRACT_CLEAR_NOCHANGE_FFLAGS) + (void)clear_nochange_fflags(a); + if (unlink(a->name) != 0) { + archive_set_error(&a->archive, errno, + "Can't unlink already-existing object"); + return (ARCHIVE_FAILED); + } + a->pst = NULL; + /* Try again. */ + en = create_filesystem_object(a); + } else if (!S_ISDIR(a->mode)) { + /* A dir is in the way of a non-dir, rmdir it. */ + if (a->flags & ARCHIVE_EXTRACT_CLEAR_NOCHANGE_FFLAGS) + (void)clear_nochange_fflags(a); + if (rmdir(a->name) != 0) { + archive_set_error(&a->archive, errno, + "Can't replace existing directory with non-directory"); + return (ARCHIVE_FAILED); + } + /* Try again. */ + en = create_filesystem_object(a); + } else { + /* + * There's a dir in the way of a dir. Don't + * waste time with rmdir()/mkdir(), just fix + * up the permissions on the existing dir. + * Note that we don't change perms on existing + * dirs unless _EXTRACT_PERM is specified. + */ + if ((a->mode != a->st.st_mode) + && (a->todo & TODO_MODE_FORCE)) + a->deferred |= (a->todo & TODO_MODE); + /* Ownership doesn't need deferred fixup. */ + en = 0; /* Forget the EEXIST. */ + } + } + + if (en) { + /* Everything failed; give up here. */ + if ((&a->archive)->error == NULL) + archive_set_error(&a->archive, en, "Can't create '%s'", + a->name); + return (ARCHIVE_FAILED); + } + + a->pst = NULL; /* Cached stat data no longer valid. */ + return (ret); +} + +/* + * Returns 0 if creation succeeds, or else returns errno value from + * the failed system call. Note: This function should only ever perform + * a single system call. + */ +static int +create_filesystem_object(struct archive_write_disk *a) +{ + /* Create the entry. */ + const char *linkname; + mode_t final_mode, mode; + int r; + /* these for check_symlinks_fsobj */ + char *linkname_copy; /* non-const copy of linkname */ + struct stat st; + struct archive_string error_string; + int error_number; + + /* We identify hard/symlinks according to the link names. */ + /* Since link(2) and symlink(2) don't handle modes, we're done here. */ + linkname = archive_entry_hardlink(a->entry); + if (linkname != NULL) { +#if !HAVE_LINK + return (EPERM); +#else + archive_string_init(&error_string); + linkname_copy = strdup(linkname); + if (linkname_copy == NULL) { + return (EPERM); + } + /* + * TODO: consider using the cleaned-up path as the link + * target? + */ + r = cleanup_pathname_fsobj(linkname_copy, &error_number, + &error_string, a->flags); + if (r != ARCHIVE_OK) { + archive_set_error(&a->archive, error_number, "%s", + error_string.s); + free(linkname_copy); + archive_string_free(&error_string); + /* + * EPERM is more appropriate than error_number for our + * callers + */ + return (EPERM); + } + r = check_symlinks_fsobj(linkname_copy, &error_number, + &error_string, a->flags); + if (r != ARCHIVE_OK) { + archive_set_error(&a->archive, error_number, "%s", + error_string.s); + free(linkname_copy); + archive_string_free(&error_string); + /* + * EPERM is more appropriate than error_number for our + * callers + */ + return (EPERM); + } + free(linkname_copy); + archive_string_free(&error_string); + r = link(linkname, a->name) ? errno : 0; + /* + * New cpio and pax formats allow hardlink entries + * to carry data, so we may have to open the file + * for hardlink entries. + * + * If the hardlink was successfully created and + * the archive doesn't have carry data for it, + * consider it to be non-authoritative for meta data. + * This is consistent with GNU tar and BSD pax. + * If the hardlink does carry data, let the last + * archive entry decide ownership. + */ + if (r == 0 && a->filesize <= 0) { + a->todo = 0; + a->deferred = 0; + } else if (r == 0 && a->filesize > 0) { +#ifdef HAVE_LSTAT + r = lstat(a->name, &st); +#else + r = stat(a->name, &st); +#endif + if (r != 0) + r = errno; + else if ((st.st_mode & AE_IFMT) == AE_IFREG) { + a->fd = open(a->name, O_WRONLY | O_TRUNC | + O_BINARY | O_CLOEXEC | O_NOFOLLOW); + __archive_ensure_cloexec_flag(a->fd); + if (a->fd < 0) + r = errno; + } + } + return (r); +#endif + } + linkname = archive_entry_symlink(a->entry); + if (linkname != NULL) { +#if HAVE_SYMLINK + return symlink(linkname, a->name) ? errno : 0; +#else + return (EPERM); +#endif + } + + /* + * The remaining system calls all set permissions, so let's + * try to take advantage of that to avoid an extra chmod() + * call. (Recall that umask is set to zero right now!) + */ + + /* Mode we want for the final restored object (w/o file type bits). */ + final_mode = a->mode & 07777; + /* + * The mode that will actually be restored in this step. Note + * that SUID, SGID, etc, require additional work to ensure + * security, so we never restore them at this point. + */ + mode = final_mode & 0777 & ~a->user_umask; + + switch (a->mode & AE_IFMT) { + default: + /* POSIX requires that we fall through here. */ + /* FALLTHROUGH */ + case AE_IFREG: + a->fd = open(a->name, + O_WRONLY | O_CREAT | O_EXCL | O_BINARY | O_CLOEXEC, mode); + __archive_ensure_cloexec_flag(a->fd); + r = (a->fd < 0); + break; + case AE_IFCHR: +#ifdef HAVE_MKNOD + /* Note: we use AE_IFCHR for the case label, and + * S_IFCHR for the mknod() call. This is correct. */ + r = mknod(a->name, mode | S_IFCHR, + archive_entry_rdev(a->entry)); + break; +#else + /* TODO: Find a better way to warn about our inability + * to restore a char device node. */ + return (EINVAL); +#endif /* HAVE_MKNOD */ + case AE_IFBLK: +#ifdef HAVE_MKNOD + r = mknod(a->name, mode | S_IFBLK, + archive_entry_rdev(a->entry)); + break; +#else + /* TODO: Find a better way to warn about our inability + * to restore a block device node. */ + return (EINVAL); +#endif /* HAVE_MKNOD */ + case AE_IFDIR: + mode = (mode | MINIMUM_DIR_MODE) & MAXIMUM_DIR_MODE; + r = mkdir(a->name, mode); + if (r == 0) { + /* Defer setting dir times. */ + a->deferred |= (a->todo & TODO_TIMES); + a->todo &= ~TODO_TIMES; + /* Never use an immediate chmod(). */ + /* We can't avoid the chmod() entirely if EXTRACT_PERM + * because of SysV SGID inheritance. */ + if ((mode != final_mode) + || (a->flags & ARCHIVE_EXTRACT_PERM)) + a->deferred |= (a->todo & TODO_MODE); + a->todo &= ~TODO_MODE; + } + break; + case AE_IFIFO: +#ifdef HAVE_MKFIFO + r = mkfifo(a->name, mode); + break; +#else + /* TODO: Find a better way to warn about our inability + * to restore a fifo. */ + return (EINVAL); +#endif /* HAVE_MKFIFO */ + } + + /* All the system calls above set errno on failure. */ + if (r) + return (errno); + + /* If we managed to set the final mode, we've avoided a chmod(). */ + if (mode == final_mode) + a->todo &= ~TODO_MODE; + return (0); +} + +/* + * Cleanup function for archive_extract. Mostly, this involves processing + * the fixup list, which is used to address a number of problems: + * * Dir permissions might prevent us from restoring a file in that + * dir, so we restore the dir with minimum 0700 permissions first, + * then correct the mode at the end. + * * Similarly, the act of restoring a file touches the directory + * and changes the timestamp on the dir, so we have to touch-up dir + * timestamps at the end as well. + * * Some file flags can interfere with the restore by, for example, + * preventing the creation of hardlinks to those files. + * * Mac OS extended metadata includes ACLs, so must be deferred on dirs. + * + * Note that tar/cpio do not require that archives be in a particular + * order; there is no way to know when the last file has been restored + * within a directory, so there's no way to optimize the memory usage + * here by fixing up the directory any earlier than the + * end-of-archive. + * + * XXX TODO: Directory ACLs should be restored here, for the same + * reason we set directory perms here. XXX + */ +static int +_archive_write_disk_close(struct archive *_a) +{ + struct archive_write_disk *a = (struct archive_write_disk *)_a; + struct fixup_entry *next, *p; + int ret; + + archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, + ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA, + "archive_write_disk_close"); + ret = _archive_write_disk_finish_entry(&a->archive); + + /* Sort dir list so directories are fixed up in depth-first order. */ + p = sort_dir_list(a->fixup_list); + + while (p != NULL) { + a->pst = NULL; /* Mark stat cache as out-of-date. */ + if (p->fixup & TODO_TIMES) { + set_times(a, -1, p->mode, p->name, + p->atime, p->atime_nanos, + p->birthtime, p->birthtime_nanos, + p->mtime, p->mtime_nanos, + p->ctime, p->ctime_nanos); + } + if (p->fixup & TODO_MODE_BASE) + chmod(p->name, p->mode); + if (p->fixup & TODO_ACLS) + archive_write_disk_set_acls(&a->archive, -1, p->name, + &p->acl, p->mode); + if (p->fixup & TODO_FFLAGS) + set_fflags_platform(a, -1, p->name, + p->mode, p->fflags_set, 0); + if (p->fixup & TODO_MAC_METADATA) + set_mac_metadata(a, p->name, p->mac_metadata, + p->mac_metadata_size); + next = p->next; + archive_acl_clear(&p->acl); + free(p->mac_metadata); + free(p->name); + free(p); + p = next; + } + a->fixup_list = NULL; + return (ret); +} + +static int +_archive_write_disk_free(struct archive *_a) +{ + struct archive_write_disk *a; + int ret; + if (_a == NULL) + return (ARCHIVE_OK); + archive_check_magic(_a, ARCHIVE_WRITE_DISK_MAGIC, + ARCHIVE_STATE_ANY | ARCHIVE_STATE_FATAL, "archive_write_disk_free"); + a = (struct archive_write_disk *)_a; + ret = _archive_write_disk_close(&a->archive); + archive_write_disk_set_group_lookup(&a->archive, NULL, NULL, NULL); + archive_write_disk_set_user_lookup(&a->archive, NULL, NULL, NULL); + if (a->entry) + archive_entry_free(a->entry); + archive_string_free(&a->_name_data); + archive_string_free(&a->archive.error_string); + archive_string_free(&a->path_safe); + a->archive.magic = 0; + __archive_clean(&a->archive); + free(a->decmpfs_header_p); + free(a->resource_fork); + free(a->compressed_buffer); + free(a->uncompressed_buffer); +#if defined(__APPLE__) && defined(UF_COMPRESSED) && defined(HAVE_SYS_XATTR_H)\ + && defined(HAVE_ZLIB_H) + if (a->stream_valid) { + switch (deflateEnd(&a->stream)) { + case Z_OK: + break; + default: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Failed to clean up compressor"); + ret = ARCHIVE_FATAL; + break; + } + } +#endif + free(a); + return (ret); +} + +/* + * Simple O(n log n) merge sort to order the fixup list. In + * particular, we want to restore dir timestamps depth-first. + */ +static struct fixup_entry * +sort_dir_list(struct fixup_entry *p) +{ + struct fixup_entry *a, *b, *t; + + if (p == NULL) + return (NULL); + /* A one-item list is already sorted. */ + if (p->next == NULL) + return (p); + + /* Step 1: split the list. */ + t = p; + a = p->next->next; + while (a != NULL) { + /* Step a twice, t once. */ + a = a->next; + if (a != NULL) + a = a->next; + t = t->next; + } + /* Now, t is at the mid-point, so break the list here. */ + b = t->next; + t->next = NULL; + a = p; + + /* Step 2: Recursively sort the two sub-lists. */ + a = sort_dir_list(a); + b = sort_dir_list(b); + + /* Step 3: Merge the returned lists. */ + /* Pick the first element for the merged list. */ + if (strcmp(a->name, b->name) > 0) { + t = p = a; + a = a->next; + } else { + t = p = b; + b = b->next; + } + + /* Always put the later element on the list first. */ + while (a != NULL && b != NULL) { + if (strcmp(a->name, b->name) > 0) { + t->next = a; + a = a->next; + } else { + t->next = b; + b = b->next; + } + t = t->next; + } + + /* Only one list is non-empty, so just splice it on. */ + if (a != NULL) + t->next = a; + if (b != NULL) + t->next = b; + + return (p); +} + +/* + * Returns a new, initialized fixup entry. + * + * TODO: Reduce the memory requirements for this list by using a tree + * structure rather than a simple list of names. + */ +static struct fixup_entry * +new_fixup(struct archive_write_disk *a, const char *pathname) +{ + struct fixup_entry *fe; + + fe = (struct fixup_entry *)calloc(1, sizeof(struct fixup_entry)); + if (fe == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for a fixup"); + return (NULL); + } + fe->next = a->fixup_list; + a->fixup_list = fe; + fe->fixup = 0; + fe->name = strdup(pathname); + return (fe); +} + +/* + * Returns a fixup structure for the current entry. + */ +static struct fixup_entry * +current_fixup(struct archive_write_disk *a, const char *pathname) +{ + if (a->current_fixup == NULL) + a->current_fixup = new_fixup(a, pathname); + return (a->current_fixup); +} + +/* Error helper for new *_fsobj functions */ +static void +fsobj_error(int *a_eno, struct archive_string *a_estr, + int err, const char *errstr, const char *path) +{ + if (a_eno) + *a_eno = err; + if (a_estr) + archive_string_sprintf(a_estr, "%s%s", errstr, path); +} + +/* + * TODO: Someday, integrate this with the deep dir support; they both + * scan the path and both can be optimized by comparing against other + * recent paths. + */ +/* TODO: Extend this to support symlinks on Windows Vista and later. */ + +/* + * Checks the given path to see if any elements along it are symlinks. Returns + * ARCHIVE_OK if there are none, otherwise puts an error in errmsg. + */ +static int +check_symlinks_fsobj(char *path, int *a_eno, struct archive_string *a_estr, + int flags) +{ +#if !defined(HAVE_LSTAT) + /* Platform doesn't have lstat, so we can't look for symlinks. */ + (void)path; /* UNUSED */ + (void)error_number; /* UNUSED */ + (void)error_string; /* UNUSED */ + (void)flags; /* UNUSED */ + return (ARCHIVE_OK); +#else + int res = ARCHIVE_OK; + char *tail; + char *head; + int last; + char c; + int r; + struct stat st; + int restore_pwd; + + /* Nothing to do here if name is empty */ + if(path[0] == '\0') + return (ARCHIVE_OK); + + /* + * Guard against symlink tricks. Reject any archive entry whose + * destination would be altered by a symlink. + * + * Walk the filename in chunks separated by '/'. For each segment: + * - if it doesn't exist, continue + * - if it's symlink, abort or remove it + * - if it's a directory and it's not the last chunk, cd into it + * As we go: + * head points to the current (relative) path + * tail points to the temporary \0 terminating the segment we're + * currently examining + * c holds what used to be in *tail + * last is 1 if this is the last tail + */ + restore_pwd = open(".", O_RDONLY | O_BINARY | O_CLOEXEC); + __archive_ensure_cloexec_flag(restore_pwd); + if (restore_pwd < 0) + return (ARCHIVE_FATAL); + head = path; + tail = path; + last = 0; + /* TODO: reintroduce a safe cache here? */ + /* Skip the root directory if the path is absolute. */ + if(tail == path && tail[0] == '/') + ++tail; + /* Keep going until we've checked the entire name. + * head, tail, path all alias the same string, which is + * temporarily zeroed at tail, so be careful restoring the + * stashed (c=tail[0]) for error messages. + * Exiting the loop with break is okay; continue is not. + */ + while (!last) { + /* + * Skip the separator we just consumed, plus any adjacent ones + */ + while (*tail == '/') + ++tail; + /* Skip the next path element. */ + while (*tail != '\0' && *tail != '/') + ++tail; + /* is this the last path component? */ + last = (tail[0] == '\0') || (tail[0] == '/' && tail[1] == '\0'); + /* temporarily truncate the string here */ + c = tail[0]; + tail[0] = '\0'; + /* Check that we haven't hit a symlink. */ + r = lstat(head, &st); + if (r != 0) { + tail[0] = c; + /* We've hit a dir that doesn't exist; stop now. */ + if (errno == ENOENT) { + break; + } else { + /* + * Treat any other error as fatal - best to be + * paranoid here. + * Note: This effectively disables deep + * directory support when security checks are + * enabled. Otherwise, very long pathnames that + * trigger an error here could evade the + * sandbox. + * TODO: We could do better, but it would + * probably require merging the symlink checks + * with the deep-directory editing. + */ + fsobj_error(a_eno, a_estr, errno, + "Could not stat ", path); + res = ARCHIVE_FAILED; + break; + } + } else if (S_ISDIR(st.st_mode)) { + if (!last) { + if (chdir(head) != 0) { + tail[0] = c; + fsobj_error(a_eno, a_estr, errno, + "Could not chdir ", path); + res = (ARCHIVE_FATAL); + break; + } + /* Our view is now from inside this dir: */ + head = tail + 1; + } + } else if (S_ISLNK(st.st_mode)) { + if (last) { + /* + * Last element is symlink; remove it + * so we can overwrite it with the + * item being extracted. + */ + if (unlink(head)) { + tail[0] = c; + fsobj_error(a_eno, a_estr, errno, + "Could not remove symlink ", + path); + res = ARCHIVE_FAILED; + break; + } + /* + * Even if we did remove it, a warning + * is in order. The warning is silly, + * though, if we're just replacing one + * symlink with another symlink. + */ + tail[0] = c; + /* + * FIXME: not sure how important this is to + * restore + */ + /* + if (!S_ISLNK(path)) { + fsobj_error(a_eno, a_estr, 0, + "Removing symlink ", path); + } + */ + /* Symlink gone. No more problem! */ + res = ARCHIVE_OK; + break; + } else if (flags & ARCHIVE_EXTRACT_UNLINK) { + /* User asked us to remove problems. */ + if (unlink(head) != 0) { + tail[0] = c; + fsobj_error(a_eno, a_estr, 0, + "Cannot remove intervening " + "symlink ", path); + res = ARCHIVE_FAILED; + break; + } + tail[0] = c; + } else if ((flags & + ARCHIVE_EXTRACT_SECURE_SYMLINKS) == 0) { + /* + * We are not the last element and we want to + * follow symlinks if they are a directory. + * + * This is needed to extract hardlinks over + * symlinks. + */ + r = stat(head, &st); + if (r != 0) { + tail[0] = c; + if (errno == ENOENT) { + break; + } else { + fsobj_error(a_eno, a_estr, + errno, + "Could not stat ", path); + res = (ARCHIVE_FAILED); + break; + } + } else if (S_ISDIR(st.st_mode)) { + if (chdir(head) != 0) { + tail[0] = c; + fsobj_error(a_eno, a_estr, + errno, + "Could not chdir ", path); + res = (ARCHIVE_FATAL); + break; + } + /* + * Our view is now from inside + * this dir: + */ + head = tail + 1; + } else { + tail[0] = c; + fsobj_error(a_eno, a_estr, 0, + "Cannot extract through " + "symlink ", path); + res = ARCHIVE_FAILED; + break; + } + } else { + tail[0] = c; + fsobj_error(a_eno, a_estr, 0, + "Cannot extract through symlink ", path); + res = ARCHIVE_FAILED; + break; + } + } + /* be sure to always maintain this */ + tail[0] = c; + if (tail[0] != '\0') + tail++; /* Advance to the next segment. */ + } + /* Catches loop exits via break */ + tail[0] = c; +#ifdef HAVE_FCHDIR + /* If we changed directory above, restore it here. */ + if (restore_pwd >= 0) { + r = fchdir(restore_pwd); + if (r != 0) { + fsobj_error(a_eno, a_estr, errno, + "chdir() failure", ""); + } + close(restore_pwd); + restore_pwd = -1; + if (r != 0) { + res = (ARCHIVE_FATAL); + } + } +#endif + /* TODO: reintroduce a safe cache here? */ + return res; +#endif +} + +/* + * Check a->name for symlinks, returning ARCHIVE_OK if its clean, otherwise + * calls archive_set_error and returns ARCHIVE_{FATAL,FAILED} + */ +static int +check_symlinks(struct archive_write_disk *a) +{ + struct archive_string error_string; + int error_number; + int rc; + archive_string_init(&error_string); + rc = check_symlinks_fsobj(a->name, &error_number, &error_string, + a->flags); + if (rc != ARCHIVE_OK) { + archive_set_error(&a->archive, error_number, "%s", + error_string.s); + } + archive_string_free(&error_string); + a->pst = NULL; /* to be safe */ + return rc; +} + + +#if defined(__CYGWIN__) +/* + * 1. Convert a path separator from '\' to '/' . + * We shouldn't check multibyte character directly because some + * character-set have been using the '\' character for a part of + * its multibyte character code. + * 2. Replace unusable characters in Windows with underscore('_'). + * See also : http://msdn.microsoft.com/en-us/library/aa365247.aspx + */ +static void +cleanup_pathname_win(char *path) +{ + wchar_t wc; + char *p; + size_t alen, l; + int mb, complete, utf8; + + alen = 0; + mb = 0; + complete = 1; + utf8 = (strcmp(nl_langinfo(CODESET), "UTF-8") == 0)? 1: 0; + for (p = path; *p != '\0'; p++) { + ++alen; + if (*p == '\\') { + /* If previous byte is smaller than 128, + * this is not second byte of multibyte characters, + * so we can replace '\' with '/'. */ + if (utf8 || !mb) + *p = '/'; + else + complete = 0;/* uncompleted. */ + } else if (*(unsigned char *)p > 127) + mb = 1; + else + mb = 0; + /* Rewrite the path name if its next character is unusable. */ + if (*p == ':' || *p == '*' || *p == '?' || *p == '"' || + *p == '<' || *p == '>' || *p == '|') + *p = '_'; + } + if (complete) + return; + + /* + * Convert path separator in wide-character. + */ + p = path; + while (*p != '\0' && alen) { + l = mbtowc(&wc, p, alen); + if (l == (size_t)-1) { + while (*p != '\0') { + if (*p == '\\') + *p = '/'; + ++p; + } + break; + } + if (l == 1 && wc == L'\\') + *p = '/'; + p += l; + alen -= l; + } +} +#endif + +/* + * Canonicalize the pathname. In particular, this strips duplicate + * '/' characters, '.' elements, and trailing '/'. It also raises an + * error for an empty path, a trailing '..', (if _SECURE_NODOTDOT is + * set) any '..' in the path or (if ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS + * is set) if the path is absolute. + */ +static int +cleanup_pathname_fsobj(char *path, int *a_eno, struct archive_string *a_estr, + int flags) +{ + char *dest, *src; + char separator = '\0'; + + dest = src = path; + if (*src == '\0') { + fsobj_error(a_eno, a_estr, ARCHIVE_ERRNO_MISC, + "Invalid empty ", "pathname"); + return (ARCHIVE_FAILED); + } + +#if defined(__CYGWIN__) + cleanup_pathname_win(path); +#endif + /* Skip leading '/'. */ + if (*src == '/') { + if (flags & ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS) { + fsobj_error(a_eno, a_estr, ARCHIVE_ERRNO_MISC, + "Path is ", "absolute"); + return (ARCHIVE_FAILED); + } + + separator = *src++; + } + + /* Scan the pathname one element at a time. */ + for (;;) { + /* src points to first char after '/' */ + if (src[0] == '\0') { + break; + } else if (src[0] == '/') { + /* Found '//', ignore second one. */ + src++; + continue; + } else if (src[0] == '.') { + if (src[1] == '\0') { + /* Ignore trailing '.' */ + break; + } else if (src[1] == '/') { + /* Skip './'. */ + src += 2; + continue; + } else if (src[1] == '.') { + if (src[2] == '/' || src[2] == '\0') { + /* Conditionally warn about '..' */ + if (flags + & ARCHIVE_EXTRACT_SECURE_NODOTDOT) { + fsobj_error(a_eno, a_estr, + ARCHIVE_ERRNO_MISC, + "Path contains ", "'..'"); + return (ARCHIVE_FAILED); + } + } + /* + * Note: Under no circumstances do we + * remove '..' elements. In + * particular, restoring + * '/foo/../bar/' should create the + * 'foo' dir as a side-effect. + */ + } + } + + /* Copy current element, including leading '/'. */ + if (separator) + *dest++ = '/'; + while (*src != '\0' && *src != '/') { + *dest++ = *src++; + } + + if (*src == '\0') + break; + + /* Skip '/' separator. */ + separator = *src++; + } + /* + * We've just copied zero or more path elements, not including the + * final '/'. + */ + if (dest == path) { + /* + * Nothing got copied. The path must have been something + * like '.' or '/' or './' or '/././././/./'. + */ + if (separator) + *dest++ = '/'; + else + *dest++ = '.'; + } + /* Terminate the result. */ + *dest = '\0'; + return (ARCHIVE_OK); +} + +static int +cleanup_pathname(struct archive_write_disk *a) +{ + struct archive_string error_string; + int error_number; + int rc; + archive_string_init(&error_string); + rc = cleanup_pathname_fsobj(a->name, &error_number, &error_string, + a->flags); + if (rc != ARCHIVE_OK) { + archive_set_error(&a->archive, error_number, "%s", + error_string.s); + } + archive_string_free(&error_string); + return rc; +} + +/* + * Create the parent directory of the specified path, assuming path + * is already in mutable storage. + */ +static int +create_parent_dir(struct archive_write_disk *a, char *path) +{ + char *slash; + int r; + + /* Remove tail element to obtain parent name. */ + slash = strrchr(path, '/'); + if (slash == NULL) + return (ARCHIVE_OK); + *slash = '\0'; + r = create_dir(a, path); + *slash = '/'; + return (r); +} + +/* + * Create the specified dir, recursing to create parents as necessary. + * + * Returns ARCHIVE_OK if the path exists when we're done here. + * Otherwise, returns ARCHIVE_FAILED. + * Assumes path is in mutable storage; path is unchanged on exit. + */ +static int +create_dir(struct archive_write_disk *a, char *path) +{ + struct stat st; + struct fixup_entry *le; + char *slash, *base; + mode_t mode_final, mode; + int r; + + /* Check for special names and just skip them. */ + slash = strrchr(path, '/'); + if (slash == NULL) + base = path; + else + base = slash + 1; + + if (base[0] == '\0' || + (base[0] == '.' && base[1] == '\0') || + (base[0] == '.' && base[1] == '.' && base[2] == '\0')) { + /* Don't bother trying to create null path, '.', or '..'. */ + if (slash != NULL) { + *slash = '\0'; + r = create_dir(a, path); + *slash = '/'; + return (r); + } + return (ARCHIVE_OK); + } + + /* + * Yes, this should be stat() and not lstat(). Using lstat() + * here loses the ability to extract through symlinks. Also note + * that this should not use the a->st cache. + */ + if (stat(path, &st) == 0) { + if (S_ISDIR(st.st_mode)) + return (ARCHIVE_OK); + if ((a->flags & ARCHIVE_EXTRACT_NO_OVERWRITE)) { + archive_set_error(&a->archive, EEXIST, + "Can't create directory '%s'", path); + return (ARCHIVE_FAILED); + } + if (unlink(path) != 0) { + archive_set_error(&a->archive, errno, + "Can't create directory '%s': " + "Conflicting file cannot be removed", + path); + return (ARCHIVE_FAILED); + } + } else if (errno != ENOENT && errno != ENOTDIR) { + /* Stat failed? */ + archive_set_error(&a->archive, errno, + "Can't test directory '%s'", path); + return (ARCHIVE_FAILED); + } else if (slash != NULL) { + *slash = '\0'; + r = create_dir(a, path); + *slash = '/'; + if (r != ARCHIVE_OK) + return (r); + } + + /* + * Mode we want for the final restored directory. Per POSIX, + * implicitly-created dirs must be created obeying the umask. + * There's no mention whether this is different for privileged + * restores (which the rest of this code handles by pretending + * umask=0). I've chosen here to always obey the user's umask for + * implicit dirs, even if _EXTRACT_PERM was specified. + */ + mode_final = DEFAULT_DIR_MODE & ~a->user_umask; + /* Mode we want on disk during the restore process. */ + mode = mode_final; + mode |= MINIMUM_DIR_MODE; + mode &= MAXIMUM_DIR_MODE; + if (mkdir(path, mode) == 0) { + if (mode != mode_final) { + le = new_fixup(a, path); + if (le == NULL) + return (ARCHIVE_FATAL); + le->fixup |=TODO_MODE_BASE; + le->mode = mode_final; + } + return (ARCHIVE_OK); + } + + /* + * Without the following check, a/b/../b/c/d fails at the + * second visit to 'b', so 'd' can't be created. Note that we + * don't add it to the fixup list here, as it's already been + * added. + */ + if (stat(path, &st) == 0 && S_ISDIR(st.st_mode)) + return (ARCHIVE_OK); + + archive_set_error(&a->archive, errno, "Failed to create dir '%s'", + path); + return (ARCHIVE_FAILED); +} + +/* + * Note: Although we can skip setting the user id if the desired user + * id matches the current user, we cannot skip setting the group, as + * many systems set the gid based on the containing directory. So + * we have to perform a chown syscall if we want to set the SGID + * bit. (The alternative is to stat() and then possibly chown(); it's + * more efficient to skip the stat() and just always chown().) Note + * that a successful chown() here clears the TODO_SGID_CHECK bit, which + * allows set_mode to skip the stat() check for the GID. + */ +static int +set_ownership(struct archive_write_disk *a) +{ +#ifndef __CYGWIN__ +/* unfortunately, on win32 there is no 'root' user with uid 0, + so we just have to try the chown and see if it works */ + + /* If we know we can't change it, don't bother trying. */ + if (a->user_uid != 0 && a->user_uid != a->uid) { + archive_set_error(&a->archive, errno, + "Can't set UID=%jd", (intmax_t)a->uid); + return (ARCHIVE_WARN); + } +#endif + +#ifdef HAVE_FCHOWN + /* If we have an fd, we can avoid a race. */ + if (a->fd >= 0 && fchown(a->fd, a->uid, a->gid) == 0) { + /* We've set owner and know uid/gid are correct. */ + a->todo &= ~(TODO_OWNER | TODO_SGID_CHECK | TODO_SUID_CHECK); + return (ARCHIVE_OK); + } +#endif + + /* We prefer lchown() but will use chown() if that's all we have. */ + /* Of course, if we have neither, this will always fail. */ +#ifdef HAVE_LCHOWN + if (lchown(a->name, a->uid, a->gid) == 0) { + /* We've set owner and know uid/gid are correct. */ + a->todo &= ~(TODO_OWNER | TODO_SGID_CHECK | TODO_SUID_CHECK); + return (ARCHIVE_OK); + } +#elif HAVE_CHOWN + if (!S_ISLNK(a->mode) && chown(a->name, a->uid, a->gid) == 0) { + /* We've set owner and know uid/gid are correct. */ + a->todo &= ~(TODO_OWNER | TODO_SGID_CHECK | TODO_SUID_CHECK); + return (ARCHIVE_OK); + } +#endif + + archive_set_error(&a->archive, errno, + "Can't set user=%jd/group=%jd for %s", + (intmax_t)a->uid, (intmax_t)a->gid, a->name); + return (ARCHIVE_WARN); +} + +/* + * Note: Returns 0 on success, non-zero on failure. + */ +static int +set_time(int fd, int mode, const char *name, + time_t atime, long atime_nsec, + time_t mtime, long mtime_nsec) +{ + /* Select the best implementation for this platform. */ +#if defined(HAVE_UTIMENSAT) && defined(HAVE_FUTIMENS) + /* + * utimensat() and futimens() are defined in + * POSIX.1-2008. They support ns resolution and setting times + * on fds and symlinks. + */ + struct timespec ts[2]; + (void)mode; /* UNUSED */ + ts[0].tv_sec = atime; + ts[0].tv_nsec = atime_nsec; + ts[1].tv_sec = mtime; + ts[1].tv_nsec = mtime_nsec; + if (fd >= 0) + return futimens(fd, ts); + return utimensat(AT_FDCWD, name, ts, AT_SYMLINK_NOFOLLOW); + +#elif HAVE_UTIMES + /* + * The utimes()-family functions support ?s-resolution and + * setting times fds and symlinks. utimes() is documented as + * LEGACY by POSIX, futimes() and lutimes() are not described + * in POSIX. + */ + struct timeval times[2]; + + times[0].tv_sec = atime; + times[0].tv_usec = atime_nsec / 1000; + times[1].tv_sec = mtime; + times[1].tv_usec = mtime_nsec / 1000; + +#ifdef HAVE_FUTIMES + if (fd >= 0) + return (futimes(fd, times)); +#else + (void)fd; /* UNUSED */ +#endif +#ifdef HAVE_LUTIMES + (void)mode; /* UNUSED */ + return (lutimes(name, times)); +#else + if (S_ISLNK(mode)) + return (0); + return (utimes(name, times)); +#endif + +#elif defined(HAVE_UTIME) + /* + * utime() is POSIX-standard but only supports 1s resolution and + * does not support fds or symlinks. + */ + struct utimbuf times; + (void)fd; /* UNUSED */ + (void)name; /* UNUSED */ + (void)atime_nsec; /* UNUSED */ + (void)mtime_nsec; /* UNUSED */ + times.actime = atime; + times.modtime = mtime; + if (S_ISLNK(mode)) + return (ARCHIVE_OK); + return (utime(name, ×)); + +#else + /* + * We don't know how to set the time on this platform. + */ + (void)fd; /* UNUSED */ + (void)mode; /* UNUSED */ + (void)name; /* UNUSED */ + (void)atime_nsec; /* UNUSED */ + (void)mtime_nsec; /* UNUSED */ + return (ARCHIVE_WARN); +#endif +} + +#ifdef F_SETTIMES +static int +set_time_tru64(int fd, int mode, const char *name, + time_t atime, long atime_nsec, + time_t mtime, long mtime_nsec, + time_t ctime, long ctime_nsec) +{ + struct attr_timbuf tstamp; + tstamp.atime.tv_sec = atime; + tstamp.mtime.tv_sec = mtime; + tstamp.ctime.tv_sec = ctime; +#if defined (__hpux) && defined (__ia64) + tstamp.atime.tv_nsec = atime_nsec; + tstamp.mtime.tv_nsec = mtime_nsec; + tstamp.ctime.tv_nsec = ctime_nsec; +#else + tstamp.atime.tv_usec = atime_nsec / 1000; + tstamp.mtime.tv_usec = mtime_nsec / 1000; + tstamp.ctime.tv_usec = ctime_nsec / 1000; +#endif + return (fcntl(fd,F_SETTIMES,&tstamp)); +} +#endif /* F_SETTIMES */ + +static int +set_times(struct archive_write_disk *a, + int fd, int mode, const char *name, + time_t atime, long atime_nanos, + time_t birthtime, long birthtime_nanos, + time_t mtime, long mtime_nanos, + time_t cctime, long ctime_nanos) +{ + /* Note: set_time doesn't use libarchive return conventions! + * It uses syscall conventions. So 0 here instead of ARCHIVE_OK. */ + int r1 = 0, r2 = 0; + +#ifdef F_SETTIMES + /* + * on Tru64 try own fcntl first which can restore even the + * ctime, fall back to default code path below if it fails + * or if we are not running as root + */ + if (a->user_uid == 0 && + set_time_tru64(fd, mode, name, + atime, atime_nanos, mtime, + mtime_nanos, cctime, ctime_nanos) == 0) { + return (ARCHIVE_OK); + } +#else /* Tru64 */ + (void)cctime; /* UNUSED */ + (void)ctime_nanos; /* UNUSED */ +#endif /* Tru64 */ + +#ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME + /* + * If you have struct stat.st_birthtime, we assume BSD + * birthtime semantics, in which {f,l,}utimes() updates + * birthtime to earliest mtime. So we set the time twice, + * first using the birthtime, then using the mtime. If + * birthtime == mtime, this isn't necessary, so we skip it. + * If birthtime > mtime, then this won't work, so we skip it. + */ + if (birthtime < mtime + || (birthtime == mtime && birthtime_nanos < mtime_nanos)) + r1 = set_time(fd, mode, name, + atime, atime_nanos, + birthtime, birthtime_nanos); +#else + (void)birthtime; /* UNUSED */ + (void)birthtime_nanos; /* UNUSED */ +#endif + r2 = set_time(fd, mode, name, + atime, atime_nanos, + mtime, mtime_nanos); + if (r1 != 0 || r2 != 0) { + archive_set_error(&a->archive, errno, + "Can't restore time"); + return (ARCHIVE_WARN); + } + return (ARCHIVE_OK); +} + +static int +set_times_from_entry(struct archive_write_disk *a) +{ + time_t atime, birthtime, mtime, cctime; + long atime_nsec, birthtime_nsec, mtime_nsec, ctime_nsec; + + /* Suitable defaults. */ + atime = birthtime = mtime = cctime = a->start_time; + atime_nsec = birthtime_nsec = mtime_nsec = ctime_nsec = 0; + + /* If no time was provided, we're done. */ + if (!archive_entry_atime_is_set(a->entry) +#if HAVE_STRUCT_STAT_ST_BIRTHTIME + && !archive_entry_birthtime_is_set(a->entry) +#endif + && !archive_entry_mtime_is_set(a->entry)) + return (ARCHIVE_OK); + + if (archive_entry_atime_is_set(a->entry)) { + atime = archive_entry_atime(a->entry); + atime_nsec = archive_entry_atime_nsec(a->entry); + } + if (archive_entry_birthtime_is_set(a->entry)) { + birthtime = archive_entry_birthtime(a->entry); + birthtime_nsec = archive_entry_birthtime_nsec(a->entry); + } + if (archive_entry_mtime_is_set(a->entry)) { + mtime = archive_entry_mtime(a->entry); + mtime_nsec = archive_entry_mtime_nsec(a->entry); + } + if (archive_entry_ctime_is_set(a->entry)) { + cctime = archive_entry_ctime(a->entry); + ctime_nsec = archive_entry_ctime_nsec(a->entry); + } + + return set_times(a, a->fd, a->mode, a->name, + atime, atime_nsec, + birthtime, birthtime_nsec, + mtime, mtime_nsec, + cctime, ctime_nsec); +} + +static int +set_mode(struct archive_write_disk *a, int mode) +{ + int r = ARCHIVE_OK; + mode &= 07777; /* Strip off file type bits. */ + + if (a->todo & TODO_SGID_CHECK) { + /* + * If we don't know the GID is right, we must stat() + * to verify it. We can't just check the GID of this + * process, since systems sometimes set GID from + * the enclosing dir or based on ACLs. + */ + if ((r = lazy_stat(a)) != ARCHIVE_OK) + return (r); + if (a->pst->st_gid != a->gid) { + mode &= ~ S_ISGID; + if (a->flags & ARCHIVE_EXTRACT_OWNER) { + /* + * This is only an error if you + * requested owner restore. If you + * didn't, we'll try to restore + * sgid/suid, but won't consider it a + * problem if we can't. + */ + archive_set_error(&a->archive, -1, + "Can't restore SGID bit"); + r = ARCHIVE_WARN; + } + } + /* While we're here, double-check the UID. */ + if (a->pst->st_uid != a->uid + && (a->todo & TODO_SUID)) { + mode &= ~ S_ISUID; + if (a->flags & ARCHIVE_EXTRACT_OWNER) { + archive_set_error(&a->archive, -1, + "Can't restore SUID bit"); + r = ARCHIVE_WARN; + } + } + a->todo &= ~TODO_SGID_CHECK; + a->todo &= ~TODO_SUID_CHECK; + } else if (a->todo & TODO_SUID_CHECK) { + /* + * If we don't know the UID is right, we can just check + * the user, since all systems set the file UID from + * the process UID. + */ + if (a->user_uid != a->uid) { + mode &= ~ S_ISUID; + if (a->flags & ARCHIVE_EXTRACT_OWNER) { + archive_set_error(&a->archive, -1, + "Can't make file SUID"); + r = ARCHIVE_WARN; + } + } + a->todo &= ~TODO_SUID_CHECK; + } + + if (S_ISLNK(a->mode)) { +#ifdef HAVE_LCHMOD + /* + * If this is a symlink, use lchmod(). If the + * platform doesn't support lchmod(), just skip it. A + * platform that doesn't provide a way to set + * permissions on symlinks probably ignores + * permissions on symlinks, so a failure here has no + * impact. + */ + if (lchmod(a->name, mode) != 0) { + switch (errno) { + case ENOTSUP: + case ENOSYS: +#if ENOTSUP != EOPNOTSUPP + case EOPNOTSUPP: +#endif + /* + * if lchmod is defined but the platform + * doesn't support it, silently ignore + * error + */ + break; + default: + archive_set_error(&a->archive, errno, + "Can't set permissions to 0%o", (int)mode); + r = ARCHIVE_WARN; + } + } +#endif + } else if (!S_ISDIR(a->mode)) { + /* + * If it's not a symlink and not a dir, then use + * fchmod() or chmod(), depending on whether we have + * an fd. Dirs get their perms set during the + * post-extract fixup, which is handled elsewhere. + */ +#ifdef HAVE_FCHMOD + if (a->fd >= 0) { + if (fchmod(a->fd, mode) != 0) { + archive_set_error(&a->archive, errno, + "Can't set permissions to 0%o", (int)mode); + r = ARCHIVE_WARN; + } + } else +#endif + /* If this platform lacks fchmod(), then + * we'll just use chmod(). */ + if (chmod(a->name, mode) != 0) { + archive_set_error(&a->archive, errno, + "Can't set permissions to 0%o", (int)mode); + r = ARCHIVE_WARN; + } + } + return (r); +} + +static int +set_fflags(struct archive_write_disk *a) +{ + struct fixup_entry *le; + unsigned long set, clear; + int r; + int critical_flags; + mode_t mode = archive_entry_mode(a->entry); + + /* + * Make 'critical_flags' hold all file flags that can't be + * immediately restored. For example, on BSD systems, + * SF_IMMUTABLE prevents hardlinks from being created, so + * should not be set until after any hardlinks are created. To + * preserve some semblance of portability, this uses #ifdef + * extensively. Ugly, but it works. + * + * Yes, Virginia, this does create a security race. It's mitigated + * somewhat by the practice of creating dirs 0700 until the extract + * is done, but it would be nice if we could do more than that. + * People restoring critical file systems should be wary of + * other programs that might try to muck with files as they're + * being restored. + */ + /* Hopefully, the compiler will optimize this mess into a constant. */ + critical_flags = 0; +#ifdef SF_IMMUTABLE + critical_flags |= SF_IMMUTABLE; +#endif +#ifdef UF_IMMUTABLE + critical_flags |= UF_IMMUTABLE; +#endif +#ifdef SF_APPEND + critical_flags |= SF_APPEND; +#endif +#ifdef UF_APPEND + critical_flags |= UF_APPEND; +#endif +#if defined(FS_APPEND_FL) + critical_flags |= FS_APPEND_FL; +#elif defined(EXT2_APPEND_FL) + critical_flags |= EXT2_APPEND_FL; +#endif +#if defined(FS_IMMUTABLE_FL) + critical_flags |= FS_IMMUTABLE_FL; +#elif defined(EXT2_IMMUTABLE_FL) + critical_flags |= EXT2_IMMUTABLE_FL; +#endif +#ifdef FS_JOURNAL_DATA_FL + critical_flags |= FS_JOURNAL_DATA_FL; +#endif + + if (a->todo & TODO_FFLAGS) { + archive_entry_fflags(a->entry, &set, &clear); + + /* + * The first test encourages the compiler to eliminate + * all of this if it's not necessary. + */ + if ((critical_flags != 0) && (set & critical_flags)) { + le = current_fixup(a, a->name); + if (le == NULL) + return (ARCHIVE_FATAL); + le->fixup |= TODO_FFLAGS; + le->fflags_set = set; + /* Store the mode if it's not already there. */ + if ((le->fixup & TODO_MODE) == 0) + le->mode = mode; + } else { + r = set_fflags_platform(a, a->fd, + a->name, mode, set, clear); + if (r != ARCHIVE_OK) + return (r); + } + } + return (ARCHIVE_OK); +} + +static int +clear_nochange_fflags(struct archive_write_disk *a) +{ + int nochange_flags; + mode_t mode = archive_entry_mode(a->entry); + + /* Hopefully, the compiler will optimize this mess into a constant. */ + nochange_flags = 0; +#ifdef SF_IMMUTABLE + nochange_flags |= SF_IMMUTABLE; +#endif +#ifdef UF_IMMUTABLE + nochange_flags |= UF_IMMUTABLE; +#endif +#ifdef SF_APPEND + nochange_flags |= SF_APPEND; +#endif +#ifdef UF_APPEND + nochange_flags |= UF_APPEND; +#endif +#ifdef EXT2_APPEND_FL + nochange_flags |= EXT2_APPEND_FL; +#endif +#ifdef EXT2_IMMUTABLE_FL + nochange_flags |= EXT2_IMMUTABLE_FL; +#endif + + return (set_fflags_platform(a, a->fd, a->name, mode, 0, + nochange_flags)); +} + + +#if ( defined(HAVE_LCHFLAGS) || defined(HAVE_CHFLAGS) || defined(HAVE_FCHFLAGS) ) && defined(HAVE_STRUCT_STAT_ST_FLAGS) +/* + * BSD reads flags using stat() and sets them with one of {f,l,}chflags() + */ +static int +set_fflags_platform(struct archive_write_disk *a, int fd, const char *name, + mode_t mode, unsigned long set, unsigned long clear) +{ + int r; + + (void)mode; /* UNUSED */ + if (set == 0 && clear == 0) + return (ARCHIVE_OK); + + /* + * XXX Is the stat here really necessary? Or can I just use + * the 'set' flags directly? In particular, I'm not sure + * about the correct approach if we're overwriting an existing + * file that already has flags on it. XXX + */ + if ((r = lazy_stat(a)) != ARCHIVE_OK) + return (r); + + a->st.st_flags &= ~clear; + a->st.st_flags |= set; +#ifdef HAVE_FCHFLAGS + /* If platform has fchflags() and we were given an fd, use it. */ + if (fd >= 0 && fchflags(fd, a->st.st_flags) == 0) + return (ARCHIVE_OK); +#endif + /* + * If we can't use the fd to set the flags, we'll use the + * pathname to set flags. We prefer lchflags() but will use + * chflags() if we must. + */ +#ifdef HAVE_LCHFLAGS + if (lchflags(name, a->st.st_flags) == 0) + return (ARCHIVE_OK); +#elif defined(HAVE_CHFLAGS) + if (S_ISLNK(a->st.st_mode)) { + archive_set_error(&a->archive, errno, + "Can't set file flags on symlink."); + return (ARCHIVE_WARN); + } + if (chflags(name, a->st.st_flags) == 0) + return (ARCHIVE_OK); +#endif + archive_set_error(&a->archive, errno, + "Failed to set file flags"); + return (ARCHIVE_WARN); +} + +#elif (defined(FS_IOC_GETFLAGS) && defined(FS_IOC_SETFLAGS) && \ + defined(HAVE_WORKING_FS_IOC_GETFLAGS)) || \ + (defined(EXT2_IOC_GETFLAGS) && defined(EXT2_IOC_SETFLAGS) && \ + defined(HAVE_WORKING_EXT2_IOC_GETFLAGS)) +/* + * Linux uses ioctl() to read and write file flags. + */ +static int +set_fflags_platform(struct archive_write_disk *a, int fd, const char *name, + mode_t mode, unsigned long set, unsigned long clear) +{ + int ret; + int myfd = fd; + int newflags, oldflags; + int sf_mask = 0; + + if (set == 0 && clear == 0) + return (ARCHIVE_OK); + /* Only regular files and dirs can have flags. */ + if (!S_ISREG(mode) && !S_ISDIR(mode)) + return (ARCHIVE_OK); + + /* If we weren't given an fd, open it ourselves. */ + if (myfd < 0) { + myfd = open(name, O_RDONLY | O_NONBLOCK | O_BINARY | O_CLOEXEC); + __archive_ensure_cloexec_flag(myfd); + } + if (myfd < 0) + return (ARCHIVE_OK); + + /* + * Linux has no define for the flags that are only settable by + * the root user. This code may seem a little complex, but + * there seem to be some Linux systems that lack these + * defines. (?) The code below degrades reasonably gracefully + * if sf_mask is incomplete. + */ +#if defined(FS_IMMUTABLE_FL) + sf_mask |= FS_IMMUTABLE_FL; +#elif defined(EXT2_IMMUTABLE_FL) + sf_mask |= EXT2_IMMUTABLE_FL; +#endif +#if defined(FS_APPEND_FL) + sf_mask |= FS_APPEND_FL; +#elif defined(EXT2_APPEND_FL) + sf_mask |= EXT2_APPEND_FL; +#endif +#if defined(FS_JOURNAL_DATA_FL) + sf_mask |= FS_JOURNAL_DATA_FL; +#endif + /* + * XXX As above, this would be way simpler if we didn't have + * to read the current flags from disk. XXX + */ + ret = ARCHIVE_OK; + + /* Read the current file flags. */ + if (ioctl(myfd, +#ifdef FS_IOC_GETFLAGS + FS_IOC_GETFLAGS, +#else + EXT2_IOC_GETFLAGS, +#endif + &oldflags) < 0) + goto fail; + + /* Try setting the flags as given. */ + newflags = (oldflags & ~clear) | set; + if (ioctl(myfd, +#ifdef FS_IOC_SETFLAGS + FS_IOC_SETFLAGS, +#else + EXT2_IOC_SETFLAGS, +#endif + &newflags) >= 0) + goto cleanup; + if (errno != EPERM) + goto fail; + + /* If we couldn't set all the flags, try again with a subset. */ + newflags &= ~sf_mask; + oldflags &= sf_mask; + newflags |= oldflags; + if (ioctl(myfd, +#ifdef FS_IOC_SETFLAGS + FS_IOC_SETFLAGS, +#else + EXT2_IOC_SETFLAGS, +#endif + &newflags) >= 0) + goto cleanup; + + /* We couldn't set the flags, so report the failure. */ +fail: + archive_set_error(&a->archive, errno, + "Failed to set file flags"); + ret = ARCHIVE_WARN; +cleanup: + if (fd < 0) + close(myfd); + return (ret); +} + +#else + +/* + * Of course, some systems have neither BSD chflags() nor Linux' flags + * support through ioctl(). + */ +static int +set_fflags_platform(struct archive_write_disk *a, int fd, const char *name, + mode_t mode, unsigned long set, unsigned long clear) +{ + (void)a; /* UNUSED */ + (void)fd; /* UNUSED */ + (void)name; /* UNUSED */ + (void)mode; /* UNUSED */ + (void)set; /* UNUSED */ + (void)clear; /* UNUSED */ + return (ARCHIVE_OK); +} + +#endif /* __linux */ + +#ifndef HAVE_COPYFILE_H +/* Default is to simply drop Mac extended metadata. */ +static int +set_mac_metadata(struct archive_write_disk *a, const char *pathname, + const void *metadata, size_t metadata_size) +{ + (void)a; /* UNUSED */ + (void)pathname; /* UNUSED */ + (void)metadata; /* UNUSED */ + (void)metadata_size; /* UNUSED */ + return (ARCHIVE_OK); +} + +static int +fixup_appledouble(struct archive_write_disk *a, const char *pathname) +{ + (void)a; /* UNUSED */ + (void)pathname; /* UNUSED */ + return (ARCHIVE_OK); +} +#else + +/* + * On Mac OS, we use copyfile() to unpack the metadata and + * apply it to the target file. + */ + +#if defined(HAVE_SYS_XATTR_H) +static int +copy_xattrs(struct archive_write_disk *a, int tmpfd, int dffd) +{ + ssize_t xattr_size; + char *xattr_names = NULL, *xattr_val = NULL; + int ret = ARCHIVE_OK, xattr_i; + + xattr_size = flistxattr(tmpfd, NULL, 0, 0); + if (xattr_size == -1) { + archive_set_error(&a->archive, errno, + "Failed to read metadata(xattr)"); + ret = ARCHIVE_WARN; + goto exit_xattr; + } + xattr_names = malloc(xattr_size); + if (xattr_names == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for metadata(xattr)"); + ret = ARCHIVE_FATAL; + goto exit_xattr; + } + xattr_size = flistxattr(tmpfd, xattr_names, xattr_size, 0); + if (xattr_size == -1) { + archive_set_error(&a->archive, errno, + "Failed to read metadata(xattr)"); + ret = ARCHIVE_WARN; + goto exit_xattr; + } + for (xattr_i = 0; xattr_i < xattr_size; + xattr_i += strlen(xattr_names + xattr_i) + 1) { + char *xattr_val_saved; + ssize_t s; + int f; + + s = fgetxattr(tmpfd, xattr_names + xattr_i, NULL, 0, 0, 0); + if (s == -1) { + archive_set_error(&a->archive, errno, + "Failed to get metadata(xattr)"); + ret = ARCHIVE_WARN; + goto exit_xattr; + } + xattr_val_saved = xattr_val; + xattr_val = realloc(xattr_val, s); + if (xattr_val == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Failed to get metadata(xattr)"); + ret = ARCHIVE_WARN; + free(xattr_val_saved); + goto exit_xattr; + } + s = fgetxattr(tmpfd, xattr_names + xattr_i, xattr_val, s, 0, 0); + if (s == -1) { + archive_set_error(&a->archive, errno, + "Failed to get metadata(xattr)"); + ret = ARCHIVE_WARN; + goto exit_xattr; + } + f = fsetxattr(dffd, xattr_names + xattr_i, xattr_val, s, 0, 0); + if (f == -1) { + archive_set_error(&a->archive, errno, + "Failed to get metadata(xattr)"); + ret = ARCHIVE_WARN; + goto exit_xattr; + } + } +exit_xattr: + free(xattr_names); + free(xattr_val); + return (ret); +} +#endif + +static int +copy_acls(struct archive_write_disk *a, int tmpfd, int dffd) +{ +#ifndef HAVE_SYS_ACL_H + return 0; +#else + acl_t acl, dfacl = NULL; + int acl_r, ret = ARCHIVE_OK; + + acl = acl_get_fd(tmpfd); + if (acl == NULL) { + if (errno == ENOENT) + /* There are not any ACLs. */ + return (ret); + archive_set_error(&a->archive, errno, + "Failed to get metadata(acl)"); + ret = ARCHIVE_WARN; + goto exit_acl; + } + dfacl = acl_dup(acl); + acl_r = acl_set_fd(dffd, dfacl); + if (acl_r == -1) { + archive_set_error(&a->archive, errno, + "Failed to get metadata(acl)"); + ret = ARCHIVE_WARN; + goto exit_acl; + } +exit_acl: + if (acl) + acl_free(acl); + if (dfacl) + acl_free(dfacl); + return (ret); +#endif +} + +static int +create_tempdatafork(struct archive_write_disk *a, const char *pathname) +{ + struct archive_string tmpdatafork; + int tmpfd; + + archive_string_init(&tmpdatafork); + archive_strcpy(&tmpdatafork, "tar.md.XXXXXX"); + tmpfd = mkstemp(tmpdatafork.s); + if (tmpfd < 0) { + archive_set_error(&a->archive, errno, + "Failed to mkstemp"); + archive_string_free(&tmpdatafork); + return (-1); + } + if (copyfile(pathname, tmpdatafork.s, 0, + COPYFILE_UNPACK | COPYFILE_NOFOLLOW + | COPYFILE_ACL | COPYFILE_XATTR) < 0) { + archive_set_error(&a->archive, errno, + "Failed to restore metadata"); + close(tmpfd); + tmpfd = -1; + } + unlink(tmpdatafork.s); + archive_string_free(&tmpdatafork); + return (tmpfd); +} + +static int +copy_metadata(struct archive_write_disk *a, const char *metadata, + const char *datafork, int datafork_compressed) +{ + int ret = ARCHIVE_OK; + + if (datafork_compressed) { + int dffd, tmpfd; + + tmpfd = create_tempdatafork(a, metadata); + if (tmpfd == -1) + return (ARCHIVE_WARN); + + /* + * Do not open the data fork compressed by HFS+ compression + * with at least a writing mode(O_RDWR or O_WRONLY). it + * makes the data fork uncompressed. + */ + dffd = open(datafork, 0); + if (dffd == -1) { + archive_set_error(&a->archive, errno, + "Failed to open the data fork for metadata"); + close(tmpfd); + return (ARCHIVE_WARN); + } + +#if defined(HAVE_SYS_XATTR_H) + ret = copy_xattrs(a, tmpfd, dffd); + if (ret == ARCHIVE_OK) +#endif + ret = copy_acls(a, tmpfd, dffd); + close(tmpfd); + close(dffd); + } else { + if (copyfile(metadata, datafork, 0, + COPYFILE_UNPACK | COPYFILE_NOFOLLOW + | COPYFILE_ACL | COPYFILE_XATTR) < 0) { + archive_set_error(&a->archive, errno, + "Failed to restore metadata"); + ret = ARCHIVE_WARN; + } + } + return (ret); +} + +static int +set_mac_metadata(struct archive_write_disk *a, const char *pathname, + const void *metadata, size_t metadata_size) +{ + struct archive_string tmp; + ssize_t written; + int fd; + int ret = ARCHIVE_OK; + + /* This would be simpler if copyfile() could just accept the + * metadata as a block of memory; then we could sidestep this + * silly dance of writing the data to disk just so that + * copyfile() can read it back in again. */ + archive_string_init(&tmp); + archive_strcpy(&tmp, pathname); + archive_strcat(&tmp, ".XXXXXX"); + fd = mkstemp(tmp.s); + + if (fd < 0) { + archive_set_error(&a->archive, errno, + "Failed to restore metadata"); + archive_string_free(&tmp); + return (ARCHIVE_WARN); + } + written = write(fd, metadata, metadata_size); + close(fd); + if ((size_t)written != metadata_size) { + archive_set_error(&a->archive, errno, + "Failed to restore metadata"); + ret = ARCHIVE_WARN; + } else { + int compressed; + +#if defined(UF_COMPRESSED) + if ((a->todo & TODO_HFS_COMPRESSION) != 0 && + (ret = lazy_stat(a)) == ARCHIVE_OK) + compressed = a->st.st_flags & UF_COMPRESSED; + else +#endif + compressed = 0; + ret = copy_metadata(a, tmp.s, pathname, compressed); + } + unlink(tmp.s); + archive_string_free(&tmp); + return (ret); +} + +static int +fixup_appledouble(struct archive_write_disk *a, const char *pathname) +{ + char buff[8]; + struct stat st; + const char *p; + struct archive_string datafork; + int fd = -1, ret = ARCHIVE_OK; + + archive_string_init(&datafork); + /* Check if the current file name is a type of the resource + * fork file. */ + p = strrchr(pathname, '/'); + if (p == NULL) + p = pathname; + else + p++; + if (p[0] != '.' || p[1] != '_') + goto skip_appledouble; + + /* + * Check if the data fork file exists. + * + * TODO: Check if this write disk object has handled it. + */ + archive_strncpy(&datafork, pathname, p - pathname); + archive_strcat(&datafork, p + 2); + if (lstat(datafork.s, &st) == -1 || + (st.st_mode & AE_IFMT) != AE_IFREG) + goto skip_appledouble; + + /* + * Check if the file is in the AppleDouble form. + */ + fd = open(pathname, O_RDONLY | O_BINARY | O_CLOEXEC); + __archive_ensure_cloexec_flag(fd); + if (fd == -1) { + archive_set_error(&a->archive, errno, + "Failed to open a restoring file"); + ret = ARCHIVE_WARN; + goto skip_appledouble; + } + if (read(fd, buff, 8) == -1) { + archive_set_error(&a->archive, errno, + "Failed to read a restoring file"); + close(fd); + ret = ARCHIVE_WARN; + goto skip_appledouble; + } + close(fd); + /* Check AppleDouble Magic Code. */ + if (archive_be32dec(buff) != 0x00051607) + goto skip_appledouble; + /* Check AppleDouble Version. */ + if (archive_be32dec(buff+4) != 0x00020000) + goto skip_appledouble; + + ret = copy_metadata(a, pathname, datafork.s, +#if defined(UF_COMPRESSED) + st.st_flags & UF_COMPRESSED); +#else + 0); +#endif + if (ret == ARCHIVE_OK) { + unlink(pathname); + ret = ARCHIVE_EOF; + } +skip_appledouble: + archive_string_free(&datafork); + return (ret); +} +#endif + +#if ARCHIVE_XATTR_LINUX || ARCHIVE_XATTR_DARWIN || ARCHIVE_XATTR_AIX +/* + * Restore extended attributes - Linux, Darwin and AIX implementations: + * AIX' ea interface is syntaxwise identical to the Linux xattr interface. + */ +static int +set_xattrs(struct archive_write_disk *a) +{ + struct archive_entry *entry = a->entry; + struct archive_string errlist; + int ret = ARCHIVE_OK; + int i = archive_entry_xattr_reset(entry); + short fail = 0; + + archive_string_init(&errlist); + + while (i--) { + const char *name; + const void *value; + size_t size; + int e; + + archive_entry_xattr_next(entry, &name, &value, &size); + + if (name == NULL) + continue; +#if ARCHIVE_XATTR_LINUX + /* Linux: quietly skip POSIX.1e ACL extended attributes */ + if (strncmp(name, "system.", 7) == 0 && + (strcmp(name + 7, "posix_acl_access") == 0 || + strcmp(name + 7, "posix_acl_default") == 0)) + continue; + if (strncmp(name, "trusted.SGI_", 12) == 0 && + (strcmp(name + 12, "ACL_DEFAULT") == 0 || + strcmp(name + 12, "ACL_FILE") == 0)) + continue; + + /* Linux: xfsroot namespace is obsolete and unsupported */ + if (strncmp(name, "xfsroot.", 8) == 0) { + fail = 1; + archive_strcat(&errlist, name); + archive_strappend_char(&errlist, ' '); + continue; + } +#endif + + if (a->fd >= 0) { +#if ARCHIVE_XATTR_LINUX + e = fsetxattr(a->fd, name, value, size, 0); +#elif ARCHIVE_XATTR_DARWIN + e = fsetxattr(a->fd, name, value, size, 0, 0); +#elif ARCHIVE_XATTR_AIX + e = fsetea(a->fd, name, value, size, 0); +#endif + } else { +#if ARCHIVE_XATTR_LINUX + e = lsetxattr(archive_entry_pathname(entry), + name, value, size, 0); +#elif ARCHIVE_XATTR_DARWIN + e = setxattr(archive_entry_pathname(entry), + name, value, size, 0, XATTR_NOFOLLOW); +#elif ARCHIVE_XATTR_AIX + e = lsetea(archive_entry_pathname(entry), + name, value, size, 0); +#endif + } + if (e == -1) { + ret = ARCHIVE_WARN; + archive_strcat(&errlist, name); + archive_strappend_char(&errlist, ' '); + if (errno != ENOTSUP && errno != ENOSYS) + fail = 1; + } + } + + if (ret == ARCHIVE_WARN) { + if (fail && errlist.length > 0) { + errlist.length--; + errlist.s[errlist.length] = '\0'; + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Cannot restore extended attributes: %s", + errlist.s); + } else + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Cannot restore extended " + "attributes on this file system."); + } + + archive_string_free(&errlist); + return (ret); +} +#elif ARCHIVE_XATTR_FREEBSD +/* + * Restore extended attributes - FreeBSD implementation + */ +static int +set_xattrs(struct archive_write_disk *a) +{ + struct archive_entry *entry = a->entry; + struct archive_string errlist; + int ret = ARCHIVE_OK; + int i = archive_entry_xattr_reset(entry); + short fail = 0; + + archive_string_init(&errlist); + + while (i--) { + const char *name; + const void *value; + size_t size; + archive_entry_xattr_next(entry, &name, &value, &size); + if (name != NULL) { + int e; + int namespace; + + if (strncmp(name, "user.", 5) == 0) { + /* "user." attributes go to user namespace */ + name += 5; + namespace = EXTATTR_NAMESPACE_USER; + } else { + /* Other namespaces are unsupported */ + archive_strcat(&errlist, name); + archive_strappend_char(&errlist, ' '); + fail = 1; + ret = ARCHIVE_WARN; + continue; + } + + if (a->fd >= 0) { + e = extattr_set_fd(a->fd, namespace, name, + value, size); + } else { + e = extattr_set_link( + archive_entry_pathname(entry), namespace, + name, value, size); + } + if (e != (int)size) { + archive_strcat(&errlist, name); + archive_strappend_char(&errlist, ' '); + ret = ARCHIVE_WARN; + if (errno != ENOTSUP && errno != ENOSYS) + fail = 1; + } + } + } + + if (ret == ARCHIVE_WARN) { + if (fail && errlist.length > 0) { + errlist.length--; + errlist.s[errlist.length] = '\0'; + + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Cannot restore extended attributes: %s", + errlist.s); + } else + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Cannot restore extended " + "attributes on this file system."); + } + + archive_string_free(&errlist); + return (ret); +} +#else +/* + * Restore extended attributes - stub implementation for unsupported systems + */ +static int +set_xattrs(struct archive_write_disk *a) +{ + static int warning_done = 0; + + /* If there aren't any extended attributes, then it's okay not + * to extract them, otherwise, issue a single warning. */ + if (archive_entry_xattr_count(a->entry) != 0 && !warning_done) { + warning_done = 1; + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Cannot restore extended attributes on this system"); + return (ARCHIVE_WARN); + } + /* Warning was already emitted; suppress further warnings. */ + return (ARCHIVE_OK); +} +#endif + +/* + * Test if file on disk is older than entry. + */ +static int +older(struct stat *st, struct archive_entry *entry) +{ + /* First, test the seconds and return if we have a definite answer. */ + /* Definitely older. */ + if (to_int64_time(st->st_mtime) < to_int64_time(archive_entry_mtime(entry))) + return (1); + /* Definitely younger. */ + if (to_int64_time(st->st_mtime) > to_int64_time(archive_entry_mtime(entry))) + return (0); + /* If this platform supports fractional seconds, try those. */ +#if HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC + /* Definitely older. */ + if (st->st_mtimespec.tv_nsec < archive_entry_mtime_nsec(entry)) + return (1); +#elif HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC + /* Definitely older. */ + if (st->st_mtim.tv_nsec < archive_entry_mtime_nsec(entry)) + return (1); +#elif HAVE_STRUCT_STAT_ST_MTIME_N + /* older. */ + if (st->st_mtime_n < archive_entry_mtime_nsec(entry)) + return (1); +#elif HAVE_STRUCT_STAT_ST_UMTIME + /* older. */ + if (st->st_umtime * 1000 < archive_entry_mtime_nsec(entry)) + return (1); +#elif HAVE_STRUCT_STAT_ST_MTIME_USEC + /* older. */ + if (st->st_mtime_usec * 1000 < archive_entry_mtime_nsec(entry)) + return (1); +#else + /* This system doesn't have high-res timestamps. */ +#endif + /* Same age or newer, so not older. */ + return (0); +} + +#ifndef ARCHIVE_ACL_SUPPORT +int +archive_write_disk_set_acls(struct archive *a, int fd, const char *name, + struct archive_acl *abstract_acl, __LA_MODE_T mode) +{ + (void)a; /* UNUSED */ + (void)fd; /* UNUSED */ + (void)name; /* UNUSED */ + (void)abstract_acl; /* UNUSED */ + (void)mode; /* UNUSED */ + return (ARCHIVE_OK); +} +#endif + +#endif /* !_WIN32 || __CYGWIN__ */ + diff --cc Utilities/cmlibarchive/libarchive/archive_write_set_format_7zip.c index 3fc5a07,0000000..2bd4ec4 mode 100644,000000..100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_set_format_7zip.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_7zip.c @@@ -1,2328 -1,0 +1,2315 @@@ +/*- + * Copyright (c) 2011-2012 Michihiro NAKAJIMA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "archive_platform.h" +__FBSDID("$FreeBSD$"); + +#ifdef HAVE_ERRNO_H +#include +#endif +#include +#ifdef HAVE_BZLIB_H +#include +#endif +#if HAVE_LZMA_H +#include +#endif +#ifdef HAVE_ZLIB_H +#include +#endif + +#include "archive.h" +#ifndef HAVE_ZLIB_H +#include "archive_crc32.h" +#endif +#include "archive_endian.h" +#include "archive_entry.h" +#include "archive_entry_locale.h" +#include "archive_ppmd7_private.h" +#include "archive_private.h" +#include "archive_rb.h" +#include "archive_string.h" +#include "archive_write_private.h" + +/* + * Codec ID + */ +#define _7Z_COPY 0 +#define _7Z_LZMA1 0x030101 +#define _7Z_LZMA2 0x21 +#define _7Z_DEFLATE 0x040108 +#define _7Z_BZIP2 0x040202 +#define _7Z_PPMD 0x030401 + +/* + * 7-Zip header property IDs. + */ +#define kEnd 0x00 +#define kHeader 0x01 +#define kArchiveProperties 0x02 +#define kAdditionalStreamsInfo 0x03 +#define kMainStreamsInfo 0x04 +#define kFilesInfo 0x05 +#define kPackInfo 0x06 +#define kUnPackInfo 0x07 +#define kSubStreamsInfo 0x08 +#define kSize 0x09 +#define kCRC 0x0A +#define kFolder 0x0B +#define kCodersUnPackSize 0x0C +#define kNumUnPackStream 0x0D +#define kEmptyStream 0x0E +#define kEmptyFile 0x0F +#define kAnti 0x10 +#define kName 0x11 +#define kCTime 0x12 +#define kATime 0x13 +#define kMTime 0x14 +#define kAttributes 0x15 +#define kEncodedHeader 0x17 + +enum la_zaction { + ARCHIVE_Z_FINISH, + ARCHIVE_Z_RUN +}; + +/* + * A stream object of universal compressor. + */ +struct la_zstream { + const uint8_t *next_in; + size_t avail_in; + uint64_t total_in; + + uint8_t *next_out; + size_t avail_out; + uint64_t total_out; + + uint32_t prop_size; + uint8_t *props; + + int valid; + void *real_stream; + int (*code) (struct archive *a, + struct la_zstream *lastrm, + enum la_zaction action); + int (*end)(struct archive *a, + struct la_zstream *lastrm); +}; + +#define PPMD7_DEFAULT_ORDER 6 +#define PPMD7_DEFAULT_MEM_SIZE (1 << 24) + +struct ppmd_stream { + int stat; + CPpmd7 ppmd7_context; + CPpmd7z_RangeEnc range_enc; + IByteOut byteout; + uint8_t *buff; + uint8_t *buff_ptr; + uint8_t *buff_end; + size_t buff_bytes; +}; + +struct coder { + unsigned codec; + size_t prop_size; + uint8_t *props; +}; + +struct file { + struct archive_rb_node rbnode; + + struct file *next; + unsigned name_len; + uint8_t *utf16name;/* UTF16-LE name. */ + uint64_t size; + unsigned flg; +#define MTIME_IS_SET (1<<0) +#define ATIME_IS_SET (1<<1) +#define CTIME_IS_SET (1<<2) +#define CRC32_IS_SET (1<<3) +#define HAS_STREAM (1<<4) + + struct { + time_t time; + long time_ns; + } times[3]; +#define MTIME 0 +#define ATIME 1 +#define CTIME 2 + + mode_t mode; + uint32_t crc32; + + int dir:1; +}; + +struct _7zip { + int temp_fd; + uint64_t temp_offset; + + struct file *cur_file; + size_t total_number_entry; + size_t total_number_nonempty_entry; + size_t total_number_empty_entry; + size_t total_number_dir_entry; + size_t total_bytes_entry_name; + size_t total_number_time_defined[3]; + uint64_t total_bytes_compressed; + uint64_t total_bytes_uncompressed; + uint64_t entry_bytes_remaining; + uint32_t entry_crc32; + uint32_t precode_crc32; + uint32_t encoded_crc32; + int crc32flg; +#define PRECODE_CRC32 1 +#define ENCODED_CRC32 2 + + unsigned opt_compression; + int opt_compression_level; + + struct la_zstream stream; + struct coder coder; + + struct archive_string_conv *sconv; + + /* + * Compressed data buffer. + */ + unsigned char wbuff[512 * 20 * 6]; + size_t wbuff_remaining; + + /* + * The list of the file entries which has its contents is used to + * manage struct file objects. + * We use 'next' (a member of struct file) to chain. + */ + struct { + struct file *first; + struct file **last; + } file_list, empty_list; + struct archive_rb_tree rbtree;/* for empty files */ +}; + +static int _7z_options(struct archive_write *, + const char *, const char *); +static int _7z_write_header(struct archive_write *, + struct archive_entry *); +static ssize_t _7z_write_data(struct archive_write *, + const void *, size_t); +static int _7z_finish_entry(struct archive_write *); +static int _7z_close(struct archive_write *); +static int _7z_free(struct archive_write *); +static int file_cmp_node(const struct archive_rb_node *, + const struct archive_rb_node *); +static int file_cmp_key(const struct archive_rb_node *, const void *); +static int file_new(struct archive_write *a, struct archive_entry *, + struct file **); +static void file_free(struct file *); +static void file_register(struct _7zip *, struct file *); +static void file_register_empty(struct _7zip *, struct file *); +static void file_init_register(struct _7zip *); +static void file_init_register_empty(struct _7zip *); +static void file_free_register(struct _7zip *); +static ssize_t compress_out(struct archive_write *, const void *, size_t , + enum la_zaction); +static int compression_init_encoder_copy(struct archive *, + struct la_zstream *); +static int compression_code_copy(struct archive *, + struct la_zstream *, enum la_zaction); +static int compression_end_copy(struct archive *, struct la_zstream *); +static int compression_init_encoder_deflate(struct archive *, + struct la_zstream *, int, int); +#ifdef HAVE_ZLIB_H +static int compression_code_deflate(struct archive *, + struct la_zstream *, enum la_zaction); +static int compression_end_deflate(struct archive *, struct la_zstream *); +#endif +static int compression_init_encoder_bzip2(struct archive *, + struct la_zstream *, int); +#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) +static int compression_code_bzip2(struct archive *, + struct la_zstream *, enum la_zaction); +static int compression_end_bzip2(struct archive *, struct la_zstream *); +#endif +static int compression_init_encoder_lzma1(struct archive *, + struct la_zstream *, int); +static int compression_init_encoder_lzma2(struct archive *, + struct la_zstream *, int); +#if defined(HAVE_LZMA_H) +static int compression_code_lzma(struct archive *, + struct la_zstream *, enum la_zaction); +static int compression_end_lzma(struct archive *, struct la_zstream *); +#endif +static int compression_init_encoder_ppmd(struct archive *, + struct la_zstream *, unsigned, uint32_t); +static int compression_code_ppmd(struct archive *, + struct la_zstream *, enum la_zaction); +static int compression_end_ppmd(struct archive *, struct la_zstream *); +static int _7z_compression_init_encoder(struct archive_write *, unsigned, + int); +static int compression_code(struct archive *, + struct la_zstream *, enum la_zaction); +static int compression_end(struct archive *, + struct la_zstream *); +static int enc_uint64(struct archive_write *, uint64_t); +static int make_header(struct archive_write *, uint64_t, uint64_t, + uint64_t, int, struct coder *); +static int make_streamsInfo(struct archive_write *, uint64_t, uint64_t, + uint64_t, int, struct coder *, int, uint32_t); + +int +archive_write_set_format_7zip(struct archive *_a) +{ + static const struct archive_rb_tree_ops rb_ops = { + file_cmp_node, file_cmp_key + }; + struct archive_write *a = (struct archive_write *)_a; + struct _7zip *zip; + + archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_NEW, "archive_write_set_format_7zip"); + + /* If another format was already registered, unregister it. */ + if (a->format_free != NULL) + (a->format_free)(a); + + zip = calloc(1, sizeof(*zip)); + if (zip == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate 7-Zip data"); + return (ARCHIVE_FATAL); + } + zip->temp_fd = -1; + __archive_rb_tree_init(&(zip->rbtree), &rb_ops); + file_init_register(zip); + file_init_register_empty(zip); + + /* Set default compression type and its level. */ +#if HAVE_LZMA_H + zip->opt_compression = _7Z_LZMA1; +#elif defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) + zip->opt_compression = _7Z_BZIP2; +#elif defined(HAVE_ZLIB_H) + zip->opt_compression = _7Z_DEFLATE; +#else + zip->opt_compression = _7Z_COPY; +#endif + zip->opt_compression_level = 6; + + a->format_data = zip; + + a->format_name = "7zip"; + a->format_options = _7z_options; + a->format_write_header = _7z_write_header; + a->format_write_data = _7z_write_data; + a->format_finish_entry = _7z_finish_entry; + a->format_close = _7z_close; + a->format_free = _7z_free; + a->archive.archive_format = ARCHIVE_FORMAT_7ZIP; + a->archive.archive_format_name = "7zip"; + + return (ARCHIVE_OK); +} + +static int +_7z_options(struct archive_write *a, const char *key, const char *value) +{ + struct _7zip *zip; + + zip = (struct _7zip *)a->format_data; + + if (strcmp(key, "compression") == 0) { + const char *name = NULL; + + if (value == NULL || strcmp(value, "copy") == 0 || + strcmp(value, "COPY") == 0 || + strcmp(value, "store") == 0 || + strcmp(value, "STORE") == 0) + zip->opt_compression = _7Z_COPY; + else if (strcmp(value, "deflate") == 0 || + strcmp(value, "DEFLATE") == 0) +#if HAVE_ZLIB_H + zip->opt_compression = _7Z_DEFLATE; +#else + name = "deflate"; +#endif + else if (strcmp(value, "bzip2") == 0 || + strcmp(value, "BZIP2") == 0) +#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) + zip->opt_compression = _7Z_BZIP2; +#else + name = "bzip2"; +#endif + else if (strcmp(value, "lzma1") == 0 || + strcmp(value, "LZMA1") == 0) +#if HAVE_LZMA_H + zip->opt_compression = _7Z_LZMA1; +#else + name = "lzma1"; +#endif + else if (strcmp(value, "lzma2") == 0 || + strcmp(value, "LZMA2") == 0) +#if HAVE_LZMA_H + zip->opt_compression = _7Z_LZMA2; +#else + name = "lzma2"; +#endif + else if (strcmp(value, "ppmd") == 0 || + strcmp(value, "PPMD") == 0 || + strcmp(value, "PPMd") == 0) + zip->opt_compression = _7Z_PPMD; + else { + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "Unknown compression name: `%s'", + value); + return (ARCHIVE_FAILED); + } + if (name != NULL) { + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "`%s' compression not supported " + "on this platform", + name); + return (ARCHIVE_FAILED); + } + return (ARCHIVE_OK); + } + if (strcmp(key, "compression-level") == 0) { + if (value == NULL || + !(value[0] >= '0' && value[0] <= '9') || + value[1] != '\0') { + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "Illegal value `%s'", + value); + return (ARCHIVE_FAILED); + } + zip->opt_compression_level = value[0] - '0'; + return (ARCHIVE_OK); + } + + /* Note: The "warn" return is just to inform the options + * supervisor that we didn't handle it. It will generate + * a suitable error if no one used this option. */ + return (ARCHIVE_WARN); +} + +static int +_7z_write_header(struct archive_write *a, struct archive_entry *entry) +{ + struct _7zip *zip; + struct file *file; + int r; + + zip = (struct _7zip *)a->format_data; + zip->cur_file = NULL; + zip->entry_bytes_remaining = 0; + + if (zip->sconv == NULL) { + zip->sconv = archive_string_conversion_to_charset( + &a->archive, "UTF-16LE", 1); + if (zip->sconv == NULL) + return (ARCHIVE_FATAL); + } + + r = file_new(a, entry, &file); + if (r < ARCHIVE_WARN) { + file_free(file); + return (r); + } + if (file->size == 0 && file->dir) { + if (!__archive_rb_tree_insert_node(&(zip->rbtree), + (struct archive_rb_node *)file)) { + /* We have already had the same file. */ + file_free(file); + return (ARCHIVE_OK); + } + } + + if (file->flg & MTIME_IS_SET) + zip->total_number_time_defined[MTIME]++; + if (file->flg & CTIME_IS_SET) + zip->total_number_time_defined[CTIME]++; + if (file->flg & ATIME_IS_SET) + zip->total_number_time_defined[ATIME]++; + + zip->total_number_entry++; + zip->total_bytes_entry_name += file->name_len + 2; + if (file->size == 0) { + /* Count up the number of empty files. */ + zip->total_number_empty_entry++; + if (file->dir) + zip->total_number_dir_entry++; + else + file_register_empty(zip, file); + return (r); + } + + /* + * Init compression. + */ + if ((zip->total_number_entry - zip->total_number_empty_entry) == 1) { + r = _7z_compression_init_encoder(a, zip->opt_compression, + zip->opt_compression_level); + if (r < 0) { + file_free(file); + return (ARCHIVE_FATAL); + } + } + + /* Register a non-empty file. */ + file_register(zip, file); + + /* + * Set the current file to cur_file to read its contents. + */ + zip->cur_file = file; + + + /* Save a offset of current file in temporary file. */ + zip->entry_bytes_remaining = file->size; + zip->entry_crc32 = 0; + + /* + * Store a symbolic link name as file contents. + */ + if (archive_entry_filetype(entry) == AE_IFLNK) { + ssize_t bytes; + const void *p = (const void *)archive_entry_symlink(entry); + bytes = compress_out(a, p, (size_t)file->size, ARCHIVE_Z_RUN); + if (bytes < 0) + return ((int)bytes); + zip->entry_crc32 = crc32(zip->entry_crc32, p, (unsigned)bytes); + zip->entry_bytes_remaining -= bytes; + } + + return (r); +} + +/* + * Write data to a temporary file. + */ +static int +write_to_temp(struct archive_write *a, const void *buff, size_t s) +{ + struct _7zip *zip; + const unsigned char *p; + ssize_t ws; + + zip = (struct _7zip *)a->format_data; + + /* + * Open a temporary file. + */ + if (zip->temp_fd == -1) { + zip->temp_offset = 0; + zip->temp_fd = __archive_mktemp(NULL); + if (zip->temp_fd < 0) { + archive_set_error(&a->archive, errno, + "Couldn't create temporary file"); + return (ARCHIVE_FATAL); + } + } + + p = (const unsigned char *)buff; + while (s) { + ws = write(zip->temp_fd, p, s); + if (ws < 0) { + archive_set_error(&(a->archive), errno, + "fwrite function failed"); + return (ARCHIVE_FATAL); + } + s -= ws; + p += ws; + zip->temp_offset += ws; + } + return (ARCHIVE_OK); +} + +static ssize_t +compress_out(struct archive_write *a, const void *buff, size_t s, + enum la_zaction run) +{ + struct _7zip *zip = (struct _7zip *)a->format_data; + int r; + + if (run == ARCHIVE_Z_FINISH && zip->stream.total_in == 0 && s == 0) + return (0); + + if ((zip->crc32flg & PRECODE_CRC32) && s) + zip->precode_crc32 = crc32(zip->precode_crc32, buff, + (unsigned)s); + zip->stream.next_in = (const unsigned char *)buff; + zip->stream.avail_in = s; + for (;;) { + /* Compress file data. */ + r = compression_code(&(a->archive), &(zip->stream), run); + if (r != ARCHIVE_OK && r != ARCHIVE_EOF) + return (ARCHIVE_FATAL); + if (zip->stream.avail_out == 0) { + if (write_to_temp(a, zip->wbuff, sizeof(zip->wbuff)) + != ARCHIVE_OK) + return (ARCHIVE_FATAL); + zip->stream.next_out = zip->wbuff; + zip->stream.avail_out = sizeof(zip->wbuff); + if (zip->crc32flg & ENCODED_CRC32) + zip->encoded_crc32 = crc32(zip->encoded_crc32, + zip->wbuff, sizeof(zip->wbuff)); + if (run == ARCHIVE_Z_FINISH && r != ARCHIVE_EOF) + continue; + } + if (zip->stream.avail_in == 0) + break; + } + if (run == ARCHIVE_Z_FINISH) { + uint64_t bytes = sizeof(zip->wbuff) - zip->stream.avail_out; + if (write_to_temp(a, zip->wbuff, (size_t)bytes) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + if ((zip->crc32flg & ENCODED_CRC32) && bytes) + zip->encoded_crc32 = crc32(zip->encoded_crc32, + zip->wbuff, (unsigned)bytes); + } + + return (s); +} + +static ssize_t +_7z_write_data(struct archive_write *a, const void *buff, size_t s) +{ + struct _7zip *zip; + ssize_t bytes; + + zip = (struct _7zip *)a->format_data; + + if (s > zip->entry_bytes_remaining) + s = (size_t)zip->entry_bytes_remaining; + if (s == 0 || zip->cur_file == NULL) + return (0); + bytes = compress_out(a, buff, s, ARCHIVE_Z_RUN); + if (bytes < 0) + return (bytes); + zip->entry_crc32 = crc32(zip->entry_crc32, buff, (unsigned)bytes); + zip->entry_bytes_remaining -= bytes; + return (bytes); +} + +static int +_7z_finish_entry(struct archive_write *a) +{ + struct _7zip *zip; + size_t s; + ssize_t r; + + zip = (struct _7zip *)a->format_data; + if (zip->cur_file == NULL) + return (ARCHIVE_OK); + + while (zip->entry_bytes_remaining > 0) { + s = (size_t)zip->entry_bytes_remaining; + if (s > a->null_length) + s = a->null_length; + r = _7z_write_data(a, a->nulls, s); + if (r < 0) + return ((int)r); + } + zip->total_bytes_compressed += zip->stream.total_in; + zip->total_bytes_uncompressed += zip->stream.total_out; + zip->cur_file->crc32 = zip->entry_crc32; + zip->cur_file = NULL; + + return (ARCHIVE_OK); +} + +static int +flush_wbuff(struct archive_write *a) +{ + struct _7zip *zip; + int r; + size_t s; + + zip = (struct _7zip *)a->format_data; + s = sizeof(zip->wbuff) - zip->wbuff_remaining; + r = __archive_write_output(a, zip->wbuff, s); + if (r != ARCHIVE_OK) + return (r); + zip->wbuff_remaining = sizeof(zip->wbuff); + return (r); +} + +static int +copy_out(struct archive_write *a, uint64_t offset, uint64_t length) +{ + struct _7zip *zip; + int r; + + zip = (struct _7zip *)a->format_data; + if (zip->temp_offset > 0 && + lseek(zip->temp_fd, offset, SEEK_SET) < 0) { + archive_set_error(&(a->archive), errno, "lseek failed"); + return (ARCHIVE_FATAL); + } + while (length) { + size_t rsize; + ssize_t rs; + unsigned char *wb; + + if (length > zip->wbuff_remaining) + rsize = zip->wbuff_remaining; + else + rsize = (size_t)length; + wb = zip->wbuff + (sizeof(zip->wbuff) - zip->wbuff_remaining); + rs = read(zip->temp_fd, wb, rsize); + if (rs < 0) { + archive_set_error(&(a->archive), errno, + "Can't read temporary file(%jd)", + (intmax_t)rs); + return (ARCHIVE_FATAL); + } + if (rs == 0) { + archive_set_error(&(a->archive), 0, + "Truncated 7-Zip archive"); + return (ARCHIVE_FATAL); + } + zip->wbuff_remaining -= rs; + length -= rs; + if (zip->wbuff_remaining == 0) { + r = flush_wbuff(a); + if (r != ARCHIVE_OK) + return (r); + } + } + return (ARCHIVE_OK); +} + +static int +_7z_close(struct archive_write *a) +{ + struct _7zip *zip; + unsigned char *wb; + uint64_t header_offset, header_size, header_unpacksize; + uint64_t length; + uint32_t header_crc32; + int r; + + zip = (struct _7zip *)a->format_data; + + if (zip->total_number_entry > 0) { + struct archive_rb_node *n; + uint64_t data_offset, data_size, data_unpacksize; + unsigned header_compression; + + r = (int)compress_out(a, NULL, 0, ARCHIVE_Z_FINISH); + if (r < 0) + return (r); + data_offset = 0; + data_size = zip->stream.total_out; + data_unpacksize = zip->stream.total_in; + zip->coder.codec = zip->opt_compression; + zip->coder.prop_size = zip->stream.prop_size; + zip->coder.props = zip->stream.props; + zip->stream.prop_size = 0; + zip->stream.props = NULL; + zip->total_number_nonempty_entry = + zip->total_number_entry - zip->total_number_empty_entry; + + /* Connect an empty file list. */ + if (zip->empty_list.first != NULL) { + *zip->file_list.last = zip->empty_list.first; + zip->file_list.last = zip->empty_list.last; + } + /* Connect a directory file list. */ + ARCHIVE_RB_TREE_FOREACH(n, &(zip->rbtree)) { + file_register(zip, (struct file *)n); + } + + /* + * NOTE: 7z command supports just LZMA1, LZMA2 and COPY for + * the compression type for encoding the header. + */ +#if HAVE_LZMA_H + header_compression = _7Z_LZMA1; + /* If the stored file is only one, do not encode the header. + * This is the same way 7z command does. */ + if (zip->total_number_entry == 1) + header_compression = _7Z_COPY; +#else + header_compression = _7Z_COPY; +#endif + r = _7z_compression_init_encoder(a, header_compression, 6); + if (r < 0) + return (r); + zip->crc32flg = PRECODE_CRC32; + zip->precode_crc32 = 0; + r = make_header(a, data_offset, data_size, data_unpacksize, + 1, &(zip->coder)); + if (r < 0) + return (r); + r = (int)compress_out(a, NULL, 0, ARCHIVE_Z_FINISH); + if (r < 0) + return (r); + header_offset = data_offset + data_size; + header_size = zip->stream.total_out; + header_crc32 = zip->precode_crc32; + header_unpacksize = zip->stream.total_in; + + if (header_compression != _7Z_COPY) { + /* + * Encode the header in order to reduce the size + * of the archive. + */ + free(zip->coder.props); + zip->coder.codec = header_compression; + zip->coder.prop_size = zip->stream.prop_size; + zip->coder.props = zip->stream.props; + zip->stream.prop_size = 0; + zip->stream.props = NULL; + + r = _7z_compression_init_encoder(a, _7Z_COPY, 0); + if (r < 0) + return (r); + zip->crc32flg = ENCODED_CRC32; + zip->encoded_crc32 = 0; + + /* + * Make EncodedHeader. + */ + r = enc_uint64(a, kEncodedHeader); + if (r < 0) + return (r); + r = make_streamsInfo(a, header_offset, header_size, + header_unpacksize, 1, &(zip->coder), 0, + header_crc32); + if (r < 0) + return (r); + r = (int)compress_out(a, NULL, 0, ARCHIVE_Z_FINISH); + if (r < 0) + return (r); + header_offset = header_offset + header_size; + header_size = zip->stream.total_out; + header_crc32 = zip->encoded_crc32; + } + zip->crc32flg = 0; + } else { + header_offset = header_size = 0; + header_crc32 = 0; + } + + length = zip->temp_offset; + + /* + * Make the zip header on wbuff(write buffer). + */ + wb = zip->wbuff; + zip->wbuff_remaining = sizeof(zip->wbuff); + memcpy(&wb[0], "7z\xBC\xAF\x27\x1C", 6); + wb[6] = 0;/* Major version. */ + wb[7] = 3;/* Minor version. */ + archive_le64enc(&wb[12], header_offset);/* Next Header Offset */ + archive_le64enc(&wb[20], header_size);/* Next Header Size */ + archive_le32enc(&wb[28], header_crc32);/* Next Header CRC */ + archive_le32enc(&wb[8], crc32(0, &wb[12], 20));/* Start Header CRC */ + zip->wbuff_remaining -= 32; + + /* + * Read all file contents and an encoded header from the temporary + * file and write out it. + */ + r = copy_out(a, 0, length); + if (r != ARCHIVE_OK) + return (r); + r = flush_wbuff(a); + return (r); +} + +/* + * Encode 64 bits value into 7-Zip's encoded UINT64 value. + */ +static int +enc_uint64(struct archive_write *a, uint64_t val) +{ + unsigned mask = 0x80; + uint8_t numdata[9]; + int i; + + numdata[0] = 0; + for (i = 1; i < (int)sizeof(numdata); i++) { + if (val < mask) { + numdata[0] |= (uint8_t)val; + break; + } + numdata[i] = (uint8_t)val; + val >>= 8; + numdata[0] |= mask; + mask >>= 1; + } + return ((int)compress_out(a, numdata, i, ARCHIVE_Z_RUN)); +} + +static int +make_substreamsInfo(struct archive_write *a, struct coder *coders) +{ + struct _7zip *zip = (struct _7zip *)a->format_data; + struct file *file; + int r; + + /* + * Make SubStreamsInfo. + */ + r = enc_uint64(a, kSubStreamsInfo); + if (r < 0) + return (r); + + if (zip->total_number_nonempty_entry > 1 && coders->codec != _7Z_COPY) { + /* + * Make NumUnPackStream. + */ + r = enc_uint64(a, kNumUnPackStream); + if (r < 0) + return (r); + + /* Write numUnpackStreams */ + r = enc_uint64(a, zip->total_number_nonempty_entry); + if (r < 0) + return (r); + + /* + * Make kSize. + */ + r = enc_uint64(a, kSize); + if (r < 0) + return (r); + file = zip->file_list.first; + for (;file != NULL; file = file->next) { + if (file->next == NULL || + file->next->size == 0) + break; + r = enc_uint64(a, file->size); + if (r < 0) + return (r); + } + } + + /* + * Make CRC. + */ + r = enc_uint64(a, kCRC); + if (r < 0) + return (r); + + + /* All are defined */ + r = enc_uint64(a, 1); + if (r < 0) + return (r); + file = zip->file_list.first; + for (;file != NULL; file = file->next) { + uint8_t crc[4]; + if (file->size == 0) + break; + archive_le32enc(crc, file->crc32); + r = (int)compress_out(a, crc, 4, ARCHIVE_Z_RUN); + if (r < 0) + return (r); + } + + /* Write End. */ + r = enc_uint64(a, kEnd); + if (r < 0) + return (r); + return (ARCHIVE_OK); +} + +static int +make_streamsInfo(struct archive_write *a, uint64_t offset, uint64_t pack_size, + uint64_t unpack_size, int num_coder, struct coder *coders, int substrm, + uint32_t header_crc) +{ + struct _7zip *zip = (struct _7zip *)a->format_data; + uint8_t codec_buff[8]; + int numFolders, fi; + int codec_size; + int i, r; + + if (coders->codec == _7Z_COPY) + numFolders = (int)zip->total_number_nonempty_entry; + else + numFolders = 1; + + /* + * Make PackInfo. + */ + r = enc_uint64(a, kPackInfo); + if (r < 0) + return (r); + + /* Write PackPos. */ + r = enc_uint64(a, offset); + if (r < 0) + return (r); + + /* Write NumPackStreams. */ + r = enc_uint64(a, numFolders); + if (r < 0) + return (r); + + /* Make Size. */ + r = enc_uint64(a, kSize); + if (r < 0) + return (r); + + if (numFolders > 1) { + struct file *file = zip->file_list.first; + for (;file != NULL; file = file->next) { + if (file->size == 0) + break; + r = enc_uint64(a, file->size); + if (r < 0) + return (r); + } + } else { + /* Write size. */ + r = enc_uint64(a, pack_size); + if (r < 0) + return (r); + } + + r = enc_uint64(a, kEnd); + if (r < 0) + return (r); + + /* + * Make UnPackInfo. + */ + r = enc_uint64(a, kUnPackInfo); + if (r < 0) + return (r); + + /* + * Make Folder. + */ + r = enc_uint64(a, kFolder); + if (r < 0) + return (r); + + /* Write NumFolders. */ + r = enc_uint64(a, numFolders); + if (r < 0) + return (r); + + /* Write External. */ + r = enc_uint64(a, 0); + if (r < 0) + return (r); + + for (fi = 0; fi < numFolders; fi++) { + /* Write NumCoders. */ + r = enc_uint64(a, num_coder); + if (r < 0) + return (r); + + for (i = 0; i < num_coder; i++) { + unsigned codec_id = coders[i].codec; + + /* Write Codec flag. */ + archive_be64enc(codec_buff, codec_id); + for (codec_size = 8; codec_size > 0; codec_size--) { + if (codec_buff[8 - codec_size]) + break; + } + if (codec_size == 0) + codec_size = 1; + if (coders[i].prop_size) + r = enc_uint64(a, codec_size | 0x20); + else + r = enc_uint64(a, codec_size); + if (r < 0) + return (r); + + /* Write Codec ID. */ + codec_size &= 0x0f; + r = (int)compress_out(a, &codec_buff[8-codec_size], + codec_size, ARCHIVE_Z_RUN); + if (r < 0) + return (r); + + if (coders[i].prop_size) { + /* Write Codec property size. */ + r = enc_uint64(a, coders[i].prop_size); + if (r < 0) + return (r); + + /* Write Codec properties. */ + r = (int)compress_out(a, coders[i].props, + coders[i].prop_size, ARCHIVE_Z_RUN); + if (r < 0) + return (r); + } + } + } + + /* + * Make CodersUnPackSize. + */ + r = enc_uint64(a, kCodersUnPackSize); + if (r < 0) + return (r); + + if (numFolders > 1) { + struct file *file = zip->file_list.first; + for (;file != NULL; file = file->next) { + if (file->size == 0) + break; + r = enc_uint64(a, file->size); + if (r < 0) + return (r); + } + + } else { + /* Write UnPackSize. */ + r = enc_uint64(a, unpack_size); + if (r < 0) + return (r); + } + + if (!substrm) { + uint8_t crc[4]; + /* + * Make CRC. + */ + r = enc_uint64(a, kCRC); + if (r < 0) + return (r); + + /* All are defined */ + r = enc_uint64(a, 1); + if (r < 0) + return (r); + archive_le32enc(crc, header_crc); + r = (int)compress_out(a, crc, 4, ARCHIVE_Z_RUN); + if (r < 0) + return (r); + } + + /* Write End. */ + r = enc_uint64(a, kEnd); + if (r < 0) + return (r); + + if (substrm) { + /* + * Make SubStreamsInfo. + */ + r = make_substreamsInfo(a, coders); + if (r < 0) + return (r); + } + + + /* Write End. */ + r = enc_uint64(a, kEnd); + if (r < 0) + return (r); + + return (ARCHIVE_OK); +} + + +#define EPOC_TIME ARCHIVE_LITERAL_ULL(116444736000000000) +static uint64_t +utcToFiletime(time_t t, long ns) +{ + uint64_t fileTime; + + fileTime = t; + fileTime *= 10000000; + fileTime += ns / 100; + fileTime += EPOC_TIME; + return (fileTime); +} + +static int +make_time(struct archive_write *a, uint8_t type, unsigned flg, int ti) +{ + uint8_t filetime[8]; + struct _7zip *zip = (struct _7zip *)a->format_data; + struct file *file; + int r; + uint8_t b, mask; + + /* + * Make Time Bools. + */ + if (zip->total_number_time_defined[ti] == zip->total_number_entry) { + /* Write Time Type. */ + r = enc_uint64(a, type); + if (r < 0) + return (r); + /* Write EmptyStream Size. */ + r = enc_uint64(a, 2 + zip->total_number_entry * 8); + if (r < 0) + return (r); + /* All are defined. */ + r = enc_uint64(a, 1); + if (r < 0) + return (r); + } else { + if (zip->total_number_time_defined[ti] == 0) + return (ARCHIVE_OK); + + /* Write Time Type. */ + r = enc_uint64(a, type); + if (r < 0) + return (r); + /* Write EmptyStream Size. */ + r = enc_uint64(a, 2 + ((zip->total_number_entry + 7) >> 3) + + zip->total_number_time_defined[ti] * 8); + if (r < 0) + return (r); + + /* All are not defined. */ + r = enc_uint64(a, 0); + if (r < 0) + return (r); + + b = 0; + mask = 0x80; + file = zip->file_list.first; + for (;file != NULL; file = file->next) { + if (file->flg & flg) + b |= mask; + mask >>= 1; + if (mask == 0) { + r = (int)compress_out(a, &b, 1, ARCHIVE_Z_RUN); + if (r < 0) + return (r); + mask = 0x80; + b = 0; + } + } + if (mask != 0x80) { + r = (int)compress_out(a, &b, 1, ARCHIVE_Z_RUN); + if (r < 0) + return (r); + } + } + + /* External. */ + r = enc_uint64(a, 0); + if (r < 0) + return (r); + + + /* + * Make Times. + */ + file = zip->file_list.first; + for (;file != NULL; file = file->next) { + if ((file->flg & flg) == 0) + continue; + archive_le64enc(filetime, utcToFiletime(file->times[ti].time, + file->times[ti].time_ns)); + r = (int)compress_out(a, filetime, 8, ARCHIVE_Z_RUN); + if (r < 0) + return (r); + } + + return (ARCHIVE_OK); +} + +static int +make_header(struct archive_write *a, uint64_t offset, uint64_t pack_size, + uint64_t unpack_size, int codernum, struct coder *coders) +{ + struct _7zip *zip = (struct _7zip *)a->format_data; + struct file *file; + int r; + uint8_t b, mask; + + /* + * Make FilesInfo. + */ + r = enc_uint64(a, kHeader); + if (r < 0) + return (r); + + /* + * If there are empty files only, do not write MainStreamInfo. + */ + if (zip->total_number_nonempty_entry) { + /* + * Make MainStreamInfo. + */ + r = enc_uint64(a, kMainStreamsInfo); + if (r < 0) + return (r); + r = make_streamsInfo(a, offset, pack_size, unpack_size, + codernum, coders, 1, 0); + if (r < 0) + return (r); + } + + /* + * Make FilesInfo. + */ + r = enc_uint64(a, kFilesInfo); + if (r < 0) + return (r); + + /* Write numFiles. */ + r = enc_uint64(a, zip->total_number_entry); + if (r < 0) + return (r); + + if (zip->total_number_empty_entry > 0) { + /* Make EmptyStream. */ + r = enc_uint64(a, kEmptyStream); + if (r < 0) + return (r); + + /* Write EmptyStream Size. */ + r = enc_uint64(a, (zip->total_number_entry+7)>>3); + if (r < 0) + return (r); + + b = 0; + mask = 0x80; + file = zip->file_list.first; + for (;file != NULL; file = file->next) { + if (file->size == 0) + b |= mask; + mask >>= 1; + if (mask == 0) { + r = (int)compress_out(a, &b, 1, ARCHIVE_Z_RUN); + if (r < 0) + return (r); + mask = 0x80; + b = 0; + } + } + if (mask != 0x80) { + r = (int)compress_out(a, &b, 1, ARCHIVE_Z_RUN); + if (r < 0) + return (r); + } + } + + if (zip->total_number_empty_entry > zip->total_number_dir_entry) { + /* Make EmptyFile. */ + r = enc_uint64(a, kEmptyFile); + if (r < 0) + return (r); + + /* Write EmptyFile Size. */ + r = enc_uint64(a, (zip->total_number_empty_entry + 7) >> 3); + if (r < 0) + return (r); + + b = 0; + mask = 0x80; + file = zip->file_list.first; + for (;file != NULL; file = file->next) { + if (file->size) + continue; + if (!file->dir) + b |= mask; + mask >>= 1; + if (mask == 0) { + r = (int)compress_out(a, &b, 1, ARCHIVE_Z_RUN); + if (r < 0) + return (r); + mask = 0x80; + b = 0; + } + } + if (mask != 0x80) { + r = (int)compress_out(a, &b, 1, ARCHIVE_Z_RUN); + if (r < 0) + return (r); + } + } + + /* Make Name. */ + r = enc_uint64(a, kName); + if (r < 0) + return (r); + + /* Write Name size. */ + r = enc_uint64(a, zip->total_bytes_entry_name+1); + if (r < 0) + return (r); + + /* Write dmy byte. */ + r = enc_uint64(a, 0); + if (r < 0) + return (r); + + file = zip->file_list.first; + for (;file != NULL; file = file->next) { + r = (int)compress_out(a, file->utf16name, file->name_len+2, + ARCHIVE_Z_RUN); + if (r < 0) + return (r); + } + + /* Make MTime. */ + r = make_time(a, kMTime, MTIME_IS_SET, MTIME); + if (r < 0) + return (r); + + /* Make CTime. */ + r = make_time(a, kCTime, CTIME_IS_SET, CTIME); + if (r < 0) + return (r); + + /* Make ATime. */ + r = make_time(a, kATime, ATIME_IS_SET, ATIME); + if (r < 0) + return (r); + + /* Make Attributes. */ + r = enc_uint64(a, kAttributes); + if (r < 0) + return (r); + + /* Write Attributes size. */ + r = enc_uint64(a, 2 + zip->total_number_entry * 4); + if (r < 0) + return (r); + + /* Write "All Are Defined". */ + r = enc_uint64(a, 1); + if (r < 0) + return (r); + + /* Write dmy byte. */ + r = enc_uint64(a, 0); + if (r < 0) + return (r); + + file = zip->file_list.first; + for (;file != NULL; file = file->next) { + /* + * High 16bits is unix mode. + * Low 16bits is Windows attributes. + */ + uint32_t encattr, attr; + if (file->dir) + attr = 0x8010; + else + attr = 0x8020; + if ((file->mode & 0222) == 0) + attr |= 1;/* Read Only. */ + attr |= ((uint32_t)file->mode) << 16; + archive_le32enc(&encattr, attr); + r = (int)compress_out(a, &encattr, 4, ARCHIVE_Z_RUN); + if (r < 0) + return (r); + } + + /* Write End. */ + r = enc_uint64(a, kEnd); + if (r < 0) + return (r); + + /* Write End. */ + r = enc_uint64(a, kEnd); + if (r < 0) + return (r); + + return (ARCHIVE_OK); +} + + +static int +_7z_free(struct archive_write *a) +{ + struct _7zip *zip = (struct _7zip *)a->format_data; + + /* Close the temporary file. */ + if (zip->temp_fd >= 0) + close(zip->temp_fd); + + file_free_register(zip); + compression_end(&(a->archive), &(zip->stream)); + free(zip->coder.props); + free(zip); + + return (ARCHIVE_OK); +} + +static int +file_cmp_node(const struct archive_rb_node *n1, + const struct archive_rb_node *n2) +{ + const struct file *f1 = (const struct file *)n1; + const struct file *f2 = (const struct file *)n2; + + if (f1->name_len == f2->name_len) + return (memcmp(f1->utf16name, f2->utf16name, f1->name_len)); + return (f1->name_len > f2->name_len)?1:-1; +} + +static int +file_cmp_key(const struct archive_rb_node *n, const void *key) +{ + const struct file *f = (const struct file *)n; + + return (f->name_len - *(const char *)key); +} + +static int +file_new(struct archive_write *a, struct archive_entry *entry, + struct file **newfile) +{ + struct _7zip *zip; + struct file *file; + const char *u16; + size_t u16len; + int ret = ARCHIVE_OK; + + zip = (struct _7zip *)a->format_data; + *newfile = NULL; + + file = calloc(1, sizeof(*file)); + if (file == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory"); + return (ARCHIVE_FATAL); + } + + if (0 > archive_entry_pathname_l(entry, &u16, &u16len, zip->sconv)) { + if (errno == ENOMEM) { + free(file); + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for UTF-16LE"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "A filename cannot be converted to UTF-16LE;" + "You should disable making Joliet extension"); + ret = ARCHIVE_WARN; + } + file->utf16name = malloc(u16len + 2); + if (file->utf16name == NULL) { + free(file); + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Name"); + return (ARCHIVE_FATAL); + } + memcpy(file->utf16name, u16, u16len); + file->utf16name[u16len+0] = 0; + file->utf16name[u16len+1] = 0; + file->name_len = (unsigned)u16len; + file->mode = archive_entry_mode(entry); + if (archive_entry_filetype(entry) == AE_IFREG) + file->size = archive_entry_size(entry); + else + archive_entry_set_size(entry, 0); + if (archive_entry_filetype(entry) == AE_IFDIR) + file->dir = 1; + else if (archive_entry_filetype(entry) == AE_IFLNK) + file->size = strlen(archive_entry_symlink(entry)); + if (archive_entry_mtime_is_set(entry)) { + file->flg |= MTIME_IS_SET; + file->times[MTIME].time = archive_entry_mtime(entry); + file->times[MTIME].time_ns = archive_entry_mtime_nsec(entry); + } + if (archive_entry_atime_is_set(entry)) { + file->flg |= ATIME_IS_SET; + file->times[ATIME].time = archive_entry_atime(entry); + file->times[ATIME].time_ns = archive_entry_atime_nsec(entry); + } + if (archive_entry_ctime_is_set(entry)) { + file->flg |= CTIME_IS_SET; + file->times[CTIME].time = archive_entry_ctime(entry); + file->times[CTIME].time_ns = archive_entry_ctime_nsec(entry); + } + + *newfile = file; + return (ret); +} + +static void +file_free(struct file *file) +{ + free(file->utf16name); + free(file); +} + +static void +file_register(struct _7zip *zip, struct file *file) +{ + file->next = NULL; + *zip->file_list.last = file; + zip->file_list.last = &(file->next); +} + +static void +file_init_register(struct _7zip *zip) +{ + zip->file_list.first = NULL; + zip->file_list.last = &(zip->file_list.first); +} + +static void +file_free_register(struct _7zip *zip) +{ + struct file *file, *file_next; + + file = zip->file_list.first; + while (file != NULL) { + file_next = file->next; + file_free(file); + file = file_next; + } +} + +static void +file_register_empty(struct _7zip *zip, struct file *file) +{ + file->next = NULL; + *zip->empty_list.last = file; + zip->empty_list.last = &(file->next); +} + +static void +file_init_register_empty(struct _7zip *zip) +{ + zip->empty_list.first = NULL; + zip->empty_list.last = &(zip->empty_list.first); +} + +#if !defined(HAVE_ZLIB_H) || !defined(HAVE_BZLIB_H) ||\ + !defined(BZ_CONFIG_ERROR) || !defined(HAVE_LZMA_H) +static int +compression_unsupported_encoder(struct archive *a, + struct la_zstream *lastrm, const char *name) +{ + + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "%s compression not supported on this platform", name); + lastrm->valid = 0; + lastrm->real_stream = NULL; + return (ARCHIVE_FAILED); +} +#endif + +/* + * _7_COPY compressor. + */ +static int +compression_init_encoder_copy(struct archive *a, struct la_zstream *lastrm) +{ + + if (lastrm->valid) + compression_end(a, lastrm); + lastrm->valid = 1; + lastrm->code = compression_code_copy; + lastrm->end = compression_end_copy; + return (ARCHIVE_OK); +} + +static int +compression_code_copy(struct archive *a, + struct la_zstream *lastrm, enum la_zaction action) +{ + size_t bytes; + + (void)a; /* UNUSED */ + if (lastrm->avail_out > lastrm->avail_in) + bytes = lastrm->avail_in; + else + bytes = lastrm->avail_out; + if (bytes) { + memcpy(lastrm->next_out, lastrm->next_in, bytes); + lastrm->next_in += bytes; + lastrm->avail_in -= bytes; + lastrm->total_in += bytes; + lastrm->next_out += bytes; + lastrm->avail_out -= bytes; + lastrm->total_out += bytes; + } + if (action == ARCHIVE_Z_FINISH && lastrm->avail_in == 0) + return (ARCHIVE_EOF); + return (ARCHIVE_OK); +} + +static int +compression_end_copy(struct archive *a, struct la_zstream *lastrm) +{ + (void)a; /* UNUSED */ + lastrm->valid = 0; + return (ARCHIVE_OK); +} + +/* + * _7_DEFLATE compressor. + */ +#ifdef HAVE_ZLIB_H +static int +compression_init_encoder_deflate(struct archive *a, + struct la_zstream *lastrm, int level, int withheader) +{ + z_stream *strm; + + if (lastrm->valid) + compression_end(a, lastrm); + strm = calloc(1, sizeof(*strm)); + if (strm == NULL) { + archive_set_error(a, ENOMEM, + "Can't allocate memory for gzip stream"); + return (ARCHIVE_FATAL); + } + /* zlib.h is not const-correct, so we need this one bit + * of ugly hackery to convert a const * pointer to + * a non-const pointer. */ + strm->next_in = (Bytef *)(uintptr_t)(const void *)lastrm->next_in; + strm->avail_in = (uInt)lastrm->avail_in; + strm->total_in = (uLong)lastrm->total_in; + strm->next_out = lastrm->next_out; + strm->avail_out = (uInt)lastrm->avail_out; + strm->total_out = (uLong)lastrm->total_out; + if (deflateInit2(strm, level, Z_DEFLATED, + (withheader)?15:-15, + 8, Z_DEFAULT_STRATEGY) != Z_OK) { + free(strm); + lastrm->real_stream = NULL; + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "Internal error initializing compression library"); + return (ARCHIVE_FATAL); + } + lastrm->real_stream = strm; + lastrm->valid = 1; + lastrm->code = compression_code_deflate; + lastrm->end = compression_end_deflate; + return (ARCHIVE_OK); +} + +static int +compression_code_deflate(struct archive *a, + struct la_zstream *lastrm, enum la_zaction action) +{ + z_stream *strm; + int r; + + strm = (z_stream *)lastrm->real_stream; + /* zlib.h is not const-correct, so we need this one bit + * of ugly hackery to convert a const * pointer to + * a non-const pointer. */ + strm->next_in = (Bytef *)(uintptr_t)(const void *)lastrm->next_in; + strm->avail_in = (uInt)lastrm->avail_in; + strm->total_in = (uLong)lastrm->total_in; + strm->next_out = lastrm->next_out; + strm->avail_out = (uInt)lastrm->avail_out; + strm->total_out = (uLong)lastrm->total_out; + r = deflate(strm, + (action == ARCHIVE_Z_FINISH)? Z_FINISH: Z_NO_FLUSH); + lastrm->next_in = strm->next_in; + lastrm->avail_in = strm->avail_in; + lastrm->total_in = strm->total_in; + lastrm->next_out = strm->next_out; + lastrm->avail_out = strm->avail_out; + lastrm->total_out = strm->total_out; + switch (r) { + case Z_OK: + return (ARCHIVE_OK); + case Z_STREAM_END: + return (ARCHIVE_EOF); + default: + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "GZip compression failed:" + " deflate() call returned status %d", r); + return (ARCHIVE_FATAL); + } +} + +static int +compression_end_deflate(struct archive *a, struct la_zstream *lastrm) +{ + z_stream *strm; + int r; + + strm = (z_stream *)lastrm->real_stream; + r = deflateEnd(strm); + free(strm); + lastrm->real_stream = NULL; + lastrm->valid = 0; + if (r != Z_OK) { + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "Failed to clean up compressor"); + return (ARCHIVE_FATAL); + } + return (ARCHIVE_OK); +} +#else +static int +compression_init_encoder_deflate(struct archive *a, + struct la_zstream *lastrm, int level, int withheader) +{ + + (void) level; /* UNUSED */ + (void) withheader; /* UNUSED */ + if (lastrm->valid) + compression_end(a, lastrm); + return (compression_unsupported_encoder(a, lastrm, "deflate")); +} +#endif + +/* + * _7_BZIP2 compressor. + */ +#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) +static int +compression_init_encoder_bzip2(struct archive *a, + struct la_zstream *lastrm, int level) +{ + bz_stream *strm; + + if (lastrm->valid) + compression_end(a, lastrm); + strm = calloc(1, sizeof(*strm)); + if (strm == NULL) { + archive_set_error(a, ENOMEM, + "Can't allocate memory for bzip2 stream"); + return (ARCHIVE_FATAL); + } + /* bzlib.h is not const-correct, so we need this one bit + * of ugly hackery to convert a const * pointer to + * a non-const pointer. */ + strm->next_in = (char *)(uintptr_t)(const void *)lastrm->next_in; + strm->avail_in = lastrm->avail_in; + strm->total_in_lo32 = (uint32_t)(lastrm->total_in & 0xffffffff); + strm->total_in_hi32 = (uint32_t)(lastrm->total_in >> 32); + strm->next_out = (char *)lastrm->next_out; + strm->avail_out = lastrm->avail_out; + strm->total_out_lo32 = (uint32_t)(lastrm->total_out & 0xffffffff); + strm->total_out_hi32 = (uint32_t)(lastrm->total_out >> 32); + if (BZ2_bzCompressInit(strm, level, 0, 30) != BZ_OK) { + free(strm); + lastrm->real_stream = NULL; + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "Internal error initializing compression library"); + return (ARCHIVE_FATAL); + } + lastrm->real_stream = strm; + lastrm->valid = 1; + lastrm->code = compression_code_bzip2; + lastrm->end = compression_end_bzip2; + return (ARCHIVE_OK); +} + +static int +compression_code_bzip2(struct archive *a, + struct la_zstream *lastrm, enum la_zaction action) +{ + bz_stream *strm; + int r; + + strm = (bz_stream *)lastrm->real_stream; + /* bzlib.h is not const-correct, so we need this one bit + * of ugly hackery to convert a const * pointer to + * a non-const pointer. */ + strm->next_in = (char *)(uintptr_t)(const void *)lastrm->next_in; + strm->avail_in = lastrm->avail_in; + strm->total_in_lo32 = (uint32_t)(lastrm->total_in & 0xffffffff); + strm->total_in_hi32 = (uint32_t)(lastrm->total_in >> 32); + strm->next_out = (char *)lastrm->next_out; + strm->avail_out = lastrm->avail_out; + strm->total_out_lo32 = (uint32_t)(lastrm->total_out & 0xffffffff); + strm->total_out_hi32 = (uint32_t)(lastrm->total_out >> 32); + r = BZ2_bzCompress(strm, + (action == ARCHIVE_Z_FINISH)? BZ_FINISH: BZ_RUN); + lastrm->next_in = (const unsigned char *)strm->next_in; + lastrm->avail_in = strm->avail_in; + lastrm->total_in = + (((uint64_t)(uint32_t)strm->total_in_hi32) << 32) + + (uint64_t)(uint32_t)strm->total_in_lo32; + lastrm->next_out = (unsigned char *)strm->next_out; + lastrm->avail_out = strm->avail_out; + lastrm->total_out = + (((uint64_t)(uint32_t)strm->total_out_hi32) << 32) + + (uint64_t)(uint32_t)strm->total_out_lo32; + switch (r) { + case BZ_RUN_OK: /* Non-finishing */ + case BZ_FINISH_OK: /* Finishing: There's more work to do */ + return (ARCHIVE_OK); + case BZ_STREAM_END: /* Finishing: all done */ + /* Only occurs in finishing case */ + return (ARCHIVE_EOF); + default: + /* Any other return value indicates an error */ + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "Bzip2 compression failed:" + " BZ2_bzCompress() call returned status %d", r); + return (ARCHIVE_FATAL); + } +} + +static int +compression_end_bzip2(struct archive *a, struct la_zstream *lastrm) +{ + bz_stream *strm; + int r; + + strm = (bz_stream *)lastrm->real_stream; + r = BZ2_bzCompressEnd(strm); + free(strm); + lastrm->real_stream = NULL; + lastrm->valid = 0; + if (r != BZ_OK) { + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "Failed to clean up compressor"); + return (ARCHIVE_FATAL); + } + return (ARCHIVE_OK); +} + +#else +static int +compression_init_encoder_bzip2(struct archive *a, + struct la_zstream *lastrm, int level) +{ + + (void) level; /* UNUSED */ + if (lastrm->valid) + compression_end(a, lastrm); + return (compression_unsupported_encoder(a, lastrm, "bzip2")); +} +#endif + +/* + * _7_LZMA1, _7_LZMA2 compressor. + */ +#if defined(HAVE_LZMA_H) +static int +compression_init_encoder_lzma(struct archive *a, + struct la_zstream *lastrm, int level, uint64_t filter_id) +{ + static const lzma_stream lzma_init_data = LZMA_STREAM_INIT; + lzma_stream *strm; + lzma_filter *lzmafilters; + lzma_options_lzma lzma_opt; + int r; + + if (lastrm->valid) + compression_end(a, lastrm); + strm = calloc(1, sizeof(*strm) + sizeof(*lzmafilters) * 2); + if (strm == NULL) { + archive_set_error(a, ENOMEM, + "Can't allocate memory for lzma stream"); + return (ARCHIVE_FATAL); + } + lzmafilters = (lzma_filter *)(strm+1); + if (level > 6) + level = 6; + if (lzma_lzma_preset(&lzma_opt, level)) { + free(strm); + lastrm->real_stream = NULL; + archive_set_error(a, ENOMEM, + "Internal error initializing compression library"); + return (ARCHIVE_FATAL); + } + lzmafilters[0].id = filter_id; + lzmafilters[0].options = &lzma_opt; + lzmafilters[1].id = LZMA_VLI_UNKNOWN;/* Terminate */ + + r = lzma_properties_size(&(lastrm->prop_size), lzmafilters); + if (r != LZMA_OK) { + free(strm); + lastrm->real_stream = NULL; + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "lzma_properties_size failed"); + return (ARCHIVE_FATAL); + } + if (lastrm->prop_size) { + lastrm->props = malloc(lastrm->prop_size); + if (lastrm->props == NULL) { + free(strm); + lastrm->real_stream = NULL; + archive_set_error(a, ENOMEM, + "Cannot allocate memory"); + return (ARCHIVE_FATAL); + } + r = lzma_properties_encode(lzmafilters, lastrm->props); + if (r != LZMA_OK) { + free(strm); + lastrm->real_stream = NULL; + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "lzma_properties_encode failed"); + return (ARCHIVE_FATAL); + } + } + + *strm = lzma_init_data; + r = lzma_raw_encoder(strm, lzmafilters); + switch (r) { + case LZMA_OK: + lastrm->real_stream = strm; + lastrm->valid = 1; + lastrm->code = compression_code_lzma; + lastrm->end = compression_end_lzma; + r = ARCHIVE_OK; + break; + case LZMA_MEM_ERROR: + free(strm); + lastrm->real_stream = NULL; + archive_set_error(a, ENOMEM, + "Internal error initializing compression library: " + "Cannot allocate memory"); + r = ARCHIVE_FATAL; + break; + default: + free(strm); + lastrm->real_stream = NULL; + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "Internal error initializing compression library: " + "It's a bug in liblzma"); + r = ARCHIVE_FATAL; + break; + } + return (r); +} + +static int +compression_init_encoder_lzma1(struct archive *a, + struct la_zstream *lastrm, int level) +{ + return compression_init_encoder_lzma(a, lastrm, level, + LZMA_FILTER_LZMA1); +} + +static int +compression_init_encoder_lzma2(struct archive *a, + struct la_zstream *lastrm, int level) +{ + return compression_init_encoder_lzma(a, lastrm, level, + LZMA_FILTER_LZMA2); +} + +static int +compression_code_lzma(struct archive *a, + struct la_zstream *lastrm, enum la_zaction action) +{ + lzma_stream *strm; + int r; + + strm = (lzma_stream *)lastrm->real_stream; + strm->next_in = lastrm->next_in; + strm->avail_in = lastrm->avail_in; + strm->total_in = lastrm->total_in; + strm->next_out = lastrm->next_out; + strm->avail_out = lastrm->avail_out; + strm->total_out = lastrm->total_out; + r = lzma_code(strm, + (action == ARCHIVE_Z_FINISH)? LZMA_FINISH: LZMA_RUN); + lastrm->next_in = strm->next_in; + lastrm->avail_in = strm->avail_in; + lastrm->total_in = strm->total_in; + lastrm->next_out = strm->next_out; + lastrm->avail_out = strm->avail_out; + lastrm->total_out = strm->total_out; + switch (r) { + case LZMA_OK: + /* Non-finishing case */ + return (ARCHIVE_OK); + case LZMA_STREAM_END: + /* This return can only occur in finishing case. */ + return (ARCHIVE_EOF); + case LZMA_MEMLIMIT_ERROR: + archive_set_error(a, ENOMEM, + "lzma compression error:" + " %ju MiB would have been needed", + (uintmax_t)((lzma_memusage(strm) + 1024 * 1024 -1) + / (1024 * 1024))); + return (ARCHIVE_FATAL); + default: + /* Any other return value indicates an error */ + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "lzma compression failed:" + " lzma_code() call returned status %d", r); + return (ARCHIVE_FATAL); + } +} + +static int +compression_end_lzma(struct archive *a, struct la_zstream *lastrm) +{ + lzma_stream *strm; + + (void)a; /* UNUSED */ + strm = (lzma_stream *)lastrm->real_stream; + lzma_end(strm); + free(strm); + lastrm->valid = 0; + lastrm->real_stream = NULL; + return (ARCHIVE_OK); +} +#else +static int +compression_init_encoder_lzma1(struct archive *a, + struct la_zstream *lastrm, int level) +{ + + (void) level; /* UNUSED */ + if (lastrm->valid) + compression_end(a, lastrm); + return (compression_unsupported_encoder(a, lastrm, "lzma")); +} +static int +compression_init_encoder_lzma2(struct archive *a, + struct la_zstream *lastrm, int level) +{ + + (void) level; /* UNUSED */ + if (lastrm->valid) + compression_end(a, lastrm); + return (compression_unsupported_encoder(a, lastrm, "lzma")); +} +#endif + +/* + * _7_PPMD compressor. + */ - static void * - ppmd_alloc(void *p, size_t size) - { - (void)p; - return malloc(size); - } - static void - ppmd_free(void *p, void *address) - { - (void)p; - free(address); - } - static ISzAlloc g_szalloc = { ppmd_alloc, ppmd_free }; +static void +ppmd_write(void *p, Byte b) +{ + struct archive_write *a = ((IByteOut *)p)->a; + struct _7zip *zip = (struct _7zip *)(a->format_data); + struct la_zstream *lastrm = &(zip->stream); + struct ppmd_stream *strm; + + if (lastrm->avail_out) { + *lastrm->next_out++ = b; + lastrm->avail_out--; + lastrm->total_out++; + return; + } + strm = (struct ppmd_stream *)lastrm->real_stream; + if (strm->buff_ptr < strm->buff_end) { + *strm->buff_ptr++ = b; + strm->buff_bytes++; + } +} + +static int +compression_init_encoder_ppmd(struct archive *a, + struct la_zstream *lastrm, unsigned maxOrder, uint32_t msize) +{ + struct ppmd_stream *strm; + uint8_t *props; + int r; + + if (lastrm->valid) + compression_end(a, lastrm); + strm = calloc(1, sizeof(*strm)); + if (strm == NULL) { + archive_set_error(a, ENOMEM, + "Can't allocate memory for PPMd"); + return (ARCHIVE_FATAL); + } + strm->buff = malloc(32); + if (strm->buff == NULL) { + free(strm); + archive_set_error(a, ENOMEM, + "Can't allocate memory for PPMd"); + return (ARCHIVE_FATAL); + } + strm->buff_ptr = strm->buff; + strm->buff_end = strm->buff + 32; + + props = malloc(1+4); + if (props == NULL) { + free(strm->buff); + free(strm); + archive_set_error(a, ENOMEM, + "Coludn't allocate memory for PPMd"); + return (ARCHIVE_FATAL); + } + props[0] = maxOrder; + archive_le32enc(props+1, msize); + __archive_ppmd7_functions.Ppmd7_Construct(&strm->ppmd7_context); + r = __archive_ppmd7_functions.Ppmd7_Alloc( - &strm->ppmd7_context, msize, &g_szalloc); ++ &strm->ppmd7_context, msize); + if (r == 0) { + free(strm->buff); + free(strm); + free(props); + archive_set_error(a, ENOMEM, + "Coludn't allocate memory for PPMd"); + return (ARCHIVE_FATAL); + } + __archive_ppmd7_functions.Ppmd7_Init(&(strm->ppmd7_context), maxOrder); + strm->byteout.a = (struct archive_write *)a; + strm->byteout.Write = ppmd_write; + strm->range_enc.Stream = &(strm->byteout); + __archive_ppmd7_functions.Ppmd7z_RangeEnc_Init(&(strm->range_enc)); + strm->stat = 0; + + lastrm->real_stream = strm; + lastrm->valid = 1; + lastrm->code = compression_code_ppmd; + lastrm->end = compression_end_ppmd; + lastrm->prop_size = 5; + lastrm->props = props; + return (ARCHIVE_OK); +} + +static int +compression_code_ppmd(struct archive *a, + struct la_zstream *lastrm, enum la_zaction action) +{ + struct ppmd_stream *strm; + + (void)a; /* UNUSED */ + + strm = (struct ppmd_stream *)lastrm->real_stream; + + /* Copy encoded data if there are remaining bytes from previous call. */ + if (strm->buff_bytes) { + uint8_t *p = strm->buff_ptr - strm->buff_bytes; + while (lastrm->avail_out && strm->buff_bytes) { + *lastrm->next_out++ = *p++; + lastrm->avail_out--; + lastrm->total_out++; + strm->buff_bytes--; + } + if (strm->buff_bytes) + return (ARCHIVE_OK); + if (strm->stat == 1) + return (ARCHIVE_EOF); + strm->buff_ptr = strm->buff; + } + while (lastrm->avail_in && lastrm->avail_out) { + __archive_ppmd7_functions.Ppmd7_EncodeSymbol( + &(strm->ppmd7_context), &(strm->range_enc), + *lastrm->next_in++); + lastrm->avail_in--; + lastrm->total_in++; + } + if (lastrm->avail_in == 0 && action == ARCHIVE_Z_FINISH) { + __archive_ppmd7_functions.Ppmd7z_RangeEnc_FlushData( + &(strm->range_enc)); + strm->stat = 1; + /* Return EOF if there are no remaining bytes. */ + if (strm->buff_bytes == 0) + return (ARCHIVE_EOF); + } + return (ARCHIVE_OK); +} + +static int +compression_end_ppmd(struct archive *a, struct la_zstream *lastrm) +{ + struct ppmd_stream *strm; + + (void)a; /* UNUSED */ + + strm = (struct ppmd_stream *)lastrm->real_stream; - __archive_ppmd7_functions.Ppmd7_Free(&strm->ppmd7_context, &g_szalloc); ++ __archive_ppmd7_functions.Ppmd7_Free(&strm->ppmd7_context); + free(strm->buff); + free(strm); + lastrm->real_stream = NULL; + lastrm->valid = 0; + return (ARCHIVE_OK); +} + +/* + * Universal compressor initializer. + */ +static int +_7z_compression_init_encoder(struct archive_write *a, unsigned compression, + int compression_level) +{ + struct _7zip *zip; + int r; + + zip = (struct _7zip *)a->format_data; + switch (compression) { + case _7Z_DEFLATE: + r = compression_init_encoder_deflate( + &(a->archive), &(zip->stream), + compression_level, 0); + break; + case _7Z_BZIP2: + r = compression_init_encoder_bzip2( + &(a->archive), &(zip->stream), + compression_level); + break; + case _7Z_LZMA1: + r = compression_init_encoder_lzma1( + &(a->archive), &(zip->stream), + compression_level); + break; + case _7Z_LZMA2: + r = compression_init_encoder_lzma2( + &(a->archive), &(zip->stream), + compression_level); + break; + case _7Z_PPMD: + r = compression_init_encoder_ppmd( + &(a->archive), &(zip->stream), + PPMD7_DEFAULT_ORDER, PPMD7_DEFAULT_MEM_SIZE); + break; + case _7Z_COPY: + default: + r = compression_init_encoder_copy( + &(a->archive), &(zip->stream)); + break; + } + if (r == ARCHIVE_OK) { + zip->stream.total_in = 0; + zip->stream.next_out = zip->wbuff; + zip->stream.avail_out = sizeof(zip->wbuff); + zip->stream.total_out = 0; + } + + return (r); +} + +static int +compression_code(struct archive *a, struct la_zstream *lastrm, + enum la_zaction action) +{ + if (lastrm->valid) + return (lastrm->code(a, lastrm, action)); + return (ARCHIVE_OK); +} + +static int +compression_end(struct archive *a, struct la_zstream *lastrm) +{ + if (lastrm->valid) { + lastrm->prop_size = 0; + free(lastrm->props); + lastrm->props = NULL; + return (lastrm->end(a, lastrm)); + } + return (ARCHIVE_OK); +} + + https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=2aaed7a05053c3bcbebbff5ae1beb51e590b3ad1 commit 2aaed7a05053c3bcbebbff5ae1beb51e590b3ad1 Author: LibArchive Upstream AuthorDate: Mon Sep 3 20:07:16 2018 -0700 Commit: Brad King CommitDate: Wed Sep 26 09:52:15 2018 -0400 LibArchive 2018-09-03 (5fe69dd0) Code extracted from: https://github.com/libarchive/libarchive.git at commit 5fe69dd018745a88eecf1f7db40daf12d26f7ed0 (v3.3.3). diff --git a/CMakeLists.txt b/CMakeLists.txt index 73bf07b..80871bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -179,6 +179,7 @@ include(CTest) OPTION(ENABLE_NETTLE "Enable use of Nettle" ON) OPTION(ENABLE_OPENSSL "Enable use of OpenSSL" ON) +OPTION(ENABLE_LZ4 "Enable the use of the system LZ4 library if found" ON) OPTION(ENABLE_LZO "Enable the use of the system LZO library if found" OFF) OPTION(ENABLE_LZMA "Enable the use of the system LZMA library if found" ON) @@ -492,7 +493,7 @@ IF(ENABLE_LZO) INCLUDE(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(LZO2 DEFAULT_MSG LZO2_LIBRARY LZO2_INCLUDE_DIR) ELSE(ENABLE_LZO) - SET(LIBZMA_FOUND FALSE) # Override cached value + SET(LZO2_FOUND FALSE) # Override cached value ENDIF(ENABLE_LZO) IF(LZO2_FOUND) SET(HAVE_LIBLZO2 1) @@ -509,15 +510,19 @@ MARK_AS_ADVANCED(CLEAR LZO2_LIBRARY) # # Find LZ4 # -IF (LZ4_INCLUDE_DIR) - # Already in cache, be silent - SET(LZ4_FIND_QUIETLY TRUE) -ENDIF (LZ4_INCLUDE_DIR) +IF(ENABLE_LZ4) + IF (LZ4_INCLUDE_DIR) + # Already in cache, be silent + SET(LZ4_FIND_QUIETLY TRUE) + ENDIF (LZ4_INCLUDE_DIR) -FIND_PATH(LZ4_INCLUDE_DIR lz4.h) -FIND_LIBRARY(LZ4_LIBRARY NAMES lz4 liblz4) -INCLUDE(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(LZ4 DEFAULT_MSG LZ4_LIBRARY LZ4_INCLUDE_DIR) + FIND_PATH(LZ4_INCLUDE_DIR lz4.h) + FIND_LIBRARY(LZ4_LIBRARY NAMES lz4 liblz4) + INCLUDE(FindPackageHandleStandardArgs) + FIND_PACKAGE_HANDLE_STANDARD_ARGS(LZ4 DEFAULT_MSG LZ4_LIBRARY LZ4_INCLUDE_DIR) +ELSE(ENABLE_LZ4) + SET(LZ4_FOUND FALSE) # Override cached value +ENDIF(ENABLE_LZ4) IF(LZ4_FOUND) SET(HAVE_LIBLZ4 1) SET(HAVE_LZ4_H 1) @@ -533,6 +538,31 @@ IF(LZ4_FOUND) ENDIF(LZ4_FOUND) MARK_AS_ADVANCED(CLEAR LZ4_INCLUDE_DIR) MARK_AS_ADVANCED(CLEAR LZ4_LIBRARY) +# +# Find Zstd +# +IF (ZSTD_INCLUDE_DIR) + # Already in cache, be silent + SET(ZSTD_FIND_QUIETLY TRUE) +ENDIF (ZSTD_INCLUDE_DIR) + +FIND_PATH(ZSTD_INCLUDE_DIR zstd.h) +FIND_LIBRARY(ZSTD_LIBRARY NAMES zstd libzstd) +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(ZSTD DEFAULT_MSG ZSTD_LIBRARY ZSTD_INCLUDE_DIR) +IF(ZSTD_FOUND) + SET(HAVE_ZSTD_H 1) + INCLUDE_DIRECTORIES(${ZSTD_INCLUDE_DIR}) + LIST(APPEND ADDITIONAL_LIBS ${ZSTD_LIBRARY}) + SET(CMAKE_REQUIRED_LIBRARIES ${ZSTD_LIBRARY}) + SET(CMAKE_REQUIRED_INCLUDES ${ZSTD_INCLUDE_DIR}) + CHECK_FUNCTION_EXISTS(ZSTD_compressStream HAVE_LIBZSTD) + # + # TODO: test for static library. + # +ENDIF(ZSTD_FOUND) +MARK_AS_ADVANCED(CLEAR ZSTD_INCLUDE_DIR) +MARK_AS_ADVANCED(CLEAR ZSTD_LIBRARY) # # Check headers @@ -609,6 +639,7 @@ LA_CHECK_INCLUDE_FILE("sys/select.h" HAVE_SYS_SELECT_H) LA_CHECK_INCLUDE_FILE("sys/stat.h" HAVE_SYS_STAT_H) LA_CHECK_INCLUDE_FILE("sys/statfs.h" HAVE_SYS_STATFS_H) LA_CHECK_INCLUDE_FILE("sys/statvfs.h" HAVE_SYS_STATVFS_H) +LA_CHECK_INCLUDE_FILE("sys/sysmacros.h" HAVE_SYS_SYSMACROS_H) LA_CHECK_INCLUDE_FILE("sys/time.h" HAVE_SYS_TIME_H) LA_CHECK_INCLUDE_FILE("sys/utime.h" HAVE_SYS_UTIME_H) LA_CHECK_INCLUDE_FILE("sys/utsname.h" HAVE_SYS_UTSNAME_H) diff --git a/build/cmake/config.h.in b/build/cmake/config.h.in index e646213..04f938d 100644 --- a/build/cmake/config.h.in +++ b/build/cmake/config.h.in @@ -725,6 +725,9 @@ typedef uint64_t uintmax_t; /* Define to 1 if you have the `z' library (-lz). */ #cmakedefine HAVE_LIBZ 1 +/* Define to 1 if you have the `zstd' library (-lzstd). */ +#cmakedefine HAVE_LIBZSTD 1 + /* Define to 1 if you have the header file. */ #cmakedefine HAVE_LIMITS_H 1 @@ -1065,6 +1068,10 @@ typedef uint64_t uintmax_t; /* Define to 1 if you have the header file. */ #cmakedefine HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_SYSMACROS_H 1 + /* Define to 1 if you have the header file. */ #cmakedefine HAVE_SYS_TIME_H 1 @@ -1179,6 +1186,9 @@ typedef uint64_t uintmax_t; /* Define to 1 if you have the header file. */ #cmakedefine HAVE_ZLIB_H 1 +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_ZSTD_H 1 + /* Define to 1 if you have the `_ctime64_s' function. */ #cmakedefine HAVE__CTIME64_S 1 diff --git a/build/pkgconfig/libarchive.pc.in b/build/pkgconfig/libarchive.pc.in index 95d7159..4b631e6 100644 --- a/build/pkgconfig/libarchive.pc.in +++ b/build/pkgconfig/libarchive.pc.in @@ -7,5 +7,6 @@ Name: libarchive Description: library that can create and read several streaming archive formats Version: @VERSION@ Cflags: -I${includedir} +Cflags.private: -DLIBARCHIVE_STATIC Libs: -L${libdir} -larchive Libs.private: @LIBS@ diff --git a/build/version b/build/version index 2dd0839..2427eab 100644 --- a/build/version +++ b/build/version @@ -1 +1 @@ -3003002 +3003003 diff --git a/libarchive/CMakeLists.txt b/libarchive/CMakeLists.txt index 5e958da..82dd56c 100644 --- a/libarchive/CMakeLists.txt +++ b/libarchive/CMakeLists.txt @@ -88,6 +88,7 @@ SET(libarchive_SOURCES archive_read_support_filter_rpm.c archive_read_support_filter_uu.c archive_read_support_filter_xz.c + archive_read_support_filter_zstd.c archive_read_support_format_7zip.c archive_read_support_format_all.c archive_read_support_format_ar.c @@ -134,6 +135,7 @@ SET(libarchive_SOURCES archive_write_add_filter_program.c archive_write_add_filter_uuencode.c archive_write_add_filter_xz.c + archive_write_add_filter_zstd.c archive_write_set_format.c archive_write_set_format_7zip.c archive_write_set_format_ar.c diff --git a/libarchive/archive.h b/libarchive/archive.h index 316a68a..cdbbedd 100644 --- a/libarchive/archive.h +++ b/libarchive/archive.h @@ -36,7 +36,7 @@ * assert that ARCHIVE_VERSION_NUMBER >= 2012108. */ /* Note: Compiler will complain if this does not match archive_entry.h! */ -#define ARCHIVE_VERSION_NUMBER 3003002 +#define ARCHIVE_VERSION_NUMBER 3003003 #include #include /* for wchar_t */ @@ -155,7 +155,7 @@ __LA_DECL int archive_version_number(void); /* * Textual name/version of the library, useful for version displays. */ -#define ARCHIVE_VERSION_ONLY_STRING "3.3.2" +#define ARCHIVE_VERSION_ONLY_STRING "3.3.3" #define ARCHIVE_VERSION_STRING "libarchive " ARCHIVE_VERSION_ONLY_STRING __LA_DECL const char * archive_version_string(void); @@ -177,6 +177,7 @@ __LA_DECL const char * archive_zlib_version(void); __LA_DECL const char * archive_liblzma_version(void); __LA_DECL const char * archive_bzlib_version(void); __LA_DECL const char * archive_liblz4_version(void); +__LA_DECL const char * archive_libzstd_version(void); /* Declare our basic types. */ struct archive; @@ -276,6 +277,7 @@ typedef const char *archive_passphrase_callback(struct archive *, #define ARCHIVE_FILTER_LZOP 11 #define ARCHIVE_FILTER_GRZIP 12 #define ARCHIVE_FILTER_LZ4 13 +#define ARCHIVE_FILTER_ZSTD 14 #if ARCHIVE_VERSION_NUMBER < 4000000 #define ARCHIVE_COMPRESSION_NONE ARCHIVE_FILTER_NONE @@ -433,6 +435,7 @@ __LA_DECL int archive_read_support_filter_program_signature __LA_DECL int archive_read_support_filter_rpm(struct archive *); __LA_DECL int archive_read_support_filter_uu(struct archive *); __LA_DECL int archive_read_support_filter_xz(struct archive *); +__LA_DECL int archive_read_support_filter_zstd(struct archive *); __LA_DECL int archive_read_support_format_7zip(struct archive *); __LA_DECL int archive_read_support_format_all(struct archive *); @@ -778,6 +781,7 @@ __LA_DECL int archive_write_add_filter_program(struct archive *, const char *cmd); __LA_DECL int archive_write_add_filter_uuencode(struct archive *); __LA_DECL int archive_write_add_filter_xz(struct archive *); +__LA_DECL int archive_write_add_filter_zstd(struct archive *); /* A convenience function to set the format based on the code or name. */ diff --git a/libarchive/archive_acl.c b/libarchive/archive_acl.c index b8b6b63..4736531 100644 --- a/libarchive/archive_acl.c +++ b/libarchive/archive_acl.c @@ -1159,6 +1159,7 @@ archive_acl_from_text_w(struct archive_acl *acl, const wchar_t *text, switch (want_type) { case ARCHIVE_ENTRY_ACL_TYPE_POSIX1E: want_type = ARCHIVE_ENTRY_ACL_TYPE_ACCESS; + __LA_FALLTHROUGH; case ARCHIVE_ENTRY_ACL_TYPE_ACCESS: case ARCHIVE_ENTRY_ACL_TYPE_DEFAULT: numfields = 5; @@ -1626,6 +1627,7 @@ archive_acl_from_text_l(struct archive_acl *acl, const char *text, switch (want_type) { case ARCHIVE_ENTRY_ACL_TYPE_POSIX1E: want_type = ARCHIVE_ENTRY_ACL_TYPE_ACCESS; + __LA_FALLTHROUGH; case ARCHIVE_ENTRY_ACL_TYPE_ACCESS: case ARCHIVE_ENTRY_ACL_TYPE_DEFAULT: numfields = 5; diff --git a/libarchive/archive_cmdline.c b/libarchive/archive_cmdline.c index 7d3bac5..5c519cd 100644 --- a/libarchive/archive_cmdline.c +++ b/libarchive/archive_cmdline.c @@ -100,10 +100,10 @@ get_argument(struct archive_string *as, const char *p) /* * Set up command line arguments. - * Returns ARChIVE_OK if everything okey. - * Returns ARChIVE_FAILED if there is a lack of the `"' terminator or an + * Returns ARCHIVE_OK if everything okey. + * Returns ARCHIVE_FAILED if there is a lack of the `"' terminator or an * empty command line. - * Returns ARChIVE_FATAL if no memory. + * Returns ARCHIVE_FATAL if no memory. */ int __archive_cmdline_parse(struct archive_cmdline *data, const char *cmd) diff --git a/libarchive/archive_cryptor.c b/libarchive/archive_cryptor.c index ced52fd..71967c9 100644 --- a/libarchive/archive_cryptor.c +++ b/libarchive/archive_cryptor.c @@ -153,7 +153,7 @@ aes_ctr_encrypt_counter(archive_crypto_ctx *ctx) CCCryptorStatus r; r = CCCryptorReset(ref, NULL); - if (r != kCCSuccess) + if (r != kCCSuccess && r != kCCUnimplemented) return -1; r = CCCryptorUpdate(ref, ctx->nonce, AES_BLOCK_SIZE, ctx->encr_buf, AES_BLOCK_SIZE, NULL); diff --git a/libarchive/archive_cryptor_private.h b/libarchive/archive_cryptor_private.h index 0ca544b..b975922 100644 --- a/libarchive/archive_cryptor_private.h +++ b/libarchive/archive_cryptor_private.h @@ -64,7 +64,7 @@ typedef struct { } archive_crypto_ctx; #elif defined(_WIN32) && !defined(__CYGWIN__) && defined(HAVE_BCRYPT_H) -#include +#include /* Common in other bcrypt implementations, but missing from VS2008. */ #ifndef BCRYPT_SUCCESS diff --git a/libarchive/archive_disk_acl_freebsd.c b/libarchive/archive_disk_acl_freebsd.c index 07d08ff..aba41e5 100644 --- a/libarchive/archive_disk_acl_freebsd.c +++ b/libarchive/archive_disk_acl_freebsd.c @@ -93,7 +93,9 @@ static const acl_perm_map_t acl_nfs4_flag_map[] = { {ARCHIVE_ENTRY_ACL_ENTRY_INHERIT_ONLY, ACL_ENTRY_INHERIT_ONLY}, {ARCHIVE_ENTRY_ACL_ENTRY_SUCCESSFUL_ACCESS, ACL_ENTRY_SUCCESSFUL_ACCESS}, {ARCHIVE_ENTRY_ACL_ENTRY_FAILED_ACCESS, ACL_ENTRY_FAILED_ACCESS}, +#ifdef ACL_ENTRY_INHERITED {ARCHIVE_ENTRY_ACL_ENTRY_INHERITED, ACL_ENTRY_INHERITED} +#endif }; static const int acl_nfs4_flag_map_size = diff --git a/libarchive/archive_entry.c b/libarchive/archive_entry.c index 30fb456..f722bbe 100644 --- a/libarchive/archive_entry.c +++ b/libarchive/archive_entry.c @@ -1491,7 +1491,7 @@ archive_entry_acl_next(struct archive_entry *entry, int want_type, int *type, * the style of the generated ACL. */ wchar_t * -archive_entry_acl_to_text_w(struct archive_entry *entry, ssize_t *len, +archive_entry_acl_to_text_w(struct archive_entry *entry, la_ssize_t *len, int flags) { return (archive_acl_to_text_w(&entry->acl, len, flags, @@ -1499,7 +1499,7 @@ archive_entry_acl_to_text_w(struct archive_entry *entry, ssize_t *len, } char * -archive_entry_acl_to_text(struct archive_entry *entry, ssize_t *len, +archive_entry_acl_to_text(struct archive_entry *entry, la_ssize_t *len, int flags) { return (archive_acl_to_text_l(&entry->acl, len, flags, NULL)); diff --git a/libarchive/archive_entry.h b/libarchive/archive_entry.h index bcc2962..78a060c 100644 --- a/libarchive/archive_entry.h +++ b/libarchive/archive_entry.h @@ -30,7 +30,7 @@ #define ARCHIVE_ENTRY_H_INCLUDED /* Note: Compiler will complain if this does not match archive.h! */ -#define ARCHIVE_VERSION_NUMBER 3003002 +#define ARCHIVE_VERSION_NUMBER 3003003 /* * Note: archive_entry.h is for use outside of libarchive; the @@ -42,6 +42,7 @@ #include #include /* for wchar_t */ +#include #include #if defined(_WIN32) && !defined(__CYGWIN__) diff --git a/libarchive/archive_match.c b/libarchive/archive_match.c index be72066..f150e82 100644 --- a/libarchive/archive_match.c +++ b/libarchive/archive_match.c @@ -1582,7 +1582,7 @@ time_excluded(struct archive_match *a, struct archive_entry *entry) */ int -archive_match_include_uid(struct archive *_a, int64_t uid) +archive_match_include_uid(struct archive *_a, la_int64_t uid) { struct archive_match *a; @@ -1593,7 +1593,7 @@ archive_match_include_uid(struct archive *_a, int64_t uid) } int -archive_match_include_gid(struct archive *_a, int64_t gid) +archive_match_include_gid(struct archive *_a, la_int64_t gid) { struct archive_match *a; diff --git a/libarchive/archive_openssl_hmac_private.h b/libarchive/archive_openssl_hmac_private.h index 59f95b8..921249b 100644 --- a/libarchive/archive_openssl_hmac_private.h +++ b/libarchive/archive_openssl_hmac_private.h @@ -28,7 +28,8 @@ #include #include -#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER) +#if OPENSSL_VERSION_NUMBER < 0x10100000L || \ + (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x20700000L) #include /* malloc, free */ #include /* memset */ static inline HMAC_CTX *HMAC_CTX_new(void) diff --git a/libarchive/archive_pack_dev.c b/libarchive/archive_pack_dev.c index 098881b..53bddd7 100644 --- a/libarchive/archive_pack_dev.c +++ b/libarchive/archive_pack_dev.c @@ -57,6 +57,9 @@ __RCSID("$NetBSD$"); #ifdef HAVE_SYS_STAT_H #include #endif +#ifdef HAVE_SYS_SYSMACROS_H +#include +#endif #ifdef HAVE_UNISTD_H #include #endif diff --git a/libarchive/archive_platform.h b/libarchive/archive_platform.h index 34be8ed..32b884c 100644 --- a/libarchive/archive_platform.h +++ b/libarchive/archive_platform.h @@ -52,6 +52,17 @@ #error Oops: No config.h and no pre-built configuration in archive_platform.h. #endif +/* On macOS check for some symbols based on the deployment target version. */ +#if defined(__APPLE__) +# undef HAVE_FUTIMENS +# undef HAVE_UTIMENSAT +# include +# if MAC_OS_X_VERSION_MIN_REQUIRED >= 101300 +# define HAVE_FUTIMENS 1 +# define HAVE_UTIMENSAT 1 +# endif +#endif + /* It should be possible to get rid of this by extending the feature-test * macros to cover Windows API functions, probably along with non-trivial * refactoring of code to find structures that sit more cleanly on top of @@ -180,4 +191,10 @@ #define ARCHIVE_ERRNO_MISC (-1) #endif +#if defined(__GNUC__) && (__GNUC__ >= 7) +#define __LA_FALLTHROUGH __attribute__((fallthrough)) +#else +#define __LA_FALLTHROUGH +#endif + #endif /* !ARCHIVE_PLATFORM_H_INCLUDED */ diff --git a/libarchive/archive_ppmd7.c b/libarchive/archive_ppmd7.c index 1aed922..d0bacc6 100644 --- a/libarchive/archive_ppmd7.c +++ b/libarchive/archive_ppmd7.c @@ -115,14 +115,14 @@ static void Ppmd7_Construct(CPpmd7 *p) memset(p->HB2Flag + 0x40, 8, 0x100 - 0x40); } -static void Ppmd7_Free(CPpmd7 *p, ISzAlloc *alloc) +static void Ppmd7_Free(CPpmd7 *p) { - alloc->Free(alloc, p->Base); + free(p->Base); p->Size = 0; p->Base = 0; } -static Bool Ppmd7_Alloc(CPpmd7 *p, UInt32 size, ISzAlloc *alloc) +static Bool Ppmd7_Alloc(CPpmd7 *p, UInt32 size) { if (p->Base == 0 || p->Size != size) { @@ -131,14 +131,14 @@ static Bool Ppmd7_Alloc(CPpmd7 *p, UInt32 size, ISzAlloc *alloc) if (size < UNIT_SIZE) { return False; } - Ppmd7_Free(p, alloc); + Ppmd7_Free(p); p->AlignOffset = #ifdef PPMD_32BIT (4 - size) & 3; #else 4 - (size & 3); #endif - if ((p->Base = (Byte *)alloc->Alloc(alloc, p->AlignOffset + size + if ((p->Base = (Byte *)malloc(p->AlignOffset + size #ifndef PPMD_32BIT + UNIT_SIZE #endif diff --git a/libarchive/archive_ppmd7_private.h b/libarchive/archive_ppmd7_private.h index 06c99e8..577d6fb 100644 --- a/libarchive/archive_ppmd7_private.h +++ b/libarchive/archive_ppmd7_private.h @@ -95,8 +95,8 @@ typedef struct { /* Base Functions */ void (*Ppmd7_Construct)(CPpmd7 *p); - Bool (*Ppmd7_Alloc)(CPpmd7 *p, UInt32 size, ISzAlloc *alloc); - void (*Ppmd7_Free)(CPpmd7 *p, ISzAlloc *alloc); + Bool (*Ppmd7_Alloc)(CPpmd7 *p, UInt32 size); + void (*Ppmd7_Free)(CPpmd7 *p); void (*Ppmd7_Init)(CPpmd7 *p, unsigned maxOrder); #define Ppmd7_WasAllocated(p) ((p)->Base != NULL) diff --git a/libarchive/archive_ppmd_private.h b/libarchive/archive_ppmd_private.h index e78bde5..a83b851 100644 --- a/libarchive/archive_ppmd_private.h +++ b/libarchive/archive_ppmd_private.h @@ -69,13 +69,6 @@ typedef struct void (*Write)(void *p, Byte b); } IByteOut; - -typedef struct -{ - void *(*Alloc)(void *p, size_t size); - void (*Free)(void *p, void *address); /* address can be 0 */ -} ISzAlloc; - /*** End defined in Types.h ***/ /*** Begin defined in CpuArch.h ***/ diff --git a/libarchive/archive_read.c b/libarchive/archive_read.c index a642a33..0e56e76 100644 --- a/libarchive/archive_read.c +++ b/libarchive/archive_read.c @@ -120,7 +120,8 @@ archive_read_new(void) * Record the do-not-extract-to file. This belongs in archive_read_extract.c. */ void -archive_read_extract_set_skip_file(struct archive *_a, int64_t d, int64_t i) +archive_read_extract_set_skip_file(struct archive *_a, la_int64_t d, + la_int64_t i) { struct archive_read *a = (struct archive_read *)_a; @@ -747,7 +748,7 @@ choose_format(struct archive_read *a) * Return the file offset (within the uncompressed data stream) where * the last header started. */ -int64_t +la_int64_t archive_read_header_position(struct archive *_a) { struct archive_read *a = (struct archive_read *)_a; @@ -820,7 +821,7 @@ archive_read_format_capabilities(struct archive *_a) * DO NOT intermingle calls to this function and archive_read_data_block * to read a single entry body. */ -ssize_t +la_ssize_t archive_read_data(struct archive *_a, void *buff, size_t s) { struct archive *a = (struct archive *)_a; @@ -943,7 +944,7 @@ archive_read_data_skip(struct archive *_a) return (r); } -int64_t +la_int64_t archive_seek_data(struct archive *_a, int64_t offset, int whence) { struct archive_read *a = (struct archive_read *)_a; @@ -1626,7 +1627,8 @@ __archive_read_filter_seek(struct archive_read_filter *filter, int64_t offset, switch (whence) { case SEEK_CUR: /* Adjust the offset and use SEEK_SET instead */ - offset += filter->position; + offset += filter->position; + __LA_FALLTHROUGH; case SEEK_SET: cursor = 0; while (1) diff --git a/libarchive/archive_read_append_filter.c b/libarchive/archive_read_append_filter.c index 5e4d163..da7c55b 100644 --- a/libarchive/archive_read_append_filter.c +++ b/libarchive/archive_read_append_filter.c @@ -89,6 +89,10 @@ archive_read_append_filter(struct archive *_a, int code) strcpy(str, "lz4"); r1 = archive_read_support_filter_lz4(_a); break; + case ARCHIVE_FILTER_ZSTD: + strcpy(str, "zstd"); + r1 = archive_read_support_filter_zstd(_a); + break; case ARCHIVE_FILTER_LZIP: strcpy(str, "lzip"); r1 = archive_read_support_filter_lzip(_a); diff --git a/libarchive/archive_read_disk_entry_from_file.c b/libarchive/archive_read_disk_entry_from_file.c index 548ba89..1786cff 100644 --- a/libarchive/archive_read_disk_entry_from_file.c +++ b/libarchive/archive_read_disk_entry_from_file.c @@ -127,7 +127,7 @@ archive_read_disk_entry_setup_acls(struct archive_read_disk *a, /* * Enter working directory and return working pathname of archive_entry. * If a pointer to an integer is provided and its value is below zero - * open a file descriptor on this pahtname. + * open a file descriptor on this pathname. */ const char * archive_read_disk_entry_setup_path(struct archive_read_disk *a, diff --git a/libarchive/archive_read_disk_posix.c b/libarchive/archive_read_disk_posix.c index 6961ae6..cdf7541 100644 --- a/libarchive/archive_read_disk_posix.c +++ b/libarchive/archive_read_disk_posix.c @@ -387,7 +387,7 @@ archive_read_disk_vtable(void) } const char * -archive_read_disk_gname(struct archive *_a, int64_t gid) +archive_read_disk_gname(struct archive *_a, la_int64_t gid) { struct archive_read_disk *a = (struct archive_read_disk *)_a; if (ARCHIVE_OK != __archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, @@ -399,7 +399,7 @@ archive_read_disk_gname(struct archive *_a, int64_t gid) } const char * -archive_read_disk_uname(struct archive *_a, int64_t uid) +archive_read_disk_uname(struct archive *_a, la_int64_t uid) { struct archive_read_disk *a = (struct archive_read_disk *)_a; if (ARCHIVE_OK != __archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, @@ -413,7 +413,7 @@ archive_read_disk_uname(struct archive *_a, int64_t uid) int archive_read_disk_set_gname_lookup(struct archive *_a, void *private_data, - const char * (*lookup_gname)(void *private, int64_t gid), + const char * (*lookup_gname)(void *private, la_int64_t gid), void (*cleanup_gname)(void *private)) { struct archive_read_disk *a = (struct archive_read_disk *)_a; @@ -432,7 +432,7 @@ archive_read_disk_set_gname_lookup(struct archive *_a, int archive_read_disk_set_uname_lookup(struct archive *_a, void *private_data, - const char * (*lookup_uname)(void *private, int64_t uid), + const char * (*lookup_uname)(void *private, la_int64_t uid), void (*cleanup_uname)(void *private)) { struct archive_read_disk *a = (struct archive_read_disk *)_a; diff --git a/libarchive/archive_read_disk_windows.c b/libarchive/archive_read_disk_windows.c index 3b90330..d82048d 100644 --- a/libarchive/archive_read_disk_windows.c +++ b/libarchive/archive_read_disk_windows.c @@ -117,7 +117,7 @@ struct filesystem { */ #define MAX_OVERLAPPED 8 -#define BUFFER_SIZE (1024 * 8) +#define READ_BUFFER_SIZE (1024 * 64) /* Default to 64KB per https://technet.microsoft.com/en-us/library/cc938632.aspx */ #define DIRECT_IO 0/* Disabled */ #define ASYNC_IO 1/* Enabled */ @@ -320,7 +320,7 @@ archive_read_disk_vtable(void) } const char * -archive_read_disk_gname(struct archive *_a, int64_t gid) +archive_read_disk_gname(struct archive *_a, la_int64_t gid) { struct archive_read_disk *a = (struct archive_read_disk *)_a; if (ARCHIVE_OK != __archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, @@ -332,7 +332,7 @@ archive_read_disk_gname(struct archive *_a, int64_t gid) } const char * -archive_read_disk_uname(struct archive *_a, int64_t uid) +archive_read_disk_uname(struct archive *_a, la_int64_t uid) { struct archive_read_disk *a = (struct archive_read_disk *)_a; if (ARCHIVE_OK != __archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, @@ -346,7 +346,7 @@ archive_read_disk_uname(struct archive *_a, int64_t uid) int archive_read_disk_set_gname_lookup(struct archive *_a, void *private_data, - const char * (*lookup_gname)(void *private, int64_t gid), + const char * (*lookup_gname)(void *private, la_int64_t gid), void (*cleanup_gname)(void *private)) { struct archive_read_disk *a = (struct archive_read_disk *)_a; @@ -567,7 +567,7 @@ start_next_async_read(struct archive_read_disk *a, struct tree *t) /* Allocate read buffer. */ if (olp->buff == NULL) { void *p; - size_t s = (size_t)align_num_per_sector(t, BUFFER_SIZE); + size_t s = (size_t)align_num_per_sector(t, READ_BUFFER_SIZE); p = VirtualAlloc(NULL, s, MEM_COMMIT, PAGE_READWRITE); if (p == NULL) { archive_set_error(&a->archive, ENOMEM, @@ -683,7 +683,7 @@ _archive_read_data_block(struct archive *_a, const void **buff, break; } while (r == ARCHIVE_OK && t->ol_num_doing < MAX_OVERLAPPED); } else { - if (start_next_async_read(a, t) == ARCHIVE_FATAL) + if ((r = start_next_async_read(a, t)) == ARCHIVE_FATAL) goto abort_read_data; } @@ -923,6 +923,7 @@ next_entry(struct archive_read_disk *a, struct tree *t, t->entry_fh = CreateFileW(tree_current_access_path(t), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, flags, NULL); if (t->entry_fh == INVALID_HANDLE_VALUE) { + la_dosmaperr(GetLastError()); archive_set_error(&a->archive, errno, "Couldn't open %ls", tree_current_path(a->tree)); return (ARCHIVE_FAILED); @@ -2275,10 +2276,10 @@ setup_sparse_from_disk(struct archive_read_disk *a, if (range.Length.QuadPart > 0) continue; } else { - /* The remaining data is hole. */ + /* The entire file is a hole. Add one data block of size 0 at the end. */ archive_entry_sparse_add_entry(entry, - range.FileOffset.QuadPart, - range.Length.QuadPart); + entry_size, + 0); } break; } else { diff --git a/libarchive/archive_read_filter.3 b/libarchive/archive_read_filter.3 index 7f020e3..ef0a701 100644 --- a/libarchive/archive_read_filter.3 +++ b/libarchive/archive_read_filter.3 @@ -38,6 +38,7 @@ .Nm archive_read_support_filter_rpm , .Nm archive_read_support_filter_uu , .Nm archive_read_support_filter_xz , +.Nm archive_read_support_filter_zstd , .Nm archive_read_support_filter_program , .Nm archive_read_support_filter_program_signature .Nd functions for reading streaming archives @@ -73,6 +74,8 @@ Streaming Archive Library (libarchive, -larchive) .Ft int .Fn archive_read_support_filter_xz "struct archive *" .Ft int +.Fn archive_read_support_filter_zstd "struct archive *" +.Ft int .Fo archive_read_support_filter_program .Fa "struct archive *" .Fa "const char *cmd" @@ -99,7 +102,8 @@ Streaming Archive Library (libarchive, -larchive) .Fn archive_read_support_filter_none , .Fn archive_read_support_filter_rpm , .Fn archive_read_support_filter_uu , -.Fn archive_read_support_filter_xz +.Fn archive_read_support_filter_xz , +.Fn archive_read_support_filter_zstd , .Xc Enables auto-detection code and decompression support for the specified compression. diff --git a/libarchive/archive_read_support_filter_all.c b/libarchive/archive_read_support_filter_all.c index 68c53de..edb508c 100644 --- a/libarchive/archive_read_support_filter_all.c +++ b/libarchive/archive_read_support_filter_all.c @@ -71,6 +71,8 @@ archive_read_support_filter_all(struct archive *a) archive_read_support_filter_grzip(a); /* Lz4 falls back to "lz4 -d" command-line program. */ archive_read_support_filter_lz4(a); + /* Zstd falls back to "zstd -d" command-line program. */ + archive_read_support_filter_zstd(a); /* Note: We always return ARCHIVE_OK here, even if some of the * above return ARCHIVE_WARN. The intent here is to enable diff --git a/libarchive/archive_read_support_filter_zstd.c b/libarchive/archive_read_support_filter_zstd.c new file mode 100644 index 0000000..c8bb36b --- /dev/null +++ b/libarchive/archive_read_support_filter_zstd.c @@ -0,0 +1,292 @@ +/*- + * Copyright (c) 2009-2011 Sean Purcell + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "archive_platform.h" + +__FBSDID("$FreeBSD$"); + +#ifdef HAVE_ERRNO_H +#include +#endif + +#ifdef HAVE_ERRNO_H +#include +#endif +#include +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_UNISTD_H +#include +#endif +#if HAVE_ZSTD_H +#include +#endif + +#include "archive.h" +#include "archive_endian.h" +#include "archive_private.h" +#include "archive_read_private.h" + +#if HAVE_ZSTD_H && HAVE_LIBZSTD + +struct private_data { + ZSTD_DStream *dstream; + unsigned char *out_block; + size_t out_block_size; + int64_t total_out; + char in_frame; /* True = in the middle of a zstd frame. */ + char eof; /* True = found end of compressed data. */ +}; + +/* Zstd Filter. */ +static ssize_t zstd_filter_read(struct archive_read_filter *, const void**); +static int zstd_filter_close(struct archive_read_filter *); +#endif + +/* + * Note that we can detect zstd compressed files even if we can't decompress + * them. (In fact, we like detecting them because we can give better error + * messages.) So the bid framework here gets compiled even if no zstd library + * is available. + */ +static int zstd_bidder_bid(struct archive_read_filter_bidder *, + struct archive_read_filter *); +static int zstd_bidder_init(struct archive_read_filter *); + +int +archive_read_support_filter_zstd(struct archive *_a) +{ + struct archive_read *a = (struct archive_read *)_a; + struct archive_read_filter_bidder *bidder; + + archive_check_magic(_a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_filter_zstd"); + + if (__archive_read_get_bidder(a, &bidder) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + bidder->data = NULL; + bidder->name = "zstd"; + bidder->bid = zstd_bidder_bid; + bidder->init = zstd_bidder_init; + bidder->options = NULL; + bidder->free = NULL; +#if HAVE_ZSTD_H && HAVE_LIBZSTD + return (ARCHIVE_OK); +#else + archive_set_error(_a, ARCHIVE_ERRNO_MISC, + "Using external zstd program for zstd decompression"); + return (ARCHIVE_WARN); +#endif +} + +/* + * Test whether we can handle this data. + */ +static int +zstd_bidder_bid(struct archive_read_filter_bidder *self, + struct archive_read_filter *filter) +{ + const unsigned char *buffer; + ssize_t avail; + unsigned prefix; + + /* Zstd frame magic values */ + const unsigned zstd_magic = 0xFD2FB528U; + + (void) self; /* UNUSED */ + + buffer = __archive_read_filter_ahead(filter, 4, &avail); + if (buffer == NULL) + return (0); + + prefix = archive_le32dec(buffer); + if (prefix == zstd_magic) + return (32); + + return (0); +} + +#if !(HAVE_ZSTD_H && HAVE_LIBZSTD) + +/* + * If we don't have the library on this system, we can't do the + * decompression directly. We can, however, try to run "zstd -d" + * in case that's available. + */ +static int +zstd_bidder_init(struct archive_read_filter *self) +{ + int r; + + r = __archive_read_program(self, "zstd -d -qq"); + /* Note: We set the format here even if __archive_read_program() + * above fails. We do, after all, know what the format is + * even if we weren't able to read it. */ + self->code = ARCHIVE_FILTER_ZSTD; + self->name = "zstd"; + return (r); +} + +#else + +/* + * Initialize the filter object + */ +static int +zstd_bidder_init(struct archive_read_filter *self) +{ + struct private_data *state; + const size_t out_block_size = ZSTD_DStreamOutSize(); + void *out_block; + ZSTD_DStream *dstream; + + self->code = ARCHIVE_FILTER_ZSTD; + self->name = "zstd"; + + state = (struct private_data *)calloc(sizeof(*state), 1); + out_block = (unsigned char *)malloc(out_block_size); + dstream = ZSTD_createDStream(); + + if (state == NULL || out_block == NULL || dstream == NULL) { + free(out_block); + free(state); + ZSTD_freeDStream(dstream); /* supports free on NULL */ + archive_set_error(&self->archive->archive, ENOMEM, + "Can't allocate data for zstd decompression"); + return (ARCHIVE_FATAL); + } + + self->data = state; + + state->out_block_size = out_block_size; + state->out_block = out_block; + state->dstream = dstream; + self->read = zstd_filter_read; + self->skip = NULL; /* not supported */ + self->close = zstd_filter_close; + + state->eof = 0; + state->in_frame = 0; + + return (ARCHIVE_OK); +} + +static ssize_t +zstd_filter_read(struct archive_read_filter *self, const void **p) +{ + struct private_data *state; + size_t decompressed; + ssize_t avail_in; + ZSTD_outBuffer out; + ZSTD_inBuffer in; + + state = (struct private_data *)self->data; + + out = (ZSTD_outBuffer) { state->out_block, state->out_block_size, 0 }; + + /* Try to fill the output buffer. */ + while (out.pos < out.size && !state->eof) { + if (!state->in_frame) { + const size_t ret = ZSTD_initDStream(state->dstream); + if (ZSTD_isError(ret)) { + archive_set_error(&self->archive->archive, + ARCHIVE_ERRNO_MISC, + "Error initializing zstd decompressor: %s", + ZSTD_getErrorName(ret)); + return (ARCHIVE_FATAL); + } + } + in.src = __archive_read_filter_ahead(self->upstream, 1, + &avail_in); + if (avail_in < 0) { + return avail_in; + } + if (in.src == NULL && avail_in == 0) { + if (!state->in_frame) { + /* end of stream */ + state->eof = 1; + break; + } else { + archive_set_error(&self->archive->archive, + ARCHIVE_ERRNO_MISC, + "Truncated zstd input"); + return (ARCHIVE_FATAL); + } + } + in.size = avail_in; + in.pos = 0; + + { + const size_t ret = + ZSTD_decompressStream(state->dstream, &out, &in); + + if (ZSTD_isError(ret)) { + archive_set_error(&self->archive->archive, + ARCHIVE_ERRNO_MISC, + "Zstd decompression failed: %s", + ZSTD_getErrorName(ret)); + return (ARCHIVE_FATAL); + } + + /* Decompressor made some progress */ + __archive_read_filter_consume(self->upstream, in.pos); + + /* ret guaranteed to be > 0 if frame isn't done yet */ + state->in_frame = (ret != 0); + } + } + + decompressed = out.pos; + state->total_out += decompressed; + if (decompressed == 0) + *p = NULL; + else + *p = state->out_block; + return (decompressed); +} + +/* + * Clean up the decompressor. + */ +static int +zstd_filter_close(struct archive_read_filter *self) +{ + struct private_data *state; + + state = (struct private_data *)self->data; + + ZSTD_freeDStream(state->dstream); + free(state->out_block); + free(state); + + return (ARCHIVE_OK); +} + +#endif /* HAVE_ZLIB_H && HAVE_LIBZSTD */ diff --git a/libarchive/archive_read_support_format_7zip.c b/libarchive/archive_read_support_format_7zip.c index 3387eaf..bccbf89 100644 --- a/libarchive/archive_read_support_format_7zip.c +++ b/libarchive/archive_read_support_format_7zip.c @@ -975,18 +975,6 @@ decode_codec_id(const unsigned char *codecId, size_t id_size) return (id); } -static void * -ppmd_alloc(void *p, size_t size) -{ - (void)p; - return malloc(size); -} -static void -ppmd_free(void *p, void *address) -{ - (void)p; - free(address); -} static Byte ppmd_read(void *p) { @@ -1006,8 +994,6 @@ ppmd_read(void *p) return (b); } -static ISzAlloc g_szalloc = { ppmd_alloc, ppmd_free }; - static int init_decompression(struct archive_read *a, struct _7zip *zip, const struct _7z_coder *coder1, const struct _7z_coder *coder2) @@ -1237,7 +1223,7 @@ init_decompression(struct archive_read *a, struct _7zip *zip, if (zip->ppmd7_valid) { __archive_ppmd7_functions.Ppmd7_Free( - &zip->ppmd7_context, &g_szalloc); + &zip->ppmd7_context); zip->ppmd7_valid = 0; } @@ -1256,7 +1242,7 @@ init_decompression(struct archive_read *a, struct _7zip *zip, } __archive_ppmd7_functions.Ppmd7_Construct(&zip->ppmd7_context); r = __archive_ppmd7_functions.Ppmd7_Alloc( - &zip->ppmd7_context, msize, &g_szalloc); + &zip->ppmd7_context, msize); if (r == 0) { archive_set_error(&a->archive, ENOMEM, "Coludn't allocate memory for PPMd"); @@ -1636,7 +1622,7 @@ free_decompression(struct archive_read *a, struct _7zip *zip) #endif if (zip->ppmd7_valid) { __archive_ppmd7_functions.Ppmd7_Free( - &zip->ppmd7_context, &g_szalloc); + &zip->ppmd7_context); zip->ppmd7_valid = 0; } return (r); @@ -2569,6 +2555,7 @@ read_Header(struct archive_read *a, struct _7z_header_info *h, case kDummy: if (ll == 0) break; + __LA_FALLTHROUGH; default: if (header_bytes(a, ll) == NULL) return (-1); diff --git a/libarchive/archive_read_support_format_cpio.c b/libarchive/archive_read_support_format_cpio.c index ad9f782..67d5b21 100644 --- a/libarchive/archive_read_support_format_cpio.c +++ b/libarchive/archive_read_support_format_cpio.c @@ -633,6 +633,13 @@ header_newc(struct archive_read *a, struct cpio *cpio, /* Pad name to 2 more than a multiple of 4. */ *name_pad = (2 - *namelength) & 3; + /* Make sure that the padded name length fits into size_t. */ + if (*name_pad > SIZE_MAX - *namelength) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "cpio archive has invalid namelength"); + return (ARCHIVE_FATAL); + } + /* * Note: entry_bytes_remaining is at least 64 bits and * therefore guaranteed to be big enough for a 33-bit file diff --git a/libarchive/archive_read_support_format_iso9660.c b/libarchive/archive_read_support_format_iso9660.c index f01d37b..28acfef 100644 --- a/libarchive/archive_read_support_format_iso9660.c +++ b/libarchive/archive_read_support_format_iso9660.c @@ -409,7 +409,8 @@ static int next_entry_seek(struct archive_read *, struct iso9660 *, struct file_info **); static struct file_info * parse_file_info(struct archive_read *a, - struct file_info *parent, const unsigned char *isodirrec); + struct file_info *parent, const unsigned char *isodirrec, + size_t reclen); static int parse_rockridge(struct archive_read *a, struct file_info *file, const unsigned char *start, const unsigned char *end); @@ -1022,7 +1023,7 @@ read_children(struct archive_read *a, struct file_info *parent) if (*(p + DR_name_len_offset) == 1 && *(p + DR_name_offset) == '\001') continue; - child = parse_file_info(a, parent, p); + child = parse_file_info(a, parent, p, b - p); if (child == NULL) { __archive_read_consume(a, skip_size); return (ARCHIVE_FATAL); @@ -1112,7 +1113,7 @@ choose_volume(struct archive_read *a, struct iso9660 *iso9660) */ seenJoliet = iso9660->seenJoliet;/* Save flag. */ iso9660->seenJoliet = 0; - file = parse_file_info(a, NULL, block); + file = parse_file_info(a, NULL, block, vd->size); if (file == NULL) return (ARCHIVE_FATAL); iso9660->seenJoliet = seenJoliet; @@ -1144,7 +1145,7 @@ choose_volume(struct archive_read *a, struct iso9660 *iso9660) return (ARCHIVE_FATAL); } iso9660->seenJoliet = 0; - file = parse_file_info(a, NULL, block); + file = parse_file_info(a, NULL, block, vd->size); if (file == NULL) return (ARCHIVE_FATAL); iso9660->seenJoliet = seenJoliet; @@ -1749,7 +1750,7 @@ archive_read_format_iso9660_cleanup(struct archive_read *a) */ static struct file_info * parse_file_info(struct archive_read *a, struct file_info *parent, - const unsigned char *isodirrec) + const unsigned char *isodirrec, size_t reclen) { struct iso9660 *iso9660; struct file_info *file, *filep; @@ -1763,16 +1764,20 @@ parse_file_info(struct archive_read *a, struct file_info *parent, iso9660 = (struct iso9660 *)(a->format->data); - dr_len = (size_t)isodirrec[DR_length_offset]; - name_len = (size_t)isodirrec[DR_name_len_offset]; - location = archive_le32dec(isodirrec + DR_extent_offset); - fsize = toi(isodirrec + DR_size_offset, DR_size_size); - /* Sanity check that dr_len needs at least 34. */ - if (dr_len < 34) { + if (reclen != 0) + dr_len = (size_t)isodirrec[DR_length_offset]; + /* + * Sanity check that reclen is not zero and dr_len is greater than + * reclen but at least 34 + */ + if (reclen == 0 || reclen < dr_len || dr_len < 34) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Invalid length of directory record"); + "Invalid length of directory record"); return (NULL); } + name_len = (size_t)isodirrec[DR_name_len_offset]; + location = archive_le32dec(isodirrec + DR_extent_offset); + fsize = toi(isodirrec + DR_size_offset, DR_size_size); /* Sanity check that name_len doesn't exceed dr_len. */ if (dr_len - 33 < name_len || name_len == 0) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, diff --git a/libarchive/archive_read_support_format_lha.c b/libarchive/archive_read_support_format_lha.c index b8ef4ae..95c99bb 100644 --- a/libarchive/archive_read_support_format_lha.c +++ b/libarchive/archive_read_support_format_lha.c @@ -701,6 +701,12 @@ archive_read_format_lha_read_header(struct archive_read *a, * Prepare variables used to read a file content. */ lha->entry_bytes_remaining = lha->compsize; + if (lha->entry_bytes_remaining < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid LHa entry size"); + return (ARCHIVE_FATAL); + } lha->entry_offset = 0; lha->entry_crc_calculated = 0; diff --git a/libarchive/archive_read_support_format_mtree.c b/libarchive/archive_read_support_format_mtree.c index 44b6083..5b0eadc 100644 --- a/libarchive/archive_read_support_format_mtree.c +++ b/libarchive/archive_read_support_format_mtree.c @@ -49,6 +49,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_mtree.c 2011 #include "archive.h" #include "archive_entry.h" #include "archive_private.h" +#include "archive_rb.h" #include "archive_read_private.h" #include "archive_string.h" #include "archive_pack_dev.h" @@ -75,7 +76,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_mtree.c 2011 #define MTREE_HAS_OPTIONAL 0x0800 #define MTREE_HAS_NOCHANGE 0x1000 /* FreeBSD specific */ -#define MTREE_HASHTABLE_SIZE 1024 +#define MAX_LINE_LEN (1024 * 1024) struct mtree_option { struct mtree_option *next; @@ -83,13 +84,13 @@ struct mtree_option { }; struct mtree_entry { + struct archive_rb_node rbnode; + struct mtree_entry *next_dup; struct mtree_entry *next; struct mtree_option *options; char *name; char full; char used; - unsigned int name_hash; - struct mtree_entry *hashtable_next; }; struct mtree { @@ -102,11 +103,12 @@ struct mtree { const char *archive_format_name; struct mtree_entry *entries; struct mtree_entry *this_entry; - struct mtree_entry *entry_hashtable[MTREE_HASHTABLE_SIZE]; + struct archive_rb_tree entry_rbtree; struct archive_string current_dir; struct archive_string contents_name; struct archive_entry_linkresolver *resolver; + struct archive_rb_tree rbtree; int64_t cur_size; char checkfs; @@ -115,7 +117,6 @@ struct mtree { static int bid_keycmp(const char *, const char *, ssize_t); static int cleanup(struct archive_read *); static int detect_form(struct archive_read *, int *); -static unsigned int hash(const char *); static int mtree_bid(struct archive_read *, int); static int parse_file(struct archive_read *, struct archive_entry *, struct mtree *, struct mtree_entry *, int *); @@ -217,9 +218,30 @@ free_options(struct mtree_option *head) } } +static int +mtree_cmp_node(const struct archive_rb_node *n1, + const struct archive_rb_node *n2) +{ + const struct mtree_entry *e1 = (const struct mtree_entry *)n1; + const struct mtree_entry *e2 = (const struct mtree_entry *)n2; + + return (strcmp(e1->name, e2->name)); +} + +static int +mtree_cmp_key(const struct archive_rb_node *n, const void *key) +{ + const struct mtree_entry *e = (const struct mtree_entry *)n; + + return (strcmp(e->name, key)); +} + int archive_read_support_format_mtree(struct archive *_a) { + static const struct archive_rb_tree_ops rb_ops = { + mtree_cmp_node, mtree_cmp_key, + }; struct archive_read *a = (struct archive_read *)_a; struct mtree *mtree; int r; @@ -235,6 +257,8 @@ archive_read_support_format_mtree(struct archive *_a) } mtree->fd = -1; + __archive_rb_tree_init(&mtree->rbtree, &rb_ops); + r = __archive_read_register_format(a, mtree, "mtree", mtree_bid, archive_read_format_mtree_options, read_header, read_data, skip, NULL, cleanup, NULL, NULL); @@ -334,6 +358,14 @@ next_line(struct archive_read *a, size_t nbytes_req = (*ravail+1023) & ~1023U; ssize_t tested; + /* + * Place an arbitrary limit on the line length. + * mtree is almost free-form input and without line length limits, + * it can consume a lot of memory. + */ + if (len >= MAX_LINE_LEN) + return (-1); + /* Increase reading bytes if it is not enough to at least * new two lines. */ if (nbytes_req < (size_t)*ravail + 160) @@ -865,12 +897,11 @@ process_add_entry(struct archive_read *a, struct mtree *mtree, struct mtree_option **global, const char *line, ssize_t line_len, struct mtree_entry **last_entry, int is_form_d) { - struct mtree_entry *entry, *ht_iter; + struct mtree_entry *entry; struct mtree_option *iter; const char *next, *eq, *name, *end; size_t name_len, len; int r, i; - unsigned int ht_idx; if ((entry = malloc(sizeof(*entry))) == NULL) { archive_set_error(&a->archive, errno, "Can't allocate memory"); @@ -881,8 +912,6 @@ process_add_entry(struct archive_read *a, struct mtree *mtree, entry->name = NULL; entry->used = 0; entry->full = 0; - entry->name_hash = 0; - entry->hashtable_next = NULL; /* Add this entry to list. */ if (*last_entry == NULL) @@ -935,15 +964,17 @@ process_add_entry(struct archive_read *a, struct mtree *mtree, memcpy(entry->name, name, name_len); entry->name[name_len] = '\0'; parse_escapes(entry->name, entry); - entry->name_hash = hash(entry->name); - ht_idx = entry->name_hash % MTREE_HASHTABLE_SIZE; - if ((ht_iter = mtree->entry_hashtable[ht_idx]) != NULL) { - while (ht_iter->hashtable_next) - ht_iter = ht_iter->hashtable_next; - ht_iter->hashtable_next = entry; - } else { - mtree->entry_hashtable[ht_idx] = entry; + entry->next_dup = NULL; + if (entry->full) { + if (!__archive_rb_tree_insert_node(&mtree->rbtree, &entry->rbnode)) { + struct mtree_entry *alt; + alt = (struct mtree_entry *)__archive_rb_tree_find_node( + &mtree->rbtree, entry->name); + while (alt->next_dup) + alt = alt->next_dup; + alt->next_dup = entry; + } } for (iter = *global; iter != NULL; iter = iter->next) { @@ -1138,14 +1169,13 @@ parse_file(struct archive_read *a, struct archive_entry *entry, * with pathname canonicalization, which is a very * tricky subject.) */ - for (mp = mentry->hashtable_next; mp != NULL; mp = mp->hashtable_next) { - if (mp->full && !mp->used - && mentry->name_hash == mp->name_hash - && strcmp(mentry->name, mp->name) == 0) { + mp = (struct mtree_entry *)__archive_rb_tree_find_node( + &mtree->rbtree, mentry->name); + for (; mp; mp = mp->next_dup) { + if (mp->full && !mp->used) { /* Later lines override earlier ones. */ mp->used = 1; - r1 = parse_line(a, entry, mtree, mp, - &parsed_kws); + r1 = parse_line(a, entry, mtree, mp, &parsed_kws); if (r1 < r) r = r1; } @@ -1489,6 +1519,7 @@ parse_keyword(struct archive_read *a, struct mtree *mtree, } if (strcmp(key, "cksum") == 0) break; + __LA_FALLTHROUGH; case 'd': if (strcmp(key, "device") == 0) { /* stat(2) st_rdev field, e.g. the major/minor IDs @@ -1502,12 +1533,14 @@ parse_keyword(struct archive_read *a, struct mtree *mtree, archive_entry_set_rdev(entry, dev); return r; } + __LA_FALLTHROUGH; case 'f': if (strcmp(key, "flags") == 0) { *parsed_kws |= MTREE_HAS_FFLAGS; archive_entry_copy_fflags_text(entry, val); break; } + __LA_FALLTHROUGH; case 'g': if (strcmp(key, "gid") == 0) { *parsed_kws |= MTREE_HAS_GID; @@ -1519,16 +1552,19 @@ parse_keyword(struct archive_read *a, struct mtree *mtree, archive_entry_copy_gname(entry, val); break; } + __LA_FALLTHROUGH; case 'i': if (strcmp(key, "inode") == 0) { archive_entry_set_ino(entry, mtree_atol(&val, 10)); break; } + __LA_FALLTHROUGH; case 'l': if (strcmp(key, "link") == 0) { archive_entry_copy_symlink(entry, val); break; } + __LA_FALLTHROUGH; case 'm': if (strcmp(key, "md5") == 0 || strcmp(key, "md5digest") == 0) break; @@ -1545,6 +1581,7 @@ parse_keyword(struct archive_read *a, struct mtree *mtree, } break; } + __LA_FALLTHROUGH; case 'n': if (strcmp(key, "nlink") == 0) { *parsed_kws |= MTREE_HAS_NLINK; @@ -1552,6 +1589,7 @@ parse_keyword(struct archive_read *a, struct mtree *mtree, (unsigned int)mtree_atol(&val, 10)); break; } + __LA_FALLTHROUGH; case 'r': if (strcmp(key, "resdevice") == 0) { /* stat(2) st_dev field, e.g. the device ID where the @@ -1567,6 +1605,7 @@ parse_keyword(struct archive_read *a, struct mtree *mtree, if (strcmp(key, "rmd160") == 0 || strcmp(key, "rmd160digest") == 0) break; + __LA_FALLTHROUGH; case 's': if (strcmp(key, "sha1") == 0 || strcmp(key, "sha1digest") == 0) break; @@ -1583,6 +1622,7 @@ parse_keyword(struct archive_read *a, struct mtree *mtree, archive_entry_set_size(entry, mtree_atol(&val, 10)); break; } + __LA_FALLTHROUGH; case 't': if (strcmp(key, "tags") == 0) { /* @@ -1625,18 +1665,21 @@ parse_keyword(struct archive_read *a, struct mtree *mtree, archive_entry_set_filetype(entry, AE_IFBLK); break; } + __LA_FALLTHROUGH; case 'c': if (strcmp(val, "char") == 0) { archive_entry_set_filetype(entry, AE_IFCHR); break; } + __LA_FALLTHROUGH; case 'd': if (strcmp(val, "dir") == 0) { archive_entry_set_filetype(entry, AE_IFDIR); break; } + __LA_FALLTHROUGH; case 'f': if (strcmp(val, "fifo") == 0) { archive_entry_set_filetype(entry, @@ -1648,12 +1691,14 @@ parse_keyword(struct archive_read *a, struct mtree *mtree, AE_IFREG); break; } + __LA_FALLTHROUGH; case 'l': if (strcmp(val, "link") == 0) { archive_entry_set_filetype(entry, AE_IFLNK); break; } + __LA_FALLTHROUGH; default: archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, @@ -1665,6 +1710,7 @@ parse_keyword(struct archive_read *a, struct mtree *mtree, *parsed_kws |= MTREE_HAS_TYPE; break; } + __LA_FALLTHROUGH; case 'u': if (strcmp(key, "uid") == 0) { *parsed_kws |= MTREE_HAS_UID; @@ -1676,6 +1722,7 @@ parse_keyword(struct archive_read *a, struct mtree *mtree, archive_entry_copy_uname(entry, val); break; } + __LA_FALLTHROUGH; default: archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "Unrecognized key %s=%s", key, val); @@ -1962,19 +2009,3 @@ readline(struct archive_read *a, struct mtree *mtree, char **start, find_off = u - mtree->line.s; } } - -static unsigned int -hash(const char *p) -{ - /* A 32-bit version of Peter Weinberger's (PJW) hash algorithm, - as used by ELF for hashing function names. */ - unsigned g, h = 0; - while (*p != '\0') { - h = (h << 4) + *p++; - if ((g = h & 0xF0000000) != 0) { - h ^= g >> 24; - h &= 0x0FFFFFFF; - } - } - return h; -} diff --git a/libarchive/archive_read_support_format_rar.c b/libarchive/archive_read_support_format_rar.c index cbb14c3..2345222 100644 --- a/libarchive/archive_read_support_format_rar.c +++ b/libarchive/archive_read_support_format_rar.c @@ -604,20 +604,6 @@ lzss_emit_match(struct rar *rar, int offset, int length) rar->lzss.position += length; } -static void * -ppmd_alloc(void *p, size_t size) -{ - (void)p; - return malloc(size); -} -static void -ppmd_free(void *p, void *address) -{ - (void)p; - free(address); -} -static ISzAlloc g_szalloc = { ppmd_alloc, ppmd_free }; - static Byte ppmd_read(void *p) { @@ -1038,7 +1024,7 @@ archive_read_format_rar_read_data(struct archive_read *a, const void **buff, case COMPRESS_METHOD_BEST: ret = read_data_compressed(a, buff, size, offset); if (ret != ARCHIVE_OK && ret != ARCHIVE_WARN) - __archive_ppmd7_functions.Ppmd7_Free(&rar->ppmd7_context, &g_szalloc); + __archive_ppmd7_functions.Ppmd7_Free(&rar->ppmd7_context); break; default: @@ -1253,7 +1239,7 @@ archive_read_format_rar_cleanup(struct archive_read *a) free(rar->dbo); free(rar->unp_buffer); free(rar->lzss.window); - __archive_ppmd7_functions.Ppmd7_Free(&rar->ppmd7_context, &g_szalloc); + __archive_ppmd7_functions.Ppmd7_Free(&rar->ppmd7_context); free(rar); (a->format->data) = NULL; return (ARCHIVE_OK); @@ -1496,7 +1482,11 @@ read_header(struct archive_read *a, struct archive_entry *entry, return (ARCHIVE_FATAL); } filename[filename_size++] = '\0'; - filename[filename_size++] = '\0'; + /* + * Do not increment filename_size here as the computations below + * add the space for the terminating NUL explicitly. + */ + filename[filename_size] = '\0'; /* Decoded unicode form is UTF-16BE, so we have to update a string * conversion object for it. */ @@ -1654,7 +1644,7 @@ read_header(struct archive_read *a, struct archive_entry *entry, rar->unp_offset = 0; rar->unp_buffer_size = UNP_BUFFER_SIZE; memset(rar->lengthtable, 0, sizeof(rar->lengthtable)); - __archive_ppmd7_functions.Ppmd7_Free(&rar->ppmd7_context, &g_szalloc); + __archive_ppmd7_functions.Ppmd7_Free(&rar->ppmd7_context); rar->ppmd_valid = rar->ppmd_eod = 0; /* Don't set any archive entries for non-file header types */ @@ -2118,7 +2108,7 @@ parse_codes(struct archive_read *a) /* Make sure ppmd7_contest is freed before Ppmd7_Construct * because reading a broken file cause this abnormal sequence. */ - __archive_ppmd7_functions.Ppmd7_Free(&rar->ppmd7_context, &g_szalloc); + __archive_ppmd7_functions.Ppmd7_Free(&rar->ppmd7_context); rar->bytein.a = a; rar->bytein.Read = &ppmd_read; @@ -2133,7 +2123,7 @@ parse_codes(struct archive_read *a) } if (!__archive_ppmd7_functions.Ppmd7_Alloc(&rar->ppmd7_context, - rar->dictionary_size, &g_szalloc)) + rar->dictionary_size)) { archive_set_error(&a->archive, ENOMEM, "Out of memory"); diff --git a/libarchive/archive_read_support_format_tar.c b/libarchive/archive_read_support_format_tar.c index 30d5bc8..60800bb 100644 --- a/libarchive/archive_read_support_format_tar.c +++ b/libarchive/archive_read_support_format_tar.c @@ -251,15 +251,15 @@ archive_read_support_format_tar(struct archive *_a) ARCHIVE_STATE_NEW, "archive_read_support_format_tar"); tar = (struct tar *)calloc(1, sizeof(*tar)); -#ifdef HAVE_COPYFILE_H - /* Set this by default on Mac OS. */ - tar->process_mac_extensions = 1; -#endif if (tar == NULL) { archive_set_error(&a->archive, ENOMEM, "Can't allocate tar data"); return (ARCHIVE_FATAL); } +#ifdef HAVE_COPYFILE_H + /* Set this by default on Mac OS. */ + tar->process_mac_extensions = 1; +#endif r = __archive_read_register_format(a, tar, "tar", archive_read_format_tar_bid, @@ -2241,7 +2241,7 @@ gnu_add_sparse_entry(struct archive_read *a, struct tar *tar, else tar->sparse_list = p; tar->sparse_last = p; - if (remaining < 0 || offset < 0) { + if (remaining < 0 || offset < 0 || offset > INT64_MAX - remaining) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Malformed sparse map data"); return (ARCHIVE_FATAL); } diff --git a/libarchive/archive_read_support_format_xar.c b/libarchive/archive_read_support_format_xar.c index 7a22beb..602fc77 100644 --- a/libarchive/archive_read_support_format_xar.c +++ b/libarchive/archive_read_support_format_xar.c @@ -1040,6 +1040,9 @@ atol10(const char *p, size_t char_cnt) uint64_t l; int digit; + if (char_cnt == 0) + return (0); + l = 0; digit = *p - '0'; while (digit >= 0 && digit < 10 && char_cnt-- > 0) { @@ -1054,7 +1057,10 @@ atol8(const char *p, size_t char_cnt) { int64_t l; int digit; - + + if (char_cnt == 0) + return (0); + l = 0; while (char_cnt-- > 0) { if (*p >= '0' && *p <= '7') @@ -2623,6 +2629,14 @@ strappend_base64(struct xar *xar, archive_strncat(as, (const char *)buff, len); } +static int +is_string(const char *known, const char *data, size_t len) +{ + if (strlen(known) != len) + return -1; + return memcmp(data, known, len); +} + static void xml_data(void *userData, const char *s, int len) { @@ -2674,26 +2688,26 @@ xml_data(void *userData, const char *s, int len) archive_strncpy(&(xar->file->symlink), s, len); break; case FILE_TYPE: - if (strncmp("file", s, len) == 0 || - strncmp("hardlink", s, len) == 0) + if (is_string("file", s, len) == 0 || + is_string("hardlink", s, len) == 0) xar->file->mode = (xar->file->mode & ~AE_IFMT) | AE_IFREG; - if (strncmp("directory", s, len) == 0) + if (is_string("directory", s, len) == 0) xar->file->mode = (xar->file->mode & ~AE_IFMT) | AE_IFDIR; - if (strncmp("symlink", s, len) == 0) + if (is_string("symlink", s, len) == 0) xar->file->mode = (xar->file->mode & ~AE_IFMT) | AE_IFLNK; - if (strncmp("character special", s, len) == 0) + if (is_string("character special", s, len) == 0) xar->file->mode = (xar->file->mode & ~AE_IFMT) | AE_IFCHR; - if (strncmp("block special", s, len) == 0) + if (is_string("block special", s, len) == 0) xar->file->mode = (xar->file->mode & ~AE_IFMT) | AE_IFBLK; - if (strncmp("socket", s, len) == 0) + if (is_string("socket", s, len) == 0) xar->file->mode = (xar->file->mode & ~AE_IFMT) | AE_IFSOCK; - if (strncmp("fifo", s, len) == 0) + if (is_string("fifo", s, len) == 0) xar->file->mode = (xar->file->mode & ~AE_IFMT) | AE_IFIFO; xar->file->has |= HAS_TYPE; diff --git a/libarchive/archive_read_support_format_zip.c b/libarchive/archive_read_support_format_zip.c index 4c4f6fa..18f0d04 100644 --- a/libarchive/archive_read_support_format_zip.c +++ b/libarchive/archive_read_support_format_zip.c @@ -511,7 +511,13 @@ process_extra(struct archive_read *a, const char *p, size_t extra_length, struct case 0x5455: { /* Extended time field "UT". */ - int flags = p[offset]; + int flags; + if (datasize == 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Incomplete extended time field"); + return ARCHIVE_FAILED; + } + flags = p[offset]; offset++; datasize--; /* Flag bits indicate which dates are present. */ @@ -723,6 +729,11 @@ process_extra(struct archive_read *a, const char *p, size_t extra_length, struct } case 0x9901: /* WinZip AES extra data field. */ + if (datasize < 6) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Incomplete AES field"); + return ARCHIVE_FAILED; + } if (p[offset + 2] == 'A' && p[offset + 3] == 'E') { /* Vendor version. */ zip_entry->aes_extra.vendor = @@ -881,6 +892,24 @@ zip_read_local_file_header(struct archive_read *a, struct archive_entry *entry, zip_entry->mode |= 0664; } + /* Windows archivers sometimes use backslash as the directory separator. + Normalize to slash. */ + if (zip_entry->system == 0 && + (wp = archive_entry_pathname_w(entry)) != NULL) { + if (wcschr(wp, L'/') == NULL && wcschr(wp, L'\\') != NULL) { + size_t i; + struct archive_wstring s; + archive_string_init(&s); + archive_wstrcpy(&s, wp); + for (i = 0; i < archive_strlen(&s); i++) { + if (s.s[i] == '\\') + s.s[i] = '/'; + } + archive_entry_copy_pathname_w(entry, s.s); + archive_wstring_free(&s); + } + } + /* Make sure that entries with a trailing '/' are marked as directories * even if the External File Attributes contains bogus values. If this * is not a directory and there is no type, assume regularfile. */ @@ -1056,6 +1085,7 @@ zip_read_local_file_header(struct archive_read *a, struct archive_entry *entry, zip->end_of_entry = 1; /* Set up a more descriptive format name. */ + archive_string_empty(&zip->format_name); archive_string_sprintf(&zip->format_name, "ZIP %d.%d (%s)", version / 10, version % 10, compression_name(zip->entry->compression)); diff --git a/libarchive/archive_string.c b/libarchive/archive_string.c index 5ae09b6..554533e 100644 --- a/libarchive/archive_string.c +++ b/libarchive/archive_string.c @@ -214,7 +214,8 @@ archive_wstring_append(struct archive_wstring *as, const wchar_t *p, size_t s) { if (archive_wstring_ensure(as, as->length + s + 1) == NULL) return (NULL); - wmemmove(as->s + as->length, p, s); + if (s) + wmemmove(as->s + as->length, p, s); as->length += s; as->s[as->length] = 0; return (as); diff --git a/libarchive/archive_util.c b/libarchive/archive_util.c index bac9ba1..96d6145 100644 --- a/libarchive/archive_util.c +++ b/libarchive/archive_util.c @@ -140,7 +140,7 @@ archive_compression_name(struct archive *a) /* * Return a count of the number of compressed bytes processed. */ -int64_t +la_int64_t archive_position_compressed(struct archive *a) { return archive_filter_bytes(a, -1); @@ -149,7 +149,7 @@ archive_position_compressed(struct archive *a) /* * Return a count of the number of uncompressed bytes processed. */ -int64_t +la_int64_t archive_position_uncompressed(struct archive *a) { return archive_filter_bytes(a, 0); diff --git a/libarchive/archive_version_details.c b/libarchive/archive_version_details.c index 813f0f3..bfb20ea 100644 --- a/libarchive/archive_version_details.c +++ b/libarchive/archive_version_details.c @@ -45,6 +45,9 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_util.c 201098 2009-12-28 02:58:1 #ifdef HAVE_LZ4_H #include #endif +#ifdef HAVE_ZSTD_H +#include +#endif #include "archive.h" #include "archive_private.h" @@ -59,6 +62,7 @@ archive_version_details(void) const char *liblzma = archive_liblzma_version(); const char *bzlib = archive_bzlib_version(); const char *liblz4 = archive_liblz4_version(); + const char *libzstd = archive_libzstd_version(); if (!init) { archive_string_init(&str); @@ -84,6 +88,10 @@ archive_version_details(void) archive_strcat(&str, " liblz4/"); archive_strcat(&str, liblz4); } + if (libzstd) { + archive_strcat(&str, " libzstd/"); + archive_strcat(&str, libzstd); + } } return str.s; } @@ -131,3 +139,13 @@ archive_liblz4_version(void) return NULL; #endif } + +const char * +archive_libzstd_version(void) +{ +#if HAVE_ZSTD_H && HAVE_LIBZSTD + return ZSTD_VERSION_STRING; +#else + return NULL; +#endif +} diff --git a/libarchive/archive_virtual.c b/libarchive/archive_virtual.c index de2595a..f509ee5 100644 --- a/libarchive/archive_virtual.c +++ b/libarchive/archive_virtual.c @@ -48,7 +48,7 @@ archive_filter_name(struct archive *a, int n) return ((a->vtable->archive_filter_name)(a, n)); } -int64_t +la_int64_t archive_filter_bytes(struct archive *a, int n) { return ((a->vtable->archive_filter_bytes)(a, n)); @@ -124,14 +124,15 @@ archive_write_finish_entry(struct archive *a) return ((a->vtable->archive_write_finish_entry)(a)); } -ssize_t +la_ssize_t archive_write_data(struct archive *a, const void *buff, size_t s) { return ((a->vtable->archive_write_data)(a, buff, s)); } -ssize_t -archive_write_data_block(struct archive *a, const void *buff, size_t s, int64_t o) +la_ssize_t +archive_write_data_block(struct archive *a, const void *buff, size_t s, + la_int64_t o) { if (a->vtable->archive_write_data_block == NULL) { archive_set_error(a, ARCHIVE_ERRNO_MISC, @@ -156,7 +157,7 @@ archive_read_next_header2(struct archive *a, struct archive_entry *entry) int archive_read_data_block(struct archive *a, - const void **buff, size_t *s, int64_t *o) + const void **buff, size_t *s, la_int64_t *o) { return ((a->vtable->archive_read_data_block)(a, buff, s, o)); } diff --git a/libarchive/archive_write.3 b/libarchive/archive_write.3 index 376d71d..c1164f5 100644 --- a/libarchive/archive_write.3 +++ b/libarchive/archive_write.3 @@ -71,7 +71,7 @@ support. .\" .Ss Set options See -.Xr archive_read_set_options 3 . +.Xr archive_write_set_options 3 . .\" .Ss Open archive See diff --git a/libarchive/archive_write.c b/libarchive/archive_write.c index 0634a22..e8daf53 100644 --- a/libarchive/archive_write.c +++ b/libarchive/archive_write.c @@ -190,7 +190,7 @@ archive_write_get_bytes_in_last_block(struct archive *_a) * an archive to itself recursively. */ int -archive_write_set_skip_file(struct archive *_a, int64_t d, int64_t i) +archive_write_set_skip_file(struct archive *_a, la_int64_t d, la_int64_t i) { struct archive_write *a = (struct archive_write *)_a; archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, diff --git a/libarchive/archive_write_add_filter.c b/libarchive/archive_write_add_filter.c index 08f518a..203f414 100644 --- a/libarchive/archive_write_add_filter.c +++ b/libarchive/archive_write_add_filter.c @@ -53,6 +53,7 @@ struct { int code; int (*setter)(struct archive *); } codes[] = { ARCHIVE_FILTER_LZOP, archive_write_add_filter_lzip }, { ARCHIVE_FILTER_UU, archive_write_add_filter_uuencode }, { ARCHIVE_FILTER_XZ, archive_write_add_filter_xz }, + { ARCHIVE_FILTER_ZSTD, archive_write_add_filter_zstd }, { -1, NULL } }; diff --git a/libarchive/archive_write_add_filter_by_name.c b/libarchive/archive_write_add_filter_by_name.c index 85a8d47..ffa633c 100644 --- a/libarchive/archive_write_add_filter_by_name.c +++ b/libarchive/archive_write_add_filter_by_name.c @@ -57,6 +57,7 @@ struct { const char *name; int (*setter)(struct archive *); } names[] = { "lzop", archive_write_add_filter_lzop }, { "uuencode", archive_write_add_filter_uuencode }, { "xz", archive_write_add_filter_xz }, + { "zstd", archive_write_add_filter_zstd }, { NULL, NULL } }; diff --git a/libarchive/archive_write_add_filter_gzip.c b/libarchive/archive_write_add_filter_gzip.c index 04eb06c..e4b3435 100644 --- a/libarchive/archive_write_add_filter_gzip.c +++ b/libarchive/archive_write_add_filter_gzip.c @@ -226,7 +226,12 @@ archive_compressor_gzip_open(struct archive_write_filter *f) data->compressed[7] = (uint8_t)(t>>24)&0xff; } else memset(&data->compressed[4], 0, 4); - data->compressed[8] = 0; /* No deflate options */ + if (data->compression_level == 9) + data->compressed[8] = 2; + else if(data->compression_level == 1) + data->compressed[8] = 4; + else + data->compressed[8] = 0; data->compressed[9] = 3; /* OS=Unix */ data->stream.next_out += 10; data->stream.avail_out -= 10; diff --git a/libarchive/archive_write_add_filter_zstd.c b/libarchive/archive_write_add_filter_zstd.c new file mode 100644 index 0000000..671fc6a --- /dev/null +++ b/libarchive/archive_write_add_filter_zstd.c @@ -0,0 +1,335 @@ +/*- + * Copyright (c) 2017 Sean Purcell + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "archive_platform.h" + +__FBSDID("$FreeBSD$"); + + +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_ZSTD_H +#include +#endif + +#include "archive.h" +#include "archive_private.h" +#include "archive_string.h" +#include "archive_write_private.h" + +/* Don't compile this if we don't have zstd.h */ + +struct private_data { + int compression_level; +#if HAVE_ZSTD_H && HAVE_LIBZSTD + ZSTD_CStream *cstream; + int64_t total_in; + ZSTD_outBuffer out; +#else + struct archive_write_program_data *pdata; +#endif +}; + +static int archive_compressor_zstd_options(struct archive_write_filter *, + const char *, const char *); +static int archive_compressor_zstd_open(struct archive_write_filter *); +static int archive_compressor_zstd_write(struct archive_write_filter *, + const void *, size_t); +static int archive_compressor_zstd_close(struct archive_write_filter *); +static int archive_compressor_zstd_free(struct archive_write_filter *); +#if HAVE_ZSTD_H && HAVE_LIBZSTD +static int drive_compressor(struct archive_write_filter *, + struct private_data *, int, const void *, size_t); +#endif + + +/* + * Add a zstd compression filter to this write handle. + */ +int +archive_write_add_filter_zstd(struct archive *_a) +{ + struct archive_write *a = (struct archive_write *)_a; + struct archive_write_filter *f = __archive_write_allocate_filter(_a); + struct private_data *data; + archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_NEW, "archive_write_add_filter_zstd"); + + data = calloc(1, sizeof(*data)); + if (data == NULL) { + archive_set_error(&a->archive, ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + f->data = data; + f->open = &archive_compressor_zstd_open; + f->options = &archive_compressor_zstd_options; + f->close = &archive_compressor_zstd_close; + f->free = &archive_compressor_zstd_free; + f->code = ARCHIVE_FILTER_ZSTD; + f->name = "zstd"; + data->compression_level = 3; /* Default level used by the zstd CLI */ +#if HAVE_ZSTD_H && HAVE_LIBZSTD + data->cstream = ZSTD_createCStream(); + if (data->cstream == NULL) { + free(data); + archive_set_error(&a->archive, ENOMEM, + "Failed to allocate zstd compressor object"); + return (ARCHIVE_FATAL); + } + + return (ARCHIVE_OK); +#else + data->pdata = __archive_write_program_allocate("zstd"); + if (data->pdata == NULL) { + free(data); + archive_set_error(&a->archive, ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Using external zstd program"); + return (ARCHIVE_WARN); +#endif +} + +static int +archive_compressor_zstd_free(struct archive_write_filter *f) +{ + struct private_data *data = (struct private_data *)f->data; +#if HAVE_ZSTD_H && HAVE_LIBZSTD + ZSTD_freeCStream(data->cstream); + free(data->out.dst); +#else + __archive_write_program_free(data->pdata); +#endif + free(data); + f->data = NULL; + return (ARCHIVE_OK); +} + +/* + * Set write options. + */ +static int +archive_compressor_zstd_options(struct archive_write_filter *f, const char *key, + const char *value) +{ + struct private_data *data = (struct private_data *)f->data; + + if (strcmp(key, "compression-level") == 0) { + int level = atoi(value); +#if HAVE_ZSTD_H && HAVE_LIBZSTD + if (level < 1 || level > ZSTD_maxCLevel()) { +#else + /* If we don't have the library, hard-code the max level */ + if (level < 1 || level > 22) { +#endif + return (ARCHIVE_WARN); + } + data->compression_level = level; + return (ARCHIVE_OK); + } + + /* Note: The "warn" return is just to inform the options + * supervisor that we didn't handle it. It will generate + * a suitable error if no one used this option. */ + return (ARCHIVE_WARN); +} + +#if HAVE_ZSTD_H && HAVE_LIBZSTD +/* + * Setup callback. + */ +static int +archive_compressor_zstd_open(struct archive_write_filter *f) +{ + struct private_data *data = (struct private_data *)f->data; + int ret; + + ret = __archive_write_open_filter(f->next_filter); + if (ret != ARCHIVE_OK) + return (ret); + + if (data->out.dst == NULL) { + size_t bs = ZSTD_CStreamOutSize(), bpb; + if (f->archive->magic == ARCHIVE_WRITE_MAGIC) { + /* Buffer size should be a multiple number of + * the of bytes per block for performance. */ + bpb = archive_write_get_bytes_per_block(f->archive); + if (bpb > bs) + bs = bpb; + else if (bpb != 0) + bs -= bs % bpb; + } + data->out.size = bs; + data->out.pos = 0; + data->out.dst + = (unsigned char *)malloc(data->out.size); + if (data->out.dst == NULL) { + archive_set_error(f->archive, ENOMEM, + "Can't allocate data for compression buffer"); + return (ARCHIVE_FATAL); + } + } + + f->write = archive_compressor_zstd_write; + + if (ZSTD_isError(ZSTD_initCStream(data->cstream, + data->compression_level))) { + archive_set_error(f->archive, ARCHIVE_ERRNO_MISC, + "Internal error initializing zstd compressor object"); + return (ARCHIVE_FATAL); + } + + return (ARCHIVE_OK); +} + +/* + * Write data to the compressed stream. + */ +static int +archive_compressor_zstd_write(struct archive_write_filter *f, const void *buff, + size_t length) +{ + struct private_data *data = (struct private_data *)f->data; + int ret; + + /* Update statistics */ + data->total_in += length; + + if ((ret = drive_compressor(f, data, 0, buff, length)) != ARCHIVE_OK) + return (ret); + + return (ARCHIVE_OK); +} + +/* + * Finish the compression... + */ +static int +archive_compressor_zstd_close(struct archive_write_filter *f) +{ + struct private_data *data = (struct private_data *)f->data; + int r1, r2; + + /* Finish zstd frame */ + r1 = drive_compressor(f, data, 1, NULL, 0); + + r2 = __archive_write_close_filter(f->next_filter); + + return r1 < r2 ? r1 : r2; +} + +/* + * Utility function to push input data through compressor, + * writing full output blocks as necessary. + * + * Note that this handles both the regular write case (finishing == + * false) and the end-of-archive case (finishing == true). + */ +static int +drive_compressor(struct archive_write_filter *f, + struct private_data *data, int finishing, const void *src, size_t length) +{ + ZSTD_inBuffer in = (ZSTD_inBuffer) { src, length, 0 }; + + for (;;) { + if (data->out.pos == data->out.size) { + const int ret = __archive_write_filter(f->next_filter, + data->out.dst, data->out.size); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + data->out.pos = 0; + } + + /* If there's nothing to do, we're done. */ + if (!finishing && in.pos == in.size) + return (ARCHIVE_OK); + + { + const size_t zstdret = !finishing ? + ZSTD_compressStream(data->cstream, &data->out, &in) + : ZSTD_endStream(data->cstream, &data->out); + + if (ZSTD_isError(zstdret)) { + archive_set_error(f->archive, + ARCHIVE_ERRNO_MISC, + "Zstd compression failed: %s", + ZSTD_getErrorName(zstdret)); + return (ARCHIVE_FATAL); + } + + /* If we're finishing, 0 means nothing left to flush */ + if (finishing && zstdret == 0) { + const int ret = __archive_write_filter(f->next_filter, + data->out.dst, data->out.pos); + return (ret); + } + } + } +} + +#else /* HAVE_ZSTD_H && HAVE_LIBZSTD */ + +static int +archive_compressor_zstd_open(struct archive_write_filter *f) +{ + struct private_data *data = (struct private_data *)f->data; + struct archive_string as; + int r; + + archive_string_init(&as); + archive_string_sprintf(&as, "zstd -%d", data->compression_level); + + f->write = archive_compressor_zstd_write; + r = __archive_write_program_open(f, data->pdata, as.s); + archive_string_free(&as); + return (r); +} + +static int +archive_compressor_zstd_write(struct archive_write_filter *f, const void *buff, + size_t length) +{ + struct private_data *data = (struct private_data *)f->data; + + return __archive_write_program_write(f, data->pdata, buff, length); +} + +static int +archive_compressor_zstd_close(struct archive_write_filter *f) +{ + struct private_data *data = (struct private_data *)f->data; + + return __archive_write_program_close(f, data->pdata); +} + +#endif /* HAVE_ZSTD_H && HAVE_LIBZSTD */ diff --git a/libarchive/archive_write_disk_posix.c b/libarchive/archive_write_disk_posix.c index 6ad5399..3fd5f57 100644 --- a/libarchive/archive_write_disk_posix.c +++ b/libarchive/archive_write_disk_posix.c @@ -835,7 +835,7 @@ _archive_write_disk_header(struct archive *_a, struct archive_entry *entry) } int -archive_write_disk_set_skip_file(struct archive *_a, int64_t d, int64_t i) +archive_write_disk_set_skip_file(struct archive *_a, la_int64_t d, la_int64_t i) { struct archive_write_disk *a = (struct archive_write_disk *)_a; archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, @@ -1786,7 +1786,7 @@ finish_metadata: int archive_write_disk_set_group_lookup(struct archive *_a, void *private_data, - int64_t (*lookup_gid)(void *private, const char *gname, int64_t gid), + la_int64_t (*lookup_gid)(void *private, const char *gname, la_int64_t gid), void (*cleanup_gid)(void *private)) { struct archive_write_disk *a = (struct archive_write_disk *)_a; @@ -1822,7 +1822,7 @@ archive_write_disk_set_user_lookup(struct archive *_a, } int64_t -archive_write_disk_gid(struct archive *_a, const char *name, int64_t id) +archive_write_disk_gid(struct archive *_a, const char *name, la_int64_t id) { struct archive_write_disk *a = (struct archive_write_disk *)_a; archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, @@ -1833,7 +1833,7 @@ archive_write_disk_gid(struct archive *_a, const char *name, int64_t id) } int64_t -archive_write_disk_uid(struct archive *_a, const char *name, int64_t id) +archive_write_disk_uid(struct archive *_a, const char *name, la_int64_t id) { struct archive_write_disk *a = (struct archive_write_disk *)_a; archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, @@ -1981,6 +1981,10 @@ restore_entry(struct archive_write_disk *a) if ((en == EISDIR || en == EEXIST) && (a->flags & ARCHIVE_EXTRACT_NO_OVERWRITE)) { /* If we're not overwriting, we're done. */ + if (S_ISDIR(a->mode)) { + /* Don't overwrite any settings on existing directories. */ + a->todo = 0; + } archive_entry_unset_size(a->entry); return (ARCHIVE_OK); } diff --git a/libarchive/archive_write_disk_windows.c b/libarchive/archive_write_disk_windows.c index 94b016e..78eda4a 100644 --- a/libarchive/archive_write_disk_windows.c +++ b/libarchive/archive_write_disk_windows.c @@ -906,7 +906,7 @@ _archive_write_disk_header(struct archive *_a, struct archive_entry *entry) } int -archive_write_disk_set_skip_file(struct archive *_a, int64_t d, int64_t i) +archive_write_disk_set_skip_file(struct archive *_a, la_int64_t d, la_int64_t i) { struct archive_write_disk *a = (struct archive_write_disk *)_a; archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, @@ -1156,7 +1156,7 @@ _archive_write_disk_finish_entry(struct archive *_a) int archive_write_disk_set_group_lookup(struct archive *_a, void *private_data, - int64_t (*lookup_gid)(void *private, const char *gname, int64_t gid), + la_int64_t (*lookup_gid)(void *private, const char *gname, la_int64_t gid), void (*cleanup_gid)(void *private)) { struct archive_write_disk *a = (struct archive_write_disk *)_a; @@ -1192,7 +1192,7 @@ archive_write_disk_set_user_lookup(struct archive *_a, } int64_t -archive_write_disk_gid(struct archive *_a, const char *name, int64_t id) +archive_write_disk_gid(struct archive *_a, const char *name, la_int64_t id) { struct archive_write_disk *a = (struct archive_write_disk *)_a; archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, @@ -1203,7 +1203,7 @@ archive_write_disk_gid(struct archive *_a, const char *name, int64_t id) } int64_t -archive_write_disk_uid(struct archive *_a, const char *name, int64_t id) +archive_write_disk_uid(struct archive *_a, const char *name, la_int64_t id) { struct archive_write_disk *a = (struct archive_write_disk *)_a; archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, @@ -1322,9 +1322,20 @@ restore_entry(struct archive_write_disk *a) } } + if ((en == ENOENT) && (archive_entry_hardlink(a->entry) != NULL)) { + archive_set_error(&a->archive, en, + "Hard-link target '%s' does not exist.", + archive_entry_hardlink(a->entry)); + return (ARCHIVE_FAILED); + } + if ((en == EISDIR || en == EEXIST) && (a->flags & ARCHIVE_EXTRACT_NO_OVERWRITE)) { /* If we're not overwriting, we're done. */ + if (S_ISDIR(a->mode)) { + /* Don't overwrite any settings on existing directories. */ + a->todo = 0; + } archive_entry_unset_size(a->entry); return (ARCHIVE_OK); } diff --git a/libarchive/archive_write_filter.3 b/libarchive/archive_write_filter.3 index e1d1891..d6fa071 100644 --- a/libarchive/archive_write_filter.3 +++ b/libarchive/archive_write_filter.3 @@ -42,7 +42,8 @@ .Nm archive_write_add_filter_none , .Nm archive_write_add_filter_program , .Nm archive_write_add_filter_uuencode , -.Nm archive_write_add_filter_xz +.Nm archive_write_add_filter_xz , +.Nm archive_write_add_filter_zstd , .Nd functions enabling output filters .Sh LIBRARY Streaming Archive Library (libarchive, -larchive) @@ -76,6 +77,8 @@ Streaming Archive Library (libarchive, -larchive) .Fn archive_write_add_filter_uuencode "struct archive *" .Ft int .Fn archive_write_add_filter_xz "struct archive *" +.Ft int +.Fn archive_write_add_filter_zstd "struct archive *" .Sh DESCRIPTION .Bl -tag -width indent .It Xo @@ -89,6 +92,7 @@ Streaming Archive Library (libarchive, -larchive) .Fn archive_write_add_filter_lzma , .Fn archive_write_add_filter_lzop , .Fn archive_write_add_filter_xz , +.Fn archive_write_add_filter_zstd , .Xc The resulting archive will be compressed as specified. Note that the compressed output is always properly blocked. diff --git a/libarchive/archive_write_set_format_7zip.c b/libarchive/archive_write_set_format_7zip.c index 41ed74d..f63a226 100644 --- a/libarchive/archive_write_set_format_7zip.c +++ b/libarchive/archive_write_set_format_7zip.c @@ -2095,19 +2095,6 @@ compression_init_encoder_lzma2(struct archive *a, /* * _7_PPMD compressor. */ -static void * -ppmd_alloc(void *p, size_t size) -{ - (void)p; - return malloc(size); -} -static void -ppmd_free(void *p, void *address) -{ - (void)p; - free(address); -} -static ISzAlloc g_szalloc = { ppmd_alloc, ppmd_free }; static void ppmd_write(void *p, Byte b) { @@ -2167,7 +2154,7 @@ compression_init_encoder_ppmd(struct archive *a, archive_le32enc(props+1, msize); __archive_ppmd7_functions.Ppmd7_Construct(&strm->ppmd7_context); r = __archive_ppmd7_functions.Ppmd7_Alloc( - &strm->ppmd7_context, msize, &g_szalloc); + &strm->ppmd7_context, msize); if (r == 0) { free(strm->buff); free(strm); @@ -2243,7 +2230,7 @@ compression_end_ppmd(struct archive *a, struct la_zstream *lastrm) (void)a; /* UNUSED */ strm = (struct ppmd_stream *)lastrm->real_stream; - __archive_ppmd7_functions.Ppmd7_Free(&strm->ppmd7_context, &g_szalloc); + __archive_ppmd7_functions.Ppmd7_Free(&strm->ppmd7_context); free(strm->buff); free(strm); lastrm->real_stream = NULL; diff --git a/libarchive/archive_write_set_format_ar.c b/libarchive/archive_write_set_format_ar.c index c9771d8..50305cc 100644 --- a/libarchive/archive_write_set_format_ar.c +++ b/libarchive/archive_write_set_format_ar.c @@ -180,7 +180,7 @@ archive_write_ar_header(struct archive_write *a, struct archive_entry *entry) } memset(buff, ' ', 60); - strncpy(&buff[AR_fmag_offset], "`\n", 2); + memcpy(&buff[AR_fmag_offset], "`\n", 2); if (strcmp(pathname, "/") == 0 ) { /* Entry is archive symbol table in GNU format */ @@ -189,7 +189,7 @@ archive_write_ar_header(struct archive_write *a, struct archive_entry *entry) } if (strcmp(pathname, "__.SYMDEF") == 0) { /* Entry is archive symbol table in BSD format */ - strncpy(buff + AR_name_offset, "__.SYMDEF", 9); + memcpy(buff + AR_name_offset, "__.SYMDEF", 9); goto stat; } if (strcmp(pathname, "//") == 0) { @@ -225,7 +225,7 @@ archive_write_ar_header(struct archive_write *a, struct archive_entry *entry) * actually 15 bytes. */ if (strlen(filename) <= 15) { - strncpy(&buff[AR_name_offset], + memcpy(&buff[AR_name_offset], filename, strlen(filename)); buff[AR_name_offset + strlen(filename)] = '/'; } else { @@ -248,7 +248,7 @@ archive_write_ar_header(struct archive_write *a, struct archive_entry *entry) return (ARCHIVE_FATAL); } - strncpy(se, filename, strlen(filename)); + memcpy(se, filename, strlen(filename)); strcpy(se + strlen(filename), "/\n"); ss = strstr(ar->strtab, se); @@ -285,11 +285,11 @@ archive_write_ar_header(struct archive_write *a, struct archive_entry *entry) * archive header. */ if (strlen(filename) <= 16 && strchr(filename, ' ') == NULL) { - strncpy(&buff[AR_name_offset], filename, strlen(filename)); + memcpy(&buff[AR_name_offset], filename, strlen(filename)); buff[AR_name_offset + strlen(filename)] = ' '; } else { - strncpy(buff + AR_name_offset, "#1/", 3); + memcpy(buff + AR_name_offset, "#1/", 3); if (format_decimal(strlen(filename), buff + AR_name_offset + 3, AR_name_size - 3)) { @@ -374,13 +374,14 @@ archive_write_ar_data(struct archive_write *a, const void *buff, size_t s) return (ARCHIVE_WARN); } - ar->strtab = (char *)malloc(s); + ar->strtab = (char *)malloc(s + 1); if (ar->strtab == NULL) { archive_set_error(&a->archive, ENOMEM, "Can't allocate strtab buffer"); return (ARCHIVE_FATAL); } - strncpy(ar->strtab, buff, s); + memcpy(ar->strtab, buff, s); + ar->strtab[s] = '\0'; ar->has_strtab = 1; } diff --git a/libarchive/archive_write_set_format_pax.c b/libarchive/archive_write_set_format_pax.c index 0eaf733..3cebeae 100644 --- a/libarchive/archive_write_set_format_pax.c +++ b/libarchive/archive_write_set_format_pax.c @@ -1654,7 +1654,7 @@ build_pax_attribute_name(char *dest, const char *src) * GNU PAX Format 1.0 requires the special name, which pattern is: * /GNUSparseFile./ * - * Since reproducable archives are more important, use 0 as pid. + * Since reproducible archives are more important, use 0 as pid. * * This function is used for only Sparse file, a file type of which * is regular file. https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=710f37c47a7df54c39e50d050e790271c547ad80 commit 710f37c47a7df54c39e50d050e790271c547ad80 Author: Brad King AuthorDate: Wed Sep 26 09:52:01 2018 -0400 Commit: Brad King CommitDate: Wed Sep 26 09:52:01 2018 -0400 libarchive: Update script to get 3.3.3 diff --git a/Utilities/Scripts/update-libarchive.bash b/Utilities/Scripts/update-libarchive.bash index 7534f94..3188658 100755 --- a/Utilities/Scripts/update-libarchive.bash +++ b/Utilities/Scripts/update-libarchive.bash @@ -8,7 +8,7 @@ readonly name="LibArchive" readonly ownership="LibArchive Upstream " readonly subtree="Utilities/cmlibarchive" readonly repo="https://github.com/libarchive/libarchive.git" -readonly tag="v3.3.2" +readonly tag="v3.3.3" readonly shortlog=false readonly paths=" CMakeLists.txt https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=97e1213a88437835256aba8e9628a5375265978f commit 97e1213a88437835256aba8e9628a5375265978f Merge: 3181f84 e7e88e9 Author: Brad King AuthorDate: Wed Sep 26 09:51:12 2018 -0400 Commit: Brad King CommitDate: Wed Sep 26 09:51:12 2018 -0400 Merge branch 'libarchive-libressl-2.7' into update-libarchive https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=62709beff8e9bf786b9c3ec5fbd791ce2d452232 commit 62709beff8e9bf786b9c3ec5fbd791ce2d452232 Author: Sean Warren AuthorDate: Wed Sep 26 15:18:24 2018 +1000 Commit: Brad King CommitDate: Wed Sep 26 07:54:50 2018 -0400 FindMatlab: Add Matlab 2018a,b to version list diff --git a/Help/release/dev/FindMatlab-2018b.rst b/Help/release/dev/FindMatlab-2018b.rst index 28758f1..c698b9d 100644 --- a/Help/release/dev/FindMatlab-2018b.rst +++ b/Help/release/dev/FindMatlab-2018b.rst @@ -7,3 +7,6 @@ FindMatlab-2018b * The :module:`FindMatlab` module now explicitly exports mexFunction in Visual Studio. + +* The :module:`FindMatlab` module gained the ability to discover Matlab R2018a + and R2018b. diff --git a/Modules/FindMatlab.cmake b/Modules/FindMatlab.cmake index da832ce..547a330 100644 --- a/Modules/FindMatlab.cmake +++ b/Modules/FindMatlab.cmake @@ -242,6 +242,8 @@ if(NOT MATLAB_ADDITIONAL_VERSIONS) endif() set(MATLAB_VERSIONS_MAPPING + "R2018b=9.5" + "R2018a=9.4" "R2017b=9.3" "R2017a=9.2" "R2016b=9.1" https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=9a56ed3438f652ec526afabeab87e04f330e4724 commit 9a56ed3438f652ec526afabeab87e04f330e4724 Author: Sean Warren AuthorDate: Wed Sep 26 15:17:40 2018 +1000 Commit: Brad King CommitDate: Wed Sep 26 07:54:01 2018 -0400 FindMatlab: Explicitly export mexFunction in MSVC Fixes: #18391 diff --git a/Help/release/dev/FindMatlab-2018b.rst b/Help/release/dev/FindMatlab-2018b.rst index 7e17966..28758f1 100644 --- a/Help/release/dev/FindMatlab-2018b.rst +++ b/Help/release/dev/FindMatlab-2018b.rst @@ -4,3 +4,6 @@ FindMatlab-2018b * The :module:`FindMatlab` module gained new components ``ENGINE_LIBRARY`` and ``DATAARRAY_LIBRARY`` to request finding the Matlab C++ Engine and DataArray libraries respectively. + +* The :module:`FindMatlab` module now explicitly exports mexFunction in Visual + Studio. diff --git a/Modules/FindMatlab.cmake b/Modules/FindMatlab.cmake index 4565076..da832ce 100644 --- a/Modules/FindMatlab.cmake +++ b/Modules/FindMatlab.cmake @@ -996,6 +996,20 @@ function(matlab_add_mex) endif() # documentation # entry point in the mex file + taking care of visibility and symbol clashes. + if (MSVC) + get_target_property( + _previous_link_flags + ${${prefix}_NAME} + LINK_FLAGS) + if(NOT _previous_link_flags) + set(_previous_link_flags) + endif() + + set_target_properties(${${prefix}_NAME} + PROPERTIES + LINK_FLAGS "${_previous_link_flags} /EXPORT:mexFunction") + endif() + if(WIN32) set_target_properties(${${prefix}_NAME} PROPERTIES https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=6c57f6b347f2acf19ef043e38463ac03919594f3 commit 6c57f6b347f2acf19ef043e38463ac03919594f3 Author: Sean Warren AuthorDate: Wed Sep 26 15:15:37 2018 +1000 Commit: Brad King CommitDate: Wed Sep 26 07:53:50 2018 -0400 FindMatlab: Optionally allow linking to MatlabEngine and MatlabDataArray Fixes: #17971 diff --git a/Help/release/dev/FindMatlab-2018b.rst b/Help/release/dev/FindMatlab-2018b.rst new file mode 100644 index 0000000..7e17966 --- /dev/null +++ b/Help/release/dev/FindMatlab-2018b.rst @@ -0,0 +1,6 @@ +FindMatlab-2018b +---------------- + +* The :module:`FindMatlab` module gained new components ``ENGINE_LIBRARY`` and + ``DATAARRAY_LIBRARY`` to request finding the Matlab C++ Engine and DataArray + libraries respectively. diff --git a/Modules/FindMatlab.cmake b/Modules/FindMatlab.cmake index 12a2f75..4565076 100644 --- a/Modules/FindMatlab.cmake +++ b/Modules/FindMatlab.cmake @@ -21,6 +21,8 @@ # # * ``MX_LIBRARY``, ``ENG_LIBRARY`` and ``MAT_LIBRARY``: respectively the ``MX``, # ``ENG`` and ``MAT`` libraries of Matlab +# * ``ENGINE_LIBRARY``, ``DATAARRAY_LIBRARY``: respectively the ``MatlabEngine`` +# and ``MatlabDataArray`` libraries of Matlab (Matlab 2018a and later) # * ``MAIN_PROGRAM`` the Matlab binary program. Note that this component is not # available on the MCR version, and will yield an error if the MCR is found # instead of the regular Matlab installation. @@ -107,6 +109,12 @@ # ``Matlab_MAT_LIBRARY`` # Matlab matrix library. Available only if the component ``MAT_LIBRARY`` # is requested. +# ``Matlab_ENGINE_LIBRARY`` +# Matlab C++ engine library. Available only if the component ``ENGINE_LIBRARY`` +# is requested. +# ``Matlab_DATAARRAY_LIBRARY`` +# Matlab C++ data array library. Available only if the component ``DATAARRAY_LIBRARY`` +# is requested. # ``Matlab_LIBRARIES`` # the whole set of libraries of Matlab # ``Matlab_MEX_COMPILER`` @@ -960,6 +968,14 @@ function(matlab_add_mex) target_link_libraries(${${prefix}_NAME} ${Matlab_MX_LIBRARY}) endif() + if(DEFINED Matlab_ENGINE_LIBRARY) + target_link_libraries(${${prefix}_NAME} ${Matlab_ENGINE_LIBRARY}) + endif() + + if(DEFINED Matlab_DATAARRAY_LIBRARY) + target_link_libraries(${${prefix}_NAME} ${Matlab_DATAARRAY_LIBRARY}) + endif() + target_link_libraries(${${prefix}_NAME} ${Matlab_MEX_LIBRARY} ${${prefix}_LINK_TO}) set_target_properties(${${prefix}_NAME} PROPERTIES @@ -1416,6 +1432,8 @@ if(DEFINED Matlab_ROOT_DIR_LAST_CACHED) Matlab_MX_LIBRARY Matlab_ENG_LIBRARY Matlab_MAT_LIBRARY + Matlab_ENGINE_LIBRARY + Matlab_DATAARRAY_LIBRARY Matlab_MEX_EXTENSION Matlab_SIMULINK_INCLUDE_DIR @@ -1668,10 +1686,52 @@ if(_matlab_find_mcc_compiler GREATER -1) endif() unset(_matlab_find_mcc_compiler) +# component MatlabEngine +list(FIND Matlab_FIND_COMPONENTS ENGINE_LIBRARY _matlab_find_matlab_engine) +if(_matlab_find_matlab_engine GREATER -1) + _Matlab_find_library( + ${_matlab_lib_prefix_for_search} + Matlab_ENGINE_LIBRARY + MatlabEngine + PATHS ${_matlab_lib_dir_for_search} + DOC "MatlabEngine Library" + NO_DEFAULT_PATH + ) + if(Matlab_ENGINE_LIBRARY) + set(Matlab_ENGINE_LIBRARY_FOUND TRUE) + endif() +endif() +unset(_matlab_find_matlab_engine) + +# component MatlabDataArray +list(FIND Matlab_FIND_COMPONENTS DATAARRAY_LIBRARY _matlab_find_matlab_dataarray) +if(_matlab_find_matlab_dataarray GREATER -1) + _Matlab_find_library( + ${_matlab_lib_prefix_for_search} + Matlab_DATAARRAY_LIBRARY + MatlabDataArray + PATHS ${_matlab_lib_dir_for_search} + DOC "MatlabDataArray Library" + NO_DEFAULT_PATH + ) + if(Matlab_DATAARRAY_LIBRARY) + set(Matlab_DATAARRAY_LIBRARY_FOUND TRUE) + endif() +endif() +unset(_matlab_find_matlab_dataarray) + unset(_matlab_lib_dir_for_search) set(Matlab_LIBRARIES ${Matlab_MEX_LIBRARY} ${Matlab_MX_LIBRARY} ${Matlab_ENG_LIBRARY} ${Matlab_MAT_LIBRARY}) +if(Matlab_DATAARRAY_LIBRARY_FOUND) + set(Matlab_LIBRARIES ${Matlab_LIBRARIES} ${Matlab_DATAARRAY_LIBRARY}) +endif() + +if(Matlab_ENGINE_LIBRARY_FOUND) + set(Matlab_LIBRARIES ${Matlab_LIBRARIES} ${Matlab_ENGINE_LIBRARY}) +endif() + find_package_handle_standard_args( Matlab FOUND_VAR Matlab_FOUND @@ -1692,6 +1752,8 @@ if(Matlab_INCLUDE_DIRS AND Matlab_LIBRARIES) Matlab_MEX_LIBRARY Matlab_MX_LIBRARY Matlab_ENG_LIBRARY + Matlab_ENGINE_LIBRARY + Matlab_DATAARRAY_LIBRARY Matlab_MAT_LIBRARY Matlab_INCLUDE_DIRS Matlab_FOUND ----------------------------------------------------------------------- Summary of changes: CMakeLists.txt | 1 + Help/release/dev/FindMatlab-2018b.rst | 12 + Modules/CMakeDetermineASMCompiler.cmake | 6 +- Modules/FindMatlab.cmake | 78 +++++ Utilities/Scripts/update-libarchive.bash | 2 +- Utilities/cmlibarchive/CMakeLists.txt | 49 ++- Utilities/cmlibarchive/build/cmake/config.h.in | 10 + .../cmlibarchive/build/pkgconfig/libarchive.pc.in | 1 + Utilities/cmlibarchive/build/version | 2 +- Utilities/cmlibarchive/libarchive/CMakeLists.txt | 2 + Utilities/cmlibarchive/libarchive/archive.h | 8 +- Utilities/cmlibarchive/libarchive/archive_acl.c | 2 + .../cmlibarchive/libarchive/archive_cmdline.c | 6 +- .../cmlibarchive/libarchive/archive_cryptor.c | 2 +- .../libarchive/archive_cryptor_private.h | 2 +- .../libarchive/archive_disk_acl_freebsd.c | 2 + Utilities/cmlibarchive/libarchive/archive_entry.c | 4 +- Utilities/cmlibarchive/libarchive/archive_entry.h | 3 +- Utilities/cmlibarchive/libarchive/archive_match.c | 4 +- .../libarchive/archive_openssl_hmac_private.h | 3 +- .../cmlibarchive/libarchive/archive_pack_dev.c | 3 + .../cmlibarchive/libarchive/archive_platform.h | 6 + Utilities/cmlibarchive/libarchive/archive_ppmd7.c | 10 +- .../libarchive/archive_ppmd7_private.h | 4 +- .../cmlibarchive/libarchive/archive_ppmd_private.h | 7 - Utilities/cmlibarchive/libarchive/archive_read.c | 12 +- .../libarchive/archive_read_append_filter.c | 4 + .../libarchive/archive_read_disk_entry_from_file.c | 2 +- .../libarchive/archive_read_disk_posix.c | 8 +- .../libarchive/archive_read_disk_windows.c | 19 +- .../cmlibarchive/libarchive/archive_read_filter.3 | 6 +- .../libarchive/archive_read_support_filter_all.c | 2 + .../libarchive/archive_read_support_filter_zstd.c | 292 ++++++++++++++++++ .../libarchive/archive_read_support_format_7zip.c | 21 +- .../libarchive/archive_read_support_format_cpio.c | 7 + .../archive_read_support_format_iso9660.c | 29 +- .../libarchive/archive_read_support_format_lha.c | 6 + .../libarchive/archive_read_support_format_mtree.c | 109 ++++--- .../libarchive/archive_read_support_format_rar.c | 30 +- .../libarchive/archive_read_support_format_tar.c | 10 +- .../libarchive/archive_read_support_format_xar.c | 32 +- .../libarchive/archive_read_support_format_zip.c | 32 +- Utilities/cmlibarchive/libarchive/archive_string.c | 3 +- Utilities/cmlibarchive/libarchive/archive_util.c | 4 +- .../libarchive/archive_version_details.c | 18 ++ .../cmlibarchive/libarchive/archive_virtual.c | 11 +- Utilities/cmlibarchive/libarchive/archive_write.3 | 2 +- Utilities/cmlibarchive/libarchive/archive_write.c | 2 +- .../libarchive/archive_write_add_filter.c | 1 + .../libarchive/archive_write_add_filter_by_name.c | 1 + .../libarchive/archive_write_add_filter_gzip.c | 7 +- .../libarchive/archive_write_add_filter_zstd.c | 335 +++++++++++++++++++++ .../libarchive/archive_write_disk_posix.c | 12 +- .../libarchive/archive_write_disk_windows.c | 19 +- .../cmlibarchive/libarchive/archive_write_filter.3 | 6 +- .../libarchive/archive_write_set_format_7zip.c | 17 +- .../libarchive/archive_write_set_format_ar.c | 17 +- .../libarchive/archive_write_set_format_pax.c | 2 +- 58 files changed, 1098 insertions(+), 209 deletions(-) create mode 100644 Help/release/dev/FindMatlab-2018b.rst create mode 100644 Utilities/cmlibarchive/libarchive/archive_read_support_filter_zstd.c create mode 100644 Utilities/cmlibarchive/libarchive/archive_write_add_filter_zstd.c hooks/post-receive -- CMake From kwrobot at kitware.com Thu Sep 27 14:55:06 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Thu, 27 Sep 2018 14:55:06 -0400 (EDT) Subject: [Cmake-commits] CMake branch, release, updated. v3.12.2-12-ga9694d6 Message-ID: <20180927185506.65BACFE503@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, release has been updated via a9694d6538b5a975b08cea89bdd86ebce6166452 (commit) via e7e88e955bc773be792e645ee8558d78b4183a87 (commit) from 60e6e5db61d6f27814bb68dee1f497848e147ffb (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- ----------------------------------------------------------------------- Summary of changes: Utilities/cmlibarchive/libarchive/archive_openssl_hmac_private.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) hooks/post-receive -- CMake From kwrobot at kitware.com Fri Sep 28 00:05:06 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Fri, 28 Sep 2018 00:05:06 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-751-g8bb0e09 Message-ID: <20180928040506.740D212156F@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 8bb0e09e38d3ab75198b1cd9746bfa7a7b80ff94 (commit) from 3f7312a97800801735a63dd65b17e06a0fc61348 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=8bb0e09e38d3ab75198b1cd9746bfa7a7b80ff94 commit 8bb0e09e38d3ab75198b1cd9746bfa7a7b80ff94 Author: Kitware Robot AuthorDate: Fri Sep 28 00:01:10 2018 -0400 Commit: Kitware Robot CommitDate: Fri Sep 28 00:01:10 2018 -0400 CMake Nightly Date Stamp diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 1a82e2a..d9aa818 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 12) -set(CMake_VERSION_PATCH 20180927) +set(CMake_VERSION_PATCH 20180928) #set(CMake_VERSION_RC 1) ----------------------------------------------------------------------- Summary of changes: Source/CMakeVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) hooks/post-receive -- CMake From kwrobot at kitware.com Fri Sep 28 11:05:04 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Fri, 28 Sep 2018 11:05:04 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-758-g8fea6b0 Message-ID: <20180928150504.8702D125475@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 8fea6b0764dbf1b6893e7ca81d93cddca2facfce (commit) via 9c4445a0dd67a0176a00426a3bb6fed149c03810 (commit) via 22282d69316eaf6e4a2b50af2ca7585a58f00d28 (commit) via 57b9a072cb7e943885a608e99188822b6064708a (commit) via 98e4fbdc063ea738f1f2fa38028be14492297d0f (commit) via 6597428c364c0a495bba88a6154ac0ed7f3cd461 (commit) via d8294fefe8063cc2e0a0cfecf7fd8fef619cf0da (commit) from 8bb0e09e38d3ab75198b1cd9746bfa7a7b80ff94 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=8fea6b0764dbf1b6893e7ca81d93cddca2facfce commit 8fea6b0764dbf1b6893e7ca81d93cddca2facfce Merge: 9c4445a 98e4fbd Author: Brad King AuthorDate: Fri Sep 28 14:58:20 2018 +0000 Commit: Kitware Robot CommitDate: Fri Sep 28 10:58:51 2018 -0400 Merge topic 'vs-msbuild-platform' 98e4fbdc06 VS: Pass platform when invoking MSBuild 6597428c36 ctest: Fix generator platform under --build-nocmake d8294fefe8 cmake: Fix generator platform under --build mode Acked-by: Kitware Robot Merge-request: !2413 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=9c4445a0dd67a0176a00426a3bb6fed149c03810 commit 9c4445a0dd67a0176a00426a3bb6fed149c03810 Merge: 8bb0e09 22282d6 Author: Brad King AuthorDate: Fri Sep 28 14:58:08 2018 +0000 Commit: Kitware Robot CommitDate: Fri Sep 28 10:58:15 2018 -0400 Merge topic 'addvs2017arm64' 22282d6931 Tests: Add VSWinStore* test for VS 2017 ARM64 57b9a072cb Tests: Teach VSWinStore* tests to pass the architecture as a parameter Acked-by: Kitware Robot Merge-request: !2389 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=22282d69316eaf6e4a2b50af2ca7585a58f00d28 commit 22282d69316eaf6e4a2b50af2ca7585a58f00d28 Author: Gilles Khouzam AuthorDate: Fri Sep 14 11:33:46 2018 -0700 Commit: Brad King CommitDate: Wed Sep 26 06:57:43 2018 -0400 Tests: Add VSWinStore* test for VS 2017 ARM64 diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index b325039..03f4c32 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -2168,6 +2168,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release add_test_VSWinStorePhone(vs15-store10_0-X86 "Visual Studio 15 2017" WindowsStore 10.0 Win32) add_test_VSWinStorePhone(vs15-store10_0-ARM "Visual Studio 15 2017" WindowsStore 10.0 ARM) add_test_VSWinStorePhone(vs15-store10_0-X64 "Visual Studio 15 2017" WindowsStore 10.0 x64) + add_test_VSWinStorePhone(vs15-store10_0-ARM64 "Visual Studio 15 2017" WindowsStore 10.0 ARM64) endif() if(vs14 AND ws10_0) add_test_VSWinStorePhone(vs14-store10_0-X86 "Visual Studio 14 2015" WindowsStore 10.0 Win32) https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=57b9a072cb7e943885a608e99188822b6064708a commit 57b9a072cb7e943885a608e99188822b6064708a Author: Gilles Khouzam AuthorDate: Fri Sep 14 11:33:46 2018 -0700 Commit: Brad King CommitDate: Wed Sep 26 06:57:04 2018 -0400 Tests: Teach VSWinStore* tests to pass the architecture as a parameter Instead of specifying the architecture in the generator name, pass it as the generator platform. This has been preferred since CMake 3.1. diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index fb44077..b325039 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -2128,12 +2128,13 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release get_filename_component(ntver "[HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion;CurrentVersion]" NAME) if(WIN32 AND ntver VERSION_GREATER 6.1) # Windows >= 8.0 - macro(add_test_VSWinStorePhone name generator systemName systemVersion) + macro(add_test_VSWinStorePhone name generator systemName systemVersion architecture) add_test(NAME VSWinStorePhone.${name} COMMAND ${CMAKE_CTEST_COMMAND} --build-and-test "${CMake_SOURCE_DIR}/Tests/VSWinStorePhone" "${CMake_BINARY_DIR}/Tests/VSWinStorePhone/${name}" --build-generator "${generator}" + --build-generator-platform "${architecture}" --build-project VSWinStorePhone --build-config $ --build-options -DCMAKE_SYSTEM_NAME=${systemName} @@ -2143,14 +2144,14 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release endmacro() if(vs11 AND ws80) - add_test_VSWinStorePhone(vs11-store80-X86 "Visual Studio 11 2012" WindowsStore 8.0) - add_test_VSWinStorePhone(vs11-store80-ARM "Visual Studio 11 2012 ARM" WindowsStore 8.0) - add_test_VSWinStorePhone(vs11-store80-X64 "Visual Studio 11 2012 Win64" WindowsStore 8.0) + add_test_VSWinStorePhone(vs11-store80-X86 "Visual Studio 11 2012" WindowsStore 8.0 Win32) + add_test_VSWinStorePhone(vs11-store80-ARM "Visual Studio 11 2012" WindowsStore 8.0 ARM) + add_test_VSWinStorePhone(vs11-store80-X64 "Visual Studio 11 2012" WindowsStore 8.0 x64) endif() if(vs12 AND ws81) - add_test_VSWinStorePhone(vs12-store81-X86 "Visual Studio 12 2013" WindowsStore 8.1) - add_test_VSWinStorePhone(vs12-store81-ARM "Visual Studio 12 2013 ARM" WindowsStore 8.1) - add_test_VSWinStorePhone(vs12-store81-X64 "Visual Studio 12 2013 Win64" WindowsStore 8.1) + add_test_VSWinStorePhone(vs12-store81-X86 "Visual Studio 12 2013" WindowsStore 8.1 Win32) + add_test_VSWinStorePhone(vs12-store81-ARM "Visual Studio 12 2013" WindowsStore 8.1 ARM) + add_test_VSWinStorePhone(vs12-store81-X64 "Visual Studio 12 2013" WindowsStore 8.1 x64) add_test(NAME VSXaml COMMAND ${CMAKE_CTEST_COMMAND} --build-and-test @@ -2164,22 +2165,22 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release ) endif() if(CMake_TEST_VSWinStorePhone_VS_2017 AND ws10_0) - add_test_VSWinStorePhone(vs15-store10_0-X86 "Visual Studio 15 2017" WindowsStore 10.0) - add_test_VSWinStorePhone(vs15-store10_0-ARM "Visual Studio 15 2017 ARM" WindowsStore 10.0) - add_test_VSWinStorePhone(vs15-store10_0-X64 "Visual Studio 15 2017 Win64" WindowsStore 10.0) + add_test_VSWinStorePhone(vs15-store10_0-X86 "Visual Studio 15 2017" WindowsStore 10.0 Win32) + add_test_VSWinStorePhone(vs15-store10_0-ARM "Visual Studio 15 2017" WindowsStore 10.0 ARM) + add_test_VSWinStorePhone(vs15-store10_0-X64 "Visual Studio 15 2017" WindowsStore 10.0 x64) endif() if(vs14 AND ws10_0) - add_test_VSWinStorePhone(vs14-store10_0-X86 "Visual Studio 14 2015" WindowsStore 10.0) - add_test_VSWinStorePhone(vs14-store10_0-ARM "Visual Studio 14 2015 ARM" WindowsStore 10.0) - add_test_VSWinStorePhone(vs14-store10_0-X64 "Visual Studio 14 2015 Win64" WindowsStore 10.0) + add_test_VSWinStorePhone(vs14-store10_0-X86 "Visual Studio 14 2015" WindowsStore 10.0 Win32) + add_test_VSWinStorePhone(vs14-store10_0-ARM "Visual Studio 14 2015" WindowsStore 10.0 ARM) + add_test_VSWinStorePhone(vs14-store10_0-X64 "Visual Studio 14 2015" WindowsStore 10.0 x64) endif() if(vs11 AND wp80) - add_test_VSWinStorePhone(vs11-phone80-X86 "Visual Studio 11 2012" WindowsPhone 8.0) - add_test_VSWinStorePhone(vs11-phone80-ARM "Visual Studio 11 2012 ARM" WindowsPhone 8.0) + add_test_VSWinStorePhone(vs11-phone80-X86 "Visual Studio 11 2012" WindowsPhone 8.0 Win32) + add_test_VSWinStorePhone(vs11-phone80-ARM "Visual Studio 11 2012" WindowsPhone 8.0 ARM) endif() if(vs12 AND wp81) - add_test_VSWinStorePhone(vs12-phone81-X86 "Visual Studio 12 2013" WindowsPhone 8.1) - add_test_VSWinStorePhone(vs12-phone81-ARM "Visual Studio 12 2013 ARM" WindowsPhone 8.1) + add_test_VSWinStorePhone(vs12-phone81-X86 "Visual Studio 12 2013" WindowsPhone 8.1 Win32) + add_test_VSWinStorePhone(vs12-phone81-ARM "Visual Studio 12 2013" WindowsPhone 8.1 ARM) endif() endif() https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=98e4fbdc063ea738f1f2fa38028be14492297d0f commit 98e4fbdc063ea738f1f2fa38028be14492297d0f Author: Brad King AuthorDate: Tue Sep 25 13:25:36 2018 -0400 Commit: Brad King CommitDate: Tue Sep 25 13:27:13 2018 -0400 VS: Pass platform when invoking MSBuild MSBuild expects a `/p:Platform=...` argument to tell it which platform to build among those in the `.vcxproj` files. We have not historically had to do this because we generate only one platform. However, when a project uses `include_external_msproject` the included project file may have other platforms. Fixes: #18308 diff --git a/Source/cmGlobalVisualStudio10Generator.cxx b/Source/cmGlobalVisualStudio10Generator.cxx index 5ea323a..82fcaad 100644 --- a/Source/cmGlobalVisualStudio10Generator.cxx +++ b/Source/cmGlobalVisualStudio10Generator.cxx @@ -938,6 +938,7 @@ void cmGlobalVisualStudio10Generator::GenerateBuildCommand( configArg += "Debug"; } makeCommand.push_back(configArg); + makeCommand.push_back("/p:Platform=" + this->GetPlatformName()); makeCommand.push_back(std::string("/p:VisualStudioVersion=") + this->GetIDEVersion()); https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=6597428c364c0a495bba88a6154ac0ed7f3cd461 commit 6597428c364c0a495bba88a6154ac0ed7f3cd461 Author: Brad King AuthorDate: Tue Sep 25 13:20:30 2018 -0400 Commit: Brad King CommitDate: Tue Sep 25 13:27:11 2018 -0400 ctest: Fix generator platform under --build-nocmake When constructing a global generator instance in `--build-and-test` mode we need to set the platform passed by `--build-generator-platform` directly on the generator. The old code that set it on the `cmake` class instance did nothing because that only affects cache initialization, which is not done by `--build-nocmake`. diff --git a/Source/CTest/cmCTestBuildAndTestHandler.cxx b/Source/CTest/cmCTestBuildAndTestHandler.cxx index fccbc95..668a387 100644 --- a/Source/CTest/cmCTestBuildAndTestHandler.cxx +++ b/Source/CTest/cmCTestBuildAndTestHandler.cxx @@ -5,6 +5,7 @@ #include "cmCTest.h" #include "cmCTestTestHandler.h" #include "cmGlobalGenerator.h" +#include "cmMakefile.h" #include "cmSystemTools.h" #include "cmWorkingDirectory.h" #include "cmake.h" @@ -210,9 +211,14 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring) if (this->BuildNoCMake) { // Make the generator available for the Build call below. - cm.SetGlobalGenerator(cm.CreateGlobalGenerator(this->BuildGenerator)); - cm.SetGeneratorPlatform(this->BuildGeneratorPlatform); - cm.SetGeneratorToolset(this->BuildGeneratorToolset); + cmGlobalGenerator* gen = cm.CreateGlobalGenerator(this->BuildGenerator); + cm.SetGlobalGenerator(gen); + if (!this->BuildGeneratorPlatform.empty()) { + cmMakefile mf(gen, cm.GetCurrentSnapshot()); + if (!gen->SetGeneratorPlatform(this->BuildGeneratorPlatform, &mf)) { + return 1; + } + } // Load the cache to make CMAKE_MAKE_PROGRAM available. cm.LoadCache(this->BinaryDir); https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=d8294fefe8063cc2e0a0cfecf7fd8fef619cf0da commit d8294fefe8063cc2e0a0cfecf7fd8fef619cf0da Author: Brad King AuthorDate: Tue Sep 25 10:08:57 2018 -0400 Commit: Brad King CommitDate: Tue Sep 25 13:27:08 2018 -0400 cmake: Fix generator platform under --build mode diff --git a/Source/cmake.cxx b/Source/cmake.cxx index c26a380..889a5fb 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -2467,6 +2467,14 @@ int cmake::Build(int jobs, const std::string& dir, const std::string& target, return 1; } } + const char* cachedGeneratorPlatform = + this->State->GetCacheEntryValue("CMAKE_GENERATOR_PLATFORM"); + if (cachedGeneratorPlatform) { + cmMakefile mf(gen, this->GetCurrentSnapshot()); + if (!gen->SetGeneratorPlatform(cachedGeneratorPlatform, &mf)) { + return 1; + } + } std::string output; std::string projName; const char* cachedProjectName = ----------------------------------------------------------------------- Summary of changes: Source/CTest/cmCTestBuildAndTestHandler.cxx | 12 +++++++--- Source/cmGlobalVisualStudio10Generator.cxx | 1 + Source/cmake.cxx | 8 +++++++ Tests/CMakeLists.txt | 36 +++++++++++++++-------------- 4 files changed, 37 insertions(+), 20 deletions(-) hooks/post-receive -- CMake From kwrobot at kitware.com Fri Sep 28 11:15:05 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Fri, 28 Sep 2018 11:15:05 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-761-g4e98203 Message-ID: <20180928151505.DB7B1102BFA@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 4e98203c6c318f7c2caf4c31b2c2863772eef57b (commit) via 36489b85aa308e3a1b984da0d1e7d3aff4467752 (commit) via 22e670a3062869e3014455563d800c72f35d9e4f (commit) from 8fea6b0764dbf1b6893e7ca81d93cddca2facfce (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=4e98203c6c318f7c2caf4c31b2c2863772eef57b commit 4e98203c6c318f7c2caf4c31b2c2863772eef57b Merge: 8fea6b0 36489b8 Author: Brad King AuthorDate: Fri Sep 28 15:13:52 2018 +0000 Commit: Kitware Robot CommitDate: Fri Sep 28 11:13:59 2018 -0400 Merge topic 'vs-global-props-for-all-targets' 36489b85aa VS: Add test for CMAKE_VS_GLOBALS 22e670a306 VS: Add option to set VS_GLOBAL_* for all targets Acked-by: Kitware Robot Merge-request: !2345 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=36489b85aa308e3a1b984da0d1e7d3aff4467752 commit 36489b85aa308e3a1b984da0d1e7d3aff4467752 Author: Mikhail Korolev AuthorDate: Thu Sep 27 15:17:19 2018 +0300 Commit: Brad King CommitDate: Fri Sep 28 11:13:03 2018 -0400 VS: Add test for CMAKE_VS_GLOBALS diff --git a/Tests/RunCMake/VS10Project/RunCMakeTest.cmake b/Tests/RunCMake/VS10Project/RunCMakeTest.cmake index d50de3d..4bfb2f2 100644 --- a/Tests/RunCMake/VS10Project/RunCMakeTest.cmake +++ b/Tests/RunCMake/VS10Project/RunCMakeTest.cmake @@ -13,3 +13,4 @@ run_cmake(VsCSharpCustomTags) run_cmake(VsCSharpReferenceProps) run_cmake(VsCSharpWithoutSources) run_cmake(VsSdkDirectories) +run_cmake(VsGlobals) diff --git a/Tests/RunCMake/VS10Project/VsGlobals-check.cmake b/Tests/RunCMake/VS10Project/VsGlobals-check.cmake new file mode 100644 index 0000000..0e7fd45 --- /dev/null +++ b/Tests/RunCMake/VS10Project/VsGlobals-check.cmake @@ -0,0 +1,44 @@ +set(vcProjectFile "${RunCMake_TEST_BINARY_DIR}/foo.vcxproj") +if(NOT EXISTS "${vcProjectFile}") + set(RunCMake_TEST_FAILED "Project file ${vcProjectFile} does not exist.") + return() +endif() + +set(InsideGlobals FALSE) +set(DefaultLanguageSet FALSE) +set(MinimumVisualStudioVersionSet FALSE) + +file(STRINGS "${vcProjectFile}" lines) +foreach(line IN LISTS lines) + if(line MATCHES "^ * *$") + set(InsideGlobals TRUE) + elseif(line MATCHES "^ *([a-zA-Z\\-]+) *$") + if("${CMAKE_MATCH_1}" STREQUAL "en-US") + if(InsideGlobals) + message(STATUS "foo.vcxproj has correct DefaultLanguage global property") + set(DefaultLanguageSet TRUE) + else() + message(STATUS "DefaultLanguage is set but not within \"Globals\" property group") + endif() + endif() + elseif(line MATCHES "^ *([0-9\\.]+) *$") + if("${CMAKE_MATCH_1}" STREQUAL "14.0") + if(InsideGlobals) + message(STATUS "foo.vcxproj has correct MinimumVisualStudioVersion global property") + set(MinimumVisualStudioVersionSet TRUE) + else() + message(STATUS "MinimumVisualStudioVersion is set but not within \"Globals\" property group") + endif() + endif() + endif() +endforeach() + +if(NOT DefaultLanguageSet) + set(RunCMake_TEST_FAILED "DefaultLanguageSet not found or not set correctly.") + return() +endif() + +if(NOT MinimumVisualStudioVersionSet) + set(RunCMake_TEST_FAILED "MinimumVisualStudioVersionSet not found or not set correctly.") + return() +endif() diff --git a/Tests/RunCMake/VS10Project/VsGlobals.cmake b/Tests/RunCMake/VS10Project/VsGlobals.cmake new file mode 100644 index 0000000..a3ed5af --- /dev/null +++ b/Tests/RunCMake/VS10Project/VsGlobals.cmake @@ -0,0 +1,8 @@ +enable_language(CXX) + +set(CMAKE_VS_GLOBALS + "DefaultLanguage=en-US" + "MinimumVisualStudioVersion=14.0" +) + +add_library(foo foo.cpp) https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=22e670a3062869e3014455563d800c72f35d9e4f commit 22e670a3062869e3014455563d800c72f35d9e4f Author: Mikhail Korolev AuthorDate: Fri Sep 21 14:23:22 2018 +0300 Commit: Brad King CommitDate: Tue Sep 25 09:20:25 2018 -0400 VS: Add option to set VS_GLOBAL_* for all targets Fixes: #18287 diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst index 6071999..f217f11 100644 --- a/Help/manual/cmake-variables.7.rst +++ b/Help/manual/cmake-variables.7.rst @@ -394,6 +394,7 @@ Variables that Control the Build /variable/CMAKE_TRY_COMPILE_TARGET_TYPE /variable/CMAKE_USE_RELATIVE_PATHS /variable/CMAKE_VISIBILITY_INLINES_HIDDEN + /variable/CMAKE_VS_GLOBALS /variable/CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD /variable/CMAKE_VS_INCLUDE_PACKAGE_TO_DEFAULT_BUILD /variable/CMAKE_VS_SDK_EXCLUDE_DIRECTORIES diff --git a/Help/release/dev/vs-global-props-for-all-targets.rst b/Help/release/dev/vs-global-props-for-all-targets.rst new file mode 100644 index 0000000..647949e --- /dev/null +++ b/Help/release/dev/vs-global-props-for-all-targets.rst @@ -0,0 +1,6 @@ +vs-global-props-for-all-targets +------------------------------- + +* A :variable:`CMAKE_VS_GLOBALS` variable was added to initialize + :prop_tgt:`VS_GLOBAL_` target properties on targets as + they are created. diff --git a/Help/variable/CMAKE_VS_GLOBALS.rst b/Help/variable/CMAKE_VS_GLOBALS.rst new file mode 100644 index 0000000..83777b6 --- /dev/null +++ b/Help/variable/CMAKE_VS_GLOBALS.rst @@ -0,0 +1,21 @@ +CMAKE_VS_GLOBALS +---------------- + +List of ``Key=Value`` records to be set per target as target properties +:prop_tgt:`VS_GLOBAL_` with ``variable=Key`` and value ``Value``. + +For example: + +.. code-block:: cmake + + set(CMAKE_VS_GLOBALS + "DefaultLanguage=en-US" + "MinimumVisualStudioVersion=14.0" + ) + +will set properties ``VS_GLOBAL_DefaultLanguage`` to ``en-US`` and +``VS_GLOBAL_MinimumVisualStudioVersion`` to ``14.0`` for all targets +(except for ``INTERFACE`` libraries). + +This variable is meant to be set by a +:variable:`toolchain file `. diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 4e353c7..a338fe3 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -440,6 +440,31 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, if (this->TargetTypeValue <= cmStateEnums::UTILITY) { this->SetPropertyDefault("DOTNET_TARGET_FRAMEWORK_VERSION", nullptr); } + + if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY && + this->GetType() != cmStateEnums::UTILITY) { + + // check for "CMAKE_VS_GLOBALS" variable and set up target properties + // if any + const char* globals = mf->GetDefinition("CMAKE_VS_GLOBALS"); + if (globals) { + const std::string genName = mf->GetGlobalGenerator()->GetName(); + if (cmHasLiteralPrefix(genName, "Visual Studio")) { + std::vector props; + cmSystemTools::ExpandListArgument(globals, props); + const std::string vsGlobal = "VS_GLOBAL_"; + for (const std::string& i : props) { + // split NAME=VALUE + const std::string::size_type assignment = i.find('='); + if (assignment != std::string::npos) { + const std::string propName = vsGlobal + i.substr(0, assignment); + const std::string propValue = i.substr(assignment + 1); + this->SetPropertyDefault(propName, propValue.c_str()); + } + } + } + } + } } cmGlobalGenerator* cmTarget::GetGlobalGenerator() const ----------------------------------------------------------------------- Summary of changes: Help/manual/cmake-variables.7.rst | 1 + .../dev/vs-global-props-for-all-targets.rst | 6 +++ Help/variable/CMAKE_VS_GLOBALS.rst | 21 +++++++++++ Source/cmTarget.cxx | 25 ++++++++++++ Tests/RunCMake/VS10Project/RunCMakeTest.cmake | 1 + Tests/RunCMake/VS10Project/VsGlobals-check.cmake | 44 ++++++++++++++++++++++ Tests/RunCMake/VS10Project/VsGlobals.cmake | 8 ++++ 7 files changed, 106 insertions(+) create mode 100644 Help/release/dev/vs-global-props-for-all-targets.rst create mode 100644 Help/variable/CMAKE_VS_GLOBALS.rst create mode 100644 Tests/RunCMake/VS10Project/VsGlobals-check.cmake create mode 100644 Tests/RunCMake/VS10Project/VsGlobals.cmake hooks/post-receive -- CMake From kwrobot at kitware.com Fri Sep 28 11:25:04 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Fri, 28 Sep 2018 11:25:04 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-763-gcac09cc Message-ID: <20180928152504.E485B1206E7@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via cac09cc52ccba9f3435e4d7cc227d15b6a009855 (commit) via f158ac19e1e52362b04ff08c309ac3cf8e429bb7 (commit) from 4e98203c6c318f7c2caf4c31b2c2863772eef57b (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=cac09cc52ccba9f3435e4d7cc227d15b6a009855 commit cac09cc52ccba9f3435e4d7cc227d15b6a009855 Merge: 4e98203 f158ac1 Author: Brad King AuthorDate: Fri Sep 28 15:16:47 2018 +0000 Commit: Kitware Robot CommitDate: Fri Sep 28 11:17:09 2018 -0400 Merge topic 'customcommandworkingdirectory' f158ac19e1 add_custom_{command,target}: WORKING_DIRECTORY generator expressions Acked-by: Kitware Robot Merge-request: !2409 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=f158ac19e1e52362b04ff08c309ac3cf8e429bb7 commit f158ac19e1e52362b04ff08c309ac3cf8e429bb7 Author: Jon Chronopoulos AuthorDate: Sat Sep 22 17:00:28 2018 +1000 Commit: Brad King CommitDate: Fri Sep 28 11:15:33 2018 -0400 add_custom_{command,target}: WORKING_DIRECTORY generator expressions This teaches add_custom_command and add_custom_target WORKING_DIRECTORY about generator expressions Fixes: #14089 diff --git a/Help/command/add_custom_command.rst b/Help/command/add_custom_command.rst index 5f74c54..71fe494 100644 --- a/Help/command/add_custom_command.rst +++ b/Help/command/add_custom_command.rst @@ -182,6 +182,9 @@ The options are: If it is a relative path it will be interpreted relative to the build tree directory corresponding to the current source directory. + Arguments to ``WORKING_DIRECTORY`` may use + :manual:`generator expressions `. + ``DEPFILE`` Specify a ``.d`` depfile for the :generator:`Ninja` generator. A ``.d`` file holds dependencies usually emitted by the custom diff --git a/Help/command/add_custom_target.rst b/Help/command/add_custom_target.rst index bd61c8b..a6b2f77 100644 --- a/Help/command/add_custom_target.rst +++ b/Help/command/add_custom_target.rst @@ -121,3 +121,6 @@ The options are: Execute the command with the given current working directory. If it is a relative path it will be interpreted relative to the build tree directory corresponding to the current source directory. + + Arguments to ``WORKING_DIRECTORY`` may use + :manual:`generator expressions `. diff --git a/Help/release/dev/custom_command-working_directory-genex.rst b/Help/release/dev/custom_command-working_directory-genex.rst new file mode 100644 index 0000000..ae06202 --- /dev/null +++ b/Help/release/dev/custom_command-working_directory-genex.rst @@ -0,0 +1,5 @@ +custom_command-working_directory-genex +-------------------------------------- + +* The :command:`add_custom_command` and :command:`add_custom_target` commands + learned to support generator expressions in ``WORKING_DIRECTORY`` options. diff --git a/Source/cmCustomCommandGenerator.cxx b/Source/cmCustomCommandGenerator.cxx index 6c9f9d6..5bbae17 100644 --- a/Source/cmCustomCommandGenerator.cxx +++ b/Source/cmCustomCommandGenerator.cxx @@ -64,6 +64,13 @@ cmCustomCommandGenerator::cmCustomCommandGenerator(cmCustomCommand const& cc, } this->Depends.insert(this->Depends.end(), result.begin(), result.end()); } + + const std::string& workingdirectory = this->CC.GetWorkingDirectory(); + if (!workingdirectory.empty()) { + std::unique_ptr cge = + this->GE->Parse(workingdirectory); + this->WorkingDirectory = cge->Evaluate(this->LG, this->Config); + } } cmCustomCommandGenerator::~cmCustomCommandGenerator() @@ -186,7 +193,7 @@ const char* cmCustomCommandGenerator::GetComment() const std::string cmCustomCommandGenerator::GetWorkingDirectory() const { - return this->CC.GetWorkingDirectory(); + return this->WorkingDirectory; } std::vector const& cmCustomCommandGenerator::GetOutputs() const diff --git a/Source/cmCustomCommandGenerator.h b/Source/cmCustomCommandGenerator.h index 34fd653..b7e2a39 100644 --- a/Source/cmCustomCommandGenerator.h +++ b/Source/cmCustomCommandGenerator.h @@ -23,6 +23,7 @@ class cmCustomCommandGenerator cmGeneratorExpression* GE; cmCustomCommandLines CommandLines; std::vector Depends; + std::string WorkingDirectory; const char* GetCrossCompilingEmulator(unsigned int c) const; const char* GetArgv0Location(unsigned int c) const; diff --git a/Tests/CustomCommandWorkingDirectory/CMakeLists.txt b/Tests/CustomCommandWorkingDirectory/CMakeLists.txt index 4975feb..5495a9b 100644 --- a/Tests/CustomCommandWorkingDirectory/CMakeLists.txt +++ b/Tests/CustomCommandWorkingDirectory/CMakeLists.txt @@ -42,3 +42,23 @@ add_custom_target( ) add_dependencies(working2 Custom2) + +file(MAKE_DIRECTORY ${TestWorkingDir_BINARY_DIR}/genex) +add_custom_command( + OUTPUT "${TestWorkingDir_BINARY_DIR}/genex/working.c" + COMMAND "${CMAKE_COMMAND}" -E copy "${TestWorkingDir_SOURCE_DIR}/working.c.in" "${TestWorkingDir_BINARY_DIR}/genex/working.c" + WORKING_DIRECTORY "${TestWorkingDir_BINARY_DIR}/$<1:genex>/" + COMMENT "custom command" +) + +add_executable(workinggenex "${TestWorkingDir_BINARY_DIR}/genex/working.c" + "${TestWorkingDir_BINARY_DIR}/genex/customTarget.c") + +add_custom_target( + CustomGenex ALL + COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${TestWorkingDir_SOURCE_DIR}/customTarget.c" "${TestWorkingDir_BINARY_DIR}/genex/customTarget.c" + BYPRODUCTS "${TestWorkingDir_BINARY_DIR}/genex/customTarget.c" + WORKING_DIRECTORY "${TestWorkingDir_BINARY_DIR}/$<1:genex>/" +) + +add_dependencies(workinggenex CustomGenex) ----------------------------------------------------------------------- Summary of changes: Help/command/add_custom_command.rst | 3 +++ Help/command/add_custom_target.rst | 3 +++ .../dev/custom_command-working_directory-genex.rst | 5 +++++ Source/cmCustomCommandGenerator.cxx | 9 ++++++++- Source/cmCustomCommandGenerator.h | 1 + Tests/CustomCommandWorkingDirectory/CMakeLists.txt | 20 ++++++++++++++++++++ 6 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 Help/release/dev/custom_command-working_directory-genex.rst hooks/post-receive -- CMake From kwrobot at kitware.com Sat Sep 29 00:05:05 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Sat, 29 Sep 2018 00:05:05 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-764-g400bf98 Message-ID: <20180929040505.5001C113D1B@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via 400bf98ee78590712c8894d0498c8011d94f80a2 (commit) from cac09cc52ccba9f3435e4d7cc227d15b6a009855 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=400bf98ee78590712c8894d0498c8011d94f80a2 commit 400bf98ee78590712c8894d0498c8011d94f80a2 Author: Kitware Robot AuthorDate: Sat Sep 29 00:01:10 2018 -0400 Commit: Kitware Robot CommitDate: Sat Sep 29 00:01:10 2018 -0400 CMake Nightly Date Stamp diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index d9aa818..621f6d3 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 12) -set(CMake_VERSION_PATCH 20180928) +set(CMake_VERSION_PATCH 20180929) #set(CMake_VERSION_RC 1) ----------------------------------------------------------------------- Summary of changes: Source/CMakeVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) hooks/post-receive -- CMake From kwrobot at kitware.com Sun Sep 30 00:05:05 2018 From: kwrobot at kitware.com (Kitware Robot) Date: Sun, 30 Sep 2018 00:05:05 -0400 (EDT) Subject: [Cmake-commits] CMake branch, master, updated. v3.12.2-765-ga4e3b3e Message-ID: <20180930040505.368761252F5@public.kitware.com> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake". The branch, master has been updated via a4e3b3ed756f3629cd542d8e2057a5b41cbad750 (commit) from 400bf98ee78590712c8894d0498c8011d94f80a2 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=a4e3b3ed756f3629cd542d8e2057a5b41cbad750 commit a4e3b3ed756f3629cd542d8e2057a5b41cbad750 Author: Kitware Robot AuthorDate: Sun Sep 30 00:01:05 2018 -0400 Commit: Kitware Robot CommitDate: Sun Sep 30 00:01:05 2018 -0400 CMake Nightly Date Stamp diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 621f6d3..b860350 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 12) -set(CMake_VERSION_PATCH 20180929) +set(CMake_VERSION_PATCH 20180930) #set(CMake_VERSION_RC 1) ----------------------------------------------------------------------- Summary of changes: Source/CMakeVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) hooks/post-receive -- CMake