aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build2/dist/module.hxx6
-rw-r--r--build2/dist/operation.cxx38
-rw-r--r--build2/file.cxx1
3 files changed, 35 insertions, 10 deletions
diff --git a/build2/dist/module.hxx b/build2/dist/module.hxx
index e6eb975..b66ca73 100644
--- a/build2/dist/module.hxx
+++ b/build2/dist/module.hxx
@@ -36,6 +36,9 @@ namespace build2
// after it has been copied to the distribution directory. The project's
// root scope and callback-specific data are passed along.
//
+ // Note that if registered, the callbacks are also called (recursively)
+ // in subprojects.
+ //
using callback_func = void (const path&, const scope&, void*);
void
@@ -56,8 +59,9 @@ namespace build2
callback_func* function;
void* data;
};
+ using callbacks = vector<callback>;
- vector<callback> callbacks_;
+ callbacks callbacks_;
};
}
}
diff --git a/build2/dist/operation.cxx b/build2/dist/operation.cxx
index cdc0b6d..01339b4 100644
--- a/build2/dist/operation.cxx
+++ b/build2/dist/operation.cxx
@@ -303,18 +303,39 @@ namespace build2
// Figure out where this file is inside the target directory.
//
bool src (t.dir.sub (src_root));
+ dir_path dl (src ? t.dir.leaf (src_root) : t.dir.leaf (out_root));
- dir_path d (td);
- d /= src
- ? t.dir.leaf (src_root)
- : t.dir.leaf (out_root);
-
+ dir_path d (td / dl);
if (!exists (d))
install (dist_cmd, d);
path r (install (dist_cmd, t, d));
- for (module::callback cb: mod.callbacks_)
+ // See if this file is in a subproject.
+ //
+ const scope* srs (rs);
+ const module::callbacks* cbs (&mod.callbacks_);
+
+ if (auto l = rs->vars[var_subprojects])
+ {
+ for (auto p: cast<subprojects> (l))
+ {
+ const dir_path& pd (p.second);
+ if (dl.sub (pd))
+ {
+ srs = &scopes.find (out_root / pd);
+
+ if (auto* m = srs->modules.lookup<module> (module::name))
+ cbs = &m->callbacks_;
+ else
+ fail << "dist module not loaded in subproject " << pd;
+
+ break;
+ }
+ }
+ }
+
+ for (module::callback cb: *cbs)
{
const path& pat (cb.pattern);
@@ -325,7 +346,8 @@ namespace build2
{
assert (pat.relative ());
- dir_path d ((src ? src_root : out_root) / pat.directory ());
+ dir_path d ((src ? srs->src_path () : srs->out_path ()) /
+ pat.directory ());
d.normalize ();
if (d != t.dir)
@@ -333,7 +355,7 @@ namespace build2
}
if (path_match (pat.leaf ().string (), t.path ().leaf ().string ()))
- cb.function (r, *rs, cb.data);
+ cb.function (r, *srs, cb.data);
}
}
diff --git a/build2/file.cxx b/build2/file.cxx
index 89120d3..8a0f2dc 100644
--- a/build2/file.cxx
+++ b/build2/file.cxx
@@ -407,7 +407,6 @@ namespace build2
// Scan the specified directory for any subprojects. If a subdirectory
// is a subproject, then enter it into the map, handling the duplicates.
- // Otherwise, scan the subdirectory recursively.
//
static void
find_subprojects (scope& s,