From 2319d01e262b705716e19474865f555f3ca81a7d Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 1 May 2017 13:50:13 +0300 Subject: Add hxx extension for headers and lib prefix for library dirs --- bpkg/.gitignore | 6 +- bpkg/archive | 40 - bpkg/archive.cxx | 4 +- bpkg/archive.hxx | 40 + bpkg/auth | 104 --- bpkg/auth.cxx | 12 +- bpkg/auth.hxx | 104 +++ bpkg/bpkg.cxx | 54 +- bpkg/buildfile | 8 +- bpkg/cfg-create | 19 - bpkg/cfg-create.cxx | 10 +- bpkg/cfg-create.hxx | 19 + bpkg/checksum | 32 - bpkg/checksum.cxx | 4 +- bpkg/checksum.hxx | 32 + bpkg/common.cli | 4 +- bpkg/database | 82 -- bpkg/database.cxx | 10 +- bpkg/database.hxx | 82 ++ bpkg/diagnostics | 240 ------ bpkg/diagnostics.cxx | 2 +- bpkg/diagnostics.hxx | 240 ++++++ bpkg/fetch | 45 - bpkg/fetch.cxx | 6 +- bpkg/fetch.hxx | 45 + bpkg/forward | 20 - bpkg/forward.hxx | 20 + bpkg/help | 21 - bpkg/help.cxx | 8 +- bpkg/help.hxx | 21 + bpkg/manifest-utility | 45 - bpkg/manifest-utility.cxx | 4 +- bpkg/manifest-utility.hxx | 45 + bpkg/odb.sh | 13 +- bpkg/openssl | 31 - bpkg/openssl.cxx | 4 +- bpkg/openssl.hxx | 31 + bpkg/options-types | 18 - bpkg/options-types.hxx | 18 + bpkg/package | 916 -------------------- bpkg/package.cxx | 6 +- bpkg/package.hxx | 917 +++++++++++++++++++++ bpkg/pkg-build | 19 - bpkg/pkg-build.cxx | 38 +- bpkg/pkg-build.hxx | 19 + bpkg/pkg-clean | 23 - bpkg/pkg-clean.hxx | 23 + bpkg/pkg-command | 37 - bpkg/pkg-command.cxx | 10 +- bpkg/pkg-command.hxx | 37 + bpkg/pkg-configure | 35 - bpkg/pkg-configure.cxx | 18 +- bpkg/pkg-configure.hxx | 35 + bpkg/pkg-disfigure | 32 - bpkg/pkg-disfigure.cxx | 10 +- bpkg/pkg-disfigure.hxx | 32 + bpkg/pkg-drop | 33 - bpkg/pkg-drop.cxx | 20 +- bpkg/pkg-drop.hxx | 33 + bpkg/pkg-fetch | 42 - bpkg/pkg-fetch.cxx | 22 +- bpkg/pkg-fetch.hxx | 42 + bpkg/pkg-install | 24 - bpkg/pkg-install.hxx | 24 + bpkg/pkg-purge | 38 - bpkg/pkg-purge.cxx | 10 +- bpkg/pkg-purge.hxx | 38 + bpkg/pkg-status | 19 - bpkg/pkg-status.cxx | 12 +- bpkg/pkg-status.hxx | 19 + bpkg/pkg-test | 23 - bpkg/pkg-test.hxx | 23 + bpkg/pkg-uninstall | 24 - bpkg/pkg-uninstall.hxx | 24 + bpkg/pkg-unpack | 37 - bpkg/pkg-unpack.cxx | 16 +- bpkg/pkg-unpack.hxx | 37 + bpkg/pkg-update | 33 - bpkg/pkg-update.hxx | 33 + bpkg/pkg-verify | 39 - bpkg/pkg-verify.cxx | 6 +- bpkg/pkg-verify.hxx | 39 + bpkg/rep-add | 19 - bpkg/rep-add.cxx | 12 +- bpkg/rep-add.hxx | 19 + bpkg/rep-create | 19 - bpkg/rep-create.cxx | 16 +- bpkg/rep-create.hxx | 19 + bpkg/rep-fetch | 19 - bpkg/rep-fetch.cxx | 16 +- bpkg/rep-fetch.hxx | 19 + bpkg/rep-info | 19 - bpkg/rep-info.cxx | 14 +- bpkg/rep-info.hxx | 19 + bpkg/repository-signing.cli | 2 +- bpkg/satisfaction | 50 -- bpkg/satisfaction.cxx | 8 +- bpkg/satisfaction.hxx | 50 ++ bpkg/system-repository | 55 -- bpkg/system-repository.cxx | 2 +- bpkg/system-repository.hxx | 55 ++ bpkg/types | 104 --- bpkg/types-parsers | 46 -- bpkg/types-parsers.cxx | 4 +- bpkg/types-parsers.hxx | 46 ++ bpkg/types.hxx | 104 +++ bpkg/utility | 121 --- bpkg/utility.cxx | 6 +- bpkg/utility.hxx | 121 +++ bpkg/version-impl.in | 95 --- bpkg/version.hxx.in | 95 +++ bpkg/wrapper-traits | 59 -- bpkg/wrapper-traits.hxx | 59 ++ build/root.build | 2 +- tests/.gitignore | 2 + tests/common/bar/stable/libbar-1.0.0.tar.gz | Bin 957 -> 995 bytes tests/common/bar/testing/libbar-1.1.0.tar.gz | Bin 959 -> 994 bytes tests/common/bar/unstable/libbar-1.1.1.tar.gz | Bin 1189 -> 1220 bytes tests/common/foo/stable/libfoo-1.0.0.tar.gz | Bin 881 -> 904 bytes tests/common/foo/testing/libfoo-1.1.0.tar.gz | Bin 874 -> 899 bytes tests/common/hello/libhello-1.0.0.tar.gz | Bin 2362 -> 2414 bytes tests/common/libhello-1.0.0/build/export.build | 4 +- tests/common/libhello-1.0.0/build/root.build | 2 +- tests/common/libhello-1.0.0/buildfile | 2 +- tests/common/libhello-1.0.0/hello/buildfile | 21 - tests/common/libhello-1.0.0/hello/export | 36 - tests/common/libhello-1.0.0/hello/hello | 13 - tests/common/libhello-1.0.0/hello/hello.cxx | 16 - tests/common/libhello-1.0.0/libhello/buildfile | 21 + tests/common/libhello-1.0.0/libhello/export.hxx | 36 + tests/common/libhello-1.0.0/libhello/hello.cxx | 16 + tests/common/libhello-1.0.0/libhello/hello.hxx | 13 + tests/common/libhello-1.0.0/tests/.gitignore | 1 + tests/common/libhello-1.0.0/tests/build/root.build | 2 +- tests/common/libhello-1.0.0/tests/test/driver.cxx | 2 +- 135 files changed, 2972 insertions(+), 2969 deletions(-) delete mode 100644 bpkg/archive create mode 100644 bpkg/archive.hxx delete mode 100644 bpkg/auth create mode 100644 bpkg/auth.hxx delete mode 100644 bpkg/cfg-create create mode 100644 bpkg/cfg-create.hxx delete mode 100644 bpkg/checksum create mode 100644 bpkg/checksum.hxx delete mode 100644 bpkg/database create mode 100644 bpkg/database.hxx delete mode 100644 bpkg/diagnostics create mode 100644 bpkg/diagnostics.hxx delete mode 100644 bpkg/fetch create mode 100644 bpkg/fetch.hxx delete mode 100644 bpkg/forward create mode 100644 bpkg/forward.hxx delete mode 100644 bpkg/help create mode 100644 bpkg/help.hxx delete mode 100644 bpkg/manifest-utility create mode 100644 bpkg/manifest-utility.hxx delete mode 100644 bpkg/openssl create mode 100644 bpkg/openssl.hxx delete mode 100644 bpkg/options-types create mode 100644 bpkg/options-types.hxx delete mode 100644 bpkg/package create mode 100644 bpkg/package.hxx delete mode 100644 bpkg/pkg-build create mode 100644 bpkg/pkg-build.hxx delete mode 100644 bpkg/pkg-clean create mode 100644 bpkg/pkg-clean.hxx delete mode 100644 bpkg/pkg-command create mode 100644 bpkg/pkg-command.hxx delete mode 100644 bpkg/pkg-configure create mode 100644 bpkg/pkg-configure.hxx delete mode 100644 bpkg/pkg-disfigure create mode 100644 bpkg/pkg-disfigure.hxx delete mode 100644 bpkg/pkg-drop create mode 100644 bpkg/pkg-drop.hxx delete mode 100644 bpkg/pkg-fetch create mode 100644 bpkg/pkg-fetch.hxx delete mode 100644 bpkg/pkg-install create mode 100644 bpkg/pkg-install.hxx delete mode 100644 bpkg/pkg-purge create mode 100644 bpkg/pkg-purge.hxx delete mode 100644 bpkg/pkg-status create mode 100644 bpkg/pkg-status.hxx delete mode 100644 bpkg/pkg-test create mode 100644 bpkg/pkg-test.hxx delete mode 100644 bpkg/pkg-uninstall create mode 100644 bpkg/pkg-uninstall.hxx delete mode 100644 bpkg/pkg-unpack create mode 100644 bpkg/pkg-unpack.hxx delete mode 100644 bpkg/pkg-update create mode 100644 bpkg/pkg-update.hxx delete mode 100644 bpkg/pkg-verify create mode 100644 bpkg/pkg-verify.hxx delete mode 100644 bpkg/rep-add create mode 100644 bpkg/rep-add.hxx delete mode 100644 bpkg/rep-create create mode 100644 bpkg/rep-create.hxx delete mode 100644 bpkg/rep-fetch create mode 100644 bpkg/rep-fetch.hxx delete mode 100644 bpkg/rep-info create mode 100644 bpkg/rep-info.hxx delete mode 100644 bpkg/satisfaction create mode 100644 bpkg/satisfaction.hxx delete mode 100644 bpkg/system-repository create mode 100644 bpkg/system-repository.hxx delete mode 100644 bpkg/types delete mode 100644 bpkg/types-parsers create mode 100644 bpkg/types-parsers.hxx create mode 100644 bpkg/types.hxx delete mode 100644 bpkg/utility create mode 100644 bpkg/utility.hxx delete mode 100644 bpkg/version-impl.in create mode 100644 bpkg/version.hxx.in delete mode 100644 bpkg/wrapper-traits create mode 100644 bpkg/wrapper-traits.hxx create mode 100644 tests/.gitignore delete mode 100644 tests/common/libhello-1.0.0/hello/buildfile delete mode 100644 tests/common/libhello-1.0.0/hello/export delete mode 100644 tests/common/libhello-1.0.0/hello/hello delete mode 100644 tests/common/libhello-1.0.0/hello/hello.cxx create mode 100644 tests/common/libhello-1.0.0/libhello/buildfile create mode 100644 tests/common/libhello-1.0.0/libhello/export.hxx create mode 100644 tests/common/libhello-1.0.0/libhello/hello.cxx create mode 100644 tests/common/libhello-1.0.0/libhello/hello.hxx create mode 100644 tests/common/libhello-1.0.0/tests/.gitignore diff --git a/bpkg/.gitignore b/bpkg/.gitignore index dde5e32..f72601d 100644 --- a/bpkg/.gitignore +++ b/bpkg/.gitignore @@ -1,8 +1,6 @@ bpkg -*-options *-options.?xx -*-odb *-odb.?xx -repository-signing +repository-signing.hxx repository-signing.cxx -version-impl +version.hxx diff --git a/bpkg/archive b/bpkg/archive deleted file mode 100644 index 1f33538..0000000 --- a/bpkg/archive +++ /dev/null @@ -1,40 +0,0 @@ -// file : bpkg/archive -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_ARCHIVE -#define BPKG_ARCHIVE - -#include - -#include -#include - -#include - -namespace bpkg -{ - // Return the package directory based on the package archive. - // - dir_path - package_dir (const path& archive); - - // Start the process of extracting the specified file from the archive. If - // error is false, then redirect STDERR to /dev/null (this can be used, for - // example, to suppress diagnostics). - // - // Return a pair of processes that form a pipe. Wait on the second first. - // - pair - start_extract (const common_options&, - const path& archive, - const path& file, - bool error = true); - - // Start as above and then extract the file content as a string. - // - string - extract (const common_options&, const path& archive, const path& file); -} - -#endif // BPKG_ARCHIVE diff --git a/bpkg/archive.cxx b/bpkg/archive.cxx index 54ab8ea..4ad996f 100644 --- a/bpkg/archive.cxx +++ b/bpkg/archive.cxx @@ -2,12 +2,12 @@ // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include +#include #include #include -#include +#include using namespace std; using namespace butl; diff --git a/bpkg/archive.hxx b/bpkg/archive.hxx new file mode 100644 index 0000000..44f7a7b --- /dev/null +++ b/bpkg/archive.hxx @@ -0,0 +1,40 @@ +// file : bpkg/archive.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_ARCHIVE_HXX +#define BPKG_ARCHIVE_HXX + +#include + +#include +#include + +#include + +namespace bpkg +{ + // Return the package directory based on the package archive. + // + dir_path + package_dir (const path& archive); + + // Start the process of extracting the specified file from the archive. If + // error is false, then redirect STDERR to /dev/null (this can be used, for + // example, to suppress diagnostics). + // + // Return a pair of processes that form a pipe. Wait on the second first. + // + pair + start_extract (const common_options&, + const path& archive, + const path& file, + bool error = true); + + // Start as above and then extract the file content as a string. + // + string + extract (const common_options&, const path& archive, const path& file); +} + +#endif // BPKG_ARCHIVE_HXX diff --git a/bpkg/auth b/bpkg/auth deleted file mode 100644 index 5c32824..0000000 --- a/bpkg/auth +++ /dev/null @@ -1,104 +0,0 @@ -// file : bpkg/auth -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_AUTH -#define BPKG_AUTH - -#include - -#include -#include - -#include -#include - -namespace bpkg -{ - // Authenticate a repository certificate. If the configuration directory is - // NULL, then perform without a certificate database. If it is empty, then - // check if the current working directory is a configuration. If it is, then - // use its certificate database. Otherwise, continue as if it was NULL. All - // other values (including '.') are assumed to be valid configuration paths - // and will be diagnosed if that's not the case. - // - // If the configuration is used, then check if we are already in transaction. - // If so, then assume the configuration database is already opened and use - // that. Otherwise, open the database and start a new transaction. - // - // Note that one drawback of doing this as part of an existing transaction - // is that if things go south and the transaction gets aborted, then all the - // user's confirmations will be lost. For example, rep-fetch could fail - // because it was unable to fetch some prerequisite repositories. - // - shared_ptr - authenticate_certificate (const common_options&, - const dir_path* configuration, - const optional& cert_pem, - const repository_location&); - - // Authenticate a repository. First check that the certificate can be used - // to authenticate this repository by making sure their names match. Then - // recover the packages manifest file SHA256 checksum from the signature - // and compare the calculated checksum to the recovered one. - // - // If the configuration directory is NULL, then create a temporary - // certificate PEM file (cert_pem must be present). If the directory is - // empty, then check if the current working directory is a configuration. - // If it's not, then continue as if it was NULL (cert_pem must be present). - // If it is, then continue as if a valid configuration directory was - // specified. All other values (including '.') are assumed to be valid - // configuration paths and will be diagnosed if that's not the case. In the - // case of a valid configuration use the certificate PEM file from the - // configuration (the file is supposed to have been created by the preceding - // authenticate_certificate() call). - // - void - authenticate_repository (const common_options&, - const dir_path* configuration, - const optional& cert_pem, - const certificate&, - const signature_manifest&, - const repository_location&); - - // Sign a repository by calculating its packages manifest file signature. - // This is done by encrypting the file's SHA256 checksum with the repository - // certificate's private key and then base64-encoding the result. Issue - // diagnstics and fail if the certificate has expired, and issue a warning - // if it expires in less than 2 months. The repository argument is used for - // diagnostics only. - // - // Note that currently we don't check if the key matches the certificate. A - // relatively easy way to accomplish this would be to execute the following - // commands and match the results: - // - // openssl x509 -noout -modulus -in cert.pem - // openssl rsa -noout -modulus -in key.pem - // - // But taking into account that we need to be able to use custom engines to - // access keys, it seems to be impossible to provide the same additional - // openssl options to fit both the rsa and pkeyutl commands. The first would - // require "-engine pkcs11 -inform engine", while the second -- "-engine - // pkcs11 -keyform engine". Also it would require to enter the key password - // again, which is a showstopper. Maybe the easiest would be to recover the - // sum back from the signature using the certificate, and compare it with - // the original sum (like we do in authenticate_repository()). But that - // would require to temporarily save the certificate to file. - // - std::vector - sign_repository (const common_options&, - const string& sha256sum, - const string& key_name, // --key option value - const string& cert_pem, - const dir_path& repository); - - // Parse a repository certificate. The repository location argument is used - // for diagnostics only. - // - shared_ptr - parse_certificate (const common_options&, - const string& cert_pem, - const repository_location&); -} - -#endif // BPKG_AUTH diff --git a/bpkg/auth.cxx b/bpkg/auth.cxx index bafc321..7cba934 100644 --- a/bpkg/auth.cxx +++ b/bpkg/auth.cxx @@ -2,7 +2,7 @@ // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include +#include #include #include // numeric_limits @@ -15,11 +15,11 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include using namespace std; using namespace butl; diff --git a/bpkg/auth.hxx b/bpkg/auth.hxx new file mode 100644 index 0000000..90f60e4 --- /dev/null +++ b/bpkg/auth.hxx @@ -0,0 +1,104 @@ +// file : bpkg/auth.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_AUTH_HXX +#define BPKG_AUTH_HXX + +#include + +#include +#include + +#include +#include + +namespace bpkg +{ + // Authenticate a repository certificate. If the configuration directory is + // NULL, then perform without a certificate database. If it is empty, then + // check if the current working directory is a configuration. If it is, then + // use its certificate database. Otherwise, continue as if it was NULL. All + // other values (including '.') are assumed to be valid configuration paths + // and will be diagnosed if that's not the case. + // + // If the configuration is used, then check if we are already in transaction. + // If so, then assume the configuration database is already opened and use + // that. Otherwise, open the database and start a new transaction. + // + // Note that one drawback of doing this as part of an existing transaction + // is that if things go south and the transaction gets aborted, then all the + // user's confirmations will be lost. For example, rep-fetch could fail + // because it was unable to fetch some prerequisite repositories. + // + shared_ptr + authenticate_certificate (const common_options&, + const dir_path* configuration, + const optional& cert_pem, + const repository_location&); + + // Authenticate a repository. First check that the certificate can be used + // to authenticate this repository by making sure their names match. Then + // recover the packages manifest file SHA256 checksum from the signature + // and compare the calculated checksum to the recovered one. + // + // If the configuration directory is NULL, then create a temporary + // certificate PEM file (cert_pem must be present). If the directory is + // empty, then check if the current working directory is a configuration. + // If it's not, then continue as if it was NULL (cert_pem must be present). + // If it is, then continue as if a valid configuration directory was + // specified. All other values (including '.') are assumed to be valid + // configuration paths and will be diagnosed if that's not the case. In the + // case of a valid configuration use the certificate PEM file from the + // configuration (the file is supposed to have been created by the preceding + // authenticate_certificate() call). + // + void + authenticate_repository (const common_options&, + const dir_path* configuration, + const optional& cert_pem, + const certificate&, + const signature_manifest&, + const repository_location&); + + // Sign a repository by calculating its packages manifest file signature. + // This is done by encrypting the file's SHA256 checksum with the repository + // certificate's private key and then base64-encoding the result. Issue + // diagnstics and fail if the certificate has expired, and issue a warning + // if it expires in less than 2 months. The repository argument is used for + // diagnostics only. + // + // Note that currently we don't check if the key matches the certificate. A + // relatively easy way to accomplish this would be to execute the following + // commands and match the results: + // + // openssl x509 -noout -modulus -in cert.pem + // openssl rsa -noout -modulus -in key.pem + // + // But taking into account that we need to be able to use custom engines to + // access keys, it seems to be impossible to provide the same additional + // openssl options to fit both the rsa and pkeyutl commands. The first would + // require "-engine pkcs11 -inform engine", while the second -- "-engine + // pkcs11 -keyform engine". Also it would require to enter the key password + // again, which is a showstopper. Maybe the easiest would be to recover the + // sum back from the signature using the certificate, and compare it with + // the original sum (like we do in authenticate_repository()). But that + // would require to temporarily save the certificate to file. + // + std::vector + sign_repository (const common_options&, + const string& sha256sum, + const string& key_name, // --key option value + const string& cert_pem, + const dir_path& repository); + + // Parse a repository certificate. The repository location argument is used + // for diagnostics only. + // + shared_ptr + parse_certificate (const common_options&, + const string& cert_pem, + const repository_location&); +} + +#endif // BPKG_AUTH_HXX diff --git a/bpkg/bpkg.cxx b/bpkg/bpkg.cxx index e78e732..86f86db 100644 --- a/bpkg/bpkg.cxx +++ b/bpkg/bpkg.cxx @@ -11,37 +11,37 @@ #include // strcmp() #include -#include -#include +#include +#include -#include -#include +#include +#include // Commands. // -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include using namespace std; using namespace bpkg; diff --git a/bpkg/buildfile b/bpkg/buildfile index 1ed635b..b7532f5 100644 --- a/bpkg/buildfile +++ b/bpkg/buildfile @@ -50,12 +50,12 @@ exe{bpkg}: \ {hxx }{ types } \ {hxx cxx}{ types-parsers } \ {hxx cxx}{ utility } \ -{hxx }{ version-impl } \ +{hxx }{ version } \ {hxx }{ wrapper-traits } \ $libs -hxx{version-impl}: in{version-impl} $src_root/file{manifest} -hxx{version-impl}: dist = true +hxx{version}: in{version} $src_root/file{manifest} +hxx{version}: dist = true # Disable "unknown pragma" warnings. # @@ -114,7 +114,7 @@ if $cli.configured # Option length must be the same to get commands/topics/options aligned. # cli.options += -I $src_root --include-with-brackets --include-prefix bpkg \ ---guard-prefix BPKG --cxx-prologue "#include " \ +--guard-prefix BPKG --cxx-prologue "#include " \ --cli-namespace bpkg::cli --generate-vector-scanner --generate-file-scanner \ --generate-specifier --generate-parse --page-usage 'bpkg::print_$name$_' \ --ansi-color --include-base-last --option-length 23 diff --git a/bpkg/cfg-create b/bpkg/cfg-create deleted file mode 100644 index 88247f2..0000000 --- a/bpkg/cfg-create +++ /dev/null @@ -1,19 +0,0 @@ -// file : bpkg/cfg-create -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_CFG_CREATE -#define BPKG_CFG_CREATE - -#include -#include - -#include - -namespace bpkg -{ - int - cfg_create (const cfg_create_options&, cli::scanner& args); -} - -#endif // BPKG_CFG_CREATE diff --git a/bpkg/cfg-create.cxx b/bpkg/cfg-create.cxx index 9112871..6f12d55 100644 --- a/bpkg/cfg-create.cxx +++ b/bpkg/cfg-create.cxx @@ -2,14 +2,14 @@ // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include +#include #include -#include -#include -#include -#include +#include +#include +#include +#include using namespace std; using namespace butl; diff --git a/bpkg/cfg-create.hxx b/bpkg/cfg-create.hxx new file mode 100644 index 0000000..e008fd8 --- /dev/null +++ b/bpkg/cfg-create.hxx @@ -0,0 +1,19 @@ +// file : bpkg/cfg-create.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_CFG_CREATE_HXX +#define BPKG_CFG_CREATE_HXX + +#include +#include + +#include + +namespace bpkg +{ + int + cfg_create (const cfg_create_options&, cli::scanner& args); +} + +#endif // BPKG_CFG_CREATE_HXX diff --git a/bpkg/checksum b/bpkg/checksum deleted file mode 100644 index 002162b..0000000 --- a/bpkg/checksum +++ /dev/null @@ -1,32 +0,0 @@ -// file : bpkg/checksum -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_CHECKSUM -#define BPKG_CHECKSUM - -#include -#include - -#include - -namespace bpkg -{ - // Calculate SHA256 sum of the specified memory buffer in binary mode. Issue - // diagnostics and throw failed if anything goes wrong. - // - string - sha256 (const common_options&, const char* buf, size_t n); - - // The same but for a stream (if ifdstream, open in binary mode). - // - string - sha256 (const common_options&, istream&); - - // The same but for a file. - // - string - sha256 (const common_options&, const path& file); -} - -#endif // BPKG_CHECKSUM diff --git a/bpkg/checksum.cxx b/bpkg/checksum.cxx index a76ab55..d70446b 100644 --- a/bpkg/checksum.cxx +++ b/bpkg/checksum.cxx @@ -2,7 +2,7 @@ // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include +#include #include @@ -10,7 +10,7 @@ #include #include -#include +#include using namespace std; using namespace butl; diff --git a/bpkg/checksum.hxx b/bpkg/checksum.hxx new file mode 100644 index 0000000..ec5a82e --- /dev/null +++ b/bpkg/checksum.hxx @@ -0,0 +1,32 @@ +// file : bpkg/checksum.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_CHECKSUM_HXX +#define BPKG_CHECKSUM_HXX + +#include +#include + +#include + +namespace bpkg +{ + // Calculate SHA256 sum of the specified memory buffer in binary mode. Issue + // diagnostics and throw failed if anything goes wrong. + // + string + sha256 (const common_options&, const char* buf, size_t n); + + // The same but for a stream (if ifdstream, open in binary mode). + // + string + sha256 (const common_options&, istream&); + + // The same but for a file. + // + string + sha256 (const common_options&, const path& file); +} + +#endif // BPKG_CHECKSUM_HXX diff --git a/bpkg/common.cli b/bpkg/common.cli index 8b99038..45d13d3 100644 --- a/bpkg/common.cli +++ b/bpkg/common.cli @@ -4,8 +4,8 @@ include ; -include ; -include ; +include ; +include ; "\section=1" "\name=bpkg-common-options" diff --git a/bpkg/database b/bpkg/database deleted file mode 100644 index aa32d5c..0000000 --- a/bpkg/database +++ /dev/null @@ -1,82 +0,0 @@ -// file : bpkg/database -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_DATABASE -#define BPKG_DATABASE - -#include // remove_reference - -#include -#include -#include - -#include - -#include -#include - -#include - -namespace bpkg -{ - using odb::query; - using odb::result; - using odb::session; - - using odb::sqlite::database; - using odb::sqlite::transaction; - - database - open (const dir_path& configuration, tracer&, bool create = false); - - struct tracer_guard - { - tracer_guard (database& db, tracer& t) - : db_ (db), t_ (db.tracer ()) {db.tracer (t);} - ~tracer_guard () {db_.tracer (*t_);} - - private: - database& db_; - odb::tracer* t_; - }; - - // Range-based for-loop iteration over query result that returns - // object pointers. For example: - // - // for (shared_ptr o: pointer_result (db.query (...))) - // - template - class pointer_result_range - { - R r_; - - public: - pointer_result_range (R&& r): r_ (forward (r)) {} - - using base_iterator = typename std::remove_reference::type::iterator; - - struct iterator: base_iterator - { - iterator () = default; - - explicit - iterator (base_iterator i): base_iterator (move (i)) {} - - typename base_iterator::pointer_type - operator* () {return this->load ();} - }; - - iterator begin () {return iterator (r_.begin ());} - iterator end () {return iterator (r_.end ());} - }; - - template - inline pointer_result_range - pointer_result (R&& r) - { - return pointer_result_range (forward (r)); - } -} - -#endif // BPKG_DATABASE diff --git a/bpkg/database.cxx b/bpkg/database.cxx index 4b5aad9..a590eca 100644 --- a/bpkg/database.cxx +++ b/bpkg/database.cxx @@ -2,15 +2,15 @@ // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include +#include #include #include -#include -#include -#include -#include +#include +#include +#include +#include using namespace std; diff --git a/bpkg/database.hxx b/bpkg/database.hxx new file mode 100644 index 0000000..f90aa6b --- /dev/null +++ b/bpkg/database.hxx @@ -0,0 +1,82 @@ +// file : bpkg/database.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_DATABASE_HXX +#define BPKG_DATABASE_HXX + +#include // remove_reference + +#include +#include +#include + +#include + +#include +#include + +#include + +namespace bpkg +{ + using odb::query; + using odb::result; + using odb::session; + + using odb::sqlite::database; + using odb::sqlite::transaction; + + database + open (const dir_path& configuration, tracer&, bool create = false); + + struct tracer_guard + { + tracer_guard (database& db, tracer& t) + : db_ (db), t_ (db.tracer ()) {db.tracer (t);} + ~tracer_guard () {db_.tracer (*t_);} + + private: + database& db_; + odb::tracer* t_; + }; + + // Range-based for-loop iteration over query result that returns + // object pointers. For example: + // + // for (shared_ptr o: pointer_result (db.query (...))) + // + template + class pointer_result_range + { + R r_; + + public: + pointer_result_range (R&& r): r_ (forward (r)) {} + + using base_iterator = typename std::remove_reference::type::iterator; + + struct iterator: base_iterator + { + iterator () = default; + + explicit + iterator (base_iterator i): base_iterator (move (i)) {} + + typename base_iterator::pointer_type + operator* () {return this->load ();} + }; + + iterator begin () {return iterator (r_.begin ());} + iterator end () {return iterator (r_.end ());} + }; + + template + inline pointer_result_range + pointer_result (R&& r) + { + return pointer_result_range (forward (r)); + } +} + +#endif // BPKG_DATABASE_HXX diff --git a/bpkg/diagnostics b/bpkg/diagnostics deleted file mode 100644 index a1a785f..0000000 --- a/bpkg/diagnostics +++ /dev/null @@ -1,240 +0,0 @@ -// file : bpkg/diagnostics -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_DIAGNOSTICS -#define BPKG_DIAGNOSTICS - -#include - -#include - -#include -#include - -namespace bpkg -{ - using butl::diag_record; - - // Throw this exception to terminate the process. The handler should - // assume that the diagnostics has already been issued. - // - class failed: public std::exception {}; - - // Print process commmand line. If the number of elements is specified - // (or the second version is used), then it will print the piped multi- - // process command line, if present. In this case, the expected format - // is as follows: - // - // name1 arg arg ... nullptr - // name2 arg arg ... nullptr - // ... - // nameN arg arg ... nullptr nullptr - // - void - print_process (diag_record&, const char* const args[], size_t n = 0); - - void - print_process (const char* const args[], size_t n = 0); - - inline void - print_process (diag_record& dr, const cstrings& args) - { - print_process (dr, args.data (), args.size ()); - } - - inline void - print_process (const cstrings& args) - { - print_process (args.data (), args.size ()); - } - - // Verbosity level. Update documentation for --verbose if changing. - // - // 0 - disabled - // 1 - high-level information messages - // 2 - essential underlying commands that are being executed - // 3 - all underlying commands that are being executed - // 4 - information that could be helpful to the user - // 5 - information that could be helpful to the developer - // 6 - even more detailed information - // - // While uint8 is more than enough, use uint16 for the ease of printing. - // - extern uint16_t verb; - - template inline void l1 (const F& f) {if (verb >= 1) f ();} - template inline void l2 (const F& f) {if (verb >= 2) f ();} - template inline void l3 (const F& f) {if (verb >= 3) f ();} - template inline void l4 (const F& f) {if (verb >= 4) f ();} - template inline void l5 (const F& f) {if (verb >= 5) f ();} - template inline void l6 (const F& f) {if (verb >= 6) f ();} - - // Diagnostic facility, base infrastructure. - // - using butl::diag_stream; - using butl::diag_epilogue; - - // Diagnostic facility, project specifics. - // - struct simple_prologue_base - { - explicit - simple_prologue_base (const char* type, const char* name) - : type_ (type), name_ (name) {} - - void - operator() (const diag_record& r) const; - - private: - const char* type_; - const char* name_; - }; - - class location - { - public: - location () {} - location (string f, uint64_t l, uint64_t c) - : file (move (f)), line (l), column (c) {} - - string file; - uint64_t line; - uint64_t column; - }; - - struct location_prologue_base - { - location_prologue_base (const char* type, - const char* name, - const location& l) - : type_ (type), name_ (name), loc_ (l) {} - - void - operator() (const diag_record& r) const; - - private: - const char* type_; - const char* name_; - const location loc_; - }; - - struct basic_mark_base - { - using simple_prologue = butl::diag_prologue; - using location_prologue = butl::diag_prologue; - - explicit - basic_mark_base (const char* type, - const char* name = nullptr, - const void* data = nullptr, - diag_epilogue* epilogue = nullptr) - : type_ (type), name_ (name), data_ (data), epilogue_ (epilogue) {} - - simple_prologue - operator() () const - { - return simple_prologue (epilogue_, type_, name_); - } - - location_prologue - operator() (const location& l) const - { - return location_prologue (epilogue_, type_, name_, l); - } - - template - location_prologue - operator() (const L& l) const - { - return location_prologue ( - epilogue_, type_, name_, get_location (l, data_)); - } - - template - location_prologue - operator() (F&& f, L&& l, C&& c) const - { - return location_prologue ( - epilogue_, - type_, - name_, - location (forward (f), forward (l), forward (c))); - } - - protected: - const char* type_; - const char* name_; - const void* data_; - diag_epilogue* const epilogue_; - }; - using basic_mark = butl::diag_mark; - - extern const basic_mark error; - extern const basic_mark warn; - extern const basic_mark info; - extern const basic_mark text; - - // trace - // - // Also implement the ODB tracer interface so that we can use it to trace - // database statement execution. - // - struct trace_mark_base: basic_mark_base, odb::tracer - { - explicit - trace_mark_base (const char* name, const void* data = nullptr) - : basic_mark_base ("trace", name, data) {} - - // odb::tracer interface. - // - virtual void - prepare (odb::connection&, const odb::statement&); - - virtual void - execute (odb::connection&, const char* statement); - - virtual void - deallocate (odb::connection&, const odb::statement&); - }; - using trace_mark = butl::diag_mark; - using tracer = trace_mark; - - // fail - // - struct fail_mark_base: basic_mark_base - { - explicit - fail_mark_base (const char* type, - const void* data = nullptr) - : basic_mark_base (type, - nullptr, - data, - [](const diag_record& r) - { - r.flush (); - throw failed (); - }) {} - }; - - using fail_mark = butl::diag_mark; - - struct fail_end_base - { - [[noreturn]] void - operator() (const diag_record& r) const - { - // If we just throw then the record's destructor will see an active - // exception and will not flush the record. - // - r.flush (); - throw failed (); - } - }; - using fail_end = butl::diag_noreturn_end; - - extern const fail_mark fail; - extern const fail_end endf; -} - -#endif // BPKG_DIAGNOSTICS diff --git a/bpkg/diagnostics.cxx b/bpkg/diagnostics.cxx index c15d7d5..9eaf118 100644 --- a/bpkg/diagnostics.cxx +++ b/bpkg/diagnostics.cxx @@ -2,7 +2,7 @@ // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include +#include #include // strchr() #include diff --git a/bpkg/diagnostics.hxx b/bpkg/diagnostics.hxx new file mode 100644 index 0000000..64eecd9 --- /dev/null +++ b/bpkg/diagnostics.hxx @@ -0,0 +1,240 @@ +// file : bpkg/diagnostics.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_DIAGNOSTICS_HXX +#define BPKG_DIAGNOSTICS_HXX + +#include + +#include + +#include +#include + +namespace bpkg +{ + using butl::diag_record; + + // Throw this exception to terminate the process. The handler should + // assume that the diagnostics has already been issued. + // + class failed: public std::exception {}; + + // Print process commmand line. If the number of elements is specified + // (or the second version is used), then it will print the piped multi- + // process command line, if present. In this case, the expected format + // is as follows: + // + // name1 arg arg ... nullptr + // name2 arg arg ... nullptr + // ... + // nameN arg arg ... nullptr nullptr + // + void + print_process (diag_record&, const char* const args[], size_t n = 0); + + void + print_process (const char* const args[], size_t n = 0); + + inline void + print_process (diag_record& dr, const cstrings& args) + { + print_process (dr, args.data (), args.size ()); + } + + inline void + print_process (const cstrings& args) + { + print_process (args.data (), args.size ()); + } + + // Verbosity level. Update documentation for --verbose if changing. + // + // 0 - disabled + // 1 - high-level information messages + // 2 - essential underlying commands that are being executed + // 3 - all underlying commands that are being executed + // 4 - information that could be helpful to the user + // 5 - information that could be helpful to the developer + // 6 - even more detailed information + // + // While uint8 is more than enough, use uint16 for the ease of printing. + // + extern uint16_t verb; + + template inline void l1 (const F& f) {if (verb >= 1) f ();} + template inline void l2 (const F& f) {if (verb >= 2) f ();} + template inline void l3 (const F& f) {if (verb >= 3) f ();} + template inline void l4 (const F& f) {if (verb >= 4) f ();} + template inline void l5 (const F& f) {if (verb >= 5) f ();} + template inline void l6 (const F& f) {if (verb >= 6) f ();} + + // Diagnostic facility, base infrastructure. + // + using butl::diag_stream; + using butl::diag_epilogue; + + // Diagnostic facility, project specifics. + // + struct simple_prologue_base + { + explicit + simple_prologue_base (const char* type, const char* name) + : type_ (type), name_ (name) {} + + void + operator() (const diag_record& r) const; + + private: + const char* type_; + const char* name_; + }; + + class location + { + public: + location () {} + location (string f, uint64_t l, uint64_t c) + : file (move (f)), line (l), column (c) {} + + string file; + uint64_t line; + uint64_t column; + }; + + struct location_prologue_base + { + location_prologue_base (const char* type, + const char* name, + const location& l) + : type_ (type), name_ (name), loc_ (l) {} + + void + operator() (const diag_record& r) const; + + private: + const char* type_; + const char* name_; + const location loc_; + }; + + struct basic_mark_base + { + using simple_prologue = butl::diag_prologue; + using location_prologue = butl::diag_prologue; + + explicit + basic_mark_base (const char* type, + const char* name = nullptr, + const void* data = nullptr, + diag_epilogue* epilogue = nullptr) + : type_ (type), name_ (name), data_ (data), epilogue_ (epilogue) {} + + simple_prologue + operator() () const + { + return simple_prologue (epilogue_, type_, name_); + } + + location_prologue + operator() (const location& l) const + { + return location_prologue (epilogue_, type_, name_, l); + } + + template + location_prologue + operator() (const L& l) const + { + return location_prologue ( + epilogue_, type_, name_, get_location (l, data_)); + } + + template + location_prologue + operator() (F&& f, L&& l, C&& c) const + { + return location_prologue ( + epilogue_, + type_, + name_, + location (forward (f), forward (l), forward (c))); + } + + protected: + const char* type_; + const char* name_; + const void* data_; + diag_epilogue* const epilogue_; + }; + using basic_mark = butl::diag_mark; + + extern const basic_mark error; + extern const basic_mark warn; + extern const basic_mark info; + extern const basic_mark text; + + // trace + // + // Also implement the ODB tracer interface so that we can use it to trace + // database statement execution. + // + struct trace_mark_base: basic_mark_base, odb::tracer + { + explicit + trace_mark_base (const char* name, const void* data = nullptr) + : basic_mark_base ("trace", name, data) {} + + // odb::tracer interface. + // + virtual void + prepare (odb::connection&, const odb::statement&); + + virtual void + execute (odb::connection&, const char* statement); + + virtual void + deallocate (odb::connection&, const odb::statement&); + }; + using trace_mark = butl::diag_mark; + using tracer = trace_mark; + + // fail + // + struct fail_mark_base: basic_mark_base + { + explicit + fail_mark_base (const char* type, + const void* data = nullptr) + : basic_mark_base (type, + nullptr, + data, + [](const diag_record& r) + { + r.flush (); + throw failed (); + }) {} + }; + + using fail_mark = butl::diag_mark; + + struct fail_end_base + { + [[noreturn]] void + operator() (const diag_record& r) const + { + // If we just throw then the record's destructor will see an active + // exception and will not flush the record. + // + r.flush (); + throw failed (); + } + }; + using fail_end = butl::diag_noreturn_end; + + extern const fail_mark fail; + extern const fail_end endf; +} + +#endif // BPKG_DIAGNOSTICS_HXX diff --git a/bpkg/fetch b/bpkg/fetch deleted file mode 100644 index d85bf9b..0000000 --- a/bpkg/fetch +++ /dev/null @@ -1,45 +0,0 @@ -// file : bpkg/fetch -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_FETCH -#define BPKG_FETCH - -#include - -#include -#include - -#include - -namespace bpkg -{ - repository_manifests - fetch_repositories (const dir_path&, bool ignore_unknown); - - pair - fetch_repositories (const common_options&, - const repository_location&, - bool ignore_unknown); - - package_manifests - fetch_packages (const dir_path&, bool ignore_unknown); - - pair - fetch_packages (const common_options&, - const repository_location&, - bool ignore_unknown); - - signature_manifest - fetch_signature (const common_options&, - const repository_location&, - bool ignore_unknown); - - path - fetch_archive (const common_options&, - const repository_location&, - const path& archive, - const dir_path& destdir); -} - -#endif // BPKG_FETCH diff --git a/bpkg/fetch.cxx b/bpkg/fetch.cxx index 6fe851e..71be02b 100644 --- a/bpkg/fetch.cxx +++ b/bpkg/fetch.cxx @@ -2,7 +2,7 @@ // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include +#include #include @@ -11,8 +11,8 @@ #include #include -#include -#include +#include +#include using namespace std; using namespace butl; diff --git a/bpkg/fetch.hxx b/bpkg/fetch.hxx new file mode 100644 index 0000000..e047f29 --- /dev/null +++ b/bpkg/fetch.hxx @@ -0,0 +1,45 @@ +// file : bpkg/fetch.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_FETCH_HXX +#define BPKG_FETCH_HXX + +#include + +#include +#include + +#include + +namespace bpkg +{ + repository_manifests + fetch_repositories (const dir_path&, bool ignore_unknown); + + pair + fetch_repositories (const common_options&, + const repository_location&, + bool ignore_unknown); + + package_manifests + fetch_packages (const dir_path&, bool ignore_unknown); + + pair + fetch_packages (const common_options&, + const repository_location&, + bool ignore_unknown); + + signature_manifest + fetch_signature (const common_options&, + const repository_location&, + bool ignore_unknown); + + path + fetch_archive (const common_options&, + const repository_location&, + const path& archive, + const dir_path& destdir); +} + +#endif // BPKG_FETCH_HXX diff --git a/bpkg/forward b/bpkg/forward deleted file mode 100644 index b91e282..0000000 --- a/bpkg/forward +++ /dev/null @@ -1,20 +0,0 @@ -// file : bpkg/forward -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_FORWARD -#define BPKG_FORWARD - -#include - -namespace bpkg -{ - using odb::sqlite::database; - using odb::sqlite::transaction; - - // - // - class selected_package; -} - -#endif // BPKG_FORWARD diff --git a/bpkg/forward.hxx b/bpkg/forward.hxx new file mode 100644 index 0000000..cb49926 --- /dev/null +++ b/bpkg/forward.hxx @@ -0,0 +1,20 @@ +// file : bpkg/forward.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_FORWARD_HXX +#define BPKG_FORWARD_HXX + +#include + +namespace bpkg +{ + using odb::sqlite::database; + using odb::sqlite::transaction; + + // + // + class selected_package; +} + +#endif // BPKG_FORWARD_HXX diff --git a/bpkg/help b/bpkg/help deleted file mode 100644 index 99c261b..0000000 --- a/bpkg/help +++ /dev/null @@ -1,21 +0,0 @@ -// file : bpkg/help -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_HELP -#define BPKG_HELP - -#include -#include - -#include - -namespace bpkg -{ - using usage_function = cli::usage_para (ostream&, cli::usage_para); - - int - help (const help_options&, const string& topic, usage_function* usage); -} - -#endif // BPKG_HELP diff --git a/bpkg/help.cxx b/bpkg/help.cxx index 133c08e..61152b3 100644 --- a/bpkg/help.cxx +++ b/bpkg/help.cxx @@ -2,16 +2,16 @@ // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include +#include #include -#include -#include +#include +#include // Help topics. // -#include +#include using namespace std; using namespace butl; diff --git a/bpkg/help.hxx b/bpkg/help.hxx new file mode 100644 index 0000000..b8096d5 --- /dev/null +++ b/bpkg/help.hxx @@ -0,0 +1,21 @@ +// file : bpkg/help.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_HELP_HXX +#define BPKG_HELP_HXX + +#include +#include + +#include + +namespace bpkg +{ + using usage_function = cli::usage_para (ostream&, cli::usage_para); + + int + help (const help_options&, const string& topic, usage_function* usage); +} + +#endif // BPKG_HELP_HXX diff --git a/bpkg/manifest-utility b/bpkg/manifest-utility deleted file mode 100644 index c6d9ab8..0000000 --- a/bpkg/manifest-utility +++ /dev/null @@ -1,45 +0,0 @@ -// file : bpkg/manifest-utility -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_MANIFEST_UTILITY -#define BPKG_MANIFEST_UTILITY - -#include - -#include -#include - -namespace bpkg -{ - // Package naming schemes. - // - enum class package_scheme - { - none, - sys - }; - - // Extract scheme from [:]. Position the pointer right after - // the scheme end if present, otherwise leave unchanged. - // - package_scheme - parse_package_scheme (const char*&); - - // Extract name and version components from [/]. - // - string - parse_package_name (const char*); - - version - parse_package_version (const char*); - - // First use the passed location as is. If the result is relative, - // then assume this is a relative path to the repository directory - // and complete it based on the current working directory. - // - repository_location - parse_location (const char*); -} - -#endif // BPKG_MANIFEST_UTILITY diff --git a/bpkg/manifest-utility.cxx b/bpkg/manifest-utility.cxx index c8fb6e9..850ce59 100644 --- a/bpkg/manifest-utility.cxx +++ b/bpkg/manifest-utility.cxx @@ -2,9 +2,9 @@ // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include +#include -#include +#include using namespace std; diff --git a/bpkg/manifest-utility.hxx b/bpkg/manifest-utility.hxx new file mode 100644 index 0000000..afa93f5 --- /dev/null +++ b/bpkg/manifest-utility.hxx @@ -0,0 +1,45 @@ +// file : bpkg/manifest-utility.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_MANIFEST_UTILITY_HXX +#define BPKG_MANIFEST_UTILITY_HXX + +#include + +#include +#include + +namespace bpkg +{ + // Package naming schemes. + // + enum class package_scheme + { + none, + sys + }; + + // Extract scheme from [:]. Position the pointer right after + // the scheme end if present, otherwise leave unchanged. + // + package_scheme + parse_package_scheme (const char*&); + + // Extract name and version components from [/]. + // + string + parse_package_name (const char*); + + version + parse_package_version (const char*); + + // First use the passed location as is. If the result is relative, + // then assume this is a relative path to the repository directory + // and complete it based on the current working directory. + // + repository_location + parse_location (const char*); +} + +#endif // BPKG_MANIFEST_UTILITY_HXX diff --git a/bpkg/odb.sh b/bpkg/odb.sh index 1d8b66a..776cccb 100755 --- a/bpkg/odb.sh +++ b/bpkg/odb.sh @@ -9,9 +9,10 @@ lib="\ -I$HOME/work/odb/libodb-default \ -I$HOME/work/odb/libodb" -$odb $lib -I.. -I../../libbpkg -I../../libbutl \ - -d sqlite --std c++11 --hxx-suffix "" --generate-query --generate-schema \ - --odb-epilogue '#include ' \ - --hxx-prologue '#include ' \ - --include-with-brackets --include-prefix bpkg --guard-prefix BPKG \ - --sqlite-override-null package +$odb $lib -I.. -I../../libbpkg -I../../libbutl \ + -DLIBODB_BUILD2 -DLIBODB_SQLITE_BUILD2 --generate-schema \ + -d sqlite --std c++11 --hxx-suffix ".hxx" --generate-query \ + --odb-epilogue '#include ' \ + --hxx-prologue '#include ' \ + --include-with-brackets --include-prefix bpkg --guard-prefix BPKG \ + --sqlite-override-null package.hxx diff --git a/bpkg/openssl b/bpkg/openssl deleted file mode 100644 index c665521..0000000 --- a/bpkg/openssl +++ /dev/null @@ -1,31 +0,0 @@ -// file : bpkg/openssl -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_OPENSSL -#define BPKG_OPENSSL - -#include - -#include -#include - -#include - -namespace bpkg -{ - // Start the openssl process. Parameters in, out, err flags if the caller - // wish to write to, or read from the process STDIN, STDOUT, STDERR streams. - // If out and err are both true, then STDERR is redirected to STDOUT, and - // they both can be read from in_ofd descriptor. - // - butl::process - start_openssl (const common_options&, - const char* command, - const cstrings& options, - bool in = false, - bool out = false, - bool err = false); -} - -#endif // BPKG_OPENSSL diff --git a/bpkg/openssl.cxx b/bpkg/openssl.cxx index 01f07a0..e8de30b 100644 --- a/bpkg/openssl.cxx +++ b/bpkg/openssl.cxx @@ -2,11 +2,11 @@ // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include +#include #include -#include +#include using namespace std; using namespace butl; diff --git a/bpkg/openssl.hxx b/bpkg/openssl.hxx new file mode 100644 index 0000000..30671ae --- /dev/null +++ b/bpkg/openssl.hxx @@ -0,0 +1,31 @@ +// file : bpkg/openssl.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_OPENSSL_HXX +#define BPKG_OPENSSL_HXX + +#include + +#include +#include + +#include + +namespace bpkg +{ + // Start the openssl process. Parameters in, out, err flags if the caller + // wish to write to, or read from the process STDIN, STDOUT, STDERR streams. + // If out and err are both true, then STDERR is redirected to STDOUT, and + // they both can be read from in_ofd descriptor. + // + butl::process + start_openssl (const common_options&, + const char* command, + const cstrings& options, + bool in = false, + bool out = false, + bool err = false); +} + +#endif // BPKG_OPENSSL_HXX diff --git a/bpkg/options-types b/bpkg/options-types deleted file mode 100644 index b252191..0000000 --- a/bpkg/options-types +++ /dev/null @@ -1,18 +0,0 @@ -// file : bpkg/options-types -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_OPTIONS_TYPES -#define BPKG_OPTIONS_TYPES - -namespace bpkg -{ - enum class auth - { - none, - remote, - all - }; -} - -#endif // BPKG_OPTIONS_TYPES diff --git a/bpkg/options-types.hxx b/bpkg/options-types.hxx new file mode 100644 index 0000000..093f25d --- /dev/null +++ b/bpkg/options-types.hxx @@ -0,0 +1,18 @@ +// file : bpkg/options-types.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_OPTIONS_TYPES_HXX +#define BPKG_OPTIONS_TYPES_HXX + +namespace bpkg +{ + enum class auth + { + none, + remote, + all + }; +} + +#endif // BPKG_OPTIONS_TYPES_HXX diff --git a/bpkg/package b/bpkg/package deleted file mode 100644 index 0bf0a41..0000000 --- a/bpkg/package +++ /dev/null @@ -1,916 +0,0 @@ -// file : bpkg/package -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_PACKAGE -#define BPKG_PACKAGE - -#include -#include -#include -#include -#include // static_assert - -#include -#include - -#include - -#include -#include - -#pragma db model version(3, 3, closed) - -namespace bpkg -{ - // Compare two lazy pointers via the pointed-to object ids. - // - struct compare_lazy_ptr - { - template - bool - operator() (const P& x, const P& y) const - { - return x.object_id () < y.object_id (); - } - }; - - // path - // - using optional_string = optional; - using optional_path = optional; - using optional_dir_path = optional; - - #pragma db map type(path) as(string) \ - to((?).string ()) from(bpkg::path (?)) - - #pragma db map type(optional_path) as(bpkg::optional_string) \ - to((?) ? (?)->string () : bpkg::optional_string ()) \ - from((?) ? bpkg::path (*(?)) : bpkg::optional_path ()) - - #pragma db map type(dir_path) as(string) \ - to((?).string ()) from(bpkg::dir_path (?)) - - #pragma db map type(optional_dir_path) as(bpkg::optional_string) \ - to((?) ? (?)->string () : bpkg::optional_string ()) \ - from((?) ? bpkg::dir_path (*(?)) : bpkg::optional_dir_path ()) - - // timestamp - // - using butl::timestamp; - using butl::timestamp_unknown; - - // Ensure that timestamp can be represented in nonoseconds without loss of - // accuracy, so the following ODB mapping is adequate. - // - static_assert ( - std::ratio_greater_equal::value, - "The following timestamp ODB mapping is invalid"); - - // As pointed out in butl/timestamp we will overflow in year 2262, but by - // that time some larger basic type will be available for mapping. - // - #pragma db map type(timestamp) as(uint64_t) \ - to(std::chrono::duration_cast ( \ - (?).time_since_epoch ()).count ()) \ - from(butl::timestamp ( \ - std::chrono::duration_cast ( \ - std::chrono::nanoseconds (?)))) - - // An image type that is used to map version to the database since - // there is no way to modify individual components directly. We have - // to define it before including since some value - // types that are defined there use version as their data members. - // - #pragma db value - struct _version - { - uint16_t epoch; - string canonical_upstream; - string canonical_release; - uint16_t revision; - string upstream; - optional release; - }; -} - -#include -#include - -// Prevent assert() macro expansion in get/set expressions. This should -// appear after all #include directives since the assert() macro is -// redefined in each inclusion. -// -#ifdef ODB_COMPILER -# undef assert -# define assert assert -void assert (int); -#endif - -namespace bpkg -{ - // version - // - // Sometimes we need to split the version into two parts: the part - // that goes into the object id (epoch, canonical upstream, canonical - // release, revision) and the original upstream and release. This is what - // the canonical_version and upstream_version value types are for. Note that - // upstream_version derives from version and uses it as storage. The idea - // here is this: when we split the version, we often still want to have the - // "whole" version object readily accessible and that's exactly what this - // strange contraption is for. See available_package for an example - // on how everything fits together. - // - // - #pragma db value - struct canonical_version - { - uint16_t epoch; - string canonical_upstream; - string canonical_release; - uint16_t revision; - - // By default SQLite3 uses BINARY collation for TEXT columns. So while this - // means we don't need to do anything special to make "absent" (~) and - // specified canonical releases compare properly, better make it explicit - // in case the Unicode Collation Algorithm (UCA, where '~' < 'a') becomes - // the default. - // - #pragma db member(canonical_release) options("COLLATE BINARY") - }; - - #pragma db value transient - struct upstream_version: version - { - #pragma db member(upstream_) virtual(string) \ - get(this.upstream) \ - set(this = bpkg::version (0, std::move (?), std::string (), 0)) - - #pragma db member(release_) virtual(optional_string) \ - get(this.release) \ - set(this = bpkg::version ( \ - 0, std::move (this.upstream), std::move (?), 0)) - - upstream_version () = default; - upstream_version (version v): version (move (v)) {} - upstream_version& - operator= (version v) {version& b (*this); b = v; return *this;} - - void - init (const canonical_version& cv, const upstream_version& uv) - { - *this = version (cv.epoch, uv.upstream, uv.release, cv.revision); - assert (cv.canonical_upstream == canonical_upstream && - cv.canonical_release == canonical_release); - } - }; - - #pragma db map type(version) as(_version) \ - to(bpkg::_version{(?).epoch, \ - (?).canonical_upstream, \ - (?).canonical_release, \ - (?).revision, \ - (?).upstream, \ - (?).release}) \ - from(bpkg::version ((?).epoch, \ - std::move ((?).upstream), \ - std::move ((?).release), \ - (?).revision)) - - using optional_version = optional; - using _optional_version = optional<_version>; - - #pragma db map type(optional_version) as(_optional_version) \ - to((?) \ - ? bpkg::_version{(?)->epoch, \ - (?)->canonical_upstream, \ - (?)->canonical_release, \ - (?)->revision, \ - (?)->upstream, \ - (?)->release} \ - : bpkg::_optional_version ()) \ - from((?) \ - ? bpkg::version ((?)->epoch, \ - std::move ((?)->upstream), \ - std::move ((?)->release), \ - (?)->revision) \ - : bpkg::optional_version ()) - - // repository_location - // - #pragma db map type(repository_location) as(string) \ - to((?).string ()) from(bpkg::repository_location (?)) - - - // repository - // - #pragma db object pointer(shared_ptr) session - class repository - { - public: - // We use a weak pointer for prerequisite repositories because we - // could have cycles. No cycles in complements, thought. - // - using complements_type = - std::set, compare_lazy_ptr>; - using prerequisites_type = - std::set, compare_lazy_ptr>; - - string name; // Object id (canonical name). - repository_location location; - complements_type complements; - prerequisites_type prerequisites; - - // Used to detect recursive fetching. Will probably be replaced - // by the 'repositories' file timestamp or hashsum later. - // - #pragma db transient - bool fetched = false; - - public: - explicit - repository (repository_location l): location (move (l)) - { - name = location.canonical_name (); - } - - // Database mapping. - // - #pragma db member(name) id - - #pragma db member(location) \ - set(this.location = std::move (?); \ - assert (this.name == this.location.canonical_name ())) - - #pragma db member(complements) id_column("repository") \ - value_column("complement") value_not_null - - #pragma db member(prerequisites) id_column("repository") \ - value_column("prerequisite") value_not_null - - private: - friend class odb::access; - repository () = default; - }; - - #pragma db view object(repository) query(repository::name != "" && (?)) - struct repository_count - { - #pragma db column("count(*)") - size_t result; - - operator size_t () const {return result;} - }; - - - // package_location - // - #pragma db value - struct package_location - { - using repository_type = bpkg::repository; - - lazy_shared_ptr repository; - path location; // Relative to the repository. - }; - - // dependencies - // - #pragma db value(dependency_constraint) definition - #pragma db value(dependency) definition - #pragma db member(dependency::constraint) column("") - #pragma db value(dependency_alternatives) definition - - using dependencies = vector; - - // Wildcard version. Satisfies any dependency constraint and is represented - // as 0+0 (which is also the "stub version"; since a real version is always - // greater than the stub version, we reuse it to signify a special case). - // - extern const version wildcard_version; - - // available_package - // - #pragma db value - struct available_package_id - { - string name; - canonical_version version; - - available_package_id () = default; - available_package_id (string, const bpkg::version&); - }; - - bool - operator< (const available_package_id&, const available_package_id&); - - #pragma db object pointer(shared_ptr) session - class available_package - { - public: - using version_type = bpkg::version; - - available_package_id id; - upstream_version version; - - // List of repositories to which this package version belongs (yes, - // in our world, it can be in multiple, unrelated repositories). - // - // Note that if the repository is the special root repository (its - // location is empty), then this is a transient (or "fake") object - // for an existing package archive or package directory. In this - // case the location is the path to the archive/directory and to - // determine which one it is, use file/dir_exists(). While on the - // topic of fake available_package objects, when one is created for - // a selected package (see make_available()), this list is left empty - // with the thinking being that since the package is already in at - // least fetched state, we shouldn't be needing its location. - // - vector locations; //@@ Map? - - // Package manifest data. - // - using dependencies_type = bpkg::dependencies; - - dependencies_type dependencies; - - // Present for non-transient objects only. - // - optional sha256sum; - - private: - #pragma db transient - mutable optional system_version_; - - public: - available_package (package_manifest&& m) - : id (move (m.name), m.version), - version (move (m.version)), - dependencies (move (m.dependencies)), - sha256sum (move (m.sha256sum)) {} - - // Create a stub available package with a fixed system version. This - // constructor is only used to create transient/fake available packages - // based on the system selected packages. - // - available_package (string n, version_type sysv) - : id (move (n), wildcard_version), - version (wildcard_version), - system_version_ (sysv) {} - - bool - stub () const {return version.compare (wildcard_version, true) == 0;} - - // Return package system version if one has been discovered. Note that - // we do not implicitly assume a wildcard version. - // - const version_type* - system_version () const - { - if (!system_version_) - { - if (const system_package* sp = system_repository.find (id.name)) - { - // Only cache if it is authoritative. - // - if (sp->authoritative) - system_version_ = sp->version; - else - return &sp->version; - } - } - - return system_version_ ? &*system_version_ : nullptr; - } - - // As above but also return an indication if the version information is - // authoritative. - // - pair - system_version_authoritative () const - { - const system_package* sp (system_repository.find (id.name)); - - if (!system_version_) - { - if (sp != nullptr) - { - // Only cache if it is authoritative. - // - if (sp->authoritative) - system_version_ = sp->version; - else - return make_pair (&sp->version, false); - } - } - - return make_pair (system_version_ ? &*system_version_ : nullptr, - sp != nullptr ? sp->authoritative : false); - } - - // Database mapping. - // - #pragma db member(id) id column("") - #pragma db member(version) set(this.version.init (this.id.version, (?))) - #pragma db member(locations) id_column("") value_column("") \ - unordered value_not_null - - // dependencies - // - using _dependency_key = odb::nested_key; - using _dependency_alternatives_type = - std::map<_dependency_key, dependency>; - - #pragma db value(_dependency_key) - #pragma db member(_dependency_key::outer) column("dependency_index") - #pragma db member(_dependency_key::inner) column("index") - - #pragma db member(dependencies) id_column("") value_column("") - #pragma db member(dependency_alternatives) \ - virtual(_dependency_alternatives_type) \ - after(dependencies) \ - get(odb::nested_get (this.dependencies)) \ - set(odb::nested_set (this.dependencies, std::move (?))) \ - id_column("") key_column("") value_column("dep_") - - private: - friend class odb::access; - available_package () = default; - }; - - #pragma db view object(available_package) - struct available_package_count - { - #pragma db column("count(*)") - size_t result; - - operator size_t () const {return result;} - }; - - // Only return packages that are in the specified repository or its - // complements, recursively. While you could maybe come up with a - // (barely comprehensible) view/query to achieve this, doing it on - // the "client side" is definitely more straightforward. - // - vector> - filter (const shared_ptr&, odb::result&&); - - pair, shared_ptr> - filter_one (const shared_ptr&, odb::result&&); - - // package_state - // - enum class package_state - { - transient, // No longer or not yet in the database. - broken, - fetched, - unpacked, - configured - }; - - string - to_string (package_state); - - package_state - to_package_state (const string&); // May throw invalid_argument. - - inline ostream& - operator<< (ostream& os, package_state s) {return os << to_string (s);} - - #pragma db map type(package_state) as(string) \ - to(to_string (?)) \ - from(bpkg::to_package_state (?)) - - // package_substate - // - enum class package_substate - { - none, - system // System package; valid states: configured. - }; - - string - to_string (package_substate); - - package_substate - to_package_substate (const string&); // May throw invalid_argument. - - inline ostream& - operator<< (ostream& os, package_substate s) {return os << to_string (s);} - - #pragma db map type(package_substate) as(string) \ - to(to_string (?)) \ - from(bpkg::to_package_substate (?)) - - // package - // - #pragma db object pointer(shared_ptr) session - class selected_package - { - public: - using version_type = bpkg::version; - - string name; // Object id. - version_type version; - package_state state; - package_substate substate; - - // The hold flags indicate whether this package and/or version - // should be retained in the configuration. A held package will - // not be automatically removed. A held version will not be - // automatically upgraded. Note also that the two flags are - // orthogonal: we may want to keep a specific version of the - // package as long as it has dependents. - // - bool hold_package; - bool hold_version; - - // Repository from which this package came. Note that it is not - // a pointer to the repository object because it could be wiped - // out (e.g., as a result of rep-fetch). We call such packages - // "orphans". While we can get a list of orphan's prerequisites - // (by loading its manifest), we wouldn't know which repository - // to use as a base to resolve them. As a result, an orphan that - // is not already configured (and thus has all its prerequisites - // resolved) is not very useful and can only be purged. - // - repository_location repository; - - // Path to the archive of this package, if any. If not absolute, - // then it is relative to the configuration directory. The purge - // flag indicates whether the archive should be removed when the - // packaged is purged. If the archive is not present, it should - // be false. - // - optional archive; - bool purge_archive; - - // Path to the source directory of this package, if any. If not - // absolute, then it is relative to the configuration directory. - // The purge flag indicates whether the directory should be - // removed when the packaged is purged. If the source directory - // is not present, it should be false. - // - optional src_root; - bool purge_src; - - // Path to the output directory of this package, if any. It is - // always relative to the configuration directory and currently - // is always -. It is only set once the package - // is configured and its main purse is to keep track of what - // needs to be cleaned by the user before a broken package can - // be purged. Note that it could be the same as out_root. - // - optional out_root; - - // A map of "effective" prerequisites (i.e., pointers to other selected - // packages) to optional dependency constraint. Note that because it is a - // single constraint, we don't support multiple dependencies on the same - // package (e.g., two ranges of versions). See pkg_configure(). - // - using prerequisites_type = std::map, - optional, - compare_lazy_ptr>; - prerequisites_type prerequisites; - - bool - system () const - { - // The system substate is only valid for the configured state. - // - assert (substate != package_substate::system || - state == package_state::configured); - - return substate == package_substate::system; - } - - // Represent the wildcard version with the "*" string. Represent naturally - // all other versions. - // - string - version_string () const; - - // Database mapping. - // - #pragma db member(name) id - - #pragma db member(prerequisites) id_column("package") \ - key_column("prerequisite") value_column("") key_not_null - - private: - friend class odb::access; - selected_package () = default; - }; - - // Print the package name, version and the 'sys:' prefix for the system - // substate. The wildcard version is represented with the "*" string. - // - ostream& - operator<< (ostream&, const selected_package&); - - // certificate - // - // Information extracted from a repository X.509 certificate. The actual - // certificate is stored on disk as .bpkg/certs/.pem (we have - // to store it as a file because that's the only way to pass it to openssl). - // - // If a repository is not authenticated (has no certificate/signature, - // called unauth from now on), then we ask for the user's confirmation and - // create a dummy certificate in order not to ask for the same confirmation - // (for this repository) on next fetch. The problem is, there could be - // multiple sections in such a repository and it would be annoying to - // confirm all of them. So what we are going to do is create a dummy - // certificate not for this specific repository location but for a - // repository location only up to the version, so the name member will - // contain the name prefix rather than the full name (just like a normal - // certificate would). The fingerprint member for such a dummy certificate - // contains the SHA256 checksum of this name. Members other then name and - // fingerprint are meaningless for the dummy certificate. - // - #pragma db object pointer(shared_ptr) session - class certificate - { - public: - string fingerprint; // Object id (note: SHA256 fingerprint). - - string name; // CN component of Subject. - string organization; // O component of Subject. - string email; // email: in Subject Alternative Name. - - timestamp start_date; // notBefore (UTC) - timestamp end_date; // notAfter (UTC) - - bool - dummy () const {return start_date == timestamp_unknown;} - - bool - expired () const - { - assert (!dummy ()); - return timestamp::clock::now () > end_date; - } - - public: - certificate (string f, - string n, - string o, - string e, - timestamp sd, - timestamp ed) - : fingerprint (move (f)), - name (move (n)), - organization (move (o)), - email (move (e)), - start_date (move (sd)), - end_date (move (ed)) - { - } - - // Create dummy certificate. - // - certificate (string f, string n) - : fingerprint (move (f)), - name (move (n)), - start_date (timestamp_unknown), - end_date (timestamp_unknown) - { - } - - // Database mapping. - // - #pragma db member(fingerprint) id - - private: - friend class odb::access; - certificate () = default; - }; - - // Note: prints all the certificate information on one line so mostly - // useful for tracing. - // - ostream& - operator<< (ostream&, const certificate&); - - // Return a list of packages that depend on this package along with - // their constraints. - // - /* - #pragma db view object(selected_package) \ - container(selected_package::prerequisites = pp inner: pp.key) - struct package_dependent - { - #pragma db column(pp.id) - string name; - - #pragma db column(pp.value) - optional constraint; - }; - */ - - // @@ Using raw container table since ODB doesn't support containers - // in views yet. - // - #pragma db view object(selected_package) \ - table("selected_package_prerequisites" = "pp" inner: \ - "pp.prerequisite = " + selected_package::name) - struct package_dependent - { - #pragma db column("pp.package") - string name; - - #pragma db column("pp.") - optional constraint; - }; - - - // Version comparison operators. - // - // They allow comparing objects that have epoch, canonical_upstream, - // canonical_release, and revision data members. The idea is that this - // works for both query members of types version and canonical_version - // as well as for comparing canonical_version to version. - // - template - inline auto - compare_version_eq (const T1& x, const T2& y, bool revision) - -> decltype (x.epoch == y.epoch) - { - // Since we don't quite know what T1 and T2 are (and where the resulting - // expression will run), let's not push our luck with something like - // (!revision || x.revision == y.revision). - // - auto r (x.epoch == y.epoch && - x.canonical_upstream == y.canonical_upstream && - x.canonical_release == y.canonical_release); - - return revision - ? r && x.revision == y.revision - : r; - } - - /* - Currently unused (and probably should stay that way). - - template - inline auto - operator== (const T1& x, const T2& y) -> decltype (x.epoch == y.epoch) - { - return compare_version_eq (x, y, true); - } - */ - - template - inline auto - compare_version_ne (const T1& x, const T2& y, bool revision) - -> decltype (x.epoch == y.epoch) - { - auto r (x.epoch != y.epoch || - x.canonical_upstream != y.canonical_upstream || - x.canonical_release != y.canonical_release); - - return revision - ? r || x.revision != y.revision - : r; - } - - template - inline auto - operator!= (const T1& x, const T2& y) -> decltype (x.epoch != y.epoch) - { - return compare_version_ne (x, y, true); - } - - template - inline auto - compare_version_lt (const T1& x, const T2& y, bool revision) - -> decltype (x.epoch == y.epoch) - { - auto r ( - x.epoch < y.epoch || - (x.epoch == y.epoch && x.canonical_upstream < y.canonical_upstream) || - (x.epoch == y.epoch && x.canonical_upstream == y.canonical_upstream && - x.canonical_release < y.canonical_release)); - - return revision - ? r || - (x.epoch == y.epoch && x.canonical_upstream == y.canonical_upstream && - x.canonical_release == y.canonical_release && x.revision < y.revision) - : r; - } - - template - inline auto - operator< (const T1& x, const T2& y) -> decltype (x.epoch < y.epoch) - { - return compare_version_lt (x, y, true); - } - - template - inline auto - compare_version_le (const T1& x, const T2& y, bool revision) - -> decltype (x.epoch == y.epoch) - { - auto r ( - x.epoch < y.epoch || - (x.epoch == y.epoch && x.canonical_upstream < y.canonical_upstream)); - - return revision - ? r || - (x.epoch == y.epoch && x.canonical_upstream == y.canonical_upstream && - x.canonical_release < y.canonical_release) || - (x.epoch == y.epoch && x.canonical_upstream == y.canonical_upstream && - x.canonical_release == y.canonical_release && x.revision <= y.revision) - : r || - (x.epoch == y.epoch && x.canonical_upstream == y.canonical_upstream && - x.canonical_release <= y.canonical_release); - } - - /* - Currently unused (and probably should stay that way). - - template - inline auto - operator<= (const T1& x, const T2& y) -> decltype (x.epoch <= y.epoch) - { - return compare_version_le (x, y, true); - } - */ - - template - inline auto - compare_version_gt (const T1& x, const T2& y, bool revision) - -> decltype (x.epoch == y.epoch) - { - auto r ( - x.epoch > y.epoch || - (x.epoch == y.epoch && x.canonical_upstream > y.canonical_upstream) || - (x.epoch == y.epoch && x.canonical_upstream == y.canonical_upstream && - x.canonical_release > y.canonical_release)); - - return revision - ? r || - (x.epoch == y.epoch && x.canonical_upstream == y.canonical_upstream && - x.canonical_release == y.canonical_release && x.revision > y.revision) - : r; - } - - template - inline auto - operator> (const T1& x, const T2& y) -> decltype (x.epoch > y.epoch) - { - return compare_version_gt (x, y, true); - } - - template - inline auto - compare_version_ge (const T1& x, const T2& y, bool revision) - -> decltype (x.epoch == y.epoch) - { - auto r ( - x.epoch > y.epoch || - (x.epoch == y.epoch && x.canonical_upstream > y.canonical_upstream)); - - return revision - ? r || - (x.epoch == y.epoch && x.canonical_upstream == y.canonical_upstream && - x.canonical_release > y.canonical_release) || - (x.epoch == y.epoch && x.canonical_upstream == y.canonical_upstream && - x.canonical_release == y.canonical_release && x.revision >= y.revision) - : r || - (x.epoch == y.epoch && x.canonical_upstream == y.canonical_upstream && - x.canonical_release >= y.canonical_release); - } - - template - inline auto - operator>= (const T1& x, const T2& y) -> decltype (x.epoch >= y.epoch) - { - return compare_version_ge (x, y, true); - } - - template - inline auto - order_by_version_desc (const T& x) -> //decltype ("ORDER BY" + x.epoch) - decltype (x.epoch == 0) - { - return "ORDER BY" - + x.epoch + "DESC," - + x.canonical_upstream + "DESC," - + x.canonical_release + "DESC," - + x.revision + "DESC"; - } - - template - inline auto - order_by_revision_desc (const T& x) -> //decltype ("ORDER BY" + x.epoch) - decltype (x.revision == 0) - { - return "ORDER BY" + x.revision + "DESC"; - } -} - -#include - -#endif // BPKG_PACKAGE diff --git a/bpkg/package.cxx b/bpkg/package.cxx index 37ed214..1c98f42 100644 --- a/bpkg/package.cxx +++ b/bpkg/package.cxx @@ -2,10 +2,10 @@ // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include -#include +#include +#include -#include +#include using namespace std; diff --git a/bpkg/package.hxx b/bpkg/package.hxx new file mode 100644 index 0000000..bd45e9c --- /dev/null +++ b/bpkg/package.hxx @@ -0,0 +1,917 @@ +// file : bpkg/package.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_PACKAGE_HXX +#define BPKG_PACKAGE_HXX + +#include +#include +#include +#include +#include // static_assert + +#include +#include + +#include + +#include +#include + +#pragma db model version(3, 3, closed) + +namespace bpkg +{ + // Compare two lazy pointers via the pointed-to object ids. + // + struct compare_lazy_ptr + { + template + bool + operator() (const P& x, const P& y) const + { + return x.object_id () < y.object_id (); + } + }; + + // path + // + using optional_string = optional; + using optional_path = optional; + using optional_dir_path = optional; + + #pragma db map type(path) as(string) \ + to((?).string ()) from(bpkg::path (?)) + + #pragma db map type(optional_path) as(bpkg::optional_string) \ + to((?) ? (?)->string () : bpkg::optional_string ()) \ + from((?) ? bpkg::path (*(?)) : bpkg::optional_path ()) + + #pragma db map type(dir_path) as(string) \ + to((?).string ()) from(bpkg::dir_path (?)) + + #pragma db map type(optional_dir_path) as(bpkg::optional_string) \ + to((?) ? (?)->string () : bpkg::optional_string ()) \ + from((?) ? bpkg::dir_path (*(?)) : bpkg::optional_dir_path ()) + + // timestamp + // + using butl::timestamp; + using butl::timestamp_unknown; + + // Ensure that timestamp can be represented in nonoseconds without loss of + // accuracy, so the following ODB mapping is adequate. + // + static_assert ( + std::ratio_greater_equal::value, + "The following timestamp ODB mapping is invalid"); + + // As pointed out in butl/timestamp we will overflow in year 2262, but by + // that time some larger basic type will be available for mapping. + // + #pragma db map type(timestamp) as(uint64_t) \ + to(std::chrono::duration_cast ( \ + (?).time_since_epoch ()).count ()) \ + from(butl::timestamp ( \ + std::chrono::duration_cast ( \ + std::chrono::nanoseconds (?)))) + + // An image type that is used to map version to the database since + // there is no way to modify individual components directly. We have + // to define it before including since some value + // types that are defined there use version as their data members. + // + #pragma db value + struct _version + { + uint16_t epoch; + string canonical_upstream; + string canonical_release; + uint16_t revision; + string upstream; + optional release; + }; +} + +#include + +#include + +// Prevent assert() macro expansion in get/set expressions. This should +// appear after all #include directives since the assert() macro is +// redefined in each inclusion. +// +#ifdef ODB_COMPILER_HXX +# undef assert +# define assert assert +void assert (int); +#endif + +namespace bpkg +{ + // version + // + // Sometimes we need to split the version into two parts: the part + // that goes into the object id (epoch, canonical upstream, canonical + // release, revision) and the original upstream and release. This is what + // the canonical_version and upstream_version value types are for. Note that + // upstream_version derives from version and uses it as storage. The idea + // here is this: when we split the version, we often still want to have the + // "whole" version object readily accessible and that's exactly what this + // strange contraption is for. See available_package for an example + // on how everything fits together. + // + // + #pragma db value + struct canonical_version + { + uint16_t epoch; + string canonical_upstream; + string canonical_release; + uint16_t revision; + + // By default SQLite3 uses BINARY collation for TEXT columns. So while this + // means we don't need to do anything special to make "absent" (~) and + // specified canonical releases compare properly, better make it explicit + // in case the Unicode Collation Algorithm (UCA, where '~' < 'a') becomes + // the default. + // + #pragma db member(canonical_release) options("COLLATE BINARY") + }; + + #pragma db value transient + struct upstream_version: version + { + #pragma db member(upstream_) virtual(string) \ + get(this.upstream) \ + set(this = bpkg::version (0, std::move (?), std::string (), 0)) + + #pragma db member(release_) virtual(optional_string) \ + get(this.release) \ + set(this = bpkg::version ( \ + 0, std::move (this.upstream), std::move (?), 0)) + + upstream_version () = default; + upstream_version (version v): version (move (v)) {} + upstream_version& + operator= (version v) {version& b (*this); b = v; return *this;} + + void + init (const canonical_version& cv, const upstream_version& uv) + { + *this = version (cv.epoch, uv.upstream, uv.release, cv.revision); + assert (cv.canonical_upstream == canonical_upstream && + cv.canonical_release == canonical_release); + } + }; + + #pragma db map type(version) as(_version) \ + to(bpkg::_version{(?).epoch, \ + (?).canonical_upstream, \ + (?).canonical_release, \ + (?).revision, \ + (?).upstream, \ + (?).release}) \ + from(bpkg::version ((?).epoch, \ + std::move ((?).upstream), \ + std::move ((?).release), \ + (?).revision)) + + using optional_version = optional; + using _optional_version = optional<_version>; + + #pragma db map type(optional_version) as(_optional_version) \ + to((?) \ + ? bpkg::_version{(?)->epoch, \ + (?)->canonical_upstream, \ + (?)->canonical_release, \ + (?)->revision, \ + (?)->upstream, \ + (?)->release} \ + : bpkg::_optional_version ()) \ + from((?) \ + ? bpkg::version ((?)->epoch, \ + std::move ((?)->upstream), \ + std::move ((?)->release), \ + (?)->revision) \ + : bpkg::optional_version ()) + + // repository_location + // + #pragma db map type(repository_location) as(string) \ + to((?).string ()) from(bpkg::repository_location (?)) + + + // repository + // + #pragma db object pointer(shared_ptr) session + class repository + { + public: + // We use a weak pointer for prerequisite repositories because we + // could have cycles. No cycles in complements, thought. + // + using complements_type = + std::set, compare_lazy_ptr>; + using prerequisites_type = + std::set, compare_lazy_ptr>; + + string name; // Object id (canonical name). + repository_location location; + complements_type complements; + prerequisites_type prerequisites; + + // Used to detect recursive fetching. Will probably be replaced + // by the 'repositories' file timestamp or hashsum later. + // + #pragma db transient + bool fetched = false; + + public: + explicit + repository (repository_location l): location (move (l)) + { + name = location.canonical_name (); + } + + // Database mapping. + // + #pragma db member(name) id + + #pragma db member(location) \ + set(this.location = std::move (?); \ + assert (this.name == this.location.canonical_name ())) + + #pragma db member(complements) id_column("repository") \ + value_column("complement") value_not_null + + #pragma db member(prerequisites) id_column("repository") \ + value_column("prerequisite") value_not_null + + private: + friend class odb::access; + repository () = default; + }; + + #pragma db view object(repository) query(repository::name != "" && (?)) + struct repository_count + { + #pragma db column("count(*)") + size_t result; + + operator size_t () const {return result;} + }; + + + // package_location + // + #pragma db value + struct package_location + { + using repository_type = bpkg::repository; + + lazy_shared_ptr repository; + path location; // Relative to the repository. + }; + + // dependencies + // + #pragma db value(dependency_constraint) definition + #pragma db value(dependency) definition + #pragma db member(dependency::constraint) column("") + #pragma db value(dependency_alternatives) definition + + using dependencies = vector; + + // Wildcard version. Satisfies any dependency constraint and is represented + // as 0+0 (which is also the "stub version"; since a real version is always + // greater than the stub version, we reuse it to signify a special case). + // + extern const version wildcard_version; + + // available_package + // + #pragma db value + struct available_package_id + { + string name; + canonical_version version; + + available_package_id () = default; + available_package_id (string, const bpkg::version&); + }; + + bool + operator< (const available_package_id&, const available_package_id&); + + #pragma db object pointer(shared_ptr) session + class available_package + { + public: + using version_type = bpkg::version; + + available_package_id id; + upstream_version version; + + // List of repositories to which this package version belongs (yes, + // in our world, it can be in multiple, unrelated repositories). + // + // Note that if the repository is the special root repository (its + // location is empty), then this is a transient (or "fake") object + // for an existing package archive or package directory. In this + // case the location is the path to the archive/directory and to + // determine which one it is, use file/dir_exists(). While on the + // topic of fake available_package objects, when one is created for + // a selected package (see make_available()), this list is left empty + // with the thinking being that since the package is already in at + // least fetched state, we shouldn't be needing its location. + // + vector locations; //@@ Map? + + // Package manifest data. + // + using dependencies_type = bpkg::dependencies; + + dependencies_type dependencies; + + // Present for non-transient objects only. + // + optional sha256sum; + + private: + #pragma db transient + mutable optional system_version_; + + public: + available_package (package_manifest&& m) + : id (move (m.name), m.version), + version (move (m.version)), + dependencies (move (m.dependencies)), + sha256sum (move (m.sha256sum)) {} + + // Create a stub available package with a fixed system version. This + // constructor is only used to create transient/fake available packages + // based on the system selected packages. + // + available_package (string n, version_type sysv) + : id (move (n), wildcard_version), + version (wildcard_version), + system_version_ (sysv) {} + + bool + stub () const {return version.compare (wildcard_version, true) == 0;} + + // Return package system version if one has been discovered. Note that + // we do not implicitly assume a wildcard version. + // + const version_type* + system_version () const + { + if (!system_version_) + { + if (const system_package* sp = system_repository.find (id.name)) + { + // Only cache if it is authoritative. + // + if (sp->authoritative) + system_version_ = sp->version; + else + return &sp->version; + } + } + + return system_version_ ? &*system_version_ : nullptr; + } + + // As above but also return an indication if the version information is + // authoritative. + // + pair + system_version_authoritative () const + { + const system_package* sp (system_repository.find (id.name)); + + if (!system_version_) + { + if (sp != nullptr) + { + // Only cache if it is authoritative. + // + if (sp->authoritative) + system_version_ = sp->version; + else + return make_pair (&sp->version, false); + } + } + + return make_pair (system_version_ ? &*system_version_ : nullptr, + sp != nullptr ? sp->authoritative : false); + } + + // Database mapping. + // + #pragma db member(id) id column("") + #pragma db member(version) set(this.version.init (this.id.version, (?))) + #pragma db member(locations) id_column("") value_column("") \ + unordered value_not_null + + // dependencies + // + using _dependency_key = odb::nested_key; + using _dependency_alternatives_type = + std::map<_dependency_key, dependency>; + + #pragma db value(_dependency_key) + #pragma db member(_dependency_key::outer) column("dependency_index") + #pragma db member(_dependency_key::inner) column("index") + + #pragma db member(dependencies) id_column("") value_column("") + #pragma db member(dependency_alternatives) \ + virtual(_dependency_alternatives_type) \ + after(dependencies) \ + get(odb::nested_get (this.dependencies)) \ + set(odb::nested_set (this.dependencies, std::move (?))) \ + id_column("") key_column("") value_column("dep_") + + private: + friend class odb::access; + available_package () = default; + }; + + #pragma db view object(available_package) + struct available_package_count + { + #pragma db column("count(*)") + size_t result; + + operator size_t () const {return result;} + }; + + // Only return packages that are in the specified repository or its + // complements, recursively. While you could maybe come up with a + // (barely comprehensible) view/query to achieve this, doing it on + // the "client side" is definitely more straightforward. + // + vector> + filter (const shared_ptr&, odb::result&&); + + pair, shared_ptr> + filter_one (const shared_ptr&, odb::result&&); + + // package_state + // + enum class package_state + { + transient, // No longer or not yet in the database. + broken, + fetched, + unpacked, + configured + }; + + string + to_string (package_state); + + package_state + to_package_state (const string&); // May throw invalid_argument. + + inline ostream& + operator<< (ostream& os, package_state s) {return os << to_string (s);} + + #pragma db map type(package_state) as(string) \ + to(to_string (?)) \ + from(bpkg::to_package_state (?)) + + // package_substate + // + enum class package_substate + { + none, + system // System package; valid states: configured. + }; + + string + to_string (package_substate); + + package_substate + to_package_substate (const string&); // May throw invalid_argument. + + inline ostream& + operator<< (ostream& os, package_substate s) {return os << to_string (s);} + + #pragma db map type(package_substate) as(string) \ + to(to_string (?)) \ + from(bpkg::to_package_substate (?)) + + // package + // + #pragma db object pointer(shared_ptr) session + class selected_package + { + public: + using version_type = bpkg::version; + + string name; // Object id. + version_type version; + package_state state; + package_substate substate; + + // The hold flags indicate whether this package and/or version + // should be retained in the configuration. A held package will + // not be automatically removed. A held version will not be + // automatically upgraded. Note also that the two flags are + // orthogonal: we may want to keep a specific version of the + // package as long as it has dependents. + // + bool hold_package; + bool hold_version; + + // Repository from which this package came. Note that it is not + // a pointer to the repository object because it could be wiped + // out (e.g., as a result of rep-fetch). We call such packages + // "orphans". While we can get a list of orphan's prerequisites + // (by loading its manifest), we wouldn't know which repository + // to use as a base to resolve them. As a result, an orphan that + // is not already configured (and thus has all its prerequisites + // resolved) is not very useful and can only be purged. + // + repository_location repository; + + // Path to the archive of this package, if any. If not absolute, + // then it is relative to the configuration directory. The purge + // flag indicates whether the archive should be removed when the + // packaged is purged. If the archive is not present, it should + // be false. + // + optional archive; + bool purge_archive; + + // Path to the source directory of this package, if any. If not + // absolute, then it is relative to the configuration directory. + // The purge flag indicates whether the directory should be + // removed when the packaged is purged. If the source directory + // is not present, it should be false. + // + optional src_root; + bool purge_src; + + // Path to the output directory of this package, if any. It is + // always relative to the configuration directory and currently + // is always -. It is only set once the package + // is configured and its main purse is to keep track of what + // needs to be cleaned by the user before a broken package can + // be purged. Note that it could be the same as out_root. + // + optional out_root; + + // A map of "effective" prerequisites (i.e., pointers to other selected + // packages) to optional dependency constraint. Note that because it is a + // single constraint, we don't support multiple dependencies on the same + // package (e.g., two ranges of versions). See pkg_configure(). + // + using prerequisites_type = std::map, + optional, + compare_lazy_ptr>; + prerequisites_type prerequisites; + + bool + system () const + { + // The system substate is only valid for the configured state. + // + assert (substate != package_substate::system || + state == package_state::configured); + + return substate == package_substate::system; + } + + // Represent the wildcard version with the "*" string. Represent naturally + // all other versions. + // + string + version_string () const; + + // Database mapping. + // + #pragma db member(name) id + + #pragma db member(prerequisites) id_column("package") \ + key_column("prerequisite") value_column("") key_not_null + + private: + friend class odb::access; + selected_package () = default; + }; + + // Print the package name, version and the 'sys:' prefix for the system + // substate. The wildcard version is represented with the "*" string. + // + ostream& + operator<< (ostream&, const selected_package&); + + // certificate + // + // Information extracted from a repository X.509 certificate. The actual + // certificate is stored on disk as .bpkg/certs/.pem (we have + // to store it as a file because that's the only way to pass it to openssl). + // + // If a repository is not authenticated (has no certificate/signature, + // called unauth from now on), then we ask for the user's confirmation and + // create a dummy certificate in order not to ask for the same confirmation + // (for this repository) on next fetch. The problem is, there could be + // multiple sections in such a repository and it would be annoying to + // confirm all of them. So what we are going to do is create a dummy + // certificate not for this specific repository location but for a + // repository location only up to the version, so the name member will + // contain the name prefix rather than the full name (just like a normal + // certificate would). The fingerprint member for such a dummy certificate + // contains the SHA256 checksum of this name. Members other then name and + // fingerprint are meaningless for the dummy certificate. + // + #pragma db object pointer(shared_ptr) session + class certificate + { + public: + string fingerprint; // Object id (note: SHA256 fingerprint). + + string name; // CN component of Subject. + string organization; // O component of Subject. + string email; // email: in Subject Alternative Name. + + timestamp start_date; // notBefore (UTC) + timestamp end_date; // notAfter (UTC) + + bool + dummy () const {return start_date == timestamp_unknown;} + + bool + expired () const + { + assert (!dummy ()); + return timestamp::clock::now () > end_date; + } + + public: + certificate (string f, + string n, + string o, + string e, + timestamp sd, + timestamp ed) + : fingerprint (move (f)), + name (move (n)), + organization (move (o)), + email (move (e)), + start_date (move (sd)), + end_date (move (ed)) + { + } + + // Create dummy certificate. + // + certificate (string f, string n) + : fingerprint (move (f)), + name (move (n)), + start_date (timestamp_unknown), + end_date (timestamp_unknown) + { + } + + // Database mapping. + // + #pragma db member(fingerprint) id + + private: + friend class odb::access; + certificate () = default; + }; + + // Note: prints all the certificate information on one line so mostly + // useful for tracing. + // + ostream& + operator<< (ostream&, const certificate&); + + // Return a list of packages that depend on this package along with + // their constraints. + // + /* + #pragma db view object(selected_package) \ + container(selected_package::prerequisites = pp inner: pp.key) + struct package_dependent + { + #pragma db column(pp.id) + string name; + + #pragma db column(pp.value) + optional constraint; + }; + */ + + // @@ Using raw container table since ODB doesn't support containers + // in views yet. + // + #pragma db view object(selected_package) \ + table("selected_package_prerequisites" = "pp" inner: \ + "pp.prerequisite = " + selected_package::name) + struct package_dependent + { + #pragma db column("pp.package") + string name; + + #pragma db column("pp.") + optional constraint; + }; + + + // Version comparison operators. + // + // They allow comparing objects that have epoch, canonical_upstream, + // canonical_release, and revision data members. The idea is that this + // works for both query members of types version and canonical_version + // as well as for comparing canonical_version to version. + // + template + inline auto + compare_version_eq (const T1& x, const T2& y, bool revision) + -> decltype (x.epoch == y.epoch) + { + // Since we don't quite know what T1 and T2 are (and where the resulting + // expression will run), let's not push our luck with something like + // (!revision || x.revision == y.revision). + // + auto r (x.epoch == y.epoch && + x.canonical_upstream == y.canonical_upstream && + x.canonical_release == y.canonical_release); + + return revision + ? r && x.revision == y.revision + : r; + } + + /* + Currently unused (and probably should stay that way). + + template + inline auto + operator== (const T1& x, const T2& y) -> decltype (x.epoch == y.epoch) + { + return compare_version_eq (x, y, true); + } + */ + + template + inline auto + compare_version_ne (const T1& x, const T2& y, bool revision) + -> decltype (x.epoch == y.epoch) + { + auto r (x.epoch != y.epoch || + x.canonical_upstream != y.canonical_upstream || + x.canonical_release != y.canonical_release); + + return revision + ? r || x.revision != y.revision + : r; + } + + template + inline auto + operator!= (const T1& x, const T2& y) -> decltype (x.epoch != y.epoch) + { + return compare_version_ne (x, y, true); + } + + template + inline auto + compare_version_lt (const T1& x, const T2& y, bool revision) + -> decltype (x.epoch == y.epoch) + { + auto r ( + x.epoch < y.epoch || + (x.epoch == y.epoch && x.canonical_upstream < y.canonical_upstream) || + (x.epoch == y.epoch && x.canonical_upstream == y.canonical_upstream && + x.canonical_release < y.canonical_release)); + + return revision + ? r || + (x.epoch == y.epoch && x.canonical_upstream == y.canonical_upstream && + x.canonical_release == y.canonical_release && x.revision < y.revision) + : r; + } + + template + inline auto + operator< (const T1& x, const T2& y) -> decltype (x.epoch < y.epoch) + { + return compare_version_lt (x, y, true); + } + + template + inline auto + compare_version_le (const T1& x, const T2& y, bool revision) + -> decltype (x.epoch == y.epoch) + { + auto r ( + x.epoch < y.epoch || + (x.epoch == y.epoch && x.canonical_upstream < y.canonical_upstream)); + + return revision + ? r || + (x.epoch == y.epoch && x.canonical_upstream == y.canonical_upstream && + x.canonical_release < y.canonical_release) || + (x.epoch == y.epoch && x.canonical_upstream == y.canonical_upstream && + x.canonical_release == y.canonical_release && x.revision <= y.revision) + : r || + (x.epoch == y.epoch && x.canonical_upstream == y.canonical_upstream && + x.canonical_release <= y.canonical_release); + } + + /* + Currently unused (and probably should stay that way). + + template + inline auto + operator<= (const T1& x, const T2& y) -> decltype (x.epoch <= y.epoch) + { + return compare_version_le (x, y, true); + } + */ + + template + inline auto + compare_version_gt (const T1& x, const T2& y, bool revision) + -> decltype (x.epoch == y.epoch) + { + auto r ( + x.epoch > y.epoch || + (x.epoch == y.epoch && x.canonical_upstream > y.canonical_upstream) || + (x.epoch == y.epoch && x.canonical_upstream == y.canonical_upstream && + x.canonical_release > y.canonical_release)); + + return revision + ? r || + (x.epoch == y.epoch && x.canonical_upstream == y.canonical_upstream && + x.canonical_release == y.canonical_release && x.revision > y.revision) + : r; + } + + template + inline auto + operator> (const T1& x, const T2& y) -> decltype (x.epoch > y.epoch) + { + return compare_version_gt (x, y, true); + } + + template + inline auto + compare_version_ge (const T1& x, const T2& y, bool revision) + -> decltype (x.epoch == y.epoch) + { + auto r ( + x.epoch > y.epoch || + (x.epoch == y.epoch && x.canonical_upstream > y.canonical_upstream)); + + return revision + ? r || + (x.epoch == y.epoch && x.canonical_upstream == y.canonical_upstream && + x.canonical_release > y.canonical_release) || + (x.epoch == y.epoch && x.canonical_upstream == y.canonical_upstream && + x.canonical_release == y.canonical_release && x.revision >= y.revision) + : r || + (x.epoch == y.epoch && x.canonical_upstream == y.canonical_upstream && + x.canonical_release >= y.canonical_release); + } + + template + inline auto + operator>= (const T1& x, const T2& y) -> decltype (x.epoch >= y.epoch) + { + return compare_version_ge (x, y, true); + } + + template + inline auto + order_by_version_desc (const T& x) -> //decltype ("ORDER BY" + x.epoch) + decltype (x.epoch == 0) + { + return "ORDER BY" + + x.epoch + "DESC," + + x.canonical_upstream + "DESC," + + x.canonical_release + "DESC," + + x.revision + "DESC"; + } + + template + inline auto + order_by_revision_desc (const T& x) -> //decltype ("ORDER BY" + x.epoch) + decltype (x.revision == 0) + { + return "ORDER BY" + x.revision + "DESC"; + } +} + +#include + +#endif // BPKG_PACKAGE_HXX diff --git a/bpkg/pkg-build b/bpkg/pkg-build deleted file mode 100644 index 2566965..0000000 --- a/bpkg/pkg-build +++ /dev/null @@ -1,19 +0,0 @@ -// file : bpkg/pkg-build -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_PKG_BUILD -#define BPKG_PKG_BUILD - -#include -#include - -#include - -namespace bpkg -{ - int - pkg_build (const pkg_build_options&, cli::scanner& args); -} - -#endif // BPKG_PKG_BUILD diff --git a/bpkg/pkg-build.cxx b/bpkg/pkg-build.cxx index 385ec81..de5c9c7 100644 --- a/bpkg/pkg-build.cxx +++ b/bpkg/pkg-build.cxx @@ -2,7 +2,7 @@ // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include +#include #include #include @@ -11,24 +11,24 @@ #include // cout #include // find() -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include using namespace std; using namespace butl; diff --git a/bpkg/pkg-build.hxx b/bpkg/pkg-build.hxx new file mode 100644 index 0000000..429e613 --- /dev/null +++ b/bpkg/pkg-build.hxx @@ -0,0 +1,19 @@ +// file : bpkg/pkg-build.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_PKG_BUILD_HXX +#define BPKG_PKG_BUILD_HXX + +#include +#include + +#include + +namespace bpkg +{ + int + pkg_build (const pkg_build_options&, cli::scanner& args); +} + +#endif // BPKG_PKG_BUILD_HXX diff --git a/bpkg/pkg-clean b/bpkg/pkg-clean deleted file mode 100644 index be8f4db..0000000 --- a/bpkg/pkg-clean +++ /dev/null @@ -1,23 +0,0 @@ -// file : bpkg/pkg-clean -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_PKG_CLEAN -#define BPKG_PKG_CLEAN - -#include -#include - -#include -#include - -namespace bpkg -{ - inline int - pkg_clean (const pkg_clean_options& o, cli::scanner& args) - { - return pkg_command ("clean", o, args); - } -} - -#endif // BPKG_PKG_CLEAN diff --git a/bpkg/pkg-clean.hxx b/bpkg/pkg-clean.hxx new file mode 100644 index 0000000..f1a983a --- /dev/null +++ b/bpkg/pkg-clean.hxx @@ -0,0 +1,23 @@ +// file : bpkg/pkg-clean.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_PKG_CLEAN_HXX +#define BPKG_PKG_CLEAN_HXX + +#include +#include + +#include +#include + +namespace bpkg +{ + inline int + pkg_clean (const pkg_clean_options& o, cli::scanner& args) + { + return pkg_command ("clean", o, args); + } +} + +#endif // BPKG_PKG_CLEAN_HXX diff --git a/bpkg/pkg-command b/bpkg/pkg-command deleted file mode 100644 index 4706c59..0000000 --- a/bpkg/pkg-command +++ /dev/null @@ -1,37 +0,0 @@ -// file : bpkg/pkg-command -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_PKG_COMMAND -#define BPKG_PKG_COMMAND - -#include -#include // selected_package -#include - -#include - -namespace bpkg -{ - // Common pkg-{update,clean,test,install,...} implementation. - // - int - pkg_command (const string& cmd, // Without the 'pkg-' prefix. - const configuration_options&, - cli::scanner& args); - - struct pkg_command_vars - { - shared_ptr pkg; - strings vars; - }; - - void - pkg_command (const string& cmd, - const dir_path& configuration, - const common_options&, - const strings& common_vars, - const vector&); -} - -#endif // BPKG_PKG_COMMAND diff --git a/bpkg/pkg-command.cxx b/bpkg/pkg-command.cxx index 6e6542f..980e593 100644 --- a/bpkg/pkg-command.cxx +++ b/bpkg/pkg-command.cxx @@ -2,12 +2,12 @@ // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include +#include -#include -#include -#include -#include +#include +#include +#include +#include using namespace std; using namespace butl; diff --git a/bpkg/pkg-command.hxx b/bpkg/pkg-command.hxx new file mode 100644 index 0000000..de6ccf9 --- /dev/null +++ b/bpkg/pkg-command.hxx @@ -0,0 +1,37 @@ +// file : bpkg/pkg-command.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_PKG_COMMAND_HXX +#define BPKG_PKG_COMMAND_HXX + +#include +#include // selected_package +#include + +#include + +namespace bpkg +{ + // Common pkg-{update,clean,test,install,...} implementation. + // + int + pkg_command (const string& cmd, // Without the 'pkg-' prefix. + const configuration_options&, + cli::scanner& args); + + struct pkg_command_vars + { + shared_ptr pkg; + strings vars; + }; + + void + pkg_command (const string& cmd, + const dir_path& configuration, + const common_options&, + const strings& common_vars, + const vector&); +} + +#endif // BPKG_PKG_COMMAND_HXX diff --git a/bpkg/pkg-configure b/bpkg/pkg-configure deleted file mode 100644 index 5867428..0000000 --- a/bpkg/pkg-configure +++ /dev/null @@ -1,35 +0,0 @@ -// file : bpkg/pkg-configure -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_PKG_CONFIGURE -#define BPKG_PKG_CONFIGURE - -#include -#include // transaction, selected_package -#include - -#include -#include - -namespace bpkg -{ - int - pkg_configure (const pkg_configure_options&, cli::scanner& args); - - // Configure the package, update its state, and commit the transaction. - // - void - pkg_configure (const dir_path& configuration, - const common_options&, - transaction&, - const shared_ptr&, - const strings& config_vars); - - // Configure a system package and commit the transaction. - // - shared_ptr - pkg_configure_system (const string& name, const version&, transaction&); -} - -#endif // BPKG_PKG_CONFIGURE diff --git a/bpkg/pkg-configure.cxx b/bpkg/pkg-configure.cxx index bc55be3..2ed51e5 100644 --- a/bpkg/pkg-configure.cxx +++ b/bpkg/pkg-configure.cxx @@ -2,17 +2,17 @@ // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include +#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include -#include -#include +#include +#include using namespace std; using namespace butl; diff --git a/bpkg/pkg-configure.hxx b/bpkg/pkg-configure.hxx new file mode 100644 index 0000000..651daba --- /dev/null +++ b/bpkg/pkg-configure.hxx @@ -0,0 +1,35 @@ +// file : bpkg/pkg-configure.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_PKG_CONFIGURE_HXX +#define BPKG_PKG_CONFIGURE_HXX + +#include +#include // transaction, selected_package +#include + +#include +#include + +namespace bpkg +{ + int + pkg_configure (const pkg_configure_options&, cli::scanner& args); + + // Configure the package, update its state, and commit the transaction. + // + void + pkg_configure (const dir_path& configuration, + const common_options&, + transaction&, + const shared_ptr&, + const strings& config_vars); + + // Configure a system package and commit the transaction. + // + shared_ptr + pkg_configure_system (const string& name, const version&, transaction&); +} + +#endif // BPKG_PKG_CONFIGURE_HXX diff --git a/bpkg/pkg-disfigure b/bpkg/pkg-disfigure deleted file mode 100644 index 6dfe60b..0000000 --- a/bpkg/pkg-disfigure +++ /dev/null @@ -1,32 +0,0 @@ -// file : bpkg/pkg-disfigure -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_PKG_DISFIGURE -#define BPKG_PKG_DISFIGURE - -#include -#include // transaction, selected_package -#include - -#include - -namespace bpkg -{ - int - pkg_disfigure (const pkg_disfigure_options&, cli::scanner& args); - - // Disfigure the package, update its state, and commit the - // transaction. If the package state is broken, then this - // is taken to mean it hasn't been successfully configured - // and no clean prior to disfigure is necessary (or possible, - // for that matter). - // - void - pkg_disfigure (const dir_path& configuration, - const common_options&, - transaction&, - const shared_ptr&); -} - -#endif // BPKG_PKG_DISFIGURE diff --git a/bpkg/pkg-disfigure.cxx b/bpkg/pkg-disfigure.cxx index 09b3056..4c32d53 100644 --- a/bpkg/pkg-disfigure.cxx +++ b/bpkg/pkg-disfigure.cxx @@ -2,12 +2,12 @@ // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include +#include -#include -#include -#include -#include +#include +#include +#include +#include using namespace std; using namespace butl; diff --git a/bpkg/pkg-disfigure.hxx b/bpkg/pkg-disfigure.hxx new file mode 100644 index 0000000..920fc7c --- /dev/null +++ b/bpkg/pkg-disfigure.hxx @@ -0,0 +1,32 @@ +// file : bpkg/pkg-disfigure.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_PKG_DISFIGURE_HXX +#define BPKG_PKG_DISFIGURE_HXX + +#include +#include // transaction, selected_package +#include + +#include + +namespace bpkg +{ + int + pkg_disfigure (const pkg_disfigure_options&, cli::scanner& args); + + // Disfigure the package, update its state, and commit the + // transaction. If the package state is broken, then this + // is taken to mean it hasn't been successfully configured + // and no clean prior to disfigure is necessary (or possible, + // for that matter). + // + void + pkg_disfigure (const dir_path& configuration, + const common_options&, + transaction&, + const shared_ptr&); +} + +#endif // BPKG_PKG_DISFIGURE_HXX diff --git a/bpkg/pkg-drop b/bpkg/pkg-drop deleted file mode 100644 index ffb7b35..0000000 --- a/bpkg/pkg-drop +++ /dev/null @@ -1,33 +0,0 @@ -// file : bpkg/pkg-drop -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_PKG_DROP -#define BPKG_PKG_DROP - -#include - -#include -#include // database, selected_package -#include - -#include - -namespace bpkg -{ - int - pkg_drop (const pkg_drop_options&, cli::scanner& args); - - // Examine the list of prerequisite packages and drop those that don't - // have any dependents. Return the set of packages that were actually - // dropped. Note that it should be called in session. - // - std::set> - pkg_drop (const dir_path& configuration, - const common_options&, - database&, - const std::set>&, - bool prompt); -} - -#endif // BPKG_PKG_DROP diff --git a/bpkg/pkg-drop.cxx b/bpkg/pkg-drop.cxx index 85ad897..4309b2e 100644 --- a/bpkg/pkg-drop.cxx +++ b/bpkg/pkg-drop.cxx @@ -2,23 +2,23 @@ // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include +#include #include #include #include // cout -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include -#include +#include -#include -#include +#include +#include using namespace std; using namespace butl; diff --git a/bpkg/pkg-drop.hxx b/bpkg/pkg-drop.hxx new file mode 100644 index 0000000..b7e0be1 --- /dev/null +++ b/bpkg/pkg-drop.hxx @@ -0,0 +1,33 @@ +// file : bpkg/pkg-drop.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_PKG_DROP_HXX +#define BPKG_PKG_DROP_HXX + +#include + +#include +#include // database, selected_package +#include + +#include + +namespace bpkg +{ + int + pkg_drop (const pkg_drop_options&, cli::scanner& args); + + // Examine the list of prerequisite packages and drop those that don't + // have any dependents. Return the set of packages that were actually + // dropped. Note that it should be called in session. + // + std::set> + pkg_drop (const dir_path& configuration, + const common_options&, + database&, + const std::set>&, + bool prompt); +} + +#endif // BPKG_PKG_DROP_HXX diff --git a/bpkg/pkg-fetch b/bpkg/pkg-fetch deleted file mode 100644 index 2ce0cb5..0000000 --- a/bpkg/pkg-fetch +++ /dev/null @@ -1,42 +0,0 @@ -// file : bpkg/pkg-fetch -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_PKG_FETCH -#define BPKG_PKG_FETCH - -#include // version - -#include -#include // transaction, selected_package -#include - -#include - -namespace bpkg -{ - int - pkg_fetch (const pkg_fetch_options&, cli::scanner& args); - - // Fetch the package as an archive file and commit the transaction. - // - shared_ptr - pkg_fetch (const common_options&, - const dir_path& configuration, - transaction&, - path archive, - bool replace, - bool purge); - - // Fetch the package from a repository and commit the transaction. - // - shared_ptr - pkg_fetch (const common_options&, - const dir_path& configuration, - transaction&, - string name, - version, - bool replace); -} - -#endif // BPKG_PKG_FETCH diff --git a/bpkg/pkg-fetch.cxx b/bpkg/pkg-fetch.cxx index 9995db3..114a55d 100644 --- a/bpkg/pkg-fetch.cxx +++ b/bpkg/pkg-fetch.cxx @@ -2,20 +2,20 @@ // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include +#include -#include +#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include -#include -#include +#include +#include using namespace std; using namespace butl; diff --git a/bpkg/pkg-fetch.hxx b/bpkg/pkg-fetch.hxx new file mode 100644 index 0000000..d17dbdf --- /dev/null +++ b/bpkg/pkg-fetch.hxx @@ -0,0 +1,42 @@ +// file : bpkg/pkg-fetch.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_PKG_FETCH_HXX +#define BPKG_PKG_FETCH_HXX + +#include // version + +#include +#include // transaction, selected_package +#include + +#include + +namespace bpkg +{ + int + pkg_fetch (const pkg_fetch_options&, cli::scanner& args); + + // Fetch the package as an archive file and commit the transaction. + // + shared_ptr + pkg_fetch (const common_options&, + const dir_path& configuration, + transaction&, + path archive, + bool replace, + bool purge); + + // Fetch the package from a repository and commit the transaction. + // + shared_ptr + pkg_fetch (const common_options&, + const dir_path& configuration, + transaction&, + string name, + version, + bool replace); +} + +#endif // BPKG_PKG_FETCH_HXX diff --git a/bpkg/pkg-install b/bpkg/pkg-install deleted file mode 100644 index eaaef09..0000000 --- a/bpkg/pkg-install +++ /dev/null @@ -1,24 +0,0 @@ -// file : bpkg/pkg-install -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_PKG_INSTALL -#define BPKG_PKG_INSTALL - -#include -#include // selected_package -#include - -#include -#include - -namespace bpkg -{ - inline int - pkg_install (const pkg_install_options& o, cli::scanner& args) - { - return pkg_command ("install", o, args); - } -} - -#endif // BPKG_PKG_INSTALL diff --git a/bpkg/pkg-install.hxx b/bpkg/pkg-install.hxx new file mode 100644 index 0000000..83ad4de --- /dev/null +++ b/bpkg/pkg-install.hxx @@ -0,0 +1,24 @@ +// file : bpkg/pkg-install.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_PKG_INSTALL_HXX +#define BPKG_PKG_INSTALL_HXX + +#include +#include // selected_package +#include + +#include +#include + +namespace bpkg +{ + inline int + pkg_install (const pkg_install_options& o, cli::scanner& args) + { + return pkg_command ("install", o, args); + } +} + +#endif // BPKG_PKG_INSTALL_HXX diff --git a/bpkg/pkg-purge b/bpkg/pkg-purge deleted file mode 100644 index 4e6f0c2..0000000 --- a/bpkg/pkg-purge +++ /dev/null @@ -1,38 +0,0 @@ -// file : bpkg/pkg-purge -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_PKG_PURGE -#define BPKG_PKG_PURGE - -#include -#include // transaction, selected_package -#include - -#include - -namespace bpkg -{ - int - pkg_purge (const pkg_purge_options&, cli::scanner& args); - - // Purge the package, remove it from the database, and commit the - // transaction. If this fails, set the package state to broken. - // - void - pkg_purge (const dir_path& configuration, - transaction&, - const shared_ptr&); - - // Remove package's filesystem objects (the source directory and, if - // the archive argument is true, the package archive). If this fails, - // set the package state to broken, commit the transaction, and fail. - // - void - pkg_purge_fs (const dir_path& configuration, - transaction&, - const shared_ptr&, - bool archive = true); -} - -#endif // BPKG_PKG_PURGE diff --git a/bpkg/pkg-purge.cxx b/bpkg/pkg-purge.cxx index 1b61c5c..7b58461 100644 --- a/bpkg/pkg-purge.cxx +++ b/bpkg/pkg-purge.cxx @@ -2,12 +2,12 @@ // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include +#include -#include -#include -#include -#include +#include +#include +#include +#include using namespace std; using namespace butl; diff --git a/bpkg/pkg-purge.hxx b/bpkg/pkg-purge.hxx new file mode 100644 index 0000000..9468a02 --- /dev/null +++ b/bpkg/pkg-purge.hxx @@ -0,0 +1,38 @@ +// file : bpkg/pkg-purge.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_PKG_PURGE_HXX +#define BPKG_PKG_PURGE_HXX + +#include +#include // transaction, selected_package +#include + +#include + +namespace bpkg +{ + int + pkg_purge (const pkg_purge_options&, cli::scanner& args); + + // Purge the package, remove it from the database, and commit the + // transaction. If this fails, set the package state to broken. + // + void + pkg_purge (const dir_path& configuration, + transaction&, + const shared_ptr&); + + // Remove package's filesystem objects (the source directory and, if + // the archive argument is true, the package archive). If this fails, + // set the package state to broken, commit the transaction, and fail. + // + void + pkg_purge_fs (const dir_path& configuration, + transaction&, + const shared_ptr&, + bool archive = true); +} + +#endif // BPKG_PKG_PURGE_HXX diff --git a/bpkg/pkg-status b/bpkg/pkg-status deleted file mode 100644 index f2d5493..0000000 --- a/bpkg/pkg-status +++ /dev/null @@ -1,19 +0,0 @@ -// file : bpkg/pkg-status -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_PKG_STATUS -#define BPKG_PKG_STATUS - -#include -#include - -#include - -namespace bpkg -{ - int - pkg_status (const pkg_status_options&, cli::scanner& args); -} - -#endif // BPKG_PKG_STATUS diff --git a/bpkg/pkg-status.cxx b/bpkg/pkg-status.cxx index 56d4c6a..84f7ce8 100644 --- a/bpkg/pkg-status.cxx +++ b/bpkg/pkg-status.cxx @@ -2,15 +2,15 @@ // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include +#include #include // cout -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include using namespace std; using namespace butl; diff --git a/bpkg/pkg-status.hxx b/bpkg/pkg-status.hxx new file mode 100644 index 0000000..b2afd0f --- /dev/null +++ b/bpkg/pkg-status.hxx @@ -0,0 +1,19 @@ +// file : bpkg/pkg-status.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_PKG_STATUS_HXX +#define BPKG_PKG_STATUS_HXX + +#include +#include + +#include + +namespace bpkg +{ + int + pkg_status (const pkg_status_options&, cli::scanner& args); +} + +#endif // BPKG_PKG_STATUS_HXX diff --git a/bpkg/pkg-test b/bpkg/pkg-test deleted file mode 100644 index dffcdd7..0000000 --- a/bpkg/pkg-test +++ /dev/null @@ -1,23 +0,0 @@ -// file : bpkg/pkg-test -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_PKG_TEST -#define BPKG_PKG_TEST - -#include -#include - -#include -#include - -namespace bpkg -{ - inline int - pkg_test (const pkg_test_options& o, cli::scanner& args) - { - return pkg_command ("test", o, args); - } -} - -#endif // BPKG_PKG_TEST diff --git a/bpkg/pkg-test.hxx b/bpkg/pkg-test.hxx new file mode 100644 index 0000000..dd27c9c --- /dev/null +++ b/bpkg/pkg-test.hxx @@ -0,0 +1,23 @@ +// file : bpkg/pkg-test.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_PKG_TEST_HXX +#define BPKG_PKG_TEST_HXX + +#include +#include + +#include +#include + +namespace bpkg +{ + inline int + pkg_test (const pkg_test_options& o, cli::scanner& args) + { + return pkg_command ("test", o, args); + } +} + +#endif // BPKG_PKG_TEST_HXX diff --git a/bpkg/pkg-uninstall b/bpkg/pkg-uninstall deleted file mode 100644 index 9033ce4..0000000 --- a/bpkg/pkg-uninstall +++ /dev/null @@ -1,24 +0,0 @@ -// file : bpkg/pkg-uninstall -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_PKG_UNINSTALL -#define BPKG_PKG_UNINSTALL - -#include -#include // selected_package -#include - -#include -#include - -namespace bpkg -{ - inline int - pkg_uninstall (const pkg_uninstall_options& o, cli::scanner& args) - { - return pkg_command ("uninstall", o, args); - } -} - -#endif // BPKG_PKG_UNINSTALL diff --git a/bpkg/pkg-uninstall.hxx b/bpkg/pkg-uninstall.hxx new file mode 100644 index 0000000..2464d62 --- /dev/null +++ b/bpkg/pkg-uninstall.hxx @@ -0,0 +1,24 @@ +// file : bpkg/pkg-uninstall.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_PKG_UNINSTALL_HXX +#define BPKG_PKG_UNINSTALL_HXX + +#include +#include // selected_package +#include + +#include +#include + +namespace bpkg +{ + inline int + pkg_uninstall (const pkg_uninstall_options& o, cli::scanner& args) + { + return pkg_command ("uninstall", o, args); + } +} + +#endif // BPKG_PKG_UNINSTALL_HXX diff --git a/bpkg/pkg-unpack b/bpkg/pkg-unpack deleted file mode 100644 index a7eaab7..0000000 --- a/bpkg/pkg-unpack +++ /dev/null @@ -1,37 +0,0 @@ -// file : bpkg/pkg-unpack -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_PKG_UNPACK -#define BPKG_PKG_UNPACK - -#include -#include // transaction, selected_package -#include - -#include - -namespace bpkg -{ - int - pkg_unpack (const pkg_unpack_options&, cli::scanner& args); - - // Unpack the package as a source directory and commit the transaction. - // - shared_ptr - pkg_unpack (const dir_path& configuration, - transaction&, - const dir_path&, - bool replace, - bool purge); - - // Unpack the fetched package and commit the transaction. - // - shared_ptr - pkg_unpack (const common_options&, - const dir_path& configuration, - transaction&, - const string& name); -} - -#endif // BPKG_PKG_UNPACK diff --git a/bpkg/pkg-unpack.cxx b/bpkg/pkg-unpack.cxx index 9aead38..21883d9 100644 --- a/bpkg/pkg-unpack.cxx +++ b/bpkg/pkg-unpack.cxx @@ -2,19 +2,19 @@ // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include +#include #include -#include +#include -#include -#include -#include -#include +#include +#include +#include +#include -#include -#include +#include +#include using namespace std; using namespace butl; diff --git a/bpkg/pkg-unpack.hxx b/bpkg/pkg-unpack.hxx new file mode 100644 index 0000000..39b4e83 --- /dev/null +++ b/bpkg/pkg-unpack.hxx @@ -0,0 +1,37 @@ +// file : bpkg/pkg-unpack.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_PKG_UNPACK_HXX +#define BPKG_PKG_UNPACK_HXX + +#include +#include // transaction, selected_package +#include + +#include + +namespace bpkg +{ + int + pkg_unpack (const pkg_unpack_options&, cli::scanner& args); + + // Unpack the package as a source directory and commit the transaction. + // + shared_ptr + pkg_unpack (const dir_path& configuration, + transaction&, + const dir_path&, + bool replace, + bool purge); + + // Unpack the fetched package and commit the transaction. + // + shared_ptr + pkg_unpack (const common_options&, + const dir_path& configuration, + transaction&, + const string& name); +} + +#endif // BPKG_PKG_UNPACK_HXX diff --git a/bpkg/pkg-update b/bpkg/pkg-update deleted file mode 100644 index 7c6fe02..0000000 --- a/bpkg/pkg-update +++ /dev/null @@ -1,33 +0,0 @@ -// file : bpkg/pkg-update -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_PKG_UPDATE -#define BPKG_PKG_UPDATE - -#include -#include // selected_package -#include - -#include -#include - -namespace bpkg -{ - inline int - pkg_update (const pkg_update_options& o, cli::scanner& args) - { - return pkg_command ("update", o, args); - } - - inline void - pkg_update (const dir_path& configuration, - const common_options& o, - const strings& common_vars, - const vector& pkgs) - { - pkg_command ("update", configuration, o, common_vars, pkgs); - } -} - -#endif // BPKG_PKG_UPDATE diff --git a/bpkg/pkg-update.hxx b/bpkg/pkg-update.hxx new file mode 100644 index 0000000..5f62bd9 --- /dev/null +++ b/bpkg/pkg-update.hxx @@ -0,0 +1,33 @@ +// file : bpkg/pkg-update.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_PKG_UPDATE_HXX +#define BPKG_PKG_UPDATE_HXX + +#include +#include // selected_package +#include + +#include +#include + +namespace bpkg +{ + inline int + pkg_update (const pkg_update_options& o, cli::scanner& args) + { + return pkg_command ("update", o, args); + } + + inline void + pkg_update (const dir_path& configuration, + const common_options& o, + const strings& common_vars, + const vector& pkgs) + { + pkg_command ("update", configuration, o, common_vars, pkgs); + } +} + +#endif // BPKG_PKG_UPDATE_HXX diff --git a/bpkg/pkg-verify b/bpkg/pkg-verify deleted file mode 100644 index ac43bf1..0000000 --- a/bpkg/pkg-verify +++ /dev/null @@ -1,39 +0,0 @@ -// file : bpkg/pkg-verify -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_PKG_VERIFY -#define BPKG_PKG_VERIFY - -#include - -#include -#include - -#include - -namespace bpkg -{ - int - pkg_verify (const pkg_verify_options&, cli::scanner& args); - - // Verify archive is a valid package and return its manifest. Throw - // failed if invalid or if something goes wrong. If diag is false, - // then don't issue diagnostics about the reason why the package is - // invalid. - // - package_manifest - pkg_verify (const common_options&, - const path& archive, - bool ignore_unknown, - bool diag = true); - - // Similar to the above but verifies that a source directory is a valid - // package. Note that it doesn't enforce the - form for the - // directory itself. - // - package_manifest - pkg_verify (const dir_path& source, bool ignore_unknown, bool diag = true); -} - -#endif // BPKG_PKG_VERIFY diff --git a/bpkg/pkg-verify.cxx b/bpkg/pkg-verify.cxx index 275c710..e4535f3 100644 --- a/bpkg/pkg-verify.cxx +++ b/bpkg/pkg-verify.cxx @@ -2,14 +2,14 @@ // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include +#include #include #include #include -#include -#include +#include +#include using namespace std; using namespace butl; diff --git a/bpkg/pkg-verify.hxx b/bpkg/pkg-verify.hxx new file mode 100644 index 0000000..a96442c --- /dev/null +++ b/bpkg/pkg-verify.hxx @@ -0,0 +1,39 @@ +// file : bpkg/pkg-verify.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_PKG_VERIFY_HXX +#define BPKG_PKG_VERIFY_HXX + +#include + +#include +#include + +#include + +namespace bpkg +{ + int + pkg_verify (const pkg_verify_options&, cli::scanner& args); + + // Verify archive is a valid package and return its manifest. Throw + // failed if invalid or if something goes wrong. If diag is false, + // then don't issue diagnostics about the reason why the package is + // invalid. + // + package_manifest + pkg_verify (const common_options&, + const path& archive, + bool ignore_unknown, + bool diag = true); + + // Similar to the above but verifies that a source directory is a valid + // package. Note that it doesn't enforce the - form for the + // directory itself. + // + package_manifest + pkg_verify (const dir_path& source, bool ignore_unknown, bool diag = true); +} + +#endif // BPKG_PKG_VERIFY_HXX diff --git a/bpkg/rep-add b/bpkg/rep-add deleted file mode 100644 index e687dea..0000000 --- a/bpkg/rep-add +++ /dev/null @@ -1,19 +0,0 @@ -// file : bpkg/rep-add -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_REP_ADD -#define BPKG_REP_ADD - -#include -#include - -#include - -namespace bpkg -{ - int - rep_add (const rep_add_options&, cli::scanner& args); -} - -#endif // BPKG_REP_ADD diff --git a/bpkg/rep-add.cxx b/bpkg/rep-add.cxx index 93d9925..6de0738 100644 --- a/bpkg/rep-add.cxx +++ b/bpkg/rep-add.cxx @@ -2,13 +2,13 @@ // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include +#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include using namespace std; using namespace butl; diff --git a/bpkg/rep-add.hxx b/bpkg/rep-add.hxx new file mode 100644 index 0000000..9f91713 --- /dev/null +++ b/bpkg/rep-add.hxx @@ -0,0 +1,19 @@ +// file : bpkg/rep-add.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_REP_ADD_HXX +#define BPKG_REP_ADD_HXX + +#include +#include + +#include + +namespace bpkg +{ + int + rep_add (const rep_add_options&, cli::scanner& args); +} + +#endif // BPKG_REP_ADD_HXX diff --git a/bpkg/rep-create b/bpkg/rep-create deleted file mode 100644 index 8f1d906..0000000 --- a/bpkg/rep-create +++ /dev/null @@ -1,19 +0,0 @@ -// file : bpkg/rep-create -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_REP_CREATE -#define BPKG_REP_CREATE - -#include -#include - -#include - -namespace bpkg -{ - int - rep_create (const rep_create_options&, cli::scanner& args); -} - -#endif // BPKG_REP_CREATE diff --git a/bpkg/rep-create.cxx b/bpkg/rep-create.cxx index 1762c31..b38d418 100644 --- a/bpkg/rep-create.cxx +++ b/bpkg/rep-create.cxx @@ -2,7 +2,7 @@ // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include +#include #include @@ -10,15 +10,15 @@ #include // dir_iterator #include -#include +#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include -#include +#include using namespace std; using namespace butl; diff --git a/bpkg/rep-create.hxx b/bpkg/rep-create.hxx new file mode 100644 index 0000000..b177267 --- /dev/null +++ b/bpkg/rep-create.hxx @@ -0,0 +1,19 @@ +// file : bpkg/rep-create.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_REP_CREATE_HXX +#define BPKG_REP_CREATE_HXX + +#include +#include + +#include + +namespace bpkg +{ + int + rep_create (const rep_create_options&, cli::scanner& args); +} + +#endif // BPKG_REP_CREATE_HXX diff --git a/bpkg/rep-fetch b/bpkg/rep-fetch deleted file mode 100644 index 4569e93..0000000 --- a/bpkg/rep-fetch +++ /dev/null @@ -1,19 +0,0 @@ -// file : bpkg/rep-fetch -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_REP_FETCH -#define BPKG_REP_FETCH - -#include -#include - -#include - -namespace bpkg -{ - int - rep_fetch (const rep_fetch_options&, cli::scanner& args); -} - -#endif // BPKG_REP_FETCH diff --git a/bpkg/rep-fetch.cxx b/bpkg/rep-fetch.cxx index 35bfb1a..2a298b8 100644 --- a/bpkg/rep-fetch.cxx +++ b/bpkg/rep-fetch.cxx @@ -2,16 +2,16 @@ // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include +#include -#include +#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include using namespace std; using namespace butl; diff --git a/bpkg/rep-fetch.hxx b/bpkg/rep-fetch.hxx new file mode 100644 index 0000000..ccc9e11 --- /dev/null +++ b/bpkg/rep-fetch.hxx @@ -0,0 +1,19 @@ +// file : bpkg/rep-fetch.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_REP_FETCH_HXX +#define BPKG_REP_FETCH_HXX + +#include +#include + +#include + +namespace bpkg +{ + int + rep_fetch (const rep_fetch_options&, cli::scanner& args); +} + +#endif // BPKG_REP_FETCH_HXX diff --git a/bpkg/rep-info b/bpkg/rep-info deleted file mode 100644 index fffea10..0000000 --- a/bpkg/rep-info +++ /dev/null @@ -1,19 +0,0 @@ -// file : bpkg/rep-info -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_REP_INFO -#define BPKG_REP_INFO - -#include -#include - -#include - -namespace bpkg -{ - int - rep_info (const rep_info_options&, cli::scanner& args); -} - -#endif // BPKG_REP_INFO diff --git a/bpkg/rep-info.cxx b/bpkg/rep-info.cxx index 9acbdcc..7dbb0f9 100644 --- a/bpkg/rep-info.cxx +++ b/bpkg/rep-info.cxx @@ -2,20 +2,20 @@ // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include +#include #include // cout #include // sha256_to_fingerprint() #include -#include +#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include using namespace std; using namespace butl; diff --git a/bpkg/rep-info.hxx b/bpkg/rep-info.hxx new file mode 100644 index 0000000..6bd5279 --- /dev/null +++ b/bpkg/rep-info.hxx @@ -0,0 +1,19 @@ +// file : bpkg/rep-info.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_REP_INFO_HXX +#define BPKG_REP_INFO_HXX + +#include +#include + +#include + +namespace bpkg +{ + int + rep_info (const rep_info_options&, cli::scanner& args); +} + +#endif // BPKG_REP_INFO_HXX diff --git a/bpkg/repository-signing.cli b/bpkg/repository-signing.cli index a702fd8..1b73fc2 100644 --- a/bpkg/repository-signing.cli +++ b/bpkg/repository-signing.cli @@ -2,7 +2,7 @@ // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -include ; +include ; "\section=1" "\name=bpkg-repository-signing" diff --git a/bpkg/satisfaction b/bpkg/satisfaction deleted file mode 100644 index 6f8ce45..0000000 --- a/bpkg/satisfaction +++ /dev/null @@ -1,50 +0,0 @@ -// file : bpkg/satisfaction -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_SATISFACTION -#define BPKG_SATISFACTION - -#include -#include - -#include -#include - -namespace bpkg -{ - // Return true if version satisfies the constraint. - // - bool - satisfies (const version&, const dependency_constraint&); - - inline bool - satisfies (const version& v, const optional& c) - { - return !c || satisfies (v, *c); - } - - // Return true if any version that satisfies l also satisfies r, or, in - // other words, l is stricter than or equal to r. Or, in yet other words, - // l is a subset of r. - // - bool - satisfies (const dependency_constraint& l, const dependency_constraint& r); - - inline bool - satisfies (const optional& l, - const optional& r) - { - return l ? (!r || satisfies (*l, *r)) : !r; - } - - // Special build-time dependencies. - // - void - satisfy_build2 (const common_options&, const string& pkg, const dependency&); - - void - satisfy_bpkg (const common_options&, const string& pkg, const dependency&); -} - -#endif // BPKG_SATISFACTION diff --git a/bpkg/satisfaction.cxx b/bpkg/satisfaction.cxx index bf033e9..7bcf1fd 100644 --- a/bpkg/satisfaction.cxx +++ b/bpkg/satisfaction.cxx @@ -2,14 +2,14 @@ // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include +#include #include #include -#include -#include -#include +#include +#include +#include using namespace std; using namespace butl; diff --git a/bpkg/satisfaction.hxx b/bpkg/satisfaction.hxx new file mode 100644 index 0000000..8def6a1 --- /dev/null +++ b/bpkg/satisfaction.hxx @@ -0,0 +1,50 @@ +// file : bpkg/satisfaction.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_SATISFACTION_HXX +#define BPKG_SATISFACTION_HXX + +#include +#include + +#include +#include + +namespace bpkg +{ + // Return true if version satisfies the constraint. + // + bool + satisfies (const version&, const dependency_constraint&); + + inline bool + satisfies (const version& v, const optional& c) + { + return !c || satisfies (v, *c); + } + + // Return true if any version that satisfies l also satisfies r, or, in + // other words, l is stricter than or equal to r. Or, in yet other words, + // l is a subset of r. + // + bool + satisfies (const dependency_constraint& l, const dependency_constraint& r); + + inline bool + satisfies (const optional& l, + const optional& r) + { + return l ? (!r || satisfies (*l, *r)) : !r; + } + + // Special build-time dependencies. + // + void + satisfy_build2 (const common_options&, const string& pkg, const dependency&); + + void + satisfy_bpkg (const common_options&, const string& pkg, const dependency&); +} + +#endif // BPKG_SATISFACTION_HXX diff --git a/bpkg/system-repository b/bpkg/system-repository deleted file mode 100644 index 44b8c4e..0000000 --- a/bpkg/system-repository +++ /dev/null @@ -1,55 +0,0 @@ -// file : bpkg/system-repository -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_SYSTEM_REPOSITORY -#define BPKG_SYSTEM_REPOSITORY - -#include - -#include - -#include -#include - -namespace bpkg -{ - // A map of discovered system package versions. The information can be - // authoritative (i.e., it was provided by the user or auto-discovered - // on this run) or non-authoritative (i.e., comes from selected_packages - // that are present in the database; in a sence it was authoritative but - // on some previous run. - // - // Note that in our model we assume that once an authoritative version has - // been discovered, it does not change (on this run; see caching logic in - // available package). - // - struct system_package - { - using version_type = bpkg::version; - - version_type version; - bool authoritative; - }; - - class system_repository_type - { - public: - const version& - insert (const string& name, const version&, bool authoritative); - - const system_package* - find (const string& name) - { - auto i (map_.find (name)); - return i != map_.end () ? &i->second : nullptr; - } - - private: - std::map map_; - }; - - extern system_repository_type system_repository; -} - -#endif // BPKG_SYSTEM_REPOSITORY diff --git a/bpkg/system-repository.cxx b/bpkg/system-repository.cxx index 3d0a0c0..3c329d6 100644 --- a/bpkg/system-repository.cxx +++ b/bpkg/system-repository.cxx @@ -2,7 +2,7 @@ // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include +#include namespace bpkg { diff --git a/bpkg/system-repository.hxx b/bpkg/system-repository.hxx new file mode 100644 index 0000000..b28e758 --- /dev/null +++ b/bpkg/system-repository.hxx @@ -0,0 +1,55 @@ +// file : bpkg/system-repository.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_SYSTEM_REPOSITORY_HXX +#define BPKG_SYSTEM_REPOSITORY_HXX + +#include + +#include + +#include +#include + +namespace bpkg +{ + // A map of discovered system package versions. The information can be + // authoritative (i.e., it was provided by the user or auto-discovered + // on this run) or non-authoritative (i.e., comes from selected_packages + // that are present in the database; in a sence it was authoritative but + // on some previous run. + // + // Note that in our model we assume that once an authoritative version has + // been discovered, it does not change (on this run; see caching logic in + // available package). + // + struct system_package + { + using version_type = bpkg::version; + + version_type version; + bool authoritative; + }; + + class system_repository_type + { + public: + const version& + insert (const string& name, const version&, bool authoritative); + + const system_package* + find (const string& name) + { + auto i (map_.find (name)); + return i != map_.end () ? &i->second : nullptr; + } + + private: + std::map map_; + }; + + extern system_repository_type system_repository; +} + +#endif // BPKG_SYSTEM_REPOSITORY_HXX diff --git a/bpkg/types b/bpkg/types deleted file mode 100644 index cfe2add..0000000 --- a/bpkg/types +++ /dev/null @@ -1,104 +0,0 @@ -// file : bpkg/types -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_TYPES -#define BPKG_TYPES - -#include -#include -#include // unique_ptr, shared_ptr -#include // pair -#include // size_t, nullptr_t -#include // uint{8,16,32,64}_t -#include -#include -#include // function, reference_wrapper - -#include // ios_base::failure -#include // exception -#include // logic_error, invalid_argument, runtime_error -#include - -#include - -#include -#include - -namespace bpkg -{ - // Commonly-used types. - // - using std::uint8_t; - using std::uint16_t; - using std::uint32_t; - using std::uint64_t; - - using std::size_t; - using std::nullptr_t; - - using std::pair; - using std::string; - using std::function; - using std::reference_wrapper; - - using std::unique_ptr; - using std::shared_ptr; - using std::weak_ptr; - - using std::vector; - - using strings = vector; - using cstrings = vector; - - using std::istream; - using std::ostream; - - // Exceptions. While is included, there is no using for - // std::exception -- use qualified. - // - using std::logic_error; - using std::invalid_argument; - using std::runtime_error; - using std::system_error; - using io_error = std::ios_base::failure; - - // - // - using butl::optional; - using butl::nullopt; - - // ODB smart pointers. - // - using odb::lazy_shared_ptr; - using odb::lazy_weak_ptr; - - // - // - using butl::path; - using butl::dir_path; - using butl::basic_path; - using butl::invalid_path; - - using paths = std::vector; - using dir_paths = std::vector; -} - -// In order to be found (via ADL) these have to be either in std:: or in -// butl::. The latter is bad idea since libbutl includes the default -// implementation. -// -namespace std -{ - // Custom path printing (canonicalized, with trailing slash for directories). - // - inline ostream& - operator<< (ostream& os, const ::butl::path& p) - { - string r (p.representation ()); - ::butl::path::traits::canonicalize (r); - return os << r; - } -} - -#endif // BPKG_TYPES diff --git a/bpkg/types-parsers b/bpkg/types-parsers deleted file mode 100644 index d32a6cf..0000000 --- a/bpkg/types-parsers +++ /dev/null @@ -1,46 +0,0 @@ -// file : bpkg/types-parsers -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -// CLI parsers, included into the generated source files. -// - -#ifndef BPKG_TYPES_PARSERS -#define BPKG_TYPES_PARSERS - -#include -#include - -namespace bpkg -{ - namespace cli - { - class scanner; - - template - struct parser; - - template <> - struct parser - { - static void - parse (path&, bool&, scanner&); - }; - - template <> - struct parser - { - static void - parse (dir_path&, bool&, scanner&); - }; - - template <> - struct parser - { - static void - parse (auth&, bool&, scanner&); - }; - } -} - -#endif // BPKG_TYPES_PARSERS diff --git a/bpkg/types-parsers.cxx b/bpkg/types-parsers.cxx index 7067a9e..6da395c 100644 --- a/bpkg/types-parsers.cxx +++ b/bpkg/types-parsers.cxx @@ -2,9 +2,9 @@ // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include +#include -#include // bpkg::cli namespace +#include // bpkg::cli namespace namespace bpkg { diff --git a/bpkg/types-parsers.hxx b/bpkg/types-parsers.hxx new file mode 100644 index 0000000..bddb425 --- /dev/null +++ b/bpkg/types-parsers.hxx @@ -0,0 +1,46 @@ +// file : bpkg/types-parsers.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +// CLI parsers, included into the generated source files. +// + +#ifndef BPKG_TYPES_PARSERS_HXX +#define BPKG_TYPES_PARSERS_HXX + +#include +#include + +namespace bpkg +{ + namespace cli + { + class scanner; + + template + struct parser; + + template <> + struct parser + { + static void + parse (path&, bool&, scanner&); + }; + + template <> + struct parser + { + static void + parse (dir_path&, bool&, scanner&); + }; + + template <> + struct parser + { + static void + parse (auth&, bool&, scanner&); + }; + } +} + +#endif // BPKG_TYPES_PARSERS_HXX diff --git a/bpkg/types.hxx b/bpkg/types.hxx new file mode 100644 index 0000000..37c38e5 --- /dev/null +++ b/bpkg/types.hxx @@ -0,0 +1,104 @@ +// file : bpkg/types.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_TYPES_HXX +#define BPKG_TYPES_HXX + +#include +#include +#include // unique_ptr, shared_ptr +#include // pair +#include // size_t, nullptr_t +#include // uint{8,16,32,64}_t +#include +#include +#include // function, reference_wrapper + +#include // ios_base::failure +#include // exception +#include // logic_error, invalid_argument, runtime_error +#include + +#include + +#include +#include + +namespace bpkg +{ + // Commonly-used types. + // + using std::uint8_t; + using std::uint16_t; + using std::uint32_t; + using std::uint64_t; + + using std::size_t; + using std::nullptr_t; + + using std::pair; + using std::string; + using std::function; + using std::reference_wrapper; + + using std::unique_ptr; + using std::shared_ptr; + using std::weak_ptr; + + using std::vector; + + using strings = vector; + using cstrings = vector; + + using std::istream; + using std::ostream; + + // Exceptions. While is included, there is no using for + // std::exception -- use qualified. + // + using std::logic_error; + using std::invalid_argument; + using std::runtime_error; + using std::system_error; + using io_error = std::ios_base::failure; + + // + // + using butl::optional; + using butl::nullopt; + + // ODB smart pointers. + // + using odb::lazy_shared_ptr; + using odb::lazy_weak_ptr; + + // + // + using butl::path; + using butl::dir_path; + using butl::basic_path; + using butl::invalid_path; + + using paths = std::vector; + using dir_paths = std::vector; +} + +// In order to be found (via ADL) these have to be either in std:: or in +// butl::. The latter is bad idea since libbutl includes the default +// implementation. +// +namespace std +{ + // Custom path printing (canonicalized, with trailing slash for directories). + // + inline ostream& + operator<< (ostream& os, const ::butl::path& p) + { + string r (p.representation ()); + ::butl::path::traits::canonicalize (r); + return os << r; + } +} + +#endif // BPKG_TYPES_HXX diff --git a/bpkg/utility b/bpkg/utility deleted file mode 100644 index 6f4c3ca..0000000 --- a/bpkg/utility +++ /dev/null @@ -1,121 +0,0 @@ -// file : bpkg/utility -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_UTILITY -#define BPKG_UTILITY - -#include // make_shared() -#include // to_string() -#include // move(), forward(), declval(), make_pair() -#include // assert() -#include // make_move_iterator() - -#include - -#include // casecmp(), reverse_iterate(), etc - -#include - -#include -#include - -namespace bpkg -{ - using std::move; - using std::forward; - using std::declval; - - using std::make_pair; - using std::make_shared; - using std::make_move_iterator; - using std::to_string; - - // - // - using butl::casecmp; - using butl::reverse_iterate; - - using butl::exception_guard; - using butl::make_exception_guard; - - // Widely-used paths. - // - extern const dir_path bpkg_dir; // .bpkg/ - extern const dir_path certs_dir; // .bpkg/certs/ - - // Y/N prompt. The def argument, if specified, should be either 'y' - // or 'n'. It is used as the default answer, in case the user just - // hits enter. Issue diagnostics and throw failed if no answer could - // be extracted from STDOUT (e.g., because it was closed). - // - bool - yn_prompt (const char* prompt, char def = '\0'); - - // Filesystem. - // - bool - exists (const path&); - - bool - exists (const dir_path&); - - bool - empty (const dir_path&); - - void - mk (const dir_path&); - - void - mk_p (const dir_path&); - - void - rm (const path&); - - void - rm_r (const dir_path&, bool dir = true); - - using auto_rm = butl::auto_rmfile; - using auto_rm_r = butl::auto_rmdir; - - // Process. - // - // By default the process command line is printed for verbosity >= 2 - // (essential command lines). - // - // If fallback is specified, then this directory is searched for the - // executable as a last resort. - // - void - run (const char* args[], const dir_path& fallback = dir_path ()); - - inline void - run (cstrings& args, const dir_path& fallback = dir_path ()) - { - run (args.data (), fallback); - } - - // Directory extracted from argv[0] (i.e., this process' recall directory) - // or empty if there is none. Can be used as a search fallback. - // - extern dir_path exec_dir; - - // Run build2, mapping verbosity levels. If quiet is true, then run build2 - // quiet if our verbosity level is 1. Common vars (cvars) are set on the - // configuration scope. - // - class common_options; - - const char* - name_b (const common_options&); - - void - run_b (const common_options&, - const dir_path& configuration, - const string& buildspec, - bool quiet = false, - const strings& pvars = strings (), - const strings& cvars = strings ()); -} - -#endif // BPKG_UTILITY diff --git a/bpkg/utility.cxx b/bpkg/utility.cxx index 95e47ba..c538035 100644 --- a/bpkg/utility.cxx +++ b/bpkg/utility.cxx @@ -2,15 +2,15 @@ // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include +#include #include // cout, cin #include #include -#include -#include +#include +#include using namespace std; using namespace butl; diff --git a/bpkg/utility.hxx b/bpkg/utility.hxx new file mode 100644 index 0000000..c84b466 --- /dev/null +++ b/bpkg/utility.hxx @@ -0,0 +1,121 @@ +// file : bpkg/utility.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_UTILITY_HXX +#define BPKG_UTILITY_HXX + +#include // make_shared() +#include // to_string() +#include // move(), forward(), declval(), make_pair() +#include // assert() +#include // make_move_iterator() + +#include + +#include // casecmp(), reverse_iterate(), etc + +#include + +#include +#include + +namespace bpkg +{ + using std::move; + using std::forward; + using std::declval; + + using std::make_pair; + using std::make_shared; + using std::make_move_iterator; + using std::to_string; + + // + // + using butl::casecmp; + using butl::reverse_iterate; + + using butl::exception_guard; + using butl::make_exception_guard; + + // Widely-used paths. + // + extern const dir_path bpkg_dir; // .bpkg/ + extern const dir_path certs_dir; // .bpkg/certs/ + + // Y/N prompt. The def argument, if specified, should be either 'y' + // or 'n'. It is used as the default answer, in case the user just + // hits enter. Issue diagnostics and throw failed if no answer could + // be extracted from STDOUT (e.g., because it was closed). + // + bool + yn_prompt (const char* prompt, char def = '\0'); + + // Filesystem. + // + bool + exists (const path&); + + bool + exists (const dir_path&); + + bool + empty (const dir_path&); + + void + mk (const dir_path&); + + void + mk_p (const dir_path&); + + void + rm (const path&); + + void + rm_r (const dir_path&, bool dir = true); + + using auto_rm = butl::auto_rmfile; + using auto_rm_r = butl::auto_rmdir; + + // Process. + // + // By default the process command line is printed for verbosity >= 2 + // (essential command lines). + // + // If fallback is specified, then this directory is searched for the + // executable as a last resort. + // + void + run (const char* args[], const dir_path& fallback = dir_path ()); + + inline void + run (cstrings& args, const dir_path& fallback = dir_path ()) + { + run (args.data (), fallback); + } + + // Directory extracted from argv[0] (i.e., this process' recall directory) + // or empty if there is none. Can be used as a search fallback. + // + extern dir_path exec_dir; + + // Run build2, mapping verbosity levels. If quiet is true, then run build2 + // quiet if our verbosity level is 1. Common vars (cvars) are set on the + // configuration scope. + // + class common_options; + + const char* + name_b (const common_options&); + + void + run_b (const common_options&, + const dir_path& configuration, + const string& buildspec, + bool quiet = false, + const strings& pvars = strings (), + const strings& cvars = strings ()); +} + +#endif // BPKG_UTILITY_HXX diff --git a/bpkg/version-impl.in b/bpkg/version-impl.in deleted file mode 100644 index 8d15e68..0000000 --- a/bpkg/version-impl.in +++ /dev/null @@ -1,95 +0,0 @@ -// file : bpkg/version-impl.in -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_VERSION // Note: using the version macro itself. - -// Note: using build2 standard versioning scheme. The numeric version format -// is AAABBBCCCDDDE where: -// -// AAA - major version number -// BBB - minor version number -// CCC - bugfix version number -// DDD - alpha / beta (DDD + 500) version number -// E - final (0) / snapshot (1) -// -// When DDDE is not 0, 1 is subtracted from AAABBBCCC. For example: -// -// Version AAABBBCCCDDDE -// -// 0.1.0 0000010000000 -// 0.1.2 0000010010000 -// 1.2.3 0010020030000 -// 2.2.0-a.1 0020019990010 -// 3.0.0-b.2 0029999995020 -// 2.2.0-a.1.z 0020019990011 -// -#define BPKG_VERSION $bpkg.version.project_number$ULL -#define BPKG_VERSION_STR "$bpkg.version.project$" -#define BPKG_VERSION_ID "$bpkg.version.project_id$" - -#define BPKG_VERSION_MAJOR $bpkg.version.major$ -#define BPKG_VERSION_MINOR $bpkg.version.minor$ -#define BPKG_VERSION_PATCH $bpkg.version.patch$ - -#define BPKG_PRE_RELEASE $bpkg.version.pre_release$ - -#define BPKG_SNAPSHOT $bpkg.version.snapshot_sn$ULL -#define BPKG_SNAPSHOT_ID "$bpkg.version.snapshot_id$" - -#include - -$libbutl.check(LIBBUTL_VERSION, LIBBUTL_SNAPSHOT)$ - -#include - -$libbpkg.check(LIBBPKG_VERSION, LIBBPKG_SNAPSHOT)$ - -#include - -$libodb.check(LIBODB_VERSION, LIBODB_SNAPSHOT)$ - -#include - -$libodb-sqlite.check(LIBODB_SQLITE_VERSION, LIBODB_SQLITE_SNAPSHOT)$ - -// User agent. -// -#if defined(_WIN32) -# if defined(__MINGW32__) -# define BPKG_OS "MinGW" -# else -# define BPKG_OS "Windows" -# endif -#elif defined(__linux) -# define BPKG_OS "GNU/Linux" -#elif defined(__APPLE__) -# define BPKG_OS "MacOS" -#elif defined(__CYGWIN__) -# define BPKG_OS "Cygwin" -#elif defined(__FreeBSD__) -# define BPKG_OS "FreeBSD" -#elif defined(__OpenBSD__) -# define BPKG_OS "OpenBSD" -#elif defined(__NetBSD__) -# define BPKG_OS "NetBSD" -#elif defined(__sun) -# define BPKG_OS "Solaris" -#elif defined(__hpux) -# define BPKG_OS "HP-UX" -#elif defined(_AIX) -# define BPKG_OS "AIX" -#elif defined(__unix) -# define BPKG_OS "Unix" -#elif defined(__posix) -# define BPKG_OS "Posix" -#else -# define BPKG_OS "Other" -#endif - -#define BPKG_USER_AGENT \ - "bpkg/" BPKG_VERSION_STR " (" BPKG_OS "; +https://build2.org)" \ - " libbpkg/" LIBBPKG_VERSION_STR \ - " libbutl/" LIBBUTL_VERSION_STR - -#endif // BPKG_VERSION diff --git a/bpkg/version.hxx.in b/bpkg/version.hxx.in new file mode 100644 index 0000000..b51b69e --- /dev/null +++ b/bpkg/version.hxx.in @@ -0,0 +1,95 @@ +// file : bpkg/version.hxx.in -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_VERSION // Note: using the version macro itself. + +// Note: using build2 standard versioning scheme. The numeric version format +// is AAABBBCCCDDDE where: +// +// AAA - major version number +// BBB - minor version number +// CCC - bugfix version number +// DDD - alpha / beta (DDD + 500) version number +// E - final (0) / snapshot (1) +// +// When DDDE is not 0, 1 is subtracted from AAABBBCCC. For example: +// +// Version AAABBBCCCDDDE +// +// 0.1.0 0000010000000 +// 0.1.2 0000010010000 +// 1.2.3 0010020030000 +// 2.2.0-a.1 0020019990010 +// 3.0.0-b.2 0029999995020 +// 2.2.0-a.1.z 0020019990011 +// +#define BPKG_VERSION $bpkg.version.project_number$ULL +#define BPKG_VERSION_STR "$bpkg.version.project$" +#define BPKG_VERSION_ID "$bpkg.version.project_id$" + +#define BPKG_VERSION_MAJOR $bpkg.version.major$ +#define BPKG_VERSION_MINOR $bpkg.version.minor$ +#define BPKG_VERSION_PATCH $bpkg.version.patch$ + +#define BPKG_PRE_RELEASE $bpkg.version.pre_release$ + +#define BPKG_SNAPSHOT $bpkg.version.snapshot_sn$ULL +#define BPKG_SNAPSHOT_ID "$bpkg.version.snapshot_id$" + +#include + +$libbutl.check(LIBBUTL_VERSION, LIBBUTL_SNAPSHOT)$ + +#include + +$libbpkg.check(LIBBPKG_VERSION, LIBBPKG_SNAPSHOT)$ + +#include + +$libodb.check(LIBODB_VERSION, LIBODB_SNAPSHOT)$ + +#include + +$libodb-sqlite.check(LIBODB_SQLITE_VERSION, LIBODB_SQLITE_SNAPSHOT)$ + +// User agent. +// +#if defined(_WIN32) +# if defined(__MINGW32__) +# define BPKG_OS "MinGW" +# else +# define BPKG_OS "Windows" +# endif +#elif defined(__linux) +# define BPKG_OS "GNU/Linux" +#elif defined(__APPLE__) +# define BPKG_OS "MacOS" +#elif defined(__CYGWIN__) +# define BPKG_OS "Cygwin" +#elif defined(__FreeBSD__) +# define BPKG_OS "FreeBSD" +#elif defined(__OpenBSD__) +# define BPKG_OS "OpenBSD" +#elif defined(__NetBSD__) +# define BPKG_OS "NetBSD" +#elif defined(__sun) +# define BPKG_OS "Solaris" +#elif defined(__hpux) +# define BPKG_OS "HP-UX" +#elif defined(_AIX) +# define BPKG_OS "AIX" +#elif defined(__unix) +# define BPKG_OS "Unix" +#elif defined(__posix) +# define BPKG_OS "Posix" +#else +# define BPKG_OS "Other" +#endif + +#define BPKG_USER_AGENT \ + "bpkg/" BPKG_VERSION_STR " (" BPKG_OS "; +https://build2.org)" \ + " libbpkg/" LIBBPKG_VERSION_STR \ + " libbutl/" LIBBUTL_VERSION_STR + +#endif // BPKG_VERSION diff --git a/bpkg/wrapper-traits b/bpkg/wrapper-traits deleted file mode 100644 index 0da2de4..0000000 --- a/bpkg/wrapper-traits +++ /dev/null @@ -1,59 +0,0 @@ -// file : bpkg/wrapper-traits -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BPKG_WRAPPER_TRAITS -#define BPKG_WRAPPER_TRAITS - -#include - -#include - -namespace odb -{ - template - class wrapper_traits> - { - public: - typedef T wrapped_type; - typedef butl::optional wrapper_type; - - // T can be const. - // - typedef - typename odb::details::meta::remove_const::result - unrestricted_wrapped_type; - - static const bool null_handler = true; - static const bool null_default = true; - - static bool - get_null (const wrapper_type& o) - { - return !o; - } - - static void - set_null (wrapper_type& o) - { - o = wrapper_type (); - } - - static const wrapped_type& - get_ref (const wrapper_type& o) - { - return *o; - } - - static unrestricted_wrapped_type& - set_ref (wrapper_type& o) - { - if (!o) - o = unrestricted_wrapped_type (); - - return const_cast (*o); - } - }; -} - -#endif // BPKG_WRAPPER_TRAITS diff --git a/bpkg/wrapper-traits.hxx b/bpkg/wrapper-traits.hxx new file mode 100644 index 0000000..bdd0861 --- /dev/null +++ b/bpkg/wrapper-traits.hxx @@ -0,0 +1,59 @@ +// file : bpkg/wrapper-traits.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_WRAPPER_TRAITS_HXX +#define BPKG_WRAPPER_TRAITS_HXX + +#include + +#include + +namespace odb +{ + template + class wrapper_traits> + { + public: + typedef T wrapped_type; + typedef butl::optional wrapper_type; + + // T can be const. + // + typedef + typename odb::details::meta::remove_const::result + unrestricted_wrapped_type; + + static const bool null_handler = true; + static const bool null_default = true; + + static bool + get_null (const wrapper_type& o) + { + return !o; + } + + static void + set_null (wrapper_type& o) + { + o = wrapper_type (); + } + + static const wrapped_type& + get_ref (const wrapper_type& o) + { + return *o; + } + + static unrestricted_wrapped_type& + set_ref (wrapper_type& o) + { + if (!o) + o = unrestricted_wrapped_type (); + + return const_cast (*o); + } + }; +} + +#endif // BPKG_WRAPPER_TRAITS_HXX diff --git a/build/root.build b/build/root.build index f19d700..053e2fb 100644 --- a/build/root.build +++ b/build/root.build @@ -6,7 +6,7 @@ cxx.std = latest using cxx -hxx{*}: extension = +hxx{*}: extension = hxx ixx{*}: extension = ixx txx{*}: extension = txx cxx{*}: extension = cxx diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..35ec43f --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1,2 @@ +test/ +test-*/ diff --git a/tests/common/bar/stable/libbar-1.0.0.tar.gz b/tests/common/bar/stable/libbar-1.0.0.tar.gz index d77c1ba..7d4f9e8 100644 Binary files a/tests/common/bar/stable/libbar-1.0.0.tar.gz and b/tests/common/bar/stable/libbar-1.0.0.tar.gz differ diff --git a/tests/common/bar/testing/libbar-1.1.0.tar.gz b/tests/common/bar/testing/libbar-1.1.0.tar.gz index f081804..1dc004e 100644 Binary files a/tests/common/bar/testing/libbar-1.1.0.tar.gz and b/tests/common/bar/testing/libbar-1.1.0.tar.gz differ diff --git a/tests/common/bar/unstable/libbar-1.1.1.tar.gz b/tests/common/bar/unstable/libbar-1.1.1.tar.gz index a0fbdc3..bafd5e2 100644 Binary files a/tests/common/bar/unstable/libbar-1.1.1.tar.gz and b/tests/common/bar/unstable/libbar-1.1.1.tar.gz differ diff --git a/tests/common/foo/stable/libfoo-1.0.0.tar.gz b/tests/common/foo/stable/libfoo-1.0.0.tar.gz index c29dd9d..0aba2aa 100644 Binary files a/tests/common/foo/stable/libfoo-1.0.0.tar.gz and b/tests/common/foo/stable/libfoo-1.0.0.tar.gz differ diff --git a/tests/common/foo/testing/libfoo-1.1.0.tar.gz b/tests/common/foo/testing/libfoo-1.1.0.tar.gz index a6c0202..0e9bf9c 100644 Binary files a/tests/common/foo/testing/libfoo-1.1.0.tar.gz and b/tests/common/foo/testing/libfoo-1.1.0.tar.gz differ diff --git a/tests/common/hello/libhello-1.0.0.tar.gz b/tests/common/hello/libhello-1.0.0.tar.gz index 29341c7..c9a25d9 100644 Binary files a/tests/common/hello/libhello-1.0.0.tar.gz and b/tests/common/hello/libhello-1.0.0.tar.gz differ diff --git a/tests/common/libhello-1.0.0/build/export.build b/tests/common/libhello-1.0.0/build/export.build index 1eb73b7..0151425 100644 --- a/tests/common/libhello-1.0.0/build/export.build +++ b/tests/common/libhello-1.0.0/build/export.build @@ -1,6 +1,6 @@ $out_root/: { - include hello/ + include libhello/ } -export $out_root/hello/lib{hello} +export $out_root/libhello/lib{hello} diff --git a/tests/common/libhello-1.0.0/build/root.build b/tests/common/libhello-1.0.0/build/root.build index 4f70114..8ceadfa 100644 --- a/tests/common/libhello-1.0.0/build/root.build +++ b/tests/common/libhello-1.0.0/build/root.build @@ -2,5 +2,5 @@ cxx.std = 11 using cxx -hxx{*}: extension = +hxx{*}: extension = hxx cxx{*}: extension = cxx diff --git a/tests/common/libhello-1.0.0/buildfile b/tests/common/libhello-1.0.0/buildfile index 57e0f35..b3ad7e3 100644 --- a/tests/common/libhello-1.0.0/buildfile +++ b/tests/common/libhello-1.0.0/buildfile @@ -1,4 +1,4 @@ -./: hello/ tests/ doc{INSTALL version} file{manifest} +./: libhello/ tests/ doc{INSTALL version} file{manifest} doc{version}: file{manifest} # Generated by the version module. doc{version}: dist = true diff --git a/tests/common/libhello-1.0.0/hello/buildfile b/tests/common/libhello-1.0.0/hello/buildfile deleted file mode 100644 index 9af86cf..0000000 --- a/tests/common/libhello-1.0.0/hello/buildfile +++ /dev/null @@ -1,21 +0,0 @@ -lib{hello}: {hxx cxx}{hello} hxx{export} - -# For pre-releases use the complete version to make sure they cannot be used -# in place of another pre-release or the final version. -# -if $version.pre_release - lib{hello}: bin.lib.version = @"-$version.project_id" -else - lib{hello}: bin.lib.version = @"-$version.major.$version.minor" - -cxx.poptions += "-I$src_root" -obja{*}: cxx.poptions += -DLIBHELLO_STATIC_BUILD -objs{*}: cxx.poptions += -DLIBHELLO_SHARED_BUILD - -lib{hello}: cxx.export.poptions = "-I$src_root" -liba{hello}: cxx.export.poptions += -DLIBHELLO_STATIC -libs{hello}: cxx.export.poptions += -DLIBHELLO_SHARED - -# Install into the hello/ subdirectory of, say, /usr/include/. -# -install.include = $install.include/hello/ diff --git a/tests/common/libhello-1.0.0/hello/export b/tests/common/libhello-1.0.0/hello/export deleted file mode 100644 index 18f4968..0000000 --- a/tests/common/libhello-1.0.0/hello/export +++ /dev/null @@ -1,36 +0,0 @@ -// file: hello/export -*- C++ -*- - -#pragma once - -// Normally we don't export class templates (but do complete specializations), -// inline functions, and classes with only inline member functions. Exporting -// classes that inherit from non-exported/imported bases (e.g., std::string) -// will end up badly. The only known workarounds are to not inherit or to not -// export. Also, MinGW GCC doesn't like seeing non-exported function being -// used before their inline definition. The workaround is to reorder code. In -// the end it's all trial and error. - -#if defined(LIBHELLO_STATIC) // Using static. -# define LIBHELLO_EXPORT -#elif defined(LIBHELLO_STATIC_BUILD) // Building static. -# define LIBHELLO_EXPORT -#elif defined(LIBHELLO_SHARED) // Using shared. -# ifdef _WIN32 -# define LIBHELLO_EXPORT __declspec(dllimport) -# else -# define LIBHELLO_EXPORT -# endif -#elif defined(LIBHELLO_SHARED_BUILD) // Building shared. -# ifdef _WIN32 -# define LIBHELLO_EXPORT __declspec(dllexport) -# else -# define LIBHELLO_EXPORT -# endif -#else -// If none of the above macros are defined, then we assume we are being used -// by some third-party build system that cannot/doesn't signal the library -// type. Note that this fallback works for both static and shared but in case -// of shared will be sub-optimal compared to having dllimport. -// -# define LIBHELLO_EXPORT // Using static or shared. -#endif diff --git a/tests/common/libhello-1.0.0/hello/hello b/tests/common/libhello-1.0.0/hello/hello deleted file mode 100644 index 5fb7d9e..0000000 --- a/tests/common/libhello-1.0.0/hello/hello +++ /dev/null @@ -1,13 +0,0 @@ -// file: hello/hello -*- C++ -*- - -#pragma once - -#include - -#include - -namespace hello -{ - LIBHELLO_EXPORT void - say (const std::string& name); -} diff --git a/tests/common/libhello-1.0.0/hello/hello.cxx b/tests/common/libhello-1.0.0/hello/hello.cxx deleted file mode 100644 index 65d0aa7..0000000 --- a/tests/common/libhello-1.0.0/hello/hello.cxx +++ /dev/null @@ -1,16 +0,0 @@ -// file: hello/hello.cxx -*- C++ -*- - -#include - -#include - -using namespace std; - -namespace hello -{ - void - say (const string& n) - { - cout << "Hello, " << n << '!' << endl; - } -} diff --git a/tests/common/libhello-1.0.0/libhello/buildfile b/tests/common/libhello-1.0.0/libhello/buildfile new file mode 100644 index 0000000..f79b9e7 --- /dev/null +++ b/tests/common/libhello-1.0.0/libhello/buildfile @@ -0,0 +1,21 @@ +lib{hello}: {hxx cxx}{hello} hxx{export} + +# For pre-releases use the complete version to make sure they cannot be used +# in place of another pre-release or the final version. +# +if $version.pre_release + lib{hello}: bin.lib.version = @"-$version.project_id" +else + lib{hello}: bin.lib.version = @"-$version.major.$version.minor" + +cxx.poptions += "-I$src_root" +obja{*}: cxx.poptions += -DLIBHELLO_STATIC_BUILD +objs{*}: cxx.poptions += -DLIBHELLO_SHARED_BUILD + +lib{hello}: cxx.export.poptions = "-I$src_root" +liba{hello}: cxx.export.poptions += -DLIBHELLO_STATIC +libs{hello}: cxx.export.poptions += -DLIBHELLO_SHARED + +# Install into the libhello/ subdirectory of, say, /usr/include/. +# +install.include = $install.include/libhello/ diff --git a/tests/common/libhello-1.0.0/libhello/export.hxx b/tests/common/libhello-1.0.0/libhello/export.hxx new file mode 100644 index 0000000..e6c723e --- /dev/null +++ b/tests/common/libhello-1.0.0/libhello/export.hxx @@ -0,0 +1,36 @@ +// file: libhello/export.hxx -*- C++ -*- + +#pragma once + +// Normally we don't export class templates (but do complete specializations), +// inline functions, and classes with only inline member functions. Exporting +// classes that inherit from non-exported/imported bases (e.g., std::string) +// will end up badly. The only known workarounds are to not inherit or to not +// export. Also, MinGW GCC doesn't like seeing non-exported function being +// used before their inline definition. The workaround is to reorder code. In +// the end it's all trial and error. + +#if defined(LIBHELLO_STATIC) // Using static. +# define LIBHELLO_EXPORT +#elif defined(LIBHELLO_STATIC_BUILD) // Building static. +# define LIBHELLO_EXPORT +#elif defined(LIBHELLO_SHARED) // Using shared. +# ifdef _WIN32 +# define LIBHELLO_EXPORT __declspec(dllimport) +# else +# define LIBHELLO_EXPORT +# endif +#elif defined(LIBHELLO_SHARED_BUILD) // Building shared. +# ifdef _WIN32 +# define LIBHELLO_EXPORT __declspec(dllexport) +# else +# define LIBHELLO_EXPORT +# endif +#else +// If none of the above macros are defined, then we assume we are being used +// by some third-party build system that cannot/doesn't signal the library +// type. Note that this fallback works for both static and shared but in case +// of shared will be sub-optimal compared to having dllimport. +// +# define LIBHELLO_EXPORT // Using static or shared. +#endif diff --git a/tests/common/libhello-1.0.0/libhello/hello.cxx b/tests/common/libhello-1.0.0/libhello/hello.cxx new file mode 100644 index 0000000..677815d --- /dev/null +++ b/tests/common/libhello-1.0.0/libhello/hello.cxx @@ -0,0 +1,16 @@ +// file: libhello/hello.cxx -*- C++ -*- + +#include + +#include + +using namespace std; + +namespace hello +{ + void + say (const string& n) + { + cout << "Hello, " << n << '!' << endl; + } +} diff --git a/tests/common/libhello-1.0.0/libhello/hello.hxx b/tests/common/libhello-1.0.0/libhello/hello.hxx new file mode 100644 index 0000000..58bd7b2 --- /dev/null +++ b/tests/common/libhello-1.0.0/libhello/hello.hxx @@ -0,0 +1,13 @@ +// file: libhello/hello.hxx -*- C++ -*- + +#pragma once + +#include + +#include + +namespace hello +{ + LIBHELLO_EXPORT void + say (const std::string& name); +} diff --git a/tests/common/libhello-1.0.0/tests/.gitignore b/tests/common/libhello-1.0.0/tests/.gitignore new file mode 100644 index 0000000..93fe433 --- /dev/null +++ b/tests/common/libhello-1.0.0/tests/.gitignore @@ -0,0 +1 @@ +!test/ diff --git a/tests/common/libhello-1.0.0/tests/build/root.build b/tests/common/libhello-1.0.0/tests/build/root.build index de723b8..a2ee38a 100644 --- a/tests/common/libhello-1.0.0/tests/build/root.build +++ b/tests/common/libhello-1.0.0/tests/build/root.build @@ -2,7 +2,7 @@ cxx.std = 11 using cxx -hxx{*}: extension = +hxx{*}: extension = hxx cxx{*}: extension = cxx # Every exe{} in this subproject is by default a test. diff --git a/tests/common/libhello-1.0.0/tests/test/driver.cxx b/tests/common/libhello-1.0.0/tests/test/driver.cxx index 59bfb2d..38937f0 100644 --- a/tests/common/libhello-1.0.0/tests/test/driver.cxx +++ b/tests/common/libhello-1.0.0/tests/test/driver.cxx @@ -1,6 +1,6 @@ // file: tests/test/driver.cxx -*- C++ -*- -#include +#include int main () -- cgit v1.1