Comments (9)
I’ve been trying to figure out how we can make this work.
Without depending on libSwiftPM ourselves (which is not stable, so would be a maintenance headache) it is a chicken and egg situation.
We would need to write a Package.swift in order to resolve the deps so that we can write the Package.swift to specify the names of the products that are the dependencies of our script’s executable target.
If you write a Package.swift without any targets, I believe it will resolve the deps still, then we can re-write it correctly after getting product names via dump-package
.
Which will likely make build-times slower, oh well.
from swift-sh.
Thanks will fix. The work-around is to only specify the comment once per repository.
from swift-sh.
I did try that
#!/usr/bin/swift sh
import Basic // https://github.com/apple/swift-package-manager.git ~> 0.2.1
import Utility
Which yields
error: product dependency 'Basic' not found
Thanks!
from swift-sh.
Yeah that is a different bug which is going to be very to fix. SwiftPM doesn’t vend products that we can depend on named the same as the module names it contains.
I don’t have the bandwidth to fix this in the near future since it will basically involve a rewrite.
from swift-sh.
Specifically the target that the script needs to depend on is called SwiftPM
, not Basic
.
To determine this we can either depend on SwiftPM in swift-sh or parse the output from swift package dump-package
. Neither libSwiftPM or the JSON output are stable APIs so… hard choice.
from swift-sh.
In this case Utility
depends on Basic
so it turns out that the following works:
#!/usr/bin/swift sh
import Utility // https://github.com/apple/swift-package-manager.git ~> 0.3.0
// Note: Basic depends on Utility. The order of these imports is thus significant.
import Basic
let path = RelativePath("~/Library/Developer") // RelativePath is part of Basic module
print(path.asString)
from swift-sh.
I did have a similar issue, I had no such module 'CommandParser'
when I did it this way:
import Foundation
import PlatformLookup // mackoj/SimulatorControl
import CommandParser
import Shell
Here PlatformLookup
is the Package name and it's a target within the package.
let package = Package(
name: "PlatformLookup",
platforms: [.macOS(.v10_14)],
products: [
.executable(name: "cli", targets: ["cli"]),
.library(name: "CommandParser", targets: ["CommandParser"]),
.library(name: "SimulatorControl", targets: ["SimulatorControl"]),
.library(name: "Shell", targets: ["Shell"]),
.library(name: "PlatformLookup", targets: ["PlatformLookup"]),
],
dependencies: [
.package(url: "https://github.com/mrackwitz/Version.git", from: "0.7.2")
],
targets: [
.target(name: "cli", dependencies: ["PlatformLookup", "CommandParser"]),
.target(
name: "PlatformLookup",
dependencies: ["SimulatorControl", "Shell"]
), .target(name: "Shell"),
.target(name: "SimulatorControl", dependencies: ["Version"]),
.target(name: "CommandParser", dependencies: ["PlatformLookup"]),
.testTarget(
name: "PlatformLookupTests",
dependencies: ["PlatformLookup"]
), .testTarget(name: "ShellTests", dependencies: ["Shell"]),
],
swiftLanguageVersions: [.v5]
)
It only worked when I put CommandParser
first because I think there is some kind of sorting happening and you should have the first package in alphabetical order do the swift-sh magic import or it won't be loaded.
This was the actual solution.
import Foundation
import CommandParser // mackoj/SimulatorControl
import PlatformLookup
import Shell
I hope it help @mxcl.
from swift-sh.
The workaround described above are no longer working in version 2.1.0
.
I updated swift-sh from an earlier version since I'm now using Xcode 12.2 and existing scripts are no longer working with the error: product dependency 'MyModule' in package 'my-module' not found
I have a package that has the following structure (simplified/anonymized):
let package = Package(
name: "MyModule",
platforms: [.iOS("11.4"), .macOS("10.13"), .watchOS("4.3")],
products: [
.library(name: "MyModule", targets: ["MyModule"]),
.library(name: "MyModuleExtension", targets: ["MyModuleExtension"]),
],
dependencies: [
.package(name: "SomeExternalLib", url: "[email protected]:xxx/xxx.git", from: "2.0.5"),
],
targets: [
.target(name: "MyModule", dependencies: []),
.target(name: "MyModuleExtension", dependencies: ["MyModule", "SomeExternalLib"]),
]
)
Trying to use in a script:
#!/usr/bin/swift sh
import Foundation
import MyModuleExtension // [email protected]:stefanhp/my-module.git == 1.4
import MyModule
print("Hello world!")
It seems that the problem is that the package name MyModule
is different from the git path my-module
.
If I fork the repo to [email protected]:stefanhp/MyModule.git
it works again. But renaming the GitHub repos is not an option because there are a lot of dependencies on them. Maintaining a fork just for swift-sh usage is not very efficient.
Would there be another way to workaround this issue?
Thanks
from swift-sh.
I’ve been trying to figure out how we can make this work.
Without depending on libSwiftPM ourselves (which is not stable, so would be a maintenance headache) it is a chicken and egg situation.
We would need to write a Package.swift in order to resolve the deps so that we can write the Package.swift to specify the names of the products that are the dependencies of our script’s executable target.
If you write a Package.swift without any targets, I believe it will resolve the deps still, then we can re-write it correctly after getting product names via
dump-package
.Which will likely make build-times slower, oh well.
Would it make sense to do the follow?
``
import ProductName // @mxcl/Path.swift~PackageName/ProductName == 1.0.0
// ^^^^^^^^^^
// makes no assumptions about name alignment.
// can parse the info directly into package dependencies and then into dependency for the target.
// I chose ~ but another separator could make sense. '#' maybe?
from swift-sh.
Related Issues (20)
- Scripts don't run on M1 w/ Xcode 12.3 (x86 Homebrew) HOT 2
- Something odd about the 2.2.0 release brew record HOT 2
- Error: reference to member 'v11_1' cannot be resolved without a contextual type.macOS(.v11_1) HOT 3
- Change version to 11 HOT 1
- Fail to import when the package-name and repo-name are not identical HOT 1
- CI won't build linux with swift 5.1
- Brew complaining about outdated formula syntax HOT 1
- Error during installation: Invalid bottle tag symbol HOT 1
- Support scripts w/ `@main` HOT 1
- Dashes in product name breaks dependency resolving HOT 1
- Does not build for release with the Xcode 13 GM HOT 4
- PathKit dependency needs to be updated to 1.0.1 HOT 1
- Error reference to member `v12_1` cannot be resolved HOT 1
- Expose an option that prints the cached build directory? HOT 2
- CI and test failures update & PR links HOT 2
- Editing using `swift sh edit` eventually fails with "The file doesn't exist" HOT 2
- Configurable templates/context HOT 4
- Package not regenerated if you change the import reference HOT 1
- error: The operation couldn’t be completed. (NSPOSIXErrorDomain.13) HOT 6
- Missing support for async entry points HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swift-sh.