From da89007801070651f592575f73dd4130dc324998 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 14 Feb 2022 11:58:58 +0200 Subject: Implement package skeleton loading and enable and reflect clauses evaluation --- bpkg/package-skeleton.hxx | 96 ++++++++++++++++------------------------------- 1 file changed, 33 insertions(+), 63 deletions(-) (limited to 'bpkg/package-skeleton.hxx') diff --git a/bpkg/package-skeleton.hxx b/bpkg/package-skeleton.hxx index 1a56bfb..c4c59cc 100644 --- a/bpkg/package-skeleton.hxx +++ b/bpkg/package-skeleton.hxx @@ -19,14 +19,14 @@ namespace bpkg class package_skeleton { public: - // If the package is external and will not be disfigured, then the - // existing package source root directory needs to be specified. In this - // case this source directory and the automatically deduced potentially - // non-existent out root directory will be used for build2 state loading - // instead of the newly created skeleton directory. This, in particular, - // makes sure we take into account the existing configuration variables - // while evaluating the dependency clauses (this logic is "parallel" to - // the configuration preservation in pkg-build.cxx). + // If the package is external, then the existing package source root + // directory needs to be specified (as absolute and normalized). In this + // case, if output root is specified (as absolute and normalized; normally + // /), then it's used as is. Otherwise, an empty + // skeleton directory is used as output root. + // + // If the package is not external, then none of the root directories + // should be specified. // // Note that the database and available_package are expected to outlive // this object. @@ -34,70 +34,38 @@ namespace bpkg // Note also that this creates an "unloaded" skeleton and is therefore // cheap. // - // @@ Note that storing the list of configuration variables by reference - // complicates its use in pkg-build, where both the configuration and - // the optional skeleton are parts of the same copyable/moveable - // build_package object. We could probably move the configuration into - // the skeleton if create it, complicating an access to the - // configuration for the users (if the skeleton is present then get - // configuration from it, etc). Let's however keep it simple for now - // and just copy the configuration. - // package_skeleton (database&, const available_package&, - const strings& cvs, - optional src_root); + strings config_vars, + optional src_root, + optional out_root); - // Evaluate the enable clause. + // For the following evaluate_*() functions assume that the clause belongs + // to the specified (by index) depends value (used to print its location + // on failure for an external package). // - // @@ What can we pass as location? Maybe somehow point to manifest in the - // skeleton (will need to re-acquire the position somehow)? + // Evaluate the enable clause. // bool - evaluate_enable (const string&) - { - // @@ TMP - // - fail << "conditional dependency for package " << name () << - info << "conditional dependencies are not yet supported"; - - load (); - - // TODO - - return true; // @@ TMP - } + evaluate_enable (const string&, size_t depends_index); // Evaluate the reflect clause. // void - evaluate_reflect (const string& r) - { - load (); - - // TODO - - // @@ DEP For now we assume that the reflection, if present, contains - // a single configuration variable that assigns a literal value. - // - reflect_.push_back (r); - - // Mark the build system state as needing reloading since some computed - // values in root.build may depend on the new configuration values. - // - dirty_ = true; - } + evaluate_reflect (const string&, size_t depends_index); // Return the accumulated reflect values. // + // Note that the result is merged with config_vars and you should be used + // instead rather than in addition to config_vars. + // + // Note also that this should be the final call on this object. + // strings - collect_reflect () - { - return reflect_; - } + collect_reflect () &&; const package_name& - name () const {return available_.get ().id.name;} + name () const {return available_->id.name;} // Implementation details. // @@ -116,24 +84,26 @@ namespace bpkg // // Call this function before evaluating every clause. // - void + build2::scope& load (); private: // NOTE: remember to update move/copy constructors! // - reference_wrapper db_; - reference_wrapper available_; + database* db_; + const available_package* available_; strings config_vars_; - dir_path src_root_; + dir_path src_root_; // Must be absolute and normalized. dir_path out_root_; // If empty, the same as src_root_. - unique_ptr ctx_; bool created_ = false; - bool dirty_ = false; + unique_ptr ctx_; + build2::scope* rs_ = nullptr; - strings reflect_; + strings reflect_names_; // Reflect configuration variable names. + strings reflect_vars_; // Reflect configuration variable overrides. + string reflect_frag_; // Reflect configuration variable fragment. }; } -- cgit v1.1