Skip to content

Commit

Permalink
scrooge generator: add an option to enable finagle compilation (fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
kevingessner authored and johnynek committed Aug 18, 2017
1 parent d1d3d27 commit dffcc54
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/scala/scripts/TwitterScroogeGenerator.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package scripts

import io.bazel.rules_scala.scrooge_support.{ Compiler, CompilerDefaults }
import com.twitter.scrooge.backend.WithFinagle
import io.bazel.rulesscala.jar.JarCreator
import io.bazel.rulesscala.io_utils.DeleteRecursively
import java.io.{ File, PrintStream }
Expand Down Expand Up @@ -69,11 +70,18 @@ class ScroogeGenerator extends Processor {
// immediateThriftSrcJars.
val remoteSelfThriftSources = getIdx(4)

// Further configuration options for scrooge.
val additionalFlags = getIdx(5)

val tmp = Paths.get(Option(System.getenv("TMPDIR")).getOrElse("/tmp"))
val scroogeOutput = Files.createTempDirectory(tmp, "scrooge")

val scrooge = new Compiler

if (additionalFlags.contains("--with-finagle")) {
scrooge.flags += WithFinagle
}

scrooge.compileJars ++= immediateThriftSrcJars
scrooge.compileJars ++= remoteSelfThriftSources
scrooge.includeJars ++= onlyTransitiveThriftSrcJars
Expand Down
11 changes: 9 additions & 2 deletions twitter_scrooge/twitter_scrooge.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,12 @@ def _gen_scrooge_srcjar_impl(ctx):
# https://github.com/bazelbuild/bazel/issues/3329
worker_arg_pad = "_"
path_content = "\n".join([worker_arg_pad + _colon_paths(ps) for ps in [immediate_thrift_srcs, only_transitive_thrift_srcs, remote_jars, external_jars]])
worker_content = "{output}\n{paths}\n".format(output = ctx.outputs.srcjar.path, paths = path_content)
worker_content = "{output}\n{paths}\n{flags}".format(
output = ctx.outputs.srcjar.path,
paths = path_content,
flags = worker_arg_pad + ':'.join([
'--with-finagle' if ctx.attr.with_finagle else '',
]))

argfile = ctx.new_file(ctx.outputs.srcjar, "%s_worker_input" % ctx.label.name)
ctx.file_action(output=argfile, content=worker_content)
Expand Down Expand Up @@ -226,6 +231,7 @@ scrooge_scala_srcjar = rule(
# do the code gen.
"remote_jars": attr.label_list(),
"jvm_flags": attr.string_list(), # the jvm flags to use with the generator
"with_finagle": attr.bool(default=False),
"_pluck_scrooge_scala": attr.label(
executable=True,
cfg="host",
Expand All @@ -237,13 +243,14 @@ scrooge_scala_srcjar = rule(
},
)

def scrooge_scala_library(name, deps=[], remote_jars=[], jvm_flags=[], visibility=None):
def scrooge_scala_library(name, deps=[], remote_jars=[], jvm_flags=[], visibility=None, with_finagle=False):
srcjar = name + '_srcjar'
scrooge_scala_srcjar(
name = srcjar,
deps = deps,
remote_jars = remote_jars,
visibility = visibility,
with_finagle = with_finagle,
)

# deps from macro invocation would come via srcjar
Expand Down

0 comments on commit dffcc54

Please sign in to comment.