Skip to content

Commit b0adb09

Browse files
committedMay 24, 2017
pants13-pre: pre-download the native engine
This saves pants 1.3 from having to download it at startup. Eventually we'll build it ourselves (it's a rust binary) but for now this works.
1 parent 39e042f commit b0adb09

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed
 

‎pkgs/development/tools/build-managers/pants/default.nix

+47-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ stdenv, pythonPackages }:
1+
{ stdenv, pythonPackages, runCommand, curl }:
22

33
with stdenv.lib;
44
with pythonPackages;
@@ -22,6 +22,37 @@ let
2222
maintainers = with maintainers; [ copumpkin ];
2323
};
2424
};
25+
26+
pants13-version = "1.3.0rc2";
27+
28+
# TODO: compile the rust native engine ourselves so we don't need to do this shit. We don't use
29+
# fetchurl because we don't know the URL ahead of time, even though it's deterministic. So we have
30+
# this downloader figure out the URL on the fly and then produce the deterministic result, so we
31+
# can still be a fixed-output derivation.
32+
pants13-native-engine-prefix = {
33+
"x86_64-darwin" = "mac/10.11";
34+
"x86_64-linux" = "linux/x86_64";
35+
"i686-linux" = "linux/i386";
36+
}.${stdenv.system} or (throw "Unsupported system ${stdenv.system}!");
37+
38+
pants13-native-engine = runCommand "pants-native-${pants13-version}" {
39+
buildInputs = [ curl ];
40+
outputHashMode = "recursive";
41+
outputHashAlgo = "sha256";
42+
outputHash = "0n8z7rg0yfpxplvcw88lwv733zkhbzhc4w4zd4aznbcmfqdiz5br";
43+
} ''
44+
native_version=$(curl -k -L https://raw.githubusercontent.com/pantsbuild/pants/release_${pants13-version}/src/python/pants/engine/subsystem/native_engine_version)
45+
curl -kLO "https://dl.bintray.com/pantsbuild/bin/build-support/bin/native-engine/${pants13-native-engine-prefix}/$native_version/native_engine.so"
46+
47+
# Ugh it tries to "download" from this prefix so let's just replicate their directory structure for now...
48+
mkdir -p $out/bin/native-engine/${pants13-native-engine-prefix}/$native_version/
49+
50+
# These should behave the same way in Nix land and we try not to differentiate between OS revisions...
51+
ln -s 10.11 $out/bin/native-engine/mac/10.10
52+
ln -s 10.11 $out/bin/native-engine/mac/10.12
53+
54+
cp native_engine.so $out/bin/native-engine/${pants13-native-engine-prefix}/$native_version/
55+
'';
2556
in {
2657
pants =
2758
pythonPackages.buildPythonPackage rec {
@@ -61,7 +92,7 @@ in {
6192

6293
pants13-pre = buildPythonApplication rec {
6394
pname = "pantsbuild.pants";
64-
version = "1.3.0rc2";
95+
version = pants13-version;
6596
name = "${pname}-${version}";
6697

6798
src = fetchPypi {
@@ -71,6 +102,9 @@ in {
71102

72103
prePatch = ''
73104
sed -E -i "s/'([[:alnum:].-]+)[=><][[:digit:]=><.,]*'/'\\1'/g" setup.py
105+
106+
substituteInPlace src/pants/option/global_options.py \
107+
--replace "'/etc/pantsrc'" "'$out/etc/pantsrc', '/etc/pantsrc'"
74108
'';
75109

76110
# Unnecessary, and causes some really weird behavior around .class files, which
@@ -84,6 +118,17 @@ in {
84118
fasteners coverage pywatchman futures cffi
85119
];
86120

121+
# Teach pants about where its native engine lives.
122+
# TODO: there's probably a better way to teach it this without having it "download"
123+
# from a local file: URL to its cache, but I don't know how and this seems to work.
124+
postFixup = ''
125+
mkdir -p $out/etc
126+
cat >$out/etc/pantsrc <<EOF
127+
[binaries]
128+
baseurls: [ 'file://${pants13-native-engine}' ]
129+
EOF
130+
'';
131+
87132
meta = {
88133
description = "A build system for software projects in a variety of languages";
89134
homepage = "http://www.pantsbuild.org/";

0 commit comments

Comments
 (0)
Please sign in to comment.