summaryrefslogtreecommitdiff
path: root/yarns/splitting.yarn
blob: dbe87a5cf59fd6af472f8e9db3a0d8885401bab0 (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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
Artifact splitting tests
========================

Parsing and validation
----------------------

To verify that the products fields are parsed correctly, we have a
scenario that uses all of them, not relying on the default rules.

    SCENARIO building a system with morphologies that have splitting rules
    GIVEN a workspace
    AND a git server

To test that all the fields are recognised, we set the new fields to
their default values.

    AND chunk test-chunk includes the default splitting rules
    AND stratum strata/test-stratum.morph includes the default splitting rules
    AND system systems/test-system.morph includes the default splitting rules

The default rules produce a system that is identical to not providing
them, and since this test is about validation, we don't care about the
result, so much as it succeeding to build something.

    WHEN the user checks out the system branch called master
    THEN morph build the system systems/test-system.morph of the branch master

Smaller systems
---------------

An example use-case for splitting is to only include the runtime
strata for a target system, rather than including all the development
information, such as the documentation, C library headers and C static
libraries.

    SCENARIO building a system only using runtime strata
    GIVEN a workspace
    AND a git server

The only change we need to make is to add a field to the system morphology
to select which artifact to use in the system.

    AND system systems/test-system.morph uses test-stratum-runtime from test-stratum
    WHEN the user checks out the system branch called master

The best way to test that only using some stratum artifacts works is
to check which files the output has, so we deploy a tarball and inspect
its contents.

    GIVEN a cluster called test-cluster.morph in system branch master
    AND a system in cluster test-cluster.morph in branch master called test-system
    AND system test-system in cluster test-cluster.morph in branch master builds systems/test-system.morph
    AND system test-system in cluster test-cluster.morph in branch master has deployment type: tar
    WHEN the user builds the system systems/test-system.morph in branch master
    AND the user attempts to deploy the cluster test-cluster.morph in branch master with options test-system.location="$DATADIR/test.tar"

The -runtime artifacts include executables and shared libraries.

    THEN morph succeeded
    AND tarball test.tar contains bin/test
    AND tarball test.tar contains lib/libtest.so

The -devel artifacts include static libraries and documentation, so if
we've successfully excluded it, we won't have those files.

    AND tarball test.tar doesn't contain lib/libtest.a
    AND tarball test.tar doesn't contain man/man3/test.3.gz

As a consequence of how dependencies are generated, if we select strata
to go into our system, such that there are chunk artifacts that are not
needed, then they don't get built.

    SCENARIO building a system that has unused chunks
    GIVEN a workspace
    AND a git server

This GIVEN has a chunk in the stratum that never successfully builds,
so we know that if the system successfully builds, then we only built
chunks that were needed.

    AND stratum strata/test-stratum.morph has chunks that aren't used in test-stratum-minimal
    AND system systems/test-system.morph uses test-stratum-minimal from test-stratum
    WHEN the user checks out the system branch called master
    THEN morph build the system systems/test-system.morph of the branch master


Implementations
---------------

    IMPLEMENTS GIVEN chunk (\S+) includes the default splitting rules
    # Append default products rules
    name="$(basename "${MATCH_1%.*}")"
    cat <<EOF >>"$DATADIR/gits/$name/$MATCH_1"
    products:
    - artifact: $name-bins
      include: [ "(usr/)?s?bin/.*" ]
    - artifact: $name-libs
      include:
      - (usr/)?lib(32|64)?/lib[^/]*\.so(\.\d+)*
      - (usr/)?libexec/.*
    - artifact: $name-devel
      include:
      - (usr/)?include/.*
      - (usr/)?lib(32|64)?/lib.*\.a
      - (usr/)?lib(32|64)?/lib.*\.la
      - (usr/)?(lib(32|64)?|share)/pkgconfig/.*\.pc
    - artifact: $name-doc
      include:
      - (usr/)?share/doc/.*
      - (usr/)?share/man/.*
      - (usr/)?share/info/.*
    - artifact: $name-locale
      include:
      - (usr/)?share/locale/.*
      - (usr/)?share/i18n/.*
      - (usr/)?share/zoneinfo/.*
    - artifact: $name-misc
      include: [ .* ]
    EOF
    run_in "$DATADIR/gits/$name" git add "$MATCH_1"
    run_in "$DATADIR/gits/$name" git commit -m 'Add default splitting rules'

    IMPLEMENTS GIVEN stratum (\S+) includes the default splitting rules
    name=$(basename "${MATCH_1%.*}")
    cat <<EOF >"$DATADIR/gits/morphs/$MATCH_1"
    name: $name
    kind: stratum
    products:
    - artifact: $name-devel
      include:
      - .*-devel
      - .*-debug
      - .*-doc
    - artifact: $name-runtime
      include:
      - .*-bins
      - .*-libs
      - .*-locale
      - .*-misc
      - .*
    chunks:
    -   name: test-chunk
        repo: test:test-chunk
        ref: master
        morph: test-chunk
        build-mode: test
        build-depends: []
        artifacts:
            test-chunk-bins: $name-runtime
            test-chunk-libs: $name-runtime
            test-chunk-locale: $name-runtime
            test-chunk-misc: $name-runtime
            test-chunk-devel: $name-devel
            test-chunk-doc: $name-devel
    EOF
    run_in "$DATADIR/gits/morphs" git add "$MATCH_1"
    run_in "$DATADIR/gits/morphs" git commit -m 'Add default splitting rules'

    IMPLEMENTS GIVEN system (\S+) includes the default splitting rules
    cat << EOF >> "$DATADIR/gits/morphs/$MATCH_1"
    strata:
    -   name: test-stratum
        morph: strata/test-stratum.morph
        artifacts:
        - test-stratum-runtime
        - test-stratum-devel
    EOF
    run_in "$DATADIR/gits/morphs" git add "$MATCH_1"
    run_in "$DATADIR/gits/morphs" git commit -m 'Add default splitting rules'

    IMPLEMENTS GIVEN stratum (\S+) has chunks that aren't used in (\S+)
    # Create an extra chunk that will never successfully build
    cat >"$DATADIR/gits/test-chunk/unbuildable-chunk.morph" <<EOF
    name: unbuildable-chunk
    kind: chunk
    install-commands:
    - "false"
    EOF
    run_in "$DATADIR/gits/test-chunk" git add unbuildable-chunk.morph
    run_in "$DATADIR/gits/test-chunk" git commit -m 'Add unbuildable chunk'

    # Create a stratum that has an artifact that doesn't include any
    # artifacts from unbuildable-chunk
    cat >>"$DATADIR/gits/morphs/$MATCH_1" <<EOF
    products:
    - artifact: $MATCH_2
      include:
      - test-chunk-.*
    chunks:
    - name: test-chunk
      repo: test:test-chunk
      ref: master
      morph: test-chunk
      build-mode: test
      build-depends: []
    - name: unbuildable-chunk
      repo: test:test-chunk
      ref: refs/heads/master
      morph: unbuildable-chunk
      build-mode: test
      build-depends:
      - test-chunk
    EOF
    run_in "$DATADIR/gits/morphs" git add "$MATCH_1"
    run_in "$DATADIR/gits/morphs" git commit -m "add $MATCH_2 to stratum"