upload tizen1.0 source
[sdk/tools/sdk-build.git] / build-cli
1 #!/usr/bin/ruby -d
2
3 =begin
4  
5  build-cli
6
7 Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
8
9 Contact:
10 Taejun Ha <taejun.ha@samsung.com>
11 Jiil Hyoun <jiil.hyoun@samsung.com>
12 Donghyuk Yang <donghyuk.yang@samsung.com>
13 DongHee Yang <donghee.yang@samsung.com>
14
15 Licensed under the Apache License, Version 2.0 (the "License");
16 you may not use this file except in compliance with the License.
17 You may obtain a copy of the License at
18
19 http://www.apache.org/licenses/LICENSE-2.0
20
21 Unless required by applicable law or agreed to in writing, software
22 distributed under the License is distributed on an "AS IS" BASIS,
23 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24 See the License for the specific language governing permissions and
25 limitations under the License.
26
27 Contributors:
28 - S-Core Co., Ltd
29 =end
30
31 require "socket"
32 require 'fileutils'
33 $LOAD_PATH.unshift File.dirname(__FILE__)+"/src/common"
34 $LOAD_PATH.unshift File.dirname(__FILE__)+"/src/build_server"
35 require "utils"
36 require "BuildClientOptionParser"
37 require "BuildComm"
38
39 #option parsing 
40 option = option_parse
41
42 # if "--os" is not specified, use host os type
43 if option[:os].nil? then 
44     option[:os] = Utils::HOST_OS
45 else 
46     if not option[:os] =~ /^(linux|windows|darwin)$/ then 
47         puts "We have no plan to Buld OS \"#{option[:os]}\" \n please check your option OS "
48         exit 1
49     end
50 end
51
52 if option[:domain].nil? then
53         option[:domain] = "127.0.0.1"
54 end
55
56 if option[:port].nil? then
57         option[:port] = 2222
58 end
59
60 begin
61         case option[:cmd] 
62         when "build" 
63                 client = BuildCommClient.create( option[:domain], option[:port])
64                 if not client.nil? then
65                         client.send "BUILD,GIT,#{option[:git]},#{option[:commit]},#{option[:os]},,#{option[:async]}"
66                         client.print_stream
67                         client.terminate
68                 end
69         when "resolve"
70                 client = BuildCommClient.create( option[:domain], option[:port])
71                 if not client.nil? then
72                         client.send "RESOLVE,GIT,#{option[:git]},#{option[:commit]},#{option[:os]},,#{option[:async]}" 
73                         client.print_stream
74                         client.terminate
75                 end
76         when "query"
77                 # SYSTEM INFO
78                 client = BuildCommClient.create( option[:domain], option[:port])
79                 if not client.nil? then
80                         client.send "QUERY,SYSTEM" 
81                         result0 = client.receive_data()
82                         if result0.nil? then
83                                 client.terminate
84                                 exit(-1)
85                         end
86                         result0 = result0[0].split(",").map { |x| x.strip }
87                         puts "HOST-OS: #{result0[0]}"
88                         puts "MAX_WORKING_JOBS: #{result0[1]}"
89                         client.terminate
90                 end
91
92                 # JOB INFO
93                 client = BuildCommClient.create( option[:domain], option[:port])
94                 if not client.nil? then
95                         client.send "QUERY,JOB"
96                         result1 = client.receive_data()
97                         if result0.nil? then
98                                 client.terminate
99                                 exit(-1)
100                         end
101                         puts "* JOB *"
102                         for item in result1
103                                 tok = item.split(",").map { |x| x.strip }
104                                 puts "#{tok[1]} #{tok[0]} #{tok[2]}"    
105                         end
106                 end
107
108         else
109                 raise RuntimeError, "input option incorrect : #{option[:cmd]}"
110         end
111
112 rescue => e
113         puts e.message
114         exit(-1)
115 end
116
117 exit 0