Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
depfile_shared.h
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4#ifndef QTBASE_DEPFILE_SHARED_H
5#define QTBASE_DEPFILE_SHARED_H
6
7#include <QByteArray>
8#include <QString>
9#include <QFile>
10
11// Escape characters in given path. Dependency paths are Make-style, not NMake/Jom style.
12// The paths can also be consumed by Ninja.
13// "$" replaced by "$$"
14// "#" replaced by "\#"
15// " " replaced by "\ "
16// "\#" replaced by "\\#"
17// "\ " replaced by "\\\ "
18//
19// The escape rules are according to what clang / llvm escapes when generating a Make-style
20// dependency file.
21// Is a template function, because input param can be either a QString or a QByteArray.
22template <typename T> struct CharType;
23template <> struct CharType<QString> { using type = QLatin1Char; };
24template <> struct CharType<QByteArray> { using type = char; };
25template <typename StringType>
26StringType escapeDependencyPath(const StringType &path)
27{
28 using CT = typename CharType<StringType>::type;
29 StringType escapedPath;
30 int size = path.size();
31 escapedPath.reserve(size);
32 for (int i = 0; i < size; ++i) {
33 if (path[i] == CT('$')) {
34 escapedPath.append(CT('$'));
35 } else if (path[i] == CT('#')) {
36 escapedPath.append(CT('\\'));
37 } else if (path[i] == CT(' ')) {
38 escapedPath.append(CT('\\'));
39 int backwards_it = i - 1;
40 while (backwards_it > 0 && path[backwards_it] == CT('\\')) {
41 escapedPath.append(CT('\\'));
42 --backwards_it;
43 }
44 }
45 escapedPath.append(path[i]);
46 }
47 return escapedPath;
48}
49
54
55#endif // QTBASE_DEPFILE_SHARED_H
\inmodule QtCore
Definition qbytearray.h:57
static QByteArray encodeName(const QString &fileName)
Converts fileName to an 8-bit encoding that you can use in native APIs.
Definition qfile.h:158
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
StringType escapeDependencyPath(const StringType &path)
static QByteArray escapeAndEncodeDependencyPath(const QString &path)
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLsizei const GLchar *const * path
\inmodule QtCore \reentrant
Definition qchar.h:18