commit 67a74bb7bb63bf76d2e393362fdbab5c39be3f55 Author: Ryan Date: Mon Sep 2 01:43:44 2024 +0200 wip diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1631641 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,19 @@ +# This is a good default: files that are auto-detected by git to be text are +# converted to the platform-native line ending (LF on Unix, CRLF on Windows) +# in the working tree and to LF in the repository. +# +* text=auto + +# Use `eol=crlf` for files that should have the CRLF line ending both in the +# working tree (even on Unix) and in the repository. +# +#*.bat text eol=crlf + +# Use `eol=lf` for files that should have the LF line ending both in the +# working tree (even on Windows) and in the repository. +# +#*.sh text eol=lf + +# Use `binary` to make sure certain files are never auto-detected as text. +# +#*.png binary diff --git a/.gitea/workflows/on-push.yaml b/.gitea/workflows/on-push.yaml new file mode 100644 index 0000000..a30faf4 --- /dev/null +++ b/.gitea/workflows/on-push.yaml @@ -0,0 +1,16 @@ +name: on-push +on: [push] + +jobs: + build-and-test: + runs-on: linux + container: code.helloryan.se/infra/buildenv/cxx-amd64-fedora-40:latest + volumes: + - /build + steps: + - name: Init + run: bpkg create -d /build cc config.cxx=g++ + - name: Build + run: cd /build && bpkg build $GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git##$GITHUB_SHA + - name: Test + run: cd /build && bpkg test diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c96e1ec --- /dev/null +++ b/.gitignore @@ -0,0 +1,31 @@ +.bdep/ + +# Local default options files. +# +.build2/local/ + +# Compiler/linker output. +# +*.d +*.t +*.i +*.i.* +*.ii +*.ii.* +*.o +*.obj +*.gcm +*.pcm +*.ifc +*.so +*.dylib +*.dll +*.a +*.lib +*.exp +*.pdb +*.ilk +*.exe +*.exe.dlls/ +*.exe.manifest +*.pc diff --git a/README.md b/README.md new file mode 100644 index 0000000..4b3e27c --- /dev/null +++ b/README.md @@ -0,0 +1,41 @@ +# libcopy-test - A C++ library + +The `libcopy-test` C++ library provides . + + +## Usage + +To start using `libcopy-test` in your project, add the following `depends` +value to your `manifest`, adjusting the version constraint as appropriate: + +``` +depends: libcopy-test ^ +``` + +Then import the library in your `buildfile`: + +``` +import libs = libcopy-test%lib{} +``` + + +## Importable targets + +This package provides the following importable targets: + +``` +lib{} +``` + + + + +## Configuration variables + +This package provides the following configuration variables: + +``` +[bool] config.libcopy_test. ?= false +``` + + diff --git a/build/.gitignore b/build/.gitignore new file mode 100644 index 0000000..974e01d --- /dev/null +++ b/build/.gitignore @@ -0,0 +1,4 @@ +/config.build +/root/ +/bootstrap/ +build/ diff --git a/build/bootstrap.build b/build/bootstrap.build new file mode 100644 index 0000000..27e598e --- /dev/null +++ b/build/bootstrap.build @@ -0,0 +1,7 @@ +project = libcopy-test + +using version +using config +using test +using install +using dist diff --git a/build/export.build b/build/export.build new file mode 100644 index 0000000..f404360 --- /dev/null +++ b/build/export.build @@ -0,0 +1,6 @@ +$out_root/ +{ + include libcopy-test/ +} + +export $out_root/libcopy-test/$import.target diff --git a/build/root.build b/build/root.build new file mode 100644 index 0000000..21e0a2e --- /dev/null +++ b/build/root.build @@ -0,0 +1,16 @@ +# Uncomment to suppress warnings coming from external libraries. +# +#cxx.internal.scope = current + +cxx.std = latest + +using cxx + +hxx{*}: extension = hxx +ixx{*}: extension = ixx +txx{*}: extension = txx +cxx{*}: extension = cxx + +# The test target for cross-testing (running tests under Wine, etc). +# +test.target = $cxx.target diff --git a/buildfile b/buildfile new file mode 100644 index 0000000..9a5145b --- /dev/null +++ b/buildfile @@ -0,0 +1,5 @@ +./: {*/ -build/} doc{README.md} manifest + +# Don't install tests. +# +tests/: install = false diff --git a/libcopy-test/.gitignore b/libcopy-test/.gitignore new file mode 100644 index 0000000..0c9102a --- /dev/null +++ b/libcopy-test/.gitignore @@ -0,0 +1,3 @@ +# Generated version header. +# +version.hxx diff --git a/libcopy-test/buildfile b/libcopy-test/buildfile new file mode 100644 index 0000000..977689c --- /dev/null +++ b/libcopy-test/buildfile @@ -0,0 +1,43 @@ +intf_libs = # Interface dependencies. +impl_libs = # Implementation dependencies. +#import xxxx_libs += libhello%lib{hello} + +lib{copy-test}: {hxx ixx txx cxx}{** -version} hxx{version} $impl_libs $intf_libs + +hxx{version}: in{version} $src_root/manifest + +# Build options. +# +cxx.poptions =+ "-I$out_root" "-I$src_root" + +obja{*}: cxx.poptions += -DLIBCOPY_TEST_STATIC_BUILD +objs{*}: cxx.poptions += -DLIBCOPY_TEST_SHARED_BUILD + +# Export options. +# +lib{copy-test}: +{ + cxx.export.poptions = "-I$out_root" "-I$src_root" + cxx.export.libs = $intf_libs +} + +liba{copy-test}: cxx.export.poptions += -DLIBCOPY_TEST_STATIC +libs{copy-test}: cxx.export.poptions += -DLIBCOPY_TEST_SHARED + +# For pre-releases use the complete version to make sure they cannot +# be used in place of another pre-release or the final version. See +# the version module for details on the version.* variable values. +# +if $version.pre_release + lib{copy-test}: bin.lib.version = "-$version.project_id" +else + lib{copy-test}: bin.lib.version = "-$version.major.$version.minor" + +# Install into the libcopy-test/ subdirectory of, say, /usr/include/ +# recreating subdirectories. +# +{hxx ixx txx}{*}: +{ + install = include/libcopy-test/ + install.subdirs = true +} diff --git a/libcopy-test/copy-test.cxx b/libcopy-test/copy-test.cxx new file mode 100644 index 0000000..36198cd --- /dev/null +++ b/libcopy-test/copy-test.cxx @@ -0,0 +1,17 @@ +#include + +#include +#include + +using namespace std; + +namespace copy_test +{ + void say_hello (ostream& o, const string& n) + { + if (n.empty ()) + throw invalid_argument ("empty name"); + + o << "Hello, " << n << '!' << endl; + } +} diff --git a/libcopy-test/copy-test.hxx b/libcopy-test/copy-test.hxx new file mode 100644 index 0000000..d33c2e8 --- /dev/null +++ b/libcopy-test/copy-test.hxx @@ -0,0 +1,15 @@ +#pragma once + +#include +#include + +#include + +namespace copy_test +{ + // Print a greeting for the specified name into the specified + // stream. Throw std::invalid_argument if the name is empty. + // + LIBCOPY_TEST_SYMEXPORT void + say_hello (std::ostream&, const std::string& name); +} diff --git a/libcopy-test/export.hxx b/libcopy-test/export.hxx new file mode 100644 index 0000000..3346a54 --- /dev/null +++ b/libcopy-test/export.hxx @@ -0,0 +1,39 @@ +#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 functions being +// used before their inline definition. The workaround is to reorder code. In +// the end it's all trial and error. + +#if defined(LIBCOPY_TEST_STATIC) // Using static. +# define LIBCOPY_TEST_SYMEXPORT +#elif defined(LIBCOPY_TEST_STATIC_BUILD) // Building static. +# define LIBCOPY_TEST_SYMEXPORT +#elif defined(LIBCOPY_TEST_SHARED) // Using shared. +# ifdef _WIN32 +# define LIBCOPY_TEST_SYMEXPORT __declspec(dllimport) +# else +# define LIBCOPY_TEST_SYMEXPORT +# endif +#elif defined(LIBCOPY_TEST_SHARED_BUILD) // Building shared. +# ifdef _WIN32 +# define LIBCOPY_TEST_SYMEXPORT __declspec(dllexport) +# else +# define LIBCOPY_TEST_SYMEXPORT +# 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 libraries +// provided the library only exports functions (in other words, no global +// exported data) and for the shared case the result will be sub-optimal +// compared to having dllimport. If, however, your library does export data, +// then you will probably want to replace the fallback with the (commented +// out) error since it won't work for the shared case. +// +# define LIBCOPY_TEST_SYMEXPORT // Using static or shared. +//# error define LIBCOPY_TEST_STATIC or LIBCOPY_TEST_SHARED preprocessor macro to signal libcopy-test library type being linked +#endif diff --git a/libcopy-test/version.hxx.in b/libcopy-test/version.hxx.in new file mode 100644 index 0000000..6c47676 --- /dev/null +++ b/libcopy-test/version.hxx.in @@ -0,0 +1,34 @@ +#pragma once + +// The numeric version format is AAAAABBBBBCCCCCDDDE where: +// +// AAAAA - major version number +// BBBBB - minor version number +// CCCCC - bugfix version number +// DDD - alpha / beta (DDD + 500) version number +// E - final (0) / snapshot (1) +// +// When DDDE is not 0, 1 is subtracted from AAAAABBBBBCCCCC. For example: +// +// Version AAAAABBBBBCCCCCDDDE +// +// 0.1.0 0000000001000000000 +// 0.1.2 0000000001000020000 +// 1.2.3 0000100002000030000 +// 2.2.0-a.1 0000200001999990010 +// 3.0.0-b.2 0000299999999995020 +// 2.2.0-a.1.z 0000200001999990011 +// +#define LIBCOPY_TEST_VERSION $libcopy_test.version.project_number$ULL +#define LIBCOPY_TEST_VERSION_STR "$libcopy_test.version.project$" +#define LIBCOPY_TEST_VERSION_ID "$libcopy_test.version.project_id$" +#define LIBCOPY_TEST_VERSION_FULL "$libcopy_test.version$" + +#define LIBCOPY_TEST_VERSION_MAJOR $libcopy_test.version.major$ +#define LIBCOPY_TEST_VERSION_MINOR $libcopy_test.version.minor$ +#define LIBCOPY_TEST_VERSION_PATCH $libcopy_test.version.patch$ + +#define LIBCOPY_TEST_PRE_RELEASE $libcopy_test.version.pre_release$ + +#define LIBCOPY_TEST_SNAPSHOT_SN $libcopy_test.version.snapshot_sn$ULL +#define LIBCOPY_TEST_SNAPSHOT_ID "$libcopy_test.version.snapshot_id$" diff --git a/manifest b/manifest new file mode 100644 index 0000000..06d59a2 --- /dev/null +++ b/manifest @@ -0,0 +1,13 @@ +: 1 +name: libcopy-test +version: 0.1.0-a.0.z +language: c++ +summary: copy-test C++ library +license: other: proprietary ; Not free/open source. +description-file: README.md +url: https://example.org/libcopy-test +email: ryan@helloryan.se +#build-error-email: ryan@helloryan.se +depends: * build2 >= 0.16.0 +depends: * bpkg >= 0.16.0 +#depends: libhello ^1.0.0 diff --git a/repositories.manifest b/repositories.manifest new file mode 100644 index 0000000..0405750 --- /dev/null +++ b/repositories.manifest @@ -0,0 +1,11 @@ +: 1 +summary: libcopy-test project repository + +#: +#role: prerequisite +#location: https://pkg.cppget.org/1/stable +#trust: ... + +#: +#role: prerequisite +#location: https://git.build2.org/hello/libhello.git diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..662178d --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1,8 @@ +# Test executables. +# +driver + +# Testscript output directories (can be symlinks). +# +test +test-* diff --git a/tests/basics/buildfile b/tests/basics/buildfile new file mode 100644 index 0000000..e86c8de --- /dev/null +++ b/tests/basics/buildfile @@ -0,0 +1,3 @@ +import libs = libcopy-test%lib{copy-test} + +exe{driver}: {hxx ixx txx cxx}{**} $libs testscript{**} diff --git a/tests/basics/driver.cxx b/tests/basics/driver.cxx new file mode 100644 index 0000000..c08af8b --- /dev/null +++ b/tests/basics/driver.cxx @@ -0,0 +1,35 @@ +#include +#include + +#include +#include + +#undef NDEBUG +#include + +int main () +{ + using namespace std; + using namespace copy_test; + + // Basics. + // + { + ostringstream o; + say_hello (o, "World"); + assert (o.str () == "Hello, World!\n"); + } + + // Empty name. + // + try + { + ostringstream o; + say_hello (o, ""); + assert (false); + } + catch (const invalid_argument& e) + { + assert (e.what () == string ("empty name")); + } +} diff --git a/tests/build/.gitignore b/tests/build/.gitignore new file mode 100644 index 0000000..974e01d --- /dev/null +++ b/tests/build/.gitignore @@ -0,0 +1,4 @@ +/config.build +/root/ +/bootstrap/ +build/ diff --git a/tests/build/bootstrap.build b/tests/build/bootstrap.build new file mode 100644 index 0000000..a07b5ea --- /dev/null +++ b/tests/build/bootstrap.build @@ -0,0 +1,5 @@ +project = # Unnamed tests subproject. + +using config +using test +using dist diff --git a/tests/build/root.build b/tests/build/root.build new file mode 100644 index 0000000..a67b2fe --- /dev/null +++ b/tests/build/root.build @@ -0,0 +1,16 @@ +cxx.std = latest + +using cxx + +hxx{*}: extension = hxx +ixx{*}: extension = ixx +txx{*}: extension = txx +cxx{*}: extension = cxx + +# Every exe{} in this subproject is by default a test. +# +exe{*}: test = true + +# The test target for cross-testing (running tests under Wine, etc). +# +test.target = $cxx.target diff --git a/tests/buildfile b/tests/buildfile new file mode 100644 index 0000000..aeeab15 --- /dev/null +++ b/tests/buildfile @@ -0,0 +1 @@ +./: {*/ -build/}