aboutsummaryrefslogtreecommitdiff
path: root/build2/target.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-01-24 12:03:50 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-01-24 12:03:50 +0200
commitaec5f7309b2ee7210dc39de9c792f35273c73c10 (patch)
tree039064cbccb9ef01a5b93ca1659ae05137e61d3f /build2/target.cxx
parent4b507ea962169a8d19e4b37b940448eba97d87a4 (diff)
Differentiate extension printing according to stream verbosity
Diffstat (limited to 'build2/target.cxx')
-rw-r--r--build2/target.cxx64
1 files changed, 56 insertions, 8 deletions
diff --git a/build2/target.cxx b/build2/target.cxx
index 89e16b5..3fd099d 100644
--- a/build2/target.cxx
+++ b/build2/target.cxx
@@ -248,7 +248,7 @@ namespace build2
}
ostream&
- operator<< (ostream& os, const target_key& k)
+ to_stream (ostream& os, const target_key& k, uint16_t ev)
{
// If the name is empty, then we want to print the directory
// inside {}, e.g., dir{bar/}, not bar/dir{}.
@@ -271,8 +271,22 @@ namespace build2
{
os << *k.name;
- if (k.ext != nullptr && !k.ext->empty ())
- os << '.' << *k.ext;
+ // If the extension derivation function is NULL, then it means this
+ // target type doesn't use extensions.
+ //
+ if (k.type->extension != nullptr)
+ {
+ // For verbosity level 0 we don't print the extension. For 1 we print
+ // it if there is one. For 2 we print 'foo.?' if it hasn't yet been
+ // assigned and 'foo.' if it is assigned as "no extension" (empty).
+ //
+ if (ev > 0 && (ev > 1 || (k.ext != nullptr && !k.ext->empty ())))
+ {
+ os << '.' << (k.ext != nullptr ? *k.ext : "?");
+ }
+ }
+ else
+ assert (k.ext == nullptr);
}
else
os << *k.dir;
@@ -282,6 +296,17 @@ namespace build2
return os;
}
+ ostream&
+ operator<< (ostream& os, const target_key& k)
+ {
+ if (auto p = k.type->print)
+ p (os, k);
+ else
+ to_stream (os, k, stream_verb (os));
+
+ return os;
+ }
+
// path_target
//
void path_target::
@@ -414,8 +439,6 @@ namespace build2
throw failed ();
}
- // Assert if called.
- //
const string&
target_extension_assert (const target_key&, scope&)
{
@@ -423,6 +446,20 @@ namespace build2
throw failed ();
}
+ void
+ target_print_0_ext_verb (ostream& os, const target_key& k)
+ {
+ uint16_t v (stream_verb (os));
+ to_stream (os, k, v < 2 ? 0 : v); // Remap 1 to 0.
+ }
+
+ void
+ target_print_1_ext_verb (ostream& os, const target_key& k)
+ {
+ uint16_t v (stream_verb (os));
+ to_stream (os, k, v < 1 ? 1 : v); // Remap 0 to 1.
+ }
+
// type info
//
@@ -432,6 +469,7 @@ namespace build2
nullptr,
nullptr,
nullptr,
+ nullptr,
&search_target,
false
};
@@ -442,6 +480,7 @@ namespace build2
&target::static_type,
nullptr,
nullptr,
+ nullptr,
&search_target,
false
};
@@ -452,6 +491,7 @@ namespace build2
&mtime_target::static_type,
nullptr,
nullptr,
+ nullptr,
&search_target,
false
};
@@ -478,6 +518,7 @@ namespace build2
&path_target::static_type,
&file_factory<file>,
&target_extension_var<file_ext_var, file_ext_def>,
+ &target_print_1_ext_verb, // Print extension even at verbosity level 0.
&search_file,
false
};
@@ -487,7 +528,8 @@ namespace build2
"alias",
&target::static_type,
&target_factory<alias>,
- nullptr, // Should never need.
+ nullptr, // Extension not used.
+ nullptr,
&search_alias,
false
};
@@ -497,7 +539,8 @@ namespace build2
"dir",
&alias::static_type,
&target_factory<dir>,
- nullptr, // Should never need.
+ nullptr, // Extension not used.
+ nullptr,
&search_alias,
false
};
@@ -507,7 +550,8 @@ namespace build2
"fsdir",
&target::static_type,
&target_factory<fsdir>,
- nullptr, // Should never need.
+ nullptr, // Extension not used.
+ nullptr,
&search_target,
false
};
@@ -527,6 +571,7 @@ namespace build2
&file::static_type,
&file_factory<buildfile>,
&buildfile_target_extension,
+ nullptr,
&search_file,
false
};
@@ -537,6 +582,7 @@ namespace build2
&file::static_type,
&file_factory<doc>,
&target_extension_var<file_ext_var, file_ext_def>, // Same as file.
+ &target_print_1_ext_verb, // Same as file.
&search_file,
false
};
@@ -556,6 +602,7 @@ namespace build2
&doc::static_type,
&man_factory,
&target_extension_assert, // Should be specified explicitly (see factory).
+ &target_print_1_ext_verb, // Print extension even at verbosity level 0.
&search_file,
false
};
@@ -567,6 +614,7 @@ namespace build2
&man::static_type,
&file_factory<man1>,
&target_extension_fix<man1_ext>,
+ &target_print_0_ext_verb, // Fixed extension, no use printing.
&search_file,
false
};