diff options
author | joeycastillo <joeycastillo@utexas.edu> | 2021-08-30 14:42:11 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-30 14:42:11 -0400 |
commit | eb3d9b26cbda2d2612f11eb39843b221224f1fa7 (patch) | |
tree | 7a514b4d21dd0d2a324a5e1313a144f26bf20799 /tinyusb/test/vendor/ceedling/plugins/module_generator/lib/module_generator.rb | |
parent | ee9cc322d301631c9ff0751d9bed717c6492b6a5 (diff) | |
parent | b0845cc3f1a8234a30c980eccf10e44765e4e105 (diff) | |
download | Sensor-Watch-eb3d9b26cbda2d2612f11eb39843b221224f1fa7.tar.gz Sensor-Watch-eb3d9b26cbda2d2612f11eb39843b221224f1fa7.tar.bz2 Sensor-Watch-eb3d9b26cbda2d2612f11eb39843b221224f1fa7.zip |
Merge pull request #9 from joeycastillo/usb-refactor
USB refactor / Makefile simplification
Diffstat (limited to 'tinyusb/test/vendor/ceedling/plugins/module_generator/lib/module_generator.rb')
-rwxr-xr-x | tinyusb/test/vendor/ceedling/plugins/module_generator/lib/module_generator.rb | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/tinyusb/test/vendor/ceedling/plugins/module_generator/lib/module_generator.rb b/tinyusb/test/vendor/ceedling/plugins/module_generator/lib/module_generator.rb new file mode 100755 index 00000000..b2fac006 --- /dev/null +++ b/tinyusb/test/vendor/ceedling/plugins/module_generator/lib/module_generator.rb @@ -0,0 +1,70 @@ +require 'ceedling/plugin' +require 'ceedling/constants' +require 'erb' +require 'fileutils' + +class ModuleGenerator < Plugin + + attr_reader :config + + def create(module_name, optz={}) + + require "generate_module.rb" #From Unity Scripts + + if ((!optz.nil?) && (optz[:destroy])) + UnityModuleGenerator.new( divine_options(optz) ).destroy(module_name) + else + UnityModuleGenerator.new( divine_options(optz) ).generate(module_name) + end + end + + private + + def divine_options(optz={}) + unity_generator_options = + { + :path_src => ((defined? MODULE_GENERATOR_SOURCE_ROOT ) ? MODULE_GENERATOR_SOURCE_ROOT.gsub('\\', '/').sub(/^\//, '').sub(/\/$/, '') : "src" ), + :path_inc => ((defined? MODULE_GENERATOR_INC_ROOT ) ? + MODULE_GENERATOR_INC_ROOT.gsub('\\', '/').sub(/^\//, '').sub(/\/$/, '') + : (defined? MODULE_GENERATOR_SOURCE_ROOT ) ? + MODULE_GENERATOR_SOURCE_ROOT.gsub('\\', '/').sub(/^\//, '').sub(/\/$/, '') + : "src" ), + :path_tst => ((defined? MODULE_GENERATOR_TEST_ROOT ) ? MODULE_GENERATOR_TEST_ROOT.gsub( '\\', '/').sub(/^\//, '').sub(/\/$/, '') : "test" ), + :pattern => optz[:pattern], + :test_prefix => ((defined? PROJECT_TEST_FILE_PREFIX ) ? PROJECT_TEST_FILE_PREFIX : "Test" ), + :mock_prefix => ((defined? CMOCK_MOCK_PREFIX ) ? CMOCK_MOCK_PREFIX : "Mock" ), + :includes => ((defined? MODULE_GENERATOR_INCLUDES ) ? MODULE_GENERATOR_INCLUDES : {} ), + :boilerplates => ((defined? MODULE_GENERATOR_BOILERPLATES) ? MODULE_GENERATOR_BOILERPLATES : {} ), + :naming => ((defined? MODULE_GENERATOR_NAMING ) ? MODULE_GENERATOR_NAMING : nil ), + :update_svn => ((defined? MODULE_GENERATOR_UPDATE_SVN ) ? MODULE_GENERATOR_UPDATE_SVN : false ), + } + + # Read Boilerplate template file. + if (defined? MODULE_GENERATOR_BOILERPLATE_FILES) + + bf = MODULE_GENERATOR_BOILERPLATE_FILES + + if !bf[:src].nil? && File.exists?(bf[:src]) + unity_generator_options[:boilerplates][:src] = File.read(bf[:src]) + end + + if !bf[:inc].nil? && File.exists?(bf[:inc]) + unity_generator_options[:boilerplates][:inc] = File.read(bf[:inc]) + end + + if !bf[:tst].nil? && File.exists?(bf[:tst]) + unity_generator_options[:boilerplates][:tst] = File.read(bf[:tst]) + end + end + + # If using "create[<module_root>:<module_name>]" option from command line. + unless optz[:module_root_path].to_s.empty? + unity_generator_options[:path_src] = File.join(optz[:module_root_path], unity_generator_options[:path_src]) + unity_generator_options[:path_inc] = File.join(optz[:module_root_path], unity_generator_options[:path_inc]) + unity_generator_options[:path_tst] = File.join(optz[:module_root_path], unity_generator_options[:path_tst]) + end + + return unity_generator_options + end + +end |