aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/install
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2019-10-29 12:42:15 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2019-10-29 12:42:15 +0200
commitbeedc17766c58799eae1919cb471f686b8286363 (patch)
tree2d23aac9cc76808e0d71121c1ca5666063b850e5 /libbuild2/install
parent86e96b929031e7edc4ac1319e0fd42e8bb854146 (diff)
Regularize and make accessible install/uninstall primitives
Diffstat (limited to 'libbuild2/install')
-rw-r--r--libbuild2/install/rule.cxx59
-rw-r--r--libbuild2/install/rule.hxx47
2 files changed, 70 insertions, 36 deletions
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 <dir>
- //
- 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 <file> <dir>/
- // install <file> <file>
- //
- 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<path> (*m, "install"))
{
- install_target (m->as<file> (), *p, tp.empty () /* verbose */);
+ install_target (m->as<file> (), *p, tp.empty () ? 1 : 2);
r |= target_state::changed;
}
}
@@ -999,24 +1000,18 @@ namespace build2
//
if (!tp.empty ())
{
- install_target (t, cast<path> (t["install"]), true /* verbose */);
+ install_target (t, cast<path> (t["install"]), 1);
r |= target_state::changed;
}
return r;
}
- // uninstall -d <dir>
- //
- // 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 <dir>
+ //
+ static void
+ install_d (const scope& rs,
+ const install_dir& base,
+ const dir_path& dir,
+ uint16_t verbosity = 1);
+
+ // Install a file:
+ //
+ // install <file> <base>/ # if <name> is empty
+ // install <file> <base>/<name> # if <name> 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 <target> <base>/<link>
//
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 <target> <base>/ rm <base>/<target>.leaf (); name empty
- // uninstall <target> <name> rm <base>/<name>; target can be NULL
+ // uninstall <target> <base>/ # rm <base>/<target>.leaf (); name empty
+ // uninstall <target> <name> # rm <base>/<name>; 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 <dir>
+ //
+ // 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;