nixpkgs/pkgs/development/tools/bazel-watcher/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

111 lines
3.6 KiB
Nix
Raw Normal View History

2018-09-11 05:36:11 +00:00
{ buildBazelPackage
2022-07-05 15:54:40 +00:00
, bazel_5
2018-09-11 05:36:11 +00:00
, fetchFromGitHub
, git
, go
2021-03-25 09:36:54 +00:00
, python3
, lib, stdenv
2018-09-11 05:36:11 +00:00
}:
let
patches = [
./use-go-in-path.patch
];
# Patch the protoc alias so that it always builds from source.
rulesProto = fetchFromGitHub {
owner = "bazelbuild";
repo = "rules_proto";
2024-01-09 20:09:53 +00:00
rev = "4.0.0";
hash = "sha256-WVPZx14thneAC4PdiDhBibnPwlCKEF9c93CHR0t1Efo=";
postFetch = ''
sed -i 's|name = "protoc"|name = "_protoc_original"|' $out/proto/private/BUILD.release
cat <<EOF >>$out/proto/private/BUILD.release
alias(name = "protoc", actual = "@com_github_protocolbuffers_protobuf//:protoc", visibility = ["//visibility:public"])
EOF
'';
};
in
2018-09-11 05:36:11 +00:00
buildBazelPackage rec {
2022-02-01 22:01:51 +00:00
pname = "bazel-watcher";
2024-01-09 20:09:53 +00:00
version = "0.24.0";
2018-09-11 05:36:11 +00:00
src = fetchFromGitHub {
owner = "bazelbuild";
repo = "bazel-watcher";
rev = "v${version}";
2024-01-09 20:09:53 +00:00
hash = "sha256-ebNHAYKyE3226KiCc2/VSz1OSITuPwuYlAIS3JrWzj0=";
2018-09-11 05:36:11 +00:00
};
2021-03-25 09:36:54 +00:00
nativeBuildInputs = [ go git python3 ];
removeRulesCC = false;
2018-09-11 05:36:11 +00:00
2022-07-05 15:54:40 +00:00
bazel = bazel_5;
bazelFlags = [ "--override_repository=rules_proto=${rulesProto}" ];
2022-07-05 15:55:06 +00:00
bazelBuildFlags = lib.optionals stdenv.cc.isClang [ "--cxxopt=-x" "--cxxopt=c++" "--host_cxxopt=-x" "--host_cxxopt=c++" ];
bazelTargets = [ "//cmd/ibazel" ];
2018-09-11 05:36:11 +00:00
fetchConfigured = false; # we want to fetch all dependencies, regardless of the current system
2018-09-11 05:36:11 +00:00
fetchAttrs = {
inherit patches;
2018-09-11 05:36:11 +00:00
preBuild = ''
patchShebangs .
2022-07-05 15:54:40 +00:00
echo ${bazel_5.version} > .bazelversion
2018-09-11 05:36:11 +00:00
'';
preInstall = ''
# Remove the go_sdk (it's just a copy of the go derivation) and all
# references to it from the marker files. Bazel does not need to download
# this sdk because we have patched the WORKSPACE file to point to the one
# currently present in PATH. Without removing the go_sdk from the marker
# file, the hash of it will change anytime the Go derivation changes and
# that would lead to impurities in the marker files which would result in
2024-01-09 20:09:53 +00:00
# a different hash for the fetch phase.
2018-09-11 05:36:11 +00:00
rm -rf $bazelOut/external/{go_sdk,\@go_sdk.marker}
sed -e '/^FILE:@go_sdk.*/d' -i $bazelOut/external/\@*.marker
2018-12-08 08:34:12 +00:00
# Retains go build input markers
chmod -R 755 $bazelOut/external/{bazel_gazelle_go_repository_cache,@\bazel_gazelle_go_repository_cache.marker}
rm -rf $bazelOut/external/{bazel_gazelle_go_repository_cache,@\bazel_gazelle_go_repository_cache.marker}
2018-12-08 08:34:12 +00:00
# Remove the gazelle tools, they contain go binaries that are built
# non-deterministically. As long as the gazelle version matches the tools
# should be equivalent.
rm -rf $bazelOut/external/{bazel_gazelle_go_repository_tools,\@bazel_gazelle_go_repository_tools.marker}
sed -e '/^FILE:@bazel_gazelle_go_repository_tools.*/d' -i $bazelOut/external/\@*.marker
# remove com_google_protobuf because it had files with different permissions on linux and darwin
rm -rf $bazelOut/external/com_google_protobuf
2018-09-11 05:36:11 +00:00
'';
2024-01-09 20:09:53 +00:00
sha256 = "sha256-B2KVD/FmkAa7MNhLaH286gF3uA20qjN3CoA83KRB9E8=";
2018-09-11 05:36:11 +00:00
};
buildAttrs = {
inherit patches;
2018-09-11 05:36:11 +00:00
preBuild = ''
patchShebangs .
2023-01-10 11:03:42 +00:00
substituteInPlace cmd/ibazel/BUILD.bazel --replace '{STABLE_GIT_VERSION}' ${version}
2022-07-05 15:54:40 +00:00
echo ${bazel_5.version} > .bazelversion
2018-09-11 05:36:11 +00:00
'';
installPhase = ''
2023-01-10 11:03:42 +00:00
install -Dm755 bazel-bin/cmd/ibazel/ibazel_/ibazel $out/bin/ibazel
2018-09-11 05:36:11 +00:00
'';
};
meta = with lib; {
homepage = "https://github.com/bazelbuild/bazel-watcher";
description = "Tools for building Bazel targets when source files change";
2018-09-11 05:36:11 +00:00
license = licenses.asl20;
maintainers = with maintainers; [ kalbasit ];
mainProgram = "ibazel";
2018-09-11 05:36:11 +00:00
platforms = platforms.all;
};
}