Browse Source

Projucer: added a command-line flag --lf to make the whitespace and other file-generating tools use LF as linefeeds rather than CRLF

tags/2021-05-28
jules 7 years ago
parent
commit
aeee6f4c33
4 changed files with 74 additions and 56 deletions
  1. +6
    -6
      extras/Projucer/Source/Application/Windows/jucer_PIPCreatorWindowComponent.h
  2. +64
    -44
      extras/Projucer/Source/Application/jucer_CommandLine.cpp
  3. +3
    -5
      extras/Projucer/Source/Utility/Helpers/jucer_MiscUtilities.cpp
  4. +1
    -1
      extras/Projucer/Source/Utility/Helpers/jucer_MiscUtilities.h

+ 6
- 6
extras/Projucer/Source/Application/Windows/jucer_PIPCreatorWindowComponent.h View File

@@ -222,7 +222,7 @@ private:
if (descriptionValue.get().toString().isNotEmpty()) section.add (" description: " + descriptionValue.get().toString());
if (! section.isEmpty())
metadata.add (section.joinIntoString (getLineEnding()));
metadata.add (section.joinIntoString (getPreferredLinefeed()));
}
{
@@ -235,7 +235,7 @@ private:
if (exportersString.isNotEmpty()) section.add (" exporters: " + exportersString);
if (! section.isEmpty())
metadata.add (section.joinIntoString (getLineEnding()));
metadata.add (section.joinIntoString (getPreferredLinefeed()));
}
{
@@ -245,7 +245,7 @@ private:
if (definesValue.get().toString().isNotEmpty()) section.add (" defines: " + definesValue.get().toString());
if (! section.isEmpty())
metadata.add (section.joinIntoString (getLineEnding()));
metadata.add (section.joinIntoString (getPreferredLinefeed()));
}
{
@@ -255,7 +255,7 @@ private:
if (mainClassValue.get().toString().isNotEmpty()) section.add (" mainClass: " + mainClassValue.get().toString());
if (! section.isEmpty())
metadata.add (section.joinIntoString (getLineEnding()));
metadata.add (section.joinIntoString (getPreferredLinefeed()));
}
{
@@ -264,10 +264,10 @@ private:
if (useLocalCopyValue.get()) section.add (" useLocalCopy: " + useLocalCopyValue.get().toString());
if (! section.isEmpty())
metadata.add (section.joinIntoString (getLineEnding()));
metadata.add (section.joinIntoString (getPreferredLinefeed()));
}
return metadata.joinIntoString (String (getLineEnding()) + getLineEnding());
return metadata.joinIntoString (String (getPreferredLinefeed()) + getPreferredLinefeed());
}
void createPIPFile (File fileToSave)


+ 64
- 44
extras/Projucer/Source/Application/jucer_CommandLine.cpp View File

@@ -31,6 +31,9 @@
#include "jucer_CommandLine.h"
//==============================================================================
const char* preferredLinefeed = "\r\n";
const char* getPreferredLinefeed() { return preferredLinefeed; }
//==============================================================================
namespace
@@ -62,6 +65,20 @@ namespace
throw CommandLineError ("Not enough arguments!");
}
static bool findArgument (StringArray& args, const String& target)
{
for (int i = 0; i < args.size(); ++i)
{
if (args[i].trim() == target)
{
args.remove (i);
return true;
}
}
return false;
}
static File getFile (const String& filename)
{
return File::getCurrentWorkingDirectory().getChildFile (filename.unquoted());
@@ -405,9 +422,9 @@ namespace
if (options.removeTabs && ! anyTabsRemoved)
return;
const String newText = joinLinesIntoSourceFile (lines);
auto newText = joinLinesIntoSourceFile (lines);
if (newText != content && newText != content + getLineEnding())
if (newText != content && newText != content + getPreferredLinefeed())
replaceFile (file, newText, options.removeTabs ? "Removing tabs in: "
: "Cleaning file: ");
}
@@ -471,29 +488,28 @@ namespace
lines.addLines (content);
bool hasChanged = false;
for (int i = 0; i < lines.size(); ++i)
for (auto& line : lines)
{
String line = lines[i];
if (line.trimStart().startsWith ("#include \""))
{
const String includedFile (line.fromFirstOccurrenceOf ("\"", true, false)
.upToLastOccurrenceOf ("\"", true, false)
.trim()
.unquoted());
auto includedFile = line.fromFirstOccurrenceOf ("\"", true, false)
.upToLastOccurrenceOf ("\"", true, false)
.trim()
.unquoted();
const File target (file.getSiblingFile (includedFile));
auto target = file.getSiblingFile (includedFile);
if (! target.exists())
{
File header = findSimilarlyNamedHeader (allFiles, target.getFileName(), file);
auto header = findSimilarlyNamedHeader (allFiles, target.getFileName(), file);
if (header.exists())
{
lines.set (i, line.upToFirstOccurrenceOf ("#include \"", true, false)
+ header.getRelativePathFrom (file.getParentDirectory())
.replaceCharacter ('\\', '/')
+ "\"");
line = line.upToFirstOccurrenceOf ("#include \"", true, false)
+ header.getRelativePathFrom (file.getParentDirectory())
.replaceCharacter ('\\', '/')
+ "\"";
hasChanged = true;
}
}
@@ -502,9 +518,9 @@ namespace
if (hasChanged)
{
const String newText = joinLinesIntoSourceFile (lines);
auto newText = joinLinesIntoSourceFile (lines);
if (newText != content && newText != content + getLineEnding())
if (newText != content && newText != content + getPreferredLinefeed())
replaceFile (file, newText, "Fixing includes in: ");
}
}
@@ -512,9 +528,8 @@ namespace
static void fixRelativeIncludePaths (const StringArray& args)
{
checkArgumentCount (args, 2);
const File target (getDirectoryCheckingForExistence (args[1]));
Array<File> files = findAllSourceFiles (target);
auto target = getDirectoryCheckingForExistence (args[1]);
auto files = findAllSourceFiles (target);
for (int i = 0; i < files.size(); ++i)
fixIncludes (files.getReference(i), files);
@@ -553,7 +568,7 @@ namespace
for (int i = 0; i < text.length(); ++i)
out << " << '" << String::charToString (text[i]) << "'";
out << ";" << newLine;
out << ";" << preferredLinefeed;
}
};
@@ -577,18 +592,18 @@ namespace
MemoryOutputStream out;
out << "String createString()" << newLine
<< "{" << newLine;
out << "String createString()" << preferredLinefeed
<< "{" << preferredLinefeed;
for (int i = 0; i < sections.size(); ++i)
sections.getReference(i).writeGenerator (out);
out << newLine
<< " String result = " << getStringConcatenationExpression (rng, 0, sections.size()) << ";" << newLine
<< newLine
<< " jassert (result == " << originalText.quoted() << ");" << newLine
<< " return result;" << newLine
<< "}" << newLine;
out << preferredLinefeed
<< " String result = " << getStringConcatenationExpression (rng, 0, sections.size()) << ";" << preferredLinefeed
<< preferredLinefeed
<< " jassert (result == " << originalText.quoted() << ");" << preferredLinefeed
<< " return result;" << preferredLinefeed
<< "}" << preferredLinefeed;
std::cout << out.toString() << std::endl;
}
@@ -646,32 +661,32 @@ namespace
MemoryOutputStream header, cpp;
header << "// Auto-generated binary data by the Projucer" << newLine
<< "// Source file: " << source.getRelativePathFrom (target.getParentDirectory()) << newLine
<< newLine;
header << "// Auto-generated binary data by the Projucer" << preferredLinefeed
<< "// Source file: " << source.getRelativePathFrom (target.getParentDirectory()) << preferredLinefeed
<< preferredLinefeed;
cpp << header.toString();
if (target.hasFileExtension (headerFileExtensions))
{
header << "static constexpr unsigned char " << variableName << "[] =" << newLine
<< literal.toString() << newLine
<< newLine;
header << "static constexpr unsigned char " << variableName << "[] =" << preferredLinefeed
<< literal.toString() << preferredLinefeed
<< preferredLinefeed;
replaceFile (target, header.toString(), "Writing: ");
}
else if (target.hasFileExtension (cppFileExtensions))
{
header << "extern const char* " << variableName << ";" << newLine
<< "const unsigned int " << variableName << "Size = " << (int) dataSize << ";" << newLine
<< newLine;
header << "extern const char* " << variableName << ";" << preferredLinefeed
<< "const unsigned int " << variableName << "Size = " << (int) dataSize << ";" << preferredLinefeed
<< preferredLinefeed;
cpp << CodeHelpers::createIncludeStatement (target.withFileExtension (".h").getFileName()) << newLine
<< newLine
<< "static constexpr unsigned char " << variableName << "_local[] =" << newLine
<< literal.toString() << newLine
<< newLine
<< "const char* " << variableName << " = (const char*) " << variableName << "_local;" << newLine;
cpp << CodeHelpers::createIncludeStatement (target.withFileExtension (".h").getFileName()) << preferredLinefeed
<< preferredLinefeed
<< "static constexpr unsigned char " << variableName << "_local[] =" << preferredLinefeed
<< literal.toString() << preferredLinefeed
<< preferredLinefeed
<< "const char* " << variableName << " = (const char*) " << variableName << "_local;" << preferredLinefeed;
replaceFile (target, cpp.toString(), "Writing: ");
replaceFile (target.withFileExtension (".h"), header.toString(), "Writing: ");
@@ -836,6 +851,8 @@ namespace
<< std::endl
<< " " << appName << " --create-project-from-pip path/to/PIP path/to/output" << std::endl
<< " Generates a JUCE project from a PIP file." << std::endl
<< std::endl
<< "Note that for any of the file-rewriting commands, add the option \"--lf\" if you want it to use LF linefeeds instead of CRLF" << std::endl
<< std::endl;
}
}
@@ -847,6 +864,9 @@ int performCommandLine (const String& commandLine)
args.addTokens (commandLine, true);
args.trim();
if (findArgument (args, "--lf") || findArgument (args, "-lf"))
preferredLinefeed = "\n";
String command (args[0]);
try


+ 3
- 5
extras/Projucer/Source/Utility/Helpers/jucer_MiscUtilities.cpp View File

@@ -27,14 +27,12 @@
#include "../../Application/jucer_Headers.h"
//==============================================================================
const char* getLineEnding() { return "\r\n"; }
String joinLinesIntoSourceFile (StringArray& lines)
{
while (lines.size() > 10 && lines [lines.size() - 1].isEmpty())
lines.remove (lines.size() - 1);
return lines.joinIntoString (getLineEnding()) + getLineEnding();
return lines.joinIntoString (getPreferredLinefeed()) + getPreferredLinefeed();
}
String trimCommentCharsFromStartOfLine (const String& line)
@@ -48,7 +46,7 @@ String createAlphaNumericUID()
const char chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
Random r;
uid << chars [r.nextInt (52)]; // make sure the first character is always a letter
uid << chars[r.nextInt (52)]; // make sure the first character is always a letter
for (int i = 5; --i >= 0;)
{
@@ -66,7 +64,7 @@ String hexString8Digits (int value)
String createGUID (const String& seed)
{
const String hex (MD5 ((seed + "_guidsalt").toUTF8()).toHexString().toUpperCase());
auto hex = MD5 ((seed + "_guidsalt").toUTF8()).toHexString().toUpperCase();
return "{" + hex.substring (0, 8)
+ "-" + hex.substring (8, 12)


+ 1
- 1
extras/Projucer/Source/Utility/Helpers/jucer_MiscUtilities.h View File

@@ -28,7 +28,7 @@
//==============================================================================
const char* getLineEnding();
const char* getPreferredLinefeed();
String joinLinesIntoSourceFile (StringArray& lines);
String trimCommentCharsFromStartOfLine (const String& line);


Loading…
Cancel
Save