summaryrefslogtreecommitdiff
path: root/test/end-to-end/actions/nested-trees.sh
blob: a5b052c54146285d0de831a7003d6f901d7828d1 (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
#!/bin/sh
# Copyright 2022 Huawei Cloud Computing Technology Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -e

mkdir tool-root
mkdir work
cd work
touch ROOT
cat > RULES <<'EOI'
{ "2^3":
  { "expression":
    { "type": "let*"
    , "bindings":
      [ ["blob", {"type": "BLOB", "data": "Hello World"}]
      , [ "two"
        , { "type": "TREE"
          , "$1":
            { "type": "map_union"
            , "$1":
              [ { "type": "singleton_map"
                , "key": "0"
                , "value": {"type": "var", "name": "blob"}
                }
              , { "type": "singleton_map"
                , "key": "1"
                , "value": {"type": "var", "name": "blob"}
                }
              ]
            }
          }
        ]
      , [ "four"
        , { "type": "TREE"
          , "$1":
            { "type": "map_union"
            , "$1":
              [ { "type": "singleton_map"
                , "key": "0"
                , "value": {"type": "var", "name": "two"}
                }
              , { "type": "singleton_map"
                , "key": "1"
                , "value": {"type": "var", "name": "two"}
                }
              ]
            }
          }
        ]
      , [ "eight"
        , { "type": "TREE"
          , "$1":
            { "type": "map_union"
            , "$1":
              [ { "type": "singleton_map"
                , "key": "0"
                , "value": {"type": "var", "name": "four"}
                }
              , { "type": "singleton_map"
                , "key": "1"
                , "value": {"type": "var", "name": "four"}
                }
              ]
            }
          }
        ]
      ]
    , "body":
      { "type": "RESULT"
      , "artifacts":
        { "type": "singleton_map"
        , "key": "data"
        , "value": {"type": "var", "name": "eight"}
        }
      }
    }
  }
}
EOI
cat > TARGETS <<'EOI'
{ "data": {"type": "2^3"}
, "ALL":
  { "type": "generic"
  , "outs": ["index.txt"]
  , "cmds": ["find data -type f | sort > index.txt"]
  , "deps": ["data"]
  }
}
EOI

echo
echo Analysis
echo
../bin/tool-under-test analyse data \
  --local-build-root ../tool-root --dump-trees ../trees.json --dump-blobs ../blobs.json 2>&1
echo
echo Blobs
echo
cat ../blobs.json
[ $(cat ../blobs.json | jq -acM 'length') -eq 1 ]
echo
echo Trees
echo
cat ../trees.json
[ $(cat ../trees.json | jq -acM 'length') -eq 3 ]
echo
echo Build
echo
../bin/tool-under-test install -L '["env", "PATH='"${PATH}"'"]' \
      -o ../out --local-build-root ../tool-root 2>&1
echo
echo Index
echo
cat ../out/index.txt
echo
[ $(cat ../out/index.txt | wc -l) -eq 8 ]