Skip to content

Commit

Permalink
Get bzlmod working in CI (#766)
Browse files Browse the repository at this point in the history
Get bzlmod CI working
* fix a lot of python which needs tochange
* make extension for rpmbuild
* restore macos CI to rolling
* better documentation on how to use rpmbuild.
* no docbuild with bzlmod -> stardoc problems
* disable a tar test that can not work with bzlmod

Next: Split rpmbuild to a separately distributable artifact
  • Loading branch information
aiuto authored Oct 31, 2023
1 parent 1b033dd commit 8e5570c
Show file tree
Hide file tree
Showing 17 changed files with 95 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .bazelci/examples_naming.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ tasks:
name: bzlmod
platform: ubuntu1804
build_flags:
- "--experimental_enable_bzlmod"
- "--enable_bzlmod"
<<: *common
16 changes: 10 additions & 6 deletions .bazelci/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,19 @@ tasks:
name: rolling_ubuntu
<<: *ubuntu
<<: *rolling
rolling_ubuntu_bzlmod:
name: rolling_ubuntu_bzlmod
platform: ubuntu1804
build_flags:
- "--enable_bzlmod"
<<: *common
<<: *rolling
<<: *default_tests
rolling_macos:
name: rolling_macos
# It seems there is no rolling Bazel for macos.
platform: macos
bazel: last_green
bazel: rolling
<<: *macos
<<: *common
test_targets:
- "//tests/..."
- "-//tests/rpm/..."
rolling_windows:
name: rolling_windows
<<: *windows
Expand Down
7 changes: 6 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ module(

# Do not update to newer versions until you need a specific new feature.
bazel_dep(name = "rules_license", version = "0.0.4")
bazel_dep(name = "rules_python", version = "0.24.0")
bazel_dep(name = "bazel_skylib", version = "1.2.0")
bazel_dep(name = "rules_python", version = "0.10.2")

# Only for development
bazel_dep(name = "platforms", version = "0.0.5", dev_dependency = True)
bazel_dep(name = "stardoc", version = "0.5.3", dev_dependency = True)
bazel_dep(name = "rules_cc", version = "0.0.9", dev_dependency = True)

# Find the system rpmbuild if one is available.
find_rpm = use_extension("//toolchains/rpm:rpmbuild_configure.bzl", "find_system_rpmbuild_bzlmod", dev_dependency = True)
use_repo(find_rpm, "rules_pkg_rpmbuild")
register_toolchains("@rules_pkg_rpmbuild//:all", dev_dependency = True)
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,49 @@ As of Bazel 4.x, Bazel uses this rule set for packaging its distribution. Bazel
still contains a limited version of `pkg_tar` but its feature set is frozen.
Any new capabilities will be added here.


## WORKSPACE setup

Sample, but see [releases](https://github.com/bazelbuild/rules_pkg/releases) for the current release.

```
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "rules_pkg",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz",
"https://github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz",
],
sha256 = "8f9ee2dc10c1ae514ee599a8b42ed99fa262b757058f65ad3c384289ff70c4b8",
)
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
rules_pkg_dependencies()
```

To use `pkg_rpm()`, you must provide a copy of `rpmbuild`. You can use the
system installed `rpmbuild` with this stanza.
```
load("@rules_pkg//toolchains/rpm:rpmbuild_configure.bzl", "find_system_rpmbuild")
find_system_rpmbuild(
name = "rules_pkg_rpmbuild",
verbose = False,
)
```

## MODULE.bazel setup

```
bazel_dep(name = "rules_pkg", version = "0.0.10")
```
To use `pkg_rpm()`, you must provide a copy of `rpmbuild`. You can use the
system installed `rpmbuild` with this stanza.
```
find_rpm = use_extension("//toolchains/rpm:rpmbuild_configure.bzl", "find_system_rpmbuild_bzlmod")
use_repo(find_rpm, "rules_pkg_rpmbuild")
register_toolchains("@rules_pkg_rpmbuild//:all")
```

### For developers

* [Contributor information](CONTRIBUTING.md) (including contributor license agreements)
Expand Down
1 change: 0 additions & 1 deletion distro/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ load("//pkg/releasing:defs.bzl", "print_rel_notes")
load("//pkg/releasing:git.bzl", "git_changelog")
load("@rules_python//python:defs.bzl", "py_test")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@bazel_stardoc//stardoc:stardoc.bzl", "stardoc")

package(
default_applicable_licenses = ["//:license"],
Expand Down
2 changes: 1 addition & 1 deletion pkg/releasing/release_tools_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import unittest

import release_tools
from pkg.releasing import release_tools


class ReleaseToolsTest(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/install/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import stat
import subprocess

from rules_python.python.runfiles import runfiles
from python.runfiles import runfiles
from pkg.private import manifest


Expand Down
2 changes: 1 addition & 1 deletion tests/mappings/filter_directory/inspect_directory.py.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import json
import os
import unittest
from rules_python.python.runfiles import runfiles
from python.runfiles import runfiles

DIRECTORY_ROOT = "%DIRECTORY_ROOT%"
# This is JSON, which shouldn't have any triple quotes in it.
Expand Down
2 changes: 1 addition & 1 deletion tests/mappings/filter_directory/test_filter_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import tempfile
import unittest

from rules_python.python.runfiles import runfiles
from python.runfiles import runfiles

# Get the filter_directory script into the import path. There might be a
# better way to do this, but it works.
Expand Down
5 changes: 4 additions & 1 deletion tests/mappings/manifest_test_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ def assertManifestsMatch(self, expected_path, got_path):
with open(g_file, mode='rt', encoding='utf-8') as g_fp:
got = json.loads(g_fp.read())
got_dict = {x['dest']: x for x in got}
# self.assertEqual(expected_dict, got_dict)

ok = True
expected_dests = set(expected_dict.keys())
got_dests = set(got_dict.keys())
for dest, what in expected_dict.items():
got = got_dict.get(dest)
if got:
# bzlmod mode changes root to @@//, but older version give @//
origin = got.get('origin')
if origin and origin.startswith('@@//'):
got['origin'] = origin[1:]
self.assertDictEqual(what, got)
else:
print('Missing expected path "%s" in manifest' % dest)
Expand Down
2 changes: 1 addition & 1 deletion tests/rpm/pkg_rpm_basic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import io
import os

from rules_python.python.runfiles import runfiles
from python.runfiles import runfiles
from tests.rpm import rpm_util

# This provides some tests for built RPMs, mostly by taking the built RPM and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import os
import unittest

from rules_python.python.runfiles import runfiles
from python.runfiles import runfiles
from tests.rpm import rpm_util

# Tue Mar 23 00:00:00 EDT 2021
Expand Down
2 changes: 1 addition & 1 deletion tests/rpm/tree_artifacts/rpm_contents_vs_manifest_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import io
import os

from rules_python.python.runfiles import runfiles
from python.runfiles import runfiles
from tests.rpm import rpm_util

EXPECTED_RPM_MANIFEST_CSV = """
Expand Down
2 changes: 1 addition & 1 deletion tests/rpm/tree_artifacts/rpm_treeartifact_ops_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import os
import unittest

from rules_python.python.runfiles import runfiles
from python.runfiles import runfiles
from tests.rpm import rpm_util

EXPECTED_RPM_MANIFEST_CSV = """
Expand Down
2 changes: 1 addition & 1 deletion tests/tar/pkg_tar_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test_strip_prefix_substring(self):
]
self.assertTarFileContent('test-tar-strip_prefix-substring.tar', content)

def test_strip_prefix_dot(self):
def disabled_test_strip_prefix_dot(self):
content = [
{'name': 'etc'},
{'name': 'etc/nsswitch.conf'},
Expand Down
6 changes: 6 additions & 0 deletions toolchains/rpm/BUILD.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ toolchain(
toolchain = ":rpmbuild_auto",
toolchain_type = "@rules_pkg//toolchains/rpm:rpmbuild_toolchain_type",
)

toolchain(
name = "zzz_rpmbuild_missing_toolchain", # keep name lexigraphically last
toolchain = "@rules_pkg//toolchains/rpm:no_rpmbuild",
toolchain_type = "@rules_pkg//toolchains/rpm:rpmbuild_toolchain_type",
)
23 changes: 16 additions & 7 deletions toolchains/rpm/rpmbuild_configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
# limitations under the License.
"""Repository rule to autoconfigure a toolchain using the system rpmbuild."""

# NOTE: this must match the name used by register_toolchains in consuming
# MODULE.bazel files. It seems like we should have a better interface that
# allows for this module name to be specified from a single point.
NAME="rules_pkg_rpmbuild"

def _write_build(rctx, path, version):
if not path:
path = ""
Expand All @@ -27,7 +32,7 @@ def _write_build(rctx, path, version):
executable = False,
)

def _find_system_rpmbuild_impl(rctx):
def _build_repo_for_rpmbuild_toolchain_impl(rctx):
rpmbuild_path = rctx.which("rpmbuild")
if rctx.attr.verbose:
if rpmbuild_path:
Expand All @@ -44,8 +49,8 @@ def _find_system_rpmbuild_impl(rctx):
version = parts[2]
_write_build(rctx = rctx, path = rpmbuild_path, version = version)

_find_system_rpmbuild = repository_rule(
implementation = _find_system_rpmbuild_impl,
build_repo_for_rpmbuild_toolchain = repository_rule(
implementation = _build_repo_for_rpmbuild_toolchain_impl,
doc = """Create a repository that defines an rpmbuild toolchain based on the system rpmbuild.""",
local = True,
environ = ["PATH"],
Expand All @@ -56,8 +61,12 @@ _find_system_rpmbuild = repository_rule(
},
)

# For use from WORKSPACE
def find_system_rpmbuild(name, verbose=False):
_find_system_rpmbuild(name=name, verbose=verbose)
native.register_toolchains(
"@%s//:rpmbuild_auto_toolchain" % name,
"@rules_pkg//toolchains/rpm:rpmbuild_missing_toolchain")
build_repo_for_rpmbuild_toolchain(name=name, verbose=verbose)
native.register_toolchains("@%s//:all" % name)

# For use from MODULE.bzl
find_system_rpmbuild_bzlmod = module_extension(
implementation = lambda ctx: build_repo_for_rpmbuild_toolchain(name=NAME)
)

0 comments on commit 8e5570c

Please sign in to comment.