aboutsummaryrefslogtreecommitdiff
path: root/bpkg/pkg-unpack.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'bpkg/pkg-unpack.cxx')
-rw-r--r--bpkg/pkg-unpack.cxx127
1 files changed, 94 insertions, 33 deletions
diff --git a/bpkg/pkg-unpack.cxx b/bpkg/pkg-unpack.cxx
index 862feac..22ff02f 100644
--- a/bpkg/pkg-unpack.cxx
+++ b/bpkg/pkg-unpack.cxx
@@ -10,6 +10,7 @@
#include <bpkg/package-odb.hxx>
#include <bpkg/database.hxx>
#include <bpkg/checksum.hxx>
+#include <bpkg/rep-mask.hxx>
#include <bpkg/diagnostics.hxx>
#include <bpkg/manifest-utility.hxx>
@@ -58,26 +59,18 @@ namespace bpkg
// package object which may replace the existing one.
//
static shared_ptr<selected_package>
- pkg_unpack (const common_options& o,
- database& db,
+ pkg_unpack (database& db,
transaction& t,
- package_name n,
- version v,
- const package_info* pi,
- dir_path d,
- repository_location rl,
+ package_name&& n,
+ version&& v,
+ dir_path&& d,
+ repository_location&& rl,
+ shared_ptr<selected_package>&& p,
+ optional<string>&& mc,
+ optional<string>&& bc,
bool purge,
bool simulate)
{
- tracer trace ("pkg_unpack");
-
- tracer_guard tg (db, trace);
-
- optional<string> mc;
-
- if (!simulate)
- mc = package_checksum (o, d, pi);
-
// Make the package path absolute and normalized. If the package is inside
// the configuration, use the relative path. This way we can move the
// configuration around.
@@ -87,8 +80,6 @@ namespace bpkg
if (d.sub (db.config))
d = d.leaf (db.config);
- shared_ptr<selected_package> p (db.find<selected_package> (n));
-
if (p != nullptr)
{
// Clean up the source directory and archive of the package we are
@@ -117,6 +108,7 @@ namespace bpkg
p->src_root = move (d);
p->purge_src = purge;
p->manifest_checksum = move (mc);
+ p->buildfiles_checksum = move (bc);
db.update (p);
}
@@ -135,6 +127,7 @@ namespace bpkg
move (d),
purge,
move (mc),
+ move (bc),
nullopt, // No output directory yet.
{}}); // No prerequisites captured yet.
@@ -144,7 +137,63 @@ namespace bpkg
assert (p->external ());
t.commit ();
- return p;
+ return move (p);
+ }
+
+ template <typename T>
+ static shared_ptr<selected_package>
+ pkg_unpack (const common_options& o,
+ database& db,
+ transaction& t,
+ package_name n,
+ version v,
+ const vector<T>& deps,
+ const package_info* pi,
+ dir_path d,
+ repository_location rl,
+ bool purge,
+ bool simulate)
+ {
+ tracer trace ("pkg_unpack");
+
+ tracer_guard tg (db, trace);
+
+ shared_ptr<selected_package> p (db.find<selected_package> (n));
+
+ optional<string> mc;
+ optional<string> bc;
+
+ // Only calculate the manifest/subprojects and buildfiles checksums for
+ // external packages (see selected_package::external() for details).
+ //
+ if (!simulate && (rl.empty () || rl.directory_based ()))
+ {
+ mc = package_checksum (o, d, pi);
+
+ // Calculate the buildfiles checksum if the package has any buildfile
+ // clauses in the dependencies. Always calculate it over the buildfiles
+ // since the package is external.
+ //
+ if ((p != nullptr && p->manifest_checksum == mc)
+ ? p->buildfiles_checksum.has_value ()
+ : has_buildfile_clause (deps))
+ bc = package_buildfiles_checksum (nullopt /* bootstrap_build */,
+ nullopt /* root_build */,
+ {} /* buildfiles */,
+ d);
+ }
+
+ return pkg_unpack (db,
+ t,
+ move (n),
+ move (v),
+ move (d),
+ move (rl),
+ move (p),
+ move (mc),
+ move (bc),
+ purge,
+ simulate);
}
shared_ptr<selected_package>
@@ -169,11 +218,18 @@ namespace bpkg
// Verify the directory is a package and get its manifest.
//
package_manifest m (
- pkg_verify (d,
+ pkg_verify (o,
+ d,
true /* ignore_unknown */,
+ false /* ignore_toolchain */,
+ false /* load_buildfiles */,
[&o, &d, &pvi] (version& v)
{
- pvi = package_version (o, d);
+ // Note that we also query subprojects since the package
+ // information will be used for the subsequent
+ // package_iteration() call.
+ //
+ pvi = package_version (o, d, b_info_flags::subprojects);
if (pvi.version)
v = move (*pvi.version);
@@ -205,6 +261,7 @@ namespace bpkg
t,
move (m.name),
move (m.version),
+ m.dependencies,
&pvi.info,
d,
repository_location (),
@@ -232,7 +289,7 @@ namespace bpkg
check_any_available (rdb, t);
- // Note that here we compare including the revision (see pkg-fetch()
+ // Note that here we compare including the revision (see pkg_fetch()
// implementation for more details).
//
shared_ptr<available_package> ap (
@@ -248,7 +305,8 @@ namespace bpkg
for (const package_location& l: ap->locations)
{
- if (l.repository_fragment.load ()->location.directory_based ())
+ if (!rep_masked_fragment (l.repository_fragment) &&
+ l.repository_fragment.load ()->location.directory_based ())
{
pl = &l;
break;
@@ -270,6 +328,7 @@ namespace bpkg
t,
move (n),
move (v),
+ ap->dependencies,
nullptr /* package_info */,
path_cast<dir_path> (rl.path () / pl->location),
rl,
@@ -307,20 +366,22 @@ namespace bpkg
// Also, since we must have verified the archive during fetch,
// here we can just assume what the resulting directory will be.
//
- dir_path d (c / dir_path (p->name.string () + '-' + p->version.string ()));
+ const package_name& n (p->name);
+ const version& v (p->version);
- if (exists (d))
- fail << "package directory " << d << " already exists";
+ dir_path d (c / dir_path (n.string () + '-' + v.string ()));
auto_rmdir arm;
- optional<string> mc;
if (!simulate)
{
+ if (exists (d))
+ fail << "package directory " << d << " already exists";
+
// If the archive path is not absolute, then it must be relative
// to the configuration.
//
- path a (p->archive->absolute () ? *p->archive : c / *p->archive);
+ path a (p->effective_archive (c));
l4 ([&]{trace << "archive: " << a;});
@@ -343,15 +404,11 @@ namespace bpkg
{
fail << "unable to extract " << a << " to " << c << ": " << e;
}
-
- mc = package_checksum (co, d, nullptr /* package_info */);
}
p->src_root = d.leaf (); // For now assuming to be in configuration.
p->purge_src = true;
- p->manifest_checksum = move (mc);
-
p->state = package_state::unpacked;
db.update (p);
@@ -414,7 +471,11 @@ namespace bpkg
// "unpack" it from the directory-based repository.
//
p = v.empty ()
- ? pkg_unpack (o, db, t, n, false /* simulate */)
+ ? pkg_unpack (o,
+ db /* pdb */,
+ t,
+ n,
+ false /* simulate */)
: pkg_unpack (o,
db /* pdb */,
db /* rdb */,