Skip to content

Commit

Permalink
refactor(stack): Avoid copying the project package
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Viernau <frank_viernau@epam.com>
  • Loading branch information
fviernau committed Jul 3, 2024
1 parent 28fe497 commit cb1a182
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions plugins/package-managers/stack/src/main/kotlin/Stack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ class Stack(
else -> throw IOException("Multiple *.cabal files found in '$cabalFiles'.")
}

val projectPackage = parseCabalFile(cabalFile.readText())
val projectId = projectPackage.id.copy(type = managerName)
val projectPackage = parseCabalFile(cabalFile.readText(), managerName)

val externalDependencies = listDependencies(workingDir, EXTERNAL_SCOPE_NAME)
val testDependencies = listDependencies(workingDir, TEST_SCOPE_NAME)
Expand Down Expand Up @@ -135,7 +134,7 @@ class Stack(
val packages = dependencyPackageMap.values.filterTo(mutableSetOf()) { it.id in referencedPackageIds }

val project = Project(
id = projectId,
id = projectPackage.id,
definitionFilePath = VersionControlSystem.getPathInfo(definitionFile).path,
authors = projectPackage.authors,
declaredLicenses = projectPackage.declaredLicenses,
Expand Down Expand Up @@ -179,7 +178,7 @@ class Stack(
)

if (location == null || location.type == HACKAGE_PACKAGE_TYPE) {
downloadCabalFile(id)?.let { return parseCabalFile(it) }
downloadCabalFile(id)?.let { return parseCabalFile(it, "Hackage") }
}

return Package.EMPTY.copy(
Expand Down Expand Up @@ -281,13 +280,13 @@ class Stack(

// TODO: Consider replacing this with a Haskell helper script that calls "readGenericPackageDescription" and dumps
// it as JSON to the console.
private fun parseCabalFile(cabal: String): Package {
private fun parseCabalFile(cabal: String, identifierType: String): Package {
// For an example file see
// https://hackage.haskell.org/package/transformers-compat-0.5.1.4/src/transformers-compat.cabal
val map = parseKeyValue(cabal.lines().listIterator())

val id = Identifier(
type = "Hackage",
type = identifierType,
namespace = map["category"].orEmpty(),
name = map["name"].orEmpty(),
version = map["version"].orEmpty()
Expand Down

0 comments on commit cb1a182

Please sign in to comment.