File tree Expand file tree Collapse file tree 4 files changed +72
-0
lines changed Expand file tree Collapse file tree 4 files changed +72
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Environment Variables
2
+
3
+ Supplimental, examples of setting, overriding and constructing environment
4
+ variables. There is nothing special about showenv.sh, it is simply a place
5
+ holder for an external program. echo would do just as well
6
+
Original file line number Diff line number Diff line change
1
+ # CGO environment variables are used as a motivating example.
2
+
3
+ flexible :
4
+ # A task intended to be extended or called by others. Note the use of yaml
5
+ # anchors "&flexible_env"
6
+ cmds :
7
+ - ./showenv.sh
8
+ env : &flexible_env
9
+ # OTHERPATH defaults to the emptystring in Taskvars.yml, and can be set
10
+ # on the command line: OTHERPATH=other/path/ task flexible
11
+ # Or in any task calling or extending this one
12
+ CGO_LDFLAGS : " -L{{.OTHERPATH}}some/path/lib {{- range $_, $libname := .LIBNAMES | splitLines}}{{if $libname}} -l{{$libname}}{{end}}{{end}}"
13
+ vars :
14
+ LIBNAMES : |
15
+ aaa
16
+ bbb
17
+ ccc
18
+
19
+ calling :
20
+ cmds :
21
+ - task : flexible
22
+ vars :
23
+ LIBNAMES : |
24
+ xxx
25
+ yyy
26
+
27
+ extending :
28
+ cmds :
29
+ - ./showenv.sh
30
+ env :
31
+ << : *flexible_env
32
+ CGO_ANOTHER_VAR : " extending env key, this is a shallow merge"
33
+ vars :
34
+ # These variables override any pulled in from flexible_env
35
+ LIBNAMES : |
36
+ ddd
37
+ eee
38
+
39
+
40
+ envproperty :
41
+ cmds :
42
+ - ./showenv.sh
43
+ env :
44
+ CGO_LDFLAGS : " -L/some/path -laaa -lbbb -lccc"
45
+
46
+ possible :
47
+ # Notice the quotes guarding the variable references on the second line of
48
+ # the cmds.
49
+ cmds :
50
+ - |
51
+ CGO_LDFLAGS="-L/some/path -laaa -lbbb -lccc"
52
+ CGO_LDFLAGS="$CGO_LDFLAGS" ./showenv.sh "$CGO_LDFLAGS"
53
+
54
+ wrong :
55
+ # In this instance the quotes are missing, the output will be:
56
+ #
57
+ # CGO_LDFLAGS=-L/some/path-laaa-lbbb-lccc
58
+ # $@=-L/some/path-laaa-lbbb-lccc
59
+ cmds :
60
+ - |
61
+ CGO_LDFLAGS="-L/some/path -laaa -lbbb -lccc"
62
+ CGO_LDFLAGS=$CGO_LDFLAGS ./showenv.sh $CGO_LDFLAGS
Original file line number Diff line number Diff line change
1
+ OTHERPATH : " "
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+ env | grep CGO_
3
+ echo " \$ @=$@ "
You can’t perform that action at this time.
0 commit comments