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.

868 lines
34KB

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