Skip to content
Draft
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
15 changes: 11 additions & 4 deletions build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ val communityBuildDottyVersion = sys.props.get("dottyVersion").toList
val scala213Version = "2.13.14"

val scalaVersions = Seq(
"3.3.1",
"3.7.0-RC1",
"2.12.17",
scala213Version
) ++ communityBuildDottyVersion
Expand All @@ -39,7 +39,8 @@ trait AcyclicModule extends ScalaModule {
}
def compileIvyDeps = acyclicDep
def scalacPluginIvyDeps = acyclicDep
def scalacOptions = super.scalacOptions() ++ acyclicOptions()
def scalacOptions = super.scalacOptions() ++ acyclicOptions() ++
Agg.when(scalaVersion().startsWith("3"))("-experimental")
}

trait SafeDeps extends ScalaModule {
Expand Down Expand Up @@ -85,6 +86,8 @@ trait OsLibModule
with SafeDeps
with PlatformScalaModule { outer =>

def scalacPluginIvyDeps = super.scalacPluginIvyDeps() ++ Agg.when(scalaVersion().startsWith("2"))(ivy"com.lihaoyi::unroll-plugin:0.1.12")
def ivyDeps = super.ivyDeps() ++ Agg.when(scalaVersion().startsWith("2"))(ivy"com.lihaoyi::unroll-annotation:0.1.12")
def publishVersion = VcsVersion.vcsState().format()
def pomSettings = PomSettings(
description = artifactName(),
Expand All @@ -101,18 +104,20 @@ trait OsLibModule
)

trait OsLibTestModule extends ScalaModule with TestModule.Utest with SafeDeps {
def ivyDeps = Agg(Deps.utest, Deps.sourcecode)
def ivyDeps = super.ivyDeps() ++ Agg(Deps.utest, Deps.sourcecode)
// we check the textual output of system commands and expect it in english
def forkEnv = super.forkEnv() ++ Map(
"LC_ALL" -> "C",
"TEST_SUBPROCESS_ENV" -> "value",
"OS_TEST_RESOURCE_FOLDER" -> os.jvm(crossValue).test.resources().head.path.toString
)
def scalacOptions = super.scalacOptions() ++
Agg.when(scalaVersion().startsWith("3"))("-experimental")
}
}

trait OsModule extends OsLibModule { outer =>
def ivyDeps = Agg(Deps.geny)
def ivyDeps = super.ivyDeps() ++ Agg(Deps.geny)
override def compileIvyDeps = T {
val scalaReflectOpt = Option.when(!ZincWorkerUtil.isDottyOrScala3(scalaVersion()))(
Deps.scalaReflect(scalaVersion())
Expand Down Expand Up @@ -187,6 +192,8 @@ object os extends Module {
object testSpawnExitHook extends ScalaModule{
def scalaVersion = OsJvmModule.this.scalaVersion()
def moduleDeps = Seq(OsJvmModule.this)
def scalacOptions = super.scalacOptions() ++
Agg.when(scalaVersion().startsWith("3"))("-experimental")
}
object testSpawnExitHook2 extends JavaModule
}
Expand Down
63 changes: 7 additions & 56 deletions os/src/FileOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import java.nio.file.{Path => _, _}
import java.nio.file.attribute.{FileAttribute, PosixFilePermission, PosixFilePermissions}

import scala.util.Try
import scala.annotation.unroll

/**
* Create a single directory at the specified path. Optionally takes in a
Expand Down Expand Up @@ -40,8 +41,7 @@ object makeDir extends Function1[Path, Unit] {
* destination path already containts a directory
*/
object all extends Function1[Path, Unit] {
def apply(path: Path): Unit = apply(path, null, true)
def apply(path: Path, perms: PermSet = null, acceptLinkedDirectory: Boolean = true): Unit = {
def apply(path: Path, @unroll perms: PermSet = null, @unroll acceptLinkedDirectory: Boolean = true): Unit = {
checker.value.onWrite(path)
// We special case calling makeDir.all on a symlink to a directory;
// normally createDirectories blows up noisily, when really what most
Expand Down Expand Up @@ -181,7 +181,7 @@ object copy {
replaceExisting: Boolean = false,
copyAttributes: Boolean = false,
createFolders: Boolean = false,
mergeFolders: Boolean = false
@unroll mergeFolders: Boolean = false
): Unit = {
checker.value.onRead(from)
checker.value.onWrite(to)
Expand Down Expand Up @@ -213,29 +213,6 @@ object copy {
if (stat(from, followLinks = followLinks).isDir) for (p <- walk(from)) copyOne(p)
}

/** This overload is only to keep binary compatibility with older os-lib versions. */
@deprecated(
"Use os.copy(from, to, followLinks, replaceExisting, copyAttributes, " +
"createFolders, mergeFolders) instead",
"os-lib 0.7.5"
)
def apply(
from: Path,
to: Path,
followLinks: Boolean,
replaceExisting: Boolean,
copyAttributes: Boolean,
createFolders: Boolean
): Unit = apply(
from = from,
to = to,
followLinks = followLinks,
replaceExisting = replaceExisting,
copyAttributes = copyAttributes,
createFolders = createFolders,
mergeFolders = false
)

/**
* Copy a file into a particular folder, rather
* than into a particular path
Expand All @@ -248,7 +225,7 @@ object copy {
replaceExisting: Boolean = false,
copyAttributes: Boolean = false,
createFolders: Boolean = false,
mergeFolders: Boolean = false
@unroll mergeFolders: Boolean = false
): Unit = {
os.copy(
from,
Expand All @@ -260,29 +237,6 @@ object copy {
mergeFolders
)
}

/** This overload is only to keep binary compatibility with older os-lib versions. */
@deprecated(
"Use os.copy.into(from, to, followLinks, replaceExisting, copyAttributes, " +
"createFolders, mergeFolders) instead",
"os-lib 0.7.5"
)
def apply(
from: Path,
to: Path,
followLinks: Boolean,
replaceExisting: Boolean,
copyAttributes: Boolean,
createFolders: Boolean
): Unit = apply(
from = from,
to = to,
followLinks = followLinks,
replaceExisting = replaceExisting,
copyAttributes = copyAttributes,
createFolders = createFolders,
mergeFolders = false
)
}

/**
Expand Down Expand Up @@ -317,8 +271,7 @@ object copy {
* does nothing if there aren't any
*/
object remove extends Function1[Path, Boolean] {
def apply(target: Path): Boolean = apply(target, false)
def apply(target: Path, checkExists: Boolean = false): Boolean = {
def apply(target: Path, @unroll checkExists: Boolean = false): Boolean = {
checker.value.onWrite(target)
if (checkExists) {
Files.delete(target.wrapped)
Expand All @@ -329,8 +282,7 @@ object remove extends Function1[Path, Boolean] {
}

object all extends Function1[Path, Unit] {
def apply(target: Path): Unit = apply(target, ignoreErrors = false)
def apply(target: Path, ignoreErrors: Boolean = false): Unit = {
def apply(target: Path, @unroll ignoreErrors: Boolean = false): Unit = {
require(target.segmentCount != 0, s"Cannot remove a root directory: $target")
checker.value.onWrite(target)

Expand All @@ -353,8 +305,7 @@ object remove extends Function1[Path, Boolean] {
* Checks if a file or folder exists at the given path.
*/
object exists extends Function1[Path, Boolean] {
def apply(p: Path): Boolean = Files.exists(p.wrapped)
def apply(p: Path, followLinks: Boolean = true): Boolean = {
def apply(p: Path, @unroll followLinks: Boolean = true): Boolean = {
val opts = if (followLinks) Array[LinkOption]() else Array(LinkOption.NOFOLLOW_LINKS)
Files.exists(p.wrapped, opts: _*)
}
Expand Down
4 changes: 2 additions & 2 deletions os/src/Path.scala
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,8 @@ object Path extends PathMacros {
val f = implicitly[PathConvertible[T]].apply(f0)
if (f.subpath(0, 1).toString != "~") if (base == null) Path(f0) else Path(f0, base)
else {
Path(System.getProperty("user.home"))(PathConvertible.StringConvertible) /
RelPath(f.subpath(0, 1).relativize(f))(PathConvertible.NioPathConvertible)
Path(System.getProperty("user.home"))(using PathConvertible.StringConvertible) /
RelPath(f.subpath(0, 1).relativize(f))(using PathConvertible.NioPathConvertible)
}
}

Expand Down
66 changes: 4 additions & 62 deletions os/src/ProcessOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import os.SubProcess.InputStream
import java.io.IOException
import java.util.concurrent.LinkedBlockingQueue
import ProcessOps._

import scala.annotation.unroll
object call {

/**
Expand All @@ -26,7 +26,7 @@ object call {
check: Boolean = true,
propagateEnv: Boolean = true,
shutdownGracePeriod: Long = 100,
destroyOnExit: Boolean = true
@unroll destroyOnExit: Boolean = true
): CommandResult = {
os.proc(cmd).call(
cwd = cwd,
Expand All @@ -43,37 +43,6 @@ object call {
)
}

// Bincompat Forwarder
def apply(
cmd: Shellable,
env: Map[String, String],
// Make sure `cwd` only comes after `env`, so `os.call("foo", path)` is a compile error
// since the correct syntax is `os.call(("foo", path))`
cwd: Path,
stdin: ProcessInput,
stdout: ProcessOutput,
stderr: ProcessOutput,
mergeErrIntoOut: Boolean,
timeout: Long,
check: Boolean,
propagateEnv: Boolean,
timeoutGracePeriod: Long
): CommandResult = {
call(
cmd = cmd,
cwd = cwd,
env = env,
stdin = stdin,
stdout = stdout,
stderr = stderr,
mergeErrIntoOut = mergeErrIntoOut,
timeout = timeout,
check = check,
propagateEnv = propagateEnv,
shutdownGracePeriod = timeoutGracePeriod,
destroyOnExit = true
)
}
}
object spawn {

Expand All @@ -91,8 +60,8 @@ object spawn {
stderr: ProcessOutput = os.Inherit,
mergeErrIntoOut: Boolean = false,
propagateEnv: Boolean = true,
shutdownGracePeriod: Long = 100,
destroyOnExit: Boolean = true
@unroll shutdownGracePeriod: Long = 100,
@unroll destroyOnExit: Boolean = true
): SubProcess = {
os.proc(cmd).spawn(
cwd = cwd,
Expand All @@ -106,33 +75,6 @@ object spawn {
destroyOnExit = destroyOnExit
)
}

// Bincompat Forwarder
def apply(
cmd: Shellable,
// Make sure `cwd` only comes after `env`, so `os.spawn("foo", path)` is a compile error
// since the correct syntax is `os.spawn(("foo", path))`
env: Map[String, String],
cwd: Path,
stdin: ProcessInput,
stdout: ProcessOutput,
stderr: ProcessOutput,
mergeErrIntoOut: Boolean,
propagateEnv: Boolean
): SubProcess = {
spawn(
cmd = cmd,
cwd = cwd,
env = env,
stdin = stdin,
stdout = stdout,
stderr = stderr,
mergeErrIntoOut = mergeErrIntoOut,
propagateEnv = propagateEnv,
shutdownGracePeriod = 100,
destroyOnExit = true
)
}
}

/**
Expand Down
Loading