Start refactoring targets to use those coming from unity. so far we are refactoring to pull project-specific config

This commit is contained in:
Mark VanderVoord
2026-05-15 23:31:56 -04:00
parent 9900e4c5f5
commit 7d99f0f51d
5 changed files with 166 additions and 22 deletions
+75
View File
@@ -0,0 +1,75 @@
# =========================================================================
# CMock - Automatic Mock Generation for C
# ThrowTheSwitch.org
# Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
# SPDX-License-Identifier: MIT
# =========================================================================
:project:
:build_root: 'build/'
:colour: true
:paths:
:source:
- 'src/'
:include:
- 'src/'
- '../../src/'
- '../../vendor/unity/src/'
- '../../vendor/unity/examples/example_3/helper/'
- 'build/mocks/'
- 'test/'
:test: 'test/'
:build: 'build/'
:mocks: 'build/mocks/'
:extension:
:object: '.o'
:executable: '.exe'
:defines:
:common:
- __monitor
- UNITY_SUPPORT_64
:cmock:
# Core configuration
:plugins: []
:verbosity: 2
:when_no_prototypes: :warn
# File configuration
:mock_path: 'build/mocks'
:skeleton_path: ''
:mock_prefix: 'Mock'
:mock_suffix: ''
# Parser configuration
:strippables:
- '(?:__attribute__\s*\([ (]*.*?[ )]*\)+)'
:attributes:
- __ramfunc
- __irq
- __fiq
- register
- extern
:c_calling_conventions:
- __stdcall
- __cdecl
- __fastcall
:treat_externs: :exclude
:treat_inlines: :exclude
# Type handling configuration
:memcmp_if_unknown: true
:when_ptr: :compare_data
# Mock generation configuration
:weak: ''
:enforce_strict_ordering: false
:fail_on_unexpected_calls: true
:callback_include_count: true
:callback_after_arg_check: false
:includes:
- Types.h
:exclude_setjmp_h: false
+24 -6
View File
@@ -24,8 +24,26 @@ module RakefileHelpers
def load_configuration(config_file)
$cfg_file = config_file
$cfg = load_yaml(File.read("./targets/#{$cfg_file}"))
$colour_output = false unless $cfg['colour']
$cfg = load_yaml(File.read("../../test/targets/#{$cfg_file}"))
$proj = load_yaml(File.read('./project.yml'))
# Apply project-level paths, overriding the test-system paths in the target file
$cfg['compiler']['source_path'] = $proj[:paths][:source].first
$cfg['compiler']['unit_tests_path'] = $proj[:paths][:test]
$cfg['compiler']['build_path'] = $proj[:project][:build_root]
$cfg['compiler']['object_files']['destination'] = $proj[:project][:build_root]
$cfg['linker']['object_files']['path'] = $proj[:project][:build_root]
$cfg['linker']['bin_files']['destination'] = $proj[:project][:build_root]
# Merge includes: keep Array items from target (e.g., IAR tool paths), use project.yml for strings
tool_includes = $cfg['compiler']['includes']['items'].select { |i| i.is_a?(Array) }
$cfg['compiler']['includes']['items'] = tool_includes + $proj[:paths][:include]
# Merge defines: target-specific first, then project common defines
$cfg['compiler']['defines']['items'] ||= []
$cfg['compiler']['defines']['items'] |= $proj[:defines][:common]
$colour_output = $proj[:project][:colour]
end
def configure_clean
@@ -196,13 +214,13 @@ module RakefileHelpers
# Build and execute each unit test
test_files.each do |test|
# Detect dependencies and build required required modules
header_list = (extract_headers(test) + ['cmock.h'] + [$cfg[:cmock][:unity_helper_path]]).compact.uniq
header_list = (extract_headers(test) + ['cmock.h'] + [($proj[:cmock] || {})[:unity_helper_path]]).compact.uniq
header_list.each do |header|
# create mocks if needed
next unless header =~ /Mock/
require '../../lib/cmock'
@cmock ||= CMock.new(".//targets//#{$cfg_file}")
@cmock ||= CMock.new($proj[:cmock])
@cmock.setup_mocks([$cfg['compiler']['source_path'] + header.gsub('Mock', '')])
end
@@ -221,7 +239,7 @@ module RakefileHelpers
runner_name = "#{test_base}_Runner.c"
if $cfg['compiler']['runner_path'].nil?
runner_path = "#{$cfg['compiler']['build_path']}#{runner_name}"
test_gen = UnityTestRunnerGenerator.new(".//targets//#{$cfg_file}")
test_gen = UnityTestRunnerGenerator.new($cfg)
test_gen.run(test, runner_path)
else
runner_path = $cfg['compiler']['runner_path'] + runner_name
@@ -258,7 +276,7 @@ module RakefileHelpers
report 'Building application...'
obj_list = []
load_configuration(".//targets//#{$cfg_file}")
load_configuration($cfg_file)
main_path = $cfg['compiler']['source_path'] + main + C_EXTENSION
# Detect dependencies and build required required modules