cmCPackIFWGenerator.cxx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  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 "cmCPackIFWGenerator.h"
  4. #include <sstream>
  5. #include <utility>
  6. #include "cmCPackComponentGroup.h"
  7. #include "cmCPackGenerator.h"
  8. #include "cmCPackIFWCommon.h"
  9. #include "cmCPackIFWInstaller.h"
  10. #include "cmCPackIFWPackage.h"
  11. #include "cmCPackIFWRepository.h"
  12. #include "cmCPackLog.h" // IWYU pragma: keep
  13. #include "cmDuration.h"
  14. #include "cmGeneratedFileStream.h"
  15. #include "cmStringAlgorithms.h"
  16. #include "cmSystemTools.h"
  17. #include "cmValue.h"
  18. cmCPackIFWGenerator::cmCPackIFWGenerator()
  19. {
  20. this->Generator = this;
  21. }
  22. cmCPackIFWGenerator::~cmCPackIFWGenerator() = default;
  23. int cmCPackIFWGenerator::PackageFiles()
  24. {
  25. cmCPackIFWLogger(OUTPUT, "- Configuration" << std::endl);
  26. // Installer configuragion
  27. this->Installer.GenerateInstallerFile();
  28. // Packages configuration
  29. this->Installer.GeneratePackageFiles();
  30. std::string ifwTLD = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  31. std::string ifwTmpFile = cmStrCat(ifwTLD, "/IFWOutput.log");
  32. // Create repositories
  33. if (!this->RunRepogen(ifwTmpFile)) {
  34. return 0;
  35. }
  36. // Create installer
  37. if (!this->RunBinaryCreator(ifwTmpFile)) {
  38. return 0;
  39. }
  40. return 1;
  41. }
  42. std::vector<std::string> cmCPackIFWGenerator::BuildRepogenCommand()
  43. {
  44. std::vector<std::string> ifwCmd;
  45. std::string ifwArg;
  46. ifwCmd.emplace_back(this->RepoGen);
  47. if (!this->IsVersionLess("4.2")) {
  48. if (!this->ArchiveFormat.empty()) {
  49. ifwCmd.emplace_back("--archive-format");
  50. ifwCmd.emplace_back(this->ArchiveFormat);
  51. }
  52. if (!this->ArchiveCompression.empty()) {
  53. ifwCmd.emplace_back("--compression");
  54. ifwCmd.emplace_back(this->ArchiveCompression);
  55. }
  56. }
  57. if (this->IsVersionLess("2.0.0")) {
  58. ifwCmd.emplace_back("-c");
  59. ifwCmd.emplace_back(this->toplevel + "/config/config.xml");
  60. }
  61. ifwCmd.emplace_back("-p");
  62. ifwCmd.emplace_back(this->toplevel + "/packages");
  63. if (!this->PkgsDirsVector.empty()) {
  64. for (std::string const& it : this->PkgsDirsVector) {
  65. ifwCmd.emplace_back("-p");
  66. ifwCmd.emplace_back(it);
  67. }
  68. }
  69. if (!this->RepoDirsVector.empty()) {
  70. if (!this->IsVersionLess("3.1")) {
  71. for (std::string const& rd : this->RepoDirsVector) {
  72. ifwCmd.emplace_back("--repository");
  73. ifwCmd.emplace_back(rd);
  74. }
  75. } else {
  76. cmCPackIFWLogger(WARNING,
  77. "The \"CPACK_IFW_REPOSITORIES_DIRECTORIES\" "
  78. << "variable is set, but content will be skipped, "
  79. << "because this feature available only since "
  80. << "QtIFW 3.1. Please update your QtIFW instance."
  81. << std::endl);
  82. }
  83. }
  84. if (!this->OnlineOnly && !this->DownloadedPackages.empty()) {
  85. ifwCmd.emplace_back("-i");
  86. auto it = this->DownloadedPackages.begin();
  87. ifwArg = (*it)->Name;
  88. ++it;
  89. while (it != this->DownloadedPackages.end()) {
  90. ifwArg += "," + (*it)->Name;
  91. ++it;
  92. }
  93. ifwCmd.emplace_back(ifwArg);
  94. }
  95. ifwCmd.emplace_back(this->toplevel + "/repository");
  96. return ifwCmd;
  97. }
  98. int cmCPackIFWGenerator::RunRepogen(const std::string& ifwTmpFile)
  99. {
  100. if (this->Installer.RemoteRepositories.empty()) {
  101. return 1;
  102. }
  103. std::vector<std::string> ifwCmd = this->BuildRepogenCommand();
  104. cmCPackIFWLogger(VERBOSE,
  105. "Execute: " << cmSystemTools::PrintSingleCommand(ifwCmd)
  106. << std::endl);
  107. std::string output;
  108. int retVal = 1;
  109. cmCPackIFWLogger(OUTPUT, "- Generate repository" << std::endl);
  110. bool res = cmSystemTools::RunSingleCommand(ifwCmd, &output, &output, &retVal,
  111. nullptr, this->GeneratorVerbose,
  112. cmDuration::zero());
  113. if (!res || retVal) {
  114. cmGeneratedFileStream ofs(ifwTmpFile);
  115. ofs << "# Run command: " << cmSystemTools::PrintSingleCommand(ifwCmd)
  116. << std::endl
  117. << "# Output:" << std::endl
  118. << output << std::endl;
  119. cmCPackIFWLogger(
  120. ERROR,
  121. "Problem running IFW command: "
  122. << cmSystemTools::PrintSingleCommand(ifwCmd) << std::endl
  123. << "Please check \"" << ifwTmpFile << "\" for errors" << std::endl);
  124. return 0;
  125. }
  126. if (!this->Repository.RepositoryUpdate.empty() &&
  127. !this->Repository.PatchUpdatesXml()) {
  128. cmCPackIFWLogger(WARNING,
  129. "Problem patch IFW \"Updates\" "
  130. << "file: \"" << this->toplevel
  131. << "/repository/Updates.xml\"" << std::endl);
  132. }
  133. cmCPackIFWLogger(OUTPUT,
  134. "- repository: \"" << this->toplevel
  135. << "/repository\" generated"
  136. << std::endl);
  137. return 1;
  138. }
  139. std::vector<std::string> cmCPackIFWGenerator::BuildBinaryCreatorCommmand()
  140. {
  141. std::vector<std::string> ifwCmd;
  142. std::string ifwArg;
  143. ifwCmd.emplace_back(this->BinCreator);
  144. if (!this->IsVersionLess("4.2")) {
  145. if (!this->ArchiveFormat.empty()) {
  146. ifwCmd.emplace_back("--archive-format");
  147. ifwCmd.emplace_back(this->ArchiveFormat);
  148. }
  149. if (!this->ArchiveCompression.empty()) {
  150. ifwCmd.emplace_back("--compression");
  151. ifwCmd.emplace_back(this->ArchiveCompression);
  152. }
  153. }
  154. if (!this->IsVersionLess("3.0")) {
  155. #ifdef __APPLE__
  156. // macOS only
  157. std::string signingIdentity = this->Installer.SigningIdentity;
  158. if (!signingIdentity.empty()) {
  159. ifwCmd.emplace_back("--sign");
  160. ifwCmd.emplace_back(signingIdentity);
  161. }
  162. #endif
  163. }
  164. ifwCmd.emplace_back("-c");
  165. ifwCmd.emplace_back(this->toplevel + "/config/config.xml");
  166. if (!this->Installer.Resources.empty()) {
  167. ifwCmd.emplace_back("-r");
  168. auto it = this->Installer.Resources.begin();
  169. std::string path = this->toplevel + "/resources/";
  170. ifwArg = path + *it;
  171. ++it;
  172. while (it != this->Installer.Resources.end()) {
  173. ifwArg += "," + path + *it;
  174. ++it;
  175. }
  176. ifwCmd.emplace_back(ifwArg);
  177. }
  178. ifwCmd.emplace_back("-p");
  179. ifwCmd.emplace_back(this->toplevel + "/packages");
  180. if (!this->PkgsDirsVector.empty()) {
  181. for (std::string const& it : this->PkgsDirsVector) {
  182. ifwCmd.emplace_back("-p");
  183. ifwCmd.emplace_back(it);
  184. }
  185. }
  186. if (!this->RepoDirsVector.empty()) {
  187. if (!this->IsVersionLess("3.1")) {
  188. for (std::string const& rd : this->RepoDirsVector) {
  189. ifwCmd.emplace_back("--repository");
  190. ifwCmd.emplace_back(rd);
  191. }
  192. } else {
  193. cmCPackIFWLogger(WARNING,
  194. "The \"CPACK_IFW_REPOSITORIES_DIRECTORIES\" "
  195. << "variable is set, but content will be skipped, "
  196. << "because this feature available only since "
  197. << "QtIFW 3.1. Please update your QtIFW instance."
  198. << std::endl);
  199. }
  200. }
  201. if (this->OnlineOnly) {
  202. ifwCmd.emplace_back("--online-only");
  203. } else if (!this->DownloadedPackages.empty() &&
  204. !this->Installer.RemoteRepositories.empty()) {
  205. ifwCmd.emplace_back("-e");
  206. auto it = this->DownloadedPackages.begin();
  207. ifwArg = (*it)->Name;
  208. ++it;
  209. while (it != this->DownloadedPackages.end()) {
  210. ifwArg += "," + (*it)->Name;
  211. ++it;
  212. }
  213. ifwCmd.emplace_back(ifwArg);
  214. } else if (!this->DependentPackages.empty()) {
  215. ifwCmd.emplace_back("-i");
  216. ifwArg.clear();
  217. // Binary
  218. auto bit = this->BinaryPackages.begin();
  219. while (bit != this->BinaryPackages.end()) {
  220. ifwArg += (*bit)->Name + ",";
  221. ++bit;
  222. }
  223. // Depend
  224. auto it = this->DependentPackages.begin();
  225. ifwArg += it->second.Name;
  226. ++it;
  227. while (it != this->DependentPackages.end()) {
  228. ifwArg += "," + it->second.Name;
  229. ++it;
  230. }
  231. ifwCmd.emplace_back(ifwArg);
  232. }
  233. // TODO: set correct name for multipackages
  234. if (!this->packageFileNames.empty()) {
  235. ifwCmd.emplace_back(this->packageFileNames[0]);
  236. } else {
  237. ifwCmd.emplace_back("installer" + this->OutputExtension);
  238. }
  239. return ifwCmd;
  240. }
  241. int cmCPackIFWGenerator::RunBinaryCreator(const std::string& ifwTmpFile)
  242. {
  243. std::vector<std::string> ifwCmd = this->BuildBinaryCreatorCommmand();
  244. cmCPackIFWLogger(VERBOSE,
  245. "Execute: " << cmSystemTools::PrintSingleCommand(ifwCmd)
  246. << std::endl);
  247. std::string output;
  248. int retVal = 1;
  249. cmCPackIFWLogger(OUTPUT, "- Generate package" << std::endl);
  250. bool res = cmSystemTools::RunSingleCommand(ifwCmd, &output, &output, &retVal,
  251. nullptr, this->GeneratorVerbose,
  252. cmDuration::zero());
  253. if (!res || retVal) {
  254. cmGeneratedFileStream ofs(ifwTmpFile);
  255. ofs << "# Run command: " << cmSystemTools::PrintSingleCommand(ifwCmd)
  256. << std::endl
  257. << "# Output:" << std::endl
  258. << output << std::endl;
  259. cmCPackIFWLogger(
  260. ERROR,
  261. "Problem running IFW command: "
  262. << cmSystemTools::PrintSingleCommand(ifwCmd) << std::endl
  263. << "Please check \"" << ifwTmpFile << "\" for errors" << std::endl);
  264. return 0;
  265. }
  266. return 1;
  267. }
  268. const char* cmCPackIFWGenerator::GetPackagingInstallPrefix()
  269. {
  270. const char* defPrefix = this->cmCPackGenerator::GetPackagingInstallPrefix();
  271. std::string tmpPref = defPrefix ? defPrefix : "";
  272. if (this->Components.empty()) {
  273. tmpPref += "packages/" + this->GetRootPackageName() + "/data";
  274. }
  275. this->SetOption("CPACK_IFW_PACKAGING_INSTALL_PREFIX", tmpPref);
  276. return this->GetOption("CPACK_IFW_PACKAGING_INSTALL_PREFIX")->c_str();
  277. }
  278. const char* cmCPackIFWGenerator::GetOutputExtension()
  279. {
  280. return this->OutputExtension.c_str();
  281. }
  282. int cmCPackIFWGenerator::InitializeInternal()
  283. {
  284. // Search Qt Installer Framework tools
  285. const std::string BinCreatorOpt = "CPACK_IFW_BINARYCREATOR_EXECUTABLE";
  286. const std::string RepoGenOpt = "CPACK_IFW_REPOGEN_EXECUTABLE";
  287. const std::string FrameworkVersionOpt = "CPACK_IFW_FRAMEWORK_VERSION";
  288. if (!this->IsSet(BinCreatorOpt) || !this->IsSet(RepoGenOpt) ||
  289. !this->IsSet(FrameworkVersionOpt)) {
  290. this->ReadListFile("CPackIFW.cmake");
  291. }
  292. // Look 'binarycreator' executable (needs)
  293. cmValue BinCreatorStr = this->GetOption(BinCreatorOpt);
  294. if (!BinCreatorStr || cmIsNOTFOUND(BinCreatorStr)) {
  295. this->BinCreator.clear();
  296. } else {
  297. this->BinCreator = *BinCreatorStr;
  298. }
  299. if (this->BinCreator.empty()) {
  300. cmCPackIFWLogger(ERROR,
  301. "Cannot find QtIFW compiler \"binarycreator\": "
  302. "likely it is not installed, or not in your PATH"
  303. << std::endl);
  304. return 0;
  305. }
  306. // Look 'repogen' executable (optional)
  307. cmValue repoGen = this->GetOption(RepoGenOpt);
  308. if (!repoGen || cmIsNOTFOUND(repoGen)) {
  309. this->RepoGen.clear();
  310. } else {
  311. this->RepoGen = *repoGen;
  312. }
  313. // Framework version
  314. if (cmValue frameworkVersion = this->GetOption(FrameworkVersionOpt)) {
  315. this->FrameworkVersion = *frameworkVersion;
  316. } else {
  317. this->FrameworkVersion = "1.9.9";
  318. }
  319. // Variables that Change Behavior
  320. // Resolve duplicate names
  321. this->ResolveDuplicateNames =
  322. this->IsOn("CPACK_IFW_RESOLVE_DUPLICATE_NAMES");
  323. // Additional packages dirs
  324. this->PkgsDirsVector.clear();
  325. if (cmValue dirs = this->GetOption("CPACK_IFW_PACKAGES_DIRECTORIES")) {
  326. cmExpandList(dirs, this->PkgsDirsVector);
  327. }
  328. // Additional repositories dirs
  329. this->RepoDirsVector.clear();
  330. if (cmValue dirs = this->GetOption("CPACK_IFW_REPOSITORIES_DIRECTORIES")) {
  331. cmExpandList(dirs, this->RepoDirsVector);
  332. }
  333. // Archive format and compression level
  334. if (cmValue af = this->GetOption("CPACK_IFW_ARCHIVE_FORMAT")) {
  335. this->ArchiveFormat = *af;
  336. }
  337. if (cmValue ac = this->GetOption("CPACK_IFW_ARCHIVE_COMPRESSION")) {
  338. this->ArchiveCompression = *ac;
  339. }
  340. // Installer
  341. this->Installer.Generator = this;
  342. this->Installer.ConfigureFromOptions();
  343. // Repository
  344. this->Repository.Generator = this;
  345. this->Repository.Name = "Unspecified";
  346. if (cmValue site = this->GetOption("CPACK_DOWNLOAD_SITE")) {
  347. this->Repository.Url = *site;
  348. this->Installer.RemoteRepositories.push_back(&this->Repository);
  349. }
  350. // Repositories
  351. if (cmValue RepoAllStr = this->GetOption("CPACK_IFW_REPOSITORIES_ALL")) {
  352. std::vector<std::string> RepoAllVector = cmExpandedList(RepoAllStr);
  353. for (std::string const& r : RepoAllVector) {
  354. this->GetRepository(r);
  355. }
  356. }
  357. if (cmValue ifwDownloadAll = this->GetOption("CPACK_IFW_DOWNLOAD_ALL")) {
  358. this->OnlineOnly = cmIsOn(ifwDownloadAll);
  359. } else if (cmValue cpackDownloadAll =
  360. this->GetOption("CPACK_DOWNLOAD_ALL")) {
  361. this->OnlineOnly = cmIsOn(cpackDownloadAll);
  362. } else {
  363. this->OnlineOnly = false;
  364. }
  365. if (!this->Installer.RemoteRepositories.empty() && this->RepoGen.empty()) {
  366. cmCPackIFWLogger(ERROR,
  367. "Cannot find QtIFW repository generator \"repogen\": "
  368. "likely it is not installed, or not in your PATH"
  369. << std::endl);
  370. return 0;
  371. }
  372. // Executable suffix
  373. std::string exeSuffix(this->GetOption("CMAKE_EXECUTABLE_SUFFIX"));
  374. std::string sysName(this->GetOption("CMAKE_SYSTEM_NAME"));
  375. if (sysName == "Linux") {
  376. this->ExecutableSuffix = ".run";
  377. } else if (sysName == "Windows") {
  378. this->ExecutableSuffix = ".exe";
  379. } else if (sysName == "Darwin") {
  380. this->ExecutableSuffix = ".app";
  381. } else {
  382. this->ExecutableSuffix = exeSuffix;
  383. }
  384. // Output extension
  385. if (cmValue optOutExt =
  386. this->GetOption("CPACK_IFW_PACKAGE_FILE_EXTENSION")) {
  387. this->OutputExtension = *optOutExt;
  388. } else if (sysName == "Darwin") {
  389. this->OutputExtension = ".dmg";
  390. } else {
  391. this->OutputExtension = this->ExecutableSuffix;
  392. }
  393. if (this->OutputExtension.empty()) {
  394. this->OutputExtension = this->cmCPackGenerator::GetOutputExtension();
  395. }
  396. return this->Superclass::InitializeInternal();
  397. }
  398. std::string cmCPackIFWGenerator::GetComponentInstallDirNameSuffix(
  399. const std::string& componentName)
  400. {
  401. const std::string prefix = "packages/";
  402. const std::string suffix = "/data";
  403. if (this->componentPackageMethod == this->ONE_PACKAGE) {
  404. return std::string(prefix + this->GetRootPackageName() + suffix);
  405. }
  406. return prefix +
  407. this->GetComponentPackageName(&this->Components[componentName]) + suffix;
  408. }
  409. cmCPackComponent* cmCPackIFWGenerator::GetComponent(
  410. const std::string& projectName, const std::string& componentName)
  411. {
  412. auto cit = this->Components.find(componentName);
  413. if (cit != this->Components.end()) {
  414. return &(cit->second);
  415. }
  416. cmCPackComponent* component =
  417. this->cmCPackGenerator::GetComponent(projectName, componentName);
  418. if (!component) {
  419. return component;
  420. }
  421. std::string name = this->GetComponentPackageName(component);
  422. auto pit = this->Packages.find(name);
  423. if (pit != this->Packages.end()) {
  424. return component;
  425. }
  426. cmCPackIFWPackage* package = &this->Packages[name];
  427. package->Name = name;
  428. package->Generator = this;
  429. if (package->ConfigureFromComponent(component)) {
  430. package->Installer = &this->Installer;
  431. this->Installer.Packages.insert(
  432. std::pair<std::string, cmCPackIFWPackage*>(name, package));
  433. this->ComponentPackages.insert(
  434. std::pair<cmCPackComponent*, cmCPackIFWPackage*>(component, package));
  435. if (component->IsDownloaded) {
  436. this->DownloadedPackages.insert(package);
  437. } else {
  438. this->BinaryPackages.insert(package);
  439. }
  440. } else {
  441. this->Packages.erase(name);
  442. cmCPackIFWLogger(ERROR,
  443. "Cannot configure package \""
  444. << name << "\" for component \"" << component->Name
  445. << "\"" << std::endl);
  446. }
  447. return component;
  448. }
  449. cmCPackComponentGroup* cmCPackIFWGenerator::GetComponentGroup(
  450. const std::string& projectName, const std::string& groupName)
  451. {
  452. cmCPackComponentGroup* group =
  453. this->cmCPackGenerator::GetComponentGroup(projectName, groupName);
  454. if (!group) {
  455. return group;
  456. }
  457. std::string name = this->GetGroupPackageName(group);
  458. auto pit = this->Packages.find(name);
  459. if (pit != this->Packages.end()) {
  460. return group;
  461. }
  462. cmCPackIFWPackage* package = &this->Packages[name];
  463. package->Name = name;
  464. package->Generator = this;
  465. if (package->ConfigureFromGroup(group)) {
  466. package->Installer = &this->Installer;
  467. this->Installer.Packages.insert(
  468. std::pair<std::string, cmCPackIFWPackage*>(name, package));
  469. this->GroupPackages.insert(
  470. std::pair<cmCPackComponentGroup*, cmCPackIFWPackage*>(group, package));
  471. this->BinaryPackages.insert(package);
  472. } else {
  473. this->Packages.erase(name);
  474. cmCPackIFWLogger(ERROR,
  475. "Cannot configure package \""
  476. << name << "\" for component group \"" << group->Name
  477. << "\"" << std::endl);
  478. }
  479. return group;
  480. }
  481. enum cmCPackGenerator::CPackSetDestdirSupport
  482. cmCPackIFWGenerator::SupportsSetDestdir() const
  483. {
  484. return cmCPackGenerator::SETDESTDIR_SHOULD_NOT_BE_USED;
  485. }
  486. bool cmCPackIFWGenerator::SupportsAbsoluteDestination() const
  487. {
  488. return false;
  489. }
  490. bool cmCPackIFWGenerator::SupportsComponentInstallation() const
  491. {
  492. return true;
  493. }
  494. bool cmCPackIFWGenerator::IsOnePackage() const
  495. {
  496. return this->componentPackageMethod == cmCPackGenerator::ONE_PACKAGE;
  497. }
  498. std::string cmCPackIFWGenerator::GetRootPackageName()
  499. {
  500. // Default value
  501. std::string name = "root";
  502. if (cmValue optIFW_PACKAGE_GROUP =
  503. this->GetOption("CPACK_IFW_PACKAGE_GROUP")) {
  504. // Configure from root group
  505. cmCPackIFWPackage package;
  506. package.Generator = this;
  507. package.ConfigureFromGroup(optIFW_PACKAGE_GROUP);
  508. name = package.Name;
  509. } else if (cmValue optIFW_PACKAGE_NAME =
  510. this->GetOption("CPACK_IFW_PACKAGE_NAME")) {
  511. // Configure from root package name
  512. name = *optIFW_PACKAGE_NAME;
  513. } else if (cmValue optPACKAGE_NAME = this->GetOption("CPACK_PACKAGE_NAME")) {
  514. // Configure from package name
  515. name = *optPACKAGE_NAME;
  516. }
  517. return name;
  518. }
  519. std::string cmCPackIFWGenerator::GetGroupPackageName(
  520. cmCPackComponentGroup* group) const
  521. {
  522. std::string name;
  523. if (!group) {
  524. return name;
  525. }
  526. if (cmCPackIFWPackage* package = this->GetGroupPackage(group)) {
  527. return package->Name;
  528. }
  529. cmValue option =
  530. this->GetOption("CPACK_IFW_COMPONENT_GROUP_" +
  531. cmsys::SystemTools::UpperCase(group->Name) + "_NAME");
  532. name = option ? *option : group->Name;
  533. if (group->ParentGroup) {
  534. cmCPackIFWPackage* package = this->GetGroupPackage(group->ParentGroup);
  535. bool dot = !this->ResolveDuplicateNames;
  536. if (dot && !cmHasPrefix(name, package->Name)) {
  537. name = package->Name + "." + name;
  538. }
  539. }
  540. return name;
  541. }
  542. std::string cmCPackIFWGenerator::GetComponentPackageName(
  543. cmCPackComponent* component) const
  544. {
  545. std::string name;
  546. if (!component) {
  547. return name;
  548. }
  549. if (cmCPackIFWPackage* package = this->GetComponentPackage(component)) {
  550. return package->Name;
  551. }
  552. std::string prefix = "CPACK_IFW_COMPONENT_" +
  553. cmsys::SystemTools::UpperCase(component->Name) + "_";
  554. cmValue option = this->GetOption(prefix + "NAME");
  555. name = option ? *option : component->Name;
  556. if (component->Group) {
  557. cmCPackIFWPackage* package = this->GetGroupPackage(component->Group);
  558. if ((this->componentPackageMethod ==
  559. cmCPackGenerator::ONE_PACKAGE_PER_GROUP) ||
  560. this->IsOn(prefix + "COMMON")) {
  561. return package->Name;
  562. }
  563. bool dot = !this->ResolveDuplicateNames;
  564. if (dot && !cmHasPrefix(name, package->Name)) {
  565. name = package->Name + "." + name;
  566. }
  567. }
  568. return name;
  569. }
  570. cmCPackIFWPackage* cmCPackIFWGenerator::GetGroupPackage(
  571. cmCPackComponentGroup* group) const
  572. {
  573. auto pit = this->GroupPackages.find(group);
  574. return pit != this->GroupPackages.end() ? pit->second : nullptr;
  575. }
  576. cmCPackIFWPackage* cmCPackIFWGenerator::GetComponentPackage(
  577. cmCPackComponent* component) const
  578. {
  579. auto pit = this->ComponentPackages.find(component);
  580. return pit != this->ComponentPackages.end() ? pit->second : nullptr;
  581. }
  582. cmCPackIFWRepository* cmCPackIFWGenerator::GetRepository(
  583. const std::string& repositoryName)
  584. {
  585. auto rit = this->Repositories.find(repositoryName);
  586. if (rit != this->Repositories.end()) {
  587. return &(rit->second);
  588. }
  589. cmCPackIFWRepository* repository = &this->Repositories[repositoryName];
  590. repository->Name = repositoryName;
  591. repository->Generator = this;
  592. if (repository->ConfigureFromOptions()) {
  593. if (repository->Update == cmCPackIFWRepository::None) {
  594. this->Installer.RemoteRepositories.push_back(repository);
  595. } else {
  596. this->Repository.RepositoryUpdate.push_back(repository);
  597. }
  598. } else {
  599. this->Repositories.erase(repositoryName);
  600. repository = nullptr;
  601. cmCPackIFWLogger(WARNING,
  602. "Invalid repository \""
  603. << repositoryName << "\""
  604. << " configuration. Repository will be skipped."
  605. << std::endl);
  606. }
  607. return repository;
  608. }