diff options
108 files changed, 2963 insertions, 0 deletions
@@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md new file mode 100644 index 0000000..627c300 --- /dev/null +++ b/README.md @@ -0,0 +1,372 @@ +# C/C++ rules for the `just` build system + +A collection of rules for building C/C++ libraries and binaries. + +## How to use this Repository + +There are two ways to import this repository. You can generate your +`repos.json` from a template (`repos.template.json`) by importing +the `rules-cc` repository with the tool `just-import-git` + +~~~sh +$ just-import-git -C repos.template.json --as rules-cc -b master https://github.com/just-buildsystem/rules-cc > repos.json +~~~ + +Importing this way will also pull in `protoc` and `grpc_cpp_plugin` +as a dependency for generating bindings for proto dependencies, if +this feature is used. + +Alternatively, the `rules-cc` repository can be added manually to +your `repos.json`. + +~~~json +... + , "rules-cc": + { "repository": + { "type": "git" + , "branch": "master" + , "commit": "2ea50063460a3e11dfcbb71651540c0d61fddc1a" + , "repository": "https://github.com/just-buildsystem/rules-cc" + , "subdir": "rules" + } + } +... +~~~ + +Importing this way, `protoc` and `grpc_cpp_plugin` will be taken +from the host system. To change the binary names or to bring your +own proto toolchain, add a corresponding `target_root` layer (and +provide the needed binding, if your target files refer to other +reposistories containing the toolchain). + +## Consume and being consumed by CMake Libraries + +For interoperability with CMake projects, see + +- [consume CMake libraries](./doc/consume-cmake-libraries.org) +- [being consumed by CMake](./doc/being-consumed-by-cmake.org) + +## Rule Documentation + +In this documentation, the standard configuration variables +`"AR"`, `"CC"`, `"CXX"`, `"CFLAGS"`, `"CXXFLAGS"`,`"LDFLAGS"`, +`"ADD_CFLAGS"`, `"ADD_CXXFLAGS"`, `"ADD_LDFLAGS"`, `"ENV"`, +`"BUILD_POSITION_INDEPENDENT"` are ommitted. + +### Rule `["CC", "binary"]` + +A binary written in C++ + +| Field | Description | +| ----- | ----------- | +| `"name"` | The name of the binary | +| `"stage"` | The logical location of all header and source files, as well as the resulting binary file. Individual directory components are joined with `"/"`. | +| `"pure C"` | If non-empty, compile as C sources rathter than C++ sources. In particular, CC is used to compile rather than CXX | +| `"private-defines"` | List of defines set for source files local to this target. Each list entry will be prepended by `"-D"`. | +| `"private-cflags"` | List of compile flags set for source files local to this target. | +| `"private-ldflags"` | Additional linker flags for linking external libraries. | +| `"srcs"` | The source files of the library. | +| `"private-hdrs"` | Any header files that need to be present when compiling the source files. | +| `"private-deps"` | Any other libraries this binary depends upon. | +| `"private-proto"` | Any `["proto", "library"]` this target depends upon directly. The creation of C++ bindings for this proto library as well as of is dependencies will be taken care of (as anonymous targets, so no duplicate work will be carried out, even if the same proto library is used at various places). | + +### Rule `["CC", "library"]` + +A C++ library + +| Field | Description | +| ----- | ----------- | +| `"name"` | The name of the library (without leading `"lib"` or trailing `".a"`). | +| `"stage"` | The logical location of all header and source files, as well as the resulting library file. Individual directory components are joined with `"/"`. | +| `"pure C"` | If non-empty, compile as C sources rather than C++ sources. In particular, CC is used to compile rather than CXX (or their respective defaults). | +| `"defines"` | List of defines set for this target and its consumers. Each list entry will be prepended by `"-D"`. | +| `"private-defines"` | List of defines set for source files local to this target. Each list entry will be prepended by `"-D"`. | +| `"cflags"` | List of compile flags set for this target and its consumers. | +| `"private-cflags"` | List of compile flags set for source files local to this target. | +| `"ldflags"` | Additional linker flags for linking external libraries for this target and its consumers (not built by this tool, typically system libraries). | +| `"private-ldflags"` | Additional linker flags for linking external libraries (not built by this tool, typically system libraries). | +| `"soversion"` | The SOVERSION for shared libraries. Individual version components are joined with `"."`. | +| `"pkg-name"` | Name to use for pkg-config files. If this field is empty, the field `"name"` is used instead. | +| `"srcs"` | The source files of the library. | +| `"hdrs"` | Any public header files of the library. | +| `"private-hdrs"` | Any header files that only need to be present when compiling the source files, but are not needed for any consumer of the library. | +| `"deps"` | Any other libraries this library depends upon. | +| `"private-deps"` | Any other libraries this library depends upon but does not include in its public headers. | +| `"proto"` | Any `["proto", "library"]` this target depends upon directly. The creation of C++ bindings for this proto library as well as of its dependencies will be taken care of (as anonymous targets, so no duplicate work will be carried out, even if the same proto library is used at various places). | +| `"private-proto"` | Any `["proto", "library"]` this target depends upon privately. The creation of C++ bindings for this proto library as well as of its dependencies will be taken care of (as anonymous targets, so no duplicate work will be carried out, even if the same proto library is used at various places). | +| `"shared"` | If non-empty, produce a shared instead of a static library. | + +### Rule `["CC/prebuilt", "library"]` + +A prebuilt C++ library + +| Field | Description | +| ----- | ----------- | +| `"name"` | The name of the library (without leading `"lib"` or trailing file name extension), also used as name for pkg-config files. | +| `"version"` | The library version, used for pkg-config files. Individual version components are joined with `"."`. | +| `"stage"` | The logical location of all header and source files, as well as the resulting library file. Individual directory components are joined with `"/"`. | +| `"defines"` | List of defines set for this target and its consumers. Each list entry will be prepended by `"-D"`. | +| `"cflags"` | List of compile flags set for this target and its consumers. | +| `"ldflags"` | Additional linker flags (typically for linking system libraries). | +| `"lib"` | The actual prebuilt library. If multiple libraries are specified (e.g., one depends on the other), the order matters. Library types cannot be mixed. All of them have to be either static or shared. | +| `"hdrs"` | Any public header files of the library. | +| `"deps"` | Any other libraries this library depends upon. | +| `"pkg-config"` | Pkg-config file for optional infer of public cflags and ldflags. If multiple files are specified (e.g., one depends on the other), the first one is used as entry. Note that if this field is non-empty the tool `"pkg-config"` must be available in `"PATH"`, which is taken from `["CC", "defaults"]` or the `"ENV"` variable. | + +### Rule `["CC", "install-with-deps"]` + +Install target's artifacts with transitive dependencies. Depending on the target, artifacts and dependencies will be installed to subdirectories `"bin"`, `"include"`, and `"lib"`. For library targets, a pkg-config file is generated and provided in `"share/pkgconfig"`. + +| Field | Description | +| ----- | ----------- | +| `"flat-libs"` | Install libraries flat to the `"lib"` subdirectory. Be aware that conflicts may occur if any of the (transitive) libraries happen to have the same base name. | +| `"prefix"` | The prefix used for pkg-config files. The path will be made absolute and individual directory components are joined with `"/"`. If no prefix is specified, the value from the config variable `"PREFIX"` is taken, with the default value being `"/"`. | +| `"hdrs-only"` | Only collect headers from deps (without subdirectory). | +| `"targets"` | Targets to install artifacts from. | + +| Config variable | Description | +| --------------- | ----------- | +| `"PREFIX"` | The absolute path that is used as prefix inside generated pkg-config files. The default value for this variable is `"/"`. This variable is ignored if the field `"prefix"` is set. | + +### Rule `["CC/test", "test"]` + +A test written in C++ + +| Field | Description | +| ----- | ----------- | +| `"name"` | The name of the test Used to name the test binary as well as for staging the test result | +| `"args"` | Command line arguments for the test binary | +| `"stage"` | The logical location of all header and source files. Individual directory components are joined with `"/"`. | +| `"private-defines"` | List of defines set for source files local to this target. Each list entry will be prepended by `"-D"`. | +| `"private-cflags"` | List of compile flags set for source files local to this target. | +| `"private-ldflags"` | Additional linker flags for linking external libraries (not built by this tool, typically system libraries). | +| `"srcs"` | The sources of the test binary | +| `"private-hdrs"` | Any additional header files that need to be present when compiling the test binary. | +| `"data"` | Any files the test binary needs access to when running | + +| Config variable | Description | +| --------------- | ----------- | +| `"TEST_ENV"` | The environment for executing the test runner. | +| `"CC_TEST_LAUNCHER"` | List of strings representing the launcher that is prepend to the command line for running the test binary. | +| `"RUNS_PER_TEST"` | The number of times the test should be run in order to detect flakyness. If set, no test action will be taken from cache. | + +### Rule `["CC", "defaults"]` + +A rule to provide defaults. All CC targets take their defaults for CC, CXX, flags, etc from the target `["CC", "defaults"]`. This is probably the only sensible use of this rule. As targets form a different root, the defaults can be provided without changing this directory. + +| Field | Description | +| ----- | ----------- | +| `"CC"` | The C compiler to use | +| `"CXX"` | The C++ compiler to use | +| `"CFLAGS"` | Flags for C compilation. Specifying this field overwrites values from `"base"`. | +| `"CXXFLAGS"` | Flags for C++ compilation. Specifying this field overwrites values from `"base"`. | +| `"LDFLAGS"` | Linker flags for linking the final CC library. Specifying this field overwrites values from `"base"`. | +| `"ADD_CFLAGS"` | Additional compilation flags for C. Specifying this field extends values from `"base"`. | +| `"ADD_CXXFLAGS"` | Additional compilation flags for C++. Specifying this field extends values from `"base"`. | +| `"ADD_LDFLAGS"` | Additional linker flags for linking the final CC library. Specifying this field extends values from `"base"`. | +| `"AR"` | The archiver tool to use | +| `"PATH"` | Path for looking up the compilers. Individual paths are joined with `":"`. | +| `"base"` | Other targets (using the same rule) to inherit values from. | + +### Rule `["CC/proto", "defaults"]` + +A rule to provide protoc/GRPC defaults. Used to implement `["CC/proto", "defaults"]` for CC proto libraries and `["CC/proto", "service defaults"]` for CC proto service libraries (GRPC). + +| Field | Description | +| ----- | ----------- | +| `"PROTOC"` | The proto compiler. If `"toolchain"` is empty, this field's value is considered the proto compiler name that is looked up in `"PATH"`. If `"toolchain"` is non-empty, this field's value is assumed to be the relative path to the proto compiler in `"toolchain"`. Specifying this field overwrites values from `"base"`. | +| `"LDFLAGS"` | Linker flags for linking the final CC library. Specifying this field overwrites values from `"base"`. | +| `"ADD_LDFLAGS"` | Additional linker flags for linking the final CC library. Specifying this field extends values from `"base"`. | +| `"GRPC_PLUGIN"` | The GRPC plugin for the proto compiler. If `"toolchain"` is empty, this field's value is considered to be the absolute system path to the plugin. If `"toolchain"` is non-empty, this field's value is assumed to be the relative path to the plugin in `"toolchain"`. Specifying this field overwrites values from `"base"`. | +| `"PATH"` | Path for looking up the proto compiler. Individual paths are joined with `":"`. | +| `"base"` | Other targets (using the same rule) to inherit values from. If multiple targets are specified, for values that are overwritten (see documentation of other fields) the last specified value wins. | +| `"toolchain"` | Optional toolchain directory. A collection of artifacts that provide the protobuf compiler and the GRPC plugin (if needed). Note that only artifacts of the specified targets are considered (no runfiles etc.). Specifying this field overlays artifacts from `"base"`. | +| `"deps"` | Optional CC libraries the resulting CC proto libraries implicitly depend on. Those are typically `"libprotobuf"` for CC proto libraries and `"libgrpc++"` for CC proto service libraries. Specifying this field extends dependencies from `"base"`. | + +### Rule `["shell/test", "script"]` + +Shell test, given by a test script + +| Field | Description | +| ----- | ----------- | +| `"keep"` | List of names (relative to the test working directory) of files that the test might generate that should be kept as part of the output. This might be useful for further analysis of the test | +| `"name"` | A name for the test, used in reporting, as well as for staging the test result tree in the runfiles | +| `"deps"` | Any targets that should be staged (with artifacts and runfiles) into the tests working directory | +| `"test"` | The shell script for the test, launched with sh. An empty directory is created to store any temporary files needed by the test, and it is made available in the environment variable TEST_TMPDIR. The test should not assume write permissions outside the working directory and the TEST_TMPDIR. For convenience, the environment variable TMPDIR is also set to TEST_TMPDIR. If the configuration variable RUNS_PER_TEST is set, the environment variable TEST_RUN_NUMBER will also be set to the number of the attempt, counting from 0. | + +| Config variable | Description | +| --------------- | ----------- | +| `"RUNS_PER_TEST"` | The number of times the test should be run in order to detect flakyness. If set, no test action will be taken from cache. | +| `"TEST_ENV"` | Additional environment for executing the test runner. | + +### Rule `["CC/foreign/cmake", "library"]` + +Library produced by CMake configure, build, and install. + +| Field | Description | +| ----- | ----------- | +| `"name"` | The name of the library (without leading `"lib"` or trailing file name extension), also used as name for pkg-config files. | +| `"version"` | The library version, used for pkg-config files. Individual version components are joined with `"."`. | +| `"stage"` | The logical location of the public headers and library files. Individual directory components are joined with `"/"`. | +| `"options"` | CMake options for the configuration phase. (e.g., `["-GNinja", "-Ax64"]`) | +| `"defines"` | CMake defines for the configuration phase. (e.g., `["CMAKE_BUILD_TYPE=Release"]`) | +| `"jobs"` | Number of jobs to run simultaneously. If omitted, CMake's default number is used. | +| `"pre_cmds"` | List of commands executed in the project directory before calling CMake. Useful for renaming files or directories. Note that data between `"pre_cmds"` and `"post_cmds"` can be exchanged via $TMPDIR, which is uniquely reserved for this action. | +| `"post_cmds"` | List of commands executed in the install directory after successful installation but before the output files are collected. Useful for renaming files or directories (e.g., in case of SONAME mismatch). Note that data between `"pre_cmds"` and `"post_cmds"` can be exchanged via $TMPDIR, which is uniquely reserved for this action. | +| `"out_hdrs"` | Paths to produced public header files. The path is considered relative to the include directory, which be set via `"hdr_prefix"`. Note that `"out_hdrs"` and `"out_hdr_dirs"` may not overlap. | +| `"out_hdr_dirs"` | Paths to produced public header directories. The path is considered relative to the include directory, which be set via `"hdr_prefix"`. Note that `"out_hdrs"` and `"out_hdr_dirs"` may not overlap. | +| `"out_libs"` | Paths to produced library files. The path is considered relative to the library directory, which be set via `"lib_prefix"`. Order matters in the case of one library depending on another. | +| `"cflags"` | List of compile flags set for this target and its consumers. | +| `"ldflags"` | Additional linker flags that are required for the consumer of the produced libraries. | +| `"pkg-config"` | Pkg-config file for optional infer of public cflags and ldflags. If multiple files are specified (e.g., one depends on the other), the first one is used as entry. Note that if this field is non-empty the tool `"pkg-config"` must be available in `"PATH"`, which is taken from `["CC", "defaults"]` or the `"ENV"` variable. | +| `"hdr_prefix"` | Prefix where headers will be installed by CMake. Individual directory components are joined with `"/"`. Defaults to `"include"` if not set. | +| `"lib_prefix"` | Prefix where libraries will be installed by CMake. Individual directory components are joined with `"/"`. Defaults to `"lib"` if not set. | +| `"pc_prefix"` | Prefix where pkg-config files will be installed by CMake. Individual directory components are joined with `"/"`. Defaults to `"lib/pkgconfig"` if not set. | +| `"project"` | The CMake project directory. It should contain a single tree artifact | +| `"deps"` | Public dependency on other CC libraries. | + +### Rule `["CC/foreign/cmake", "data"]` + +Data produced by CMake configure, build, and install. + +| Field | Description | +| ----- | ----------- | +| `"options"` | CMake options for the configuration phase. (e.g., `["-GNinja", "-Ax64"]`) | +| `"defines"` | CMake defines for the configuration phase. (e.g., `["CMAKE_BUILD_TYPE=Release"]`) | +| `"jobs"` | Number of jobs to run simultaneously. If omitted, CMake's default number is used. | +| `"pre_cmds"` | List of commands executed in the project directory before calling CMake. Useful for renaming files or directories. Note that data between `"pre_cmds"` and `"post_cmds"` can be exchanged via $TMPDIR, which is uniquely reserved for this action. | +| `"post_cmds"` | List of commands executed in the install directory after successful installation but before the output files are collected. Useful for renaming files or directories. Note that data between `"pre_cmds"` and `"post_cmds"` can be exchanged via $TMPDIR, which is uniquely reserved for this action. | +| `"out_files"` | Paths to the produced output files. The paths are considered relative to the install directory. Note that `"out_files"` and `"out_dirs"` may not overlap. | +| `"out_dirs"` | Paths to the produced output directories. The paths are considered relative to the install directory. Note that `"out_files"` and `"out_dirs"` may not overlap. | +| `"project"` | The CMake project directory. It should contain a single tree artifact | + +### Rule `["CC/foreign/make", "library"]` + +Library produced by Make build and install. + +| Field | Description | +| ----- | ----------- | +| `"name"` | The name of the library (without leading `"lib"` or trailing file name extension), also used as name for pkg-config files. | +| `"version"` | The library version, used for pkg-config files. Individual version components are joined with `"."`. | +| `"stage"` | The logical location of the public headers and library files. Individual directory components are joined with `"/"`. | +| `"target"` | The Make target to build (default: `["install"]`). | +| `"prefix"` | The prefix used for the Make target. The path will be made absolute and individual directory components are joined with `"/"`. If no prefix is specified, the value from the config variable `"PREFIX"` is taken, with the default value being `"/"`. | +| `"options"` | Make options for the configuration phase. (e.g., `["-f", "Makefile", "ARCH=x86"]`) | +| `"jobs"` | Number of jobs to run simultaneously. If omitted, Make's default number is used. | +| `"pre_cmds"` | List of commands executed in the project directory before calling Make. Useful for renaming files or directories. Note that data between `"pre_cmds"` and `"post_cmds"` can be exchanged via $TMPDIR, which is uniquely reserved for this action. | +| `"post_cmds"` | List of commands executed in the install directory after successful installation but before the output files are collected. Useful for renaming files or directories (e.g., in case of SONAME mismatch). Note that data between `"pre_cmds"` and `"post_cmds"` can be exchanged via $TMPDIR, which is uniquely reserved for this action. | +| `"out_hdrs"` | Paths to produced public header files. The path is considered relative to the include directory, which be set via `"hdr_prefix"`. Note that `"out_hdrs"` and `"out_hdr_dirs"` may not overlap. | +| `"out_hdr_dirs"` | Paths to produced public header directories. The path is considered relative to the include directory, which be set via `"hdr_prefix"`. Note that `"out_hdrs"` and `"out_hdr_dirs"` may not overlap. | +| `"out_libs"` | Paths to produced library files. The path is considered relative to the library directory, which be set via `"lib_prefix"`. Order matters in the case of one library depending on another. | +| `"cflags"` | List of compile flags set for this target and its consumers. | +| `"ldflags"` | Additional linker flags that are required for the consumer of the produced libraries. | +| `"pkg-config"` | Pkg-config file for optional infer of public cflags and ldflags. If multiple files are specified (e.g., one depends on the other), the first one is used as entry. Note that if this field is non-empty the tool `"pkg-config"` must be available in `"PATH"`, which is taken from `["CC", "defaults"]` or the `"ENV"` variable. | +| `"hdr_prefix"` | Prefix where headers will be installed by Make. Individual directory components are joined with `"/"`. Defaults to `"include"` if not set. | +| `"lib_prefix"` | Prefix where libraries will be installed by Make. Individual directory components are joined with `"/"`. Defaults to `"lib"` if not set. | +| `"pc_prefix"` | Prefix where pkg-config files will be installed by Make. Individual directory components are joined with `"/"`. Defaults to `"lib/pkgconfig"` if not set. | +| `"var_cc"` | Variable name used to specify the C compiler (default: `"CC"`). | +| `"var_cxx"` | Variable name used to specify the C++ compiler (default: `"CXX"`). | +| `"var_ccflags"` | Variable name used to specify the C flags (default: `"CFLAGS"`). | +| `"var_cxxflags"` | Variable name used to specify the C++ flags (default: `"CXXFLAGS"`). | +| `"var_ldflags"` | Variable name used to specify the link flags (default: `"LDFLAGS"`). | +| `"var_ar"` | Variable name used to specify the archiver (default: `"AR"`). | +| `"var_prefix"` | Variable name used to specify the prefix (default: `"PREFIX"`). | +| `"var_destdir"` | Variable name used to specify the destdir (default: `"DESTDIR"`). | +| `"project"` | The Make project directory. It should contain a single tree artifact | +| `"deps"` | Public dependency on other CC libraries. | + +| Config variable | Description | +| --------------- | ----------- | +| `"PREFIX"` | The absolute path that is used as prefix inside generated pkg-config files. The default value for this variable is `"/"`. This variable is ignored if the field `"prefix"` is set. | + +### Rule `["CC/foreign/make", "data"]` + +Data produced by Make build and install. + +| Field | Description | +| ----- | ----------- | +| `"target"` | The Make target to build (default: `["install"]`). | +| `"prefix"` | The prefix used for the Make target. The path will be made absolute and individual directory components are joined with `"/"`. If no prefix is specified, the value from the config variable `"PREFIX"` is taken, with the default value being `"/"`. | +| `"options"` | Make options for the configuration phase. (e.g., `["-f", "Makefile", "ARCH=x86"]`) | +| `"jobs"` | Number of jobs to run simultaneously. If omitted, Make's default number is used. | +| `"pre_cmds"` | List of commands executed in the project directory before calling Make. Useful for renaming files or directories. Note that data between `"pre_cmds"` and `"post_cmds"` can be exchanged via $TMPDIR, which is uniquely reserved for this action. | +| `"post_cmds"` | List of commands executed in the install directory after successful installation but before the output files are collected. Useful for renaming files or directories. Note that data between `"pre_cmds"` and `"post_cmds"` can be exchanged via $TMPDIR, which is uniquely reserved for this action. | +| `"out_files"` | Paths to the produced output files. The paths are considered relative to the install directory. Note that `"out_files"` and `"out_dirs"` may not overlap. | +| `"out_dirs"` | Paths to the produced output directories. The paths are considered relative to the install directory. Note that `"out_files"` and `"out_dirs"` may not overlap. | +| `"var_cc"` | Variable name used to specify the C compiler (default: `"CC"`). | +| `"var_cxx"` | Variable name used to specify the C++ compiler (default: `"CXX"`). | +| `"var_ccflags"` | Variable name used to specify the C flags (default: `"CFLAGS"`). | +| `"var_cxxflags"` | Variable name used to specify the C++ flags (default: `"CXXFLAGS"`). | +| `"var_ldflags"` | Variable name used to specify the link flags (default: `"LDFLAGS"`). | +| `"var_ar"` | Variable name used to specify the archiver (default: `"AR"`). | +| `"var_prefix"` | Variable name used to specify the prefix (default: `"PREFIX"`). | +| `"var_destdir"` | Variable name used to specify the destdir (default: `"DESTDIR"`). | +| `"project"` | The Make project directory. It should contain a single tree artifact | + +| Config variable | Description | +| --------------- | ----------- | +| `"PREFIX"` | The absolute path that is used as prefix inside generated pkg-config files. The default value for this variable is `"/"`. This variable is ignored if the field `"prefix"` is set. | + +### Rule `["proto", "library"]` + +A proto library as abstract data structure. + + Such a library does not produce any artifacts itself, but it can be used as a dependency for various language-specific rules. + +| Field | Description | +| ----- | ----------- | +| `"stage"` | The directory to stage the source files to. Directory components are joined by `"/"`. | +| `"name"` | The name of the (abstract) library. | +| `"service"` | If non empty, generate a service library (with access to `"rpc"` definitions) instead of a regular one. | +| `"srcs"` | The proto files for this library | +| `"deps"` | Any other proto library this library depends on | + +### Rule `["data", "staged"]` + +Stage data to a logical subdirectory. + +| Field | Description | +| ----- | ----------- | +| `"stage"` | The logical directory to stage the files to. Individual directory components are joined with `"/"`. | +| `"drop"` | List of paths to drop from (each of) the `"srcs"` targets before joining and staging. In this way, GLOB constructs can be used is `"srcs"`. | +| `"srcs"` | The files to be staged | +| `"deps"` | Targets of with their runfiles should be added as well. Their staging is not changed. | + +### Rule `["patch", "file"]` + +Replace a file, logically in place, by a patched version + +| Field | Description | +| ----- | ----------- | +| `"patch-part"` | If the patch contains hunks for multiple files, only apply hunks for the specified file path. Individual directory components are joined with `"/"`. Note that the patch must be provided in unified format. | +| `"src"` | The single source file to patch, typically an explicit file reference. | +| `"patch"` | The patch to apply. | + +### Rule `["CC/auto", "config"]` + +Generate a C/C++ config header + + Generate a C/C++ configuration header using defines specified via the target configuration. In the usual case, a target using this rule is configured by depending on it from a target that uses the built-in `"configure"` rule. + +| Field | Description | +| ----- | ----------- | +| `"name"` | Name of the header file to generate (incl. file name ext). | +| `"stage"` | The location of the header. Path segments are joined with `"/"`. | +| `"guard"` | The include guard. Multiple segments are joined with `"_"`. | +| `"hdrs"` | Additional header files to be available in the include path. Useful for providing additional header files to values given in `"have_{cfile,cxxfile,ctype,cxxtype,csymbol,cxxsymbol}"`. | +| `"deps"` | Additional public header files from targets to be available in the include path. Useful for providing additional header files to values given in `"have_{cfile,cxxfile,ctype,cxxtype,csymbol,cxxsymbol}"`. | + +| Config variable | Description | +| --------------- | ----------- | +| `"defines"` | Set a define to a specific value unless its value is `"null"`. Must contain a list of pairs. The first element of each pair is the define name and the second argument is the value to set. Strings must be properly escaped. Defines generated from this field are added last, so that they can refer to defines from other `"defines*"`, `"have_*"`, and `"size_*"` values. | +| `"defines1"` | Set a define to `"1"` unless its value is untrue. Must contain a list of pairs. The first element of each pair is the define name and the second argument is the value. | +| `"defines01"` | Set a define to `"0"` or `"1"` depending on its value being true. Must contain a list of pairs. The first element of each pair is the define name and the second argument is the value. | +| `"have_cfile"` | Set a define to `"1"` if the specified C header is in the include path. Must contain a list of pairs. The first element of each pair is the define name and the second argument is the C header file name. | +| `"have_cxxfile"` | Set a define to `"1"` if the specified C++ header is in the include path. Must contain a list of pairs. The first element of each pair is the define name and the second argument is the C++ header file name. | +| `"have_ctype"` | Set a define to `"1"` if the specified C type is defined. Must contain a list of pairs. The first element of each pair is the define name and the second argument is name of the C type. If the specified C type is not a built-in type, additionally the headers `"sys/types.h"`, `"stdint.h"`, and `"stddef.h"` are checked as well. | +| `"have_cxxtype"` | Set a define to `"1"` if the specified C++ type is defined. Must contain a list of pairs. The first element of each pair is the define name and the second argument is name of the C++ type. If the specified C++ type is not a built-in type, additionally the headers `"sys/types.h"`, `"stdint.h"`, and `"stddef.h"` are checked as well. | +| `"have_csymbol"` | Set a define to `"1"` if the specified C symbol is defined by one of the specified headers in the include path. Must contain a list of pairs. The first element of each pair is the define name and the second argument is another pair. This pair's first value is the C symbol to search for and the second value is a list with the header file names to consider for searching. If the header file defines the symbol as a macro it is considered available and assumed to work. | +| `"have_cxxsymbol"` | Set a define to `"1"` if the specified C++ symbol is defined by one of the specified headers in the include path. Must contain a list of pairs. The first element of each pair is the define name and the second argument is another pair. This pair's first value is the C++ symbol to search for and the second value is a list with the header file names to consider for searching. If the header file defines the symbol as a macro it is considered available and assumed to work. | +| `"size_ctype"` | Set a define to size of the specified C type. Must contain a list of pairs. The first element of each pair is the define name and the second argument is another pair. This pair's first value is the C type to check for and the second value is a list with possible sizes as numbers. If none of the specified sizes matches, the action fails. | +| `"size_cxxtype"` | Set a define to size of the specified C++ type. Must contain a list of pairs. The first element of each pair is the define name and the second argument is another pair. This pair's first value is the C++ type to check for and the second value is a list with possible sizes as numbers. If none of the specified sizes matches, the action fails. | + diff --git a/doc/being-consumed-by-cmake.org b/doc/being-consumed-by-cmake.org new file mode 100644 index 0000000..86c1825 --- /dev/null +++ b/doc/being-consumed-by-cmake.org @@ -0,0 +1,165 @@ +* Being consumed by CMake + +To support libraries built with JustBuild to be consumed by CMake, the rule +~["CC", "install-with-deps"]~ can be used. This rule will install the library's +artifacts, its public headers, and a pkg-config file, which can be used by CMake +to properly consume the library. + +In this example, we show how to build and install the ~ssl~ library with +JustBuild, so it can be picked up and used by CMake afterwards. + +** Example: Build and install the ~ssl~ Library with JustBuild + +First make sure that ~just~, ~just-mr~, and ~just-import-git~ are available in +your ~PATH~. Then, define a new workspace by creating the ~ROOT~ marker. + +#+BEGIN_SRC sh +$ touch ROOT +#+END_SRC + +The ~ssl~ library that we want to use is a defined dependency of the JustBuild +repository ~just/ssl~. To define a repository for that library, create the +following ~repos.template.json~ file. + +#+SRCNAME: repos.template.json +#+BEGIN_SRC js +{ "main": "ssl" +, "repositories": + { "ssl": + { "repository": {"type": "file", "path": "."} + , "bindings": {"rules": "rules-cc", "just-ssl": "just/ssl"} + } + } +} +#+END_SRC + +and import the ~rules-cc~ and JustBuild repository, including its dependency +~just/ssl~, via: + +#+BEGIN_SRC sh +$ cat repos.template.json \ + | just-import-git -C - --as just -b master https://github.com/just-buildsystem/justbuild \ + | just-import-git -C - --as rules-cc -b master https://github.com/just-buildsystem/rules-cc \ + > repos.json +$ +#+END_SRC + +Next, the following ~TARGETS~ file needs to be provided. + +#+SRCNAME: TARGETS +#+BEGIN_SRC js +{ "ssl-lib": + { "type": ["@", "rules", "CC", "library"] + , "name": ["ssl"] + , "deps": [["@", "just-ssl", "", "ssl"]] + } +, "ssl-pkg": + {"type": ["@", "rules", "CC", "install-with-deps"], "targets": ["ssl-lib"]} +} +#+END_SRC + +The library target ~ssl-lib~ specifies the name ~"ssl"~ (also used as package +name) and a dependency on the ~ssl~ library from ~just-ssl~. Note that although +this library target is merely a "wrapper" (header-only library without headers), +it could equally well be a full-blown library target. Furthermore, the package +target ~ssl-pkg~ installs the ~ssl-lib~ target including its dependencies and +generates a pkg-config file that can be later used by CMake. + +Finally, the ~ssl-pkg~ target can be built and installed to a specific ~PREFIX~ +(note that ~OS~ and ~ARCH~ must be set as well). + +#+BEGIN_SRC sh +$ export PREFIX=/tmp/just_ssl +$ just-mr install -D'{"OS":"linux", "ARCH":"x64_64", "PREFIX":"'$PREFIX'"}' -o $PREFIX ssl-pkg +INFO: Requested target is [["@","ssl","","ssl-pkg"],{"ARCH":"x64_64","OS":"linux","PREFIX":"/tmp/just_ssl"}] +INFO: Analysed target [["@","ssl","","ssl-pkg"],{"ARCH":"x64_64","OS":"linux","PREFIX":"/tmp/just_ssl"}] +INFO: Export targets found: 0 cached, 2 uncached, 0 not eligible for caching +INFO: Discovered 269 actions, 3 trees, 1 blobs +INFO: Building [["@","ssl","","ssl-pkg"],{"ARCH":"x64_64","OS":"linux","PREFIX":"/tmp/just_ssl"}]. +PROG: [ 79%] 0 cached, 215 run, 8 processing (["@","just/ssl","","crypto-lib"]#105, ...). +INFO: Processed 269 actions, 0 cache hits. +INFO: Artifacts can be found in: + /tmp/just_ssl/include/openssl/aead.h [6d78db27d24746b39eacc20374697476e080c9f6:21054:f] + ... + /tmp/just_ssl/lib/libcrypto.a [df64da43f0168a717d09d609bf0c631d29c86b61:2336092:f] + /tmp/just_ssl/lib/libssl.a [77d2c2bfbe3ef3608895c854f1d1f6e1c200efd0:852620:f] + /tmp/just_ssl/share/pkgconfig/ssl.pc [9b69c758430f5b5fb6ff7a9b1f1ffc89471509af:406:f] +$ +#+END_SRC + +** Example: Consume the installed ~ssl~ Library with CMake + +As an example, a minimal ~main.c~ file is created that depends on the ~ssl~ +library. + +#+SRCNAME: main.c +#+BEGIN_SRC C +#include <openssl/evp.h> + +int main(int argc, char** argv) { + OpenSSL_add_all_algorithms(); + return 0; +} +#+END_SRC + +In the ~CMakeLists.txt~ file, the ~pkg_check_modules()~ macro can be used to +determine the compile and linker flags needed to consume our ~ssl~ library with +CMake. + +#+SRCNAME: CMakeLists.txt +#+BEGIN_SRC cmake +cmake_minimum_required(VERSION 3.1) + +project(test_ssl) + +find_package(PkgConfig REQUIRED) +pkg_check_modules(SSL REQUIRED ssl) + +add_executable(main main.c) +target_include_directories(main PRIVATE ${SSL_INCLUDE_DIRS}) +target_compile_options(main PRIVATE ${SSL_CFLAGS_OTHER}) +target_link_directories(main PRIVATE ${SSL_LIBRARY_DIRS}) +target_link_libraries(main PRIVATE ${SSL_LDFLAGS_OTHER} ${SSL_LIBRARIES}) +#+END_SRC + +Note that ~${SSL_LDFLAGS_OTHER}~ can be omitted if the ~ssl-pkg~ target was +defined with a non-empty value for the field ~"flat-libs"~ (see rule +documentation of ~["CC", "install-with-deps"]~). + +Finally, when running CMake, make sure to set the ~CMAKE_PREFIX_PATH~ to the +previously used install prefix in order to successfully find the installed ~ssl~ +library and its pkg-config file. + +#+BEGIN_SRC sh +$ cmake -DCMAKE_PREFIX_PATH=/tmp/just_ssl -S . -B /tmp/test_ssl +-- The C compiler identification is GNU 10.2.1 +-- The CXX compiler identification is GNU 10.2.1 +-- Detecting C compiler ABI info +-- Detecting C compiler ABI info - done +-- Check for working C compiler: /usr/bin/cc - skipped +-- Detecting C compile features +-- Detecting C compile features - done +-- Detecting CXX compiler ABI info +-- Detecting CXX compiler ABI info - done +-- Check for working CXX compiler: /usr/bin/c++ - skipped +-- Detecting CXX compile features +-- Detecting CXX compile features - done +-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.2") +-- Checking for module 'ssl' +-- Found ssl, version unknown +-- Configuring done +-- Generating done +-- Build files have been written to: /tmp/test_ssl +$ cmake --build /tmp/test_ssl +[ 50%] Building CXX object CMakeFiles/main.dir/main.c.o +[100%] Linking CXX executable main +[100%] Built target main +$ +#+END_SRC + +Note that if the package is moved to a different location, the ~prefix~ variable +within the pkg-config file ~share/pkgconfig/ssl.pc~ must be updated as well. +Alternatively, CMake can be instructed to automatically guess the correct prefix +by setting the variable ~PKG_CONFIG_ARGN~ to ~"--define-prefix"~ (either on the +command line or in the ~CMakeLists.txt~). However, this is a fairly recent CMake +feature and requires at least CMake version 3.22. diff --git a/doc/consume-cmake-libraries.org b/doc/consume-cmake-libraries.org new file mode 100644 index 0000000..4aa75b6 --- /dev/null +++ b/doc/consume-cmake-libraries.org @@ -0,0 +1,137 @@ +* Consume CMake Libraries + +To support libraries built with CMake to be consumed by JustBuild, the rule +~["CC/foreign/cmake", "library"]~ can be used. This rule will run CMake and +collect the library's artifacts, public headers, and pkg-config files (if +available), to produce a proper JustBuild library target. + +In this example, we show how to consume the ~gtest~ library built with CMake +using JustBuild. + +** Example: Build the ~gtest~ Library with CMake + +First make sure that ~just~, ~just-mr~, and ~just-import-git~ are available in +your ~PATH~. Then, define a new workspace by creating a ~ROOT~ marker. + +#+BEGIN_SRC sh +$ touch ROOT +#+END_SRC + +To define a repository for the +[[https://github.com/google/googletest/tree/v1.13.0][gtest]] library, create the +following ~repos.template.json~ file. + +#+SRCNAME: repos.template.json +#+BEGIN_SRC js +{ "main": "tests" +, "repositories": + { "imports": {"repository": {"type": "file", "path": "imports"}} + , "gtest": + { "repository": + { "type": "git" + , "branch": "v1.13.0" + , "commit": "b796f7d44681514f58a683a3a71ff17c94edb0c1" + , "repository": "https://github.com/google/googletest" + } + , "target_root": "imports" + , "target_file_name": "gtest.TARGETS" + , "bindings": {"rules": "rules-cc"} + } + , "tests": + { "repository": {"type": "file", "path": "."} + , "bindings": {"rules": "rules-cc", "gtest": "gtest"} + } + } +} +#+END_SRC + +Now the missing ~rules-cc~ repository can be imported via: + +#+BEGIN_SRC sh +$ just-import-git -C repos.template.json --as rules-cc -b master https://github.com/just-buildsystem/rules-cc > repos.json +$ +#+END_SRC + +Create the file ~imports/gtest.TARGETS~ with the following content. + +#+SRCNAME: imports/gtest.TARGETS +#+BEGIN_SRC js +{ "gtest_main": + { "type": ["@", "rules", "CC/foreign/cmake", "library"] + , "name": ["gtest_main"] + , "version": ["1", "13", "0"] + , "project": [["TREE", null, "."]] + , "defines": ["BUILD_SHARED_LIBS=ON"] + , "out_hdr_dirs": ["gtest"] + , "out_libs": ["libgtest_main.so.1.13.0", "libgtest.so.1.13.0"] + , "pkg-config": ["gtest_main.pc", "gtest.pc"] + } +} +#+END_SRC + +The library ~gtest_main~ uses the rule ~["CC/foreign/cmake", "library"]~. It +sets ~defines~ to build shared libraries and collects the public header +directory ~gtest~, as well as the two libraries ~libgtest_main.so.1.13.0~ and +~libgtest.so.1.13.0~ (in this particular link order). Furthermore, to +automatically infer public compile and link flags (e.g., a link dependency to +the system's ~pthread~ library), the pkg-config files ~gtest_main.pc~ and +~gtest.pc~ are read, with the former (entry point) depending on the latter. + +Now, create the actual ~test~ target, which consumes the ~gtest_main~ library, +by creating the following ~TARGETS~ file. + +#+SRCNAME: TARGETS +#+BEGIN_SRC js +{ "test": + { "type": ["@", "rules", "CC/test", "test"] + , "name": ["test"] + , "srcs": ["test.cpp"] + , "private-deps": [["@", "gtest", "", "gtest_main"]] + } +} +#+END_SRC + +The last file missing yet is the actual test source file ~test.cpp~. + +#+SRCNAME: test.cpp +#+BEGIN_SRC cpp +#include <gtest/gtest.h> + +TEST(CastTest, double) { + EXPECT_EQ (42.0, double(42)); +} +#+END_SRC + +Finally, build the ~test~ target to run the test. + +#+BEGIN_SRC sh +$ just-mr build test -Pstdout +INFO: Requested target is [["@","tests","","test"],{}] +INFO: Analysed target [["@","tests","","test"],{}] +INFO: Export targets found: 0 cached, 0 uncached, 0 not eligible for caching +INFO: Target tainted ["test"]. +INFO: Discovered 7 actions, 2 trees, 3 blobs +INFO: Building [["@","tests","","test"],{}]. +INFO: Processed 7 actions, 0 cache hits. +INFO: Artifacts built, logical paths are: + result [7ef22e9a431ad0272713b71fdc8794016c8ef12f:5:f] + stderr [8b137891791fe96927ad78e64b0aad7bded08bdc:1:f] + stdout [fc46e9e95a8a393e3c94875d66b0de956305f6a6:728:f] + time-start [93887fee067665917f67e2cb757dd30bf22b23a0:11:f] + time-stop [93887fee067665917f67e2cb757dd30bf22b23a0:11:f] + (1 runfiles omitted.) +Running main() from src/gtest_main.cc +[==========] Running 1 test from 1 test suite. +[----------] Global test environment set-up. +[----------] 1 test from CastTest +[ RUN ] CastTest.double +[ OK ] CastTest.double (0 ms) +[----------] 1 test from CastTest (0 ms total) + +[----------] Global test environment tear-down +[==========] 1 test from 1 test suite ran. (0 ms total) +[ PASSED ] 1 test. + +INFO: Target tainted ["test"]. +$ +#+END_SRC diff --git a/etc/README.template.md b/etc/README.template.md new file mode 100644 index 0000000..98fed9a --- /dev/null +++ b/etc/README.template.md @@ -0,0 +1,55 @@ +# C/C++ rules for the `just` build system + +A collection of rules for building C/C++ libraries and binaries. + +## How to use this Repository + +There are two ways to import this repository. You can generate your +`repos.json` from a template (`repos.template.json`) by importing +the `rules-cc` repository with the tool `just-import-git` + +~~~sh +$ just-import-git -C repos.template.json --as rules-cc -b master https://github.com/just-buildsystem/rules-cc > repos.json +~~~ + +Importing this way will also pull in `protoc` and `grpc_cpp_plugin` +as a dependency for generating bindings for proto dependencies, if +this feature is used. + +Alternatively, the `rules-cc` repository can be added manually to +your `repos.json`. + +~~~json +... + , "rules-cc": + { "repository": + { "type": "git" + , "branch": "master" + , "commit": "2ea50063460a3e11dfcbb71651540c0d61fddc1a" + , "repository": "https://github.com/just-buildsystem/rules-cc" + , "subdir": "rules" + } + } +... +~~~ + +Importing this way, `protoc` and `grpc_cpp_plugin` will be taken +from the host system. To change the binary names or to bring your +own proto toolchain, add a corresponding `target_root` layer (and +provide the needed binding, if your target files refer to other +reposistories containing the toolchain). + +## Consume and being consumed by CMake Libraries + +For interoperability with CMake projects, see + +- [consume CMake libraries](./doc/consume-cmake-libraries.org) +- [being consumed by CMake](./doc/being-consumed-by-cmake.org) + +## Rule Documentation + +In this documentation, the standard configuration variables +`"AR"`, `"CC"`, `"CXX"`, `"CFLAGS"`, `"CXXFLAGS"`,`"LDFLAGS"`, +`"ADD_CFLAGS"`, `"ADD_CXXFLAGS"`, `"ADD_LDFLAGS"`, `"ENV"`, +`"BUILD_POSITION_INDEPENDENT"` are ommitted. + diff --git a/etc/defaults/CC/TARGETS b/etc/defaults/CC/TARGETS new file mode 100644 index 0000000..6e095cc --- /dev/null +++ b/etc/defaults/CC/TARGETS @@ -0,0 +1,3 @@ +{ "defaults": + {"type": ["CC", "defaults"], "base": [["@", "base", "CC", "defaults"]]} +} diff --git a/CC/test/TARGETS b/etc/defaults/CC/auto/TARGETS index 0967ef4..0967ef4 100644 --- a/CC/test/TARGETS +++ b/etc/defaults/CC/auto/TARGETS diff --git a/etc/defaults/CC/proto/TARGETS b/etc/defaults/CC/proto/TARGETS new file mode 100644 index 0000000..95ae1b0 --- /dev/null +++ b/etc/defaults/CC/proto/TARGETS @@ -0,0 +1,14 @@ +{ "defaults": + { "type": ["CC/proto", "defaults"] + , "PROTOC": ["bin/protoc"] + , "deps": [["@", "protoc", "", "libprotobuf"]] + , "toolchain": [["@", "protoc", "", "toolchain"]] + } +, "service defaults": + { "type": ["CC/proto", "defaults"] + , "base": ["defaults"] + , "GRPC_PLUGIN": ["grpc_cpp_plugin"] + , "deps": [["@", "grpc", "", "grpc++"]] + , "toolchain": [["@", "grpc", "", "grpc_cpp_plugin"]] + } +} diff --git a/shell/test/TARGETS b/etc/defaults/CC/test/TARGETS index 0967ef4..0967ef4 100644 --- a/shell/test/TARGETS +++ b/etc/defaults/CC/test/TARGETS diff --git a/etc/defaults/shell/test/TARGETS b/etc/defaults/shell/test/TARGETS new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/etc/defaults/shell/test/TARGETS @@ -0,0 +1 @@ +{} diff --git a/etc/generate-doc.sh b/etc/generate-doc.sh new file mode 100755 index 0000000..01b90ce --- /dev/null +++ b/etc/generate-doc.sh @@ -0,0 +1,73 @@ +#!/bin/sh +# Copyright 2022 Huawei Cloud Computing Technology Co., Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -eu + +readonly ROOT=$(readlink -f $(dirname $0)/..) + +: ${OUTFILE:=README.md} + +doc2md() { + local MAIN="$1" + local MODULE="$2" + local RULE="$3" + + local RULE_DOC="$(just-mr --main "$MAIN" describe --rule --json "$MODULE" "$RULE")" + local DOC="$(echo "$RULE_DOC" | jq -r '.doc')" + local FIELD_DOC="$(echo "$RULE_DOC" | jq -r '.field_doc')" + local CONFIG_DOC="$(echo "$RULE_DOC" | jq -r '.config_doc | delpaths([["AR"], ["CC"], ["CXX"], ["CFLAGS"], ["CXXFLAGS"],["LDFLAGS"], ["ADD_CFLAGS"], ["ADD_CXXFLAGS"], ["ADD_LDFLAGS"], ["ENV"], ["BUILD_POSITION_INDEPENDENT"]])')" + + echo "### Rule \`[\"$MODULE\", \"$RULE\"]\`" + echo + echo "$DOC" \ + | jq -r '[.[] as $v | if ($v == "") then "\n\n" else $v end] | join(" ")' \ + | sed 's/\("[^"]*"\|\[[^]]*\]\|{[^}]*}\)/`\1`/g' + echo + echo "| Field | Description |" + echo "| ----- | ----------- |" + echo "$FIELD_DOC" \ + | jq -r 'keys_unsorted[] as $k | "| \"\($k)\" | \(.[$k] | join(" ")) |"' \ + | sed 's/\("[^"]*"\|\[[^]]*\]\|{[^}]*}\)/`\1`/g' + echo + if [ "$(echo "$CONFIG_DOC" | jq -r 'length')" -gt 0 ] + then + echo "| Config variable | Description |" + echo "| --------------- | ----------- |" + echo "$CONFIG_DOC" \ + | jq -r 'keys_unsorted[] as $k | "| \"\($k)\" | \(.[$k] | join(" ")) |"' \ + | sed 's/\("[^"]*"\|\[[^]]*\]\|{[^}]*}\)/`\1`/g' + echo + fi +} + +rm -f "$OUTFILE" +( cat "$ROOT/etc/README.template.md" + doc2md rules CC binary + doc2md rules CC library + doc2md rules CC/prebuilt library + doc2md rules CC install-with-deps + doc2md rules CC/test test + doc2md rules CC defaults + doc2md rules CC/proto defaults + doc2md rules shell/test script + doc2md rules CC/foreign/cmake library + doc2md rules CC/foreign/cmake data + doc2md rules CC/foreign/make library + doc2md rules CC/foreign/make data + doc2md rules proto library + doc2md rules data staged + doc2md rules patch file + doc2md rules CC/auto config +) >> "$OUTFILE" diff --git a/etc/generate-repos.sh b/etc/generate-repos.sh new file mode 100755 index 0000000..28d046a --- /dev/null +++ b/etc/generate-repos.sh @@ -0,0 +1,25 @@ +#!/bin/sh +# Copyright 2022 Huawei Cloud Computing Technology Co., Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -eu + +readonly ROOT=$(readlink -f $(dirname $0)/..) + +: ${BRANCH:=v1.1.0-beta1} +: ${OUTFILE:=${ROOT}/etc/repos.json} + +just-import-git --as just -C ${ROOT}/etc/repos.template.json \ + -b ${BRANCH} https://github.com/just-buildsystem/justbuild \ + | ${ROOT}/etc/json-format.py > ${OUTFILE} diff --git a/etc/imports/gtest.TARGETS b/etc/imports/gtest.TARGETS new file mode 100644 index 0000000..a9b2217 --- /dev/null +++ b/etc/imports/gtest.TARGETS @@ -0,0 +1,6 @@ +{ "tree": + { "type": "install" + , "dirs": [[["TREE", null, "."], "googletest"]] + , "tainted": ["test"] + } +} diff --git a/etc/imports/libs.TARGETS b/etc/imports/libs.TARGETS new file mode 100644 index 0000000..f455122 --- /dev/null +++ b/etc/imports/libs.TARGETS @@ -0,0 +1,3 @@ +{ "tree": + {"type": "tree", "deps": [["@", "gtest", "", "tree"]], "tainted": ["test"]} +} diff --git a/etc/imports/rules.TARGETS b/etc/imports/rules.TARGETS new file mode 100644 index 0000000..73e1ff5 --- /dev/null +++ b/etc/imports/rules.TARGETS @@ -0,0 +1 @@ +{"tree": {"type": "install", "dirs": [[["TREE", null, "."], "rules"]], "tainted": ["test"]}} diff --git a/etc/json-format.py b/etc/json-format.py new file mode 100755 index 0000000..058d098 --- /dev/null +++ b/etc/json-format.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2021-2022 Klaus Aehlig. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import json +import sys + +def is_simple(entry): + if isinstance(entry, list): + return len(entry) == 0 + if isinstance(entry, dict): + return len(entry) == 0 + return True + +def is_short(entry, indent): + return len(json.dumps(entry)) + indent < 80 + +def hdumps(entry, *, _current_indent=0): + if is_short(entry, _current_indent): + return json.dumps(entry) + if isinstance(entry, list) and entry: + result = "[ " + hdumps(entry[0], _current_indent=_current_indent+2) + for x in entry[1:]: + result += "\n" + " " * _current_indent + ", " + result += hdumps(x, _current_indent=_current_indent+2) + result += "\n" + " " * _current_indent + "]" + return result + if isinstance(entry, dict) and entry: + result = "{ " + is_first = True + for k in entry.keys(): + if not is_first: + result += "\n" + " " * _current_indent + ", " + result += json.dumps(k) + ":" + if is_simple(entry[k]): + result += " " + json.dumps(entry[k]) + elif is_short(entry[k], _current_indent + len(json.dumps(k)) + 4): + result += " " + json.dumps(entry[k]) + else: + result += "\n" + " " * _current_indent + " " + result += hdumps(entry[k], _current_indent=_current_indent+2) + is_first = False + result += "\n" + " " * _current_indent + "}" + return result + return json.dumps(entry) + +if __name__ == "__main__": + data = json.load(sys.stdin) + print(hdumps(data)) diff --git a/etc/repos.json b/etc/repos.json new file mode 100644 index 0000000..7d09c90 --- /dev/null +++ b/etc/repos.json @@ -0,0 +1,465 @@ +{ "main": "rules with bundled tools" +, "repositories": + { "rules": {"repository": {"type": "file", "path": "rules"}} + , "rules with bundled tools": + { "repository": "rules" + , "target_root": "defaults" + , "rule_root": "rules" + , "bindings": + { "base": "just/rules" + , "protoc": "just/protobuf" + , "grpc": "just/com_github_grpc_grpc" + } + } + , "defaults": {"repository": {"type": "file", "path": "etc/defaults"}} + , "tests": + { "repository": {"type": "file", "path": "tests"} + , "bindings": + { "test-just": "just" + , "test-rules": "test-rules" + , "test-libs": "test-libs" + } + } + , "imports": {"repository": {"type": "file", "path": "etc/imports"}} + , "test-rules": + { "repository": {"type": "file", "path": "rules"} + , "target_root": "imports" + , "target_file_name": "rules.TARGETS" + } + , "test-libs": + { "repository": "imports" + , "target_file_name": "libs.TARGETS" + , "bindings": {"gtest": "gtest"} + } + , "gtest": + { "repository": + { "type": "archive" + , "fetch": "https://github.com/google/googletest/archive/refs/tags/v1.13.0.tar.gz" + , "content": "cbd19f97df3ab86b174520cd850d238617c156e0" + , "sha256": "ad7fdba11ea011c1d925b3289cf4af2c66a352e18d4c7264392fead75e919363" + , "subdir": "googletest-1.13.0" + } + , "target_root": "imports" + , "target_file_name": "gtest.TARGETS" + } + , "just": + { "repository": + { "type": "git" + , "repository": "https://github.com/just-buildsystem/justbuild" + , "branch": "v1.1.0-beta1" + , "commit": "7b776d35325ed3f07eaaf69699f4be948dd1394c" + } + , "bindings": + { "rules": "just/rules-just" + , "just-distfiles": "just/just-distfiles" + , "gsl": "just/com_github_microsoft_gsl" + , "cli11": "just/cli11" + , "json": "just/json" + , "fmt": "just/fmt" + , "ssl": "just/ssl" + , "grpc": "just/com_github_grpc_grpc" + , "googleapis": "just/google_apis" + , "bazel_remote_apis": "just/bazel_remote_apis" + , "libgit2": "just/com_github_libgit2_libgit2" + , "catch2": "just/catch2" + , "protoc": "just/protobuf" + , "libcurl": "just/com_github_curl_curl" + , "libarchive": "just/com_github_libarchive_libarchive" + } + } + , "just/bazel_remote_apis": + { "repository": + { "type": "archive" + , "content": "b5deb95d544f03f1918cc9d611c7904b8173befa" + , "fetch": "https://github.com/bazelbuild/remote-apis/archive/v2.0.0.tar.gz" + , "sha256": "79204ed1fa385c03b5235f65b25ced6ac51cf4b00e45e1157beca6a28bdb8043" + , "sha512": "7465f4726a9cc263352f6f0ec5b065c53e2ad787611740e1a458331858bdf28d53d69ba3db3d83fbf4a578229a413ac230886b5fcd33ab76425c61b1f08ef3b3" + , "subdir": "remote-apis-2.0.0" + } + , "target_root": "just/import targets" + , "target_file_name": "TARGETS.bazel_remote_apis" + , "bindings": {"rules": "just/rules", "google_apis": "just/google_apis"} + } + , "just/bzip2": + { "repository": + { "type": "archive" + , "content": "f9d91f2012aedeedcfd3bd918124ca11f0160373" + , "fetch": "https://github.com/libarchive/bzip2/archive/refs/tags/bzip2-1.0.8.tar.gz" + , "sha256": "db106b740252669664fd8f3a1c69fe7f689d5cd4b132f82ba82b9afba27627df" + , "sha512": "596d1b304f1f2d64b020d04845db10a2330c7f614a9fd0b5344afff65877d2141b3fcaa43d9e2dbc2f6a7929a1dab07df54d3d4bd69678b53906472958c7b80c" + , "subdir": "bzip2-bzip2-1.0.8" + } + , "target_root": "just/import targets" + , "target_file_name": "TARGETS.bzip2" + , "bindings": {"rules": "just/rules-bzip2"} + } + , "just/catch2": + { "repository": + { "type": "archive" + , "content": "fd54249eeb20894ece50696a84ef674a0052b6da" + , "fetch": "https://github.com/catchorg/Catch2/archive/refs/tags/v3.3.2.tar.gz" + , "sha256": "8361907f4d9bff3ae7c1edb027f813659f793053c99b67837a0c0375f065bae2" + , "sha512": "3d0c5666509a19be54ea0c48a3c8e1c4a951a2d991a7c9f7fe6d326661464538f1ab9dc573b1b2647f49fb6bef45bbd866142a4ce0fba38545ad182b8d55f61f" + , "subdir": "Catch2-3.3.2" + } + , "target_root": "just/import targets" + , "target_file_name": "TARGETS.catch2" + , "bindings": {"rules": "just/rules"} + } + , "just/cli11": + { "repository": + { "type": "archive" + , "content": "f2eee8c3fe04347bbb65cbb555c83d4c8d6a7034" + , "fetch": "https://github.com/CLIUtils/CLI11/archive/refs/tags/v2.3.2.tar.gz" + , "sha256": "aac0ab42108131ac5d3344a9db0fdf25c4db652296641955720a4fbe52334e22" + , "sha512": "f48b289d52034c47b90db58c035a123b464bed488cf31bcdbe10a692214a5c05e62b99d6fb7c4b065f42df862ecf3813f11dd533b3697939d761e99d2b89c2ec" + , "subdir": "CLI11-2.3.2/" + } + , "target_root": "just/import targets" + , "target_file_name": "TARGETS.cli11" + , "bindings": {"rules": "just/rules"} + } + , "just/com_github_cares_cares": + { "repository": + { "type": "archive" + , "content": "998c90eda4410f965ca086ce59811e2cf16c8d6b" + , "fetch": "https://github.com/c-ares/c-ares/archive/refs/tags/cares-1_17_2.tar.gz" + , "sha256": "444b7dbf33cb6e8a764d069e3485cbaaa28386d60eace6988275c3cb9534d300" + , "sha512": "1111f1e7eeb0e5d9e70d1a7c8566145d0a5e6e71b020f3fcaa02ecdf1931553ddeff83fdc152a1f9c5a780078e8afe3670164b631df56eecd2b638210cc59bb3" + , "subdir": "c-ares-cares-1_17_2" + } + , "target_root": "just/import targets" + , "target_file_name": "TARGETS.cares" + , "bindings": {"rules": "just/rules", "grpc": "just/com_github_grpc_grpc"} + } + , "just/com_github_curl_curl": + { "repository": + { "type": "archive" + , "content": "540b4de2edfa015b894ad86d51b33a55f451ac99" + , "fetch": "https://github.com/curl/curl/releases/download/curl-8_0_1/curl-8.0.1.tar.gz" + , "sha256": "5fd29000a4089934f121eff456101f0a5d09e2a3e89da1d714adf06c4be887cb" + , "sha512": "87d945e65176613c6296f8b130bd6c5355e3ca3c62ee4010edd481950cad9760482fd3be8a84e51501c118c29ebc284b8f87c49b06f9d248e9da5819fda38f8f" + , "subdir": "curl-8.0.1" + } + , "target_root": "just/import targets" + , "target_file_name": "TARGETS.curl" + , "bindings": + { "rules": "just/rules-curl" + , "zlib": "just/zlib" + , "ssl": "just/ssl" + , "cares": "just/com_github_cares_cares" + } + } + , "just/com_github_grpc_grpc": + { "repository": + { "type": "archive" + , "content": "a60418787a6e6f98c584d8de42d93b8983254939" + , "fetch": "https://github.com/grpc/grpc/archive/refs/tags/v1.53.0.tar.gz" + , "sha256": "9717ffc52120861136e478155c2ff3a9c21740e2244de52fa966f376d7471adf" + , "sha512": "a02fe1969787cd39061269b8c7c1313c1f599a31aa4e11760a744a9e0f85202e33832ee669b9d0d07df4af1a45470d605a69d9e4a4df89251e9b0093aee89eca" + , "subdir": "grpc-1.53.0" + } + , "target_root": "just/import targets" + , "target_file_name": "TARGETS.grpc" + , "rule_file_name": "RULES.grpc" + , "bindings": + { "rules": "just/rules-grpc" + , "protobuf": "just/protobuf" + , "libssl": "just/ssl" + , "absl": "just/com_google_absl" + , "zlib": "just/zlib" + , "re2": "just/re2" + , "cares": "just/com_github_cares_cares" + , "google_apis": "just/google_apis" + } + } + , "just/com_github_libarchive_libarchive": + { "repository": + { "type": "archive" + , "content": "2dafab016d6338086925fd04dbaa6a18bd24cb31" + , "fetch": "https://github.com/libarchive/libarchive/releases/download/v3.6.2/libarchive-3.6.2.tar.gz" + , "sha256": "ba6d02f15ba04aba9c23fd5f236bb234eab9d5209e95d1c4df85c44d5f19b9b3" + , "sha512": "24e476465054a29a2d48adf3c197a171b5361fa5038729a1f14d578c6701424de4e5dd6a2b20a6b697969ab43bdd8afc1585f8de0465c266f455d7eaa19e5048" + , "subdir": "libarchive-3.6.2" + } + , "target_root": "just/import targets" + , "target_file_name": "TARGETS.archive" + , "bindings": + { "rules": "just/rules-archive" + , "zlib": "just/zlib" + , "ssl": "just/ssl" + , "bzip2": "just/bzip2" + } + } + , "just/com_github_libgit2_libgit2": + { "repository": + { "type": "archive" + , "content": "0c7c845401ae9ad63c5617da6df7e84145b699a0" + , "fetch": "https://github.com/libgit2/libgit2/archive/refs/tags/v1.5.2.tar.gz" + , "sha256": "57638ac0e319078f56a7e17570be754515e5b1276d3750904b4214c92e8fa196" + , "sha512": "0de5e82953482bf57e9cd221406581a12c6acfbeeea0cebbb9b701d288804ec085b7c0902ba1f04ad7cdaaead9d472be21ffe8d730050db5c77101a93448fb3a" + , "subdir": "libgit2-1.5.2" + } + , "target_root": "just/import targets" + , "target_file_name": "TARGETS.git2" + , "bindings": + {"rules": "just/rules-git2", "zlib": "just/zlib", "ssl": "just/ssl"} + } + , "just/com_github_microsoft_gsl": + { "repository": + { "type": "archive" + , "content": "386f0a89a47763481223a63d5026215af8d3c827" + , "fetch": "https://github.com/microsoft/GSL/archive/refs/tags/v4.0.0.tar.gz" + , "sha256": "f0e32cb10654fea91ad56bde89170d78cfbf4363ee0b01d8f097de2ba49f6ce9" + , "sha512": "7fa7446796c6bf82fb3bff09f86a69c446a27be528bef3b17c8bc5ad2f24d5cf86bdb3d3813ecb44726e8f395020180e97e41027330d1fbf545cc0f0b44aac29" + , "subdir": "GSL-4.0.0/include/gsl" + } + , "target_root": "just/import targets" + , "target_file_name": "TARGETS.gsl" + , "bindings": {"rules": "just/rules"} + } + , "just/com_google_absl": + { "repository": + { "type": "archive" + , "content": "8cc2a99cfd2426ba6fbdc4499a07bccfd19be8a6" + , "fetch": "https://github.com/abseil/abseil-cpp/archive/refs/tags/20230125.0.tar.gz" + , "sha256": "3ea49a7d97421b88a8c48a0de16c16048e17725c7ec0f1d3ea2683a2a75adc21" + , "sha512": "b3d334215c78b31a2eb10bd9d4a978cd48367866d6daa2065c6c727282bafe19ef7ff5bd7cd4ed5c319d3b04e0711222e08ddbe7621ef1e079fed93a7307112f" + , "subdir": "abseil-cpp-20230125.0" + } + , "target_root": "just/import targets" + , "target_file_name": "TARGETS.absl" + , "bindings": {"rules": "just/rules-absl"} + } + , "just/fmt": + { "repository": + { "type": "zip" + , "content": "558d83d0fedb1f1ee3c3c4f1576d549cae7614ed" + , "fetch": "https://github.com/fmtlib/fmt/releases/download/9.1.0/fmt-9.1.0.zip" + , "sha256": "cceb4cb9366e18a5742128cb3524ce5f50e88b476f1e54737a47ffdf4df4c996" + , "sha512": "482d1ceaf042e97c66ff570babe9bd6f9cab7e4eec3dc56eb7d5e075b6b9b16f8eb333e96de9627fa33324d32b88d2aacebd0c34c3c706650eaa1729b0dd7fd6" + , "subdir": "fmt-9.1.0" + } + , "target_root": "just/import targets" + , "target_file_name": "TARGETS.fmt" + , "bindings": {"rules": "just/rules"} + } + , "just/google_apis": + { "repository": + { "type": "archive" + , "content": "5d9001f3dff8dec1880c06c0de100a0c2fc65094" + , "fetch": "https://github.com/googleapis/googleapis/archive/2f9af297c84c55c8b871ba4495e01ade42476c92.tar.gz" + , "sha256": "5bb6b0253ccf64b53d6c7249625a7e3f6c3bc6402abd52d3778bfa48258703a0" + , "sha512": "cdeefae807df7097174b4bb28c0900b06a68d424c00ebba4ff5add260c9c651351d5e429bfc5de42f95ebb75dadec313f7bd3991c2fa476c9104f9ea656acad4" + , "subdir": "googleapis-2f9af297c84c55c8b871ba4495e01ade42476c92" + } + , "target_root": "just/import targets" + , "target_file_name": "TARGETS.google_apis" + , "bindings": {"rules": "just/rules", "patches": "just/patches"} + } + , "just/json": + { "repository": + { "type": "zip" + , "content": "a0cf5f0e098b6a8748eb1c106b0b1994b92fead9" + , "fetch": "https://github.com/nlohmann/json/releases/download/v3.11.2/include.zip" + , "sha256": "e5c7a9f49a16814be27e4ed0ee900ecd0092bfb7dbfca65b5a421b774dccaaed" + , "sha512": "99d9e6d588cabe8913a37437f86acb5d4b8b98bce12423e633c11c13b61e6c7f92ef8f9a4e991baa590329ee2b5c09ca9db9894bee1e54bdd68e8d09d83cc245" + , "subdir": "include/nlohmann" + } + , "target_root": "just/import targets" + , "target_file_name": "TARGETS.json" + , "bindings": {"rules": "just/rules"} + } + , "just/just-distfiles": + { "repository": + { "type": "distdir" + , "repositories": + [ "just/com_github_microsoft_gsl" + , "just/cli11" + , "just/json" + , "just/fmt" + , "just/ssl" + , "just/protobuf" + , "just/bazel_remote_apis" + , "just/google_apis" + , "just/com_google_absl" + , "just/zlib" + , "just/re2" + , "just/com_github_cares_cares" + , "just/com_github_grpc_grpc" + , "just/com_github_libgit2_libgit2" + ] + } + , "target_root": "just/import targets" + , "target_file_name": "TARGETS.distfiles" + } + , "just/patches": + { "repository": + { "type": "git" + , "repository": "https://github.com/just-buildsystem/justbuild" + , "branch": "v1.1.0-beta1" + , "commit": "7b776d35325ed3f07eaaf69699f4be948dd1394c" + , "subdir": "etc/patches" + } + } + , "just/protobuf": + { "repository": + { "type": "zip" + , "content": "5bc92c917a0714d0b37cbb9dcbbf434d132edc00" + , "fetch": "https://github.com/protocolbuffers/protobuf/archive/refs/tags/v3.21.12.zip" + , "sha256": "f7042d540c969b00db92e8e1066a9b8099c8379c33f40f360eb9e1d98a36ca26" + , "sha512": "7f1c9a4297a4e47705d64932483f31ed25da928d24e351d94899038f852015d4a16c88c2b962ac4a0c62e6a3f6689f87fb4cef7165d327aae5381a7b975bdf2e" + , "subdir": "protobuf-3.21.12" + } + , "target_root": "just/import targets" + , "target_file_name": "TARGETS.protobuf" + , "bindings": {"rules": "just/rules-protobuf", "zlib": "just/zlib"} + } + , "just/re2": + { "repository": + { "type": "archive" + , "content": "8eebd70d7ebd33ac5d736090cecd7cfe1831b9e3" + , "fetch": "https://github.com/google/re2/archive/refs/tags/2022-04-01.tar.gz" + , "sha256": "1ae8ccfdb1066a731bba6ee0881baad5efd2cd661acd9569b689f2586e1a50e9" + , "sha512": "fc3d7cc1ee6bd771719845566d83ffc8c4e19d838748e842a1e19c7564473c9a0a061bebb3966ffa82de6515346f9bbddc2d94ceb3de89233f58826774bd7ce7" + , "subdir": "re2-2022-04-01" + } + , "target_root": "just/import targets" + , "target_file_name": "TARGETS.re2" + , "bindings": {"rules": "just/rules-re2"} + } + , "just/rules": + { "repository": + { "type": "git" + , "repository": "https://github.com/just-buildsystem/justbuild" + , "branch": "v1.1.0-beta1" + , "commit": "7b776d35325ed3f07eaaf69699f4be948dd1394c" + , "subdir": "rules" + } + , "target_root": "just/defaults" + , "rule_root": "just/rules" + } + , "just/rules-absl": + { "repository": "just/rules" + , "target_root": "just/defaults" + , "rule_root": "just/rules" + , "target_file_name": "TARGETS.absl" + , "bindings": {"base": "just/rules"} + } + , "just/rules-archive": + { "repository": "just/rules" + , "target_root": "just/defaults" + , "rule_root": "just/rules" + , "target_file_name": "TARGETS.archive" + , "bindings": {"base": "just/rules"} + } + , "just/rules-boringssl": + { "repository": "just/rules" + , "target_root": "just/defaults" + , "rule_root": "just/rules" + , "target_file_name": "TARGETS.boringssl" + , "bindings": {"base": "just/rules"} + } + , "just/rules-bzip2": + { "repository": "just/rules" + , "target_root": "just/defaults" + , "rule_root": "just/rules" + , "target_file_name": "TARGETS.bzip2" + , "bindings": {"base": "just/rules"} + } + , "just/rules-curl": + { "repository": "just/rules" + , "target_root": "just/defaults" + , "rule_root": "just/rules" + , "target_file_name": "TARGETS.curl" + , "bindings": {"base": "just/rules"} + } + , "just/rules-git2": + { "repository": "just/rules" + , "target_root": "just/defaults" + , "rule_root": "just/rules" + , "target_file_name": "TARGETS.git2" + , "bindings": {"base": "just/rules"} + } + , "just/rules-grpc": + { "repository": "just/rules" + , "target_root": "just/defaults" + , "rule_root": "just/rules" + , "target_file_name": "TARGETS.grpc" + , "bindings": {"base": "just/rules", "protoc": "just/protobuf"} + } + , "just/rules-just": + { "repository": "just/rules" + , "target_root": "just/defaults" + , "rule_root": "just/rules" + , "target_file_name": "TARGETS.just" + , "bindings": + { "base": "just/rules" + , "protoc": "just/protobuf" + , "grpc": "just/com_github_grpc_grpc" + } + } + , "just/rules-protobuf": + { "repository": "just/rules" + , "target_root": "just/defaults" + , "rule_root": "just/rules" + , "target_file_name": "TARGETS.protobuf" + , "bindings": + { "base": "just/rules" + , "protoc": "just/protobuf" + , "grpc": "just/com_github_grpc_grpc" + } + } + , "just/rules-re2": + { "repository": "just/rules" + , "target_root": "just/defaults" + , "rule_root": "just/rules" + , "target_file_name": "TARGETS.re2" + , "bindings": {"base": "just/rules"} + } + , "just/ssl": + { "repository": + { "type": "archive" + , "content": "19cdde8ba529848172c09e84e3deb2c92dc670c3" + , "fetch": "https://github.com/google/boringssl/archive/6195bf8242156c9a2fa75702eee058f91b86a88b.tar.gz" + , "sha256": "ad0b806b6c5cbd6cae121c608945d5fed468748e330632e8d53315089ad52c67" + , "sha512": "bd0ff23103695a08c5072ef4e88042c32b684295ee6434124d9c9292586b72863c35246cd8002ad3de3a79a9dfe10a1e0beb594c1625bdf1d6f6175821ca75a1" + , "subdir": "boringssl-6195bf8242156c9a2fa75702eee058f91b86a88b" + } + , "target_root": "just/import targets" + , "target_file_name": "TARGETS.boringssl" + , "bindings": {"rules": "just/rules-boringssl"} + } + , "just/zlib": + { "repository": + { "type": "archive" + , "content": "d115fc690fa59d3be51b3442158876536140b6c2" + , "fetch": "https://github.com/madler/zlib/releases/download/v1.2.13/zlib-1.2.13.tar.gz" + , "sha256": "b3a24de97a8fdbc835b9833169501030b8977031bcb54b3b3ac13740f846ab30" + , "sha512": "99f0e843f52290e6950cc328820c0f322a4d934a504f66c7caa76bd0cc17ece4bf0546424fc95135de85a2656fed5115abb835fd8d8a390d60ffaf946c8887ad" + , "subdir": "zlib-1.2.13" + } + , "target_root": "just/import targets" + , "target_file_name": "TARGETS.zlib" + , "bindings": {"rules": "just/rules"} + } + , "just/defaults": + { "repository": + { "type": "git" + , "repository": "https://github.com/just-buildsystem/justbuild" + , "branch": "v1.1.0-beta1" + , "commit": "7b776d35325ed3f07eaaf69699f4be948dd1394c" + , "subdir": "etc/defaults" + } + } + , "just/import targets": + { "repository": + { "type": "git" + , "repository": "https://github.com/just-buildsystem/justbuild" + , "branch": "v1.1.0-beta1" + , "commit": "7b776d35325ed3f07eaaf69699f4be948dd1394c" + , "subdir": "etc/import" + } + } + } +} diff --git a/etc/repos.template.json b/etc/repos.template.json new file mode 100644 index 0000000..b18b665 --- /dev/null +++ b/etc/repos.template.json @@ -0,0 +1,46 @@ +{ "main": "rules with bundled tools" +, "repositories": + { "rules": {"repository": {"type": "file", "path": "rules"}} + , "rules with bundled tools": + { "repository": "rules" + , "target_root": "defaults" + , "rule_root": "rules" + , "bindings": + { "base": "just/rules" + , "protoc": "just/protobuf" + , "grpc": "just/com_github_grpc_grpc" + } + } + , "defaults": {"repository": {"type": "file", "path": "etc/defaults"}} + , "tests": + { "repository": {"type": "file", "path": "tests"} + , "bindings": + { "test-just": "just" + , "test-rules": "test-rules" + , "test-libs": "test-libs" + } + } + , "imports": {"repository": {"type": "file", "path": "etc/imports"}} + , "test-rules": + { "repository": {"type": "file", "path": "rules"} + , "target_root": "imports" + , "target_file_name": "rules.TARGETS" + } + , "test-libs": + { "repository": "imports" + , "target_file_name": "libs.TARGETS" + , "bindings": {"gtest": "gtest"} + } + , "gtest": + { "repository": + { "type": "archive" + , "fetch": "https://github.com/google/googletest/archive/refs/tags/v1.13.0.tar.gz" + , "content": "cbd19f97df3ab86b174520cd850d238617c156e0" + , "sha256": "ad7fdba11ea011c1d925b3289cf4af2c66a352e18d4c7264392fead75e919363" + , "subdir": "googletest-1.13.0" + } + , "target_root": "imports" + , "target_file_name": "gtest.TARGETS" + } + } +} diff --git a/CC/EXPRESSIONS b/rules/CC/EXPRESSIONS index a520cde..a520cde 100644 --- a/CC/EXPRESSIONS +++ b/rules/CC/EXPRESSIONS diff --git a/CC/RULES b/rules/CC/RULES index 37460d3..37460d3 100644 --- a/CC/RULES +++ b/rules/CC/RULES diff --git a/CC/TARGETS b/rules/CC/TARGETS index 8860e8b..8860e8b 100644 --- a/CC/TARGETS +++ b/rules/CC/TARGETS diff --git a/CC/auto/EXPRESSIONS b/rules/CC/auto/EXPRESSIONS index ac19f7a..ac19f7a 100644 --- a/CC/auto/EXPRESSIONS +++ b/rules/CC/auto/EXPRESSIONS diff --git a/CC/auto/RULES b/rules/CC/auto/RULES index e04289c..e04289c 100644 --- a/CC/auto/RULES +++ b/rules/CC/auto/RULES diff --git a/CC/auto/config_runner.py b/rules/CC/auto/config_runner.py index f938c27..f938c27 100755 --- a/CC/auto/config_runner.py +++ b/rules/CC/auto/config_runner.py diff --git a/CC/foreign/EXPRESSIONS b/rules/CC/foreign/EXPRESSIONS index 2cc1ac9..2cc1ac9 100644 --- a/CC/foreign/EXPRESSIONS +++ b/rules/CC/foreign/EXPRESSIONS diff --git a/CC/foreign/cmake/EXPRESSIONS b/rules/CC/foreign/cmake/EXPRESSIONS index 4dfcc07..4dfcc07 100644 --- a/CC/foreign/cmake/EXPRESSIONS +++ b/rules/CC/foreign/cmake/EXPRESSIONS diff --git a/CC/foreign/cmake/RULES b/rules/CC/foreign/cmake/RULES index 8e8b934..8e8b934 100644 --- a/CC/foreign/cmake/RULES +++ b/rules/CC/foreign/cmake/RULES diff --git a/CC/foreign/make/EXPRESSIONS b/rules/CC/foreign/make/EXPRESSIONS index e853b29..e853b29 100644 --- a/CC/foreign/make/EXPRESSIONS +++ b/rules/CC/foreign/make/EXPRESSIONS diff --git a/CC/foreign/make/RULES b/rules/CC/foreign/make/RULES index 9c8c738..9c8c738 100644 --- a/CC/foreign/make/RULES +++ b/rules/CC/foreign/make/RULES diff --git a/CC/pkgconfig/EXPRESSIONS b/rules/CC/pkgconfig/EXPRESSIONS index c770421..c770421 100644 --- a/CC/pkgconfig/EXPRESSIONS +++ b/rules/CC/pkgconfig/EXPRESSIONS diff --git a/CC/pkgconfig/RULES b/rules/CC/pkgconfig/RULES index a6f6ce8..a6f6ce8 100644 --- a/CC/pkgconfig/RULES +++ b/rules/CC/pkgconfig/RULES diff --git a/CC/prebuilt/EXPRESSIONS b/rules/CC/prebuilt/EXPRESSIONS index 6bfd874..6bfd874 100644 --- a/CC/prebuilt/EXPRESSIONS +++ b/rules/CC/prebuilt/EXPRESSIONS diff --git a/CC/prebuilt/RULES b/rules/CC/prebuilt/RULES index 16f9f26..16f9f26 100644 --- a/CC/prebuilt/RULES +++ b/rules/CC/prebuilt/RULES diff --git a/CC/prebuilt/read_pkgconfig.py b/rules/CC/prebuilt/read_pkgconfig.py index cb4154f..cb4154f 100755 --- a/CC/prebuilt/read_pkgconfig.py +++ b/rules/CC/prebuilt/read_pkgconfig.py diff --git a/CC/proto/EXPRESSIONS b/rules/CC/proto/EXPRESSIONS index 894b80b..894b80b 100644 --- a/CC/proto/EXPRESSIONS +++ b/rules/CC/proto/EXPRESSIONS diff --git a/CC/proto/RULES b/rules/CC/proto/RULES index 6d2e725..6d2e725 100644 --- a/CC/proto/RULES +++ b/rules/CC/proto/RULES diff --git a/CC/proto/TARGETS b/rules/CC/proto/TARGETS index 45ef759..45ef759 100644 --- a/CC/proto/TARGETS +++ b/rules/CC/proto/TARGETS diff --git a/CC/test/RULES b/rules/CC/test/RULES index af07210..af07210 100644 --- a/CC/test/RULES +++ b/rules/CC/test/RULES diff --git a/rules/CC/test/TARGETS b/rules/CC/test/TARGETS new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/rules/CC/test/TARGETS @@ -0,0 +1 @@ +{} diff --git a/CC/test/test_runner.py b/rules/CC/test/test_runner.py index 0647621..0647621 100755 --- a/CC/test/test_runner.py +++ b/rules/CC/test/test_runner.py diff --git a/EXPRESSIONS b/rules/EXPRESSIONS index c84ebf4..c84ebf4 100644 --- a/EXPRESSIONS +++ b/rules/EXPRESSIONS diff --git a/data/EXPRESSIONS b/rules/data/EXPRESSIONS index 929eaf8..929eaf8 100644 --- a/data/EXPRESSIONS +++ b/rules/data/EXPRESSIONS diff --git a/data/RULES b/rules/data/RULES index ab5c92e..ab5c92e 100644 --- a/data/RULES +++ b/rules/data/RULES diff --git a/patch/RULES b/rules/patch/RULES index b1ba95e..b1ba95e 100644 --- a/patch/RULES +++ b/rules/patch/RULES diff --git a/proto/RULES b/rules/proto/RULES index a9152dd..a9152dd 100644 --- a/proto/RULES +++ b/rules/proto/RULES diff --git a/shell/test/EXPRESSIONS b/rules/shell/test/EXPRESSIONS index ea36b32..ea36b32 100644 --- a/shell/test/EXPRESSIONS +++ b/rules/shell/test/EXPRESSIONS diff --git a/shell/test/RULES b/rules/shell/test/RULES index 19f859f..19f859f 100644 --- a/shell/test/RULES +++ b/rules/shell/test/RULES diff --git a/rules/shell/test/TARGETS b/rules/shell/test/TARGETS new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/rules/shell/test/TARGETS @@ -0,0 +1 @@ +{} diff --git a/shell/test/test_runner.sh b/rules/shell/test/test_runner.sh index 97c75ef..97c75ef 100755 --- a/shell/test/test_runner.sh +++ b/rules/shell/test/test_runner.sh diff --git a/shell/test/test_summary.py b/rules/shell/test/test_summary.py index 0b5e656..0b5e656 100755 --- a/shell/test/test_summary.py +++ b/rules/shell/test/test_summary.py diff --git a/transitions/EXPRESSIONS b/rules/transitions/EXPRESSIONS index 92be685..92be685 100644 --- a/transitions/EXPRESSIONS +++ b/rules/transitions/EXPRESSIONS diff --git a/tests/ROOT b/tests/ROOT new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/ROOT diff --git a/tests/TARGETS b/tests/TARGETS new file mode 100644 index 0000000..c64245e --- /dev/null +++ b/tests/TARGETS @@ -0,0 +1,6 @@ +{ "ALL": + { "type": "install" + , "deps": [["test_cases/deps", "ALL"], ["test_cases/cflags", "ALL"]] + , "tainted": ["test"] + } +} diff --git a/tests/test_cases/cflags/TARGETS b/tests/test_cases/cflags/TARGETS new file mode 100644 index 0000000..44c99f1 --- /dev/null +++ b/tests/test_cases/cflags/TARGETS @@ -0,0 +1,19 @@ +{ "public": + { "type": ["test_rules", "test_case"] + , "name": ["cflags_public"] + , "targets": + [ "+main_use_half3" + , "+test_use_half3" + , "+main_use_half3f" + , "+test_use_half3f" + ] + , "asserts": + [ "./main_use_half3/main_use_half3 | grep 1.5" + , "[ \"$(cat ./test_use_half3/result)\" = \"PASS\" ]" + , "./main_use_half3f/main_use_half3f | grep 1.5" + , "[ \"$(cat ./test_use_half3f/result)\" = \"PASS\" ]" + ] + , "data": [["TREE", null, "public"]] + } +, "ALL": {"type": "install", "deps": ["public"], "tainted": ["test"]} +} diff --git a/tests/test_cases/cflags/public/TARGETS b/tests/test_cases/cflags/public/TARGETS new file mode 100644 index 0000000..79aadb3 --- /dev/null +++ b/tests/test_cases/cflags/public/TARGETS @@ -0,0 +1,49 @@ +{ "half": + { "type": ["@", "rules", "CC", "library"] + , "name": ["half"] + , "hdrs": ["half.hpp"] + , "srcs": ["half.cpp"] + , "cflags": ["-DHALF_PRECISION_DOUBLE"] + , "stage": ["half"] + } +, "half3": + { "type": ["@", "rules", "CC", "library"] + , "name": ["half3"] + , "hdrs": ["half3.hpp"] + , "srcs": ["half3.cpp"] + , "deps": ["half"] + , "stage": ["half3"] + } +, "half3f": + { "type": ["@", "rules", "CC", "library"] + , "name": ["half3f"] + , "hdrs": ["half3f.hpp"] + , "srcs": ["half3f.cpp"] + , "private-deps": ["half3"] + , "stage": ["half3f"] + } +, "main_use_half3": + { "type": ["@", "rules", "CC", "binary"] + , "name": ["main_use_half3"] + , "srcs": ["main_use_half3.cpp"] + , "private-deps": ["half3"] + } +, "test_use_half3": + { "type": ["@", "rules", "CC/test", "test"] + , "name": ["test_use_half3"] + , "srcs": ["test_use_half3.cpp"] + , "private-deps": ["half3"] + } +, "main_use_half3f": + { "type": ["@", "rules", "CC", "binary"] + , "name": ["main_use_half3f"] + , "srcs": ["main_use_half3f.cpp"] + , "private-deps": ["half3f"] + } +, "test_use_half3f": + { "type": ["@", "rules", "CC/test", "test"] + , "name": ["test_use_half3f"] + , "srcs": ["test_use_half3f.cpp"] + , "private-deps": ["half3f"] + } +} diff --git a/tests/test_cases/cflags/public/half.cpp b/tests/test_cases/cflags/public/half.cpp new file mode 100644 index 0000000..e26ff6e --- /dev/null +++ b/tests/test_cases/cflags/public/half.cpp @@ -0,0 +1,5 @@ +#include "half.hpp" + +HALF_RESULT_TYPE half(int val) { + return static_cast<HALF_RESULT_TYPE>(val / 2.0); +} diff --git a/tests/test_cases/cflags/public/half.hpp b/tests/test_cases/cflags/public/half.hpp new file mode 100644 index 0000000..0baebcb --- /dev/null +++ b/tests/test_cases/cflags/public/half.hpp @@ -0,0 +1,12 @@ +#ifndef HALF_HPP +#define HALF_HPP + +#ifdef HALF_PRECISION_DOUBLE +#define HALF_RESULT_TYPE double +#else +#define HALF_RESULT_TYPE int +#endif + +HALF_RESULT_TYPE half(int val); + +#endif diff --git a/tests/test_cases/cflags/public/half3.cpp b/tests/test_cases/cflags/public/half3.cpp new file mode 100644 index 0000000..484f7f8 --- /dev/null +++ b/tests/test_cases/cflags/public/half3.cpp @@ -0,0 +1,3 @@ +#include "half3.hpp" + +HALF_RESULT_TYPE half3() { return half(3); } diff --git a/tests/test_cases/cflags/public/half3.hpp b/tests/test_cases/cflags/public/half3.hpp new file mode 100644 index 0000000..271ed68 --- /dev/null +++ b/tests/test_cases/cflags/public/half3.hpp @@ -0,0 +1,8 @@ +#ifndef HALF3_HPP +#define HALF3_HPP + +#include "half/half.hpp" + +HALF_RESULT_TYPE half3(); + +#endif diff --git a/tests/test_cases/cflags/public/half3f.cpp b/tests/test_cases/cflags/public/half3f.cpp new file mode 100644 index 0000000..88b6d55 --- /dev/null +++ b/tests/test_cases/cflags/public/half3f.cpp @@ -0,0 +1,7 @@ +#include "half3/half3.hpp" + +#ifndef HALF_PRECISION_DOUBLE +#error should be defined +#endif + +float half3f() { return static_cast<float>(half3()); } diff --git a/tests/test_cases/cflags/public/half3f.hpp b/tests/test_cases/cflags/public/half3f.hpp new file mode 100644 index 0000000..1207f63 --- /dev/null +++ b/tests/test_cases/cflags/public/half3f.hpp @@ -0,0 +1,6 @@ +#ifndef BAZ_HPP +#define BAZ_HPP + +float half3f(); + +#endif diff --git a/tests/test_cases/cflags/public/main_use_half3.cpp b/tests/test_cases/cflags/public/main_use_half3.cpp new file mode 100644 index 0000000..1c9d6ba --- /dev/null +++ b/tests/test_cases/cflags/public/main_use_half3.cpp @@ -0,0 +1,7 @@ +#include "half3/half3.hpp" +#include <iostream> + +int main() { + std::cout << half3() << std::endl; + return 0; +} diff --git a/tests/test_cases/cflags/public/main_use_half3f.cpp b/tests/test_cases/cflags/public/main_use_half3f.cpp new file mode 100644 index 0000000..3e855cd --- /dev/null +++ b/tests/test_cases/cflags/public/main_use_half3f.cpp @@ -0,0 +1,11 @@ +#include "half3f/half3f.hpp" +#include <iostream> + +#ifdef HALF_PRECISION_DOUBLE +#error should not be defined +#endif + +int main() { + std::cout << half3f() << std::endl; + return 0; +} diff --git a/tests/test_cases/cflags/public/test_use_half3.cpp b/tests/test_cases/cflags/public/test_use_half3.cpp new file mode 100644 index 0000000..1cf50ad --- /dev/null +++ b/tests/test_cases/cflags/public/test_use_half3.cpp @@ -0,0 +1,6 @@ +#include "half3/half3.hpp" + +int main() { + auto result = half3(); + return result > 1 and result < 2 ? 0 : 1; +} diff --git a/tests/test_cases/cflags/public/test_use_half3f.cpp b/tests/test_cases/cflags/public/test_use_half3f.cpp new file mode 100644 index 0000000..078e69c --- /dev/null +++ b/tests/test_cases/cflags/public/test_use_half3f.cpp @@ -0,0 +1,10 @@ +#include "half3f/half3f.hpp" + +#ifdef HALF_PRECISION_DOUBLE +#error should not be defined +#endif + +int main() { + auto result = half3f(); + return result > 1 and result < 2 ? 0 : 1; +} diff --git a/tests/test_cases/deps/TARGETS b/tests/test_cases/deps/TARGETS new file mode 100644 index 0000000..450d1a3 --- /dev/null +++ b/tests/test_cases/deps/TARGETS @@ -0,0 +1,195 @@ +{ "private": + { "type": ["test_rules", "test_case"] + , "name": ["deps_private"] + , "targets": + [ "+foo" + , "-main_includes_foo" + , "+main_links_foo" + , "+main_links_bar_foo" + , "+install_bar" + ] + , "asserts": + [ "test -f foo/foo/libfoo.a" + , "test -f foo/foo/foo.hpp" + , "! test -f foo/bar/bar.hpp" + , "./main_links_foo/main | grep foo" + , "./main_links_bar_foo/main | grep bar" + , "./main_links_bar_foo/main | grep foo" + , "test -f install_bar/lib/bar/libbar.a" + , "test -f install_bar/include/bar/bar.hpp" + , "test -f install_bar/lib/foo/libfoo.a" + , "! test -f install_bar/include/foo/foo.hpp" + ] + , "data": [["TREE", null, "private"]] + } +, "public": + { "type": ["test_rules", "test_case"] + , "name": ["deps_public"] + , "targets": + [ "+foo" + , "+main_includes_foo" + , "+main_links_foo" + , "+main_links_bar_foo" + , "+install_bar" + ] + , "asserts": + [ "test -f foo/foo/libfoo.a" + , "test -f foo/foo/foo.hpp" + , "! test -f foo/bar/bar.hpp" + , "./main_includes_foo/main | grep main" + , "./main_links_foo/main | grep foo" + , "./main_links_bar_foo/main | grep bar" + , "./main_links_bar_foo/main | grep foo" + , "test -f install_bar/lib/bar/libbar.a" + , "test -f install_bar/include/bar/bar.hpp" + , "test -f install_bar/lib/foo/libfoo.a" + , "test -f install_bar/include/foo/foo.hpp" + ] + , "data": [["TREE", null, "public"]] + } +, "shared": + { "type": ["test_rules", "test_case"] + , "name": ["deps_shared"] + , "targets": + [ "+foo" + , "+bar" + , "+main_uses_foo" + , "+test_uses_foo" + , "+main_uses_bar" + , "+test_uses_bar" + , "+test_uses_bar_s" + , "+test_uses_baz" + , "+test_uses_main" + , "+test_diamond" + , "+install_foo" + , "+install_bar_s" + , "+install_baz" + , "+install_main" + ] + , "asserts": + [ "test -f foo/libfoo.so.1.2.3" + , "test -f foo/foo/foo.hpp" + , "test -f bar/libbar.so" + , "test -f bar/bar/bar.hpp" + , "! test -f bar/foo/foo.hpp" + , "test -f install_foo/lib/libfoo.so.1.2.3" + , "test -f install_foo/include/foo/foo.hpp" + , "grep 'Name: foo' install_foo/share/pkgconfig/foo.pc" + , "grep 'Version: 1.2.3' install_foo/share/pkgconfig/foo.pc" + , "grep -- '-L${libdir}' install_foo/share/pkgconfig/foo.pc" + , "grep -- '-l:libfoo.so.1.2.3' install_foo/share/pkgconfig/foo.pc" + , "test -f install_bar_s/lib/bar/libbar.a" + , "test -f install_bar_s/include/bar/bar.hpp" + , "test -f install_bar_s/lib/libfoo.so.1.2.3" + , "! test -f install_bar_s/include/foo/foo.hpp" + , "grep 'Name: bar' install_bar_s/share/pkgconfig/bar.pc" + , "grep '${libdir}/bar/libbar.a' install_bar_s/share/pkgconfig/bar.pc" + , "grep '${libdir}/libfoo.so.1.2.3' install_bar_s/share/pkgconfig/bar.pc" + , "test -f install_baz/lib/libbaz.so" + , "test -f install_baz/include/baz/baz.hpp" + , "! test -f install_baz/lib/foo/libfoo.a" + , "! test -f install_baz/include/foo/foo.hpp" + , "./install_main/bin/main_uses_bar | grep main" + , "./install_main/bin/main_uses_bar | grep bar" + , "./install_main/bin/main_uses_bar | grep foo" + , "! test -d install_main/include" + ] + , "data": [["TREE", null, "shared"]] + } +, "prebuilt_tests": + { "type": "tree" + , "deps": + [ ["test_cases/deps/prebuilt", "foo.hpp"] + , ["test_cases/deps/prebuilt", "bar.hpp"] + , ["test_cases/deps/prebuilt", "TARGETS"] + , ["TREE", null, "shared"] + ] + } +, "prebuilt": + { "type": ["test_rules", "test_case"] + , "name": ["deps_prebuilt"] + , "targets": + [ "+foo" + , "+bar" + , "+main_uses_foo" + , "+test_uses_foo" + , "+main_uses_bar" + , "+test_uses_bar" + , "+test_uses_bar_s" + , "+test_uses_main" + , "+install_foo" + , "+install_bar" + , "+install_main" + , "+test_uses_foobar" + , "+test_uses_foobar_s" + , "+install_foobar" + ] + , "asserts": + [ "test -f foo/libfoo.so.1.2.3" + , "test -f foo/foo/foo.hpp" + , "test -f bar/libbar.so" + , "test -f bar/bar/bar.hpp" + , "test -f install_foo/share/pkgconfig/foo/foo.cflags" + , "test -f install_foo/share/pkgconfig/foo/foo.ldflags" + , "test -f install_bar/share/pkgconfig/foo/foo.cflags" + , "test -f install_bar/share/pkgconfig/foo/foo.ldflags" + , "test -f install_bar/share/pkgconfig/bar/bar.cflags" + , "test -f install_bar/share/pkgconfig/bar/bar.ldflags" + , "./install_main/bin/main_uses_bar | grep main" + , "./install_main/bin/main_uses_bar | grep bar" + , "./install_main/bin/main_uses_bar | grep foo" + , "test -f install_foobar/lib/libfoo.so.1.2.3" + , "test -f install_foobar/lib/libbar.so" + , "test -f install_foobar/share/pkgconfig/foobar.pc" + , "grep 'Cflags:.*@${prefix}/share/pkgconfig/bar/foobar.cflags' install_foobar/share/pkgconfig/foobar.pc" + , "grep -- '-DUSE_BAR=1 -DUSE_FOO=1' install_foobar/share/pkgconfig/bar/foobar.cflags" + , "grep 'Libs:.*@${prefix}/share/pkgconfig/bar/foobar.ldflags' install_foobar/share/pkgconfig/foobar.pc" + , "grep -- '-lm -lpthread' install_foobar/share/pkgconfig/bar/foobar.ldflags" + ] + , "data": ["prebuilt_tests"] + } +, "cmake": + { "type": ["test_rules", "test_case"] + , "name": ["deps_cmake"] + , "libs": ["googletest"] + , "targets": + [ "+gtest" + , "+test" + , "+gtest_main" + , "+testbin" + , "+shell_test" + , "+install_gtest" + , "+install_gtest_main" + , "+install_testbin" + ] + , "asserts": + [ "test -f gtest/libgtest.a" + , "test -f gtest/gtest/gtest.h" + , "grep 'PASSED.*1 test' test/stdout" + , "test -f gtest_main/libgtest.so.1.13.0" + , "test -f gtest_main/libgtest_main.so.1.13.0" + , "test -f gtest_main/gtest/gtest.h" + , "test -f ./testbin/test" + , "grep 'PASSED.*1 test' shell_test/stdout" + , "test -f install_gtest/lib/libgtest.a" + , "test -f install_gtest/include/gtest/gtest.h" + , "grep 'Cflags.*share/pkgconfig/gtest.cflags' install_gtest/share/pkgconfig/gtest.pc" + , "grep 'Libs.*libgtest.a' install_gtest/share/pkgconfig/gtest.pc" + , "grep 'Libs.*share/pkgconfig/gtest.ldflags' install_gtest/share/pkgconfig/gtest.pc" + , "test -f install_gtest_main/lib/libgtest.so.1.13.0" + , "test -f install_gtest_main/lib/libgtest_main.so.1.13.0" + , "test -f install_gtest_main/include/gtest/gtest.h" + , "grep 'Cflags.*share/pkgconfig/gtest_main.cflags' install_gtest_main/share/pkgconfig/gtest_main.pc" + , "grep 'Libs.*libgtest.so.1.13.0' install_gtest_main/share/pkgconfig/gtest_main.pc" + , "grep 'Libs.*libgtest_main.so.1.13.0' install_gtest_main/share/pkgconfig/gtest_main.pc" + , "grep 'Libs.*share/pkgconfig/gtest_main.ldflags' install_gtest_main/share/pkgconfig/gtest_main.pc" + , "./install_testbin/bin/test | grep 'PASSED.*1 test'" + ] + , "data": [["TREE", null, "cmake"]] + } +, "ALL": + { "type": "install" + , "deps": ["private", "public", "shared", "prebuilt", "cmake"] + , "tainted": ["test"] + } +} diff --git a/tests/test_cases/deps/cmake/TARGETS b/tests/test_cases/deps/cmake/TARGETS new file mode 100644 index 0000000..74633b9 --- /dev/null +++ b/tests/test_cases/deps/cmake/TARGETS @@ -0,0 +1,52 @@ +{ "gtest": + { "type": ["@", "rules", "CC/foreign/cmake", "library"] + , "name": ["gtest"] + , "version": ["1", "13", "0"] + , "project": [["@", "googletest", "", "tree"]] + , "out_hdr_dirs": ["gtest"] + , "out_libs": ["libgtest.a"] + , "pkg-config": ["gtest.pc"] + } +, "testlib": + { "type": ["@", "rules", "CC", "library"] + , "name": ["testlib"] + , "shared": ["yes"] + , "srcs": ["main.cpp"] + , "private-deps": ["gtest"] + } +, "test": + { "type": ["@", "rules", "CC/test", "test"] + , "name": ["test"] + , "private-deps": ["testlib", "gtest"] + } +, "gtest_main": + { "type": ["@", "rules", "CC/foreign/cmake", "library"] + , "name": ["gtest_main"] + , "version": ["1", "13", "0"] + , "project": [["@", "googletest", "", "tree"]] + , "defines": ["BUILD_SHARED_LIBS=ON"] + , "out_hdr_dirs": ["gtest"] + , "out_libs": ["libgtest_main.so.1.13.0", "libgtest.so.1.13.0"] + , "pkg-config": ["gtest_main.pc", "gtest.pc"] + } +, "testbin": + { "type": ["@", "rules", "CC", "binary"] + , "name": ["test"] + , "srcs": ["test.cpp"] + , "private-deps": ["gtest_main"] + } +, "shell_test": + { "type": ["@", "rules", "shell/test", "script"] + , "name": ["shell_test"] + , "test": ["test.sh"] + , "deps": ["testbin"] + } +, "install_gtest": + {"type": ["@", "rules", "CC", "install-with-deps"], "targets": ["gtest"]} +, "install_gtest_main": + { "type": ["@", "rules", "CC", "install-with-deps"] + , "targets": ["gtest_main"] + } +, "install_testbin": + {"type": ["@", "rules", "CC", "install-with-deps"], "targets": ["testbin"]} +} diff --git a/tests/test_cases/deps/cmake/main.cpp b/tests/test_cases/deps/cmake/main.cpp new file mode 100644 index 0000000..575a358 --- /dev/null +++ b/tests/test_cases/deps/cmake/main.cpp @@ -0,0 +1,8 @@ +#include <gtest/gtest.h> + +TEST(CastTest, float) { EXPECT_EQ(42.0f, float(42)); } + +int main(int argc, char **argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/tests/test_cases/deps/cmake/test.cpp b/tests/test_cases/deps/cmake/test.cpp new file mode 100644 index 0000000..b1811d8 --- /dev/null +++ b/tests/test_cases/deps/cmake/test.cpp @@ -0,0 +1,3 @@ +#include <gtest/gtest.h> + +TEST(CastTest, double) { EXPECT_EQ(42.0, double(42)); } diff --git a/tests/test_cases/deps/cmake/test.sh b/tests/test_cases/deps/cmake/test.sh new file mode 100644 index 0000000..80b7965 --- /dev/null +++ b/tests/test_cases/deps/cmake/test.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +set -e + +./test | grep PASSED diff --git a/tests/test_cases/deps/prebuilt/TARGETS b/tests/test_cases/deps/prebuilt/TARGETS new file mode 100644 index 0000000..c923995 --- /dev/null +++ b/tests/test_cases/deps/prebuilt/TARGETS @@ -0,0 +1,158 @@ +{ "foo.pc": + { "type": "file_gen" + , "name": "foo.pc" + , "data": + { "type": "join" + , "separator": "\n" + , "$1": + [ "Name: foo" + , "Version: 1.2.3" + , "Description: test prebuilt foo" + , "URL: unknown" + , "Cflags: -I/usr/include -DUSE_FOO=1" + , "Libs: -L/usr/lib -lfoo -lpthread" + ] + } + } +, "foo": + { "type": ["@", "rules", "CC/prebuilt", "library"] + , "name": ["foo"] + , "version": ["1", "2", "3"] + , "hdrs": ["foo.hpp"] + , "lib": [["shared", "foo"]] + , "pkg-config": ["foo.pc"] + , "stage": ["foo"] + } +, "foo_s": + { "type": ["@", "rules", "CC/prebuilt", "library"] + , "name": ["foo"] + , "version": ["1", "2", "3"] + , "hdrs": ["foo.hpp"] + , "lib": [["shared", "foo_s"]] + , "pkg-config": ["foo.pc"] + , "stage": ["foo"] + } +, "bar.pc": + { "type": "file_gen" + , "name": "bar.pc" + , "data": + { "type": "join" + , "separator": "\n" + , "$1": + [ "Name: bar" + , "Version: unknown" + , "Description: test prebuilt bar" + , "URL: unknown" + , "Cflags: -I/usr/include -DUSE_BAR=1" + , "Libs: -L/usr/lib -lbar -lpthread -lm" + ] + } + } +, "bar": + { "type": ["@", "rules", "CC/prebuilt", "library"] + , "name": ["bar"] + , "hdrs": ["bar.hpp"] + , "lib": [["shared", "bar"]] + , "pkg-config": ["bar.pc"] + , "stage": ["bar"] + , "deps": ["foo"] + } +, "bar_s": + { "type": ["@", "rules", "CC/prebuilt", "library"] + , "name": ["bar"] + , "hdrs": ["bar.hpp"] + , "lib": [["shared", "bar_s"]] + , "pkg-config": ["bar.pc"] + , "stage": ["bar"] + , "deps": ["foo"] + } +, "main_uses_foo": + { "type": ["@", "rules", "CC", "binary"] + , "name": ["main_uses_foo"] + , "srcs": [["shared", "main_uses_foo.cpp"]] + , "private-deps": ["foo"] + } +, "test_uses_foo": + { "type": ["@", "rules", "CC/test", "test"] + , "name": ["test_uses_foo"] + , "srcs": [["shared", "test_uses_foo.cpp"]] + , "private-deps": ["foo"] + } +, "main_uses_bar": + { "type": ["@", "rules", "CC", "binary"] + , "name": ["main_uses_bar"] + , "srcs": [["shared", "main_uses_bar.cpp"]] + , "private-deps": ["bar"] + } +, "test_uses_bar": + { "type": ["@", "rules", "CC/test", "test"] + , "name": ["test_uses_bar"] + , "srcs": [["shared", "test_uses_bar.cpp"]] + , "private-deps": ["bar"] + } +, "test_uses_bar_s": + { "type": ["@", "rules", "CC/test", "test"] + , "name": ["test_uses_bar"] + , "srcs": [["shared", "test_uses_bar.cpp"]] + , "private-deps": ["bar_s"] + } +, "test_uses_main": + { "type": ["@", "rules", "shell/test", "script"] + , "name": ["test_uses_main"] + , "test": [["shared", "test_uses_main.sh"]] + , "deps": ["main_uses_bar"] + } +, "install_foo": + {"type": ["@", "rules", "CC", "install-with-deps"], "targets": ["foo"]} +, "install_bar": + {"type": ["@", "rules", "CC", "install-with-deps"], "targets": ["bar"]} +, "install_main": + { "type": ["@", "rules", "CC", "install-with-deps"] + , "targets": ["main_uses_bar"] + } +, "foobar.pc": + { "type": "file_gen" + , "name": "foobar.pc" + , "data": + { "type": "join" + , "separator": "\n" + , "$1": + [ "Name: foobar" + , "Version: unknown" + , "Description: test compound prebuilt foobar" + , "URL: unknown" + , "Requires: bar, foo >= 1.2.3" + ] + } + } +, "foobar": + { "type": ["@", "rules", "CC/prebuilt", "library"] + , "name": ["foobar"] + , "hdrs": ["bar.hpp"] + , "lib": [["shared", "bar"], ["shared", "foo"]] + , "pkg-config": ["foobar.pc", "foo.pc", "bar.pc"] + , "stage": ["bar"] + } +, "foobar_s": + { "type": ["@", "rules", "CC/prebuilt", "library"] + , "name": ["foobar"] + , "hdrs": ["bar.hpp"] + , "lib": [["shared", "bar_s"], ["shared", "foo_s"]] + , "pkg-config": ["foobar.pc", "foo.pc", "bar.pc"] + , "stage": ["bar"] + } +, "test_uses_foobar": + { "type": ["@", "rules", "CC/test", "test"] + , "name": ["test_uses_bar"] + , "srcs": [["shared", "test_uses_bar.cpp"]] + , "private-deps": ["foobar"] + } +, "test_uses_foobar_s": + { "type": ["@", "rules", "CC/test", "test"] + , "name": ["test_uses_bar"] + , "srcs": [["shared", "test_uses_bar.cpp"]] + , "private-deps": ["foobar_s"] + } +, "install_foobar": + {"type": ["@", "rules", "CC", "install-with-deps"], "targets": ["foobar"]} +} diff --git a/tests/test_cases/deps/prebuilt/bar.hpp b/tests/test_cases/deps/prebuilt/bar.hpp new file mode 100644 index 0000000..243dba6 --- /dev/null +++ b/tests/test_cases/deps/prebuilt/bar.hpp @@ -0,0 +1,8 @@ +#ifndef BAR_HPP +#define BAR_HPP + +#ifdef USE_BAR +int bar(); +#endif + +#endif diff --git a/tests/test_cases/deps/prebuilt/foo.hpp b/tests/test_cases/deps/prebuilt/foo.hpp new file mode 100644 index 0000000..4f040d4 --- /dev/null +++ b/tests/test_cases/deps/prebuilt/foo.hpp @@ -0,0 +1,8 @@ +#ifndef FOO_HPP +#define FOO_HPP + +#ifdef USE_FOO +int foo(); +#endif + +#endif diff --git a/tests/test_cases/deps/private/TARGETS b/tests/test_cases/deps/private/TARGETS new file mode 100644 index 0000000..dd72948 --- /dev/null +++ b/tests/test_cases/deps/private/TARGETS @@ -0,0 +1,36 @@ +{ "foo": + { "type": ["@", "rules", "CC", "library"] + , "name": ["foo"] + , "hdrs": ["foo.hpp"] + , "srcs": ["foo.cpp"] + , "stage": ["foo"] + } +, "bar": + { "type": ["@", "rules", "CC", "library"] + , "name": ["bar"] + , "hdrs": ["bar.hpp"] + , "srcs": ["bar.cpp"] + , "private-deps": ["foo"] + , "stage": ["bar"] + } +, "main_includes_foo": + { "type": ["@", "rules", "CC", "binary"] + , "name": ["main"] + , "srcs": ["main_includes_foo.cpp"] + , "private-deps": ["bar"] + } +, "main_links_foo": + { "type": ["@", "rules", "CC", "binary"] + , "name": ["main"] + , "srcs": ["main_links_foo.cpp"] + , "private-deps": ["bar"] + } +, "main_links_bar_foo": + { "type": ["@", "rules", "CC", "binary"] + , "name": ["main"] + , "srcs": ["main_links_bar_foo.cpp"] + , "private-deps": ["bar"] + } +, "install_bar": + {"type": ["@", "rules", "CC", "install-with-deps"], "targets": ["bar"]} +} diff --git a/tests/test_cases/deps/private/bar.cpp b/tests/test_cases/deps/private/bar.cpp new file mode 100644 index 0000000..dfce0e8 --- /dev/null +++ b/tests/test_cases/deps/private/bar.cpp @@ -0,0 +1,8 @@ +#include "foo/foo.hpp" +#include "bar.hpp" +#include <iostream> + +int bar() { + std::cout << "bar\n"; + return foo(); +} diff --git a/tests/test_cases/deps/private/bar.hpp b/tests/test_cases/deps/private/bar.hpp new file mode 100644 index 0000000..94d4f16 --- /dev/null +++ b/tests/test_cases/deps/private/bar.hpp @@ -0,0 +1,6 @@ +#ifndef BAR_HPP +#define BAR_HPP + +int bar(); + +#endif diff --git a/tests/test_cases/deps/private/foo.cpp b/tests/test_cases/deps/private/foo.cpp new file mode 100644 index 0000000..f985022 --- /dev/null +++ b/tests/test_cases/deps/private/foo.cpp @@ -0,0 +1,7 @@ +#include "foo.hpp" +#include <iostream> + +int foo() { + std::cout << "foo\n"; + return 0; +} diff --git a/tests/test_cases/deps/private/foo.hpp b/tests/test_cases/deps/private/foo.hpp new file mode 100644 index 0000000..1a28686 --- /dev/null +++ b/tests/test_cases/deps/private/foo.hpp @@ -0,0 +1,6 @@ +#ifndef FOO_HPP +#define FOO_HPP + +int foo(); + +#endif diff --git a/tests/test_cases/deps/private/main_includes_foo.cpp b/tests/test_cases/deps/private/main_includes_foo.cpp new file mode 100644 index 0000000..16701c7 --- /dev/null +++ b/tests/test_cases/deps/private/main_includes_foo.cpp @@ -0,0 +1,9 @@ +// test that foo.hpp not available + +#include "foo/foo.hpp" +#include <iostream> + +int main() { + std::cout << "main\n"; + return 0; +} diff --git a/tests/test_cases/deps/private/main_links_bar_foo.cpp b/tests/test_cases/deps/private/main_links_bar_foo.cpp new file mode 100644 index 0000000..e936074 --- /dev/null +++ b/tests/test_cases/deps/private/main_links_bar_foo.cpp @@ -0,0 +1,9 @@ +// test that foo is linked after bar + +#include "bar/bar.hpp" +#include <iostream> + +int main() { + std::cout << "main\n"; + return bar(); +} diff --git a/tests/test_cases/deps/private/main_links_foo.cpp b/tests/test_cases/deps/private/main_links_foo.cpp new file mode 100644 index 0000000..1e1e07a --- /dev/null +++ b/tests/test_cases/deps/private/main_links_foo.cpp @@ -0,0 +1,10 @@ +// test that foo is linked + +#include <iostream> + +int foo(); // forward declare + +int main() { + std::cout << "main\n"; + return foo(); +} diff --git a/tests/test_cases/deps/public/TARGETS b/tests/test_cases/deps/public/TARGETS new file mode 100644 index 0000000..bc1807a --- /dev/null +++ b/tests/test_cases/deps/public/TARGETS @@ -0,0 +1,36 @@ +{ "foo": + { "type": ["@", "rules", "CC", "library"] + , "name": ["foo"] + , "hdrs": ["foo.hpp"] + , "srcs": ["foo.cpp"] + , "stage": ["foo"] + } +, "bar": + { "type": ["@", "rules", "CC", "library"] + , "name": ["bar"] + , "hdrs": ["bar.hpp"] + , "srcs": ["bar.cpp"] + , "deps": ["foo"] + , "stage": ["bar"] + } +, "main_includes_foo": + { "type": ["@", "rules", "CC", "binary"] + , "name": ["main"] + , "srcs": ["main_includes_foo.cpp"] + , "private-deps": ["bar"] + } +, "main_links_foo": + { "type": ["@", "rules", "CC", "binary"] + , "name": ["main"] + , "srcs": ["main_links_foo.cpp"] + , "private-deps": ["bar"] + } +, "main_links_bar_foo": + { "type": ["@", "rules", "CC", "binary"] + , "name": ["main"] + , "srcs": ["main_links_bar_foo.cpp"] + , "private-deps": ["bar"] + } +, "install_bar": + {"type": ["@", "rules", "CC", "install-with-deps"], "targets": ["bar"]} +} diff --git a/tests/test_cases/deps/public/bar.cpp b/tests/test_cases/deps/public/bar.cpp new file mode 100644 index 0000000..f2a779a --- /dev/null +++ b/tests/test_cases/deps/public/bar.cpp @@ -0,0 +1,7 @@ +#include "bar.hpp" +#include <iostream> + +int bar(Foo *foo) { + std::cout << "bar\n"; + return (foo == nullptr) ? -1 : foo->foo(); +} diff --git a/tests/test_cases/deps/public/bar.hpp b/tests/test_cases/deps/public/bar.hpp new file mode 100644 index 0000000..ec9c165 --- /dev/null +++ b/tests/test_cases/deps/public/bar.hpp @@ -0,0 +1,8 @@ +#ifndef BAR_HPP +#define BAR_HPP + +#include "foo/foo.hpp" + +int bar(Foo *foo); + +#endif diff --git a/tests/test_cases/deps/public/foo.cpp b/tests/test_cases/deps/public/foo.cpp new file mode 100644 index 0000000..6899c7a --- /dev/null +++ b/tests/test_cases/deps/public/foo.cpp @@ -0,0 +1,7 @@ +#include "foo.hpp" +#include <iostream> + +int Foo::foo() { + std::cout << "foo\n"; + return 0; +} diff --git a/tests/test_cases/deps/public/foo.hpp b/tests/test_cases/deps/public/foo.hpp new file mode 100644 index 0000000..025f3ef --- /dev/null +++ b/tests/test_cases/deps/public/foo.hpp @@ -0,0 +1,8 @@ +#ifndef FOO_HPP +#define FOO_HPP + +struct Foo { + int foo(); +}; + +#endif diff --git a/tests/test_cases/deps/public/main_includes_foo.cpp b/tests/test_cases/deps/public/main_includes_foo.cpp new file mode 100644 index 0000000..e8a85b6 --- /dev/null +++ b/tests/test_cases/deps/public/main_includes_foo.cpp @@ -0,0 +1,9 @@ +// test that foo.hpp is available (despite unused here) + +#include "foo/foo.hpp" +#include <iostream> + +int main() { + std::cout << "main\n"; + return 0; +} diff --git a/tests/test_cases/deps/public/main_links_bar_foo.cpp b/tests/test_cases/deps/public/main_links_bar_foo.cpp new file mode 100644 index 0000000..02c2966 --- /dev/null +++ b/tests/test_cases/deps/public/main_links_bar_foo.cpp @@ -0,0 +1,10 @@ +// test that foo is linked after bar + +#include "bar/bar.hpp" +#include <iostream> + +int main() { + std::cout << "main\n"; + Foo foo{}; + return bar(&foo); +} diff --git a/tests/test_cases/deps/public/main_links_foo.cpp b/tests/test_cases/deps/public/main_links_foo.cpp new file mode 100644 index 0000000..f9cc308 --- /dev/null +++ b/tests/test_cases/deps/public/main_links_foo.cpp @@ -0,0 +1,10 @@ +// test that foo is linked + +#include "foo/foo.hpp" +#include <iostream> + +int main() { + std::cout << "main\n"; + Foo{}.foo(); + return 0; +} diff --git a/tests/test_cases/deps/shared/TARGETS b/tests/test_cases/deps/shared/TARGETS new file mode 100644 index 0000000..9db7fb8 --- /dev/null +++ b/tests/test_cases/deps/shared/TARGETS @@ -0,0 +1,104 @@ +{ "foo": + { "type": ["@", "rules", "CC", "library"] + , "shared": ["yes"] + , "name": ["foo"] + , "soversion": ["1", "2", "3"] + , "hdrs": ["foo.hpp"] + , "srcs": ["foo.cpp"] + , "stage": ["foo"] + } +, "foo_s": + { "type": ["@", "rules", "CC", "library"] + , "name": ["foo"] + , "hdrs": ["foo.hpp"] + , "srcs": ["foo.cpp"] + , "stage": ["foo"] + } +, "bar": + { "type": ["@", "rules", "CC", "library"] + , "shared": ["yes"] + , "name": ["bar"] + , "hdrs": ["bar.hpp"] + , "srcs": ["bar.cpp"] + , "stage": ["bar"] + , "private-deps": ["foo"] + } +, "bar_s": + { "type": ["@", "rules", "CC", "library"] + , "name": ["bar"] + , "hdrs": ["bar.hpp"] + , "srcs": ["bar.cpp"] + , "stage": ["bar"] + , "private-deps": ["foo"] + } +, "baz": + { "type": ["@", "rules", "CC", "library"] + , "name": ["baz"] + , "shared": ["yes"] + , "hdrs": ["baz.hpp"] + , "srcs": ["baz.cpp"] + , "stage": ["baz"] + , "private-deps": ["foo_s"] + } +, "main_uses_foo": + { "type": ["@", "rules", "CC", "binary"] + , "name": ["main_uses_foo"] + , "srcs": ["main_uses_foo.cpp"] + , "private-deps": ["foo"] + } +, "test_uses_foo": + { "type": ["@", "rules", "CC/test", "test"] + , "name": ["test_uses_foo"] + , "srcs": ["test_uses_foo.cpp"] + , "private-deps": ["foo"] + } +, "main_uses_bar": + { "type": ["@", "rules", "CC", "binary"] + , "name": ["main_uses_bar"] + , "srcs": ["main_uses_bar.cpp"] + , "private-deps": ["bar"] + } +, "test_uses_bar": + { "type": ["@", "rules", "CC/test", "test"] + , "name": ["test_uses_bar"] + , "srcs": ["test_uses_bar.cpp"] + , "private-deps": ["bar"] + } +, "test_uses_bar_s": + { "type": ["@", "rules", "CC/test", "test"] + , "name": ["test_uses_bar_s"] + , "srcs": ["test_uses_bar.cpp"] + , "private-deps": ["bar_s"] + } +, "test_uses_baz": + { "type": ["@", "rules", "CC/test", "test"] + , "name": ["test_uses_baz"] + , "srcs": ["test_uses_baz.cpp"] + , "private-deps": ["baz"] + } +, "test_uses_main": + { "type": ["@", "rules", "shell/test", "script"] + , "name": ["test_uses_main"] + , "test": ["test_uses_main.sh"] + , "deps": ["main_uses_bar"] + } +, "test_diamond": + { "type": ["@", "rules", "CC/test", "test"] + , "name": ["test_diamond"] + , "srcs": ["test_diamond.cpp"] + , "private-deps": ["foo_s", "baz"] + } +, "install_foo": + { "type": ["@", "rules", "CC", "install-with-deps"] + , "targets": ["foo"] + , "flat-libs": ["yes"] + } +, "install_bar_s": + {"type": ["@", "rules", "CC", "install-with-deps"], "targets": ["bar_s"]} +, "install_baz": + {"type": ["@", "rules", "CC", "install-with-deps"], "targets": ["baz"]} +, "install_main": + { "type": ["@", "rules", "CC", "install-with-deps"] + , "targets": ["main_uses_bar"] + } +} diff --git a/tests/test_cases/deps/shared/bar.cpp b/tests/test_cases/deps/shared/bar.cpp new file mode 100644 index 0000000..dfce0e8 --- /dev/null +++ b/tests/test_cases/deps/shared/bar.cpp @@ -0,0 +1,8 @@ +#include "foo/foo.hpp" +#include "bar.hpp" +#include <iostream> + +int bar() { + std::cout << "bar\n"; + return foo(); +} diff --git a/tests/test_cases/deps/shared/bar.hpp b/tests/test_cases/deps/shared/bar.hpp new file mode 100644 index 0000000..94d4f16 --- /dev/null +++ b/tests/test_cases/deps/shared/bar.hpp @@ -0,0 +1,6 @@ +#ifndef BAR_HPP +#define BAR_HPP + +int bar(); + +#endif diff --git a/tests/test_cases/deps/shared/baz.cpp b/tests/test_cases/deps/shared/baz.cpp new file mode 100644 index 0000000..fae4845 --- /dev/null +++ b/tests/test_cases/deps/shared/baz.cpp @@ -0,0 +1,8 @@ +#include "foo/foo.hpp" +#include "baz.hpp" +#include <iostream> + +int baz() { + std::cout << "baz\n"; + return foo(); +} diff --git a/tests/test_cases/deps/shared/baz.hpp b/tests/test_cases/deps/shared/baz.hpp new file mode 100644 index 0000000..643cf65 --- /dev/null +++ b/tests/test_cases/deps/shared/baz.hpp @@ -0,0 +1,6 @@ +#ifndef BAZ_HPP +#define BAZ_HPP + +int baz(); + +#endif diff --git a/tests/test_cases/deps/shared/foo.cpp b/tests/test_cases/deps/shared/foo.cpp new file mode 100644 index 0000000..f985022 --- /dev/null +++ b/tests/test_cases/deps/shared/foo.cpp @@ -0,0 +1,7 @@ +#include "foo.hpp" +#include <iostream> + +int foo() { + std::cout << "foo\n"; + return 0; +} diff --git a/tests/test_cases/deps/shared/foo.hpp b/tests/test_cases/deps/shared/foo.hpp new file mode 100644 index 0000000..1a28686 --- /dev/null +++ b/tests/test_cases/deps/shared/foo.hpp @@ -0,0 +1,6 @@ +#ifndef FOO_HPP +#define FOO_HPP + +int foo(); + +#endif diff --git a/tests/test_cases/deps/shared/main_uses_bar.cpp b/tests/test_cases/deps/shared/main_uses_bar.cpp new file mode 100644 index 0000000..9cfc855 --- /dev/null +++ b/tests/test_cases/deps/shared/main_uses_bar.cpp @@ -0,0 +1,8 @@ +#include "bar/bar.hpp" +#include <iostream> + +int main() { + std::cout << "main\n"; + bar(); + return 0; +} diff --git a/tests/test_cases/deps/shared/main_uses_foo.cpp b/tests/test_cases/deps/shared/main_uses_foo.cpp new file mode 100644 index 0000000..0fb3bb6 --- /dev/null +++ b/tests/test_cases/deps/shared/main_uses_foo.cpp @@ -0,0 +1,8 @@ +#include "foo/foo.hpp" +#include <iostream> + +int main() { + std::cout << "main\n"; + foo(); + return 0; +} diff --git a/tests/test_cases/deps/shared/test_diamond.cpp b/tests/test_cases/deps/shared/test_diamond.cpp new file mode 100644 index 0000000..9298230 --- /dev/null +++ b/tests/test_cases/deps/shared/test_diamond.cpp @@ -0,0 +1,4 @@ +#include "baz/baz.hpp" +#include "foo/foo.hpp" + +int main() { return foo() + baz(); } diff --git a/tests/test_cases/deps/shared/test_uses_bar.cpp b/tests/test_cases/deps/shared/test_uses_bar.cpp new file mode 100644 index 0000000..c2076ec --- /dev/null +++ b/tests/test_cases/deps/shared/test_uses_bar.cpp @@ -0,0 +1,3 @@ +#include "bar/bar.hpp" + +int main() { return bar(); } diff --git a/tests/test_cases/deps/shared/test_uses_baz.cpp b/tests/test_cases/deps/shared/test_uses_baz.cpp new file mode 100644 index 0000000..02d67f9 --- /dev/null +++ b/tests/test_cases/deps/shared/test_uses_baz.cpp @@ -0,0 +1,3 @@ +#include "baz/baz.hpp" + +int main() { return baz(); } diff --git a/tests/test_cases/deps/shared/test_uses_foo.cpp b/tests/test_cases/deps/shared/test_uses_foo.cpp new file mode 100644 index 0000000..88feb93 --- /dev/null +++ b/tests/test_cases/deps/shared/test_uses_foo.cpp @@ -0,0 +1,3 @@ +#include "foo/foo.hpp" + +int main() { return foo(); } diff --git a/tests/test_cases/deps/shared/test_uses_main.sh b/tests/test_cases/deps/shared/test_uses_main.sh new file mode 100644 index 0000000..ab8672f --- /dev/null +++ b/tests/test_cases/deps/shared/test_uses_main.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +set -e + +./main_uses_bar | grep main +./main_uses_bar | grep bar +./main_uses_bar | grep foo diff --git a/tests/test_rules/EXPRESSIONS b/tests/test_rules/EXPRESSIONS new file mode 100644 index 0000000..f1ca6f4 --- /dev/null +++ b/tests/test_rules/EXPRESSIONS @@ -0,0 +1,46 @@ +{ "stage_singleton_field": + { "vars": ["fieldname", "transition", "location"] + , "expression": + { "type": "assert_non_empty" + , "msg": + ["No artifact specified in field", {"type": "var", "name": "fieldname"}] + , "$1": + { "type": "disjoint_map_union" + , "msg": + [ "Expecting (essentially) a single artifact in field" + , {"type": "var", "name": "fieldname"} + ] + , "$1": + { "type": "foreach" + , "var": "src" + , "range": + {"type": "FIELD", "name": {"type": "var", "name": "fieldname"}} + , "body": + { "type": "disjoint_map_union" + , "$1": + { "type": "foreach" + , "var": "artifact" + , "range": + { "type": "values" + , "$1": + { "type": "DEP_ARTIFACTS" + , "dep": {"type": "var", "name": "src"} + , "transition": + { "type": "var" + , "name": "transition" + , "default": {"type": "empty_map"} + } + } + } + , "body": + { "type": "singleton_map" + , "key": {"type": "var", "name": "location"} + , "value": {"type": "var", "name": "artifact"} + } + } + } + } + } + } + } +} diff --git a/tests/test_rules/README.md b/tests/test_rules/README.md new file mode 100644 index 0000000..5a1baed --- /dev/null +++ b/tests/test_rules/README.md @@ -0,0 +1,28 @@ +# Test Rules + +This is a test rule that supports building and installing multiple targets with +a given set of rules. For each target, it can be specified whether building it +should fail or succeed. After processing all targets, additional assertions +(list of shell commands) can be run. + +## Setup + +The test rules expect to find the following three bindings: + - `[["@", "test-rules", "", "tree"]]`, which contains a single tree artifact + with the rules to test. + - `[["@", "test-just", "", ""]]`, which contains a single executable artifact + that is the JustBuild binary to use for the tests. + - `[["@", "test-libs", "", "tree"]]`, which contains a single tree artifact + that holds the file trees of external libraries. + +## Rule `["test_rules", "test_case"]` + +Define a test case for rule tests. + +| Field | Description | +| ----- | ----------- | +| `"name"` | Name of the test (multiple entries are joined). | +| `"libs"` | Paths to external libraries' trees provided by the `"test-libs"` repository. From within a test cases, the library's tree can be accessed via `["@", "<libname>", "", "tree"]`. | +| `"targets"` | Target names to build and install. Each target name is prefixed by `"+"` or `"-"`, indicating if the build should fail or not. Targets that build successfully will be installed to a directory named identical to the target name (without the prefix). | +| `"asserts"` | List of commands to execute after all targets were processed. To access artifacts from installed targets, use the corresponding target name as prefix dir (e.g., target `"+foo"` installs to `"./foo/"`). | +| `"data"` | The directory that contains the project with the targets to test. | diff --git a/tests/test_rules/RULES b/tests/test_rules/RULES new file mode 100644 index 0000000..f53efba --- /dev/null +++ b/tests/test_rules/RULES @@ -0,0 +1,204 @@ +{ "test_case": + { "doc": ["Define a test case for rule tests."] + , "string_fields": ["name", "libs", "targets", "asserts"] + , "target_fields": ["data"] + , "field_doc": + { "name": ["Name of the test (multiple entries are joined)."] + , "libs": + [ "Paths to external libraries' trees provided by the \"test-libs\"" + , "repository. From within a test cases, the library's tree can be" + , "accessed via [\"@\", \"<libpath>\", \"\", \"tree\"]." + ] + , "targets": + [ "Target names to build and install. Each target name is prefixed by" + , "\"+\" or \"-\", indicating if the build should fail or not." + , "Targets that build successfully will be installed to a directory" + , "named identical to the target name (without the prefix)." + ] + , "asserts": + [ "List of commands to execute after all targets were processed. To" + , "access artifacts from installed targets, use the corresponding target" + , "name as prefix dir (e.g., target \"+foo\" installs to \"./foo/\")." + ] + , "data": + ["The directory that contains the project with the targets to test."] + } + , "tainted": ["test"] + , "implicit": + { "runner": ["test_runner.py"] + , "rules": [["@", "test-rules", "", "tree"]] + , "just": [["@", "test-just", "", ""]] + , "libs_tree": [["@", "test-libs", "", "tree"]] + } + , "imports": {"stage_artifact": "stage_singleton_field"} + , "expression": + { "type": "let*" + , "bindings": + [ ["name", {"type": "join", "$1": {"type": "FIELD", "name": "name"}}] + , ["fieldname", "just"] + , ["location", "bin/just"] + , ["just", {"type": "CALL_EXPRESSION", "name": "stage_artifact"}] + , ["fieldname", "rules"] + , ["location", "rules"] + , ["rules", {"type": "CALL_EXPRESSION", "name": "stage_artifact"}] + , [ "imports" + , { "type": "singleton_map" + , "key": "imports/TARGETS" + , "value": + { "type": "BLOB" + , "data": "{\"tree\":{\"type\":\"install\",\"dirs\":[[[\"TREE\",null,\".\"],\".\"]]}}" + } + } + ] + , ["fieldname", "libs_tree"] + , ["location", "libs"] + , ["libs", {"type": "CALL_EXPRESSION", "name": "stage_artifact"}] + , ["fieldname", "data"] + , ["location", "work"] + , ["work", {"type": "CALL_EXPRESSION", "name": "stage_artifact"}] + , ["fieldname", "runner"] + , ["location", "runner"] + , ["runner", {"type": "CALL_EXPRESSION", "name": "stage_artifact"}] + , ["targets", {"type": "FIELD", "name": "targets"}] + , ["asserts", {"type": "FIELD", "name": "asserts"}] + , [ "work_bindings" + , { "type": "map_union" + , "$1": + { "type": "++" + , "$1": + [ [{"type": "singleton_map", "key": "rules", "value": "rules"}] + , { "type": "foreach" + , "range": {"type": "FIELD", "name": "libs"} + , "var": "libpath" + , "body": + { "type": "singleton_map" + , "key": {"type": "var", "name": "libpath"} + , "value": {"type": "var", "name": "libpath"} + } + } + ] + } + } + ] + , [ "work_deps" + , { "type": "map_union" + , "$1": + { "type": "++" + , "$1": + [ [ { "type": "let*" + , "bindings": + [ ["workspace_root", ["file", "rules"]] + , ["rules", {"type": "env", "vars": ["workspace_root"]}] + ] + , "body": {"type": "env", "vars": ["rules"]} + } + ] + , { "type": "foreach" + , "range": {"type": "FIELD", "name": "libs"} + , "var": "libpath" + , "body": + { "type": "let*" + , "bindings": + [ [ "workspace_root" + , [ "file" + , { "type": "join" + , "$1": ["libs/", {"type": "var", "name": "libpath"}] + } + ] + ] + , ["target_root", ["file", "imports"]] + ] + , "body": + { "type": "singleton_map" + , "key": {"type": "var", "name": "libpath"} + , "value": + { "type": "env" + , "vars": ["workspace_root", "target_root"] + } + } + } + } + ] + } + } + ] + , [ "repos" + , { "type": "singleton_map" + , "key": "repos.json" + , "value": + { "type": "BLOB" + , "data": + { "type": "json_encode" + , "$1": + { "type": "let*" + , "bindings": + [ ["workspace_root", ["file", "work"]] + , ["bindings", {"type": "var", "name": "work_bindings"}] + , [ "work" + , {"type": "env", "vars": ["workspace_root", "bindings"]} + ] + , [ "repositories" + , { "type": "map_union" + , "$1": + [ {"type": "env", "vars": ["work"]} + , {"type": "var", "name": "work_deps"} + ] + } + ] + , ["main", "work"] + ] + , "body": {"type": "env", "vars": ["main", "repositories"]} + } + } + } + } + ] + , [ "config" + , { "type": "singleton_map" + , "key": "config.json" + , "value": + { "type": "BLOB" + , "data": + { "type": "json_encode" + , "$1": {"type": "env", "vars": ["targets", "asserts"]} + } + } + } + ] + , [ "results" + , { "type": "ACTION" + , "inputs": + { "type": "map_union" + , "$1": + [ {"type": "var", "name": "runner"} + , {"type": "var", "name": "rules"} + , {"type": "var", "name": "just"} + , {"type": "var", "name": "imports"} + , {"type": "var", "name": "libs"} + , {"type": "var", "name": "repos"} + , {"type": "var", "name": "work"} + , {"type": "var", "name": "config"} + ] + } + , "outs": ["stdout", "stderr", "result", "time-start", "time-stop"] + , "cmd": ["./runner"] + , "may_fail": ["test"] + , "fail_message": + { "type": "join" + , "$1": ["Rule test ", {"type": "var", "name": "name"}, " failed"] + } + } + ] + ] + , "body": + { "type": "RESULT" + , "artifacts": {"type": "var", "name": "results"} + , "runfiles": + { "type": "singleton_map" + , "key": {"type": "var", "name": "name"} + , "value": {"type": "TREE", "$1": {"type": "var", "name": "results"}} + } + } + } + } +} diff --git a/tests/test_rules/TARGETS b/tests/test_rules/TARGETS new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/tests/test_rules/TARGETS @@ -0,0 +1 @@ +{} diff --git a/tests/test_rules/test_runner.py b/tests/test_rules/test_runner.py new file mode 100755 index 0000000..976f041 --- /dev/null +++ b/tests/test_rules/test_runner.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python3 +# Copyright 2022 Huawei Cloud Computing Technology Co., Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import json +import os +import subprocess +import time + +time_start = time.time() +time_stop = 0 +result = "UNKNOWN" +stderr = "" +stdout = "" + + +def dump_results(): + with open("result", "w") as f: + f.write("%s\n" % (result, )) + with open("time-start", "w") as f: + f.write("%d\n" % (time_start, )) + with open("time-stop", "w") as f: + f.write("%d\n" % (time_stop, )) + with open("stdout", "w") as f: + f.write("%s\n" % (stdout, )) + with open("stderr", "w") as f: + f.write("%s\n" % (stderr, )) + + +dump_results() + +with open('config.json') as f: + config = json.load(f) + +os.makedirs("./outs") + +# install targets +failed_targets = 0 +stdout += "Test targets:\n" +for t in config.get('targets', []): + target = t[1:] + should_fail = t[0] == "-" + ret = subprocess.run([ + "./bin/just", "install", "--local-build-root", "./build_root", "-C", + "repos.json", "-o", "/".join(["./outs", target]), target + ], + capture_output=True) + success = ret.returncode != 0 if should_fail else ret.returncode == 0 + failed_targets += 0 if success else 1 + stdout += f" [{'PASS' if success else 'FAIL'}] {target}\n" + stderr += "".join([ + f"stdout/stderr of test target '{target}':\n", + ret.stdout.decode("utf-8"), + ret.stderr.decode("utf-8"), "\n" + ]) +stdout += f" {failed_targets} targets failed\n" + +# run asserts +failed_asserts = 0 +stdout += "Test asserts:\n" +for cmd in config.get('asserts', []): + ret = subprocess.run(cmd, cwd="./outs", shell=True, capture_output=True) + success = ret.returncode == 0 + failed_asserts += 0 if success else 1 + stdout += f" [{'PASS' if success else 'FAIL'}] {cmd}\n" + stderr += "".join([ + f"stdout/stderr of test assert '{cmd}':\n", + ret.stdout.decode("utf-8"), + ret.stderr.decode("utf-8"), "\n" + ]) +stdout += f" {failed_asserts} asserts failed\n" + +retval = min(failed_targets + failed_asserts, 125) +result = "PASS" if retval == 0 else "FAIL" + +time_stop = time.time() +dump_results() +exit(retval) |