From beedc17766c58799eae1919cb471f686b8286363 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 29 Oct 2019 12:42:15 +0200 Subject: Regularize and make accessible install/uninstall primitives --- libbuild2/install/rule.cxx | 59 +++++++++++++++++++++------------------------- libbuild2/install/rule.hxx | 47 ++++++++++++++++++++++++++++++++---- 2 files changed, 70 insertions(+), 36 deletions(-) (limited to 'libbuild2') diff --git a/libbuild2/install/rule.cxx b/libbuild2/install/rule.cxx index 7cee10e..5655526 100644 --- a/libbuild2/install/rule.cxx +++ b/libbuild2/install/rule.cxx @@ -690,13 +690,11 @@ namespace build2 return p; } - // install -d - // - static void + void file_rule:: install_d (const scope& rs, const install_dir& base, const dir_path& d, - bool verbose = true) + uint16_t verbosity) { context& ctx (rs.ctx); @@ -737,7 +735,7 @@ namespace build2 dir_path pd (d.directory ()); if (pd != base.dir) - install_d (rs, base, pd, verbose); + install_d (rs, base, pd, verbosity); } cstrings args; @@ -763,24 +761,24 @@ namespace build2 process_path pp (run_search (args[0])); - if (verb >= 2) - print_process (args); - else if (verb && verbose) - text << "install " << chd; + if (verb >= verbosity) + { + if (verb >= 2) + print_process (args); + else if (verb) + text << "install " << chd; + } run (pp, args); } - // install / - // install - // - static void + void file_rule:: install_f (const scope& rs, const install_dir& base, const path& name, const file& t, const path& f, - bool verbose) + uint16_t verbosity) { context& ctx (rs.ctx); @@ -817,10 +815,13 @@ namespace build2 process_path pp (run_search (args[0])); - if (verb >= 2) - print_process (args); - else if (verb && verbose) - text << "install " << t; + if (verb >= verbosity) + { + if (verb >= 2) + print_process (args); + else if (verb) + text << "install " << t; + } if (!ctx.dry_run) run (pp, args); @@ -921,7 +922,7 @@ namespace build2 auto install_target = [&rs, this] (const file& t, const path& p, - bool verbose) + uint16_t verbosity) { // Note: similar logic to resolve_file(). // @@ -949,7 +950,7 @@ namespace build2 // sudo, etc). // for (auto i (ids.begin ()), j (i); i != ids.end (); j = i++) - install_d (rs, *j, i->dir, verbose); // install -d + install_d (rs, *j, i->dir, verbosity); // install -d install_dir& id (ids.back ()); @@ -974,7 +975,7 @@ namespace build2 n ? p.leaf () : fp.leaf () != tp.leaf () ? tp.leaf () : path (), t, f.path, - verbose); + verbosity); install_post (t, id, move (f)); }; @@ -989,7 +990,7 @@ namespace build2 { if (const path* p = lookup_install (*m, "install")) { - install_target (m->as (), *p, tp.empty () /* verbose */); + install_target (m->as (), *p, tp.empty () ? 1 : 2); r |= target_state::changed; } } @@ -999,24 +1000,18 @@ namespace build2 // if (!tp.empty ()) { - install_target (t, cast (t["install"]), true /* verbose */); + install_target (t, cast (t["install"]), 1); r |= target_state::changed; } return r; } - // uninstall -d - // - // We try to remove all the directories between base and dir but not base - // itself unless base == dir. Return false if nothing has been removed - // (i.e., the directories do not exist or are not empty). - // - static bool + bool file_rule:: uninstall_d (const scope& rs, const install_dir& base, const dir_path& d, - uint16_t verbosity = 1) + uint16_t verbosity) { // See install_d() for the rationale. // @@ -1244,7 +1239,7 @@ namespace build2 // for (auto i (ids.rbegin ()), j (i), e (ids.rend ()); i != e; j = ++i) { - if (install::uninstall_d (rs, ++j != e ? *j : *i, i->dir, verbosity)) + if (uninstall_d (rs, ++j != e ? *j : *i, i->dir, verbosity)) r |= target_state::changed; } diff --git a/libbuild2/install/rule.hxx b/libbuild2/install/rule.hxx index c7e6a17..56d3970 100644 --- a/libbuild2/install/rule.hxx +++ b/libbuild2/install/rule.hxx @@ -158,7 +158,32 @@ namespace build2 // The verbosity argument specified the level to start printing the // command at. Note that these functions respect the dry_run flag. - // Install a symlink: base/link -> target. + // Install (create) a directory: + // + // install -d + // + static void + install_d (const scope& rs, + const install_dir& base, + const dir_path& dir, + uint16_t verbosity = 1); + + // Install a file: + // + // install / # if is empty + // install / # if is not empty + // + static void + install_f (const scope& rs, + const install_dir& base, + const path& name, + const file& target, + const path& file, + uint16_t verbosity = 1); + + // Install (make) a symlink: + // + // ln -s / // static void install_l (const scope& rs, @@ -167,10 +192,10 @@ namespace build2 const path& link, uint16_t verbosity = 1); - // Uninstall a file or symlink: + // Uninstall (remove) a file or symlink: // - // uninstall / rm /.leaf (); name empty - // uninstall rm /; target can be NULL + // uninstall / # rm /.leaf (); name empty + // uninstall # rm /; target can be NULL // // Return false if nothing has been removed (i.e., the file does not // exist). @@ -182,6 +207,20 @@ namespace build2 const path& name, uint16_t verbosity = 1); + // Uninstall (remove) an empty directory. + // + // uninstall -d + // + // We try to remove all the directories between base and dir but not base + // itself unless base == dir. Return false if nothing has been removed + // (i.e., the directories do not exist or are not empty). + // + static bool + uninstall_d (const scope& rs, + const install_dir& base, + const dir_path& dir, + uint16_t verbosity = 1); + target_state perform_install (action, const target&) const; -- cgit v1.1