File tree Expand file tree Collapse file tree 2 files changed +84
-1
lines changed
cabal-testsuite/PackageTests/PreProcess/TooManyCommandLineArgs Expand file tree Collapse file tree 2 files changed +84
-1
lines changed Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bash
2
+
3
+ # NB only check for duplicated -L or -I arguments because that’s the
4
+ # primary source of duplication. Some minor duplicates can also occur,
5
+ # like -Wl,--no-as-needed but there’s not too many of them yet to
6
+ # cause command line overflow.
7
+
8
+ # Quadratic algorithm because darwin CI doesn’t seem to have bash that
9
+ # supports associative arrays.
10
+ check_duplicate () {
11
+ local test_arg=" $1 "
12
+ local occurs=" 0"
13
+
14
+ if ! [[ " $test_arg " == -L * || " $test_arg " == -I* ]]; then
15
+ return 0
16
+ fi
17
+
18
+ shift
19
+ for tmp in " ${@ } " ; do
20
+ if [[ " $tmp " == @* ]]; then
21
+ while IFS= read -d $' \n ' -r arg ; do
22
+ if [[ " $arg " == " $test_arg " ]]; then
23
+ occurs=$(( occurs + 1 ))
24
+ fi
25
+ done < " ${tmp#@ } "
26
+ else
27
+ if [[ " $tmp " == " $test_arg " ]]; then
28
+ occurs=$(( occurs + 1 ))
29
+ fi
30
+ fi
31
+ done
32
+
33
+ if [[ " $occurs " -gt 1 ]]; then
34
+ return 1
35
+ else
36
+ return 0
37
+ fi
38
+ }
39
+
40
+ i=1
41
+ for x in " ${@ } " ; do
42
+ if [[ " $x " == @* ]]; then
43
+ file=
44
+ while IFS= read -d $' \n ' -r arg ; do
45
+ y=" $arg "
46
+ if ! check_duplicate " $arg " " ${@: $i } " ; then
47
+ echo " Duplicate argument detected: '$y '"
48
+ echo " All args: ${@ } "
49
+ exit 1
50
+ fi
51
+ done < " ${x#@ } "
52
+ else
53
+ if ! check_duplicate " $x " " ${@: $i } " ; then
54
+ echo " Duplicate argument detected: '$x '"
55
+ echo " All args: ${@ } "
56
+ exit 1
57
+ fi
58
+ fi
59
+
60
+ i=$(( i + 1 ))
61
+ done
62
+
63
+ if which cc > /dev/null 2>&1 ; then
64
+ cc -DNOERROR6 " ${@ } "
65
+ elif which gcc > /dev/null 2>&1 ; then
66
+ gcc -DNOERROR6 " ${@ } "
67
+ elif which clang > /dev/null 2>&1 ; then
68
+ clang -DNOERROR6 " ${@ } "
69
+ else
70
+ echo " Cannot find C compiler" >&2
71
+ exit 1
72
+ fi
Original file line number Diff line number Diff line change @@ -87,9 +87,20 @@ main = cabalTest $ do
87
87
libFlags =
88
88
concatMap (\ x -> [" --extra-lib-dirs" , cwd </> x]) libDirs
89
89
90
+ let customCC = cwd </> " custom-cc"
91
+
90
92
-- Parallel flag means output of this test is nondeterministic
91
93
_<- recordMode DoNotRecord $
92
- cabal " v2-build" $ [" -j" , " my-toplevel:exe:my-executable" ] ++ includeFlags ++ libFlags
94
+ cabal " v2-build" $
95
+ [" -j" , " my-toplevel:exe:my-executable" ]
96
+ -- Don’t validate absence of duplicates on Windows because
97
+ -- it’s too inconvenient to do in bat files. Let’s just
98
+ -- assume that deduplication will happen on Windows but
99
+ -- still try to run the test to see whether command-line
100
+ -- argument length limit is not hit.
101
+ ++ [" --with-gcc=" ++ customCC | not isWindows]
102
+ ++ includeFlags
103
+ ++ libFlags
93
104
r <- withPlan $ runPlanExe' " my-toplevel" " my-executable" []
94
105
assertOutputContains
95
106
(" Result = " ++ show (42 + 55 + 10 * (55 + 10 * 55 ) + 3 * 55 ))
You can’t perform that action at this time.
0 commit comments