git 如何使用Swift Package Manager从repo中排除文件/文件夹?

chy5wohz  于 2023-06-20  发布在  Git
关注(0)|答案(3)|浏览(164)

我的库FlexColorPicker最近采用了SPM支持。它工作,但我不喜欢当FlexColorPicker包通过Xcode添加时,一些不需要的文件被下载。例如,FlexColorPicker.podspec和整个GifsAndScreenshots文件夹。
有没有办法避免下载这些不必要的文件?
使用Xcode添加包:File → Swift Packages → Add Package Dependency... →选择目标→输入https://github.com/RastislavMirek/FlexColorPicker →确认

50few1ms

50few1ms1#

您可以在Package.swift文件中的目标上使用exclude参数来完成此操作。它接受路径数组(相对于目标根)。
从文档:

/// Create a library or executable target.
///
/// A target can either contain Swift or C-family source files. You cannot
/// mix Swift and C-family source files within a target. A target is
/// considered to be an executable target if there is a `main.swift`,
/// `main.m`, `main.c` or `main.cpp` file in the target's directory. All
/// other targets are considered to be library targets.
///
/// - Parameters:
///   - name: The name of the target.
///   - dependencies: The dependencies of the target. These can either be other targets in the package or products from package dependencies.
///   - path: The custom path for the target. By default, targets will be looked up in the <package-root>/Sources/<target-name> directory.
///       Do not escape the package root, i.e. values like "../Foo" or "/Foo" are invalid.
///   - exclude: A list of paths to exclude from being considered source files. This path is relative to the target's directory.
///   - sources: An explicit list of source files.
///   - publicHeadersPath: The directory containing public headers of a C-family family library target.
///   - cSettings: The C settings for this target.
///   - cxxSettings: The C++ settings for this target.
///   - swiftSettings: The Swift settings for this target.
///   - linkerSettings: The linker settings for this target.
...

在Package.swift文件中使用它看起来像这样:

...
  targets: [
    // Targets are the basic building blocks of a package. A target can define a module or a test suite.
    // Targets can depend on other targets in this package, and on products in packages which this package depends on.
    .target(
      name: "MyApp",
      dependencies: [],
      exclude: ["example.swift"]
    ),
...

另外,developer.apple.com有一些docs for the target -> exclude parameter

camsedfj

camsedfj2#

这在目前是不可能的。SwiftPM对git repo做了一个克隆,因此它也可以获得这些文件中的任何一个。
我知道git可以从仓库中克隆特定的路径,但我不确定它的限制。为了支持SwiftPM的这种功能,需要有一个Swift Evolution提案。

gfttwv5a

gfttwv5a3#

您可以通过向要排除的文件夹中添加Package.swift文件来从您的包中排除文件夹,该文件夹包含以下内容:

// swift-tools-version:5.5

import PackageDescription

let package = Package()

这将不再使它在XCode导航器中可见。

相关问题