summaryrefslogtreecommitdiff
path: root/ps/RULES
blob: 6a4a1844e06b75759d0bf777cbf1921292ec1353 (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
{ "family":
  { "doc":
    [ "From a single eps file, create many,"
    , "with /stage set to different values."
    ]
  , "target_fields": ["src"]
  , "string_fields": ["stages", "stage", "drawbb", "name"]
  , "field_doc":
    { "src": ["The single eps source file the variations are taken from"]
    , "stages": ["The values of /stage for wich a file should be generated."]
    , "drawbb": ["If non-empty, set drawbb to true, else to false"]
    , "stage": ["The logical directory to stage the output to"]
    , "name":
      [ "The base name of the output files"
      , "The stage name will be appended, separated by \"_\", and the ending \".eps\" will be added"
      ]
    }
  , "imports": {"stage_field": ["./", "..", "stage_singleton_field"]}
  , "expression":
    { "type": "let*"
    , "bindings":
      [ [ "stage"
        , { "type": "join"
          , "separator": "/"
          , "$1": {"type": "FIELD", "name": "stage"}
          }
        ]
      , ["name", {"type": "join", "$1": {"type": "FIELD", "name": "name"}}]
      , [ "drawbb"
        , { "type": "if"
          , "cond": {"type": "FIELD", "name": "drawbb"}
          , "then": "true"
          , "else": "false"
          }
        ]
      , [ "src.eps"
        , { "type": "let*"
          , "bindings": [["fieldname", "src"], ["location", "src.eps"]]
          , "body": {"type": "CALL_EXPRESSION", "name": "stage_field"}
          }
        ]
      , [ "outputs"
        , { "type": "map_union"
          , "$1":
            { "type": "foreach"
            , "range": {"type": "FIELD", "name": "stages"}
            , "var": "n"
            , "body":
              { "type": "let*"
              , "bindings":
                [ [ "script.ed"
                  , { "type": "singleton_map"
                    , "key": "script.ed"
                    , "value":
                      { "type": "BLOB"
                      , "data":
                        { "type": "join"
                        , "$1":
                          [ "1\n/\\/stage.*bind def\nd\na\n/stage { "
                          , {"type": "var", "name": "n"}
                          , " } bind def\n.\n1\n/\\/drawbb.*bind def\nd\na\n/drawbb { "
                          , {"type": "var", "name": "drawbb"}
                          , " } bind def\n.\nw\nq\n"
                          ]
                        }
                      }
                    }
                  ]
                , [ "out.eps"
                  , { "type": "ACTION"
                    , "inputs":
                      { "type": "map_union"
                      , "$1":
                        [ {"type": "var", "name": "src.eps"}
                        , {"type": "var", "name": "script.ed"}
                        ]
                      }
                    , "outs": ["out.eps"]
                    , "cmd":
                      [ "sh"
                      , "-c"
                      , "cp src.eps out.eps && chmod 644 out.eps && { ed out.eps < script.ed > log 2>&1 || { cat log ; exit 1; } }"
                      ]
                    }
                  ]
                ]
              , "body":
                { "type": "singleton_map"
                , "key":
                  { "type": "join"
                  , "$1":
                    [ {"type": "var", "name": "name"}
                    , "_"
                    , {"type": "var", "name": "n"}
                    , ".eps"
                    ]
                  }
                , "value":
                  { "type": "lookup"
                  , "map": {"type": "var", "name": "out.eps"}
                  , "key": "out.eps"
                  }
                }
              }
            }
          }
        ]
      , [ "staged outputs"
        , { "type": "to_subdir"
          , "subdir": {"type": "var", "name": "stage"}
          , "$1": {"type": "var", "name": "outputs"}
          }
        ]
      ]
    , "body":
      { "type": "RESULT"
      , "artifacts": {"type": "var", "name": "staged outputs"}
      , "runfiles": {"type": "var", "name": "staged outputs"}
      }
    }
  }
}