about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLuke Granger-Brown <hg@lukegb.com>2020-07-26T12·51+0100
committerlukegb <lukegb@tvl.fyi>2020-07-27T00·00+0000
commite780435d09207b84dff49c870e875ad3f052b2fe (patch)
treebf219d90d330f186eca378ea63e7d0b88d4aed74
parent2b7fe6f95769a134f55f277f7d5575530467babd (diff)
chore(3p/gerrit_plugins): add machinery for compiling Gerrit plugins from source r/1488
This looks particularly obnoxious for the owners plugin, because it's
actually two plugins with a common library in the same repo. Other
plugins are much cleaner to deal with (hence the default for
overlayPluginCmd).

Change-Id: Ibb9588c8a29b63e8509436fcbb70054e89349712
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1461
Tested-by: BuildkiteCI
Reviewed-by: glittershark <grfn@gws.fyi>
-rw-r--r--ci-builds.nix5
-rw-r--r--third_party/gerrit/default.nix6
-rw-r--r--third_party/gerrit_plugins/builder.nix28
-rw-r--r--third_party/gerrit_plugins/default.nix29
4 files changed, 58 insertions, 10 deletions
diff --git a/ci-builds.nix b/ci-builds.nix
index d4ea63d99e..6b7f48f44d 100644
--- a/ci-builds.nix
+++ b/ci-builds.nix
@@ -68,6 +68,11 @@ in lib.fix (self: {
     rapidcheck
   ] ++ builtins.attrValues lisp;
 
+  gerrit = with depot.third_party.gerrit_plugins; [
+    depot.third_party.gerrit
+    owners
+  ];
+
   lisp = with depot.lisp; [
     dns
     klatre
diff --git a/third_party/gerrit/default.nix b/third_party/gerrit/default.nix
index b90e042b73..4af2c4c182 100644
--- a/third_party/gerrit/default.nix
+++ b/third_party/gerrit/default.nix
@@ -30,17 +30,17 @@ let
   bazel = bazelTop // { override = x: bazelTop; };
   version = "3.2.2-1002-gea26b5ee7a";
 in
-pkgs.buildBazelPackage {
+pkgs.lib.makeOverridable pkgs.buildBazelPackage {
   name = "gerrit-${version}";
 
-  src = (pkgs.fetchgit {
+  src = pkgs.fetchgit {
     url = "https://gerrit.googlesource.com/gerrit";
     rev = "ea26b5ee7a1c1e4042525d308678570101d4d4d6";
     sha256 = "1bndmk7namb81zkscmpvf8ygwrj0wh842xbj0irgbm5w2xwdzkch";
     fetchSubmodules = true;
     deepClone = true;
     leaveDotGit = true;
-  });
+  };
   patches = [
     ./0001-Use-detzip-in-download_bower.py.patch
     ./0002-Syntax-highlight-nix.patch
diff --git a/third_party/gerrit_plugins/builder.nix b/third_party/gerrit_plugins/builder.nix
new file mode 100644
index 0000000000..7676f50208
--- /dev/null
+++ b/third_party/gerrit_plugins/builder.nix
@@ -0,0 +1,28 @@
+{ depot, pkgs, ... }:
+{
+  buildGerritBazelPlugin = {
+    name,
+    src,
+    depsOutputHash,
+    overlayPluginCmd ? ''
+      cp -R "${src}" "$out/plugins/${name}"
+    '',
+  }: ((depot.third_party.gerrit.override {
+    name = "${name}.jar";
+
+    src = pkgs.runCommandLocal "${name}-src" {} ''
+      cp -R "${depot.third_party.gerrit.src}" "$out"
+      chmod +w "$out/plugins"
+      ${overlayPluginCmd}
+    '';
+
+    bazelTarget = "//plugins/${name}";
+  }).overrideAttrs (super: {
+    deps = super.deps.overrideAttrs (superDeps: {
+      outputHash = depsOutputHash;
+    });
+    installPhase = ''
+      cp "bazel-bin/plugins/${name}/${name}.jar" "$out"
+    '';
+  }));
+}
diff --git a/third_party/gerrit_plugins/default.nix b/third_party/gerrit_plugins/default.nix
index 932b98c356..929d1bba9f 100644
--- a/third_party/gerrit_plugins/default.nix
+++ b/third_party/gerrit_plugins/default.nix
@@ -1,10 +1,25 @@
-{ pkgs, ... }:
+{ depot, pkgs, ... }@args:
 
-let inherit (pkgs) fetchurl;
-in {
+let
+  inherit (import ./builder.nix args) buildGerritBazelPlugin;
+in
+{
   # https://gerrit.googlesource.com/plugins/owners
-  owners = fetchurl {
-    url = "https://storage.googleapis.com/tazjins-data/tvl/owners_3.2.jar";
-    sha256 = "1xw1q3g0353aw5jqxp69n85f8y57l2p51np37n8r34kzbn5r4iz7";
-  } // { name = "owners"; };
+  owners = buildGerritBazelPlugin rec {
+    name = "owners";
+    depsOutputHash = "0j60yn65kn27s7cjkj3z6irymq7j7rj3q5h3n6xfrs5inm4md2ad";
+    src = pkgs.fetchgit {
+      url = "https://gerrit.googlesource.com/plugins/owners";
+      rev = "17817c9e319073c03513f9d5177b6142b8fd567b";
+      sha256 = "1p089shybp50svckcq51d0hfisjvbggndmvmhh8pvzvi6w8n9d89";
+      deepClone = true;
+      leaveDotGit = true;
+    };
+    overlayPluginCmd = ''
+      chmod +w "$out" "$out/plugins/external_plugin_deps.bzl"
+      cp -R "${src}/owners" "$out/plugins/owners"
+      cp "${src}/external_plugin_deps.bzl" "$out/plugins/external_plugin_deps.bzl"
+      cp -R "${src}/owners-common" "$out/owners-common"
+    '';
+  };
 }