summaryrefslogtreecommitdiff
path: root/rules/shell/RULES
blob: b9e91bbd8b70b4540d77ff0799c22081beac0d44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
{ "defaults":
  { "doc":
    [ "A rule to provide defaults for the usage of the shell"
    , ""
    , "All targets using invocations of the shell use the target"
    , "[\"shel\", \"defaults\"] to determine which shell to use and how to"
    , "invoke it. The definition of this default target is probably the only"
    , "meaningful use of this rule."
    ]
  , "target_fields": ["base", "toolchain"]
  , "string_fields": ["sh", "PATH", "bin dirs"]
  , "field_doc":
    { "base": ["Other targets (using the same rule) to inherit values from."]
    , "toolchain":
      [ "Optional toolchain directory. A collection of artifacts that"
      , "form the toolchain, in particular the shell itself, where not taken"
      , "from the ambient host environment."
      , "Values provided from base are extended."
      , "This field is built for the host."
      ]
    , "sh":
      [ "The name of the sh binary; if the the field \"toolchain\" is"
      , "not empty, the value is interpreted as relative to the toolchain"
      , "directory."
      ]
    , "PATH":
      [ "Paths for looking up system tools."
      , "Specifying this field extends values from \"base\"."
      ]
    , "bin dirs":
      [ "Directories of the toolchain that contain additional binaries."
      , "Shell-specific rules will add those into PATH."
      ]
    }
  , "config_vars": ["ARCH", "HOST_ARCH", "TARGET_ARCH"]
  , "imports":
    { "for host": ["transitions", "for host"]
    , "artifacts_list": ["", "field_artifacts_list"]
    , "base-provides-list": ["CC", "defaults-base-provides-list"]
    , "base-provides-++": ["CC", "defaults-base-provides-++"]
    , "base-provides": ["CC", "defaults-base-provides"]
    }
  , "config_transitions":
    {"toolchain": [{"type": "CALL_EXPRESSION", "name": "for host"}]}
  , "expression":
    { "type": "let*"
    , "bindings":
      [ [ "TOOLCHAIN"
        , { "type": "disjoint_map_union"
          , "msg": "toolchain artifacts must not overlap"
          , "$1":
            { "type": "++"
            , "$1":
              [ { "type": "let*"
                , "bindings":
                  [ ["provider", "TOOLCHAIN"]
                  , ["default", {"type": "empty_map"}]
                  ]
                , "body":
                  {"type": "CALL_EXPRESSION", "name": "base-provides-list"}
                }
              , { "type": "let*"
                , "bindings":
                  [ ["fieldname", "toolchain"]
                  , [ "transition"
                    , {"type": "CALL_EXPRESSION", "name": "for host"}
                    ]
                  ]
                , "body": {"type": "CALL_EXPRESSION", "name": "artifacts_list"}
                }
              ]
            }
          }
        ]
      , [ "sh"
        , { "type": "if"
          , "cond": {"type": "FIELD", "name": "sh"}
          , "then": {"type": "FIELD", "name": "sh"}
          , "else":
            { "type": "let*"
            , "bindings": [["provider", "sh"]]
            , "body": {"type": "CALL_EXPRESSION", "name": "base-provides"}
            }
          }
        ]
      , [ "NON_SYSTEM_TOOLS"
        , { "type": "map_union"
          , "$1":
            { "type": "++"
            , "$1":
              [ [ { "type": "let*"
                  , "bindings":
                    [ ["provider", "NON_SYSTEM_TOOLS"]
                    , ["default", {"type": "empty_map"}]
                    ]
                  , "body":
                    {"type": "CALL_EXPRESSION", "name": "base-provides"}
                  }
                ]
              , { "type": "if"
                , "cond": {"type": "FIELD", "name": "sh"}
                , "then":
                  [ { "type": "singleton_map"
                    , "key": "sh"
                    , "value":
                      { "type": "if"
                      , "cond": {"type": "FIELD", "name": "toolchain"}
                      , "then": true
                      , "else": false
                      }
                    }
                  ]
                }
              ]
            }
          }
        ]
      , [ "PATH"
        , { "type": "nub_left"
          , "$1":
            { "type": "++"
            , "$1":
              [ {"type": "FIELD", "name": "PATH"}
              , { "type": "let*"
                , "bindings": [["provider", "PATH"]]
                , "body":
                  {"type": "CALL_EXPRESSION", "name": "base-provides-++"}
                }
              ]
            }
          }
        ]
      , [ "bin dirs"
        , { "type": "nub_left"
          , "$1":
            { "type": "++"
            , "$1":
              [ {"type": "FIELD", "name": "bin dirs"}
              , { "type": "let*"
                , "bindings": [["provider", "bin dirs"]]
                , "body":
                  {"type": "CALL_EXPRESSION", "name": "base-provides-++"}
                }
              ]
            }
          }
        ]
      ]
    , "body":
      { "type": "RESULT"
      , "provides":
        { "type": "env"
        , "vars": ["TOOLCHAIN", "sh", "NON_SYSTEM_TOOLS", "PATH", "bin dirs"]
        }
      }
    }
  }
}