feat(tools/depotfmt): add a treefmt wrapper with depot configuration

Right now the only included formatter is gofmt, but we will extend
this over time.

The version of treefmt is bumped to 0.3.0 (which supports custom
config files) until this lands in nixpkgs.

Change-Id: I1e1aafd05ec7427c616f90c90490c528ecb2615c
Reviewed-on: https://cl.tvl.fyi/c/depot/+/4399
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
This commit is contained in:
Vincent Ambo 2021-12-18 16:01:10 +03:00 committed by tazjin
parent 3090f61713
commit d018484376
4 changed files with 37 additions and 0 deletions

View file

@ -58,6 +58,9 @@ case "${TARGET_TOOL}" in
stern)
attr="third_party.nixpkgs.stern"
;;
depotfmt)
attr="tools.depotfmt"
;;
*)
echo "The tool '${TARGET_TOOL}' is currently not installed in this repository."
exit 1

1
bin/depotfmt Symbolic link
View file

@ -0,0 +1 @@
__dispatch.sh

View file

@ -59,4 +59,21 @@ self: super: {
mkShell = super.lib.makeOverridable(args: (super.mkShell args) // {
meta.ci = false;
});
# bump treefmt to a newer version that includes our config file patch
treefmt = super.treefmt.overrideAttrs(drv: rec {
version = "0.3.0";
src = super.fetchFromGitHub {
owner = "numtide";
repo = "treefmt";
rev = "v${version}";
sha256 = "0jnfak6wmqpqwymja9bsw54al50yqzdy7lxfx66rqamqsvngqd1x";
};
cargoDeps = drv.cargoDeps.overrideAttrs(_: {
inherit src;
outputHash = "19p15gavcjldn1di7yyn80ys6rj4ajaprqk8x34vxslr4y2qychf";
});
});
}

16
tools/depotfmt.nix Normal file
View file

@ -0,0 +1,16 @@
# Builds treefmt for depot, with a hardcoded configuration that
# includes the right paths to formatters.
{ pkgs, ... }:
let
config = pkgs.writeText "depot-treefmt-config" ''
[formatter.go]
command = "${pkgs.go}/bin/gofmt"
options = [ "-w" ]
includes = ["*.go"]
'';
in pkgs.writeShellScriptBin "depotfmt" ''
exec ${pkgs.treefmt}/bin/treefmt ''${@} \
--config-file ${config} \
--tree-root $(${pkgs.git}/bin/git rev-parse --show-toplevel)
''