| # Licensed to the Apache Software Foundation (ASF) under one or more |
| # contributor license agreements. See the NOTICE file distributed with |
| # this work for additional information regarding copyright ownership. |
| # The ASF licenses this file to You under the Apache License, Version 2.0 |
| # (the "License"); you may not use this file except in compliance with |
| # the License. You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| require 'rbconfig' |
| require 'rake/clean' |
| |
| def exe_path(*args) |
| File.join(args).ext(RbConfig::CONFIG["EXEEXT"]) |
| end |
| |
| def obj_path(*args) |
| File.join(args).ext(RbConfig::CONFIG["OBJEXT"]) |
| end |
| |
| def cc_command |
| RbConfig::CONFIG["CC"] |
| end |
| |
| def make_command |
| command = RbConfig::CONFIG["make-prog"] |
| if !command |
| if RUBY_PLATFORM =~ /mswin/i |
| cc = cc_command |
| if cc =~ /^cl\b/ |
| command = "nmake" |
| else |
| command = "dmake" |
| end |
| else |
| command = "make" |
| end |
| end |
| return command |
| end |
| |
| def extra_ccflags |
| "" |
| end |
| |
| def all_ccflags |
| flags = RbConfig::CONFIG["CFLAGS"] + extra_ccflags |
| flags.gsub!(/"/, '\\"'); |
| flags |
| end |
| |
| def run_make(dir, params) |
| current_dir = Dir.pwd |
| chdir(dir) if dir |
| command = params.clone |
| command.unshift("CC=#{cc_command}") |
| if RUBY_PLATFORM =~ /mswin/i |
| if cc_command =~ /^cl\b/ |
| command.unshift("-f", "Makefile.MSVC") |
| else |
| command.unshift("-f", "Makefile.MinGW") |
| end |
| end |
| command.unshift(make_command) |
| success = system(*command) |
| if !success |
| raise "Make failed" |
| end |
| chdir(current_dir) if dir |
| end |
| |
| IS_DISTRO_NOT_DEVEL = File.directory?('core') |
| BASE_DIR = File.absolute_path(IS_DISTRO_NOT_DEVEL ? '.' : '..') |
| CHARMONIZER_ORIG_DIR = File.join(BASE_DIR, "charmonizer") |
| CHARMONIZE_EXE_PATH = exe_path(CHARMONIZER_ORIG_DIR, 'charmonize') |
| CHARMONY_PATH = "charmony.h" |
| |
| desc "Build the charmonize executable" |
| task :charmonize do |
| puts "Building #{CHARMONIZE_EXE_PATH}...\n" |
| run_make(CHARMONIZER_ORIG_DIR, []) |
| end |
| |
| desc "Run the charmonize executable, creating the charmony.h file" |
| task :charmony => [:charmonize] do |
| if !uptodate? CHARMONY_PATH, [CHARMONIZE_EXE_PATH] |
| puts "Writing #{CHARMONY_PATH}...\n" |
| command = [CHARMONIZE_EXE_PATH, cc_command, all_ccflags] |
| if ENV["CHARM_VALGRIND"] |
| command.unshift("valgrind", "--leak-check=yes") |
| end |
| success = system(*command); |
| if !success |
| raise "Failed to write charmony.h" |
| end |
| end |
| end |
| # Clean up after charmonize if it doesn't succeed on its own. |
| CLEAN.include("_charm*") |
| CLEAN.include(CHARMONY_PATH) |
| |
| desc "Build the charmonizer tests" |
| task :charmonizer_tests => [:charmony] do |
| puts "Building Charmonizer Tests...\n" |
| flags = all_ccflags + ' -I' + File.absolute_path(Dir.pwd) |
| args = ["CC=\"#{cc_command}\"", "DEFS=#{flags}", "tests"] |
| run_make(CHARMONIZER_ORIG_DIR, args) |
| end |
| |
| # Clean up after MSVC. |
| CLEAN.include("*.pdb") |
| |
| task :clean do |
| run_make(CHARMONIZER_ORIG_DIR, ["clean"]) |
| end |
| |
| task :test => [:charmonizer_tests] do |
| pattern = File.join(CHARMONIZER_ORIG_DIR, "Test*") |
| charm_tests = Dir.glob(pattern) |
| puts charm_tests |
| failed = [] |
| for charm_test in charm_tests |
| success = system(charm_test) |
| if !success |
| failed.push(charm_test) |
| end |
| end |
| if failed.length != 0 |
| puts "Failed: #{failed}" |
| else |
| puts "All tests pass" |
| end |
| end |
| |