Class: MTBuild::Application

Inherits:
Rake::Application
  • Object
show all
Includes:
Rake::DSL
Defined in:
lib/mtbuild/application.rb

Overview

This subclasses the Rake::Application class to override default Rake behaviors with MTBuild-specific behaviors

Constant Summary collapse

DEFAULT_RAKEFILES =

Default list of mtbuildfile names

[
  'mtbuildfile',
  'MTBuildfile',
  'mtbuildfile.rb',
  'MTBuildfile.rb'
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Rake::DSL

#application_task, #framework_task, #static_library_task, #test_application_task

Constructor Details

#initializeApplication

This overrides the default rakefile names with the mtbuildfile names



28
29
30
31
# File 'lib/mtbuild/application.rb', line 28

def initialize
  super
  @rakefiles = DEFAULT_RAKEFILES.dup
end

Instance Attribute Details

#rakefilesObject (readonly)

List of rakefile names to look for



17
18
19
# File 'lib/mtbuild/application.rb', line 17

def rakefiles
  @rakefiles
end

Instance Method Details

#create_default_task_if_none_existsObject



78
79
80
81
82
83
84
85
# File 'lib/mtbuild/application.rb', line 78

def create_default_task_if_none_exists
  if lookup(default_task_name).nil?
    task default_task_name do
      puts 'Nothing to do because no projects specified default tasks.'
      puts 'Use the -T flag to see the list of tasks you can build.'
    end
  end
end

#default_task_nameObject



87
88
89
# File 'lib/mtbuild/application.rb', line 87

def default_task_name
  'all'
end

#init(app_name = 'mtbuild') ⇒ Object

Override init to pass mtbuild as the app name



43
44
45
# File 'lib/mtbuild/application.rb', line 43

def init(app_name='mtbuild')
  super
end

#runObject



33
34
35
36
37
38
39
40
# File 'lib/mtbuild/application.rb', line 33

def run
  standard_exception_handling do
    init
    load_rakefile
    create_default_task_if_none_exists
    top_level
  end
end

#standard_rake_optionsObject

This modifies Rake’s command line options to do MTBuild-specific things



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/mtbuild/application.rb', line 48

def standard_rake_options
  # This hijacks the "--version" flag and displays the MTBuild version along
  # with the Rake version.
  options = super.map do |opt|
    if opt.first == '--version'
      ['--version', '-V',
        "Display the program version.",
        lambda { |value|
          puts "mtbuild, version #{MTBuild::VERSION}"
          puts "rake, version #{Rake::VERSION}"
          exit
        }
      ]
    else
      opt
    end
  end
  # This adds MTBuild-specific options
  options |= [
      ['--super-dry-run',
       "Do a dry run printing actions, but not executing them.",
       lambda { |value|
         Rake.verbose(true)
         Rake.nowrite(true)
       }
      ],
  ]
  sort_options(options)
end