diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2020-10-07 15:26:49 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2020-10-07 15:26:49 +0200 |
commit | 291a737de8f92a7f620853133aa404b98e552a21 (patch) | |
tree | 1e6c61b04fffb304a3d28513f4d3a90759b94bcd /libbuild2 | |
parent | aa25692e3f8614c356bdf94aaaa7aeb8f4515411 (diff) |
Add ability to specify extra adhoc files for distribution
Diffstat (limited to 'libbuild2')
-rw-r--r-- | libbuild2/dist/module.hxx | 20 | ||||
-rw-r--r-- | libbuild2/dist/operation.cxx | 44 |
2 files changed, 58 insertions, 6 deletions
diff --git a/libbuild2/dist/module.hxx b/libbuild2/dist/module.hxx index e445d4a..314dc96 100644 --- a/libbuild2/dist/module.hxx +++ b/libbuild2/dist/module.hxx @@ -22,9 +22,25 @@ namespace build2 const variable& var_dist_package; + // If exists, add the specified source file to the distribution. The + // last component in the path may be a wildcard pattern in which case + // all the files matching this pattern are added. The file path must be + // relative to the source root. + // + // Note that the file may still be explicitly excluded by a buildfile. + // + // Note also that the patterns in the last component restriction is due + // to symlink trickiness. + // + void + add_adhoc (path f) + { + adhoc.push_back (move (f)); + } + // Distribution post-processing callbacks. // - // The last component in the pattern may contain shell wildcards. If the + // Only the last component in the pattern may contain wildcards. If the // path contains a directory, then it is matched from the distribution // root only. Otherwise, it is matched against all the files being // distributed. For example: @@ -57,6 +73,8 @@ namespace build2 : var_dist_package (v_d_p) {} public: + vector<path> adhoc; + struct callback { const path pattern; diff --git a/libbuild2/dist/operation.cxx b/libbuild2/dist/operation.cxx index a5dfba0..21d5283 100644 --- a/libbuild2/dist/operation.cxx +++ b/libbuild2/dist/operation.cxx @@ -263,11 +263,45 @@ namespace build2 } } - // Add buildfiles that are not normally loaded as part of the project, - // for example, the export stub. They will still be ignored on the - // next step if the user explicitly marked them dist=false. + // Add ad hoc files and buildfiles that are not normally loaded as + // part of the project, for example, the export stub. They will still + // be ignored on the next step if the user explicitly marked them + // dist=false. // - add_target<buildfile> (rs, rs.root_extra->export_file); + auto add_adhoc = [] (const scope& rs) + { + add_target<buildfile> (rs, rs.root_extra->export_file); + + if (auto* m = rs.find_module<module> (module::name)) + { + for (const path& f: m->adhoc) + { + if (!path_pattern (f)) + add_target<file> (rs, f); + else + try + { + path_search (f, + [&rs] (path&& pe, const string&, bool interm) + { + if (!interm) + add_target<file> (rs, pe, true /* exists */); + + return true; + }, + rs.src_path (), + path_match_flags::none /* no follow_symlinks */); + } + catch (const system_error& e) + { + fail << "unable to scan " << rs.src_path () / f.directory () + << ": " << e; + } + } + } + }; + + add_adhoc (rs); // The same for subprojects that have been loaded. // @@ -285,7 +319,7 @@ namespace build2 if (!nrs.src_path ().sub (src_root)) // Not a strong amalgamation. continue; - add_target<buildfile> (nrs, nrs.root_extra->export_file); + add_adhoc (nrs); } } |