Class: OpenmsxBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/openmsx_builder.rb

Defined Under Namespace

Classes: NotConfigured

Constant Summary collapse

CONFIG_FILENAME =
File.expand_path('~/.openMSX-builder.yaml')
DEFAULTS =
{
  :projects => {
    :openmsx => {
      :source_dir => File.expand_path("~/Development/openMSX"),
      :builds_subdir => 'derived/univ-darwin-opt-3rd',
      :report_bcc => [],
      :report_from => "openMSX auto-builder by FiXato <[email protected]>",
      :nice_name => 'openMSX (universal)',
      :publish_location => 'ssh_host:path/to/existing/publish/dir',
      :site_path => 'http://your.host.example/publish/dir',
      :target_cpu => 'univ',
    },
    :openmsx_x86 => {
      :source_dir => File.expand_path("~/Development/openMSX"),
      :builds_subdir => 'derived/x86-darwin-opt-3rd',
      :report_bcc => [],
      :report_from => "openMSX auto-builder by FiXato <[email protected]>",
      :nice_name => 'openMSX (x86)',
      :publish_location => 'ssh_host:path/to/existing/publish/dir',
      :site_path => 'http://your.host.example/publish/dir',
      :target_cpu => 'x86',
    },
    :openmsx_ppc => {
      :source_dir => File.expand_path("~/Development/openMSX"),
      :builds_subdir => 'derived/ppc-darwin-opt-3rd',
      :report_bcc => [],
      :report_from => "openMSX auto-builder by FiXato <[email protected]>",
      :nice_name => 'openMSX (ppc)',
      :publish_location => 'ssh_host:path/to/existing/publish/dir',
      :site_path => 'http://your.host.example/publish/dir',
      :target_cpu => 'ppc',
    },
    :openmsx_debugger => {
      :source_dir => File.expand_path("~/Development/openmsx-debugger"),
      :builds_subdir => 'derived',
      :report_bcc => [],
      :report_from => "openMSX auto-builder by FiXato <[email protected]>",
      :nice_name => 'openMSX Debugger',
      :publish_location => 'ssh_host:path/to/existing/publish/dir',
      :site_path => 'http://your.host.example/publish/dir',
    },
  },
  :smtp_settings => {
    :address              => "mail.example",
    :port                 => 25,
    :domain               => 'mail.example',
    :user_name            => '[email protected]',
    :password             => '',
    :authentication       => :plain,
    :enable_starttls_auto => true
  },
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, type = :openmsx) ⇒ OpenmsxBuilder

Returns a new instance of OpenmsxBuilder.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/openmsx_builder.rb', line 63

def initialize(options,type=:openmsx)
  @options = options
  @type = type
  @log = Logger.new(STDOUT)
  @log.level = Logger::FATAL
  @log.level = Logger::ERROR if @options.include?('--log-errors')
  @log.level = Logger::WARN if @options.include?('--warn')
  @log.level = Logger::INFO if @options.include?('--verbose')
  @log.level = Logger::DEBUG if @options.include?('--debug')
  @log.debug("Logger created with level #{@log.level}")
  @current_revision = `svnversion -cn #{setting(:source_dir)}`.split(':').last.to_i
  @fails = 0
  @build_outputs = []
  config
rescue NotConfigured => e
  @log.fatal e.message
  exit
end

Instance Attribute Details

#build_outputsObject

Returns the value of attribute build_outputs.



62
63
64
# File 'lib/openmsx_builder.rb', line 62

def build_outputs
  @build_outputs
end

#typeObject

Returns the value of attribute type.



62
63
64
# File 'lib/openmsx_builder.rb', line 62

def type
  @type
end

Instance Method Details

#configObject

Raises:



82
83
84
85
86
87
# File 'lib/openmsx_builder.rb', line 82

def config
  create_default_config unless File.exist?(CONFIG_FILENAME)
  @config ||= YAML.load_file(CONFIG_FILENAME)
  raise NotConfigured.new("You need to set up your config file at #{CONFIG_FILENAME} first") if @config == DEFAULTS
  @config
end

#create_default_configObject



89
90
91
92
93
94
# File 'lib/openmsx_builder.rb', line 89

def create_default_config
  system("mkdir -p #{File.dirname(CONFIG_FILENAME)}")
  File.open(CONFIG_FILENAME,'w') do |f|
    f.write DEFAULTS.to_yaml
  end
end

#publish_allObject



96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/openmsx_builder.rb', line 96

def publish_all
  @log.info "Publishing all #{@type} builds found"
  if openmsx?
    regexp = /openmsx-.+-(\d+)-mac-univ-bin.dmg$/
  elsif openmsx_debugger?
    regexp = /openMSX-debugger-(\d+)-mac-x86.tbz$/
  end
  Dir.glob(filemask_for_revision('*')).sort.each do |file|
    publish_revision($1,file) if file =~ regexp
  end
  nil
end

#publish_revision(revision, archive_name = nil) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/openmsx_builder.rb', line 109

def publish_revision(revision,archive_name=nil)
  if archive_name.nil?
    if openmsx?
      archive_name = Dir.glob(filemask_for_revision(revision)).first
    elsif openmsx_debugger?
      archive_name = filemask_for_revision(revision)
      archive(File.join(setting(:source_dir),setting(:builds_subdir),'openMSX_Debugger.app'),File.basename(archive_name))
    end
  end

  destination = File.join(setting(:publish_location),File.basename(archive_name))
  @log.info "Publishing '#{archive_name}' to '#{destination}'."
  @log.debug `scp -p "#{archive_name}" #{destination}`

  return nil unless @options.include?('--tweet')
  url = File.join(setting(:site_path),File.basename(archive_name))
  message = "[#{setting(:nice_name)}] Revision #{revision} is now available:\r\n #{url}"
  tweetmsx.update(message)
rescue TweetMsx::NotConfigured => e
  @log.error e.message
end

#runObject



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/openmsx_builder.rb', line 135

def run
  return publish_all if @options.include?('--publish-all')
  return publish_revision(@current_revision) if @options.include?('--publish-current')
  if @options.include?('--dont-update')
    @new_revision = @current_revision
    @log.info "Update skipped. Still at revision #{@new_revision}"
  else
    update_svn
  end

  if @new_revision >= @current_revision
    @log.info "Revision #{@new_revision} is not older than #{@current_revision}. Proceeding with build."
    build unless already_built?(@new_revision)
  end
end

#setting(key) ⇒ Object



131
132
133
# File 'lib/openmsx_builder.rb', line 131

def setting(key)
  config[:projects][type][key]
end

#update_svnObject



151
152
153
154
155
156
157
# File 'lib/openmsx_builder.rb', line 151

def update_svn
  @log.info "openMSX is currently at #{@current_revision}. Proceeding with `svn update`"
  @log.debug `cd #{setting(:source_dir)} && svn up`
  @new_revision = `svnversion -nc #{setting(:source_dir)}`.split(':').last.to_i
  @log.info "Now at revision #{@new_revision}"
  nil
end