From b07c40f8a457bbb8f7f2d4d142e5e5e974465e25 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 3 Jun 2022 12:21:26 +0200 Subject: Initial up_negotiate_configuration() implementation --- bpkg/package-configuration.hxx | 119 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 bpkg/package-configuration.hxx (limited to 'bpkg/package-configuration.hxx') diff --git a/bpkg/package-configuration.hxx b/bpkg/package-configuration.hxx new file mode 100644 index 0000000..55a43a5 --- /dev/null +++ b/bpkg/package-configuration.hxx @@ -0,0 +1,119 @@ +// file : bpkg/package-configuration.hxx -*- C++ -*- +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_PACKAGE_CONFIGURATION_HXX +#define BPKG_PACKAGE_CONFIGURATION_HXX + +#include + +#include // build2::names +#include // build2::config::variable_origin + +#include +#include + +#include + +using namespace std; + +namespace bpkg +{ + class package_skeleton; + + struct config_variable_value + { + string name; + + // The variable_origin values have the following meaning: + // + // default -- default value from the config directive + // buildfile -- dependent configuration (config_source::dependent) + // override -- user configuration (config_source::user) + // undefined -- none of the above + // + build2::config::variable_origin origin; + + // If origin is not undefined, then this is the reversed variable value + // with absent signifying NULL. + // + optional value; + + // Variable type name with absent signifying untyped. + // + optional type; + + // If origin is buildfile, then this is the "originating dependent" which + // first set this variable to this value. + // + optional dependent; + + // Value version (used internally by package_skeleton). + // + size_t version; + }; + + class package_configuration: public vector + { + public: + config_variable_value* + find (const string& name) + { + auto i (find_if (begin (), end (), + [&name] (const config_variable_value& v) + { + return v.name == name; + })); + return i != end () ? &*i : nullptr; + } + + const config_variable_value* + find (const string& name) const + { + auto i (find_if (begin (), end (), + [&name] (const config_variable_value& v) + { + return v.name == name; + })); + return i != end () ? &*i : nullptr; + } + }; + + + // @@ Maybe redo as small_vector? + // + using package_configurations = map; + + + // A subset of config_variable_value for variable values set by the + // dependents (origin is buildfile). Used to track change history. + // + struct dependent_config_variable_value + { + string name; + optional value; + package_key dependent; + }; + + class dependent_config_variable_values: + public small_vector + { + public: + /* + @@ + void + sort (); + */ + }; + + // Up-negotiate the configuration for the specified dependencies of the + // specified dependent. Return true if the configuration has changed. + // + bool + up_negotiate_configuration ( + package_configurations&, + package_skeleton& dependent, + pair position, + const small_vector, 1>& dependencies); +} + +#endif // BPKG_PACKAGE_CONFIGURATION_HXX -- cgit v1.1