tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
lol
0
fork
atom
overview
issues
pulls
pipelines
bazel_7: split tests for clarity
Guillaume Maudoux
2 years ago
d1f60e01
03f458b3
+160
-147
2 changed files
expand all
collapse all
unified
split
pkgs
development
tools
build-managers
bazel
bazel_7
default.nix
tests.nix
+12
-147
pkgs/development/tools/build-managers/bazel/bazel_7/default.nix
···
1
1
{ stdenv
2
2
+
# nix tooling and utilities
2
3
, callPackage
3
4
, lib
4
5
, fetchurl
5
6
, fetchpatch
6
7
, fetchFromGitHub
7
7
-
, installShellFiles
8
8
, runCommand
9
9
, runCommandCC
10
10
, makeWrapper
11
11
, recurseIntoAttrs
12
12
, newScope
13
13
+
, writeTextFile
14
14
+
, autoPatchelfHook
15
15
+
, substituteAll
13
16
# this package (through the fixpoint glass)
14
17
, bazel_self
18
18
+
# native build inputs
19
19
+
, runtimeShell
15
20
, lr
16
21
, xe
17
22
, zip
···
28
33
, findutils
29
34
, diffutils
30
35
, gnupatch
36
36
+
, file
37
37
+
, installShellFiles
31
38
# updater
32
39
, python3
33
40
, writeScript
34
41
# Apple dependencies
35
42
, cctools
36
43
, libcxx
44
44
+
, sigtool
37
45
, CoreFoundation
38
46
, CoreServices
39
47
, Foundation
···
41
49
# Allow to independently override the jdks used to build and run respectively
42
50
, buildJdk
43
51
, runJdk
44
44
-
, runtimeShell
45
52
# Downstream packages for tests
46
53
, bazel-watcher
47
54
# Always assume all markers valid (this is needed because we remove markers; they are non-deterministic).
48
55
# Also, don't clean up environment variables (so that NIX_ environment variables are passed to compilers).
49
56
, enableNixHacks ? false
50
50
-
, gcc-unwrapped
51
51
-
, autoPatchelfHook
52
52
-
, file
53
53
-
, substituteAll
54
54
-
, writeTextFile
55
55
-
, writeText
56
56
-
, darwin
57
57
-
, jdk11_headless
58
58
-
, jdk17_headless
59
59
-
, openjdk8
60
60
-
, ripgrep
61
61
-
, sigtool
62
57
}:
63
58
64
59
let
···
259
254
# nix-build . -A bazel_7.tests
260
255
#
261
256
# in the nixpkgs checkout root to exercise them locally.
262
262
-
passthru.tests =
263
263
-
let
264
264
-
runLocal = name: attrs: script:
265
265
-
let
266
266
-
attrs' = removeAttrs attrs [ "buildInputs" ];
267
267
-
buildInputs = attrs.buildInputs or [ ];
268
268
-
in
269
269
-
runCommandCC name
270
270
-
({
271
271
-
inherit buildInputs;
272
272
-
preferLocalBuild = true;
273
273
-
meta.platforms = platforms;
274
274
-
} // attrs')
275
275
-
script;
276
276
-
277
277
-
# bazel wants to extract itself into $install_dir/install every time it runs,
278
278
-
# so let’s do that only once.
279
279
-
extracted = bazelPkg:
280
280
-
let
281
281
-
install_dir =
282
282
-
# `install_base` field printed by `bazel info`, minus the hash.
283
283
-
# yes, this path is kinda magic. Sorry.
284
284
-
"$HOME/.cache/bazel/_bazel_nixbld";
285
285
-
in
286
286
-
runLocal "bazel-extracted-homedir" { passthru.install_dir = install_dir; } ''
287
287
-
export HOME=$(mktemp -d)
288
288
-
touch WORKSPACE # yeah, everything sucks
289
289
-
install_base="$(${bazelPkg}/bin/bazel info install_base)"
290
290
-
# assert it’s actually below install_dir
291
291
-
[[ "$install_base" =~ ${install_dir} ]] \
292
292
-
|| (echo "oh no! $install_base but we are \
293
293
-
trying to copy ${install_dir} to $out instead!"; exit 1)
294
294
-
cp -R ${install_dir} $out
295
295
-
'';
296
296
-
297
297
-
bazelTest = { name, bazelScript, workspaceDir, bazelPkg, buildInputs ? [ ] }:
298
298
-
let
299
299
-
be = extracted bazelPkg;
300
300
-
in
301
301
-
runLocal name
302
302
-
{
303
303
-
inherit buildInputs;
304
304
-
# Necessary for the tests to pass on Darwin with sandbox enabled.
305
305
-
__darwinAllowLocalNetworking = true;
306
306
-
}
307
307
-
''
308
308
-
# Bazel needs a real home for self-extraction and internal cache
309
309
-
export HOME=$(mktemp -d)
310
310
-
311
311
-
${# Concurrent bazel invocations have the same workspace path.
312
312
-
# On darwin, for some reason, it means they access and corrupt the same execroot.
313
313
-
# Having a different workspace path ensures we use different execroots.
314
314
-
# A different user seems to be enough for a different bazel cache root.
315
315
-
lib.optionalString isDarwin ''
316
316
-
export USER=$(basename $HOME)
317
317
-
# cd $(mktemp --tmpdir=. -d)
318
318
-
''
319
319
-
}
320
320
-
${# Speed-up tests by caching bazel extraction.
321
321
-
# Except on Darwin, because nobody knows how Darwin works.
322
322
-
lib.optionalString (!isDarwin) ''
323
323
-
mkdir -p ${be.install_dir}
324
324
-
cp -R ${be}/install ${be.install_dir}
325
325
-
326
326
-
# https://stackoverflow.com/questions/47775668/bazel-how-to-skip-corrupt-installation-on-centos6
327
327
-
# Bazel checks whether the mtime of the install dir files
328
328
-
# is >9 years in the future, otherwise it extracts itself again.
329
329
-
# see PosixFileMTime::IsUntampered in src/main/cpp/util
330
330
-
# What the hell bazel.
331
331
-
${lr}/bin/lr -0 -U ${be.install_dir} | ${xe}/bin/xe -N0 -0 touch --date="9 years 6 months" {}
332
332
-
''
333
333
-
}
334
334
-
${# Note https://github.com/bazelbuild/bazel/issues/5763#issuecomment-456374609
335
335
-
# about why to create a subdir for the workspace.
336
336
-
'' cp -r ${workspaceDir} wd && chmod u+w wd && cd wd ''
337
337
-
}
338
338
-
${# run the actual test snippet
339
339
-
bazelScript
340
340
-
}
341
341
-
${# Try to keep darwin clean of our garbage
342
342
-
lib.optionalString isDarwin ''
343
343
-
rm -rf $HOME || true
344
344
-
''
345
345
-
}
346
346
-
347
347
-
touch $out
348
348
-
'';
349
349
-
350
350
-
bazel-examples = fetchFromGitHub {
351
351
-
owner = "bazelbuild";
352
352
-
repo = "examples";
353
353
-
rev = "93564e1f1e7a3c39d6a94acee12b8d7b74de3491";
354
354
-
hash = "sha256-DaPKp7Sn5uvfZRjdDx6grot3g3B7trqCyL0TRIdwg98=";
355
355
-
};
356
356
-
357
357
-
callBazelTest = newScope {
358
358
-
inherit runLocal bazelTest bazel-examples distDir;
359
359
-
inherit Foundation;
360
360
-
extraBazelArgs = ''
361
361
-
--repository_cache=${repoCache} \
362
362
-
--repo_env=JAVA_HOME=${runJdk}${if isDarwin then "/zulu-17.jdk/Contents/Home" else "/lib/openjdk"} \
363
363
-
'';
364
364
-
bazel = bazel_self;
365
365
-
};
366
366
-
367
367
-
bazelWithNixHacks = bazel_self.override { enableNixHacks = true; };
368
368
-
369
369
-
in
370
370
-
(lib.optionalAttrs (!stdenv.hostPlatform.isDarwin) {
371
371
-
# `extracted` doesn’t work on darwin
372
372
-
shebang = callBazelTest ../shebang-test.nix { inherit extracted; };
373
373
-
}) // {
374
374
-
bashTools = callBazelTest ../bash-tools-test.nix { };
375
375
-
cpp = callBazelTest ../cpp-test.nix { };
376
376
-
java = callBazelTest ../java-test.nix { };
377
377
-
# TODO: protobuf tests just fail for now.
378
378
-
#protobuf = callBazelTest ../protobuf-test.nix { };
379
379
-
pythonBinPath = callBazelTest ../python-bin-path-test.nix { };
380
380
-
381
381
-
bashToolsWithNixHacks = callBazelTest ../bash-tools-test.nix { bazel = bazelWithNixHacks; };
382
382
-
383
383
-
cppWithNixHacks = callBazelTest ../cpp-test.nix { bazel = bazelWithNixHacks; };
384
384
-
javaWithNixHacks = callBazelTest ../java-test.nix { bazel = bazelWithNixHacks; };
385
385
-
#protobufWithNixHacks = callBazelTest ../protobuf-test.nix { bazel = bazelWithNixHacks; };
386
386
-
pythonBinPathWithNixHacks = callBazelTest ../python-bin-path-test.nix { bazel = bazelWithNixHacks; };
387
387
-
388
388
-
# downstream packages using buildBazelPackage
389
389
-
# fixed-output hashes of the fetch phase need to be spot-checked manually
390
390
-
# TODO
391
391
-
#downstream = recurseIntoAttrs ({
392
392
-
# inherit bazel-watcher;
393
393
-
#});
394
394
-
};
257
257
+
passthru.tests = callPackage ./tests.nix {
258
258
+
inherit Foundation bazel_self distDir repoCache runJdk;
259
259
+
};
395
260
396
261
src_for_updater = stdenv.mkDerivation rec {
397
262
name = "updater-sources";
+148
pkgs/development/tools/build-managers/bazel/bazel_7/tests.nix
···
1
1
+
{ lib
2
2
+
# tooling
3
3
+
, fetchFromGitHub
4
4
+
, newScope
5
5
+
, runCommandCC
6
6
+
, stdenv
7
7
+
# inputs
8
8
+
, Foundation
9
9
+
, bazel_self
10
10
+
, distDir
11
11
+
, lr
12
12
+
, repoCache
13
13
+
, runJdk
14
14
+
, xe
15
15
+
}:
16
16
+
let
17
17
+
inherit (stdenv.hostPlatform) isDarwin;
18
18
+
19
19
+
runLocal = name: attrs: script:
20
20
+
let
21
21
+
attrs' = removeAttrs attrs [ "buildInputs" ];
22
22
+
buildInputs = attrs.buildInputs or [ ];
23
23
+
in
24
24
+
runCommandCC name
25
25
+
({
26
26
+
inherit buildInputs;
27
27
+
preferLocalBuild = true;
28
28
+
meta.platforms = bazel_self.meta.platforms;
29
29
+
} // attrs')
30
30
+
script;
31
31
+
32
32
+
# bazel wants to extract itself into $install_dir/install every time it runs,
33
33
+
# so let’s do that only once.
34
34
+
extracted = bazelPkg:
35
35
+
let
36
36
+
install_dir =
37
37
+
# `install_base` field printed by `bazel info`, minus the hash.
38
38
+
# yes, this path is kinda magic. Sorry.
39
39
+
"$HOME/.cache/bazel/_bazel_nixbld";
40
40
+
in
41
41
+
runLocal "bazel-extracted-homedir" { passthru.install_dir = install_dir; } ''
42
42
+
export HOME=$(mktemp -d)
43
43
+
touch WORKSPACE # yeah, everything sucks
44
44
+
install_base="$(${bazelPkg}/bin/bazel info install_base)"
45
45
+
# assert it’s actually below install_dir
46
46
+
[[ "$install_base" =~ ${install_dir} ]] \
47
47
+
|| (echo "oh no! $install_base but we are \
48
48
+
trying to copy ${install_dir} to $out instead!"; exit 1)
49
49
+
cp -R ${install_dir} $out
50
50
+
'';
51
51
+
52
52
+
bazelTest = { name, bazelScript, workspaceDir, bazelPkg, buildInputs ? [ ] }:
53
53
+
runLocal name
54
54
+
{
55
55
+
inherit buildInputs;
56
56
+
# Necessary for the tests to pass on Darwin with sandbox enabled.
57
57
+
__darwinAllowLocalNetworking = true;
58
58
+
}
59
59
+
''
60
60
+
# Bazel needs a real home for self-extraction and internal cache
61
61
+
export HOME=$(mktemp -d)
62
62
+
63
63
+
${# Concurrent bazel invocations have the same workspace path.
64
64
+
# On darwin, for some reason, it means they access and corrupt the same execroot.
65
65
+
# Having a different workspace path ensures we use different execroots.
66
66
+
# A different user seems to be enough for a different bazel cache root.
67
67
+
lib.optionalString isDarwin ''
68
68
+
export USER=$(basename $HOME)
69
69
+
# cd $(mktemp --tmpdir=. -d)
70
70
+
''
71
71
+
}
72
72
+
${# Speed-up tests by caching bazel extraction.
73
73
+
# Except on Darwin, because nobody knows how Darwin works.
74
74
+
let bazelExtracted = extracted bazelPkg;
75
75
+
in lib.optionalString (!isDarwin) ''
76
76
+
mkdir -p ${bazelExtracted.install_dir}
77
77
+
cp -R ${bazelExtracted}/install ${bazelExtracted.install_dir}
78
78
+
79
79
+
# https://stackoverflow.com/questions/47775668/bazel-how-to-skip-corrupt-installation-on-centos6
80
80
+
# Bazel checks whether the mtime of the install dir files
81
81
+
# is >9 years in the future, otherwise it extracts itself again.
82
82
+
# see PosixFileMTime::IsUntampered in src/main/cpp/util
83
83
+
# What the hell bazel.
84
84
+
${lr}/bin/lr -0 -U ${bazelExtracted.install_dir} | ${xe}/bin/xe -N0 -0 touch --date="9 years 6 months" {}
85
85
+
''
86
86
+
}
87
87
+
${# Note https://github.com/bazelbuild/bazel/issues/5763#issuecomment-456374609
88
88
+
# about why to create a subdir for the workspace.
89
89
+
'' cp -r ${workspaceDir} wd && chmod u+w wd && cd wd ''
90
90
+
}
91
91
+
${# run the actual test snippet
92
92
+
bazelScript
93
93
+
}
94
94
+
${# Try to keep darwin clean of our garbage
95
95
+
lib.optionalString isDarwin ''
96
96
+
rm -rf $HOME || true
97
97
+
''
98
98
+
}
99
99
+
100
100
+
touch $out
101
101
+
'';
102
102
+
103
103
+
bazel-examples = fetchFromGitHub {
104
104
+
owner = "bazelbuild";
105
105
+
repo = "examples";
106
106
+
rev = "93564e1f1e7a3c39d6a94acee12b8d7b74de3491";
107
107
+
hash = "sha256-DaPKp7Sn5uvfZRjdDx6grot3g3B7trqCyL0TRIdwg98=";
108
108
+
};
109
109
+
110
110
+
callBazelTest = newScope {
111
111
+
inherit runLocal bazelTest bazel-examples distDir;
112
112
+
inherit Foundation;
113
113
+
extraBazelArgs = ''
114
114
+
--repository_cache=${repoCache} \
115
115
+
--repo_env=JAVA_HOME=${runJdk}${if isDarwin then "/zulu-17.jdk/Contents/Home" else "/lib/openjdk"} \
116
116
+
'';
117
117
+
bazel = bazel_self;
118
118
+
};
119
119
+
120
120
+
bazelWithNixHacks = bazel_self.override { enableNixHacks = true; };
121
121
+
122
122
+
in
123
123
+
(lib.optionalAttrs (!stdenv.hostPlatform.isDarwin) {
124
124
+
# `extracted` doesn’t work on darwin
125
125
+
shebang = callBazelTest ../shebang-test.nix { inherit extracted; };
126
126
+
}) // {
127
127
+
bashTools = callBazelTest ../bash-tools-test.nix { };
128
128
+
cpp = callBazelTest ../cpp-test.nix { };
129
129
+
java = callBazelTest ../java-test.nix { };
130
130
+
# TODO: protobuf tests just fail for now.
131
131
+
#protobuf = callBazelTest ../protobuf-test.nix { };
132
132
+
pythonBinPath = callBazelTest ../python-bin-path-test.nix { };
133
133
+
134
134
+
bashToolsWithNixHacks = callBazelTest ../bash-tools-test.nix { bazel = bazelWithNixHacks; };
135
135
+
136
136
+
cppWithNixHacks = callBazelTest ../cpp-test.nix { bazel = bazelWithNixHacks; };
137
137
+
javaWithNixHacks = callBazelTest ../java-test.nix { bazel = bazelWithNixHacks; };
138
138
+
#protobufWithNixHacks = callBazelTest ../protobuf-test.nix { bazel = bazelWithNixHacks; };
139
139
+
pythonBinPathWithNixHacks = callBazelTest ../python-bin-path-test.nix { bazel = bazelWithNixHacks; };
140
140
+
141
141
+
# downstream packages using buildBazelPackage
142
142
+
# fixed-output hashes of the fetch phase need to be spot-checked manually
143
143
+
# TODO
144
144
+
#downstream = recurseIntoAttrs ({
145
145
+
# inherit bazel-watcher;
146
146
+
#});
147
147
+
}
148
148
+