<div><br><div class="gmail_quote"><div dir="auto">Geordie J &lt;<a href="mailto:geojay@gmail.com">geojay@gmail.com</a>&gt; schrieb am Fr. 21. Juli 2017 um 14:39:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Hi Ankit, thanks for your reply.<div><br><div></div></div></div><div style="word-wrap:break-word"><div><div><blockquote type="cite"><div>Am 21.07.2017 um 07:33 schrieb Ankit Aggarwal via swift-users &lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt;:</div><br class="m_3924764206806564691Apple-interchange-newline"><div><div><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jul 20, 2017 at 10:34 PM, Geordie J via swift-users <span>&lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Hi all,<div><br></div><div>My team and I are trying to use SwiftPM to develop a relatively complex app with multiple dependencies, all of which are being developed locally and in parallel. The reason for this is compatibility with an existing module/import structure used by our iOS app. Maybe I’m doing something very wrong but my experience so far (2 months in) is that this is extremely difficult with SwiftPM.</div><div><br></div><div>What I’d love to be able to do is to just run `git add submodule <a href="http://blah.com/mysubmodule.git%60" target="_blank">http://blah.com/mysubmodule.git`</a> in the Packages subdirectory and SwiftPM would just let me manage dependencies from there myself.</div><div><br></div><div>I was excited to see that SwiftPM 4 has a &quot;Top of Tree&quot; development option for this purpose. So far my experience with this has not been good. Firstly because SwiftPM <i>still</i> unnecessarily tries to clone my repos itself (some of which are huge), and secondly because this creates an absolute path dependency in `.build/dependencies-state.json`, meaning this setup isn’t sharable within our dev team.</div><div><br></div><div>Attempting this with &quot;local&quot; git urls adds an almost absurd level of complexity, having to tag each commit for SwiftPM to build. The fact that we&#39;d need to make a commit to test whether the project even builds is insane enough as is, let alone the tagging and trying to tell the base project to use a newer minor version etc etc.</div><div><br></div><div>Adding multiple subtargets is also not an option because the dependencies (as dynamic libraries) really are shared between multiple targets/sub-dependencies, which SwiftPM seems to deal with quite well.</div><div><br></div><div><b>tldr;</b> *Please* let us manage dependencies ourselves. It’d be so easy if Package.swift had an option along the lines of <b>.Package.local(named: &quot;XYZ&quot;)</b> that it then looked for in ./Packages/XYZ. Again, maybe I’m overlooking something but this seems like an obvious and vital option to have. It’d also simplify the introductory SwiftPM docs significantly.</div><div><br></div><div>Is anyone else having this issue? Would this change really be as simple and painless as it sounds? I would be prepared to make a pull request along these lines.</div></div></blockquote><div><br></div><div>I think you&#39;re not really using the Top of Tree feature. You need to add each dependency using its canonical URL, hosted at some server like github. After adding the dependencies, you can use edit feature to put a dependency in Top of Tree mode. To do so, run:</div><div><br></div><div>$ swift package edit &lt;PackageName&gt; --path ../path/to/self/managed/checkout/of/the/package</div></div></div></div></div></blockquote><div><br></div></div></div></div><div style="word-wrap:break-word"><div><div><div>Yes, this is what I tried this week. I’m pretty sure this is not a case of misunderstanding the feature or the docs.</div></div></div></div><div style="word-wrap:break-word"><div><div><br><blockquote type="cite"><div><div><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>The package manager will then stop using the cloned repository and use the checkout present at that path (regardless of the state it is in).</div></div></div></div></div></blockquote><div><br></div></div></div></div><div style="word-wrap:break-word"><div><div><div>Yes, but then I have – per dependency – two checkouts of a potentially huge repository. Why force everyone on the dev team to clone a huge repo twice, only to *never* use one of the clones. Also, SwiftPM breaks when —path points at Packages/PackageName, which is exactly where I’d expect the package to be, not in some arbitrary external path (+ some kind of internal checkout cache that will never be used) as well.</div><div><br></div><div>I haven’t tried to test this recently because it’s a slow process but I have the impression the deps could be even be cloned more than twice, depending on how cleverly SwiftPM realises that multiple Packages have the same dependency.</div><div><br></div><div>Also, this makes managing interdependent state of development amongst dependencies more difficult than needed. How do we guarantee that devs are on the same commit when using top of tree development? Tagging and managing version numbers etc for day-to-day development is emphatically not an option for us. Since SwiftPM packages only work from a git context anyway, why not allow use of git’s established pattern of dealing with this, namely submodules?</div></div></div></div><div style="word-wrap:break-word"><div><div><br><blockquote type="cite"><div><div><div class="gmail_extra"><div class="gmail_quote"><div>Sharing this setup is not automatic, but simple. Each user just needs to run the above command once per dependency.</div></div></div></div></div></blockquote><div><br></div></div></div></div><div style="word-wrap:break-word"><div><div><div>We have about 10 dependencies, <i>all </i>of which will<i> always</i> be in this state. This seems like a lot of overhead and room for user error, plus it’s a huge workaround for something that could be very simple.</div></div></div></div><div style="word-wrap:break-word"><div><div><br><blockquote type="cite"><div><div><div class="gmail_extra"><div class="gmail_quote"><div>Also, you only need to do this if you&#39;re actively working on a dependency. </div></div></div></div></div></blockquote><div><br></div></div></div></div><div style="word-wrap:break-word"><div><div><div>The point is that we will <i>always</i> be working on the dependencies. This is the core of what we’re doing, not a short aside. This is what makes me think we are either doing something wrong, or there is a big feature gap (as it appears from here).</div></div></div></div><div style="word-wrap:break-word"><div><div><br><blockquote type="cite"><div><div><div class="gmail_extra"><div class="gmail_quote"><div>The new manifest also supports using branch instead of version range, which is very helpful during the development period.</div></div></div></div></div></blockquote><div><br></div></div></div></div><div style="word-wrap:break-word"><div><div><div>This has much the same result as top-of-tree development, but it is how we were able to &quot;hack&quot; SwiftPM 3 into leaving us alone.</div></div></div></div><div style="word-wrap:break-word"><div><div><div><br></div><blockquote type="cite"><div><div><div class="gmail_extra"><div class="gmail_quote"><div>Let me know if something is unclear or if you have more questions!</div></div></div></div></div></blockquote><div><br></div></div></div></div><div style="word-wrap:break-word"><div><div><div>Maybe an overview of our structure would be helpful to make our use case clearer:</div><div><br></div><div>Main Project (git repo, not a Swift Package, contains no swift code directly)</div><div>–– Dependencies (external)</div><div>–– Subproject (<b>internal</b> git submodule, is a Swift Package, has multiple Swift Targets)</div><div>–––– Dependency A (<b>internal</b>, git submodule)</div><div>–––––––– Huge external C-language dependencies (managed via git submodules)</div><div>–––– Dependency B (<b>internal</b>, git submodule)</div><div><div>–––––––– Depends on internal dependency D</div></div><div>–––– Dependency C (<b>internal</b>, git submodule)</div><div><div>–––––––– Depends on <b>internal</b> dependency A</div><div>–––––––– Depends on <b>internal</b> dependency B</div><div>–––––––– etc.</div></div><div>–––– Dependency D (<b>internal</b>, git submodule)</div><div></div></div></div></div></blockquote><div dir="auto"><br></div><div dir="auto">Reading over this entire thread, I&#39;ve come across this again, which I think sums up the pain point better than anything else:</div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div><div><br></div><div><b>I think the friction is coming from the fact that we’d like to use SwiftPM <i>just to build</i>, rather than to manage our dependencies.</b></div></div></div></div></blockquote><div dir="auto"><br></div><div dir="auto"><div dir="auto">When I say &quot;swift build&quot;, I expect swift to build! Not to check for commits and tags and dependencies, not to clone anything, just build what is there. For all the other stuff we have the &quot;swift package ...&quot; commands.</div><div dir="auto"><br></div><div dir="auto">Imagine if &quot;swift package update&quot; did the step that currently happens before &quot;swift build&quot; builds the project (dep management, cloning etc). And to retain old behaviour we could have &quot;swift build --update-deps&quot; with a note on failing &quot;swift build&quot; builds suggesting users try the update flag to get the old behaviour.</div><div dir="auto"><br></div><div dir="auto">I think this would be an equally welcome addition for users not currently on a strong internet connection.</div><div dir="auto"><br></div><div dir="auto">The question would be how Swift knows which dependency is which. The answer should be pretty simple: look in each Packages/package/Package.swift for the available package names and build them if there&#39;s a dependency on them somewhere in the graph.</div><div dir="auto"><br></div><div dir="auto">There&#39;s something about that idea that seems at odds with the current git-centric model, though I&#39;m still skeptical that the git-centric model is a reasonable base case.  For example, it&#39;s confusing because Sources/TargetName uses a filesystem convention while package dependencies currently do not, but kind of actually do after &quot;swift package edit&quot; has been run, and would have to with any of the current proposals. Is the complexity of using git as the base case becoming clear? No matter what we&#39;re doing, the reality is that we end up with files in our filesystem. To me having the dep as a remote git repo is actually the edge case, which is the opposite of the current model.</div><div dir="auto"><br></div><div dir="auto">To do anything with a moderate level of complexity took me weeks to get figure out the ins and outs of and get to a point where it was repeatable within the team. Again, I think this can be done better. And I think assuming that dependencies are local unless specified otherwise would make this a lot easier. Why not for example just have &quot;swift package update&quot; check out the git repos into its internal build cache and symlink them into Packages/PackageName, always building packages from ./Packages? I&#39;d find that a lot more consistent and transparent.</div><div dir="auto"><br></div><div dir="auto">In the meantime the multi-package repo proposal seems like a step in the right direction. In a way though it seems to me like a crutch for an underlying inconsistency in both tooling namespaces (&quot;swift build&quot; vs &quot;swift package&quot;) and in convention vs configuration (specific directory structure vs automated dep management via git).</div><div dir="auto"><br></div><div dir="auto">I&#39;m not sure what the implications of this are, but I&#39;m starting to wonder whether &quot;swift build&quot; and &quot;swift package&quot; are conceptually two different but related projects, and whether it&#39;d be a good idea in the medium-long term to more clearly separate them.</div><div dir="auto"><br></div><div dir="auto">Cheers,</div><div dir="auto">Geordie</div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto">PS. The top-of-tree workaround does work after all, but is complicated because we&#39;re also running &quot;swift build&quot; from within a docker image to build for other platforms, so the absolute paths are (inescapably) different between the environments.</div><div dir="auto"><br></div><div dir="auto">Again, the idea of having absolute paths there at all seems unnecessary, but until multi-package repos are available it seems the best option will be scripting a find-and-replace in &quot;.build/dependencies-state.json&quot; before running &quot;swift build&quot;...</div></div><div dir="auto"><br></div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div><div><b></b></div><div><br></div><div>Again, this could be solved with a simple API addition in the manifest:</div><div><br></div><div>Package(</div><div>  …</div><div>  dependencies: [</div><div>    .package.local(named: &quot;Dependency A&quot;)</div><div>    .package.local(named: &quot;Dependency B&quot;)</div><div>    ...</div><div>  ]</div><div>)</div><div><br></div><div><br></div><div>At the end of the day it seems we can work around this by cloning the submodules at <b>Project/Submodule</b> instead of <b>Project/Package/Submodule</b> and then running <b>swift package edit Submodule —path ./Submodule</b>, just that this process would have to be manual for each new dev cloning the repo. And then we’d still have two checkouts of the same thing. Yes, this works, it just seems very inefficient and still hacky. And it’s very possible it&#39;ll break again with future SwiftPM versions.</div><div><br></div><div>I’m just surprised the idea of a &quot;local dependency&quot; is not seen as a first class citizen in SwiftPM, still trying to understand the logic behind that. Maybe you can give me an idea of the reasoning behind this?</div><div><br></div><div>Best Regards,</div><div>Geordie</div></div></div></div></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div><div></div></div></div></div><div style="word-wrap:break-word"><div><div><br><blockquote type="cite"><div><div><div class="gmail_extra"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div></div><div>Best Regards,</div><div>Geordie</div><div><br></div><div><br></div><div>PS. In SwiftPM 3 we had been using a hack that worked great: by filling in the dependencies&#39; &quot;basedOn&quot; key in `workspace-state.json`, SwiftPM just left us alone.. We were able to commit `workspace-state.json` into our base project’s git repo and the rest Just Worked™. Now with the absolute paths being checked for this doesn’t seem to be an option.</div></div><br></blockquote><div><br></div><div>Please do not rely on internals of the package manager as they&#39;re not stable and will change without notice.</div></div></div></div></div></blockquote><div><br></div></div></div></div><div style="word-wrap:break-word"><div><div><div>This was not our preferred way of going about it of course. But it was (unfortunately) the best solution to the problem.</div></div></div></div><div style="word-wrap:break-word"><div><div><br><blockquote type="cite"><div><div><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">_______________________________________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br>
<br></blockquote></div><br></div></div>
_______________________________________________<br>swift-users mailing list<br><a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br></div></blockquote></div></div></div></blockquote></div></div>