# 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' gem 'rake-compiler' require 'rake/extensiontask' 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') AUTOGEN_DIR = "autogen" BASE_DIR = File.absolute_path(IS_DISTRO_NOT_DEVEL ? '.' : '..') CHARMONIZER_ORIG_DIR = File.join(BASE_DIR, "charmonizer") CHARMONIZE_C_PATH = File.absolute_path('charmonize.c') CHARMONIZE_EXE_PATH = File.absolute_path(exe_path('charmonize')) CLOWNFISH_PATH = File.join(BASE_DIR,"clownfish","ruby") CHARMONY_PATH = "charmony.h" CORE_SOURCE_DIR = File.join(BASE_DIR, "core") desc "Build clownfish" task :clownfish => [:charmonizer_tests] do puts "Building clownfish...\n" build_cfc require_relative File.join(CLOWNFISH_PATH,"ext","Clownfish","CFC") puts "Parsing Clownfish files...\n"; hierarchy_obj = compile_clownfish core_binding_obj = Clownfish::CFC::Binding::Core.new( hierarchy_obj, AUTOGEN_DIR, autogen_header, '', ) puts "Writing Clownfish autogenerated files...\n" modified = core_binding_obj.write_all_modified end desc "Build the charmonize executable" task :charmonize do puts "Building #{CHARMONIZE_EXE_PATH}...\n" meld_c = File.absolute_path("charmonize.c") charmonize_main = File.join(CHARMONIZER_ORIG_DIR, 'charmonize.c') run_make_args = [ "meld", "FILES=#{charmonize_main}", "OUT=#{meld_c}" ] run_make(CHARMONIZER_ORIG_DIR, run_make_args) if !uptodate?(CHARMONIZE_EXE_PATH, [meld_c]) outflag = cc_command.match(/cl\b/) ? "/Fe" : "-o " command = "#{cc_command} #{outflag}#{CHARMONIZE_EXE_PATH} #{meld_c}" puts command success = system(command) if !success raise "Failed to write charmony.h" end end end CLEAN.include(CHARMONIZE_C_PATH) CLEAN.include(CHARMONIZE_EXE_PATH) 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=\"#{cc_command}\"", "--enable-c", "--", all_ccflags ] if ENV["CHARM_VALGRIND"] command.unshift("valgrind", "--leak-check=yes") end puts command.join(" ") 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 def autogen_header return <<"END_AUTOGEN"; /*********************************************** !!!! DO NOT EDIT !!!! This file was auto-generated by Rakefile ***********************************************/ /* 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. */ END_AUTOGEN end def compile_clownfish hierarchy_obj = Clownfish::CFC::Model::Hierarchy.new(CORE_SOURCE_DIR, AUTOGEN_DIR) hierarchy_obj.build return hierarchy_obj end def build_cfc Dir.chdir(CLOWNFISH_PATH) do if system('rake clownfish').nil? abort "Failed to make clownfish" end end end