Skip to content

Commit

Permalink
Adds acknowledgements for Cargo licenses
Browse files Browse the repository at this point in the history
  • Loading branch information
lukbukkit committed Apr 17, 2024
1 parent 3774d71 commit e1ff525
Show file tree
Hide file tree
Showing 5 changed files with 1,211 additions and 44 deletions.
75 changes: 41 additions & 34 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions CellGuard/CellGuard.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
CFA09CF92A73D4B000D16832 /* SwiftExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFA09CF82A73D4B000D16832 /* SwiftExtensions.swift */; };
CFA632552AB3501800D46025 /* CSV in Frameworks */ = {isa = PBXBuildFile; productRef = CFA632542AB3501800D46025 /* CSV */; };
CFA632582AB3503400D46025 /* ZIPFoundation in Frameworks */ = {isa = PBXBuildFile; productRef = CFA632572AB3503400D46025 /* ZIPFoundation */; };
CFB323A92BD03AE1007A6807 /* cargo-licenses.json in Resources */ = {isa = PBXBuildFile; fileRef = CFB323A82BD03AE1007A6807 /* cargo-licenses.json */; };
CFB51834297AEFA80006C690 /* CellStatusIcon.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFB51833297AEFA80006C690 /* CellStatusIcon.swift */; };
CFB8B2882963417B00503189 /* LocationDataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFB8B2872963417B00503189 /* LocationDataManager.swift */; };
CFB8B28A2963498200503189 /* CellGuardAppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFB8B2892963498200503189 /* CellGuardAppDelegate.swift */; };
Expand Down Expand Up @@ -252,6 +253,7 @@
CF9626C22AB7474500C46953 /* PersistenceCSVExporter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PersistenceCSVExporter.swift; sourceTree = "<group>"; };
CF9EEEE72B34B6A500F9B6D8 /* OpenSysdiagnoseSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenSysdiagnoseSettings.swift; sourceTree = "<group>"; };
CFA09CF82A73D4B000D16832 /* SwiftExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftExtensions.swift; sourceTree = "<group>"; };
CFB323A82BD03AE1007A6807 /* cargo-licenses.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "cargo-licenses.json"; sourceTree = "<group>"; };
CFB51833297AEFA80006C690 /* CellStatusIcon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CellStatusIcon.swift; sourceTree = "<group>"; };
CFB8B2872963417B00503189 /* LocationDataManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationDataManager.swift; sourceTree = "<group>"; };
CFB8B2892963498200503189 /* CellGuardAppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CellGuardAppDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -624,6 +626,7 @@
children = (
CFFF19DE2BC6CF47004E40CE /* Package.resolved */,
CF5756172B2F259100C7C60A /* BridgingHeader.h */,
CFB323A82BD03AE1007A6807 /* cargo-licenses.json */,
CFD023352961A10D00AA5A1C /* CellGuard */,
CFD0234B2961A10E00AA5A1C /* CellGuardTests */,
CFD023552961A10E00AA5A1C /* CellGuardUITests */,
Expand Down Expand Up @@ -872,6 +875,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
CFB323A92BD03AE1007A6807 /* cargo-licenses.json in Resources */,
CF07EFA72A3B4C10005B53ED /* operator-definitions.json in Resources */,
CF4E53942A31CE2500AE2059 /* qmi-definitions.json in Resources */,
CFD0233E2961A10D00AA5A1C /* Preview Assets.xcassets in Resources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,30 @@
import SwiftUI
import AcknowList

struct CargoLicenseFile: Codable {
var rootName: String
var thirdPartyLibraries: [CargoThirdPartyLibrary]
}

struct CargoThirdPartyLibrary: Codable {
var packageName: String
var packageVersion: String
var repository: String
var license: String
var licenses: [CargoLicense]
}

struct CargoLicense: Codable {
var license: String
var text: String
}

struct AcknowledgementView: View {

@State private var acknowledgements: [Acknow] = []
@State private var swiftAcknowledgements: [Acknow] = []
@State private var rustAcknowledgements: [Acknow] = []

private func loadAcknowledgements () {
private func loadSwiftAcknowledgements () {
var acknowledgements: [Acknow] = []

if let url = Bundle.main.url(forResource: "Package", withExtension: "resolved"),
Expand All @@ -32,16 +51,54 @@ struct AcknowledgementView: View {
}

acknowledgements.sort { $0.title < $1.title }
self.acknowledgements = acknowledgements
self.swiftAcknowledgements = acknowledgements
}

private func loadRustAcknowledgements() {
let jsonDecoder = JSONDecoder()
jsonDecoder.keyDecodingStrategy = .convertFromSnakeCase

guard let url = Bundle.main.url(forResource: "cargo-licenses", withExtension: "json"),
let data = try? Data(contentsOf: url),
let json = try? jsonDecoder.decode(CargoLicenseFile.self, from: data) else {
return
}

// Convert to Acknow type and remove duplicates
// See: https://stackoverflow.com/a/46354989
var seen = Set<String>()
rustAcknowledgements = json.thirdPartyLibraries.map { library in
if library.license.count == 0 {
return Acknow(title: library.packageName, repository: URL(string: library.repository)!)
} else {
return Acknow(title: library.packageName, text: library.license + "\n\n" + library.licenses.map { $0.text }.joined(separator: "\n\n"))
}
}.filter { (acknow: Acknow) in
seen.insert(acknow.title).inserted
}
}

var body: some View {
AcknowListSwiftUIView(acknowledgements: acknowledgements)
.onAppear {
if (acknowledgements.isEmpty) {
loadAcknowledgements()
}
List {
NavigationLink {
AcknowListSwiftUIView(acknowledgements: swiftAcknowledgements)
} label: {
Text("Swift")
}
NavigationLink {
AcknowListSwiftUIView(acknowledgements: rustAcknowledgements)
} label: {
Text("Rust")
}
}
.onAppear {
if swiftAcknowledgements.isEmpty {
loadSwiftAcknowledgements()
}
if rustAcknowledgements.isEmpty {
loadRustAcknowledgements()
}
}
}

}
18 changes: 16 additions & 2 deletions CellGuard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Install additional iOS targets (64 bit for real device & simulator):
rustup target add aarch64-apple-ios x86_64-apple-ios
# Install cargo-lipo
cargo install cargo-lipo
cargo install cargo-lipo cargo-bundle-licenses
```

The first time after cloning, you have to compile the libraries yourself by executing the following command:
Expand All @@ -27,7 +27,7 @@ PROJECT_DIR=. CONFIGURATION=Release ./build-rust.sh
```
If you're using XCode to build an app archive for TestFlight distribution, you should switch the *Build Configuration* setting to *Release* in the *Archive* section.

Upon changes, XCode will rebuild the libraries automatically.
Upon changes, XCode will rebuild the libraries automatically.

### XCode

Expand Down Expand Up @@ -84,3 +84,17 @@ To read more on how to build jailbroken apps, see
⛔️ Currently, a bug assumed to be caused by Swift concurrency prevents the app from starting if it is installed using a .deb file. Read more on [GitHub](https://github.com/utmapp/UTM/issues/3628#issuecomment-1144471721).

Thus, we recommend the other way of installing the app.

## Update Dependencies

### Rust

To update the Rust dependencies run the following commands in the top-level directory.
```sh
# Update Rust dependencies with cargo package manager
cargo update

# Update generated license file, might require some manual edits
# See: https://github.com/sstadick/cargo-bundle-licenses?tab=readme-ov-file#usage
cargo bundle-licenses --format json --output CellGuard/cargo-licenses.json --previous CellGuard/cargo-licenses.json
```
Loading

0 comments on commit e1ff525

Please sign in to comment.