Debugging Swift Package Manager dependances - swift

How do you debug package dependancies you have imported into your project? I can't seem to see the code within the packages.
Currently I am using Carthage and you can simply set breakpoints within the code (there are flags that allow you to do this in Carthage).

It looks like you can use editable packages. Not sure how debugging this works though.

Related

How to enable java linting in Code Mirror?

We are trying to create a code editor(IDE) in Angular 11. We mainly use java code in it. We need to show lint errors while typing and also beautifier in it. Is there any package or solution already available?

Swift Package and `#if canImport(...)`. How does it work?

Excuse the vague title.
I'm trying to build a package to help me use third-party cloud storage APIs (Firebase Storage for example), adding Combine support, etc. This package does the same thing with CloudKit. Everything compiles fine, but when I import the package module into a separate project of mine, the module is apparently missing some public symbols...
Specifically, the ones wrapped inside of an #if canImport(FirebaseStorage) condition. Since Firebase doesn't support SwiftPM yet, this part of the package behaves as expected in the package project itself; it simply skips compiling that whole bit. I figured that a client project that can import this module would compile it fine.
Aside: What I'm trying to do looks something like optional dependencies. I don't want to have to import Firebase to use this package's other features. I have considered splitting the package into separate sub-packages, each depending upon the particular third-party library I want to use. I might do that anyway. But the problem remains that Firebase doesn't yet support SwiftPM (although I hear they're close).
My issue appears similar to this one. My client project just doesn't seem to see the conditioned symbols, though it can import Firebase and FirebaseStorage just fine! I mean that the generated module header is missing them entirely, preventing my client project from compiling when I use them.
It seems to me that the compile condition never leaves the package's own scope of dependent targets. Is this the case? Or am I missing something obvious? I had always assumed that Swift Packages just import and compile the Swift source files into named modules, but now I think that is not so.
Is there a way to build code into a Swift Package that compiles only when the client can import a third-party module that does not yet support SwiftPM? Or does conditional compilation not work that way?
EDIT: Here is the Swift documentation on conditional compilation, for reference.
(Answer from experience in Apr 2020)
It looks like I'm just misunderstanding the compile order.
Importing my packaged module (let's call it CloudStorage) declares a dependency in the client project to that module. Before the client project can compile with its other dependencies, CloudStorage needs to compile without the main project's dependencies. Since CloudStorage doesn't know anything about those dependencies, canImport for those dependencies evaluates to false.
This may have changed in a later version of Swift. I've yet to try again.
canImport checks whether the module name provided can be imported. For swift packages, this evaluates to true if you have provided the module as a target dependency in the package manifest and all of its associated target dependency condition are satisfied.
The benefit of this is this allows you to write code in a platform agnostic way and let your package manifest take care of platform support.
Let's say I have Firebase as a dependency in my target:
.product(name: "Firebase", package: "firebase-ios-sdk", condition: .when(platforms: [.iOS, .macOS, .tvOS])),
I can write my code that depends on Firebase with canImport. Suppose in future firebase-sdk started supporting another platform, I can add the platform to my availability condition and start supporting that platform in my code as well.
But if you don't have the module listed as dependency, even if your client app can import the module, this condition will always evaluate to false. This is due to the sandbox nature of swift package build system and all your package targets are isolated so that consuming client's build settings doesn't affect your package target.

I can't import MacPorts' /opt/local/include/ncurses.h into my Swift project. It conflicts with macos SDK /usr/include/ curses.h. Any hint?

EDIT: Getting negatives for such a detailed and HONEST question? Sometimes I don't really get Stack Overflow. Really.
Hi, I'm trying to create a PoC using Swift 5 (Xcode 10.2.1) and a modern rendition of ncurses (in this case, MacPorts' one, some 6.1.2018XXXX version)
My Poc has no code as of now, as my problems start before being able to add any sensible line to my .swift files.
So far I've done the following things:
1.- I have a proper working MacPorts ncurses library installed: that means "sudo port install htop" can build "htop" application without any problem, proving that way that my ncurses library is correctly installed (.h files seem to be deployed inside /opt/local/include/ directory)
2.- I create an empty CONSOLE APPLICATION swift program (using Xcode 10.2.1 own wizard). It just takes 4 mouse clicks, and you get some "Hello world" silly main.swift file.
3.- I create a bridging header to import my .h files (in this case ncurses.h).
The contents of this bridging header will/should be something like this:
#import "/opt/local/include/ncurses.h"
4.- I compile and run the silly empty "hello world" swift program, and I get tons of somewhat "expected" errors. Something like:
"Darwin/SDK curses.h symbol xxxxxxxxx is also defined inside your /opt/local/ncurses.h file. Bailing out." (it's not the literal error I get, you just get the idea)
So my question is:
Can I disable/remove Darwin/internal/MacOs SDK curses.h from my XCode project definition somewhere, in order my bridging header only sees one copy of my 2 (n)curses.h file (that should be my macports one)?
I've tried many things described in this other thread, but with no luck: How to disable "curses.h" header (a part of "stdio.h in Xcode 6.3 OSX Yosemite) to avoid conflicting function declarations
Specially "Enable Modules" option, which no matter the value you set it to, seems to do nothing.
BTW: I know when I might solve this .h headers issue, I will probably need to add some additional -lib linking option in the "build phase"(?) tab inside Xcode, but I'll try to manage myself when that moment arrives.
As of now my concern is "I wan't to remove Apple Internal Macos SDK curses support/files from my Xcode project". Is it achievable?
PS: I'm using Mojave 10.4.4 with no problem
I'm having the same issues, although trying to use ncurses via the Swift Package Manager. Despite being actively trying to find a solution I've been unsuccessful so far. Check my question just in case: Swift package manager unable to compile ncurses installed through Homebrew
This answer should give you all the information you need to get it working :) https://stackoverflow.com/a/56728436/554972

How do I use Swift Package Manager with an existing macOS project?

I've been using Cocoapods to manage dependencies for my Swift project. I came across this package which is not listed at Cocoapods. Instead it suggests using Swift Package Manager. However, whenever I try to use Swift Package Manager to do basically anything, it ends up completely destroying my entire project.
So, in order to figure out how to actually use Swift Package Manager, I'm playing with it in a test project.
Here's what I've tried:
Create a new project from Xcode
File -> New -> Project -> Cocoa App
Product Name: basic-ssh-test
This creates a basic application which loads a blank window when I hit "Run". Just for fun I added print("test") to the applicationDidFinishLaunching function in my AppDelegate so the debug window says "test" when I run the program.
Now I want to add the Shout package as a dependency.
swift package init --type executable
This creates the following files:
Creating executable package: basic-ssh-test
Creating Package.swift
Creating README.md
Creating .gitignore
Creating Sources/
Creating Sources/basic-ssh-test/main.swift
Creating Tests/
Now I'm going to add the "Shout" dependency to my new Package.swift file:
// swift-tools-version:4.0
import PackageDescription
let package = Package(
name: "basic-ssh-test",
dependencies: [
.package(url: "https://github.com/jakeheis/Shout", from: "0.2.0")
],
targets: [
.target(
name: "basic-ssh-test",
dependencies: ["Shout"]),
]
)
And I'll pull in the dependencies:
swift package resolve
This results in the dependencies being pulled into the .build directory:
Fetching https://github.com/jakeheis/Shout
Fetching https://github.com/jakeheis/CSSH
Fetching https://github.com/IBM-Swift/BlueSocket
Cloning https://github.com/IBM-Swift/BlueSocket
Resolving https://github.com/IBM-Swift/BlueSocket at 0.12.91
Cloning https://github.com/jakeheis/CSSH
Resolving https://github.com/jakeheis/CSSH at 1.0.3
Cloning https://github.com/jakeheis/Shout
Resolving https://github.com/jakeheis/Shout at 0.3.0
Now I regenerate the xcodeproj file:
swift package generate-xcodeproj
Now when I open the xcodeproj file there is a new group called Sources that has a single directory basic-ssh-test with a single swift file in it main.swift with print("Hello, world!").
The code that I'm actually interested in running is now in a blue folder called basic-ssh-test. All of the necessary files are still in there, but instead of running my application, Xcode is running the main.swift file. I can tell because the debug output is "Hello, world!" instead of "test".
I've read a couple of tutorials that claim that Swift Package Manager will move my source files and continue to build the same as before, but that's clearly not the case.
There's also no longer a "Main Interface" option in my Build Settings, so I can't select "MainMenu.xib" as my application starting point.
This is essentially the same thing that happens when I try to use Swift Project Manager with my existing project. It pulls in the dependencies, but it basically ignores my entire existing project and just runs the "hello world" code.
How do I use Swift Package Manager to add a dependency to an existing project without ignoring the existing codebase?
I think SPM is only compatible with Mac command line executables or libraries. This explicitly states SPM doesn't support iOS, watchOS, or tvOS platforms at all. But, since macOS AppKit/Cocoa application targets are very similar to iOS or tvOS Xcode targets, I would say this statement implies that SPM can't be used with macOS Cocoa applications out of the box either, which is what I think you're hoping for.
It looks like there is some work here on how to use it with iOS application targets which should largely translate to a macOS Cocoa target.
Until the time of this writing answer, Swift Package Manager do not support the iOS, tvOS, and watchOS. Instead, you will have to add the files from the package directly to your project.
I would suggest you creating a Dependencies group in your project and a group below that with the package name, like this answer:
So, first you will add the files dependency that you want to import into your project to the name of the package name that included in Dependencies group that we make before.
After you add the files then you can access the code as you usually would when you write it yourself like the image below. No need imports. You can see more details in here. hope it helps.
You can create a windowed application using SPM (I have a whole project sitting waiting for ABI that does this) you just need some boiler plate in swift.main. I’ll dig it out.
However the method others are suggesting is never going to work (with current versions of SPM).
However, what I am seeing is that you really want to use SPM to manage dependencies (keeping up to date etc). So I think you could do that much more easily.
Rather than creating a executable as your default target, instead create a library (perhaps call it basic-ssh-dependencies). Generate your Xcode project and drag THAT into your primary Xcode project and configure your target to to depend on it. When you update the library from SPM for changes in dependencies you should re-gen your Xcode-proj.
Let me know your mileage and any wrinkles, or if I’ve misunderstood what you are trying to achieve.
Update for XCode 11
This is A LOT easier now with XCode 11. As of this writing the current version of XCode is 11.3.1.
For an existing XCode project simply:
go to File->Swift Packages->Add Package Dependency...
enter the URL of the hosted package you want to add
choose the rules about which versions your app will use
click Finish

I can't get qml to use my custom plugin

I'm working in QtQuick and right now struggling with a weird problem: I can't get my custom plugin to work in Qml. There's a simple demo in the SDK (Examples/4.7/declarative/tutorials/extending/chapter6-plugins) and this doesn't work on my computer either. I don't get any error messages except that it doesn't recognize my custom items. Has anybody seen this problem? Any suggestions?
My setup:
Win 7 Home Premium, Qt Creator 2.1.0, Qt 4.7.3 (MinGW 4.4)
Thanks
Beside the qmldir issue already mentioned by blakharaz, also make sure to set QML_IMPORT_PATH in your pro file or setting the path via QDeclarativeEngine::addImportPath() so the module can be found on your development environment (if you don't install them systemwide before using).
And when using subfolders, make sure they are part of the import (see http://doc.qt.nokia.com/4.7-snapshot/qdeclarativemodules.html)
It would be nice to have some code. One possible issue could be the directory structure or the qmldir file. If you want to have a plugin called Foo you basically need a directory Foo which contains the Foo.dll (or libFoo.so) and a qmldir file (content is at least "plugin Foo")
If you have that "import Foo 1.0" should load the library.
I just had the exact same problem.
Build your .dlls as release instead of debug, that fixed it for me.