Skip to content

Commit af0f99e

Browse files
authored
Merge pull request #76 from fosslight/develop
Support local scm package for Cocoapods
2 parents 47b8e47 + a4addd7 commit af0f99e

File tree

1 file changed

+66
-43
lines changed

1 file changed

+66
-43
lines changed

src/fosslight_dependency/package_manager/Cocoapods.py

Lines changed: 66 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
import json
99
import yaml
1010
import re
11+
import traceback
1112
import fosslight_util.constant as constant
1213
import fosslight_dependency.constant as const
1314
from fosslight_dependency._package_manager import PackageManager
1415

1516
logger = logging.getLogger(constant.LOGGER_NAME)
1617

1718
_spec_repos = 'SPEC REPOS'
19+
_external_sources = 'EXTERNAL SOURCES'
1820
_source_type = ['git', 'http', 'svn', 'hg']
1921

2022

@@ -35,10 +37,19 @@ def parse_oss_information(self, f_name):
3537
pod_in_sepc_list = []
3638
pod_not_in_spec_list = []
3739
spec_repo_list = []
38-
39-
for spec_item_key in podfile_yaml[_spec_repos]:
40-
for spec_item in podfile_yaml[_spec_repos][spec_item_key]:
41-
spec_repo_list.append(spec_item)
40+
external_source_list = []
41+
42+
if _spec_repos in podfile_yaml:
43+
for spec_item_key in podfile_yaml[_spec_repos]:
44+
for spec_item in podfile_yaml[_spec_repos][spec_item_key]:
45+
spec_repo_list.append(spec_item)
46+
if _external_sources in podfile_yaml:
47+
for external_sources_key in podfile_yaml[_external_sources]:
48+
external_source_list.append(external_sources_key)
49+
spec_repo_list.append(external_sources_key)
50+
if len(spec_repo_list) == 0:
51+
logger.error("Cannot fint SPEC REPOS or EXTERNAL SOURCES in Podfile.lock.")
52+
return ''
4253

4354
for pods_list in podfile_yaml['PODS']:
4455
if not isinstance(pods_list, str):
@@ -59,54 +70,66 @@ def parse_oss_information(self, f_name):
5970
sheet_list = []
6071

6172
for pod_oss in pod_in_sepc_list:
62-
63-
search_oss_name = ""
64-
for alphabet_oss in pod_oss[0]:
65-
if not alphabet_oss.isalnum():
66-
search_oss_name += "\\\\" + alphabet_oss
73+
try:
74+
if pod_oss[0] in external_source_list:
75+
podspec_filename = pod_oss[0] + '.podspec.json'
76+
spec_file_path = os.path.join("Pods", "Local Podspecs", podspec_filename)
6777
else:
68-
search_oss_name += alphabet_oss
69-
70-
command = 'pod spec which --regex ' + '^' + search_oss_name + '$'
71-
spec_which = os.popen(command).readline()
72-
if spec_which.startswith('[!]'):
73-
logger.error("This command(" + command + ") returns an error")
74-
return ''
78+
search_oss_name = ""
79+
for alphabet_oss in pod_oss[0]:
80+
if not alphabet_oss.isalnum():
81+
search_oss_name += "\\\\" + alphabet_oss
82+
else:
83+
search_oss_name += alphabet_oss
84+
85+
command = 'pod spec which --regex ' + '^' + search_oss_name + '$'
86+
spec_which = os.popen(command).readline()
87+
if spec_which.startswith('[!]'):
88+
logger.error("This command(" + command + ") returns an error")
89+
return ''
90+
91+
file_path = spec_which.rstrip().split(os.path.sep)
92+
if file_path[0] == '':
93+
file_path_without_version = os.path.join(os.sep, *file_path[:-2])
94+
else:
95+
file_path_without_version = os.path.join(*file_path[:-2])
96+
spec_file_path = os.path.join(file_path_without_version, pod_oss[1], file_path[-1])
97+
98+
oss_name, oss_version, license_name, dn_loc, homepage = self.get_oss_in_podspec(spec_file_path)
7599

76-
file_path = spec_which.rstrip().split(os.path.sep)
77-
if file_path[0] == '':
78-
file_path_without_version = os.path.join(os.sep, *file_path[:-2])
79-
else:
80-
file_path_without_version = os.path.join(*file_path[:-2])
81-
spec_file_path = os.path.join(file_path_without_version, pod_oss[1], file_path[-1])
100+
sheet_list.append([const.SUPPORT_PACKAE.get(self.package_manager_name),
101+
oss_name, oss_version, license_name, dn_loc, homepage, '', '', ''])
102+
except Exception as e:
103+
logger.warning('It failed to get ' + pod_oss[0] + ': ' + str(e))
104+
logger.warning(traceback.format_exc())
82105

83-
with open(spec_file_path, 'r', encoding='utf8') as json_file:
84-
json_data = json.load(json_file)
106+
return sheet_list
85107

86-
oss_origin_name = json_data['name']
87-
oss_name = self.package_manager_name + ":" + oss_origin_name
88-
oss_version = json_data['version']
89-
homepage = self.dn_url + 'pods/' + oss_origin_name
108+
def get_oss_in_podspec(self, spec_file_path):
109+
with open(spec_file_path, 'r', encoding='utf8') as json_file:
110+
json_data = json.load(json_file)
90111

91-
if not isinstance(json_data['license'], str):
92-
if 'type' in json_data['license']:
93-
license_name = json_data['license']['type']
94-
else:
95-
license_name = json_data['license']
112+
oss_origin_name = json_data['name']
113+
oss_name = self.package_manager_name + ":" + oss_origin_name
114+
oss_version = json_data['version']
115+
homepage = self.dn_url + 'pods/' + oss_origin_name
96116

97-
license_name = license_name.replace(",", "")
117+
if not isinstance(json_data['license'], str):
118+
if 'type' in json_data['license']:
119+
license_name = json_data['license']['type']
120+
else:
121+
license_name = json_data['license']
98122

99-
source_keys = [key for key in json_data['source']]
100-
for src_type_i in _source_type:
101-
if src_type_i in source_keys:
102-
dn_loc = json_data['source'][src_type_i]
103-
if dn_loc.endswith('.git'):
104-
dn_loc = dn_loc[:-4]
123+
license_name = license_name.replace(",", "")
105124

106-
sheet_list.append([const.SUPPORT_PACKAE.get(self.package_manager_name),
107-
oss_name, oss_version, license_name, dn_loc, homepage, '', '', ''])
125+
source_keys = [key for key in json_data['source']]
126+
for src_type_i in _source_type:
127+
if src_type_i in source_keys:
128+
dn_loc = json_data['source'][src_type_i]
129+
if dn_loc.endswith('.git'):
130+
dn_loc = dn_loc[:-4]
108131

109-
return sheet_list
132+
return oss_name, oss_version, license_name, dn_loc, homepage
110133

111134

112135
def compile_pods_item(pods_item, spec_repo_list, pod_in_sepc_list, pod_not_in_spec_list):

0 commit comments

Comments
 (0)