Skip to content

Commit 0931a0b

Browse files
committed
[cbuild2cmake] Improve executes dependencies
1 parent 5532df6 commit 0931a0b

File tree

8 files changed

+98
-239
lines changed

8 files changed

+98
-239
lines changed

cmd/cbuild2cmake/commands/root_test.go

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -305,49 +305,9 @@ set(OUTPUTS_1
305305
err := cmd.Execute()
306306
assert.Nil(err)
307307

308-
// check super CMakeLists contents
309-
content, err := utils.ReadFileContent(testCaseRoot + "/tmp/CMakeLists.txt")
308+
// check golden references
309+
err, mismatch := inittest.CompareFiles(testCaseRoot+"/ref", testCaseRoot+"/tmp")
310310
assert.Nil(err)
311-
312-
content = strings.ReplaceAll(content, "\r\n", "\n")
313-
assert.Contains(content, `
314-
# Execute: project.Release+ARMCM0-Sign_Artifact
315-
set(INPUT
316-
${SOLUTION_ROOT}/script/sign.cmake
317-
${SOLUTION_ROOT}/out/project/ARMCM0/Release/project.axf
318-
)
319-
list(GET INPUT 0 INPUT_0)
320-
set(OUTPUT
321-
${SOLUTION_ROOT}/out/project/ARMCM0/Release/project.axf.signed
322-
)
323-
add_custom_target(project.Release+ARMCM0-Sign_Artifact ALL DEPENDS ${OUTPUT})
324-
add_custom_command(OUTPUT ${OUTPUT} DEPENDS ${INPUT}
325-
COMMAND ${CMAKE_COMMAND} -DINPUT="${INPUT}" -DOUTPUT="${OUTPUT}" -P "${INPUT_0}"
326-
COMMENT project.Release+ARMCM0-Sign_Artifact
327-
)`)
328-
assert.Contains(content, `
329-
# Build dependencies
330-
add_dependencies(project.Debug+ARMCM0-build
331-
Generate_Project_Sources
332-
)
333-
add_dependencies(project.Release+ARMCM0-build
334-
Generate_Project_Sources
335-
)
336-
add_dependencies(Archive_Artifacts
337-
project.Release+ARMCM0-build
338-
project.Release+ARMCM0-Sign_Artifact
339-
)
340-
add_dependencies(project.Release+ARMCM0-executes
341-
Archive_Artifacts
342-
)
343-
add_dependencies(Run_After_Archiving
344-
Archive_Artifacts
345-
)
346-
add_dependencies(project.Release+ARMCM0-Sign_Artifact
347-
project.Release+ARMCM0-build
348-
)
349-
add_dependencies(project.Release+ARMCM0-executes
350-
project.Release+ARMCM0-Sign_Artifact
351-
)`)
311+
assert.False(mismatch)
352312
})
353313
}

pkg/maker/buildcontent.go

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type CompilerAbstractions struct {
3838

3939
type ScopeMap map[string]map[string][]string
4040
type LanguageMap map[string][]string
41+
type DependenciesMap map[string][]string
4142

4243
var CategoryLanguageMap = map[string]string{
4344
"headerAsm": "ASM",
@@ -158,6 +159,7 @@ func (m *Maker) AddStepSuffix(name string) string {
158159

159160
func (m *Maker) CMakeTargetAddDependencies(name string, dependencies []string) string {
160161
var content string
162+
dependencies = utils.AppendUniquely(dependencies, m.GetAllRunAlways(name)...)
161163
if len(dependencies) > 0 {
162164
content += "\nadd_dependencies(" + m.AddStepSuffix(name)
163165
for _, dependency := range dependencies {
@@ -176,22 +178,53 @@ func (m *Maker) BuildDependencies() string {
176178
}
177179
content += m.CMakeTargetAddDependencies(cbuild.Project+cbuild.Configuration, cbuild.DependsOn)
178180
}
181+
var postBuildDependencies = make(DependenciesMap)
179182
for _, item := range m.CbuildIndex.BuildIdx.Executes {
180183
content += m.CMakeTargetAddDependencies(item.Execute, item.DependsOn)
181-
// add executes statement to ${CONTEXT}-executes target of context
182-
// if dependency is a context
183-
for _, dependsOn := range item.DependsOn {
184-
if slices.Contains(m.Contexts, dependsOn) {
185-
content += m.CMakeTargetAddDependencies(dependsOn+"-executes", []string{item.Execute})
186-
}
187-
}
184+
postBuildDependencies = m.GetContextDependencies(item.Execute, item.DependsOn, postBuildDependencies)
185+
}
186+
// add executes statement to ${CONTEXT}-executes target of context
187+
for context, dependencies := range postBuildDependencies {
188+
content += m.CMakeTargetAddDependencies(context+"-executes", dependencies)
188189
}
189190
if len(content) > 0 {
190191
content = "\n\n# Build dependencies" + content
191192
}
192193
return content
193194
}
194195

196+
func (m *Maker) GetContextDependencies(execute string, dependsOn []string, deps DependenciesMap) DependenciesMap {
197+
for _, item := range dependsOn {
198+
if slices.Contains(m.Contexts, item) {
199+
// collect dependency on context (post build step)
200+
deps[item] = utils.AppendUniquely(deps[item], execute)
201+
} else {
202+
// check recursively further dependencies
203+
deps = m.GetContextDependencies(execute, m.GetDependsOn(item), deps)
204+
}
205+
}
206+
return deps
207+
}
208+
209+
func (m *Maker) GetDependsOn(execute string) (dependsOn []string) {
210+
for _, item := range m.CbuildIndex.BuildIdx.Executes {
211+
if item.Execute == execute {
212+
dependsOn = item.DependsOn
213+
break
214+
}
215+
}
216+
return dependsOn
217+
}
218+
219+
func (m *Maker) GetAllRunAlways(execute string) (elements []string) {
220+
for _, item := range m.CbuildIndex.BuildIdx.Executes {
221+
if item.Execute != execute && item.Always != nil {
222+
elements = utils.AppendUniquely(elements, item.Execute)
223+
}
224+
}
225+
return elements
226+
}
227+
195228
func CMakeTargetIncludeDirectories(name string, includes ScopeMap) string {
196229
if len(includes) == 0 {
197230
return ""

test/data/solutions/executes/project/project.Debug+ARMCM0.cbuild.yml

Lines changed: 0 additions & 127 deletions
This file was deleted.
Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
build:
2-
generated-by: csolution version 0.0.0+gdf212332
2+
generated-by: csolution version 2.6.0
33
solution: ../solution.csolution.yml
44
project: project.cproject.yml
55
context: project.Release+ARMCM0
66
compiler: AC6
77
device: ARMCM0
8-
device-pack: ARM::Cortex_DFP@1.0.0
8+
device-pack: ARM::Cortex_DFP@1.1.0
99
processor:
1010
fpu: off
1111
core: Cortex-M0
1212
packs:
13-
- pack: ARM::CMSIS@6.0.0
14-
path: ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.0.0
15-
- pack: ARM::Cortex_DFP@1.0.0
16-
path: ${CMSIS_PACK_ROOT}/ARM/Cortex_DFP/1.0.0
13+
- pack: ARM::CMSIS@6.1.0
14+
path: ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.1.0
15+
- pack: ARM::Cortex_DFP@1.1.0
16+
path: ${CMSIS_PACK_ROOT}/ARM/Cortex_DFP/1.1.0
1717
misc:
1818
ASM:
1919
- -masm=auto
@@ -42,50 +42,50 @@ build:
4242
- _RTE_
4343
add-path:
4444
- RTE/_Release_ARMCM0
45-
- ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.0.0/CMSIS/Core/Include
46-
- ${CMSIS_PACK_ROOT}/ARM/Cortex_DFP/1.0.0/Device/ARMCM0/Include
45+
- ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.1.0/CMSIS/Core/Include
46+
- ${CMSIS_PACK_ROOT}/ARM/Cortex_DFP/1.1.0/Device/ARMCM0/Include
4747
add-path-asm:
4848
- RTE/_Release_ARMCM0
49-
- ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.0.0/CMSIS/Core/Include
50-
- ${CMSIS_PACK_ROOT}/ARM/Cortex_DFP/1.0.0/Device/ARMCM0/Include
49+
- ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.1.0/CMSIS/Core/Include
50+
- ${CMSIS_PACK_ROOT}/ARM/Cortex_DFP/1.1.0/Device/ARMCM0/Include
5151
output-dirs:
52-
intdir: ../tmp/project/ARMCM0/Release
52+
intdir: ../tmp
5353
outdir: ../out/project/ARMCM0/Release
5454
rtedir: RTE
5555
output:
5656
- type: elf
5757
file: project.axf
5858
components:
59-
- component: ARM::CMSIS:CORE@6.0.0
59+
- component: ARM::CMSIS:CORE@6.1.0
6060
condition: ARMv6_7_8-M Device
61-
from-pack: ARM::CMSIS@6.0.0
61+
from-pack: ARM::CMSIS@6.1.0
6262
selected-by: ARM::CMSIS:CORE
6363
files:
64-
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.0.0/CMSIS/Core/Include
64+
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.1.0/CMSIS/Core/Include
6565
category: include
66-
version: 6.0.0
67-
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.0.0/CMSIS/Core/Include/tz_context.h
66+
version: 6.1.0
67+
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.1.0/CMSIS/Core/Include/tz_context.h
6868
category: header
69-
version: 6.0.0
70-
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.0.0/CMSIS/Core/Template/ARMv8-M/main_s.c
69+
version: 6.1.0
70+
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.1.0/CMSIS/Core/Template/ARMv8-M/main_s.c
7171
category: sourceC
7272
attr: template
7373
version: 1.1.1
7474
select: Secure mode 'main' module for ARMv8-M
75-
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.0.0/CMSIS/Core/Template/ARMv8-M/tz_context.c
75+
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.1.0/CMSIS/Core/Template/ARMv8-M/tz_context.c
7676
category: sourceC
7777
attr: template
7878
version: 1.1.1
7979
select: RTOS Context Management (TrustZone for ARMv8-M)
80-
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.0.0/CMSIS/Documentation/html/Core/index.html
80+
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.1.0/CMSIS/Documentation/html/Core/index.html
8181
category: doc
82-
version: 6.0.0
82+
version: 6.1.0
8383
- component: ARM::Device:Startup&C [email protected]
8484
condition: ARMCM0 CMSIS
85-
from-pack: ARM::Cortex_DFP@1.0.0
85+
from-pack: ARM::Cortex_DFP@1.1.0
8686
selected-by: ARM::Device:Startup&C Startup
8787
files:
88-
- file: ${CMSIS_PACK_ROOT}/ARM/Cortex_DFP/1.0.0/Device/ARMCM0/Include/ARMCM0.h
88+
- file: ${CMSIS_PACK_ROOT}/ARM/Cortex_DFP/1.1.0/Device/ARMCM0/Include/ARMCM0.h
8989
category: header
9090
version: 2.2.0
9191
- file: RTE/Device/ARMCM0/ARMCM0_ac6.sct
@@ -105,23 +105,18 @@ build:
105105
groups:
106106
- group: Source
107107
files:
108-
- file: ./source0.c
108+
- file: source0.c
109109
category: sourceC
110-
- file: ./source1.c
110+
- file: source1.c
111111
category: sourceC
112112
constructed-files:
113113
- file: RTE/_Release_ARMCM0/RTE_Components.h
114114
category: header
115115
licenses:
116-
- license: <unknown>
117-
license-agreement: ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.0.0/LICENSE
116+
- license: Apache-2.0
118117
packs:
119-
- pack: ARM::[email protected]
120-
components:
121-
- component: ARM::CMSIS:[email protected]
122-
- license: <unknown>
123-
license-agreement: ${CMSIS_PACK_ROOT}/ARM/Cortex_DFP/1.0.0/LICENSE
124-
packs:
125-
- pack: ARM::[email protected]
118+
- pack: ARM::[email protected]
119+
- pack: ARM::[email protected]
126120
components:
121+
- component: ARM::CMSIS:[email protected]
127122
- component: ARM::Device:Startup&C [email protected]

test/data/solutions/executes/project/project.cproject.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ project:
1313
- file: ./source1.c
1414

1515
executes:
16-
- execute: Sign Artifact
16+
- execute: Sign_Artifact
1717
run: ${CMAKE_COMMAND} -DINPUT=$input$ -DOUTPUT=$output$ -P $input(0)$
1818
input:
1919
- $SolutionDir()$/script/sign.cmake

0 commit comments

Comments
 (0)