Chromium Contributing Explained: Writing Good Patches

47
1 Samsung Open Source Group Chromium Contribution Process Explained a.k.a. Writing good patches Adenilson Cavalcanti MSc. BSc. Samsung Open Source Group [email protected] (or [email protected])

Transcript of Chromium Contributing Explained: Writing Good Patches

Page 1: Chromium Contributing Explained: Writing Good Patches

1Samsung Open Source Group

Chromium Contribution Process Explained

a.k.a. Writing good patches

Adenilson CavalcantiMSc. BSc.

Samsung Open Source [email protected] (or

[email protected])

Page 2: Chromium Contributing Explained: Writing Good Patches

2Samsung Open Source Group

About the instructor

Adenilson Cavalcanti (a.k.a. Savago) WebKit & Blink committer. W3C CSS WG member. Servo contributor. 15 years of C++. 13 years of Linux/OSS experience. 8 years of mobile. 4 years of WebKit. 2 years of Blink.

Page 3: Chromium Contributing Explained: Writing Good Patches

3Samsung Open Source Group

Why Are We Here?

Share some lessons learned while contributing to Blink (and other open source projects).

Start the discussion about good practices.Explain some cultural aspects of the Chromium community.

Present tips and tricks of the trade.

Page 4: Chromium Contributing Explained: Writing Good Patches

4Samsung Open Source Group

Presentation Structure

Chromium contribution workflow explained.5 Principles to make good contributions.Tips.Best practices working with Chromium team.

Page 5: Chromium Contributing Explained: Writing Good Patches

5

Blink Contribution Workflow Explained

Page 6: Chromium Contributing Explained: Writing Good Patches

6Samsung Open Source Group

The Workflow in a Nutshell

Associate your @company email to a Google account.

Checkout and build.Implement a change.Create a branch.Run the tests.Push to remote.Kick the bots (or ask someone to do it).Ask for review.

Page 7: Chromium Contributing Explained: Writing Good Patches

7

Create a Google Account

• Visit: https://accounts.google.com/SignUp• Use your @company.com account.• You will receive the validation link through your email.

• The password can (and should) be different.

Samsung Open Source Group

Page 8: Chromium Contributing Explained: Writing Good Patches

8Samsung Open Source Group

Create a Google Account

Page 9: Chromium Contributing Explained: Writing Good Patches

9Samsung Open Source Group *if a colleague has a checkout, use a pendrive to copy.

CheckoutInstall depot tools:

git clone https://chromium.googlecode.com/chromium/tools/depot_tools.git

Export PATH=$DEPOT_FOLDERCheckout the code* (21GB)

mkdir chromium; cd chromium; fetch –nohooks chromium; gclient runhooks

Update: git checkout master; git rebase-update; gclient sync --jobs=16

Further info: http://dev.chromium.org/developers/how-tos/get-the-code

Page 10: Chromium Contributing Explained: Writing Good Patches

10Samsung Open Source Group

BuildBeefy hardware: 64 bits + 16GB ram.Intel [email protected] takes 45 minutes.Uses +30GB of disk space.Building*:

./build/gyp_chromium –Dwerror= #configure ninja -C out/Debug/ blink_tests -j10 #layout tests ninja -C out/Debug/ content_unittests -j10 #content Targets: unit_tests | browser_tests | net_unittests |

gpu_unittests ninja -C out/Debug chrome -j10 #chromium browser

Page 11: Chromium Contributing Explained: Writing Good Patches

11Samsung Open Source Group

Patching

Make a change, create a branch and commit: git checkout –b myFeature git commit -a -m “It does something.”

Page 12: Chromium Contributing Explained: Writing Good Patches

12Samsung Open Source Group

Running Tests + Upload

Layout tests: ./Tools/Scripts/run-webkit-tests --debug css3/filters

Content tests: ./out/Debug/content_unittests | unit_tests

If everything is ok (i.e. no regressions), upload the patch: git cl upload

Kick the bots: git cl try

Page 13: Chromium Contributing Explained: Writing Good Patches

13

Notify chromium

issues

2. Develop patch

7. Land patch

Retry 3xManual commit

Submitting Patches: Blink

Page 14: Chromium Contributing Explained: Writing Good Patches

14Samsung Open Source Group

Watching the Bots

You should receive emails about bot status.Investigate if a bot is red.

Page 15: Chromium Contributing Explained: Writing Good Patches

15Samsung Open Source Group

Blink/Chromium: Gaining Status

Committer:

• Same as WebKit (30~40 non-trivial patches).

• Bonus if already a WebKit committer.

Owner:

• Have provided high quality reviews / design feedback.

• Be a Chromium project member for at least 6 months.

• Have submitted a substantial number of non-trivial changes.

• Had made changes to the affected directory within 90 days.

• Bandwidth to contribute with other owners.

Page 16: Chromium Contributing Explained: Writing Good Patches

16

5 Principles To Make Good Contributions

Page 17: Chromium Contributing Explained: Writing Good Patches

17Samsung Open Source Group

The Magic Secret to a Good Patch

Answer these 5 questions.

Page 18: Chromium Contributing Explained: Writing Good Patches

18Samsung Open Source Group

The 5 Magical Questions

Does it improve performance?Is it an enabler for others?Is it spec compliant?Is it innovative?Does it fit the project architecture?

Page 19: Chromium Contributing Explained: Writing Good Patches

19Samsung Open Source Group

If Everything Fails…

Does it improve the performance?Is it an enabler for others?Is it spec compliant?Is it innovative?Does it fit the project architecture?

DOES IT AT LEAST CLEAN UP THE CODE REMARKABLY?

Page 20: Chromium Contributing Explained: Writing Good Patches

20

If the Answer is No…

Give up and try something different.

Samsung Open Source Group

Page 21: Chromium Contributing Explained: Writing Good Patches

21Samsung Open Source Group

Final Consideration

Submit something you are proud of.Put yourself in the reviewer’s shoes.

Page 22: Chromium Contributing Explained: Writing Good Patches

22Samsung Open Source Group

Final Consideration

Submit something you are proud of.Put yourself in the reviewer’s shoes.

Remember: you are putting your name on the line in addition to our company image.

Page 23: Chromium Contributing Explained: Writing Good Patches

23

Extra Tips

Page 24: Chromium Contributing Explained: Writing Good Patches

24Samsung Open Source Group

Writing Good Commit LogsTo be useful, a log must foremost describe why a change was made (the what is obvious by reading the code).

Programmer types: poor programmers don’t write logs; good programmers write logs that need the code to be

understood; great programmers write logs that are self explanatory

and may include references to external documentation.

Page 25: Chromium Contributing Explained: Writing Good Patches

25Samsung Open Source Group

Writing Good Commit LogsBad log: “fix bug and refactor.”

Good log example:

Page 26: Chromium Contributing Explained: Writing Good Patches

26Samsung Open Source Group

Commits Must Be Atomic

Do one change (e.g. implementing one feature) and resist the urge to add non-related things (e.g. aesthetics, typos, etc).

If you identified something else, open a new bug to track the issue and submit another patch later.

Page 27: Chromium Contributing Explained: Writing Good Patches

27Samsung Open Source Group

Quality X Quantity

3 good patches are much better than 15 obvious ones.

Page 28: Chromium Contributing Explained: Writing Good Patches

28Samsung Open Source Group

1 Ferrari F12 == 16 Fiat 500.

Quality X Quantity

Page 29: Chromium Contributing Explained: Writing Good Patches

29Samsung Open Source Group

Self-Review Your Code

When you are done, look for possible areas for improvement.

Try to find cases where it would fail.Does it scale up? Does it scale down?

Page 30: Chromium Contributing Explained: Writing Good Patches

30Samsung Open Source Group

Know Thy Browser

Have all browsers handy and know their behavior for what you working on.

Page 31: Chromium Contributing Explained: Writing Good Patches

31Samsung Open Source Group

Know the Code Style

Before starting anything, read: https://www.chromium.org/developers/coding-style https://www.chromium.org/blink/coding-style

Fix the mistakes pointed by ‘git cl upload’.

Page 32: Chromium Contributing Explained: Writing Good Patches

32

Best Practices Working with Chromium Team

Page 33: Chromium Contributing Explained: Writing Good Patches

33Samsung Open Source Group

Communication is King

Think twice and formulate your thoughts in an articulated way.

If you have difficulties with English, prefer async comm (e.g. mailing list).

Go straight to the point, time is valuable.The way you speak may affect how reviewers may perceive your ideas.

When using IRC:

Page 34: Chromium Contributing Explained: Writing Good Patches

34Samsung Open Source Group

How to Ask Smart Questions*

Do your homework: research; read available documentation; ask your team members;

Write the question with a clear title.Proof read before posting.Add links to each relevant info you found (to prove that at least you tried to find answers).

*Reference: http://catb.org/~esr/faqs/smart-questions.html

Page 35: Chromium Contributing Explained: Writing Good Patches

35Samsung Open Source Group

Know the Time Zones

The team is distributed (from Korea): California is 16 hours behind. Europe (UK) is 8 hours behind.

Sometimes you will have to wake up earlier (or wait for late night) to reach the right person.

Page 36: Chromium Contributing Explained: Writing Good Patches

36Samsung Open Source Group

Observe Cultural Differences

Code review is straight and to the point.The criticism is directed at the code, not at you as a person.

Any accepted contribution brings a cost for maintenance and has to be within the high standards of the project.

Page 37: Chromium Contributing Explained: Writing Good Patches

37Samsung Open Source Group

Observe Cultural Differences

USA: it is alright, OK.Russia: zero.Brazil: insult!

Page 38: Chromium Contributing Explained: Writing Good Patches

38Samsung Open Source Group

Choose an Area and a Reviewer

Select an area/subsystem to work on.Develop a relationship with one or two reviewers.

Avoid jumping from one area to another as it will impact your productivity and your potential nomination to become a committer in the future.

Page 39: Chromium Contributing Explained: Writing Good Patches

39Samsung Open Source Group

Use Bots Sparingly

Bots consume resources and many queued jobs slows down every single contributor.

Only select 3 or 4 bots (e.g. mac, windows, android, linux-debug) and submit the job if you have tested it locally.

Recently a developer was almost had bot permissions blocked because he was ‘trigger happy’.

Page 40: Chromium Contributing Explained: Writing Good Patches

40Samsung Open Source Group

When to Duck

Generally, the reviewers are right when they ask for changes.

Be grateful for the feedback and implement all changes.

Don’t push back or stall (especially if you are not used to the subsystem you are working).

Again: the reviewers are doing you a favor by reviewing your patch.

Page 41: Chromium Contributing Explained: Writing Good Patches

41Samsung Open Source Group

When to Hold Your Ground

If you truly believe your idea makes sense and have done great research.

If you have data (e.g. benchmarks).When you can point to specs (W3C, WHATWG).When other browsers implement the same behavior.

Page 42: Chromium Contributing Explained: Writing Good Patches

42Samsung Open Source Group

The Job is Never Completed

After a patch has landed, keep watching the bots for any regressions: http://build.chromium.org/p/chromium/waterfall

If you noticed that your patch is responsible for a regression, ping the reviewer in IRC and discuss what to do next.

Page 43: Chromium Contributing Explained: Writing Good Patches

43Samsung Open Source Group

Check Your Email on the Weekends*

It may happen that your contribution triggered a regression and in such case you will be notified by email.

Promptly answer the email and start investigating.

If not possible, suggest to rollback the patch and explain when you can start looking into the subject.

*if you can’t, time your patches with weekdays (e.g. Tuesday/Wednesday).

Page 44: Chromium Contributing Explained: Writing Good Patches

44Samsung Open Source Group

Check Your Email on the Weekends

This happenedin a Friday at 23hs!

Page 45: Chromium Contributing Explained: Writing Good Patches

45Samsung Open Source Group

Follow the Mailing List

Be aware of what is happening in the project as a whole.

Sign in to blink-dev and chromium-dev.Before starting something bigger, ask reviewers what they think about it.

Page 46: Chromium Contributing Explained: Writing Good Patches

46Samsung Open Source Group

Questions and Answers

Page 47: Chromium Contributing Explained: Writing Good Patches

47Samsung Open Source Group

Thank You!