-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for partially-shared source directories #145
Conversation
} | ||
|
||
private def makePartiallySharedSettings(platforms: Seq[Platform])(mkSettings: Seq[Platform] => Seq[Setting[_]]): Map[Platform, Seq[Setting[_]]] = { | ||
platforms.to[ListSet] // preserve the platform ordering |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose another option here is to use SortedSet
and impose a lexical ordering instead. This might be less surprising for users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would definitely recommend using lexicographic ordering, indeed. CrossProject
is not really designed with the idea that the platforms are ordered in any way, so relying on that order is brittle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, thanks.
7a96e24
to
4f50dc9
Compare
@sjrd polite bump? :) |
@sjrd I know sbt-crossproject PRs are no fun but whenever you can take a look would be much appreciated. Thanks! :) |
Right. I keep forgetting it. I'm on vacation this week but I'll have a look next week. |
Have a nice vacation! :) |
require(List(isJVM, isJS, isNative).count(identity) == 1) | ||
|
||
if (isJVM) | ||
require(JSOrJVM.check && JVMOrNative.check && !JSOrNative.check) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert
would make more sense than require
here. Same for the two below.
import scala.collection.immutable.HashMap | ||
import scala.collection.immutable.ListSet | ||
import scala.language.implicitConversions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import scala.collection.immutable.HashMap | |
import scala.collection.immutable.ListSet | |
import scala.language.implicitConversions | |
import scala.language.implicitConversions | |
import scala.collection.immutable.HashMap | |
import scala.collection.immutable.ListSet |
Language imports should always come first, in a dedicated "paragraph".
if (platforms.isEmpty) { | ||
None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every implementation will always have to do that. Instead, we should make it a pre-condition of partiallyShared{Src,Resources}Dir
that platforms.nonEmpty
. This is a bit more work for the (unique) caller of these methods, and less work for everyone who would like to implement CrossType
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is still relevant, I believe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woops, I thought I got this. Must have been another one 🤔
.map { platformSubset => // make the settings for this subset of platforms | ||
val settings = mkSettings(platformSubset) | ||
platformSubset.map(_ -> settings).toMap | ||
} | ||
.fold(platforms.map(_ -> Seq.empty).toMap)(mergeMapSeq) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems complicated and non intuitive to me. I think it may be reinventing a groupBy
+ flatMap
. Can't it be rewritten as follows:
.map { platformSubset => // make the settings for this subset of platforms | |
val settings = mkSettings(platformSubset) | |
platformSubset.map(_ -> settings).toMap | |
} | |
.fold(platforms.map(_ -> Seq.empty).toMap)(mergeMapSeq) | |
.flatMap { platformSubset => // make the settings for this subset of platforms | |
val settings = mkSettings(platformSubset) | |
platformSubset.map(_ -> settings) | |
} // Seq[(Platform, Seq[Setting])] | |
.groupBy(_._1).map(kv => kv._1 -> kv._2.flatMap(_._2)) |
The last line would be easier with Scala 2.13's groupMapReduce
, but we can't use it since this is 2.12 code. It would be written as
.groupMapReduce(_._1)(_._2)(_ ++ _)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The last line can even probably be delayed until the very end of shared{Src,Resources}Dir
. Until then, we would keep using Seq[(Platform, Seq[Setting])]
everywhere. This would entirely avoid passing through merge
/toHashMap
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this was a big big improvement 😅
) | ||
) | ||
}.toMap | ||
|
||
new CrossProject(id, crossType, projects) | ||
} | ||
|
||
private def sharedSrcSettings(crossType: CrossType): Seq[Setting[_]] = { | ||
private def sharedSrcSettings( | ||
platforms: Seq[Platform], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This parameter is redundant. It is already accessible as an instance field.
84c3b81
to
b61c500
Compare
.map(_.toSeq.sortBy(_.identifier)) // use a consistent ordering | ||
.flatMap { platformSubset => // make the settings for this subset of platforms | ||
val settings = mkSettings(platformSubset) | ||
platformSubset.map(_ -> settings).toMap |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
platformSubset.map(_ -> settings).toMap | |
platformSubset.map(_ -> settings) |
if (platforms.isEmpty) { | ||
None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is still relevant, I believe.
b61c500
to
06f7f75
Compare
@sjrd thanks for the review! Too much to ask for a 1.2.0? 😛 |
This commit adds the following changes - Move shared sources to js-native directory to reduce redundant files - See portable-scala/sbt-crossproject#145 - Port hash functions in pure Scala for js and native platform with reference to https://github.com/square/okio (Apache V2 License)
Fixes #17.
For a full-cross-project set up for platforms
a
,b
,c
,d
, etc. (in this order), configures the standard source and resource directories under these directories:a-b
a-c
a-d
b-c
b-d
c-d
a-b-c
a-b-d
a-c-d
b-c-d
This is in addition to the already supported
shared
,a
,b
,c
, andd
directories.