Skip to content

Commit

Permalink
#URL macro (#657)
Browse files Browse the repository at this point in the history
  • Loading branch information
mallexxx authored Mar 7, 2024
1 parent 9bafa02 commit dbe75fa
Show file tree
Hide file tree
Showing 34 changed files with 312 additions and 239 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ jobs:
-destination 'platform=iOS Simulator,name=iPhone 15' \
-derivedDataPath DerivedData \
-skipPackagePluginValidation \
-skipMacroValidation \
CODE_SIGNING_ALLOWED=NO \
| tee -a ios-build-log.txt \
| xcbeautify --report junit --report-path . --junit-report-filename ios-unittests.xml
Expand Down
13 changes: 11 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/apple-toolbox.git",
"state" : {
"revision" : "e3dc4faf70ca09718a2d20d5c47b449389e8c153",
"version" : "1.0.0"
"revision" : "d51beaf1736013b530576ace13a16d6d1a63742c",
"version" : "2.0.0"
}
},
{
Expand Down Expand Up @@ -72,6 +72,15 @@
"version" : "1.3.0"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax.git",
"state" : {
"revision" : "64889f0c732f210a935a0ad7cda38f77f876262d",
"version" : "509.1.1"
}
},
{
"identity" : "swifter",
"kind" : "remoteSourceControl",
Expand Down
17 changes: 14 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// swift-tools-version:5.7
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
import Foundation
import PackageDescription

let swiftlintPlugin = Target.PluginUsage.plugin(name: "SwiftLintPlugin", package: "apple-toolbox")

Expand Down Expand Up @@ -47,7 +47,7 @@ let package = Package(
.package(url: "https://github.com/httpswift/swifter.git", exact: "1.5.0"),
.package(url: "https://github.com/duckduckgo/bloom_cpp.git", exact: "3.0.0"),
.package(url: "https://github.com/duckduckgo/wireguard-apple", exact: "1.1.1"),
.package(url: "https://github.com/duckduckgo/apple-toolbox.git", exact: "1.0.0"),
.package(url: "https://github.com/duckduckgo/apple-toolbox.git", exact: "2.0.0"),
],
targets: [
.target(
Expand All @@ -62,6 +62,7 @@ let package = Package(
"UserScript",
"ContentBlocking",
"SecureStorage",
.product(name: "Macros", package: "apple-toolbox"),
],
resources: [
.process("ContentBlocking/UserScripts/contentblockerrules.js"),
Expand Down Expand Up @@ -146,6 +147,7 @@ let package = Package(
"Common",
.product(name: "DDGSyncCrypto", package: "sync_crypto"),
"Networking",
.product(name: "Macros", package: "apple-toolbox"),
],
resources: [
.process("SyncMetadata.xcdatamodeld"),
Expand Down Expand Up @@ -277,6 +279,7 @@ let package = Package(
dependencies: [
"Networking",
"Persistence",
.product(name: "Macros", package: "apple-toolbox"),
],
plugins: [swiftlintPlugin]
),
Expand All @@ -286,6 +289,7 @@ let package = Package(
.target(name: "WireGuardC"),
.product(name: "WireGuard", package: "wireguard-apple"),
"Common",
.product(name: "Macros", package: "apple-toolbox"),
],
swiftSettings: [
.define("DEBUG", .when(configuration: .debug))
Expand Down Expand Up @@ -322,6 +326,7 @@ let package = Package(
name: "Subscription",
dependencies: [
"Common",
.product(name: "Macros", package: "apple-toolbox"),
],
swiftSettings: [
.define("DEBUG", .when(configuration: .debug))
Expand Down Expand Up @@ -360,6 +365,7 @@ let package = Package(
"RemoteMessaging", // Move tests later (lots of test dependencies in BSK)
"SecureStorageTestsUtils",
"TestUtils",
.product(name: "Macros", package: "apple-toolbox"),
],
resources: [
.copy("Resources")
Expand All @@ -371,6 +377,7 @@ let package = Package(
dependencies: [
"DDGSync",
"TestUtils",
.product(name: "Macros", package: "apple-toolbox"),
],
plugins: [swiftlintPlugin]
),
Expand All @@ -385,6 +392,7 @@ let package = Package(
name: "CommonTests",
dependencies: [
"Common",
.product(name: "Macros", package: "apple-toolbox"),
],
plugins: [swiftlintPlugin]
),
Expand All @@ -400,6 +408,7 @@ let package = Package(
dependencies: [
"Navigation",
.product(name: "Swifter", package: "swifter"),
.product(name: "Macros", package: "apple-toolbox"),
],
resources: [
.copy("Resources")
Expand Down Expand Up @@ -465,6 +474,7 @@ let package = Package(
dependencies: [
"SecureStorage",
"SecureStorageTestsUtils",
.product(name: "Macros", package: "apple-toolbox"),
],
plugins: [swiftlintPlugin]
),
Expand All @@ -473,6 +483,7 @@ let package = Package(
dependencies: [
"PrivacyDashboard",
"TestUtils",
.product(name: "Macros", package: "apple-toolbox"),
],
plugins: [swiftlintPlugin]
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
//

import Foundation
import Macros

public protocol SuggestionLoading: AnyObject {

Expand All @@ -29,7 +30,7 @@ public protocol SuggestionLoading: AnyObject {

public class SuggestionLoader: SuggestionLoading {

static let remoteSuggestionsUrl = URL(string: "https://duckduckgo.com/ac/")!
static let remoteSuggestionsUrl = #URL("https://duckduckgo.com/ac/")
static let searchParameter = "q"

public enum SuggestionLoaderError: Error {
Expand Down
5 changes: 3 additions & 2 deletions Sources/DDGSync/DDGSyncing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import BrowserServicesKit
import Combine
import DDGSyncCrypto
import Foundation
import Macros

public enum SyncAuthState: String, Sendable, Codable {
/// Sync engine is not initialized.
Expand Down Expand Up @@ -176,9 +177,9 @@ public enum ServerEnvironment: LosslessStringConvertible {
var baseURL: URL {
switch self {
case .development:
return URL(string: "https://dev-sync-use.duckduckgo.com")!
return #URL("https://dev-sync-use.duckduckgo.com")
case .production:
return URL(string: "https://sync.duckduckgo.com")!
return #URL("https://sync.duckduckgo.com")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
//

import Foundation
import Macros

public enum NetworkProtectionAuthenticationMethod {
case inviteCode(String)
Expand Down Expand Up @@ -118,8 +119,8 @@ public struct AuthenticationFailureResponse: Decodable {
final class NetworkProtectionBackendClient: NetworkProtectionClient {

enum Constants {
static let productionEndpoint = URL(string: "https://controller.netp.duckduckgo.com")!
static let stagingEndpoint = URL(string: "https://staging.netp.duckduckgo.com")!
static let productionEndpoint = #URL("https://controller.netp.duckduckgo.com")
static let stagingEndpoint = #URL("https://staging.netp.duckduckgo.com")
}

private enum DecoderError: Error {
Expand Down
5 changes: 3 additions & 2 deletions Sources/NetworkProtection/Settings/VPNSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import Combine
import Foundation
import Macros

/// Persists and publishes changes to tunnel settings.
///
Expand Down Expand Up @@ -81,9 +82,9 @@ public final class VPNSettings {
public var endpointURL: URL {
switch self {
case .production:
return URL(string: "https://controller.netp.duckduckgo.com")!
return #URL("https://controller.netp.duckduckgo.com")
case .staging:
return URL(string: "https://staging1.netp.duckduckgo.com")!
return #URL("https://staging1.netp.duckduckgo.com")
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions Sources/Subscription/Services/AuthService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
// limitations under the License.
//

import Foundation
import Common
import Foundation
import Macros

public struct AuthService: APIService {

Expand All @@ -29,9 +30,9 @@ public struct AuthService: APIService {
public static var baseURL: URL {
switch SubscriptionPurchaseEnvironment.currentServiceEnvironment {
case .production:
URL(string: "https://quack.duckduckgo.com/api/auth")!
#URL("https://quack.duckduckgo.com/api/auth")
case .staging:
URL(string: "https://quackdev.duckduckgo.com/api/auth")!
#URL("https://quackdev.duckduckgo.com/api/auth")
}
}

Expand Down
7 changes: 4 additions & 3 deletions Sources/Subscription/Services/SubscriptionService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
// limitations under the License.
//

import Foundation
import Common
import Foundation
import Macros

public struct SubscriptionService: APIService {

Expand All @@ -29,9 +30,9 @@ public struct SubscriptionService: APIService {
public static var baseURL: URL {
switch SubscriptionPurchaseEnvironment.currentServiceEnvironment {
case .production:
URL(string: "https://subscriptions.duckduckgo.com/api")!
#URL("https://subscriptions.duckduckgo.com/api")
case .staging:
URL(string: "https://subscriptions-dev.duckduckgo.com/api")!
#URL("https://subscriptions-dev.duckduckgo.com/api")
}
}

Expand Down
13 changes: 7 additions & 6 deletions Sources/Subscription/URL+Subscription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
//

import Foundation
import Macros

public extension URL {

static var subscriptionBaseURL: URL {
switch SubscriptionPurchaseEnvironment.currentServiceEnvironment {
case .production:
URL(string: "https://duckduckgo.com/subscriptions")!
#URL("https://duckduckgo.com/subscriptions")
case .staging:
URL(string: "https://duckduckgo.com/subscriptions?environment=staging")!
#URL("https://duckduckgo.com/subscriptions?environment=staging")
}
}

Expand All @@ -34,7 +35,7 @@ public extension URL {
}

static var subscriptionFAQ: URL {
URL(string: "https://duckduckgo.com/about")!
#URL("https://duckduckgo.com/about")
}

// MARK: - Subscription Email
Expand All @@ -53,17 +54,17 @@ public extension URL {
// MARK: - App Store app manage subscription URL

static var manageSubscriptionsInAppStoreAppURL: URL {
URL(string: "macappstores://apps.apple.com/account/subscriptions")!
#URL("macappstores://apps.apple.com/account/subscriptions")
}

// MARK: - Identity Theft Restoration

static var identityTheftRestoration: URL {
switch SubscriptionPurchaseEnvironment.currentServiceEnvironment {
case .production:
URL(string: "https://duckduckgo.com/identity-theft-restoration")!
#URL("https://duckduckgo.com/identity-theft-restoration")
case .staging:
URL(string: "https://duckduckgo.com/identity-theft-restoration?environment=staging")!
#URL("https://duckduckgo.com/identity-theft-restoration?environment=staging")
}
}
}
3 changes: 2 additions & 1 deletion Sources/TestUtils/Utils/HTTPURLResponseExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
//

import Foundation
import Macros
import Networking

extension HTTPURLResponse {

static let testEtag = "test-etag"
static let testUrl = URL(string: "www.example.com")!
static let testUrl = #URL("http://www.example.com")

static let ok = HTTPURLResponse(url: testUrl,
statusCode: 200,
Expand Down
Loading

0 comments on commit dbe75fa

Please sign in to comment.