Commit Graph

100 Commits

Author SHA1 Message Date
Maximilian Goldstein a9038a6cc6 QQmlJSLogger: Switch to an ID based system
This change makes qmljslogger use an ID based system for categorizing
logging entries instead of using an enum. This allows plugins to
register their own logging categories after the fact.

It's also necessary for us to later show the warning ID when
printing warnings and for creating documentation for each ID entry.

Currently not every ID maps cleanly to only one type of warning,
this has to be cleaned up in a follow-up change.

Task-number: QTBUG-103453
Change-Id: I4cac6be7ca165b938e0ea032d077823bf17baf75
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-06-30 11:23:36 +02:00
Lucie Gérard 0dc4fd240a Use SPDX license identifiers
Replace the current license disclaimer in files by
a SPDX-License-Identifier.
Files that have to be modified by hand are modified.
License files are organized under LICENSES directory.

Pick-to: 6.4
Task-number: QTBUG-67283
Change-Id: I63563bbeb6f60f89d2c99660400dca7fab78a294
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2022-06-11 08:05:15 +02:00
Maximilian Goldstein dc6b39fb2e Turn qmlcompiler into a shared library
Converts qmlcompiler into a shared library so it isn't duplicated when
statically linked in tools and so that plugins can link against it.

Change-Id: I91e13cc588796f71a5463dbdce21e42a74120565
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-03-25 13:12:32 +01:00
Ulf Hermann 6ff2669b36 qmlcachegen: Re-enable pragma Strict checking
We've accidentally disabled the pragma Strict check when re-designing
the logging system.

Change-Id: I74cf0d4a45742831037ec0bc0615f1f6a15b7023
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
2022-02-18 12:13:47 +01:00
Andrei Golubev 690b7cb6a2 Redesign QQmlJSLogger internals
High-level goal: be able to reuse existing infrastructure
"as is" to configure semantic analysis categories in tools
(qmllint, qmltc, qmlsc, etc.)

To achieve that, simplify the logging to always "log"
something, without explicitly specifying the severity. The
severity is now baked into the category (and we can extend
those to cover different cases)

One slight deviation is the cache generation which likes
to do its own thing at present. Provide a "forced logging"
option where we can specify which severify we want. The
hope is that this gets removed at some point

Particular list of (noteworthy) changes:
* No more "thresholding" by the level (this is rarely needed
  and is actually questionable). Instead, we can ignore a
  particular category explicitly
* Category levels are repurposed as category severities
  (at least from the high-level picture that always should've
  been this way)
* log{Warning,Info,Critical} removed. We use category severity
  instead
* "category error" makes zero sense so removed: if our severity
  is:
  - QtWarningMsg (qmllint), it is already an "error"
  - QtCriticalMsg (compilers), it is already an "error"
* Align m_output and m_{infos,warnings,errors} stored information
* Accept the fact that we don't support QtDebugMsg and QtFatalMsg
* Additional categories added to cover for places where the same
  category would be both an error and not an error

Task-number: QTBUG-100052
Change-Id: I3cd5d17d58be204f48428877bed053f756ac40a8
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-02-12 23:21:29 +01:00
Maximilian Goldstein dc9de38abe qmllint: Warn about missing singleton pragmas/qmldir entries
This change adds a warning if we encounter a component marked as a
singleton in a qmldir file which does not contain a pragma
Singleton entry and vice versa.

Note that the warning only gets triggered if the singleton is
actually used.

Fixes: QTBUG-98558
Change-Id: Id7c63f48ba49759c15dffcaee0270c7caab2eb7d
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
2022-02-03 11:17:34 +01:00
Ulf Hermann 576fafd1e6 Pass qmldir to qmlcachegen, qmllint and qmltc, not the qmltypes file
The tools will still grudgingly accept qmltypes files being passed via
the -i option. We generally expect qmldir files, though. Ignoring the
qmldir file and importing the qmltypes directly, ignores qmldir imports,
dependencies and other component entries. This leads to unresolvable
types.

[ChangeLog][QML Tooling] qmllint expects qmldir files, not qmltypes
files to be passed via the -i option now. This enables it to see the
imports and dependencies of the module being imported. For backwards
compatibility it still accepts qmltypes files, with a warning.

Pick-to: 6.3
Fixes: QTBUG-99043
Change-Id: I5ed32d7e78df1e604aaf1bfa2ebda09d5d57b628
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-12-13 11:51:13 +00:00
Ulf Hermann 58ff7aa4fe Compile QML files ahead of time with qmlcachegen
qmlcachegen compiles bindings and functions to C++ as far as
QQmlJSAotCompiler can. It does respect "pragma Strict" and rejects the
file if it's violated. Furthermore, it sets up the logger to follow the
qt.qml.compiler.aot logging category. By default it's completely silent.

Compiling the examples with qmlcachegen exposes a bug in the type
resolver where it returns an invalid generic type. It should never do
that. Fix it by returning JSValue.

[ChangeLog][QtQml][Important Behavior Changes] QML bindings and
functions are now compiled to C++ by qmlcachegen, if possible. Use the
qt.qml.compiler.aot logging category to receive diagnostics about the
compilation.

Task-number: QTBUG-98305
Change-Id: I6953812c3fd20b68339617a5714fcbe16a384360
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-12-03 12:09:26 +01:00
Ulf Hermann 06b3f1f2e7 Replace qmlcachegen's --qmljs-runtime with generic mechanism
We don't need --qmljs-runtime after all. However, we do want to pass
custom arguments to qmlcachegen. This way we don't need to change the
world whenever we invent one.

Pick-to: 6.2
Change-Id: I99f0c99c4b15e469605dc43d26871fa43dc36c08
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-06-18 15:41:50 +02:00
Pavol Markovic 1bae74dfa0 qmlcachegen: Fix typo in command line option description
'resource-file-mapping option' is actually using '=' in code and tools

Change-Id: I0d67e13e9d614bf973a0d4332c6b4dcda4c121a4
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-06-12 22:06:07 +12:00
Ulf Hermann 5c4e3c44f7 qmlcachegen: Add an ignored option -I
In other implementations this may be used the same way as qmllint's -I
option, to specify additional import paths.

Change-Id: I447712551ff1fb2a7c379712e938f778b37c514a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-03-04 23:35:16 +01:00
Ulf Hermann 74bf3c8c33 Rework QQmlJSResourceFileMapper
We need more generic filtering capabilities so that it can, for example,
retrieve all the .qml files in a directory, both as qrc paths and local
file paths.

Change-Id: I72a72abc6dd39adb41bcd035f7aa6777e50cb5a5
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
2021-02-24 13:01:42 +01:00
Ulf Hermann 1e089ad28d qmlcachegen: Accept both --resource and --resource-path
--resource-path directly specifies the resource path for the file being
compiled and overrides any information we might retrieve from the qrc
file. However, we might still find other relevant information in the qrc
file.

Change-Id: I587c6e4e81f792f62a28b035ee97b33d12eeb06d
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-02-23 13:54:33 +01:00
Ulf Hermann 06ab8d790d Add a -i <qmltypes> option to qmlcachegen
qmlcachegen needs to see the qmltypes file for the current project so
that it can query it for C++ types exposed to QML.

This is only relevant when generating C++ code, which qmlcachegen itself
cannot do. However, in order to write a compatible drop-in, we need it.

Also, hide related ignored options from --help in qmlcachegen.

Change-Id: Id2f1b8b1750351c7de8dfe49e4065ef1b29423b7
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-01-12 20:58:25 +01:00
Ulf Hermann 9aba23c99e Allow passing --qmljs-runtime to the qmlcachegen implementation
This signals qmlcachegenplus to not paste the whole JavaScript type
system into each generated file. In turn, user projects need to add a
dependency in order to build against the JS runtime.

qmlcachegen ignores the option.

Change-Id: I0f87dedb969e99e94fbb712b7faa23d84f76dfbe
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2020-12-02 08:59:12 +01:00
Ulf Hermann 7a7edf14ec Allow passing --direct-calls to the qmlcachegen implementation
qmlcachegenplus has an argument --direct-calls which instructs it to
call methods of known C++ types directly rather than through the JS
engine or the metaobject. This is faster but requires that all those
types are visible to the generated code. Introduce a way to pass this
option on a per-target base.

Adjust qmlcachegen to ignore the option.

Change-Id: I474e577e4a197f6ca4c8b8e868dfd39983e77041
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-12-01 11:20:24 +01:00
Ulf Hermann 8528bd527f qmlcachegen: Move functions to compile QML/JS files to QmlCompiler
We need to re-use them. Also, provide a way to insert AOT compiled
functions into the C++ code.

Change-Id: I7b0d13cb307e8f979745f096a9614f087d135f68
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-10-23 13:31:26 +02:00
Ulf Hermann db13153905 qmlcachegen: Add empty AOT built functions to the loader
This enables us to use the same generateloader.cpp for qmlcachegen and
any replacement that actually produces AOT compiled functions.

Change-Id: I12fe81236e4ef16a627729c644d54b6c171b3860
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-10-23 13:31:19 +02:00
Ulf Hermann 2458f07eb5 Move generateloader.cpp to QmlCompiler
We need to be able to generate the loader code from multiple places.

Change-Id: I9e04fd3583b535bc5f7d5fb293cb61309c1e199a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-10-23 13:31:14 +02:00
Ulf Hermann 51f6d418fa qmlcachegen: Move resourcefilter.cpp into QmlCompiler
For backwards compatibility, a replacement for qmlcachegen will need to
provide the same functionality.

Change-Id: I22664230ea636d384190122223d15819ebee930c
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-10-20 17:19:26 +02:00
Ulf Hermann 4f44f82b9f QmlCompiler: Rename ResourceFileMapper
The file class names should start with a common prefix.

Change-Id: I5e014c103668a1bc73d359b00a1dda33e5637a79
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-10-05 14:58:52 +02:00
Ulf Hermann 767dd738d3 Long live libQtQmlCompiler!
Move all the code from tools/shared into src/qmlcompiler and build a
static library from it so that we can re-use it in external tools.

Change-Id: I7c8d8e59063dc7c711f4072f103a01095e6f5997
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-10-05 14:58:32 +02:00
Alexandru Croitor 26c5243491 Merge remote-tracking branch 'origin/dev' into wip/cmake
Conflicts:
	dependencies.yaml
	src/qml/qml/qqmlengine.cpp

Change-Id: I6a73fd1064286f4a2232de85c2ce7f80452d4641
2020-03-12 15:03:03 +01:00
Simon Hausmann 8ab237edf1 Restore offset/length in QQmlJS::DiagnosticMessage
This is needed in a few places outside of declarative, so this change
restores the loc member in DiagnosticMessage and moves
QQmlJS::AST::SourceLocation into common's QQmlJS namespace/directory.
QQmlError is unaffected and retains only line/column.

Amends d4d197d062

Change-Id: Ifb9d344228e3c6e9e26fc4fe112686f9336ea2b2
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-03-02 10:35:50 +01:00
Ulf Hermann cc759804aa Avoid deprecated non-q-prefixed hex() function
Use Qt::hex() instead.

Change-Id: I46bc2f2006ce860cd938a86432783011365c8164
Reviewed-by: Liang Qi <liang.qi@qt.io>
2019-12-17 09:47:15 +01:00
Alexandru Croitor c2f8b9535d Merge remote-tracking branch 'origin/dev' into wip/cmake
Removed dependencies.yaml because we don't use it yet in wip/cmake.
Fixed conflict in qmlcachegen.cpp.

Change-Id: Ie1060c737bee1daa85779903598e5b6d5020d922
2019-10-14 19:02:37 +02:00
Alexandru Croitor 6a0bb9a7d6 Merge remote-tracking branch 'origin/wip/qt6' into wip/cmake
Change-Id: I4a91928610f79c8e21a05781953ffa41508c828a
2019-10-11 16:21:42 +02:00
Qt Forward Merge Bot a510c9c9f4 Merge remote-tracking branch 'origin/5.15' into dev
Change-Id: I801567c11fcc3244a1ee7dabeb5079d49fc5c3a1
2019-09-22 22:29:02 +02:00
Simon Hausmann d5f3e7a7e3 Fix regression when using CONFIG+=QtQuickCompiler and .qrc files in subdirs
Commit 41864db3b6 removed the processing
of .qrc files that removed .qml/etc. files. Since the chaining of
resources remains critical to ensure that the cached compilation units
are loaded, the build system copied the input .qrc file to a new one.
That mere copying caused the build to break when the copied .qrc file
was not in the same directory as the original one, as file paths within
the .qrc file are interpreted as relative to the .qrc file, which was
now in a different location. To fix this, this patch brings back the
"filtering" code that rewrites the paths to the source files in the .qrc
file.

Fixes: QTBUG-78253
Change-Id: Ie1d56f3248e713a964260bc2da37c9374f7b6a36
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2019-09-19 11:32:23 +02:00
Simon Hausmann 83be211744 Merge remote-tracking branch 'origin/wip/qt6' into dev
Change-Id: I10c4b7fcfa0397d999d45e310c2f8f051d57d4d2
2019-09-19 08:53:00 +02:00
Simon Hausmann 41864db3b6 Fix *.js files disappearing from RESOURCES when not using QtQml
[ChangeLog][QtQml][Important Behavior Changes] Using the Qt Quick
Compiler would exclude the original .qml files from the resource system.
This made it impossible to change the Qt library binary later as the
program binary was tied the to the exact Qt version. In addition
sometimes unrelated files (QTBUG-73669) were removed. For the latter
scenario, retain and skip options were added for the Qt Quick Compiler.
In Qt 5.15 the Qt Quick Compiler does not remove the input files
anymore. All files are retained and the compiler merely adds the more
efficient binary representation to the application.

Task-number: QTBUG-73669
Change-Id: I5a523bfc69d4f48a1451bd880616c82fd73b8d15
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2019-09-09 07:52:25 +02:00
Ulf Hermann 2746518c76 Merge remote-tracking branch 'origin/dev' into wip/qt6
Conflicts:
	.qmake.conf
	src/qml/qml/qqmlengine.cpp
	src/qmlmodels/qqmlmodelsmodule.cpp

Change-Id: Id60420f8250a9c97fcfe56d4eea19b62c6870404
2019-09-05 11:08:59 +02:00
Tasuku Suzuki 6b106d4463 Fix build without features.temporaryfile
Change-Id: If990efb64a4117bc7624062fededa7ce6a910f14
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2019-08-19 22:06:26 +09:00
Leander Beernaert 494dc05ea1 Extend qmlcachge to support --retain with CMake
Add missing code so we can use the --retain argument when running
qmlcachgen from a CMake project.

Change-Id: I0b4a2f2ea6c424ba698ee178a332f585271b945e
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2019-08-13 07:52:51 +00:00
Leander Beernaert 059d792264 Add support for generating qmlcache_loader without qrc
Added support for response file expansion to qmlcachegen.

Add the option --standalone-namespace to qmlcachegen so we can
generate qmlcache_loader from a collection of resource paths
instead of operating on qrc files. This is necessary, since the
namespace identifier is extraced from the qrc file name, which
we no longer have.

This pach was made in order to tend to the cmake port's version of
qtquickcompiler support which does not rely on qrc files.

Change-Id: If15190f3492e6695f5a6e61bf8816998760541f7
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-07-31 12:33:44 +00:00
Simon Hausmann 880a143eb5 Merge remote-tracking branch 'origin/dev' into wip/qt6
Change-Id: I4476733af61fcf3a2af1d121a4585c3fae1c240e
2019-07-12 20:36:48 +02:00
Ulf Hermann f5e4f07841 Disentangle includes and namespaces
Avoid using namespace in headers and include only the headers we
actually need.

Change-Id: I526a0f874dc09b07693fd87070665be396d3b637
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-07-11 11:14:54 +02:00
Ulf Hermann 9a8dd594b5 Merge JSCodeGen and QQmlJSCodeGenerator
Change-Id: I2219cba0dd3782cb2e0b09b8f3c4d5472e6e5d7e
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-07-10 18:22:40 +02:00
Alexandru Croitor 9c5af084a9 Merge remote-tracking branch 'origin/dev' into wip/qt6
Change-Id: Ifc24fbd99ee216e528a213fdbfd2892b3df419fe
2019-07-08 11:36:14 +02:00
Alexandru Croitor 1c5c5f7aad Fix Qt6 build in preparation of qt5 submodule update
Fixes the QTextStream usages.

Change-Id: I0c009a82fb644a9f3c3d42ec410d18b680977f23
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-07-08 05:56:02 +02:00
Ulf Hermann 40ded579bd Simplify codegen error handling
There can only ever be one error, either a syntax error or a reference
error. We record the error type as we want to get rid of the virtual
throw<X>Error methods in favor of an explicit compilation result.

Change-Id: Ie228490aad8efb7885083f6485f931299567f54c
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-07-04 16:03:36 +02:00
Ulf Hermann e72637deed Move saveToDisk into SaveableUnitPointer
This way we can keep the flag mutilation closely local to the place
where we write the data. Also, SaveableUnitPointer doesn't need a full
CompilationUnit this way.

Change-Id: I01872e4c406cb2ccbaa1fa35325cc063b1e8a7df
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-06-24 11:13:05 +02:00
Ulf Hermann d4d197d062 Simplify errors and diagnostics
We only need two classes to describe all possible diagnostics:

* A low-level private POD DiagnosticMessage. This is easily copied and
  passed around internally. It doesn't need to adhere to a stable API
  and it doesn't carry any extra baggage.

* The high-level public QQmlError with its stable interface. This can
  internally also use a DiagnosticMessage as storage.

Change-Id: I52be88d9b5d9855a661b8032b01eedb43a0fb0b3
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-06-14 19:08:51 +02:00
Ulf Hermann ae1c2375f5 Add abstraction for temporarily setting StaticData when saving
The StaticData flag needs to be saved to disk, but removed again
afterwards so that we can free() the malloc'd data. This also allows us
to avoid copying all the data into a byte array before saving.

Change-Id: I96513f8d98acf0ea0b4514d96376b487e8444917
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-05-17 10:34:31 +00:00
Ulf Hermann 7f7d87c68d Split CompiledData::CompilationUnit in two
We need a CompilationUnit that only holds the data needed for
compilation and another one that is executable by the runtime.

Change-Id: I704d859ba028576a18460f5e3a59f210f64535d3
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-05-16 12:09:23 +00:00
Ulf Hermann a8b3536d6e Move compileModule() into qv4codegen.cpp
This is a better fit for the method. In turn, remove all the
V4_BOOTSTRAP conditions from qv4engine_p.h and make sure we don't
include or compile it in bootstrap mode.

Change-Id: I5933b0724e561313ca20c420b83e4d70e63bddf5
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-05-08 12:05:30 +00:00
Qt Forward Merge Bot 187b2e0efc Merge remote-tracking branch 'origin/5.12' into 5.13
Change-Id: I2f0b4f8543a448c9acffe0932e0fd67c0b7412f4
2019-03-27 10:27:56 +01:00
Simon Hausmann 516523750d Enable lookups for imported scripts and worker scripts
This is straight-forward to enable, with the minor adjustment that we
need to handle the case where a global lookup is done without a calling
qml context (worker script). We don't know at compile time whether a
script will be imported directly or used as a worker script, so we have
to generate the global qml lookup instruction regardless and handle it
at run-time.

Change-Id: Ia033afa214d919d906c676498dd3eceb1c5639d8
Reviewed-by: Michael Brasser <michael.brasser@live.com>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2019-03-25 10:26:11 +00:00
Qt Forward Merge Bot a1e38651ce Merge remote-tracking branch 'origin/5.12' into 5.13
Conflicts:
	.qmake.conf
	src/qmltest/quicktest.cpp
	tests/auto/qml/qmlcachegen/qmlcachegen.pro

Change-Id: I70e96e8817d59647f876b8b77b30cdeede8f0662
2019-03-25 10:13:23 +01:00
Simon Hausmann 78888f485f Enable lookups in QML files when compiling ahead of time
This should have been enabled in the series earlier when for
QTBUG-69898.

Change-Id: Ide7507d5dcf439463c22b631d49d654624737d1f
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-03-22 12:42:37 +00:00