From 29f6e38b4f8d55f3da61fcd061c8b8ff3c5eaa00 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 19 Feb 2018 15:15:43 +0200 Subject: Make search_existing_file() more consistent --- build2/search.cxx | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) (limited to 'build2/search.cxx') diff --git a/build2/search.cxx b/build2/search.cxx index f0b163a..c7a7783 100644 --- a/build2/search.cxx +++ b/build2/search.cxx @@ -88,14 +88,26 @@ namespace build2 const target_key& ctk (cpk.tk); const scope* s (cpk.scope); + path f; + if (ctk.dir->absolute ()) + f = *ctk.dir; // Already normalized. + else { - // Bail out if not inside project's src_root. - // - if (s == nullptr || !ctk.dir->sub (s->root_scope ()->src_path ())) - return nullptr; + f = s->src_path (); + + if (!ctk.dir->empty ()) + { + f /= *ctk.dir; + f.normalize (); + } } + // Bail out if not inside project's src_root. + // + if (s == nullptr || !f.sub (s->root_scope ()->src_path ())) + return nullptr; + // Figure out the extension. Pretty similar logic to file::derive_path(). // optional ext (ctk.ext); @@ -128,21 +140,6 @@ namespace build2 // Check if there is a file. // - path f; - - if (tk.dir->absolute ()) - f = *tk.dir; // Already normalized. - else - { - f = s->src_path (); - - if (!tk.dir->empty ()) - { - f /= *tk.dir; - f.normalize (); - } - } - f /= *tk.name; if (!ext->empty ()) @@ -171,7 +168,7 @@ namespace build2 // // In the other two cases we use the prerequisite's out (in case it is // relative, we need to complete it, which is @@ OUT TODO). Note that we - // blindly trust the user's value which can be use for some interesting + // blindly trust the user's value which can be used for some interesting // tricks, for example: // // ../cxx{foo}@./ -- cgit v1.1