34
35
36
37
38
39
40
41
42
43
44
45
46
47
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
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/windows_gui/uiribbon.rb', line 34
def Build(opts = {})
opts[:name] ||= File.basename($0, '.rbw')
path = File.dirname(File.expand_path($0))
xml_path = "#{path}/#{opts[:name]}.xml"
rb_path = "#{path}/#{opts[:name]}.rb"
dll_path = "#{path}/#{opts[:name]}.dll"
log_path = "#{path}/#{opts[:name]}.log"
opts[:sdkroot] ||= "#{ENV['ProgramFiles']}/Windows Kits/10"
opts[:vcroot] ||= "#{ENV['ProgramFiles']}/Microsoft Visual Studio 14.0/VC"
opts[:uicc] ||= "#{opts[:sdkroot]}/bin/x86/uicc.exe"
opts[:rc] ||= "#{opts[:sdkroot]}/bin/x86/rc.exe"
opts[:vcvars] ||= "#{opts[:vcroot]}/bin/vcvars32.bat"
opts[:link] ||= "#{opts[:vcroot]}/bin/link.exe"
raise 'Building the UIRibbon resources requires Windows SDK and VC' unless
[:uicc, :rc, :vcvars, :link].all? { |tool| File.exist?(opts[tool]) }
STDERR.puts "UIRibbon resources build toolchain OK"
File.delete(log_path) if File.exist?(log_path)
system <<-CMD
@echo off && \
"#{opts[:uicc]}" "#{opts[:name]}.xml" "#{opts[:name]}.bml" /header:"#{opts[:name]}.h" /res:"#{opts[:name]}.rc" > "#{opts[:name]}.log" && \
"#{opts[:rc]}" /nologo /fo"#{ENV['TEMP']}/#{opts[:name]}.res" "#{opts[:name]}.rc" >> "#{opts[:name]}.log" && \
call "#{opts[:vcvars]}" >> "#{opts[:name]}.log" && \
"#{opts[:link]}" /nologo /machine:x86 /dll /noentry /out:"#{opts[:name]}.dll" "#{ENV['TEMP']}/#{opts[:name]}.res" >> "#{opts[:name]}.log"
CMD
if File.read(log_path) =~ /error/im
ShellExecute(nil, L('open'), L(log_path.dup), nil, nil, SW_SHOWNORMAL) if
opts[:open_log_if_failed]
raise "UIRibbon resources build FAILED - see #{log_path} for details"
end
File.open(rb_path, 'w') { |rb|
rb.puts "# Generated by the UIRibbon build, do NOT modify\n\n"
File.foreach("#{path}/#{opts[:name]}.h") { |line|
rb.puts "#{$1[0].upcase}#{$1[1..-1]} = #{$2}" if line =~ /^\s*#define\s+(\w+)\s+(\d+)/
}
}
%w{bml h rc}.each { |ext|
File.delete("#{path}/#{opts[:name]}.#{ext}") if File.exist?("#{path}/#{opts[:name]}.#{ext}")
} if opts[:clean_byproducts]
STDERR.puts "UIRibbon resources build succeeded"
end
|