Skip to content

Commit d82e2ce

Browse files
authored
Merge pull request #48 from fosslight/develop
Support carthage package manager
2 parents ba177d1 + 43f616a commit d82e2ce

File tree

6 files changed

+112
-6
lines changed

6 files changed

+112
-6
lines changed

.github/workflows/pull-request.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ jobs:
7676
fosslight_dependency -p tests/test_pub -o tests/result/pub
7777
fosslight_dependency -p tests/test_cocoapods/cocoapods-tips/JWSCocoapodsTips -o tests/result/Cocoapods
7878
fosslight_dependency -p tests/test_swift -o tests/result/swift -t ${{ secrets.TOKEN }}
79+
fosslight_dependency -p tests/test_carthage -o tests/result/carthage -t ${{ secrets.TOKEN }}
7980
reuse:
8081
runs-on: ubuntu-latest
8182
steps:

.reuse/dep5

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,8 @@ License: Apache-2.0
7676

7777
Files: tests/test_swift/*
7878
Copyright: 2021 LG Electronics
79+
License: Apache-2.0
80+
81+
Files: tests/test_carthage/*
82+
Copyright: 2021 LG Electronics
7983
License: Apache-2.0

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Currently, it supports the following package managers.
2020
- [Pub](https://pub.dev/) (Dart with flutter)
2121
- [Cocoapods](https://cocoapods.org/) (Swift/Obj-C)
2222
- [Swift](https://swift.org/package-manager/) (Swift)
23+
- [Carthage](https://github.com/Carthage/Carthage) (Carthage)
2324

2425
## 🧐 How to analyze the dependencies
2526

src/fosslight_dependency/_help.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,23 @@
1919
Pub (Dart with flutter)
2020
Cocoapods (Swift/Obj-C)
2121
Swift (Swift)
22+
Carthage (Swift/Obj-C)
2223
2324
Options:
2425
Optional
2526
-h\t\t\t\t Print help message.
2627
-v\t\t\t\t Print the version of the script.
27-
-m <package_manager>\t Enter the package manager(npm, maven, gradle, pip, pub, cocoapods, android, swift).
28+
-m <package_manager>\t Enter the package manager.
29+
\t(npm, maven, gradle, pip, pub, cocoapods, android, swift, carthage)
2830
-p <input_path>\t\t Enter the path where the script will be run.
2931
-o <output_path>\t\t Enter the path where the result file will be generated.
3032
3133
Required only for pypi
3234
-a <activate_cmd>\t\t Virtual environment activate command(ex, 'conda activate (venv name)')
3335
-d <deactivate_cmd>\t\t Virtual environment deactivate command(ex, 'conda deactivate')
3436
35-
Required only for swift
36-
-t <token>\t\t Enter the github personal access token.
37+
Required only for swift, carthage
38+
-t <token>\t\t\t Enter the github personal access token.
3739
3840
Optional only for gradle, maven
3941
-c <dir_name>\t\t Enter the customized build output directory name

src/fosslight_dependency/analyze_dependency.py

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
_PKG_NAME = "fosslight_dependency"
3333

3434
# Check the manifest file
35-
SUPPORT_PACKAE = ["pip", "npm", "maven", "gradle", "pub", "cocoapods", "android", "swift"]
35+
SUPPORT_PACKAE = ["pip", "npm", "maven", "gradle", "pub", "cocoapods", "android", "swift", "carthage"]
3636
manifest_array = [[SUPPORT_PACKAE[0], "requirements.txt"], [SUPPORT_PACKAE[1], "package.json"], [SUPPORT_PACKAE[2], "pom.xml"],
3737
[SUPPORT_PACKAE[3], "build.gradle"], [SUPPORT_PACKAE[4], "pubspec.yaml"], [SUPPORT_PACKAE[5], "Podfile.lock"],
38-
[SUPPORT_PACKAE[7], "Package.resolved"]]
38+
[SUPPORT_PACKAE[7], "Package.resolved"], [SUPPORT_PACKAE[8], "Cartfile.resolved"]]
3939

4040
# binary url to check license text
4141
license_scanner_url_linux = "third_party/nomos/nomossa"
@@ -999,7 +999,69 @@ def parse_and_generate_output_swift(input_fp):
999999
except Exception:
10001000
logger.info("Cannot find the license name with github api.")
10011001

1002-
if license_name == "":
1002+
if license_name == "" or license_name == "NOASSERTION":
1003+
try:
1004+
license_txt_data = base64.b64decode(repository.get_license().content).decode('utf-8')
1005+
tmp_license_txt = open(tmp_license_txt_file_name, 'w', encoding='utf-8')
1006+
tmp_license_txt.write(license_txt_data)
1007+
tmp_license_txt.close()
1008+
license_name = check_and_run_license_scanner(tmp_license_txt_file_name, os_name)
1009+
except Exception:
1010+
logger.info("Cannot find the license name with license scanner binary.")
1011+
1012+
if os.path.isfile(tmp_license_txt_file_name):
1013+
os.remove(tmp_license_txt_file_name)
1014+
1015+
sheet_list["SRC"].append(['Package.resolved', oss_name, oss_version, license_name, dn_loc, homepage, '', '', ''])
1016+
1017+
return sheet_list
1018+
1019+
1020+
def parse_and_generate_output_carthge(input_fp):
1021+
global GITHUB_TOKEN
1022+
1023+
sheet_list = {}
1024+
sheet_list["SRC"] = []
1025+
1026+
os_name = check_os()
1027+
check_license_scanner(os_name)
1028+
1029+
if GITHUB_TOKEN is not None:
1030+
g = Github(GITHUB_TOKEN)
1031+
else:
1032+
g = Github()
1033+
1034+
for i, line in enumerate(input_fp.readlines()):
1035+
1036+
re_result = re.findall(r'github[\s]\"(\S*)\"[\s]\"(\S*)\"', line)
1037+
try:
1038+
github_repo = re_result[0][0]
1039+
oss_origin_name = github_repo.split('/')[1]
1040+
oss_name = "carthage:" + oss_origin_name
1041+
oss_version = re_result[0][1]
1042+
homepage = "https://github.com/" + github_repo
1043+
dn_loc = homepage
1044+
1045+
license_name = ''
1046+
except Exception:
1047+
logger.error("It cannot find the github oss information. So skip it.")
1048+
break
1049+
1050+
try:
1051+
repository = g.get_repo(github_repo)
1052+
except Exception:
1053+
logger.error("It cannot find the license name. Please use '-t' option with github token.")
1054+
logger.error("{0}{1}".format("refer:https://docs.github.com/en/github/authenticating-to-github/",
1055+
"keeping-your-account-and-data-secure/creating-a-personal-access-token"))
1056+
repository = ''
1057+
1058+
if repository is not None:
1059+
try:
1060+
license_name = repository.get_license().license.spdx_id
1061+
except Exception:
1062+
logger.info("Cannot find the license name with github api.")
1063+
1064+
if license_name == "" or license_name == "NOASSERTION":
10031065
try:
10041066
license_txt_data = base64.b64decode(repository.get_license().content).decode('utf-8')
10051067
tmp_license_txt = open(tmp_license_txt_file_name, 'w', encoding='utf-8')
@@ -1145,6 +1207,17 @@ def main_swift():
11451207
return sheet_list
11461208

11471209

1210+
def main_carthage():
1211+
1212+
input_fp = open_input_file()
1213+
1214+
sheet_list = parse_and_generate_output_carthge(input_fp)
1215+
1216+
close_input_file(input_fp)
1217+
1218+
return sheet_list
1219+
1220+
11481221
def set_package_variables(package):
11491222
global PACKAGE, dn_url, output_file_name, input_file_name, venv_tmp_dir, pom_backup, is_maven_first_try, \
11501223
tmp_license_txt_file_name, source_type
@@ -1193,6 +1266,11 @@ def set_package_variables(package):
11931266
output_file_name = "swift_dependency_output"
11941267
tmp_license_txt_file_name = "tmp_license.txt"
11951268

1269+
elif PACKAGE == "carthage":
1270+
input_file_name = "Cartfile.resolved"
1271+
output_file_name = "carthage_dependency_output"
1272+
tmp_license_txt_file_name = "tmp_license.txt"
1273+
11961274
else:
11971275
logger.error("### Error Message ###")
11981276
logger.error("You enter the wrong first argument.")
@@ -1240,6 +1318,8 @@ def main():
12401318
sheet_list = main_android()
12411319
elif PACKAGE == "swift":
12421320
sheet_list = main_swift()
1321+
elif PACKAGE == "carthage":
1322+
sheet_list = main_carthage()
12431323
else:
12441324
logger.error("### Error Message ###")
12451325
logger.error("Please enter the supported package manager. (Check the help message with (-h) option.)")

tests/test_carthage/Cartfile.resolved

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
github "AgileBits/onepassword-app-extension" "bcc4cc97fed9a6e73fa204f2e61138e353cb3ef7"
2+
github "DaveWoodCom/XCGLogger" "7.0.0"
3+
github "Dev1an/A-Star" "3.0.0-beta-1"
4+
github "Leanplum/Leanplum-iOS-SDK" "2.4.3"
5+
github "SDWebImage/SDWebImage" "5.0.6"
6+
github "SnapKit/SnapKit" "5.0.0"
7+
github "SwiftyJSON/SwiftyJSON" "5.0.0"
8+
github "adjust/ios_sdk" "v4.17.2"
9+
github "apple/swift-protobuf" "1.5.0"
10+
github "cezheng/Fuzi" "3.1.1"
11+
github "getsentry/sentry-cocoa" "4.4.0"
12+
github "google/EarlGrey" "1.15.1"
13+
github "jrendel/SwiftKeychainWrapper" "3.4.0"
14+
github "kif-framework/KIF" "v3.7.7"
15+
github "mozilla-mobile/MappaMundi" "1d17845e4bd6077d790aca5a2b4a468f19567934"
16+
github "mozilla-mobile/telemetry-ios" "1.1.1"
17+
github "mozilla/application-services" "v0.32.3"
18+
github "swisspol/GCDWebServer" "3.5.2"

0 commit comments

Comments
 (0)