2 # Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
5 # @author Chulwoo Shin <cw1.shin@samsung.com>
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
22 def analyze_dependency(pkg_group):
25 if pkg_list[pkg_id].get('dependency') is not None:
26 return pkg_list[pkg_id].get('dependency')
29 visited[pkg_id] = number[0]
30 min_num[pkg_id] = number[0]
33 dep_set = set([pkg_list[pkg_id]['name']])
35 if pkg_list[pkg_id].get('requires'):
36 for req in pkg_list[pkg_id].get('requires'):
37 req_id = req.get('id')
38 if req_id is not None:
39 if scc_list[req_id] > 0:
40 dep_set.update(pkg_list[req_id].get('dependency'))
43 if visited[req_id] == 0:
44 dep_set.update(dep_dfs(req_id))
46 min_num[pkg_id] = min(min_num[pkg_id], min_num[req_id])
49 #TODO: package doest not exist
50 #print('def_dfs::', req['name'], 'is not exist (in dep_analysis)')
52 if min_num[pkg_id] == visited[pkg_id]:
53 # scc (string connected components)
54 make_scc(pkg_id, list(dep_set))
58 def make_scc(pkg_id, dep_list):
64 scc_list[p_id] = scc_num[0]
65 pkg_list[p_id]['dependency'] = dep_list
70 for pkg_id in range(len(pkg_list)):
71 if visited[pkg_id] == 0:
74 #TODO: Exception handling
78 # package install-dependency analysis
79 pkg_list = pkg_group.get('pkg_list')
82 visited = [0]*len(pkg_list)
83 min_num = [0]*len(pkg_list)
84 scc_list = [0]*len(pkg_list)