├── .bazelci ├── examples_naming.yml ├── examples_rich_structure.yml ├── examples_stamping.yml ├── integration.yml ├── presubmit.yml └── tests.yml ├── .bazelignore ├── .bazelrc ├── .bcr ├── README.md ├── config.yml ├── metadata.template.json ├── presubmit.yml └── source.template.json ├── .github └── workflows │ ├── pre-commit.yml │ └── scorecard.yml ├── .gitignore ├── .pre-commit-config.yaml ├── .typos.toml ├── AUTHORS ├── BUILD ├── CHANGELOG.md ├── CODEOWNERS ├── CONTRIBUTING.md ├── CONTRIBUTORS ├── LICENSE ├── MODULE.bazel ├── README.md ├── WORKSPACE ├── WORKSPACE.bzlmod ├── deps.bzl ├── developers.md ├── distro ├── BUILD ├── __init__.py ├── packaging_test.py └── testdata │ └── BUILD.tpl ├── doc_build ├── BUILD ├── common.md ├── merge.py └── toc.md.tpl ├── docs ├── 0.10.0 │ └── reference.md ├── 0.4.0 │ └── reference.md ├── 0.5.0 │ └── reference.md ├── 0.6.0 │ └── reference.md ├── 0.7.0 │ └── reference.md ├── 0.8.0 │ └── reference.md ├── 0.9.1 │ └── reference.md ├── 1.0.1 │ └── reference.md ├── 1.1.0 │ └── reference.md ├── _config.yml ├── _includes │ ├── head-custom.html │ └── head.html ├── favicon.ico ├── index.md ├── latest.md ├── pkg_deb.md └── robots.txt ├── examples ├── BUILD ├── naming_package_files │ ├── BUILD │ ├── MODULE.bazel │ ├── my_package_name.bzl │ ├── package_upload.bzl │ └── readme.md ├── readme.md ├── rich_structure │ ├── BUILD │ ├── MODULE.bazel │ ├── README.md │ ├── README.txt │ ├── copyright │ ├── docs │ │ ├── BUILD │ │ ├── index.md │ │ ├── reference │ │ │ └── index.md │ │ └── user_guide.md │ ├── foo_defs.bzl │ ├── resources │ │ └── l10n │ │ │ ├── BUILD │ │ │ ├── foo │ │ │ ├── en │ │ │ │ └── msg.cat │ │ │ └── it │ │ │ │ └── msg.cat │ │ │ ├── fooctl │ │ │ ├── en │ │ │ │ └── msg.cat │ │ │ └── it │ │ │ │ └── msg.cat │ │ │ └── food │ │ │ ├── en │ │ │ └── msg.cat │ │ │ └── it │ │ │ └── msg.cat │ └── src │ │ ├── client │ │ ├── BUILD │ │ ├── bar.rules │ │ ├── baz.rules │ │ ├── foo.1 │ │ ├── foo.cc │ │ ├── foo.h │ │ ├── foocore.cc │ │ └── fooctl.cc │ │ └── server │ │ ├── BUILD │ │ ├── foo.h │ │ ├── foocore.cc │ │ ├── food.8 │ │ └── food.cc ├── rpm │ ├── debuginfo │ │ ├── BUILD │ │ ├── MODULE.bazel │ │ ├── README.md │ │ └── test.c │ ├── nospecfile │ │ ├── BUILD │ │ ├── MODULE.bazel │ │ └── README.md │ ├── prebuilt_rpmbuild │ │ ├── BUILD │ │ ├── README.md │ │ ├── WORKSPACE │ │ ├── local │ │ │ ├── BUILD │ │ │ ├── rpmbuild.bzl │ │ │ └── rpmbuild_binary │ │ └── test_rpm.spec │ ├── subrpm │ │ ├── BUILD │ │ ├── MODULE.bazel │ │ └── README.md │ ├── system_rpmbuild │ │ ├── BUILD │ │ ├── README.md │ │ ├── WORKSPACE │ │ └── test_rpm.spec │ └── system_rpmbuild_bzlmod │ │ ├── BUILD │ │ ├── MODULE.bazel │ │ ├── README.md │ │ └── test_rpm.spec ├── time_stamping │ ├── BUILD │ ├── MODULE.bazel │ └── readme.md └── where_is_my_output │ ├── BUILD │ ├── MODULE.bazel │ ├── README.md │ └── show_all_outputs.bzl ├── mappings.bzl ├── patching.md ├── pkg.bzl ├── pkg ├── .bazelignore ├── BUILD ├── __init__.py ├── deb.bzl ├── deps.bzl ├── filter_directory.py ├── install.bzl ├── legacy │ ├── BUILD │ ├── rpm.bzl │ └── tests │ │ └── rpm │ │ ├── BUILD │ │ └── test_rpm.spec ├── make_rpm.py ├── mappings.bzl ├── package_variables.bzl ├── path.bzl ├── pkg.bzl ├── private │ ├── BUILD │ ├── __init__.py │ ├── archive.py │ ├── build_info.py │ ├── deb │ │ ├── BUILD │ │ ├── deb.bzl │ │ └── make_deb.py │ ├── helpers.py │ ├── install.py.tpl │ ├── make_starlark_library.bzl │ ├── manifest.py │ ├── pkg_files.bzl │ ├── tar │ │ ├── BUILD │ │ ├── build_tar.py │ │ ├── tar.bzl │ │ └── tar_writer.py │ ├── util.bzl │ └── zip │ │ ├── BUILD │ │ ├── __init__.py │ │ ├── build_zip.py │ │ └── zip.bzl ├── providers.bzl ├── releasing │ ├── BUILD │ ├── __init__.py │ ├── defs.bzl │ ├── git.bzl │ ├── git_changelog_private.py │ ├── print_rel_notes.py │ ├── release_tools.py │ └── release_tools_test.py ├── rpm.bzl ├── rpm │ ├── BUILD │ ├── augment_rpm_files_install.py │ └── template.spec.tpl ├── rpm_pfg.bzl ├── tar.bzl ├── verify_archive.bzl ├── verify_archive_test_main.py.tpl └── zip.bzl ├── tests ├── BUILD ├── a.cc ├── archive_test.py ├── b.cc ├── deb │ ├── BUILD │ ├── config │ ├── control_field_test.py │ ├── deb_preinst │ ├── deb_tests.bzl │ ├── deb_triggers │ ├── pkg_deb_test.py │ └── templates ├── foo.cc ├── helpers_test.py ├── install │ ├── BUILD │ └── test.py ├── mappings │ ├── BUILD │ ├── all.manifest.golden │ ├── executable.manifest.golden │ ├── executable.manifest.windows.golden │ ├── external_repo │ │ ├── MODULE.bazel │ │ ├── WORKSPACE │ │ └── pkg │ │ │ ├── BUILD │ │ │ ├── dir │ │ │ └── extproj.sh │ │ │ └── test.bzl │ ├── filter_directory │ │ ├── BUILD │ │ ├── defs.bzl │ │ ├── inspect_directory.py.tpl │ │ └── test_filter_directory.py │ ├── glob_for_texts_manifest.golden │ ├── manifest_test_lib.py │ ├── manifest_test_main.py.tpl │ ├── mappings_external_repo_test.bzl │ ├── mappings_test.bzl │ ├── node_modules_manifest.golden │ ├── testdata │ │ ├── a_script.sh │ │ ├── config │ │ └── hello.txt │ └── utf8_manifest.golden ├── my_package_name.bzl ├── package_naming_aggregate_test.sh ├── path_test.bzl ├── path_test.py ├── rpm │ ├── BUILD │ ├── analysis_tests.bzl │ ├── make_rpm_test.py │ ├── pkg_rpm_basic_test.py │ ├── rpm_util.py │ ├── source_date_epoch │ │ ├── BUILD │ │ ├── epoch.txt │ │ └── rpm_contents_vs_manifest_test.py │ ├── template-test.spec.tpl │ ├── test.c │ ├── test_debuginfo_rpm_contents.txt.golden │ ├── test_rpm_dirs_contents.txt.golden │ ├── test_sub_rpm_contents.txt.golden │ ├── toolchain_tests.bzl │ └── tree_artifacts │ │ ├── BUILD │ │ ├── rpm_contents_vs_manifest_test.py │ │ └── rpm_treeartifact_ops_test.py ├── stamp_test.py ├── tar │ ├── BUILD │ ├── compressor.py │ ├── defs.bzl │ ├── is_compressed_test.py │ ├── pkg_tar_test.py │ └── tar_writer_test.py ├── testdata │ ├── README.md │ ├── a.ar │ ├── a_ab.ar │ ├── a_b.ar │ ├── a_b_ab.ar │ ├── ab.ar │ ├── b.ar │ ├── config │ ├── deb_preinst │ ├── deb_triggers │ ├── duplicate_entries.tar │ ├── empty.ar │ ├── executable.sh │ ├── file_with_a_ridiculously_long_name_consectetur_adipiscing_elit_fusce_laoreet_lorem_neque_sed_pharetra_erat.txt │ ├── hello.txt │ ├── loremipsum.txt │ ├── outer_BUILD │ ├── tar_test.tar │ ├── tar_test.tar.bz2 │ ├── tar_test.tar.gz │ ├── tar_test.tar.xz │ ├── templates │ ├── test_tar_package_dir_file.txt │ ├── utf8 │ │ ├── 1-a │ │ ├── 2-λ │ │ ├── 3-世 │ │ ├── BUILD │ │ └── sübdir │ │ │ ├── 2-λ │ │ │ └── hello │ ├── utf8_linux.tar │ ├── utf8_linux.zip │ ├── utf8_mac.tar │ ├── utf8_mac.zip │ ├── utf8_win.tar │ └── utf8_win.zip ├── util │ ├── BUILD │ ├── create_directory_with_contents.py │ ├── defs.bzl │ └── md5.py ├── verify_archive │ └── BUILD └── zip │ ├── BUILD │ ├── unicode_test.py │ ├── zip_byte_for_byte_test.py │ ├── zip_test.py │ └── zip_test_lib.py ├── toolchains ├── BUILD ├── git │ ├── BUILD │ ├── BUILD.tpl │ ├── git.bzl │ └── git_configure.bzl └── rpm │ ├── BUILD │ ├── BUILD.tpl │ ├── rpmbuild.bzl │ └── rpmbuild_configure.bzl └── version.bzl /.bazelci/examples_naming.yml: -------------------------------------------------------------------------------- 1 | common: &common 2 | working_directory: ../examples/naming_package_files 3 | build_targets: 4 | - "..." 5 | 6 | tasks: 7 | centos7: 8 | platform: centos7_java11_devtoolset10 9 | <<: *common 10 | ubuntu2204: 11 | platform: ubuntu2204 12 | <<: *common 13 | macos: 14 | platform: macos 15 | <<: *common 16 | windows: 17 | platform: windows 18 | <<: *common 19 | bzlmod: 20 | name: bzlmod 21 | platform: ubuntu2204 22 | build_flags: 23 | - "--enable_bzlmod" 24 | <<: *common 25 | -------------------------------------------------------------------------------- /.bazelci/examples_rich_structure.yml: -------------------------------------------------------------------------------- 1 | common: &common 2 | working_directory: ../examples/rich_structure 3 | build_targets: 4 | - "..." 5 | 6 | tasks: 7 | centos7: 8 | platform: centos7_java11_devtoolset10 9 | <<: *common 10 | ubuntu2204: 11 | platform: ubuntu2204 12 | <<: *common 13 | macos: 14 | <<: *common 15 | windows: 16 | <<: *common 17 | -------------------------------------------------------------------------------- /.bazelci/examples_stamping.yml: -------------------------------------------------------------------------------- 1 | common: &common 2 | working_directory: ../examples/time_stamping 3 | build_targets: 4 | - "..." 5 | 6 | tasks: 7 | centos7: 8 | platform: centos7_java11_devtoolset10 9 | <<: *common 10 | ubuntu2204: 11 | platform: ubuntu2204 12 | <<: *common 13 | macos: 14 | <<: *common 15 | windows: 16 | <<: *common 17 | -------------------------------------------------------------------------------- /.bazelci/integration.yml: -------------------------------------------------------------------------------- 1 | # These test the packaging of the product itself. 2 | # They only have to run on linux with a recent bazel 3 | 4 | common: &common 5 | working_directory: .. 6 | build_targets: 7 | - "//doc_build:all" 8 | - "//distro/..." 9 | 10 | tasks: 11 | integration: 12 | name: rolling_distro 13 | platform: ubuntu2204 14 | <<: *common 15 | -------------------------------------------------------------------------------- /.bazelci/presubmit.yml: -------------------------------------------------------------------------------- 1 | imports: 2 | - tests.yml 3 | - examples_naming.yml 4 | - examples_rich_structure.yml 5 | - examples_stamping.yml 6 | - integration.yml 7 | -------------------------------------------------------------------------------- /.bazelignore: -------------------------------------------------------------------------------- 1 | # The following directories have their own WORKSPACEs (or contain WORKSPACEs), 2 | # so they shouldn't be built when in the main part of the rules_pkg repository. 3 | 4 | deb_packages/ 5 | examples/ 6 | -------------------------------------------------------------------------------- /.bazelrc: -------------------------------------------------------------------------------- 1 | build --enable_workspace 2 | -------------------------------------------------------------------------------- /.bcr/README.md: -------------------------------------------------------------------------------- 1 | # Bazel Central Registry 2 | 3 | When the ruleset is released, we want it to be published to the 4 | Bazel Central Registry automatically: 5 | 6 | 7 | This folder contains configuration files to automate the publish step. 8 | See 9 | for authoritative documentation about these files. 10 | -------------------------------------------------------------------------------- /.bcr/config.yml: -------------------------------------------------------------------------------- 1 | fixedReleaser: 2 | login: aiuto 3 | email: aiuto@google.com 4 | -------------------------------------------------------------------------------- /.bcr/metadata.template.json: -------------------------------------------------------------------------------- 1 | { 2 | "homepage": "https://github.com/bazelbuild/rules_pkg", 3 | "maintainers": [ 4 | { 5 | "email": "aiuto@google.com", 6 | "name": "Tony Aiuto", 7 | } 8 | ], 9 | "repository": ["github:bazelbuild/rules_pkg"], 10 | "versions": [], 11 | "yanked_versions": {} 12 | } 13 | -------------------------------------------------------------------------------- /.bcr/presubmit.yml: -------------------------------------------------------------------------------- 1 | build_targets: &build_targets 2 | - '@rules_pkg//...' 3 | # Re-enable those targets when toolchain registration is supported. 4 | - '-@rules_pkg//toolchains/...' 5 | - '-@rules_pkg//pkg:make_rpm' 6 | 7 | platforms: 8 | centos7_java11_devtoolset10: 9 | build_targets: *build_targets 10 | debian10: 11 | build_targets: *build_targets 12 | macos: 13 | build_targets: *build_targets 14 | ubuntu2204: 15 | build_targets: *build_targets 16 | windows: 17 | build_targets: *build_targets 18 | -------------------------------------------------------------------------------- /.bcr/source.template.json: -------------------------------------------------------------------------------- 1 | { 2 | "integrity": "**leave this alone**", 3 | "url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/rules_pkg-{TAG}.tar.gz" 4 | } 5 | -------------------------------------------------------------------------------- /.github/workflows/pre-commit.yml: -------------------------------------------------------------------------------- 1 | name: Pre-Commit 2 | 3 | on: 4 | push: 5 | branches: [main] 6 | pull_request: 7 | branches: [main] 8 | 9 | jobs: 10 | pre-commit: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v4 14 | - uses: pre-commit/action@v3.0.1 15 | -------------------------------------------------------------------------------- /.github/workflows/scorecard.yml: -------------------------------------------------------------------------------- 1 | # This workflow uses actions that are not certified by GitHub. They are provided 2 | # by a third-party and are governed by separate terms of service, privacy 3 | # policy, and support documentation. 4 | 5 | name: Scorecard supply-chain security 6 | on: 7 | # For Branch-Protection check. Only the default branch is supported. See 8 | # https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection 9 | branch_protection_rule: 10 | # To guarantee Maintained check is occasionally updated. See 11 | # https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained 12 | schedule: 13 | - cron: '41 10 * * 4' 14 | push: 15 | branches: [ "main" ] 16 | 17 | # Declare default permissions as read only. 18 | permissions: read-all 19 | 20 | jobs: 21 | analysis: 22 | name: Scorecard analysis 23 | runs-on: ubuntu-latest 24 | permissions: 25 | # Needed to upload the results to code-scanning dashboard. 26 | security-events: write 27 | # Needed to publish results and get a badge (see publish_results below). 28 | id-token: write 29 | # Uncomment the permissions below if installing in a private repository. 30 | # contents: read 31 | # actions: read 32 | 33 | steps: 34 | - name: Setup Node.js environment 35 | uses: actions/setup-node@v4 36 | 37 | - name: "Checkout code" 38 | uses: actions/checkout@v4 39 | with: 40 | persist-credentials: false 41 | 42 | - name: "Run analysis" 43 | uses: ossf/scorecard-action@v2 44 | with: 45 | results_file: results.sarif 46 | results_format: sarif 47 | # (Optional) "write" PAT token. Uncomment the `repo_token` line below if: 48 | # - you want to enable the Branch-Protection check on a *public* repository, or 49 | # - you are installing Scorecard on a *private* repository 50 | # To create the PAT, follow the steps in https://github.com/ossf/scorecard-action#authentication-with-pat. 51 | # repo_token: ${{ secrets.SCORECARD_TOKEN }} 52 | 53 | # Public repositories: 54 | # - Publish results to OpenSSF REST API for easy access by consumers 55 | # - Allows the repository to include the Scorecard badge. 56 | # - See https://github.com/ossf/scorecard-action#publishing-results. 57 | # For private repositories: 58 | # - `publish_results` will always be set to `false`, regardless 59 | # of the value entered here. 60 | publish_results: true 61 | 62 | # Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF 63 | # format to the repository Actions tab. 64 | - name: "Upload artifact" 65 | uses: actions/upload-artifact@v3 66 | with: 67 | name: SARIF file 68 | path: results.sarif 69 | retention-days: 5 70 | 71 | # Upload the results to GitHub's code scanning dashboard. 72 | - name: "Upload to code-scanning" 73 | uses: github/codeql-action/upload-sarif@17573ee1cc1b9d061760f3a006fc4aac4f944fd5 # v2.2.4 74 | with: 75 | sarif_file: results.sarif 76 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .bazeliskrc 2 | .ijwb 3 | bazel-* 4 | MODULE.bazel.lock 5 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | # Optional local setup for a git pre-commit hook to automatically format/lint. 2 | # This avoids sending a red PR and having to find the buildifier output on the CI results page. 3 | # See https://pre-commit.com for more information on installing pre-commit. 4 | # See https://pre-commit.com/hooks.html for more hooks. 5 | 6 | repos: 7 | # Check formatting and lint for starlark code 8 | - repo: https://github.com/keith/pre-commit-buildifier 9 | rev: 8.0.0 10 | hooks: 11 | - id: buildifier 12 | - id: buildifier-lint 13 | - repo: https://github.com/pre-commit/pre-commit-hooks 14 | rev: v5.0.0 15 | hooks: 16 | - id: check-toml 17 | - id: destroyed-symlinks 18 | - id: detect-private-key 19 | - id: end-of-file-fixer 20 | exclude: | 21 | (?x)^( 22 | tests/testdata/| 23 | docs/ 24 | ) 25 | - id: trailing-whitespace 26 | - repo: https://github.com/crate-ci/typos 27 | rev: v1.29.4 28 | hooks: 29 | - id: typos 30 | exclude: | 31 | (?x)^( 32 | CHANGELOG.md| 33 | tests/testdata/ 34 | ) 35 | -------------------------------------------------------------------------------- /.typos.toml: -------------------------------------------------------------------------------- 1 | [default.extend-words] 2 | FO = "FO" 3 | fo = "fo" 4 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | # This the official list of Bazel authors for copyright purposes. 2 | # This file is distinct from the CONTRIBUTORS files. 3 | # See the latter for an explanation. 4 | 5 | # Names should be added to this file as: 6 | # Name or Organization 7 | # The email address is not required for organizations. 8 | 9 | Google Inc. 10 | -------------------------------------------------------------------------------- /BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@rules_license//rules:license.bzl", "license") 16 | 17 | package( 18 | default_applicable_licenses = [":license"], 19 | default_visibility = ["//visibility:public"], 20 | ) 21 | 22 | license( 23 | name = "license", 24 | license_kinds = [ 25 | "@rules_license//licenses/spdx:Apache-2.0", 26 | ], 27 | license_text = "LICENSE", 28 | ) 29 | 30 | exports_files( 31 | ["WORKSPACE"], 32 | ) 33 | 34 | exports_files( 35 | glob([ 36 | "*.bzl", 37 | ]), 38 | ) 39 | 40 | filegroup( 41 | name = "standard_package", 42 | srcs = glob([ 43 | "*.bzl", 44 | ]) + [ 45 | "BUILD", 46 | "LICENSE", 47 | "MODULE.bazel", 48 | ], 49 | visibility = ["//distro:__pkg__"], 50 | ) 51 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @aiuto @cgrindel 2 | 3 | /.bazelci/ @meteorcloudy 4 | /.bcr/ @meteorcloudy 5 | /.github/ @meteorcloudy 6 | /.pre-commit-config.yaml @meteorcloudy 7 | 8 | /deb_packages/ @aiuto 9 | /docs/ @aiuto @jylinv0 10 | /doc_build/ @aiuto @jylinv0 11 | 12 | /pkg/rpm/ @nacl 13 | /pkg/tests/rpm/ @nacl 14 | /legacy/tests/rpm @nacl 15 | /toolchains/rpm @nacl 16 | 17 | /pkg/deb.bzl @aiuto @dannysullivan 18 | /pkg/private/deb/ @aiuto @dannysullivan 19 | /pkg/tests/deb/ @aiuto @dannysullivan 20 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Want to contribute? Great! First, read this page (including the small print at 2 | the end). 3 | 4 | ### Before you contribute 5 | 6 | **Before we can use your code, you must sign the [Google Individual Contributor 7 | License 8 | Agreement](https://developers.google.com/open-source/cla/individual?csw=1) 9 | (CLA)**, which you can do online. 10 | 11 | The CLA is necessary mainly because you own the copyright to your changes, even 12 | after your contribution becomes part of our codebase, so we need your permission 13 | to use and distribute your code. We also need to be sure of various other things 14 | — for instance that you'll tell us if you know that your code infringes on other 15 | people's patents. You don't have to sign the CLA until after you've submitted 16 | your code for review and a member has approved it, but you must do it before we 17 | can put your code into our codebase. 18 | 19 | Before you start working on a larger contribution, you should get in touch with 20 | us first. Use the issue tracker to explain your idea so we can help and possibly 21 | guide you. 22 | 23 | ### Code reviews and other contributions. 24 | 25 | **All submissions, including submissions by project members, require review.** 26 | Please follow the instructions in [the patching guide](/patching.md). 27 | 28 | ### The small print 29 | 30 | Contributions made by corporations are covered by a different agreement than the 31 | one above, the [Software Grant and Corporate Contributor License 32 | Agreement](https://cla.developers.google.com/about/google-corporate). 33 | -------------------------------------------------------------------------------- /CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # People who have agreed to one of the CLAs and can contribute patches. 2 | # The AUTHORS file lists the copyright holders; this file 3 | # lists people. For example, Google employees are listed here 4 | # but not in AUTHORS, because Google holds the copyright. 5 | # 6 | # https://developers.google.com/open-source/cla/individual 7 | # https://developers.google.com/open-source/cla/corporate 8 | # 9 | # Names should be added to this file as: 10 | # Name 11 | Andrew Psaltis 12 | Tony Aiuto 13 | -------------------------------------------------------------------------------- /MODULE.bazel: -------------------------------------------------------------------------------- 1 | module( 2 | name = "rules_pkg", 3 | version = "1.1.0", # Must sync with version.bzl. 4 | compatibility_level = 1, 5 | repo_name = "rules_pkg", 6 | ) 7 | 8 | # Do not update to newer versions until you need a specific new feature. 9 | bazel_dep(name = "rules_license", version = "1.0.0") 10 | bazel_dep(name = "rules_python", version = "1.0.0") 11 | bazel_dep(name = "bazel_skylib", version = "1.7.1") 12 | 13 | # Only for development 14 | bazel_dep(name = "platforms", version = "0.0.10", dev_dependency = True) 15 | bazel_dep(name = "rules_cc", version = "0.0.17", dev_dependency = True) 16 | bazel_dep(name = "stardoc", version = "0.7.2", dev_dependency = True) 17 | 18 | # Find the system rpmbuild if one is available. 19 | find_rpm = use_extension("//toolchains/rpm:rpmbuild_configure.bzl", "find_system_rpmbuild_bzlmod", dev_dependency = True) 20 | use_repo(find_rpm, "rules_pkg_rpmbuild") 21 | 22 | register_toolchains( 23 | "@rules_pkg_rpmbuild//:all", 24 | dev_dependency = True, 25 | ) 26 | 27 | local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository") 28 | 29 | local_repository( 30 | name = "mappings_test_external_repo", 31 | path = "tests/mappings/external_repo", 32 | ) 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Bazel package building 2 | 3 | Bazel rules for building tar, zip, deb, and rpm for packages. 4 | 5 | For the latest version, see [Releases](https://github.com/bazelbuild/rules_pkg/releases) (with `WORKSPACE` setup) / 6 | [Documentation](https://bazelbuild.github.io/rules_pkg) 7 | 8 | Use rules-pkg-discuss@googlegroups.com for discussion. 9 | 10 | CI: 11 | [![Build status](https://badge.buildkite.com/e12f23186aa579f1e20fcb612a22cd799239c3134bc38e1aff.svg)](https://buildkite.com/bazel/rules-pkg) 12 | 13 | ## Basic rules 14 | 15 | ### Package building rules 16 | 17 | * [pkg](https://github.com/bazelbuild/rules_pkg/tree/main/pkg) - Rules for 18 | building packages of various types. 19 | * [examples](https://github.com/bazelbuild/rules_pkg/tree/main/examples) - 20 | Cookbook examples for using the rules. 21 | 22 | As of Bazel 4.x, Bazel uses this rule set for packaging its distribution. Bazel 23 | still contains a limited version of `pkg_tar` but its feature set is frozen. 24 | Any new capabilities will be added here. 25 | 26 | 27 | ## WORKSPACE setup 28 | 29 | Sample, but see [releases](https://github.com/bazelbuild/rules_pkg/releases) for the current release. 30 | 31 | ```starlark 32 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 33 | http_archive( 34 | name = "rules_pkg", 35 | urls = [ 36 | "https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz", 37 | "https://github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz", 38 | ], 39 | sha256 = "8f9ee2dc10c1ae514ee599a8b42ed99fa262b757058f65ad3c384289ff70c4b8", 40 | ) 41 | load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") 42 | rules_pkg_dependencies() 43 | ``` 44 | 45 | To use `pkg_rpm()`, you must provide a copy of `rpmbuild`. You can use the 46 | system installed `rpmbuild` with this stanza. 47 | ```starlark 48 | load("@rules_pkg//toolchains/rpm:rpmbuild_configure.bzl", "find_system_rpmbuild") 49 | 50 | find_system_rpmbuild( 51 | name = "rules_pkg_rpmbuild", 52 | verbose = False, 53 | ) 54 | ``` 55 | 56 | ## MODULE.bazel setup 57 | 58 | ```starlark 59 | bazel_dep(name = "rules_pkg", version = "0.0.10") 60 | ``` 61 | To use `pkg_rpm()`, you must provide a copy of `rpmbuild`. You can use the 62 | system installed `rpmbuild` with this stanza. 63 | ```starlark 64 | find_rpm = use_extension("//toolchains/rpm:rpmbuild_configure.bzl", "find_system_rpmbuild_bzlmod") 65 | use_repo(find_rpm, "rules_pkg_rpmbuild") 66 | register_toolchains("@rules_pkg_rpmbuild//:all") 67 | ``` 68 | 69 | ### For developers 70 | 71 | * [Contributor information](CONTRIBUTING.md) (including contributor license agreements) 72 | * [Patch process](patching.md) 73 | * [Coding guidelines](developers.md) and other developer information 74 | 75 | We hold an engineering status meeting on the first Monday of every month at 10am USA East coast time. 76 | [Add to calendar](https://calendar.google.com/event?action=TEMPLATE&tmeid=MDE2ODMzazlwZnRxbWtkZG5wa2hlYjllMGVfMjAyMTA1MDNUMTUwMDAwWiBjXzUzcHBwZzFudWthZXRmb3E5NzhxaXViNmxzQGc&tmsrc=c_53pppg1nukaetfoq978qiub6ls%40group.calendar.google.com&scp=ALL) / 77 | [meeting notes](https://docs.google.com/document/d/1wkY8ZIcrG8tlKCHzv4st-EltsdlpQENH58fguRnErWY/edit?usp=sharing) 78 | -------------------------------------------------------------------------------- /WORKSPACE: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | workspace(name = "rules_pkg") 16 | 17 | load("@rules_pkg//pkg:deps.bzl", "rules_pkg_dependencies") 18 | 19 | rules_pkg_dependencies() 20 | 21 | load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") 22 | 23 | bazel_skylib_workspace() 24 | 25 | ### INTERNAL ONLY - lines after this are not included in the release packaging. 26 | # 27 | # Include dependencies which are only needed for development here. 28 | 29 | # Used to test invoking rules with targets in an external repo. 30 | local_repository( 31 | name = "mappings_test_external_repo", 32 | path = "tests/mappings/external_repo", 33 | ) 34 | 35 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 36 | 37 | http_archive( 38 | name = "platforms", 39 | sha256 = "218efe8ee736d26a3572663b374a253c012b716d8af0c07e842e82f238a0a7ee", 40 | urls = [ 41 | "https://github.com/bazelbuild/platforms/releases/download/0.0.10/platforms-0.0.10.tar.gz", 42 | ], 43 | ) 44 | 45 | # Find rpmbuild if it exists. 46 | load("@rules_pkg//toolchains/rpm:rpmbuild_configure.bzl", "find_system_rpmbuild") 47 | 48 | find_system_rpmbuild( 49 | name = "rules_pkg_rpmbuild", 50 | verbose = False, 51 | ) 52 | 53 | # Needed for making our release notes 54 | load("@rules_pkg//toolchains/git:git_configure.bzl", "experimental_find_system_git") 55 | 56 | experimental_find_system_git( 57 | name = "rules_pkg_git", 58 | verbose = False, 59 | ) 60 | 61 | http_archive( 62 | name = "bazel_stardoc", 63 | sha256 = "0e1ed4a98f26e718776bd64d053d02bb34d98572ccd03d6ba355112a1205706b", 64 | urls = [ 65 | "https://mirror.bazel.build/github.com/bazelbuild/stardoc/releases/download/0.7.2/stardoc-0.7.2.tar.gz", 66 | "https://github.com/bazelbuild/stardoc/releases/download/0.7.2/stardoc-0.7.2.tar.gz", 67 | ], 68 | ) 69 | 70 | load("@bazel_stardoc//:setup.bzl", "stardoc_repositories") 71 | 72 | stardoc_repositories() 73 | 74 | http_archive( 75 | name = "rules_cc", 76 | sha256 = "abc605dd850f813bb37004b77db20106a19311a96b2da1c92b789da529d28fe1", 77 | strip_prefix = "rules_cc-0.0.17", 78 | urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.17/rules_cc-0.0.17.tar.gz"], 79 | ) 80 | 81 | load("@rules_cc//cc:repositories.bzl", "rules_cc_dependencies") 82 | 83 | rules_cc_dependencies() 84 | -------------------------------------------------------------------------------- /WORKSPACE.bzlmod: -------------------------------------------------------------------------------- 1 | # Include dependencies which are only needed for development here. 2 | 3 | local_repository( 4 | name = "mappings_test_external_repo", 5 | path = "tests/mappings/external_repo", 6 | ) 7 | 8 | # TODO(aiuto): bzlmod chokes on @rules_pkg// in the toolchain labels. 9 | # Find rpmbuild if it exists. 10 | # load("//toolchains/rpm:rpmbuild_configure.bzl", "find_system_rpmbuild") 11 | # 12 | #find_system_rpmbuild( 13 | # name = "rules_pkg_rpmbuild", 14 | # verbose = False, 15 | #) 16 | 17 | # Needed for making our release notes 18 | load("//toolchains/git:git_configure.bzl", "experimental_find_system_git_bzlmod") 19 | 20 | experimental_find_system_git_bzlmod( 21 | name = "rules_pkg_git", 22 | verbose = False, 23 | ) 24 | 25 | register_toolchains( 26 | "@rules_pkg_git//:git_auto_toolchain", 27 | "//toolchains/git:git_missing_toolchain", 28 | ) 29 | -------------------------------------------------------------------------------- /deps.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Workspace dependencies for rules_pkg/pkg. 15 | This is for backwards compatibility with existing usage. Please use 16 | load("//pkg:deps.bzl", "rules_pkg_dependencies") 17 | going forward. 18 | """ 19 | 20 | load("//pkg:deps.bzl", _rules_pkg_dependencies = "rules_pkg_dependencies") 21 | 22 | rules_pkg_dependencies = _rules_pkg_dependencies 23 | 24 | def rules_pkg_register_toolchains(): 25 | pass 26 | -------------------------------------------------------------------------------- /distro/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazelbuild/rules_pkg/c590e619313f3227c06541b00deb6074680b8922/distro/__init__.py -------------------------------------------------------------------------------- /distro/testdata/BUILD.tpl: -------------------------------------------------------------------------------- 1 | load("@not_named_rules_pkg//pkg:tar.bzl", "pkg_tar") 2 | 3 | pkg_tar( 4 | name = "dummy_tar", 5 | srcs = [ 6 | ":BUILD", 7 | ], 8 | extension = "tar.gz", 9 | owner = "0.0", 10 | package_dir = "etc", 11 | tags = [ 12 | "manual", 13 | ], 14 | ) 15 | -------------------------------------------------------------------------------- /doc_build/merge.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Copyright 2022 The Bazel Authors. All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | """merge stardoc output into a single page. 16 | 17 | - concatenates files 18 | - corrects things that stardoc botches 19 | """ 20 | 21 | import re 22 | import sys 23 | import typing 24 | 25 | 26 | ID_RE = re.compile(r'') 27 | WRAPS_RE = re.compile(r'@wraps\((.*)\)') 28 | SINCE_RE = re.compile(r'@since\(([^)]*)\)') 29 | CENTER_RE = re.compile(r'

([^<]*)

') 30 | 31 | 32 | def merge_file(file: str, out, wrapper_map:typing.Dict[str, str]) -> None: 33 | with open(file, 'r') as inp: 34 | content = inp.read() 35 | m = ID_RE.search(content) 36 | this_pkg = m.group(1) if m else None 37 | m = WRAPS_RE.search(content) 38 | if m: 39 | # I wrap something, so don't emit me. 40 | wrapper_map[m.group(1)] = this_pkg 41 | return 42 | # If something wraps me, rewrite myself with the wrapper name. 43 | if this_pkg in wrapper_map: 44 | content = content.replace(this_pkg, wrapper_map[this_pkg]) 45 | del wrapper_map[this_pkg] 46 | merge_text(content, out) 47 | 48 | 49 | def merge_text(text: str, out) -> None: 50 | """Merge a block of text into an output stream. 51 | 52 | Args: 53 | text: block of text produced by Starroc. 54 | out: an output file stream. 55 | """ 56 | for line in text.split('\n'): 57 | line = SINCE_RE.sub(r'
Since \1
', line) 58 | 59 | if line.startswith('| :'): 60 | line = fix_stardoc_table_align(line) 61 | # Compensate for https://github.com/bazelbuild/stardoc/issues/118. 62 | # Convert escaped HTML
  • back to raw text 63 | line = line.replace('<li>', '
  • ') 64 | line = CENTER_RE.sub(r'\1', line) 65 | _ = out.write(line) 66 | _ = out.write('\n') 67 | 68 | 69 | def fix_stardoc_table_align(line: str) -> str: 70 | """Change centered descriptions to left justified.""" 71 | if line.startswith('| :-------------: | :-------------: '): 72 | return '| :------------ | :--------------- | :---------: | :---------: | :----------- |' 73 | return line 74 | 75 | 76 | def main(argv: typing.Sequence[str]) -> None: 77 | wrapper_map = {} 78 | for file in argv[1:]: 79 | merge_file(file, sys.stdout, wrapper_map) 80 | if wrapper_map: 81 | print("We didn't use all the @wraps()", wrapper_map, file=sys.stderr) 82 | sys.exit(1) 83 | return 0 84 | 85 | 86 | if __name__ == '__main__': 87 | sys.exit(main(sys.argv)) 88 | -------------------------------------------------------------------------------- /doc_build/toc.md.tpl: -------------------------------------------------------------------------------- 1 | # rules_pkg - {VERSION} 2 | 3 | 29 | -------------------------------------------------------------------------------- /docs/_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman 2 | -------------------------------------------------------------------------------- /docs/_includes/head-custom.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /docs/_includes/head.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /docs/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazelbuild/rules_pkg/c590e619313f3227c06541b00deb6074680b8922/docs/favicon.ico -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | # bazelbuild/rules_pkg 2 | 3 | Bazel rules for building tar, zip, deb, and rpm packages. 4 | 5 | Use rules-pkg-discuss@googlegroups.com for discussion. 6 | 7 | * [Examples](https://github.com/bazelbuild/rules_pkg/tree/main/examples) - 8 | Cookbook examples for using the rules. 9 | 10 | ## Reference 11 | 12 | We are in the process of migrating from hand-written docs to generated ones. 13 | Some rules are fully documented in their definitions, and will have complete 14 | documentation in the Latest or versioned snapshots. Some rules still have 15 | attributes only defined in the "Legacy" documentation. You may have to 16 | consult more than one place to get a complete picture. 17 | 18 | * [Latest Snapshot at head](latest.md) 19 | * [Version 1.1.0](1.1.0/reference.md) 20 | * [Version 1.0.1](1.0.1/reference.md) 21 | * [Version 0.10.0](0.10.0/reference.md) 22 | * [Version 0.9.1](0.9.1/reference.md) 23 | * [Version 0.8.0](0.8.0/reference.md) 24 | * [Version 0.7.0](0.7.0/reference.md) 25 | * [Version 0.6.0](0.6.0/reference.md) 26 | * [Version 0.5.0](0.5.0/reference.md) 27 | * [Version 0.4.0](0.4.0/reference.md) 28 | * [Legacy](https://github.com/bazelbuild/rules_pkg/blob/main/pkg/docs/reference.md) 29 | -------------------------------------------------------------------------------- /docs/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Disallow: /0.4.0/ 3 | Disallow: /0.5.0/ 4 | -------------------------------------------------------------------------------- /examples/BUILD: -------------------------------------------------------------------------------- 1 | # placeholder 2 | -------------------------------------------------------------------------------- /examples/naming_package_files/MODULE.bazel: -------------------------------------------------------------------------------- 1 | module( 2 | name = "rules_pkg_examples", 3 | version = "0.0.1", 4 | ) 5 | 6 | bazel_dep(name = "rules_pkg") 7 | local_path_override( 8 | module_name = "rules_pkg", 9 | path = "../..", 10 | ) 11 | 12 | bazel_dep(name = "platforms", version = "0.0.10") 13 | bazel_dep(name = "rules_cc", version = "0.0.17") 14 | -------------------------------------------------------------------------------- /examples/naming_package_files/package_upload.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Example of how we can use OutputGroupInfo to find an output name.""" 15 | 16 | def _debian_upload_impl(ctx): 17 | # Find out the basename of the deb file we created. 18 | ogi = ctx.attr.package[OutputGroupInfo] 19 | deb = ogi.deb.to_list()[0] 20 | changes = ogi.changes.to_list()[0] 21 | package_basename = deb.basename.split(".")[0] 22 | content = ["# Uploading %s" % package_basename] 23 | for f in [deb, changes]: 24 | if f.basename.startswith(package_basename): 25 | content.append("gsutil cp %s gs://%s/%s" % ( 26 | f.path, 27 | ctx.attr.host, 28 | f.basename, 29 | )) 30 | ctx.actions.write(ctx.outputs.out, "\n".join(content)) 31 | 32 | debian_upload = rule( 33 | implementation = _debian_upload_impl, 34 | doc = """A demonstration of consuming OutputGroupInfo to get a file name.""", 35 | attrs = { 36 | "package": attr.label( 37 | doc = "Package to upload", 38 | mandatory = True, 39 | providers = [OutputGroupInfo], 40 | ), 41 | "host": attr.string( 42 | doc = "Host to upload to", 43 | mandatory = True, 44 | ), 45 | "out": attr.output( 46 | doc = "Script file to create.", 47 | mandatory = True, 48 | ), 49 | }, 50 | ) 51 | -------------------------------------------------------------------------------- /examples/naming_package_files/readme.md: -------------------------------------------------------------------------------- 1 | # Examples of how to name packages using build time configuration. 2 | 3 | ## Examples 4 | 5 | The examples below only show snippets of the relevant technique. 6 | See the BUILD file for the complete source. 7 | 8 | ### Using command line flags to modify a package name 9 | 10 | We can use a `config_setting` to capture the command line flag and then 11 | `select()` on that to drop a part into into the name. 12 | 13 | ```python 14 | config_setting( 15 | name = "special_build", 16 | values = {"define": "SPECIAL=1"}, 17 | ) 18 | 19 | my_package_naming( 20 | name = "my_naming_vars", 21 | special_build = select({ 22 | ":special_build": "-IsSpecial", 23 | "//conditions:default": "", 24 | }), 25 | ) 26 | ``` 27 | 28 | ```shell 29 | bazel build :example1 30 | ls -l bazel-bin/example1.tar bazel-bin/RulesPkgExamples-k8-fastbuild.tar 31 | ``` 32 | 33 | ```shell 34 | bazel build :example1 --define=SPECIAL=1 35 | ls -l bazel-bin/example1*.tar 36 | ``` 37 | 38 | ### Using values from a toolchain in a package name. 39 | 40 | The rule providing the naming can depend on toolchains just like a `*_library` 41 | or `*_binary` rule 42 | 43 | ```python 44 | def _names_from_toolchains_impl(ctx): 45 | values = {} 46 | cc_toolchain = find_cc_toolchain(ctx) 47 | values['cc_cpu'] = cc_toolchain.cpu 48 | return PackageVariablesInfo(values = values) 49 | 50 | names_from_toolchains = rule( 51 | implementation = _names_from_toolchains_impl, 52 | attrs = { 53 | "_cc_toolchain": attr.label( 54 | default = Label( 55 | "@rules_cc//cc:current_cc_toolchain", 56 | ), 57 | ), 58 | }, 59 | toolchains = ["@rules_cc//cc:toolchain_type"], 60 | ) 61 | ``` 62 | 63 | ```shell 64 | bazel build :example2 65 | ls -l bazel-bin/example2*.tar 66 | ``` 67 | 68 | ### Debian package names 69 | 70 | Debian package names are of the form `_-_.deb`. 71 | 72 | One way you might do that is shown in this snipped from the `BUILD` file. 73 | 74 | ```python 75 | VERSION = "1" 76 | REVISION = "2" 77 | 78 | basic_naming( 79 | name = "my_naming_vars", 80 | 81 | version = VERSION, 82 | revision = REVISION, 83 | ... 84 | ) 85 | 86 | pkg_deb( 87 | name = "a_deb_package", 88 | package = "foo-tools", 89 | ... 90 | # Note: target_cpu comes from the --cpu on the command line, and does not 91 | # have to be stated in the BUILD file. 92 | package_file_name = "foo-tools_{version}-{revision}_{target_cpu}.deb", 93 | package_variables = ":my_naming_vars", 94 | version = VERSION, 95 | ) 96 | ``` 97 | 98 | Try building `bazel build :a_deb_package` then examine the results. Note that 99 | the .deb out file has the correctly formed name, while the target itself is 100 | a symlink to that file. 101 | 102 | ```console 103 | $ ls -l bazel-bin/a_deb_package.deb bazel-bin/foo-tools_1-2_k8.deb 104 | lrwxrwxrwx 1 user primarygroup 163 Jul 26 12:56 bazel-bin/a_deb_package.deb -> /home/user/.cache/bazel/_bazel_user/.../execroot/rules_pkg_examples/bazel-out/k8-fastbuild/bin/foo-tools_1-2_k8.deb 105 | -r-xr-xr-x 1 user primarygroup 10662 Jul 26 12:56 bazel-bin/foo-tools_1-2_k8.deb 106 | ``` 107 | -------------------------------------------------------------------------------- /examples/readme.md: -------------------------------------------------------------------------------- 1 | # rules_pkg - Examples 2 | 3 | ## TBD 4 | -------------------------------------------------------------------------------- /examples/rich_structure/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@rules_pkg//pkg:mappings.bzl", "pkg_filegroup", "pkg_files", "strip_prefix") 16 | load("@rules_pkg//pkg:tar.bzl", "pkg_tar") 17 | load("@rules_pkg//pkg:zip.bzl", "pkg_zip") 18 | 19 | # This is the top level BUILD for a hypothetical project Foo. It has a client, 20 | # a server, docs, and runtime directories needed by the server. 21 | # We want to ship it for Linux, macOS, and Windows. 22 | # 23 | # This example shows various techniques for specifying how your source tree 24 | # transforms into the installation tree. As such, it favors using a lot of 25 | # distinct features, at the expense of uniformity. 26 | 27 | pkg_files( 28 | name = "share_doc", 29 | srcs = [ 30 | "//docs", 31 | ], 32 | # Where it should be in the final package 33 | prefix = "usr/share/doc/foo", 34 | # Required, but why?: see #354 35 | strip_prefix = strip_prefix.from_pkg(), 36 | ) 37 | 38 | pkg_filegroup( 39 | name = "manpages", 40 | srcs = [ 41 | "//src/client:manpages", 42 | "//src/server:manpages", 43 | ], 44 | prefix = "/usr/share", 45 | ) 46 | 47 | pkg_tar( 48 | name = "foo_tar", 49 | srcs = [ 50 | "README.txt", 51 | ":manpages", 52 | ":share_doc", 53 | "//resources/l10n:all", 54 | "//src/client:arch", 55 | "//src/server:arch", 56 | ], 57 | ) 58 | 59 | pkg_zip( 60 | name = "foo_zip", 61 | srcs = [ 62 | "README.txt", 63 | ":manpages", 64 | ":share_doc", 65 | "//resources/l10n:all", 66 | "//src/client:arch", 67 | "//src/server:arch", 68 | ], 69 | ) 70 | -------------------------------------------------------------------------------- /examples/rich_structure/MODULE.bazel: -------------------------------------------------------------------------------- 1 | module( 2 | name = "rules_pkg_examples", 3 | version = "0.0.1", 4 | ) 5 | 6 | bazel_dep(name = "rules_pkg") 7 | local_path_override( 8 | module_name = "rules_pkg", 9 | path = "../..", 10 | ) 11 | 12 | bazel_dep(name = "platforms", version = "0.0.10") 13 | bazel_dep(name = "rules_cc", version = "0.0.17") 14 | -------------------------------------------------------------------------------- /examples/rich_structure/README.md: -------------------------------------------------------------------------------- 1 | # Example of how pkg_* rules can compose to create a rich package structure. 2 | 3 | ## Use case 4 | 5 | Our use case is building a distribution package that represents a typical \*nix tool. 6 | That would include elements such as: 7 | 8 | - A main program that requires runtime support files 9 | - Associated documentation 10 | - A service associated with the main binary 11 | - Associate configuration files 12 | 13 | where each elements must be installed in a specific place in the file system. 14 | The final package might look like this for Linux: 15 | 16 | ``` 17 | etc/foo.rc 18 | etc/food.conf 19 | sbin/food 20 | usr/bin/foo # symlink to ../share/foo/bin/foo 21 | usr/bin/fooctl # symlink to ../share/foo/bin/fooctl 22 | usr/bin/foocheck 23 | usr/lib/foo/runtime.so 24 | usr/lib/foo/runtime.so 25 | usr/share/doc/foo/copyright 26 | usr/share/doc/foo/README.txt 27 | usr/share/doc/foo/foo.html 28 | usr/share/man/man1/foo.1.gz 29 | usr/share/man/man1/fooctl.1.gz 30 | usr/share/man/man8/food.8.gz 31 | usr/share/foo/bin/foo 32 | usr/share/foo/bin/fooctl 33 | usr/share/foo/bar.rules 34 | usr/share/foo/baz.rules 35 | usr/share/foo/locale/foo/en/msgs.cat 36 | usr/share/foo/locale/foo/it/msgs.cat 37 | usr/share/foo/locale/fooctl/en/msgs.cat 38 | usr/share/foo/locale/fooctl/it/msgs.cat 39 | usr/share/foo/locale/food/en/msgs.cat 40 | usr/share/foo/locale/food/it/msgs.cat 41 | var/tmp/foo 42 | var/tmp/foo/queue 43 | ``` 44 | 45 | For macOS, it would be mostly the same, but files under `usr/share/foo` would 46 | move to `Library/Foo`. 47 | 48 | To emulate reality better, the source tree is organized in a way that is 49 | convenient for the developers. This example illustrates techniques to create 50 | the desired final structure. 51 | -------------------------------------------------------------------------------- /examples/rich_structure/README.txt: -------------------------------------------------------------------------------- 1 | This is the Foo system. It does not do anything. 2 | -------------------------------------------------------------------------------- /examples/rich_structure/copyright: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /examples/rich_structure/docs/BUILD: -------------------------------------------------------------------------------- 1 | # Some docs 2 | 3 | filegroup( 4 | name = "docs", 5 | srcs = glob( 6 | ["**/*"], 7 | exclude = ["BUILD"], 8 | ), 9 | visibility = ["//visibility:public"], 10 | ) 11 | -------------------------------------------------------------------------------- /examples/rich_structure/docs/index.md: -------------------------------------------------------------------------------- 1 | # The foo system 2 | 3 | Some text 4 | -------------------------------------------------------------------------------- /examples/rich_structure/docs/reference/index.md: -------------------------------------------------------------------------------- 1 | # A reference manual 2 | -------------------------------------------------------------------------------- /examples/rich_structure/docs/user_guide.md: -------------------------------------------------------------------------------- 1 | # More docs 2 | -------------------------------------------------------------------------------- /examples/rich_structure/foo_defs.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Shared bzl constants and methods for building the Foo product.""" 15 | 16 | shared_object_path_selector = { 17 | "@platforms//os:linux": "/usr/share/foo", 18 | "@platforms//os:macos": "/Library/Foo", 19 | "@platforms//os:windows": "/Program Files/Foo", 20 | "//conditions:default": "/usr/local/share/foo", 21 | } 22 | -------------------------------------------------------------------------------- /examples/rich_structure/resources/l10n/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes", "pkg_filegroup", "pkg_files", "strip_prefix") 16 | load("@rules_pkg//pkg:tar.bzl", "pkg_tar") 17 | load("//:foo_defs.bzl", "shared_object_path_selector") 18 | 19 | # There are localized message catalogs for all the components. 20 | 21 | # Typically, you would have a lot of these and drop them in, so using a glob 22 | # to gather them is appropriate. 23 | pkg_files( 24 | name = "messages", 25 | srcs = glob(["**/msg.cat"]), 26 | attributes = pkg_attributes( 27 | # We know they should be read only. We don't know who should own them. 28 | mode = "0444", 29 | ), 30 | strip_prefix = strip_prefix.from_pkg(), 31 | ) 32 | 33 | # Use the English catalog again under a different name. 34 | # This is a trick for reusing a single source file or files in multiple places 35 | # in the output tree. Here we place foo/en/msg.cat under foo/en_GB/msg.cat. 36 | # This is more efficient than having a rule copy the files to a new location. 37 | # The final package builder is passed just the information that the original 38 | # srcs should be placed in the output archive under this other name. 39 | pkg_files( 40 | name = "extra_messages", 41 | srcs = ["foo/en/msg.cat"], 42 | attributes = pkg_attributes( 43 | mode = "0444", 44 | ), 45 | prefix = "foo/en_GB", 46 | strip_prefix = strip_prefix.from_pkg(), 47 | ) 48 | 49 | # This gathers together all our message catalogs, and adds a prefix based 50 | # on the target OS 51 | pkg_filegroup( 52 | name = "all", 53 | srcs = [ 54 | ":extra_messages", 55 | ":messages", 56 | ], 57 | prefix = select(shared_object_path_selector) + "/locale", 58 | visibility = ["//visibility:public"], 59 | ) 60 | 61 | pkg_files( 62 | name = "mraw", 63 | srcs = glob(["**/msg.cat"]), 64 | attributes = pkg_attributes( 65 | mode = "0444", 66 | ), 67 | strip_prefix = strip_prefix.from_root("resources"), 68 | ) 69 | 70 | pkg_tar( 71 | name = "raw", 72 | srcs = [":mraw"], 73 | ) 74 | -------------------------------------------------------------------------------- /examples/rich_structure/resources/l10n/foo/en/msg.cat: -------------------------------------------------------------------------------- 1 | 100 hello 2 | -------------------------------------------------------------------------------- /examples/rich_structure/resources/l10n/foo/it/msg.cat: -------------------------------------------------------------------------------- 1 | 100 ciao 2 | -------------------------------------------------------------------------------- /examples/rich_structure/resources/l10n/fooctl/en/msg.cat: -------------------------------------------------------------------------------- 1 | 100 forty-two 2 | -------------------------------------------------------------------------------- /examples/rich_structure/resources/l10n/fooctl/it/msg.cat: -------------------------------------------------------------------------------- 1 | 100 quarantadue 2 | -------------------------------------------------------------------------------- /examples/rich_structure/resources/l10n/food/en/msg.cat: -------------------------------------------------------------------------------- 1 | 100 help! 2 | -------------------------------------------------------------------------------- /examples/rich_structure/resources/l10n/food/it/msg.cat: -------------------------------------------------------------------------------- 1 | 100 aiuto! 2 | -------------------------------------------------------------------------------- /examples/rich_structure/src/client/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") 16 | load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes", "pkg_filegroup", "pkg_files", "pkg_mklink") 17 | load("@rules_pkg//pkg:tar.bzl", "pkg_tar") 18 | load("//:foo_defs.bzl", "shared_object_path_selector") 19 | 20 | cc_library( 21 | name = "foolib", 22 | srcs = [ 23 | "foocore.cc", 24 | ], 25 | hdrs = [ 26 | "foo.h", 27 | ], 28 | ) 29 | 30 | cc_binary( 31 | name = "foo", 32 | srcs = [ 33 | "foo.cc", 34 | ], 35 | # TODO(aiuto): How to we get the data to be in /usr/share/foo? 36 | # See #153 as a starting point for runfiles discussions. 37 | data = [ 38 | "bar.rules", 39 | "baz.rules", 40 | ], 41 | deps = [ 42 | ":foolib", 43 | ], 44 | ) 45 | 46 | cc_binary( 47 | name = "fooctl", 48 | srcs = [ 49 | "fooctl.cc", 50 | ], 51 | ) 52 | 53 | pkg_files( 54 | name = "binary", 55 | srcs = [ 56 | ":foo", 57 | ":fooctl", 58 | ], 59 | include_runfiles = True, 60 | # Where it should be in the final package 61 | prefix = select(shared_object_path_selector) + "/bin", 62 | ) 63 | 64 | pkg_files( 65 | name = "runtime", 66 | srcs = [ 67 | ":foolib", 68 | ], 69 | prefix = "usr/lib/foo", 70 | ) 71 | 72 | pkg_tar( 73 | name = "man", 74 | srcs = [ 75 | "foo.1", 76 | ], 77 | out = "foo.1.gz", 78 | extension = ".gz", 79 | ) 80 | 81 | pkg_files( 82 | name = "manpages", 83 | srcs = [ 84 | ":man", 85 | ], 86 | attributes = pkg_attributes( 87 | group = "man", 88 | mode = "0444", 89 | owner = "man", 90 | ), 91 | prefix = "man/man1", 92 | visibility = ["//visibility:public"], 93 | ) 94 | 95 | pkg_mklink( 96 | name = "usr_bin", 97 | link_name = "usr/bin/foo", 98 | target = select(shared_object_path_selector) + "/bin/foo", 99 | ) 100 | 101 | pkg_filegroup( 102 | name = "arch", 103 | srcs = [ 104 | ":binary", 105 | ":runtime", 106 | ":usr_bin", 107 | ], 108 | visibility = ["//visibility:public"], 109 | ) 110 | -------------------------------------------------------------------------------- /examples/rich_structure/src/client/bar.rules: -------------------------------------------------------------------------------- 1 | bar 2 | -------------------------------------------------------------------------------- /examples/rich_structure/src/client/baz.rules: -------------------------------------------------------------------------------- 1 | baz 2 | -------------------------------------------------------------------------------- /examples/rich_structure/src/client/foo.1: -------------------------------------------------------------------------------- 1 | .TH FOO 1 local 2 | .SH NAME 3 | foo \- create and manipulate foos 4 | .SH SYNOPSIS 5 | .ll +8 6 | .B foo 7 | [ 8 | .I "name \&..." 9 | ] 10 | .ll -8 11 | .SH DESCRIPTION 12 | .I Foo 13 | does nothing. 14 | -------------------------------------------------------------------------------- /examples/rich_structure/src/client/foo.cc: -------------------------------------------------------------------------------- 1 | #include "foo.h" 2 | 3 | int main(int argc, char* argv[]) { 4 | return foo_core(42); 5 | } 6 | -------------------------------------------------------------------------------- /examples/rich_structure/src/client/foo.h: -------------------------------------------------------------------------------- 1 | int foo_core(int); 2 | -------------------------------------------------------------------------------- /examples/rich_structure/src/client/foocore.cc: -------------------------------------------------------------------------------- 1 | #include "foo.h" 2 | 3 | int foo_core(int) { 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /examples/rich_structure/src/client/fooctl.cc: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | int main(int argc, char* argv[]) { 5 | std::cout << "fooctl does nothing" << std::endl; 6 | } 7 | -------------------------------------------------------------------------------- /examples/rich_structure/src/server/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") 16 | load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes", "pkg_filegroup", "pkg_files", "pkg_mkdirs") 17 | load("@rules_pkg//pkg:tar.bzl", "pkg_tar") 18 | 19 | cc_library( 20 | name = "foolib", 21 | srcs = [ 22 | "foocore.cc", 23 | ], 24 | hdrs = [ 25 | "foo.h", 26 | ], 27 | ) 28 | 29 | cc_binary( 30 | name = "food", 31 | srcs = [ 32 | "food.cc", 33 | ], 34 | data = [ 35 | ":foolib", 36 | ], 37 | ) 38 | 39 | pkg_files( 40 | name = "binary", 41 | srcs = [ 42 | ":food", 43 | ], 44 | attributes = pkg_attributes( 45 | group = "root", 46 | mode = "0551", 47 | owner = "root", 48 | ), 49 | prefix = "/usr/sbin", 50 | ) 51 | 52 | pkg_tar( 53 | name = "mansrc", 54 | srcs = [ 55 | "food.8", 56 | ], 57 | out = "food.8.gz", 58 | extension = ".gz", 59 | ) 60 | 61 | pkg_files( 62 | name = "manpages", 63 | srcs = [ 64 | ":mansrc", 65 | ], 66 | attributes = pkg_attributes( 67 | group = "man", 68 | mode = "0444", 69 | owner = "man", 70 | ), 71 | prefix = "man/man8", 72 | visibility = ["//visibility:public"], 73 | ) 74 | 75 | pkg_mkdirs( 76 | name = "runtime", 77 | attributes = pkg_attributes( 78 | group = "bin", 79 | mode = "0771", 80 | owner = "foo", 81 | ), 82 | dirs = [ 83 | "/var/tmp/foo", 84 | "/var/tmp/foo/queue", 85 | ], 86 | ) 87 | 88 | pkg_filegroup( 89 | name = "arch", 90 | srcs = [ 91 | ":binary", 92 | ":runtime", 93 | ], 94 | visibility = ["//visibility:public"], 95 | ) 96 | -------------------------------------------------------------------------------- /examples/rich_structure/src/server/foo.h: -------------------------------------------------------------------------------- 1 | /* foo.h */ 2 | -------------------------------------------------------------------------------- /examples/rich_structure/src/server/foocore.cc: -------------------------------------------------------------------------------- 1 | int foocore = 1; 2 | -------------------------------------------------------------------------------- /examples/rich_structure/src/server/food.8: -------------------------------------------------------------------------------- 1 | .TH FOOD 1 local 2 | .SH NAME 3 | food \- the foo daemon 4 | .SH SYNOPSIS 5 | .ll +8 6 | .B food 7 | .ll -8 8 | .SH DESCRIPTION 9 | .I Food 10 | serves the foo system. 11 | -------------------------------------------------------------------------------- /examples/rich_structure/src/server/food.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char* argv[]) { 4 | std::cout << "food does nothing" << std::endl; 5 | } 6 | -------------------------------------------------------------------------------- /examples/rpm/debuginfo/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # -*- coding: utf-8 -*- 15 | 16 | load("@rules_pkg//pkg:mappings.bzl", "pkg_files") 17 | load("@rules_pkg//pkg:rpm.bzl", "pkg_rpm") 18 | 19 | cc_binary( 20 | name = "test", 21 | srcs = [ 22 | "test.c", 23 | ], 24 | copts = ["-g"], 25 | ) 26 | 27 | pkg_files( 28 | name = "rpm_files", 29 | srcs = [ 30 | ":test", 31 | ], 32 | ) 33 | 34 | pkg_rpm( 35 | name = "test-rpm", 36 | srcs = [ 37 | ":rpm_files", 38 | ], 39 | debuginfo = True, 40 | description = "Description", 41 | license = "Some license", 42 | release = "0", 43 | summary = "Summary", 44 | version = "1", 45 | ) 46 | 47 | # If you have rpmbuild, you probably have rpm2cpio too. 48 | # Feature idea: Add rpm2cpio and cpio to the rpmbuild toolchain 49 | genrule( 50 | name = "inspect_content", 51 | srcs = [":test-rpm"], 52 | outs = ["content.txt"], 53 | cmd = "rpm2cpio $(locations :test-rpm) | cpio -ivt >$@", 54 | ) 55 | -------------------------------------------------------------------------------- /examples/rpm/debuginfo/MODULE.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2024 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | module(name = "rules_pkg_example_rpm_system_rpmbuild_bzlmod") 16 | 17 | bazel_dep(name = "rules_pkg") 18 | local_path_override( 19 | module_name = "rules_pkg", 20 | path = "../../..", 21 | ) 22 | 23 | find_rpmbuild = use_extension( 24 | "@rules_pkg//toolchains/rpm:rpmbuild_configure.bzl", 25 | "find_system_rpmbuild_bzlmod", 26 | ) 27 | use_repo(find_rpmbuild, "rules_pkg_rpmbuild") 28 | 29 | register_toolchains( 30 | "@rules_pkg_rpmbuild//:all", 31 | ) 32 | -------------------------------------------------------------------------------- /examples/rpm/debuginfo/README.md: -------------------------------------------------------------------------------- 1 | # Using system rpmbuild with bzlmod and generating debuginfo 2 | 3 | ## Summary 4 | 5 | This example uses the `find_system_rpmbuild_bzlmod` module extension to help 6 | us register the system rpmbuild as a toolchain in a bzlmod environment. 7 | 8 | It configures the system toolchain to be aware of which debuginfo configuration 9 | to use (defaults to "none", the example uses "centos7"). 10 | 11 | ## To use 12 | 13 | ``` 14 | bazel build :* 15 | rpm2cpio bazel-bin/test-rpm.rpm | cpio -ivt 16 | cat bazel-bin/content.txt 17 | ``` 18 | -------------------------------------------------------------------------------- /examples/rpm/debuginfo/test.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return 0; 3 | } 4 | -------------------------------------------------------------------------------- /examples/rpm/nospecfile/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2024 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # -*- coding: utf-8 -*- 15 | 16 | load("@rules_pkg//pkg:mappings.bzl", "pkg_files") 17 | load("@rules_pkg//pkg:rpm.bzl", "pkg_rpm") 18 | 19 | pkg_files( 20 | name = "rpm_files", 21 | srcs = [ 22 | "BUILD", 23 | "MODULE.bazel", 24 | "README.md", 25 | ], 26 | ) 27 | 28 | pkg_rpm( 29 | name = "test-rpm", 30 | srcs = [ 31 | ":rpm_files", 32 | ], 33 | architecture = "x86_64", 34 | description = "This is a package description.", 35 | license = "Apache License, v2.0", 36 | provides = [ 37 | "somefile", 38 | ], 39 | release = "0", 40 | requires = [ 41 | "somerpm", 42 | ], 43 | summary = "rules_pkg example RPM", 44 | version = "1", 45 | ) 46 | 47 | # If you have rpmbuild, you probably have rpm2cpio too. 48 | # Feature idea: Add rpm2cpio and cpio to the rpmbuild toolchain 49 | genrule( 50 | name = "inspect_content", 51 | srcs = [":test-rpm"], 52 | outs = ["content.txt"], 53 | cmd = "rpm2cpio $(locations :test-rpm) | cpio -ivt >$@", 54 | ) 55 | -------------------------------------------------------------------------------- /examples/rpm/nospecfile/MODULE.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2024 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | module(name = "rules_pkg_example_rpm_system_rpmbuild_bzlmod") 16 | 17 | bazel_dep(name = "rules_pkg") 18 | local_path_override( 19 | module_name = "rules_pkg", 20 | path = "../../..", 21 | ) 22 | 23 | find_rpmbuild = use_extension( 24 | "@rules_pkg//toolchains/rpm:rpmbuild_configure.bzl", 25 | "find_system_rpmbuild_bzlmod", 26 | ) 27 | use_repo(find_rpmbuild, "rules_pkg_rpmbuild") 28 | 29 | register_toolchains( 30 | "@rules_pkg_rpmbuild//:all", 31 | ) 32 | -------------------------------------------------------------------------------- /examples/rpm/nospecfile/README.md: -------------------------------------------------------------------------------- 1 | # Using system rpmbuild with bzlmod 2 | 3 | ## Summary 4 | 5 | This example builds an RPM using the system `rpmbuild` from a pure bazel 6 | `pkg_rpm()` definition instead of using a separate specfile. 7 | 8 | ## To use 9 | 10 | ``` 11 | bazel build :* 12 | rpm2cpio bazel-bin/test-rpm.rpm | cpio -ivt 13 | cat bazel-bin/content.txt 14 | ``` 15 | -------------------------------------------------------------------------------- /examples/rpm/prebuilt_rpmbuild/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # -*- coding: utf-8 -*- 15 | 16 | load("@rules_pkg//pkg:rpm.bzl", "pkg_rpm") 17 | 18 | pkg_rpm( 19 | name = "test-rpm", 20 | data = [ 21 | "BUILD", 22 | "README.md", 23 | "WORKSPACE", 24 | "test_rpm.spec", 25 | ], 26 | release = "0", 27 | spec_file = "test_rpm.spec", 28 | version = "1", 29 | ) 30 | 31 | # If you have rpmbuild, you probably have rpm2cpio too. 32 | # Feature idea: Add rpm2cpio and cpio to the rpmbuild toolchain 33 | genrule( 34 | name = "inspect_content", 35 | srcs = [":test-rpm"], 36 | outs = ["content.txt"], 37 | cmd = "rpm2cpio $(locations :test-rpm) | cpio -ivt >$@", 38 | ) 39 | -------------------------------------------------------------------------------- /examples/rpm/prebuilt_rpmbuild/README.md: -------------------------------------------------------------------------------- 1 | # Using a prebuilt rpmbuild instead of the system one. 2 | 3 | ## Summary 4 | 5 | This example defines a rpmbuild toolchain in `local` that can be used 6 | by rules_pkg. This must be copied into place as `local/rpmbuild_binary` 7 | for use by `register_toolchains()`. 8 | 9 | The RPM itself is based on a user provided spec file. 10 | 11 | ## To use 12 | 13 | ``` 14 | cp /usr/bin/rpmbuild local/rpmbuild_binary 15 | bazel build :* 16 | rpm2cpio bazel-bin/test-rpm.rpm | cpio -ivt 17 | cat bazel-bin/content.txt 18 | ``` 19 | -------------------------------------------------------------------------------- /examples/rpm/prebuilt_rpmbuild/WORKSPACE: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | workspace(name = "rules_pkg_example_rpm_prebuilt_rpmbuild") 16 | 17 | local_repository( 18 | name = "rules_pkg", 19 | path = "../../..", 20 | ) 21 | 22 | load("@rules_pkg//pkg:deps.bzl", "rules_pkg_dependencies") 23 | 24 | rules_pkg_dependencies() 25 | 26 | load("//local:rpmbuild.bzl", "register_my_rpmbuild_toolchain") 27 | 28 | register_my_rpmbuild_toolchain() 29 | -------------------------------------------------------------------------------- /examples/rpm/prebuilt_rpmbuild/local/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@rules_pkg//toolchains/rpm:rpmbuild.bzl", "rpmbuild_toolchain") 16 | 17 | rpmbuild_toolchain( 18 | name = "prebuilt_rpmbuild", 19 | # You could also point to a target that builds rpmbuild from source. 20 | label = ":rpmbuild_binary", 21 | ) 22 | 23 | toolchain( 24 | name = "local_rpmbuild", 25 | toolchain = ":prebuilt_rpmbuild", 26 | toolchain_type = "@rules_pkg//toolchains/rpm:rpmbuild_toolchain_type", 27 | ) 28 | -------------------------------------------------------------------------------- /examples/rpm/prebuilt_rpmbuild/local/rpmbuild.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Register a prebuilt rpmbuild.""" 15 | 16 | # buildifier: disable=unnamed-macro 17 | def register_my_rpmbuild_toolchain(): 18 | """Register a prebuilt rpmbuild.""" 19 | native.register_toolchains("//local:local_rpmbuild") 20 | -------------------------------------------------------------------------------- /examples/rpm/prebuilt_rpmbuild/local/rpmbuild_binary: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo Replace me with a real rpmbuild 4 | -------------------------------------------------------------------------------- /examples/rpm/prebuilt_rpmbuild/test_rpm.spec: -------------------------------------------------------------------------------- 1 | Name: example 2 | Version: 0 3 | Release: 1 4 | Summary: Example .spec file 5 | License: Apache License, v2.0 6 | 7 | # Do not try to use magic to determine file types 8 | %define __spec_install_post %{nil} 9 | # Do not die because we give it more input files than are in the files section 10 | %define _unpackaged_files_terminate_build 0 11 | 12 | %description 13 | This is a package description. 14 | 15 | %build 16 | 17 | %install 18 | cp WORKSPACE BUILD README.md test_rpm.spec %{buildroot}/ 19 | 20 | %files 21 | /WORKSPACE 22 | /BUILD 23 | /README.md 24 | /test_rpm.spec 25 | -------------------------------------------------------------------------------- /examples/rpm/subrpm/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2024 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # -*- coding: utf-8 -*- 15 | 16 | load("@rules_pkg//pkg:mappings.bzl", "pkg_files") 17 | load("@rules_pkg//pkg:rpm.bzl", "pkg_rpm", "pkg_sub_rpm") 18 | 19 | pkg_files( 20 | name = "subrpm_files", 21 | srcs = [ 22 | "BUILD", 23 | ], 24 | ) 25 | 26 | pkg_sub_rpm( 27 | name = "subrpm", 28 | package_name = "subrpm", 29 | srcs = [ 30 | ":subrpm_files", 31 | ], 32 | description = "Test subrpm description", 33 | provides = [ 34 | "someprovision", 35 | ], 36 | requires = [ 37 | "somerpm", 38 | ], 39 | summary = "Test subrpm", 40 | ) 41 | 42 | pkg_files( 43 | name = "rpm_files", 44 | srcs = [ 45 | "MODULE.bazel", 46 | "README.md", 47 | ], 48 | ) 49 | 50 | pkg_rpm( 51 | name = "test-rpm", 52 | srcs = [ 53 | ":rpm_files", 54 | ], 55 | architecture = "x86_64", 56 | description = "This is a package description.", 57 | license = "Apache License, v2.0", 58 | provides = [ 59 | "somefile", 60 | ], 61 | release = "0", 62 | requires = [ 63 | "somerpm", 64 | ], 65 | subrpms = [ 66 | ":subrpm", 67 | ], 68 | summary = "rules_pkg example RPM", 69 | version = "1", 70 | ) 71 | 72 | # If you have rpmbuild, you probably have rpm2cpio too. 73 | # Feature idea: Add rpm2cpio and cpio to the rpmbuild toolchain 74 | genrule( 75 | name = "inspect_content", 76 | srcs = [":test-rpm"], 77 | outs = ["content.txt"], 78 | cmd = "rpm2cpio $(locations :test-rpm) | cpio -ivt >$@", 79 | ) 80 | -------------------------------------------------------------------------------- /examples/rpm/subrpm/MODULE.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2024 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | module(name = "rules_pkg_example_rpm_system_rpmbuild_bzlmod") 16 | 17 | bazel_dep(name = "rules_pkg") 18 | local_path_override( 19 | module_name = "rules_pkg", 20 | path = "../../..", 21 | ) 22 | 23 | find_rpmbuild = use_extension( 24 | "@rules_pkg//toolchains/rpm:rpmbuild_configure.bzl", 25 | "find_system_rpmbuild_bzlmod", 26 | ) 27 | use_repo(find_rpmbuild, "rules_pkg_rpmbuild") 28 | 29 | register_toolchains( 30 | "@rules_pkg_rpmbuild//:all", 31 | ) 32 | -------------------------------------------------------------------------------- /examples/rpm/subrpm/README.md: -------------------------------------------------------------------------------- 1 | # Using system rpmbuild with bzlmod 2 | 3 | ## Summary 4 | 5 | This example builds an RPM using the system `rpmbuild` from a pure bazel 6 | `pkg_rpm()` definition instead of using a separate specfile. 7 | 8 | ## To use 9 | 10 | ``` 11 | bazel build :* 12 | rpm2cpio bazel-bin/test-rpm.rpm | cpio -ivt 13 | cat bazel-bin/content.txt 14 | ``` 15 | -------------------------------------------------------------------------------- /examples/rpm/system_rpmbuild/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # -*- coding: utf-8 -*- 15 | 16 | load("@rules_pkg//pkg:rpm.bzl", "pkg_rpm") 17 | 18 | pkg_rpm( 19 | name = "test-rpm", 20 | data = [ 21 | "BUILD", 22 | "README.md", 23 | "WORKSPACE", 24 | "test_rpm.spec", 25 | ], 26 | release = "0", 27 | spec_file = "test_rpm.spec", 28 | version = "1", 29 | ) 30 | 31 | # If you have rpmbuild, you probably have rpm2cpio too. 32 | # Feature idea: Add rpm2cpio and cpio to the rpmbuild toolchain 33 | genrule( 34 | name = "inspect_content", 35 | srcs = [":test-rpm"], 36 | outs = ["content.txt"], 37 | cmd = "rpm2cpio $(locations :test-rpm) | cpio -ivt >$@", 38 | ) 39 | -------------------------------------------------------------------------------- /examples/rpm/system_rpmbuild/README.md: -------------------------------------------------------------------------------- 1 | # Using system rpmbuild 2 | 3 | ## Summary 4 | 5 | This example uses the `find_system_rpmbuild()` macro built into `rules_pkg` 6 | to search for `rpmbuild` in on the local system and use that to drive the 7 | packaging process. 8 | 9 | The RPM itself is based on a user provided spec file. 10 | 11 | ## To use 12 | 13 | ``` 14 | bazel build :* 15 | rpm2cpio bazel-bin/test-rpm.rpm | cpio -ivt 16 | cat bazel-bin/content.txt 17 | ``` 18 | -------------------------------------------------------------------------------- /examples/rpm/system_rpmbuild/WORKSPACE: -------------------------------------------------------------------------------- 1 | # Copyright 2024 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | workspace(name = "rules_pkg_example_rpm_system_rpmbuild") 16 | 17 | local_repository( 18 | name = "rules_pkg", 19 | path = "../../..", 20 | ) 21 | 22 | load("@rules_pkg//pkg:deps.bzl", "rules_pkg_dependencies") 23 | 24 | rules_pkg_dependencies() 25 | 26 | load( 27 | "@rules_pkg//toolchains/rpm:rpmbuild_configure.bzl", 28 | "find_system_rpmbuild", 29 | ) 30 | 31 | find_system_rpmbuild(name = "my_rpmbuild") 32 | -------------------------------------------------------------------------------- /examples/rpm/system_rpmbuild/test_rpm.spec: -------------------------------------------------------------------------------- 1 | Name: example 2 | Version: 0 3 | Release: 1 4 | Summary: Example .spec file 5 | License: Apache License, v2.0 6 | 7 | # Do not try to use magic to determine file types 8 | %define __spec_install_post %{nil} 9 | # Do not die because we give it more input files than are in the files section 10 | %define _unpackaged_files_terminate_build 0 11 | 12 | %description 13 | This is a package description. 14 | 15 | %build 16 | 17 | %install 18 | cp WORKSPACE BUILD README.md test_rpm.spec %{buildroot}/ 19 | 20 | %files 21 | /WORKSPACE 22 | /BUILD 23 | /README.md 24 | /test_rpm.spec 25 | -------------------------------------------------------------------------------- /examples/rpm/system_rpmbuild_bzlmod/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # -*- coding: utf-8 -*- 15 | 16 | load("@rules_pkg//pkg:rpm.bzl", "pkg_rpm") 17 | 18 | pkg_rpm( 19 | name = "test-rpm", 20 | data = [ 21 | "BUILD", 22 | "MODULE.bazel", 23 | "README.md", 24 | "test_rpm.spec", 25 | ], 26 | release = "0", 27 | spec_file = "test_rpm.spec", 28 | version = "1", 29 | ) 30 | 31 | # If you have rpmbuild, you probably have rpm2cpio too. 32 | # Feature idea: Add rpm2cpio and cpio to the rpmbuild toolchain 33 | genrule( 34 | name = "inspect_content", 35 | srcs = [":test-rpm"], 36 | outs = ["content.txt"], 37 | cmd = "rpm2cpio $(locations :test-rpm) | cpio -ivt >$@", 38 | ) 39 | -------------------------------------------------------------------------------- /examples/rpm/system_rpmbuild_bzlmod/MODULE.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2024 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | module(name = "rules_pkg_example_rpm_system_rpmbuild_bzlmod") 16 | 17 | bazel_dep(name = "rules_pkg") 18 | local_path_override( 19 | module_name = "rules_pkg", 20 | path = "../../..", 21 | ) 22 | 23 | find_rpmbuild = use_extension( 24 | "@rules_pkg//toolchains/rpm:rpmbuild_configure.bzl", 25 | "find_system_rpmbuild_bzlmod", 26 | ) 27 | use_repo(find_rpmbuild, "rules_pkg_rpmbuild") 28 | 29 | register_toolchains( 30 | "@rules_pkg_rpmbuild//:all", 31 | ) 32 | -------------------------------------------------------------------------------- /examples/rpm/system_rpmbuild_bzlmod/README.md: -------------------------------------------------------------------------------- 1 | # Using system rpmbuild with bzlmod 2 | 3 | ## Summary 4 | 5 | This example uses the `find_system_rpmbuild_bzlmod` module extension to help 6 | us register the system rpmbuild as a toolchain in a bzlmod environment. 7 | 8 | The RPM itself is based on a user provided spec file. 9 | 10 | ## To use 11 | 12 | ``` 13 | bazel build :* 14 | rpm2cpio bazel-bin/test-rpm.rpm | cpio -ivt 15 | cat bazel-bin/content.txt 16 | ``` 17 | -------------------------------------------------------------------------------- /examples/rpm/system_rpmbuild_bzlmod/test_rpm.spec: -------------------------------------------------------------------------------- 1 | Name: example 2 | Version: 0 3 | Release: 1 4 | Summary: Example .spec file 5 | License: Apache License, v2.0 6 | 7 | # Do not try to use magic to determine file types 8 | %define __spec_install_post %{nil} 9 | # Do not die because we give it more input files than are in the files section 10 | %define _unpackaged_files_terminate_build 0 11 | 12 | %description 13 | This is a package description. 14 | 15 | %build 16 | 17 | %install 18 | cp MODULE.bazel BUILD README.md test_rpm.spec %{buildroot}/ 19 | 20 | %files 21 | /MODULE.bazel 22 | /BUILD 23 | /README.md 24 | /test_rpm.spec 25 | -------------------------------------------------------------------------------- /examples/time_stamping/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # -*- coding: utf-8 -*- 15 | 16 | load("@rules_pkg//pkg:tar.bzl", "pkg_tar") 17 | 18 | licenses(["notice"]) 19 | 20 | pkg_tar( 21 | name = "never_stamped", 22 | srcs = [ 23 | ":BUILD", 24 | ], 25 | ) 26 | 27 | pkg_tar( 28 | name = "always_stamped", 29 | srcs = [ 30 | ":BUILD", 31 | ], 32 | stamp = 1, 33 | ) 34 | 35 | pkg_tar( 36 | name = "controlled_by_stamp_option", 37 | srcs = [ 38 | ":BUILD", 39 | ], 40 | stamp = -1, 41 | ) 42 | -------------------------------------------------------------------------------- /examples/time_stamping/MODULE.bazel: -------------------------------------------------------------------------------- 1 | module( 2 | name = "rules_pkg_examples", 3 | version = "0.0.1", 4 | ) 5 | 6 | bazel_dep(name = "rules_pkg") 7 | local_path_override( 8 | module_name = "rules_pkg", 9 | path = "../..", 10 | ) 11 | -------------------------------------------------------------------------------- /examples/time_stamping/readme.md: -------------------------------------------------------------------------------- 1 | # Examples of how time stamping works. 2 | 3 | ## How it works 4 | 5 | Target declarations may use the `stamp` attribute to control 6 | the time stamping of files in an archive. The behavior follows 7 | the pattern of the cc_binary rule: 8 | 9 | https://docs.bazel.build/versions/main/be/c-cpp.html#cc_binary 10 | 11 | Read the BUILD file for more details. 12 | 13 | ## Try this 14 | 15 | ``` 16 | bazel build :* 17 | for tarball in bazel-bin/*.tar ; do 18 | echo ==== $tarball 19 | tar tvf $tarball 20 | done 21 | 22 | bazel build :* --stamp=1 23 | for tarball in bazel-bin/*.tar ; do 24 | echo ==== $tarball 25 | tar tvf $tarball 26 | done 27 | ``` 28 | 29 | You should see something like: 30 | ``` 31 | INFO: Build completed successfully, 3 total actions 32 | ==== bazel-bin/always_stamped.tar 33 | -r-xr-xr-x 0 0 0 968 May 3 17:34 BUILD 34 | ==== bazel-bin/controlled_by_stamp_option.tar 35 | -r-xr-xr-x 0 0 0 968 Dec 31 1999 BUILD 36 | ==== bazel-bin/never_stamped.tar 37 | -r-xr-xr-x 0 0 0 968 Dec 31 1999 BUILD 38 | INFO: Build option --stamp has changed, discarding analysis cache. 39 | INFO: Build completed successfully, 3 total actions 40 | ==== bazel-bin/always_stamped.tar 41 | -r-xr-xr-x 0 0 0 968 May 3 17:34 BUILD 42 | ==== bazel-bin/controlled_by_stamp_option.ta 43 | -r-xr-xr-x 0 0 0 968 May 6 17:42 BUILD 44 | ==== bazel-bin/never_stamped.tar 45 | -r-xr-xr-x 0 0 0 968 Dec 31 1999 BUILD 46 | ``` 47 | -------------------------------------------------------------------------------- /examples/where_is_my_output/BUILD: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Copyright 2021 The Bazel Authors. All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # Build a trivial .deb package to show how to find the output files. 16 | 17 | load("@rules_pkg//pkg:deb.bzl", "pkg_deb") 18 | load("@rules_pkg//pkg:tar.bzl", "pkg_tar") 19 | 20 | genrule( 21 | name = "generate_files", 22 | outs = [ 23 | "etc/example.conf", 24 | "usr/bin/a_binary", 25 | ], 26 | cmd = "for i in $(OUTS); do echo 1 >$$i; done", 27 | ) 28 | 29 | pkg_tar( 30 | name = "content", 31 | srcs = [":generate_files"], 32 | ) 33 | 34 | pkg_deb( 35 | name = "deb", 36 | data = ":content", 37 | description = "My wonderful product", 38 | maintainer = "someone@somewhere.com", 39 | package = "mwp", 40 | version = "3.14", 41 | ) 42 | 43 | # We can also depend just on the .changes file 44 | 45 | filegroup( 46 | name = "the_changes_file", 47 | srcs = [":deb"], 48 | output_group = "changes", 49 | ) 50 | 51 | genrule( 52 | name = "use_changes_file", 53 | srcs = [":the_changes_file"], 54 | outs = ["copy_of_changes.txt"], 55 | cmd = "cp $(location :the_changes_file) $@", 56 | ) 57 | -------------------------------------------------------------------------------- /examples/where_is_my_output/MODULE.bazel: -------------------------------------------------------------------------------- 1 | module( 2 | name = "rules_pkg_examples", 3 | version = "0.0.1", 4 | ) 5 | 6 | bazel_dep(name = "rules_pkg") 7 | local_path_override( 8 | module_name = "rules_pkg", 9 | path = "../..", 10 | ) 11 | -------------------------------------------------------------------------------- /examples/where_is_my_output/show_all_outputs.bzl: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Copyright 2021 The Bazel Authors. All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | """ 16 | Extract the paths to the various outputs of pkg_deb 17 | 18 | Usage: 19 | bazel cquery //pkg:deb --output=starlark --starlark:file=show_all_outputs.bzl 20 | """ 21 | 22 | # buildifier: disable=function-docstring 23 | def format(target): 24 | provider_map = providers(target) 25 | output_group_info = provider_map["OutputGroupInfo"] 26 | 27 | # Look at the attributes of the provider. Visit the depsets. 28 | ret = [] 29 | for attr in dir(output_group_info): 30 | if attr.startswith("_"): 31 | continue 32 | attr_value = getattr(output_group_info, attr) 33 | if type(attr_value) == "depset": 34 | for file in attr_value.to_list(): 35 | ret.append("%s: %s" % (attr, file.path)) 36 | return "\n".join(ret) 37 | -------------------------------------------------------------------------------- /mappings.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """File mappings for packaging rules.""" 16 | 17 | load( 18 | "//pkg:mappings.bzl", 19 | _REMOVE_BASE_DIRECTORY = "REMOVE_BASE_DIRECTORY", 20 | _filter_directory = "filter_directory", 21 | _pkg_attributes = "pkg_attributes", 22 | _pkg_filegroup = "pkg_filegroup", 23 | _pkg_files = "pkg_files", 24 | _pkg_mkdirs = "pkg_mkdirs", 25 | _pkg_mklink = "pkg_mklink", 26 | _strip_prefix = "strip_prefix", 27 | ) 28 | 29 | REMOVE_BASE_DIRECTORY = _REMOVE_BASE_DIRECTORY 30 | 31 | filter_directory = _filter_directory 32 | 33 | pkg_attributes = _pkg_attributes 34 | 35 | pkg_filegroup = _pkg_filegroup 36 | 37 | pkg_files = _pkg_files 38 | 39 | pkg_mkdirs = _pkg_mkdirs 40 | 41 | pkg_mklink = _pkg_mklink 42 | 43 | strip_prefix = _strip_prefix 44 | -------------------------------------------------------------------------------- /patching.md: -------------------------------------------------------------------------------- 1 | # Patch Acceptance Process 2 | 3 | - PRs that change or add behavior are not accepted without being tied to an 4 | issue. Most fixes, even if you think they are obvious, require an issue 5 | too. Almost every change breaks someone who has depended on the behavior, 6 | even broken behavior. 7 | - Significant changes need a design document. Please create an issue describing 8 | the proposed change, and post a link to it to rules-pkg-discuss@googlegroups.com. 9 | Wait for discussion to come to agreement before proceeding. 10 | - Features and bug fixes should be as portable as possible. 11 | - do not not disable tests on Windows because it is convenient for you 12 | - if a feature is only available on specific platforms, it must be optional. That 13 | is, it requires a distinct bzlmod MODULE 14 | - All fixes and features must have tests. 15 | - Ensure you've signed a [Contributor License 16 | Agreement](https://cla.developers.google.com). 17 | - Send us a pull request on 18 | [GitHub](https://github.com/bazelbuild/rules_pkg/pulls). If you're new to GitHub, 19 | read [about pull 20 | requests](https://help.github.com/articles/about-pull-requests/). Note that 21 | we restrict permissions to create branches on the main repository, so 22 | you will need to push your commit to [your own fork of the 23 | repository](https://help.github.com/articles/working-with-forks/). 24 | - Wait for a repository owner to assign you a reviewer. We strive to do that 25 | within 4 business days, but it may take longer. If your review gets lost 26 | you can escalate by starting a thread on 27 | [GitHub Discussions](https://github.com/bazelbuild/bazel/discussions). 28 | - Work with the reviewer to complete a code review. For each change, create a 29 | new commit and push it to make changes to your pull request. 30 | - A maintainer will approve the PR and merge it. 31 | 32 | Tips 33 | - Large PRs are harder to review. If you have to refactor code to implement a feature 34 | please split that into at least 2 PRs. The first to refactor without changing behavior 35 | and the second to implemtn the new behavior. Of course, as above, any PR that large 36 | should be discussed in an issue first 37 | - Please do not send PRs that update dependencies (WORKSPACE or MODULE.bzl) just to 38 | stay at head. We try to maintain backwards compatibility to LTS releases as long as 39 | possible, so we only update to new versions of dependencies when it is required. 40 | 41 | For further information about working with Bazel and rules in general: 42 | - Read the [Bazel governance plan](https://www.bazel.build/governance.html). 43 | - Read the [contributing to Bazel](https://www.bazel.build/contributing.html) guide. 44 | -------------------------------------------------------------------------------- /pkg.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """Rules for manipulation of various packaging.""" 16 | 17 | load("//pkg:deb.bzl", _pkg_deb = "pkg_deb") 18 | load("//pkg:tar.bzl", _pkg_tar = "pkg_tar") 19 | load("//pkg:zip.bzl", _pkg_zip = "pkg_zip") 20 | 21 | pkg_deb = _pkg_deb 22 | pkg_tar = _pkg_tar 23 | pkg_zip = _pkg_zip 24 | -------------------------------------------------------------------------------- /pkg/.bazelignore: -------------------------------------------------------------------------------- 1 | tests/external_project 2 | -------------------------------------------------------------------------------- /pkg/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazelbuild/rules_pkg/c590e619313f3227c06541b00deb6074680b8922/pkg/__init__.py -------------------------------------------------------------------------------- /pkg/deb.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Forwarder for pkg_deb.""" 15 | 16 | load("//pkg/private/deb:deb.bzl", _pkg_deb = "pkg_deb") 17 | 18 | pkg_deb = _pkg_deb 19 | -------------------------------------------------------------------------------- /pkg/deps.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """WORKSPACE dependencies for rules_pkg/pkg.""" 16 | 17 | load("@bazel_tools//tools/build_defs/repo:http.bzl", _http_archive = "http_archive") 18 | load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") 19 | 20 | def http_archive(**kwargs): 21 | maybe(_http_archive, **kwargs) 22 | 23 | def rules_pkg_dependencies(): 24 | http_archive( 25 | name = "bazel_skylib", 26 | sha256 = "bc283cdfcd526a52c3201279cda4bc298652efa898b10b4db0837dc51652756f", 27 | urls = [ 28 | "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz", 29 | "https://github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz", 30 | ], 31 | ) 32 | 33 | http_archive( 34 | name = "platforms", 35 | urls = [ 36 | "https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.10/platforms-0.0.10.tar.gz", 37 | "https://github.com/bazelbuild/platforms/releases/download/0.0.10/platforms-0.0.10.tar.gz", 38 | ], 39 | sha256 = "218efe8ee736d26a3572663b374a253c012b716d8af0c07e842e82f238a0a7ee", 40 | ) 41 | 42 | http_archive( 43 | name = "rules_python", 44 | sha256 = "4f7e2aa1eb9aa722d96498f5ef514f426c1f55161c3c9ae628c857a7128ceb07", 45 | strip_prefix = "rules_python-1.0.0", 46 | url = "https://github.com/bazelbuild/rules_python/releases/download/1.0.0/rules_python-1.0.0.tar.gz", 47 | ) 48 | 49 | http_archive( 50 | name = "rules_license", 51 | urls = [ 52 | "https://mirror.bazel.build/github.com/bazelbuild/rules_license/releases/download/1.0.0/rules_license-1.0.0.tar.gz", 53 | "https://github.com/bazelbuild/rules_license/releases/download/1.0.0/rules_license-1.0.0.tar.gz", 54 | ], 55 | sha256 = "26d4021f6898e23b82ef953078389dd49ac2b5618ac564ade4ef87cced147b38", 56 | ) 57 | 58 | def rules_pkg_register_toolchains(): 59 | pass 60 | -------------------------------------------------------------------------------- /pkg/legacy/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | package(default_applicable_licenses = ["//:license"]) 16 | 17 | exports_files(["rpm.bzl"]) 18 | 19 | filegroup( 20 | name = "standard_package", 21 | srcs = glob([ 22 | "*.bzl", 23 | ]) + [ 24 | "BUILD", 25 | ], 26 | visibility = ["//pkg:__pkg__"], 27 | ) 28 | -------------------------------------------------------------------------------- /pkg/legacy/tests/rpm/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # -*- coding: utf-8 -*- 15 | 16 | load("//pkg:rpm.bzl", "pkg_rpm") 17 | 18 | package(default_applicable_licenses = ["//:license"]) 19 | 20 | pkg_rpm( 21 | name = "test-rpm", 22 | data = [ 23 | "BUILD", 24 | "//pkg/legacy:rpm.bzl", 25 | ], 26 | debug = 1, 27 | release = "0", 28 | spec_file = "test_rpm.spec", 29 | version = "1", 30 | ) 31 | -------------------------------------------------------------------------------- /pkg/legacy/tests/rpm/test_rpm.spec: -------------------------------------------------------------------------------- 1 | Name: rules_pkg 2 | Version: 0 3 | Release: 1 4 | Summary: Test data 5 | URL: https://github.com/bazelbuild/rules_pkg 6 | License: Apache License, v2.0 7 | 8 | # Do not try to use magic to determine file types 9 | %define __spec_install_post %{nil} 10 | # Do not die because we give it more input files than are in the files section 11 | %define _unpackaged_files_terminate_build 0 12 | 13 | %description 14 | This is a package description. 15 | 16 | %prep 17 | 18 | %build 19 | 20 | %install 21 | cp -r ./pkg/legacy %{buildroot}/ 22 | 23 | %files 24 | /legacy/rpm.bzl 25 | /legacy/tests/rpm/BUILD 26 | -------------------------------------------------------------------------------- /pkg/package_variables.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """Utility methods to populate PackageVariablesInfo instances.""" 16 | 17 | def add_ctx_variables(ctx, values): 18 | """Add selected variables from ctx.""" 19 | values["target_cpu"] = ctx.var.get("TARGET_CPU") 20 | values["compilation_mode"] = ctx.var.get("COMPILATION_MODE") 21 | return values 22 | -------------------------------------------------------------------------------- /pkg/pkg.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2015 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """Rules for manipulation of various packaging.""" 16 | 17 | load("//pkg/private/deb:deb.bzl", _pkg_deb = "pkg_deb") 18 | load("//pkg/private/tar:tar.bzl", _pkg_tar = "pkg_tar") 19 | load("//pkg/private/zip:zip.bzl", _pkg_zip = "pkg_zip") 20 | 21 | pkg_deb = _pkg_deb 22 | pkg_tar = _pkg_tar 23 | pkg_zip = _pkg_zip 24 | -------------------------------------------------------------------------------- /pkg/private/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """rules_pkg internal code. 15 | 16 | All interfaces are subject to change at any time. 17 | """ 18 | 19 | load("@rules_python//python:defs.bzl", "py_library") 20 | 21 | package(default_applicable_licenses = ["//:license"]) 22 | 23 | filegroup( 24 | name = "standard_package", 25 | srcs = [ 26 | "BUILD", 27 | "install.py.tpl", 28 | ] + glob([ 29 | "*.bzl", 30 | "*.py", 31 | ]), 32 | visibility = [ 33 | "//distro:__pkg__", 34 | "//pkg:__pkg__", 35 | ], 36 | ) 37 | 38 | exports_files( 39 | glob([ 40 | "*.bzl", 41 | ]), 42 | visibility = [ 43 | "//distro:__pkg__", 44 | "//doc_build:__pkg__", 45 | "//pkg:__pkg__", 46 | ], 47 | ) 48 | 49 | # pkg_install's template script file 50 | exports_files( 51 | ["install.py.tpl"], 52 | visibility = ["//visibility:public"], 53 | ) 54 | 55 | config_setting( 56 | name = "private_stamp_detect", 57 | values = {"stamp": "1"}, 58 | # When --incompatible_config_setting_private_default_visibility is set, this fails unless this is public. 59 | # TODO: refactor to clear up confusion that this is a "private" target with public access. 60 | visibility = ["//visibility:public"], 61 | ) 62 | 63 | py_library( 64 | name = "build_info", 65 | srcs = [ 66 | "build_info.py", 67 | ], 68 | imports = ["../.."], 69 | srcs_version = "PY3", 70 | visibility = [ 71 | "//:__subpackages__", 72 | "//tests:__pkg__", 73 | ], 74 | ) 75 | 76 | py_library( 77 | name = "archive", 78 | srcs = [ 79 | "__init__.py", 80 | "archive.py", 81 | ], 82 | imports = ["../.."], 83 | srcs_version = "PY3", 84 | visibility = [ 85 | "//:__subpackages__", 86 | "//tests:__subpackages__", 87 | ], 88 | ) 89 | 90 | py_library( 91 | name = "helpers", 92 | srcs = [ 93 | "__init__.py", 94 | "helpers.py", 95 | ], 96 | imports = ["../.."], 97 | srcs_version = "PY3", 98 | visibility = [ 99 | "//:__subpackages__", 100 | "//tests:__pkg__", 101 | ], 102 | ) 103 | 104 | py_library( 105 | name = "manifest", 106 | srcs = ["manifest.py"], 107 | imports = ["../.."], 108 | srcs_version = "PY3", 109 | visibility = ["//visibility:public"], 110 | ) 111 | -------------------------------------------------------------------------------- /pkg/private/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazelbuild/rules_pkg/c590e619313f3227c06541b00deb6074680b8922/pkg/private/__init__.py -------------------------------------------------------------------------------- /pkg/private/archive.py: -------------------------------------------------------------------------------- 1 | # Copyright 2015 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Archive reader library for the .deb file testing.""" 15 | 16 | import io 17 | import os 18 | 19 | class SimpleArReader(object): 20 | """A simple AR file reader. 21 | 22 | This enable to read AR file (System V variant) as described 23 | in https://en.wikipedia.org/wiki/Ar_(Unix). 24 | 25 | The standard usage of this class is: 26 | 27 | with SimpleArReader(filename) as ar: 28 | nextFile = ar.next() 29 | while nextFile: 30 | print('This archive contains', nextFile.filename) 31 | nextFile = ar.next() 32 | 33 | Upon error, this class will raise a ArError exception. 34 | """ 35 | 36 | class ArError(Exception): 37 | pass 38 | 39 | class SimpleArFileEntry(object): 40 | """Represent one entry in a AR archive. 41 | 42 | Attributes: 43 | filename: the filename of the entry, as described in the archive. 44 | timestamp: the timestamp of the file entry. 45 | owner_id: numeric id of the user and group owning the file. 46 | group_id: numeric id of the user and group owning the file. 47 | mode: unix permission mode of the file 48 | size: size of the file 49 | data: the content of the file. 50 | """ 51 | 52 | def __init__(self, f): 53 | self.filename = f.read(16).decode('utf-8').strip() 54 | if self.filename.endswith('/'): # SysV variant 55 | self.filename = self.filename[:-1] 56 | self.timestamp = int(f.read(12).strip()) 57 | self.owner_id = int(f.read(6).strip()) 58 | self.group_id = int(f.read(6).strip()) 59 | self.mode = int(f.read(8).strip(), 8) 60 | self.size = int(f.read(10).strip()) 61 | pad = f.read(2) 62 | if pad != b'\x60\x0a': 63 | raise SimpleArReader.ArError('Invalid AR file header') 64 | self.data = f.read(self.size) 65 | 66 | MAGIC_STRING = b'!\n' 67 | 68 | def __init__(self, filename): 69 | self.filename = filename 70 | 71 | def __enter__(self): 72 | self.f = open(self.filename, 'rb') 73 | if self.f.read(len(self.MAGIC_STRING)) != self.MAGIC_STRING: 74 | raise self.ArError('Not a ar file: ' + self.filename) 75 | return self 76 | 77 | def __exit__(self, t, v, traceback): 78 | self.f.close() 79 | 80 | def next(self): 81 | """Read the next file. Returns None when reaching the end of file.""" 82 | # AR sections are two bit aligned using new lines. 83 | if self.f.tell() % 2 != 0: 84 | self.f.read(1) 85 | # An AR sections is at least 60 bytes. Some file might contains garbage 86 | # bytes at the end of the archive, ignore them. 87 | if self.f.tell() > os.fstat(self.f.fileno()).st_size - 60: 88 | return None 89 | return self.SimpleArFileEntry(self.f) 90 | -------------------------------------------------------------------------------- /pkg/private/build_info.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Get BUILD_TIMESTAMP.""" 15 | 16 | 17 | def get_timestamp(volatile_status_file): 18 | """Get BUILD_TIMESTAMP as an integer. 19 | 20 | Reads a file of "namevalue" pairs and returns the value 21 | of the BUILD_TIMESTAMP. The file should be in the workspace status 22 | format: https://docs.bazel.build/versions/master/user-manual.html#workspace_status 23 | 24 | Args: 25 | volatile_status_file: path to input file. Typically ctx.version_file.path. 26 | Returns: 27 | int: value of BUILD_TIMESTAMP 28 | Exceptions: 29 | Exception: Raised if there is no BUILD_TIMESTAMP or if it is not a number. 30 | """ 31 | with open(volatile_status_file, 'r') as status_f: 32 | for line in status_f: 33 | parts = line.strip().split(' ') 34 | if len(parts) > 1 and parts[0] == 'BUILD_TIMESTAMP': 35 | return int(parts[1]) 36 | raise Exception( 37 | "Invalid status file <%s>. Expected to find BUILD_TIMESTAMP" % volatile_status_file) 38 | -------------------------------------------------------------------------------- /pkg/private/deb/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """rules_pkg internal code. 15 | 16 | All interfaces are subject to change at any time. 17 | """ 18 | 19 | load("@rules_python//python:defs.bzl", "py_binary", "py_library") 20 | 21 | package(default_applicable_licenses = ["//:license"]) 22 | 23 | filegroup( 24 | name = "standard_package", 25 | srcs = [ 26 | "BUILD", 27 | ] + glob([ 28 | "*.bzl", 29 | "*.py", 30 | ]), 31 | visibility = [ 32 | "//distro:__pkg__", 33 | "//pkg:__pkg__", 34 | ], 35 | ) 36 | 37 | exports_files( 38 | glob([ 39 | "*.bzl", 40 | ]), 41 | visibility = [ 42 | "//distro:__pkg__", 43 | "//doc_build:__pkg__", 44 | "//pkg:__pkg__", 45 | ], 46 | ) 47 | 48 | py_binary( 49 | name = "make_deb", 50 | srcs = ["make_deb.py"], 51 | imports = ["../../.."], 52 | python_version = "PY3", 53 | visibility = ["//visibility:public"], 54 | deps = [ 55 | "//pkg/private:helpers", 56 | ], 57 | ) 58 | 59 | py_library( 60 | name = "make_deb_lib", 61 | srcs = ["make_deb.py"], 62 | imports = ["../../.."], 63 | srcs_version = "PY3", 64 | visibility = ["//tests/deb:__pkg__"], 65 | deps = [ 66 | "//pkg/private:helpers", 67 | ], 68 | ) 69 | -------------------------------------------------------------------------------- /pkg/private/make_starlark_library.bzl: -------------------------------------------------------------------------------- 1 | """Turn a label_list of mixed sources and bzl_library's into a bzl_library. 2 | 3 | The sources can be anything. Only the ones that end in ".bzl" will be added. 4 | """ 5 | 6 | load("@bazel_skylib//:bzl_library.bzl", "StarlarkLibraryInfo") 7 | 8 | def _make_starlark_library(ctx): 9 | direct = [] 10 | transitive = [] 11 | for src in ctx.attr.srcs: 12 | if StarlarkLibraryInfo in src: 13 | transitive.append(src[StarlarkLibraryInfo]) 14 | else: 15 | for file in src[DefaultInfo].files.to_list(): 16 | if file.path.endswith(".bzl"): 17 | # print(file.path) 18 | direct.append(file) 19 | all_files = depset(direct, transitive = transitive) 20 | return [ 21 | DefaultInfo(files = all_files, runfiles = ctx.runfiles(transitive_files = all_files)), 22 | StarlarkLibraryInfo(srcs = direct, transitive_srcs = all_files), 23 | ] 24 | 25 | starlark_library = rule( 26 | implementation = _make_starlark_library, 27 | attrs = { 28 | "srcs": attr.label_list( 29 | doc = "Any mix of source files. Only .bzl files will be used.", 30 | allow_files = True, 31 | cfg = "exec", 32 | mandatory = True, 33 | ), 34 | }, 35 | ) 36 | -------------------------------------------------------------------------------- /pkg/private/manifest.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """Common package builder manifest helpers 16 | """ 17 | 18 | import json 19 | 20 | 21 | # These must be kept in sync with the declarations in private/pkg_files.bzl 22 | ENTRY_IS_RAW_LINK = "raw_symlink" # Entry is a file: take content from 23 | ENTRY_IS_FILE = "file" # Entry is a file: take content from 24 | ENTRY_IS_LINK = "symlink" # Entry is a symlink: dest -> 25 | ENTRY_IS_DIR = "dir" # Entry is an empty dir 26 | ENTRY_IS_TREE = "tree" # Entry is a tree artifact: take tree from 27 | ENTRY_IS_EMPTY_FILE = "empty-file" # Entry is a an empty file 28 | 29 | class ManifestEntry(object): 30 | """Structured wrapper around rules_pkg-produced manifest entries""" 31 | type: str 32 | dest: str 33 | src: str 34 | mode: str 35 | user: str 36 | group: str 37 | uid: int 38 | gid: int 39 | origin: str = None 40 | 41 | def __init__(self, type, dest, src, mode, user, group, uid = None, gid = None, origin = None): 42 | self.type = type 43 | self.dest = dest 44 | self.src = src 45 | self.mode = mode 46 | self.user = user 47 | self.group = group 48 | self.uid = uid 49 | self.gid = gid 50 | self.origin = origin 51 | 52 | def __repr__(self): 53 | return "ManifestEntry<{}>".format(vars(self)) 54 | 55 | def read_entries_from(fh): 56 | """Return a list of ManifestEntry's from `fh`""" 57 | # Subtle: decode the content with read() rather than in json.load() because 58 | # the load in older python releases (< 3.7?) does not know how to decode. 59 | raw_entries = json.loads(fh.read()) 60 | return [ManifestEntry(**entry) for entry in raw_entries] 61 | 62 | def read_entries_from_file(manifest_path): 63 | """Return a list of ManifestEntry's from the manifest file at `path`""" 64 | with open(manifest_path, 'r', encoding='utf-8') as fh: 65 | return read_entries_from(fh) 66 | 67 | def entry_type_to_string(et): 68 | """Entry type stringifier""" 69 | if et == ENTRY_IS_FILE: 70 | return "file" 71 | elif et == ENTRY_IS_LINK: 72 | return "symlink", 73 | elif et == ENTRY_IS_DIR: 74 | return "directory" 75 | elif et == ENTRY_IS_TREE: 76 | return "tree" 77 | elif et == ENTRY_IS_EMPTY_FILE: 78 | return "empty_file" 79 | else: 80 | raise ValueError("Invalid entry id {}".format(et)) 81 | -------------------------------------------------------------------------------- /pkg/private/tar/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """rules_pkg internal code. 15 | 16 | All interfaces are subject to change at any time. 17 | """ 18 | 19 | load("@rules_python//python:defs.bzl", "py_binary", "py_library") 20 | 21 | package( 22 | default_applicable_licenses = ["//:license"], 23 | ) 24 | 25 | filegroup( 26 | name = "standard_package", 27 | srcs = [ 28 | "BUILD", 29 | ] + glob([ 30 | "*.bzl", 31 | "*.py", 32 | ]), 33 | visibility = [ 34 | "//distro:__pkg__", 35 | "//pkg:__pkg__", 36 | ], 37 | ) 38 | 39 | exports_files( 40 | glob(["*.bzl"]), 41 | visibility = [ 42 | "//distro:__pkg__", 43 | "//doc_build:__pkg__", 44 | ], 45 | ) 46 | 47 | py_binary( 48 | name = "build_tar", 49 | srcs = ["build_tar.py"], 50 | imports = ["../../.."], 51 | python_version = "PY3", 52 | srcs_version = "PY3", 53 | visibility = ["//visibility:public"], 54 | deps = [ 55 | ":tar_writer", 56 | "//pkg/private:archive", 57 | "//pkg/private:build_info", 58 | "//pkg/private:helpers", 59 | "//pkg/private:manifest", 60 | ], 61 | ) 62 | 63 | py_library( 64 | name = "tar_writer", 65 | srcs = [ 66 | "tar_writer.py", 67 | ], 68 | imports = ["../../.."], 69 | srcs_version = "PY3", 70 | visibility = [ 71 | "//tests:__subpackages__", 72 | ], 73 | ) 74 | -------------------------------------------------------------------------------- /pkg/private/zip/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """rules_pkg internal code. 15 | 16 | All interfaces are subject to change at any time. 17 | """ 18 | 19 | load("@rules_python//python:defs.bzl", "py_binary") 20 | 21 | package(default_applicable_licenses = ["//:license"]) 22 | 23 | filegroup( 24 | name = "standard_package", 25 | srcs = [ 26 | "BUILD", 27 | ] + glob([ 28 | "*.bzl", 29 | "*.py", 30 | ]), 31 | visibility = [ 32 | "//distro:__pkg__", 33 | "//pkg:__pkg__", 34 | ], 35 | ) 36 | 37 | exports_files( 38 | glob([ 39 | "*.bzl", 40 | ]), 41 | visibility = [ 42 | "//distro:__pkg__", 43 | "//doc_build:__pkg__", 44 | "//pkg:__pkg__", 45 | ], 46 | ) 47 | 48 | py_binary( 49 | name = "build_zip", 50 | srcs = ["build_zip.py"], 51 | imports = ["../../.."], 52 | python_version = "PY3", 53 | srcs_version = "PY3", 54 | visibility = ["//visibility:public"], 55 | deps = [ 56 | "//pkg/private:build_info", 57 | "//pkg/private:helpers", 58 | "//pkg/private:manifest", 59 | ], 60 | ) 61 | -------------------------------------------------------------------------------- /pkg/private/zip/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazelbuild/rules_pkg/c590e619313f3227c06541b00deb6074680b8922/pkg/private/zip/__init__.py -------------------------------------------------------------------------------- /pkg/releasing/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") 2 | 3 | package( 4 | default_applicable_licenses = ["//:license"], 5 | default_visibility = ["//visibility:public"], 6 | ) 7 | 8 | # WARNING: 2021-06-28. This is experimental and subject to change. 9 | 10 | # Sample usage: 11 | # load("@rules_pkg//releasing:defs.bzl", "print_rel_notes") 12 | # print_rel_notes( 13 | # name = "relnotes", 14 | # repo = "rules_pkg", 15 | # version = "2.1", 16 | # outs = ["relnotes.txt"], 17 | # ) 18 | 19 | filegroup( 20 | name = "standard_package", 21 | srcs = ["BUILD"] + glob([ 22 | "*.bzl", 23 | "*.py", 24 | ]), 25 | visibility = [ 26 | "//distro:__pkg__", 27 | "//pkg:__pkg__", 28 | ], 29 | ) 30 | 31 | py_library( 32 | name = "release_utils", 33 | srcs = [ 34 | "__init__.py", 35 | "release_tools.py", 36 | ], 37 | imports = ["../.."], 38 | srcs_version = "PY3", 39 | ) 40 | 41 | py_binary( 42 | name = "print_rel_notes", 43 | srcs = [ 44 | "print_rel_notes.py", 45 | ], 46 | imports = ["../.."], 47 | python_version = "PY3", 48 | deps = [ 49 | ":release_utils", 50 | ], 51 | ) 52 | 53 | py_test( 54 | name = "release_tools_test", 55 | srcs = ["release_tools_test.py"], 56 | python_version = "PY3", 57 | deps = [ 58 | ":release_utils", 59 | ], 60 | ) 61 | 62 | # This is an internal tool. Use at your own risk. 63 | py_binary( 64 | name = "git_changelog_private", 65 | srcs = [ 66 | "git_changelog_private.py", 67 | ], 68 | srcs_version = "PY3", 69 | # TODO(https://github.com/bazelbuild/bazel/issues/7377): Make this private. 70 | visibility = ["//visibility:public"], 71 | ) 72 | -------------------------------------------------------------------------------- /pkg/releasing/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazelbuild/rules_pkg/c590e619313f3227c06541b00deb6074680b8922/pkg/releasing/__init__.py -------------------------------------------------------------------------------- /pkg/releasing/defs.bzl: -------------------------------------------------------------------------------- 1 | """Implementation for print_rel_notes.""" 2 | 3 | # buildifier: disable=function-docstring 4 | def print_rel_notes( 5 | name, 6 | repo, 7 | version, 8 | artifact_name = None, 9 | outs = None, 10 | setup_file = "", 11 | deps_method = "", 12 | toolchains_method = "", 13 | org = "bazelbuild", 14 | changelog = None, 15 | mirror_host = None): 16 | if not artifact_name: 17 | artifact_name = ":%s-%s.tar.gz" % (repo, version) 18 | 19 | # Must use Label to get a path relative to the rules_pkg repository, 20 | # instead of the calling BUILD file. 21 | print_rel_notes_helper = Label("//pkg/releasing:print_rel_notes") 22 | tools = [print_rel_notes_helper] 23 | cmd = [ 24 | "LC_ALL=C.UTF-8 $(location %s)" % str(print_rel_notes_helper), 25 | "--org=%s" % org, 26 | "--repo=%s" % repo, 27 | "--version=%s" % version, 28 | "--tarball=$(location %s)" % artifact_name, 29 | ] 30 | if setup_file: 31 | cmd.append("--setup_file=%s" % setup_file) 32 | if deps_method: 33 | cmd.append("--deps_method=%s" % deps_method) 34 | if toolchains_method: 35 | cmd.append("--toolchains_method=%s" % toolchains_method) 36 | if changelog: 37 | cmd.append("--changelog=$(location %s)" % changelog) 38 | 39 | # We should depend on a changelog as a tool so that it is always built 40 | # for the host configuration. If the changelog is generated on the fly, 41 | # then we would have to run commands against our revision control 42 | # system. That only makes sense locally on the host, because the 43 | # revision history is never exported to a remote build system. 44 | tools.append(changelog) 45 | if mirror_host: 46 | cmd.append("--mirror_host=%s" % mirror_host) 47 | cmd.append(">$@") 48 | native.genrule( 49 | name = name, 50 | srcs = [ 51 | artifact_name, 52 | ], 53 | outs = outs or [name + ".txt"], 54 | cmd = " ".join(cmd), 55 | tools = tools, 56 | ) 57 | -------------------------------------------------------------------------------- /pkg/releasing/git_changelog_private.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Utilities to extract git commit descriptions in useful ways.""" 15 | 16 | import argparse 17 | import os 18 | import subprocess 19 | import sys 20 | 21 | 22 | def guess_previous_release_tag(git_path, pattern=None): 23 | assert git_path 24 | most_recent = None 25 | cmd = [git_path, 'tag'] 26 | if pattern: 27 | cmd.extend(['--list', pattern]) 28 | # We are doing something dumb here for now. Grab the list of tags, and pick 29 | # the last one. 30 | with subprocess.Popen(cmd, stdout=subprocess.PIPE) as proc: 31 | most_recent = proc.stdout.read().decode('utf-8') 32 | most_recent = most_recent.strip().replace('\n\n', '\n').split('\n')[-1] 33 | return most_recent 34 | 35 | 36 | def git_changelog(from_ref, to_ref='HEAD', git_path=None): 37 | assert from_ref 38 | assert to_ref 39 | assert git_path 40 | cmd = [git_path, 'log', '%s..%s' % (from_ref, to_ref)] 41 | with subprocess.Popen(cmd, stdout=subprocess.PIPE) as proc: 42 | return proc.stdout.read().decode('utf-8') 43 | 44 | 45 | def main(): 46 | parser = argparse.ArgumentParser( 47 | description='Helper for extracting git changelog', 48 | fromfile_prefix_chars='@') 49 | parser.add_argument('--git_path', required=True, help='path to git binary') 50 | parser.add_argument('--git_root', required=True, help='path to git client') 51 | parser.add_argument('--out', required=True, help='output path') 52 | parser.add_argument('--from_ref', help='from REF') 53 | parser.add_argument('--to_ref', help='to REF') 54 | parser.add_argument('--verbose', action='store_true') 55 | 56 | options = parser.parse_args() 57 | 58 | with open(options.out, 'w', encoding='utf-8') as out: 59 | os.chdir(options.git_root) 60 | from_ref = options.from_ref 61 | if not from_ref or from_ref == '_LATEST_TAG_': 62 | from_ref = guess_previous_release_tag(options.git_path) 63 | to_ref = options.to_ref or 'HEAD' 64 | if options.verbose: 65 | print('Getting changelog from %s to %s' % (from_ref, to_ref)) 66 | changelog = git_changelog( 67 | from_ref=from_ref, to_ref=to_ref, git_path=options.git_path) 68 | out.write(changelog) 69 | return 0 70 | 71 | if __name__ == '__main__': 72 | main() 73 | -------------------------------------------------------------------------------- /pkg/rpm.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """RPM packaging interfaces 16 | 17 | This module provides a wrapper macro "pkg_rpm" that allows users to select 18 | between the two variants of `pkg_rpm`: 19 | 20 | - `pkg_rpm_pfg`, which arranges contents via the `pkg_filegroup` 21 | framework defined in `:mappings.bzl`. 22 | 23 | - `pkg_rpm_legacy`, which arranges contents via a spec file template. 24 | 25 | `pkg_rpm_legacy` is deprecated and will be removed in a future release of 26 | rules_pkg. 27 | 28 | The mechanism for choosing between the two is documented in the function itself. 29 | 30 | """ 31 | 32 | load("//pkg:rpm_pfg.bzl", _pkg_sub_rpm = "pkg_sub_rpm", pkg_rpm_pfg = "pkg_rpm") 33 | load("//pkg/legacy:rpm.bzl", pkg_rpm_legacy = "pkg_rpm") 34 | 35 | pkg_sub_rpm = _pkg_sub_rpm 36 | 37 | def pkg_rpm(name, srcs = None, spec_file = None, subrpms = None, **kwargs): 38 | """pkg_rpm wrapper 39 | 40 | This rule selects between the two implementations of pkg_rpm as described in 41 | the module docstring. In particular: 42 | 43 | If `srcs` is provided, this macro will choose `pkg_rpm_pfg`. If 44 | `spec_file` is provided, it will choose `pkg_rpm_legacy`. 45 | 46 | If neither or both are provided, this will fail. 47 | 48 | Args: 49 | name: rule name 50 | srcs: pkg_rpm_pfg `srcs` attribute 51 | spec_file: pkg_rpm_legacy `spec_file` attribute 52 | subrpms: pkg_rpm_pfg `subrpms` attribute 53 | **kwargs: arguments to either `pkg_rpm_pfg` or `pkg_rpm_legacy`, 54 | depending on mode 55 | 56 | """ 57 | if srcs != None and spec_file: 58 | fail("Cannot determine which pkg_rpm rule to use. `srcs` and `spec_file` are mutually exclusive") 59 | 60 | if subrpms and spec_file: 61 | fail("Cannot build sub RPMs with a specfile. `subrpms` and `spec_file` are mutually exclusive") 62 | 63 | if srcs == None and not spec_file: 64 | fail("Either `srcs` or `spec_file` must be provided.") 65 | 66 | if srcs != None: 67 | pkg_rpm_pfg( 68 | name = name, 69 | srcs = srcs, 70 | subrpms = subrpms, 71 | **kwargs 72 | ) 73 | elif spec_file: 74 | pkg_rpm_legacy( 75 | name = name, 76 | spec_file = spec_file, 77 | **kwargs 78 | ) 79 | 80 | else: 81 | fail("This should be unreachable; kindly file a bug against rules_pkg.") 82 | -------------------------------------------------------------------------------- /pkg/rpm/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@rules_python//python:defs.bzl", "py_binary") 16 | 17 | package(default_applicable_licenses = ["//:license"]) 18 | 19 | exports_files( 20 | glob([ 21 | "*.tpl", 22 | ]), 23 | visibility = ["//visibility:public"], 24 | ) 25 | 26 | filegroup( 27 | name = "standard_package", 28 | srcs = glob([ 29 | "*.py", 30 | "*.tpl", 31 | ]) + [ 32 | "BUILD", 33 | ], 34 | visibility = ["//pkg:__pkg__"], 35 | ) 36 | 37 | # Helper script used to augment the %install scriptlet and %files list with 38 | # those found in TreeArtifacts (directory outputs) See also #292. 39 | py_binary( 40 | name = "augment_rpm_files_install", 41 | srcs = ["augment_rpm_files_install.py"], 42 | visibility = ["//visibility:public"], 43 | ) 44 | -------------------------------------------------------------------------------- /pkg/rpm/template.spec.tpl: -------------------------------------------------------------------------------- 1 | # -*- rpm-spec -*- 2 | 3 | # This comprises the entirety of the preamble 4 | %include %build_rpm_options 5 | 6 | %description 7 | %include %build_rpm_description 8 | 9 | %install 10 | %include %build_rpm_install 11 | 12 | %files -f %build_rpm_files 13 | 14 | ${PRE_SCRIPTLET} 15 | 16 | ${POST_SCRIPTLET} 17 | 18 | ${PREUN_SCRIPTLET} 19 | 20 | ${POSTUN_SCRIPTLET} 21 | 22 | ${POSTTRANS_SCRIPTLET} 23 | 24 | ${SUBRPMS} 25 | 26 | ${CHANGELOG} 27 | -------------------------------------------------------------------------------- /pkg/tar.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2022 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Forwarder for pkg_tar.""" 15 | 16 | load("//pkg/private/tar:tar.bzl", _pkg_tar = "pkg_tar") 17 | 18 | pkg_tar = _pkg_tar 19 | -------------------------------------------------------------------------------- /pkg/zip.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Forwarder for pkg_zip.""" 15 | 16 | load("//pkg/private/zip:zip.bzl", _pkg_zip = "pkg_zip") 17 | 18 | pkg_zip = _pkg_zip 19 | -------------------------------------------------------------------------------- /tests/a.cc: -------------------------------------------------------------------------------- 1 | int a = 1; 2 | -------------------------------------------------------------------------------- /tests/b.cc: -------------------------------------------------------------------------------- 1 | int b = 2; 2 | -------------------------------------------------------------------------------- /tests/deb/config: -------------------------------------------------------------------------------- 1 | # test config file 2 | -------------------------------------------------------------------------------- /tests/deb/control_field_test.py: -------------------------------------------------------------------------------- 1 | # Copyright 2022 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # -*- coding: utf-8 -*- 16 | """Testing for archive.""" 17 | 18 | import codecs 19 | from io import BytesIO 20 | import os 21 | import sys 22 | import tarfile 23 | import unittest 24 | 25 | from pkg.private.deb import make_deb 26 | 27 | class MakeControlFieldTest(unittest.TestCase): 28 | """Tests for MakeControlField. 29 | 30 | https://www.debian.org/doc/debian-policy/ch-controlfields.html#syntax-of-control-files 31 | """ 32 | 33 | def test_simple(self): 34 | self.assertEqual( 35 | 'Package: fizzbuzz\n', 36 | make_deb.MakeDebianControlField('Package', 'fizzbuzz')) 37 | 38 | def test_simple_strip(self): 39 | self.assertEqual( 40 | 'Package: fizzbuzz\n', 41 | make_deb.MakeDebianControlField('Package', ' fizzbuzz')) 42 | self.assertEqual( 43 | 'Package: fizzbuzz\n', 44 | make_deb.MakeDebianControlField('Package', ' fizzbuzz ')) 45 | 46 | def test_simple_no_newline(self): 47 | with self.assertRaises(ValueError): 48 | make_deb.MakeDebianControlField('Package', ' fizz\nbuzz ') 49 | 50 | 51 | def test_multiline(self): 52 | self.assertEqual( 53 | 'Description: fizzbuzz\n', 54 | make_deb.MakeDebianControlField( 55 | 'Description', 'fizzbuzz', multiline=make_deb.Multiline.YES)) 56 | self.assertEqual( 57 | 'Description: fizz\n buzz\n', 58 | make_deb.MakeDebianControlField( 59 | 'Description', 'fizz\n buzz\n', multiline=make_deb.Multiline.YES)) 60 | self.assertEqual( 61 | 'Description:\n fizz\n buzz\n', 62 | make_deb.MakeDebianControlField( 63 | 'Description', ' fizz\n buzz\n', multiline=make_deb.Multiline.YES_ADD_NEWLINE)) 64 | 65 | def test_multiline_add_required_space(self): 66 | self.assertEqual( 67 | 'Description: fizz\n buzz\n', 68 | make_deb.MakeDebianControlField( 69 | 'Description', 'fizz\nbuzz', multiline=make_deb.Multiline.YES)) 70 | self.assertEqual( 71 | 'Description:\n fizz\n buzz\n', 72 | make_deb.MakeDebianControlField( 73 | 'Description', 'fizz\nbuzz\n', multiline=make_deb.Multiline.YES_ADD_NEWLINE)) 74 | 75 | def test_multiline_add_trailing_newline(self): 76 | self.assertEqual( 77 | 'Description: fizz\n buzz\n baz\n', 78 | make_deb.MakeDebianControlField( 79 | 'Description', 'fizz\n buzz\n baz', multiline=make_deb.Multiline.YES)) 80 | 81 | 82 | if __name__ == '__main__': 83 | unittest.main() 84 | -------------------------------------------------------------------------------- /tests/deb/deb_preinst: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # tete ®, Й, ק ,م, ๗, あ, 叶, 葉, 말, ü and é 3 | echo fnord 4 | -------------------------------------------------------------------------------- /tests/deb/deb_tests.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Helpers for pkg_deb tests.""" 15 | 16 | load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts") 17 | 18 | def _package_naming_test_impl(ctx): 19 | env = analysistest.begin(ctx) 20 | target_under_test = analysistest.target_under_test(env) 21 | 22 | ogi = target_under_test[OutputGroupInfo] 23 | 24 | deb_path = ogi.deb.to_list()[0].path 25 | 26 | # Test that the .changes file is computed correctly 27 | changes_path = ogi.changes.to_list()[0].path 28 | expected_changes_path = deb_path[0:-3] + "changes" 29 | asserts.equals( 30 | env, 31 | changes_path, 32 | expected_changes_path, 33 | "Changes file does not have the correct name", 34 | ) 35 | 36 | # Is the generated file name what we expect 37 | if ctx.attr.expected_name: 38 | asserts.equals( 39 | env, 40 | deb_path.split("/")[-1], # basename(path) 41 | ctx.attr.expected_name, 42 | "Deb package file name is not correct", 43 | ) 44 | return analysistest.end(env) 45 | 46 | package_naming_test = analysistest.make( 47 | _package_naming_test_impl, 48 | attrs = { 49 | "expected_name": attr.string(), 50 | }, 51 | ) 52 | -------------------------------------------------------------------------------- /tests/deb/deb_triggers: -------------------------------------------------------------------------------- 1 | # tutu ®, Й, ק ,م, ๗, あ, 叶, 葉, 말, ü and é 2 | some-trigger 3 | -------------------------------------------------------------------------------- /tests/deb/templates: -------------------------------------------------------------------------------- 1 | Template: deb/test 2 | Type: string 3 | Default: 4 | Description: test question 5 | test question to check that templates are included into 6 | debian directory 7 | -------------------------------------------------------------------------------- /tests/foo.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | extern int a, b; 6 | 7 | // A very roundabout hello world. 8 | int main(int argc, char* argv[]) { 9 | std::string runfiles(argv[0]); 10 | runfiles.append(".runfiles"); 11 | std::string hello(runfiles + "/rules_pkg/tests/testdata/hello.txt"); 12 | std::fstream fs; 13 | fs.open(hello, std::iostream::in); 14 | char tmp[1000]; 15 | fs.read(tmp, sizeof(tmp)); 16 | fs.close(); 17 | std::cout << tmp; 18 | 19 | return (a + b > 0) ? 0 : 1; 20 | } 21 | -------------------------------------------------------------------------------- /tests/install/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@rules_python//python:defs.bzl", "py_test") 16 | load("//pkg:install.bzl", "pkg_install") 17 | load("//pkg:mappings.bzl", "pkg_attributes", "pkg_files", "pkg_mkdirs") 18 | load("//tests/util:defs.bzl", "directory", "fake_artifact") 19 | 20 | package(default_applicable_licenses = ["//:license"]) 21 | 22 | py_test( 23 | name = "install_test", 24 | srcs = ["test.py"], 25 | args = ["-v"], 26 | data = [ 27 | ":test_installer", 28 | ], 29 | imports = ["../.."], 30 | main = "test.py", 31 | tags = [ 32 | # TODO(nacl): investigate this. See also 33 | # https://buildkite.com/bazel/rules-pkg/builds/961#992dbe09-7e4b-4e34-91b6-491120476ed3 34 | "no-windows", 35 | # TODO(nacl): consider enabling this for testing on Linux. 36 | #"requires-fakeroot" 37 | ], 38 | deps = [ 39 | "//pkg/private:manifest", 40 | "@rules_python//python/runfiles", 41 | ], 42 | ) 43 | 44 | pkg_install( 45 | name = "test_installer", 46 | srcs = [ 47 | ":artifact-in-owned-dir", 48 | ":artifact-in-unowned-dir", 49 | ":dirs", 50 | ":generate_tree_pkg_files", 51 | ], 52 | ) 53 | 54 | fake_artifact( 55 | name = "artifact", 56 | ) 57 | 58 | pkg_files( 59 | name = "artifact-in-owned-dir", 60 | srcs = ["artifact"], 61 | attributes = pkg_attributes(mode = "0700"), 62 | prefix = "owned-dir", 63 | ) 64 | 65 | pkg_files( 66 | name = "artifact-in-unowned-dir", 67 | srcs = ["artifact"], 68 | attributes = pkg_attributes(mode = "0755"), 69 | prefix = "unowned-dir", 70 | ) 71 | 72 | pkg_mkdirs( 73 | name = "dirs", 74 | dirs = [ 75 | "empty-owned-dir", 76 | "owned-dir", 77 | ], 78 | ) 79 | 80 | directory( 81 | name = "generate_tree", 82 | contents = "hello there", 83 | filenames = [ 84 | # buildifier: don't sort 85 | "b/e", 86 | "a/a", 87 | "b/c/d", 88 | "b/d", 89 | "a/b/c", 90 | ], 91 | ) 92 | 93 | pkg_files( 94 | name = "generate_tree_pkg_files", 95 | srcs = [":generate_tree"], 96 | attributes = pkg_attributes( 97 | mode = "640", 98 | ), 99 | ) 100 | -------------------------------------------------------------------------------- /tests/mappings/all.manifest.golden: -------------------------------------------------------------------------------- 1 | [ 2 | {"type": "file", "dest": "BUILD", "src": "tests/mappings/BUILD", "mode": "", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests/mappings:BUILD"}, 3 | {"type": "dir", "dest": "foodir", "src": null, "mode": "711", "user": "foo", "group": "bar", "uid": null, "gid": null, "origin": "@//tests/mappings:dirs"}, 4 | 5 | {"type": "file", "dest": "mappings_test.bzl", "src": "tests/mappings/mappings_test.bzl", "mode": "0644", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests/mappings:files"}, 6 | {"type": "tree", "dest": "treeartifact", "src": "tests/mappings/treeartifact", "mode": "0644", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests/mappings:directory-with-contents"} 7 | ] 8 | -------------------------------------------------------------------------------- /tests/mappings/executable.manifest.golden: -------------------------------------------------------------------------------- 1 | [ 2 | {"dest":"an_executable.runfiles/_main/tests/an_executable","gid":null,"group":null,"mode":"0755","origin":"@//tests:an_executable","src":"tests/an_executable","type":"file","uid":null,"user":null}, 3 | {"dest":"an_executable.runfiles/_main/tests/foo.cc","gid":null,"group":null,"mode":"","origin":"@//tests:an_executable","src":"tests/foo.cc","type":"file","uid":null,"user":null}, 4 | {"dest":"an_executable.runfiles/_main/tests/testdata/hello.txt","gid":null,"group":null,"mode":"","origin":"@//tests:an_executable","src":"tests/testdata/hello.txt","type":"file","uid":null,"user":null}, 5 | {"dest":"an_executable","gid":null,"group":null,"mode":"0755","origin":"@//tests:an_executable","src":"tests/an_executable","type":"file","uid":null,"user":null}, 6 | {"dest":"an_executable.repo_mapping","gid":null,"group":null,"mode":"","origin":"@//tests:an_executable","src":"tests/an_executable.repo_mapping","type":"file","uid":null,"user":null}, 7 | {"dest":"an_executable.runfiles/_repo_mapping","gid":null,"group":null,"mode":"","origin":"@//tests:an_executable","src":"tests/an_executable.repo_mapping","type":"file","uid":null,"user":null}, 8 | {"dest":"mappings_test.bzl","gid":null,"group":null,"mode":"","origin":"@//tests/mappings:mappings_test.bzl","src":"tests/mappings/mappings_test.bzl","type":"file","uid":null,"user":null} 9 | ] 10 | -------------------------------------------------------------------------------- /tests/mappings/executable.manifest.windows.golden: -------------------------------------------------------------------------------- 1 | [ 2 | {"dest":"an_executable.exe.runfiles/_main/tests/foo.cc","gid":null,"group":null,"mode":"","origin":"@//tests:an_executable","src":"tests/foo.cc","type":"file","uid":null,"user":null}, 3 | {"dest":"an_executable.exe.runfiles/_main/tests/an_executable.exe","gid":null,"group":null,"mode":"0755","origin":"@//tests:an_executable","src":"tests/an_executable.exe","type":"file","uid":null,"user":null}, 4 | {"dest":"an_executable.exe.runfiles/_main/tests/testdata/hello.txt","gid":null,"group":null,"mode":"","origin":"@//tests:an_executable","src":"tests/testdata/hello.txt","type":"file","uid":null,"user":null}, 5 | {"dest":"an_executable.exe","gid":null,"group":null,"mode":"0755","origin":"@//tests:an_executable","src":"tests/an_executable.exe","type":"file","uid":null,"user":null}, 6 | {"dest":"an_executable.exe.repo_mapping","gid":null,"group":null,"mode":"","origin":"@//tests:an_executable","src": "tests/an_executable.exe.repo_mapping","type": "file","uid":null,"user":null}, 7 | {"dest":"an_executable.exe.runfiles/_repo_mapping","gid":null,"group":null,"mode":"","origin":"@//tests:an_executable","src": "tests/an_executable.exe.repo_mapping","type": "file","uid":null,"user":null}, 8 | {"dest":"mappings_test.bzl","gid":null,"group":null,"mode":"","origin":"@//tests/mappings:mappings_test.bzl","src":"tests/mappings/mappings_test.bzl","type":"file","uid":null,"user":null} 9 | ] 10 | -------------------------------------------------------------------------------- /tests/mappings/external_repo/MODULE.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2025 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | module( 16 | name = "test_external_project", 17 | version = "0", 18 | compatibility_level = 0, 19 | ) 20 | 21 | local_path_override( 22 | module_name = "rules_pkg", 23 | path = "../../../", 24 | ) 25 | 26 | bazel_dep(name = "rules_license", version = "1.0.0") 27 | bazel_dep(name = "rules_python", version = "1.0.0") 28 | bazel_dep(name = "bazel_skylib", version = "1.7.1") 29 | 30 | ######################################### 31 | # Do not update to newer versions until you need a specific new feature. 32 | 33 | # Only for development 34 | #bazel_dep(name = "platforms", version = "0.0.10", dev_dependency = True) 35 | #bazel_dep(name = "rules_cc", version = "0.0.17", dev_dependency = True) 36 | #bazel_dep(name = "stardoc", version = "0.7.2", dev_dependency = True) 37 | # 38 | ## Find the system rpmbuild if one is available. 39 | #find_rpm = use_extension("//toolchains/rpm:rpmbuild_configure.bzl", "find_system_rpmbuild_bzlmod", dev_dependency = True) 40 | #use_repo(find_rpm, "rules_pkg_rpmbuild") 41 | # 42 | #register_toolchains( 43 | # "@rules_pkg_rpmbuild//:all", 44 | # dev_dependency = True, 45 | #) 46 | -------------------------------------------------------------------------------- /tests/mappings/external_repo/WORKSPACE: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | workspace(name = "test_external_project") 16 | -------------------------------------------------------------------------------- /tests/mappings/external_repo/pkg/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@//pkg:mappings.bzl", "pkg_files", "strip_prefix") 16 | load("@//pkg:tar.bzl", "pkg_tar") 17 | load("@//pkg:verify_archive.bzl", "verify_archive_test") 18 | load("@//tests/util:defs.bzl", "fake_artifact") 19 | load("test.bzl", "test_referencing_remote_file") 20 | 21 | package(default_visibility = ["//visibility:public"]) 22 | 23 | exports_files( 24 | glob(["**"]), 25 | ) 26 | 27 | fake_artifact( 28 | name = "dir/script", 29 | files = ["dir/extproj.sh"], 30 | visibility = ["//visibility:public"], 31 | ) 32 | 33 | pkg_files( 34 | name = "extproj_script_pf", 35 | srcs = ["dir/extproj.sh"], 36 | prefix = "usr/bin", 37 | strip_prefix = strip_prefix.from_pkg(), 38 | tags = ["manual"], 39 | ) 40 | 41 | test_referencing_remote_file( 42 | name = "pf_local_file_in_extrepo", 43 | ) 44 | 45 | # Add a target to ensure verify_archive_test can be 46 | # called from another workspace 47 | pkg_tar( 48 | name = "external_archive", 49 | srcs = ["dir/extproj.sh"], 50 | ) 51 | 52 | verify_archive_test( 53 | name = "external_archive_test", 54 | max_size = 1, 55 | min_size = 1, 56 | must_contain = ["extproj.sh"], 57 | target = ":external_archive", 58 | ) 59 | -------------------------------------------------------------------------------- /tests/mappings/external_repo/pkg/dir/extproj.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2021 The Bazel Authors. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | echo "External project script!" 18 | -------------------------------------------------------------------------------- /tests/mappings/external_repo/pkg/test.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """Tests for file mapping routines in pkg/mappings.bzl. 16 | 17 | Test implementation copied from pkg/mappings.bzl 18 | 19 | """ 20 | 21 | load("@//pkg:mappings.bzl", "pkg_files", "strip_prefix") 22 | load("@//pkg:providers.bzl", "PackageFilesInfo") 23 | load("@bazel_skylib//lib:new_sets.bzl", "sets") 24 | load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts") 25 | 26 | #### BEGIN copied code 27 | 28 | def _pkg_files_contents_test_impl(ctx): 29 | env = analysistest.begin(ctx) 30 | target_under_test = analysistest.target_under_test(env) 31 | 32 | expected_dests = sets.make(ctx.attr.expected_dests) 33 | actual_dests = sets.make(target_under_test[PackageFilesInfo].dest_src_map.keys()) 34 | 35 | asserts.new_set_equals(env, expected_dests, actual_dests, "pkg_files dests do not match expectations") 36 | 37 | return analysistest.end(env) 38 | 39 | pkg_files_contents_test = analysistest.make( 40 | _pkg_files_contents_test_impl, 41 | attrs = { 42 | # Other attributes can be tested here, but the most important one is the 43 | # destinations. 44 | "expected_dests": attr.string_list( 45 | mandatory = True, 46 | ), 47 | # attrs are always passed through unchanged (and maybe rejected) 48 | }, 49 | ) 50 | 51 | #### END copied code 52 | 53 | # Called from the rules_pkg tests 54 | def test_referencing_remote_file(name): 55 | pkg_files( 56 | name = "{}_g".format(name), 57 | prefix = "usr/share", 58 | srcs = ["@//tests:loremipsum_txt"], 59 | # The prefix in rules_pkg. Why yes, this is knotty 60 | strip_prefix = strip_prefix.from_root("tests"), 61 | tags = ["manual"], 62 | ) 63 | 64 | pkg_files_contents_test( 65 | name = name, 66 | target_under_test = ":{}_g".format(name), 67 | expected_dests = ["usr/share/testdata/loremipsum.txt"], 68 | ) 69 | -------------------------------------------------------------------------------- /tests/mappings/filter_directory/defs.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """Rules and macros to support testing rules that output directories.""" 16 | 17 | load("@rules_python//python:defs.bzl", "py_test") 18 | 19 | def _inspect_directory_script_impl(ctx): 20 | script = ctx.actions.declare_file("{}.py".format(ctx.attr.name)) 21 | ctx.actions.expand_template( 22 | template = ctx.file._inspector_template, 23 | output = script, 24 | substitutions = { 25 | "%EXPECTED_STRUCTURE%": json.encode(ctx.attr.expected_structure), 26 | "%DIRECTORY_ROOT%": ctx.file.directory.short_path, 27 | }, 28 | ) 29 | 30 | return [DefaultInfo(files = depset([script]))] 31 | 32 | _inspect_directory_script = rule( 33 | doc = """Create a script for testing the contents of directories.""", 34 | implementation = _inspect_directory_script_impl, 35 | attrs = { 36 | "directory": attr.label( 37 | mandatory = True, 38 | allow_single_file = True, 39 | ), 40 | "expected_structure": attr.string_list( 41 | mandatory = True, 42 | ), 43 | "_inspector_template": attr.label( 44 | default = ":inspect_directory.py.tpl", 45 | allow_single_file = True, 46 | ), 47 | }, 48 | ) 49 | 50 | def inspect_directory_test(name, directory, expected_structure, **kwargs): 51 | script_name = name + "_script" 52 | 53 | _inspect_directory_script( 54 | name = script_name, 55 | directory = directory, 56 | expected_structure = expected_structure, 57 | ) 58 | 59 | # This appears to be necessary because of 60 | # https://github.com/bazelbuild/bazel/issues/1147 61 | native.sh_library( 62 | name = name + "_dir_lib", 63 | srcs = [directory], 64 | ) 65 | 66 | py_test( 67 | name = name, 68 | srcs = [":" + script_name], 69 | main = ":" + script_name + ".py", 70 | data = [name + "_dir_lib"], 71 | deps = ["@rules_python//python/runfiles"], 72 | **kwargs 73 | ) 74 | -------------------------------------------------------------------------------- /tests/mappings/filter_directory/inspect_directory.py.tpl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # Copyright 2021 The Bazel Authors. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | import json 18 | import os 19 | import unittest 20 | from python.runfiles import runfiles 21 | 22 | DIRECTORY_ROOT = "%DIRECTORY_ROOT%" 23 | # This is JSON, which shouldn't have any triple quotes in it. 24 | EXPECTED_STRUCTURE = """%EXPECTED_STRUCTURE%""" 25 | 26 | 27 | class DirectoryStructureTest(unittest.TestCase): 28 | def setUp(self): 29 | self.runfiles = runfiles.Create() 30 | 31 | def test_directory_structure_matches_global(self): 32 | real_directory_root = self.runfiles.Rlocation( 33 | os.path.join(os.environ["TEST_WORKSPACE"], DIRECTORY_ROOT) 34 | ) 35 | 36 | # This may be a bazel bug -- shouldn't an empty directory be passed in 37 | # anyway? 38 | self.assertTrue( 39 | os.path.isdir(real_directory_root), 40 | "TreeArtifact root does not exist, is the input empty?", 41 | ) 42 | 43 | expected_set = set(json.loads(EXPECTED_STRUCTURE)) 44 | actual_set = set() 45 | for root, dirs, files in os.walk(real_directory_root): 46 | if root != real_directory_root: 47 | rel_root = os.path.relpath(root, real_directory_root) 48 | else: 49 | # We are in the root. Don't bother with path relativization. 50 | rel_root = '' 51 | for f in files: 52 | actual_set.add(os.path.join(rel_root, f)) 53 | 54 | self.assertEqual( 55 | expected_set, 56 | actual_set, 57 | "Directory structure mismatch" 58 | ) 59 | 60 | 61 | if __name__ == "__main__": 62 | unittest.main() 63 | -------------------------------------------------------------------------------- /tests/mappings/glob_for_texts_manifest.golden: -------------------------------------------------------------------------------- 1 | [ 2 | {"type": "file", "dest": "file_with_a_ridiculously_long_name_consectetur_adipiscing_elit_fusce_laoreet_lorem_neque_sed_pharetra_erat.txt", "src": "tests/testdata/file_with_a_ridiculously_long_name_consectetur_adipiscing_elit_fusce_laoreet_lorem_neque_sed_pharetra_erat.txt", "mode": "", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests:glob_for_texts"}, 3 | {"type": "file", "dest": "hello.txt", "src": "tests/testdata/hello.txt", "mode": "", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests:glob_for_texts"}, 4 | {"type": "file", "dest": "loremipsum.txt", "src": "tests/testdata/loremipsum.txt", "mode": "", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests:glob_for_texts"}, 5 | {"type": "file", "dest": "test_tar_package_dir_file.txt", "src": "tests/testdata/test_tar_package_dir_file.txt", "mode": "", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests:glob_for_texts"} 6 | ] 7 | -------------------------------------------------------------------------------- /tests/mappings/manifest_test_lib.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Compare to content manifest files.""" 15 | 16 | import json 17 | import unittest 18 | 19 | from python.runfiles import runfiles 20 | 21 | class ContentManifestTest(unittest.TestCase): 22 | """Test harness to see if we wrote the content manifest correctly.""" 23 | 24 | run_files = runfiles.Create() 25 | 26 | def assertManifestsMatch(self, expected_path, got_path): 27 | """Check two manifest files for equality. 28 | 29 | Args: 30 | expected_path: The path to the content we expect. 31 | got_path: The path to the content we got. 32 | """ 33 | e_file = ContentManifestTest.run_files.Rlocation('rules_pkg/' + expected_path) 34 | with open(e_file, mode='rt', encoding='utf-8') as e_fp: 35 | expected = json.loads(e_fp.read()) 36 | expected_dict = {x['dest']: x for x in expected} 37 | g_file = ContentManifestTest.run_files.Rlocation('rules_pkg/' + got_path) 38 | with open(g_file, mode='rt', encoding='utf-8') as g_fp: 39 | got = json.loads(g_fp.read()) 40 | got_dict = {x['dest']: x for x in got} 41 | 42 | ok = True 43 | expected_dests = set(expected_dict.keys()) 44 | got_dests = set(got_dict.keys()) 45 | for dest, what in expected_dict.items(): 46 | got = got_dict.get(dest) 47 | if got: 48 | # bzlmod mode changes root to @@//, but older version give @// 49 | origin = got.get('origin') 50 | if origin and origin.startswith('@@//'): 51 | got['origin'] = origin[1:] 52 | self.assertDictEqual(what, got) 53 | else: 54 | print('Missing expected path "%s" in manifest' % dest) 55 | ok = False 56 | for dest, what in got_dict.items(): 57 | expected = expected_dict.get(dest) 58 | if expected: 59 | self.assertDictEqual(expected, what) 60 | else: 61 | print('Got unexpected path "%s" in manifest:' % dest, what) 62 | ok = False 63 | 64 | if not ok: 65 | print('To update the golden file:') 66 | print(' cp bazel-bin/%s %s' % (got_path, expected_path)) 67 | print('or') 68 | print('============= snip ==========') 69 | print(got_dict.values()) 70 | print('============= snip ==========') 71 | self.assertTrue(ok) 72 | -------------------------------------------------------------------------------- /tests/mappings/manifest_test_main.py.tpl: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Tests for generated content manifest.""" 15 | 16 | import unittest 17 | 18 | from tests.mappings import manifest_test_lib 19 | 20 | class ${TEST_NAME}(manifest_test_lib.ContentManifestTest): 21 | 22 | def test_match(self): 23 | self.assertManifestsMatch('${EXPECTED}', '${TARGET}') 24 | 25 | 26 | if __name__ == '__main__': 27 | unittest.main() 28 | -------------------------------------------------------------------------------- /tests/mappings/node_modules_manifest.golden: -------------------------------------------------------------------------------- 1 | [ 2 | {"type": "symlink", "dest": "node_modules/.pnpm/bar@1.0.0/node_modules/bar", "src": "STORE/bar", "mode": "", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests/mappings:node_modules"}, 3 | {"type": "symlink", "dest": "node_modules/.pnpm/bar@1.0.0/node_modules/qar", "src": "../../qar@2.0.0/node_modules/qar", "mode": "", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests/mappings:node_modules"}, 4 | {"type": "symlink", "dest": "node_modules/.pnpm/foo@1.0.0/node_modules/bar", "src": "../../bar@1.0.0/node_modules/bar", "mode": "", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests/mappings:node_modules"}, 5 | {"type": "symlink", "dest": "node_modules/.pnpm/foo@1.0.0/node_modules/foo", "src": "STORE/foo", "mode": "", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests/mappings:node_modules"}, 6 | {"type": "symlink", "dest": "node_modules/.pnpm/foo@1.0.0/node_modules/qar", "src": "../../qar@2.0.0/node_modules/qar", "mode": "", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests/mappings:node_modules"}, 7 | {"type": "symlink", "dest": "node_modules/.pnpm/qar@2.0.0/node_modules/qar", "src": "STORE/qar", "mode": "", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests/mappings:node_modules"}, 8 | {"type": "symlink", "dest": "node_modules/foo", "src": ".pnpm/foo@1.0.0/node_modules/foo", "mode": "", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests/mappings:node_modules"} 9 | ] 10 | -------------------------------------------------------------------------------- /tests/mappings/testdata/a_script.sh: -------------------------------------------------------------------------------- 1 | echo a_script 2 | -------------------------------------------------------------------------------- /tests/mappings/testdata/config: -------------------------------------------------------------------------------- 1 | # test config file 2 | -------------------------------------------------------------------------------- /tests/mappings/testdata/hello.txt: -------------------------------------------------------------------------------- 1 | Hello, world! 2 | -------------------------------------------------------------------------------- /tests/mappings/utf8_manifest.golden: -------------------------------------------------------------------------------- 1 | [ 2 | {"type": "file", "dest": "1-a", "src": "tests/testdata/utf8/1-a", "mode": "0644", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests/mappings:utf8_files"}, 3 | {"type": "file", "dest": "2-λ", "src": "tests/testdata/utf8/2-λ", "mode": "0644", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests/mappings:utf8_files"}, 4 | {"type": "file", "dest": "3-世", "src": "tests/testdata/utf8/3-世", "mode": "0644", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests/mappings:utf8_files"}, 5 | {"type": "file", "dest": "BUILD", "src": "tests/testdata/utf8/BUILD", "mode": "0644", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests/mappings:utf8_files"}, 6 | {"type": "file", "dest": "sübdir/2-λ", "src": "tests/testdata/utf8/sübdir/2-λ", "mode": "0644", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests/mappings:utf8_files"}, 7 | {"type": "file", "dest": "sübdir/hello", "src": "tests/testdata/utf8/sübdir/hello", "mode": "0644", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests/mappings:utf8_files"} 8 | ] 9 | -------------------------------------------------------------------------------- /tests/my_package_name.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """Sample rule to show package naming.""" 16 | 17 | load("//pkg:providers.bzl", "PackageVariablesInfo") 18 | 19 | def _my_package_naming_impl(ctx): 20 | values = {} 21 | 22 | # then add in my own custom values 23 | values["label"] = ctx.attr.label 24 | return PackageVariablesInfo(values = values) 25 | 26 | my_package_naming = rule( 27 | implementation = _my_package_naming_impl, 28 | attrs = { 29 | "label": attr.string(doc = "A label that matters to me."), 30 | }, 31 | ) 32 | -------------------------------------------------------------------------------- /tests/package_naming_aggregate_test.sh: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # This test simply checks that when we create packages with package_file_name 16 | # that we get the expected file names. 17 | set -e 18 | 19 | # Portably find the absolute path to the test data, even if this code has been 20 | # vendored in to a source tree and re-rooted. 21 | TEST_PACKAGE="$(echo ${TEST_TARGET} | sed -e 's/:.*$//' -e 's@//@@')" 22 | declare -r DATA_DIR="${TEST_SRCDIR}/${TEST_WORKSPACE}/${TEST_PACKAGE}" 23 | 24 | for pkg in test_naming_some_value.deb test_naming_some_value.tar test_naming_some_value.zip ; do 25 | ls -l "${DATA_DIR}/$pkg" 26 | done 27 | echo "PASS" 28 | -------------------------------------------------------------------------------- /tests/path_test.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """Tests for path.bzl""" 16 | 17 | load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts") 18 | load("//pkg:mappings.bzl", "pkg_mkdirs") 19 | load("//pkg:path.bzl", "compute_data_path") 20 | 21 | ########## 22 | # Test compute_data_path 23 | ########## 24 | def _compute_data_path_test_impl(ctx): 25 | env = analysistest.begin(ctx) 26 | 27 | # Subtle: This allows you to vendor the library into your own repo at some 28 | # arbitrary path. 29 | expect = ctx.attr.expected_path 30 | if expect.startswith("tests"): 31 | expect = ctx.label.package + expect[5:] 32 | asserts.equals( 33 | env, 34 | expect, 35 | compute_data_path(ctx.label, ctx.attr.in_path), 36 | ) 37 | return analysistest.end(env) 38 | 39 | compute_data_path_test = analysistest.make( 40 | _compute_data_path_test_impl, 41 | attrs = { 42 | "in_path": attr.string(mandatory = True), 43 | "expected_path": attr.string(mandatory = True), 44 | }, 45 | ) 46 | 47 | def _test_compute_data_path(name): 48 | pkg_mkdirs( 49 | name = "dummy", 50 | dirs = [], 51 | tags = ["manual"], 52 | ) 53 | 54 | compute_data_path_test( 55 | name = name + "_normal_test", 56 | target_under_test = ":dummy", 57 | in_path = "a/b/c", 58 | expected_path = "tests/a/b/c", 59 | ) 60 | 61 | compute_data_path_test( 62 | name = name + "_absolute_test", 63 | target_under_test = ":dummy", 64 | in_path = "/a/b/c", 65 | expected_path = "a/b/c", 66 | ) 67 | 68 | compute_data_path_test( 69 | name = name + "_relative_test", 70 | target_under_test = ":dummy", 71 | in_path = "./a/b/c", 72 | expected_path = "tests/a/b/c", 73 | ) 74 | 75 | compute_data_path_test( 76 | name = name + "_empty_test", 77 | target_under_test = ":dummy", 78 | in_path = "./", 79 | expected_path = "tests", 80 | ) 81 | 82 | compute_data_path_test( 83 | name = name + "_empty2_test", 84 | target_under_test = ":dummy", 85 | in_path = "./.", 86 | expected_path = "tests", 87 | ) 88 | 89 | def path_tests(name): 90 | """Declare path.bzl analysis tests.""" 91 | _test_compute_data_path(name = name + "_compute_data_path") 92 | -------------------------------------------------------------------------------- /tests/rpm/source_date_epoch/epoch.txt: -------------------------------------------------------------------------------- 1 | 1616472000 2 | -------------------------------------------------------------------------------- /tests/rpm/template-test.spec.tpl: -------------------------------------------------------------------------------- 1 | # -*- rpm-spec -*- 2 | 3 | ################################################################################ 4 | # Test customizations 5 | 6 | # Force MD5 file digesting to preserve compatibility with (very old) versions of 7 | # rpm. 8 | # 9 | # For valid values to set here, see: 10 | # https://github.com/rpm-software-management/rpm/blob/8d628a138ee4c3d1b77b993a3c5b71345ce052e8/macros.in#L393-L405 11 | # 12 | # At some point, we might want to consider bumping this up to use SHA-1 (2), but 13 | # that would be best reserved for when we don't know of anyone using rpm < 4.6. 14 | %define _source_filedigest_algorithm 1 15 | %define _binary_filedigest_algorithm 1 16 | 17 | # Do not try to use magic to determine file types 18 | %define __spec_install_post %{nil} 19 | 20 | ################################################################################ 21 | 22 | # Hey! 23 | # 24 | # Keep the below in sync with pkg/rpm/template.spec.tpl! 25 | 26 | ################################################################################ 27 | 28 | # This comprises the entirety of the preamble 29 | %include %build_rpm_options 30 | 31 | %description 32 | %include %build_rpm_description 33 | 34 | %install 35 | %include %build_rpm_install 36 | 37 | %files -f %build_rpm_files 38 | 39 | ${PRE_SCRIPTLET} 40 | 41 | ${POST_SCRIPTLET} 42 | 43 | ${PREUN_SCRIPTLET} 44 | 45 | ${POSTUN_SCRIPTLET} 46 | 47 | ${POSTTRANS_SCRIPTLET} 48 | -------------------------------------------------------------------------------- /tests/rpm/test.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return 0; 3 | } 4 | -------------------------------------------------------------------------------- /tests/rpm/test_debuginfo_rpm_contents.txt.golden: -------------------------------------------------------------------------------- 1 | ===== main RPM ===== 2 | Name : test_debuginfo_rpm 3 | Version : 1 4 | Release : 0 5 | Install Date: (not installed) 6 | Group : Unspecified 7 | License : Some license 8 | Signature : (none) 9 | Source RPM : test_debuginfo_rpm-1-0.src.rpm 10 | Summary : Summary 11 | Description : 12 | Description 13 | /test_debuginfo 14 | ===== sub RPM ====== 15 | Name : test_debuginfo_rpm-debuginfo 16 | Version : 1 17 | Release : 0 18 | Install Date: (not installed) 19 | Group : Development/Debug 20 | License : Some license 21 | Signature : (none) 22 | Source RPM : test_debuginfo_rpm-1-0.src.rpm 23 | Summary : Debug information for package test_debuginfo_rpm 24 | Description : 25 | This package provides debug information for package test_debuginfo_rpm. 26 | Debug information is useful when developing applications that use this 27 | package or when debugging this package. 28 | /usr/lib/debug 29 | /usr/lib/debug/test_debuginfo.debug 30 | -------------------------------------------------------------------------------- /tests/rpm/test_rpm_dirs_contents.txt.golden: -------------------------------------------------------------------------------- 1 | drwxr-xr-x /dir 2 | -rw-r--r-- /dir/config.txt 3 | -------------------------------------------------------------------------------- /tests/rpm/test_sub_rpm_contents.txt.golden: -------------------------------------------------------------------------------- 1 | ===== main RPM ===== 2 | Name : test_sub_rpm_main 3 | Version : 1 4 | Release : 0 5 | Architecture: noarch 6 | Install Date: (not installed) 7 | Group : Unspecified 8 | Size : 19 9 | License : Apache License, v2.0 10 | Signature : (none) 11 | Source RPM : test_sub_rpm_main-1-0.src.rpm 12 | Summary : rules_pkg example RPM 13 | Description : 14 | This is a package description. 15 | /test_sub_rpm_main_file_input.txt 16 | ===== sub RPM ====== 17 | Name : test_sub_rpm_main-test_sub_rpm 18 | Version : 1 19 | Release : 0 20 | Architecture: noarch 21 | Install Date: (not installed) 22 | Group : Unspecified 23 | Size : 17 24 | License : Apache License, v2.0 25 | Signature : (none) 26 | Source RPM : test_sub_rpm_main-1-0.src.rpm 27 | Summary : Test subrpm 28 | Description : 29 | Test subrpm description 30 | /test_sub_rpm_file_input.txt 31 | ===== sub RPM ====== 32 | Name : test_sub_rpm_main-test_sub_rpm2 33 | Version : 1 34 | Release : 0 35 | Architecture: noarch 36 | Install Date: (not installed) 37 | Group : Unspecified 38 | Size : 17 39 | License : Apache License, v2.0 40 | Signature : (none) 41 | Source RPM : test_sub_rpm_main-1-0.src.rpm 42 | Summary : Test subrpm2 43 | Description : 44 | Test subrpm2 description 45 | postinstall scriptlet (using /bin/sh): 46 | echo post 47 | postuninstall scriptlet (using /bin/sh): 48 | echo postun 49 | /test_sub_rpm_file_input.txt 50 | -------------------------------------------------------------------------------- /tests/rpm/tree_artifacts/rpm_contents_vs_manifest_test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # Copyright 2021 The Bazel Authors. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | import unittest 18 | import csv 19 | import io 20 | import os 21 | 22 | from python.runfiles import runfiles 23 | from tests.rpm import rpm_util 24 | 25 | EXPECTED_RPM_MANIFEST_CSV = """ 26 | path,digest,user,group,mode,fflags,symlink 27 | /test_dir/a,dc35e5df50b75e25610e1aaaa29edaa4,root,root,100644,, 28 | /test_dir/b,dc35e5df50b75e25610e1aaaa29edaa4,root,root,100644,, 29 | /test_dir/subdir/c,dc35e5df50b75e25610e1aaaa29edaa4,root,root,100644,, 30 | /test_dir/subdir/d,dc35e5df50b75e25610e1aaaa29edaa4,root,root,100644,, 31 | /test_dir/e,d41d8cd98f00b204e9800998ecf8427e,root,root,100644,, 32 | /test_dir/f,d41d8cd98f00b204e9800998ecf8427e,root,root,100644,, 33 | """.strip() 34 | 35 | 36 | class PkgRpmCompManifest(unittest.TestCase): 37 | def setUp(self): 38 | self.runfiles = runfiles.Create() 39 | self.maxDiff = None 40 | # Allow for parameterization of this test based on the desired RPM to 41 | # test. 42 | 43 | # runfiles prefers Bazely (POSIX-style) relative paths, so we can't 44 | # really use os.path.join() here. 45 | self.rpm_path = self.runfiles.Rlocation('/'.join([ 46 | os.environ["TEST_WORKSPACE"], 47 | "tests", "rpm", "tree_artifacts", 48 | # The object behind os.environ is not a dict, and thus doesn't have 49 | # the "getdefault()" we'd otherwise use here. 50 | os.environ["TEST_RPM"] if "TEST_RPM" in os.environ else "test_dirs_rpm.rpm", 51 | ])) 52 | 53 | def test_contents_match(self): 54 | sio = io.StringIO(EXPECTED_RPM_MANIFEST_CSV) 55 | manifest_reader = csv.DictReader(sio) 56 | manifest_specs = {r['path']: r for r in manifest_reader} 57 | 58 | rpm_specs = rpm_util.read_rpm_filedata(self.rpm_path) 59 | 60 | self.assertDictEqual(manifest_specs, rpm_specs) 61 | 62 | 63 | if __name__ == "__main__": 64 | unittest.main() 65 | -------------------------------------------------------------------------------- /tests/rpm/tree_artifacts/rpm_treeartifact_ops_test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # Copyright 2021 The Bazel Authors. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | import csv 18 | import io 19 | import os 20 | import unittest 21 | 22 | from python.runfiles import runfiles 23 | from tests.rpm import rpm_util 24 | 25 | EXPECTED_RPM_MANIFEST_CSV = """ 26 | path,digest,user,group,mode,fflags,symlink 27 | /a,dc35e5df50b75e25610e1aaaa29edaa4,root,root,100644,, 28 | /b,dc35e5df50b75e25610e1aaaa29edaa4,root,root,100644,, 29 | /subdir/c,dc35e5df50b75e25610e1aaaa29edaa4,root,root,100644,, 30 | /subdir/d,dc35e5df50b75e25610e1aaaa29edaa4,root,root,100644,, 31 | """.strip() 32 | 33 | 34 | class PkgRpmCompManifest(unittest.TestCase): 35 | def setUp(self): 36 | self.runfiles = runfiles.Create() 37 | self.maxDiff = None 38 | # Allow for parameterization of this test based on the desired RPM to 39 | # test. 40 | self.rpm_path = self.runfiles.Rlocation(os.path.join( 41 | os.environ["TEST_WORKSPACE"], 42 | "tests", "rpm", "tree_artifacts", 43 | # The object behind os.environ is not a dict, and thus doesn't have 44 | # the "getdefault()" we'd otherwise use here. 45 | os.environ["TEST_RPM"] if "TEST_RPM" in os.environ else "treeartifact_ops_rpm.rpm", 46 | )) 47 | 48 | def test_contents_match(self): 49 | sio = io.StringIO(EXPECTED_RPM_MANIFEST_CSV) 50 | manifest_reader = csv.DictReader(sio) 51 | manifest_specs = {r['path']: r for r in manifest_reader} 52 | 53 | rpm_specs = rpm_util.read_rpm_filedata(self.rpm_path) 54 | 55 | self.assertDictEqual(manifest_specs, rpm_specs) 56 | 57 | 58 | if __name__ == "__main__": 59 | unittest.main() 60 | -------------------------------------------------------------------------------- /tests/tar/compressor.py: -------------------------------------------------------------------------------- 1 | '''Fake compressor that just prepends garbage bytes.''' 2 | 3 | import sys 4 | 5 | GARBAGE = b'garbage' 6 | 7 | if __name__ == '__main__': 8 | assert sys.argv[1:] == ['-a', '-b', '-c'] 9 | sys.stdout.buffer.write(GARBAGE) 10 | sys.stdout.buffer.write(sys.stdin.buffer.read()) 11 | -------------------------------------------------------------------------------- /tests/tar/defs.bzl: -------------------------------------------------------------------------------- 1 | """Helpers for testing tar packaging.""" 2 | 3 | def _raw_symlinks_impl(ctx): 4 | link1 = ctx.actions.declare_symlink(ctx.label.name + "_link1") 5 | ctx.actions.symlink(output = link1, target_path = "./link1") 6 | 7 | runfile_link = ctx.actions.declare_symlink(ctx.label.name + "_runfile_link") 8 | ctx.actions.symlink(output = runfile_link, target_path = "../runfile_link") 9 | 10 | return [DefaultInfo( 11 | files = depset([link1]), 12 | runfiles = ctx.runfiles([runfile_link]), 13 | )] 14 | 15 | raw_symlinks = rule( 16 | implementation = _raw_symlinks_impl, 17 | ) 18 | -------------------------------------------------------------------------------- /tests/tar/is_compressed_test.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Tests if input files are compressed.""" 15 | 16 | import unittest 17 | 18 | from python.runfiles import runfiles 19 | 20 | 21 | class IsCompressedTest(unittest.TestCase): 22 | 23 | def setUp(self): 24 | self.data_files = runfiles.Create() 25 | 26 | def get_file_under_test(self, file_name): 27 | """Get the file path to a generated archive in the runfiles.""" 28 | 29 | return self.data_files.Rlocation( 30 | "rules_pkg/tests/tar/" + file_name 31 | ) 32 | 33 | def is_zip_compressed(self, file_name): 34 | """Returns true if file_name is zip compressed.""" 35 | with open(self.get_file_under_test(file_name), 'rb') as inp: 36 | content = inp.read(2) 37 | # A quick web search will show these magic constants are correct. 38 | return content[0] == 0x1f and content[1] == 0x8b 39 | 40 | def is_bz2_compressed(self, file_name): 41 | """Returns true if file_name is bz2 compressed.""" 42 | with open(self.get_file_under_test(file_name), 'rb') as inp: 43 | content = inp.read(7) 44 | # A quick web search will show these magic constants are correct. 45 | # This is probably well beyond what we need in this test, but why not? 46 | return (content[0] == ord('B') and content[1] == ord('Z') 47 | and ord('1') <= content[3] and content[3] <= ord('9') 48 | and content[4] == 0x31 and content[5] == 0x41 and content[6] == 0x59) 49 | 50 | def test_guess_compression_from_extension(self): 51 | self.assertTrue( 52 | self.is_bz2_compressed("test-tar-compression-from-extension-bz2.bz2")) 53 | self.assertTrue( 54 | self.is_zip_compressed("test-tar-compression-from-extension-targz.tar.gz")) 55 | self.assertTrue( 56 | self.is_zip_compressed("test-tar-compression-from-extension-tgz.tgz")) 57 | 58 | 59 | if __name__ == '__main__': 60 | unittest.main() 61 | -------------------------------------------------------------------------------- /tests/testdata/README.md: -------------------------------------------------------------------------------- 1 | This folder contains test data. 2 | 3 | The utf8 folder contains a set of files whose names are not ASCII or ISO-8859-1. 4 | They may be used for testing the ability to handle files using non ASCII 5 | file names. Along with those we have 4 samples of what native tar and zip 6 | utilities do with these file names: 7 | 8 | - utf8_linux.tar: From linux: `tar cf utf8_linux.tar utf8` 9 | - utf8_linux.zip From linux: `zip -r utf8_linux.zip utf8` 10 | - utf8_mac.tar: From macos: `tar cf utf8_linux.tar utf8` 11 | - utf8_mac.zip From macos: `zip -r utf8_linux.zip utf8` 12 | - utf8_win.tar: From window: `tar cf utf8_win.tar utf8` 13 | - utf8_win.zip From window: `7z a -r utf8_win.zip utf8` 14 | 15 | The samples are are intended to be used as input data for tests 16 | of capabilities that read data (such as unpacking and filtering 17 | a tar file). Code must be able to read tar and zip files produced 18 | on a different OS and interpret file names correctly. For now we 19 | can study the differences by platform. 20 | 21 | -------------------------------------------------------------------------------- /tests/testdata/a.ar: -------------------------------------------------------------------------------- 1 | ! 2 | a/ 1439231934 1000 1000 100664 1 ` 3 | a 4 | -------------------------------------------------------------------------------- /tests/testdata/a_ab.ar: -------------------------------------------------------------------------------- 1 | ! 2 | a/ 1439231934 1000 1000 100664 1 ` 3 | a 4 | ab/ 1439231936 1000 1000 100664 2 ` 5 | ab 6 | -------------------------------------------------------------------------------- /tests/testdata/a_b.ar: -------------------------------------------------------------------------------- 1 | ! 2 | a/ 1439231934 1000 1000 100664 1 ` 3 | a 4 | b/ 1439231939 1000 1000 100664 1 ` 5 | b 6 | -------------------------------------------------------------------------------- /tests/testdata/a_b_ab.ar: -------------------------------------------------------------------------------- 1 | ! 2 | a/ 1439231934 1000 1000 100664 1 ` 3 | a 4 | b/ 1439231939 1000 1000 100664 1 ` 5 | b 6 | ab/ 1439231936 1000 1000 100664 2 ` 7 | ab 8 | -------------------------------------------------------------------------------- /tests/testdata/ab.ar: -------------------------------------------------------------------------------- 1 | ! 2 | ab/ 1439231936 1000 1000 100664 2 ` 3 | ab 4 | -------------------------------------------------------------------------------- /tests/testdata/b.ar: -------------------------------------------------------------------------------- 1 | ! 2 | b/ 1439231939 1000 1000 100664 1 ` 3 | b 4 | -------------------------------------------------------------------------------- /tests/testdata/config: -------------------------------------------------------------------------------- 1 | # test config file 2 | -------------------------------------------------------------------------------- /tests/testdata/deb_preinst: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # tete ®, Й, ק ,م, ๗, あ, 叶, 葉, 말, ü and é 3 | echo fnord 4 | -------------------------------------------------------------------------------- /tests/testdata/deb_triggers: -------------------------------------------------------------------------------- 1 | # tutu ®, Й, ק ,م, ๗, あ, 叶, 葉, 말, ü and é 2 | some-trigger 3 | -------------------------------------------------------------------------------- /tests/testdata/empty.ar: -------------------------------------------------------------------------------- 1 | ! 2 | -------------------------------------------------------------------------------- /tests/testdata/executable.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | echo "Hello" 3 | -------------------------------------------------------------------------------- /tests/testdata/file_with_a_ridiculously_long_name_consectetur_adipiscing_elit_fusce_laoreet_lorem_neque_sed_pharetra_erat.txt: -------------------------------------------------------------------------------- 1 | Hello there! -------------------------------------------------------------------------------- /tests/testdata/hello.txt: -------------------------------------------------------------------------------- 1 | Hello, world! 2 | -------------------------------------------------------------------------------- /tests/testdata/loremipsum.txt: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sit amet nunc 2 | lectus. Sed at nulla vel turpis egestas pharetra et at velit. Cras pharetra 3 | iaculis dui, id vestibulum odio auctor eget. Class aptent taciti sociosqu ad 4 | litora torquent per conubia nostra, per inceptos himenaeos. Ut massa lectus, 5 | lobortis vel vehicula id, mattis id odio. Mauris eget imperdiet nisi. Nunc id 6 | urna a lorem porttitor varius ut vitae risus. Ut faucibus, magna eget rutrum 7 | efficitur, nulla nulla porta lectus, venenatis convallis nisi magna auctor arcu. 8 | -------------------------------------------------------------------------------- /tests/testdata/outer_BUILD: -------------------------------------------------------------------------------- 1 | ../BUILD -------------------------------------------------------------------------------- /tests/testdata/tar_test.tar.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazelbuild/rules_pkg/c590e619313f3227c06541b00deb6074680b8922/tests/testdata/tar_test.tar.bz2 -------------------------------------------------------------------------------- /tests/testdata/tar_test.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazelbuild/rules_pkg/c590e619313f3227c06541b00deb6074680b8922/tests/testdata/tar_test.tar.gz -------------------------------------------------------------------------------- /tests/testdata/tar_test.tar.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazelbuild/rules_pkg/c590e619313f3227c06541b00deb6074680b8922/tests/testdata/tar_test.tar.xz -------------------------------------------------------------------------------- /tests/testdata/templates: -------------------------------------------------------------------------------- 1 | Template: deb/test 2 | Type: string 3 | Default: 4 | Description: test question 5 | test question to check that templates are included into 6 | debian directory 7 | -------------------------------------------------------------------------------- /tests/testdata/test_tar_package_dir_file.txt: -------------------------------------------------------------------------------- 1 | /package 2 | -------------------------------------------------------------------------------- /tests/testdata/utf8/1-a: -------------------------------------------------------------------------------- 1 | my name takes 3 octets in utf-8 2 | -------------------------------------------------------------------------------- /tests/testdata/utf8/2-λ: -------------------------------------------------------------------------------- 1 | my name takes 4 octets in utf-8 2 | -------------------------------------------------------------------------------- /tests/testdata/utf8/3-世: -------------------------------------------------------------------------------- 1 | my name takes 5 octets in utf-8 2 | -------------------------------------------------------------------------------- /tests/testdata/utf8/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | package(default_applicable_licenses = ["//:license"]) 16 | 17 | filegroup( 18 | name = "files", 19 | srcs = glob(["**"]), 20 | visibility = ["//visibility:public"], 21 | ) 22 | -------------------------------------------------------------------------------- /tests/testdata/utf8/sübdir/2-λ: -------------------------------------------------------------------------------- 1 | my name takes 4 octets in utf-8 2 | -------------------------------------------------------------------------------- /tests/testdata/utf8/sübdir/hello: -------------------------------------------------------------------------------- 1 | hello 2 | -------------------------------------------------------------------------------- /tests/testdata/utf8_linux.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazelbuild/rules_pkg/c590e619313f3227c06541b00deb6074680b8922/tests/testdata/utf8_linux.zip -------------------------------------------------------------------------------- /tests/testdata/utf8_mac.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazelbuild/rules_pkg/c590e619313f3227c06541b00deb6074680b8922/tests/testdata/utf8_mac.zip -------------------------------------------------------------------------------- /tests/testdata/utf8_win.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazelbuild/rules_pkg/c590e619313f3227c06541b00deb6074680b8922/tests/testdata/utf8_win.zip -------------------------------------------------------------------------------- /tests/util/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Test utilities 16 | 17 | load("@rules_python//python:defs.bzl", "py_binary") 18 | 19 | package(default_applicable_licenses = ["//:license"]) 20 | 21 | exports_files(["defs.bzl"]) 22 | 23 | py_binary( 24 | name = "md5", 25 | srcs = ["md5.py"], 26 | python_version = "PY3", 27 | srcs_version = "PY3", 28 | visibility = ["//visibility:public"], 29 | ) 30 | 31 | py_binary( 32 | name = "create_directory_with_contents", 33 | srcs = ["create_directory_with_contents.py"], 34 | python_version = "PY3", 35 | srcs_version = "PY3", 36 | visibility = ["//visibility:public"], 37 | ) 38 | -------------------------------------------------------------------------------- /tests/util/create_directory_with_contents.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # Copyright 2021 The Bazel Authors. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | import sys 18 | import os 19 | 20 | """Creates a directory containing some files with provided contents 21 | 22 | Usage: ./this.py output_dir_name file1 contents1 ... fileN contentsN 23 | """ 24 | 25 | dirname = sys.argv[1] 26 | 27 | files_contents_map = {} 28 | 29 | # Simple way of grouping over pairs. There are other ones, like 30 | # https://stackoverflow.com/a/16789836, but they either requiring copying a 31 | # bunch of code around or having something that's a smidge unreadable. 32 | rest_args_iter = iter(sys.argv[2:]) 33 | for a in rest_args_iter: 34 | files_contents_map[a] = next(rest_args_iter) 35 | 36 | os.makedirs(dirname, exist_ok=True) 37 | 38 | for fname, contents in files_contents_map.items(): 39 | path = os.path.join(dirname, fname) 40 | os.makedirs( 41 | os.path.dirname(path), 42 | exist_ok=True, 43 | ) 44 | if contents.startswith('@@'): 45 | os.symlink(contents[2:], path) 46 | else: 47 | with open(path, 'w') as fh: 48 | fh.write(contents) 49 | -------------------------------------------------------------------------------- /tests/util/md5.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # Copyright 2021 The Bazel Authors. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | '''Simple cross-platform md5sum tool for computing hashes in packaging tests.''' 18 | 19 | import hashlib 20 | import sys 21 | 22 | fname = sys.argv[1] 23 | 24 | md5 = hashlib.md5() 25 | 26 | with open(fname, 'rb') as fh: 27 | md5.update(fh.read()) 28 | 29 | print(md5.hexdigest()) 30 | -------------------------------------------------------------------------------- /tests/verify_archive/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2025 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # -*- coding: utf-8 -*- 15 | """Tests for verify_archive.""" 16 | 17 | load("//pkg:tar.bzl", "pkg_tar") 18 | load("//pkg:verify_archive.bzl", "verify_archive_test") 19 | 20 | # Test data 21 | 22 | pkg_tar( 23 | name = "loremipsum_tar", 24 | srcs = [ 25 | "//tests:loremipsum_txt", 26 | ], 27 | ) 28 | 29 | pkg_tar( 30 | name = "loremipsum_tar_test_only", 31 | testonly = True, 32 | srcs = [ 33 | "//tests:loremipsum_txt", 34 | ], 35 | ) 36 | 37 | # Test cases 38 | 39 | verify_archive_test( 40 | name = "test_py_test_attrs_is_allowed", 41 | size = "small", 42 | timeout = "moderate", 43 | flaky = True, 44 | target = ":loremipsum_tar", 45 | ) 46 | 47 | verify_archive_test( 48 | name = "test_testonly_is_allowed", 49 | testonly = True, 50 | target = ":loremipsum_tar_test_only", 51 | ) 52 | 53 | verify_archive_test( 54 | name = "test_visibility_is_allowed", 55 | target = ":loremipsum_tar", 56 | visibility = ["//visibility:private"], 57 | ) 58 | 59 | verify_archive_test( 60 | name = "test_target_compatible_with_is_allowed", 61 | target = ":loremipsum_tar", 62 | target_compatible_with = ["@platforms//cpu:x86_64"], 63 | ) 64 | 65 | verify_archive_test( 66 | name = "test_tags_are_allowed", 67 | tags = ["test_tag"], 68 | target = ":loremipsum_tar", 69 | ) 70 | -------------------------------------------------------------------------------- /tests/zip/unicode_test.py: -------------------------------------------------------------------------------- 1 | # Copyright 2022 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import unittest 16 | 17 | from tests.zip import zip_test_lib 18 | 19 | class UnicodeHandlingTests(zip_test_lib.ZipContentsTestBase): 20 | 21 | def test_unicode_file_names(self): 22 | self.assertZipFileContent("unicode_names.zip", [ 23 | {"filename": "1-a"}, 24 | {"filename": "2-λ"}, 25 | {"filename": "3-世"}, 26 | {"filename": "BUILD"}, 27 | {"filename": "sübdir/", "isdir": True}, 28 | {"filename": "sübdir/2-λ"}, 29 | {"filename": "sübdir/hello"}, 30 | ]) 31 | 32 | 33 | if __name__ == "__main__": 34 | unittest.main() 35 | -------------------------------------------------------------------------------- /tests/zip/zip_byte_for_byte_test.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import filecmp 16 | import unittest 17 | 18 | from tests.zip import zip_test_lib 19 | 20 | 21 | class ZipEquivalency(zip_test_lib.ZipTest): 22 | """Check that some generated zip files are equivalent to each-other.""" 23 | 24 | def assertFilesEqual(self, actual, expected): 25 | """Assert that two zip files contain the same bytes.""" 26 | 27 | zips_are_equal = filecmp.cmp( 28 | self.get_test_zip(actual), 29 | self.get_test_zip(expected), 30 | ) 31 | self.assertTrue(zips_are_equal) 32 | 33 | def test_small_timestamp(self): 34 | self.assertFilesEqual( 35 | "test_zip_basic_timestamp_before_epoch.zip", 36 | "test_zip_basic.zip", 37 | ) 38 | 39 | def test_extension(self): 40 | self.assertFilesEqual( 41 | "test_zip_basic_renamed.foo", 42 | "test_zip_basic.zip", 43 | ) 44 | 45 | def test_package_dir1(self): 46 | self.assertFilesEqual( 47 | "test_zip_package_dir1.zip", 48 | "test_zip_package_dir0.zip", 49 | ) 50 | 51 | def test_package_dir2(self): 52 | self.assertFilesEqual( 53 | "test_zip_package_dir2.zip", 54 | "test_zip_package_dir0.zip", 55 | ) 56 | 57 | if __name__ == "__main__": 58 | unittest.main() 59 | -------------------------------------------------------------------------------- /toolchains/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | package(default_applicable_licenses = ["//:license"]) 15 | 16 | filegroup( 17 | name = "standard_package", 18 | srcs = glob([ 19 | "*", 20 | ]), 21 | visibility = ["//distro:__pkg__"], 22 | ) 23 | 24 | exports_files( 25 | glob(["*"]), 26 | visibility = ["//visibility:public"], 27 | ) 28 | -------------------------------------------------------------------------------- /toolchains/git/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """toolchain to wrap the git binary. 15 | 16 | Type: @rules_pkg//toolchains/git:git_toolchain_type 17 | 18 | Toolchains: 19 | - git_missing_toolchain: provides a fallback toolchain for exec platforms 20 | where git might not be available. 21 | 22 | - git_auto_toolchain: a toolchain that uses the installed git. See 23 | git_configure.bzl%find_system_git for usage. 24 | """ 25 | 26 | load("//toolchains/git:git.bzl", "git_toolchain", "is_git_available") 27 | 28 | package(default_applicable_licenses = ["//:license"]) 29 | 30 | filegroup( 31 | name = "standard_package", 32 | srcs = glob(["*"]), 33 | visibility = ["//distro:__pkg__"], 34 | ) 35 | 36 | exports_files( 37 | glob(["*"]), 38 | visibility = ["//visibility:public"], 39 | ) 40 | 41 | # Expose the availability of an actual git as a config_setting, so we can 42 | # select() on it. 43 | config_setting( 44 | name = "have_git", 45 | flag_values = { 46 | ":is_git_available": "1", 47 | }, 48 | visibility = ["//visibility:public"], 49 | ) 50 | 51 | # Expose the availability of an actual git as a feature flag, so we can 52 | # create a config_setting from it. 53 | is_git_available( 54 | name = "is_git_available", 55 | visibility = ["//:__subpackages__"], 56 | ) 57 | 58 | toolchain_type( 59 | name = "git_toolchain_type", 60 | visibility = ["//visibility:public"], 61 | ) 62 | 63 | # git_missing_toolchain provides a fallback toolchain so that toolchain 64 | # resolution can succeed even on platforms that do not have a working git. 65 | # If this toolchain is selected, the constraint ":have_git" will not be 66 | # satistifed. 67 | git_toolchain( 68 | name = "no_git", 69 | ) 70 | 71 | toolchain( 72 | name = "git_missing_toolchain", 73 | toolchain = ":no_git", 74 | toolchain_type = ":git_toolchain_type", 75 | ) 76 | -------------------------------------------------------------------------------- /toolchains/git/BUILD.tpl: -------------------------------------------------------------------------------- 1 | # This content is generated by {GENERATOR} 2 | load("@rules_pkg//toolchains/git:git.bzl", "git_toolchain") 3 | 4 | git_toolchain( 5 | name = "git_auto", 6 | # path to git executable 7 | path = "{GIT_PATH}", 8 | # path to the top of the git client (but really any folder under it) 9 | client_top = "{GIT_ROOT}", 10 | ) 11 | 12 | toolchain( 13 | name = "git_auto_toolchain", 14 | toolchain = ":git_auto", 15 | toolchain_type = "@rules_pkg//toolchains/git:git_toolchain_type", 16 | ) 17 | -------------------------------------------------------------------------------- /toolchains/git/git.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """toolchain to provide access to git from Bazel. 15 | 16 | A git toolchain is somewhat unusual compared to other toolchains. 17 | It not only provides a path to the git executable, but it also 18 | holds the absolute path to our workspace, which is presumed to 19 | be under revision control. This allows us to write helper tools 20 | that escape the Bazel sandbox and pop back to the workspace/repo. 21 | """ 22 | 23 | GitInfo = provider( 24 | doc = """Information needed to invoke git.""", 25 | fields = { 26 | "name": "The name of the toolchain", 27 | "valid": "Is this toolchain valid and usable?", 28 | "label": "Label of a target providing a git binary", 29 | "path": "The path to a pre-built git", 30 | "client_top": "The path to the top of the git client." + 31 | " In reality, we use the path to the WORKSPACE file as" + 32 | " a proxy for a folder underneath the git client top.", 33 | }, 34 | ) 35 | 36 | def _git_toolchain_impl(ctx): 37 | if ctx.attr.label and ctx.attr.path: 38 | fail("git_toolchain must not specify both label and path.") 39 | valid = bool(ctx.attr.label) or bool(ctx.attr.path) 40 | toolchain_info = platform_common.ToolchainInfo( 41 | git = GitInfo( 42 | name = str(ctx.label), 43 | valid = valid, 44 | label = ctx.attr.label, 45 | path = ctx.attr.path, 46 | client_top = ctx.attr.client_top, 47 | ), 48 | ) 49 | return [toolchain_info] 50 | 51 | git_toolchain = rule( 52 | implementation = _git_toolchain_impl, 53 | attrs = { 54 | "label": attr.label( 55 | doc = "A valid label of a target to build or a prebuilt binary. Mutually exclusive with path.", 56 | cfg = "exec", 57 | executable = True, 58 | allow_files = True, 59 | ), 60 | "path": attr.string( 61 | doc = "The path to the git executable. Mutually exclusive with label.", 62 | ), 63 | "client_top": attr.string( 64 | doc = "The top of your git client.", 65 | ), 66 | }, 67 | ) 68 | 69 | # Expose the presence of a git in the resolved toolchain as a flag. 70 | def _is_git_available_impl(ctx): 71 | toolchain = ctx.toolchains["@rules_pkg//toolchains/git:git_toolchain_type"] 72 | available = toolchain and toolchain.git.valid 73 | return [config_common.FeatureFlagInfo( 74 | value = ("1" if available else "0"), 75 | )] 76 | 77 | is_git_available = rule( 78 | implementation = _is_git_available_impl, 79 | attrs = {}, 80 | toolchains = ["@rules_pkg//toolchains/git:git_toolchain_type"], 81 | ) 82 | -------------------------------------------------------------------------------- /toolchains/rpm/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """toolchain to wrap an rpmbuild binary. 16 | 17 | Type: @rules_pkg//toolchains/rpm:rpmbuild_toolchain_type 18 | 19 | Toolchains: 20 | - rpmbuild_missing_toolchain: provides a fallback toolchain for exec platforms 21 | where rpmbuild might not be available. 22 | 23 | - rpmbuild_auto_toolchain: a toolchain that uses the installed rpmbuild. See 24 | rpmbuild_configure.bzl%find_system_rpmbuild for usage. 25 | """ 26 | 27 | load("//toolchains/rpm:rpmbuild.bzl", "is_rpmbuild_available", "rpmbuild_toolchain") 28 | 29 | package(default_applicable_licenses = ["//:license"]) 30 | 31 | filegroup( 32 | name = "standard_package", 33 | srcs = glob([ 34 | "*", 35 | ]), 36 | visibility = [ 37 | "//distro:__pkg__", 38 | "//doc_build:__pkg__", 39 | ], 40 | ) 41 | 42 | exports_files( 43 | glob(["*"]), 44 | visibility = ["//visibility:public"], 45 | ) 46 | 47 | # Expose the availability of an actual rpmbuild as a config_setting, so we can 48 | # select() on it. 49 | config_setting( 50 | name = "have_rpmbuild", 51 | flag_values = { 52 | ":is_rpmbuild_available": "1", 53 | }, 54 | visibility = ["//visibility:public"], 55 | ) 56 | 57 | # Expose the availability of an actual rpmbuild as a feature flag, so we can 58 | # create a config_setting from it. 59 | is_rpmbuild_available( 60 | name = "is_rpmbuild_available", 61 | visibility = ["//:__subpackages__"], 62 | ) 63 | 64 | toolchain_type( 65 | name = "rpmbuild_toolchain_type", 66 | visibility = ["//visibility:public"], 67 | ) 68 | 69 | # rpmbuild_missing_toolchain provides a fallback toolchain so that toolchain 70 | # resolution can succeed even on platforms that do not have a working rpmbuild. 71 | # If this toolchain is selected, the constraint ":have_rpmbuild" will not be 72 | # satistifed. 73 | rpmbuild_toolchain( 74 | name = "no_rpmbuild", 75 | ) 76 | 77 | toolchain( 78 | name = "rpmbuild_missing_toolchain", 79 | toolchain = ":no_rpmbuild", 80 | toolchain_type = ":rpmbuild_toolchain_type", 81 | ) 82 | -------------------------------------------------------------------------------- /toolchains/rpm/BUILD.tpl: -------------------------------------------------------------------------------- 1 | # This content is generated by {GENERATOR} 2 | load("@rules_pkg//toolchains/rpm:rpmbuild.bzl", "rpmbuild_toolchain") 3 | 4 | rpmbuild_toolchain( 5 | name = "rpmbuild_auto", 6 | path = "{RPMBUILD_PATH}", 7 | version = "{RPMBUILD_VERSION}", 8 | debuginfo_type = "{RPMBUILD_DEBUGINFO_TYPE}", 9 | ) 10 | 11 | toolchain( 12 | name = "rpmbuild_auto_toolchain", 13 | toolchain = ":rpmbuild_auto", 14 | toolchain_type = "@rules_pkg//toolchains/rpm:rpmbuild_toolchain_type", 15 | ) 16 | 17 | toolchain( 18 | name = "zzz_rpmbuild_missing_toolchain", # keep name lexicographically last 19 | toolchain = "@rules_pkg//toolchains/rpm:no_rpmbuild", 20 | toolchain_type = "@rules_pkg//toolchains/rpm:rpmbuild_toolchain_type", 21 | ) 22 | -------------------------------------------------------------------------------- /version.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2019 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """The version of rules_pkg.""" 15 | 16 | version = "1.1.0" 17 | --------------------------------------------------------------------------------