1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512
|
# ****************************************************************************
#
# Copyright (c) Microsoft Corporation.
#
# This source code is subject to terms and conditions of the Microsoft Public License. A
# copy of the license can be found in the License.html file at the root of this distribution. If
# you cannot locate the Microsoft Public License, please send an email to
# ironruby@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
# by the terms of the Microsoft Public License.
#
# You must not remove this notice, or any other, from this software.
#
#
# ****************************************************************************
require 'rubygems'
require 'pathname2'
require 'rexml/document'
require 'fileutils'
require 'tempfile'
ENV['HOME'] ||= ENV['USERPROFILE']
EXCLUDED_EXTENSIONS = %w[.old .suo .vspscc .vssscc .user .log .pdb .cache .swp]
EXCLUDED_FILES = "dirs.proj makefile sources .gitignore"
DEFAULT_ROBOCOPY_OPTIONS = "/XF *#{EXCLUDED_EXTENSIONS.join(' *')} #{EXCLUDED_FILES} /XD .git /NP /COPY:DAT /A-:R "
CURRENT_DIR = File.dirname(File.expand_path(__FILE__))
class Pathname
def filtered_subdirs(extras = [])
return [] unless exist?
filtered_subdirs = subdirs.find_all { |dir| (dir.to_a & (EXCLUDED_DIRECTORIES + extras)) == [] }
result = filtered_subdirs.map { |dir| self + dir }
result.unshift self
end
def subdirs
glob("**/*", File::FNM_DOTMATCH).find_all { |path| (self + path).directory? }
end
def files
raise "Cannot call files on a filename path: #{self}" if !directory?
entries.find_all { |e| !(self + e).directory? }.sort
end
def filtered_files
raise "Cannot call filtered_files on a filename path: #{self}" if !directory?
files.find_all { |f| !EXCLUDED_EXTENSIONS.include?((self + f).extname) }
end
end
class Configuration
class Group
attr_reader :super_group
def initialize(name, super_group)
@name = name
@switches = {}
@references = []
@super_group = super_group
end
def switches(config, *args)
@switches[config] ||= []
@switches[config] += args
end
def references(*refs)
@references += refs
end
def remove_switches(config, *args)
args.each { |arg| @switches[config].delete arg } unless @switches[config].nil?
end
def get_switches(config)
all = @switches[:all].nil? ? [] : @switches[:all]
(@switches[config].nil? ? [] : @switches[config]) + all
end
def get_references
@references
end
def framework_path(*args, &b)
@framework_path = (if args.length == 0
b.call
elsif args.length == 1
args.first
else
raise 'framework_path must be called with either a path or a block that defines a path'
end << nil)
end
def resolve_framework_path(path)
@framework_path.each do |candidate|
raise "cannot resolve path #{path}" if candidate.nil?
candidate_path = candidate + path
break candidate_path if candidate_path.file?
end
end
end
def self.define(&b)
@master = {}
instance_eval(&b)
end
def self.group(*args, &b)
name = args.first
super_group = args.length == 2 ? @master[args.last] : nil
@master[name] ||= Group.new(name, super_group)
@master[name].instance_eval(&b)
end
def self.get_switches(group, config)
result = []
current = @master[group]
while !current.nil?
result += current.get_switches(config)
current = current.super_group
end
result
end
def self.get_references(group)
result = []
current = @master[group]
while !current.nil?
result += current.get_references
current = current.super_group
end
result.map { |assembly| resolve_framework_path(group, assembly) }
end
def self.resolve_framework_path(group, path)
@master[group].resolve_framework_path(path)
end
def self.mono?
return true if ENV['mono']
ENV['OS'] != "Windows_NT"
end
end
Configuration.define do
group(:common) {
switches :all, 'nologo', 'noconfig', 'nowarn:1591,1701,1702', 'errorreport:prompt', 'warn:4', 'warnaserror-'
switches :debug, 'define:"DEBUG;TRACE;MICROSOFT_SCRIPTING_CORE"', 'debug+', 'debug:full', 'optimize-'
switches :release, 'define:TRACE', 'optimize+'
references 'System.dll'
}
group(:desktop, :common) {
references 'System.Configuration.dll'
}
group(:silverlight, :common) {
switches :all, 'define:SILVERLIGHT', 'nostdlib+', 'platform:AnyCPU'
references 'mscorlib.dll'
}
unless mono?
group(:desktop) {
framework_path [Pathname.new(ENV['windir'].dup) + 'Microsoft.NET/Framework/v2.0.50727',
Pathname.new('c:/program files/reference assemblies/microsoft/framework/v3.5')]
}
group(:silverlight) {
framework_path [Pathname.new('c:/program files/microsoft silverlight/2.0.30523.6')]
}
else
group(:mono) {
framework_path {
libdir = IO.popen('pkg-config --variable=libdir mono').read.strip
path = [Pathname.new(libdir) + 'mono' + '2.0', Pathname.new('/usr/lib/mono/2.0/')]
path << Pathname.new(ENV['MONO_LIB'] + '/mono/2.0/') unless ENV['MONO_LIB'].nil?
path
}
switches :all, 'noconfig'
remove_switches ['warnaserror+']
}
end
end
module IronRubyUtils
def banner(message)
rake_output_message "-" * 79
rake_output_message message
rake_output_message "-" * 79
end
def copy_dir(source_dir, target_dir, options = '')
log_filename = Pathname.new(Dir.tmpdir) + "rake_transform.log"
exec_f %Q{robocopy "#{source_dir}" "#{target_dir}" #{DEFAULT_ROBOCOPY_OPTIONS} "/LOG+:#{log_filename}" #{options}}
end
# Low-level command helpers
def is_test?
ENV['test']
end
def mono?
Configuration.mono?
end
def rake_version
cmd = mono? ? "rake" : "rake.bat"
`#{cmd} --version`.chomp.gsub(/.*?(\d\.\d\.\d)/, '\1')
end
def exec(cmd)
if is_test?
rake_output_message ">> #{cmd}"
else
sh cmd
end
end
def exec_net(cmd)
unless mono?
exec cmd
else
exec "mono #{cmd}"
end
end
def exec_f(cmd)
begin
exec(cmd)
rescue
end
end
def configuration
ENV['configuration'] ? ENV['configuration'].to_sym : :debug
end
def platform
ENV['platform'].nil? ? :windows : ENV['platform'].to_sym
end
def clr
unless mono?
ENV['clr'] ? ENV['clr'].to_sym : :desktop
else
:mono
end
end
def build_path
project_root + Pathname.new(File.join("Bin", "#{clr == :desktop ? configuration : "#{clr}_#{configuration}"}"))
end
def project_root
Pathname.new(File.expand_path(File.join(CURRENT_DIR, "..","..")))
end
end
class CSProjCompiler
include IronRubyUtils
def initialize(&b)
@targets = {}
instance_eval(&b)
end
def dir(target)
Pathname.new(@targets[target][:dir])
end
def compile(name)
banner name.to_s
args = @targets[name.to_sym]
working_dir = File.expand_path(args[:dir], File.dirname(__FILE__))
build_dir = build_path
Dir.chdir(working_dir) do |p|
cs_args = ["out:\"#{build_dir + args[:output]}\""]
cs_args += references(args[:references], working_dir).map { |ref| "r:\"#{ref}\"" }
cs_args += compiler_switches
cs_args += args[:switches] if args[:switches]
if args[:resources]
resgen working_dir, args[:resources]
args[:resources].each_value { |res| cs_args << "resource:\"#{build_path + res}\"" }
end
cmd = ''
cmd << CS_COMPILER
if cs_args.include?('noconfig')
cs_args.delete('noconfig')
cmd << " /noconfig"
end
temp = Tempfile.new(name.to_s)
cs_args.each { |opt| temp << ' /' + opt + "\n"}
options = get_compile_path_list(args[:csproj]).join("\n")
temp.puts options
temp.close
cmd << " @" << temp.path
exec cmd
end
end
def get_case_sensitive_path(pathname)
return "../AssemblyVersion.cs" if pathname == "..\\AssemblyVersion.cs"
elements = pathname.split '\\'
result = Pathname.new '.'
elements.each do |element|
entry = result.entries.find { |p| p.downcase == element.downcase }
result = result + entry unless entry.nil?
end
result.to_s
end
def get_compile_path_list(csproj)
csproj ||= '*.csproj'
cs_proj_files = Dir[csproj]
if cs_proj_files.length == 1
doc = REXML::Document.new(File.open(cs_proj_files.first))
result = doc.elements.collect("/Project/ItemGroup/Compile") { |c| c.attributes['Include'] }
result.delete_if { |e| e =~ /(Silverlight\\SilverlightVersion.cs|System\\Dynamic\\Parameterized.System.Dynamic.cs)|\.\./ }
result.map! { |p| get_case_sensitive_path(p) } if mono?
result
else
raise ArgumentError.new("Found more than one .csproj file in directory! #{cs_proj_files.join(", ")}")
end
end
def resgen(base_path, resource_map)
base_path = Pathname.new(base_path)
resource_map.each_pair do |input, output|
exec %Q{resgen "#{base_path + input.dup}" "#{build_path + output}"}
end
end
def resolve_framework_path(file)
Configuration.resolve_framework_path(clr, file)
end
def compiler_switches
Configuration.get_switches(clr, configuration)
end
def references(refs, working_dir)
references = Configuration.get_references(clr)
refs.each do |ref|
references << if ref =~ /^\!/
resolve_framework_path(ref[1..-1])
else
(build_path + ref).relative_path_from(working_dir)
end
end if refs
references
end
def clean
FileUtils.rm_rf build_path
FileUtils.mkdir_p build_path
end
def transform_config(source_path, target_path, paths)
file = File.new source_path
doc = Document.new file
# replace LibraryPaths
options = XPath.each(doc, '/configuration/microsoft.scripting/options/set') do |node|
if node.attributes['language'] == 'Ruby' && node.attributes['option'] == 'LibraryPaths'
node.attributes['value'] = paths
end
end
File.open(target_path, 'w+') do |f|
f.write doc.to_s
end
end
def transform_config_file(configuration, source_path, target_build_path)
# signing is on for IronRuby in Merlin, off for SVN and Binary
layout = {'Merlin' => { :LibraryPaths => '..\..\Languages\Ruby\libs;..\..\..\External.LCA_RESTRICTED\Languages\Ruby\Ruby-1.8.6p287\lib\ruby\site_ruby\1.8;..\..\..\External.LCA_RESTRICTED\Languages\Ruby\Ruby-1.8.6p287\lib\ruby\site_ruby;..\..\..\External.LCA_RESTRICTED\Languages\Ruby\Ruby-1.8.6p287\lib\ruby\1.8' },
'Binary' => { :LibraryPaths => '..\lib\IronRuby;..\lib\ruby\site_ruby\1.8;..\lib\ruby\site_ruby;..\lib\ruby\1.8' },
'MerlinMono' => { :LibraryPaths => '../../Languages/Ruby/libs;../../../External.LCA_RESTRICTED/Languages/Ruby/Ruby-1.8.6p287/lib/ruby/site_ruby/1.8;../../../External.LCA_RESTRICTED/Languages/Ruby/Ruby-1.8.6p287/lib/ruby/site_ruby;../../../External.LCA_RESTRICTED/Languages/Ruby/Ruby-1.8.6p287/lib/ruby/1.8' },
'MonoRL' => { :LibraryPaths => '../lib;../lib/ironruby;../lib/ruby/site_ruby/1.8/;../lib/ruby/site_ruby/;../lib/ruby/1.8/' } }
transform_config source_path, target_build_path, layout[configuration][:LibraryPaths]
end
def move_config(name = "ir.exe.config")
source = project_root + "Config/Unsigned/App.config"
config_file = build_path + name
transform_config_file(mono? ? ((ENV['configuration']||:debug).to_sym == :debug ? 'MerlinMono' : 'MonoRL' ) : 'Merlin', source, config_file)
end
def method_missing(name, *args)
@targets[name.to_sym] = *args
end
end
IronRubyCompiler = CSProjCompiler.new do
#====================================================================
# DLR
#====================================================================
dlr_core :references => ['!System.dll','!System.Configuration.dll','Microsoft.Scripting.ExtensionAttribute.dll'],
:switches => ['target:library', 'define:MICROSOFT_SCRIPTING_CORE'],
:output => 'Microsoft.Scripting.Core.dll',
:csproj => 'Microsoft.Scripting.Core.csproj',
:dir => '../../../../ndp/fx/src/Core/Microsoft/Scripting'
dlr_extension :references => ['!System.dll'],
:switches => ['target:library'],
:output => 'Microsoft.Scripting.ExtensionAttribute.dll',
:csproj => 'Microsoft.Scripting.ExtensionAttribute.csproj',
:dir => '../../../../ndp/fx/src/Core/Microsoft/Scripting'
dlr_libs :references => ['Microsoft.Scripting.Core.dll', '!System.Xml.dll', '!System.dll', '!System.Configuration.dll', 'Microsoft.Scripting.ExtensionAttribute.dll','!System.Runtime.Remoting.dll'],
:switches => ['target:library'],
:resources => {Pathname.new('Math') + 'MathResources.resx' => Pathname.new('Microsoft.Scripting.Math.MathResources.resources')},
:output => 'Microsoft.Scripting.dll',
:csproj => 'Microsoft.Scripting.csproj',
:dir => '../../Runtime/Microsoft.Scripting'
dlr_com :references => ['Microsoft.Scripting.Core.dll', '!System.Xml.dll', '!System.dll', 'Microsoft.Scripting.ExtensionAttribute.dll'],
:switches => ['target:library', 'unsafe', 'define:MICROSOFT_DYNAMIC;CLR2'],
:output => 'Microsoft.Dynamic.dll',
:csproj => 'Microsoft.Dynamic.csproj',
:dir => '../../../../ndp/fx/src/Dynamic/System/Dynamic'
dlr_debug :references => ['!System.dll', 'Microsoft.Scripting.Core.dll', 'Microsoft.Scripting.dll','Microsoft.Scripting.ExtensionAttribute.dll'],
:switches => ['target:library'],
:output => 'Microsoft.Scripting.Debugging.dll',
:csproj => 'Microsoft.Scripting.Debugging.csproj',
:dir => '../../Debugging/Microsoft.Scripting.Debugging'
#====================================================================
# IRONRUBY
#====================================================================
generator :references => ['Microsoft.Scripting.Core.dll', 'Microsoft.Scripting.dll','Microsoft.Scripting.ExtensionAttribute.dll', 'IronRuby.dll', '!System.dll'],
:output => 'ClassInitGenerator.exe',
:dir => './ClassInitGenerator'
ironruby :references => ['Microsoft.Scripting.Core.dll', 'Microsoft.Scripting.dll', 'Microsoft.Scripting.ExtensionAttribute.dll', 'Microsoft.Dynamic.dll', '!System.dll', '!System.Configuration.dll'],
:switches => ['target:library'],
:output => 'IronRuby.dll',
:dir => './Ruby',
:csproj => 'Ruby.csproj'
libraries :references => ['Microsoft.Scripting.Core.dll', 'Microsoft.Scripting.dll', 'Microsoft.Scripting.ExtensionAttribute.dll', 'IronRuby.dll', '!System.dll'],
:switches => ['target:library'],
:output => 'IronRuby.Libraries.dll',
:dir => 'Libraries.LCA_RESTRICTED',
:csproj => 'IronRuby.Libraries.csproj'
console :references => ['Microsoft.Scripting.Core.dll','Microsoft.Scripting.dll','IronRuby.dll'],
:output => 'ir.exe',
:dir => './Console',
:csproj => 'Ruby.Console.csproj'
test_runner :references => ['Microsoft.Scripting.Core.dll', 'Microsoft.Scripting.dll', 'Microsoft.Scripting.ExtensionAttribute.dll', 'IronRuby.dll', 'IronRuby.Libraries.dll', '!System.dll', '!System.Windows.Forms.dll'],
:output => 'IronRuby.Tests.exe',
:dir => './IronRuby.Tests',
:csproj => 'IronRuby.Tests.csproj'
scanner :references => ['Microsoft.Scripting.Core.dll', 'Microsoft.Scripting.dll', 'IronRuby.dll', 'IronRuby.Libraries.dll', '!System.Core.dll'],
:output => 'IronRuby.Libraries.Scanner.exe',
:dir => './IronRuby.Libraries.Scanner'
yaml :references => ['Microsoft.Scripting.Core.dll', 'Microsoft.Scripting.dll', 'IronRuby.dll', 'IronRuby.Libraries.dll', '!System.dll'],
:switches => ['target:library'],
:output => 'IronRuby.Libraries.Yaml.dll',
:dir => '../../../External.LCA_RESTRICTED/Languages/IronRuby/Yaml/IronRuby.Libraries.Yaml',
:csproj => 'IronRuby.Libraries.Yaml.csproj'
#====================================================================
# IRONPYTHON
#====================================================================
ironpython :references => ['Microsoft.Dynamic.dll', 'Microsoft.Scripting.Core.dll', 'Microsoft.Scripting.dll', 'Microsoft.Scripting.ExtensionAttribute.dll', '!System.Data.dll', '!System.dll', '!System.Xml.dll', 'Microsoft.Scripting.Debugging.dll'],
:switches => ['target:library'],
:output => 'IronPython.dll',
:resources => {Pathname.new('Resources.resx') => Pathname.new('IronPython.Resources.resources')},
:dir => '../IronPython/IronPython',
:csproj => 'IronPython.csproj'
ipyw :references => ['IronPython.dll', 'Microsoft.Scripting.Core.dll', 'Microsoft.Scripting.dll', '!System.dll', '!System.Windows.Forms.dll'],
:switches => ['target:winexe', "define:IRONPYTHON_WINDOW", "win32icon:ipy.ico"],
:output => 'ipyw.exe',
:dir => '../IronPython/IronPythonWindow',
:csproj => 'IronPythonWindow.csproj'
#ironpython_test :references => ['IronPython.dll', 'Microsoft.Scripting.Core.dll', 'Microsoft.Scripting.dll', '!System.Data.dll', '!System.dll', '!System.Xml.dll', 'Interop.Shell32.dll'],
#:switches => ['target:library'],
#:output => 'IronPythonTest.dll',
#:dir => '../IronPython/IronPythonTest',
#:csproj => 'IronPythonTest.csproj'
ipy :references => ['IronPython.dll', 'Microsoft.Scripting.Core.dll','Microsoft.Scripting.dll', '!System.dll'],
:switches => ['target:exe', 'win32icon:ipy.ico'],
:output => 'ipy.exe',
:dir => '../IronPython/IronPythonConsole',
:csproj => 'IronPythonConsole.csproj'
ironpython_modules :references => ['IronPython.dll', 'Microsoft.Scripting.Core.dll', 'Microsoft.Scripting.dll', 'Microsoft.Scripting.ExtensionAttribute.dll', '!System.Data.dll', '!System.dll', '!System.Xml.dll'],
:switches => ['target:library'],
:output => 'IronPython.Modules.dll',
:dir => '../IronPython/IronPython.Modules',
:csproj => 'IronPython.Modules.csproj'
end
|