Skip to content

Commit 77f1397

Browse files
authored
build: avoid race condition on install (xapi-project#6446)
We had various builds fail with: ``` cp: cannot create directory 'autogen-out/include': File exists ``` This is likely a race condition between `cp -r` and the other command both trying to create that directory (and `cp -r` not handling the race condition correctly, i.e. a TOCTOU bug in `cp -r`). Work this around by running the 2 command in sequence: then even if they both try to create the 'include' directory there won't be any race.
2 parents b575fde + 2f26381 commit 77f1397

File tree

12 files changed

+211
-291
lines changed

12 files changed

+211
-291
lines changed

ocaml/sdk-gen/c/autogen/dune

+13-19
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
(rule
2-
(targets COPYING)
3-
(deps
4-
../../LICENSE
5-
)
6-
(action (copy %{deps} %{targets}))
7-
)
2+
(targets COPYING)
3+
(deps ../../LICENSE)
4+
(action
5+
(copy %{deps} %{targets})))
86

97
(rule
10-
(targets README)
11-
(deps
12-
../README.dist
13-
)
14-
(action (copy %{deps} %{targets}))
15-
)
8+
(targets README)
9+
(deps ../README.dist)
10+
(action
11+
(copy %{deps} %{targets})))
1612

1713
(alias
18-
(name generate)
19-
(deps
20-
COPYING
21-
README
22-
(source_tree .)
23-
)
24-
)
14+
(name generate)
15+
(deps
16+
COPYING
17+
README
18+
(source_tree .)))
2519

2620
(data_only_dirs src include)

ocaml/sdk-gen/c/dune

+19-27
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,26 @@
11
(executable
2-
(modes exe)
3-
(name gen_c_binding)
4-
(libraries
5-
astring
6-
CommonFunctions
7-
8-
mustache
9-
xapi-datamodel
10-
)
11-
)
2+
(modes exe)
3+
(name gen_c_binding)
4+
(libraries astring CommonFunctions mustache xapi-datamodel))
125

136
(rule
14-
(alias generate)
15-
(package xapi-sdk)
16-
(targets (dir autogen-out))
17-
(deps
18-
(:x gen_c_binding.exe)
19-
(source_tree templates)
20-
(source_tree autogen)
21-
)
22-
(action (concurrent
23-
(bash "cp -r autogen/ autogen-out/")
24-
(run %{x})
25-
))
26-
)
7+
(alias generate)
8+
(package xapi-sdk)
9+
(targets
10+
(dir autogen-out))
11+
(deps
12+
(:x gen_c_binding.exe)
13+
(source_tree templates)
14+
(source_tree autogen))
15+
(action
16+
(progn
17+
(bash "cp -r autogen/ autogen-out/")
18+
(run %{x}))))
2719

2820
(data_only_dirs templates)
2921

3022
(install
31-
(package xapi-sdk)
32-
(section share_root)
33-
(dirs (autogen-out as c))
34-
)
23+
(package xapi-sdk)
24+
(section share_root)
25+
(dirs
26+
(autogen-out as c)))

ocaml/sdk-gen/common/dune

+5-13
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
(library
2-
(name CommonFunctions)
3-
(modes best)
4-
(wrapped false)
5-
(libraries
6-
astring
7-
xapi-datamodel
8-
mustache
9-
xapi-stdext-std
10-
xapi-stdext-unix
11-
)
12-
(modules_without_implementation license)
13-
)
14-
2+
(name CommonFunctions)
3+
(modes best)
4+
(wrapped false)
5+
(libraries astring xapi-datamodel mustache xapi-stdext-std xapi-stdext-unix)
6+
(modules_without_implementation license))

ocaml/sdk-gen/csharp/autogen/dune

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
(rule
2-
(alias generate)
3-
(targets LICENSE)
4-
(deps
5-
../../LICENSE
6-
)
7-
(action (copy %{deps} %{targets}))
8-
)
2+
(alias generate)
3+
(targets LICENSE)
4+
(deps ../../LICENSE)
5+
(action
6+
(copy %{deps} %{targets})))
97

108
(data_only_dirs src)
11-

ocaml/sdk-gen/csharp/dune

+32-51
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,41 @@
11
(executable
2-
(modes exe)
3-
(name gen_csharp_binding)
4-
(modules Gen_csharp_binding)
5-
(libraries
6-
astring
7-
CommonFunctions
8-
9-
mustache
10-
xapi-consts
11-
xapi-datamodel
12-
)
13-
)
2+
(modes exe)
3+
(name gen_csharp_binding)
4+
(modules Gen_csharp_binding)
5+
(libraries astring CommonFunctions mustache xapi-consts xapi-datamodel))
146

157
(executable
16-
(modes exe)
17-
(name friendly_error_names)
18-
(modules Friendly_error_names)
19-
(libraries
20-
CommonFunctions
21-
22-
mustache
23-
xapi-datamodel
24-
xmllight2
25-
str
26-
)
27-
)
8+
(modes exe)
9+
(name friendly_error_names)
10+
(modules Friendly_error_names)
11+
(libraries CommonFunctions mustache xapi-datamodel xmllight2 str))
2812

2913
(rule
30-
(alias generate)
31-
(targets (dir autogen-out))
32-
(deps
33-
(:x gen_csharp_binding.exe)
34-
(source_tree templates)
35-
(:sh ../windows-line-endings.sh)
36-
(source_tree autogen)
37-
(:x2 friendly_error_names.exe)
38-
FriendlyErrorNames.resx
39-
(:y XE_SR_ERRORCODES.xml)
40-
(source_tree templates)
41-
)
42-
(action
43-
(progn
44-
(concurrent
45-
(bash "cp -r autogen/ autogen-out/")
46-
(run %{x})
47-
(run %{x2} -s %{y})
48-
)
49-
(bash "rm autogen-out/.gitignore")
50-
(bash "%{sh} autogen-out/")
51-
))
52-
)
14+
(alias generate)
15+
(targets
16+
(dir autogen-out))
17+
(deps
18+
(:x gen_csharp_binding.exe)
19+
(source_tree templates)
20+
(:sh ../windows-line-endings.sh)
21+
(source_tree autogen)
22+
(:x2 friendly_error_names.exe)
23+
FriendlyErrorNames.resx
24+
(:y XE_SR_ERRORCODES.xml)
25+
(source_tree templates))
26+
(action
27+
(progn
28+
(progn
29+
(bash "cp -r autogen/ autogen-out/")
30+
(run %{x})
31+
(run %{x2} -s %{y}))
32+
(bash "rm autogen-out/.gitignore")
33+
(bash "%{sh} autogen-out/"))))
5334

5435
(data_only_dirs templates)
5536

5637
(install
57-
(package xapi-sdk)
58-
(section share_root)
59-
(dirs (autogen-out as csharp))
60-
)
38+
(package xapi-sdk)
39+
(section share_root)
40+
(dirs
41+
(autogen-out as csharp)))

ocaml/sdk-gen/dune

+13-15
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
(data_only_dirs component-test)
22

33
(alias
4-
(name sdkgen)
5-
(package xapi-sdk)
6-
(deps
7-
c/gen_c_binding.exe
8-
csharp/gen_csharp_binding.exe
9-
java/main.exe
10-
powershell/gen_powershell_binding.exe
11-
go/gen_go_binding.exe
12-
(alias_rec c/generate)
13-
(alias_rec csharp/generate)
14-
(alias_rec java/generate)
15-
(alias_rec powershell/generate)
16-
(alias_rec go/generate)
17-
)
18-
)
4+
(name sdkgen)
5+
(package xapi-sdk)
6+
(deps
7+
c/gen_c_binding.exe
8+
csharp/gen_csharp_binding.exe
9+
java/main.exe
10+
powershell/gen_powershell_binding.exe
11+
go/gen_go_binding.exe
12+
(alias_rec c/generate)
13+
(alias_rec csharp/generate)
14+
(alias_rec java/generate)
15+
(alias_rec powershell/generate)
16+
(alias_rec go/generate)))

ocaml/sdk-gen/go/autogen/dune

+13-19
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
(rule
2-
(targets LICENSE)
3-
(deps
4-
../../LICENSE
5-
)
6-
(action (copy %{deps} %{targets}))
7-
)
2+
(targets LICENSE)
3+
(deps ../../LICENSE)
4+
(action
5+
(copy %{deps} %{targets})))
86

97
(rule
10-
(targets README)
11-
(deps
12-
../README.md
13-
)
14-
(action (copy %{deps} %{targets}))
15-
)
8+
(targets README)
9+
(deps ../README.md)
10+
(action
11+
(copy %{deps} %{targets})))
1612

1713
(alias
18-
(name generate)
19-
(deps
20-
LICENSE
21-
README
22-
(source_tree .)
23-
)
24-
)
14+
(name generate)
15+
(deps
16+
LICENSE
17+
README
18+
(source_tree .)))
2519

2620
(data_only_dirs src)

ocaml/sdk-gen/go/dune

+42-50
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,52 @@
11
(executable
2-
(modes exe)
3-
(name gen_go_binding)
4-
(modules gen_go_binding)
5-
(libraries
6-
CommonFunctions
7-
mustache
8-
xapi-datamodel
9-
xapi-stdext-unix
10-
gen_go_helper
11-
)
12-
)
2+
(modes exe)
3+
(name gen_go_binding)
4+
(modules gen_go_binding)
5+
(libraries
6+
CommonFunctions
7+
mustache
8+
xapi-datamodel
9+
xapi-stdext-unix
10+
gen_go_helper))
1311

1412
(library
15-
(name gen_go_helper)
16-
(modules gen_go_helper)
17-
(modes best)
18-
(libraries
19-
CommonFunctions
20-
astring
21-
(re_export mustache)
22-
(re_export xapi-consts)
23-
(re_export xapi-datamodel)
24-
xapi-stdext-std
25-
)
26-
)
13+
(name gen_go_helper)
14+
(modules gen_go_helper)
15+
(modes best)
16+
(libraries
17+
CommonFunctions
18+
astring
19+
(re_export mustache)
20+
(re_export xapi-consts)
21+
(re_export xapi-datamodel)
22+
xapi-stdext-std))
2723

2824
(rule
29-
(alias generate)
30-
(targets (dir autogen-out))
31-
(deps
32-
(:x gen_go_binding.exe)
33-
(source_tree templates)
34-
(source_tree autogen)
35-
)
36-
(action
37-
(concurrent
38-
(bash "cp -r autogen/ autogen-out/")
39-
(run %{x} --destdir autogen-out)
40-
)
41-
)
42-
)
25+
(alias generate)
26+
(targets
27+
(dir autogen-out))
28+
(deps
29+
(:x gen_go_binding.exe)
30+
(source_tree templates)
31+
(source_tree autogen))
32+
(action
33+
(progn
34+
(bash "cp -r autogen/ autogen-out/")
35+
(run %{x} --destdir autogen-out))))
4336

4437
(test
45-
(name test_gen_go)
46-
(package xapi-sdk)
47-
(modules test_gen_go)
48-
(libraries CommonFunctions alcotest fmt xapi-test-utils gen_go_helper)
49-
(deps
50-
(source_tree test_data)
51-
(source_tree templates)
52-
)
53-
)
38+
(name test_gen_go)
39+
(package xapi-sdk)
40+
(modules test_gen_go)
41+
(libraries CommonFunctions alcotest fmt xapi-test-utils gen_go_helper)
42+
(deps
43+
(source_tree test_data)
44+
(source_tree templates)))
5445

5546
(data_only_dirs test_data templates)
47+
5648
(install
57-
(package xapi-sdk)
58-
(section share_root)
59-
(dirs (autogen-out as go))
60-
)
49+
(package xapi-sdk)
50+
(section share_root)
51+
(dirs
52+
(autogen-out as go)))

0 commit comments

Comments
 (0)