Can the incremental compiler in sbt be turned off for CI builds? - scala

While looking for a way to improve compile times on our build server, I came across this issue about overhead added by the incremental compiler. Since our build server checks out a fresh copy of the source and builds from scratch each time, it would be nice to be able to disable the incremental compiler completely and not have to pay for something that will not be used. Is this possible?

Grzegorz says in #1078:
The original numbers I got back in January were wrong because I was using hacked version of incremental compiler for benchmarks. I gathered more numbers using sbt 0.13.2 and the overhead of incremental compiler [snip] As you can see, for all projects apart from Scala itself, the overhead is below 10%.
So the case was closed as invalid. Related, Ability to disable incremental compiler for CI builds was closed as won't-fix.
Is this possible?
The here answer is, no (we might be open to pull reqs).

Related

scala sbt compilation horror due to slowness and various issues

I am having a very horrible time coding in scala using sbt.
I know compilation in scala is inherently slow as compared to java.
I have tried both eclipse and intellij, to do development in scala + sbt, and both the well knows IDE sucks at the job. Please guide me with the following horrors I am facing:
How to reduce the compilation time to milliseconds in scala(just like it was for java) even for big projects....in the IDEs(eclipse/intellij)....given that I am using sbt
How to ensure the builds in the IDEs work incrementally and on changed files only. I observe that full build happens in the IDE on every code change/save of the file.....again keep in mind that I am using sbt
Please suggest the same for the command line, after every code change, when I do sbt package, and it seems sbt recompiles the complete project rather than changed files.
In intellij, when I try to run a unit test cases, the whole sbt based project is compiled again
Also, if I import a project in intellij and use sbt command line at the same time, the intellij build and the command line build don't play well with each other and I start to observe full compilations in intellij and weired compilation errors
This is only a partial answer, because it depends a lot on what you're doing and what your code looks like - but I tend not to use an IDE for compilation/tests. Instead, I run this in sbt (sometimes with other commands, depending on what I'm doing)
> ~test-quick
which (quoting the docs):
The tests that failed in the previous run
The tests that were not run before
The tests that have one or more transitive dependencies, maybe in a different project, recompiled.
The tilde makes it run every time there has been a code change
For me anyway, it's very fast and importantly only runs what could have changed
Another thing which I have heard (but can't promise will speed things up) is to explicitly type as much as you can. The type inferrer is meant to be quite slow (which makes sense when you think about what it must have to do)
Edit as requested by Saby
Before I go through the points you've raised, I just want to point out that these aren't really horrors and eclipse/intellij don't actually suck at what they do. In fact, when you think about it, it's impressive they work at all.
Scala is a far more complicated language than java and that means the compiler has to do a lot more than java's. What I'm talking about here is features such as macros, implicits and type inference. Those features aren't free and compilation time and memory will take hits here. (basically because the compiler has to all sorts of crazy stuff for type inference; run through the code multiple times for macros; etc, etc, etc)
Obviously, like any other language, your compilation time is determined by a lot of things: what features you use, what patterns you use, what dependencies you have to name just a few.
Anyway, point by point:
I honestly don't know how to answer this one. I am currently working on a smallish java project (think a dozen dependencies, a few thousand lines of code, some spring but not much else going on) and I am certainly not getting millisecond compilation times in Intellij. If this really is causing problems, then my only suggestion is to use the command line.
I don't really know anything at all about eclipse, but if you are using Intellij 13 you can set the incremental compiler like this. The sbt plugin was changed quite a bit in Intellij 14 so I don't think this is an option anymore (ie it does whatever it does)
I think my answer above covers this. The point is you don't have to use sbt package, and I don't typically. Instead type sbt and when it loads type ~test-quick and only run sbt package when you need to
That's probably just how intellij works. Like 3, I don't think you can change this anymore
I don't know what these are, but you should probably Google the error and if you can't find anything create a new Stack Overflow question with some examples.
Other things to consider
Setup can be important. Most hardcore Scala developers I know code in sublime text or emacs using a plugin called ensime and sbt on the command line to test/compile it (along with a repl or two). Otherwise (at the time of writing this anyway), most other people (including me) use Intellij to write their code and then either use sbt on the command line or Intellij itself to test/compile. You need to play about and find what's best for you.
Another thing you want to think about is the version of sbt you're on. I don't have benchmarks for this, but I remember older versions being slower and it would be painful to change the way you work just because you're running an old version of something.
Also make sure you have the java 8 sdk installed - I know the girls and guys at Typesafe are spending more and more time optimising sbt for java 8.
Points 2 and 4 just work for me (and have for a long time), no special setup required.
Also, if I import a project in intellij and use sbt command line at the same time, the intellij build and the command line build don't play well with each other and I start to observe full compilations in intellij and weired compilation errors
This should be fixed in the new Scala plugin version.

What is "incremental linking"?

I've looked at Microsoft's MSDN and all around the web, but I still haven't been able to get a really good idea of what it is.
Does it mean the completed program loads DLLs at different times during its execution, as apposed to all at once upon launch?
Am I totally way off? :)
Linking involves packaging together all of the .obj files built from your source files, as well as any .lib files you reference, into your output (eg .exe or .dll).
Without incremental linking, this has to be done from scratch each time.
Incremental linking links your exe/dll in a way which makes it easier for the linker to update the existing exe/dll when you make a small change and re-compile.
So, incremental linking just makes it faster to compile and link your project.
The only runtime effect it might have is that it may make your exe/dll slightly bigger and slower, as decribed here:
http://msdn.microsoft.com/en-us/library/4khtbfyf.aspx
Edit: As mentioned by Logan, incremental linking is also incompatible with link time code generation - therefore losing a possible performance optimization.
You may want to use incremental linking for debug builds to speed development, but disable it for release builds to improve runtime performance.
Delay loaded DLLs may be what you are thinking of:
http://msdn.microsoft.com/en-us/library/151kt790.aspx
Also, quite importantly, incremental link is a prerequisite for Edit&Continue - possibily to edit your code and recompile it on the fly, without restarting.
So it is a good thing to have on debug builds, but not release builds.

How to become more productive using Scala? (Tools, IDEs)

What Tools do you people use to work with Scala? For my learning phase, I used the Scala REPL and hacked some code with TextMate and compiled it with the scalac CLI. But as the projects grow in size, much more sophisticated tools are required.
I am aware of the Scala plugins for Elipse, IntelliJ and Netbeans and I tried them all. The best one is IMHO IntelliJ, but still far away from being perfect.
The major issue I have is the lack of auto completion. As a not-so-advanced Scala coder, I still dont know the whole standard API and have to switch between the Scaladoc and IDE regularly. This feels like "killing productivity". But they all fail to auto-complete method arguments. (I heard that method arguments are not included in compiled scala code, but what about attaching source to do auto completion?)
Another very annoying issue is the build process. I am using Maven to build my Scala projects and manage their dependencies. But nevertheless, I have to do a full rebuild to test my changes. Maybe I am spoiled by Eclipses incremental rebuild available in the Java world, but it feels like a big issue to me.
I like Scala very much and I feel way more productive while coding, but the lack of sophisticed tools let me feel less productive. And both seem to cancel out themselves.
So, whats my question? I doubt every single Scala programmer uses good ol' vim or emacs along with scalac to do their work. So what tools do you use? What workflows have you developed to bring speed into developing with the Scala language?
Edit
Clarification what I ment with auto-completion of method arguments.
val myList = "foo" :: "all your base" :: Nil
myList.partition(_.length > 3)
For the code above, IntelliJ fail to provide me with the information that partition requires that I have to pass a () => Boolean function. In fact, IntelliJ does not check for this contraint. I can pass a String and IntelliJ will not indicate my error until I do a compile.
scalac
Get familiar with command line options to Scalac.
-deprecation
-Xprint:all: watch your code progress through compiler phases, very useful to see what implicits are applied.
-help / -X' /-Y` list all options.
The latest nightly builds of scalac include a bash completion file that makes these easier to use.
IntelliJ IDEA
Method completion with Javadoc (CTRL-Space, CTRL-Q/Apple-J) Screenshot
Parameter Info for the example in the question (CTRL-P) Screenshot
Method Argument Completion (CTRL-SHIFT-Space). Screenshot
You need to have the source or javadocs linked into the dependencies in IntelliJ to see the Javadoc.
It doesn't currently highlight type errors on the fly, as there are still too many false-positives in complex code. This is coming, though.
Simple Build Tool
SBT keeps the compiler resident, and analyzes dependencies between classes to allow incremental recompilation. It can also monitor for changes to source files and automatically trigger recompilation and/or test execution.
Continous Compilation: >~compile
Continuous Compilation + Test: ~test-quick
I have SBT and IntelliJ project configured in http://github.com/scalaz/scalaz, you could use this as a reference.
I've been using Scala daily for the last six months. I'm still using vim (and ctags to find stuff), and Maven for builds. I've gotten some good mileage out of JRebel when working on Lift web apps -- it will reload changes on the fly without server restarts.
I spent some time looking into IDEs, but it got depressing really fast. I really missed a lot of Eclipse features at first, but after a period of adjustment I don't think I'm significantly less productive now.
I've heard some rumblings that NetBeans is the current champ for Scala IDEs, but I haven't tried it first hand.
One simple way is to use fsc, an offline compiler. It maintains caches of information, and the standard compiler will talk to fsc (running as a daemon) and use its cached information during compilation, thus speeding up your compilation cycle.
Here's my answer on a similar thread. After giving about an hour to Ensime. I just can't help but get the word out. I must say it's very, very well written for an Emacs package.
I am afraid you have to wait for Scala to become rock-solid.
I had exactly the same issue with Java ten years ago. It was even worse.
I also tried them all. For Scala 2.7.7 IntelliJ is the winner, but for Scala 2.8.0-SNAPSHOT Eclipse is not that bad.
Wait half of a year after 2.8.0 is released and check again. It should become bearable.
With Scala 2.8, please see this for getting better performance out of Maven.
You should also give Netbeans 6.8 a try with the nightly Scala build. I am very satisfied programming Scala with this IDE. For building, I sometimes also use Ant. The best thing about NB Scala plugin is that it is fast and code-completion works flawlessly.
For the example you gave: NB gives me this error
code-completion:
The Eclipse Scala IDE is quite mature now (as of 3.0).

What's the best Scala build system? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I've seen questions about IDE's here -- Which is the best IDE for Scala development? and What is the current state of tooling for Scala?, but I've had mixed experiences with IDEs. Right now, I'm using the Eclipse IDE with the automatic workspace refresh option, and KDE 4's Kate as my text editor. Here are some of the problems I'd like to solve:
use my own editor IDEs are really geared at everyone using their components. I like Kate better, but the refresh system is very annoying (it doesn't use inotify, rather, maybe a 10s polling interval). The reason I don't use the built-in text editor is because broken auto-complete functionalities cause the IDE to hang for maybe 10s.
rebuild only modified files The Eclipse build system is broken. It doesn't know when to rebuild classes. I find myself almost half of the time going to project->clean. Worse, it seems even after it has finished building my project, a few minutes later it will pop up with some bizarre error (edit - these errors appear to be things that were previously solved with a project > clean, but then come back up...). Finally, setting "Preferences / Continue launch if project contains errors" to "prompt" seems to have no effect for Scala projects (i.e. it always launches even if there are errors).
build customization I can use the "nightly" release, but I'll want to modify and use my own Scala builds, not the compiler that's built into the IDE's plugin. It would also be nice to pass [e.g.] -Xprint:jvm to the compiler (to print out lowered code).
fast compiling Though Eclipse doesn't always build right, it does seem snappy -- even more so than fsc.
I looked at Ant and Maven, though haven't employed either yet (I'll also need to spend time solving #3 and #4). I wanted to see if anyone has other suggestions before I spend time getting a suboptimal build system working. Thanks in advance!
UPDATE - I'm now using Maven, passing a project as a compiler plugin to it. It seems fast enough; I'm not sure what kind of jar caching Maven does. A current repository for Scala 2.8.0 is available [link]. The archetypes are very cool, and cross-platform support seems very good. However, about compile issues, I'm not sure if fsc is actually fixed, or my project is stable enough (e.g. class names aren't changing) -- running it manually doesn't bother me as much. If you'd like to see an example, feel free to browse the pom.xml files I'm using [github].
UPDATE 2 - from benchmarks I've seen, Daniel Spiewak is right that buildr's faster than Maven (and, if one is doing incremental changes, Maven's 10 second latency gets annoying), so if one can craft a compatible build file, then it's probably worth it...
Points 2 and 4 are extremely difficult to manage with the current scalac. The problem is that Scala's compiler is a little dumb about building files. Basically, it will build whatever you feed it, regardless of whether or not that file really needs to be built. Scala 2.8.0 will have some tremendous improvements in this respect, but until then... Eclipse SDT actually has some very elaborate (and very hackish) code for doing change detection and dependency tracking. On the whole, it does a decent job, but as you have seen, there are wrinkles. Eclipse SDT 2.8.0 will rely on the aforementioned improvements to scalac itself.
So, building only modified files is pretty much out of the question. Aside from SDT, the only tool I know of which even tries this is SBT (Simple Build Tool). It uses a compiler plugin to track files as they are compiled and query the dependency graph computed by the compiler itself. In practice, this yields about a 50% improvement over the recompile-the-world approach. Once again, this is a hack to get around deficiencies in pre-2.8.0 scalac.
The good news is that reasonably fast compilation is still achievable even without worrying about change detection. FSC uses the same technology (ooh, that sounded so "Charlie Eppes") that Eclipse SDT uses to implement fast incremental compilation. In short, it's pretty snappy.
Personally, I use Apache Buildr. Its configuration is significantly cleaner than either Maven's or SBT's and its startup time is orders of magnitude less (when running under MRI). It integrates with FSC and attempts to do some basic change detection on its own (fairly primitive). It also has auto-magical support for the major Scala test frameworks (ScalaTest, ScalaCheck and Specs) as well as support for joint compilation with Java sources and IDE meta generation for IntelliJ and Eclipse. Oh, and it supports all of Maven's features (dependency resolution, etc) and then some. I'm even working on an extension which would allow interactive shell support integrated with JavaRebel and supporting several shell providers (Scala, JIRB, Clojure REPL, etc). It's not ready for the SVN yet, but I'll commit once it's ready (possibly in time for 1.3.5).
As you can see, I'm very firmly of the opinion that Buildr is the best Scala build tool out there. Its documentation is a little spotty where Scala is concerned, but that's because everything is so straightforward that it's hard to document without feeling verbose. You can always check out one of my GitHub repositories for examples. Good luck!
Have you looked at Intellij IDEA and its Scala integration ? Intellij has a loyal (fanatical?) following amongst Java developers, so you may find this is appropriate for your needs.
Am also quite frustrated with the scala plugin on Eclipse and I can add a few more problems to the list:
auto-complete only works some of the time
the debugger doesn't work properly (especially when trying to debug scala xml)
the debugger forgets breakpoints
'go to definition' doesn't work more often than not.
I'm glad to hear that Buildr sounds like a better alternative (on the build front anyhow), I'll give that a try - thanks!
If you use Emacs, I think Ensime is a pretty good IDE. I think at the time writing, Ensime is the only IDE that will give you fast and accurate autocompletion on both Scala and Java objects, including implicit conversions.
There's code browsing support using Speedbar, code templates using the excellent Yasnippet, and code completion menu using Autocomplete. These are all very modern, actively maintained Emacs packages. There's also out of the box incremental building support for Maven and SBT.
There's a lot more in there such as interactive debugging, refactoring, and the Scala interpreter in an inferior process. All the things you want in a modern IDE for Scala is already there in Ensime. Highly recommended for Emacsens.
For the reasons of completeness, I have to say that there is also Pants -- the build tool that in use in Twitter (one of the early scala adopters)
The main difference it that it is intended not only for scala (and written in python, by the way) and is modeled after google build system.
It's not so bloated as sbt, so for the freshmans it's much simplier, but I've never heard about Pants usage outside of twitter and foursquare.
If you scared of SBT, maybe another no-so-popular build tool, ABT, could be an alternative for you?
I went down the same road, and here is where I am at:
- After some initial investigation, I dropped Kate. I love to use it for most things, but when it came to things like defining tab completions, I found it sorely lacking. I would recommend that you look into gedit instead, which is much more robust for Scala development
- With gedit as my editor, I use SBT and have found it to be a great build tool. I can put it into a 'test' mode where when any code changes it recompiles the relevant files and runs my test suite. This has been an extremely effective way to work.
I have not taken a look at Buildr yet. I would like to say that I will, but honestly with SBT at my disposal I don't really have a compelling need to look at another build tool.
If you want to use Eclipse, but build the project using sbt, and still be able to debug, take a look at this post here:
zikaprog.wordpress.com/2010/04/19/scala-eclipse-sbt-and-debugging/
It also can be applied to builders other than sbt.
The latest version of the Maven Scala plugin supports Zinc/Nailgun for faster start times and faster incremental builds. See Zinc and Incremental Compilation.

Best build process solution to manage build versions

I run a rather complex project with several independent applications. These use however a couple of shared components. So I have a source tree looking something like the below.
My Project
Application A
Shared1
Shared2
Application B
Application C
All applications have their own MSBuild script that builds the project and all the shared resources it needs. I also run these builds on a CruiseControl controlled continuous integration build server.
When the applications are deployed they are deployed on several servers to distribute load. This means that it’s extremely important to keep track of what build/revision is deployed on each of the different servers (we need to have the current version in the DLL version, for example “1.0.0.68”).
It’s equally important to be able to recreate a revision/build that been built to be able to roll back if something didn’t work out as intended (o yes, that happends ...). Today we’re using SourceSafe for source control but that possible to change if we could present good reasons for that (SS it’s actually working ok for us so far).
Another principle that we try to follow is that it’s only code that been build and tested by the integration server that we deploy further.
"CrusieControl Build Labels" solution
We had several ideas on solving the above. The first was to have the continuous integration server build and locally deploy the project and test it (it does that now). As you probably know a successful build in CruiseControl generates a build label and I guess we somehow could use that to set the DLL version of our executables (so build label 35 would create a DLL like “1.0.0.35” )? The idea was also to use this build label to label the complete source tree. Then we probably could check out by that label and recreate the build later on.
The reason for labeling the complete tree is to include not only the actual application code (that’s in one place in the source tree) but also all the shared items (that’s in different places in the tree). So a successful build of “Application A” would label to whole tree with label “ApplicationA35” for example.
There might however be an issue when trying to recreate this build and setting the DLL version before deploying as we then don’t have access to the CruiseControl generated build label anymore. If all CrusieControl build labels were unique for all the projects we could use only the number for labeling but that’s not the case (both application A and B could at the same time be on build 35) so we have to include the application name in the label. Hence SourceSafe label “Application35”. How can I then recreate build 34 and set 1.0.0.34 to the DLL version numbers once we built build 35?
"Revision number" solution
Someone told me that Subversion for example creates a revision number for the entire source tree on every check in – is this the case? Has SourceSafe something similar? If this is correct the idea is then to grab that revision number when getting latest and build on the CruiseControl server. The revision number could then be used to set the DLL version number (to for example “1.0.0.5678”). I guess we could then get this specific revision for the Subversion if needed and that then would include that application and all the shared items to be able to recreate a specific version from the past. Would that work and could this also be achived using SourceSafe?
Summarize
So the two main requirements are:
Be able to track build/revision number of the build and deployed DLL.
Be able to rebuild a past revision/build, set the old build/revision number on the executables of that build (to comply with requirement 1).
So how would you solve this? What would be your preferred approach and how would you solve it (or do you have a totally different idea?)? **Pleased give detailed answers. **
Bonus question What are the difference between a revision number and a build number and when would one really need both?
Your scheme is sound and achievable in VSS (although I would suggest you consider an alternative, VSS is really an outdated product).
For your "CI" Build - you would do the Versioning take a look at MSBuild Community Tasks Project which has a "Version" tasks. Typically you will have a "Version.txt" in your source tree and the MSBuild task will increment the "Release" number while the developers control the Major.Minor.Release.Revision numbers (that's how a client of mine wanted it). You can use revision if you prefer.
You then would have a "FileUpdate" tasks to edit the AssemblyInfo.cs file with that version, and your EXE's and "DLL's" will have the desired version.
Finally the VSSLabel task will label all your files appropriately.
For your "Rebuild" Build - you would modify your "Get" to get files from that Label, obviously not execute the "Version" task (as you are SELECTING a version to build) and then the FileUpdate tasks would use that version number.
Bonus question:
These are all "how you want to use them" - I would use build number for, well the build number, that is what I'd increment. If you are using CI you'll have very many builds - the vast majority with no intention of ever deploying anywhere.
The major and minor are self evident - but revision I've always used for a "Hotfix" indicator. I intend to have a "1.3" release - which would in reality be a product with say 1.3.1234.0 version. While working on 1.4 - I find a bug - and need a hot fix as 1.3.2400.1. Then when 1.4 is ready - it would be say 1.4.3500.0
I need more space than responding as comments directly allows...
Thanks! Good answer! What would be the
difference, what would be better
solving this using SubVersion for
example?Richard Hallgren (15 hours
ago)
The problems with VSS have nothing to do with this example (although the "Labeling" feature I believe is implemented inefficiently...)
Here are a few of the issues with VSS
1) Branching is basically impossible
2) Shared checkout is generally not used (I know of a few people who have had success with it)
3) performance is very poor - it is exteremly "chatty"
4) unless you have a very small repository - it is completely unreliable, to the point for most shops it's a ticking timebomb.
For 4 - the problem is that VSS is implemented by the entire repository being represented as "flat files" in the file system. When the repository gets over a certain size (I believe 4GB but I'm not confident in that figure) you get a chance for "corruption". As the size increases the chances of corruption grow until it becomes an almost certainty.
So take a look at your repository size - and if you are getting into the Gigabytes - I'd strongly recommend you begin planning on replacing VSS.
Regardless - a google of "VSS Sucks" gives 30K hits... I think if you did start using an alterantive - you will realize it's well worth the effort.
Have CC.net label the successful builds
have each project in the solution link to a common solutioninfo.cs file which contains assembly and file version attributes (remove from each projects assemblyinfo.cs)
Before the build have cruise control run an msbuild regex replace (from msbuild community tasks) to update the version information using the cc.net build label (passed in as a parameter to the msbuild task)
build the solution, run tests, fx cop etc
Optionally revert the solution info file
The result is that all assemblies in the cc.net published build have the same version numbers which conform to a label in the source code repository
UppercuT can do all of this with a custom packaging task to split the applications up. And to get the version number of the source, you might think about Subversion.
It's also insanely easy to get started.
http://code.google.com/p/uppercut/
Some good explanations here: UppercuT