Exclude folders - New feature in SPM
Download examples
Swift Package Manager got a New Feature! Yea! Hurray! ππ―πΎππ£π
But why we needed it? Let's see ...
The Problem
Let's have a look on this folder structure
Package
βββ LibA
β βββ A.swift
βββ LibB
β βββ B.swift
βββ Tools
β βββ Tools.swift
Now we run swift-build and get the follow result:
.build
βββ LibA.a
βββ LibB.a
βββ Tools.a
So, the problem here is that I don't want to generate a target for a Tools folder. I want to exclude it. Let's do that, it've very easy.
Exclude folders
Open Package.swift file and declare exclude folders for your package.
import PackageDescription
let package = Package(
exclude: ["Tools"]
)
That's it!π Now just clean cached .build folder and build the package again. Not it creates only 2 targets LibA.a and LibB.a
Some rules to remember:
- You can exclude many folders.
["A", "B"] - Also you can specify path to a nested folder.
["A\subFolder"] - The names are case-sensitive.
("Tools" != "tools")
import PackageDescription
let package = Package(
exclude: ["Tools", "someOther", "Lib/code/Old"]
)
The paths specified in the exclude are relative to the Root folder of the package. This means that the example above would exclude these folders:
Package
βββ Tools
βββ someOther
βββ Lib
β βββ code
β βββ Old
P.S
To use that feature you need use latest version of a swift-build from master branch.
- Clone the repo,
- Build
swift-buildtool by running./Utilities/bootstrap - Opne
.build/debugfolder - Run it -
./swift-build --chdir PackagePathToBuild
Example:./swift-build --chdir /Users/kostiantyn/HelloSPM