From 0e96e47debd1d8c48d1d23fd51c9ee05f61c80e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 7 Oct 2013 17:55:45 +0200 Subject: [PATCH] qmake: Centralize TARGET sanitization in default_post.prf MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Shared between UNIX and Win generators, and allows prfs after default_post to rely on sane TARGET and DESTDIR values. This allows us to clean up the DESTDIR logic in testcase.prf, which was completely busted. Doing the two in separate commits is unfortunately not possible as the old testcase.prf logic was so broken it would barf if only looked at. Change-Id: Ibf21216195c760ee46ae679c162b207b77a9d813 Reviewed-by: Jan Arve Sæther Reviewed-by: Tor Arne Vestbø Reviewed-by: Oswald Buddenhagen --- mkspecs/features/default_post.prf | 12 +++++++ mkspecs/features/testcase.prf | 43 +++++++++++++------------- qmake/generators/unix/unixmake.cpp | 14 +-------- qmake/generators/win32/winmakefile.cpp | 14 --------- 4 files changed, 35 insertions(+), 48 deletions(-) diff --git a/mkspecs/features/default_post.prf b/mkspecs/features/default_post.prf index c756455dd21..4501b2a568b 100644 --- a/mkspecs/features/default_post.prf +++ b/mkspecs/features/default_post.prf @@ -6,6 +6,18 @@ contains(TEMPLATE, ".*(lib|app)"):CONFIG += have_target load(resolve_config) +# If the TARGET looks like a path, split it into DESTDIR and the resulting TARGET +target_dir_part = $$dirname(TARGET) +!isEmpty(target_dir_part) { + isEmpty(DESTDIR): \ + DESTDIR = $$target_dir_part + else: \ + DESTDIR = $$DESTDIR/$$target_dir_part + + TARGET = $$basename(TARGET) + DESTDIR = $$clean_path($$DESTDIR) +} + QT_BREAKPAD_ROOT_PATH = $$(QT_BREAKPAD_ROOT_PATH) !isEmpty(QT_BREAKPAD_ROOT_PATH): \ # quick test first whether requested ... !static:release:have_target: \ # is it applicable? diff --git a/mkspecs/features/testcase.prf b/mkspecs/features/testcase.prf index e31d1f45394..10f421a8e2a 100644 --- a/mkspecs/features/testcase.prf +++ b/mkspecs/features/testcase.prf @@ -10,34 +10,35 @@ check.files = check.path = . # If the test ends up in a different directory, we should cd to that directory. -# Note that qmake modifies DESTDIR after this file is processed, -# therefore, testing DESTDIR for emptiness is not sufficient. -# Also note that in debug-and-release mode we don't want to cd into the debug/release -# directory (e.g. if the test goes to foo/release/tst_thing.exe, we want to do -# cd foo && release/tst_thing.exe ). -MUNGED_DESTDIR=$$DESTDIR -MUNGED_TARGET=$$TARGET -win32:debug_and_release { - contains(DESTDIR,^release$)|contains(DESTDIR,^debug$):MUNGED_DESTDIR= +TESTRUN_CWD = $$DESTDIR - # In debug-and-release mode, the first ../ in TARGET breaks out of the debug/release - # subdirectory. However, since make's working directory is already outside of the - # debug/release subdirectory, this first ../ should be ignored when deciding if - # we have to change directory before running the test. - MUNGED_TARGET=$$replace(MUNGED_TARGET,^\\.\\./,) +debug_and_release:debug_and_release_target { + # But in debug-and-release-target mode we don't want to cd into the debug/release + # directory (e.g. if the test goes to foo/release/tst_thing.exe, we want to do + # 'cd foo && release/tst_thing.exe', not 'cd foo/release && tst_thing.exe'). + + TESTRUN_CWD ~= s/(release|debug)$// + TEST_TARGET_DIR = $$relative_path($$absolute_path($$DESTDIR, $$OUT_PWD), $$absolute_path($$TESTRUN_CWD, $$OUT_PWD)) } -!isEmpty(MUNGED_DESTDIR):!contains(MUNGED_DESTDIR,^\\./?):check.commands = cd $(DESTDIR) && -contains(MUNGED_TARGET,.*/.*):check.commands = cd $(DESTDIR) && + +!isEmpty(TESTRUN_CWD):!contains(TESTRUN_CWD,^\\./?): \ + check.commands = cd $$system_path($$TESTRUN_CWD) && # Allow for a custom test runner script check.commands += $(TESTRUNNER) -mac { - app_bundle: check.commands += ./$(QMAKE_TARGET).app/Contents/MacOS/$(QMAKE_TARGET) - else: check.commands += ./$(QMAKE_TARGET) +unix { + isEmpty(TEST_TARGET_DIR): TEST_TARGET_DIR = . + + mac:app_bundle: \ + check.commands += $${TEST_TARGET_DIR}/$(QMAKE_TARGET).app/Contents/MacOS/$(QMAKE_TARGET) + else: \ + check.commands += $${TEST_TARGET_DIR}/$(QMAKE_TARGET) +} else { + # Windows + !isEmpty(TEST_TARGET_DIR): TEST_TARGET_DIR = $${TEST_TARGET_DIR}$${QMAKE_DIR_SEP} + check.commands += $${TEST_TARGET_DIR}$(TARGET) } -else:unix: check.commands += ./$(QMAKE_TARGET) -else: check.commands += $(DESTDIR_TARGET) # Allow for custom arguments to tests check.commands += $(TESTARGS) diff --git a/qmake/generators/unix/unixmake.cpp b/qmake/generators/unix/unixmake.cpp index adeb55af865..1c95392932b 100644 --- a/qmake/generators/unix/unixmake.cpp +++ b/qmake/generators/unix/unixmake.cpp @@ -106,20 +106,8 @@ UnixMakefileGenerator::init() return; /* subdirs is done */ } - //If the TARGET looks like a path split it into DESTDIR and the resulting TARGET - if(!project->isEmpty("TARGET")) { + if (!project->isEmpty("TARGET")) project->values("TARGET") = escapeFilePaths(project->values("TARGET")); - ProString targ = unescapeFilePath(project->first("TARGET")); - int slsh = qMax(targ.lastIndexOf('/'), targ.lastIndexOf(Option::dir_sep)); - if(slsh != -1) { - if(project->isEmpty("DESTDIR")) - project->values("DESTDIR").append(""); - else if(project->first("DESTDIR").right(1) != Option::dir_sep) - project->values("DESTDIR") = ProStringList(project->first("DESTDIR") + Option::dir_sep); - project->values("DESTDIR") = ProStringList(project->first("DESTDIR") + targ.left(slsh+1)); - project->values("TARGET") = ProStringList(targ.mid(slsh+1)); - } - } project->values("QMAKE_ORIG_TARGET") = project->values("TARGET"); project->values("QMAKE_ORIG_DESTDIR") = project->values("DESTDIR"); diff --git a/qmake/generators/win32/winmakefile.cpp b/qmake/generators/win32/winmakefile.cpp index 2ef2d82b5aa..0ad0f09bce0 100644 --- a/qmake/generators/win32/winmakefile.cpp +++ b/qmake/generators/win32/winmakefile.cpp @@ -274,20 +274,6 @@ Win32MakefileGenerator::processPrlFiles() void Win32MakefileGenerator::processVars() { - //If the TARGET looks like a path split it into DESTDIR and the resulting TARGET - if(!project->isEmpty("TARGET")) { - ProString targ = project->first("TARGET"); - int slsh = qMax(targ.lastIndexOf('/'), targ.lastIndexOf(Option::dir_sep)); - if(slsh != -1) { - if(project->isEmpty("DESTDIR")) - project->values("DESTDIR").append(""); - else if(project->first("DESTDIR").right(1) != Option::dir_sep) - project->values("DESTDIR") = ProStringList(project->first("DESTDIR") + Option::dir_sep); - project->values("DESTDIR") = ProStringList(project->first("DESTDIR") + targ.left(slsh+1)); - project->values("TARGET") = ProStringList(targ.mid(slsh+1)); - } - } - project->values("QMAKE_ORIG_TARGET") = project->values("TARGET"); if (project->isEmpty("QMAKE_PROJECT_NAME")) project->values("QMAKE_PROJECT_NAME") = project->values("QMAKE_ORIG_TARGET");