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

时间:2019-10-10 11:34:47

标签: xcode git github xcode11 swift-package-manager

我的图书馆FlexColorPicker最近采用了SPM支持。它可以工作,但是我不喜欢通过XCode添加FlexColorPicker软件包时(文件→Swift软件包→添加软件包依赖性...→选择目标→输入https://github.com/RastislavMirek/FlexColorPicker→确认),例如,下载了一些不需要的文件。 FlexColorPicker.podspec和整个GifsAndScreenshots文件夹。

有没有一种方法可以防止下载不必要的文件?

2 个答案:

答案 0 :(得分:1)

您可以在exclude文件中的目标上使用Package.swift参数来执行此操作。它接受路径数组。

来自docs

/// 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

答案 1 :(得分:0)

目前无法实现。 SwiftPM会克隆git repo,因此也会获取其中的任何文件。

我知道git可以从仓库中克隆特定的路径,但是我不确定这些限制。为了在SwiftPM中支持这种功能,需要一个Swift Evolution提案。