<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">+ swift-build-dev<div class=""><br class=""></div><div class="">To take a step back here, there are two problems I see in this space:<br class=""><br class="">1) Building unnecessary test-only stuff.<br class=""><br class="">Say you have a package A which depends on a package B. B might declare a library, a test module, and some auxiliary target that's only needed by the tests. Today, if you check out A and run `swift build`, it will build B's auxiliary target (among&nbsp;other things built). That's unnecessary, and it would be nice to avoid that.<br class=""><br class="">The&nbsp;product definitions proposal&nbsp;will fix this. Once that's implemented, B would publish its library as its only product, and A would declare that it depends on that product. Then, when building A, we would know that we don't need the auxiliary&nbsp;target from B, and wouldn't build it. So I think the products proposal will solve this problem.<br class=""><br class="">2) Cloning unnecessary test-only stuff.<br class=""><br class="">Say you have a package A which depends on a package B, and B has a test module which depends on a package C. Once the products proposal has been implemented and you adopt it, running `swift build` on A will be smart enough not to&nbsp;build the test module from B or any of the targets from C; however, SwiftPM will still clone the C repository when doing dependency resolution, even though it never winds up building its products.<br class=""><br class="">I don't personally see that as a major problem, but it is one that would be nice to address at some point. Ways we could address this include:<br class=""><br class="">– We could add a "testDependencies" property on the package. These dependencies would only be resolved and cloned in situations where one or more test targets from that package need to be built. Some problems with this would be:<br class=""><br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>* Since these dependencies would only conditionally resolve, but otherwise would affect dependency resolution as normal, this could lead to some really unexpected emergent behavior. For example, if a package that's only included in the&nbsp;graph via testDependencies happens to depend on another package that's otherwise already in the graph, but with a more restrictive version specification, then whether or not you're building tests would force that other package to re-resolve with a different version.<br class=""><br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>* This is a non-generalized solution to a general problem. That is, once we have the products proposal implemented, you could wind up in this situation with no tests involved, but this mechanism wouldn't solve the problem in that case. To&nbsp;give a concrete example, if A depends on B, B vends two products, and only one of them depends on C, it's unnecessary to clone C unless the product that needs it is used by A. A properly general mechanism would let you make that&nbsp;dependency conditional on whether you need it for whatever reason, and not tie it to testing in particular. Another reason you might have this problem is if you have a dependency that only applies on one platform (e.g. linux but not macOS).&nbsp;(Conditional compilation blocks can be used for the platform case, but – once we have a better mechanism – I don't think that they should be used, for reasons that would be best discussed in its own thread).<br class=""><br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>* Adding additional properties to the Package should be done carefully. Every new property is new API surface area, and makes our documentation, initializer, etc more complicated. In my opinion, this new property doesn't justify that cost if&nbsp;it's just saving you from initial cloning of the extra packages.<br class=""><br class="">– We could add in-line dependencies for targets, as Ankit suggested. This is a more generalizable mechanism than "testDependencies". That said, it could potentially require you to duplicate your dependency declaration, which is bad. (E.g. if two&nbsp;test targets in your package depend on the same auxiliary package, that dependency would need to be stated twice). It also adds unfortunate complexity.<br class=""><br class="">– We could add a general mechanism for declaring dependencies as conditional, supporting a variety of possible conditions. Some of the SwiftPM developers are in the early discussion stages for a proposal for how to to make various parts of a&nbsp;manifest conditional, as part of a larger conversation on build settings; we'll bring our thoughts to this list once we have something coherent to propose. But if we come up with a general syntax for making things like settings conditional, the same&nbsp;consistent syntax could potentially be applied to dependencies as well.<br class=""><br class="">- - -<br class=""><br class="">Personally, I think that the products proposal solves the first problem nicely, and that we should revisit the second problem as part of an upcoming conversation about conditionals in the manifest.<br class=""></div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>- Rick</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div class="">On Jan 30, 2017, at 11:55 AM, Robert Widmann via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 30, 2017, at 2:38 PM, Ankit Agarwal &lt;<a href="mailto:ankit@ankit.im" class="">ankit@ankit.im</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><br class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div dir="auto" class=""><div class="">Not in practice (with respect to package manifests). In fact, it seems that, given there are separate commands (swift build and swift test), separate directories (Sources and Tests), and separate products, that there's a hole to be filled here by separate handling for test suites in package manifests.</div></div></blockquote><div class=""><br class=""></div><div class="">FWIW, overriding conventions will potentially allow you control the layout of the package (when we have that feature).</div></div></div></div></div></blockquote><div class=""><br class=""></div><div class="">In that case, as long as there are plans for this kind of feature, I can hold off on submitting this proposal until it materializes.</div></div></div></div></blockquote></div></body></html>