qmake: Get parent path / chop one path level
-
That's why there are scopes that can be used for this kind of situations
-
I have something that works...under some circumstances.
It seems to always work when running a scripted compile run (Windows and Linux, vs2010 and gcc), but it doesn't seem to work in Creator when evaluating files of the code model.defineReplace(replaceBackslashes) { TEMP_DIRNAME = $$1 FINAL_DIRNAME = $$replace(TEMP_DIRNAME,\\\\,/) return($$FINAL_DIRNAME) } defineReplace(cleanupPath) { TEMP_DIRNAME = $$files($$1) FINAL_DIRNAME = $$replaceBackslashes($$TEMP_DIRNAME) return($$FINAL_DIRNAME) }
For Creator, both TEMP_DIRNAME and FINAL_DIRNAME in "cleanupPath" are always empty...for some reason. In the scripted compile job, they look just the way they are supposed to.
Any idea why?
-
Probably because Qt Creator doesn't pass any parameter.
How are you calling qmake on the command line ?
-
A typical scripted call to qmake would look something like this:
qmake.exe CONFIG-=debug CONFIG-=release CONFIG-=debug_and_release CONFIG-=build_all CONFIG+=debug CONFIG+=hmk_build -o tpet.mak ..\..\..\code\tpet.pro
-
Then why not use
_PRO_FILE_PWD_
as suggested by @Wieland and your replace function to convert forward slashed to back slashes so you wouldn't be dependent on how you call qmake. -
@SGaist
Going in circles....
Certainly, I use the_PRO_FILE_PWD_
as my starting point, but some tools need a clean path without stuff likepwdFolder/../../xyz/folder
in it. The function he suggested for cleaning the path is not available in Qt 4.8.This brings me back to the question why my original code does not work in context of Creator's code evaluation.
According to the docs,$files
"Expands the specified wildcard pattern and returns a list of filenames. If recursive is true, this function descends into subdirectories."Assuming that a folder is also a file (at least, that is how most file systems I know treat folders internally), the function should evaluate the location of the folder, and return the correct clean path for it. And it does so in the scripted qmake call.
There is no more information in the docs - whether there are certainly boundary conditions for this function to work, limitations, etc. So I'm really at a loss why this does not work as expected.
-
Try with:
defineReplace(cleanPath) { win32:1 ~= s|\\\\|/|g contains(1, ^/.*):pfx = / else:pfx = segs = $ $split(1, /) out = for(seg, segs) { equals(seg, ..):out = $ $member(out, 0, -2) else:!equals(seg, .):out += $ $seg } win32:return($$join(out, \\, $ $pfx)) return($$join(out, /, $ $pfx)) } sub_dir = $ $_PRO_FILE_PWD_/../testme path_for_cmd = $ $cleanPath($ $sub_dir) message($ $path_for_cmd)
With additional space between $ removed