@@ -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,26 @@ 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 : "Build name conflicts" ,
204
+ Subject : & build .HCL2Ref .DefRange ,
205
+ Detail : "build name is required when using the same source in two different builds" ,
206
+ })
207
+ continue
204
208
}
205
209
210
+ buildName := fmt .Sprintf ("%s.%s" , build .Name , source .String ())
211
+
206
212
if _ , ok := h .buildNames [buildName ]; ok {
207
213
diags = append (diags , & hcl.Diagnostic {
208
214
Severity : hcl .DiagError ,
209
215
Summary : "Build name conflicts" ,
210
216
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 ()),
217
+ Detail : fmt .Sprintf ("Two sources are used in the same build block or " +
218
+ "two build has the same name causing a conflict, there must only " +
219
+ "be one instance of %s" , source .String ()),
213
220
})
214
221
}
215
222
h .buildNames [buildName ] = struct {}{}
0 commit comments