cmInstallCommandArguments.cxx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmInstallCommandArguments.h"
  4. #include <algorithm>
  5. #include <utility>
  6. #include <cmext/string_view>
  7. #include "cmRange.h"
  8. #include "cmSystemTools.h"
  9. // Table of valid permissions.
  10. const char* cmInstallCommandArguments::PermissionsTable[] = {
  11. "OWNER_READ", "OWNER_WRITE", "OWNER_EXECUTE", "GROUP_READ",
  12. "GROUP_WRITE", "GROUP_EXECUTE", "WORLD_READ", "WORLD_WRITE",
  13. "WORLD_EXECUTE", "SETUID", "SETGID", nullptr
  14. };
  15. const std::string cmInstallCommandArguments::EmptyString;
  16. cmInstallCommandArguments::cmInstallCommandArguments(
  17. std::string defaultComponent)
  18. : DefaultComponentName(std::move(defaultComponent))
  19. {
  20. this->Bind("DESTINATION"_s, this->Destination);
  21. this->Bind("COMPONENT"_s, this->Component);
  22. this->Bind("NAMELINK_COMPONENT"_s, this->NamelinkComponent);
  23. this->Bind("EXCLUDE_FROM_ALL"_s, this->ExcludeFromAll);
  24. this->Bind("RENAME"_s, this->Rename);
  25. this->Bind("PERMISSIONS"_s, this->Permissions);
  26. this->Bind("CONFIGURATIONS"_s, this->Configurations);
  27. this->Bind("OPTIONAL"_s, this->Optional);
  28. this->Bind("NAMELINK_ONLY"_s, this->NamelinkOnly);
  29. this->Bind("NAMELINK_SKIP"_s, this->NamelinkSkip);
  30. this->Bind("TYPE"_s, this->Type);
  31. }
  32. const std::string& cmInstallCommandArguments::GetDestination() const
  33. {
  34. if (!this->DestinationString.empty()) {
  35. return this->DestinationString;
  36. }
  37. if (this->GenericArguments) {
  38. return this->GenericArguments->GetDestination();
  39. }
  40. return EmptyString;
  41. }
  42. const std::string& cmInstallCommandArguments::GetComponent() const
  43. {
  44. if (!this->Component.empty()) {
  45. return this->Component;
  46. }
  47. if (this->GenericArguments) {
  48. return this->GenericArguments->GetComponent();
  49. }
  50. if (!this->DefaultComponentName.empty()) {
  51. return this->DefaultComponentName;
  52. }
  53. static std::string unspecifiedComponent = "Unspecified";
  54. return unspecifiedComponent;
  55. }
  56. const std::string& cmInstallCommandArguments::GetNamelinkComponent() const
  57. {
  58. if (!this->NamelinkComponent.empty()) {
  59. return this->NamelinkComponent;
  60. }
  61. return this->GetComponent();
  62. }
  63. const std::string& cmInstallCommandArguments::GetRename() const
  64. {
  65. if (!this->Rename.empty()) {
  66. return this->Rename;
  67. }
  68. if (this->GenericArguments) {
  69. return this->GenericArguments->GetRename();
  70. }
  71. return EmptyString;
  72. }
  73. const std::string& cmInstallCommandArguments::GetPermissions() const
  74. {
  75. if (!this->PermissionsString.empty()) {
  76. return this->PermissionsString;
  77. }
  78. if (this->GenericArguments) {
  79. return this->GenericArguments->GetPermissions();
  80. }
  81. return EmptyString;
  82. }
  83. bool cmInstallCommandArguments::GetOptional() const
  84. {
  85. if (this->Optional) {
  86. return true;
  87. }
  88. if (this->GenericArguments) {
  89. return this->GenericArguments->GetOptional();
  90. }
  91. return false;
  92. }
  93. bool cmInstallCommandArguments::GetExcludeFromAll() const
  94. {
  95. if (this->ExcludeFromAll) {
  96. return true;
  97. }
  98. if (this->GenericArguments) {
  99. return this->GenericArguments->GetExcludeFromAll();
  100. }
  101. return false;
  102. }
  103. bool cmInstallCommandArguments::GetNamelinkOnly() const
  104. {
  105. if (this->NamelinkOnly) {
  106. return true;
  107. }
  108. if (this->GenericArguments) {
  109. return this->GenericArguments->GetNamelinkOnly();
  110. }
  111. return false;
  112. }
  113. bool cmInstallCommandArguments::GetNamelinkSkip() const
  114. {
  115. if (this->NamelinkSkip) {
  116. return true;
  117. }
  118. if (this->GenericArguments) {
  119. return this->GenericArguments->GetNamelinkSkip();
  120. }
  121. return false;
  122. }
  123. bool cmInstallCommandArguments::HasNamelinkComponent() const
  124. {
  125. if (!this->NamelinkComponent.empty()) {
  126. return true;
  127. }
  128. if (this->GenericArguments) {
  129. return this->GenericArguments->HasNamelinkComponent();
  130. }
  131. return false;
  132. }
  133. const std::string& cmInstallCommandArguments::GetType() const
  134. {
  135. return this->Type;
  136. }
  137. const std::string& cmInstallCommandArguments::GetDefaultComponent() const
  138. {
  139. return this->DefaultComponentName;
  140. }
  141. const std::vector<std::string>& cmInstallCommandArguments::GetConfigurations()
  142. const
  143. {
  144. if (!this->Configurations.empty()) {
  145. return this->Configurations;
  146. }
  147. if (this->GenericArguments) {
  148. return this->GenericArguments->GetConfigurations();
  149. }
  150. return this->Configurations;
  151. }
  152. bool cmInstallCommandArguments::Finalize()
  153. {
  154. if (!this->CheckPermissions()) {
  155. return false;
  156. }
  157. this->DestinationString = this->Destination;
  158. cmSystemTools::ConvertToUnixSlashes(this->DestinationString);
  159. return true;
  160. }
  161. bool cmInstallCommandArguments::CheckPermissions()
  162. {
  163. this->PermissionsString.clear();
  164. return std::all_of(this->Permissions.begin(), this->Permissions.end(),
  165. [this](std::string const& perm) -> bool {
  166. return cmInstallCommandArguments::CheckPermissions(
  167. perm, this->PermissionsString);
  168. });
  169. }
  170. bool cmInstallCommandArguments::CheckPermissions(
  171. const std::string& onePermission, std::string& permissions)
  172. {
  173. // Check the permission against the table.
  174. for (const char** valid = cmInstallCommandArguments::PermissionsTable;
  175. *valid; ++valid) {
  176. if (onePermission == *valid) {
  177. // This is a valid permission.
  178. permissions += " ";
  179. permissions += onePermission;
  180. return true;
  181. }
  182. }
  183. // This is not a valid permission.
  184. return false;
  185. }
  186. cmInstallCommandIncludesArgument::cmInstallCommandIncludesArgument() = default;
  187. const std::vector<std::string>&
  188. cmInstallCommandIncludesArgument::GetIncludeDirs() const
  189. {
  190. return this->IncludeDirs;
  191. }
  192. void cmInstallCommandIncludesArgument::Parse(
  193. const std::vector<std::string>* args, std::vector<std::string>*)
  194. {
  195. if (args->empty()) {
  196. return;
  197. }
  198. for (std::string dir : cmMakeRange(*args).advance(1)) {
  199. cmSystemTools::ConvertToUnixSlashes(dir);
  200. this->IncludeDirs.push_back(std::move(dir));
  201. }
  202. }
  203. cmInstallCommandFileSetArguments::cmInstallCommandFileSetArguments(
  204. std::string defaultComponent)
  205. : cmInstallCommandArguments(std::move(defaultComponent))
  206. {
  207. this->Bind("FILE_SET"_s, this->FileSet);
  208. }
  209. void cmInstallCommandFileSetArguments::Parse(
  210. std::vector<std::string> args, std::vector<std::string>* unconsumedArgs)
  211. {
  212. args.insert(args.begin(), "FILE_SET");
  213. this->cmInstallCommandArguments::Parse(args, unconsumedArgs);
  214. }