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

Does not work sbt 1.4 remote cache feature #10490

Closed
xuwei-k opened this issue Oct 20, 2020 · 8 comments · Fixed by #10707
Closed

Does not work sbt 1.4 remote cache feature #10490

xuwei-k opened this issue Oct 20, 2020 · 8 comments · Fixed by #10707
Milestone

Comments

@xuwei-k
Copy link
Contributor

xuwei-k commented Oct 20, 2020

Play Version

2.8.2

API

Maybe both(Java and Scala)

Operating System

Mac and Linux (also maybe Windows)

JDK

1.8

Library Dependencies

unrelated

Expected Behavior

it should work sbt 1.4 remote cache feature

Actual Behavior

recompile even if there is cache

Reproducible Test Case

step and log

$ sbt pushRemoteCache
$ sbt clean pullRemoteCache compile
[info] welcome to sbt 1.4.1 (AdoptOpenJDK Java 1.8.0_265)
[info] loading settings for project sbt-remote-cache-playframework-build from plugins.sbt ...
[info] loading project definition from /home/runner/work/sbt-remote-cache-playframework/sbt-remote-cache-playframework/project
[info] loading settings for project sbt-remote-cache-playframework from build.sbt ...
[info] set current project to sbt-remote-cache-playframework (in build file:/home/runner/work/sbt-remote-cache-playframework/sbt-remote-cache-playframework/)
[info] Executing in batch mode. For better performance use sbt's shell
[success] Total time: 0 s, completed Oct 20, 2020 5:01:29 AM
[info] remote cache artifact extracted for Some(cached-compile)
[info] remote cache artifact extracted for Some(cached-test)
[success] Total time: 1 s, completed Oct 20, 2020 5:01:30 AM
[warn] There may be incompatibilities among your library dependencies; run 'evicted' to see detailed eviction warnings.
[info] compiling 5 Scala sources and 1 Java source to /home/runner/work/sbt-remote-cache-playframework/sbt-remote-cache-playframework/target/scala-2.13/classes ...
[info] done compiling
[success] Total time: 9 s, completed Oct 20, 2020 5:01:39 AM

app/controllers/Application.scala

package controllers

import play.api.mvc._
import javax.inject.Inject

class Application @Inject()(cc: ControllerComponents) extends AbstractController(cc) {

  def index = Action {
    Ok("hello")
  }

}

build.sbt

scalaVersion := "2.13.3"

libraryDependencies +=  guice

enablePlugins(PlayScala)

pushRemoteCacheTo := Some(
  MavenCache("local-cache", (ThisBuild / baseDirectory).value / "remote-cache")
)

remoteCacheId := "fixed-id"

remoteCacheIdCandidates := Seq(remoteCacheId.value)

pushRemoteCacheConfiguration := pushRemoteCacheConfiguration.value.withOverwrite(true)

conf/routes

GET     /                           controllers.Application.index

project/build.properties

sbt.version=1.4.1

project/plugins.sbt

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.2")

Note

playframework routes generator embed current DATE in generated source comments.
I think it is the cause this issue 🤔

$  git grep @DATE
dev-mode/routes-compiler/src/main/twirl/play/routes/compiler/inject/forwardsRouter.scala.twirl:// @@DATE:@sourceInfo.date
dev-mode/routes-compiler/src/main/twirl/play/routes/compiler/static/javaWrappers.scala.twirl:// @@DATE:@sourceInfo.date
dev-mode/routes-compiler/src/main/twirl/play/routes/compiler/static/javascriptReverseRouter.scala.twirl:// @@DATE:@sourceInfo.date
dev-mode/routes-compiler/src/main/twirl/play/routes/compiler/static/reverseRouter.scala.twirl:// @@DATE:@sourceInfo.date
dev-mode/routes-compiler/src/main/twirl/play/routes/compiler/static/routesPrefix.scala.twirl:// @@DATE:@sourceInfo.date

cat target/scala-2.13/routes/main/router/RoutesPrefix.scala

different @DATE comment 😢

after first compile
// @GENERATOR:play-routes-compiler
// @SOURCE:/home/runner/work/sbt-remote-cache-playframework/sbt-remote-cache-playframework/conf/routes
// @DATE:Tue Oct 20 05:01:03 UTC 2020
after second compile

(I want to use remote cache but play re-generate different source 😢 )

// @GENERATOR:play-routes-compiler
// @SOURCE:/home/runner/work/sbt-remote-cache-playframework/sbt-remote-cache-playframework/conf/routes
// @DATE:Tue Oct 20 05:01:31 UTC 2020

Is this a sbt bug or playframework bug? /cc @eed3si9n
playframework should not embed @DATE comment? 🤔

@xuwei-k
Copy link
Contributor Author

xuwei-k commented Oct 20, 2020

There is one other thing routes-generator embed @SOURCE as absolute path. I think it may become an obstacle between share caches😢

@raboof
Copy link
Member

raboof commented Oct 20, 2020

playframework should not embed @Date comment? 🤔

I agree it would be better not to include a date there, to make the output more deterministic

@xuwei-k
Copy link
Contributor Author

xuwei-k commented Oct 20, 2020

workaround:

routesGenerator := {
  import play.routes.compiler.{RoutesCompiler, RoutesGenerator, Rule}
  val base = InjectedRoutesGenerator
  new RoutesGenerator {
    override def generate(
      task: RoutesCompiler.RoutesCompilerTask,
      namespace: Option[String],
      rules: List[Rule]
    ): Seq[(String, String)] = {
      val baseDir = (ThisBuild / baseDirectory).value.getCanonicalPath + "/"
      val sourceCommentPrefix = s"// @SOURCE:${baseDir}"
      base.generate(task = task, namespace = namespace, rules = rules).map {
        case (fileName, src) =>
          fileName -> src.linesIterator
            .filterNot(_ contains "@DATE")
            .map {
              case line if line.startsWith(sourceCommentPrefix) =>
                line.replace(baseDir, "")
              case line =>
                line
            }
            .mkString("\n")
      }
    }
    override def id = base.id
  }
}

@ignasi35
Copy link
Member

playframework should not embed @DATE comment? 🤔

Could this be the DATE of the source file (instead of the timestamp when the source code was created?)

@ignasi35
Copy link
Member

playframework/twirl@a769228/compiler/src/main/scala/play/twirl/compiler/TwirlCompiler.scala#L725

Maybe twirl has same issue 😢

see playframework/twirl#209

@mkurz mkurz added this to the 2.8.8 milestone Feb 16, 2021
@mkurz
Copy link
Member

mkurz commented Feb 16, 2021

For the generated routes files i think we can fix this like we did with twirl by removing the generation date and keeping the source comment relative:
playframework/twirl#378

@mkurz
Copy link
Member

mkurz commented Feb 16, 2021

Fix is here: #10707

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants