aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build2/rule.cxx7
-rw-r--r--build2/search.cxx2
-rw-r--r--build2/target.cxx13
-rw-r--r--build2/target.hxx36
4 files changed, 40 insertions, 18 deletions
diff --git a/build2/rule.cxx b/build2/rule.cxx
index a462e58..a48fef2 100644
--- a/build2/rule.cxx
+++ b/build2/rule.cxx
@@ -67,7 +67,12 @@ namespace build2
// derivation function to treat this as prerequisite (just like
// in search_existing_file()).
//
- pt.derive_extension (nullptr, true);
+ if (pt.derive_extension (true) == nullptr)
+ {
+ l4 ([&]{trace << "no default extension for target " << pt;});
+ return false;
+ }
+
p = &pt.derive_path ();
}
diff --git a/build2/search.cxx b/build2/search.cxx
index 6be62b2..66f13a9 100644
--- a/build2/search.cxx
+++ b/build2/search.cxx
@@ -105,7 +105,7 @@ namespace build2
// (of course, if the user specified the extension explicitly, we will
// still do so).
//
- l4 ([&]{trace << "no existing file for prerequisite " << cpk;});
+ l4 ([&]{trace << "no default extension for prerequisite " << cpk;});
return nullptr;
}
}
diff --git a/build2/target.cxx b/build2/target.cxx
index 1b6757c..3ee9850 100644
--- a/build2/target.cxx
+++ b/build2/target.cxx
@@ -530,8 +530,8 @@ namespace build2
// path_target
//
- const string& path_target::
- derive_extension (const char* de, bool search)
+ const string* path_target::
+ derive_extension (bool search, const char* de)
{
// See also search_existing_file() if updating anything here.
//
@@ -541,7 +541,7 @@ namespace build2
// Note that returning by reference is now MT-safe since once the
// extension is specified, it is immutable.
//
- return *p;
+ return p;
else
{
optional<string> e;
@@ -559,10 +559,15 @@ namespace build2
if (de != nullptr)
e = de;
else
+ {
+ if (search)
+ return nullptr;
+
fail << "no default extension for target " << *this;
+ }
}
- return ext (move (*e));
+ return &ext (move (*e));
}
}
diff --git a/build2/target.hxx b/build2/target.hxx
index 884b185..19c8946 100644
--- a/build2/target.hxx
+++ b/build2/target.hxx
@@ -1190,19 +1190,22 @@ namespace build2
// As above but ignore the extension.
//
+ const target*
+ find (const target_type& type,
+ const dir_path& dir,
+ const dir_path& out,
+ const string& name) const
+ {
+ slock l (mutex_);
+ auto i (map_.find (target_key {&type, &dir, &out, &name, nullopt}));
+ return i != map_.end () ? i->second.get () : nullptr;
+ }
+
template <typename T>
const T*
find (const dir_path& dir, const dir_path& out, const string& name) const
{
- slock l (mutex_);
-
- auto i (
- map_.find (
- target_key {&T::static_type, &dir, &out, &name, nullopt}));
-
- return i != map_.end ()
- ? static_cast<const T*> (i->second.get ())
- : nullptr;
+ return static_cast<const T*> (find (T::static_type, dir, out, name));
}
// If the target was inserted, keep the map exclusive-locked and return
@@ -1424,11 +1427,20 @@ namespace build2
derive_path (path_type base, const char* default_ext = nullptr);
// As above but only derives (and returns) the extension (empty means no
- // extension used). If search is true then look for the extension as if
- // it was a prerequisite, not a target.
+ // extension used).
//
const string&
- derive_extension (const char* default_ext = nullptr, bool search = false);
+ derive_extension (const char* default_ext = nullptr)
+ {
+ return *derive_extension (false, default_ext);
+ }
+
+ // As above but if search is true then look for the extension as if it was
+ // a prerequisite, not a target. In this case, if no extension can be
+ // derived, return NULL instead of failing (like search_existing_file()).
+ //
+ const string*
+ derive_extension (bool search, const char* default_ext = nullptr);
// Const versions of the above that can be used on unlocked targets. Note
// that here we don't allow providing any defaults since you probably