Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using locally built images #143

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,13 @@ orfs.default(
use_repo(orfs, "docker_orfs")
```

Setting this attribute to a valid image and checksum will enable Bazel to automatically pull the image and extract ORFS artifacts.
Setting this attribute to a valid image and checksum will enable Bazel to automatically pull the image and extract ORFS artifacts on `bazel run` or `bazel build`:

```bash
bazel build <target>_<stage>
```

If the directory under the `<absolute_path>` does not exist, it will be created. If a relative path is provided, the `bazel run` command above will fail.
> **NOTE:** If `sha256` is set to an empty string `""`, Bazel will attempt to use a local image with name provided in the `image` field.

### Local flow

Expand All @@ -187,6 +187,8 @@ A locally built and modified [ORFS](https://openroad-flow-scripts.readthedocs.io
bazel run <target>_<stage>_deps -- <absolute_path> && <absolute_path>/make do-<stage>
```

> **NOTE:** If the directory under the `<absolute_path>` does not exist, it will be created. If a relative path is provided, the `bazel run` command above will fail.

A convenient way to re-run the floorplan and view the results would be:

```bash
Expand Down
25 changes: 24 additions & 1 deletion docker.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "patch")

def _impl(repository_ctx):
image = "{}@sha256:{}".format(repository_ctx.attr.image, repository_ctx.attr.sha256)
if repository_ctx.attr.sha256 != "":
image = "{}@sha256:{}".format(repository_ctx.attr.image, repository_ctx.attr.sha256)
else:
image = repository_ctx.attr.image

python_name = "python3"
python = repository_ctx.which(python_name)
Expand All @@ -14,6 +17,26 @@ def _impl(repository_ctx):
if not docker:
fail("Failed to find {}.".format(docker_name))

if repository_ctx.attr.sha256 == "":
inspect = repository_ctx.execute([
docker,
"inspect",
"--type=image",
image,
])
if inspect.return_code != 0:
fail("Local image {} does not exist: {}".format(image, inspect.stderr), inspect.return_code)
repository_ctx.report_progress("Using local {}.".format(repository_ctx.attr.image))
else:
pull = repository_ctx.execute([
docker,
"pull",
image,
])
if pull.return_code != 0:
fail("Image {} cannot be pulled: {}".format(image, pull.stderr), pull.return_code)
repository_ctx.report_progress("Pulled {}.".format(repository_ctx.attr.image))

created = repository_ctx.execute(
[
docker,
Expand Down