Skip to content
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 Scala Native as a supported platform #238

Merged
merged 1 commit into from
May 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ before_cache:

script:
# Your normal script
- sbt ++$TRAVIS_SCALA_VERSION test:compile squantsJS/fastOptJS
- sbt ++$TRAVIS_SCALA_VERSION squantsJVM/test:compile squantsJS/test:compile squantsJS/fastOptJS
- if [[ $TRAVIS_SCALA_VERSION == "2.11.8" ]]; then sbt ++$TRAVIS_SCALA_VERSION squantsNative/compile; fi;
- sbt ++$TRAVIS_SCALA_VERSION squantsJS/test squantsJVM/test
- sbt ++$TRAVIS_SCALA_VERSION doc tut
- sbt ++$TRAVIS_SCALA_VERSION squantsJS/doc squantsJVM/doc tut

# Tricks to avoid unnecessary cache updates
- find $HOME/.sbt -name "*.lock" | xargs rm
Expand All @@ -58,4 +59,4 @@ notifications:
- https://webhooks.gitter.im/e/e50c1534becaa7b20529
on_success: change # options: [always|never|change] default: always
on_failure: always # options: [always|never|change] default: always
on_start: never # options: [always|never|change] default: always
on_start: never # options: [always|never|change] default: always
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1224,9 +1224,11 @@ To make a release do the following:
sbt tut
```

* Publish a cross-version signed package
* Publish a cross-version signed package (no cross-version available for Scala Native)
```
sbt +publishSigned
sbt +squantsJVM/publishSigned
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to break these out into three commands now?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point, breaking it will probably slow down travis a bit while warming up sbt

sbt +squantsJS/publishSigned
sbt squantsNative/publishSigned
```

* Then make a release (Note: after this step the release cannot be replaced)
Expand Down
7 changes: 5 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import sbtcrossproject.{crossProject, CrossType}

lazy val defaultSettings =
Project.defaultSettings ++
Compiler.defaultSettings ++
Expand All @@ -7,7 +9,7 @@ lazy val defaultSettings =
Console.defaultSettings ++
Docs.defaultSettings

lazy val squants = crossProject
lazy val squants = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.crossType(CrossType.Full)
.in(file("."))
.settings(defaultSettings: _*)
Expand All @@ -30,7 +32,8 @@ lazy val root = project.in(file("."))
publishLocal := {},
publishArtifact := false
)
.aggregate(squantsJVM, squantsJS)
.aggregate(squantsJVM, squantsJS, squantsNative)

lazy val squantsJVM = squants.jvm.enablePlugins(SbtOsgi)
lazy val squantsJS = squants.js
lazy val squantsNative = squants.native
18 changes: 18 additions & 0 deletions js/src/main/scala/squants/Platform.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package squants

object Platform {
/**
* Helper function to achieve uniform Double formatting over JVM and JS platforms.
* Simple Double.toString will format 1.0 as "1.0" on JVM and as "1" on JS
* @param d Double number to be formatted
* @return
*/
private[squants] def crossFormat(d: Double): String = {
if (d.toLong == d) {
"%.1f".format(d)
}
else {
d.toString
}
}
}
18 changes: 18 additions & 0 deletions jvm/src/main/scala/squants/Platform.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package squants

object Platform {
/**
* Helper function to achieve uniform Double formatting over JVM, JS, and native platforms.
* Simple Double.toString will format 1.0 as "1.0" on JVM and as "1" on JS
* @param d Double number to be formatted
* @return
*/
private[squants] def crossFormat(d: Double): String = {
if (d.toLong == d) {
"%.1f".format(d)
}
else {
d.toString
}
}
}
15 changes: 15 additions & 0 deletions native/src/main/scala/squants/Platform.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package squants

object Platform {
/**
* Helper function to achieve uniform Double formatting over JVM, JS, and native platforms.
* Simple Double.toString will format 1.0 as "1.0" on JVM and as "1" on JS
* @param d Double number to be formatted
* @return
*/
private[squants] def crossFormat(d: Double): String = {
// we cannot use the same logic as JS and JVM because string formatting is not supported
// by Scala Native yet
d.toString
}
}
6 changes: 6 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.14")

addSbtPlugin("org.scala-native" % "sbt-crossproject" % "0.1.0")

addSbtPlugin("org.scala-native" % "sbt-scalajs-crossproject" % "0.1.0")

addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.2.1")

addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.5.1")

addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.8.0")
Expand Down
2 changes: 1 addition & 1 deletion shared/src/main/scala/squants/Quantity.scala
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ abstract class Quantity[A <: Quantity[A]] extends Serializable with Ordered[A] {
* @param uom UnitOfMeasure[A] with UnitConverter
* @return String
*/
def toString(uom: UnitOfMeasure[A]): String = s"${crossFormat(to(uom))} ${uom.symbol}"
def toString(uom: UnitOfMeasure[A]): String = s"${Platform.crossFormat(to(uom))} ${uom.symbol}"

/**
* Returns a string representing the quantity's value in the given `unit` in the given `format`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

package squants.market

import squants.{ Ratio, crossFormat }
import squants.Ratio
import squants.Platform.crossFormat

/**
* Represent the rate of exchange between two currencies
Expand Down
8 changes: 0 additions & 8 deletions shared/src/main/scala/squants/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,4 @@ package object squants {
def /(that: Time) = Each(bd) / that
def per(that: Time): Frequency = /(that)
}

/**
* Helper function to achieve uniform Double formatting over JVM and JS platforms.
* Simple Double.toString will format 1.0 as "1.0" on JVM and as "1" on JS
* @param d Double number to be formatted
* @return
*/
private[squants] def crossFormat(d: Double): String = if (d.toLong == d) { "%.1f".format(d) } else { d.toString }
}
1 change: 1 addition & 0 deletions shared/src/main/scala/squants/thermal/Temperature.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package squants.thermal

import squants._
import squants.Platform.crossFormat
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, is this really the only place this is being used? Regardless I like this solution

import squants.energy.Joules
import scala.util.{ Failure, Success, Try }

Expand Down