Skip to content

Commit 67a63bc

Browse files
delanLoirooriol
authored andcommitted
Servo initial downstream commit
Any ancestors of this commit are from upstream mozilla-central, with some filtering and renaming. Our patches and sync tooling start here. The sync tooling has all been squashed into this commit, based on: https://github.com/servo/stylo/commits/64731e10dc8ef87ef52aa2fb9f988c3b2530f3a7
1 parent 0d89b1a commit 67a63bc

11 files changed

+288
-0
lines changed

.github/workflows/main.yml

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
workflow_dispatch:
8+
merge_group:
9+
types: [checks_requested]
10+
11+
12+
jobs:
13+
linux-debug:
14+
name: Linux (Debug)
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: Install Rust
19+
uses: dtolnay/rust-toolchain@stable
20+
- name: Run Tests
21+
run: cargo build --features servo
22+
env:
23+
RUST_BACKTRACE: 1
24+
25+
linux-release:
26+
name: Linux (Release)
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@v4
30+
- name: Install Rust
31+
uses: dtolnay/rust-toolchain@stable
32+
- name: Run Tests
33+
run: cargo build --release --features servo
34+
env:
35+
RUST_BACKTRACE: 1
36+
37+
build-result:
38+
name: Result
39+
runs-on: ubuntu-latest
40+
if: ${{ always() }}
41+
needs:
42+
- linux-debug
43+
- linux-release
44+
steps:
45+
- name: Success
46+
if: ${{ !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }}
47+
run: exit 0
48+
- name: Failure
49+
if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
50+
run: exit 1
51+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: 🪞 Mirror `main`
2+
on:
3+
push:
4+
branches:
5+
- main
6+
7+
jobs:
8+
mirror:
9+
name: Mirror
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
with:
14+
fetch-depth: 0
15+
- name: Get branch name
16+
id: branch-name
17+
run: |
18+
first_commit=$(git log --pretty=\%H --grep='Servo initial downstream commit')
19+
upstream_base="$first_commit~"
20+
echo BRANCH_NAME=$(git log -n1 --pretty='%as' $upstream_base) >> $GITHUB_OUTPUT
21+
- uses: google/[email protected]
22+
name: Mirror to ${{ steps.branch-name.outputs.BRANCH_NAME }}
23+
with:
24+
github-token: ${{ secrets.GITHUB_TOKEN }}
25+
source: main
26+
dest: ${{ steps.branch-name.outputs.BRANCH_NAME }}

.github/workflows/sync-upstream.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Sync upstream with mozilla-central
2+
3+
on:
4+
schedule:
5+
- cron: '0 13 * * *'
6+
workflow_dispatch:
7+
8+
jobs:
9+
sync:
10+
name: Sync
11+
runs-on: ubuntu-22.04
12+
steps:
13+
- uses: actions/checkout@v3
14+
with:
15+
fetch-depth: 1
16+
- uses: actions/cache@v3
17+
with:
18+
path: _cache/upstream
19+
key: upstream
20+
- run: |
21+
./sync.sh _filtered
22+
git fetch -f --progress ./_filtered master:upstream
23+
git push -fu --progress origin upstream

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/_cache/
2+
/_filtered/
3+
/target/
4+
/style/properties/__pycache__/

README.md

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
Stylo
2+
=====
3+
4+
This repo contains Servo’s downstream fork of [Stylo](https://searchfox.org/mozilla-central/source/servo).
5+
6+
The branches are as follows:
7+
8+
- [`upstream`](https://github.com/servo/style/tree/upstream) has upstream mozilla-central filtered to the paths we care about ([style.paths](style.paths)), but is otherwise unmodified
9+
- [`main`](https://github.com/servo/style/tree/ci) has our downstream patches, plus the scripts and workflows for syncing with mozilla-central, to be rebased onto `upstream`
10+
11+
## Building Servo against your local Stylo
12+
13+
Assuming your local `servo` and `stylo` directories are siblings, you can build `servo` against `stylo` by adding the following to `servo/Cargo.toml`:
14+
15+
```toml
16+
[patch."https://github.com/servo/stylo.git"]
17+
derive_common = { path = "../stylo/derive_common" }
18+
malloc_size_of = { path = "../stylo/malloc_size_of" }
19+
selectors = { path = "../stylo/selectors" }
20+
servo_arc = { path = "../stylo/servo_arc" }
21+
servo_atoms = { path = "../stylo/atoms" }
22+
size_of_test = { path = "../stylo/size_of_test" }
23+
static_prefs = { path = "../stylo/style_static_prefs" }
24+
style_config = { path = "../stylo/style_config" }
25+
style_derive = { path = "../stylo/style_derive" }
26+
style = { path = "../stylo/style" }
27+
style_traits = { path = "../stylo/style_traits" }
28+
```
29+
30+
## Syncing `upstream` with mozilla-central
31+
32+
Start by generating a filtered copy of mozilla-central. This will cache the raw mozilla-central in `_cache/upstream`, storing the result in `_filtered`:
33+
34+
```sh
35+
$ ./sync.sh _filtered
36+
```
37+
38+
If `_filtered` already exists, you will need to delete it and try again:
39+
40+
```sh
41+
$ rm -Rf _filtered
42+
```
43+
44+
Now overwrite our `upstream` with those commits and push:
45+
46+
```sh
47+
$ git fetch -f --progress ./_filtered master:upstream
48+
$ git push -fu --progress origin upstream
49+
```
50+
51+
## Rebasing `main` onto `upstream`
52+
53+
Start by fetching `upstream` into your local repo:
54+
55+
```sh
56+
$ git fetch -f origin upstream:upstream
57+
```
58+
59+
In general, the filtering process is deterministic, yielding the same commit hashes each time, so we can rebase normally:
60+
61+
```sh
62+
$ git rebase upstream
63+
```
64+
65+
But if the filtering config changes or Mozilla moves to GitHub, the commit hashes on `upstream` may change. In this case, we need to tell git where the old upstream ends and our own commits start (notice the `~`):
66+
67+
```sh
68+
$ git log --pretty=\%H --grep='Servo initial downstream commit'
69+
e62d7f0090941496e392e1dc91df103a38e3f488
70+
71+
$ git rebase --onto upstream e62d7f0090941496e392e1dc91df103a38e3f488~
72+
Successfully rebased and updated refs/heads/main.
73+
```
74+
75+
`start-rebase.sh` takes care of this automatically, but you should still use `git rebase` for subsequent steps like `--continue` and `--abort`:
76+
77+
```sh
78+
$ ./start-rebase.sh upstream
79+
$ ./start-rebase.sh upstream -i # interactive
80+
$ git rebase --continue # not ./start-rebase.sh --continue
81+
$ git rebase --abort # not ./start-rebase.sh --abort
82+
```
83+
84+
Or if we aren’t ready to rebase onto the tip of upstream:
85+
86+
```sh
87+
$ ./start-rebase.sh upstream~10 -i
88+
```

commit-from-merge.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
# Usage: commit-from-merge.sh <path/to/servo/servo> <merge commit> [extra git-commit(1) arguments ...]
3+
# Given a merge commit made by bors, runs git-commit(1) with your local changes
4+
# while borrowing the author name/email from the right-hand parent of the merge,
5+
# and the author date from the committer date of the merge.
6+
set -eu
7+
8+
lookup_repo=$1; shift
9+
merge_commit=$1; shift
10+
author_name_email=$(git -C "$lookup_repo" log -n1 --pretty='%aN <%aE>' "$merge_commit"\^2)
11+
committer_date=$(git -C "$lookup_repo" log -n1 --pretty='%cd' "$merge_commit")
12+
13+
set -- git commit --author="$author_name_email" --date="$committer_date" "$@"
14+
echo "$@"
15+
"$@"

commit-from-squashed.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
# Usage: commit-from-squashed.sh <squashed commit> [extra git-commit(1) arguments ...]
3+
# Given a squashed commit made by the GitHub merge queue, runs git-commit(1) with your local changes
4+
# while borrowing our author name/email from that commit, our author date from its committer date,
5+
# and our commit message from that commit.
6+
set -eu
7+
8+
squashed_commit=$1; shift
9+
committer_date=$(git log -n1 --pretty='%cd' "$squashed_commit")
10+
11+
# -c is equivalent to --author=$(...'%aN <%aE>') -m $(...'%B'), but allows editing
12+
set -- git commit -c "$squashed_commit" --date="$committer_date" "$@"
13+
echo "$@"
14+
"$@"

shell.nix

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
with import (builtins.fetchTarball {
2+
url = "https://github.com/NixOS/nixpkgs/archive/46ae0210ce163b3cba6c7da08840c1d63de9c701.tar.gz";
3+
}) {};
4+
stdenv.mkDerivation rec {
5+
name = "style-sync-shell";
6+
}

start-rebase.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
# Usage: start-rebase.sh <new base> [extra git-rebase(1) arguments ...]
3+
# Equivalent to git rebase --onto <new base> <last old upstream commit>.
4+
set -eu
5+
6+
new_base=$1; shift
7+
first_commit=$(git log --pretty=\%H --grep='Servo initial downstream commit')
8+
old_base=$first_commit~
9+
10+
git rebase --onto "$new_base" "$old_base" "$@"

style.paths

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Filters and renames use git-filter-repo(1) --paths-from-file:
2+
# https://htmlpreview.github.io/?https://github.com/newren/git-filter-repo/blob/docs/html/git-filter-repo.html#_filtering_based_on_many_paths
3+
4+
servo/components/
5+
servo/rustfmt.toml
6+
7+
regex:servo/components/(.+)==>\1
8+
servo/rustfmt.toml==>rustfmt.toml

sync.sh

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/sh
2+
# Usage: sync.sh <path/to/filtered>
3+
set -eu
4+
5+
root=$(pwd)
6+
mkdir -p "$1"
7+
cd -- "$1"
8+
filtered=$(pwd)
9+
mkdir -p "$root/_cache"
10+
cd "$root/_cache"
11+
export PATH="$PWD:$PATH"
12+
13+
step() {
14+
if [ "${TERM-}" != '' ]; then
15+
tput setaf 12
16+
fi
17+
>&2 printf '* %s\n' "$*"
18+
if [ "${TERM-}" != '' ]; then
19+
tput sgr0
20+
fi
21+
}
22+
23+
step Downloading git-filter-repo if needed
24+
if ! git filter-repo --version 2> /dev/null; then
25+
curl -O https://raw.githubusercontent.com/newren/git-filter-repo/v2.38.0/git-filter-repo
26+
chmod +x git-filter-repo
27+
28+
git filter-repo --version
29+
fi
30+
31+
step Cloning upstream if needed
32+
if ! [ -e upstream ]; then
33+
git clone --bare --single-branch --progress https://github.com/mozilla/gecko-dev.git upstream
34+
fi
35+
36+
step Updating upstream
37+
branch=$(git -C upstream rev-parse --abbrev-ref HEAD)
38+
git -C upstream fetch origin $branch:$branch
39+
40+
step Filtering upstream
41+
# Cloning and filtering is much faster than git filter-repo --source --target.
42+
git clone --bare upstream -- "$filtered"
43+
git -C "$filtered" filter-repo --force --paths-from-file "$root/style.paths"

0 commit comments

Comments
 (0)