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.

923 lines
37KB

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