From 6864549af2a12df66f83f2e072ba67dca2055a96 Mon Sep 17 00:00:00 2001 From: Ara Adkins Date: Fri, 14 Jun 2019 16:26:49 +0100 Subject: [PATCH] Project Setup (#4) * Set up the interpreter project. * Reformat build.sbt * Fix style guide --- build.sbt | 98 ++++++++++++++----- doc/scala-style-guide.md | 61 +----------- .../scala/org/enso/interpreter/Main.scala | 5 + .../scala/org/enso/interpreter/Main.scala | 8 ++ .../scala/org/enso/interpreter/Main.scala | 6 ++ 5 files changed, 94 insertions(+), 84 deletions(-) create mode 100644 interpreter/src/bench/scala/org/enso/interpreter/Main.scala create mode 100644 interpreter/src/main/scala/org/enso/interpreter/Main.scala create mode 100644 interpreter/src/test/scala/org/enso/interpreter/Main.scala diff --git a/build.sbt b/build.sbt index 7efd96f417c..a8ee16987f8 100644 --- a/build.sbt +++ b/build.sbt @@ -1,46 +1,92 @@ -version := "1.0" +// Global Configuration organization := "org.enso" scalaVersion := "2.12.8" +// Compiler Options +scalacOptions ++= Seq( + "-deprecation", + "-feature", + "-unchecked", + "-Xlint" +) + +// Benchmark Configuration lazy val Benchmark = config("bench") extend Test -lazy val bench = taskKey[Unit]("Run Benchmarks") +lazy val bench = taskKey[Unit]("Run Benchmarks") +// Global Project lazy val enso = (project in file(".")) - .aggregate(syntax, pkg) + .settings(version := "0.1") + .aggregate( + syntax, + pkg, + interpreter + ) +// Sub-Projects lazy val syntax = (project in file("syntax")) + .settings( + mainClass in (Compile, run) := Some("org.enso.syntax.Main"), + version := "0.1" + ) + .settings( + libraryDependencies ++= Seq( + "com.storm-enroute" %% "scalameter" % "0.17" % "bench", + "org.typelevel" %% "cats-core" % "1.6.0", + "org.scalatest" %% "scalatest" % "3.0.5" % Test, + "com.lihaoyi" %% "pprint" % "0.5.3" + ), + resolvers ++= Seq( + "Sonatype OSS Snapshots" at + "https://oss.sonatype.org/content/repositories/snapshots", + "Sonatype OSS Releases" at + "https://oss.sonatype.org/content/repositories/releases" + ) + ) + .settings(SbtJFlexPlugin.jflexSettings) + .configs(Test) + .settings( + testFrameworks += new TestFramework("org.scalameter.ScalaMeterFramework"), + logBuffered := false + ) .configs(Benchmark) .settings( inConfig(Benchmark)(Defaults.testSettings), - name := "syntax", - organization := "org.enso", - scalaVersion := "2.12.8", - scalacOptions ++= Seq("-deprecation", "-unchecked", "-feature", "-Xlint"), - publishArtifact := false, - libraryDependencies ++= Seq( - "com.storm-enroute" %% "scalameter" % "0.17" % "bench", - "org.typelevel" %% "cats-core" % "1.6.0", - "org.scalatest" %% "scalatest" % "3.0.5" % Test, - "com.lihaoyi" %% "pprint" % "0.5.3" - ), - resolvers ++= Seq( - "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots", - "Sonatype OSS Releases" at "https://oss.sonatype.org/content/repositories/releases" - ), - testFrameworks += new TestFramework("org.scalameter.ScalaMeterFramework"), - parallelExecution in Benchmark := false, - logBuffered := false + bench := (test in Benchmark).value, + parallelExecution in Benchmark := false ) - .settings(SbtJFlexPlugin.jflexSettings) - .settings(mainClass in (Compile, run) := Some("org.enso.syntax.Main")) - .settings(bench := { - (test in Benchmark).value - }) lazy val pkg = (project in file("pkg")) .settings( mainClass in (Compile, run) := Some("org.enso.pkg.Main"), + version := "0.1" + ) + .settings( libraryDependencies ++= Seq("circe-core", "circe-generic", "circe-yaml") .map("io.circe" %% _ % "0.10.0"), libraryDependencies += "commons-io" % "commons-io" % "2.6" ) + +lazy val interpreter = (project in file("interpreter")) + .settings( + mainClass in (Compile, run) := Some("org.enso.interpreter.Main"), + version := "0.1" + ) + .settings( + libraryDependencies ++= Seq( + "com.chuusai" %% "shapeless" % "2.3.3", + "com.storm-enroute" %% "scalameter" % "0.17" % "bench", + "org.graalvm.sdk" % "graal-sdk" % "19.0.0", + "org.scalacheck" %% "scalacheck" % "1.14.0" % Test, + "org.scalatest" %% "scalatest" % "3.2.0-SNAP10" % Test, + "org.typelevel" %% "cats-core" % "2.0.0-M4" + ) + ) + .dependsOn(syntax) + .configs(Test) + .configs(Benchmark) + .settings( + inConfig(Benchmark)(Defaults.testSettings), + bench := (test in Benchmark).value, + parallelExecution in Benchmark := false + ) diff --git a/doc/scala-style-guide.md b/doc/scala-style-guide.md index 7835b5a58ce..ca6e4ddfd24 100644 --- a/doc/scala-style-guide.md +++ b/doc/scala-style-guide.md @@ -11,9 +11,6 @@ programmer burden; there is usually only _one way_ to lay out code correctly. - [Code Formatting](#code-formatting) - [Naming](#naming) - - [Imports](#imports) - - [Visibility](#visibility) - - [Section Headers](#section-headers) - [Build Tooling](#build-tooling) - [Commenting](#commenting) - [Documentation Comments](#documentation-comments) @@ -40,8 +37,9 @@ should be used for all new Scala projects. All files must be formatted using `scalafmt` before commit, and this should be set up as either a precommit hook, or using the integration in IntelliJ. If you use the IntelliJ integration, please note that you need only have the official -[Scala Plugin](https://www.jetbrains.com/help/idea/discover-intellij-idea-for-scala.html) installed, and be using IntelliJ 2019.1 -or later. You should _not_ use the independent Scalafmt plugin. +[Scala Plugin](https://www.jetbrains.com/help/idea/discover-intellij-idea-for-scala.html) +installed, and be using IntelliJ 2019.1 or later. You should _not_ use the +independent Scalafmt plugin. ### Naming Luna has some fairly simple general naming conventions, though the sections @@ -56,59 +54,6 @@ below may provide more rules for use in specific cases. temporary data in a function. - Names should be descriptive, even if this makes them longer. -### Imports -Organisation of imports is simple, and should be ordered alphabetically within -each of the following sections. Each section should be separated from the one -above using a blank line. - -1. **Standard Library:** Any imports from the standard library. -2. **Java Standard Library:** Any imports from the Java standard library. -3. **Additional Dependencies:** Imports from project dependencies. - -In general, we prefer not to import unqualified into the package scope, as this -just leads to additional clutter. - -### Visibility -There is nothing more frustrating than needing to use a function that hasn't -been exported from a package. To this end, we strongly discourage making things -private or protected in our codebase. - -If, however, you want to indicate that something is for internal use, you use -one of the following two methods. - -1. **Nested Types:** Declaration of inner types called `Internal`. -2. **Internal Packages:** For a package named `com.luna-lang.package` that - contains `MyType`, we can define internal functions and data-types in a - package named `com.luna-lang.package.mytype`. This means that these functions - can be imported by clients of the API if they need to, but that we provide no - guarantees about API stability when using those functions. - -### Section Headers -In order to visually break up the code for easier 'visual grepping', we organise -it using section headers. These allow us to easily find the section that we are -looking for, even in a large file. - -For each Scala type, within the body of the type, we organise functions as -follows: - -```hs --- === Definition === -- -{- The definition of the type goes here -} - - --- === API === -- -{- The API of the type goes here -} - - --- === Instances === -- -{- Any instances for the type go here -} - -``` - -The section header must be preceded by three blank lines, while the subsection -headers (except the first) should be preceded by two blank lines. Any of these -subsections may be omitted if they don't exist. - ## Build Tooling All Scala projects in the Luna organisation should manage their dependencies and build setup using [SBT](hhttps://www.scala-sbt.org/1.x/docs/index.html). diff --git a/interpreter/src/bench/scala/org/enso/interpreter/Main.scala b/interpreter/src/bench/scala/org/enso/interpreter/Main.scala new file mode 100644 index 00000000000..13d99cc44d7 --- /dev/null +++ b/interpreter/src/bench/scala/org/enso/interpreter/Main.scala @@ -0,0 +1,5 @@ +package org.enso.interpreter + +import org.scalameter.Bench + +object MainBenchmark extends Bench.OfflineReport {} diff --git a/interpreter/src/main/scala/org/enso/interpreter/Main.scala b/interpreter/src/main/scala/org/enso/interpreter/Main.scala new file mode 100644 index 00000000000..3a3fb5c8b7c --- /dev/null +++ b/interpreter/src/main/scala/org/enso/interpreter/Main.scala @@ -0,0 +1,8 @@ +package org.enso.interpreter + +object Main { + + def main(args: Array[String]): Unit = { + println(x = "Hello, Enso!") + } +} diff --git a/interpreter/src/test/scala/org/enso/interpreter/Main.scala b/interpreter/src/test/scala/org/enso/interpreter/Main.scala new file mode 100644 index 00000000000..9d1a99f1b23 --- /dev/null +++ b/interpreter/src/test/scala/org/enso/interpreter/Main.scala @@ -0,0 +1,6 @@ +package org.enso.interpreter + +import org.scalatest.FlatSpec +import org.scalatest.Matchers + +class MainSpec extends FlatSpec with Matchers {}