Specifying different build types (Debug/Release)

124 views
Skip to first unread message

Michael Franz

unread,
Jan 18, 2013, 10:06:50 AM1/18/13
to simple-b...@googlegroups.com
Hi,

Our old sbt 0.7.7 build we were able to have a debug and release build.  We did this by using system properties (-Duse.elide=true/false, -Dcpp.build.type=Debug/Release).  This allowed us to dynamically add compiler options (-Xelide-below 800) and set some other 'val's for the C++ build.  Is there a better mechanism with sbt 0.12 that would allow me to execute slightly different build depending on the build type?

I took a quick look at InputTasks.  The way I have structured my new build, I need to change settings, the tasks then use the settings I already have.

Thank you

Michael

Mark Harrah

unread,
Jan 18, 2013, 2:37:04 PM1/18/13
to simple-b...@googlegroups.com
I don't think InputTasks will meet your needs there. They are a way to define the task to run based on user input. They cannot change other settings or tasks, though.

You might define settings that define the build type and whether to use elide. For example,

val useElide = SettingKey[Boolean]("use-elide", "...description...")
val cppBuildType = SettingKey[BuildType]("cpp-build-type", "...description...")

sealed trait BuildType
case object Release extends BuildType
case object Debug extends BuildType

Then, your tasks that should have different behavior based on the build type would take it as input. For the compiler options example,

scalacOptions <++= useElide map { flag =>
if(flag) Seq("-Xelide-below", "800") else Nil
}

You can use the 'set' command (see 'help set') to change a setting from the command line. For example,

$ sbt
> set every cppBuildType := Release

That will set the build type in all projects to be a release. You can verify it took effect with 'show' or 'inspect':

> show cpp-build-type
> show compile:scalac-options

-Mark

> Thank you
>
> Michael
>
> --
> You received this message because you are subscribed to the Google Groups "simple-build-tool" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/simple-build-tool/-/qqS3eTsAbI0J.
> To post to this group, send email to simple-b...@googlegroups.com.
> To unsubscribe from this group, send email to simple-build-t...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/simple-build-tool?hl=en.
>

Michael Franz

unread,
Jan 18, 2013, 4:51:16 PM1/18/13
to simple-b...@googlegroups.com
This is great!  This is similar to what I had already done.  I had continued to use the system property as I did not know how to change settings from the command line.  I did some quick changes, and this solution seems to work.

Thank you!
Reply all
Reply to author
Forward
0 new messages