theoremlp / rules_multitool

Bazel rules for ergonomic tool definitions
Apache License 2.0
24 stars 5 forks source link

Module dependencies tool version "winning". #41

Closed Geethree closed 5 months ago

Geethree commented 5 months ago

Okay let's say that I pull in aspect_rules_lint v0.21.0 which under the hood is using terraform v1.7.5, with this lockfile

cat multitool.lock.json 
{
  "$schema": "https://raw.githubusercontent.com/theoremlp/rules_multitool/main/lockfile.schema.json",
  "terraform": {
    "binaries": [
      {
        "kind": "archive",
        "url": "https://releases.hashicorp.com/terraform/1.8.5/terraform_1.8.5_darwin_arm64.zip",
        "sha256": "627c5005ab4a2bee36316f4967a41f16d55f79ea737f78b6bb34325c728c73e1",
        "os": "macos",
        "cpu": "arm64",
        "file": "terraform"
      },
      {
        "kind": "archive",
        "url": "https://releases.hashicorp.com/terraform/1.8.5/terraform_1.8.5_darwin_amd64.zip",
        "sha256": "051c702e156a4d1a1c628783cf2ca0e1db8cca7b4c0f1686ea623558ed5560f9",
        "os": "macos",
        "cpu": "x86_64",
        "file": "terraform"
      },
      {
        "kind": "archive",
        "url": "https://releases.hashicorp.com/terraform/1.8.5/terraform_1.8.5_linux_amd64.zip",
        "sha256": "bb1ee3e8314da76658002e2e584f2d8854b6def50b7f124e27b957a42ddacfea",
        "os": "linux",
        "cpu": "x86_64",
        "file": "terraform"
      },
      {
        "kind": "archive",
        "url": "https://releases.hashicorp.com/terraform/1.8.5/terraform_1.8.5_linux_arm64.zip",
        "sha256": "2cd8cf46c46041c5f46766ec5e96728905df60ef92fd32d9889033ef8c305f46",
        "os": "linux",
        "cpu": "arm64",
        "file": "terraform"
      }
    ]
  },
  "terraform_v185": {
    "binaries": [
      {
        "kind": "archive",
        "url": "https://releases.hashicorp.com/terraform/1.8.5/terraform_1.8.5_darwin_arm64.zip",
        "sha256": "627c5005ab4a2bee36316f4967a41f16d55f79ea737f78b6bb34325c728c73e1",
        "os": "macos",
        "cpu": "arm64",
        "file": "terraform"
      },
      {
        "kind": "archive",
        "url": "https://releases.hashicorp.com/terraform/1.8.5/terraform_1.8.5_darwin_amd64.zip",
        "sha256": "051c702e156a4d1a1c628783cf2ca0e1db8cca7b4c0f1686ea623558ed5560f9",
        "os": "macos",
        "cpu": "x86_64",
        "file": "terraform"
      },
      {
        "kind": "archive",
        "url": "https://releases.hashicorp.com/terraform/1.8.5/terraform_1.8.5_linux_amd64.zip",
        "sha256": "bb1ee3e8314da76658002e2e584f2d8854b6def50b7f124e27b957a42ddacfea",
        "os": "linux",
        "cpu": "x86_64",
        "file": "terraform"
      },
      {
        "kind": "archive",
        "url": "https://releases.hashicorp.com/terraform/1.8.5/terraform_1.8.5_linux_arm64.zip",
        "sha256": "2cd8cf46c46041c5f46766ec5e96728905df60ef92fd32d9889033ef8c305f46",
        "os": "linux",
        "cpu": "arm64",
        "file": "terraform"
      }
    ]
  }
}

I see the following

gspencer@gspencer-mlt autobots % bazel run @multitool//tools/terraform version
INFO: Analyzed target @@rules_multitool~~multitool~multitool//tools/terraform:terraform (9 packages loaded, 66 targets configured).
INFO: Found 1 target...
Target @@rules_multitool~~multitool~multitool//tools/terraform:terraform up-to-date:
  bazel-bin/external/rules_multitool~~multitool~multitool/tools/terraform/terraform
INFO: Elapsed time: 2.124s, Critical Path: 0.04s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Running command line: bazel-bin/external/rules_multitool~~multitool~multitool/tools/terraform/terraform version
Terraform v1.7.5
on darwin_arm64

Your version of Terraform is out of date! The latest version
is 1.8.5. You can update by downloading from https://www.terraform.io/downloads.html
gspencer@gspencer-mlt autobots % bazel run @multitool//tools/terraform_v185 version
INFO: Analyzed target @@rules_multitool~~multitool~multitool//tools/terraform_v185:terraform_v185 (1 packages loaded, 3 targets configured).
INFO: Found 1 target...
Target @@rules_multitool~~multitool~multitool//tools/terraform_v185:terraform_v185 up-to-date:
  bazel-bin/external/rules_multitool~~multitool~multitool/tools/terraform_v185/terraform_v185
INFO: Elapsed time: 0.651s, Critical Path: 0.05s
INFO: 5 processes: 5 internal.
INFO: Build completed successfully, 5 total actions
INFO: Running command line: bazel-bin/external/rules_multitool~~multitool~multitool/tools/terraform_v185/terraform_v185 version
Terraform v1.8.5
on darwin_arm64

It appears to me that the first time a tool is loaded.. that version wins. I assume that the aspect_rules_lint module is loaded first and there for is the known "terraform" tool. The silent error gets me though..

For now I can work around with the pattern above, but it feels subpar.

Geethree commented 5 months ago

I suppose it is because there is only one hub name

https://github.com/theoremlp/rules_multitool/blob/218c3db84d0ad812a2fdc10d891ccf9950531bb6/multitool/extension.bzl#L17-L21