Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
qt-creator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tobias Hunger
qt-creator
Commits
45fbbba2
Commit
45fbbba2
authored
16 years ago
by
Roberto Raggi
Browse files
Options
Downloads
Patches
Plain Diff
Improved a little bit the example and show how to compute the deps for all the files in QtCore.
parent
483449e4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/manual/preprocessor/main.cpp
+59
-19
59 additions, 19 deletions
tests/manual/preprocessor/main.cpp
with
59 additions
and
19 deletions
tests/manual/preprocessor/main.cpp
+
59
−
19
View file @
45fbbba2
...
...
@@ -17,12 +17,16 @@ class MakeDepend: public Client
{
Environment
*
env
;
QList
<
QDir
>
systemDirs
;
QStringList
included
;
public:
MakeDepend
(
Environment
*
env
)
:
env
(
env
)
{
}
QStringList
includedFiles
()
const
{
return
included
;
}
void
addSystemDir
(
const
QDir
&
dir
)
{
systemDirs
.
append
(
dir
);
}
...
...
@@ -32,17 +36,22 @@ public:
virtual
void
macroAdded
(
const
Macro
&
)
{
}
virtual
void
sourceNeeded
(
QString
&
fileName
,
IncludeType
mode
,
unsigned
)
void
addInclude
(
const
QString
&
absoluteFilePath
)
{
included
.
append
(
absoluteFilePath
);
}
virtual
void
sourceNeeded
(
QString
&
fileName
,
IncludeType
mode
,
unsigned
line
)
{
// ### cache
const
QString
currentFile
=
QFile
::
decodeName
(
env
->
currentFile
);
if
(
mode
==
IncludeLocal
)
{
// ### cache
const
QFileInfo
currentFile
(
QFile
::
decodeName
(
env
->
currentFile
));
const
QDir
dir
=
currentFile
.
dir
();
const
QFileInfo
currentFileInfo
(
currentFile
);
const
QDir
dir
=
currentFileInfo
.
dir
();
// ### cleanup
QFileInfo
fileInfo
(
dir
,
fileName
);
if
(
fileInfo
.
exists
())
{
fileName
=
fileInfo
.
absoluteFilePath
();
std
::
cout
<<
' '
<<
qPrintable
(
fileName
);
addInclude
(
fileInfo
.
absoluteFilePath
());
return
;
}
}
...
...
@@ -50,13 +59,15 @@ public:
foreach
(
const
QDir
&
dir
,
systemDirs
)
{
QFileInfo
fileInfo
(
dir
,
fileName
);
if
(
fileInfo
.
exists
()
&&
fileInfo
.
isFile
())
{
fileName
=
fileInfo
.
absoluteFilePath
();
std
::
cout
<<
' '
<<
qPrintable
(
fileName
);
addInclude
(
fileInfo
.
absoluteFilePath
());
return
;
}
}
std
::
cerr
<<
"file '"
<<
qPrintable
(
fileName
)
<<
"' not found"
<<
std
::
endl
;
#ifdef PP_WITH_DIAGNOSTICS
std
::
cerr
<<
qPrintable
(
currentFile
)
<<
':'
<<
line
<<
": error: "
<<
qPrintable
(
fileName
)
<<
": No such file or directory"
<<
std
::
endl
;
#endif
}
virtual
void
startExpandingMacro
(
unsigned
,
const
Macro
&
,
...
...
@@ -76,22 +87,51 @@ public:
int
main
(
int
argc
,
char
*
argv
[])
{
Environment
env
;
MakeDepend
client
(
&
env
);
QCoreApplication
app
(
argc
,
argv
);
QStringList
todo
=
app
.
arguments
();
todo
.
removeFirst
();
if
(
todo
.
isEmpty
())
todo
.
append
(
qgetenv
(
"QTDIR"
)
+
"/include/QtCore/QtCore"
);
QMap
<
QString
,
QStringList
>
processed
;
while
(
!
todo
.
isEmpty
())
{
const
QString
fn
=
todo
.
takeFirst
();
if
(
processed
.
contains
(
fn
))
continue
;
client
.
addSystemDir
(
QLatin1String
(
"/usr/include"
));
Preprocessor
preproc
(
&
client
,
&
env
);
QStringList
deps
;
for
(
int
i
=
1
;
i
<
argc
;
++
i
)
{
const
QByteArray
fileName
=
argv
[
i
];
std
::
cout
<<
fileName
.
constData
()
<<
':'
;
QFile
file
(
QFile
::
decodeName
(
fileName
));
QFile
file
(
fn
);
if
(
file
.
open
(
QFile
::
ReadOnly
))
{
// ### we should QTextStream here.
const
QByteArray
code
=
file
.
readAll
();
preproc
.
preprocess
(
fileName
,
code
,
/*result = */
0
);
Environment
env
;
MakeDepend
client
(
&
env
);
client
.
addSystemDir
(
qgetenv
(
"QTDIR"
)
+
"/include"
);
Preprocessor
preproc
(
&
client
,
&
env
);
preproc
.
preprocess
(
QFile
::
encodeName
(
fn
),
code
,
/*result = */
0
);
deps
=
client
.
includedFiles
();
todo
+=
deps
;
}
std
::
cout
<<
std
::
endl
;
processed
.
insert
(
fn
,
deps
);
}
QMapIterator
<
QString
,
QStringList
>
it
(
processed
);
while
(
it
.
hasNext
())
{
it
.
next
();
if
(
it
.
value
().
isEmpty
())
continue
;
// no deps, nothing to do.
std
::
cout
<<
qPrintable
(
it
.
key
())
<<
":
\\\n
"
<<
qPrintable
(
it
.
value
().
join
(
QLatin1String
(
"
\\\n
"
)))
<<
std
::
endl
<<
std
::
endl
;
}
return
0
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment