spring 2020 software engineering build systems …rjust/courses/2020...today gradle live demo get...
TRANSCRIPT
CSE 403Software Engineering
Spring 2020
Build systems
May 6, 2020
Recap: The Joel Test
1. Do you use source control?2. Can you make a build [+ release] in one step?3. Do you make daily builds?4. Do you have a bug database?5. Do you fix bugs before writing new code?6. Do you have an up-to-date schedule?7. Do you have a spec?8. Do programmers have quiet working conditions?9. Do you use the best tools money can buy?
10. Do you have testers?11. Do new candidates write code during their interview?12. Do you do hallway usability testing?
Recap: The Joel Test (20 years later)
1. Do you use source control?2. Can you make a build [+ release] in one step?3. Do you make daily builds? Do you use CI (clean master branch)?4. Do you have a bug database?5. Do you fix bugs before writing new code?6. Do you have an up-to-date schedule?7. Do you have a spec?8. Do programmers have quiet working conditions?9. Do you use the best tools money can buy?
10. Do you have testers? Do you do automated testing ANDdo you have testers on your team?
11. Do new candidates write code during their interview?12. Do you do hallway usability testing?
Recap: The Joel Test (20 years later)
1. Do you use source control?2. Can you make a build [+ release] in one step?3. Do you make daily builds? Do you use CI (clean master branch)?4. Do you have a bug database?5. Do you fix bugs before writing new code?6. Do you have an up-to-date schedule?7. Do you have a spec?8. Do programmers have quiet working conditions?9. Do you use the best tools money can buy?
10. Do you have testers? Do you do automated testing ANDdo you have testers on your team?
11. Do new candidates write code during their interview?12. Do you do hallway usability testing?
403 requires
Build systems● What is a build system?● Best practices● Gradle live demo
Today
● Get the source code● Install dependencies● Compile the code● Run static analysis● Generate documentation● Run tests● Create artifacts for customers● Ship!
What does a developer do?
Which of these tasks should be handled manually?
● Get the source code● Install dependencies● Compile the code● Run static analysis● Generate documentation● Run tests● Create artifacts for customers● Ship!
What does a developer do?
Which of these tasks should be handled manually?NONE!
● Get the source code● Install dependencies● Compile the code● Run static analysis● Generate documentation● Run tests● Create artifacts for customers● Ship!
How to automate these tasks?
Orchestrate tasks with a build system!
● Get the source code● Install dependencies● Compile the code● Run static analysis● Generate documentation● Run tests● Create artifacts for customers● Ship!
What is a build system (build tool)?
A tool for automating software engineering tasks:
Build systems: tasks
Tasks are code!● Should be checked into version control● Should be code-reviewed● Should be tested
Build systems: dependencies between tasks
Example code and corresponding tests:
> ls src/
Lib.java LibTest.java Main.java SystemTest.java
compileMain
compileLib
run libtest
run systemtest
Build systems: dependencies between tasks
What are the dependencies between these tasks?
compileMain
compileLib
run libtest
run systemtest
Build systems: dependencies between tasks
compileMain
compileLib
run libtest
run systemtest
Build systems: dependencies between tasks
In what order should we run these tasks?
Large projects may have thousands of task dependencies● Dependencies between tasks form a directed acyclic graph.
Build systems: determining task order
Large projects may have thousands of task dependencies● Dependencies between tasks form a directed acyclic graph.
Topological sort● Order nodes such that all dependencies are satisfied● Implemented by computing indegree
(number of incoming edges) for each node
Build systems: determining task order
compileMain
compileLib
run libtest
run systemtest
Build systems: topological sort
What’s the indegree of each node?
compileMain
compileLib
run libtest
run systemtest
0
0
1
3
Build systems: topological sort
compileMain
compileLib
run libtest
run systemtest
0
0
0
2
Build systems: topological sort
compileMain
compileLib
run libtest
run systemtest
0
0
0
1
Build systems: topological sort
compileMain
compileLib
run libtest
run systemtest
0
0
0
0
Build systems: topological sort
compileMain
compileLib
run libtest
run systemtest
0
0
0
0
Build systems: topological sort
compileMain
compileLib
run libtest
run systemtest
Valid sorts:
1. compile Lib, run lib test, compile Main, run system test
2. compile Main, compile Lib, run lib test, run system test
3. compile Lib, compile Main, run lib test, run system test
Build systems: topological sort
Which of these sorts is preferable?
compileMain
compileLib
run libtest
run systemtest
Valid sorts:
1. compile Lib, run lib test, compile Main, run system test
2. compile Main, compile Lib, run lib test, run system test
3. compile Lib, compile Main, run lib test, run system test
Build systems: topological sort
Which of these sorts is preferable?
Build systems: examples
gradle
Open-source successor to ant and maven● Groovy/Kotlin DSL (vs. xml)● Many defaults for (maven) conventions
bazel
Open-source version of Google’s internal build tool (blaze)
Example task: gradle
task reformat(type: Exec, dependsOn: getCodeFormatScripts, group: 'Format') { description 'Format the Java source code' // jdk8 and checker-qual have no source, so skip onlyIf { !project.name.is('jdk8') && !project.name.is('checker-qual') } executable 'python' doFirst { args += "${formatScriptsHome}/run-google-java-format.py" args += "--aosp" // 4 space indentation args += getJavaFilesToFormat(project.name) }}
task reformat(type: Exec, dependsOn: getCodeFormatScripts, group: 'Format') { description 'Format the Java source code' // jdk8 and checker-qual have no source, so skip onlyIf { !project.name.is('jdk8') && !project.name.is('checker-qual') } executable 'python' doFirst { args += "${formatScriptsHome}/run-google-java-format.py" args += "--aosp" // 4 space indentation args += getJavaFilesToFormat(project.name) }} explicitly specified
dependencies
Example task: gradle
task reformat(type: Exec, dependsOn: getCodeFormatScripts, group: 'Format') { description 'Format the Java source code' // jdk8 and checker-qual have no source, so skip onlyIf { !project.name.is('jdk8') && !project.name.is('checker-qual') } executable 'python' doFirst { args += "${formatScriptsHome}/run-google-java-format.py" args += "--aosp" // 4 space indentation args += getJavaFilesToFormat(project.name) }} Actual code (no xml)!
Example task: gradle
In many cases, following conventions andusing built-in tasks is sufficient to get started!
Best practices
● Automate everything (one-step build)!● Always use a build tool.● Use CI to build and test your code on every commit.● Don’t depend on anything that’s not in the build file (hermetic)!● Don’t break the build
Live demo: Build systems
Set up:1. Two clones of the basic-stats repo (cloned from Bitbucket).2. Goal: migrate from Ant to Gradle.
Two scenarios:1. Bad: Breaking the build on master2. Good: New hermetic build on a branch
Live demo: Breaking the build
René breaking the build on master
Kaushal making a small change
Live demo: New hermetic build
● Development on a branch● Backward compatibility● Testing and code review