diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2017-06-30 02:53:57 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2017-07-03 23:56:29 +0300 |
commit | 17d44ec2c41a5b485cecae51a07396f85a601248 (patch) | |
tree | 5b8f74f8176059c9ab8cbbc770e4b9ee75872f41 /libbrep | |
parent | c2a0ae3e226d1cedceb2a7814c8adfbbfbd7afe1 (diff) |
Fix builds page to correctly display unbuilt package count
Diffstat (limited to 'libbrep')
-rw-r--r-- | libbrep/.gitignore | 2 | ||||
-rw-r--r-- | libbrep/build-extra.sql | 20 | ||||
-rw-r--r-- | libbrep/build-package.hxx | 56 | ||||
-rw-r--r-- | libbrep/build.hxx | 39 | ||||
-rw-r--r-- | libbrep/buildfile | 38 | ||||
-rwxr-xr-x | libbrep/odb.sh | 10 | ||||
-rw-r--r-- | libbrep/package-extra.sql | 2 |
7 files changed, 147 insertions, 20 deletions
diff --git a/libbrep/.gitignore b/libbrep/.gitignore index 3f251f5..48fba7b 100644 --- a/libbrep/.gitignore +++ b/libbrep/.gitignore @@ -5,6 +5,8 @@ package.sql package-extra.hxx build-odb.?xx +build-package-odb.?xx build.sql +build-extra.hxx version.hxx diff --git a/libbrep/build-extra.sql b/libbrep/build-extra.sql new file mode 100644 index 0000000..31736c8 --- /dev/null +++ b/libbrep/build-extra.sql @@ -0,0 +1,20 @@ +-- This file should be parsable by the brep-migrate utility. To decrease the +-- parser complexity, there is a number of restrictions, see package-extra.sql +-- file for details. +-- + +-- The foreign table for build_package object. +-- +-- +DROP FOREIGN TABLE IF EXISTS build_package; + +CREATE FOREIGN TABLE build_package ( + name TEXT NOT NULL, + version_epoch INTEGER NOT NULL, + version_canonical_upstream TEXT NOT NULL, + version_canonical_release TEXT NOT NULL COLLATE "C", + version_revision INTEGER NOT NULL, + version_upstream TEXT NOT NULL, + version_release TEXT NULL, + internal_repository TEXT NULL) +SERVER package_server OPTIONS (table_name 'package'); diff --git a/libbrep/build-package.hxx b/libbrep/build-package.hxx new file mode 100644 index 0000000..b0688c2 --- /dev/null +++ b/libbrep/build-package.hxx @@ -0,0 +1,56 @@ +// file : libbrep/build-package.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef LIBBREP_BUILD_PACKAGE_HXX +#define LIBBREP_BUILD_PACKAGE_HXX + +#include <odb/core.hxx> + +#include <libbrep/types.hxx> +#include <libbrep/utility.hxx> + +#include <libbrep/common.hxx> // Must be included last (see assert). + +namespace brep +{ + // This is a "foreign object" that is mapped to the subset of package object + // using PostgreSQL foreign table mechanism. Note that since we maintain the + // two in sync by hand, we should only a have a minimal subset of "core" + // members (ideally just the primary key) that are unlikly to disappear or + // change. + // + // The mapping is established in build-extra.sql. + // + #pragma db object table("build_package") pointer(shared_ptr) readonly + class build_package + { + public: + package_id id; + upstream_version version; + optional<string> internal_repository; + + // Database mapping. + // + #pragma db member(id) id column("") + #pragma db member(version) set(this.version.init (this.id.version, (?))) + + private: + friend class odb::access; + build_package () = default; + }; + + #pragma db view object(build_package) + struct build_package_count + { + size_t result; + + operator size_t () const {return result;} + + // Database mapping. + // + #pragma db member(result) column("count(" + build_package::id.name + ")") + }; +} + +#endif // LIBBREP_BUILD_PACKAGE_HXX diff --git a/libbrep/build.hxx b/libbrep/build.hxx index dd6f10d..7a231bd 100644 --- a/libbrep/build.hxx +++ b/libbrep/build.hxx @@ -17,7 +17,10 @@ #include <libbrep/types.hxx> #include <libbrep/utility.hxx> -#include <libbrep/common.hxx> // Must be included last (see assert). +// Must be included last (see assert in libbrep/common.hxx). +// +#include <libbrep/common.hxx> +#include <libbrep/build-package.hxx> // Used by the data migration entries. // @@ -261,6 +264,40 @@ namespace brep #pragma db transient canonical_version version_; }; + + // Build of an existing internal package. + // + #pragma db view \ + object(build) \ + object(build_package inner: \ + build::id.package.name == build_package::id.name && \ + brep::compare_version_eq (build::id.package.version, \ + build_package::id.version, \ + true) && \ + build_package::internal_repository.is_not_null ()) + struct package_build + { + shared_ptr<brep::build> build; + }; + + #pragma db view \ + object(build) \ + object(build_package inner: \ + build::id.package.name == build_package::id.name && \ + brep::compare_version_eq (build::id.package.version, \ + build_package::id.version, \ + true) && \ + build_package::internal_repository.is_not_null ()) + struct package_build_count + { + size_t result; + + operator size_t () const {return result;} + + // Database mapping. + // + #pragma db member(result) column("count(" + build::id.package.name + ")") + }; } #endif // LIBBREP_BUILD_HXX diff --git a/libbrep/buildfile b/libbrep/buildfile index b4005ab..1403756 100644 --- a/libbrep/buildfile +++ b/libbrep/buildfile @@ -12,24 +12,26 @@ import int_libs += libbutl%lib{butl} import int_libs += libbpkg%lib{bpkg} import int_libs += libbbot%lib{bbot} -lib{brep}: \ -{hxx cxx}{ build } \ -{file }{ build.xml } \ -{hxx ixx cxx}{ build-odb } \ -{hxx cxx}{ common } \ -{hxx ixx cxx}{ common-odb } \ -{hxx cxx}{ package } \ -{file }{ package.xml } \ -{hxx ixx cxx}{ package-odb } \ -{hxx }{ package-extra } \ -{hxx cxx}{ package-traits } \ -{hxx cxx}{ database-lock } \ -{hxx }{ types } \ -{hxx }{ utility } \ -{hxx }{ version } \ -{hxx }{ wrapper-traits } \ - $int_libs \ -sql{build package package-extra} +lib{brep}: \ +{hxx cxx}{ build } \ +{file }{ build.xml } \ +{hxx ixx cxx}{ build-odb } \ +{hxx }{ build-package } \ +{hxx ixx cxx}{ build-package-odb } \ +{hxx cxx}{ common } \ +{hxx ixx cxx}{ common-odb } \ +{hxx cxx}{ package } \ +{file }{ package.xml } \ +{hxx ixx cxx}{ package-odb } \ +{hxx }{ package-extra } \ +{hxx cxx}{ package-traits } \ +{hxx cxx}{ database-lock } \ +{hxx }{ types } \ +{hxx }{ utility } \ +{hxx }{ version } \ +{hxx }{ wrapper-traits } \ + $int_libs \ +sql{build build-extra package package-extra} hxx{version}: in{version} $src_root/file{manifest} hxx{version}: dist = true diff --git a/libbrep/odb.sh b/libbrep/odb.sh index 2897afa..5f5a783 100755 --- a/libbrep/odb.sh +++ b/libbrep/odb.sh @@ -38,3 +38,13 @@ $odb $lib -d pgsql --std c++11 --generate-query --generate-schema \ --include-with-brackets --include-prefix libbrep \ --guard-prefix LIBBREP \ build.hxx + +$odb $lib -d pgsql --std c++11 --generate-query \ + --odb-epilogue '#include <libbrep/wrapper-traits.hxx>' \ + --generate-prepared -DLIBODB_BUILD2 -DLIBODB_PGSQL_BUILD2 \ + -I .. -I ../../libbbot -I ../../libbpkg -I ../../libbutl \ + --include-with-brackets --include-prefix libbrep \ + --guard-prefix LIBBREP \ + build-package.hxx + +xxd -i <build-extra.sql >build-extra.hxx diff --git a/libbrep/package-extra.sql b/libbrep/package-extra.sql index 823c3af..5c18da2 100644 --- a/libbrep/package-extra.sql +++ b/libbrep/package-extra.sql @@ -3,7 +3,7 @@ -- -- * comments must start with -- at the beginning of the line (ignoring -- leading spaces) --- * only CREATE and DROP statements for FUNCTION and TYPE +-- * only CREATE and DROP statements for FUNCTION, TYPE and FOREIGN TABLE -- * function bodies must be defined using $$-quoted strings -- * strings other then function bodies must be quoted with ' or " -- * statements must end with ";\n" |