-
Notifications
You must be signed in to change notification settings - Fork 78
Find a better syncing solution for script files #90
Comments
@kareman @darthpelo @clayellis @pixyzehn @cojoj @alexaubry @garricn Any ideas on how this can be solved in a better way? 🙂 |
Just firing off ideas in the hopes that one of them sticks —
Or maybe that's basically what you described about Symlinking? |
One solution could be to create a small daemon that uses the Kernel Queues API to listen to file changes in the background. 🌎 From the Documentation:
Whenever the daemon would receive a file change notification from the kernel, it would copy the modified file back to its intended location, and keep both files in sync almost immediately; all this with:
Furthermore, the implementation would be fairly simple 😄 |
@clayellis The problem is that when the user edits the script in Xcode, the original script file is not the file being edited. Meaning that if some edits are made after Marathon stops syncing, they won't be copied back to the original. So the copying needs to go @alexaubry Very interesting idea. That could totally be a way forward. Need to investigate it, but looks very interesting 👍 Keep the ideas coming guys, this is going to require some brainstorming for sure 😄 |
D'oh! I was bored in a meeting when I drummed that up. I had the files backwards. I'll keep thinking. I like @alexaubry's idea — time for some reading. |
AppleScript? 🤔 (Blind guess, without any proven background) |
But we should look for something not tied to Apple's ecosystem. |
This isn't a permanent fix, nor is it very reliable one, but it's something to add to the list of ideas.
From
This works as a replacement of the current system except when Xcode was already open before we open a script for editing. In which case |
Can we make Xcode edit the original script file and place a symlink in marathons copy to it? So |
@cojoj The fix can totally be tied to Apple's ecosystem, as this is for Xcode editing only. I don't know how AppleScript could solve this problem though 😄 @clayellis Like you said, @kareman The problem is that the file need to be named Great ideas so far guys, keep 'em coming! 👍 |
The problem is that the file need to be named main.swift in order to work with Xcode as a command line tool, and we don't want to force all scripts to be named main.swift 😢 I think users of Marathon would understand why script files are named
You could regard each of these nested files as a script bundle. In the future, these script bundles could store other resources for the script to consume? Like a playground? |
When the user starts editing a script (using
marathon edit Myscript.swift
), we start syncing the file between the internal copy that Marathon maintains (in order to be able to generate packages for the script) and the original script file (located wherever the user wants).Currently, this sycning mechanism is done through a simple timer, that every 3 seconds copies the original script file back into Marathon's script folder. This is not ideal for a few reasons:
Before I implemented the syncing this way, I tried two other solutions:
Symlinking the script file
Marathon makes heavy use of symlinks (for example for packages, to "trick" SPM that packages are already compiled, so it won't re-compile them for every script). So my initial idea was to use symlinks for scripts as well. The problem is that Xcode doesn't like symlinks, and would not be able to save the file back (basically it tried to save into the symlink itself, which would cause an error dialog in Xcode). So I abandoned that idea.
Hooking into file system events
The next thing I tried was using GCD to hook into the file system to get notified whenever the file was changed. While this worked really well if the script was edited using an editor like Atom, it didn't work for Xcode, which doesn't seem to generate the same events every time the file is saved.
What we want
So, given the above context, what we want is a more robust syncing solution that fullfils the following requirements:
Perhaps we could hook into the Xcode project itself somehow? Looking for ideas from the community here 😄
The text was updated successfully, but these errors were encountered: