Skip to content

Commit 40e7762

Browse files
Merge pull request #2112 from DataDog/rum-7285-add-api-surface-step-to-ci
RUM-7285 Add api-surface step to Lint stage Co-authored-by: mariedm <marie.denis@datadoghq.com>
2 parents 5f84a6a + d131e65 commit 40e7762

11 files changed

Lines changed: 434 additions & 98 deletions

File tree

.gitlab-ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ Lint:
125125
- make lint license-check
126126
- make rum-models-verify sr-models-verify
127127

128+
API Surface Verify:
129+
stage: lint
130+
rules:
131+
- if: '$CI_COMMIT_BRANCH =~ /^(release|hotfix)\/.*/'
132+
script:
133+
- make clean repo-setup ENV=ci
134+
- make api-surface-verify
135+
128136
Unit Tests (iOS):
129137
stage: test
130138
rules:

Makefile

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -321,37 +321,60 @@ sr-snapshot-tests-open:
321321
@$(ECHO_TITLE) "make sr-snapshot-tests-open"
322322
./tools/sr-snapshot-test.sh --open-project
323323

324-
# Generate api-surface files for Datadog.
324+
### API-SURFACE
325+
326+
# Define default paths for API output files
327+
SWIFT_OUTPUT_PATH ?= api-surface-swift
328+
OBJC_OUTPUT_PATH ?= api-surface-objc
329+
330+
# Use different paths when running in CI
331+
ifeq ($(ENV),ci)
332+
SWIFT_OUTPUT_PATH := api-surface-swift-generated
333+
OBJC_OUTPUT_PATH := api-surface-objc-generated
334+
endif
335+
336+
# Define the list of Datadog modules for API surface generation
337+
DATADOG_MODULES := DatadogCore DatadogLogs DatadogTrace DatadogRUM DatadogCrashReporting DatadogWebViewTracking DatadogSessionReplay
338+
339+
# Generate api-surface files for Datadog APIs
325340
api-surface:
326-
@echo "Generating api-surface-swift"
327-
@cd tools/api-surface && \
328-
swift run api-surface spm \
329-
--path ../../ \
330-
--language swift \
331-
--library-name DatadogCore \
332-
--library-name DatadogLogs \
333-
--library-name DatadogTrace \
334-
--library-name DatadogRUM \
335-
--library-name DatadogCrashReporting \
336-
--library-name DatadogWebViewTracking \
337-
--library-name DatadogSessionReplay \
338-
> ../../api-surface-swift && \
339-
cd -
340-
341-
@echo "Generating api-surface-objc"
342-
@cd tools/api-surface && \
343-
swift run api-surface spm \
344-
--path ../../ \
345-
--language objc \
346-
--library-name DatadogCore \
347-
--library-name DatadogLogs \
348-
--library-name DatadogTrace \
349-
--library-name DatadogRUM \
350-
--library-name DatadogCrashReporting \
351-
--library-name DatadogWebViewTracking \
352-
--library-name DatadogSessionReplay \
353-
> ../../api-surface-objc && \
354-
cd -
341+
@$(ECHO_TITLE) "make api-surface"
342+
@echo "Generating api-surface-swift"
343+
@cd tools/api-surface && \
344+
swift run api-surface generate \
345+
--path ../../ \
346+
--language swift \
347+
$(foreach module,$(DATADOG_MODULES),--library-name $(module)) \
348+
--output-file ../../$(SWIFT_OUTPUT_PATH)
349+
350+
@echo "Generating api-surface-objc"
351+
@cd tools/api-surface && \
352+
swift run api-surface generate \
353+
--path ../../ \
354+
--language objc \
355+
$(foreach module,$(DATADOG_MODULES),--library-name $(module)) \
356+
--output-file ../../$(OBJC_OUTPUT_PATH)
357+
358+
# Verify API surface files for Datadog APIs
359+
api-surface-verify:
360+
@$(ECHO_TITLE) "make api-surface-verify"
361+
@echo "Verifying api-surface-swift"
362+
@cd tools/api-surface && \
363+
swift run api-surface verify \
364+
--path ../../ \
365+
--language swift \
366+
$(foreach module,$(DATADOG_MODULES),--library-name $(module)) \
367+
--output-file /tmp/api-surface-swift-generated \
368+
../../api-surface-swift
369+
370+
@echo "Verifying api-surface-objc"
371+
@cd tools/api-surface && \
372+
swift run api-surface verify \
373+
--path ../../ \
374+
--language objc \
375+
$(foreach module,$(DATADOG_MODULES),--library-name $(module)) \
376+
--output-file /tmp/api-surface-objc-generated \
377+
../../api-surface-objc
355378

356379
# Builds API documentation using the same process as Swift Package Index.
357380
spi-docs-build:

api-surface-objc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ public final class objc_URLSessionInstrumentation: NSObject
7171
public static func enable(configuration: objc_URLSessionInstrumentationConfiguration)
7272
public static func disable(delegateClass: URLSessionDataDelegate.Type)
7373

74-
7574
# ----------------------------------
7675
# API surface for DatadogLogs:
7776
# ----------------------------------
@@ -233,7 +232,6 @@ public enum objc_LogEventRadioAccessTechnology: Int
233232
case LTE
234233
case unknown
235234

236-
237235
# ----------------------------------
238236
# API surface for DatadogTrace:
239237
# ----------------------------------
@@ -310,7 +308,6 @@ public final class objc_Tracer: NSObject, objc_OTTracer
310308
public func inject(_ spanContext: objc_OTSpanContext, format: String, carrier: Any) throws
311309
public func extractWithFormat(_ format: String, carrier: Any) throws
312310

313-
314311
# ----------------------------------
315312
# API surface for DatadogRUM:
316313
# ----------------------------------
@@ -2351,14 +2348,12 @@ public class objc_RUMMonitor: NSObject
23512348
[?] extension objc_RUMMonitor
23522349
public func _internal_sync_addError(_ error: Error,source: objc_RUMErrorSource,attributes: [String: Any])
23532350

2354-
23552351
# ----------------------------------
23562352
# API surface for DatadogCrashReporting:
23572353
# ----------------------------------
23582354

23592355

23602356

2361-
23622357
# ----------------------------------
23632358
# API surface for DatadogWebViewTracking:
23642359
# ----------------------------------
@@ -2367,7 +2362,6 @@ public final class objc_WebViewTracking: NSObject
23672362
public static func enable(webView: WKWebView,hosts: Set<String> = [],logsSampleRate: SampleRate = .maxSampleRate)
23682363
public static func disable(webView: WKWebView)
23692364

2370-
23712365
# ----------------------------------
23722366
# API surface for DatadogSessionReplay:
23732367
# ----------------------------------

api-surface-swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public enum Datadog
5858
public var backgroundTasksEnabled: Bool
5959
public init(clientToken: String,env: String,site: DatadogSite = .us1,service: String? = nil,bundle: Bundle = .main,batchSize: BatchSize = .medium,uploadFrequency: UploadFrequency = .average,proxyConfiguration: [AnyHashable: Any]? = nil,encryption: DataEncryption? = nil,serverDateProvider: ServerDateProvider? = nil,batchProcessingLevel: BatchProcessingLevel = .medium,backgroundTasksEnabled: Bool = false)
6060

61-
6261
# ----------------------------------
6362
# API surface for DatadogLogs:
6463
# ----------------------------------
@@ -178,7 +177,6 @@ public enum Logs
178177
public protocol LogEventMapper
179178
func map(event: LogEvent, callback: @escaping (LogEvent) -> Void)
180179

181-
182180
# ----------------------------------
183181
# API surface for DatadogTrace:
184182
# ----------------------------------
@@ -315,7 +313,6 @@ public enum SpanTags
315313
public class Tracer
316314
public static func shared(in core: DatadogCoreProtocol = CoreRegistry.default) -> OTTracer
317315

318-
319316
# ----------------------------------
320317
# API surface for DatadogRUM:
321318
# ----------------------------------
@@ -528,7 +525,6 @@ public enum PerformanceMetric
528525
case flutterRasterTime
529526
case jsFrameTimeSeconds
530527

531-
532528
# ----------------------------------
533529
# API surface for DatadogCrashReporting:
534530
# ----------------------------------
@@ -542,7 +538,6 @@ public protocol CrashReportingPlugin: AnyObject
542538
func inject(context: Data)
543539
var backtraceReporter: BacktraceReporting?
544540

545-
546541
# ----------------------------------
547542
# API surface for DatadogWebViewTracking:
548543
# ----------------------------------
@@ -555,7 +550,6 @@ public enum WebViewTracking
555550
public func send(body: Any, slotId: String? = nil)
556551
public static func messageEmitter(in core: DatadogCoreProtocol,logsSampleRate: SampleRate = .maxSampleRate) -> AbstractMessageEmitter
557552

558-
559553
# ----------------------------------
560554
# API surface for DatadogSessionReplay:
561555
# ----------------------------------

tools/api-surface/Fixtures/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 5.7.1
1+
// swift-tools-version: 5.9
22

33
import PackageDescription
44

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
3+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
4+
* Copyright 2019-Present Datadog, Inc.
5+
*/
6+
7+
/// ObjC APIs for Fixture1 used in `api-surface` tests.
8+
9+
import Foundation
10+
11+
@objc(DDObjcCar)
12+
@objcMembers
13+
@_spi(objc)
14+
public class objc_Car: NSObject {
15+
@objc
16+
public enum Manufacturer: Int {
17+
case manufacturer1
18+
case manufacturer2
19+
case manufacturer3
20+
}
21+
22+
internal let swiftCar: Car
23+
24+
public init(manufacturer: Manufacturer) {
25+
let swiftManufacturer: Car.Manufacturer
26+
switch manufacturer {
27+
case .manufacturer1: swiftManufacturer = .manufacturer1
28+
case .manufacturer2: swiftManufacturer = .manufacturer2
29+
case .manufacturer3: swiftManufacturer = .manufacturer3
30+
@unknown default: swiftManufacturer = .manufacturer1
31+
}
32+
self.swiftCar = Car(manufacturer: swiftManufacturer)
33+
}
34+
35+
public func startEngine() -> Bool {
36+
swiftCar.startEngine()
37+
}
38+
39+
public func stopEngine() -> Bool {
40+
swiftCar.stopEngine()
41+
}
42+
43+
public var price: Int {
44+
swiftCar.price
45+
}
46+
}
47+
48+
@objc(DDCarDelegate)
49+
@_spi(objc)
50+
public protocol objc_CarDelegate: AnyObject {
51+
func carDidStart(_ car: objc_Car)
52+
func carDidStop(_ car: objc_Car)
53+
}
54+
55+
@objc(DDCarConfiguration)
56+
@objcMembers
57+
@_spi(objc)
58+
public class objc_CarConfiguration: NSObject {
59+
public var maxPrice: Int
60+
61+
public init(maxPrice: Int) {
62+
self.maxPrice = maxPrice
63+
}
64+
65+
public func setDelegate(_ delegate: objc_CarDelegate?) {
66+
// Configure delegate
67+
}
68+
}

tools/api-surface/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let package = Package(
77
platforms: [.macOS(.v13)],
88
dependencies: [
99
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.2.2"),
10-
.package(url: "https://github.com/jpsim/SourceKitten", exact: "0.34.1"),
10+
.package(url: "https://github.com/jpsim/SourceKitten", exact: "0.37.2"),
1111
],
1212
targets: [
1313
.executableTarget(

tools/api-surface/Sources/APISurfaceCore/APISurface.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public struct APISurface {
3131
let module = Module(
3232
xcodeBuildArguments: [
3333
"-scheme", libraryName,
34-
"-destination", "platform='iOS Simulator'",
34+
"-destination", "platform=iOS Simulator,name=iPhone 16 Pro,OS=18.3.1",
3535
"-sdk", "iphonesimulator",
3636
],
3737
inPath: newPath

0 commit comments

Comments
 (0)