CMake: Fix target enumerating on Windows. For some reason, $ at the end of regexp causes matches to be empty. While there, filter out internal CMake targets.
ClosedPublic

Authored by arrowd on Jan 3 2016, 5:34 PM.

Diff Detail

Repository
R32 KDevelop
Branch
5.0
Lint
No Linters Available
Unit
No Unit Test Coverage
arrowd updated this revision to Diff 1712.Jan 3 2016, 5:34 PM
arrowd retitled this revision from to CMake: Fix target enumerating on Windows. For some reason, $ at the end of regexp causes matches to be empty. While there, filter out internal CMake targets..
arrowd updated this object.
arrowd edited the test plan for this revision. (Show Details)
Restricted Application added a subscriber: kdevelop-devel. · View Herald TranscriptJan 3 2016, 5:34 PM
arrowd added a project: KDevelop.
apol added inline comments.Jan 3 2016, 5:49 PM
projectmanagers/cmake/cmakeimportjsonjob.cpp
116

I don't understand why.

125

This should be in CMakeManager::populateTargets(), with the *_automoc target filtering.

arrowd added inline comments.Jan 3 2016, 5:57 PM
projectmanagers/cmake/cmakeimportjsonjob.cpp
116

Me neither. What you suggest?

125

K, will do.

apol added inline comments.Jan 3 2016, 6:05 PM
projectmanagers/cmake/cmakeimportjsonjob.cpp
116

You can explain a bit better why it doesn't match with the $. If you print the matched strings, what do you get?

arrowd updated this revision to Diff 1715.Jan 3 2016, 6:14 PM

Perform target filtering in CMakeManager::populateTargets()

arrowd marked an inline comment as done.Jan 3 2016, 6:14 PM
arrowd added inline comments.
projectmanagers/cmake/cmakeimportjsonjob.cpp
116

They are empty, both of them.

apol edited edge metadata.Jan 3 2016, 7:13 PM

Commit the filtering part, if you want. This is unrelated anyway.

projectmanagers/cmake/cmakeimportjsonjob.cpp
116

What's the original string? Does it look like it should match?

arrowd added inline comments.Jan 3 2016, 7:15 PM
projectmanagers/cmake/cmakeimportjsonjob.cpp
116

Absolutely.

C:/bla/bla/path/to/build/CMakeFiles/targetname.dir

But no matches.

kfunk edited edge metadata.EditedJan 3 2016, 7:45 PM

Note: Please unit test this.

Factor out the import logic, then in a unit test parse a small TargetDirectories.txt file and check whether the parse succeeded. Trivial.

apol added inline comments.Jan 4 2016, 1:09 AM
projectmanagers/cmake/cmakeimportjsonjob.cpp
116

Well, changing the line would mean to remove it because either we don't understand how QRegularExpression works or because ::readLine() isn't doint its job well (and thus should be properly fixed in Qt).

arrowd updated this revision to Diff 1718.Jan 4 2016, 8:50 AM
arrowd edited edge metadata.

Optionally consume \r symbol at the end of line.

arrowd added inline comments.Jan 4 2016, 8:52 AM
projectmanagers/cmake/cmakeimportjsonjob.cpp
114 ↗(On Diff #1718)

How about this? Even if it is a bug in Qt, this code wouldn't break once it is fixed.

kfunk added inline comments.Jan 4 2016, 9:48 AM
projectmanagers/cmake/cmakeimportjsonjob.cpp
114 ↗(On Diff #1718)

Could also switch to QTextStream-based file reading, which strips \r\n and \n. Makes this code more readable and avoids us having to do implement platform-specific behavior.

See: http://doc.qt.io/qt-5/qtextstream.html#readLine

arrowd updated this revision to Diff 1723.Jan 4 2016, 11:24 AM

Use QTextStream to trim lines from \r\n.

arrowd marked an inline comment as done.Jan 4 2016, 11:26 AM
kfunk accepted this revision.Jan 4 2016, 11:45 AM
kfunk edited edge metadata.

Perfect! +1

This revision is now accepted and ready to land.Jan 4 2016, 11:45 AM
kfunk added inline comments.Jan 4 2016, 11:46 AM
projectmanagers/cmake/cmakeimportjsonjob.cpp
117

Just while(...)

apol accepted this revision.Jan 4 2016, 1:52 PM
apol edited edge metadata.

Looks good to me.

arrowd updated this revision to Diff 1728.Jan 4 2016, 5:51 PM
arrowd edited edge metadata.

Add a testcase.

arrowd updated this revision to Diff 1729.Jan 4 2016, 5:53 PM

Tweak test logic.

kfunk added inline comments.Jan 4 2016, 6:11 PM
projectmanagers/cmake/tests/test_cmakemanager.cpp
304 ↗(On Diff #1729)

Be explicit: Call it testEnumerateTargets()

308 ↗(On Diff #1729)

QTemporaryFile?

320 ↗(On Diff #1729)

Better use QTemporaryDir("/path/to/subdir") on the stack => takes care of construction & deletion of this dir

arrowd updated this revision to Diff 1731.Jan 4 2016, 6:42 PM

Rename test. Use QTemporary{File,Dir}.

arrowd marked 3 inline comments as done.Jan 4 2016, 6:45 PM
kfunk added a comment.Jan 4 2016, 7:35 PM

Feel free to push after fixing those minor issues. Thanks!

projectmanagers/cmake/tests/test_cmakemanager.cpp
308 ↗(On Diff #1731)

Cleaner to use absolute file paths here: QDir::tempPath() + "/TargetDirectories.txt"

-> Doesn't pollute your CWD

309 ↗(On Diff #1731)

Dito, using the default ctor of QTemporaryDir is fine already.