From e7f4231e935edae79ba2cd4d73a6e49591188bcc Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 1 Sep 2016 09:57:48 +0200 Subject: Add support for specifying directory in config.dist.archives --- build2/dist/init.cxx | 9 +++++++-- build2/dist/operation.cxx | 38 ++++++++++++++++++++++++++++++-------- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/build2/dist/init.cxx b/build2/dist/init.cxx index 2bf26e0..428ca5c 100644 --- a/build2/dist/init.cxx +++ b/build2/dist/init.cxx @@ -41,13 +41,18 @@ namespace build2 // Note: some overridable, some not. // + // config.dist.archives is a list of archive extensions that can be + // optionally prefixed with a directory. If it is relative, then it is + // prefixed with config.dist.root. Otherwise, the archive is written + // to the absolute location. + // v.insert ("config.dist.root", true); - v.insert ("config.dist.archives", true); + v.insert ("config.dist.archives", true); v.insert ("config.dist.cmd", true); v.insert ("dist.root"); v.insert ("dist.cmd"); - v.insert ("dist.archives"); + v.insert ("dist.archives"); v.insert ("dist", variable_visibility::target); // Flag. diff --git a/build2/dist/operation.cxx b/build2/dist/operation.cxx index 12bcc61..4628350 100644 --- a/build2/dist/operation.cxx +++ b/build2/dist/operation.cxx @@ -45,10 +45,13 @@ namespace build2 static void install (const path& cmd, file&, const dir_path&); - // cd && tar|zip ... . + // cd && tar|zip ... /. // static void - archive (const dir_path& root, const string& pkg, const string& ext); + archive (const dir_path& root, + const string& pkg, + const dir_path& dir, + const string& ext); static void dist_execute (action, const action_targets& ts, bool) @@ -289,8 +292,22 @@ namespace build2 // if (auto l = rs->vars["dist.archives"]) { - for (const string& e: cast (l)) - archive (dist_root, dist_package, e); + for (const path& p: cast (l)) + { + dir_path d (p.relative () ? dist_root : dir_path ()); + d /= p.directory (); + + const string& s (p.string ()); + size_t i (path::traits::find_leaf (s)); + + if (i == string::npos) + fail << "invalid archive '" << s << "' in dist.archives"; + + if (s[i] == '.') // Skip dot if specified. + ++i; + + archive (dist_root, dist_package, d, string (s, i)); + } } } @@ -386,13 +403,16 @@ namespace build2 } static void - archive (const dir_path& root, const string& pkg, const string& e) + archive (const dir_path& root, + const string& pkg, + const dir_path& dir, + const string& e) { string a (pkg + '.' + e); // Delete old archive for good measure. // - path ap (root / path (a)); + path ap (dir / path (a)); if (file_exists (ap, false)) rmfile (ap); @@ -401,9 +421,11 @@ namespace build2 // cstrings args; if (e == "zip") - args = {"zip", "-rq", a.c_str (), pkg.c_str (), nullptr}; + args = {"zip", "-rq", + ap.string ().c_str (), pkg.c_str (), nullptr}; else - args = {"tar", "-a", "-cf", a.c_str (), pkg.c_str (), nullptr}; + args = {"tar", "-a", "-cf", + ap.string ().c_str (), pkg.c_str (), nullptr}; if (verb >= 2) print_process (args); -- cgit v1.1