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