I have a simple Swift module that I have built with Xcode (i.e., a .framework).
I have a script (a .swift file with a"#!/usr/bin/env scrum swift shebang line).
I want to import the module into the script.
How do I tell the script where to find the module?
After scouring the web, I found the -F option to add a directory to a framework search path. Indeed, if I put the .framework in the same directory as the script and add -F . to the shebang line, that does work.
The problem is that I want to point to a specific directory ... which has spaces in its name. This is the what I’ve tried:
#!/usr/bin/env xcrun swift -F'/Users/neil/Library/Mobile Documents/com~apple~CloudDocs/zba/Templates and Includes'
And this is what happens:
<unknown>:0: error: no such file or directory: 'Documents/com~apple~CloudDocs/zba/Templates'
I.e., when it parses the shebang line, it breaks the directory path on blanks, even though I've enclosed the path in single-quotes. (Backslashing the spaces doesn’t work any better.)
Am I doing this wrong, or is there an error somewhere in the shebang-processing code?
And, as a bonus question, is this the only way of getting a framework into a script, or are there alternatives — a framework search path environment variable, for example?
jonprescott
(Jonathan Prescott)
2
Try double quotes (""). Or, escape the blanks with backslash (\). It should be just like what you would type on the command line. Blanks are end-of-token markers for the shell, but, you can enclose the string in double-quotes, or escape the blanks to tell the shell to consider the whole as a single string. Single-quotes don't work.
On macOS, I think swift looks into /System/Library/Frameworks, /Library/Frameworks, and ~/Library/Frameworks, by default. However, /System/Library/Frameworks is locked on a recent Macs.
Thank you for the suggestions. Unfortunately, single quotes, double quotes, back slashes — none of them work. (The tildes really are supposed to be tildes. That's the actual directory path to your iCloud Drive directory. Lovely, isn't it?)
I tried moving PersistentIncludeParameters.framework into ~/Library/Frameworks, and, alas, that doesn't work either.
$ ls -l ~/Library/Frameworks
total 0
drwx---r-x+ 5 neil admin 160 Aug 24 2010 EWSMac.framework
drwx---r-x+ 6 neil admin 192 Nov 10 2007 GoogleMapsShared.framework
drwxr-xr-x@ 7 neil admin 224 Jul 18 21:14 PersistentIncludeParameters.framework
$ ./Minutes\ Table.swift
./Minutes Table.swift:4:8: error: no such module 'PersistentIncludeParameters'
import PersistentIncludeParameters
^
$
So, I put the framework in ~/Library/Frameworks, and put -F /Users/myname/Library/Frameworks on the shebang line, and since there are no spaces in it, that works.
ole
(Ole Begemann)
5
@neilfaiman I think you have to wrap the entire argument in quotes, including the "-F". Like this:
... swift '-F/Users/neil/Library/Mobile Documents/com~apple~CloudDocs/zba/Templates and Includes'
I think you have to wrap the entire argument in quotes, including the " -F ".
That doesn't work here. With this command line:
#!/usr/bin/swift '-F/Users/neil/Library/Mobile Documents/com~apple~CloudDocs/zba/Templates and Includes/PersistentIncludeParameters.framework'
I get the error:
$ ./Minutes\ Table.swift
<unknown>:0: error: no such file or directory: ''-F/Users/neil/Library/Mobile'
$
(And the same if I use #!/usr/bin/env xcrun swift)
1 Like