aboutsummaryrefslogtreecommitdiff
path: root/mod/build-config-module.hxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2018-12-07 23:12:05 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2018-12-11 14:05:48 +0300
commit294c558d577cd4acb2ee8e94e0dfd6acdb946c6c (patch)
tree02742141dad6cf91040eb48eca54b718dee8ad55 /mod/build-config-module.hxx
parent7dabb6e931740b2777be5dca53c3cec0b984f0fb (diff)
Add support for build configuration class inheritance
Diffstat (limited to 'mod/build-config-module.hxx')
-rw-r--r--mod/build-config-module.hxx96
1 files changed, 96 insertions, 0 deletions
diff --git a/mod/build-config-module.hxx b/mod/build-config-module.hxx
new file mode 100644
index 0000000..bd6e0b0
--- /dev/null
+++ b/mod/build-config-module.hxx
@@ -0,0 +1,96 @@
+// file : mod/build-config-module.hxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2018 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#ifndef MOD_BUILD_CONFIG_MODULE_HXX
+#define MOD_BUILD_CONFIG_MODULE_HXX
+
+#include <map>
+#include <algorithm> // find()
+
+#include <libbutl/utility.mxx> // compare_c_string
+
+#include <libbpkg/manifest.hxx>
+
+#include <libbbot/build-config.hxx>
+
+#include <libbrep/types.hxx>
+#include <libbrep/utility.hxx>
+
+#include <mod/module.hxx>
+#include <mod/options.hxx>
+
+// Base class for modules that utilize the build controller configuration.
+//
+// Specifically, it loads build controller configuration and provides various
+// build configuration-related utilities. Note that the configuration is
+// shared across multiple modules once loaded.
+//
+// Note that the build database is in the database_module.
+//
+namespace brep
+{
+ class build_config_module
+ {
+ protected:
+ // Parse build configuration file and establish mapping of build bot agent
+ // public keys fingerprints to their paths. Throw tab_parsing on parsing
+ // error, system_error on the underlying OS error.
+ //
+ void
+ init (const options::build&);
+
+ // Return true if the specified build configuration is excluded by a
+ // package based on its underlying build class set, build class
+ // expressions, and build constraints, potentially extending the
+ // underlying set with the special classes. Set the exclusion reason if
+ // requested.
+ //
+ bool
+ exclude (const vector<bpkg::build_class_expr>&,
+ const vector<bpkg::build_constraint>&,
+ const bbot::build_config&,
+ string* reason = nullptr) const;
+
+ // Check if the configuration belongs to the specified class.
+ //
+ // Note that the configuration base classes are not checked.
+ //
+ static bool
+ belongs (const bbot::build_config& cfg, const char* cls)
+ {
+ const strings& cs (cfg.classes);
+ return std::find (cs.begin (), cs.end (), cls) != cs.end ();
+ }
+
+ // Convert dash-separated components (target, build configuration name,
+ // machine name) or a pattern thereof into a path, replacing dashes with
+ // slashes (directory separators), `**` with `*/**/*`, and appending the
+ // trailing slash for a subsequent match using the path_match()
+ // functionality (the idea here is for `linux**` to match `linux-gcc`
+ // which is quite natural to expect). Throw invalid_path if the resulting
+ // path is invalid.
+ //
+ // Note that the match_absent path match flag must be used for the above
+ // `**` transformation to work.
+ //
+ static path
+ dash_components_to_path (const string&);
+
+ protected:
+ // Build configurations.
+ //
+ shared_ptr<const bbot::build_configs> build_conf_;
+ shared_ptr<const cstrings> build_conf_names_;
+
+ shared_ptr<const std::map<const char*,
+ const bbot::build_config*,
+ butl::compare_c_string>> build_conf_map_;
+
+ // Map of build bot agent public keys fingerprints to the key file paths.
+ //
+ shared_ptr<const std::map<string, path>> bot_agent_key_map_;
+ };
+}
+
+#endif // MOD_BUILD_CONFIG_MODULE_HXX