+ All Categories
Home > Documents > Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer...

Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer...

Date post: 23-Jun-2020
Category:
Upload: others
View: 0 times
Download: 0 times
Share this document with a friend
61
Build Systems CSE 403, Spring 2018
Transcript
Page 1: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Build SystemsCSE 403, Spring 2018

Page 2: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

What does a developer do?

Page 3: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

What does a developer do?

● Get the source code● Install dependencies● Compile the code● Run static analysis● Generate documentation● Run tests● Create artifacts for customers● Ship!

Page 4: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

What does a developer do?

● Get the source code● Install dependencies● Compile the code● Run static analysis● Generate documentation● Run tests● Create artifacts for customers● Ship!

Which should be handled manually?

Page 5: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

What does a developer do?

● Get the source code● Install dependencies● Compile the code● Run static analysis● Generate documentation● Run tests● Create artifacts for customers● Ship!

Which should be handled manually?

NONE!

Page 6: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

What to do instead?

Page 7: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

What to do instead?

Automate with a build system!

Page 8: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

What is a build system?

Page 9: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

What is a build system?

● A tool for automating software engineering tasks

Page 10: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

What is a build system?

● A tool for automating software engineering tasks○ Getting the source code○ Installing dependencies○ Compiling the code○ Running static analysis○ Generating documentation○ Running tests○ Creating artifacts for customers○ Shipping!

Page 11: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

What is a build system?

● A tool for automating software engineering tasks○ Getting the source code○ Installing dependencies○ Compiling the code○ Running static analysis○ Generating documentation○ Running tests○ Creating artifacts for customers○ Shipping!

A good build tool handles all these

Page 12: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

What is a build system?

● A tool for automating software engineering ○ Getting the source code○ Installing dependencies○ Compiling the code○ Running static analysis○ Generating documentation○ Running tests○ Creating artifacts for customers○ Shipping!

A good build system handles all these

Page 13: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Tasks

● A task is something that the build system can do

Page 14: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Tasks

● A task is something that the build system can do○ Getting the source code○ Installing dependencies○ Compiling the code○ Running static analysis○ Generating documentation○ Running tests○ Creating artifacts for customers○ Shipping!

Page 15: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Tasks

● A task is something that the build system can do○ Getting the source code○ Installing dependencies○ Compiling the code○ Running static analysis○ Generating documentation○ Running tests○ Creating artifacts for customers○ Shipping!

All tasks!

Page 16: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Tasks

Tasks are code!

Page 17: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Tasks

Tasks are code!

● Should be checked into version control● Should be code-reviewed● Should be tested

Page 18: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Dependencies between tasks

> ls src/

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

Page 19: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Dependencies between tasks

compileMain

compileLib

run libtest

run systemtest

Page 20: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Dependencies between tasks

compileMain

compileLib

run libtest

run systemtest

Page 21: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Dependencies between tasks

● A large project may have thousands of tasks

Page 22: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Dependencies between tasks

● A large project may have thousands of tasks○ What order to run in?○ How to speed up?

Page 23: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Dependencies between tasks

● A large project may have thousands of tasks○ What order to run in?○ How to speed up?

Page 24: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Determining task ordering

● Dependencies between tasks form a directed acyclic graph

Page 25: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Determining task ordering

● Dependencies between tasks form a directed acyclic graph

Topological sort!

Page 26: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Topological sort

● Any ordering on the nodes such that all dependencies are satisfied

Page 27: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Topological sort

● Any ordering on the nodes such that all dependencies are satisfied

● Implement by computing indegree (number of incoming edges) for each node

Page 28: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Topological sort

compileMain

compileLib

run libtest

run systemtest

Page 29: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Topological sort

compileMain

compileLib

run libtest

run systemtest

0

0

1

3

Page 30: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Topological sort

compileMain

compileLib

run libtest

run systemtest

0

0

0

2

Page 31: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Topological sort

compileMain

compileLib

run libtest

run systemtest

0

0

0

1

Page 32: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Topological sort

compileMain

compileLib

run libtest

run systemtest

0

0

0

0

Page 33: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Topological sort

compileMain

compileLib

run libtest

run systemtest

0

0

0

0

Page 34: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Topological sort

compileMain

compileLib

run libtest

run systemtest

Valid sorts:

1. compile Lib, run lib test, compile Main, run system test

Page 35: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

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

Page 36: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

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

Page 37: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

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

Why is this order silly?

Page 38: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Examples of modern build systems

gradle

Apache’s open-source successor to ant, maven

bazel

Google’s internal build tool, open-sourced

https://gradle.org/

https://www.bazel.build/

Page 39: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

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 40: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

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

kind of rule

Page 41: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

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

explicitly specified dependencies

Page 42: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

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

code!

Page 43: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Example task: bazel

java_binary( name = "dux", main_class = "org.dux.cli.DuxCLI", deps = ["@google_options//:compile", "@checker_qual//:compile", "@google_cloud_storage//:compile", "@slf4j//:compile", "@logback_classic//:compile"], srcs = glob(["src/org/dux/cli/*.java", "src/org/dux/backingstore/*.java"),)

Page 44: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Example task: bazel

java_binary( name = "dux", main_class = "org.dux.cli.DuxCLI", deps = ["@google_options//:compile", "@checker_qual//:compile", "@google_cloud_storage//:compile", "@slf4j//:compile", "@logback_classic//:compile"], srcs = glob(["src/org/dux/cli/*.java", "src/org/dux/backingstore/*.java"),)

kind of rule

Page 45: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Example task: bazel

java_binary( name = "dux", main_class = "org.dux.cli.DuxCLI", deps = ["@google_options//:compile", "@checker_qual//:compile", "@google_cloud_storage//:compile", "@slf4j//:compile", "@logback_classic//:compile"], srcs = glob(["src/org/dux/cli/*.java", "src/org/dux/backingstore/*.java"),)

explicitly specified dependencies

Page 46: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Example task: bazel

java_binary( name = "dux", main_class = "org.dux.cli.DuxCLI", deps = ["@google_options//:compile", "@checker_qual//:compile", "@google_cloud_storage//:compile", "@slf4j//:compile", "@logback_classic//:compile"], srcs = glob(["src/org/dux/cli/*.java", "src/org/dux/backingstore/*.java"),)

explicitly specified dependencies(also bazel tasks)

Page 47: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

External and internal dependencies

● A list of tasks (internal) or libraries (external)

Page 48: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

External and internal dependencies

● A list of tasks (internal) or libraries (external)

deps = ["@google_options//:compile", "@checker_qual//:compile", "@google_cloud_storage//:compile", "@slf4j//:compile", "@logback_classic//:compile"],

https://docs.gradle.org/current/userguide/artifact dependencies tutorial.html

Page 49: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Why list dependencies?

● Reproducibility!

Page 50: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Why list dependencies?

● Reproducibility!

deps = ["@google_options//:compile", "@checker_qual//:compile", "@google_cloud_storage//:compile", "@slf4j//:compile", "@logback_classic//:compile"],

https://docs.gradle.org/current/userguide/artifact dependencies tutorial.html

Page 51: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Dependencies between tasks

● A large project may have thousands of tasks○ What order to run in?○ How to speed up?

Page 52: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

How to speed up builds?

Page 53: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

How to speed up builds?

● Incrementalize - only rebuild what you have to

Page 54: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Incrementalization

Main.class

Lib.class

Main.java

Lib.java

Page 55: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Incrementalization

Main.class

Lib.class

Main.java

Lib.java

modified 10:45 AM

modified 1:30 PM

1:31 PMmodified 11:06 AM

modified 11:06 AM

Page 56: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Incrementalization

● Compute hash codes for inputs to each task● When about to execute a task, check input hashes - if they match

the last time the task was executed, skip it!

Page 57: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

How to speed up builds?

● Incrementalize - only rebuild what you have to● Execute many tasks in parallel● Cache artifacts in the cloud

Page 58: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Best practices

● Automate everything

Page 59: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Best practices

● Automate everything● Always use a build tool

Page 60: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Best practices

● Automate everything● Always use a build tool● Have a build server that builds and tests your code on every

commit (continuous integration)

Page 61: Build Systems - University of Washington...Build Systems CSE 403, Spring 2018 What does a developer do? What does a developer do? Get the source code Install dependencies Compile the

Best practices

● Automate everything● Always use a build tool● Have a build server that builds and tests your code on every

commit (continuous integration)● Don’t break the build


Recommended