aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2018-11-20 12:38:30 (GMT)
committerKaren Arutyunov <karen@codesynthesis.com>2018-11-27 20:12:33 (GMT)
commit48d1a2bd4d8e3cc2407cc7b696810a0f4910814a (patch)
tree3a5cef2316a786355b0a8828da9dcae5fb1e05b3
parent05912fbf27846af1f4ca1b824cc39815179d430e (diff)
Add support for configuration classes in buildtab
-rw-r--r--libbbot/build-config.cxx34
-rw-r--r--libbbot/build-config.hxx7
-rw-r--r--tests/buildtab/driver.cxx20
-rw-r--r--tests/buildtab/testscript36
4 files changed, 82 insertions, 15 deletions
diff --git a/libbbot/build-config.cxx b/libbbot/build-config.cxx
index 23935e3..de9a71d 100644
--- a/libbbot/build-config.cxx
+++ b/libbbot/build-config.cxx
@@ -12,6 +12,9 @@
#include <libbutl/path.mxx>
#include <libbutl/fdstream.mxx>
#include <libbutl/tab-parser.mxx>
+#include <libbutl/string-parser.mxx>
+
+#include <libbpkg/manifest.hxx> // build_class_term::validate_name()
#include <libbbot/manifest.hxx> // task_manifest::check_config()
@@ -53,7 +56,7 @@ namespace bbot
build_config config;
config.machine_pattern = move (tl[i++].value);
- // Configuration name field is a required one.
+ // Configuration name, target and classes fields are the required ones.
//
if (i == n)
bad_line ("no configuration name found");
@@ -80,6 +83,35 @@ namespace bbot
bad_line (e.what ());
}
+ if (++i == n)
+ bad_line ("no classes found");
+
+ // Parse a potentially quoted class list.
+ //
+ try
+ {
+ // We don't expect the class names be quotes as they cannot contain
+ // spaces.
+ //
+ using namespace string_parser;
+ config.classes = parse_quoted (unquote (tl[i].value),
+ false /* unquote */);
+
+ // Validate the class names.
+ //
+ for (const string& c: config.classes)
+ {
+ if (c == "none")
+ throw invalid_argument ("class 'none' is reserved");
+
+ bpkg::build_class_term::validate_name (c);
+ }
+ }
+ catch (const invalid_argument& e)
+ {
+ bad_line (e.what ());
+ }
+
try
{
for (++i; i < n; ++i)
diff --git a/libbbot/build-config.hxx b/libbbot/build-config.hxx
index 7ff5eba..3f1c0cc 100644
--- a/libbbot/build-config.hxx
+++ b/libbbot/build-config.hxx
@@ -23,10 +23,11 @@ namespace bbot
//
struct build_config
{
- std::string machine_pattern; // Machine name pattern.
- std::string name; // Configuration name.
+ std::string machine_pattern; // Machine name pattern.
+ std::string name; // Configuration name.
butl::target_triplet target;
- std::vector<std::string> vars; // Note: quoting is preserved.
+ std::vector<std::string> classes;
+ std::vector<std::string> vars; // Note: quoting is preserved.
// Warning-detecting regular expressions. Note that quoting is preserved.
//
diff --git a/tests/buildtab/driver.cxx b/tests/buildtab/driver.cxx
index 097b3d9..5242fe4 100644
--- a/tests/buildtab/driver.cxx
+++ b/tests/buildtab/driver.cxx
@@ -26,14 +26,28 @@ try
cin.exceptions (ios::failbit | ios::badbit);
cout.exceptions (ios::failbit | ios::badbit);
- for (const auto& c: parse_buildtab (cin, "cin"))
+ for (const build_config& c: parse_buildtab (cin, "cin"))
{
cout << c.machine_pattern << ' ' << c.name << ' ' << c.target;
- for (const auto& v: c.vars)
+ string classes;
+ for (const string& cs: c.classes)
+ {
+ if (!classes.empty ())
+ classes += ' ';
+
+ classes += cs;
+ }
+
+ if (c.classes.size () > 1)
+ cout << " \"" << classes << '"';
+ else
+ cout << ' ' << classes;
+
+ for (const string& v: c.vars)
cout << ' ' << v;
- for (const auto& r: c.warning_regexes)
+ for (const string& r: c.warning_regexes)
cout << " ~" << r;
cout << '\n';
diff --git a/tests/buildtab/testscript b/tests/buildtab/testscript
index 6adc4bc..511d284 100644
--- a/tests/buildtab/testscript
+++ b/tests/buildtab/testscript
@@ -10,19 +10,31 @@
: all-fileds-combinations
:
$* <<EOF >>EOF
- windows*-vc_14* windows-vc_14-32 i686-microsoft-win32-msvc14.0
- windows*-vc_14* windows-vc_14-32-debug i686-microsoft-win32-msvc14.0 config.cc.coptions=/Z7 config.cc.loptions=/DEBUG ~"warning C4\d{3}: "
+ windows*-vc_14* windows-vc_14-32 i686-microsoft-win32-msvc14.0 default
+ windows*-vc_14* windows-vc_14-32-debug i686-microsoft-win32-msvc14.0 default config.cc.coptions=/Z7 config.cc.loptions=/DEBUG ~"warning C4\d{3}: "
EOF
: empty-lines
:
$* <<EOI >>EOO
- windows*-vc_14* windows-vc_14-32-debug i686-microsoft-win32-msvc14.0
+ windows*-vc_14* windows-vc_14-32-debug i686-microsoft-win32-msvc14.0 default
# abc
EOI
- windows*-vc_14* windows-vc_14-32-debug i686-microsoft-win32-msvc14.0
+ windows*-vc_14* windows-vc_14-32-debug i686-microsoft-win32-msvc14.0 default
EOO
+
+ : single-class
+ :
+ $* <<EOF >>EOF
+ windows*-vc_14* windows-vc_14-32 i686-microsoft-win32-msvc14.0 default
+ EOF
+
+ : multiple-classes
+ :
+ $* <<EOF >>EOF
+ windows*-vc_14* windows-vc_14-32 i686-microsoft-win32-msvc14.0 "all default"
+ EOF
}
: parse-errors
@@ -52,22 +64,30 @@
cin:1:34: error: missing cpu
EOE
+ : invalid-class
+ :
+ $* <<EOI 2>>EOE == 1
+ windows*-vc_14* windows-vc_14-32 i686-microsoft-win32-msvc14.0 a=b
+ EOI
+ cin:1:64: error: class name 'a=b' contains '='
+ EOE
+
: invalid-var
:
{
: unquoted
:
$* <<EOI 2>>EOE == 1
- windows*-vc_14* windows-vc_14-32 i686-microsoft-win32-msvc14.0 config.cc.coptions="/Z7
+ windows*-vc_14* windows-vc_14-32 i686-microsoft-win32-msvc14.0 default config.cc.coptions="/Z7
EOI
- cin:1:87: error: unterminated quoted string
+ cin:1:95: error: unterminated quoted string
EOE
}
: dup-config-name
:
$* <<EOI 2>'cin:2:17: error: duplicate configuration name' == 1
- windows*-vc_14* windows-vc_14-32 i686-microsoft-win32-msvc14.0
- windows*-vc_14* windows-vc_14-32 i686-microsoft-win32-msvc14.0
+ windows*-vc_14* windows-vc_14-32 i686-microsoft-win32-msvc14.0 default
+ windows*-vc_14* windows-vc_14-32 i686-microsoft-win32-msvc14.0 default
EOI
}