cmCPackIFWGenerator.cxx 21 KB

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