Skip to content

Commit

Permalink
Add buildifier target and buildifier tests (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcmyers committed Aug 29, 2024
1 parent 7fcb47e commit e48bbc7
Show file tree
Hide file tree
Showing 17 changed files with 223 additions and 17 deletions.
16 changes: 16 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files")
load("@buildifier_prebuilt//:rules.bzl", "buildifier", "buildifier_test")
load("@gazelle//:def.bzl", "DEFAULT_LANGUAGES", "gazelle", "gazelle_binary")
load("//oci:toolchain.bzl", "oci_local_toolchain")

Expand All @@ -10,6 +11,21 @@ oci_local_toolchain(
name = "oci_local_toolchain",
)

buildifier(
name = "buildifier",
exclude_patterns = ["./.git/*"],
lint_mode = "warn",
mode = "fix",
)

buildifier_test(
name = "buildifier_test",
exclude_patterns = ["./.git/*"],
lint_mode = "warn",
no_sandbox = True,
workspace = "//:WORKSPACE",
)

gazelle(
name = "gazelle",
gazelle = ":default_gazelle_binary",
Expand Down
9 changes: 3 additions & 6 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,20 @@ module(

bazel_dep(name = "aspect_bazel_lib", version = "2.7.3")
bazel_dep(name = "bazel_skylib", version = "1.6.1")
bazel_dep(name = "bazel_skylib_gazelle_plugin", dev_dependency = True, version = "1.6.1")
bazel_dep(name = "gazelle", version = "0.38.0")
bazel_dep(name = "rules_go", version = "0.47.1")
bazel_dep(name = "rules_pkg", version = "0.10.1")
bazel_dep(name = "stardoc", version = "0.6.2")

go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.6.1", dev_dependency = True)
bazel_dep(name = "buildifier_prebuilt", version = "7.3.1", dev_dependency = True)

go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(version = "1.22.5")

go_sdk.host()

go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")

go_deps.from_file(go_mod = "//:go.mod")

use_repo(
go_deps,
"com_github_blakesmith_ar",
Expand Down Expand Up @@ -49,7 +47,6 @@ use_repo(
"org_golang_x_sync",
"org_golang_x_sys",
)

go_deps.module_override(
patch_strip = 1,
patches = [
Expand Down
152 changes: 152 additions & 0 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
workspace(name = "com_github_datadog_rules_oci")
2 changes: 1 addition & 1 deletion docs/docs.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- Generated with Stardoc: http://skydoc.bazel.build -->


public API

<a id="oci_image"></a>

Expand Down
2 changes: 2 additions & 0 deletions oci/blob.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
""" blob """

load("@com_github_datadog_rules_oci//oci:providers.bzl", "OCIDescriptor")

def _oci_blob_impl(ctx):
Expand Down
7 changes: 6 additions & 1 deletion oci/debug_flag.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
DebugInfo = provider(fields = ["debug"])
""" debug_flag """

DebugInfo = provider(
"DebugInfo",
fields = ["debug"],
)

def _debug_flag_impl(ctx):
return [DebugInfo(debug = ctx.build_setting_value)]
Expand Down
4 changes: 3 additions & 1 deletion oci/defs.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
""" public API """

load(":image.bzl", _oci_image = "oci_image", _oci_image_index = "oci_image_index", _oci_image_layer = "oci_image_layer")
load(":pull.bzl", _oci_pull = "oci_pull")
load(":push.bzl", _oci_push = "oci_push")
load(":image.bzl", _oci_image = "oci_image", _oci_image_index = "oci_image_index", _oci_image_layer = "oci_image_layer")

oci_pull = _oci_pull
oci_push = _oci_push
Expand Down
5 changes: 4 additions & 1 deletion oci/image.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
""" image """

load("@com_github_datadog_rules_oci//oci:providers.bzl", "OCIDescriptor", "OCILayout")

# buildifier: disable=function-docstring
def get_descriptor_file(ctx, desc):
if hasattr(desc, "descriptor_file"):
return desc.descriptor_file
Expand Down Expand Up @@ -249,7 +252,7 @@ oci_image = rule(
doc = "Used to extract a manifest from base if base is an index",
),
"env": attr.string_list(
doc = """Entries are in the format of `VARNAME=VARVALUE`. These values act as defaults and
doc = """Entries are in the format of `VARNAME=VARVALUE`. These values act as defaults and
are merged with any specified when creating a container.""",
),
"layers": attr.label_list(
Expand Down
4 changes: 3 additions & 1 deletion oci/layout.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
load("@com_github_datadog_rules_oci//oci:providers.bzl", "OCIDescriptor", "OCIImageIndexManifest", "OCILayout")
""" layout """

load("@com_github_datadog_rules_oci//oci:providers.bzl", "OCIDescriptor", "OCILayout")

def _oci_layout_index_impl(ctx):
blobs_map = {}
Expand Down
4 changes: 3 additions & 1 deletion oci/manifests.bzl
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
""" manifests """

load("@com_github_datadog_rules_oci//oci:providers.bzl", "OCIDescriptor", "OCIImageIndexManifest", "OCIImageManifest", "OCILayout")

def _oci_image_manifest_impl(ctx):
return [OCIImageManifest(
config = ctx.attr.config[OCIDescriptor],
layers = [l[OCIDescriptor] for l in ctx.attr.layers],
layers = [layer[OCIDescriptor] for layer in ctx.attr.layers],
annotations = ctx.attr.annotations,
), ctx.attr.layout[OCILayout], ctx.attr.descriptor[OCIDescriptor]]

Expand Down
8 changes: 8 additions & 0 deletions oci/providers.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
""" providers """

OCIReferenceInfo = provider(
doc = "Refers to any artifact represented by an OCI-like reference URI",
fields = {
Expand All @@ -9,13 +11,16 @@ OCIReferenceInfo = provider(
},
)

# buildifier: disable=name-conventions
OCILayout = provider(
"OCI Layout",
fields = {
"blob_index": "",
"files": "",
},
)

# buildifier: disable=name-conventions
OCIDescriptor = provider(
doc = "",
fields = {
Expand All @@ -29,6 +34,7 @@ OCIDescriptor = provider(
},
)

# buildifier: disable=name-conventions
OCIImageManifest = provider(
doc = "",
fields = {
Expand All @@ -38,6 +44,7 @@ OCIImageManifest = provider(
},
)

# buildifier: disable=name-conventions
OCIImageIndexManifest = provider(
doc = "",
fields = {
Expand All @@ -46,6 +53,7 @@ OCIImageIndexManifest = provider(
},
)

# buildifier: disable=name-conventions
OCIPlatform = provider(
doc = "Platform describes the platform which the image in the manifest runs on",
fields = {
Expand Down
3 changes: 3 additions & 0 deletions oci/pull.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
""" pull """

# A directory to store cached OCI artifacts
# TODO(griffin) currently not used, but going to start depending on this for
# integration into the bzl wrapper.
Expand All @@ -12,6 +14,7 @@ def failout(msg, cmd_result):
.format(msg = msg, stdout = cmd_result.stdout, stderr = cmd_result.stderr),
)

# buildifier: disable=function-docstring
def pull(rctx, layout_root, repository, digest, registry = "", shallow = False, debug = False):
cmd = [
rctx.path(_repo_toolchain(rctx, "ocitool")),
Expand Down
4 changes: 3 additions & 1 deletion oci/push.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
""" push """

load("@aspect_bazel_lib//lib:stamping.bzl", "STAMP_ATTRS", "maybe_stamp")
load("@com_github_datadog_rules_oci//oci:providers.bzl", "OCIDescriptor", "OCILayout", "OCIReferenceInfo")
load("@com_github_datadog_rules_oci//oci:debug_flag.bzl", "DebugInfo")
load("@com_github_datadog_rules_oci//oci:providers.bzl", "OCIDescriptor", "OCILayout", "OCIReferenceInfo")

def _oci_push_impl(ctx):
toolchain = ctx.toolchains["@com_github_datadog_rules_oci//oci:toolchain"]
Expand Down
Loading

0 comments on commit e48bbc7

Please sign in to comment.