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 deps = [ ":lib" ],
55 )
56 '';
57
58 workspaceDir = runLocal "our_workspace" {} (''
59 mkdir $out
60 cp ${WORKSPACE} $out/WORKSPACE
61 mkdir $out/python
62 cp ${pythonLib} $out/python/lib.py
63 cp ${pythonBin} $out/python/bin.py
64 cp ${pythonBUILD} $out/python/BUILD.bazel
65 ''
66 + (lib.optionalString stdenv.isDarwin ''
67 mkdir $out/tools
68 cp ${toolsBazel} $out/tools/bazel
69 ''));
70
71 testBazel = bazelTest {
72 name = "bazel-test-builtin-rules";
73 inherit workspaceDir;
74 bazelPkg = bazel;
75 bazelScript = ''
76 ${bazel}/bin/bazel \
77 run \
78 --distdir=${distDir} \
79 //python:bin
80 '';
81 };
82
83in testBazel