├── .github └── workflows │ └── upload-source-archives.yml ├── CONTRIBUTING.md ├── LICENSE ├── LICENSE-APACHE ├── LICENSE-MIT ├── NOTICE.txt ├── README.md ├── SECURITY.md ├── docs └── index.html └── rules ├── BUILD.bazel ├── cfg5 ├── BUILD ├── README.md ├── rules.bzl └── toolchains.bzl ├── common ├── BUILD.bazel ├── copy_file.bzl └── create_davinci_tool_workspace.bzl ├── davinci_developer ├── BUILD.bazel ├── README.md └── toolchains.bzl ├── defs.bzl ├── dvteam ├── BUILD.bazel ├── README.md └── rules.bzl ├── gradle ├── BUILD.bazel ├── README.md ├── rules.bzl └── toolchains.bzl ├── ocs ├── BUILD.bazel ├── README.md └── rules.bzl └── toolchains.md /.github/workflows/upload-source-archives.yml: -------------------------------------------------------------------------------- 1 | name: Upload Source Archives 2 | 3 | on: 4 | release: 5 | types: [published] 6 | 7 | jobs: 8 | upload-archives: 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - name: Checkout repo 13 | uses: actions/checkout@v4 14 | 15 | - name: Create ZIP archive 16 | run: | 17 | git archive --format=zip --output=source.zip HEAD 18 | 19 | - name: Create TAR.GZ archive 20 | run: | 21 | git archive --format=tar.gz --output=source.tar.gz HEAD 22 | 23 | - name: Upload ZIP and TAR.GZ to release 24 | uses: softprops/action-gh-release@v1 25 | with: 26 | files: | 27 | source.zip 28 | source.tar.gz 29 | 30 | - name: Add Pages link to release description 31 | run: | 32 | TAG_NAME=${{ github.ref_name }} 33 | REPO=${{ github.repository }} 34 | PAGES_URL="https://vectorgrp.github.io/bazel-rules/?tag=$TAG_NAME" 35 | 36 | echo "Updating release description for tag $TAG_NAME" 37 | 38 | # Get the current release body 39 | CURRENT_BODY=$(gh api "repos/$REPO/releases/tags/$TAG_NAME" --jq .body) 40 | 41 | # Append the Pages link if not already present 42 | if [[ "$CURRENT_BODY" != *"$PAGES_URL"* ]]; then 43 | UPDATED_BODY="$CURRENT_BODY"$'\n\n'"GitHub Pages link for download count: $PAGES_URL" 44 | 45 | RELEASE_ID=$(gh api "repos/$REPO/releases/tags/$TAG_NAME" --jq .id) 46 | 47 | gh api -X PATCH "repos/$REPO/releases/$RELEASE_ID" \ 48 | -f body="$UPDATED_BODY" 49 | else 50 | echo "Pages link already present, skipping update." 51 | fi 52 | env: 53 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 54 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Vector Bazel Rules 2 | 3 | Welcome and thank you for your interest in contributing to the Vector Bazel Rules open source project. 4 | 5 | We are sorry, but at the moment, we do not accept external contributions until we have established a contribution process. We're working behind the scenes to get this ready in the future. Until then, we would kindly ask you to not open pull requests. 6 | 7 | We will update this document when we are ready for your submissions. Thank you and stay tuned! -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This repository contains code licensed under two different open-source licenses: 2 | 3 | 1. **Apache License 2.0** 4 | - The file "copy_file.bzl" is licensed under the Apache License, Version 2.0. 5 | - See the full license in `LICENSE-APACHE`. 6 | 7 | 8 | 2. **MIT License** 9 | - The rest of the repository is licensed under the MIT License. 10 | - See the full license in `LICENSE-MIT`. 11 | 12 | By contributing to this repository, you agree that your contributions will be 13 | licensed under the respective licenses of the files being modified. 14 | 15 | Permission is hereby granted, free of charge, to any person obtaining 16 | a copy of this software and associated documentation files (the 17 | "Software"), to deal in the Software without restriction, including 18 | without limitation the rights to use, copy, modify, merge, publish, 19 | distribute, sublicense, and/or sell copies of the Software, and to 20 | permit persons to whom the Software is furnished to do so, subject to 21 | the following conditions: 22 | 23 | The above copyright notice and this permission notice shall be 24 | included in all copies or substantial portions of the Software. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 27 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 28 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 29 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 30 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 31 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 32 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 Vector Group 4 | 5 | Permission is hereby granted, free of charge, to any 6 | person obtaining a copy of this software and associated 7 | documentation files (the "Software"), to deal in the 8 | Software without restriction, including without 9 | limitation the rights to use, copy, modify, merge, 10 | publish, distribute, sublicense, and/or sell copies of 11 | the Software, and to permit persons to whom the Software 12 | is furnished to do so, subject to the following 13 | conditions: 14 | 15 | The above copyright notice and this permission notice 16 | shall be included in all copies or substantial portions 17 | of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 20 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 21 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 22 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 23 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 24 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 26 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | This repository contains files licensed under different licenses. 2 | 3 | - The file "copy_file.bzl" is licensed under the Apache License, Version 2.0. 4 | See the full license at http://www.apache.org/licenses/LICENSE-2.0. 5 | - All other files in this repository are licensed under the MIT License. 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vector Bazel Rules 2 | 3 | This repository contains the Vector Bazel Rules. 4 | 5 | In general, it contains the necessary toolchains and custom rules to start running Vector tools such as DaVinci Team in a Bazel environment. 6 | 7 | ## Who should use these rules? 8 | 9 | Everyone who wants to integrate Vector tools into their Bazel project. 10 | 11 | Whether you are creating a large Bazel application or trying out Vector tools in a smaller Bazel project, these rules will streamline your tool integration workflow. 12 | 13 | ## Getting Started 14 | 15 | In a `WORKSPACE` or `MODULE.bazel` file add an `http_archive` rule to fetch the ruleset: 16 | 17 | ```python 18 | http_archive( 19 | name = "vector_bazel_rules", 20 | sha256 = "1234567891234567891234567891234567891234567891234567891234567891", 21 | url = "https://github.com/vectorgrp/bazel-rules/releases/download//source<.zip|.tar.gz>", 22 | ) 23 | ``` 24 | Adapt `` to fetch a distinct release. 25 | 26 | Make sure to use ```bazel skylib``` as well. See https://github.com/bazelbuild/bazel-skylib/releases for details. 27 | 28 | ## Rule & Toolchain Usage 29 | 30 | Please refer to the appropriate ```rules``` folder for a detailed description in a README.md file. 31 | 32 | ## Current Limitations 33 | We do not support vVirtualtarget (VTT) for our `DaVinci Configurator 5` and `DaVinci DvTeam` rules. 34 | 35 | Support for vVirtualTarget (VTT) will be available in a future release of the Vector Bazel rules. 36 | 37 | ## Release 38 | 39 | Some rules are interdependent, so all available rules and toolchains are published in one package. 40 | 41 | ## Bazel module 42 | 43 | Currently we do not provide Bazel modules (bzlmod). -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Reporting a Vulnerability 4 | 5 | Please responsibly disclose vulnerabilities by email to `support [at] vector.com`. -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Download Counts 6 | 12 | 13 | 14 |

GitHub Asset Download Count

15 |
Loading…
16 | 17 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /rules/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2025 Vector Group 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining 6 | # a copy of this software and associated documentation files (the 7 | # "Software"), to deal in the Software without restriction, including 8 | # without limitation the rights to use, copy, modify, merge, publish, 9 | # distribute, sublicense, and/or sell copies of the Software, and to 10 | # permit persons to whom the Software is furnished to do so, subject to 11 | # the following conditions: 12 | 13 | # The above copyright notice and this permission notice shall be 14 | # included in all copies or substantial portions of the Software. 15 | 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 25 | 26 | exports_files(["defs.bzl"]) 27 | 28 | bzl_library( 29 | name = "defs", 30 | srcs = ["defs.bzl"], 31 | visibility = ["//visibility:public"], 32 | deps = [ 33 | "//rules/cfg5:rules", 34 | "//rules/cfg5:toolchains", 35 | "//rules/davinci_developer:toolchains", 36 | "//rules/dvteam:rules", 37 | "//rules/gradle:rules", 38 | "//rules/gradle:toolchains", 39 | "//rules/ocs:rules", 40 | ], 41 | ) 42 | -------------------------------------------------------------------------------- /rules/cfg5/BUILD: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2025 Vector Group 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining 6 | # a copy of this software and associated documentation files (the 7 | # "Software"), to deal in the Software without restriction, including 8 | # without limitation the rights to use, copy, modify, merge, publish, 9 | # distribute, sublicense, and/or sell copies of the Software, and to 10 | # permit persons to whom the Software is furnished to do so, subject to 11 | # the following conditions: 12 | 13 | # The above copyright notice and this permission notice shall be 14 | # included in all copies or substantial portions of the Software. 15 | 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 25 | 26 | exports_files( 27 | glob( 28 | ["*"], 29 | ), 30 | ) 31 | 32 | toolchain_type( 33 | name = "toolchain_type", 34 | visibility = ["//visibility:public"], 35 | ) 36 | 37 | bzl_library( 38 | name = "rules", 39 | srcs = ["rules.bzl"], 40 | visibility = ["//visibility:public"], 41 | deps = ["//rules/common:create_davinci_tool_workspace"], 42 | ) 43 | 44 | bzl_library( 45 | name = "toolchains", 46 | srcs = ["toolchains.bzl"], 47 | visibility = ["//visibility:public"], 48 | ) 49 | -------------------------------------------------------------------------------- /rules/cfg5/README.md: -------------------------------------------------------------------------------- 1 | # DaVinci Configurator 5 2 | This chapter contains DaVinci Configurator 5 related rules and toolchains documentation. 3 | 4 | ## cfg5_toolchain 5 | 6 | Usage in `BUILD.bazel` file: 7 | 8 |
  9 | load("@//rules:defs.bzl", "cfg5_toolchain")
 10 | 
 11 | cfg5_toolchain(name, cfg5_files, cfg5_path, cfg5cli_path)
 12 | 
13 | 14 | 15 | **ATTRIBUTES** 16 | 17 | 18 | | Name | Description | Type | Mandatory | Default | 19 | | :------------- | :------------- | :------------- | :------------- | :------------- | 20 | | name | A unique name for this target. | Name | required | | 21 | | cfg5_files | Optional cfg5 files used as input for hermiticity | Label | optional | `None` | 22 | | cfg5_path | Path to the Cfg5 used in the bazel rules | Label | optional | `None` | 23 | | cfg5cli_path | Mandatory path to the Cfg5 cli path used in the bazel rules | Label | required | | 24 | 25 | 26 | ## start_cfg5_windows 27 | 28 | Usage in `BUILD.bazel` file: 29 | 30 |
 31 | load("@//rules:defs.bzl", "start_cfg5_windows")
 32 | 
 33 | start_cfg5_windows(name, cfg5_args, dpa)
 34 | 
35 | 36 | 37 | **ATTRIBUTES** 38 | 39 | 40 | | Name | Description | Type | Mandatory | Default | 41 | | :------------- | :------------- | :------------- | :------------- | :------------- | 42 | | name | A unique name for this target. | Name | required | | 43 | | cfg5_args | Additional CFG5 arguments | String | optional | `""` | 44 | | dpa | The dpa file to start the CFG5 with | Label | required | | 45 | 46 | 47 | ## cfg5_generate_rt 48 | 49 | Usage in `BUILD.bazel` file: 50 | 51 |
 52 | load("@//rules:defs.bzl", "cfg5_generate_rt")
 53 | 
 54 | cfg5_generate_rt(name, kwargs)
 55 | 
56 | 57 | Wraps the cfg5_generate_rt with the private_is_windows select statement in place 58 | 59 | 60 | **ATTRIBUTES** 61 | 62 | 63 | | Name | Description | Default Value | 64 | | :------------- | :------------- | :------------- | 65 | | name | The unique name of this target | none | 66 | | kwargs | All of the attrs of the cfg5_generate_rt rule | none | 67 | 68 | 69 | **RETURNS** 70 | 71 | A cfg5_generate_rt_workspace_def rule that contains the actual implementation 72 | 73 | 74 | ## cfg5_generate_rt_workspace 75 | 76 | Usage in `BUILD.bazel` file: 77 | 78 |
 79 | load("@//rules:defs.bzl", "cfg5_generate_rt_workspace")
 80 | 
 81 | cfg5_generate_rt_workspace(name, kwargs)
 82 | 
83 | 84 | Wraps the cfg5_generate_rt_workspace with the private_is_windows select statement in place 85 | 86 | 87 | **ATTRIBUTES** 88 | 89 | 90 | | Name | Description | Default Value | 91 | | :------------- | :------------- | :------------- | 92 | | name | The unique name of this target | none | 93 | | kwargs | All of the attrs of the cfg5_generate_rt_workspace rule | none | 94 | 95 | 96 | **RETURNS** 97 | 98 | A cfg5_generate_rt_workspace_def rule that contains the actual implementation 99 | 100 | 101 | ## cfg5_generate_vtt 102 | 103 | Usage in `BUILD.bazel` file: 104 | 105 |
106 | load("@//rules:defs.bzl", "cfg5_generate_vtt")
107 | 
108 | cfg5_generate_vtt(name, kwargs)
109 | 
110 | 111 | Wraps the cfg5_generate_vtt with the private_is_windows select statement in place 112 | 113 | 114 | **ATTRIBUTES** 115 | 116 | 117 | | Name | Description | Default Value | 118 | | :------------- | :------------- | :------------- | 119 | | name | The unique name of this target | none | 120 | | kwargs | All of the attrs of the cfg5_generate_vtt rule | none | 121 | 122 | 123 | **RETURNS** 124 | 125 | A cfg5_generate_vtt_def rule that contains the actual implementation 126 | 127 | 128 | ## cfg5_generate_vtt_workspace 129 | 130 | Usage in `BUILD.bazel` file: 131 | 132 |
133 | load("@//rules:defs.bzl", "cfg5_generate_vtt_workspace")
134 | 
135 | cfg5_generate_vtt_workspace(name, kwargs)
136 | 
137 | 138 | Wraps the cfg5_generate_vtt_workspace with the private_is_windows select statement in place 139 | 140 | 141 | **ATTRIBUTES** 142 | 143 | 144 | | Name | Description | Default Value | 145 | | :------------- | :------------- | :------------- | 146 | | name | The unique name of this target | none | 147 | | kwargs | All of the attrs of the cfg5_generate_vtt_workspace rule | none | 148 | 149 | 150 | **RETURNS** 151 | 152 | A cfg5_generate_vtt_workspace_def rule that contains the actual implementation 153 | 154 | 155 | # Example usage 156 | The following showcases an example on how to use a rule and toolchain in your Bazel project environment. 157 | 158 | ## Instantiate a rule 159 | 160 | In a `BUILD.bazel` file refer to the rule as follows: 161 | 162 | ```python 163 | cfg5_generate_rt_workspace( 164 | name = "rt_generate", # Name of the Bazel target 165 | config_files = [ # Additional configuration files to start the cfg5 with 166 | "Config/AUTOSAR/PlatformTypes_AR4.arxml", 167 | "Config/VTT/Demo.vttmake", 168 | "Config/VTT/Demo.vttproj", 169 | "AnotherConfig/Config.arxml", 170 | ], 171 | config_folders = [ # List of config folders that the path will be checked for in each file to create a nested Config folder structure 172 | "Config", 173 | "AnotherConfig", 174 | ] 175 | dpa_file = ":FolderPath/ToDpaProject", # The folder path to your DPA project file (.dpa) 176 | genArgs = [ # List of command line argument the DaVinci Configurator 5 CLI supports 177 | "--help" 178 | ], 179 | generated_files = "FolderPath/ToGeneratedFiles/", # List of files which are output of this rule 180 | , 181 | sip = "@external_repo//:package", # Path to the Microsar Classic product package 182 | target_compatible_with = [ # Platform definition for this target 183 | "//platforms:your_platform_definition", 184 | ], 185 | ) 186 | ``` 187 | 188 | ## Configure a toolchain 189 | 190 | All toolchain configurations are typically configured within a `BUILD.bazel` file. 191 | 192 | Please see [DaVinci Configurator 5 toolchain definition](../toolchains.md#davinci-configurator-5-toolchains). -------------------------------------------------------------------------------- /rules/cfg5/rules.bzl: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2025 Vector Group 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining 6 | # a copy of this software and associated documentation files (the 7 | # "Software"), to deal in the Software without restriction, including 8 | # without limitation the rights to use, copy, modify, merge, publish, 9 | # distribute, sublicense, and/or sell copies of the Software, and to 10 | # permit persons to whom the Software is furnished to do so, subject to 11 | # the following conditions: 12 | 13 | # The above copyright notice and this permission notice shall be 14 | # included in all copies or substantial portions of the Software. 15 | 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | """Rules for cfg5""" 25 | 26 | load("//rules/common:create_davinci_tool_workspace.bzl", "create_davinci_tool_workspace") 27 | #load("//rules/vtt:toolchains.bzl", "generate_tools_vtt") 28 | 29 | _CFG5_GENERATE_TEMPLATE_WINDOWS = """ 30 | start-process -WorkingDirectory {dpa_folder} -PassThru -NoNewWindow -RedirectStandardOutput {dpa_folder}/daVinciCfg5.log -Wait {cfg5cli_path} -ArgumentList '-p {dpa_path} -g {genargs} --verbose' 31 | """ 32 | _CFG5_GENERATE_TEMPLATE_WINDOWS_WORKSPACE = """ 33 | $folderPath = '{dpa_folder}' 34 | Get-ChildItem -Path $folderPath -Recurse -File | ForEach-Object {{ $_.IsReadOnly = $false; $_.Attributes = 'Normal'}} 35 | start-process -WorkingDirectory {dpa_folder} -PassThru -NoNewWindow -RedirectStandardOutput {dpa_folder}/daVinciCfg5.log -Wait {cfg5cli_path} -ArgumentList '-p {dpa_path} -g {genargs} --verbose' 36 | """ 37 | 38 | _CFG5_GENERATE_TEMPLATE_LINUX = """ 39 | {cfg5cli_path} -p {dpa_path} -g {genargs} --verbose > {dpa_folder}/daVinciCfg5.log 40 | """ 41 | _CFG5_GENERATE_TEMPLATE_LINUX_WORKSPACE = """ 42 | sudo chmod -R 777 {dpa_folder} && 43 | {cfg5cli_path} -p {dpa_folder}/{dpa_path} -g {genargs} --verbose > {dpa_folder}/daVinciCfg5.log 44 | """ 45 | 46 | def _cfg5_generate(ctx, dpa_path, dpa_folder, dpa_file, inputs, template, is_workspace, additional_genargs, tools = []): 47 | info = ctx.toolchains["//rules/cfg5:toolchain_type"] 48 | 49 | hdrs = [] 50 | for f in ctx.outputs.generated_files: 51 | if f.extension == "h": 52 | hdrs.append(f) 53 | 54 | compilation_context = cc_common.create_compilation_context( 55 | headers = depset( 56 | hdrs, 57 | ), 58 | ) 59 | 60 | dvcfg5_report_file_name = "DVCfg5ReportFile.xml" 61 | dvcfg5_report_file = ctx.actions.declare_file(dvcfg5_report_file_name) 62 | 63 | if "/" in dpa_folder: 64 | dvcfg5_log_file_name = dpa_folder.split("/")[-1] + "/daVinciCfg5.log" 65 | else: 66 | dvcfg5_log_file_name = dpa_folder + "/daVinciCfg5.log" 67 | dvcfg5_log_file = ctx.actions.declare_file(dvcfg5_log_file_name) 68 | 69 | generate_tools = list(tools) 70 | 71 | if info.cfg5_files: 72 | generate_tools.extend(info.cfg5_files) 73 | else: 74 | generate_tools.append(info.cfg5cli_path) 75 | 76 | if ctx.attr.private_is_windows: 77 | upward_path = "../" * len(dpa_file.dirname.split("/")) 78 | report_file_path = "../" + dvcfg5_report_file.basename if is_workspace else upward_path + dvcfg5_report_file.path 79 | command = template.format( 80 | dpa_path = dpa_path, 81 | dpa_folder = dpa_folder, 82 | cfg5cli_path = info.cfg5cli_path.path, 83 | genargs = " ".join(ctx.attr.genArgs + ["--reportFile=" + report_file_path, "--reportArgs=CreateXmlFile"] + additional_genargs), 84 | ) 85 | 86 | ctx.actions.run( 87 | mnemonic = "cfg5generate", 88 | executable = "powershell.exe", 89 | tools = generate_tools, 90 | inputs = inputs, 91 | outputs = ctx.outputs.generated_files + [dvcfg5_report_file, dvcfg5_log_file], 92 | arguments = [command], 93 | env = 94 | {"OS": "Windows_NT", "windir": "C:\\Windows", "SystemRoot": "C:\\Windows"}, 95 | ) 96 | 97 | return [ 98 | DefaultInfo(files = depset(ctx.outputs.generated_files)), 99 | CcInfo(compilation_context = compilation_context), 100 | ] 101 | else: 102 | command = template.format( 103 | dpa_path = dpa_path, 104 | dpa_folder = dpa_folder, 105 | cfg5cli_path = info.cfg5cli_path.path, 106 | genargs = " ".join(ctx.attr.genArgs + ["--reportFile=" + dvcfg5_report_file.path, "--reportArgs=CreateXmlFile"] + additional_genargs), 107 | ) 108 | 109 | ctx.actions.run_shell( 110 | mnemonic = "cfg5generate", 111 | tools = generate_tools, 112 | inputs = inputs, 113 | outputs = ctx.outputs.generated_files + [dvcfg5_report_file, dvcfg5_log_file], 114 | command = command, 115 | ) 116 | 117 | return [ 118 | DefaultInfo(files = depset(ctx.outputs.generated_files)), 119 | CcInfo(compilation_context = compilation_context), 120 | ] 121 | 122 | def _cfg5_generate_workspace_impl(ctx, additional_genargs, tools = []): 123 | _cfg_workspace = create_davinci_tool_workspace(ctx, workspace_name = ctx.label.name + "_cfg_workspace", addtional_workspace_files = [ctx.file.dpa_file], is_windows = ctx.attr.private_is_windows, config_files = ctx.files.config_files, config_folders = ctx.attr.config_folders) 124 | 125 | dpa_copy = _cfg_workspace.addtional_workspace_files[0] 126 | dpa_path = dpa_copy.basename 127 | dpa_folder = dpa_copy.dirname 128 | inputs = _cfg_workspace.files + _cfg_workspace.addtional_workspace_files 129 | template = _CFG5_GENERATE_TEMPLATE_LINUX_WORKSPACE 130 | if ctx.attr.private_is_windows: 131 | template = _CFG5_GENERATE_TEMPLATE_WINDOWS_WORKSPACE 132 | 133 | if ctx.attr.sip: 134 | inputs.extend(ctx.attr.sip.files.to_list()) 135 | return _cfg5_generate(ctx, dpa_path, dpa_folder, dpa_copy, inputs, template, True, additional_genargs, tools) 136 | 137 | # def _cfg5_generate_vtt_workspace_impl(ctx): 138 | # tools = generate_tools_vtt(ctx) 139 | # return _cfg5_generate_workspace_impl(ctx, ["--genType=VTT", "--buildVTTProject"], tools) 140 | 141 | cfg5_generate_workspace_attrs = { 142 | "dpa_file": attr.label(allow_single_file = [".dpa"], doc = "Dpa project file to start the cfg5 with"), 143 | "generated_files": attr.output_list(doc = "List of generated files that are added to the output"), 144 | "config_files": attr.label_list(allow_files = True, doc = "Additional configuration files to start the cfg5 with"), 145 | "genArgs": attr.string_list(doc = "The DaVinciCfgCmd argument options."), 146 | "sip": attr.label(doc = "sip location to mark it as a dependency, as it the sip is needed for cfg5 execution"), 147 | "private_is_windows": attr.bool(mandatory = True, doc = "Is set automatically to the correct OS value"), 148 | "config_folders": attr.string_list(doc = "(Optional) List of config folders that the path will be checked for in each file to create a nested Config folder structure, default is [\"Config\"]", default = ["Config"]), 149 | } 150 | 151 | # cfg5_generate_vtt_workspace_def = rule( 152 | # implementation = _cfg5_generate_vtt_workspace_impl, 153 | # attrs = cfg5_generate_workspace_attrs, 154 | # doc = """ 155 | # Creates a separate cfg5 workspace containing all the given config files and run the cfg5 in this created directory inside the bazel-bin. 156 | # This rule is wrapped with private_is_windows attribute to separate between OS differences. 157 | # Used specifically for the vtt use case, as this adds the correct vtt flags to the Cfg5 call automatically. 158 | # """, 159 | # toolchains = ["//rules/cfg5:toolchain_type", "//rules/vtt:toolchain_type"], 160 | # ) 161 | 162 | # def cfg5_generate_vtt_workspace(name, **kwargs): 163 | # """Wraps the cfg5_generate_vtt_workspace with the private_is_windows select statement in place 164 | 165 | # Args: 166 | # name: The unique name of this target 167 | # **kwargs: All of the attrs of the cfg5_generate_vtt_workspace rule 168 | 169 | # Returns: 170 | # A cfg5_generate_vtt_workspace_def rule that contains the actual implementation 171 | # """ 172 | # cfg5_generate_vtt_workspace_def( 173 | # name = name, 174 | # private_is_windows = select({ 175 | # "@bazel_tools//src/conditions:host_windows": True, 176 | # "//conditions:default": False, 177 | # }), 178 | # **kwargs 179 | # ) 180 | 181 | def _cfg5_generate_rt_workspace_impl(ctx): 182 | return _cfg5_generate_workspace_impl(ctx, ["--genType=REAL"]) 183 | 184 | cfg5_generate_rt_workspace_def = rule( 185 | implementation = _cfg5_generate_rt_workspace_impl, 186 | attrs = cfg5_generate_workspace_attrs, 187 | doc = """ 188 | Creates a separate cfg5 workspace containing all the given config files and run the cfg5 in this created directory inside the bazel-bin. 189 | This rule is wrapped with private_is_windows attribute to separate between OS differences. 190 | Used specifically for the rt use case, as this adds the correct rt flags to the Cfg5 call automatically. 191 | """, 192 | toolchains = ["//rules/cfg5:toolchain_type"], 193 | ) 194 | 195 | def cfg5_generate_rt_workspace(name, **kwargs): 196 | """Wraps the cfg5_generate_rt_workspace with the private_is_windows select statement in place 197 | 198 | Args: 199 | name: The unique name of this target 200 | **kwargs: All of the attrs of the cfg5_generate_rt_workspace rule 201 | 202 | Returns: 203 | A cfg5_generate_rt_workspace_def rule that contains the actual implementation 204 | """ 205 | cfg5_generate_rt_workspace_def( 206 | name = name, 207 | private_is_windows = select({ 208 | "@bazel_tools//src/conditions:host_windows": True, 209 | "//conditions:default": False, 210 | }), 211 | **kwargs 212 | ) 213 | 214 | # def _cfg5_generate_vtt_impl(ctx): 215 | # info_vtt = ctx.toolchains["//rules/vtt:toolchain_type"] 216 | 217 | # if not ctx.attr.private_is_windows and not info_vtt.vtt_cmd_path and not info_vtt.vtt_cmd_label: 218 | # fail("vttcmd_path is not set in the 'vtt_toolchain', but is necessary for the generation under Linux.") 219 | # inputs = depset(ctx.files.input_arxmls, transitive = [ctx.attr.dpa_linux.files]) 220 | # dpa_path = ctx.file.dpa_windows.basename 221 | # dpa_folder = ctx.file.dpa_windows.dirname 222 | # dpa_file = ctx.file.dpa_linux 223 | # template = _CFG5_GENERATE_TEMPLATE_LINUX 224 | # if ctx.attr.private_is_windows: 225 | # dpa_file = ctx.file.dpa_windows 226 | # template = _CFG5_GENERATE_TEMPLATE_WINDOWS 227 | 228 | # tools = generate_tools_vtt(ctx) 229 | 230 | # return _cfg5_generate(ctx, dpa_path, dpa_folder, dpa_file, inputs, template, False, ["--genType=VTT", "--buildVTTProject"], tools) 231 | 232 | def _cfg5_generate_rt_impl(ctx): 233 | inputs = depset(ctx.files.input_arxmls, transitive = [ctx.attr.dpa_linux.files]) 234 | dpa_path = ctx.file.dpa_windows.basename 235 | dpa_folder = ctx.file.dpa_windows.dirname 236 | dpa_file = ctx.file.dpa_linux 237 | template = _CFG5_GENERATE_TEMPLATE_LINUX 238 | if ctx.attr.private_is_windows: 239 | dpa_file = ctx.file.dpa_windows 240 | template = _CFG5_GENERATE_TEMPLATE_WINDOWS 241 | 242 | return _cfg5_generate(ctx, dpa_path, dpa_folder, dpa_file, inputs, template, False, ["--genType=REAL"]) 243 | 244 | cfg5_generate_attrs = { 245 | "dpa_windows": attr.label(allow_single_file = [".dpa"], doc = "Dpa file for the windows execution of the cfg5"), 246 | "dpa_linux": attr.label(allow_single_file = [".dpa"], doc = "Dpa file for the linux execution of the cfg5"), 247 | "generated_files": attr.output_list(doc = "List of generated files that are added to the output"), 248 | "input_arxmls": attr.label_list(allow_files = [".arxml"], doc = "List of arxml files to use a input for the cfg5"), 249 | "genArgs": attr.string_list(doc = "The DaVinciCfgCmd argument options."), 250 | "private_is_windows": attr.bool(mandatory = True, doc = "Set automatically to the correct OS value"), 251 | } 252 | 253 | # cfg5_generate_vtt_def = rule( 254 | # implementation = _cfg5_generate_vtt_impl, 255 | # attrs = cfg5_generate_attrs, 256 | # doc = """ 257 | # Run the cfg5 directly in the project. 258 | # This rule is wrapped with private_is_windows attribute to separate between OS differences. 259 | # Used specifically for the vtt use case, as this adds the correct vtt flags to the Cfg5 call automatically. 260 | # """, 261 | # toolchains = ["//rules/cfg5:toolchain_type", "//rules/vtt:toolchain_type"], 262 | # ) 263 | 264 | # def cfg5_generate_vtt(name, **kwargs): 265 | # """Wraps the cfg5_generate_vtt with the private_is_windows select statement in place 266 | 267 | # Args: 268 | # name: The unique name of this target 269 | # **kwargs: All of the attrs of the cfg5_generate_vtt rule 270 | 271 | # Returns: 272 | # A cfg5_generate_vtt_def rule that contains the actual implementation 273 | # """ 274 | # cfg5_generate_vtt_def( 275 | # name = name, 276 | # private_is_windows = select({ 277 | # "@bazel_tools//src/conditions:host_windows": True, 278 | # "//conditions:default": False, 279 | # }), 280 | # **kwargs 281 | # ) 282 | 283 | cfg5_generate_rt_def = rule( 284 | implementation = _cfg5_generate_rt_impl, 285 | attrs = cfg5_generate_attrs, 286 | doc = """Run the cfg5 directly in the project. 287 | This rule is wrapped with private_is_windows attribute to separate between OS differences. 288 | Used specifically for the rt use case, as this adds the correct rt flags to the Cfg5 call automatically. 289 | """, 290 | toolchains = ["//rules/cfg5:toolchain_type"], 291 | ) 292 | 293 | def cfg5_generate_rt(name, **kwargs): 294 | """Wraps the cfg5_generate_rt with the private_is_windows select statement in place 295 | 296 | Args: 297 | name: The unique name of this target 298 | **kwargs: All of the attrs of the cfg5_generate_rt rule 299 | 300 | Returns: 301 | A cfg5_generate_rt_workspace_def rule that contains the actual implementation 302 | """ 303 | cfg5_generate_rt_def( 304 | name = name, 305 | private_is_windows = select({ 306 | "@bazel_tools//src/conditions:host_windows": True, 307 | "//conditions:default": False, 308 | }), 309 | **kwargs 310 | ) 311 | 312 | #This template creates a powershell script file that runs the CFG5 from the git repository and not the Bazel workspace repository. 313 | _CFG5_START_POWERSHELL_TEMPLATE = """ 314 | $ErrorActionPreference = "Stop" 315 | $script_full_path = $PSCommandPath 316 | $relative_path_to_run_files = "{script_short_path}" 317 | $relative_path_to_ws_root = "{script_package_path}" 318 | $cfg5_bin_path = "{cfg5_bin_path}" 319 | $dpa_file_path = "{dpa_file_path}" 320 | $additional_arguments = " {cfg5_args}" 321 | $project_root_path = "{project_root_path}" 322 | 323 | 324 | $dirCount_relative_path_to_run_files = ($relative_path_to_run_files -split '/' ).count - 1 325 | $dirCount_relative_path_to_ws_package = 2 326 | $dirCount_relative_path_to_ws_root = ($relative_path_to_ws_root -split '/' ).count - 1 327 | # Relative directories + parent directory of script file 328 | $dir_count_to_ws_root = $dirCount_relative_path_to_run_files + $dirCount_relative_path_to_ws_package + $dirCount_relative_path_to_ws_root + 1 329 | 330 | $ws_root_path = $script_full_path 331 | for ($i=0; $i -lt $dir_count_to_ws_root; $i++) {{ 332 | $ws_root_path = Split-Path -Parent $ws_root_path 333 | }} 334 | 335 | $cfg5_abs_path = $ws_root_path + "/" + $cfg5_bin_path 336 | $dpa_file_abs_path = $ws_root_path + "/" + $dpa_file_path 337 | $cfg5_start_command = $cfg5_abs_path +" -p "+ $dpa_file_abs_path + $additional_arguments 338 | Get-ChildItem -Path $ws_root_path/$project_root_path -Recurse | ForEach-Object {{ if ($_.PSIsContainer -eq $false -and $_.GetType().GetProperty('IsReadOnly')) {{ $_.IsReadOnly = $false }} }} 339 | Invoke-WmiMethod -Class Win32_Process -Name Create -ArgumentList "$cfg5_start_command" > cfg5_start.log 340 | """ 341 | 342 | # This template creates a batch file that serves as bootstrap for the powershell script to start CFG5 (and fork the process). 343 | _CFG5_START_SCRIPT_WRAPPER_TEMPLATE = """ 344 | powershell.exe -File "{ps_start_script_path}" 345 | """ 346 | 347 | def _start_cfg5_windows_impl(ctx): 348 | info = ctx.toolchains["//rules/cfg5:toolchain_type"] 349 | 350 | cfg5_ps_script_file = ctx.actions.declare_file(ctx.label.name + ".ps1") 351 | powershell_command = _CFG5_START_POWERSHELL_TEMPLATE.format( 352 | script_short_path = cfg5_ps_script_file.short_path, 353 | script_package_path = cfg5_ps_script_file.path, 354 | cfg5_bin_path = info.cfg5_path.path, 355 | dpa_file_path = ctx.file.dpa.path, 356 | cfg5_args = ctx.attr.cfg5_args, 357 | project_root_path = ctx.file.dpa.dirname, 358 | ).strip() 359 | ctx.actions.write(cfg5_ps_script_file, powershell_command, is_executable = True) 360 | 361 | start_script_wrapper_file = ctx.actions.declare_file(ctx.label.name + ".bat") 362 | powershell_wrapper_script_command = _CFG5_START_SCRIPT_WRAPPER_TEMPLATE.format( 363 | ps_start_script_path = cfg5_ps_script_file.short_path, 364 | ).strip() 365 | ctx.actions.write(start_script_wrapper_file, powershell_wrapper_script_command, is_executable = True) 366 | 367 | return [ 368 | DefaultInfo( 369 | executable = start_script_wrapper_file, 370 | runfiles = ctx.runfiles(files = [cfg5_ps_script_file]), 371 | ), 372 | ] 373 | 374 | start_cfg5_windows = rule( 375 | implementation = _start_cfg5_windows_impl, 376 | attrs = { 377 | "dpa": attr.label( 378 | allow_single_file = [".dpa"], 379 | mandatory = True, 380 | doc = "The dpa file to start the CFG5 with", 381 | ), 382 | "cfg5_args": attr.string( 383 | mandatory = False, 384 | doc = "Additional CFG5 arguments", 385 | ), 386 | }, 387 | executable = True, 388 | toolchains = ["//rules/cfg5:toolchain_type"], 389 | ) 390 | -------------------------------------------------------------------------------- /rules/cfg5/toolchains.bzl: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2025 Vector Group 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining 6 | # a copy of this software and associated documentation files (the 7 | # "Software"), to deal in the Software without restriction, including 8 | # without limitation the rights to use, copy, modify, merge, publish, 9 | # distribute, sublicense, and/or sell copies of the Software, and to 10 | # permit persons to whom the Software is furnished to do so, subject to 11 | # the following conditions: 12 | 13 | # The above copyright notice and this permission notice shall be 14 | # included in all copies or substantial portions of the Software. 15 | 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | """Toolchain for CFG5 """ 25 | 26 | def _cfg5_toolchain_impl(ctx): 27 | toolchain_info = platform_common.ToolchainInfo( 28 | cfg5_path = ctx.executable.cfg5_path, 29 | cfg5_files = ctx.files.cfg5_files, 30 | cfg5cli_path = ctx.executable.cfg5cli_path, 31 | ) 32 | return [toolchain_info] 33 | 34 | cfg5_toolchain = rule( 35 | implementation = _cfg5_toolchain_impl, 36 | attrs = { 37 | "cfg5_path": attr.label( 38 | mandatory = False, 39 | allow_single_file = True, 40 | cfg = "exec", 41 | executable = True, 42 | doc = "Path to the Cfg5 used in the bazel rules", 43 | ), 44 | "cfg5_files": attr.label(mandatory = False, doc = "Optional cfg5 files used as input for hermiticity"), 45 | "cfg5cli_path": attr.label( 46 | mandatory = True, 47 | allow_single_file = True, 48 | cfg = "exec", 49 | executable = True, 50 | doc = "Mandatory path to the Cfg5 cli path used in the bazel rules", 51 | ), 52 | }, 53 | ) 54 | -------------------------------------------------------------------------------- /rules/common/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2025 Vector Group 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining 6 | # a copy of this software and associated documentation files (the 7 | # "Software"), to deal in the Software without restriction, including 8 | # without limitation the rights to use, copy, modify, merge, publish, 9 | # distribute, sublicense, and/or sell copies of the Software, and to 10 | # permit persons to whom the Software is furnished to do so, subject to 11 | # the following conditions: 12 | 13 | # The above copyright notice and this permission notice shall be 14 | # included in all copies or substantial portions of the Software. 15 | 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 25 | 26 | exports_files( 27 | glob( 28 | ["*"], 29 | ), 30 | ) 31 | 32 | bzl_library( 33 | name = "create_davinci_tool_workspace", 34 | srcs = ["create_davinci_tool_workspace.bzl"], 35 | visibility = ["//visibility:public"], 36 | deps = [":copy_file"], 37 | ) 38 | 39 | bzl_library( 40 | name = "copy_file", 41 | srcs = ["copy_file.bzl"], 42 | visibility = ["//visibility:public"], 43 | ) -------------------------------------------------------------------------------- /rules/common/copy_file.bzl: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | """This is a common function for any rule needing to copy files around """ 14 | 15 | # # Hints for Bazel spawn strategy 16 | COPY_EXECUTION_REQUIREMENTS = { 17 | # ----------------+----------------------------------------------------------------------------- 18 | # no-remote | Prevents the action or test from being executed remotely or cached remotely. 19 | # | This is equivalent to using both `no-remote-cache` and `no-remote-exec`. 20 | # ----------------+----------------------------------------------------------------------------- 21 | # no-cache | Results in the action or test never being cached (remotely or locally) 22 | # ----------------+----------------------------------------------------------------------------- 23 | # See https://bazel.build/reference/be/common-definitions#common-attributes 24 | # 25 | # Copying file & directories is entirely IO-bound and there is no point doing this work 26 | # remotely. 27 | # 28 | # Also, remote-execution does not allow source directory inputs, see 29 | # https://github.com/bazelbuild/bazel/commit/c64421bc35214f0414e4f4226cc953e8c55fa0d2 So we must 30 | # not attempt to execute remotely in that case. 31 | # 32 | # There is also no point pulling the output file or directory from the remote cache since the 33 | # bytes to copy are already available locally. Conversely, no point in writing to the cache if 34 | # no one has any reason to check it for this action. 35 | # 36 | # Read and writing to disk cache is disabled as well primarily to reduce disk usage on the local 37 | # machine. A disk cache hit of a directory copy could be slghtly faster than a copy since the 38 | # disk cache stores the directory artifact as a single entry, but the slight performance bump 39 | # comes at the cost of heavy disk cache usage, which is an unmanaged directory that grow beyond 40 | # the bounds of the physical disk. 41 | "no-remote": "1", 42 | "no-cache": "1", 43 | } 44 | 45 | # https://github.com/bazelbuild/bazel-skylib/blob/main/rules/private/copy_file_private.bzl 46 | # Theses functions are mostly copied 1:1 as they cannot be import as this library is private and only the copy_file rule is available 47 | 48 | def _copy_bash(ctx, src, dst): 49 | if hasattr(src, "path"): 50 | ctx.actions.run_shell( 51 | inputs = [src], 52 | outputs = [dst], 53 | command = "cp -f \"$1\" \"$2\"", 54 | arguments = [src.path, dst.path], 55 | mnemonic = "CopyFile", 56 | progress_message = "Copying files", 57 | execution_requirements = COPY_EXECUTION_REQUIREMENTS, 58 | ) 59 | else: 60 | fail("The provided src is not a File!") 61 | 62 | def _copy_cmd(ctx, src, dst): 63 | # Most Windows binaries built with MSVC use a certain argument quoting 64 | # scheme. Bazel uses that scheme too to quote arguments. However, 65 | # cmd.exe uses different semantics, so Bazel's quoting is wrong here. 66 | # To fix that we write the command to a .bat file so no command line 67 | # quoting or escaping is required. 68 | if hasattr(src, "path"): 69 | full_name = src.path.replace("/", "") + src.basename 70 | bat = ctx.actions.declare_file(ctx.label.name + full_name + "-cmd.bat") 71 | ctx.actions.write( 72 | output = bat, 73 | # Do not use lib/shell.bzl's shell.quote() method, because that uses 74 | # Bash quoting syntax, which is different from cmd.exe's syntax. 75 | content = "@copy /Y \"%s\" \"%s\" >NUL" % ( 76 | src.path.replace("/", "\\"), 77 | dst.path.replace("/", "\\"), 78 | ), 79 | is_executable = True, 80 | ) 81 | ctx.actions.run( 82 | inputs = [src, bat], 83 | outputs = [dst], 84 | executable = "cmd.exe", 85 | arguments = ["/C", bat.path.replace("/", "\\")], 86 | mnemonic = "CopyFile", 87 | progress_message = "Copying files", 88 | execution_requirements = COPY_EXECUTION_REQUIREMENTS, 89 | ) 90 | else: 91 | fail("The provided src is not a File!") 92 | 93 | def copy_file(ctx, src, dst, is_windows): 94 | if is_windows: 95 | _copy_cmd(ctx, src, dst) 96 | else: 97 | _copy_bash(ctx, src, dst) -------------------------------------------------------------------------------- /rules/common/create_davinci_tool_workspace.bzl: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2025 Vector Group 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining 6 | # a copy of this software and associated documentation files (the 7 | # "Software"), to deal in the Software without restriction, including 8 | # without limitation the rights to use, copy, modify, merge, publish, 9 | # distribute, sublicense, and/or sell copies of the Software, and to 10 | # permit persons to whom the Software is furnished to do so, subject to 11 | # the following conditions: 12 | 13 | # The above copyright notice and this permission notice shall be 14 | # included in all copies or substantial portions of the Software. 15 | 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | """Function for creating tool workspaces, circumventing the usual way that these tools are being executed""" 25 | 26 | load("//rules/common:copy_file.bzl", "copy_file") 27 | 28 | def DaVinciToolWorkspaceInfo(files, workspace_prefix, addtional_workspace_files = []): 29 | """Creates a DaVinciToolWorkspaceInfo object that contains all the necessary information for the DaVinci tool workspace 30 | 31 | Args: 32 | files: A List of config files that are available inside the davinci tool workspace (list of File) 33 | workspace_prefix: The name of the created workspace (string) 34 | addtional_workspace_files: (Optional) The copied files that is available inside the davinci tool workspace (File, default is []]) 35 | 36 | Returns: 37 | A DaVinci tool workspace information object 38 | """ 39 | if type(files) != "list": 40 | fail("Should be of type list", "files") 41 | 42 | if len(files) < 1: 43 | fail("Should contain at least one File", "files") 44 | 45 | if type(workspace_prefix) != "string": 46 | fail("Should be of type string", "workspace_prefix") 47 | 48 | for copy in addtional_workspace_files: 49 | if copy != None: 50 | if not hasattr(copy, "basename") or not hasattr(copy, "dirname"): 51 | fail("Should be of type File", "copy") 52 | 53 | return struct( 54 | files = files, 55 | workspace_prefix = workspace_prefix, 56 | addtional_workspace_files = addtional_workspace_files, 57 | ) 58 | 59 | def create_davinci_tool_workspace(ctx, workspace_name, addtional_workspace_files = [], is_windows = False, config_files = [], config_folders = ["Config"]): 60 | """Creates a separate workspace in the bazel-bin directory where the execution of the corresponding tool is supposed to be done. This copies all the available configuration files aswell as a potentially given dpa file 61 | 62 | Args: 63 | ctx: current rule ctx that is creating the workspace 64 | workspace_name: any string is allowed, this will create the workspace under this name 65 | addtional_workspace_files: (Optional) can also provide a additional files that will be added into the workspace aside from the config_files, this will be handled differently than the remaining config 66 | is_windows: execution platform of the rule 67 | config_files: List of config files that will be used to create the workspace 68 | config_folders: (Optional) List of config folders that the path will be checked for in each file to create a nested Config folder structure, default is ["Config"] 69 | 70 | Returns: 71 | DaVinciToolWorkspaceInfo 72 | """ 73 | 74 | addtional_workspace_files_copy = [] 75 | for file in addtional_workspace_files: 76 | file_copy = file 77 | if hasattr(file, "basename"): 78 | file_copy = ctx.actions.declare_file(workspace_name + "/" + file.basename) 79 | 80 | # copies the file and renames it with an xml extension, this is to workaround the bazel restrictions of having readonly files in its output directory if the files are an action output 81 | # this way we can run dvteam on the dpa file without running into a problem as the copy is used for execution 82 | copy_file(ctx, file, file_copy, is_windows) 83 | addtional_workspace_files_copy.append(file_copy) 84 | 85 | tool_workspace_config_files = [] 86 | 87 | # this copies all the config files 88 | for file in config_files: 89 | # this will put the config files inside the Config folder, this might need to be changed later on 90 | # but is needed to make sure that no deep paths are created in the workspace creation phase 91 | if hasattr(file, "path"): 92 | for config_folder in config_folders: 93 | if (config_folder + "/" in file.path): 94 | base_path = config_folder + "/" + file.path.split("/" + config_folder + "/")[1] 95 | config_file_copy = ctx.actions.declare_file(workspace_name + "/" + base_path) 96 | tool_workspace_config_files.append(config_file_copy) 97 | copy_file(ctx, file, config_file_copy, is_windows) 98 | else: 99 | fail("Config file cannot be copied as it is not a valid File") 100 | 101 | # Check if everything worked 102 | if len(config_files) != len(tool_workspace_config_files): 103 | fail("Config was not copied successfully") 104 | 105 | return DaVinciToolWorkspaceInfo(files = tool_workspace_config_files, workspace_prefix = workspace_name, addtional_workspace_files = addtional_workspace_files_copy) -------------------------------------------------------------------------------- /rules/davinci_developer/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2025 Vector Group 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining 6 | # a copy of this software and associated documentation files (the 7 | # "Software"), to deal in the Software without restriction, including 8 | # without limitation the rights to use, copy, modify, merge, publish, 9 | # distribute, sublicense, and/or sell copies of the Software, and to 10 | # permit persons to whom the Software is furnished to do so, subject to 11 | # the following conditions: 12 | 13 | # The above copyright notice and this permission notice shall be 14 | # included in all copies or substantial portions of the Software. 15 | 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 25 | 26 | exports_files( 27 | glob( 28 | ["*"], 29 | ), 30 | ) 31 | 32 | toolchain_type( 33 | name = "toolchain_type", 34 | visibility = ["//visibility:public"], 35 | ) 36 | 37 | bzl_library( 38 | name = "toolchains", 39 | srcs = ["toolchains.bzl"], 40 | visibility = ["//visibility:public"], 41 | ) -------------------------------------------------------------------------------- /rules/davinci_developer/README.md: -------------------------------------------------------------------------------- 1 | # DaVinci Developer 2 | This chapter contains DaVinci Developer related toolchain documentation. 3 | 4 | 5 | 6 | ## davinci_developer_toolchain 7 | 8 | Usage in `BUILD.bazel` file: 9 | 10 |
11 | load("@//rules:defs.bzl", "davinci_developer_toolchain")
12 | 
13 | davinci_developer_toolchain(name, davinci_developer_cmd_label, davinci_developer_label,
14 |                             davinci_developer_path)
15 | 
16 | 17 | Either davinci_developer_label or davinci_developer_path have to be set for the toolchain to have any effect. This will then make the DaVinci Developer available via toolchain for rules like DaVinci Team 18 | 19 | **ATTRIBUTES** 20 | 21 | 22 | | Name | Description | Type | Mandatory | Default | 23 | | :------------- | :------------- | :------------- | :------------- | :------------- | 24 | | name | A unique name for this target. | Name | required | | 25 | | davinci_developer_cmd_label | Label version of the developer cmd that can be used if the DaVinci developer was downloaded via bazel, only used for linux | Label | optional | `None` | 26 | | davinci_developer_label | Label version of the developer path that can be used if the DaVinci developer was downloaded via bazel, mostly used for linux | Label | optional | `None` | 27 | | davinci_developer_path | Path version of the developer path that can be used if the DaVinci developer was not downloaded via bazel and is installed system wide, mostly used for windows | String | optional | `""` | 28 | 29 | # Example usage 30 | 31 | The following showcases an example on how to use a toolchain in your Bazel project environment. 32 | 33 | ## Configure a toolchain 34 | 35 | All toolchain configurations are typically configured within a `BUILD.bazel` file. 36 | 37 | Please see [DaVinci Developer toolchain definition](../toolchains.md#davinci-developer-toolchains). -------------------------------------------------------------------------------- /rules/davinci_developer/toolchains.bzl: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2025 Vector Group 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining 6 | # a copy of this software and associated documentation files (the 7 | # "Software"), to deal in the Software without restriction, including 8 | # without limitation the rights to use, copy, modify, merge, publish, 9 | # distribute, sublicense, and/or sell copies of the Software, and to 10 | # permit persons to whom the Software is furnished to do so, subject to 11 | # the following conditions: 12 | 13 | # The above copyright notice and this permission notice shall be 14 | # included in all copies or substantial portions of the Software. 15 | 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | """Toolchain for davinci_developer""" 25 | 26 | def _davinci_developer_toolchain_impl(ctx): 27 | toolchain_info = platform_common.ToolchainInfo( 28 | davinci_developer_label = ctx.executable.davinci_developer_label, 29 | davinci_developer_path = ctx.attr.davinci_developer_path, 30 | davinci_developer_cmd_label = ctx.executable.davinci_developer_cmd_label, 31 | ) 32 | return [toolchain_info] 33 | 34 | davinci_developer_toolchain = rule( 35 | implementation = _davinci_developer_toolchain_impl, 36 | attrs = { 37 | "davinci_developer_label": attr.label( 38 | mandatory = False, 39 | allow_single_file = True, 40 | cfg = "exec", 41 | executable = True, 42 | doc = "Label version of the developer path that can be used if the DaVinci developer was downloaded via bazel, mostly used for linux", 43 | ), 44 | "davinci_developer_path": attr.string(mandatory = False, doc = "Path version of the developer path that can be used if the DaVinci developer was not downloaded via bazel and is installed system wide, mostly used for windows"), 45 | "davinci_developer_cmd_label": attr.label( 46 | mandatory = False, 47 | allow_single_file = True, 48 | cfg = "exec", 49 | executable = True, 50 | doc = "Label version of the developer cmd that can be used if the DaVinci developer was downloaded via bazel, only used for linux", 51 | ), 52 | }, 53 | doc = """Either davinci_developer_label or davinci_developer_path have to be set for the toolchain to have any effect. This will then make the DaVinci Developer available via toolchain for rules like dvteam""", 54 | ) -------------------------------------------------------------------------------- /rules/defs.bzl: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2025 Vector Group 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining 6 | # a copy of this software and associated documentation files (the 7 | # "Software"), to deal in the Software without restriction, including 8 | # without limitation the rights to use, copy, modify, merge, publish, 9 | # distribute, sublicense, and/or sell copies of the Software, and to 10 | # permit persons to whom the Software is furnished to do so, subject to 11 | # the following conditions: 12 | 13 | # The above copyright notice and this permission notice shall be 14 | # included in all copies or substantial portions of the Software. 15 | 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | """Vector-Bazel-Rules 25 | """ 26 | load("//rules/cfg5:rules.bzl", _cfg5_generate_rt = "cfg5_generate_rt", _cfg5_generate_rt_workspace = "cfg5_generate_rt_workspace", 27 | # _cfg5_generate_vtt = "cfg5_generate_vtt", _cfg5_generate_vtt_workspace = "cfg5_generate_vtt_workspace", 28 | _start_cfg5_windows = "start_cfg5_windows") 29 | load("//rules/cfg5:toolchains.bzl", _cfg5_toolchain = "cfg5_toolchain") 30 | load("//rules/davinci_developer:toolchains.bzl", _davinci_developer_toolchain = "davinci_developer_toolchain") 31 | load("//rules/dvteam:rules.bzl", _dvteam = "dvteam") 32 | load("//rules/gradle:rules.bzl", _generate_gradle_properties = "generate_gradle_properties") 33 | load("//rules/gradle:toolchains.bzl", _gradle_toolchain = "gradle_toolchain") 34 | load("//rules/ocs:rules.bzl", _cfg5_execute_script_task = "cfg5_execute_script_task", _ocs = "ocs") 35 | 36 | # DaVinci Configurator 5 rules 37 | start_cfg5_windows = _start_cfg5_windows 38 | #cfg5_generate_vtt_workspace = _cfg5_generate_vtt_workspace 39 | cfg5_generate_rt_workspace = _cfg5_generate_rt_workspace 40 | #cfg5_generate_vtt = _cfg5_generate_vtt 41 | cfg5_generate_rt = _cfg5_generate_rt 42 | 43 | # DaVinci Team rules 44 | dvteam = _dvteam 45 | 46 | # Gradle rules 47 | generate_gradle_properties = _generate_gradle_properties 48 | 49 | # OCS rules 50 | ocs = _ocs 51 | cfg5_execute_script_task = _cfg5_execute_script_task 52 | 53 | # Toolchain rules 54 | cfg5_toolchain = _cfg5_toolchain 55 | davinci_developer_toolchain = _davinci_developer_toolchain 56 | gradle_toolchain = _gradle_toolchain -------------------------------------------------------------------------------- /rules/dvteam/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2025 Vector Group 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining 6 | # a copy of this software and associated documentation files (the 7 | # "Software"), to deal in the Software without restriction, including 8 | # without limitation the rights to use, copy, modify, merge, publish, 9 | # distribute, sublicense, and/or sell copies of the Software, and to 10 | # permit persons to whom the Software is furnished to do so, subject to 11 | # the following conditions: 12 | 13 | # The above copyright notice and this permission notice shall be 14 | # included in all copies or substantial portions of the Software. 15 | 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 25 | 26 | exports_files( 27 | glob( 28 | ["*"], 29 | ), 30 | ) 31 | 32 | bzl_library( 33 | name = "rules", 34 | srcs = ["rules.bzl"], 35 | visibility = ["//visibility:public"], 36 | deps = ["//rules/common:create_davinci_tool_workspace"], 37 | ) 38 | -------------------------------------------------------------------------------- /rules/dvteam/README.md: -------------------------------------------------------------------------------- 1 | # DaVinci Team 2 | This chapter contains DaVinci Team related rules documentation. 3 | 4 | 5 | 6 | ## dvteam 7 | 8 | Usage in `BUILD.bazel` file: 9 | 10 |
11 | load("@//rules:defs.bzl", "dvteam")
12 | 
13 | dvteam(name, kwargs)
14 | 
15 | 16 | Wraps the dvteam with the private_is_windows select statement in place 17 | 18 | **ATTRIBUTES** 19 | 20 | 21 | | Name | Description | Default Value | 22 | | :------------- | :------------- | :------------- | 23 | | name | The unique name of this target | none | 24 | | kwargs | All of the attrs of the dvteam rule | none | 25 | 26 | **RETURNS** 27 | 28 | A dvteam_def rule that contains the actual implementation 29 | 30 | # Example usage 31 | 32 | The following showcases an example on how to use a rule in your Bazel project environment. 33 | 34 | ## Instantiate a rule 35 | 36 | In a `BUILD.bazel` file refer to the rule as follows: 37 | 38 | ```python 39 | dvteam( 40 | name = "myintegrate-start-application", # Name of the Bazel target 41 | app_package_sources = [ # The additional app package sources that should be integrated 42 | "@myapplication//:package", 43 | ], 44 | config_files = ["/path/to/myEcuC_BSW-x.armxl", # The expected output files of DaVinci Team 45 | "/path/to/myEcuC_BSW-y.armxl", 46 | "/path/to/myEcuC_BSW-z.armxl", 47 | ], 48 | dpa_file = "path/to/myproject.dpa", # The dpa file to use for the DvTeam run 49 | dvteam_args = [ # The arguments for the actual DvTeam CLI for the run 50 | "--debug", 51 | "--info", 52 | ], 53 | global_instruction_files = ["//path/to/xyz.mapping.json", # List of global instruction files. Depending on the instruction type, global instructions may be an addition to or have precedence over App Package specific instructions 54 | ], 55 | gradle_file = "//path/to/build.gradle", # The build.gradle file to run DvTeam with 56 | java_keystore_file = "//path/to/java_keystore/file", # Java KeyStore file with root certificates 57 | results = ["/path/to/myproject_dvteam_task_name-x.zip", # The DvTeam run output files 58 | "/path/to/myproject_dvteam_task_name-y.zip", 59 | "/path/to/myproject_dvteam_task_name-z.zip", 60 | ], 61 | sip = "@mysip//path/to/bsw_modules", # Microsar Classic location to mark it as a dependency 62 | task = "myDvTeamTask", # The DvTeam task that will be run 63 | wfconfig = "//path/to/wfconfig.json", # The wfconfig file 64 | ) 65 | 66 | ``` 67 | ## Dependencies 68 | 69 | The ```dvteam``` rule depends on a couple of other rules and toolchains. 70 | 71 | The dotnet [Bazel rules for .NET](https://github.com/bazel-contrib/rules_dotnet/tree/master) is used for the execution of the rule under Linux. 72 | 73 | In a ```MODULE.bazel``` file add this dependency as follows: 74 | 75 | ```python 76 | bazel_dep(name = "rules_dotnet", version = "0.17.5") # Tested with that version 77 | dotnet = use_extension("@rules_dotnet//dotnet:extensions.bzl", "dotnet") 78 | dotnet.toolchain(dotnet_version = "8.0.103") # Tested with that version 79 | use_repo(dotnet, "dotnet_toolchains") 80 | ``` 81 | 82 | The `DaVinci Developer`, `DaVinci Configurator 5` and `gradle` toolchains are used for the execution of the ```dvteam``` rule regardless of the OS. 83 | 84 | All toolchain configurations are typically configured within a `BUILD.bazel` file. 85 | 86 | Please see [DaVinci Developer toolchain definition](../toolchains.md#davinci-developer-toolchains), [DaVinci Configurator 5 toolchain definition](../toolchains.md#davinci-configurator-5-toolchains) and [Gradle toolchain definition](../toolchains.md#gradle-toolchains). -------------------------------------------------------------------------------- /rules/dvteam/rules.bzl: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2025 Vector Group 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining 6 | # a copy of this software and associated documentation files (the 7 | # "Software"), to deal in the Software without restriction, including 8 | # without limitation the rights to use, copy, modify, merge, publish, 9 | # distribute, sublicense, and/or sell copies of the Software, and to 10 | # permit persons to whom the Software is furnished to do so, subject to 11 | # the following conditions: 12 | 13 | # The above copyright notice and this permission notice shall be 14 | # included in all copies or substantial portions of the Software. 15 | 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | """Rules for dvteam""" 25 | 26 | load("//rules/common:create_davinci_tool_workspace.bzl", "create_davinci_tool_workspace") 27 | 28 | _DVTEAM_TEMPLATE_ENV_VAR_LINUX = """ 29 | export GRADLE_USER_HOME=$PWD/{gradle_properties_folder} && 30 | export DEVELOPER_PATH=$PWD/{developer_path}/DEVImEx/bin && 31 | export VTT_PATH=$PWD/{vtt_path} && 32 | export SIP=$PWD/{sip_folder} && 33 | export ROOT_CONFIG=$PWD/{workspace_path} && 34 | export EXECROOT=$PWD && 35 | export DOTNET_ROOT=$PWD/{dotnet_path} && 36 | """ 37 | 38 | _DVTEAM_TEMPLATE_ENV_VAR_WINDOWS = """ 39 | $env:GRADLE_USER_HOME="$PWD/{gradle_properties_folder}"; 40 | $env:DEVELOPER_PATH="{developer_path}"; 41 | $env:VTT_PATH="{vtt_path}"; 42 | $env:SIP="$PWD/{sip_folder}"; 43 | $env:ROOT_CONFIG="$PWD/{workspace_path}"; 44 | $env:EXECROOT=$PWD; 45 | """ 46 | 47 | # the copy is necessary because the vtt path will be updated with dvteam and this is usually not allowed in the bazel output folder 48 | _DVTEAM_TEMPLATE_LINUX = """ 49 | sudo chmod 777 $PWD/{exec_folder}/{workspace_prefix}/{dpa_basename}.dpa && 50 | {gradle_path} -Dorg.gradle.project.buildDir=$PWD/{gradle_exec_folder} -Pcom.vector.dvt.ci.config=$PWD/{wfconfig} clean -b {gradle_file_path} && 51 | {gradle_path} -Dorg.gradle.project.buildDir=$PWD/{gradle_exec_folder} -Pcom.vector.dvt.ci.config=$PWD/{wfconfig} {jks_value} --no-build-cache -b {gradle_file_path} {task} {dvteam_args} 52 | """ 53 | 54 | # template for running dvteam under windows and with bazel, needs specific paths to be set 55 | _DVTEAM_TEMPLATE_WINDOWS = 'Set-ItemProperty -Path "$PWD/{exec_folder}/{workspace_prefix}/{dpa_basename}.dpa" -Name IsReadOnly -Value $false; start-process "./{gradle_path}" -ArgumentList "--no-daemon -Dorg.gradle.project.buildDir=$PWD/{gradle_exec_folder} -Pcom.vector.dvt.ci.config=$PWD/{wfconfig} clean -b {gradle_file_path}" -Wait -NoNewWindow -RedirectStandardError "$PWD/{exec_folder}/{workspace_prefix}/gradle.errout.log" -RedirectStandardOutput "$PWD/{exec_folder}/{workspace_prefix}/gradle.output.log"; start-process "./{gradle_path}" -ArgumentList "--no-daemon -Dorg.gradle.project.buildDir=$PWD/{gradle_exec_folder} -Pcom.vector.dvt.ci.config=$PWD/{wfconfig} {jks_value} -b {gradle_file_path} {task} {dvteam_args}" -Wait -NoNewWindow -RedirectStandardError "$PWD/{exec_folder}/{workspace_prefix}/gradle.errout.log" -RedirectStandardOutput "$PWD/{exec_folder}/{workspace_prefix}/gradle.output.log"' 56 | 57 | def _dvteam_impl(ctx): 58 | # simple dvteam workspace dictionary that is created for further use 59 | dvt_workspace = create_davinci_tool_workspace(ctx, workspace_name = ctx.label.name + "_dvt_workspace", addtional_workspace_files = [ctx.file.dpa_file], is_windows = ctx.attr.private_is_windows, config_files = ctx.files.config_files, config_folders = ctx.attr.config_folders) 60 | 61 | info_davinci_developer = ctx.toolchains["//rules/davinci_developer:toolchain_type"] 62 | info_gradle = ctx.toolchains["//rules/gradle:toolchain_type"] 63 | tools = [] 64 | 65 | if not info_davinci_developer.davinci_developer_label and not info_davinci_developer.davinci_developer_path: 66 | fail("Developer toolchain is needed for DaVinci Team and needs either one of davinci_developer_label or davinci_developer_path defined") 67 | developer_path = info_davinci_developer.davinci_developer_label.path if info_davinci_developer.davinci_developer_label else info_davinci_developer.davinci_developer_path 68 | 69 | if info_davinci_developer.davinci_developer_label: 70 | tools.append(info_davinci_developer.davinci_developer_label) 71 | 72 | if not info_gradle.gradle_label and not info_gradle.gradle_path: 73 | fail("Gradle toolchain is needed for DaVinci Team and needs either one of gradle_label or gradle_path defined") 74 | gradle_path = info_gradle.gradle_label.path if info_gradle.gradle_label else info_gradle.gradle_path 75 | 76 | if info_gradle.gradle_label: 77 | tools.append(info_gradle.gradle_label) 78 | if info_gradle.gradle_properties: 79 | tools.append(info_gradle.gradle_properties) 80 | 81 | inputs = ctx.files.app_package_sources + ctx.files.config_files + [ctx.file.dpa_file] + [ctx.file.gradle_file] + ctx.files.global_instruction_files + ctx.files.custom_scripts 82 | 83 | workspace_prefix = dvt_workspace.workspace_prefix 84 | dpa_copy = dvt_workspace.addtional_workspace_files[0] 85 | dpa_basename = dpa_copy.basename.split(".")[0] 86 | 87 | # find path to BUILD file 88 | build_path = ctx.label.package 89 | 90 | # folder where gradle shall be executed, currently hardcoded execroot 91 | exec_folder = ctx.bin_dir.path + "/" + build_path 92 | gradle_exec_folder = ctx.bin_dir.path + "/" + build_path + "/" + ctx.label.name 93 | sip_folder = Label(ctx.attr.sip.label).workspace_root 94 | workspace_path = dpa_copy.dirname 95 | 96 | vtt_make_path = "" 97 | info_vtt = ctx.toolchains["//rules/vtt:toolchain_type"] 98 | if info_vtt and (ctx.toolchains["//rules/vtt:toolchain_type"].vtt_make_label or ctx.toolchains["//rules/vtt:toolchain_type"].vtt_make_path): 99 | vtt_make_path = info_vtt.vtt_make_label.dirname if info_vtt.vtt_make_label else info_vtt.vtt_make_path 100 | if vtt_make_path == info_vtt.vtt_make_path: 101 | vtt_make_path = info_vtt.vtt_make_path.split("/Exec64/VttMake.exe")[0] 102 | 103 | if info_vtt.vtt_make_label: 104 | tools.append(info_vtt.vtt_make_label) 105 | 106 | info_cfg5 = ctx.toolchains["//rules/cfg5:toolchain_type"] 107 | tools.append(info_cfg5.cfg5cli_path) 108 | 109 | # Dotnet path for developer in linux 110 | dotnet_path = "" 111 | if ctx.attr.private_is_windows == False: 112 | dotnet = ctx.toolchains["@rules_dotnet//dotnet:toolchain_type"] 113 | dotnet_path = dotnet.dotnetinfo.runtime_path.split("/dotnet")[0] 114 | tools.extend(dotnet.dotnetinfo.runtime_files) 115 | 116 | # Setup OpenJDK 117 | if ctx.attr.java_keystore_file: 118 | jks_value = "-Djavax.net.ssl.trustStore={} -Djavax.net.ssl.trustStorePassword={}".format( 119 | ctx.file.java_keystore_file.path, 120 | ctx.attr.java_keystore_password, 121 | ) 122 | else: 123 | jks_value = "" 124 | 125 | java_toolchain = ctx.toolchains["@bazel_tools//tools/jdk:toolchain_type"] 126 | java_home = java_toolchain.java.java_runtime.java_home 127 | 128 | # prepare dvt_template 129 | dvt_template = _DVTEAM_TEMPLATE_WINDOWS if ctx.attr.private_is_windows else _DVTEAM_TEMPLATE_LINUX 130 | gradle_cmd = dvt_template.format( 131 | gradle_path = gradle_path, 132 | exec_folder = exec_folder, 133 | gradle_exec_folder = gradle_exec_folder, 134 | wfconfig = ctx.file.wfconfig.path, 135 | gradle_file_path = ctx.file.gradle_file.path, 136 | task = ctx.attr.task, 137 | dvteam_args = " ".join(ctx.attr.dvteam_args), 138 | workspace_prefix = workspace_prefix, 139 | dpa_basename = dpa_basename, 140 | jks_value = jks_value, 141 | ) 142 | 143 | if info_gradle.gradle_properties.path and not ctx.attr.private_is_windows: 144 | gradle_cmd = _DVTEAM_TEMPLATE_ENV_VAR_LINUX.format( 145 | gradle_properties_folder = "/".join(info_gradle.gradle_properties.path.split("/")[:-1]), 146 | developer_path = developer_path.split("/DEVImEx/bin")[0], 147 | vtt_path = vtt_make_path, 148 | sip_folder = sip_folder, 149 | workspace_path = workspace_path, 150 | dotnet_path = dotnet_path, 151 | ) + gradle_cmd 152 | 153 | if info_gradle.gradle_properties.path and ctx.attr.private_is_windows: 154 | gradle_cmd = _DVTEAM_TEMPLATE_ENV_VAR_WINDOWS.format( 155 | gradle_properties_folder = "/".join(info_gradle.gradle_properties.path.split("/")[:-1]), 156 | developer_path = developer_path, 157 | vtt_path = vtt_make_path, 158 | sip_folder = sip_folder, 159 | workspace_path = workspace_path, 160 | ) + gradle_cmd 161 | 162 | # use powershell for the windows run of dvt instead 163 | if ctx.attr.private_is_windows: 164 | ctx.actions.run( 165 | mnemonic = "dvteamWindows", 166 | executable = "powershell.exe", 167 | progress_message = "Executing DVTeam @ %s" % ctx.file.gradle_file.path, 168 | tools = tools, 169 | arguments = [gradle_cmd], 170 | env = { 171 | "OS": "Windows_NT", 172 | "windir": "C:\\Windows", 173 | "SystemRoot": "C:\\Windows", 174 | "JAVA_HOME": java_home, 175 | }, 176 | inputs = inputs + dvt_workspace.files + [ctx.file.wfconfig] + dvt_workspace.addtional_workspace_files + ctx.attr.sip.files.to_list(), 177 | outputs = ctx.outputs.results, 178 | ) 179 | 180 | else: 181 | ctx.actions.run_shell( 182 | mnemonic = "dvteamLinux", 183 | progress_message = "Executing DVTeam @ %s" % ctx.file.gradle_file.path, 184 | tools = tools, 185 | command = gradle_cmd, 186 | inputs = inputs + dvt_workspace.files + [ctx.file.wfconfig] + dvt_workspace.addtional_workspace_files + ctx.attr.sip.files.to_list(), 187 | outputs = ctx.outputs.results, 188 | ) 189 | 190 | return [ 191 | DefaultInfo(files = depset(ctx.outputs.results)), 192 | ] 193 | 194 | dvteam_attrs = { 195 | "dvteam_args": attr.string_list(doc = "The args for the actual dvteam run"), 196 | "gradle_file": attr.label(mandatory = True, allow_single_file = True, doc = "the build.gradle to run dvteam with"), 197 | "task": attr.string(mandatory = True, doc = "The dvteam task that will be run"), 198 | "app_package_sources": attr.label_list(doc = "the additional app package sources that should be integrated"), 199 | "results": attr.output_list(mandatory = True, doc = "The dvteam run output config files"), 200 | "wfconfig": attr.label(mandatory = True, allow_single_file = [".json"], doc = "The prepared wfconfig file, can use substituted variables for DEVELOPER_PATH, VTT_PATH, EXECROOT and ROOT_CONFIG these will be filled out by bazel according to the toolchain info that is given"), 201 | "config_files": attr.label_list(allow_files = [".arxml", ".dcf", ".dvg", ".xml", ".dpa", ".zip", ".a2l", ".cdd"], doc = "The expected output files of DaVinci Team"), 202 | "global_instruction_files": attr.label_list(allow_files = [".json"], doc = "List of global instruction files. Depending on the instruction type, global instructions may be an addition to or have precedence over App Package specific instructions."), 203 | "custom_scripts": attr.label_list(allow_files = [".dvgroovy"], doc = "Costum Scipts, that can be exectued in dvteam"), 204 | "dpa_file": attr.label(mandatory = True, allow_single_file = [".dpa"], doc = "dpa file to use for the dvteam run"), 205 | "sip": attr.label(mandatory = True, doc = "sip location to mark it as a dependency, as it the sip is needed for dvteam execution"), 206 | "private_is_windows": attr.bool(mandatory = True, doc = "Set automatically for the correct OS"), 207 | # "A List of the folders where the config files reside, this cannot be detected automatically, as only the current package can be resolved elegantly" 208 | "config_folders": attr.string_list(doc = "(Optional) List of config folders that the path will be checked for in each file to create a nested Config folder structure, default is [\"Config\"]", default = ["Config"]), 209 | # Attributes to add a java keystore to the used jdk toolchain 210 | "java_keystore_file": attr.label(mandatory = False, allow_single_file = True, doc = "Java KeyStore file with root certificates."), 211 | "java_keystore_password": attr.string(mandatory = False, default = "changeit", doc = "Java KeyStore password. Default value is changeit"), 212 | } 213 | 214 | dvteam_def = rule( 215 | implementation = _dvteam_impl, 216 | attrs = dvteam_attrs, 217 | doc = "DaVinciTeam rule to run gradle in the background and add the output to bazel", 218 | toolchains = [ 219 | "//rules/davinci_developer:toolchain_type", 220 | "//rules/gradle:toolchain_type", 221 | "//rules/cfg5:toolchain_type", 222 | "@bazel_tools//tools/jdk:toolchain_type", 223 | config_common.toolchain_type("@rules_dotnet//dotnet:toolchain_type", mandatory = False), 224 | config_common.toolchain_type("//rules/vtt:toolchain_type", mandatory = False), 225 | ], 226 | ) 227 | 228 | def dvteam(name, **kwargs): 229 | """Wraps the dvteam with the private_is_windows select statement in place 230 | 231 | Args: 232 | name: The unique name of this target 233 | **kwargs: All of the attrs of the dvteam rule 234 | 235 | Returns: 236 | A dvteam_def rule that contains the actual implementation 237 | """ 238 | dvteam_def( 239 | name = name, 240 | private_is_windows = select({ 241 | "@bazel_tools//src/conditions:host_windows": True, 242 | "//conditions:default": False, 243 | }), 244 | **kwargs 245 | ) 246 | -------------------------------------------------------------------------------- /rules/gradle/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2025 Vector Group 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining 6 | # a copy of this software and associated documentation files (the 7 | # "Software"), to deal in the Software without restriction, including 8 | # without limitation the rights to use, copy, modify, merge, publish, 9 | # distribute, sublicense, and/or sell copies of the Software, and to 10 | # permit persons to whom the Software is furnished to do so, subject to 11 | # the following conditions: 12 | 13 | # The above copyright notice and this permission notice shall be 14 | # included in all copies or substantial portions of the Software. 15 | 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 25 | 26 | exports_files( 27 | glob( 28 | ["*"], 29 | ), 30 | ) 31 | 32 | toolchain_type( 33 | name = "toolchain_type", 34 | visibility = ["//visibility:public"], 35 | ) 36 | 37 | bzl_library( 38 | name = "rules", 39 | srcs = ["rules.bzl"], 40 | visibility = ["//visibility:public"], 41 | deps = ["@bazel_tools//tools/build_defs/repo:utils.bzl"], 42 | ) 43 | 44 | bzl_library( 45 | name = "toolchains", 46 | srcs = ["toolchains.bzl"], 47 | visibility = ["//visibility:public"], 48 | ) 49 | -------------------------------------------------------------------------------- /rules/gradle/README.md: -------------------------------------------------------------------------------- 1 | # Gradle 2 | This chapter contains Gradle related rules and toolchains documentation. These rules and toolchains are adapted to fit the needs for our Vector products which rely on gradle. 3 | 4 | 5 | 6 | ## generate_gradle_properties 7 | 8 | Usage in `BUILD.bazel` file: 9 | 10 |
11 | load("@//rules:defs.bzl", "generate_gradle_properties")
12 | 
13 | generate_gradle_properties(name, gradle_properties_content, netrc, repo_mapping, tokens)
14 | 
15 | 16 | **ATTRIBUTES** 17 | 18 | 19 | | Name | Description | Type | Mandatory | Default | 20 | | :------------- | :------------- | :------------- | :------------- | :------------- | 21 | | name | A unique name for this repository. | Name | required | | 22 | | gradle_properties_content | The content of the gradle.properties file before the tokens are added to it | String | optional | `""` | 23 | | netrc | Location of the .netrc file to use for authentication | String | optional | `""` | 24 | | repo_mapping | In `WORKSPACE` context only: a dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.

For example, an entry `"@foo": "@bar"` declares that, for any time this repository depends on `@foo` (such as a dependency on `@foo//some:target`, it should actually resolve that dependency within globally-declared `@bar` (`@bar//some:target`).

This attribute is _not_ supported in `MODULE.bazel` context (when invoking a repository rule inside a module extension's implementation function). | Dictionary: String -> String | optional | | 25 | | tokens | Map between tokens to generate and their respective url in the .netrc file | Dictionary: String -> String | required | | 26 | 27 | 28 | 29 | ## gradle_toolchain 30 | 31 | Usage in `BUILD.bazel` file: 32 | 33 |
34 | load("@//rules:defs.bzl", "gradle_toolchain")
35 | 
36 | gradle_toolchain(name, gradle_label, gradle_path, gradle_properties)
37 | 
38 | 39 | Simple gradle toolchain that is used for DaVinciTeam rules and others that rely on gradle 40 | 41 | **ATTRIBUTES** 42 | 43 | 44 | | Name | Description | Type | Mandatory | Default | 45 | | :------------- | :------------- | :------------- | :------------- | :------------- | 46 | | name | A unique name for this target. | Name | required | | 47 | | gradle_label | Optional label version of the gradle path, usually used when gradle is downloaded as an external package with bazel | Label | optional | `None` | 48 | | gradle_path | Optional path version of the gradle path, usually used when gradle is NOT downloaded as an external package with bazel | String | optional | `""` | 49 | | gradle_properties | optional gradle properties to use other than the default system one | Label | optional | `None` | 50 | 51 | 52 | # Example usage 53 | The following showcases an example on how to use a rule and toolchain in your Bazel project environment. 54 | 55 | ## Instantiate a repository rule 56 | 57 | In a ```MODULE.bazel``` file add this dependency as follows: 58 | 59 | ```python 60 | generate_gradle_properties = use_repo_rule("@vector_bazel_rules//rules:defs.bzl", "generate_gradle_properties") 61 | 62 | generate_gradle_properties( 63 | name = "gradle_properties", 64 | tokens = {"": ""}, 65 | ) 66 | ``` 67 | 68 | ## Configure a toolchain 69 | 70 | All toolchain configurations are typically configured within a `BUILD.bazel` file. 71 | 72 | Please see [Gradle toolchain definition](../toolchains.md#gradle-toolchains). 73 | 74 | -------------------------------------------------------------------------------- /rules/gradle/rules.bzl: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2025 Vector Group 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining 6 | # a copy of this software and associated documentation files (the 7 | # "Software"), to deal in the Software without restriction, including 8 | # without limitation the rights to use, copy, modify, merge, publish, 9 | # distribute, sublicense, and/or sell copies of the Software, and to 10 | # permit persons to whom the Software is furnished to do so, subject to 11 | # the following conditions: 12 | 13 | # The above copyright notice and this permission notice shall be 14 | # included in all copies or substantial portions of the Software. 15 | 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | """This repository rule will add the .netrc information to a freshly generated gradle.properties file for later use by other tools""" 25 | 26 | load("@bazel_tools//tools/build_defs/repo:utils.bzl", "read_netrc", "read_user_netrc") 27 | 28 | def _get_netrc_token(ctx, url): 29 | """Given the list of URLs obtain the correct auth dict.""" 30 | if ctx.attr.netrc: 31 | netrc = read_netrc(ctx, ctx.attr.netrc) 32 | elif "NETRC" in ctx.os.environ: 33 | netrc = read_netrc(ctx, ctx.os.environ["NETRC"]) 34 | else: 35 | netrc = read_user_netrc(ctx) 36 | return netrc[url]["password"] 37 | 38 | def _generate_gradle_properties_impl(repository_ctx): 39 | auth_tokens = repository_ctx.attr.gradle_properties_content 40 | 41 | for token in repository_ctx.attr.tokens: 42 | auth = _get_netrc_token( 43 | repository_ctx, 44 | repository_ctx.attr.tokens[token], 45 | ) 46 | auth_tokens += token + "=" + auth + "\n" 47 | 48 | repository_ctx.file("gradle.properties", auth_tokens) 49 | 50 | repository_ctx.file( 51 | "BUILD.bazel", 52 | """ 53 | package(default_visibility = ["//visibility:public"]) 54 | 55 | exports_files(glob(["**/*"])) 56 | 57 | filegroup( 58 | name = "package", 59 | srcs = glob([ 60 | "**/*", 61 | ]), 62 | ) 63 | 64 | toolchain_type( 65 | name = "toolchain_type", 66 | visibility = ["//visibility:public"], 67 | ) 68 | """, 69 | ) 70 | 71 | # Define the repository rule 72 | generate_gradle_properties = repository_rule( 73 | implementation = _generate_gradle_properties_impl, 74 | attrs = { 75 | "netrc": attr.string( 76 | doc = "Location of the .netrc file to use for authentication", 77 | mandatory = False, 78 | ), 79 | "tokens": attr.string_dict( 80 | doc = "Map between tokens to generate and their respective url in the .netrc file", 81 | mandatory = True, 82 | ), 83 | "gradle_properties_content": attr.string( 84 | default = "", 85 | doc = "The content of the gradle.properties file before the tokens are added to it", 86 | mandatory = False, 87 | ), 88 | }, 89 | local = True, 90 | ) -------------------------------------------------------------------------------- /rules/gradle/toolchains.bzl: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2025 Vector Group 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining 6 | # a copy of this software and associated documentation files (the 7 | # "Software"), to deal in the Software without restriction, including 8 | # without limitation the rights to use, copy, modify, merge, publish, 9 | # distribute, sublicense, and/or sell copies of the Software, and to 10 | # permit persons to whom the Software is furnished to do so, subject to 11 | # the following conditions: 12 | 13 | # The above copyright notice and this permission notice shall be 14 | # included in all copies or substantial portions of the Software. 15 | 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | """Toolchain for gradle""" 25 | 26 | def _gradle_toolchain_impl(ctx): 27 | toolchain_info = platform_common.ToolchainInfo( 28 | gradle_label = ctx.executable.gradle_label, 29 | gradle_path = ctx.attr.gradle_path, 30 | gradle_properties = ctx.file.gradle_properties, 31 | ) 32 | return [toolchain_info] 33 | 34 | gradle_toolchain = rule( 35 | implementation = _gradle_toolchain_impl, 36 | attrs = { 37 | "gradle_label": attr.label( 38 | mandatory = False, 39 | allow_single_file = True, 40 | cfg = "exec", 41 | executable = True, 42 | doc = "Optional label version of the gradle path, usually used when gradle is downloaded as an external package with bazel", 43 | ), 44 | "gradle_path": attr.string( 45 | mandatory = False, 46 | doc = "Optional path version of the gradle path, usually used when gradle is NOT downloaded as an external package with bazel", 47 | ), 48 | "gradle_properties": attr.label(mandatory = False, allow_single_file = True, executable = False, doc = "optional gradle properties to use other than the default system one"), 49 | }, 50 | doc = "Simple gradle toolchain that is used for DaVinciTeam rules and others that rely on gradle", 51 | ) 52 | -------------------------------------------------------------------------------- /rules/ocs/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2025 Vector Group 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining 6 | # a copy of this software and associated documentation files (the 7 | # "Software"), to deal in the Software without restriction, including 8 | # without limitation the rights to use, copy, modify, merge, publish, 9 | # distribute, sublicense, and/or sell copies of the Software, and to 10 | # permit persons to whom the Software is furnished to do so, subject to 11 | # the following conditions: 12 | 13 | # The above copyright notice and this permission notice shall be 14 | # included in all copies or substantial portions of the Software. 15 | 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 25 | 26 | exports_files( 27 | glob( 28 | ["*"], 29 | ), 30 | ) 31 | 32 | bzl_library( 33 | name = "rules", 34 | srcs = ["rules.bzl"], 35 | visibility = ["//visibility:public"], 36 | ) 37 | -------------------------------------------------------------------------------- /rules/ocs/README.md: -------------------------------------------------------------------------------- 1 | # OCS 2 | This chapter contains OCS related rules documentation. 3 | 4 | 5 | 6 | ## ocs 7 | 8 | Usage in `BUILD.bazel` file: 9 | 10 |
 11 | load("@//rules:defs.bzl", "ocs")
 12 | 
 13 | ocs(name, kwargs)
 14 | 
15 | 16 | **ATTRIBUTES** 17 | 18 | 19 | | Name | Description | Default Value | 20 | | :------------- | :------------- | :------------- | 21 | | name | The unique name of this target | none | 22 | | kwargs | All of the attrs of the ocs rule | none | 23 | 24 | 25 | 26 | 27 | 28 | ## cfg5_execute_script_task 29 | 30 | Usage in `BUILD.bazel` file: 31 | 32 |
 33 | load("@//rules:defs.bzl", "cfg5_execute_script_task")
 34 | 
 35 | cfg5_execute_script_task(name, kwargs)
 36 | 
37 | 38 | **ATTRIBUTES** 39 | 40 | | Name | Description | Default Value | 41 | | :------------- | :------------- | :------------- | 42 | | name |

-

| none | 43 | | kwargs |

-

| none | 44 | 45 | 46 | # Example usage 47 | 48 | The following showcases an example on how to use a rule in your Bazel project environment. 49 | 50 | ## Instantiate a rule 51 | 52 | In a `BUILD.bazel` file refer to the rules as follows: 53 | 54 | ```python 55 | ocs( 56 | name = "mycustom-plugins", # Name of the Bazel target 57 | davinci_project_files = ["/path/to/myproject_files", # Project files if a project is modified 58 | ], 59 | dpa_file = "path/to/myproject.dpa", # The dpa file if a project is modified and not created 60 | ocs_app = "path/to/myocs-app.jar", # The .jar file of the ocs app 61 | ocs_config_files = glob([ # The ocs plugin json files from ocs home directory 62 | "path/to/myconfig.json", 63 | ]), 64 | result = ["/path/to/output", # OCS run output files 65 | ], 66 | ) 67 | ``` 68 | 69 | ```python 70 | cfg5_execute_script_task( 71 | name = "execute-my-script", # Name of the Bazel target 72 | davinci_project_files = ["/path/to/myproject_files", # Project files if a project is modified 73 | ], 74 | dpa_file = "path/to/myproject.dpa", # The dpa project file 75 | script_task = "myscript-task", # Name of the script task 76 | script = "//path/to/my-script.jar", # The .jar or .dvgroovy file 77 | result = ["/path/to/output", # The run output files 78 | ], 79 | ) 80 | ``` 81 | 82 | ## Dependencies 83 | 84 | The ```ocs``` rule depends on a couple of other rules and toolchains. 85 | 86 | The dotnet [Bazel rules for .NET](https://github.com/bazel-contrib/rules_dotnet/tree/master) is used for the execution of the rule under Linux. 87 | 88 | In a ```MODULE.bazel``` file add this dependency as follows: 89 | 90 | ```python 91 | bazel_dep(name = "rules_dotnet", version = "0.17.5") # Tested with that version 92 | dotnet = use_extension("@rules_dotnet//dotnet:extensions.bzl", "dotnet") 93 | dotnet.toolchain(dotnet_version = "8.0.103") # Tested with that version 94 | use_repo(dotnet, "dotnet_toolchains") 95 | ``` 96 | 97 | The `DaVinci Developer` and `DaVinci Configurator 5` toolchains are used for the execution of the ```ocs``` and ```cfg5_execute_script_task``` rules regardless of the OS. 98 | 99 | All toolchain configurations are typically configured within a `BUILD.bazel` file. 100 | 101 | Please see [DaVinci Developer toolchain definition](../toolchains.md#davinci-developer-toolchains) and [DaVinci Configurator 5 toolchain definition](../toolchains.md#davinci-configurator-5-toolchains). 102 | -------------------------------------------------------------------------------- /rules/ocs/rules.bzl: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2025 Vector Group 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining 6 | # a copy of this software and associated documentation files (the 7 | # "Software"), to deal in the Software without restriction, including 8 | # without limitation the rights to use, copy, modify, merge, publish, 9 | # distribute, sublicense, and/or sell copies of the Software, and to 10 | # permit persons to whom the Software is furnished to do so, subject to 11 | # the following conditions: 12 | 13 | # The above copyright notice and this permission notice shall be 14 | # included in all copies or substantial portions of the Software. 15 | 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | """Rules for ocs""" 25 | 26 | load("//rules/common:copy_file.bzl", "copy_file") 27 | 28 | _OCS_TEMPLATE_ENV_VAR_LINUX = "export DOTNET_ROOT=$PWD/{dotnet_path} && " 29 | 30 | _CREATE_PROJECT_TEMPLATE_WINDOWS = """ 31 | (Get-Content -Path "{create_project_file}" -Raw | ConvertFrom-Json | ForEach-Object {{ $_.generalSettings.projectFolder = "$PWD/{create_project_dir}"; 32 | $_.developerWorkspace.developerExecutable = "{developer_path}"; 33 | $_ }}) | ConvertTo-Json -Depth 32 | Set-Content -Path "{create_project_file}"; 34 | """ 35 | 36 | _CREATE_PROJECT_TEMPLATE_LINUX = """ 37 | jsonContent=$(jq '.' "{create_project_file}") && 38 | jsonContent=$(echo "$jsonContent" | jq --arg pwd "$PWD" --arg dir "{create_project_dir}" '.generalSettings.projectFolder = "\\($pwd)/\\($dir)"') && 39 | jsonContent=$(echo "$jsonContent" | jq --arg pwd "$PWD" --arg dir "{developer_path}" '.developerWorkspace.developerExecutable = "\\($pwd)/\\($dir)"') && 40 | echo "$jsonContent" | jq '.' > "{create_project_file}" && 41 | """ 42 | 43 | _INPUTFILE_TEMPLATE_WINDOWS = """ 44 | $newPath = "{file_path}"; 45 | $jsonContent = Get-Content -Path "{inputfile_file}" -Raw | ConvertFrom-Json; 46 | $jsonContent.inputFiles | ForEach-Object {{ if ( ($_.path -split "/")[-1] -eq ($newPath -split "/")[-1] ) {{ $_.path = "$PWD/$newPath"; $_ }} }}; 47 | $jsonContent | ConvertTo-Json -Depth 32 | Set-Content -Path "{inputfile_file}"; 48 | """ 49 | 50 | _INPUTFILE_TEMPLATE_LINUX = """ 51 | newPath={file_path} && 52 | jsonContent=$(jq '.' {inputfile_file}) && 53 | jsonContent=$(echo "$jsonContent" | jq --arg newPath "$newPath" --arg pwd "$PWD" '.inputFiles |= map(if (.path | split("/")[-1] == ($newPath | split("/")[-1])) then .path = "\\($pwd)/\\($newPath)" else . end)') && 54 | echo $jsonContent | jq '.' > {inputfile_file} && 55 | """ 56 | 57 | _CFG5_SCRIPT_TEMPLATE_WINDOWS = """ 58 | exit (start-process -WorkingDirectory ./ -PassThru -NoNewWindow -RedirectStandardOutput {output_folder}/daVinciCfg5.log -Wait {cfg5cli_path} -ArgumentList '--scriptLocations {script_location} -s {script_task} {task_args} {cfg5_args} --verbose').ExitCode 59 | """ 60 | 61 | _CFG5_SCRIPT_TEMPLATE_LINUX = """ 62 | {cfg5cli_path} --scriptLocations {script_location} -s {script_task} {task_args} {cfg5_args} --verbose > {output_folder}/daVinciCfg5.log 63 | """ 64 | 65 | _REMOVE_WRITE_PROTECTION_TEMPLATE_WINDOWS = "Get-ChildItem -Path {} -Recurse | ForEach-Object {{ if ($_.PSIsContainer -eq $false -and $_.GetType().GetProperty('IsReadOnly')) {{ $_.IsReadOnly = $false }} }}; " 66 | 67 | _REMOVE_WRITE_PROTECTION_TEMPLATE_LINUX = "find {} -type f -exec chmod -v u+w {{}} \\; && " 68 | 69 | def _resolve_developer(ctx): 70 | info_davinci_developer = ctx.toolchains["//rules/davinci_developer:toolchain_type"] 71 | 72 | # linux and windows use different executables 73 | if ctx.attr.private_is_windows: 74 | if not info_davinci_developer.davinci_developer_label and not info_davinci_developer.davinci_developer_path: 75 | fail("Developer toolchain is needed for DaVinci Team and needs either one of davinci_developer_label or davinci_developer_path defined") 76 | developer_path = info_davinci_developer.davinci_developer_label.path if info_davinci_developer.davinci_developer_label else info_davinci_developer.davinci_developer_path + "/Bin/DaVinciDEV.exe" 77 | 78 | else: 79 | if not info_davinci_developer.davinci_developer_cmd_label: 80 | fail("Developer toolchain is needed for DaVinci Team and linux needs davinci_developer_cmd_label defined") 81 | developer_path = info_davinci_developer.davinci_developer_cmd_label.path 82 | 83 | return developer_path 84 | 85 | def _resolve_cfg5cli(ctx): 86 | info_davinci_configurator = ctx.toolchains["//rules/cfg5:toolchain_type"] 87 | 88 | if not info_davinci_configurator.cfg5cli_path: 89 | fail("Cfg5 toolchain is needed for OCS and needs cfg5cli_path defined") 90 | cfg5cli = info_davinci_configurator.cfg5cli_path.path 91 | 92 | return cfg5cli 93 | 94 | def _format_createproject(ctx, ocs_config): 95 | # modify the location of the created project in the json file 96 | create_project_file_path = "CreateProject.json" 97 | project_dir = ctx.outputs.result[0].dirname.split("/" + ctx.label.name)[0] + "/" + ctx.label.name 98 | 99 | developer_path = _resolve_developer(ctx) 100 | 101 | for file in ocs_config: 102 | if (file.basename == create_project_file_path): 103 | create_project_file_path = file.path 104 | 105 | create_project_template = _CREATE_PROJECT_TEMPLATE_WINDOWS if ctx.attr.private_is_windows else _CREATE_PROJECT_TEMPLATE_LINUX 106 | 107 | create_project_cmd = create_project_template.format( 108 | create_project_file = create_project_file_path, 109 | create_project_dir = project_dir, 110 | developer_path = developer_path, 111 | ) 112 | 113 | return create_project_cmd 114 | 115 | def _format_inputfiles_update(ctx, ocs_config): 116 | # modify the location of the inputfiles in the json file 117 | inputfile_cmd = "" 118 | inputfile_update_file_path = "InputFilesUpdate.json" 119 | 120 | for file in ocs_config: 121 | if (file.basename == inputfile_update_file_path): 122 | inputfile_update_file_path = file.path 123 | 124 | inputfile_template = _INPUTFILE_TEMPLATE_WINDOWS if ctx.attr.private_is_windows else _INPUTFILE_TEMPLATE_LINUX 125 | 126 | for file in ctx.files.input_files: 127 | inputfile_cmd += inputfile_template.format( 128 | inputfile_file = inputfile_update_file_path, 129 | file_path = file.path, 130 | ) 131 | 132 | return inputfile_cmd 133 | 134 | def _copy_config(ctx): 135 | workspace_name = ctx.label.name 136 | 137 | command = "" 138 | command_separator = " ;" if ctx.attr.private_is_windows else " &&" 139 | 140 | # copies the dpa file and removes the write protection 141 | dpa_copy = ctx.actions.declare_file(workspace_name + "/" + ctx.file.dpa_file.basename) 142 | command += "cp {} {}{} ".format(ctx.file.dpa_file.path, dpa_copy.path, command_separator) 143 | 144 | config_output = [] 145 | 146 | # this copies all the config files 147 | for file in ctx.files.davinci_project_files: 148 | # this will put the config files inside the Config folder, this might need to be changed later on 149 | # but is needed to make sure that no deep paths are created in the workspace creation phase 150 | base_path = file.path.removeprefix(ctx.file.dpa_file.dirname) 151 | config_out = ctx.actions.declare_file(workspace_name + "/" + base_path) 152 | 153 | config_output.append(config_out) 154 | command += "cp {} {}{} ".format(file.path, config_out.path, command_separator) 155 | 156 | # Remove the write protection from the project 157 | if ctx.attr.private_is_windows: 158 | command += _REMOVE_WRITE_PROTECTION_TEMPLATE_WINDOWS.format(dpa_copy.dirname) 159 | else: 160 | command += _REMOVE_WRITE_PROTECTION_TEMPLATE_LINUX.format(dpa_copy.dirname) 161 | 162 | return [command, dpa_copy] 163 | 164 | def _ocs_impl(ctx): 165 | inputs = ctx.files.davinci_project_files + ctx.files.ocs_config_files + [ctx.file.ocs_app] + ctx.files.input_files 166 | output_folder = "{}/{}".format(ctx.bin_dir.path, ctx.label.name) 167 | cfg5_args = ctx.attr.cfg5_args 168 | ocs_args = "" 169 | dotnet_path = "" 170 | additional_cmds = "" 171 | config_file_names = [f.basename for f in ctx.files.ocs_config_files] 172 | 173 | # OCS home is one dir out of the plugins json files 174 | if (ctx.files.ocs_config_files != []): 175 | # Copy the ocs config files so that they can be modified without destroying cache hits 176 | workspace_name = ctx.label.name + "_ws" 177 | ocs_workspace = [] 178 | for file in ctx.files.ocs_config_files: 179 | base_path = file.path.removeprefix("{}/{}".format(ctx.bin_dir.path, ctx.label.name)) 180 | ocs_config_file = ctx.actions.declare_file(workspace_name + "/" + base_path) 181 | 182 | ocs_workspace.append(ocs_config_file) 183 | copy_file(ctx, file, ocs_config_file, ctx.attr.private_is_windows) 184 | 185 | inputs += ocs_workspace 186 | 187 | if ctx.attr.private_is_windows: 188 | additional_cmds += _REMOVE_WRITE_PROTECTION_TEMPLATE_WINDOWS.format(ocs_workspace[0].dirname) 189 | else: 190 | additional_cmds += _REMOVE_WRITE_PROTECTION_TEMPLATE_LINUX.format(ocs_workspace[0].dirname) 191 | 192 | if ("CreateProject.json" in config_file_names): 193 | additional_cmds += _format_createproject(ctx, ocs_workspace) 194 | 195 | # Dotnet path for developer in linux, only needed for project creation 196 | if (ctx.attr.private_is_windows == False): 197 | dotnet_path = ctx.toolchains["@rules_dotnet//dotnet:toolchain_type"].dotnetinfo.runtime_path.split("/dotnet")[0] 198 | 199 | if ("InputFilesUpdate.json" in config_file_names): 200 | additional_cmds += _format_inputfiles_update(ctx, ocs_workspace) 201 | 202 | ocs_args += '"--home {}"'.format(ocs_workspace[0].dirname.split("/plugins")[0]) 203 | 204 | if (ctx.file.dpa_file): 205 | inputs.append(ctx.file.dpa_file) 206 | cp_command, dpa_copy = _copy_config(ctx) 207 | additional_cmds += cp_command 208 | 209 | if ("CreateProject.json" not in config_file_names): 210 | # When a dpa file is specified we load the config directly, so that the CreateProject.json does not have to be specified. 211 | cfg5_args += " -p {}".format(dpa_copy.path) 212 | 213 | cf5gcli = _resolve_cfg5cli(ctx) 214 | 215 | if (ocs_args): 216 | ocs_args = "--taskArgs {}".format(ocs_args) 217 | 218 | if (ctx.attr.private_is_windows): 219 | cmd_template = _CFG5_SCRIPT_TEMPLATE_WINDOWS 220 | else: 221 | cmd_template = _CFG5_SCRIPT_TEMPLATE_LINUX 222 | 223 | command = cmd_template.format( 224 | cfg5cli_path = cf5gcli, 225 | output_folder = output_folder, 226 | script_location = ctx.file.ocs_app.dirname, 227 | script_task = "OCS", 228 | task_args = ocs_args, 229 | cfg5_args = cfg5_args.replace("$(OUTS)", output_folder), 230 | ) 231 | concatenated_cmd = additional_cmds + command 232 | 233 | if (ctx.attr.private_is_windows): 234 | ctx.actions.run( 235 | mnemonic = "ocsWindows", 236 | executable = "powershell.exe", 237 | progress_message = "Executing OCS script %s" % ctx.file.ocs_app.dirname, 238 | arguments = [concatenated_cmd], 239 | env = { 240 | "CommonProgramFiles": "C:\\Program Files (x86)\\Common Files", # Path to common shared lib from cfg5 external dependencies 241 | "OS": "Windows_NT", 242 | "windir": "C:\\Windows", 243 | "SystemRoot": "C:\\Windows", 244 | }, 245 | inputs = inputs, 246 | outputs = ctx.outputs.result, 247 | ) 248 | 249 | else: 250 | env_vars = _OCS_TEMPLATE_ENV_VAR_LINUX.format(dotnet_path = dotnet_path) 251 | ctx.actions.run_shell( 252 | mnemonic = "ocsLinux", 253 | progress_message = "Executing OCS script %s" % ctx.file.ocs_app.dirname, 254 | command = env_vars + concatenated_cmd, 255 | inputs = inputs, 256 | outputs = ctx.outputs.result, 257 | ) 258 | 259 | return [ 260 | DefaultInfo(files = depset(ctx.outputs.result)), 261 | ] 262 | 263 | ocs_attrs = { 264 | "cfg5_args": attr.string(doc = "Additional arguments for the cfg5 run"), 265 | "ocs_app": attr.label(allow_single_file = True, doc = "The .jar file of the ocs app"), 266 | "dpa_file": attr.label(mandatory = False, allow_single_file = True, doc = "The .dpa file if a project is modified and not created"), 267 | "input_files": attr.label_list(allow_empty = True, allow_files = [".arxml", ".cdd", ".dbc"], doc = "Inputfiles if inputfile update is executed"), 268 | "davinci_project_files": attr.label_list(allow_empty = True, allow_files = True, doc = "Project files if a project is modified"), 269 | "ocs_config_files": attr.label_list(allow_empty = True, allow_files = [".json"], doc = "The ocs plugin json files from ocs home directory"), 270 | "private_is_windows": attr.bool(mandatory = True, doc = "Set automatically for the correct OS"), 271 | "result": attr.output_list(mandatory = True, doc = "OCS run output files"), 272 | } 273 | 274 | ocs_def = rule( 275 | implementation = _ocs_impl, 276 | attrs = ocs_attrs, 277 | doc = """Run the cfg5 and execute the OCS as script task. Can be used to create a project or to run on an existing one. 278 | $(OUTS) variable can be used in cfg5_args to be replaced with the output directory of the rule. 279 | This rule is wrapped with private_is_windows attribute to separate between OS differences. 280 | """, 281 | toolchains = [ 282 | "//rules/davinci_developer:toolchain_type", 283 | "//rules/cfg5:toolchain_type", 284 | config_common.toolchain_type("@rules_dotnet//dotnet:toolchain_type", mandatory = False), 285 | ], 286 | ) 287 | 288 | def ocs(name, **kwargs): 289 | ocs_def( 290 | name = name, 291 | private_is_windows = select({ 292 | "@bazel_tools//src/conditions:host_windows": True, 293 | "//conditions:default": False, 294 | }), 295 | **kwargs 296 | ) 297 | 298 | def _cfg5_execute_script_task_impl(ctx): 299 | inputs = ctx.files.davinci_project_files + [ctx.file.script] 300 | 301 | output_folder = "{}/{}".format(ctx.bin_dir.path, ctx.label.name) 302 | additional_command = "" 303 | 304 | cf5gcli = _resolve_cfg5cli(ctx) 305 | cfg5_args = ctx.attr.cfg5_args 306 | 307 | task_args = ctx.attr.task_args.replace("$(OUTS)", output_folder) 308 | if (task_args): 309 | task_args = "--taskArgs {}".format(task_args) 310 | 311 | if (ctx.attr.private_is_windows): 312 | cmd_template = _CFG5_SCRIPT_TEMPLATE_WINDOWS 313 | else: 314 | cmd_template = _CFG5_SCRIPT_TEMPLATE_LINUX 315 | 316 | # Load the project if a .dpa is specified 317 | if (ctx.file.dpa_file): 318 | inputs = [ctx.file.dpa_file] 319 | additional_command, dpa_copy = _copy_config(ctx) 320 | cfg5_args += " -p {}".format(dpa_copy.path) 321 | 322 | command = cmd_template.format( 323 | cfg5cli_path = cf5gcli, 324 | output_folder = output_folder, 325 | script_location = ctx.file.script.dirname, 326 | script_task = ctx.attr.script_task, 327 | task_args = task_args, 328 | cfg5_args = cfg5_args.replace("$(OUTS)", output_folder), 329 | ) 330 | 331 | if ctx.attr.private_is_windows: 332 | ctx.actions.run( 333 | mnemonic = "cfg5ScriptWindows", 334 | executable = "powershell.exe", 335 | progress_message = "Executing script task %s" % ctx.attr.script_task, 336 | arguments = [additional_command + command], 337 | env = { 338 | "CommonProgramFiles": "C:\\Program Files (x86)\\Common Files", # Path to common shared lib from cfg5 external dependencies 339 | "OS": "Windows_NT", 340 | "windir": "C:\\Windows", 341 | "SystemRoot": "C:\\Windows", 342 | }, 343 | inputs = inputs, 344 | outputs = ctx.outputs.result, 345 | ) 346 | 347 | else: 348 | ctx.actions.run_shell( 349 | mnemonic = "cfg5ScriptLinux", 350 | progress_message = "Executing script task %s" % ctx.attr.script_task, 351 | command = additional_command + command, 352 | inputs = inputs, 353 | outputs = ctx.outputs.result, 354 | ) 355 | 356 | return [ 357 | DefaultInfo(files = depset(ctx.outputs.result)), 358 | ] 359 | 360 | cfg5_script_task_attrs = { 361 | "cfg5_args": attr.string(doc = "Additional arguments for the cfg5 run"), 362 | "script_task": attr.string(doc = "Name of the script task"), 363 | "task_args": attr.string(doc = "Script task arguments"), 364 | "script": attr.label(mandatory = True, allow_single_file = True, doc = "The .jar/.dvgroovy file"), 365 | "dpa_file": attr.label(mandatory = False, allow_single_file = True, doc = "The .dpa project file"), 366 | "davinci_project_files": attr.label_list(allow_empty = True, allow_files = True, doc = "Project files if a project is modified"), 367 | "private_is_windows": attr.bool(mandatory = True, doc = "Set automatically to the correct OS value"), 368 | "result": attr.output_list(mandatory = True, doc = "OCS run output files"), 369 | } 370 | 371 | cfg5_execute_script_task_def = rule( 372 | implementation = _cfg5_execute_script_task_impl, 373 | attrs = cfg5_script_task_attrs, 374 | doc = """Run the cfg5 and execute a script task. 375 | $(OUTS) variable can be used in cfg5_args and task_args to be replaced with the output directory of the rule. 376 | This rule is wrapped with private_is_windows attribute to separate between OS differences. 377 | """, 378 | toolchains = ["//rules/cfg5:toolchain_type"], 379 | ) 380 | 381 | def cfg5_execute_script_task(name, **kwargs): 382 | cfg5_execute_script_task_def( 383 | name = name, 384 | private_is_windows = select({ 385 | "@bazel_tools//src/conditions:host_windows": True, 386 | "//conditions:default": False, 387 | }), 388 | **kwargs 389 | ) 390 | -------------------------------------------------------------------------------- /rules/toolchains.md: -------------------------------------------------------------------------------- 1 | # Bazel Toolchains 2 | 3 | All toolchain configurations are typically configured within a `BUILD.bazel` file. 4 | 5 | ## DaVinci Configurator 5 toolchains 6 | 7 | ### Execution under Linux 8 | 9 | ```python 10 | cfg5_toolchain( 11 | name = "cfg5_linux_impl", 12 | cfg5_files = "@sip//:DaVinci_Configurator_5", # External dependency to the Microsar Classic product 13 | cfg5cli_path = "@sip//:DaVinciConfigurator/Core/DVCfgCmd", # External dependency to the DaVinci Configurator 5 CLI tool 14 | ) 15 | 16 | toolchain( 17 | name = "cfg5_linux", 18 | exec_compatible_with = [ 19 | "@platforms//os:linux", 20 | ], 21 | target_compatible_with = [ 22 | "@platforms//os:linux", 23 | ], 24 | toolchain = ":cfg5_linux_impl", 25 | toolchain_type = "@vector_bazel_rules//rules/cfg5:toolchain_type", 26 | ) 27 | ``` 28 | 29 | ### Execution under Windows 30 | 31 | ```python 32 | cfg5_toolchain( 33 | name = "cfg5_windows_impl", 34 | cfg5_files = "@sip//:DaVinci_Configurator_5", # External dependency to the Microsar Classic product 35 | cfg5_path = "@sip//:DaVinciConfigurator/Core/DaVinciCFG.exe", # External dependency to the DaVinci Configurator 5 GUI tool 36 | cfg5cli_path = "@sip//:DaVinciConfigurator/Core/DVCfgCmd.exe", # External dependency to the DaVinci Configurator 5 CLI tool 37 | ) 38 | 39 | toolchain( 40 | name = "cfg5_windows", 41 | exec_compatible_with = [ 42 | "@platforms//os:windows", 43 | ], 44 | target_compatible_with = [ 45 | "@platforms//os:windows", 46 | ], 47 | toolchain = ":cfg5_windows_impl", 48 | toolchain_type = "@vector_bazel_rules//rules/cfg5:toolchain_type", 49 | ) 50 | ``` 51 | 52 | ## DaVinci Developer toolchains 53 | 54 | ### Execution under Linux 55 | 56 | ```python 57 | davinci_developer_toolchain( 58 | name = "davinci_developer_linux_impl", 59 | davinci_developer_label = "@davinci_developer_linux//:DEVImEx/bin/DVImEx", # External dependency to the DaVinci Developer CLI tool 60 | ) 61 | 62 | toolchain( 63 | name = "davinci_developer_linux", 64 | exec_compatible_with = [ 65 | "@platforms//os:linux", 66 | ], 67 | target_compatible_with = [ 68 | "@platforms//os:linux", 69 | ], 70 | toolchain = ":davinci_developer_linux_impl", 71 | toolchain_type = "@vector_bazel_rules//rules/davinci_developer:toolchain_type", 72 | ) 73 | ``` 74 | 75 | ### Execution under Windows 76 | 77 | ```python 78 | davinci_developer_toolchain( 79 | name = "davinci_developer_windows_impl", 80 | davinci_developer_path = "X:/Path/To/DaVinci_Developer_Classic/Vx_yz", 81 | ) 82 | 83 | toolchain( 84 | name = "davinci_developer_windows", 85 | exec_compatible_with = [ 86 | "@platforms//os:windows", 87 | ], 88 | target_compatible_with = [ 89 | "@platforms//os:windows", 90 | ], 91 | toolchain = ":davinci_developer_windows_impl", 92 | toolchain_type = "@vector_bazel_rules//rules/davinci_developer:toolchain_type", 93 | ) 94 | ``` 95 | 96 | ## Gradle toolchains 97 | 98 | ### Execution under Linux 99 | 100 | ```python 101 | gradle_toolchain( 102 | name = "gradle_linux_impl", 103 | gradle_label = "@gradle//:bin/gradle", 104 | gradle_properties = "@gradle_properties//:gradle.properties", 105 | ) 106 | 107 | toolchain( 108 | name = "gradle_linux", 109 | exec_compatible_with = [ 110 | "@platforms//os:linux", 111 | ], 112 | target_compatible_with = [ 113 | "@platforms//os:linux", 114 | ], 115 | toolchain = ":gradle_linux_impl", 116 | toolchain_type = "@vector_bazel_rules//rules/gradle:toolchain_type", 117 | ) 118 | ``` 119 | 120 | ### Execution under Windows 121 | 122 | ```python 123 | gradle_toolchain( 124 | name = "gradle_windows_impl", 125 | gradle_label = "@gradle//:bin/gradle.bat", 126 | gradle_properties = "@gradle_properties//:gradle.properties", # Instanciated in MODULE.bazel file 127 | ) 128 | 129 | toolchain( 130 | name = "gradle_windows", 131 | exec_compatible_with = [ 132 | "@platforms//os:windows", 133 | ], 134 | target_compatible_with = [ 135 | "@platforms//os:windows", 136 | ], 137 | toolchain = ":gradle_windows_impl", 138 | toolchain_type = "@vector_bazel_rules//rules/gradle:toolchain_type", 139 | ) 140 | ``` --------------------------------------------------------------------------------