Skip to content

Commit

Permalink
Merge pull request #104 from eed3si9n/wip/sources_genrule
Browse files Browse the repository at this point in the history
Wrap sources JARs in genrule
  • Loading branch information
eed3si9n authored Dec 9, 2021
2 parents d57d9f9 + 3f161de commit 4490f3a
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ object MultidepsEnrichments {
repr.replaceAll("[^a-zA-Z0-9-\\.]", "_") + classifierRepr
}

def mavenLabel: String = {
def baseMavenLabel: String = {
val org = dep.module.organization.value
val moduleName = dep.module.name.value
val version = dep.version
Expand All @@ -113,9 +113,12 @@ object MultidepsEnrichments {
}
else ""

s"@maven//:${org}/${moduleName}/${version}/${moduleName}-${version}${classifierOrConfigRepr}.jar"
s"@maven//:${org}/${moduleName}/${version}/${moduleName}-${version}${classifierOrConfigRepr}"
}

def mavenLabel: String = s"$baseMavenLabel.jar"
def mavenSourcesLabel: String = s"$baseMavenLabel-sources.jar"

def withoutConfig: Dependency =
dep.withConfiguration(Configuration.empty)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ final case class ArtifactOutput(
val moduleName: String = dependency.module.name.value
val version: String = dependency.version
val mavenLabel: String = dependency.mavenLabel
val mavenSourcesLabel: String = dependency.mavenSourcesLabel
def hasSources: Boolean = sourcesArtifact.isDefined && sourcesArtifactSha256.isDefined

def httpFiles: List[TargetOutput] =
List(httpFile) ::: sourcesHttpFile.toList
Expand Down Expand Up @@ -81,7 +83,7 @@ object ArtifactOutput {
(
o.mavenLabel,
o.label + cfg.suffix,
o.sourcesArtifactSha256.map { case _ => o.sourcesLabel }
if (o.hasSources) Some(o.mavenSourcesLabel) else None,
)
)
}
Expand Down Expand Up @@ -133,7 +135,7 @@ object ArtifactOutput {
private def buildGenruleAndImportDoc(
o: ArtifactOutput,
): Doc = {
val genrule =
def genrule =
TargetOutput(
kind = "genrule",
"name" -> Docs.literal(s"genrules/${o.label}"),
Expand All @@ -143,18 +145,40 @@ object ArtifactOutput {
"tags" -> Docs.array(tags(o.dependency): _*)
).toDoc

val scalaImport =
def sourcesGenrule =
TargetOutput(
kind = "genrule",
"name" -> Docs.literal(s"genrules/${o.sourcesLabel}"),
"srcs" -> Docs.array(s"@${o.sourcesLabel}//file"),
"outs" -> Docs.array(o.mavenSourcesLabel),
"cmd" -> Docs.literal("cp $< $@"),
).toDoc

def scalaImport =
TargetOutput(
kind = "scala_import",
"name" -> Docs.literal("_" + o.label),
"jars" -> Docs.array(o.mavenLabel),
"deps" -> Docs.array(),
"exports" -> Docs.array(),
"tags" -> Docs.array(tags(o.dependency): _*),
"visibility" -> Docs.array("//visibility:public")
).toDoc

def scalaImportWithSrcJar =
TargetOutput(
kind = "scala_import",
"name" -> Docs.literal("_" + o.label),
"jars" -> Docs.array(o.mavenLabel),
"deps" -> Docs.array(),
"exports" -> Docs.array(),
"srcjar" -> Docs.literal(o.mavenSourcesLabel),
"tags" -> Docs.array(tags(o.dependency): _*),
"visibility" -> Docs.array("//visibility:public")
).toDoc

genrule / scalaImport
if (o.hasSources) genrule / sourcesGenrule / scalaImportWithSrcJar
else genrule / scalaImport
}

def buildDoc(
Expand Down
6 changes: 6 additions & 0 deletions tests/src/main/scala/tests/BaseSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,16 @@ abstract class BaseSuite extends MopedSuite(MultiVersion.app) {
val allScalaImportsGraph: List[String] =
List("kind(scala_import, @maven//:all)", "--output", "graph")
val allGenrules: List[String] = List("kind(genrule, @maven//:all)")
val nonSourceGenrules: List[String] =
List(s"""filter(".+(\\d+\\.)*(\\d+)(\\.Final)?(_test)?$$", kind(genrule, @maven//:all))""")
def allScalaImportDeps(target: String): List[String] =
List(s"kind(scala_import, allpaths($target, @maven//:all))")
def allJars(target: String): List[String] =
List(s"kind(file, allpaths($target, @maven//:all))")
def nonSourceJars(target: String): List[String] =
List(
s"""filter(".+/.+-(\\d+\\.)*(\\d+)(\\.Final)?(\\.jar)", kind(file, allpaths($target, @maven//:all)))"""
)
def nonEmptySrcjar(target: String): List[String] =
List(s"""attr("srcjar", ".+", deps($target))""")
def allScalaLibDeps(target: String): List[String] =
Expand Down
Loading

0 comments on commit 4490f3a

Please sign in to comment.