Skip to content

Commit

Permalink
Update depency setup
Browse files Browse the repository at this point in the history
* Use `maybe`s for http_archive and friends
* Update Skylib version
* Update rules_python version
* Move rules_python out of the `rules_appimage_deps()` (it's not a "runtime" dependency, only an internal test dependency)
* Use a hermetic Python toolchain for the tests, and install pytest via rules_python
  • Loading branch information
lalten committed Apr 23, 2023
1 parent b7322bb commit 209e0b2
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 49 deletions.
9 changes: 5 additions & 4 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
exports_files(
[
"requirements.txt",
],
load("@rules_python//python/pip_install:requirements.bzl", "compile_pip_requirements")

compile_pip_requirements(
name = "requirements",
extra_args = ["--resolver=backtracking"],
)
37 changes: 33 additions & 4 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,38 @@ load("//:deps.bzl", "rules_appimage_deps")

rules_appimage_deps()

load("@rules_python//python:pip.bzl", "pip_install")
# Below this is the Python setup for testing the rules_appimage Python rules.
# This is _not_ required for _using_ the rules_appimage rules.

pip_install(
name = "py_deps",
requirements = "@rules_appimage//:requirements.txt",
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

maybe(
http_archive,
name = "rules_python",
sha256 = "94750828b18044533e98a129003b6a68001204038dc4749f40b195b24c38f49f",
strip_prefix = "rules_python-0.21.0",
url = "https://github.com/bazelbuild/rules_python/releases/download/0.21.0/rules_python-0.21.0.tar.gz",
)

load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains")

py_repositories()

python_register_toolchains(
name = "rules_appimage_python",
python_version = "3.11",
)

load("@rules_appimage_python//:defs.bzl", "interpreter")
load("@rules_python//python:pip.bzl", "pip_parse")

pip_parse(
name = "rules_appimage_py_deps",
python_interpreter_target = interpreter,
requirements_lock = "//:requirements.txt",
)

load("@rules_appimage_py_deps//:requirements.bzl", "install_deps")

install_deps()
68 changes: 30 additions & 38 deletions deps.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Dependencies of rules_appimage."""

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

_SHAS = {
"appimage_runtime_aarch64": "df1dcce6992a23cdf8728e88ed24f71b3c385f6384f3484ff66f45b9c97f00f2",
Expand All @@ -15,47 +16,38 @@ _SHAS = {

def rules_appimage_deps():
"""Download dependencies and set up rules_appimage."""
excludes = native.existing_rules().keys()

if "bazel_skylib" not in excludes:
http_archive(
name = "bazel_skylib",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
],
sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506",
)

if "rules_python" not in excludes:
http_archive(
name = "rules_python",
url = "https://github.com/bazelbuild/rules_python/releases/download/0.5.0/rules_python-0.5.0.tar.gz",
sha256 = "cd6730ed53a002c56ce4e2f396ba3b3be262fd7cb68339f0377a45e8227fe332",
)
maybe(
http_archive,
name = "bazel_skylib",
sha256 = "b8a1527901774180afc798aeb28c4634bdccf19c4d98e7bdd1ce79d1fe9aaad7",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz",
],
)

for arch in ("aarch64", "armhf", "i686", "x86_64"):
name = "appimage_runtime_" + arch
if name not in excludes:
http_file(
name = name,
executable = True,
sha256 = _SHAS[name],
urls = ["https://github.com/lalten/type2-runtime/releases/download/build-2022-10-03-c5c7b07/runtime-{}".format(arch)],
)
maybe(
http_file,
name = name,
executable = True,
sha256 = _SHAS[name],
urls = ["https://github.com/lalten/type2-runtime/releases/download/build-2022-10-03-c5c7b07/runtime-{}".format(arch)],
)

name = "mksquashfs_" + arch
if name not in excludes:
http_file(
name = name,
executable = True,
sha256 = _SHAS[name],
urls = ["https://github.com/lalten/static-tools/releases/download/build-2022-10-02-970eff7/mksquashfs-{}".format(arch)],
)

if "appimagetool.png" not in excludes:
http_file(
name = "appimagetool.png",
sha256 = "0c23daaf7665216a8e8f9754c904ec18b2dfa376af2479601a571e504239fae6",
urls = ["https://raw.githubusercontent.com/AppImage/AppImageKit/b51f685/resources/appimagetool.png"],
maybe(
http_file,
name = name,
executable = True,
sha256 = _SHAS[name],
urls = ["https://github.com/lalten/static-tools/releases/download/build-2022-10-02-970eff7/mksquashfs-{}".format(arch)],
)

maybe(
http_file,
name = "appimagetool.png",
sha256 = "0c23daaf7665216a8e8f9754c904ec18b2dfa376af2479601a571e504239fae6",
urls = ["https://raw.githubusercontent.com/AppImage/AppImageKit/b51f685/resources/appimagetool.png"],
)
1 change: 1 addition & 0 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest==7.3.1
23 changes: 22 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
pytest==7.1.3
#
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# bazel run //:requirements.update
#
iniconfig==2.0.0 \
--hash=sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3 \
--hash=sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374
# via pytest
packaging==23.0 \
--hash=sha256:714ac14496c3e68c99c29b00845f7a2b85f3bb6f1078fd9f72fd20f0570002b2 \
--hash=sha256:b6ad297f8907de0fa2fe1ccbd26fdaf387f5f47c7275fedf8cce89f99446cf97
# via pytest
pluggy==1.0.0 \
--hash=sha256:4224373bacce55f955a878bf9cfa763c1e360858e330072059e10bad68531159 \
--hash=sha256:74134bbf457f031a36d68416e1509f34bd5ccc019f0bcc952c7b909d06b37bd3
# via pytest
pytest==7.3.1 \
--hash=sha256:3799fa815351fea3a5e96ac7e503a96fa51cc9942c3753cda7651b93c1cfa362 \
--hash=sha256:434afafd78b1d78ed0addf160ad2b77a30d35d4bdf8af234fe621919d9ed15e3
# via -r ./requirements.in
2 changes: 1 addition & 1 deletion tests/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@py_deps//:requirements.bzl", "requirement")
load("@rules_appimage_py_deps//:requirements.bzl", "requirement")
load("@rules_python//python:defs.bzl", "py_binary", "py_test")
load("//appimage:appimage.bzl", "appimage", "appimage_test")
load(":testrules.bzl", "rules_appimage_test_rule")
Expand Down
2 changes: 1 addition & 1 deletion tests/tool/tests/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@py_deps//:requirements.bzl", "requirement")
load("@rules_appimage_py_deps//:requirements.bzl", "requirement")
load("@rules_python//python:defs.bzl", "py_test")

py_test(
Expand Down

0 comments on commit 209e0b2

Please sign in to comment.