The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

861 lines
35KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #include "jucer_Headers.h"
  20. #include "../Project/jucer_Module.h"
  21. #include "../Utility/Helpers/jucer_TranslationHelpers.h"
  22. #include "../Utility/PIPs/jucer_PIPGenerator.h"
  23. #include "jucer_CommandLine.h"
  24. //==============================================================================
  25. const char* preferredLinefeed = "\r\n";
  26. const char* getPreferredLinefeed() { return preferredLinefeed; }
  27. //==============================================================================
  28. namespace
  29. {
  30. static void hideDockIcon()
  31. {
  32. #if JUCE_MAC
  33. Process::setDockIconVisible (false);
  34. #endif
  35. }
  36. static Array<File> findAllSourceFiles (const File& folder)
  37. {
  38. Array<File> files;
  39. for (DirectoryIterator di (folder, true, "*.cpp;*.cxx;*.cc;*.c;*.h;*.hpp;*.hxx;*.hpp;*.mm;*.m;*.java;*.dox;", File::findFiles); di.next();)
  40. if (! di.getFile().isSymbolicLink())
  41. files.add (di.getFile());
  42. return files;
  43. }
  44. static void replaceFile (const File& file, const String& newText, const String& message)
  45. {
  46. std::cout << message << file.getFullPathName() << std::endl;
  47. TemporaryFile temp (file);
  48. if (! temp.getFile().replaceWithText (newText, false, false, nullptr))
  49. ConsoleApplication::fail ("!!! ERROR Couldn't write to temp file!");
  50. if (! temp.overwriteTargetFileWithTemporary())
  51. ConsoleApplication::fail ("!!! ERROR Couldn't write to file!");
  52. }
  53. //==============================================================================
  54. struct LoadedProject
  55. {
  56. LoadedProject (const ArgumentList::Argument& fileToLoad)
  57. {
  58. hideDockIcon();
  59. auto projectFile = fileToLoad.resolveAsExistingFile();
  60. if (! projectFile.hasFileExtension (Project::projectFileExtension))
  61. ConsoleApplication::fail (projectFile.getFullPathName() + " isn't a valid jucer project file!");
  62. project.reset (new Project (projectFile));
  63. if (! project->loadFrom (projectFile, true))
  64. {
  65. project.reset();
  66. ConsoleApplication::fail ("Failed to load the project file: " + projectFile.getFullPathName());
  67. }
  68. }
  69. void save (bool justSaveResources)
  70. {
  71. if (project != nullptr)
  72. {
  73. auto error = justSaveResources ? project->saveResourcesOnly (project->getFile())
  74. : project->saveProject (project->getFile(), true);
  75. project.reset();
  76. if (error.failed())
  77. ConsoleApplication::fail ("Error when saving: " + error.getErrorMessage());
  78. }
  79. }
  80. std::unique_ptr<Project> project;
  81. };
  82. //==============================================================================
  83. /* Running a command-line of the form "projucer --resave foobar.jucer" will try to load
  84. that project and re-export all of its targets.
  85. */
  86. static void resaveProject (const ArgumentList& args, bool justSaveResources)
  87. {
  88. args.checkMinNumArguments (2);
  89. LoadedProject proj (args[1]);
  90. std::cout << (justSaveResources ? "Re-saving project resources: "
  91. : "Re-saving file: ")
  92. << proj.project->getFile().getFullPathName() << std::endl;
  93. proj.save (justSaveResources);
  94. }
  95. //==============================================================================
  96. static void getVersion (const ArgumentList& args)
  97. {
  98. args.checkMinNumArguments (2);
  99. LoadedProject proj (args[1]);
  100. std::cout << proj.project->getVersionString() << std::endl;
  101. }
  102. //==============================================================================
  103. static void setVersion (const ArgumentList& args)
  104. {
  105. args.checkMinNumArguments (2);
  106. LoadedProject proj (args[2]);
  107. String version (args[1].text.trim());
  108. std::cout << "Setting project version: " << version << std::endl;
  109. proj.project->setProjectVersion (version);
  110. proj.save (false);
  111. }
  112. //==============================================================================
  113. static void bumpVersion (const ArgumentList& args)
  114. {
  115. args.checkMinNumArguments (2);
  116. LoadedProject proj (args[1]);
  117. String version = proj.project->getVersionString();
  118. version = version.upToLastOccurrenceOf (".", true, false)
  119. + String (version.getTrailingIntValue() + 1);
  120. std::cout << "Bumping project version to: " << version << std::endl;
  121. proj.project->setProjectVersion (version);
  122. proj.save (false);
  123. }
  124. static void gitTag (const ArgumentList& args)
  125. {
  126. args.checkMinNumArguments (2);
  127. LoadedProject proj (args[1]);
  128. String version (proj.project->getVersionString());
  129. if (version.trim().isEmpty())
  130. ConsoleApplication::fail ("Cannot read version number from project!");
  131. StringArray command;
  132. command.add ("git");
  133. command.add ("tag");
  134. command.add ("-a");
  135. command.add (version);
  136. command.add ("-m");
  137. command.add (version.quoted());
  138. std::cout << "Performing command: " << command.joinIntoString(" ") << std::endl;
  139. ChildProcess c;
  140. if (! c.start (command, 0))
  141. ConsoleApplication::fail ("Cannot run git!");
  142. c.waitForProcessToFinish (10000);
  143. if (c.getExitCode() != 0)
  144. ConsoleApplication::fail ("git command failed!");
  145. }
  146. //==============================================================================
  147. static void showStatus (const ArgumentList& args)
  148. {
  149. hideDockIcon();
  150. args.checkMinNumArguments (2);
  151. LoadedProject proj (args[1]);
  152. std::cout << "Project file: " << proj.project->getFile().getFullPathName() << std::endl
  153. << "Name: " << proj.project->getProjectNameString() << std::endl
  154. << "UID: " << proj.project->getProjectUIDString() << std::endl;
  155. EnabledModuleList& modules = proj.project->getEnabledModules();
  156. if (int numModules = modules.getNumModules())
  157. {
  158. std::cout << "Modules:" << std::endl;
  159. for (int i = 0; i < numModules; ++i)
  160. std::cout << " " << modules.getModuleID (i) << std::endl;
  161. }
  162. }
  163. //==============================================================================
  164. static String getModulePackageName (const LibraryModule& module)
  165. {
  166. return module.getID() + ".jucemodule";
  167. }
  168. static void zipModule (const File& targetFolder, const File& moduleFolder)
  169. {
  170. jassert (targetFolder.isDirectory());
  171. auto moduleFolderParent = moduleFolder.getParentDirectory();
  172. LibraryModule module (moduleFolder);
  173. if (! module.isValid())
  174. ConsoleApplication::fail (moduleFolder.getFullPathName() + " is not a valid module folder!");
  175. auto targetFile = targetFolder.getChildFile (getModulePackageName (module));
  176. ZipFile::Builder zip;
  177. {
  178. DirectoryIterator i (moduleFolder, true, "*", File::findFiles);
  179. while (i.next())
  180. if (! i.getFile().isHidden())
  181. zip.addFile (i.getFile(), 9, i.getFile().getRelativePathFrom (moduleFolderParent));
  182. }
  183. std::cout << "Writing: " << targetFile.getFullPathName() << std::endl;
  184. TemporaryFile temp (targetFile);
  185. std::unique_ptr<FileOutputStream> out (temp.getFile().createOutputStream());
  186. bool ok = out != nullptr && zip.writeToStream (*out, nullptr);
  187. out.reset();
  188. ok = ok && temp.overwriteTargetFileWithTemporary();
  189. if (! ok)
  190. ConsoleApplication::fail ("Failed to write to the target file: " + targetFile.getFullPathName());
  191. }
  192. static void buildModules (const ArgumentList& args, const bool buildAllWithIndex)
  193. {
  194. hideDockIcon();
  195. args.checkMinNumArguments (3);
  196. auto targetFolder = args[1].resolveAsFile();
  197. if (! targetFolder.isDirectory())
  198. ConsoleApplication::fail ("The first argument must be the directory to put the result.");
  199. if (buildAllWithIndex)
  200. {
  201. auto folderToSearch = args[2].resolveAsFile();
  202. DirectoryIterator i (folderToSearch, false, "*", File::findDirectories);
  203. var infoList;
  204. while (i.next())
  205. {
  206. LibraryModule module (i.getFile());
  207. if (module.isValid())
  208. {
  209. zipModule (targetFolder, i.getFile());
  210. var moduleInfo (new DynamicObject());
  211. moduleInfo.getDynamicObject()->setProperty ("file", getModulePackageName (module));
  212. moduleInfo.getDynamicObject()->setProperty ("info", module.moduleInfo.moduleInfo);
  213. infoList.append (moduleInfo);
  214. }
  215. }
  216. auto indexFile = targetFolder.getChildFile ("modulelist");
  217. std::cout << "Writing: " << indexFile.getFullPathName() << std::endl;
  218. indexFile.replaceWithText (JSON::toString (infoList), false, false);
  219. }
  220. else
  221. {
  222. for (int i = 2; i < args.size(); ++i)
  223. zipModule (targetFolder, args[i].resolveAsFile());
  224. }
  225. }
  226. //==============================================================================
  227. struct CleanupOptions
  228. {
  229. bool removeTabs;
  230. bool fixDividerComments;
  231. };
  232. static void cleanWhitespace (const File& file, CleanupOptions options)
  233. {
  234. auto content = file.loadFileAsString();
  235. if (content.contains ("%""%") && content.contains ("//["))
  236. return; // ignore projucer GUI template files
  237. StringArray lines;
  238. lines.addLines (content);
  239. bool anyTabsRemoved = false;
  240. for (int i = 0; i < lines.size(); ++i)
  241. {
  242. String& line = lines.getReference (i);
  243. if (options.removeTabs && line.containsChar ('\t'))
  244. {
  245. anyTabsRemoved = true;
  246. for (;;)
  247. {
  248. const int tabPos = line.indexOfChar ('\t');
  249. if (tabPos < 0)
  250. break;
  251. const int spacesPerTab = 4;
  252. const int spacesNeeded = spacesPerTab - (tabPos % spacesPerTab);
  253. line = line.replaceSection (tabPos, 1, String::repeatedString (" ", spacesNeeded));
  254. }
  255. }
  256. if (options.fixDividerComments)
  257. {
  258. auto afterIndent = line.trim();
  259. if (afterIndent.startsWith ("//") && afterIndent.length() > 20)
  260. {
  261. afterIndent = afterIndent.substring (2);
  262. if (afterIndent.containsOnly ("=")
  263. || afterIndent.containsOnly ("/")
  264. || afterIndent.containsOnly ("-"))
  265. {
  266. line = line.substring (0, line.indexOfChar ('/'))
  267. + "//" + String::repeatedString ("=", 78);
  268. }
  269. }
  270. }
  271. line = line.trimEnd();
  272. }
  273. if (options.removeTabs && ! anyTabsRemoved)
  274. return;
  275. auto newText = joinLinesIntoSourceFile (lines);
  276. if (newText != content && newText != content + getPreferredLinefeed())
  277. replaceFile (file, newText, options.removeTabs ? "Removing tabs in: "
  278. : "Cleaning file: ");
  279. }
  280. static void scanFilesForCleanup (const ArgumentList& args, CleanupOptions options)
  281. {
  282. args.checkMinNumArguments (2);
  283. for (auto it = args.arguments.begin() + 1; it < args.arguments.end(); ++it)
  284. {
  285. auto target = it->resolveAsFile();
  286. Array<File> files;
  287. if (target.isDirectory())
  288. files = findAllSourceFiles (target);
  289. else
  290. files.add (target);
  291. for (int i = 0; i < files.size(); ++i)
  292. cleanWhitespace (files.getReference(i), options);
  293. }
  294. }
  295. static void cleanWhitespace (const ArgumentList& args, bool replaceTabs)
  296. {
  297. CleanupOptions options = { replaceTabs, false };
  298. scanFilesForCleanup (args, options);
  299. }
  300. static void tidyDividerComments (const ArgumentList& args)
  301. {
  302. CleanupOptions options = { false, true };
  303. scanFilesForCleanup (args, options);
  304. }
  305. //==============================================================================
  306. static File findSimilarlyNamedHeader (const Array<File>& allFiles, const String& name, const File& sourceFile)
  307. {
  308. File result;
  309. for (auto& f : allFiles)
  310. {
  311. if (f.getFileName().equalsIgnoreCase (name) && f != sourceFile)
  312. {
  313. if (result.exists())
  314. return {}; // multiple possible results, so don't change it!
  315. result = f;
  316. }
  317. }
  318. return result;
  319. }
  320. static void fixIncludes (const File& file, const Array<File>& allFiles)
  321. {
  322. const String content (file.loadFileAsString());
  323. StringArray lines;
  324. lines.addLines (content);
  325. bool hasChanged = false;
  326. for (auto& line : lines)
  327. {
  328. if (line.trimStart().startsWith ("#include \""))
  329. {
  330. auto includedFile = line.fromFirstOccurrenceOf ("\"", true, false)
  331. .upToLastOccurrenceOf ("\"", true, false)
  332. .trim()
  333. .unquoted();
  334. auto target = file.getSiblingFile (includedFile);
  335. if (! target.exists())
  336. {
  337. auto header = findSimilarlyNamedHeader (allFiles, target.getFileName(), file);
  338. if (header.exists())
  339. {
  340. line = line.upToFirstOccurrenceOf ("#include \"", true, false)
  341. + header.getRelativePathFrom (file.getParentDirectory())
  342. .replaceCharacter ('\\', '/')
  343. + "\"";
  344. hasChanged = true;
  345. }
  346. }
  347. }
  348. }
  349. if (hasChanged)
  350. {
  351. auto newText = joinLinesIntoSourceFile (lines);
  352. if (newText != content && newText != content + getPreferredLinefeed())
  353. replaceFile (file, newText, "Fixing includes in: ");
  354. }
  355. }
  356. static void fixRelativeIncludePaths (const ArgumentList& args)
  357. {
  358. args.checkMinNumArguments (2);
  359. auto target = args[1].resolveAsExistingFolder();
  360. auto files = findAllSourceFiles (target);
  361. for (int i = 0; i < files.size(); ++i)
  362. fixIncludes (files.getReference(i), files);
  363. }
  364. //==============================================================================
  365. static String getStringConcatenationExpression (Random& rng, int start, int length)
  366. {
  367. jassert (length > 0);
  368. if (length == 1)
  369. return "s" + String (start);
  370. int breakPos = jlimit (1, length - 1, (length / 3) + rng.nextInt (length / 3));
  371. return "(" + getStringConcatenationExpression (rng, start, breakPos)
  372. + " + " + getStringConcatenationExpression (rng, start + breakPos, length - breakPos) + ")";
  373. }
  374. static void generateObfuscatedStringCode (const ArgumentList& args)
  375. {
  376. args.checkMinNumArguments (2);
  377. auto originalText = args[1].text.unquoted();
  378. struct Section
  379. {
  380. String text;
  381. int position, index;
  382. void writeGenerator (MemoryOutputStream& out) const
  383. {
  384. String name ("s" + String (index));
  385. out << " String " << name << "; " << name;
  386. for (int i = 0; i < text.length(); ++i)
  387. out << " << '" << String::charToString (text[i]) << "'";
  388. out << ";" << preferredLinefeed;
  389. }
  390. };
  391. Array<Section> sections;
  392. String text = originalText;
  393. Random rng;
  394. while (text.isNotEmpty())
  395. {
  396. int pos = jmax (0, text.length() - (1 + rng.nextInt (6)));
  397. Section s = { text.substring (pos), pos, 0 };
  398. sections.insert (0, s);
  399. text = text.substring (0, pos);
  400. }
  401. for (int i = 0; i < sections.size(); ++i)
  402. sections.getReference(i).index = i;
  403. for (int i = 0; i < sections.size(); ++i)
  404. sections.swap (i, rng.nextInt (sections.size()));
  405. MemoryOutputStream out;
  406. out << "String createString()" << preferredLinefeed
  407. << "{" << preferredLinefeed;
  408. for (int i = 0; i < sections.size(); ++i)
  409. sections.getReference(i).writeGenerator (out);
  410. out << preferredLinefeed
  411. << " String result = " << getStringConcatenationExpression (rng, 0, sections.size()) << ";" << preferredLinefeed
  412. << preferredLinefeed
  413. << " jassert (result == " << originalText.quoted() << ");" << preferredLinefeed
  414. << " return result;" << preferredLinefeed
  415. << "}" << preferredLinefeed;
  416. std::cout << out.toString() << std::endl;
  417. }
  418. static void scanFoldersForTranslationFiles (const ArgumentList& args)
  419. {
  420. args.checkMinNumArguments (2);
  421. StringArray translations;
  422. for (auto it = args.arguments.begin() + 1; it != args.arguments.end(); ++it)
  423. {
  424. auto directoryToSearch = it->resolveAsExistingFolder();
  425. TranslationHelpers::scanFolderForTranslations (translations, directoryToSearch);
  426. }
  427. std::cout << TranslationHelpers::mungeStrings (translations) << std::endl;
  428. }
  429. static void createFinishedTranslationFile (const ArgumentList& args)
  430. {
  431. args.checkMinNumArguments (3);
  432. auto preTranslated = args[1].resolveAsExistingFile().loadFileAsString();
  433. auto postTranslated = args[2].resolveAsExistingFile().loadFileAsString();
  434. auto localisedContent = (args.size() > 3 ? args[3].resolveAsExistingFile().loadFileAsString() : String());
  435. auto localised = LocalisedStrings (localisedContent, false);
  436. using TH = TranslationHelpers;
  437. std::cout << TH::createFinishedTranslationFile (TH::withTrimmedEnds (TH::breakApart (preTranslated)),
  438. TH::withTrimmedEnds (TH::breakApart (postTranslated)),
  439. localised) << std::endl;
  440. }
  441. //==============================================================================
  442. static void encodeBinary (const ArgumentList& args)
  443. {
  444. args.checkMinNumArguments (3);
  445. auto source = args[1].resolveAsExistingFile();
  446. auto target = args[2].resolveAsExistingFile();
  447. MemoryOutputStream literal;
  448. size_t dataSize = 0;
  449. {
  450. MemoryBlock data;
  451. FileInputStream input (source);
  452. input.readIntoMemoryBlock (data);
  453. CodeHelpers::writeDataAsCppLiteral (data, literal, true, true);
  454. dataSize = data.getSize();
  455. }
  456. auto variableName = CodeHelpers::makeBinaryDataIdentifierName (source);
  457. MemoryOutputStream header, cpp;
  458. header << "// Auto-generated binary data by the Projucer" << preferredLinefeed
  459. << "// Source file: " << source.getRelativePathFrom (target.getParentDirectory()) << preferredLinefeed
  460. << preferredLinefeed;
  461. cpp << header.toString();
  462. if (target.hasFileExtension (headerFileExtensions))
  463. {
  464. header << "static constexpr unsigned char " << variableName << "[] =" << preferredLinefeed
  465. << literal.toString() << preferredLinefeed
  466. << preferredLinefeed;
  467. replaceFile (target, header.toString(), "Writing: ");
  468. }
  469. else if (target.hasFileExtension (cppFileExtensions))
  470. {
  471. header << "extern const char* " << variableName << ";" << preferredLinefeed
  472. << "const unsigned int " << variableName << "Size = " << (int) dataSize << ";" << preferredLinefeed
  473. << preferredLinefeed;
  474. cpp << CodeHelpers::createIncludeStatement (target.withFileExtension (".h").getFileName()) << preferredLinefeed
  475. << preferredLinefeed
  476. << "static constexpr unsigned char " << variableName << "_local[] =" << preferredLinefeed
  477. << literal.toString() << preferredLinefeed
  478. << preferredLinefeed
  479. << "const char* " << variableName << " = (const char*) " << variableName << "_local;" << preferredLinefeed;
  480. replaceFile (target, cpp.toString(), "Writing: ");
  481. replaceFile (target.withFileExtension (".h"), header.toString(), "Writing: ");
  482. }
  483. else
  484. {
  485. ConsoleApplication::fail ("You need to specify a .h or .cpp file as the target");
  486. }
  487. }
  488. //==============================================================================
  489. static bool isThisOS (const String& os)
  490. {
  491. auto targetOS = TargetOS::unknown;
  492. if (os == "osx") targetOS = TargetOS::osx;
  493. else if (os == "windows") targetOS = TargetOS::windows;
  494. else if (os == "linux") targetOS = TargetOS::linux;
  495. if (targetOS == TargetOS::unknown)
  496. ConsoleApplication::fail ("You need to specify a valid OS! Use osx, windows or linux");
  497. return targetOS == TargetOS::getThisOS();
  498. }
  499. static bool isValidPathIdentifier (const String& id, const String& os)
  500. {
  501. return id == "vst3Path" || (id == "aaxPath" && os != "linux") || (id == "rtasPath" && os != "linux")
  502. || id == "androidSDKPath" || id == "androidNDKPath" || id == "defaultJuceModulePath" || id == "defaultUserModulePath";
  503. }
  504. static void setGlobalPath (const ArgumentList& args)
  505. {
  506. args.checkMinNumArguments (3);
  507. if (! isValidPathIdentifier (args[2].text, args[1].text))
  508. ConsoleApplication::fail ("Identifier " + args[2].text + " is not valid for the OS " + args[1].text);
  509. auto userAppData = File::getSpecialLocation (File::userApplicationDataDirectory);
  510. #if JUCE_MAC
  511. userAppData = userAppData.getChildFile ("Application Support");
  512. #endif
  513. auto settingsFile = userAppData.getChildFile ("Projucer").getChildFile ("Projucer.settings");
  514. std::unique_ptr<XmlElement> xml (XmlDocument::parse (settingsFile));
  515. auto settingsTree = ValueTree::fromXml (*xml);
  516. if (! settingsTree.isValid())
  517. ConsoleApplication::fail ("Settings file not valid!");
  518. ValueTree childToSet;
  519. if (isThisOS (args[1].text))
  520. {
  521. childToSet = settingsTree.getChildWithProperty (Ids::name, "PROJECT_DEFAULT_SETTINGS")
  522. .getChildWithName ("PROJECT_DEFAULT_SETTINGS");
  523. }
  524. else
  525. {
  526. childToSet = settingsTree.getChildWithProperty (Ids::name, "FALLBACK_PATHS")
  527. .getChildWithName ("FALLBACK_PATHS")
  528. .getChildWithName (args[1].text + "Fallback");
  529. }
  530. if (! childToSet.isValid())
  531. ConsoleApplication::fail ("Failed to set the requested setting!");
  532. childToSet.setProperty (args[2].text, args[3].resolveAsFile().getFullPathName(), nullptr);
  533. settingsFile.replaceWithText (settingsTree.toXmlString());
  534. }
  535. static void createProjectFromPIP (const ArgumentList& args)
  536. {
  537. args.checkMinNumArguments (3);
  538. auto pipFile = args[1].resolveAsFile();
  539. if (! pipFile.existsAsFile())
  540. ConsoleApplication::fail ("PIP file doesn't exist.");
  541. auto outputDir = args[2].resolveAsFile();
  542. if (! outputDir.exists())
  543. {
  544. auto res = outputDir.createDirectory();
  545. std::cout << "Creating directory " << outputDir.getFullPathName() << std::endl;
  546. }
  547. File juceDir;
  548. if (args.size() > 3)
  549. {
  550. juceDir = args[3].resolveAsFile();
  551. if (! juceDir.exists())
  552. ConsoleApplication::fail ("Specified JUCE modules directory doesn't exist.");
  553. }
  554. PIPGenerator generator (pipFile, outputDir, juceDir);
  555. auto createJucerFileResult = generator.createJucerFile();
  556. if (! createJucerFileResult)
  557. ConsoleApplication::fail (createJucerFileResult.getErrorMessage());
  558. auto createMainCppResult = generator.createMainCpp();
  559. if (! createMainCppResult)
  560. ConsoleApplication::fail (createMainCppResult.getErrorMessage());
  561. }
  562. //==============================================================================
  563. static void showHelp()
  564. {
  565. hideDockIcon();
  566. auto appName = JUCEApplication::getInstance()->getApplicationName();
  567. std::cout << appName << std::endl
  568. << std::endl
  569. << "Usage: " << std::endl
  570. << std::endl
  571. << " " << appName << " --resave project_file" << std::endl
  572. << " Resaves all files and resources in a project." << std::endl
  573. << std::endl
  574. << " " << appName << " --resave-resources project_file" << std::endl
  575. << " Resaves just the binary resources for a project." << std::endl
  576. << std::endl
  577. << " " << appName << " --get-version project_file" << std::endl
  578. << " Returns the version number of a project." << std::endl
  579. << std::endl
  580. << " " << appName << " --set-version version_number project_file" << std::endl
  581. << " Updates the version number in a project." << std::endl
  582. << std::endl
  583. << " " << appName << " --bump-version project_file" << std::endl
  584. << " Updates the minor version number in a project by 1." << std::endl
  585. << std::endl
  586. << " " << appName << " --git-tag-version project_file" << std::endl
  587. << " Invokes 'git tag' to attach the project's version number to the current git repository." << std::endl
  588. << std::endl
  589. << " " << appName << " --status project_file" << std::endl
  590. << " Displays information about a project." << std::endl
  591. << std::endl
  592. << " " << appName << " --buildmodule target_folder module_folder" << std::endl
  593. << " Zips a module into a downloadable file format." << std::endl
  594. << std::endl
  595. << " " << appName << " --buildallmodules target_folder module_folder" << std::endl
  596. << " Zips all modules in a given folder and creates an index for them." << std::endl
  597. << std::endl
  598. << " " << appName << " --trim-whitespace target_folder" << std::endl
  599. << " Scans the given folder for C/C++ source files (recursively), and trims any trailing whitespace from their lines, as well as normalising their line-endings to CR-LF." << std::endl
  600. << std::endl
  601. << " " << appName << " --remove-tabs target_folder" << std::endl
  602. << " Scans the given folder for C/C++ source files (recursively), and replaces any tab characters with 4 spaces." << std::endl
  603. << std::endl
  604. << " " << appName << " --tidy-divider-comments target_folder" << std::endl
  605. << " Scans the given folder for C/C++ source files (recursively), and normalises any juce-style comment division lines (i.e. any lines that look like //===== or //------- or /////////// will be replaced)." << std::endl
  606. << std::endl
  607. << " " << appName << " --fix-broken-include-paths target_folder" << std::endl
  608. << " Scans the given folder for C/C++ source files (recursively). Where a file contains an #include of one of the other filenames, it changes it to use the optimum relative path. Helpful for auto-fixing includes when re-arranging files and folders in a project." << std::endl
  609. << std::endl
  610. << " " << appName << " --obfuscated-string-code string_to_obfuscate" << std::endl
  611. << " Generates a C++ function which returns the given string, but in an obfuscated way." << std::endl
  612. << std::endl
  613. << " " << appName << " --encode-binary source_binary_file target_cpp_file" << std::endl
  614. << " Converts a binary file to a C++ file containing its contents as a block of data. Provide a .h file as the target if you want a single output file, or a .cpp file if you want a pair of .h/.cpp files." << std::endl
  615. << std::endl
  616. << " " << appName << " --trans target_folders..." << std::endl
  617. << " Scans each of the given folders (recursively) for any NEEDS_TRANS macros, and generates a translation file that can be used with Projucer's translation file builder" << std::endl
  618. << std::endl
  619. << " " << appName << " --trans-finish pre_translated_file post_translated_file optional_existing_translation_file" << std::endl
  620. << " Creates a completed translations mapping file, that can be used to initialise a LocalisedStrings object. This allows you to localise the strings in your project" << std::endl
  621. << std::endl
  622. << " " << appName << " --set-global-search-path os identifier_to_set new_path" << std::endl
  623. << " Sets the global path for a specified os and identifier. The os should be either osx, windows or linux and the identifiers can be any of the following: "
  624. << "defaultJuceModulePath, defaultUserModulePath, vst3Path, aaxPath (not valid on linux), rtasPath (not valid on linux), androidSDKPath or androidNDKPath." << std::endl
  625. << std::endl
  626. << " " << appName << " --create-project-from-pip path/to/PIP path/to/output path/to/JUCE/modules (optional)" << std::endl
  627. << " Generates a JUCE project from a PIP file." << std::endl
  628. << std::endl
  629. << "Note that for any of the file-rewriting commands, add the option \"--lf\" if you want it to use LF linefeeds instead of CRLF" << std::endl
  630. << std::endl;
  631. }
  632. }
  633. //==============================================================================
  634. int performCommandLine (const ArgumentList& args)
  635. {
  636. return ConsoleApplication::invokeCatchingFailures ([&] () -> int
  637. {
  638. if (args.containsOption ("--lf"))
  639. preferredLinefeed = "\n";
  640. auto command = args[0];
  641. auto matchCommand = [&] (StringRef name) -> bool
  642. {
  643. return command == name || command.isLongOption (name);
  644. };
  645. if (matchCommand ("help")) { showHelp(); return 0; }
  646. if (matchCommand ("h")) { showHelp(); return 0; }
  647. if (matchCommand ("resave")) { resaveProject (args, false); return 0; }
  648. if (matchCommand ("resave-resources")) { resaveProject (args, true); return 0; }
  649. if (matchCommand ("get-version")) { getVersion (args); return 0; }
  650. if (matchCommand ("set-version")) { setVersion (args); return 0; }
  651. if (matchCommand ("bump-version")) { bumpVersion (args); return 0; }
  652. if (matchCommand ("git-tag-version")) { gitTag (args); return 0; }
  653. if (matchCommand ("buildmodule")) { buildModules (args, false); return 0; }
  654. if (matchCommand ("buildallmodules")) { buildModules (args, true); return 0; }
  655. if (matchCommand ("status")) { showStatus (args); return 0; }
  656. if (matchCommand ("trim-whitespace")) { cleanWhitespace (args, false); return 0; }
  657. if (matchCommand ("remove-tabs")) { cleanWhitespace (args, true); return 0; }
  658. if (matchCommand ("tidy-divider-comments")) { tidyDividerComments (args); return 0; }
  659. if (matchCommand ("fix-broken-include-paths")) { fixRelativeIncludePaths (args); return 0; }
  660. if (matchCommand ("obfuscated-string-code")) { generateObfuscatedStringCode (args); return 0; }
  661. if (matchCommand ("encode-binary")) { encodeBinary (args); return 0; }
  662. if (matchCommand ("trans")) { scanFoldersForTranslationFiles (args); return 0; }
  663. if (matchCommand ("trans-finish")) { createFinishedTranslationFile (args); return 0; }
  664. if (matchCommand ("set-global-search-path")) { setGlobalPath (args); return 0; }
  665. if (matchCommand ("create-project-from-pip")) { createProjectFromPIP (args); return 0; }
  666. if (command.isLongOption() || command.isShortOption())
  667. ConsoleApplication::fail ("Unrecognised command: " + command.text.quoted());
  668. return commandLineNotPerformed;
  669. });
  670. }