Se ha denunciado esta presentación.
Se está descargando tu SlideShare. ×

Road to sbt 1.0 paved with server


Eche un vistazo a continuación

1 de 53 Anuncio

Más Contenido Relacionado

Presentaciones para usted (20)


Similares a Road to sbt 1.0 paved with server (20)


Más reciente (20)

Road to sbt 1.0 paved with server

  1. 1. The road to sbt 1.0 Paved with Server
  2. 2. Who are we? @eed3si9n (Eugene Yokota) ● sbt core dev ● scalaxb ● treehugger.scala ● "learning Scalaz" ● sbt-assembly etc Josh Suereth ● Big Nerd ● Leader of tools team @ Typesafe ● Author o Scala in Depth o sbt in Action
  3. 3. Agenda ● A brief (incomplete and mostly wrong) history of Build Tools ● A roadmap to sbt 1.0 o Modularization ● sbt-server
  4. 4. A brief history of build tools Incomplete and mostly wrong
  5. 5. #!/bin/sh
  6. 6. $ make -j 2 hello # Makefile OBJ = test.o test2.o %.o : %.c $(CC) -c -o $@ < $< hello : $(OBJ) gcc -o $@ $^
  7. 7. Make (1976) ● new! Dependency-based programming ● Uses system command to carry out tasks ● problem! Machine-dependent Q: How do I build this program?
  8. 8. Autoconf/Automake (1991/1996) ● Generate configure script and Makefile templates o Configure generates header scripts and real makefile o Configure discovers what the machine has ● Use an even MORE arcane syntax o m4 macros o magic strings Q: How do I build on this machine?
  9. 9. Internet
  10. 10. $ ant dist <project name="MyProject" default="dist" basedir="."> <description>example build file</description> <property name="src" location="src"/> <property name="build" location="build"/> <property name="dist" location="dist"/> <target name="compile" description="compile the source " > <javac srcdir="${src}" destdir="${build}"/> </target> <target name="dist" depends="compile" description="generate the distribution" > <mkdir dir="${dist}/lib"/> <jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar" basedir="${build}"/> </target> </project>
  11. 11. Ant (2000) Q: How do I build on this machine? ● new! Built-in tasks like mkdir, javac, and jar o Self-contained and platform-independent ● task plugins (like ant-contrib) ● problem! Hard to reuse build logic
  12. 12. Package managers Q: How do I find library source/binary? ● new! Metadata to track library dependencies ● new! Repository to host source and binary ● CTAN (1993), Port (1994), RPM (1997), APT (1998)
  13. 13. Maven (2004) Q: How do I find library source/binary? Q: How do I enforce consistent builds? ● Metadata to track library dependencies ● Repository to host source and binary ● new! Default build (Convention over Configuration) ● new! Plugins that allowed reuse of build logic ● problem! Difficult to customize
  14. 14. Ivy (2004) Q: How do I find library source/binary? ● Metadata to track library dependencies ● Repository to host source and binary ● Maven integration on top of Ant
  15. 15. Rake (2003) rule '.o' => ['.c'] do |t| sh "cc #{t.source} -c -o #{}" end task :name, [:first_name, :last_name] do |t, args| puts "First name is #{args.first_name}" puts "Last name is #{args.last_name}" end
  16. 16. Rake (2004) Q: How do I build on this machine? Q: How do I customize my build? ● new! Internal DSL o Leverage Ruby libraries rather than shell programs o Provide cross-platform ruby libraries for supported language tools ● Real programming language to write tasks
  17. 17. O NOES XML! SAX parsing is declared uncool (immediately after inception) REST/JSON attempt to displace SOAP
  18. 18. Buildr (2008)/Gradle (2009)/ Leningen(2009) ● Maven integration Q: How do I find library source/binary? Q: How do I customize my build? ● Use an internal DSL and a real program language
  19. 19. sbt (2008) Q: How do I find library source/binary? Q: How do I customize my build? Q: How can I develop faster? ● new! Incremental compiler tracking source deps ● new! Interactive shell + library-aware REPL ● new! Test framework abstraction ● new! Parallel by default ● shabby-chic! ANSI colors ● Internal DSL + Maven integration
  20. 20. Google Blaze (2009) Q: How can I develop faster? Q: How do I avoid version conflicts? ● new! Incremental build ● new! Cache builds remotely ● new! Clustered Building ● Abandon Maven. Check in all source to version control. Force everyone on the same version. ● 1 SCM repo for all projects ● Assume homogeneous-ish environment
  21. 21. Pants (2014)/Buck (2014) Q: How can I develop faster? Q: How do I avoid version conflicts? ● Incremental build ● Cache builds remotely ● Force all dependencies to the same version for all projects ● Put everything in a mono-repository
  22. 22. History make (1977) automake (1996)/ autoconf (1991) Rake (2003) Maven (2004) Ivy (2004) sbt (2008) Blaze (2009) Gradle (2009) Leiningen (2009) Pants (2014) Buck (2014) RPM (1997) Ant (2000) Buildr (2008) Jon Pretty's shell scripts (2004-2015)
  23. 23. History Recap ● sbt has inherited: o dependency based programming (Make) o internal build DSL (Rake) o Package/Library Management (Maven) o Convention over configuration (Maven) o Re-usable build flow (Maven) ● sbt brings: o interactivity (on the shell) o parallel by default
  24. 24. A roadmap to sbt 1.0 stability + sbt server => modularization
  25. 25. Stability 1. Conceptual stability 2. Binary compatibility of sbt plugins 3. Source compatibility of build files
  26. 26. Concepts (mostly stable) 1. Scala incremental compiler 2. Dependency manager (Scala-aware) 3. Task and plugin system (using Scala) 4. Test framework abstraction 5. Text-based interactive shell 5. sbt server + client(s)
  27. 27. Plugin binary compatibility ● sbt 0.13 maintained 18 months of bincompat o Lots of hacks and effort. Unable to remove cruft. ● sbt 1.x.y should be bincompat with 1.0.0 ● Need to minimize surface API o able to add small features when requested
  28. 28. Build source compatibility ● Source compatibility of your build.sbt ● sbt 1.x.y should be stable ● sbt 1.0 gives us opportunity to break DSL o Deprecate project/build.scala? o Unify sbt shell key syntax w/ Scala DSL syntax
  29. 29. Modularization Componentize stable features, innovate new ideas 1. Pull out cohesive subprojects 2. Distinguish public API and internal details 3. Document usages 4. Clean up historical code 5. Cross publish for latest scala versions (if applicable) 6. Publish to Maven Central (or JCenter)
  30. 30. Module candidates ● Launcher API ● Serialization API ● Compiler/REPL API ● Test framework API ● Dependency Management API ● Network API ● IO API ● Task DSL ● Completion API ● sbt client (sbt-server)
  31. 31. sbt-server Architecture and Design
  32. 32. The problem ● Many things want access to the build ● We need to centrally control build-related tasks to avoid breakage. o intellij auto-import + "sbt ~ test" o activator + "play run"
  33. 33. sbt-server design sbt-server disk (target/) sbt client commands / watches changes Events (logs, status, custom)
  34. 34. Before server - Command Engine CMD (compile) Engine (sequential) Task Engine (parallel) Read next command from stdin Next command Read previous log file Reload the build Terminal Client
  35. 35. After server - Execution Queue CMD (compile) Engine TasksRead server Queue Next command previous log file Reload the build Server Event Loop Request Queue CommandQueue Client #1 Client #2 LatestState Next State
  36. 36. Problem: Server discovery Who starts the sbt-server, how do we know it is running, how do we connect?
  37. 37. sbt-launcher ● sbt 0.13.2 launcher had support for "servers" o launch config specifies "lock" file which prevents more than one service being started o "lock" file contains location (ip / port) of the service o server is tested (ping) for liveness by the launcher.
  38. 38. Problem: Disconnects ● Client may not be the one to start sbt ● Client may disconnect from server, or server may crash
  39. 39. Connect as an Event val connector = SbtConnector( "terminal", "Command Line Terminal", configuration.baseDirectory) def onConnect(client: SbtClient): Unit = { client handleEvents { … } client watch ... }, onError)(<execution context>)
  40. 40. Connect as an Event val connector = SbtConnector( "terminal", "Command Line Terminal", configuration.baseDirectory) def onConnect(client: SbtClient): Unit = { client handleEvents { … } client watch ... }, onError)(<execution context>) Clients reconstruct their watches and restore their view of the build on any reconnect
  41. 41. Problem: protocol We needed a good mechanism for client + server to communicate. ● Something that can evolve and maintain compatibility ● Something that is easy for plugin authors to extend.
  42. 42. sbt-serialization ● New library based on Scala Pickling o JSON - currently supported format. ● sbt-remote-control has versioned protocol and tests. ● (coming) plugin *Keys as protocol o remote clients can watch/get values o require pickler/unpickler when creating *Key o ??? release plugin "client" jar separate from impl
  43. 43. Problem: Input sbt tasks may want the user to type input
  44. 44. Example Client (input) client.requestExecution( "run", Some(TerminalInteraction -> TerminalThread) ) client server ExecutionRequest
  45. 45. Example task (input) readInput := { val context = (interactionService in Global).value context.readLine("> ", mask=false) }
  46. 46. Problem: commands block When running the `run` task, all other build commands are blocked.
  47. 47. Background Jobs ● tasks can "fork" background jobs in server ● clients can discover/connect/stop with background jobs. server background job service Forked "run" of application scala REPL ensime server? not implemented
  48. 48. Input/Interaction Design ● Commands o The requesting client provides the means for terminal interaction o Logs and stderr/stdout are sent to all clients. ● Background Jobs (Not Completed Yet) o Any client can take terminal interaction for a background task o opt-in for getting stdout/stderr events
  49. 49. Problem: Existing plugins Current plugins + sbt should be able to try out sbt server, without breaking anything
  50. 50. sbt-core-next A new, optional, plugin for sbt 0.13.x series which provides the new services for sbt-server ● BackgroundRunService ● InteractionServicePlugin ● SendEventServicePlugin ● SerializersService In use in Play 2.4
  51. 51. What's next?
  52. 52. sbt-server TODOS ● Interaction Improvements o readline abstraction (a.k.a. Scala REPL support) o Background Job hooks ● meta-project as first class citizen o replace `reload plugins` command for first-class support o ~ as first-class citizen in server ● kill-on-bad-state watchdog
  53. 53. How can I help? ● Follow @scala_sbt ● Contribute to StackOverflow sbt tag ● Report bugs ● Create plugins o Try/migrate your plugins to remote APIs: core-next ● Patch the core o Github Community labeled issues o Subscribe to sbt-dev list o Join the discussion on Gitter sbt/sbt

Notas del editor

  • This is one of the earliest build script known to human history, which builds System V on PDP-11.
  • The grandfather of all build tools.
    In April, 1976, Stuart Feldman found a precious golden ring, and the tab key.
    He used these to conjure forth Make, a tool of arcane syntax and great power.
  • Internet happens. Most of the credit is given to HTML.

  • XML naturally takes over.
    This is the 2nd generation build tool.
  • Adds metadata on top of Makefile. Takes advantage of Internet.
    Not "build tool" in the strict sense but becomes inspiration.
  • 2004 is a major inflection point in the history of build tools.
    Combines the ideas from package managers + self-contained tasks.
  • In 2003 Jim Weirich creates Rake.
    A Make-like build tool using Ruby.

  • 4th generation of build tools. Rake revolution hits JVM.
  • Internal build tool of Google.
  • 5th generation of build tools.
    Inspired by Google Blaze
    Buck is focused on Android development and optimising hot-paths in android dexing Pants is a Twitter/Foursquare project, aimed at Java/Scala and written in python.
  • Stability from the user experience perspective.
    No need to learn and re-learn.
  • sbt plugin is a huge asset to the ecosystem.
    We care a lot of the binary compatibility of the plugins.
  • Scala Process API have moved to standard lib
    We'll be using more external libraries like Scala Pickling and Scala ARM.