Skip to content

swift package init --package-path <dir-does-not-exists> does not create the directory #8393

Open
@bkhouri

Description

@bkhouri

Is it reproducible with SwiftPM command-line tools: swift build, swift test, swift package etc?

  • Confirmed reproduction steps with SwiftPM CLI. The description text must include reproduction steps with either of command-line SwiftPM commands, swift build, swift test, swift package etc.

Description

When trying to create a new package, using the --package-path option fails if the directory does not exist.

Expected behavior

swift package init --package-path <dir> should:

  • create the directory, and populate the package if it does not exists
  • should populate the package if the directory exists and is empty
  • prompt the user for action if the directory exists and is non-empty
  • should error if <dir> exists as a file

Actual behavior

directory does not exists

❯ swift package init --package-path Foo
error: chdir error: No such file or directory (2): /Users/bkhouri/Downloads/Foo

Directory exists and is empty

❯ swift package init --package-path Foo
Creating library package: Foo
Creating Package.swift
Creating .gitignore
Creating Sources
Creating Sources/Foo/Foo.swift
Creating Tests/
Creating Tests/FooTests/
Creating Tests/FooTests/FooTests.swift

Directory Exists and contains a Package.swift

❯ swift package init --package-path Foo
Creating library package: Foo
error: a manifest file already exists in this directory

Directory exists and is not empty (does not contains Package.swift)

❯ swift package init --package-path Foo
<...SNIP...>
❯ rm -rf Foo/Package.swift
❯ swift package init --package-path Foo
Creating library package: Foo
Creating Package.swift

Steps to reproduce

swift package init --package-path ./does-not-exists-yadda-yadda

Swift Package Manager version/commit hash

Swift Package Manager - Swift 6.2.0-dev

Swift & OS version (output of swift --version ; uname -a)

❯ swift --version
Apple Swift version 6.2-dev (LLVM 162ee50b401fff2, Swift 57288d13c9f3c02)
Target: arm64-apple-macosx15.0
Build config: +assertions

❯ uname -a
Darwin BKs-Work-M1Pro-MacBook-Pro-2.local 24.4.0 Darwin Kernel Version 24.4.0: Tue Mar 11 22:26:20 PDT 2025; root:xnu_development-11417.101.12~4/DEVELOPMENT_ARM64_T6000 arm64

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions