From: donghee yang Date: Fri, 21 Sep 2012 15:11:38 +0000 (+0900) Subject: [Title] Refactored to use "PROCESS" when logging its build steps X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e195b6330a1a5a32b86c030bed31874cf454b338;p=sdk%2Ftools%2Fsdk-build.git [Title] Refactored to use "PROCESS" when logging its build steps --- diff --git a/build-svr b/build-svr index fd881ff..78e48bd 100755 --- a/build-svr +++ b/build-svr @@ -90,7 +90,7 @@ begin while(true) log.info "Build Server[#{option[:name]}] Start - PORT:[#{option[:port]}]" # Start child process - cmd = Utils.execute_shell_generate("#{File.dirname(__FILE__)}/build-svr start -n #{option[:name]} -p #{option[:port]} --CHILD") + cmd = Utils.generate_shell_command("#{File.dirname(__FILE__)}/build-svr start -n #{option[:name]} -p #{option[:port]} --CHILD") IO.popen(cmd) pid = Process.wait @@ -101,7 +101,7 @@ begin break elsif ($?.exitstatus == 99) then # DIBS UPGRADE cmd = "#{File.dirname(__FILE__)}/upgrade -l #{File.dirname(__FILE__)} -S -t BUILDSERVER -n #{option[:name]} -p #{option[:port]}" - cmd = Utils.execute_shell_generate(cmd) + cmd = Utils.generate_shell_command(cmd) puts cmd Utils.spawn(cmd) log.info cmd diff --git a/src/build_server/GitBuildProject.rb b/src/build_server/GitBuildProject.rb index d06af21..3ac261c 100644 --- a/src/build_server/GitBuildProject.rb +++ b/src/build_server/GitBuildProject.rb @@ -249,9 +249,12 @@ class GitBuildProject < CommonProject def git_cmd(cmd, working_dir, log) build_command = "cd \"#{working_dir}\";#{@server.git_bin_path} #{cmd}" - ret = Utils.execute_shell_with_log(build_command,log) - - return ret + pid, status = Utils.execute_shell_with_log(build_command,log.path) + if status.exitstatus != 0 then + return false + else + return true + end end diff --git a/src/builder/Builder.rb b/src/builder/Builder.rb index f0087fe..f9eeecb 100644 --- a/src/builder/Builder.rb +++ b/src/builder/Builder.rb @@ -362,11 +362,11 @@ class Builder env_def = "BUILD_TARGET_OS=#{os} \ - TARGET_OS=#{os} \ - TARGET_OS_CATEGORY=#{os_category} \ - SRCDIR=\"#{src_path2}\" \ - ROOTDIR=\"#{build_root_dir}\" \ - VERSION=\"#{version}\" " +TARGET_OS=#{os} \ +TARGET_OS_CATEGORY=#{os_category} \ +SRCDIR=\"#{src_path2}\" \ +ROOTDIR=\"#{build_root_dir}\" \ +VERSION=\"#{version}\" " # check script file script_file = "#{src_path}/package/build.#{@host_os}" @@ -426,15 +426,16 @@ class Builder f.puts "#{target}" f.puts "echo \"success\"" end - Utils.execute_shell_with_log( "chmod +x #{src_path}/.build.sh", @log ) + Utils.execute_shell( "chmod +x #{src_path}/.build.sh", @log ) build_command = "cd \"#{src_path}\";" + env_def + "./.build.sh" # execute script - if not Utils.execute_shell_with_log( build_command, @log ) then + pid, status = Utils.execute_shell_with_log( build_command, @log.path ) + if status.exitstatus != 0 then @log.error( "Failed on build script: \"#{target}\"", Log::LV_USER) return false else - Utils.execute_shell_with_log( "rm -rf #{src_path}/.build.sh", @log ) + Utils.execute_shell( "rm -rf #{src_path}/.build.sh", @log ) return true end end @@ -618,7 +619,7 @@ class Builder # zip @log.info( "Creating package file ... #{pkg.package_name}_#{pkg.version}_#{os}.zip", Log::LV_USER) @log.info("cd \"#{install_dir}\"; zip -r -y #{src_path}/#{pkg.package_name}_#{pkg.version}_#{os}.zip *") - Utils.execute_shell_with_log("cd \"#{install_dir}\"; zip -r -y #{src_path}/#{pkg.package_name}_#{pkg.version}_#{os}.zip *", @log) + Utils.execute_shell_with_log("cd \"#{install_dir}\"; zip -r -y #{src_path}/#{pkg.package_name}_#{pkg.version}_#{os}.zip *", @log.path) if not File.exist? "#{src_path}/#{pkg.package_name}_#{pkg.version}_#{os}.zip" then return false end diff --git a/src/common/execute_with_log b/src/common/execute_with_log new file mode 100755 index 0000000..3a0bddd --- /dev/null +++ b/src/common/execute_with_log @@ -0,0 +1,35 @@ +#!/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/utils.rb b/src/common/utils.rb index ea2bf95..e74e27d 100644 --- a/src/common/utils.rb +++ b/src/common/utils.rb @@ -138,9 +138,8 @@ class Utils return 0 end - def Utils.execute_shell_generate(cmd, os_category = nil) - result_lines = [] + def Utils.generate_shell_command(cmd, os_category = nil) if os_category.nil? then os_category = get_os_category( HOST_OS ) end if os_category == "windows" then @@ -155,13 +154,9 @@ class Utils def Utils.execute_shell(cmd, os_category = nil) ret = false - if os_category.nil? then os_category = get_os_category( HOST_OS ) end - - if os_category == "windows" then - mingw_path = "sh.exe -c " - cmd = cmd.gsub("\"", "\\\"") - cmd = mingw_path + "\"#{cmd}\"" - end + + # generate command + cmd = generate_shell_command(cmd, os_category) `#{cmd}` if $?.to_i == 0 then ret = true else ret = false end @@ -173,13 +168,8 @@ class Utils def Utils.execute_shell_return(cmd, os_category = nil) result_lines = [] - if os_category.nil? then os_category = get_os_category( HOST_OS ) end - - if os_category == "windows" then - mingw_path = "sh.exe -c " - cmd = cmd.gsub("\"", "\\\"") - cmd = mingw_path + "\"#{cmd}\"" - end + # generate command + cmd = generate_shell_command(cmd, os_category) # get result IO.popen("#{cmd} 2>&1") { |io| @@ -196,41 +186,34 @@ class Utils end def Utils.execute_shell_return_ret(cmd, os_category = nil) - if os_category.nil? then os_category = get_os_category( HOST_OS ) end - if os_category == "windows" then - mingw_path = "sh.exe -c " - cmd = cmd.gsub("\"", "\\\"") - cmd = mingw_path + "\"#{cmd}\"" - end + # generate command + cmd = generate_shell_command(cmd, os_category) return `#{cmd}` end - def Utils.execute_shell_with_log(cmd, log, os_category = nil) - if os_category.nil? then os_category = get_os_category( HOST_OS ) end + # create process and log its all output(stderr, stdout) + # can decide whether wait or not + def Utils.execute_shell_with_log(cmd, log_path, wait=true) - if os_category == "windows" then - mingw_path = "sh.exe -c " - cmd = cmd.gsub("\"", "\\\"") - cmd = mingw_path + "\"#{cmd}\"" - end + # call execute + cmd = "'#{File.dirname(__FILE__)}/execute_with_log' '#{cmd}' '#{log_path}'" + + # generate command + cmd = generate_shell_command(cmd, nil) # print log - IO.popen("#{cmd} 2>&1") { |io| - io.each do |line| - log.output line - end - } - - if $?.to_i == 0 then - return true - else - return false - end + pipe = IO.popen("#{cmd} 2>&1") + if wait then + return Process.waitpid2(pipe.pid) + else + return [pipe.pid,nil] + end end + def Utils.spawn(cmd, os_category = nil) if os_category.nil? then os_category = get_os_category( HOST_OS ) end diff --git a/src/pkg_server/downloader.rb b/src/pkg_server/downloader.rb index 7e5a8c8..982fde0 100644 --- a/src/pkg_server/downloader.rb +++ b/src/pkg_server/downloader.rb @@ -45,7 +45,8 @@ class FileDownLoader logger.info "Downloading #{url}" if is_remote then - ret = Utils.execute_shell_with_log( "wget #{url} -O #{fullpath} -nv", logger ) + pid,status = Utils.execute_shell_with_log( "wget #{url} -O #{fullpath} -nv", logger ) + ret = status.exitstatus != 0 ? false : true #ret = Utils.execute_shell( "wget #{url} -O #{fullpath} -q") else if not File.exist? url then diff --git a/upgrade b/upgrade index b93eefe..9635015 100755 --- a/upgrade +++ b/upgrade @@ -153,7 +153,7 @@ begin cmd = "#{UPGRADE_CMD} -I -l #{dibs_path} -u #{pkg_svr_url}" end - cmd = Utils.execute_shell_generate(cmd) + cmd = Utils.generate_shell_command(cmd) Utils.spawn(cmd) else @@ -231,7 +231,7 @@ begin end # Start Build server - cmd = Utils.execute_shell_generate("#{dibs_path}/build-svr start -n #{svr_name} -p #{svr_port}") + cmd = Utils.generate_shell_command("#{dibs_path}/build-svr start -n #{svr_name} -p #{svr_port}") Utils.spawn(cmd) log.info("Upgrade Complete", Log::LV_USER) @@ -239,7 +239,7 @@ begin else # PACKAGE SERVER # Start Build server - cmd = Utils.execute_shell_generate("#{dibs_path}/pkg-svr start -n #{svr_name} -p #{svr_port}") + cmd = Utils.generate_shell_command("#{dibs_path}/pkg-svr start -n #{svr_name} -p #{svr_port}") Utils.spawn(cmd) log.info("Upgrade Complete", Log::LV_USER)