From: donghee yang Date: Sat, 22 Sep 2012 01:23:46 +0000 (+0900) Subject: [Title] Fixed a but that "log wraaper" process does not work on windows X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7eebd60bbb698c0f5caa24e1e9193d6f1ef2a10e;p=sdk%2Ftools%2Fsdk-build.git [Title] Fixed a but that "log wraaper" process does not work on windows --- diff --git a/src/common/execute_with_log b/src/common/execute_with_log deleted file mode 100755 index 3a0bddd..0000000 --- a/src/common/execute_with_log +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/ruby - -require 'logger' - -# parse arguments -cmd = ARGV[0] -log_path = ARGV[1] - -# if log path specified, generate log -if not log_path.nil? then - # create logger - log = Logger.new(log_path) - - # execute and write log - IO.popen("#{cmd} 2>&1") { |io| - io.each { |line| - log.info line - } - } - - # return exit code - exit $?.exitstatus -#$?.to_i -else - # execute command & wait - pipe = IO.popen("#{cmd}") - pid, status = Process.waitpid2(pipe.pid) - - # return exit code - if pid.nil? or status.nil? then - exit 1 - else - exit status.exitstatus - end -end diff --git a/src/common/execute_with_log.rb b/src/common/execute_with_log.rb new file mode 100755 index 0000000..7990697 --- /dev/null +++ b/src/common/execute_with_log.rb @@ -0,0 +1,52 @@ +#!/usr/bin/ruby +=begin + + execute_with_log.rb + +Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + +Contact: +Taejun Ha +Jiil Hyoun +Donghyuk Yang +DongHee Yang + +Licensed 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. + +Contributors: +- S-Core Co., Ltd +=end + +require 'logger' +$LOAD_PATH.unshift File.dirname(__FILE__) +require 'utils.rb' + +# parse arguments +cmd = ARGV[0] +log_path = ARGV[1] + +# create logger +log = Logger.new(log_path) + +# generate command +cmd = Utils.generate_shell_command(cmd, nil) + +# execute and write log +IO.popen("#{cmd} 2>&1") { |io| + io.each { |line| + log.info line + } +} + +# return exit code +exit $?.exitstatus diff --git a/src/common/utils.rb b/src/common/utils.rb index 70ee2ad..ae5ec28 100644 --- a/src/common/utils.rb +++ b/src/common/utils.rb @@ -25,6 +25,7 @@ limitations under the License. Contributors: - S-Core Co., Ltd =end +require 'rbconfig' class Utils STARTUP_INFO_SIZE = 68 @@ -198,32 +199,24 @@ class Utils # can decide whether wait or not def Utils.execute_shell_with_log(cmd, log_path, wait=true) - if get_os_category( HOST_OS ) != "windows" then - # call execute - cmd = "'#{File.dirname(__FILE__)}/execute_with_log' '#{cmd}' '#{log_path}'" + ruby_path=File.join(Config::CONFIG["bindir"], + Config::CONFIG["RUBY_INSTALL_NAME"] + + Config::CONFIG["EXEEXT"]) - # generate command - cmd = generate_shell_command(cmd, nil) - - # print log - pipe = IO.popen("#{cmd} 2>&1") - if wait then - return Process.waitpid2(pipe.pid) - else - return [pipe.pid,nil] - end - else - # create logger - log = Logger.new(log_path) + # call execute + os_category = get_os_category( HOST_OS ) + if os_category == "windows" then + cmd = cmd.gsub("\"", "\\\"") + end - IO.popen("#{cmd} 2>&1") { |io| - io.each { |line| - log.info line - } - } + cmd = "#{ruby_path} \"#{File.expand_path(File.dirname(__FILE__))}/execute_with_log.rb\" \"#{cmd}\" \"#{log_path}\"" - # return exit code - return [nil, $?] + # print log + pipe = IO.popen("#{cmd} 2>&1") + if wait then + return Process.waitpid2(pipe.pid) + else + return [pipe.pid,nil] end end