iT邦幫忙

2023 iThome 鐵人賽

DAY 4
0
自我挑戰組

自己的 Leak, 自己抓(swift)系列 第 4

需要掃描哪幾份檔案

  • 分享至 

  • xImage
  •  

這邊我們要先用第一個 lib SourceKitten

透過 SourceKitten.Module 取得 某 Targetfile list.

以及編譯時的參數‧

Package.swift

// swift-tools-version: 5.7
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "LeakDetect",

    dependencies: [
        .package(url: "https://github.com/jpsim/SourceKitten", from: "0.34.1"),
    ],
    targets: [
        .target(
            name: "LeakDetectKit",
            dependencies: [
                 .product(name: "SourceKittenFramework", package: "SourceKitten"),
            ]
        ),
    ]
)

Target SPM

import SourceKittenFramework

let arguments: [String] = []
// .target(name: "LeakDetectKit")
let moduleName = "LeakDetectKit"
let path = "~/LeakDetect"
Module(spmArguments: arguments, spmName: moduleName, inPath: path)

Target .xcodeproj

import SourceKittenFramework

let scheme = "My Module"
let target = "My_Module"
let arguments: [String] = [
    "-project", "/path/to/xxx.xcodeproj",
    "-scheme", scheme,
]
Module(xcodeBuildArguments: arguments, name: target)

Target .xcworkspace

import SourceKittenFramework

let scheme = "My Module"
let target = "My_Module"
let arguments: [String] = [
    "-workspace", "/path/to/xxx.xcworkspace",
    "-scheme", scheme,
]
Module(xcodeBuildArguments: arguments, name: target)

最終我們可以取得

/// 某 `Target` 底下所有的 file list
module.sourceFiles
/// 編譯此 `Target` 所需的編譯參數
module.compilerArguments

上一篇
定義潛在 Leak
下一篇
SwiftSyntax 前導 (AST)
系列文
自己的 Leak, 自己抓(swift)30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言