forked from zoidyzoidzoid/rules_pkg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b60dabf
commit 9384274
Showing
3 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
# rules_go boilerplate | ||
load("@bazel_gazelle//:def.bzl", "gazelle") | ||
|
||
gazelle( | ||
name = "gazelle", | ||
prefix = "github.com/bazelbuild/rules_pkg", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
workspace(name = "rules_pkg") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
def _rpm_packages_impl(repository_ctx): | ||
# check that keys in "packages" and "packages_sha256" are the same | ||
for package in repository_ctx.attr.packages: | ||
if package not in repository_ctx.attr.packages_sha256: | ||
fail("Package named \"%s\" was not found in packages_sha256 of rule %s" % (package, repository_ctx.name)) | ||
|
||
# download each package | ||
package_rule_dict = {} | ||
for package in repository_ctx.attr.packages: | ||
urllist = [] | ||
for mirror in repository_ctx.attr.mirrors: | ||
# allow mirror URLs that don't end in / | ||
if mirror.endswith("/"): | ||
urllist.append(mirror + repository_ctx.attr.packages[package]) | ||
else: | ||
urllist.append(mirror + "/" + repository_ctx.attr.packages[package]) | ||
repository_ctx.download( | ||
urllist, | ||
output="rpms/" + repository_ctx.attr.packages_sha256[package] + ".rpm", | ||
sha256=repository_ctx.attr.packages_sha256[package], | ||
executable=False) | ||
package_rule_dict[package] = "@" + repository_ctx.name + "//rpms:" + repository_ctx.attr.packages_sha256[package] + ".rpm" | ||
|
||
# create the rpm_packages.bzl file that contains the package name : filename mapping | ||
repository_ctx.file("rpms/rpm_packages.bzl", repository_ctx.name + " = " + struct(**package_rule_dict).to_json(), executable=False) | ||
|
||
# create the BUILD file that globs all the rpm files | ||
repository_ctx.file("rpms/BUILD", """ | ||
package(default_visibility = ["//visibility:public"]) | ||
rpm_files = glob(["*.rpm"]) | ||
exports_files(rpm_files + ["rpm_packages.bzl"]) | ||
""", executable=False) | ||
|
||
_rpm_packages = repository_rule( | ||
_rpm_packages_impl, | ||
attrs = { | ||
"distro_type": attr.string( | ||
doc = "the name of the distribution type, required - e.g. centos, fedora, or redhat", | ||
), | ||
"distro": attr.string( | ||
doc = "the name of the distribution, required - e.g. 7 or 8", | ||
), | ||
"arch": attr.string( | ||
doc = "the target package architecture, required - e.g. arm64 or amd64", | ||
), | ||
"packages": attr.string_dict( | ||
doc = "a dictionary mapping packagename to package_path, required - e.g. {\"foo\":\"pool/main/f/foo/foo_1.2.3-0_amd64.rpm\"}", | ||
), | ||
"packages_sha256": attr.string_dict( | ||
doc = "a dictionary mapping packagename to package_hash, required - e.g. {\"foo\":\"1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef\"}", | ||
), | ||
"mirrors": attr.string_list( | ||
doc = "a list of full URLs of the package repository, required - e.g. http://rpm.centos.org/centos", | ||
), | ||
"components": attr.string_list( | ||
doc = "a list of accepted components - e.g. universe, multiverse", | ||
), | ||
"pgp_key": attr.string( | ||
doc = "the name of the http_file rule that contains the pgp key that signed the Release file at <mirrorURL>/dists/<distro>/Release, required", | ||
), | ||
}, | ||
) | ||
|
||
def rpm_packages(**kwargs): | ||
_rpm_packages(**kwargs) |