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

Fix publish #703

Merged
merged 3 commits into from
Feb 24, 2022
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
28 changes: 16 additions & 12 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ class Build(val crossScalaVersion: String)
else state + "-maybe-stale"
}
def constantsFile = T.persistent {
val dest = T.dest / "Constants.scala"
val dir = T.dest / "constants"
val dest = dir / "Constants.scala"
val testRunnerMainClass = `test-runner`(Scala.defaultInternal)
.mainClass()
.getOrElse(sys.error("No main class defined for test-runner"))
Expand Down Expand Up @@ -291,8 +292,8 @@ class Build(val crossScalaVersion: String)
|}
|""".stripMargin
if (!os.isFile(dest) || os.read(dest) != code)
os.write.over(dest, code)
PathRef(dest)
os.write.over(dest, code, createFolders = true)
PathRef(dir)
}
def generatedSources = super.generatedSources() ++ Seq(constantsFile())

Expand All @@ -311,7 +312,8 @@ class Build(val crossScalaVersion: String)
def generatedSources = super.generatedSources() ++ Seq(constantsFile())

def constantsFile = T.persistent {
val dest = T.dest / "Constants2.scala"
val dir = T.dest / "constants"
val dest = dir / "Constants2.scala"
val code =
s"""package scala.build.tests
|
Expand All @@ -321,8 +323,8 @@ class Build(val crossScalaVersion: String)
|}
|""".stripMargin
if (!os.isFile(dest) || os.read(dest) != code)
os.write.over(dest, code)
PathRef(dest)
os.write.over(dest, code, createFolders = true)
PathRef(dir)
}

// uncomment below to debug tests in attach mode on 5005 port
Expand Down Expand Up @@ -432,7 +434,8 @@ trait CliIntegrationBase extends SbtModule with ScalaCliPublishModule with HasTe
}

def constantsFile = T.persistent {
val dest = T.dest / "Constants.scala"
val dir = T.dest / "constants"
val dest = dir / "Constants.scala"
val mostlyStaticDockerfile =
os.rel / ".github" / "scripts" / "docker" / "ScalaCliSlimDockerFile"
assert(
Expand Down Expand Up @@ -461,8 +464,8 @@ trait CliIntegrationBase extends SbtModule with ScalaCliPublishModule with HasTe
|}
|""".stripMargin
if (!os.isFile(dest) || os.read(dest) != code)
os.write.over(dest, code)
PathRef(dest)
os.write.over(dest, code, createFolders = true)
PathRef(dir)
}
def generatedSources = super.generatedSources() ++ Seq(constantsFile())

Expand Down Expand Up @@ -586,7 +589,8 @@ class BloopRifle(val crossScalaVersion: String) extends ScalaCliCrossSbtModule
def mainClass = Some("scala.build.blooprifle.BloopRifle")

def constantsFile = T.persistent {
val dest = T.dest / "Constants.scala"
val dir = T.dest / "constants"
val dest = dir / "Constants.scala"
val code =
s"""package scala.build.blooprifle.internal
|
Expand All @@ -598,8 +602,8 @@ class BloopRifle(val crossScalaVersion: String) extends ScalaCliCrossSbtModule
|}
|""".stripMargin
if (!os.isFile(dest) || os.read(dest) != code)
os.write.over(dest, code)
PathRef(dest)
os.write.over(dest, code, createFolders = true)
PathRef(dir)
}
def generatedSources = super.generatedSources() ++ Seq(constantsFile())

Expand Down
30 changes: 30 additions & 0 deletions project/settings.sc
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,8 @@ trait ScalaCliCompile extends ScalaModule {
else T.persistent {
val out = os.pwd / workspaceDirName / ".unused"

val workspace = T.dest / "workspace"
os.makeDir.all(workspace)
val sourceFiles = allSources()
.map(_.path)
.filter(os.exists(_))
Expand All @@ -724,6 +726,7 @@ trait ScalaCliCompile extends ScalaModule {
asOpt(compileClasspath().map(_.path), "--jar"),
asOpt(scalacPluginClasspath().map(p => s"-Xplugin:${p.path}"), "-O"),
Seq("--jvm", "zulu:17"),
workspace,
sourceFiles
)

Expand All @@ -735,6 +738,33 @@ trait ScalaCliCompile extends ScalaModule {

CompilationResult(out / "unused.txt", PathRef(classFilesDir))
}

// Same as https://github.com/com-lihaoyi/mill/blob/084a6650c587629900560b92e3eeb3b836a6f04f/scalalib/src/Lib.scala#L165-L173
// but ignoring hidden directories too, and calling os.isFile only after checking the extension
private def findSourceFiles(sources: Seq[PathRef], extensions: Seq[String]): Seq[os.Path] = {
def isHiddenFile(path: os.Path) = {
val isHidden = path.last.startsWith(".")
if (isHidden) {
val printable =
if (path.startsWith(os.pwd)) path.relativeTo(os.pwd).segments.mkString(File.separator)
else path.toString
System.err.println(
s"Warning: found unexpected hidden file $printable in sources, you may want to remove it."
)
}
isHidden
}
for {
root <- sources
if os.exists(root.path)
path <-
(if (os.isDir(root.path)) os.walk(root.path, skip = isHiddenFile(_)) else Seq(root.path))
if extensions.exists(path.ext == _) && os.isFile(path)
} yield path
}
override def allSourceFiles = T {
findSourceFiles(allSources(), Seq("scala", "java")).map(PathRef(_))
}
}

trait ScalaCliScalafixModule extends ScalafixModule with ScalaCliCompile {
Expand Down