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.

136 lines
4.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the dRowAudio JUCE module
  4. Copyright 2004-13 by dRowAudio.
  5. ------------------------------------------------------------------------------
  6. dRowAudio is provided under the terms of The MIT License (MIT):
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in all
  14. copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. SOFTWARE.
  22. ==============================================================================
  23. */
  24. //==============================================================================
  25. UnityBuilder::UnityBuilder()
  26. {
  27. }
  28. UnityBuilder::~UnityBuilder()
  29. {
  30. }
  31. bool UnityBuilder::processDirectory (const File& sourceDirectory)
  32. {
  33. if (sourceDirectory.isDirectory())
  34. {
  35. Array<File> files;
  36. sourceDirectory.findChildFiles (files, File::findFiles + File::ignoreHiddenFiles, true);
  37. String includeString, sourceString;
  38. for (int i = 0; i < files.size(); ++i)
  39. {
  40. bool includeFile = true;
  41. File& currentFile (files.getReference (i));
  42. // first check files
  43. if (! filesToIgnore.contains (currentFile))
  44. {
  45. // now check for directories
  46. for (int i = 0; i < filesToIgnore.size(); ++i)
  47. {
  48. File& currentDir (filesToIgnore.getReference (i));
  49. if (currentDir.isDirectory()
  50. && currentFile.isAChildOf (currentDir))
  51. {
  52. includeFile = false;
  53. break;
  54. }
  55. }
  56. if (includeFile)
  57. {
  58. const String relativePath (currentFile.getRelativePathFrom (sourceDirectory));
  59. if (currentFile.hasFileExtension (".h"))
  60. includeString << "#include \"" << relativePath << "\"" << newLine;
  61. else if (currentFile.hasFileExtension (".cpp"))
  62. sourceString << "#include \"" << relativePath << "\"" << newLine;
  63. }
  64. }
  65. }
  66. // now write the output files
  67. File outputFile (destinationFile.exists() ? destinationFile : sourceDirectory);
  68. if (outputFile.hasWriteAccess())
  69. {
  70. File headerFile, cppFile;
  71. if (outputFile.isDirectory())
  72. {
  73. const String baseName ("UnityBuild");
  74. headerFile = outputFile.getNonexistentChildFile (baseName, ".h");
  75. cppFile = outputFile.getNonexistentChildFile (baseName, ".cpp");
  76. }
  77. else
  78. {
  79. headerFile = outputFile.getNonexistentSibling().withFileExtension (".h");
  80. cppFile = outputFile.getNonexistentSibling().withFileExtension (".cpp");
  81. }
  82. String headerOutput (preInclusionString);
  83. String sourceOutput (preInclusionString);
  84. headerOutput << includeString << postInclusionString;
  85. sourceOutput << "#include \"" << headerFile.getFileName() << "\"" << newLine << newLine
  86. << sourceString << postInclusionString;
  87. headerFile.replaceWithText (headerOutput);
  88. cppFile.replaceWithText (sourceOutput);
  89. return true;
  90. }
  91. }
  92. return false;
  93. }
  94. void UnityBuilder::setDestinationFile (const File& newDestinationFile)
  95. {
  96. destinationFile = newDestinationFile;
  97. }
  98. void UnityBuilder::setFilesToIgnore (const Array<File>& filesToIgnore_)
  99. {
  100. filesToIgnore = filesToIgnore_;
  101. }
  102. void UnityBuilder::setPreAndPostString (const String& preInclusionString_,
  103. const String& postInclusionString_)
  104. {
  105. preInclusionString = preInclusionString_;
  106. postInclusionString = postInclusionString_;
  107. }