1{
2 bazel,
3 bazelTest,
4 stdenv,
5 cctools,
6 extraBazelArgs ? "",
7 lib,
8 runLocal,
9 runtimeShell,
10 writeScript,
11 writeText,
12 distDir,
13}:
14
15let
16 toolsBazel = writeScript "bazel" ''
17 #! ${runtimeShell}
18
19 export CXX='${stdenv.cc}/bin/clang++'
20 export LD='${cctools}/bin/ld'
21 export LIBTOOL='${cctools}/bin/libtool'
22 export CC='${stdenv.cc}/bin/clang'
23
24 # XXX: hack for macosX, this flags disable bazel usage of xcode
25 # See: https://github.com/bazelbuild/bazel/issues/4231
26 export BAZEL_USE_CPP_ONLY_TOOLCHAIN=1
27
28 exec "$BAZEL_REAL" "$@"
29 '';
30
31 WORKSPACE = writeText "WORKSPACE" ''
32 workspace(name = "our_workspace")
33 '';
34
35 pythonLib = writeText "lib.py" ''
36 def foo():
37 return 43
38 '';
39
40 pythonBin = writeText "bin.py" ''
41 from lib import foo
42
43 assert foo() == 43
44 '';
45
46 pythonBUILD = writeText "BUILD" ''
47 py_library(
48 name = "lib",
49 srcs = [ "lib.py" ],
50 )
51
52 py_binary(
53 name = "bin",
54 srcs = [ "bin.py" ],
55 imports = [ "." ],
56 deps = [ ":lib" ],
57 )
58 '';
59
60 workspaceDir = runLocal "our_workspace" { } (
61 ''
62 mkdir $out
63 cp ${WORKSPACE} $out/WORKSPACE
64 mkdir $out/python
65 cp ${pythonLib} $out/python/lib.py
66 cp ${pythonBin} $out/python/bin.py
67 cp ${pythonBUILD} $out/python/BUILD.bazel
68 ''
69 + (lib.optionalString stdenv.hostPlatform.isDarwin ''
70 mkdir $out/tools
71 cp ${toolsBazel} $out/tools/bazel
72 '')
73 );
74
75 testBazel = bazelTest {
76 name = "${bazel.pname}-test-builtin-rules";
77 inherit workspaceDir;
78 bazelPkg = bazel;
79 bazelScript = ''
80 ${bazel}/bin/bazel \
81 run \
82 --distdir=${distDir} \
83 ${extraBazelArgs} \
84 //python:bin
85 '';
86 };
87
88in
89testBazel