ceedling.rb 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. ##
  2. # This module defines the interface for interacting with and loading a project
  3. # with Ceedling.
  4. module Ceedling
  5. ##
  6. # Returns the location where the gem is installed.
  7. # === Return
  8. # _String_ - The location where the gem lives.
  9. def self.location
  10. File.join( File.dirname(__FILE__), '..')
  11. end
  12. ##
  13. # Return the path to the "built-in" plugins.
  14. # === Return
  15. # _String_ - The path where the default plugins live.
  16. def self.load_path
  17. File.join( self.location, 'plugins')
  18. end
  19. ##
  20. # Return the path to the Ceedling Rakefile
  21. # === Return
  22. # _String_
  23. def self.rakefile
  24. File.join( self.location, 'lib', 'ceedling', 'rakefile.rb' )
  25. end
  26. ##
  27. # This method selects the project file that Ceedling will use by setting the
  28. # CEEDLING_MAIN_PROJECT_FILE environment variable before loading the ceedling
  29. # rakefile. A path supplied as an argument to this method will override the
  30. # current value of the environment variable. If no path is supplied as an
  31. # argument then the existing value of the environment variable is used. If
  32. # the environment variable has not been set and no argument has been supplied
  33. # then a default path of './project.yml' will be used.
  34. #
  35. # === Arguments
  36. # +options+ _Hash_::
  37. # A hash containing the options for ceedling. Currently the following
  38. # options are supported:
  39. # * +config+ - The path to the project YAML configuration file.
  40. # * +root+ - The root of the project directory.
  41. # * +prefix+ - A prefix to prepend to plugin names in order to determine the
  42. # corresponding gem name.
  43. # * +plugins+ - The list of ceedling plugins to load
  44. def self.load_project(options = {})
  45. # Make sure our path to the yaml file is setup
  46. if options.has_key? :config
  47. ENV['CEEDLING_MAIN_PROJECT_FILE'] = options[:config]
  48. elsif ENV['CEEDLING_MAIN_PROJECT_FILE'].nil?
  49. ENV['CEEDLING_MAIN_PROJECT_FILE'] = './project.yml'
  50. end
  51. # Register the plugins
  52. if options.has_key? :plugins
  53. options[:plugins].each do |plugin|
  54. register_plugin( plugin, options[:prefix] )
  55. end
  56. end
  57. # Define the root of the project if specified
  58. Object.const_set('PROJECT_ROOT', options[:root]) if options.has_key? :root
  59. # Load ceedling
  60. load "#{self.rakefile}"
  61. end
  62. ##
  63. # Register a plugin for ceedling to use when a project is loaded. This method
  64. # *must* be called prior to calling the _load_project_ method.
  65. #
  66. # This method is intended to be used for loading plugins distributed via the
  67. # RubyGems mechanism. As such, the following gem structure is assumed for
  68. # plugins.
  69. #
  70. # * The gem name must be prefixed with 'ceedling-' followed by the plugin
  71. # name (ex. 'ceedling-bullseye')
  72. #
  73. # * The contents of the plugin must be isntalled into a subdirectory of
  74. # the gem with the same name as the plugin (ex. 'bullseye/')
  75. #
  76. # === Arguments
  77. # +name+ _String_:: The name of the plugin to load.
  78. # +prefix+ _String_::
  79. # (optional, default = nil) The prefix to use for the full gem name.
  80. def self.register_plugin(name, prefix=nil)
  81. # Figure out the full name of the gem and location
  82. prefix ||= 'ceedling-'
  83. gem_name = prefix + name
  84. gem_dir = Gem::Specification.find_by_name(gem_name).gem_dir()
  85. # Register the plugin with Ceedling
  86. require 'ceedling/defaults'
  87. DEFAULT_CEEDLING_CONFIG[:plugins][:enabled] << name
  88. DEFAULT_CEEDLING_CONFIG[:plugins][:load_paths] << gem_dir
  89. end
  90. end