spring 2020 software engineering build systems …rjust/courses/2020...today gradle live demo get...

32
CSE 403 Software Engineering Spring 2020 Build systems May 6, 2020

Upload: others

Post on 23-Jun-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate

CSE 403Software Engineering

Spring 2020

Build systems

May 6, 2020

Page 2: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate

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?

Page 3: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate

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?

Page 4: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate

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

Page 5: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate

Build systems● What is a build system?● Best practices● Gradle live demo

Today

Page 6: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate

● 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?

Page 7: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate

● 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!

Page 8: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate

● 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!

Page 9: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate

● 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:

Page 10: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate

Build systems: tasks

Tasks are code!● Should be checked into version control● Should be code-reviewed● Should be tested

Page 11: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate

Build systems: dependencies between tasks

Example code and corresponding tests:

> ls src/

Lib.java LibTest.java Main.java SystemTest.java

Page 12: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate

compileMain

compileLib

run libtest

run systemtest

Build systems: dependencies between tasks

What are the dependencies between these tasks?

Page 13: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate

compileMain

compileLib

run libtest

run systemtest

Build systems: dependencies between tasks

Page 14: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate

compileMain

compileLib

run libtest

run systemtest

Build systems: dependencies between tasks

In what order should we run these tasks?

Page 15: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate

Large projects may have thousands of task dependencies● Dependencies between tasks form a directed acyclic graph.

Build systems: determining task order

Page 16: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate

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

Page 17: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate

compileMain

compileLib

run libtest

run systemtest

Build systems: topological sort

What’s the indegree of each node?

Page 18: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate

compileMain

compileLib

run libtest

run systemtest

0

0

1

3

Build systems: topological sort

Page 19: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate

compileMain

compileLib

run libtest

run systemtest

0

0

0

2

Build systems: topological sort

Page 20: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate

compileMain

compileLib

run libtest

run systemtest

0

0

0

1

Build systems: topological sort

Page 21: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate

compileMain

compileLib

run libtest

run systemtest

0

0

0

0

Build systems: topological sort

Page 22: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate

compileMain

compileLib

run libtest

run systemtest

0

0

0

0

Build systems: topological sort

Page 23: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate

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?

Page 24: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate

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?

Page 25: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate

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)

Page 26: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate

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) }}

Page 27: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate

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

Page 28: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate

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!

Page 29: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate

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

Page 30: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate

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

Page 31: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate

Live demo: Breaking the build

René breaking the build on master

Kaushal making a small change

Page 32: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate

Live demo: New hermetic build

● Development on a branch● Backward compatibility● Testing and code review