@@ -164,7 +164,6 @@ func (h *HCLRegistry) registerAllComponents() hcl.Diagnostics {
164
164
165
165
conflictSources := map [string ]struct {}{}
166
166
167
- // we currently support only one build block but it will change in the near future
168
167
for _ , build := range h .configuration .Builds {
169
168
for _ , source := range build .Sources {
170
169
// If we encounter the same source twice, we'll defer
@@ -198,18 +197,27 @@ func (h *HCLRegistry) registerAllComponents() hcl.Diagnostics {
198
197
continue
199
198
}
200
199
201
- buildName := source .String ()
202
- if build .Name != "" {
203
- buildName = fmt .Sprintf ("%s.%s" , build .Name , buildName )
200
+ if build .Name == "" {
201
+ diags = append (diags , & hcl.Diagnostic {
202
+ Severity : hcl .DiagError ,
203
+ Summary : "Missing mandatory build name" ,
204
+ Subject : & build .HCL2Ref .DefRange ,
205
+ Detail : "A build name is required when using the same source in two or" +
206
+ " more different builds" ,
207
+ })
208
+ continue
204
209
}
205
210
211
+ buildName := fmt .Sprintf ("%s.%s" , build .Name , source .String ())
212
+
206
213
if _ , ok := h .buildNames [buildName ]; ok {
207
214
diags = append (diags , & hcl.Diagnostic {
208
215
Severity : hcl .DiagError ,
209
216
Summary : "Build name conflicts" ,
210
217
Subject : & build .HCL2Ref .DefRange ,
211
- Detail : fmt .Sprintf ("Two sources are used in the same build block, causing " +
212
- "a conflict, there must only be one instance of %s" , source .String ()),
218
+ Detail : fmt .Sprintf ("Two sources are used in the same build block or " +
219
+ "two builds have the same name, causing a conflict, there must only " +
220
+ "be one instance of %s" , source .String ()),
213
221
})
214
222
}
215
223
h .buildNames [buildName ] = struct {}{}
0 commit comments