2020-04-24 23:36:52 +00:00
|
|
|
{ buildBazelPackage
|
2022-08-12 12:06:08 +00:00
|
|
|
, bazel_5
|
2020-04-24 23:36:52 +00:00
|
|
|
, fetchFromGitHub
|
|
|
|
, git
|
|
|
|
, go
|
2021-03-20 04:20:00 +00:00
|
|
|
, python3
|
2021-02-05 17:12:51 +00:00
|
|
|
, lib, stdenv
|
2020-04-24 23:36:52 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
patches = [
|
|
|
|
./use-go-in-path.patch
|
2023-01-20 10:41:00 +00:00
|
|
|
./fix-rules-go-3408.patch
|
2020-04-24 23:36:52 +00:00
|
|
|
];
|
2022-08-12 12:06:08 +00:00
|
|
|
|
|
|
|
# Patch the protoc alias so that it always builds from source.
|
|
|
|
rulesProto = fetchFromGitHub {
|
|
|
|
owner = "bazelbuild";
|
|
|
|
repo = "rules_proto";
|
|
|
|
rev = "4.0.0-3.19.2";
|
|
|
|
sha256 = "sha256-wdmp+Tmf63PPr7G4X5F7rDas45WEETU3eKb47PFVI6o=";
|
|
|
|
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
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
in
|
|
|
|
buildBazelPackage rec {
|
2022-02-10 20:34:41 +00:00
|
|
|
pname = "bazel-watcher";
|
2023-01-20 10:41:00 +00:00
|
|
|
version = "0.21.2";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "bazelbuild";
|
|
|
|
repo = "bazel-watcher";
|
|
|
|
rev = "v${version}";
|
2023-01-20 10:41:00 +00:00
|
|
|
sha256 = "sha256-wigrE9u1VuFnqLWyVJK3M7xsjyme2dDG6YTcD9whKnw=";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2021-03-20 04:20:00 +00:00
|
|
|
nativeBuildInputs = [ go git python3 ];
|
2020-05-03 17:38:23 +00:00
|
|
|
removeRulesCC = false;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
bazel = bazel_5;
|
|
|
|
bazelFlags = [ "--override_repository=rules_proto=${rulesProto}" ];
|
|
|
|
bazelBuildFlags = lib.optionals stdenv.cc.isClang [ "--cxxopt=-x" "--cxxopt=c++" "--host_cxxopt=-x" "--host_cxxopt=c++" ];
|
2023-01-20 10:41:00 +00:00
|
|
|
bazelTarget = "//cmd/ibazel";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
fetchConfigured = false; # we want to fetch all dependencies, regardless of the current system
|
2020-04-24 23:36:52 +00:00
|
|
|
fetchAttrs = {
|
|
|
|
inherit patches;
|
|
|
|
|
|
|
|
preBuild = ''
|
|
|
|
patchShebangs .
|
2022-08-12 12:06:08 +00:00
|
|
|
|
|
|
|
echo ${bazel_5.version} > .bazelversion
|
2020-04-24 23:36:52 +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
|
|
|
|
# a different sha256 for the fetch phase.
|
|
|
|
rm -rf $bazelOut/external/{go_sdk,\@go_sdk.marker}
|
|
|
|
sed -e '/^FILE:@go_sdk.*/d' -i $bazelOut/external/\@*.marker
|
|
|
|
|
2020-05-03 17:38:23 +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}
|
|
|
|
|
2020-04-24 23:36:52 +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
|
2022-08-12 12:06:08 +00:00
|
|
|
|
|
|
|
# remove com_google_protobuf because it had files with different permissions on linux and darwin
|
|
|
|
rm -rf $bazelOut/external/com_google_protobuf
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
2023-01-20 10:41:00 +00:00
|
|
|
sha256 = "sha256-le8IepS+IGVX45Gj1aicPjYOkuUA+VVUy/PEeKLNYss=";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
buildAttrs = {
|
|
|
|
inherit patches;
|
|
|
|
|
|
|
|
preBuild = ''
|
|
|
|
patchShebangs .
|
2020-12-09 12:39:15 +00:00
|
|
|
|
2023-01-20 10:41:00 +00:00
|
|
|
substituteInPlace cmd/ibazel/BUILD.bazel --replace '{STABLE_GIT_VERSION}' ${version}
|
2022-08-12 12:06:08 +00:00
|
|
|
echo ${bazel_5.version} > .bazelversion
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
2023-01-20 10:41:00 +00:00
|
|
|
install -Dm755 bazel-bin/cmd/ibazel/ibazel_/ibazel $out/bin/ibazel
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
meta = with lib; {
|
2020-04-24 23:36:52 +00:00
|
|
|
homepage = "https://github.com/bazelbuild/bazel-watcher";
|
2020-10-19 00:13:06 +00:00
|
|
|
description = "Tools for building Bazel targets when source files change";
|
2020-04-24 23:36:52 +00:00
|
|
|
license = licenses.asl20;
|
|
|
|
maintainers = with maintainers; [ kalbasit ];
|
2022-08-12 12:06:08 +00:00
|
|
|
mainProgram = "ibazel";
|
2020-04-24 23:36:52 +00:00
|
|
|
platforms = platforms.all;
|
|
|
|
};
|
|
|
|
}
|