Skip to content

Commit

Permalink
initial code checkin
Browse files Browse the repository at this point in the history
rename PlatformInfo
Create scala.yml
cleanup tests, remove duplication
Merge branch 'main' of https://github.com/philwalk/pallet
  • Loading branch information
philwalk committed Sep 1, 2023
1 parent 1408c01 commit a98f9bb
Show file tree
Hide file tree
Showing 33 changed files with 5,094 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/scala.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Scala CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
cache: 'sbt'
- name: Run tests
run: sbt test
# Optional: This step uploads information to the GitHub dependency graph and unblocking Dependabot alerts for the repository
- name: Upload dependency graph
uses: scalacenter/sbt-dependency-submission@ab086b50c947c9774b70f39fc7f6e20ca2706c91
38 changes: 38 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
../
*.class
*.log
sall
s[0-9]*
_vb
tags

.cache
.env
.envrc
.history
.sdkmanrc
.lib/
dist/*
target/
lib_managed/
local.conf
src_managed/
project/boot/
project/plugins/project/
project/scalafix/*
project/.sbtserver
project/.sbtserver.lock
project/project/
*.swp
*.sw?

jsrc/*.jar

.idea*

# Metals
.metals/
.bsp/
.bloop/
metals.sbt
.vscode
2 changes: 2 additions & 0 deletions .jvmopts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--add-opens=java.base/java.util=ALL-UNNAMED
--add-opens=java.base/java.lang=ALL-UNNAMED
2 changes: 2 additions & 0 deletions .sbtopts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-J--add-opens=java.base/java.lang=ALL-UNNAMED
-J--add-opens=java.base/java.util=ALL-UNNAMED
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,26 @@
# pallet
Platform Independent Tooling

Provides support for various expressive idioms typical of scripting languages,
with a goal of supporting portable code runnable in many environments with little or no customization.

Target environments include Linux, OSX, Cygwin, Msys2, Mingw, WSL, Windows.

Example script:
```scala
#!/usr/bin/env -S scala -cp target/scala-3.3.0/classes
// hashbang line above is sufficient after 'sbt compile'
import vastblue.pathextend.*

def main(args: Array[String]): Unit = {
// show system memory info
for (line <- "/proc/meminfo".path.lines) {
printf("%s\n", line)
}
// list child directories of the current working directory
val cwd: Path = ".".path
for ( (p: Path) <- cwd.paths.filter { _.isDirectory }){
printf("%s\n", p.norm)
}
}
```
71 changes: 71 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
lazy val scala213 = "2.13.11"
lazy val scala330 = "3.3.0"
//lazy val supportedScalaVersions = List(scala213, scala330)
lazy val supportedScalaVersions = List(scala330)

//ThisBuild / envFileName := "dev.env" // sbt-dotenv plugin gets build environment here
ThisBuild / organization := "org.vastblue"
ThisBuild / scalaVersion := "3.3.0"
ThisBuild / version := "0.8.1-SNAPSHOT"

ThisBuild / crossScalaVersions := supportedScalaVersions

lazy val root = (project in file("."))
.settings(
// crossScalaVersions := supportedScalaVersions,
name := "pallet"
)

libraryDependencies ++= Seq(
"org.scalacheck" %% "scalacheck" % "1.17.0" % Test,
"org.scalatest" %% "scalatest" % "3.2.16" % Test,
"com.github.sbt" % "junit-interface" % "0.13.3" % Test,
)
//def rtp: String = {
// val psep = java.io.File.pathSeparator
// val syspath: List[String] = Option(System.getenv("PATH")).getOrElse("").split(psep).map { _.toString }.toList
// val javaLibraryPath: List[String] = sys.props("java.library.path").split(psep).map { _.toString }.toList
// val entries: List[String] = (javaLibraryPath ::: syspath)
// val path: String = entries.map { _.replace('\\', '/').toLowerCase }.distinct.mkString(";")
// System.setProperty("java.library.path", path)
// path
//}
//lazy val runtimePath = settingKey[String]("runtime path")
//
//runtimePath := rtp

scalacOptions := Seq(
//"-Xmaxerrs", "10",
// Warnings as errors!
//"-Xfatal-warnings", // must be commented out for scalafix actions, pre-2.13
//"-Wconf:any:error", // must be commented out for scalafix actions, 2.13+

//"-Wvalue-discard",

"-encoding", "utf-8",
"-explaintypes",
"-language:existentials",
"-language:experimental.macros",
"-language:higherKinds",
"-language:implicitConversions",

// Linting options
"-unchecked",

"-Wunused:implicits",
"-Wunused:imports",
"-Wunused:locals",
"-Wunused:params",
"-Wunused:privates",
)
scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, _)) => Seq(
"-Xsource:3",
"-Xmaxerrs", "10",
"-Yscala3-implicit-resolution",
"-language:implicitConversions",
)
case _ => Nil
})


1 change: 1 addition & 0 deletions dev.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
JAVA_OPTS='--add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED'
15 changes: 15 additions & 0 deletions jsrc/demo.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env -S scala -cp target/scala-3.3.0/classes
// the above hashbang line works after successful sbt compile
import vastblue.pathextend._

def main(args: Array[String]): Unit = {
// show system memory info
for (line <- "/proc/meminfo".path.lines) {
printf("%s\n", line)
}
// list child directories of the current working directory
val cwd: Path = ".".path
for ( (p: Path) <- cwd.paths.filter { _.isDirectory }){
printf("%s\n", p.norm)
}
}
6 changes: 6 additions & 0 deletions jsrc/dirlist.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env -S scala -cp target/scala-3.3.0/classes
import vastblue.pathextend._

def main(args: Array[String]): Unit = {
".".path.paths.filter { _.isDirectory }.foreach { (p: Path) => printf("%s\n", p.norm) }
}
17 changes: 17 additions & 0 deletions jsrc/pathsdemo.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env -S scala -cp target/scala-3.3.0/classes
import vastblue.pathextend._

object PathsDemo {
def main(args: Array[String]): Unit = {
if (args.isEmpty) {
printf("usage: %s <filepath-1> [<filepath2> ...]\n", scriptPath.path.name)
} else {
for (a <- args) {
printf("========== arg[%s]\n", a)
printf("stdpath [%s]\n", Paths.get(a).stdpath)
printf("normpath [%s]\n", Paths.get(a).norm)
printf("dospath [%s]\n", Paths.get(a).dospath)
}
}
}
}
10 changes: 10 additions & 0 deletions jsrc/platform.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env -S scala -cp target/scala-3.3.0/classes
// the above hashbang line works after successful sbt compile

import vastblue.Platform

def main(args: Array[String]): Unit =
Platform.main(args)
for ((k,v) <- Platform.mountMap){
printf("%-22s: %s\n", k, v)
}
8 changes: 8 additions & 0 deletions jsrc/postPublish.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env -S scala -cp /Users/philwalk/.ivy2/local/org.vastblue/pallet_3/0.8.0-SNAPSHOT/jars/pallet_3.jar

import vastblue.pathextend.*

def main(args: Array[String]): Unit = {
// show various info relevant to the current runtime environment
vastblue.Platform.main(args)
}
13 changes: 13 additions & 0 deletions jsrc/testversions.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env -S scala -cp target/scala-3.3.0/classes

import vastblue.pathextend._

def main(args: Array[String]): Unit =
// show runtime scala VERSION
val scalaHome = sys.props("scala.home")
val version = Paths.get(s"$scalaHome/VERSION").contentAsString.trim
printf("%s\n",version)

// display output of uname -a
import scala.sys.process._
printf("%s\n",Seq("uname","-a").lazyLines_!.toList.mkString(""))
1 change: 1 addition & 0 deletions project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.9.2
2 changes: 2 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
//addSbtPlugin("nl.gn0s1s" % "sbt-dotenv" % "3.0.0")
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.5.10")
Loading

0 comments on commit a98f9bb

Please sign in to comment.