scala - How to depend on a setting in the "current" config -
how can declare 2 custom sbt settings, , b, define b in global config scope content depends on a, define differently in several config scopes in such way resulting value of b different in each config though b defined once?
consider example targethost below, defined differently in remote in other config, , scriptcontent depending on it:
object mybuild extends build { lazy val remote = config("remote") describedas ("configuration remote environement ") lazy val targethost = settingkey[string]("private hostname of master server") lazy val scriptcontent = settingkey[string]("some deployment script") lazy val root: project = project("meme", file(".")). settings( name := "hello", targethost := "localhost", targethost in remote := "snoopy", scriptcontent := s""" # bash deployment here /usr/local/uberdeploy.sh ${targethost.value} """ ) } i scriptcontent have different value in both config scopes, since depends on targethost in global scope value same:
> scriptcontent [info] [info] # bash deployment here [info] /usr/local/uberdeploy.sh localhost [info] > remote:scriptcontent [info] [info] # bash deployment here [info] /usr/local/uberdeploy.sh localhost [info] whereas i'd obtain following:
> scriptcontent [info] [info] # bash deployment here [info] /usr/local/uberdeploy.sh localhost [info] > remote:scriptcontent [info] [info] # bash deployment here [info] /usr/local/uberdeploy.sh snoopy [info]
found it! question duplicate (sorry...), , relevant answer here: how can make sbt key see settings current configuration?
=> need apply settings multiple times, once each scope, in order force re-evaluation of content of scriptsetting:
import sbt._ import sbt.keys._ object mybuild extends build { lazy val remote = config("remote") describedas ("configuration remote environement ") lazy val targethost = settingkey[string]("private hostname of master server") lazy val scriptcontent = settingkey[string]("some deployment script") lazy val scriptsettings = seq( scriptcontent := s""" # bash deployment here /usr/local/uberdeploy.sh ${targethost.value} """ ) lazy val root: project = project("meme", file(".")) .settings( name := "hello", targethost := "localhost", targethost in remote := "snoopy" ) .settings(scriptsettings: _*) .settings(inconfig(remote)(scriptsettings) :_*) } yields expected result:
> scriptcontent [info] [info] # bash deployment here [info] /usr/local/uberdeploy.sh localhost [info] > remote:scriptcontent [info] [info] # bash deployment here [info] /usr/local/uberdeploy.sh snoopy [info] >
Comments
Post a Comment