From b7b30102882f0a85c169a0eb4944a8f1c344c9e1 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 1 Aug 2017 15:29:24 +0200 Subject: Add version, project.summary, project.url built-in variables Extract them from manifest in the version module. Use them when generating the pkg-config's .pc files. --- build2/cc/pkgconfig.cxx | 29 ++++++++++++++++++++++++----- build2/context.cxx | 20 ++++++++++++++++---- build2/context.hxx | 4 ++++ build2/version/init.cxx | 17 ++++++++++++++--- 4 files changed, 58 insertions(+), 12 deletions(-) (limited to 'build2') diff --git a/build2/cc/pkgconfig.cxx b/build2/cc/pkgconfig.cxx index 55847ef..8d0ea25 100644 --- a/build2/cc/pkgconfig.cxx +++ b/build2/cc/pkgconfig.cxx @@ -558,11 +558,30 @@ namespace build2 ofdstream os (p); auto_rmfile arm (p); - // @@ version may not be string, need to reverse. - // - os << "Name: " << cast (rs.vars[var_project]) << endl; - os << "Version: " << cast (rs.vars["version"]) << endl; - os << "Description: @@ TODO" << endl; + { + const string& n (cast (rs.vars[var_project])); + + lookup vl (rs.vars[var_version]); + if (!vl) + fail << "no version variable in project " << n << + info << "while generating " << p; + + const string& v (cast (vl)); + + os << "Name: " << n << endl; + os << "Version: " << v << endl; + + // This one is required so make something up if unspecified. + // + os << "Description: "; + if (const string* s = cast_null (rs[var_project_summary])) + os << *s << endl; + else + os << n << ' ' << v << endl; + + if (const string* u = cast_null (rs[var_project_url])) + os << "URL: " << *u << endl; + } // In pkg-config backslashes, spaces, etc are escaped with a // backslash. diff --git a/build2/context.cxx b/build2/context.cxx index 2464973..d979f92 100644 --- a/build2/context.cxx +++ b/build2/context.cxx @@ -184,6 +184,10 @@ namespace build2 const variable* var_project; const variable* var_amalgamation; const variable* var_subprojects; + const variable* var_version; + + const variable* var_project_url; + const variable* var_project_summary; const variable* var_import_target; @@ -522,11 +526,19 @@ namespace build2 // Note that subprojects is not typed since the value requires // pre-processing (see file.cxx). // - var_project = &vp.insert ("project"); - var_amalgamation = &vp.insert ("amalgamation"); - var_subprojects = &vp.insert ("subprojects"); + { + auto pv (variable_visibility::project); + + var_project = &vp.insert ("project", pv); + var_amalgamation = &vp.insert ("amalgamation", pv); + var_subprojects = &vp.insert ("subprojects", pv); + var_version = &vp.insert ("version", pv); - var_import_target = &vp.insert ("import.target"); + var_project_url = &vp.insert ("project.url", pv); + var_project_summary = &vp.insert ("project.summary", pv); + + var_import_target = &vp.insert ("import.target"); + } // Register builtin rules. // diff --git a/build2/context.hxx b/build2/context.hxx index 3aa2f73..bf31887 100644 --- a/build2/context.hxx +++ b/build2/context.hxx @@ -249,6 +249,10 @@ namespace build2 extern const variable* var_project; extern const variable* var_amalgamation; extern const variable* var_subprojects; + extern const variable* var_version; + + extern const variable* var_project_url; // project.url + extern const variable* var_project_summary; // project.summary extern const variable* var_import_target; // import.target diff --git a/build2/version/init.cxx b/build2/version/init.cxx index 699495a..c6acf88 100644 --- a/build2/version/init.cxx +++ b/build2/version/init.cxx @@ -36,8 +36,12 @@ namespace build2 tracer trace ("version::boot"); l5 ([&]{trace << "for " << rs.out_path ();}); - // Extract the version from the manifest file. + // Extract the version from the manifest file. As well as summary and + // url while at it. // + string sum; + string url; + standard_version v; dependency_constraints ds; { @@ -57,7 +61,11 @@ namespace build2 for (nv = p.next (); !nv.empty (); nv = p.next ()) { - if (nv.name == "version") + if (nv.name == "summary") + sum = move (nv.value); + else if (nv.name == "url") + url = move (nv.value); + else if (nv.name == "version") { try { @@ -180,7 +188,10 @@ namespace build2 rs.assign (v) = move (val); }; - set ("version", v.string ()); // Package version. + if (!sum.empty ()) rs.assign (var_project_summary) = move (sum); + if (!url.empty ()) rs.assign (var_project_url) = move (url); + + set ("version", v.string ()); // Project version (var_version). set ("version.project", v.string_project ()); set ("version.project_number", v.version); -- cgit v1.1