diff options
author | Fawzi Mohamed <fawzi.mohamed@qt.io> | 2021-02-03 09:06:09 +0100 |
---|---|---|
committer | Fawzi Mohamed <fawzi.mohamed@qt.io> | 2021-02-15 18:22:27 +0100 |
commit | 6d51f997df14f2b22c265c5b2fda679ece9edef3 (patch) | |
tree | 551889cb0b96998d87c234c6cce657242c4ce954 /tools/qml | |
parent | a8685fdb4d57c0ba36d80c395c2ae878595f04da (diff) |
Uniformly support shebang
The "qml" tool was the only way of loading QML files that would respect
a shebang line. This is problematic as this way you cannot load such
files programatically using QQmlComponent, limiting their re-use. Common
tools like Qt Creator, but also qmllint, qmlformat, qmlcachegen, etc
would not recognize files with shebangs.
By moving she-bang support directly in the lexer all tools implicitly
support it.
Note that we could just as easily support '#' as extra comment
character along with //, but here we narrowly add support for in
the first line only, as node does (this means that javascript files
using she-bang accepted by node, are now accepted also by qml).
The only tool needing some adjustments is qmlformat, that has to emit
the she-bang again as she-bang and as first line.
Add tests for qmlformat, and sprinkle some she-bangs in the other
tests just to be sure it doesn't affect anything.
Change-Id: I1f6d881c7438bdb23163b5dbe829d59a35d11132
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tools/qml')
-rw-r--r-- | tools/qml/main.cpp | 20 |
1 files changed, 1 insertions, 19 deletions
diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp index 7e42402dd0..8e5a493bcd 100644 --- a/tools/qml/main.cpp +++ b/tools/qml/main.cpp @@ -338,19 +338,6 @@ static void getAppFlags(int argc, char **argv) #endif // QT_GUI_LIB } -bool getFileSansBangLine(const QString &path, QByteArray &output) -{ - QFile f(path); - if (!f.open(QFile::ReadOnly | QFile::Text)) - return false; - output = f.readAll(); - if (output.startsWith("#!")) {//Remove first line in this case (except \n, to avoid disturbing line count) - output.remove(0, output.indexOf('\n')); - return true; - } - return false; -} - static void loadDummyDataFiles(QQmlEngine &engine, const QString& directory) { QDir dir(directory+"/dummydata", "*.qml"); @@ -603,12 +590,7 @@ int main(int argc, char *argv[]) QUrl url = QUrl::fromUserInput(path, QDir::currentPath(), QUrl::AssumeLocalFile); if (verboseMode) printf("qml: loading %s\n", qPrintable(url.toString())); - QByteArray strippedFile; - if (getFileSansBangLine(path, strippedFile)) - // QQmlComponent won't resolve it for us: it doesn't know it's a valid file if we loadData - e.loadData(strippedFile, e.baseUrl().resolved(url)); - else // Errors or no bang line - e.load(url); + e.load(url); } if (lw->earlyExit) |