Commit Graph

151 Commits

Author SHA1 Message Date
Jarek Kobus
2aa533c7dd Support ProcessChannelMode in ProcessLauncherImpl
Change-Id: Ifb919f19aac8ad223e6beb93c4c14fa4fdb204e9
Reviewed-by: hjk <hjk@qt.io>
2021-07-12 12:37:23 +00:00
Jarek Kobus
3335a78d5f Send started() signal from ProcessLauncherImpl
Change-Id: Ie9f3b3afe5c74407534fb3f605160cb41336c944
Reviewed-by: hjk <hjk@qt.io>
2021-07-12 12:31:18 +00:00
Jarek Kobus
94a2aefc19 Implement ProcessLauncherImpl::setErrorString()
Change-Id: Idd1f0573d5e7db1b45024ed0c5bd7d0831217f25
Reviewed-by: hjk <hjk@qt.io>
2021-07-12 12:30:54 +00:00
Jarek Kobus
327645c0f0 Remove unused readChannel()
By default QProcess::readChannel() returns StandardOutput,
and since no one modifies it, it will always be the same.
No need for an assert.

Change-Id: Id55f75e5cce4f1b8eaef2ec3094d7b103c2f0238
Reviewed-by: hjk <hjk@qt.io>
2021-07-09 15:41:39 +00:00
Jarek Kobus
1a98fe33db Implement ProcessLauncherImpl::program() getter
It returns the command stored when starting the process.

Change-Id: If90a3a54f80bc020e043045378caf2ffb603b746
Reviewed-by: hjk <hjk@qt.io>
2021-07-09 15:31:39 +00:00
Jarek Kobus
f341107c9f Mark ProcessLauncherImpl canceled when killing it
Mark ProcessLauncherImpl canceled when the kill
request has been sent to the process launcher.
If ProcessLauncherImpl is canceled, ignore the
finished reply sent from process launcher.
Recheck the state inside stopProcess() method
after calling terminate() - in this way in case of
ProcessLauncherImpl we avoid calling unimplemented
waitForFinished().

Change-Id: Ibad148f6c7e63ef619e53eb41bbeeb7693be3d25
Reviewed-by: hjk <hjk@qt.io>
2021-07-09 15:30:50 +00:00
Jarek Kobus
3402411751 Remove unused stateChanged() signal
Change-Id: Ieb8e01ed1c88f981595391698fed6dcff7c8e932
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2021-07-09 15:05:23 +00:00
Jarek Kobus
971abe115b Provide initial implementation for ProcessLauncherImpl
The initial implementation is a copy of QbsProcess
with some small adaptations. Start a LauncherProcess
in Creator's main function, just after the creation of
the application object.

Change-Id: I016df3ed664d7914c73f4a35742d5a63d5faaca0
Reviewed-by: hjk <hjk@qt.io>
2021-07-09 11:17:31 +00:00
Jarek Kobus
bbe44bf42a Abstract QProcess interface
Abstract part of QProcess interface into ProcessInterface
pure virtual class. The current API of ProcessInterface
is a part of QProcess API used currently to implement
QtcProcess. Provide 2 implementations for it: QProcessImpl
which uses QProcess and ProcessLauncherImpl which is currently
empty implementation with assertions that no method is being
called. Provide an additional switch to QtcProcess c'tor
for selecting the preferred implementation, by default it
selects QProcessImpl. This change doesn't influence any behavior.

Change-Id: Ia5328401affe127f3d36870be8478202d4143480
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: hjk <hjk@qt.io>
2021-07-09 09:39:17 +00:00
hjk
943447aed3 Utils: Count processes when qtc.utils.qtcprocess is enabled
Change-Id: I69748c751fe41bdddd73a9ad396e722ebccb7a54
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-07-02 11:07:50 +00:00
hjk
13ad1351b0 Utils: Add QtcProcess::setStandardInputFile
Needed for SshProcess.

Change-Id: Id3c8ca0cc86d7a515371fb3651e2d186cbea4df6
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2021-06-29 10:08:35 +00:00
hjk
430e81facd All: Replace most SynchronousProcess by QtcProcess
Change-Id: I0bf22fef2cd4a7297ef5a1e9aa9c3e2b9348ba42
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-06-23 07:55:31 +00:00
hjk
953ea730b8 Utils: Merge QtcProcess and SynchronousProcess
Keep SynchronousProcess as type alias for a transition period.

Change-Id: I2540b6cecc17eb46f40ed57d27589011693728f1
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-06-23 06:31:57 +00:00
hjk
32895873e4 Utils: Move remaining SynchrounousProcess functionality
To QtcProcess, as penultimate step to fully merge the two.

Change-Id: Iaab3bc3e50165f732838335bd185632f33a97900
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-06-22 13:12:04 +00:00
hjk
76cf6ce983 Utils: Add a QtcProcess flag to keep stdin open
Needed to run e.g. gdb on-device.

Change-Id: I5a98df575478f18adf1540ced44f6808bdba0b76
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-06-22 07:48:36 +00:00
hjk
ada39349a2 Utils: Merge QtcProcess line reading functions
- Pass everything through the codec.
- Always emit even incomplete last lines when the process finishes.
- Don't store raw output when line-wise processing is requested.

Change-Id: I5cc30ad0d7ab79387bfb00b48ff957468a1bd004
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-06-21 10:59:40 +00:00
hjk
8824b4e3a4 Utils: Pass stderr output through the right channel
Copy-and-pasto...

Change-Id: I6521b5557ff515ccb22cb1611f92079d9ec6042f
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2021-06-18 14:23:22 +00:00
hjk
fe7d6f0def Utils: Drop QProcess specific parameters from QtcProcess::finished()
Mid-term plan is to concentrate on use of QtcProcess::result()
instead which is a bit more system-agnostic.

There's quite a bit of potential for downstream cleanup by
re-using QtcProcess::exitMessage() now.

Change-Id: I3806b3f5933d96e64b7cfb18cc6c52823fddcbcd
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-06-14 13:31:05 +00:00
hjk
fed5a44be1 QtcProcess: Remove unused QtcProcess::rawStdErr()
Change-Id: Ie52a05ba7738e6150bdf2da0b1412c081e53bdbf
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-06-09 12:23:30 +00:00
Alessandro Portale
27f8e2dbce Utils: Fix splitting in ChannelBuffer::takeFirstLine()
Escape the '\r'

Change-Id: I8cee40dc4a65f893f1a11c7cf066777498c37339
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-06-09 06:40:11 +00:00
David Schulz
bf79f1ae38 Utils: fix QtcProcess timeout error message
Change-Id: Iccfe7cfe61937872589a708f79dec69afefb9be4
Reviewed-by: hjk <hjk@qt.io>
2021-06-08 07:36:13 +00:00
hjk
1ce7adce47 Utils: Set the working directory in QtcProcess::start
The m_process member is strictly speaking only needed for processes
handled "fully locally", i.e. without diversion through any device.

Better set it only when needed, even if only to avoid even unused
locally illegal paths like "docker://123/tmp/x" as working directory.

Change-Id: Ia9e686855ff0c213eb3be03def8c4cecc7ee37ae
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-06-08 07:32:02 +00:00
Orgad Shaneh
3c8a991a9b QtcProcess: Really set working directory for process
Git operations were broken.

Amends commit accb1e6e08.

Change-Id: I0ffe41d3d5b80990eed29f7609daaf23201e49af
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: hjk <hjk@qt.io>
2021-06-07 07:20:12 +00:00
Eike Ziller
66948d9a63 Fix build on macOS
Complains about template argument (QString) and type of value
(const QString) not being the same.
make_optional is usually used with template parameter deduction anyhow,
but in this case we can just return the value.

Change-Id: Icc5c6bb4505d09ab6a864fb7a7c6ec97e34b42b7
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-06-04 13:49:08 +00:00
Christian Stenger
133b3b58a7 Utils: Provide line based callback handling
Change-Id: Ibb1df93b457d299c377472ff6c0fbd719554d7d8
Reviewed-by: hjk <hjk@qt.io>
2021-06-04 12:28:36 +00:00
hjk
0bb0c5bd88 Utils: Combine QtcProcess internal code paths for "finished"
Change-Id: I884ab33a614fe00087c83fe6daf41c023711dd7f
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2021-06-04 08:44:08 +00:00
hjk
27a3bf3ae6 Qnx: Avoid use of QtcProcess::ioDevice()
And drop the function from the QtcProcess interface, as this was the
only user.

Change-Id: I5a21cdaacb3f91f78058e80cbe1cb1572e9bf331
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
2021-06-03 17:11:32 +00:00
Christian Stenger
4f0759d7ea Utils: Remove couple of functions from QtcProcess
Some functions do not work and should therefore not be used.
Line-based processing of the output interferes with the internal
automatic usage of the ChannelBuffers.
Remove the respective functions and move the line parsing over
to the client.

Change-Id: Iaaa58c181e35e132fae863ddb808547142c99221
Reviewed-by: hjk <hjk@qt.io>
2021-06-03 13:40:03 +00:00
Christian Stenger
2192415483 CppCheck: Fix getting output from QtcProcess
Change-Id: Ic11d1f31afe7412ec606bdbd751deb4088d5cd3f
Reviewed-by: hjk <hjk@qt.io>
2021-06-03 13:38:44 +00:00
hjk
accb1e6e08 Utils: Make QtcProcess::{setW,w}orkingDirectory use FilePath
But keep the old setter for a while to ease transition.

Change-Id: If02b79b1fcd31fbf8b06ef26876c41af891127f9
Reviewed-by: hjk <hjk@qt.io>
2021-06-03 10:31:13 +00:00
Christian Stenger
366936e331 Utils: Fix Qt6 build
Amends 08040e4e94.

Change-Id: I8e34dc73b7449b20c7c8ea140010a4bd3b31daff
Reviewed-by: hjk <hjk@qt.io>
2021-06-03 06:36:58 +00:00
hjk
0ba4338467 Utils: Rename QtcProcess::Result::Finished to FinishedWithSuccess
To make clear that this is not just any finish.

Also change FinishedError to FinishedWithError, to create
symmetry.

Also adapt enum member description to reality.

Change-Id: I13e05391eb86fdb24e2ae660f14dfddb282e1104
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2021-06-02 14:16:36 +00:00
hjk
08040e4e94 Utils: Move QProcess base to QtcProcessPrivate
Change-Id: I4c6811d42e051fadfcf32edb664ff3bc09e692e6
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-06-02 13:21:08 +00:00
hjk
57281f10a3 Utils: Add a convenience QtcProcess::start overload
Having QtcProcess::start(const QString &cmd, const QStringList &args = {})
makes porting easier.

Change-Id: I9a028b1ad99d393d14fd9c88488c179a2daa90dd
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-06-01 06:47:57 +00:00
hjk
6de05306d6 Utils: Use a structure to specify several QtcProcess device hooks
... and add a QtcProcess::systemEnvironmentForBinary(filePath)
redirecting to IDevice::systemEnvironment() of the device implicitly
given by filePath. A device implied by e.g. a qmake binary or a compiler
binary is a common scenario.

Change-Id: Ieb2c724ae66f1a1752132e4e4648a604390ca369
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2021-05-27 09:33:18 +00:00
hjk
770d87709e Utils: Join SynchronousProcess::run and runBlocking implementations
Make functionality dependent on an (intentionally ugly)
setProcessUserEventWhileRunning call.

Also, back-paddle a bit on API combination of QtcProcess and
SynchronousPrceoss for now and prevent the QtcProcess-and-
runBlocking and SynchronousProcess-and-start combinations.

Goal is still to have all in QtcProcess in the end, but this
may take a while.

Change-Id: Ic146ec5db0ab8dc9613e5b2af5f4dc90bc7465ca
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-05-25 06:40:01 +00:00
hjk
2be8061930 Utils: Fix QtcProcess::exitCode for non-SynchronousProcess
Change-Id: I18706e55db3fd31a69161be69e1cbec1a4fca975
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
2021-05-21 15:06:53 +00:00
Cristian Adam
de9be2bb9d Only define CALLBACK when PCH is used
The PCH header is undefining CALLBACK after loading Windows headers,
but we need to add it back when using Windows headers that need it.

The new definition needs only to be done when the PCH is used,
otherwise it could lead to re-definition warnings.

Amends 7880950eca

Change-Id: Iae57ac4bbbfdd45b5f9b50a2242103bec6eea5bc
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
2021-05-19 14:51:59 +00:00
hjk
90ad902486 Utils: Remove CommandLine argument from QtcProcess::run{,Blocking}
Makes run() more similar to what start() looks like.

Also add some asserts to make sure run() and related functions are
only called on SyncronousProcesses, as these are currently the only
ones where this works.

Change-Id: Idee6076c3f40a484db5c17f5bb348698cc83d220
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-05-19 13:01:51 +00:00
hjk
6830328ecf Utils: Drop SynchronousProcessResponse
Move the remnaining two members into QtcProcessPrivate, its
only user.

Change-Id: I8e0c23e1a56b36b750b5b4bd4e88d762260e42a1
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-05-17 11:49:11 +00:00
hjk
31dc479fa5 Utils: Avoid extra output copy for SynchronousProcess
The data was present in the ChannelBuffer

Change-Id: Ica645ba58bb2e86d0ef4cf5387f0a228f132e07d
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-05-17 11:24:15 +00:00
hjk
49864a8155 Utils: Remove ChannelBuffer's QObject base
Not used anymore.

Change-Id: If149abbced43b0b476715073cafa5ad4fe918c24
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2021-05-17 10:35:57 +00:00
hjk
79e02202d3 Utils: Use a setter for QtcProcess::run(.... writeData)
Change-Id: Ic56f8ecc158374251f89bb62c4b3d62168ae8409
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-05-17 09:42:00 +00:00
hjk
b2dc771d80 Utils: Simplify QtcProcess::exitMessage() interface
This was requiring parameters the process object already knows.

This is a slight behavior change in most cases, it now includes
always the command line arguments, which previously only happened
in gcctoolchain.cpp and iarewtoolchain.cpp.

Change-Id: Id25a68c397e2f1d8bf52ab29210e215b1de46c6d
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2021-05-17 08:59:48 +00:00
hjk
55f768e1b0 Utils: Make process results accessible through QtcProcess object
The result is fully stored in the object anyway. Using the extra
SynchronousProcessResponse structure only causes copies of
the data and complicates access on the user side in
a lot of cases.

The result bits are now also accessible individually.

There's obvious room for follow-up changes on the topic, e.g.
ShellCommand::runCommand's parameter list could shrink to
just a SynchronousProcess parameter.

Change-Id: I45aa7eb23832340be06905929280c012e1217263
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2021-05-14 13:19:01 +00:00
hjk
edf6178896 Utils: Simplify QtcProcess::run{,Blocking} for remote processes
No need to wrap another QtcProcess.

Change-Id: I27e8bf454605f70e99d9c37de09e0332337eb739
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-05-12 12:25:21 +00:00
Eike Ziller
1ea3d707c6 Fix build with Qt 6
Amends e9abd60732

Change-Id: Ifae84785683343467672b52f29d560aae9757bfd
Reviewed-by: hjk <hjk@qt.io>
2021-05-11 14:13:25 +00:00
Eike Ziller
f18ac508e8 Move CommandLine out of fileutils.h
to ProcessArgs and rename the files to commandline.*.
fileutils was a strange place for CommandLine, and this
reduces the dependencies needed for sdktool.

Change-Id: I9d7e8ffe8a3560f5d12934457b086f9446976883
Reviewed-by: hjk <hjk@qt.io>
2021-05-11 13:27:23 +00:00
hjk
0c8d8c6b2a Utils: Don't expose Utils::defaultExitCodeInterpreter
Instead, make its behavior implicit if none is given.

Change-Id: I3c1a054751a0afe22d0f40a2fed6dd00b5aef205
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-05-11 13:15:25 +00:00
hjk
ad5b34ab3e Utils: Remove QtcProcess::{is,set}Synchronous
This reverts a bit of fe8fbf1a4a which was over-shooting API-wise.

Change-Id: Iac4c2b9fa550f7ec0b0aa8deea8c3fc6b6ddcfba
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-05-11 12:49:08 +00:00