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.

845 lines
26KB

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