move ceedling tests to test/unit-test

This commit is contained in:
hathach
2022-12-08 09:59:02 +07:00
parent 4b50ca2a61
commit be4f4e4f79
213 changed files with 1 additions and 1 deletions

View File

@@ -0,0 +1,63 @@
ceedling-subprojects
====================
Plugin for supporting subprojects that are built as static libraries. It continues to support
dependency tracking, without getting confused between your main project files and your
subproject files. It accepts different compiler flags and linker flags, allowing you to
optimize for your situation.
First, you're going to want to add the extension to your list of known extensions:
```
:extension:
:subprojects: '.a'
```
Define a new section called :subprojects. There, you can list as many subprojects
as you may need under the :paths key. For each, you specify a unique place to build
and a unique name.
```
:subprojects:
:paths:
- :name: libprojectA
:source:
- ./subprojectA/first/dir
- ./subprojectA/second/dir
:include:
- ./subprojectA/include/dir
:build_root: ./subprojectA/build/dir
:defines:
- DEFINE_JUST_FOR_THIS_FILE
- AND_ANOTHER
- :name: libprojectB
:source:
- ./subprojectB/only/dir
:include:
- ./subprojectB/first/include/dir
- ./subprojectB/second/include/dir
:build_root: ./subprojectB/build/dir
:defines: [] #none for this one
```
You can specify the compiler and linker, just as you would a release build:
```
:tools:
:subprojects_compiler:
:executable: gcc
:arguments:
- -g
- -I"$": COLLECTION_PATHS_SUBPROJECTS
- -D$: COLLECTION_DEFINES_SUBPROJECTS
- -c "${1}"
- -o "${2}"
:subprojects_linker:
:executable: ar
:arguments:
- rcs
- ${2}
- ${1}
```
That's all there is to it! Happy Hacking!

View File

@@ -0,0 +1,33 @@
---
#:extension:
# :subprojects: '.a'
:subprojects:
:paths: []
# - :name: subprojectA
# :source:
# - ./first/subproject/dir
# - ./second/subproject/dir
# :include:
# - ./first/include/dir
# :build_root: ./subproject/build/dir
# :defines:
# - FIRST_DEFINE
:tools:
:subprojects_compiler:
:executable: gcc
:arguments:
- -g
- -I"$": COLLECTION_PATHS_SUBPROJECTS
- -D$: COLLECTION_DEFINES_SUBPROJECTS
- -c "${1}"
- -o "${2}"
:subprojects_linker:
:executable: ar
:arguments:
- rcs
- ${2}
- ${1}
...

View File

@@ -0,0 +1,92 @@
require 'ceedling/plugin'
require 'ceedling/constants'
SUBPROJECTS_ROOT_NAME = 'subprojects'
SUBPROJECTS_TASK_ROOT = SUBPROJECTS_ROOT_NAME + ':'
SUBPROJECTS_SYM = SUBPROJECTS_ROOT_NAME.to_sym
class Subprojects < Plugin
def setup
@plugin_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
# Add to the test paths
SUBPROJECTS_PATHS.each do |subproj|
subproj[:source].each do |path|
COLLECTION_PATHS_TEST_SUPPORT_SOURCE_INCLUDE_VENDOR << path
end
subproj[:include].each do |path|
COLLECTION_PATHS_TEST_SUPPORT_SOURCE_INCLUDE_VENDOR << path
end
end
# Gather information about the subprojects
@subprojects = {}
@subproject_lookup_by_path = {}
SUBPROJECTS_PATHS.each do |subproj|
@subprojects[ subproj[:name] ] = subproj.clone
@subprojects[ subproj[:name] ][:c] = []
@subprojects[ subproj[:name] ][:asm] = []
subproj[:source].each do |path|
search_path = "#{path[-1].match(/\\|\//) ? path : "#{path}/"}*#{EXTENSION_SOURCE}"
@subprojects[ subproj[:name] ][:c] += Dir[search_path]
if (EXTENSION_ASSEMBLY && !EXTENSION_ASSEMBLY.empty?)
search_path = "#{path[-1].match(/\\|\//) ? path : "#{path}/"}*#{EXTENSION_ASSEMBLY}"
@subprojects[ subproj[:name] ][:asm] += Dir[search_path]
end
end
@subproject_lookup_by_path[ subproj[:build_root] ] = subproj[:name]
end
end
def find_my_project( c_file, file_type = :c )
@subprojects.each_pair do |subprojname, subproj|
return subprojname if (subproj[file_type].include?(c_file))
end
end
def find_my_paths( c_file, file_type = :c )
@subprojects.each_pair do |subprojname, subproj|
return (subproj[:source] + (subproj[:include] || [])) if (subproj[file_type].include?(c_file))
end
return []
end
def find_my_defines( c_file, file_type = :c )
@subprojects.each_pair do |subprojname, subproj|
return (subproj[:defines] || []) if (subproj[file_type].include?(c_file))
end
return []
end
def list_all_object_files_for_subproject( lib_name )
subproj = File.basename(lib_name, EXTENSION_SUBPROJECTS)
objpath = "#{@subprojects[subproj][:build_root]}/out/c"
bbb = @subprojects[subproj][:c].map{|f| "#{objpath}/#{File.basename(f,EXTENSION_SOURCE)}#{EXTENSION_OBJECT}" }
bbb
end
def find_library_source_file_for_object( obj_name )
cname = "#{File.basename(obj_name, EXTENSION_OBJECT)}#{EXTENSION_SOURCE}"
dname = File.dirname(obj_name)[0..-7]
pname = @subproject_lookup_by_path[dname]
return @ceedling[:file_finder].find_file_from_list(cname, @subprojects[pname][:c], :error)
end
def find_library_assembly_file_for_object( obj_name )
cname = "#{File.basename(obj_name, EXTENSION_OBJECT)}#{EXTENSION_ASEMBLY}"
dname = File.dirname(obj_name)[0..-7]
pname = @subproject_lookup_by_path[dname]
return @ceedling[:file_finder].find_file_from_list(cname, @subprojects[pname][:asm], :error)
end
def replace_constant(constant, new_value)
Object.send(:remove_const, constant.to_sym) if (Object.const_defined? constant)
Object.const_set(constant, new_value)
end
end
# end blocks always executed following rake run
END {
}

View File

@@ -0,0 +1,78 @@
SUBPROJECTS_PATHS.each do |subproj|
subproj_source = subproj[:source]
subproj_include = subproj[:include]
subproj_name = subproj[:name]
subproj_build_root = subproj[:build_root]
subproj_build_out = "#{subproj[:build_root]}/out"
subproj_build_c = "#{subproj[:build_root]}/out/c"
subproj_build_asm = "#{subproj[:build_root]}/out/asm"
subproj_directories = [ subproj_build_root, subproj_build_out, subproj_build_c, subproj_build_asm ]
subproj_directories.each do |subdir|
directory(subdir)
end
CLEAN.include(File.join(subproj_build_root, '*'))
CLEAN.include(File.join(subproj_build_out, '*'))
CLOBBER.include(File.join(subproj_build_root, '**/*'))
# Add a rule for building the actual static library from our object files
rule(/#{subproj_build_root}#{'.+\\'+EXTENSION_SUBPROJECTS}$/ => [
proc do |task_name|
@ceedling[SUBPROJECTS_SYM].list_all_object_files_for_subproject(task_name)
end
]) do |bin_file|
@ceedling[:generator].generate_executable_file(
TOOLS_SUBPROJECTS_LINKER,
SUBPROJECTS_SYM,
bin_file.prerequisites,
bin_file.name,
@ceedling[:file_path_utils].form_test_build_map_filepath(bin_file.name))
end
# Add a rule for building object files from assembly files to link into a library
if (RELEASE_BUILD_USE_ASSEMBLY)
rule(/#{subproj_build_asm}#{'.+\\'+EXTENSION_OBJECT}$/ => [
proc do |task_name|
@ceedling[SUBPROJECTS_SYM].find_library_assembly_file_for_object(task_name)
end
]) do |object|
@ceedling[SUBPROJECTS_SYM].replace_constant(:COLLECTION_PATHS_SUBPROJECTS, @ceedling[SUBPROJECTS_SYM].find_my_paths(object.source, :asm))
@ceedling[SUBPROJECTS_SYM].replace_constant(:COLLECTION_DEFINES_SUBPROJECTS, @ceedling[SUBPROJECTS_SYM].find_my_defines(object.source, :asm))
@ceedling[:generator].generate_object_file(
TOOLS_SUBPROJECTS_ASSEMBLER,
OPERATION_ASSEMBLE_SYM,
SUBPROJECTS_SYM,
object.source,
object.name )
end
end
# Add a rule for building object files from C files to link into a library
rule(/#{subproj_build_c}#{'.+\\'+EXTENSION_OBJECT}$/ => [
proc do |task_name|
@ceedling[SUBPROJECTS_SYM].find_library_source_file_for_object(task_name)
end
]) do |object|
@ceedling[SUBPROJECTS_SYM].replace_constant(:COLLECTION_PATHS_SUBPROJECTS, @ceedling[SUBPROJECTS_SYM].find_my_paths(object.source, :c))
@ceedling[SUBPROJECTS_SYM].replace_constant(:COLLECTION_DEFINES_SUBPROJECTS, @ceedling[SUBPROJECTS_SYM].find_my_defines(object.source, :c))
@ceedling[:generator].generate_object_file(
TOOLS_SUBPROJECTS_COMPILER,
OPERATION_COMPILE_SYM,
SUBPROJECTS_SYM,
object.source,
object.name,
@ceedling[:file_path_utils].form_release_build_c_list_filepath( object.name ) )
end
# Add the subdirectories involved to our list of those that should be autogenerated
task :directories => subproj_directories.clone
# Finally, add the static library to our RELEASE build dependency list
task RELEASE_SYM => ["#{subproj_build_root}/#{subproj_name}#{EXTENSION_SUBPROJECTS}"]
end