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.

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