Sha256: 9a253f745eed7bbd27289d9a1b5f448c80f5879d6e03bf4ef7883fc3edfbf5af

Contents?: true

Size: 1.55 KB

Versions: 30

Compression:

Stored size: 1.55 KB

Contents

require "rubygems"
require "rake"
require "mkmf"
require "erb"
require_relative "../../lib/chef/dist"

desc "Building event log dll"

def ensure_present(commands)
  commands.each do |c|
    unless find_executable c
      warn "Could not find #{c}. Windows Event Logging will not correctly function."
    end
  end
end

# Templating the windows event log messages
# So we can inject distro constants in there
template = ERB.new(IO.read("chef-log.man.erb"))
chef_log_man = template.result
File.open("chef-log.man", "w") { |f| f.write(chef_log_man) }

EVT_MC_FILE = "chef-log.man".freeze
EVT_RC_FILE = "chef-log.rc".freeze
EVT_RESOURCE_OBJECT = "resource.o".freeze
EVT_SHARED_OBJECT = "chef-log.dll".freeze
MC = "windmc".freeze
RC = "windres".freeze
CC = "gcc".freeze

ensure_present [MC, RC, CC]

task build: [EVT_RESOURCE_OBJECT, EVT_SHARED_OBJECT]
task default: %i{build register}

file EVT_RC_FILE => EVT_MC_FILE do
  sh "#{MC} #{EVT_MC_FILE}"
end

file EVT_RESOURCE_OBJECT => EVT_RC_FILE do
  sh "#{RC} -i #{EVT_RC_FILE} -o #{EVT_RESOURCE_OBJECT}"
end

file EVT_SHARED_OBJECT => EVT_RESOURCE_OBJECT do
  sh "#{CC} -o #{EVT_SHARED_OBJECT} -shared #{EVT_RESOURCE_OBJECT}"
end

task register: EVT_SHARED_OBJECT do
  require "win32/eventlog"
  dll_file = File.expand_path(EVT_SHARED_OBJECT)
  begin
    Win32::EventLog.add_event_source(
      source: "Application",
      key_name: Chef::Dist::SHORT,
      event_message_file: dll_file,
      category_message_file: dll_file
    )
  rescue Errno::EIO => e
    puts "Skipping event log registration due to missing privileges: #{e}"
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
chef-15.17.4-universal-mingw32 ext/win32-eventlog/Rakefile
chef-15.16.7-universal-mingw32 ext/win32-eventlog/Rakefile
chef-15.16.4-universal-mingw32 ext/win32-eventlog/Rakefile
chef-15.16.2-universal-mingw32 ext/win32-eventlog/Rakefile
chef-15.15.0-universal-mingw32 ext/win32-eventlog/Rakefile
chef-15.14.0-universal-mingw32 ext/win32-eventlog/Rakefile
chef-16.4.41-universal-mingw32 ext/win32-eventlog/Rakefile
chef-16.4.38-universal-mingw32 ext/win32-eventlog/Rakefile
chef-16.4.35-universal-mingw32 ext/win32-eventlog/Rakefile
chef-16.3.45-universal-mingw32 ext/win32-eventlog/Rakefile
chef-15.13.8-universal-mingw32 ext/win32-eventlog/Rakefile
chef-16.3.38-universal-mingw32 ext/win32-eventlog/Rakefile
chef-16.2.73-universal-mingw32 ext/win32-eventlog/Rakefile
chef-15.12.22-universal-mingw32 ext/win32-eventlog/Rakefile
chef-16.2.50-universal-mingw32 ext/win32-eventlog/Rakefile
chef-16.2.44-universal-mingw32 ext/win32-eventlog/Rakefile
chef-15.11.8-universal-mingw32 ext/win32-eventlog/Rakefile
chef-16.1.16-universal-mingw32 ext/win32-eventlog/Rakefile
chef-15.11.3-universal-mingw32 ext/win32-eventlog/Rakefile
chef-16.1.0-universal-mingw32 ext/win32-eventlog/Rakefile