<commit_before>package org.jetbrains.jps.incremental.scala.sbtzinc

import java.nio.file.StandardOpenOption._
import java.nio.file._

import org.jetbrains.jps.ModuleChunk
import org.jetbrains.jps.incremental.CompileContext
import org.jetbrains.jps.incremental.scala.SettingsManager
import org.jetbrains.jps.incremental.scala.data.CompilationData

import scala.collection.JavaConverters._

/**
  * Cache and check scala, java, etc., options for changes across build runs
  */
object CompilerOptionsStore {
  private val cacheDir = "strato-options-cache"
  private val moduleCacheFileSuffix = "_options-cache.txt"

  /**
    * @return true if compiler options change was detected
    */
  def updateCompilerOptionsCache(context: CompileContext, chunk: ModuleChunk, moduleNames: Seq[String]): Boolean = {
    val scalacOptsCacheFile = getCacheFileFor(context, moduleNames)
    val previousScalacOpts = readCachedOptions(scalacOptsCacheFile)
    val currentOpts = getCurrentOptions(context, chunk)
    val changeDetected = previousScalacOpts.isEmpty || previousScalacOpts.get != currentOpts

    if (changeDetected) writeToCache(scalacOptsCacheFile, currentOpts)

    changeDetected
  }

  private def getCacheFileFor(context: CompileContext, moduleNames: Seq[String]): Path = {
    val dataPath = context.getProjectDescriptor.dataManager.getDataPaths.getTargetsDataRoot.toPath
    val scalacOptsDataFile = dataPath.resolve(cacheDir).resolve(moduleNames.head + moduleCacheFileSuffix)
    scalacOptsDataFile
  }
<commit_msg>Fix caching compiler options. Now it is per target not per module name (module name may have multiple targets)<commit_after>package org.jetbrains.jps.incremental.scala.sbtzinc

import java.nio.file.StandardOpenOption._
import java.nio.file._

import org.jetbrains.jps.ModuleChunk
import org.jetbrains.jps.incremental.{CompileContext, ModuleBuildTarget}
import org.jetbrains.jps.incremental.scala.SettingsManager
import org.jetbrains.jps.incremental.scala.data.CompilationData

import scala.collection.JavaConverters._

/**
  * Cache and check scala, java, etc., options for changes across build runs
  */
object CompilerOptionsStore {
  private val cacheDir = "intellij-scala-options-cache"
  private val moduleCacheFileSuffix = "_options-cache.txt"

  /**
    * @return true if compiler options change was detected
    */
  def updateCompilerOptionsCache(context: CompileContext, chunk: ModuleChunk, moduleNames: Seq[String]): Boolean = {
    val target = chunk.getTargets.asScala.minBy(_.getPresentableName)
    val scalacOptsCacheFile = getCacheFileFor(context, target)
    val previousScalacOpts = readCachedOptions(scalacOptsCacheFile)
    val currentOpts = getCurrentOptions(context, chunk)
    val changeDetected = previousScalacOpts.isEmpty || previousScalacOpts.get != currentOpts

    if (changeDetected) writeToCache(scalacOptsCacheFile, currentOpts)

    changeDetected
  }

  private def getCacheFileFor(context: CompileContext, target: ModuleBuildTarget): Path = {
    val dataPath = context.getProjectDescriptor.dataManager.getDataPaths.getTargetsDataRoot.toPath
    val scalacOptsDataFile = dataPath.resolve(cacheDir).resolve(target.getPresentableName + moduleCacheFileSuffix)
    scalacOptsDataFile
  }

{'fraction_non_alphanumeric': 0.08150663785118864, 'fraction_numerical': 0.0, 'mean_word_length': 5.403162055335969, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7665219', 'n_tokens_mistral': 967, 'n_tokens_neox': 944, 'n_words': 202}