From 68a8fa2c75765b8dbf20019b022c8b12edb11619 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 27 Oct 2020 10:11:26 +0200 Subject: Tweak dist rule to handle prerequisites outside project --- libbuild2/dist/rule.cxx | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'libbuild2/dist') diff --git a/libbuild2/dist/rule.cxx b/libbuild2/dist/rule.cxx index 31f34e4..ef144d0 100644 --- a/libbuild2/dist/rule.cxx +++ b/libbuild2/dist/rule.cxx @@ -23,11 +23,13 @@ namespace build2 recipe rule:: apply (action a, target& t) const { - const dir_path& out_root (t.root_scope ().out_path ()); + const scope& rs (t.root_scope ()); + const dir_path& src_root (rs.src_path ()); + const dir_path& out_root (rs.out_path ()); // If we can, go inside see-through groups. // - for (prerequisite_member p: + for (prerequisite_member pm: group_prerequisite_members (a, t, members_mode::maybe)) { // Note: no exclusion tests, we want all of them (and see also the @@ -35,7 +37,7 @@ namespace build2 // Skip prerequisites imported from other projects. // - if (p.proj ()) + if (pm.proj ()) continue; // We used to always search and match but that resulted in the @@ -54,26 +56,38 @@ namespace build2 // @@ Note that this is still an issue in a custom dist rule. // const target* pt (nullptr); - if (p.is_a ()) + if (pm.is_a ()) { - pt = p.load (); + pt = pm.load (); if (pt == nullptr) { + const prerequisite& p (pm.prerequisite); + // Search for an existing target or existing file in src. // const prerequisite_key& k (p.key ()); pt = k.tk.type->search (t, k); if (pt == nullptr) + { + // Skip it if it's outside of the project (e.g., an executable + // "imported" in an ad hoc way). + // + if (p.dir.absolute () && + !p.dir.sub (src_root) && + !p.dir.sub (out_root)) + continue; + fail << "prerequisite " << k << " is not existing source file " << "nor known output target" << endf; + } - search_custom (p.prerequisite, *pt); // Cache. + search_custom (p, *pt); // Cache. } } else - pt = &p.search (t); + pt = &pm.search (t); // Don't match targets that are outside of our project. // -- cgit v1.1