Skip to content

Commit

Permalink
Merge pull request #6191 from mkurz/fix_onLoad_1.4.x
Browse files Browse the repository at this point in the history
[1.4.x] onLoad now runs with correct FileTreeRepository and CacheStoreFactory
  • Loading branch information
eed3si9n committed Dec 4, 2020
2 parents 75184ca + 07df9aa commit 160349e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
12 changes: 8 additions & 4 deletions main/src/main/scala/sbt/Main.scala
Expand Up @@ -940,13 +940,17 @@ object BuiltinCommands {

val session = Load.initialSession(structure, eval, s0)
SessionSettings.checkSession(session, s2)
val s3 = addCacheStoreFactoryFactory(Project.setProject(session, structure, s2))
val s3 = Project.setProject(
session,
structure,
s2,
st => setupGlobalFileTreeRepository(addCacheStoreFactoryFactory(st))
)
val s4 = s3.put(Keys.useLog4J.key, Project.extract(s3).get(Keys.useLog4J))
val s5 = setupGlobalFileTreeRepository(s4)
// This is a workaround for the console task in dotty which uses the classloader cache.
// We need to override the top loader in that case so that it gets the forked jline.
s5.extendedClassLoaderCache.setParent(Project.extract(s5).get(Keys.scalaInstanceTopLoader))
addSuperShellParams(CheckBuildSources.init(LintUnused.lintUnusedFunc(s5)))
s4.extendedClassLoaderCache.setParent(Project.extract(s4).get(Keys.scalaInstanceTopLoader))
addSuperShellParams(CheckBuildSources.init(LintUnused.lintUnusedFunc(s4)))
}

private val setupGlobalFileTreeRepository: State => State = { state =>
Expand Down
12 changes: 10 additions & 2 deletions main/src/main/scala/sbt/Project.scala
Expand Up @@ -478,7 +478,15 @@ object Project extends ProjectExtra {
previousOnUnload(s.runExitHooks())
}

def setProject(session: SessionSettings, structure: BuildStructure, s: State): State = {
def setProject(session: SessionSettings, structure: BuildStructure, s: State): State =
setProject(session, structure, s, identity)

def setProject(
session: SessionSettings,
structure: BuildStructure,
s: State,
preOnLoad: State => State
): State = {
val unloaded = runUnloadHooks(s)
val (onLoad, onUnload) = getHooks(structure.data)
val newAttrs = unloaded.attributes
Expand All @@ -488,7 +496,7 @@ object Project extends ProjectExtra {
val newState = unloaded.copy(attributes = newAttrs)
// TODO: Fix this
onLoad(
updateCurrent(newState) /*LogManager.setGlobalLogLevels(updateCurrent(newState), structure.data)*/
preOnLoad(updateCurrent(newState)) /*LogManager.setGlobalLogLevels(updateCurrent(newState), structure.data)*/
)
}

Expand Down

0 comments on commit 160349e

Please sign in to comment.