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.

831 lines
26KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #include "../jucer_Headers.h"
  18. #include "jucer_Module.h"
  19. #include "jucer_ProjectType.h"
  20. #include "../Project Saving/jucer_ProjectExporter.h"
  21. #include "../Project Saving/jucer_ProjectSaver.h"
  22. #include "../Project Saving/jucer_ProjectExport_XCode.h"
  23. static String trimCommentCharsFromStartOfLine (const String& line)
  24. {
  25. return line.trimStart().trimCharactersAtStart ("*/").trimStart();
  26. }
  27. static var parseModuleDesc (const StringArray& lines)
  28. {
  29. DynamicObject* o = new DynamicObject();
  30. var result (o);
  31. for (int i = 0; i < lines.size(); ++i)
  32. {
  33. String line = trimCommentCharsFromStartOfLine (lines[i]);
  34. int colon = line.indexOfChar (':');
  35. if (colon >= 0)
  36. {
  37. String key = line.substring (0, colon).trim();
  38. String value = line.substring (colon + 1).trim();
  39. o->setProperty (key, value);
  40. }
  41. }
  42. return result;
  43. }
  44. static var parseModuleDesc (const File& header)
  45. {
  46. StringArray lines;
  47. header.readLines (lines);
  48. for (int i = 0; i < lines.size(); ++i)
  49. {
  50. if (trimCommentCharsFromStartOfLine (lines[i]).startsWith ("BEGIN_JUCE_MODULE_DECLARATION"))
  51. {
  52. StringArray desc;
  53. for (int j = i + 1; j < lines.size(); ++j)
  54. {
  55. if (trimCommentCharsFromStartOfLine (lines[j]).startsWith ("END_JUCE_MODULE_DECLARATION"))
  56. return parseModuleDesc (desc);
  57. desc.add (lines[j]);
  58. }
  59. break;
  60. }
  61. }
  62. return var();
  63. }
  64. ModuleDescription::ModuleDescription (const File& folder)
  65. : moduleFolder (folder),
  66. moduleInfo (parseModuleDesc (getHeader()))
  67. {
  68. }
  69. File ModuleDescription::getHeader() const
  70. {
  71. const char* extensions[] = { ".h", ".hpp", ".hxx" };
  72. for (int i = 0; i < numElementsInArray (extensions); ++i)
  73. {
  74. File header (moduleFolder.getChildFile (moduleFolder.getFileName() + extensions[i]));
  75. if (header.existsAsFile())
  76. return header;
  77. }
  78. return File();
  79. }
  80. StringArray ModuleDescription::getDependencies() const
  81. {
  82. StringArray deps = StringArray::fromTokens (moduleInfo ["dependencies"].toString(), " \t;,", "\"'");
  83. deps.trim();
  84. deps.removeEmptyStrings();
  85. return deps;
  86. }
  87. //==============================================================================
  88. ModuleList::ModuleList()
  89. {
  90. }
  91. ModuleList::ModuleList (const ModuleList& other)
  92. {
  93. operator= (other);
  94. }
  95. ModuleList& ModuleList::operator= (const ModuleList& other)
  96. {
  97. modules.clear();
  98. modules.addCopiesOf (other.modules);
  99. return *this;
  100. }
  101. const ModuleDescription* ModuleList::getModuleWithID (const String& moduleID) const
  102. {
  103. for (int i = 0; i < modules.size(); ++i)
  104. {
  105. ModuleDescription* m = modules.getUnchecked(i);
  106. if (m->getID() == moduleID)
  107. return m;
  108. }
  109. return nullptr;
  110. }
  111. struct ModuleSorter
  112. {
  113. static int compareElements (const ModuleDescription* m1, const ModuleDescription* m2)
  114. {
  115. return m1->getID().compareIgnoreCase (m2->getID());
  116. }
  117. };
  118. void ModuleList::sort()
  119. {
  120. ModuleSorter sorter;
  121. modules.sort (sorter);
  122. }
  123. StringArray ModuleList::getIDs() const
  124. {
  125. StringArray results;
  126. for (int i = 0; i < modules.size(); ++i)
  127. results.add (modules.getUnchecked(i)->getID());
  128. results.sort (true);
  129. return results;
  130. }
  131. Result ModuleList::tryToAddModuleFromFolder (const File& path)
  132. {
  133. ModuleDescription m (path);
  134. if (m.isValid())
  135. {
  136. modules.add (new ModuleDescription (m));
  137. return Result::ok();
  138. }
  139. return Result::fail (path.getFullPathName() + " is not a valid module");
  140. }
  141. Result ModuleList::addAllModulesInFolder (const File& path)
  142. {
  143. if (! tryToAddModuleFromFolder (path))
  144. {
  145. const int subfolders = 2;
  146. return addAllModulesInSubfoldersRecursively (path, subfolders);
  147. }
  148. return Result::ok();
  149. }
  150. Result ModuleList::addAllModulesInSubfoldersRecursively (const File& path, int depth)
  151. {
  152. if (depth > 0)
  153. {
  154. for (DirectoryIterator iter (path, false, "*", File::findDirectories); iter.next();)
  155. {
  156. const File& childPath = iter.getFile().getLinkedTarget();
  157. if (! tryToAddModuleFromFolder (childPath))
  158. addAllModulesInSubfoldersRecursively (childPath, depth - 1);
  159. }
  160. }
  161. return Result::ok();
  162. }
  163. static Array<File> getAllPossibleModulePaths (Project& project)
  164. {
  165. StringArray paths;
  166. for (Project::ExporterIterator exporter (project); exporter.next();)
  167. {
  168. for (int i = 0; i < project.getModules().getNumModules(); ++i)
  169. {
  170. const String path (exporter->getPathForModuleString (project.getModules().getModuleID (i)));
  171. if (path.isNotEmpty())
  172. paths.addIfNotAlreadyThere (path);
  173. }
  174. String oldPath (exporter->getLegacyModulePath());
  175. if (oldPath.isNotEmpty())
  176. paths.addIfNotAlreadyThere (oldPath);
  177. }
  178. Array<File> files;
  179. for (int i = 0; i < paths.size(); ++i)
  180. {
  181. const File f (project.resolveFilename (paths[i]));
  182. if (f.isDirectory())
  183. {
  184. files.add (f);
  185. if (f.getChildFile ("modules").isDirectory())
  186. files.addIfNotAlreadyThere (f.getChildFile ("modules"));
  187. }
  188. }
  189. return files;
  190. }
  191. Result ModuleList::scanAllKnownFolders (Project& project)
  192. {
  193. modules.clear();
  194. Result result (Result::ok());
  195. const Array<File> modulePaths (getAllPossibleModulePaths (project));
  196. for (int i = 0; i < modulePaths.size(); ++i)
  197. {
  198. result = addAllModulesInFolder (modulePaths.getReference(i));
  199. if (result.failed())
  200. break;
  201. }
  202. sort();
  203. return result;
  204. }
  205. //==============================================================================
  206. LibraryModule::LibraryModule (const ModuleDescription& d)
  207. : moduleInfo (d)
  208. {
  209. }
  210. //==============================================================================
  211. void LibraryModule::writeIncludes (ProjectSaver& projectSaver, OutputStream& out)
  212. {
  213. Project& project = projectSaver.project;
  214. EnabledModuleList& modules = project.getModules();
  215. const String id (getID());
  216. if (modules.shouldCopyModuleFilesLocally (id).getValue())
  217. {
  218. const File juceModuleFolder (moduleInfo.getFolder());
  219. const File localModuleFolder (project.getLocalModuleFolder (id));
  220. localModuleFolder.createDirectory();
  221. projectSaver.copyFolder (juceModuleFolder, localModuleFolder);
  222. }
  223. out << "#include <" << moduleInfo.moduleFolder.getFileName() << "/"
  224. << moduleInfo.getHeader().getFileName()
  225. << ">" << newLine;
  226. }
  227. //==============================================================================
  228. static void parseAndAddLibs (StringArray& libList, const String& libs)
  229. {
  230. libList.addTokens (libs, ", ", StringRef());
  231. libList.trim();
  232. libList.sort (false);
  233. libList.removeDuplicates (false);
  234. }
  235. void LibraryModule::addSettingsForModuleToExporter (ProjectExporter& exporter, ProjectSaver& projectSaver) const
  236. {
  237. Project& project = exporter.getProject();
  238. RelativePath modulePath = exporter.getModuleFolderRelativeToProject (getID());
  239. exporter.addToExtraSearchPaths (modulePath.getParentDirectory());
  240. const String extraInternalSearchPaths (moduleInfo.getExtraSearchPaths().trim());
  241. if (extraInternalSearchPaths.isNotEmpty())
  242. {
  243. StringArray paths;
  244. paths.addTokens (extraInternalSearchPaths, true);
  245. for (int i = 0; i < paths.size(); ++i)
  246. exporter.addToExtraSearchPaths (modulePath.getChildFile (paths.getReference(i)));
  247. }
  248. {
  249. const String extraDefs (moduleInfo.getPreprocessorDefs().trim());
  250. if (extraDefs.isNotEmpty())
  251. exporter.getExporterPreprocessorDefs() = exporter.getExporterPreprocessorDefsString() + "\n" + extraDefs;
  252. }
  253. {
  254. Array<File> compiled;
  255. const File localModuleFolder = project.getModules().shouldCopyModuleFilesLocally (getID()).getValue()
  256. ? project.getLocalModuleFolder (getID())
  257. : moduleInfo.getFolder();
  258. findAndAddCompiledUnits (exporter, &projectSaver, compiled);
  259. if (project.getModules().shouldShowAllModuleFilesInProject (getID()).getValue())
  260. addBrowseableCode (exporter, compiled, localModuleFolder);
  261. }
  262. if (exporter.isXcode())
  263. {
  264. XCodeProjectExporter& xcodeExporter = dynamic_cast<XCodeProjectExporter&> (exporter);
  265. if (project.isAUPluginHost())
  266. xcodeExporter.xcodeFrameworks.addTokens (xcodeExporter.isOSX() ? "AudioUnit CoreAudioKit" : "CoreAudioKit", false);
  267. const String frameworks (moduleInfo.moduleInfo [xcodeExporter.isOSX() ? "OSXFrameworks" : "iOSFrameworks"].toString());
  268. xcodeExporter.xcodeFrameworks.addTokens (frameworks, ", ", StringRef());
  269. parseAndAddLibs (xcodeExporter.xcodeLibs, moduleInfo.moduleInfo [exporter.isOSX() ? "OSXLibs" : "iOSLibs"].toString());
  270. }
  271. else if (exporter.isLinux())
  272. {
  273. parseAndAddLibs (exporter.linuxLibs, moduleInfo.moduleInfo ["linuxLibs"].toString());
  274. parseAndAddLibs (exporter.linuxPackages, moduleInfo.moduleInfo ["linuxPackages"].toString());
  275. }
  276. else if (exporter.isCodeBlocks() && exporter.isWindows())
  277. {
  278. parseAndAddLibs (exporter.mingwLibs, moduleInfo.moduleInfo ["mingwLibs"].toString());
  279. }
  280. }
  281. void LibraryModule::getConfigFlags (Project& project, OwnedArray<Project::ConfigFlag>& flags) const
  282. {
  283. const File header (moduleInfo.getHeader());
  284. jassert (header.exists());
  285. StringArray lines;
  286. header.readLines (lines);
  287. for (int i = 0; i < lines.size(); ++i)
  288. {
  289. String line (lines[i].trim());
  290. if (line.startsWith ("/**") && line.containsIgnoreCase ("Config:"))
  291. {
  292. ScopedPointer<Project::ConfigFlag> config (new Project::ConfigFlag());
  293. config->sourceModuleID = getID();
  294. config->symbol = line.fromFirstOccurrenceOf (":", false, false).trim();
  295. if (config->symbol.length() > 2)
  296. {
  297. ++i;
  298. while (! (lines[i].contains ("*/") || lines[i].contains ("@see")))
  299. {
  300. if (lines[i].trim().isNotEmpty())
  301. config->description = config->description.trim() + " " + lines[i].trim();
  302. ++i;
  303. }
  304. config->description = config->description.upToFirstOccurrenceOf ("*/", false, false);
  305. config->value.referTo (project.getConfigFlag (config->symbol));
  306. flags.add (config.release());
  307. }
  308. }
  309. }
  310. }
  311. //==============================================================================
  312. struct FileSorter
  313. {
  314. static int compareElements (const File& f1, const File& f2)
  315. {
  316. return f1.getFileName().compareNatural (f2.getFileName());
  317. }
  318. };
  319. bool LibraryModule::CompileUnit::hasSuffix (const File& f, const char* suffix)
  320. {
  321. String fileWithoutSuffix = f.getFileNameWithoutExtension() + String (".");
  322. return fileWithoutSuffix.containsIgnoreCase (suffix + String ("."))
  323. || fileWithoutSuffix.containsIgnoreCase (suffix + String ("_"));
  324. }
  325. void LibraryModule::CompileUnit::writeInclude (MemoryOutputStream&) const
  326. {
  327. }
  328. bool LibraryModule::CompileUnit::isNeededForExporter (ProjectExporter& exporter) const
  329. {
  330. Project& project = exporter.getProject();
  331. if ((hasSuffix (file, "_OSX") && ! exporter.isOSX())
  332. || (hasSuffix (file, "_iOS") && ! exporter.isiOS())
  333. || (hasSuffix (file, "_Windows") && ! exporter.isWindows())
  334. || (hasSuffix (file, "_Linux") && ! exporter.isLinux())
  335. || (hasSuffix (file, "_Android") && ! exporter.isAndroid())
  336. || (hasSuffix (file, "_AU") && ! (project.shouldBuildAU() .getValue() && exporter.supportsAU()))
  337. || (hasSuffix (file, "_AUv3") && ! (project.shouldBuildAUv3().getValue() && exporter.supportsAUv3()))
  338. || (hasSuffix (file, "_AAX") && ! (project.shouldBuildAAX() .getValue() && exporter.supportsAAX()))
  339. || (hasSuffix (file, "_RTAS") && ! (project.shouldBuildRTAS().getValue() && exporter.supportsRTAS()))
  340. || (hasSuffix (file, "_VST2") && ! (project.shouldBuildVST() .getValue() && exporter.supportsVST()))
  341. || (hasSuffix (file, "_VST3") && ! (project.shouldBuildVST3().getValue() && exporter.supportsVST3()))
  342. || (hasSuffix (file, "_Standalone") && ! (project.shouldBuildStandalone().getValue() && exporter.supportsStandalone())))
  343. return false;
  344. return exporter.usesMMFiles() ? isCompiledForObjC
  345. : isCompiledForNonObjC;
  346. }
  347. Array<LibraryModule::CompileUnit> LibraryModule::getAllCompileUnits() const
  348. {
  349. Array<File> files;
  350. getFolder().findChildFiles (files, File::findFiles, false);
  351. FileSorter sorter;
  352. files.sort (sorter);
  353. Array<LibraryModule::CompileUnit> units;
  354. for (int i = 0; i < files.size(); ++i)
  355. {
  356. CompileUnit cu;
  357. cu.file = files.getReference(i);
  358. if (cu.file.getFileName().startsWithIgnoreCase (getID())
  359. && cu.file.hasFileExtension (sourceFileExtensions))
  360. {
  361. units.add (cu);
  362. }
  363. }
  364. for (int i = 0; i < units.size(); ++i)
  365. {
  366. CompileUnit& cu = units.getReference(i);
  367. cu.isCompiledForObjC = true;
  368. cu.isCompiledForNonObjC = ! cu.file.hasFileExtension ("mm;m");
  369. if (cu.isCompiledForNonObjC)
  370. if (files.contains (cu.file.withFileExtension ("mm")))
  371. cu.isCompiledForObjC = false;
  372. jassert (cu.isCompiledForObjC || cu.isCompiledForNonObjC);
  373. }
  374. return units;
  375. }
  376. void LibraryModule::findAndAddCompiledUnits (ProjectExporter& exporter,
  377. ProjectSaver* projectSaver,
  378. Array<File>& result) const
  379. {
  380. Array<CompileUnit> units = getAllCompileUnits();
  381. for (int i = 0; i < units.size(); ++i)
  382. {
  383. const CompileUnit& cu = units.getReference(i);
  384. if (cu.isNeededForExporter (exporter))
  385. {
  386. File localFile = exporter.getProject().getGeneratedCodeFolder().getChildFile (cu.file.getFileName());
  387. result.add (localFile);
  388. if (projectSaver != nullptr)
  389. projectSaver->addFileToGeneratedGroup (localFile);
  390. }
  391. }
  392. }
  393. static void addFileWithGroups (Project::Item& group, const RelativePath& file, const String& path)
  394. {
  395. const int slash = path.indexOfChar (File::separator);
  396. if (slash >= 0)
  397. {
  398. const String topLevelGroup (path.substring (0, slash));
  399. const String remainingPath (path.substring (slash + 1));
  400. Project::Item newGroup (group.getOrCreateSubGroup (topLevelGroup));
  401. addFileWithGroups (newGroup, file, remainingPath);
  402. }
  403. else
  404. {
  405. if (! group.containsChildForFile (file))
  406. group.addRelativeFile (file, -1, false);
  407. }
  408. }
  409. void LibraryModule::findBrowseableFiles (const File& folder, Array<File>& filesFound) const
  410. {
  411. Array<File> tempList;
  412. FileSorter sorter;
  413. DirectoryIterator iter (folder, true, "*", File::findFiles);
  414. bool isHiddenFile;
  415. while (iter.next (nullptr, &isHiddenFile, nullptr, nullptr, nullptr, nullptr))
  416. if (! isHiddenFile && iter.getFile().hasFileExtension (browseableFileExtensions))
  417. tempList.addSorted (sorter, iter.getFile());
  418. filesFound.addArray (tempList);
  419. }
  420. void LibraryModule::addBrowseableCode (ProjectExporter& exporter, const Array<File>& compiled, const File& localModuleFolder) const
  421. {
  422. if (sourceFiles.size() == 0)
  423. findBrowseableFiles (localModuleFolder, sourceFiles);
  424. Project::Item sourceGroup (Project::Item::createGroup (exporter.getProject(), getID(), "__mainsourcegroup" + getID(), false));
  425. const RelativePath moduleFromProject (exporter.getModuleFolderRelativeToProject (getID()));
  426. for (int i = 0; i < sourceFiles.size(); ++i)
  427. {
  428. const String pathWithinModule (FileHelpers::getRelativePathFrom (sourceFiles.getReference(i), localModuleFolder));
  429. // (Note: in exporters like MSVC we have to avoid adding the same file twice, even if one of those instances
  430. // is flagged as being excluded from the build, because this overrides the other and it fails to compile)
  431. if (exporter.canCopeWithDuplicateFiles() || ! compiled.contains (sourceFiles.getReference(i)))
  432. addFileWithGroups (sourceGroup,
  433. moduleFromProject.getChildFile (pathWithinModule),
  434. pathWithinModule);
  435. }
  436. sourceGroup.sortAlphabetically (true, true);
  437. sourceGroup.addFileAtIndex (moduleInfo.getHeader(), -1, false);
  438. exporter.getModulesGroup().state.addChild (sourceGroup.state.createCopy(), -1, nullptr);
  439. }
  440. //==============================================================================
  441. EnabledModuleList::EnabledModuleList (Project& p, const ValueTree& s)
  442. : project (p), state (s)
  443. {
  444. }
  445. ModuleDescription EnabledModuleList::getModuleInfo (const String& moduleID)
  446. {
  447. return ModuleDescription (getModuleFolder (moduleID));
  448. }
  449. bool EnabledModuleList::isModuleEnabled (const String& moduleID) const
  450. {
  451. for (int i = 0; i < state.getNumChildren(); ++i)
  452. if (state.getChild(i) [Ids::ID] == moduleID)
  453. return true;
  454. return false;
  455. }
  456. bool EnabledModuleList::isAudioPluginModuleMissing() const
  457. {
  458. return project.getProjectType().isAudioPlugin()
  459. && ! isModuleEnabled ("juce_audio_plugin_client");
  460. }
  461. Value EnabledModuleList::shouldShowAllModuleFilesInProject (const String& moduleID)
  462. {
  463. return state.getChildWithProperty (Ids::ID, moduleID)
  464. .getPropertyAsValue (Ids::showAllCode, getUndoManager());
  465. }
  466. File EnabledModuleList::findLocalModuleFolder (const String& moduleID, bool useExportersForOtherOSes)
  467. {
  468. for (Project::ExporterIterator exporter (project); exporter.next();)
  469. {
  470. if (useExportersForOtherOSes || exporter->mayCompileOnCurrentOS())
  471. {
  472. const String path (exporter->getPathForModuleString (moduleID));
  473. if (path.isNotEmpty())
  474. {
  475. const File moduleFolder (project.resolveFilename (path));
  476. if (moduleFolder.exists())
  477. {
  478. if (ModuleDescription (moduleFolder).isValid())
  479. return moduleFolder;
  480. File f = moduleFolder.getChildFile (moduleID);
  481. if (ModuleDescription (f).isValid())
  482. return f;
  483. }
  484. }
  485. }
  486. }
  487. return File();
  488. }
  489. File EnabledModuleList::getModuleFolder (const String& moduleID)
  490. {
  491. File f = findLocalModuleFolder (moduleID, false);
  492. if (f == File())
  493. f = findLocalModuleFolder (moduleID, true);
  494. return f;
  495. }
  496. struct ModuleTreeSorter
  497. {
  498. static int compareElements (const ValueTree& m1, const ValueTree& m2)
  499. {
  500. return m1[Ids::ID].toString().compareIgnoreCase (m2[Ids::ID]);
  501. }
  502. };
  503. void EnabledModuleList::sortAlphabetically()
  504. {
  505. ModuleTreeSorter sorter;
  506. state.sort (sorter, getUndoManager(), false);
  507. }
  508. Value EnabledModuleList::shouldCopyModuleFilesLocally (const String& moduleID) const
  509. {
  510. return state.getChildWithProperty (Ids::ID, moduleID)
  511. .getPropertyAsValue (Ids::useLocalCopy, getUndoManager());
  512. }
  513. void EnabledModuleList::addModule (const File& moduleFolder, bool copyLocally)
  514. {
  515. ModuleDescription info (moduleFolder);
  516. if (info.isValid())
  517. {
  518. const String moduleID (info.getID());
  519. if (! isModuleEnabled (moduleID))
  520. {
  521. ValueTree module (Ids::MODULE);
  522. module.setProperty (Ids::ID, moduleID, nullptr);
  523. state.addChild (module, -1, getUndoManager());
  524. sortAlphabetically();
  525. shouldShowAllModuleFilesInProject (moduleID) = true;
  526. shouldCopyModuleFilesLocally (moduleID) = copyLocally;
  527. RelativePath path (moduleFolder.getParentDirectory(),
  528. project.getProjectFolder(), RelativePath::projectFolder);
  529. for (Project::ExporterIterator exporter (project); exporter.next();)
  530. exporter->getPathForModuleValue (moduleID) = path.toUnixStyle();
  531. }
  532. }
  533. }
  534. void EnabledModuleList::removeModule (String moduleID) // must be pass-by-value, and not a const ref!
  535. {
  536. for (int i = state.getNumChildren(); --i >= 0;)
  537. if (state.getChild(i) [Ids::ID] == moduleID)
  538. state.removeChild (i, getUndoManager());
  539. for (Project::ExporterIterator exporter (project); exporter.next();)
  540. exporter->removePathForModule (moduleID);
  541. }
  542. void EnabledModuleList::createRequiredModules (OwnedArray<LibraryModule>& modules)
  543. {
  544. for (int i = 0; i < getNumModules(); ++i)
  545. modules.add (new LibraryModule (getModuleInfo (getModuleID (i))));
  546. }
  547. StringArray EnabledModuleList::getAllModules() const
  548. {
  549. StringArray moduleIDs;
  550. for (int i = 0; i < getNumModules(); ++i)
  551. moduleIDs.add (getModuleID(i));
  552. return moduleIDs;
  553. }
  554. static void getDependencies (Project& project, const String& moduleID, StringArray& dependencies)
  555. {
  556. ModuleDescription info (project.getModules().getModuleInfo (moduleID));
  557. for (auto uid : info.getDependencies())
  558. {
  559. if (! dependencies.contains (uid, true))
  560. {
  561. dependencies.add (uid);
  562. getDependencies (project, uid, dependencies);
  563. }
  564. }
  565. }
  566. StringArray EnabledModuleList::getExtraDependenciesNeeded (const String& moduleID) const
  567. {
  568. StringArray dependencies, extraDepsNeeded;
  569. getDependencies (project, moduleID, dependencies);
  570. for (auto dep : dependencies)
  571. if (dep != moduleID && ! isModuleEnabled (dep))
  572. extraDepsNeeded.add (dep);
  573. return extraDepsNeeded;
  574. }
  575. bool EnabledModuleList::areMostModulesCopiedLocally() const
  576. {
  577. int numYes = 0, numNo = 0;
  578. for (int i = getNumModules(); --i >= 0;)
  579. {
  580. if (shouldCopyModuleFilesLocally (getModuleID (i)).getValue())
  581. ++numYes;
  582. else
  583. ++numNo;
  584. }
  585. return numYes > numNo;
  586. }
  587. void EnabledModuleList::setLocalCopyModeForAllModules (bool copyLocally)
  588. {
  589. for (int i = getNumModules(); --i >= 0;)
  590. shouldCopyModuleFilesLocally (project.getModules().getModuleID (i)) = copyLocally;
  591. }
  592. File EnabledModuleList::findDefaultModulesFolder (Project& project)
  593. {
  594. ModuleList available;
  595. available.scanAllKnownFolders (project);
  596. for (int i = available.modules.size(); --i >= 0;)
  597. {
  598. File f (available.modules.getUnchecked(i)->getFolder());
  599. if (f.isDirectory())
  600. return f.getParentDirectory();
  601. }
  602. return File::getCurrentWorkingDirectory();
  603. }
  604. void EnabledModuleList::addModuleFromUserSelectedFile()
  605. {
  606. static File lastLocation (findDefaultModulesFolder (project));
  607. FileChooser fc ("Select a module to add...", lastLocation, String(), false);
  608. if (fc.browseForDirectory())
  609. {
  610. lastLocation = fc.getResult();
  611. addModuleOfferingToCopy (lastLocation);
  612. }
  613. }
  614. void EnabledModuleList::addModuleInteractive (const String& moduleID)
  615. {
  616. ModuleList list;
  617. list.scanAllKnownFolders (project);
  618. if (const ModuleDescription* info = list.getModuleWithID (moduleID))
  619. addModule (info->moduleFolder, areMostModulesCopiedLocally());
  620. else
  621. addModuleFromUserSelectedFile();
  622. }
  623. void EnabledModuleList::addModuleOfferingToCopy (const File& f)
  624. {
  625. ModuleDescription m (f);
  626. if (! m.isValid())
  627. {
  628. AlertWindow::showMessageBoxAsync (AlertWindow::InfoIcon,
  629. "Add Module", "This wasn't a valid module folder!");
  630. return;
  631. }
  632. if (isModuleEnabled (m.getID()))
  633. {
  634. AlertWindow::showMessageBoxAsync (AlertWindow::InfoIcon,
  635. "Add Module", "The project already contains this module!");
  636. return;
  637. }
  638. addModule (m.moduleFolder, areMostModulesCopiedLocally());
  639. }
  640. bool isJuceFolder (const File& f)
  641. {
  642. return isJuceModulesFolder (f.getChildFile ("modules"));
  643. }
  644. bool isJuceModulesFolder (const File& f)
  645. {
  646. return f.isDirectory() && f.getChildFile ("juce_core").isDirectory();
  647. }