Reputation: 17764
My library FlexColorPicker recently adopted SPM support. It works but I don't like that when FlexColorPicker package is added via Xcode, some unneeded files are downloaded. For example, FlexColorPicker.podspec
and the entire GifsAndScreenshots
folder.
Is there a way to prevent downloading these unnecessary files?
To add a package using Xcode: File → Swift Packages → Add Package Dependency... → choose target → enter https://github.com/RastislavMirek/FlexColorPicker
→ confirm
Upvotes: 23
Views: 14083
Reputation: 155
It is possible to exclude folders from your Package, by adding a Package.swift
file to the folder that you want to exclude, with these contents:
// swift-tools-version:5.5
import PackageDescription
let package = Package()
This will no longer make it visible in the Xcode navigator.
Upvotes: 7
Reputation: 1437
You can do this with the exclude
parameter on a target in your Package.swift
file. It accepts an array of paths (relative to the target root).
From the 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.
...
Using it in a Package.swift file looks something like this:
...
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"]
),
...
Also, developer.apple.com has some docs for the target -> exclude parameter
Upvotes: 15
Reputation: 2014
This is not currently possible. SwiftPM does a clone of the git repo so it will get any of those files as well.
I know that git can clone specific paths from a repo but I'm not sure of the limitations. To support for such a feature with SwiftPM there would need to be a Swift Evolution proposal.
Upvotes: 5