lists.torproject.org
Sign In Sign Up
Manage this list Sign In Sign Up

Keyboard Shortcuts

Thread View

  • j: Next unread message
  • k: Previous unread message
  • j a: Jump to all threads
  • j l: Jump to MailingList overview

tbb-commits

Thread Start a new thread
Threads by month
  • ----- 2025 -----
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2024 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2023 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2022 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2021 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2020 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2019 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2018 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2017 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2016 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2015 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2014 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
tbb-commits@lists.torproject.org

  • 1 participants
  • 19117 discussions
[Git][tpo/applications/tor-browser] Pushed new branch tor-browser-134.0a1-15.0-1
by morgan (@morgan) 22 Jan '25

22 Jan '25
morgan pushed new branch tor-browser-134.0a1-15.0-1 at The Tor Project / Applications / Tor Browser -- View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/tree/tor-brows… You're receiving this email because of your account on gitlab.torproject.org.
1 0
0 0
[Git][tpo/applications/tor-browser] Pushed new branch tor-browser-133.0a1-15.0-1
by morgan (@morgan) 22 Jan '25

22 Jan '25
morgan pushed new branch tor-browser-133.0a1-15.0-1 at The Tor Project / Applications / Tor Browser -- View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/tree/tor-brows… You're receiving this email because of your account on gitlab.torproject.org.
1 0
0 0
[Git][tpo/applications/tor-browser] Pushed new branch tor-browser-132.0a1-15.0-1
by morgan (@morgan) 22 Jan '25

22 Jan '25
morgan pushed new branch tor-browser-132.0a1-15.0-1 at The Tor Project / Applications / Tor Browser -- View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/tree/tor-brows… You're receiving this email because of your account on gitlab.torproject.org.
1 0
0 0
[Git][tpo/applications/tor-browser] Pushed new branch tor-browser-131.0a1-15.0-1
by morgan (@morgan) 22 Jan '25

22 Jan '25
morgan pushed new branch tor-browser-131.0a1-15.0-1 at The Tor Project / Applications / Tor Browser -- View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/tree/tor-brows… You're receiving this email because of your account on gitlab.torproject.org.
1 0
0 0
[Git][tpo/applications/tor-browser] Pushed new branch tor-browser-130.0a1-15.0-1
by morgan (@morgan) 22 Jan '25

22 Jan '25
morgan pushed new branch tor-browser-130.0a1-15.0-1 at The Tor Project / Applications / Tor Browser -- View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/tree/tor-brows… You're receiving this email because of your account on gitlab.torproject.org.
1 0
0 0
[Git][tpo/applications/tor-browser][tor-browser-128.6.0esr-14.5-1] fixup! TB 41649: Create rebase and security backport gitlab issue templates
by morgan (@morgan) 22 Jan '25

22 Jan '25
morgan pushed to branch tor-browser-128.6.0esr-14.5-1 at The Tor Project / Applications / Tor Browser Commits: 4462e6b8 by Morgan at 2025-01-22T15:35:54+00:00 fixup! TB 41649: Create rebase and security backport gitlab issue templates - TB 43298: add rebase template for nightly-based Tor Browser Alpha and Bugzilla Triage Issue generation - TB 43341: Create Firefox Nightly Rebase Issue Template - - - - - 2 changed files: - + .gitlab/issue_templates/Bugzilla Triage.md - + .gitlab/issue_templates/Rebase Browser - Rapid.md Changes: ===================================== .gitlab/issue_templates/Bugzilla Triage.md ===================================== @@ -0,0 +1,51 @@ + # Bugzilla Triage + + **NOTE** This issue presumes the branches and tags for the next Firefox release have already been created in tor-browser.git + + - [ ] Generate Bugzilla triage CSV + - Run (from `tor-browser-build` root): + ```bash + ./tools/browser/generate-bugzilla-triage-csv ${FIREFOX_VERSION} ${PREVIOUS_NIGHTLY_TAG} ${NEXT_NIGHLTY_TAG} ${TRIAGE_ISSUE_NUMBER} ${REVIEWERS} > out.csv + ``` + - `${FIREFOX_VERSION}`: the major Firefox version of the nightly to review + - **Example**: 129 + - `${PREVIOUS_NIGHTLY_TAG}`: the nightly 'end' tag of the previous major Firefox version + - **Example**: `FIREFOX_NIGHTLY_128_END` + - `${NEXT_NIGHLTY_TAG}`: the nightly 'end' tag of the next major Firefox version we are reviewing + - **Example**: `FIREFOX_NIGHTLY_129_END` + - `${TRIAGE_ISSUE_NUMBER}`: this `tor-browser` issue + - **Example**: `43303` + - `${REVIEWERS}`: `morgan` and two additional devs to triage this Firefox version + - `boklm` + - `brizental` + - `clairehurst` + - `dan` + - `henry` + - `jwilde` + - `ma1` + - `pierov` + - **Example**: + ```bash + ./tools/browser/generate-bugzilla-triage-csv 129 FIREFOX_NIGHTLY_128_END FIREFOX_NIGHTLY_129_END 43303 morgan pierov henry > 129.csv + ``` + - [ ] Attach the generated CSV file to the triage isssue + - [ ] Import to Google Sheets ( https://sheets.google.com ) + - [ ] Create blank spreadsheet + - [ ] **Title**: `Bugzilla Triage ${VERSION}` + - [ ] Import CSV: File > Import > Upload + - **Import location**: "Replace spreadsheet" + - **Separator type**: "Comma" + - **Convert text to numbers, dates, and fomulas**: "✅" + - [ ] Convert 'Review' column's issue cells to check-boxes: + - Select relevant cells (i.e.: `A2:A1554` for in the 129 triage) + - Insert > Checkbox + - [ ] Convert 'Triaged by' cells to check-boxes + - [ ] Share Spreadsheet + - 🔒 Share > General access + - Change `Restricted` to `Anyone with the link` + - Post link in an internal note on this issue + - [ ] Page requested reviewers to this issue + - [ ] Triage Completed by: + - [ ] morgan + - [ ] reviewer 1 <!-- replace with reviewer name :) --> + - [ ] reviewer 2 <!-- replace with reviewer name :) --> ===================================== .gitlab/issue_templates/Rebase Browser - Rapid.md ===================================== @@ -0,0 +1,276 @@ +- **NOTE**: All examples in this template reference the rebase from Firefox 129.0a1 to 130.0a1 +- **TODO**: + - Documentation step for any difficulties or noteworthy things for each rapid rebase + +<details> + <summary>Explanation of Channels</summary> + + There are unfortunately some collisions between how we and Mozilla name our release channels which can make things confusing: + - **Firefox**: + - **Nightly**: \_START and \_END tags, version in the format `$(MAJOR).$(MINOR)a1` + - **Example**: Firefox Nightly 130 was `130.0a1` + - **Note**: Nightly is 2 major versions ahead of the current Release + - **Beta**: tagged each Monday, Wednesday, and Friday until release, version in the format `$(MAJOR).$(MINOR)b$(PATCH)` + - **Example**: the first Firefox Beta 130 was `130.0b1` + - **Note**: Beta is 1 major version ahead of the current Release, should be irrelevant to us + - **Release**: tagged monthly, version in the format `$(MAJOR).$(MINOR)` or `$(MAJOR).$(MINOR).$(PATCH)` + - **Example** Firefox Release 130 was `130.0` + - **ESR**: tagged monthly, version in the format `$(ESR_MAJOR).$(ESR_MINOR).$(ESR_PATCH)esr` + - **Example**: Firefox ESR 128.1 is `128.1.0esr` + - **Tor+Mullvad Browser**: + - **Rapid**: tagged monthly, based on the latest Firefox Nightly + - **Nightly**: not tagged, built nightly from our current Alpha branch's `HEAD` + - **Alpha**: tagged monthly, based on the latest Firefox ESR + - **Stable**: tagged monthly, based on oldest supported Firefox ESR + +</details> + +<details> + <summary>Branching Overview</summary> + + Rebasing Tor Browser Rapid onto the current Firefox Nightly is a bit more confusing/involved than rebasing Tor Browser Alpha or Stable from one minor ESR to the next minor ESR. + + The general process basically involves rebasing the previous Firefox Nightly-based Tor Browser Rapid onto the latest Firefox Nightly, and then cherry-picking all of the commits from the previous Firefox ESR-based Tor Browser Alpha after that channel's `build1` tag. This process presumes that the previous Tor Browser Alpha branch is locked and receiving no more changes. + + This diagram provides a high-level view of the overall code-flow for rebasing/cherry-picking commits from Tor Browser Alpha based on Firefox 128.1.0esr and Tor Browser Rapid based on Firefox 129.0a1 onto Firefox 130.0a1: + + ```mermaid +%%{init: { 'themeVariables': {'git0': '#0072b2', 'gitBranchLabel0': '#fff', 'git1': "#e69f00", 'gitBranchLabel1': '#fff', 'git2': '#009e73', 'gitBranchLabel2': '#fff', 'git3': '#cc79a7', 'gitBranchLabel3': '#fff'}, 'gitGraph': {'mainBranchName': 'tor-browser-128.1.0esr-14.5-1'}} }%% +gitGraph: + branch tor-browser-129.0a1-15.0-2 + branch tor-browser-130.0a1-15.0-1 + branch tor-browser-130.0a1-15.0-2 + + checkout tor-browser-128.1.0esr-14.5-1 + commit id: "FIREFOX_128_1_0esr_BUILD1" + commit id: "base-browser-128.1.0esr-14.5-1-build1" + commit id: "tor-browser-128.1.0esr-14.5-1-build1" + commit id: "tor-browser-128.1.0esr-14.5-1-build2" + + checkout tor-browser-129.0a1-15.0-2 + commit id: "FIREFOX_NIGHTLY_129_END" + %% commit id: "tor-browser-129.0a1-15.0-2-build1" + + checkout tor-browser-130.0a1-15.0-1 + commit id: "FIREFOX_NIGHTLY_130_END" + + checkout tor-browser-130.0a1-15.0-2 + commit id: "FIREFOX_NIGHTLY_130_END " + + checkout tor-browser-130.0a1-15.0-1 + merge tor-browser-129.0a1-15.0-2 + + checkout tor-browser-130.0a1-15.0-2 + merge tor-browser-130.0a1-15.0-1 + + + checkout tor-browser-129.0a1-15.0-2 + commit id: "tor-browser-129.0a1-15.0-2-build1" + + checkout tor-browser-130.0a1-15.0-1 + merge tor-browser-129.0a1-15.0-2 id: "tor-browser-130.0a1-15.0-1-build1" + + checkout tor-browser-130.0a1-15.0-2 + merge tor-browser-130.0a1-15.0-1 + + checkout tor-browser-130.0a1-15.0-1 + merge tor-browser-128.1.0esr-14.5-1 + + checkout tor-browser-130.0a1-15.0-2 + merge tor-browser-130.0a1-15.0-1 + + checkout tor-browser-128.1.0esr-14.5-1 + commit id: "tor-browser-128.1.0esr-14.5-1" + + checkout tor-browser-130.0a1-15.0-1 + merge tor-browser-128.1.0esr-14.5-1 id:"tor-browser-130.0a1-15.0-1-build2" + + checkout tor-browser-130.0a1-15.0-2 + + merge tor-browser-130.0a1-15.0-1 + commit id: "tor-browser-130.0a1-15.0-2-build1" + + ``` + + In this concrete example, the rebaser performs the following steps: + - create new `tor-browser-130.0a1-15.0-1`, and `tor-browser-130.0a1-15.0-2` branches from the `FIREFOX_NIGHTLY_130_END` tag. + - these will be the rebase review branches + - onto `tor-browser-130.0a1-15.0-1`, cherry-pick the range `FIREFOX_NIGHTLY_129_END..tor-browser-129.0a1-15.0-2-build1` (i.e. the Firefox Nightly 129-based Tor Browser Rapid commits) + - this updates the previous Tor Browser Rapid onto Firefox Nightly 130 + - cherry-pick the new alpha patches onto `tor-browser-130.0a1-15.0-1` (i.e. cherry-pick `tor-browser-128.1.0esr-14.5-1-build2..origin/tor-browser-128.1.0esr-14.5-1`) + - onto `tor-browser-130.0a1-15.0-2`, rebase and autosquash the `FIREFOX_NIGHTLY_130_END..tor-browser-130.0a1-15.0-2-build1` commit range + - onto `tor-browser-130.0a1-15.0-2`, cherry-pick the remaining commit range `tor-browser-130.0a1-15.0-2-build1..origin/tor-browser-130.0a1-15.0-2` + - re-order any remaining fixup! commits to be adjacent to their parents (i.e. the same rebase command queue as one would get from `git rebase --autosquash`, but with the `fixup!` commands replaced with `pick!` commands). + - this re-organises the branch in a nicely-bisectable way, and will ensure the rebase+autosquash step for the next release *should* succeed without any additional effort + +</details> + +<details> + <summary>Explanation of Variables</summary> + +- `$(NIGHTLY_VERSION)`: the Mozilla defined nightly version, used in various places for building tor-browser tags, labels, etc + - **Example**: `130.0a1` +- `$(NIGHTLY_TAG)`: the Mozilla defined hg (Mercurial) tag associated with `$(NIGHTLY_VERSION)` + - **Example**: `FIREFOX_NIGHTLY_130_END` +- `$(NIGHTLY_TAG_PREV)`: the Mozilla defined hg (Mercurial) tag associated with the previous nightly version when rebasing (ie, the nightly version we are rebasing from) + - **Example**: `FIREFOX_NIGHTLY_129_END` +- `$(BROWSER_VERSION)`: the browser version which will first be based on the next major ESR version this *Firefox* Nightly series is leading up to + - **Example**: `15` +- `$(TOR_BROWSER_BRANCH)`: the full name of the current `tor-browser` branch based off of the Firefox Nightly channel + - **Example**: `tor-browser-130.0a1-15.0-1` +- `$(TOR_BROWSER_BRANCH_PREV)`: the full name of the previous `tor-browser` branch based off of the Firefox Nightly channel + - **Example**: `tor-browser-129.0a1-15.0-1` +</details> + +### Update Branch Protection Rules + +- [ ] In [Repository Settings](https://gitlab.torproject.org/tpo/applications/tor-browser/-/sett…: + - [ ] Remove previous nightly `tor-browser` branch protection rules (this will prevent pushing new changes to the branches being rebased) + - [ ] Create new `tor-browser` branch protection rule: + - **Branch**: `tor-browser-$(NIGHTLY_VERSION)-$(BROWSER_VERSION)-*` + - **Example**: `tor-browser-130.0a1-15.0-*` + - **Allowed to merge**: `Maintainers` + - **Allowed to push and merge**: `Maintainers` + - **Allowed to force push**: `false` + - ⚠️ **IMPORTANT**: If you copied and pasted from old rules, double check you didn't add spaces at the end, as GitLab will not trim them! + +### **Create New Branches** + +- [ ] Find the Firefox mercurial tag `$(NIGHTLY_TAG)` + - Go to https://hg.mozilla.org/mozilla-central/tags + - Find and inspect the commit tagged with `$(NIGHTLY_TAG)` + - Tags are in yellow in the Mercurial web UI + - Find the equivalent commit in https://github.com/mozilla/gecko-dev/commits/master + - **Notice**: GitHub sorts commits by time, you might want to use `git log gecko-dev/master` locally, instead + - Using the differential revision link is useful to quickly find the git commit + - Sign/Tag the `gecko-dev` commit: `git tag -as $(NIGHTLY_TAG) $(GIT_HASH) -m "Hg tag $(NIGHTLY_TAG)"` +- [ ] Create two new rapid `tor-browser` branches from Firefox mercurial tag + - Branch name in the form: `tor-browser-$(NIGHTLY_VERSION)-$(BROWSER_VERSION)-${BRANCH_NUM}` + - **Example**: `tor-browser-130.0a1-15.0-1` and `tor-browser-130.0a1-15.0-2` +- [ ] Push new `tor-browser` branches and the `firefox` tag to `upstream` + +### **Rebase previous `-2` rapid branch's HEAD onto current `-1` rapid branch** + +- **Desired outcome**: + - An easy to review branch with the previous rapid branch rebased onto the latest Firefox Nighty tag + - It must be possible to run `git range-diff` between the previous `-2` and the new branch + - We want to see only the effects of the rebase + - No autosquash should happen at this point + - **Expected difficulties**: + - Conflicts with upstream developments + - Sometimes it will be hard to keep a feature working. It's fine to drop it, and create an issue to restore it after a deeper investigation. +- [ ] Checkout a new local branch for the first part of the `-1` rebase + - **Example**: `git checkout -b rapid-rebase-part1 origin/tor-browser-130.0a1-15.0-1` +- [ ] Firefox Nightly-based `tor-browser` rebase: + - [ ] cherry-pick previous Tor Browser Rapid `-2` branch to new `-1` rebase branch + - **Example**: `git cherry-pick FIREFOX_NIGHTLY_129_END..origin/tor-browser-129.0a1-15.0-2` +- [ ] Rebase Verification: + - [ ] Clean range-diff between the previous rapid branch and current rebase branch + - **Example**: + ```bash + git range-diff FIREFOX_NIGHTLY_129_END..origin/tor-browser-129.0a1-15.0-2 FIREFOX_NIGHTLY_130_END..rapid-rebase-part1 + ``` + - [ ] Optional: clean diff of diffs between previous rapid branch and current rebase branch + - **Example**: + ```bash + git diff FIREFOX_NIGHTLY_129_END origin/tor-browser-129.0a1-15.0-2 > 129.diff + git diff FIREFOX_NIGHTLY_130_END HEAD > 130.diff + # A two-column diff tool is suggested rather than plain-diff, e.g., meld on Linux. + meld 129.diff 130.diff + ``` + - **Note**: Only differences should be due to resolving merge conflicts with upstream changes from Firefox Nightly +- [ ] Open MR +- [ ] Merge +- [ ] Sign/Tag `HEAD` of the merged `tor-browser` branch: + - In **tor-browser.git**, checkout the `-1` rapid `tor-browser` branch + - In **tor-browser-build.git**, run signing script: + ```bash + ./tools/browser/sign-tag.torbrowser rapid build1 + ``` + - [ ] Push tag to `upstream` + +### **Port new alpha patches to `-1`** + +- **Desired outcome**: + - The previous release-cycle's new alpha patches cherry-picked to the end of the current nightly + - It must be possible to run `git range-diff ESR-build1..ESR NIGHTLY-build1..` + - **Expected difficulties**: + - Conflicts with upstream developments (similar to the previous part) + - The range might contain cherry-picked upstream commits, which will result in empty commits: it's fine to skip them + - **Note**: The Tor Browser Alpha branch should be closed at this point and not receiving any more MRs +- [ ] Checkout a new local branch for the second part of the `-1` rebase + - **Example**: `git checkout -b rapid-rebase-part2 origin/tor-browser-130.0a1-15.0-1` +- [ ] Cherry-pick the new `tor-browser` alpha commits (i.e. the new dangling commits which did not appear in the previous Tor Browser Alpha release): + - **Example** `git cherry-pick tor-browser-128.1.0esr-14.5-1-build1..origin/tor-browser-128.1.0esr-14.5-1` +- [ ] Rebase Verification + - [ ] Clean range-diff between the alpha patch set ranges + - **Example**: + ```bash + git range-diff tor-browser-128.1.0esr-14.5-1-build1..origin/tor-browser-128.1.0esr-14.5-1 origin/tor-browser-130.0a1-15.0-1..HEAD + ``` + - [ ] Clean diff of diffs between the alpha patch set ranges + - **Example**: + ```bash + git diff tor-browser-128.1.0esr-14.5-1-build1 origin/tor-browser-128.1.0esr-14.5-1 > 128.1.0esr.diff + git diff origin/tor-browser-130.0a1-15.0-1 HEAD > 130.diff + # A two-column diff tool is suggested rather than plain-diff, e.g., meld on Linux. + meld 128.1.0esr.diff 130.diff + ``` + - **Note**: Only differences should be due to resolving merge conflicts with upstream changes from Firefox Nightly +- [ ] Open MR +- [ ] Merge +- [ ] Sign/Tag `HEAD` of the merged `tor-browser` branch: + - In **tor-browser.git**, checkout the `-1` rapid `tor-browser` branch + - In **tor-browser-build.git**, run signing script: + ```bash + ./tools/browser/sign-tag.torbrowser rapid build2 + ``` + - [ ] Push tag to `upstream` + +### **Squash and Reorder tor-browser `-1` branch to new `-2` branch** +- **Desired outcome**: + - The rapid branch from the previous step prepared for the next nightly + - **Rationale**: + - We squash a lot of commits. We want to keep them a little bit longer rather than squashing them immediately for troubleshooting and documentation purposes. + - Doing this as a separate pass helps to separate errors due to upstream changes from errors due to processes created by our workflow. + - **Expected difficulties**: + - our patches aren't disjoint, therefore we might have conflicts when shuffling them around. +- [ ] Checkout a new local branch for the `-2` rebase, aligned to -1-build1 + - **Example**: `git checkout -b rapid-rebase-part3 tor-browser-130.0a1-15.0-1-build1` +- [ ] Rebase with autosquash. This step should be trivial and not involve any conflicts. + - **Example**: `git rebase -i --autosquash FIREFOX_NIGHTLY_130_END` +- [ ] Cherry-pick the remaining commits + - **Example**: `git cherry-pick tor-browser-130.0a1-15.0-1-build1..upstream/tor-browser-130.0a1-15.0-1` +- [ ] Create a branch for self-reviewing purposes, or take note of the current commit hash somewhere + - **Example**: `git branch rapid-rebase-part3-review` + - You do not need to publish this, and you can delete it at the end of the process (`git branch -D rapid-rebase-part3-review`) + - When you are a reviewer, it might be useful to repeat these steps locally. They should not involve mental overhead (and PieroV has a script to automate this) +- [ ] Rebase and reorder commits (i.e. replace `fixup `, `fixup -C ` and `squash ` with `pick ` commands) + - Notice the space at the end, to avoid replacing `fixup!` with `pick!` in the commit subject, even though git will probably not care of such changes +- [ ] Rebase Verification + - [ ] Clean range-diff between the temporary review branch and the final branch + - **Example**: + ```bash + git range-diff FIREFOX_NIGHTLY_130_END..rapid-rebase-part3-review FIREFOX_NIGHTLY_130_END..rapid-rebase-part3 + ``` + - If you are the reviewer, it should be trivial to create such a branch on your own, as no shuffling is involved + - [ ] Clean diff of diffs between rapid branches + - **Example**: + ```bash + git diff FIREFOX_NIGHTLY_130_END tor-browser-130.0a1-15.0-1-build2 > 130-1.diff + git diff FIREFOX_NIGHTLY_130_END HEAD > 130-2.diff + ``` + - [ ] Understandable range-diff (i.e. `fixup!` patches are distributed from end of branch next to their parent) + - **Example**: + ```bash + git range-diff FIREFOX_NIGHTLY_130_END..tor-browser-130.0a1-15.0-1-build2 FIREFOX_NIGHTLY_130_END..HEAD + ``` +- [ ] Open MR +- [ ] Merge +- [ ] Sign/Tag `HEAD` of the merged `tor-browser` branch: + - In **tor-browser.git**, checkout the `-2` rapid `tor-browser` branch + - In **tor-browser-build.git**, run signing script: + ```bash + ./tools/browser/sign-tag.torbrowser rapid build1 + ``` + - [ ] Push tag to `upstream` View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/4462e6b… -- View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/4462e6b… You're receiving this email because of your account on gitlab.torproject.org.
1 0
0 0
[Git][tpo/applications/mullvad-browser][mullvad-browser-128.6.0esr-14.5-1] fixup! Adding issue and merge request templates
by morgan (@morgan) 22 Jan '25

22 Jan '25
morgan pushed to branch mullvad-browser-128.6.0esr-14.5-1 at The Tor Project / Applications / Mullvad Browser Commits: 0d538394 by Pier Angelo Vendrame at 2025-01-22T15:20:41+00:00 fixup! Adding issue and merge request templates Remove "Emergency" from security updates as per today's meeting. Our policy usually is to backport (almost) all emergency fixes, sooner or later. The actual emergency can be inferred from the timeline. - - - - - 1 changed file: - .gitlab/merge_request_templates/default.md Changes: ===================================== .gitlab/merge_request_templates/default.md ===================================== @@ -34,12 +34,12 @@ #### Timeline - [ ] **No Backport (preferred)**: patchset for the next major stable -- [ ] **Immediate**: patchset needed as soon as possible +- [ ] **Immediate**: patchset needed as soon as possible (fixes CVEs, 0-days, etc) - [ ] **Next Minor Stable Release**: patchset that needs to be verified in nightly before backport - [ ] **Eventually**: patchset that needs to be verified in alpha before backport #### (Optional) Justification -- [ ] **Emergency security update**: patchset fixes CVEs, 0-days, etc +- [ ] **Security update**: patchset contains a security fix (be sure to select the correct item in _Timeline_) - [ ] **Critical bug-fix**: patchset fixes a bug in core-functionality - [ ] **Consistency**: patchset which would make development easier if it were in both the alpha and release branches; developer tools, build system changes, etc - [ ] **Sponsor required**: patchset required for sponsor View it on GitLab: https://gitlab.torproject.org/tpo/applications/mullvad-browser/-/commit/0d5… -- View it on GitLab: https://gitlab.torproject.org/tpo/applications/mullvad-browser/-/commit/0d5… You're receiving this email because of your account on gitlab.torproject.org.
1 0
0 0
[Git][tpo/applications/tor-browser][base-browser-128.6.0esr-14.5-1] fixup! Adding issue and merge request templates
by morgan (@morgan) 22 Jan '25

22 Jan '25
morgan pushed to branch base-browser-128.6.0esr-14.5-1 at The Tor Project / Applications / Tor Browser Commits: 450569e5 by Pier Angelo Vendrame at 2025-01-22T15:17:54+00:00 fixup! Adding issue and merge request templates Remove "Emergency" from security updates as per today's meeting. Our policy usually is to backport (almost) all emergency fixes, sooner or later. The actual emergency can be inferred from the timeline. - - - - - 1 changed file: - .gitlab/merge_request_templates/default.md Changes: ===================================== .gitlab/merge_request_templates/default.md ===================================== @@ -35,12 +35,12 @@ #### Timeline - [ ] **No Backport (preferred)**: patchset for the next major stable -- [ ] **Immediate**: patchset needed as soon as possible +- [ ] **Immediate**: patchset needed as soon as possible (fixes CVEs, 0-days, etc) - [ ] **Next Minor Stable Release**: patchset that needs to be verified in nightly before backport - [ ] **Eventually**: patchset that needs to be verified in alpha before backport #### (Optional) Justification -- [ ] **Emergency security update**: patchset fixes CVEs, 0-days, etc +- [ ] **Security update**: patchset contains a security fix (be sure to select the correct item in _Timeline_) - [ ] **Censorship event**: patchset enables censorship circumvention - [ ] **Critical bug-fix**: patchset fixes a bug in core-functionality - [ ] **Consistency**: patchset which would make development easier if it were in both the alpha and release branches; developer tools, build system changes, etc View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/450569e… -- View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/450569e… You're receiving this email because of your account on gitlab.torproject.org.
1 0
0 0
[Git][tpo/applications/tor-browser][tor-browser-128.6.0esr-14.5-1] fixup! Adding issue and merge request templates
by morgan (@morgan) 22 Jan '25

22 Jan '25
morgan pushed to branch tor-browser-128.6.0esr-14.5-1 at The Tor Project / Applications / Tor Browser Commits: 5fd73855 by Pier Angelo Vendrame at 2025-01-22T15:07:58+00:00 fixup! Adding issue and merge request templates Remove "Emergency" from security updates as per today's meeting. Our policy usually is to backport (almost) all emergency fixes, sooner or later. The actual emergency can be inferred from the timeline. - - - - - 1 changed file: - .gitlab/merge_request_templates/default.md Changes: ===================================== .gitlab/merge_request_templates/default.md ===================================== @@ -35,12 +35,12 @@ #### Timeline - [ ] **No Backport (preferred)**: patchset for the next major stable -- [ ] **Immediate**: patchset needed as soon as possible +- [ ] **Immediate**: patchset needed as soon as possible (fixes CVEs, 0-days, etc) - [ ] **Next Minor Stable Release**: patchset that needs to be verified in nightly before backport - [ ] **Eventually**: patchset that needs to be verified in alpha before backport #### (Optional) Justification -- [ ] **Emergency security update**: patchset fixes CVEs, 0-days, etc +- [ ] **Security update**: patchset contains a security fix (be sure to select the correct item in _Timeline_) - [ ] **Censorship event**: patchset enables censorship circumvention - [ ] **Critical bug-fix**: patchset fixes a bug in core-functionality - [ ] **Consistency**: patchset which would make development easier if it were in both the alpha and release branches; developer tools, build system changes, etc View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/5fd7385… -- View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/5fd7385… You're receiving this email because of your account on gitlab.torproject.org.
1 0
0 0
[Git][tpo/applications/mullvad-browser][mullvad-browser-128.6.0esr-14.5-1] fixup! Add CI for Base Browser
by Pier Angelo Vendrame (@pierov) 22 Jan '25

22 Jan '25
Pier Angelo Vendrame pushed to branch mullvad-browser-128.6.0esr-14.5-1 at The Tor Project / Applications / Mullvad Browser Commits: fe2fa243 by Henry Wilkes at 2025-01-22T15:24:17+01:00 fixup! Add CI for Base Browser MB 324: Move update-translations from tor-browser to base-browser. - - - - - 1 changed file: - .gitlab-ci.yml Changes: ===================================== .gitlab-ci.yml ===================================== @@ -8,3 +8,4 @@ variables: include: - local: '.gitlab/ci/jobs/lint/lint.yml' + - local: '.gitlab/ci/jobs/update-translations.yml' View it on GitLab: https://gitlab.torproject.org/tpo/applications/mullvad-browser/-/commit/fe2… -- View it on GitLab: https://gitlab.torproject.org/tpo/applications/mullvad-browser/-/commit/fe2… You're receiving this email because of your account on gitlab.torproject.org.
1 0
0 0
[Git][tpo/applications/tor-browser][base-browser-128.6.0esr-14.5-1] fixup! Add CI for Base Browser
by Pier Angelo Vendrame (@pierov) 22 Jan '25

22 Jan '25
Pier Angelo Vendrame pushed to branch base-browser-128.6.0esr-14.5-1 at The Tor Project / Applications / Tor Browser Commits: 048dcb76 by Henry Wilkes at 2025-01-22T15:23:52+01:00 fixup! Add CI for Base Browser MB 324: Move update-translations from tor-browser to base-browser. - - - - - 1 changed file: - .gitlab-ci.yml Changes: ===================================== .gitlab-ci.yml ===================================== @@ -8,3 +8,4 @@ variables: include: - local: '.gitlab/ci/jobs/lint/lint.yml' + - local: '.gitlab/ci/jobs/update-translations.yml' View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/048dcb7… -- View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/048dcb7… You're receiving this email because of your account on gitlab.torproject.org.
1 0
0 0
[Git][tpo/applications/tor-browser][tor-browser-128.6.0esr-14.5-1] 2 commits: fixup! Add CI for Tor Browser
by Pier Angelo Vendrame (@pierov) 22 Jan '25

22 Jan '25
Pier Angelo Vendrame pushed to branch tor-browser-128.6.0esr-14.5-1 at The Tor Project / Applications / Tor Browser Commits: 7cffb14a by Henry Wilkes at 2025-01-22T13:59:46+00:00 fixup! Add CI for Tor Browser MB 324: Move update-translations from tor-browser to base-browser. Should be dropped at the next rebase. - - - - - dbca320b by Henry Wilkes at 2025-01-22T13:59:46+00:00 fixup! Add CI for Base Browser MB 324: Move update-translations from tor-browser to base-browser. - - - - - 0 changed files: Changes: View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/2dfd29… -- View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/2dfd29… You're receiving this email because of your account on gitlab.torproject.org.
1 0
0 0
[Git][tpo/applications/mullvad-browser][mullvad-browser-128.6.0esr-14.5-1] fixup! MB 1: Mullvad Browser branding
by morgan (@morgan) 22 Jan '25

22 Jan '25
morgan pushed to branch mullvad-browser-128.6.0esr-14.5-1 at The Tor Project / Applications / Mullvad Browser Commits: 9db51048 by Pier Angelo Vendrame at 2025-01-22T13:47:45+00:00 fixup! MB 1: Mullvad Browser branding TB 43323: Add an asset for sanity tests. - - - - - 2 changed files: - + toolkit/themes/shared/icons/mullvadbrowser.png - toolkit/themes/shared/minimal-toolkit.jar.inc.mn Changes: ===================================== toolkit/themes/shared/icons/mullvadbrowser.png ===================================== Binary files /dev/null and b/toolkit/themes/shared/icons/mullvadbrowser.png differ ===================================== toolkit/themes/shared/minimal-toolkit.jar.inc.mn ===================================== @@ -45,3 +45,6 @@ toolkit.jar: # Text recognition widget skin/classic/global/media/textrecognition.css (../../shared/media/textrecognition.css) + +# For testing purposes + skin/classic/global/icons/mullvadbrowser.png (../../shared/icons/mullvadbrowser.png) View it on GitLab: https://gitlab.torproject.org/tpo/applications/mullvad-browser/-/commit/9db… -- View it on GitLab: https://gitlab.torproject.org/tpo/applications/mullvad-browser/-/commit/9db… You're receiving this email because of your account on gitlab.torproject.org.
1 0
0 0
[Git][tpo/applications/tor-browser][tor-browser-128.6.0esr-14.5-1] fixup! TB 2176: Rebrand Firefox to TorBrowser
by morgan (@morgan) 22 Jan '25

22 Jan '25
morgan pushed to branch tor-browser-128.6.0esr-14.5-1 at The Tor Project / Applications / Tor Browser Commits: 2dfd2952 by Pier Angelo Vendrame at 2025-01-22T13:28:45+00:00 fixup! TB 2176: Rebrand Firefox to TorBrowser TB 43323: Add an asset for sanity tests. - - - - - 2 changed files: - + toolkit/themes/shared/icons/torbrowser.png - toolkit/themes/shared/minimal-toolkit.jar.inc.mn Changes: ===================================== toolkit/themes/shared/icons/torbrowser.png ===================================== Binary files /dev/null and b/toolkit/themes/shared/icons/torbrowser.png differ ===================================== toolkit/themes/shared/minimal-toolkit.jar.inc.mn ===================================== @@ -45,3 +45,6 @@ toolkit.jar: # Text recognition widget skin/classic/global/media/textrecognition.css (../../shared/media/textrecognition.css) + +# For testing purposes + skin/classic/global/icons/torbrowser.png (../../shared/icons/torbrowser.png) View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/2dfd295… -- View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/2dfd295… You're receiving this email because of your account on gitlab.torproject.org.
1 0
0 0
[Git][tpo/applications/mullvad-browser][mullvad-browser-128.6.0esr-14.5-1] 3 commits: fixup! Add CI for Base Browser
by Pier Angelo Vendrame (@pierov) 22 Jan '25

22 Jan '25
Pier Angelo Vendrame pushed to branch mullvad-browser-128.6.0esr-14.5-1 at The Tor Project / Applications / Mullvad Browser Commits: d7762a48 by Henry Wilkes at 2025-01-22T11:32:35+00:00 fixup! Add CI for Base Browser MB 324: Move update-translations CI to base-browser. - - - - - e30c4e62 by Henry Wilkes at 2025-01-22T11:32:36+00:00 BB 42305: Add script to combine translation files across versions. - - - - - 7edacb63 by Henry Wilkes at 2025-01-22T11:32:36+00:00 Add CI for Mullvad Browser - - - - - 11 changed files: - .gitlab-ci.yml - + .gitlab/ci/jobs/update-translations.yml - + tools/base-browser/l10n/combine-translation-versions.py - + tools/base-browser/l10n/combine/__init__.py - + tools/base-browser/l10n/combine/combine.py - + tools/base-browser/l10n/combine/tests/README - + tools/base-browser/l10n/combine/tests/__init__.py - + tools/base-browser/l10n/combine/tests/test_android.py - + tools/base-browser/l10n/combine/tests/test_dtd.py - + tools/base-browser/l10n/combine/tests/test_fluent.py - + tools/base-browser/l10n/combine/tests/test_properties.py Changes: ===================================== .gitlab-ci.yml ===================================== @@ -1,5 +1,6 @@ stages: - lint + - update-translations variables: IMAGE_PATH: containers.torproject.org/tpo/applications/tor-browser/base:latest ===================================== .gitlab/ci/jobs/update-translations.yml ===================================== @@ -0,0 +1,95 @@ +.update-translation-base: + stage: update-translations + rules: + - if: ($TRANSLATION_FILES != "" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE == "push") + changes: + - "**/*.ftl" + - "**/*.properties" + - "**/*.dtd" + - "**/*strings.xml" + - "**/update-translations.yml" + - "**/l10n/combine/combine.py" + - "**/l10n/combine-translation-versions.py" + - if: ($TRANSLATION_FILES != "" && $FORCE_UPDATE_TRANSLATIONS == "true") + variables: + COMBINED_FILES_JSON: "combined-translation-files.json" + TRANSLATION_FILES: '[ + { + "name": "brand.ftl", + "where": ["browser/branding/mb-release"], + "branch": "mullvad-browser", + "directory": "browser/branding/mb-release" + }, + { + "name": "brand.properties", + "where": ["browser/branding/mb-release"], + "branch": "mullvad-browser", + "directory": "browser/branding/mb-release" + }, + { + "name": "brand.ftl", + "where": ["browser/branding/mb-alpha"], + "branch": "mullvad-browser", + "directory": "browser/branding/mb-alpha" + }, + { + "name": "brand.properties", + "where": ["browser/branding/mb-alpha"], + "branch": "mullvad-browser", + "directory": "browser/branding/mb-alpha" + }, + { + "name": "brand.ftl", + "where": ["browser/branding/mb-nightly"], + "branch": "mullvad-browser", + "directory": "browser/branding/mb-nightly" + }, + { + "name": "brand.properties", + "where": ["browser/branding/mb-nightly"], + "branch": "mullvad-browser", + "directory": "browser/branding/mb-nightly" + }, + { + "name": "mullvad-browser.ftl", + "branch": "mullvad-browser", + "directory": "toolkit/toolkit/global" + }, + ]' + + +combine-en-US-translations: + extends: .update-translation-base + needs: [] + image: python + variables: + PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip" + cache: + paths: + - .cache/pip + # Artifact is for translation project job + artifacts: + paths: + - "$COMBINED_FILES_JSON" + expire_in: "60 min" + reports: + dotenv: job_id.env + # Don't load artifacts for this job. + dependencies: [] + script: + # Save this CI_JOB_ID to the dotenv file to be used in the variables for the + # push-en-US-translations job. + - echo 'COMBINE_TRANSLATIONS_JOB_ID='"$CI_JOB_ID" >job_id.env + - pip install compare_locales + - python ./tools/base-browser/l10n/combine-translation-versions.py "$CI_COMMIT_BRANCH" "$TRANSLATION_FILES" "$COMBINED_FILES_JSON" + +push-en-US-translations: + extends: .update-translation-base + needs: + - job: combine-en-US-translations + variables: + COMBINED_FILES_JSON_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/jobs/${COMBINE_TRANSLATIONS_JOB_ID}/artifacts/${COMBINED_FILES_JSON}" + trigger: + strategy: depend + project: tor-browser-translation-bot/translation + branch: tor-browser-ci ===================================== tools/base-browser/l10n/combine-translation-versions.py ===================================== @@ -0,0 +1,368 @@ +import argparse +import json +import logging +import os +import re +import subprocess + +from combine import combine_files + +arg_parser = argparse.ArgumentParser( + description="Combine a translation file across two different versions" +) + +arg_parser.add_argument( + "current_branch", metavar="<current-branch>", help="branch for the newest version" +) +arg_parser.add_argument( + "files", metavar="<files>", help="JSON specifying the translation files" +) +arg_parser.add_argument("outname", metavar="<json>", help="name of the json output") + +args = arg_parser.parse_args() + +logging.basicConfig() +logger = logging.getLogger("combine-translation-versions") +logger.setLevel(logging.INFO) + + +def in_pink(msg: str) -> str: + """Present a message as pink in the terminal output. + + :param msg: The message to wrap in pink. + :returns: The message to print to terminal. + """ + # Pink and bold. + return f"\x1b[1;38;5;212m{msg}\x1b[0m" + + +def git_run(git_args: list[str]) -> None: + """Run a git command. + + :param git_args: The arguments that should follow "git". + """ + # Add some text to give context to git's stderr appearing in log. + logger.info("Running: " + in_pink("git " + " ".join(git_args))) + subprocess.run(["git", *git_args], check=True) + + +def git_text(git_args: list[str]) -> str: + """Get the text output for a git command. + + :param git_args: The arguments that should follow "git". + :returns: The stdout of the command. + """ + logger.info("Running: " + in_pink("git " + " ".join(git_args))) + return subprocess.run( + ["git", *git_args], text=True, check=True, stdout=subprocess.PIPE + ).stdout + + +def git_lines(git_args: list[str]) -> list[str]: + """Get the lines from a git command. + + :param git_args: The arguments that should follow "git". + :returns: The non-empty lines from stdout of the command. + """ + return [line for line in git_text(git_args).split("\n") if line] + + +class TranslationFile: + """Represents a translation file.""" + + def __init__(self, path: str, content: str) -> None: + self.path = path + self.content = content + + +class BrowserBranch: + """Represents a browser git branch.""" + + def __init__(self, branch_name: str, is_head: bool = False) -> None: + """Create a new instance. + + :param branch_name: The branch's git name. + :param is_head: Whether the branch matches "HEAD". + """ + version_match = re.match( + r"(?P<prefix>[a-z]+\-browser)\-" + r"(?P<firefox>[0-9]+(?:\.[0-9]+){1,2})esr\-" + r"(?P<browser>[0-9]+\.[05])\-" + r"(?P<number>[0-9]+)$", + branch_name, + ) + + if not version_match: + raise ValueError(f"Unable to parse the version from the ref {branch_name}") + + self.name = branch_name + self.prefix = version_match.group("prefix") + self.browser_version = version_match.group("browser") + self._is_head = is_head + self._ref = "HEAD" if is_head else f"origin/{branch_name}" + + firefox_nums = [int(n) for n in version_match.group("firefox").split(".")] + if len(firefox_nums) == 2: + firefox_nums.append(0) + browser_nums = [int(n) for n in self.browser_version.split(".")] + branch_number = int(version_match.group("number")) + # Prioritise the firefox ESR version, then the browser version then the + # branch number. + self._ordered = ( + firefox_nums[0], + firefox_nums[1], + firefox_nums[2], + browser_nums[0], + browser_nums[1], + branch_number, + ) + + # Minor version for browser is only ever "0" or "5", so we can convert + # the version to an integer. + self._browser_int_version = int(2 * float(self.browser_version)) + + self._file_paths: list[str] | None = None + + def release_below(self, other: "BrowserBranch", num: int) -> bool: + """Determine whether another branch is within range of a previous + browser release. + + The browser versions are expected to increment by "0.5", and a previous + release branch's version is expected to be `num * 0.5` behind the + current one. + + :param other: The branch to compare. + :param num: The number of "0.5" releases behind to test with. + """ + return other._browser_int_version == self._browser_int_version - num + + def __lt__(self, other: "BrowserBranch") -> bool: + return self._ordered < other._ordered + + def __gt__(self, other: "BrowserBranch") -> bool: + return self._ordered > other._ordered + + def _matching_dirs(self, path: str, dir_list: list[str]) -> bool: + """Test that a path is contained in the list of dirs. + + :param path: The path to check. + :param dir_list: The list of directories to check against. + :returns: Whether the path matches. + """ + for dir_path in dir_list: + if os.path.commonpath([dir_path, path]) == dir_path: + return True + return False + + def get_file( + self, filename: str, search_dirs: list[str] | None + ) -> TranslationFile | None: + """Fetch the file content for the named file in this branch. + + :param filename: The name of the file to fetch the content for. + :param search_dirs: The directories to restrict the search to, or None + to search for the file anywhere. + :returns: The file, or `None` if no file could be found. + """ + if self._file_paths is None: + if not self._is_head: + # Minimal fetch of non-HEAD branch to get the file paths. + # Individual file blobs will be downloaded as needed. + git_run( + ["fetch", "--depth=1", "--filter=blob:none", "origin", self.name] + ) + self._file_paths = git_lines( + ["ls-tree", "-r", "--format=%(path)", self._ref] + ) + + matching = [ + path + for path in self._file_paths + if os.path.basename(path) == filename + and (search_dirs is None or self._matching_dirs(path, search_dirs)) + ] + if not matching: + return None + if len(matching) > 1: + raise Exception(f"Multiple occurrences of {filename}") + + path = matching[0] + + return TranslationFile( + path=path, content=git_text(["cat-file", "blob", f"{self._ref}:{path}"]) + ) + + +def get_stable_branch( + compare_version: BrowserBranch, +) -> tuple[BrowserBranch, BrowserBranch | None]: + """Find the most recent stable branch in the origin repository. + + :param compare_version: The development branch to compare against. + :returns: The stable and legacy branches. If no legacy branch is found, + `None` will be returned instead. + """ + # We search for build1 tags. These are added *after* the rebase of browser + # commits, so the corresponding branch should contain our strings. + # Moreover, we *assume* that the branch with the most recent ESR version + # with such a tag will be used in the *next* stable build in + # tor-browser-build. + tag_glob = f"{compare_version.prefix}-*-build1" + + # To speed up, only fetch the tags without blobs. + git_run( + ["fetch", "--depth=1", "--filter=object:type=tag", "origin", "tag", tag_glob] + ) + stable_branches = [] + legacy_branches = [] + stable_annotation_regex = re.compile(r"\bstable\b") + legacy_annotation_regex = re.compile(r"\blegacy\b") + tag_pattern = re.compile( + rf"^{re.escape(compare_version.prefix)}-[^-]+esr-[^-]+-[^-]+-build1$" + ) + + for build_tag, annotation in ( + line.split(" ", 1) for line in git_lines(["tag", "-n1", "--list", tag_glob]) + ): + if not tag_pattern.match(build_tag): + continue + is_stable = bool(stable_annotation_regex.search(annotation)) + is_legacy = bool(legacy_annotation_regex.search(annotation)) + if not is_stable and not is_legacy: + continue + try: + # Branch name is the same as the tag, minus "-build1". + branch = BrowserBranch(re.sub(r"-build1$", "", build_tag)) + except ValueError: + logger.warning(f"Could not read the version for {build_tag}") + continue + if branch.prefix != compare_version.prefix: + continue + if is_stable: + # Stable can be one release version behind. + # NOTE: In principle, when switching between versions there may be a + # window of time where the development branch has not yet progressed + # to the next "0.5" release, so has the same browser version as the + # stable branch. So we also allow for matching browser versions. + # NOTE: + # 1. The "Will be unused in" message will not make sense, but we do + # not expect string differences in this scenario. + # 2. We do not expect this scenario to last for long. + if not ( + compare_version.release_below(branch, 1) + or compare_version.release_below(branch, 0) + ): + continue + stable_branches.append(branch) + elif is_legacy: + # Legacy can be two release versions behind. + # We also allow for being just one version behind. + if not ( + compare_version.release_below(branch, 2) + or compare_version.release_below(branch, 1) + ): + continue + legacy_branches.append(branch) + + if not stable_branches: + raise Exception("No stable build1 branch found") + + return ( + # Return the stable branch with the highest version. + max(stable_branches), + max(legacy_branches) if legacy_branches else None, + ) + + +current_branch = BrowserBranch(args.current_branch, is_head=True) + +stable_branch, legacy_branch = get_stable_branch(current_branch) + +if os.environ.get("TRANSLATION_INCLUDE_LEGACY", "") != "true": + legacy_branch = None + +files_list = [] + +for file_dict in json.loads(args.files): + name = file_dict["name"] + where_dirs = file_dict.get("where", None) + current_file = current_branch.get_file(name, where_dirs) + stable_file = stable_branch.get_file(name, where_dirs) + + if current_file is None and stable_file is None: + # No file in either branch. + logger.warning(f"{name} does not exist in either the current or stable branch") + elif current_file is None: + logger.warning(f"{name} deleted in the current branch") + elif stable_file is None: + logger.warning(f"{name} does not exist in the stable branch") + elif current_file.path != stable_file.path: + logger.warning( + f"{name} has different paths in the current and stable branch. " + f"{current_file.path} : {stable_file.path}" + ) + + content = combine_files( + name, + None if current_file is None else current_file.content, + None if stable_file is None else stable_file.content, + f"Will be unused in Tor Browser {current_branch.browser_version}!", + ) + + if legacy_branch and not file_dict.get("exclude-legacy", False): + legacy_file = legacy_branch.get_file(name, where_dirs) + if legacy_file is not None and current_file is None and stable_file is None: + logger.warning(f"{name} still exists in the legacy branch") + elif legacy_file is None: + logger.warning(f"{name} does not exist in the legacy branch") + elif stable_file is not None and legacy_file.path != stable_file.path: + logger.warning( + f"{name} has different paths in the stable and legacy branch. " + f"{stable_file.path} : {legacy_file.path}" + ) + elif current_file is not None and legacy_file.path != current_file.path: + logger.warning( + f"{name} has different paths in the current and legacy branch. " + f"{current_file.path} : {legacy_file.path}" + ) + + content = combine_files( + name, + content, + legacy_file.content, + f"Unused in Tor Browser {stable_branch.browser_version}!", + ) + elif legacy_branch: + logger.info(f"Excluding legacy branch for {name}") + + files_list.append( + { + "name": name, + # If "directory" is unspecified, we place the file directly beneath + # en-US/ in the translation repository. i.e. "". + "directory": file_dict.get("directory", ""), + "branch": file_dict["branch"], + "content": content, + } + ) + + +ci_commit = os.environ.get("CI_COMMIT_SHA", "") +ci_url_base = os.environ.get("CI_PROJECT_URL", "") + +json_data = { + "commit": ci_commit, + "commit-url": f"{ci_url_base}/-/commit/{ci_commit}" + if (ci_commit and ci_url_base) + else "", + "project-path": os.environ.get("CI_PROJECT_PATH", ""), + "current-branch": current_branch.name, + "stable-branch": stable_branch.name, + "files": files_list, +} + +if legacy_branch: + json_data["legacy-branch"] = legacy_branch.name + +with open(args.outname, "w") as file: + json.dump(json_data, file) ===================================== tools/base-browser/l10n/combine/__init__.py ===================================== @@ -0,0 +1,3 @@ +# flake8: noqa + +from .combine import combine_files ===================================== tools/base-browser/l10n/combine/combine.py ===================================== @@ -0,0 +1,181 @@ +import re +from typing import TYPE_CHECKING, Any + +from compare_locales.parser import getParser +from compare_locales.parser.android import AndroidEntity, DocumentWrapper +from compare_locales.parser.base import Comment, Entity, Junk, Whitespace +from compare_locales.parser.dtd import DTDEntity +from compare_locales.parser.fluent import FluentComment, FluentEntity +from compare_locales.parser.properties import PropertiesEntity + +if TYPE_CHECKING: + from collections.abc import Iterable + + +def combine_files( + filename: str, + new_content: str | None, + old_content: str | None, + comment_prefix: str, +) -> str | None: + """Combine two translation files into one to include all strings from both. + The new content is presented first, and any strings only found in the old + content are placed at the end with an additional comment. + + :param filename: The filename for the file, determines the format. + :param new_content: The new content for the file, or None if it has been + deleted. + :param old_content: The old content for the file, or None if it did not + exist before. + :comment_prefix: A comment to include for any strings that are only found in + the old content. This will be placed before any other comments for the + string. + + :returns: The combined content, or None if both given contents are None. + """ + if new_content is None and old_content is None: + return None + + # getParser from compare_locale returns the same instance for the same file + # extension. + parser = getParser(filename) + + is_android = filename.endswith(".xml") + if new_content is None: + if is_android: + # File was deleted, add some document parts. + content_start = ( + '<?xml version="1.0" encoding="utf-8" standalone="yes"?>\n<resources>\n' + ) + content_end = "</resources>\n" + else: + # Treat as an empty file. + content_start = "" + content_end = "" + existing_keys = [] + else: + parser.readUnicode(new_content) + + # Start with the same content as the current file. + # For android strings, we want to keep the final "</resources>" until after. + if is_android: + closing_match = re.match( + r"^(.*)(</resources>\s*)$", parser.ctx.contents, re.DOTALL + ) + if not closing_match: + raise ValueError("Missing a final </resources>") + content_start = closing_match.group(1) + content_end = closing_match.group(2) + else: + content_start = parser.ctx.contents + content_end = "" + existing_keys = [entry.key for entry in parser.walk(only_localizable=True)] + + # For Fluent, we want to prefix the strings using GroupComments. + # On weblate this will cause all the strings that fall under the GroupComment's + # scope to have the prefix added to their "notes". + # We set up an initial GroupComment for the first string we find. This will also + # end the scope of the last GroupComment in the new translation file. + # This will be replaced with a the next GroupComment when it is found. + fluent_group_comment_prefix = f"\n## {comment_prefix}\n" + fluent_group_comment: str | None = fluent_group_comment_prefix + + # For other formats, we want to keep all the comment lines that come directly + # before the string. + # In compare_locales.parser, only the comment line directly before an Entity + # counts as the pre_comment for that Entity. I.e. only this line will be + # included in Entity.all + # However, in weblate every comment line that comes before the Entity is + # included as a comment. So we also want to keep these additional comments to + # preserve them for weblate. + # We gather these extra comments in stacked_comments, and clear them whenever we + # reach an Entity or a blank line (Whitespace is more than "\n"). + stacked_comments: list[str] = [] + + additions: list[str] = [] + + entry_iter: Iterable[Any] = () + # If the file does not exist in the old branch, don't make any additions. + if old_content is not None: + parser.readUnicode(old_content) + entry_iter = parser.walk(only_localizable=False) + for entry in entry_iter: + if isinstance(entry, Junk): + raise ValueError(f"Unexpected Junk: {entry.all}") + if isinstance(entry, Whitespace): + # Clear stacked comments if more than one empty line. + if entry.all != "\n": + stacked_comments.clear() + continue + if isinstance(entry, Comment): + if isinstance(entry, FluentComment): + # Don't stack Fluent comments. + # Only the comments included in Entity.pre_comment count towards + # that Entity's comment. + if entry.all.startswith("##"): + # A Fluent GroupComment + if entry.all == "##": + # Empty GroupComment. Used to end the scope of a previous + # GroupComment. + # Replace this with our prefix comment. + fluent_group_comment = fluent_group_comment_prefix + else: + # Prefix the group comment. + fluent_group_comment = ( + f"{fluent_group_comment_prefix}{entry.all}\n" + ) + else: + stacked_comments.append(entry.all) + continue + if isinstance(entry, DocumentWrapper): + # Not needed. + continue + + if not isinstance(entry, Entity): + raise ValueError(f"Unexpected type: {entry.__class__.__name__}") + + if entry.key in existing_keys: + # Already included this string in the new translation file. + # Drop the gathered comments for this Entity. + stacked_comments.clear() + continue + + if isinstance(entry, FluentEntity): + if fluent_group_comment is not None: + # We have a found GroupComment which has not been included yet. + # All following Entity's will be under its scope, until the next + # GroupComment. + additions.append(fluent_group_comment) + # Added GroupComment, so don't need to add again. + fluent_group_comment = None + elif isinstance(entry, DTDEntity): + # Include our additional comment before we print the rest for this + # Entity. + additions.append(f"<!-- LOCALIZATION NOTE: {comment_prefix} -->") + elif isinstance(entry, PropertiesEntity): + additions.append(f"# {comment_prefix}") + elif isinstance(entry, AndroidEntity): + additions.append(f"<!-- {comment_prefix} -->") + else: + raise ValueError(f"Unexpected Entity type: {entry.__class__.__name__}") + + # Add any other comment lines that came directly before this Entity. + additions.extend(stacked_comments) + stacked_comments.clear() + additions.append(entry.all) + + content_middle = "" + + if additions: + # New line before and after the additions + additions.insert(0, "") + additions.append("") + if is_android: + content_middle = "\n ".join(additions) + else: + content_middle = "\n".join(additions) + + # Remove " " in otherwise blank lines. + content_middle = re.sub("^ +$", "", content_middle, flags=re.MULTILINE) + + return content_start + content_middle + content_end ===================================== tools/base-browser/l10n/combine/tests/README ===================================== @@ -0,0 +1,2 @@ +python tests to be run with pytest. +Requires the compare-locales package. ===================================== tools/base-browser/l10n/combine/tests/__init__.py ===================================== ===================================== tools/base-browser/l10n/combine/tests/test_android.py ===================================== @@ -0,0 +1,330 @@ +import textwrap + +from combine import combine_files + + +def wrap_in_xml(content): + if content is None: + return None + # Allow for indents to make the tests more readable. + content = textwrap.dedent(content) + return f"""\ +<?xml version="1.0" encoding="utf-8" standalone="yes"?> +<resources> +{textwrap.indent(content, " ")}</resources> +""" + + +def assert_result(new_content, old_content, expect): + new_content = wrap_in_xml(new_content) + old_content = wrap_in_xml(old_content) + expect = wrap_in_xml(expect) + assert expect == combine_files( + "test_strings.xml", new_content, old_content, "REMOVED STRING" + ) + + +def test_combine_empty(): + assert_result(None, None, None) + + +def test_combine_new_file(): + # New file with no old content. + assert_result( + """\ + <string name="string_1">First</string> + <string name="string_2">Second</string> + """, + None, + """\ + <string name="string_1">First</string> + <string name="string_2">Second</string> + """, + ) + + +def test_combine_removed_file(): + # Entire file was removed. + assert_result( + None, + """\ + <string name="string_1">First</string> + <string name="string_2">Second</string> + """, + """\ + + <!-- REMOVED STRING --> + <string name="string_1">First</string> + <!-- REMOVED STRING --> + <string name="string_2">Second</string> + """, + ) + + +def test_no_change(): + content = """\ + <string name="string_1">First</string> + <string name="string_2">Second</string> + """ + assert_result(content, content, content) + + +def test_added_string(): + assert_result( + """\ + <string name="string_1">First</string> + <string name="string_new">NEW</string> + <string name="string_2">Second</string> + """, + """\ + <string name="string_1">First</string> + <string name="string_2">Second</string> + """, + """\ + <string name="string_1">First</string> + <string name="string_new">NEW</string> + <string name="string_2">Second</string> + """, + ) + + +def test_removed_string(): + assert_result( + """\ + <string name="string_1">First</string> + <string name="string_2">Second</string> + """, + """\ + <string name="string_1">First</string> + <string name="removed">REMOVED</string> + <string name="string_2">Second</string> + """, + """\ + <string name="string_1">First</string> + <string name="string_2">Second</string> + + <!-- REMOVED STRING --> + <string name="removed">REMOVED</string> + """, + ) + + +def test_removed_and_added(): + assert_result( + """\ + <string name="new_1">New string</string> + <string name="string_1">First</string> + <string name="string_2">Second</string> + <string name="new_2">New string 2</string> + """, + """\ + <string name="string_1">First</string> + <string name="removed_1">First removed</string> + <string name="removed_2">Second removed</string> + <string name="string_2">Second</string> + <string name="removed_3">Third removed</string> + """, + """\ + <string name="new_1">New string</string> + <string name="string_1">First</string> + <string name="string_2">Second</string> + <string name="new_2">New string 2</string> + + <!-- REMOVED STRING --> + <string name="removed_1">First removed</string> + <!-- REMOVED STRING --> + <string name="removed_2">Second removed</string> + <!-- REMOVED STRING --> + <string name="removed_3">Third removed</string> + """, + ) + + +def test_updated(): + # String content was updated. + assert_result( + """\ + <string name="changed_string">NEW</string> + """, + """\ + <string name="changed_string">OLD</string> + """, + """\ + <string name="changed_string">NEW</string> + """, + ) + + +def test_updated_comment(): + # String comment was updated. + assert_result( + """\ + <!-- NEW --> + <string name="changed_string">string</string> + """, + """\ + <!-- OLD --> + <string name="changed_string">string</string> + """, + """\ + <!-- NEW --> + <string name="changed_string">string</string> + """, + ) + # Comment added. + assert_result( + """\ + <!-- NEW --> + <string name="changed_string">string</string> + """, + """\ + <string name="changed_string">string</string> + """, + """\ + <!-- NEW --> + <string name="changed_string">string</string> + """, + ) + # Comment removed. + assert_result( + """\ + <string name="changed_string">string</string> + """, + """\ + <!-- OLD --> + <string name="changed_string">string</string> + """, + """\ + <string name="changed_string">string</string> + """, + ) + + # With file comments + assert_result( + """\ + <!-- NEW file comment --> + + <!-- NEW --> + <string name="changed_string">string</string> + """, + """\ + <!-- OLD file comment --> + + <!-- OLD --> + <string name="changed_string">string</string> + """, + """\ + <!-- NEW file comment --> + + <!-- NEW --> + <string name="changed_string">string</string> + """, + ) + + +def test_reordered(): + # String was re_ordered. + assert_result( + """\ + <string name="string_1">value</string> + <string name="moved_string">move</string> + """, + """\ + <string name="moved_string">move</string> + <string name="string_1">value</string> + """, + """\ + <string name="string_1">value</string> + <string name="moved_string">move</string> + """, + ) + + +def test_removed_string_with_comment(): + assert_result( + """\ + <!-- Comment for first. --> + <string name="string_1">First</string> + <string name="string_2">Second</string> + """, + """\ + <!-- Comment for first. --> + <string name="string_1">First</string> + <!-- Comment for removed. --> + <string name="removed">REMOVED</string> + <string name="string_2">Second</string> + """, + """\ + <!-- Comment for first. --> + <string name="string_1">First</string> + <string name="string_2">Second</string> + + <!-- REMOVED STRING --> + <!-- Comment for removed. --> + <string name="removed">REMOVED</string> + """, + ) + + # With file comments and multi-line. + # All comments prior to a removed string are moved with it, until another + # entity or blank line is reached. + assert_result( + """\ + <!-- First File comment --> + + <!-- Comment for first. --> + <!-- Comment 2 for first. --> + <string name="string_1">First</string> + + <!-- Second --> + <!-- File comment --> + + <string name="string_2">Second</string> + """, + """\ + <!-- First File comment --> + + <!-- Comment for first. --> + <!-- Comment 2 for first. --> + <string name="string_1">First</string> + <string name="removed_1">First removed</string> + <!-- Comment for second removed. --> + <string name="removed_2">Second removed</string> + + <!-- Removed file comment --> + + <!-- Comment 1 for third removed --> + <!-- Comment 2 for third removed --> + <string name="removed_3">Third removed</string> + + <!-- Second --> + <!-- File comment --> + + <string name="removed_4">Fourth removed</string> + <string name="string_2">Second</string> + """, + """\ + <!-- First File comment --> + + <!-- Comment for first. --> + <!-- Comment 2 for first. --> + <string name="string_1">First</string> + + <!-- Second --> + <!-- File comment --> + + <string name="string_2">Second</string> + + <!-- REMOVED STRING --> + <string name="removed_1">First removed</string> + <!-- REMOVED STRING --> + <!-- Comment for second removed. --> + <string name="removed_2">Second removed</string> + <!-- REMOVED STRING --> + <!-- Comment 1 for third removed --> + <!-- Comment 2 for third removed --> + <string name="removed_3">Third removed</string> + <!-- REMOVED STRING --> + <string name="removed_4">Fourth removed</string> + """, + ) ===================================== tools/base-browser/l10n/combine/tests/test_dtd.py ===================================== @@ -0,0 +1,325 @@ +import textwrap + +from combine import combine_files + + +def assert_result(new_content, old_content, expect): + # Allow for indents to make the tests more readable. + if new_content is not None: + new_content = textwrap.dedent(new_content) + if old_content is not None: + old_content = textwrap.dedent(old_content) + if expect is not None: + expect = textwrap.dedent(expect) + assert expect == combine_files( + "test.dtd", new_content, old_content, "REMOVED STRING" + ) + + +def test_combine_empty(): + assert_result(None, None, None) + + +def test_combine_new_file(): + # New file with no old content. + assert_result( + """\ + <!ENTITY string.1 "First"> + <!ENTITY string.2 "Second"> + """, + None, + """\ + <!ENTITY string.1 "First"> + <!ENTITY string.2 "Second"> + """, + ) + + +def test_combine_removed_file(): + # Entire file was removed. + assert_result( + None, + """\ + <!ENTITY string.1 "First"> + <!ENTITY string.2 "Second"> + """, + """\ + + <!-- LOCALIZATION NOTE: REMOVED STRING --> + <!ENTITY string.1 "First"> + <!-- LOCALIZATION NOTE: REMOVED STRING --> + <!ENTITY string.2 "Second"> + """, + ) + + +def test_no_change(): + content = """\ + <!ENTITY string.1 "First"> + <!ENTITY string.2 "Second"> + """ + assert_result(content, content, content) + + +def test_added_string(): + assert_result( + """\ + <!ENTITY string.1 "First"> + <!ENTITY string.new "NEW"> + <!ENTITY string.2 "Second"> + """, + """\ + <!ENTITY string.1 "First"> + <!ENTITY string.2 "Second"> + """, + """\ + <!ENTITY string.1 "First"> + <!ENTITY string.new "NEW"> + <!ENTITY string.2 "Second"> + """, + ) + + +def test_removed_string(): + assert_result( + """\ + <!ENTITY string.1 "First"> + <!ENTITY string.2 "Second"> + """, + """\ + <!ENTITY string.1 "First"> + <!ENTITY removed "REMOVED"> + <!ENTITY string.2 "Second"> + """, + """\ + <!ENTITY string.1 "First"> + <!ENTITY string.2 "Second"> + + <!-- LOCALIZATION NOTE: REMOVED STRING --> + <!ENTITY removed "REMOVED"> + """, + ) + + +def test_removed_and_added(): + assert_result( + """\ + <!ENTITY new.1 "New string"> + <!ENTITY string.1 "First"> + <!ENTITY string.2 "Second"> + <!ENTITY new.2 "New string 2"> + """, + """\ + <!ENTITY string.1 "First"> + <!ENTITY removed.1 "First removed"> + <!ENTITY removed.2 "Second removed"> + <!ENTITY string.2 "Second"> + <!ENTITY removed.3 "Third removed"> + """, + """\ + <!ENTITY new.1 "New string"> + <!ENTITY string.1 "First"> + <!ENTITY string.2 "Second"> + <!ENTITY new.2 "New string 2"> + + <!-- LOCALIZATION NOTE: REMOVED STRING --> + <!ENTITY removed.1 "First removed"> + <!-- LOCALIZATION NOTE: REMOVED STRING --> + <!ENTITY removed.2 "Second removed"> + <!-- LOCALIZATION NOTE: REMOVED STRING --> + <!ENTITY removed.3 "Third removed"> + """, + ) + + +def test_updated(): + # String content was updated. + assert_result( + """\ + <!ENTITY changed.string "NEW"> + """, + """\ + <!ENTITY changed.string "OLD"> + """, + """\ + <!ENTITY changed.string "NEW"> + """, + ) + + +def test_updated_comment(): + # String comment was updated. + assert_result( + """\ + <!-- LOCALIZATION NOTE: NEW --> + <!ENTITY changed.string "string"> + """, + """\ + <!-- LOCALIZATION NOTE: OLD --> + <!ENTITY changed.string "string"> + """, + """\ + <!-- LOCALIZATION NOTE: NEW --> + <!ENTITY changed.string "string"> + """, + ) + # Comment added. + assert_result( + """\ + <!-- LOCALIZATION NOTE: NEW --> + <!ENTITY changed.string "string"> + """, + """\ + <!ENTITY changed.string "string"> + """, + """\ + <!-- LOCALIZATION NOTE: NEW --> + <!ENTITY changed.string "string"> + """, + ) + # Comment removed. + assert_result( + """\ + <!ENTITY changed.string "string"> + """, + """\ + <!-- LOCALIZATION NOTE: OLD --> + <!ENTITY changed.string "string"> + """, + """\ + <!ENTITY changed.string "string"> + """, + ) + + # With multiple comments + assert_result( + """\ + <!-- NEW FILE COMMENT --> + + <!-- LOCALIZATION NOTE: NEW --> + <!ENTITY changed.string "string"> + """, + """\ + <!-- OLD --> + + <!-- LOCALIZATION NOTE: OLD --> + <!ENTITY changed.string "string"> + """, + """\ + <!-- NEW FILE COMMENT --> + + <!-- LOCALIZATION NOTE: NEW --> + <!ENTITY changed.string "string"> + """, + ) + + +def test_reordered(): + # String was re.ordered. + assert_result( + """\ + <!ENTITY string.1 "value"> + <!ENTITY moved.string "move"> + """, + """\ + <!ENTITY moved.string "move"> + <!ENTITY string.1 "value"> + """, + """\ + <!ENTITY string.1 "value"> + <!ENTITY moved.string "move"> + """, + ) + + +def test_removed_string_with_comment(): + assert_result( + """\ + <!-- LOCALIZATION NOTE: Comment for first. --> + <!ENTITY string.1 "First"> + <!ENTITY string.2 "Second"> + """, + """\ + <!-- LOCALIZATION NOTE: Comment for first. --> + <!ENTITY string.1 "First"> + <!-- LOCALIZATION NOTE: Comment for removed. --> + <!ENTITY removed "REMOVED"> + <!ENTITY string.2 "Second"> + """, + """\ + <!-- LOCALIZATION NOTE: Comment for first. --> + <!ENTITY string.1 "First"> + <!ENTITY string.2 "Second"> + + <!-- LOCALIZATION NOTE: REMOVED STRING --> + <!-- LOCALIZATION NOTE: Comment for removed. --> + <!ENTITY removed "REMOVED"> + """, + ) + + # With multiple lines of comments. + + assert_result( + """\ + <!-- First file comment --> + + <!-- LOCALIZATION NOTE: Comment for first. --> + <!-- LOCALIZATION NOTE: Comment 2 for first. --> + <!ENTITY string.1 "First"> + + <!-- Second + - file + - comment --> + + <!ENTITY string.2 "Second"> + """, + """\ + <!-- First file comment --> + + <!-- LOCALIZATION NOTE: Comment for first. --> + <!ENTITY string.1 "First"> + <!ENTITY removed.1 "First removed"> + <!-- LOCALIZATION NOTE: Comment for second removed. --> + <!ENTITY removed.2 "Second removed"> + + <!-- Removed file comment --> + + <!-- LOCALIZATION NOTE: Comment for third removed. --> + <!-- LOCALIZATION NOTE: Comment 2 for + third removed. --> + <!ENTITY removed.3 "Third removed"> + + <!-- Second + - file + - comment --> + + <!ENTITY removed.4 "Fourth removed"> + <!ENTITY string.2 "Second"> + """, + """\ + <!-- First file comment --> + + <!-- LOCALIZATION NOTE: Comment for first. --> + <!-- LOCALIZATION NOTE: Comment 2 for first. --> + <!ENTITY string.1 "First"> + + <!-- Second + - file + - comment --> + + <!ENTITY string.2 "Second"> + + <!-- LOCALIZATION NOTE: REMOVED STRING --> + <!ENTITY removed.1 "First removed"> + <!-- LOCALIZATION NOTE: REMOVED STRING --> + <!-- LOCALIZATION NOTE: Comment for second removed. --> + <!ENTITY removed.2 "Second removed"> + <!-- LOCALIZATION NOTE: REMOVED STRING --> + <!-- LOCALIZATION NOTE: Comment for third removed. --> + <!-- LOCALIZATION NOTE: Comment 2 for + third removed. --> + <!ENTITY removed.3 "Third removed"> + <!-- LOCALIZATION NOTE: REMOVED STRING --> + <!ENTITY removed.4 "Fourth removed"> + """, + ) ===================================== tools/base-browser/l10n/combine/tests/test_fluent.py ===================================== @@ -0,0 +1,344 @@ +import textwrap + +from combine import combine_files + + +def assert_result(new_content, old_content, expect): + # Allow for indents to make the tests more readable. + if new_content is not None: + new_content = textwrap.dedent(new_content) + if old_content is not None: + old_content = textwrap.dedent(old_content) + if expect is not None: + expect = textwrap.dedent(expect) + assert expect == combine_files( + "test.ftl", new_content, old_content, "REMOVED STRING" + ) + + +def test_combine_empty(): + assert_result(None, None, None) + + +def test_combine_new_file(): + # New file with no old content. + assert_result( + """\ + string-1 = First + string-2 = Second + """, + None, + """\ + string-1 = First + string-2 = Second + """, + ) + + +def test_combine_removed_file(): + # Entire file was removed. + assert_result( + None, + """\ + string-1 = First + string-2 = Second + """, + """\ + + + ## REMOVED STRING + + string-1 = First + string-2 = Second + """, + ) + + +def test_no_change(): + content = """\ + string-1 = First + string-2 = Second + """ + assert_result(content, content, content) + + +def test_added_string(): + assert_result( + """\ + string-1 = First + string-new = NEW + string-2 = Second + """, + """\ + string-1 = First + string-2 = Second + """, + """\ + string-1 = First + string-new = NEW + string-2 = Second + """, + ) + + +def test_removed_string(): + assert_result( + """\ + string-1 = First + string-2 = Second + """, + """\ + string-1 = First + removed = REMOVED + string-2 = Second + """, + """\ + string-1 = First + string-2 = Second + + + ## REMOVED STRING + + removed = REMOVED + """, + ) + + +def test_removed_and_added(): + assert_result( + """\ + new-1 = New string + string-1 = + .attr = First + string-2 = Second + new-2 = + .title = New string 2 + """, + """\ + string-1 = + .attr = First + removed-1 = First removed + removed-2 = + .attr = Second removed + string-2 = Second + removed-3 = Third removed + """, + """\ + new-1 = New string + string-1 = + .attr = First + string-2 = Second + new-2 = + .title = New string 2 + + + ## REMOVED STRING + + removed-1 = First removed + removed-2 = + .attr = Second removed + removed-3 = Third removed + """, + ) + + +def test_updated(): + # String content was updated. + assert_result( + """\ + changed-string = NEW + """, + """\ + changed-string = OLD + """, + """\ + changed-string = NEW + """, + ) + + +def test_updated_comment(): + # String comment was updated. + assert_result( + """\ + # NEW + changed-string = string + """, + """\ + # OLD + changed-string = string + """, + """\ + # NEW + changed-string = string + """, + ) + # Comment added. + assert_result( + """\ + # NEW + changed-string = string + """, + """\ + changed-string = string + """, + """\ + # NEW + changed-string = string + """, + ) + # Comment removed. + assert_result( + """\ + changed-string = string + """, + """\ + # OLD + changed-string = string + """, + """\ + changed-string = string + """, + ) + + # With group comments. + assert_result( + """\ + ## GROUP NEW + + # NEW + changed-string = string + """, + """\ + ## GROUP OLD + + # OLD + changed-string = string + """, + """\ + ## GROUP NEW + + # NEW + changed-string = string + """, + ) + + +def test_reordered(): + # String was re-ordered. + assert_result( + """\ + string-1 = value + moved-string = move + """, + """\ + moved-string = move + string-1 = value + """, + """\ + string-1 = value + moved-string = move + """, + ) + + +def test_removed_string_with_comment(): + assert_result( + """\ + # Comment for first. + string-1 = First + string-2 = Second + """, + """\ + # Comment for first. + string-1 = First + # Comment for removed. + removed = REMOVED + string-2 = Second + """, + """\ + # Comment for first. + string-1 = First + string-2 = Second + + + ## REMOVED STRING + + # Comment for removed. + removed = REMOVED + """, + ) + + # Group comments are combined with the "REMOVED STRING" comments. + # If strings have no group comment, then a single "REMOVED STRING" is + # included for them. + assert_result( + """\ + ## First Group comment + + # Comment for first. + string-1 = First + + ## + + no-group = No group comment + + ## Second + ## Group comment + + string-2 = Second + """, + """\ + ## First Group comment + + # Comment for first. + string-1 = First + removed-1 = First removed + # Comment for second removed. + removed-2 = Second removed + + ## + + no-group = No group comment + removed-3 = Third removed + + ## Second + ## Group comment + + removed-4 = Fourth removed + string-2 = Second + """, + """\ + ## First Group comment + + # Comment for first. + string-1 = First + + ## + + no-group = No group comment + + ## Second + ## Group comment + + string-2 = Second + + + ## REMOVED STRING + ## First Group comment + + removed-1 = First removed + # Comment for second removed. + removed-2 = Second removed + + ## REMOVED STRING + + removed-3 = Third removed + + ## REMOVED STRING + ## Second + ## Group comment + + removed-4 = Fourth removed + """, + ) ===================================== tools/base-browser/l10n/combine/tests/test_properties.py ===================================== @@ -0,0 +1,322 @@ +import textwrap + +from combine import combine_files + + +def assert_result(new_content, old_content, expect): + # Allow for indents to make the tests more readable. + if new_content is not None: + new_content = textwrap.dedent(new_content) + if old_content is not None: + old_content = textwrap.dedent(old_content) + if expect is not None: + expect = textwrap.dedent(expect) + assert expect == combine_files( + "test.properties", new_content, old_content, "REMOVED STRING" + ) + + +def test_combine_empty(): + assert_result(None, None, None) + + +def test_combine_new_file(): + # New file with no old content. + assert_result( + """\ + string.1 = First + string.2 = Second + """, + None, + """\ + string.1 = First + string.2 = Second + """, + ) + + +def test_combine_removed_file(): + # Entire file was removed. + assert_result( + None, + """\ + string.1 = First + string.2 = Second + """, + """\ + + # REMOVED STRING + string.1 = First + # REMOVED STRING + string.2 = Second + """, + ) + + +def test_no_change(): + content = """\ + string.1 = First + string.2 = Second + """ + assert_result(content, content, content) + + +def test_added_string(): + assert_result( + """\ + string.1 = First + string.new = NEW + string.2 = Second + """, + """\ + string.1 = First + string.2 = Second + """, + """\ + string.1 = First + string.new = NEW + string.2 = Second + """, + ) + + +def test_removed_string(): + assert_result( + """\ + string.1 = First + string.2 = Second + """, + """\ + string.1 = First + removed = REMOVED + string.2 = Second + """, + """\ + string.1 = First + string.2 = Second + + # REMOVED STRING + removed = REMOVED + """, + ) + + +def test_removed_and_added(): + assert_result( + """\ + new.1 = New string + string.1 = First + string.2 = Second + new.2 = New string 2 + """, + """\ + string.1 = First + removed.1 = First removed + removed.2 = Second removed + string.2 = Second + removed.3 = Third removed + """, + """\ + new.1 = New string + string.1 = First + string.2 = Second + new.2 = New string 2 + + # REMOVED STRING + removed.1 = First removed + # REMOVED STRING + removed.2 = Second removed + # REMOVED STRING + removed.3 = Third removed + """, + ) + + +def test_updated(): + # String content was updated. + assert_result( + """\ + changed.string = NEW + """, + """\ + changed.string = OLD + """, + """\ + changed.string = NEW + """, + ) + + +def test_updated_comment(): + # String comment was updated. + assert_result( + """\ + # NEW + changed.string = string + """, + """\ + # OLD + changed.string = string + """, + """\ + # NEW + changed.string = string + """, + ) + # Comment added. + assert_result( + """\ + # NEW + changed.string = string + """, + """\ + changed.string = string + """, + """\ + # NEW + changed.string = string + """, + ) + # Comment removed. + assert_result( + """\ + changed.string = string + """, + """\ + # OLD + changed.string = string + """, + """\ + changed.string = string + """, + ) + + # With file comments + assert_result( + """\ + # NEW file comment + + # NEW + changed.string = string + """, + """\ + # OLD file comment + + # OLD + changed.string = string + """, + """\ + # NEW file comment + + # NEW + changed.string = string + """, + ) + + +def test_reordered(): + # String was re.ordered. + assert_result( + """\ + string.1 = value + moved.string = move + """, + """\ + moved.string = move + string.1 = value + """, + """\ + string.1 = value + moved.string = move + """, + ) + + +def test_removed_string_with_comment(): + assert_result( + """\ + # Comment for first. + string.1 = First + string.2 = Second + """, + """\ + # Comment for first. + string.1 = First + # Comment for removed. + removed = REMOVED + string.2 = Second + """, + """\ + # Comment for first. + string.1 = First + string.2 = Second + + # REMOVED STRING + # Comment for removed. + removed = REMOVED + """, + ) + + # With file comments and multi-line. + # All comments prior to a removed string are moved with it, until another + # entity or blank line is reached. + assert_result( + """\ + # First File comment + + # Comment for first. + # Comment 2 for first. + string.1 = First + + # Second + # File comment + + string.2 = Second + """, + """\ + # First File comment + + # Comment for first. + # Comment 2 for first. + string.1 = First + removed.1 = First removed + # Comment for second removed. + removed.2 = Second removed + + # Removed file comment + + # Comment 1 for third removed + # Comment 2 for third removed + removed.3 = Third removed + + # Second + # File comment + + removed.4 = Fourth removed + string.2 = Second + """, + """\ + # First File comment + + # Comment for first. + # Comment 2 for first. + string.1 = First + + # Second + # File comment + + string.2 = Second + + # REMOVED STRING + removed.1 = First removed + # REMOVED STRING + # Comment for second removed. + removed.2 = Second removed + # REMOVED STRING + # Comment 1 for third removed + # Comment 2 for third removed + removed.3 = Third removed + # REMOVED STRING + removed.4 = Fourth removed + """, + ) View it on GitLab: https://gitlab.torproject.org/tpo/applications/mullvad-browser/-/compare/76… -- View it on GitLab: https://gitlab.torproject.org/tpo/applications/mullvad-browser/-/compare/76… You're receiving this email because of your account on gitlab.torproject.org.
1 0
0 0
[Git][tpo/applications/tor-browser][tor-browser-128.6.0esr-14.5-1] fixup! TB 42247: Android helpers for the TorProvider
by Pier Angelo Vendrame (@pierov) 22 Jan '25

22 Jan '25
Pier Angelo Vendrame pushed to branch tor-browser-128.6.0esr-14.5-1 at The Tor Project / Applications / Tor Browser Commits: 1323ab5f by Pier Angelo Vendrame at 2025-01-22T12:11:01+01:00 fixup! TB 42247: Android helpers for the TorProvider Add a missing return to #getAllSettings(). - - - - - 1 changed file: - toolkit/modules/TorAndroidIntegration.sys.mjs Changes: ===================================== toolkit/modules/TorAndroidIntegration.sys.mjs ===================================== @@ -97,6 +97,7 @@ class TorAndroidIntegrationImpl { #getAllSettings() { const settings = lazy.TorSettings.getSettings(); settings.quickstart = { enabled: lazy.TorConnect.quickstart }; + return settings; } observe(subj, topic) { View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/1323ab5… -- View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/1323ab5… You're receiving this email because of your account on gitlab.torproject.org.
1 0
0 0
[Git][tpo/applications/tor-browser][base-browser-128.6.0esr-14.5-1] 2 commits: fixup! Add CI for Base Browser
by Pier Angelo Vendrame (@pierov) 22 Jan '25

22 Jan '25
Pier Angelo Vendrame pushed to branch base-browser-128.6.0esr-14.5-1 at The Tor Project / Applications / Tor Browser Commits: 5f316b25 by Henry Wilkes at 2025-01-22T12:13:24+01:00 fixup! Add CI for Base Browser MB 324: Move update-translations CI to base-browser. - - - - - 9fc48603 by Henry Wilkes at 2025-01-22T12:13:34+01:00 BB 42305: Add script to combine translation files across versions. - - - - - 11 changed files: - .gitlab-ci.yml - + .gitlab/ci/jobs/update-translations.yml - + tools/base-browser/l10n/combine-translation-versions.py - + tools/base-browser/l10n/combine/__init__.py - + tools/base-browser/l10n/combine/combine.py - + tools/base-browser/l10n/combine/tests/README - + tools/base-browser/l10n/combine/tests/__init__.py - + tools/base-browser/l10n/combine/tests/test_android.py - + tools/base-browser/l10n/combine/tests/test_dtd.py - + tools/base-browser/l10n/combine/tests/test_fluent.py - + tools/base-browser/l10n/combine/tests/test_properties.py Changes: ===================================== .gitlab-ci.yml ===================================== @@ -1,5 +1,6 @@ stages: - lint + - update-translations variables: IMAGE_PATH: containers.torproject.org/tpo/applications/tor-browser/base:latest ===================================== .gitlab/ci/jobs/update-translations.yml ===================================== @@ -0,0 +1,53 @@ +.update-translation-base: + stage: update-translations + rules: + - if: ($TRANSLATION_FILES != "" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE == "push") + changes: + - "**/*.ftl" + - "**/*.properties" + - "**/*.dtd" + - "**/*strings.xml" + - "**/update-translations.yml" + - "**/l10n/combine/combine.py" + - "**/l10n/combine-translation-versions.py" + - if: ($TRANSLATION_FILES != "" && $FORCE_UPDATE_TRANSLATIONS == "true") + variables: + COMBINED_FILES_JSON: "combined-translation-files.json" + TRANSLATION_FILES: '' + + +combine-en-US-translations: + extends: .update-translation-base + needs: [] + image: python + variables: + PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip" + cache: + paths: + - .cache/pip + # Artifact is for translation project job + artifacts: + paths: + - "$COMBINED_FILES_JSON" + expire_in: "60 min" + reports: + dotenv: job_id.env + # Don't load artifacts for this job. + dependencies: [] + script: + # Save this CI_JOB_ID to the dotenv file to be used in the variables for the + # push-en-US-translations job. + - echo 'COMBINE_TRANSLATIONS_JOB_ID='"$CI_JOB_ID" >job_id.env + - pip install compare_locales + - python ./tools/base-browser/l10n/combine-translation-versions.py "$CI_COMMIT_BRANCH" "$TRANSLATION_FILES" "$COMBINED_FILES_JSON" + +push-en-US-translations: + extends: .update-translation-base + needs: + - job: combine-en-US-translations + variables: + COMBINED_FILES_JSON_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/jobs/${COMBINE_TRANSLATIONS_JOB_ID}/artifacts/${COMBINED_FILES_JSON}" + trigger: + strategy: depend + project: tor-browser-translation-bot/translation + branch: tor-browser-ci ===================================== tools/base-browser/l10n/combine-translation-versions.py ===================================== @@ -0,0 +1,368 @@ +import argparse +import json +import logging +import os +import re +import subprocess + +from combine import combine_files + +arg_parser = argparse.ArgumentParser( + description="Combine a translation file across two different versions" +) + +arg_parser.add_argument( + "current_branch", metavar="<current-branch>", help="branch for the newest version" +) +arg_parser.add_argument( + "files", metavar="<files>", help="JSON specifying the translation files" +) +arg_parser.add_argument("outname", metavar="<json>", help="name of the json output") + +args = arg_parser.parse_args() + +logging.basicConfig() +logger = logging.getLogger("combine-translation-versions") +logger.setLevel(logging.INFO) + + +def in_pink(msg: str) -> str: + """Present a message as pink in the terminal output. + + :param msg: The message to wrap in pink. + :returns: The message to print to terminal. + """ + # Pink and bold. + return f"\x1b[1;38;5;212m{msg}\x1b[0m" + + +def git_run(git_args: list[str]) -> None: + """Run a git command. + + :param git_args: The arguments that should follow "git". + """ + # Add some text to give context to git's stderr appearing in log. + logger.info("Running: " + in_pink("git " + " ".join(git_args))) + subprocess.run(["git", *git_args], check=True) + + +def git_text(git_args: list[str]) -> str: + """Get the text output for a git command. + + :param git_args: The arguments that should follow "git". + :returns: The stdout of the command. + """ + logger.info("Running: " + in_pink("git " + " ".join(git_args))) + return subprocess.run( + ["git", *git_args], text=True, check=True, stdout=subprocess.PIPE + ).stdout + + +def git_lines(git_args: list[str]) -> list[str]: + """Get the lines from a git command. + + :param git_args: The arguments that should follow "git". + :returns: The non-empty lines from stdout of the command. + """ + return [line for line in git_text(git_args).split("\n") if line] + + +class TranslationFile: + """Represents a translation file.""" + + def __init__(self, path: str, content: str) -> None: + self.path = path + self.content = content + + +class BrowserBranch: + """Represents a browser git branch.""" + + def __init__(self, branch_name: str, is_head: bool = False) -> None: + """Create a new instance. + + :param branch_name: The branch's git name. + :param is_head: Whether the branch matches "HEAD". + """ + version_match = re.match( + r"(?P<prefix>[a-z]+\-browser)\-" + r"(?P<firefox>[0-9]+(?:\.[0-9]+){1,2})esr\-" + r"(?P<browser>[0-9]+\.[05])\-" + r"(?P<number>[0-9]+)$", + branch_name, + ) + + if not version_match: + raise ValueError(f"Unable to parse the version from the ref {branch_name}") + + self.name = branch_name + self.prefix = version_match.group("prefix") + self.browser_version = version_match.group("browser") + self._is_head = is_head + self._ref = "HEAD" if is_head else f"origin/{branch_name}" + + firefox_nums = [int(n) for n in version_match.group("firefox").split(".")] + if len(firefox_nums) == 2: + firefox_nums.append(0) + browser_nums = [int(n) for n in self.browser_version.split(".")] + branch_number = int(version_match.group("number")) + # Prioritise the firefox ESR version, then the browser version then the + # branch number. + self._ordered = ( + firefox_nums[0], + firefox_nums[1], + firefox_nums[2], + browser_nums[0], + browser_nums[1], + branch_number, + ) + + # Minor version for browser is only ever "0" or "5", so we can convert + # the version to an integer. + self._browser_int_version = int(2 * float(self.browser_version)) + + self._file_paths: list[str] | None = None + + def release_below(self, other: "BrowserBranch", num: int) -> bool: + """Determine whether another branch is within range of a previous + browser release. + + The browser versions are expected to increment by "0.5", and a previous + release branch's version is expected to be `num * 0.5` behind the + current one. + + :param other: The branch to compare. + :param num: The number of "0.5" releases behind to test with. + """ + return other._browser_int_version == self._browser_int_version - num + + def __lt__(self, other: "BrowserBranch") -> bool: + return self._ordered < other._ordered + + def __gt__(self, other: "BrowserBranch") -> bool: + return self._ordered > other._ordered + + def _matching_dirs(self, path: str, dir_list: list[str]) -> bool: + """Test that a path is contained in the list of dirs. + + :param path: The path to check. + :param dir_list: The list of directories to check against. + :returns: Whether the path matches. + """ + for dir_path in dir_list: + if os.path.commonpath([dir_path, path]) == dir_path: + return True + return False + + def get_file( + self, filename: str, search_dirs: list[str] | None + ) -> TranslationFile | None: + """Fetch the file content for the named file in this branch. + + :param filename: The name of the file to fetch the content for. + :param search_dirs: The directories to restrict the search to, or None + to search for the file anywhere. + :returns: The file, or `None` if no file could be found. + """ + if self._file_paths is None: + if not self._is_head: + # Minimal fetch of non-HEAD branch to get the file paths. + # Individual file blobs will be downloaded as needed. + git_run( + ["fetch", "--depth=1", "--filter=blob:none", "origin", self.name] + ) + self._file_paths = git_lines( + ["ls-tree", "-r", "--format=%(path)", self._ref] + ) + + matching = [ + path + for path in self._file_paths + if os.path.basename(path) == filename + and (search_dirs is None or self._matching_dirs(path, search_dirs)) + ] + if not matching: + return None + if len(matching) > 1: + raise Exception(f"Multiple occurrences of {filename}") + + path = matching[0] + + return TranslationFile( + path=path, content=git_text(["cat-file", "blob", f"{self._ref}:{path}"]) + ) + + +def get_stable_branch( + compare_version: BrowserBranch, +) -> tuple[BrowserBranch, BrowserBranch | None]: + """Find the most recent stable branch in the origin repository. + + :param compare_version: The development branch to compare against. + :returns: The stable and legacy branches. If no legacy branch is found, + `None` will be returned instead. + """ + # We search for build1 tags. These are added *after* the rebase of browser + # commits, so the corresponding branch should contain our strings. + # Moreover, we *assume* that the branch with the most recent ESR version + # with such a tag will be used in the *next* stable build in + # tor-browser-build. + tag_glob = f"{compare_version.prefix}-*-build1" + + # To speed up, only fetch the tags without blobs. + git_run( + ["fetch", "--depth=1", "--filter=object:type=tag", "origin", "tag", tag_glob] + ) + stable_branches = [] + legacy_branches = [] + stable_annotation_regex = re.compile(r"\bstable\b") + legacy_annotation_regex = re.compile(r"\blegacy\b") + tag_pattern = re.compile( + rf"^{re.escape(compare_version.prefix)}-[^-]+esr-[^-]+-[^-]+-build1$" + ) + + for build_tag, annotation in ( + line.split(" ", 1) for line in git_lines(["tag", "-n1", "--list", tag_glob]) + ): + if not tag_pattern.match(build_tag): + continue + is_stable = bool(stable_annotation_regex.search(annotation)) + is_legacy = bool(legacy_annotation_regex.search(annotation)) + if not is_stable and not is_legacy: + continue + try: + # Branch name is the same as the tag, minus "-build1". + branch = BrowserBranch(re.sub(r"-build1$", "", build_tag)) + except ValueError: + logger.warning(f"Could not read the version for {build_tag}") + continue + if branch.prefix != compare_version.prefix: + continue + if is_stable: + # Stable can be one release version behind. + # NOTE: In principle, when switching between versions there may be a + # window of time where the development branch has not yet progressed + # to the next "0.5" release, so has the same browser version as the + # stable branch. So we also allow for matching browser versions. + # NOTE: + # 1. The "Will be unused in" message will not make sense, but we do + # not expect string differences in this scenario. + # 2. We do not expect this scenario to last for long. + if not ( + compare_version.release_below(branch, 1) + or compare_version.release_below(branch, 0) + ): + continue + stable_branches.append(branch) + elif is_legacy: + # Legacy can be two release versions behind. + # We also allow for being just one version behind. + if not ( + compare_version.release_below(branch, 2) + or compare_version.release_below(branch, 1) + ): + continue + legacy_branches.append(branch) + + if not stable_branches: + raise Exception("No stable build1 branch found") + + return ( + # Return the stable branch with the highest version. + max(stable_branches), + max(legacy_branches) if legacy_branches else None, + ) + + +current_branch = BrowserBranch(args.current_branch, is_head=True) + +stable_branch, legacy_branch = get_stable_branch(current_branch) + +if os.environ.get("TRANSLATION_INCLUDE_LEGACY", "") != "true": + legacy_branch = None + +files_list = [] + +for file_dict in json.loads(args.files): + name = file_dict["name"] + where_dirs = file_dict.get("where", None) + current_file = current_branch.get_file(name, where_dirs) + stable_file = stable_branch.get_file(name, where_dirs) + + if current_file is None and stable_file is None: + # No file in either branch. + logger.warning(f"{name} does not exist in either the current or stable branch") + elif current_file is None: + logger.warning(f"{name} deleted in the current branch") + elif stable_file is None: + logger.warning(f"{name} does not exist in the stable branch") + elif current_file.path != stable_file.path: + logger.warning( + f"{name} has different paths in the current and stable branch. " + f"{current_file.path} : {stable_file.path}" + ) + + content = combine_files( + name, + None if current_file is None else current_file.content, + None if stable_file is None else stable_file.content, + f"Will be unused in Tor Browser {current_branch.browser_version}!", + ) + + if legacy_branch and not file_dict.get("exclude-legacy", False): + legacy_file = legacy_branch.get_file(name, where_dirs) + if legacy_file is not None and current_file is None and stable_file is None: + logger.warning(f"{name} still exists in the legacy branch") + elif legacy_file is None: + logger.warning(f"{name} does not exist in the legacy branch") + elif stable_file is not None and legacy_file.path != stable_file.path: + logger.warning( + f"{name} has different paths in the stable and legacy branch. " + f"{stable_file.path} : {legacy_file.path}" + ) + elif current_file is not None and legacy_file.path != current_file.path: + logger.warning( + f"{name} has different paths in the current and legacy branch. " + f"{current_file.path} : {legacy_file.path}" + ) + + content = combine_files( + name, + content, + legacy_file.content, + f"Unused in Tor Browser {stable_branch.browser_version}!", + ) + elif legacy_branch: + logger.info(f"Excluding legacy branch for {name}") + + files_list.append( + { + "name": name, + # If "directory" is unspecified, we place the file directly beneath + # en-US/ in the translation repository. i.e. "". + "directory": file_dict.get("directory", ""), + "branch": file_dict["branch"], + "content": content, + } + ) + + +ci_commit = os.environ.get("CI_COMMIT_SHA", "") +ci_url_base = os.environ.get("CI_PROJECT_URL", "") + +json_data = { + "commit": ci_commit, + "commit-url": f"{ci_url_base}/-/commit/{ci_commit}" + if (ci_commit and ci_url_base) + else "", + "project-path": os.environ.get("CI_PROJECT_PATH", ""), + "current-branch": current_branch.name, + "stable-branch": stable_branch.name, + "files": files_list, +} + +if legacy_branch: + json_data["legacy-branch"] = legacy_branch.name + +with open(args.outname, "w") as file: + json.dump(json_data, file) ===================================== tools/base-browser/l10n/combine/__init__.py ===================================== @@ -0,0 +1,3 @@ +# flake8: noqa + +from .combine import combine_files ===================================== tools/base-browser/l10n/combine/combine.py ===================================== @@ -0,0 +1,181 @@ +import re +from typing import TYPE_CHECKING, Any + +from compare_locales.parser import getParser +from compare_locales.parser.android import AndroidEntity, DocumentWrapper +from compare_locales.parser.base import Comment, Entity, Junk, Whitespace +from compare_locales.parser.dtd import DTDEntity +from compare_locales.parser.fluent import FluentComment, FluentEntity +from compare_locales.parser.properties import PropertiesEntity + +if TYPE_CHECKING: + from collections.abc import Iterable + + +def combine_files( + filename: str, + new_content: str | None, + old_content: str | None, + comment_prefix: str, +) -> str | None: + """Combine two translation files into one to include all strings from both. + The new content is presented first, and any strings only found in the old + content are placed at the end with an additional comment. + + :param filename: The filename for the file, determines the format. + :param new_content: The new content for the file, or None if it has been + deleted. + :param old_content: The old content for the file, or None if it did not + exist before. + :comment_prefix: A comment to include for any strings that are only found in + the old content. This will be placed before any other comments for the + string. + + :returns: The combined content, or None if both given contents are None. + """ + if new_content is None and old_content is None: + return None + + # getParser from compare_locale returns the same instance for the same file + # extension. + parser = getParser(filename) + + is_android = filename.endswith(".xml") + if new_content is None: + if is_android: + # File was deleted, add some document parts. + content_start = ( + '<?xml version="1.0" encoding="utf-8" standalone="yes"?>\n<resources>\n' + ) + content_end = "</resources>\n" + else: + # Treat as an empty file. + content_start = "" + content_end = "" + existing_keys = [] + else: + parser.readUnicode(new_content) + + # Start with the same content as the current file. + # For android strings, we want to keep the final "</resources>" until after. + if is_android: + closing_match = re.match( + r"^(.*)(</resources>\s*)$", parser.ctx.contents, re.DOTALL + ) + if not closing_match: + raise ValueError("Missing a final </resources>") + content_start = closing_match.group(1) + content_end = closing_match.group(2) + else: + content_start = parser.ctx.contents + content_end = "" + existing_keys = [entry.key for entry in parser.walk(only_localizable=True)] + + # For Fluent, we want to prefix the strings using GroupComments. + # On weblate this will cause all the strings that fall under the GroupComment's + # scope to have the prefix added to their "notes". + # We set up an initial GroupComment for the first string we find. This will also + # end the scope of the last GroupComment in the new translation file. + # This will be replaced with a the next GroupComment when it is found. + fluent_group_comment_prefix = f"\n## {comment_prefix}\n" + fluent_group_comment: str | None = fluent_group_comment_prefix + + # For other formats, we want to keep all the comment lines that come directly + # before the string. + # In compare_locales.parser, only the comment line directly before an Entity + # counts as the pre_comment for that Entity. I.e. only this line will be + # included in Entity.all + # However, in weblate every comment line that comes before the Entity is + # included as a comment. So we also want to keep these additional comments to + # preserve them for weblate. + # We gather these extra comments in stacked_comments, and clear them whenever we + # reach an Entity or a blank line (Whitespace is more than "\n"). + stacked_comments: list[str] = [] + + additions: list[str] = [] + + entry_iter: Iterable[Any] = () + # If the file does not exist in the old branch, don't make any additions. + if old_content is not None: + parser.readUnicode(old_content) + entry_iter = parser.walk(only_localizable=False) + for entry in entry_iter: + if isinstance(entry, Junk): + raise ValueError(f"Unexpected Junk: {entry.all}") + if isinstance(entry, Whitespace): + # Clear stacked comments if more than one empty line. + if entry.all != "\n": + stacked_comments.clear() + continue + if isinstance(entry, Comment): + if isinstance(entry, FluentComment): + # Don't stack Fluent comments. + # Only the comments included in Entity.pre_comment count towards + # that Entity's comment. + if entry.all.startswith("##"): + # A Fluent GroupComment + if entry.all == "##": + # Empty GroupComment. Used to end the scope of a previous + # GroupComment. + # Replace this with our prefix comment. + fluent_group_comment = fluent_group_comment_prefix + else: + # Prefix the group comment. + fluent_group_comment = ( + f"{fluent_group_comment_prefix}{entry.all}\n" + ) + else: + stacked_comments.append(entry.all) + continue + if isinstance(entry, DocumentWrapper): + # Not needed. + continue + + if not isinstance(entry, Entity): + raise ValueError(f"Unexpected type: {entry.__class__.__name__}") + + if entry.key in existing_keys: + # Already included this string in the new translation file. + # Drop the gathered comments for this Entity. + stacked_comments.clear() + continue + + if isinstance(entry, FluentEntity): + if fluent_group_comment is not None: + # We have a found GroupComment which has not been included yet. + # All following Entity's will be under its scope, until the next + # GroupComment. + additions.append(fluent_group_comment) + # Added GroupComment, so don't need to add again. + fluent_group_comment = None + elif isinstance(entry, DTDEntity): + # Include our additional comment before we print the rest for this + # Entity. + additions.append(f"<!-- LOCALIZATION NOTE: {comment_prefix} -->") + elif isinstance(entry, PropertiesEntity): + additions.append(f"# {comment_prefix}") + elif isinstance(entry, AndroidEntity): + additions.append(f"<!-- {comment_prefix} -->") + else: + raise ValueError(f"Unexpected Entity type: {entry.__class__.__name__}") + + # Add any other comment lines that came directly before this Entity. + additions.extend(stacked_comments) + stacked_comments.clear() + additions.append(entry.all) + + content_middle = "" + + if additions: + # New line before and after the additions + additions.insert(0, "") + additions.append("") + if is_android: + content_middle = "\n ".join(additions) + else: + content_middle = "\n".join(additions) + + # Remove " " in otherwise blank lines. + content_middle = re.sub("^ +$", "", content_middle, flags=re.MULTILINE) + + return content_start + content_middle + content_end ===================================== tools/base-browser/l10n/combine/tests/README ===================================== @@ -0,0 +1,2 @@ +python tests to be run with pytest. +Requires the compare-locales package. ===================================== tools/base-browser/l10n/combine/tests/__init__.py ===================================== ===================================== tools/base-browser/l10n/combine/tests/test_android.py ===================================== @@ -0,0 +1,330 @@ +import textwrap + +from combine import combine_files + + +def wrap_in_xml(content): + if content is None: + return None + # Allow for indents to make the tests more readable. + content = textwrap.dedent(content) + return f"""\ +<?xml version="1.0" encoding="utf-8" standalone="yes"?> +<resources> +{textwrap.indent(content, " ")}</resources> +""" + + +def assert_result(new_content, old_content, expect): + new_content = wrap_in_xml(new_content) + old_content = wrap_in_xml(old_content) + expect = wrap_in_xml(expect) + assert expect == combine_files( + "test_strings.xml", new_content, old_content, "REMOVED STRING" + ) + + +def test_combine_empty(): + assert_result(None, None, None) + + +def test_combine_new_file(): + # New file with no old content. + assert_result( + """\ + <string name="string_1">First</string> + <string name="string_2">Second</string> + """, + None, + """\ + <string name="string_1">First</string> + <string name="string_2">Second</string> + """, + ) + + +def test_combine_removed_file(): + # Entire file was removed. + assert_result( + None, + """\ + <string name="string_1">First</string> + <string name="string_2">Second</string> + """, + """\ + + <!-- REMOVED STRING --> + <string name="string_1">First</string> + <!-- REMOVED STRING --> + <string name="string_2">Second</string> + """, + ) + + +def test_no_change(): + content = """\ + <string name="string_1">First</string> + <string name="string_2">Second</string> + """ + assert_result(content, content, content) + + +def test_added_string(): + assert_result( + """\ + <string name="string_1">First</string> + <string name="string_new">NEW</string> + <string name="string_2">Second</string> + """, + """\ + <string name="string_1">First</string> + <string name="string_2">Second</string> + """, + """\ + <string name="string_1">First</string> + <string name="string_new">NEW</string> + <string name="string_2">Second</string> + """, + ) + + +def test_removed_string(): + assert_result( + """\ + <string name="string_1">First</string> + <string name="string_2">Second</string> + """, + """\ + <string name="string_1">First</string> + <string name="removed">REMOVED</string> + <string name="string_2">Second</string> + """, + """\ + <string name="string_1">First</string> + <string name="string_2">Second</string> + + <!-- REMOVED STRING --> + <string name="removed">REMOVED</string> + """, + ) + + +def test_removed_and_added(): + assert_result( + """\ + <string name="new_1">New string</string> + <string name="string_1">First</string> + <string name="string_2">Second</string> + <string name="new_2">New string 2</string> + """, + """\ + <string name="string_1">First</string> + <string name="removed_1">First removed</string> + <string name="removed_2">Second removed</string> + <string name="string_2">Second</string> + <string name="removed_3">Third removed</string> + """, + """\ + <string name="new_1">New string</string> + <string name="string_1">First</string> + <string name="string_2">Second</string> + <string name="new_2">New string 2</string> + + <!-- REMOVED STRING --> + <string name="removed_1">First removed</string> + <!-- REMOVED STRING --> + <string name="removed_2">Second removed</string> + <!-- REMOVED STRING --> + <string name="removed_3">Third removed</string> + """, + ) + + +def test_updated(): + # String content was updated. + assert_result( + """\ + <string name="changed_string">NEW</string> + """, + """\ + <string name="changed_string">OLD</string> + """, + """\ + <string name="changed_string">NEW</string> + """, + ) + + +def test_updated_comment(): + # String comment was updated. + assert_result( + """\ + <!-- NEW --> + <string name="changed_string">string</string> + """, + """\ + <!-- OLD --> + <string name="changed_string">string</string> + """, + """\ + <!-- NEW --> + <string name="changed_string">string</string> + """, + ) + # Comment added. + assert_result( + """\ + <!-- NEW --> + <string name="changed_string">string</string> + """, + """\ + <string name="changed_string">string</string> + """, + """\ + <!-- NEW --> + <string name="changed_string">string</string> + """, + ) + # Comment removed. + assert_result( + """\ + <string name="changed_string">string</string> + """, + """\ + <!-- OLD --> + <string name="changed_string">string</string> + """, + """\ + <string name="changed_string">string</string> + """, + ) + + # With file comments + assert_result( + """\ + <!-- NEW file comment --> + + <!-- NEW --> + <string name="changed_string">string</string> + """, + """\ + <!-- OLD file comment --> + + <!-- OLD --> + <string name="changed_string">string</string> + """, + """\ + <!-- NEW file comment --> + + <!-- NEW --> + <string name="changed_string">string</string> + """, + ) + + +def test_reordered(): + # String was re_ordered. + assert_result( + """\ + <string name="string_1">value</string> + <string name="moved_string">move</string> + """, + """\ + <string name="moved_string">move</string> + <string name="string_1">value</string> + """, + """\ + <string name="string_1">value</string> + <string name="moved_string">move</string> + """, + ) + + +def test_removed_string_with_comment(): + assert_result( + """\ + <!-- Comment for first. --> + <string name="string_1">First</string> + <string name="string_2">Second</string> + """, + """\ + <!-- Comment for first. --> + <string name="string_1">First</string> + <!-- Comment for removed. --> + <string name="removed">REMOVED</string> + <string name="string_2">Second</string> + """, + """\ + <!-- Comment for first. --> + <string name="string_1">First</string> + <string name="string_2">Second</string> + + <!-- REMOVED STRING --> + <!-- Comment for removed. --> + <string name="removed">REMOVED</string> + """, + ) + + # With file comments and multi-line. + # All comments prior to a removed string are moved with it, until another + # entity or blank line is reached. + assert_result( + """\ + <!-- First File comment --> + + <!-- Comment for first. --> + <!-- Comment 2 for first. --> + <string name="string_1">First</string> + + <!-- Second --> + <!-- File comment --> + + <string name="string_2">Second</string> + """, + """\ + <!-- First File comment --> + + <!-- Comment for first. --> + <!-- Comment 2 for first. --> + <string name="string_1">First</string> + <string name="removed_1">First removed</string> + <!-- Comment for second removed. --> + <string name="removed_2">Second removed</string> + + <!-- Removed file comment --> + + <!-- Comment 1 for third removed --> + <!-- Comment 2 for third removed --> + <string name="removed_3">Third removed</string> + + <!-- Second --> + <!-- File comment --> + + <string name="removed_4">Fourth removed</string> + <string name="string_2">Second</string> + """, + """\ + <!-- First File comment --> + + <!-- Comment for first. --> + <!-- Comment 2 for first. --> + <string name="string_1">First</string> + + <!-- Second --> + <!-- File comment --> + + <string name="string_2">Second</string> + + <!-- REMOVED STRING --> + <string name="removed_1">First removed</string> + <!-- REMOVED STRING --> + <!-- Comment for second removed. --> + <string name="removed_2">Second removed</string> + <!-- REMOVED STRING --> + <!-- Comment 1 for third removed --> + <!-- Comment 2 for third removed --> + <string name="removed_3">Third removed</string> + <!-- REMOVED STRING --> + <string name="removed_4">Fourth removed</string> + """, + ) ===================================== tools/base-browser/l10n/combine/tests/test_dtd.py ===================================== @@ -0,0 +1,325 @@ +import textwrap + +from combine import combine_files + + +def assert_result(new_content, old_content, expect): + # Allow for indents to make the tests more readable. + if new_content is not None: + new_content = textwrap.dedent(new_content) + if old_content is not None: + old_content = textwrap.dedent(old_content) + if expect is not None: + expect = textwrap.dedent(expect) + assert expect == combine_files( + "test.dtd", new_content, old_content, "REMOVED STRING" + ) + + +def test_combine_empty(): + assert_result(None, None, None) + + +def test_combine_new_file(): + # New file with no old content. + assert_result( + """\ + <!ENTITY string.1 "First"> + <!ENTITY string.2 "Second"> + """, + None, + """\ + <!ENTITY string.1 "First"> + <!ENTITY string.2 "Second"> + """, + ) + + +def test_combine_removed_file(): + # Entire file was removed. + assert_result( + None, + """\ + <!ENTITY string.1 "First"> + <!ENTITY string.2 "Second"> + """, + """\ + + <!-- LOCALIZATION NOTE: REMOVED STRING --> + <!ENTITY string.1 "First"> + <!-- LOCALIZATION NOTE: REMOVED STRING --> + <!ENTITY string.2 "Second"> + """, + ) + + +def test_no_change(): + content = """\ + <!ENTITY string.1 "First"> + <!ENTITY string.2 "Second"> + """ + assert_result(content, content, content) + + +def test_added_string(): + assert_result( + """\ + <!ENTITY string.1 "First"> + <!ENTITY string.new "NEW"> + <!ENTITY string.2 "Second"> + """, + """\ + <!ENTITY string.1 "First"> + <!ENTITY string.2 "Second"> + """, + """\ + <!ENTITY string.1 "First"> + <!ENTITY string.new "NEW"> + <!ENTITY string.2 "Second"> + """, + ) + + +def test_removed_string(): + assert_result( + """\ + <!ENTITY string.1 "First"> + <!ENTITY string.2 "Second"> + """, + """\ + <!ENTITY string.1 "First"> + <!ENTITY removed "REMOVED"> + <!ENTITY string.2 "Second"> + """, + """\ + <!ENTITY string.1 "First"> + <!ENTITY string.2 "Second"> + + <!-- LOCALIZATION NOTE: REMOVED STRING --> + <!ENTITY removed "REMOVED"> + """, + ) + + +def test_removed_and_added(): + assert_result( + """\ + <!ENTITY new.1 "New string"> + <!ENTITY string.1 "First"> + <!ENTITY string.2 "Second"> + <!ENTITY new.2 "New string 2"> + """, + """\ + <!ENTITY string.1 "First"> + <!ENTITY removed.1 "First removed"> + <!ENTITY removed.2 "Second removed"> + <!ENTITY string.2 "Second"> + <!ENTITY removed.3 "Third removed"> + """, + """\ + <!ENTITY new.1 "New string"> + <!ENTITY string.1 "First"> + <!ENTITY string.2 "Second"> + <!ENTITY new.2 "New string 2"> + + <!-- LOCALIZATION NOTE: REMOVED STRING --> + <!ENTITY removed.1 "First removed"> + <!-- LOCALIZATION NOTE: REMOVED STRING --> + <!ENTITY removed.2 "Second removed"> + <!-- LOCALIZATION NOTE: REMOVED STRING --> + <!ENTITY removed.3 "Third removed"> + """, + ) + + +def test_updated(): + # String content was updated. + assert_result( + """\ + <!ENTITY changed.string "NEW"> + """, + """\ + <!ENTITY changed.string "OLD"> + """, + """\ + <!ENTITY changed.string "NEW"> + """, + ) + + +def test_updated_comment(): + # String comment was updated. + assert_result( + """\ + <!-- LOCALIZATION NOTE: NEW --> + <!ENTITY changed.string "string"> + """, + """\ + <!-- LOCALIZATION NOTE: OLD --> + <!ENTITY changed.string "string"> + """, + """\ + <!-- LOCALIZATION NOTE: NEW --> + <!ENTITY changed.string "string"> + """, + ) + # Comment added. + assert_result( + """\ + <!-- LOCALIZATION NOTE: NEW --> + <!ENTITY changed.string "string"> + """, + """\ + <!ENTITY changed.string "string"> + """, + """\ + <!-- LOCALIZATION NOTE: NEW --> + <!ENTITY changed.string "string"> + """, + ) + # Comment removed. + assert_result( + """\ + <!ENTITY changed.string "string"> + """, + """\ + <!-- LOCALIZATION NOTE: OLD --> + <!ENTITY changed.string "string"> + """, + """\ + <!ENTITY changed.string "string"> + """, + ) + + # With multiple comments + assert_result( + """\ + <!-- NEW FILE COMMENT --> + + <!-- LOCALIZATION NOTE: NEW --> + <!ENTITY changed.string "string"> + """, + """\ + <!-- OLD --> + + <!-- LOCALIZATION NOTE: OLD --> + <!ENTITY changed.string "string"> + """, + """\ + <!-- NEW FILE COMMENT --> + + <!-- LOCALIZATION NOTE: NEW --> + <!ENTITY changed.string "string"> + """, + ) + + +def test_reordered(): + # String was re.ordered. + assert_result( + """\ + <!ENTITY string.1 "value"> + <!ENTITY moved.string "move"> + """, + """\ + <!ENTITY moved.string "move"> + <!ENTITY string.1 "value"> + """, + """\ + <!ENTITY string.1 "value"> + <!ENTITY moved.string "move"> + """, + ) + + +def test_removed_string_with_comment(): + assert_result( + """\ + <!-- LOCALIZATION NOTE: Comment for first. --> + <!ENTITY string.1 "First"> + <!ENTITY string.2 "Second"> + """, + """\ + <!-- LOCALIZATION NOTE: Comment for first. --> + <!ENTITY string.1 "First"> + <!-- LOCALIZATION NOTE: Comment for removed. --> + <!ENTITY removed "REMOVED"> + <!ENTITY string.2 "Second"> + """, + """\ + <!-- LOCALIZATION NOTE: Comment for first. --> + <!ENTITY string.1 "First"> + <!ENTITY string.2 "Second"> + + <!-- LOCALIZATION NOTE: REMOVED STRING --> + <!-- LOCALIZATION NOTE: Comment for removed. --> + <!ENTITY removed "REMOVED"> + """, + ) + + # With multiple lines of comments. + + assert_result( + """\ + <!-- First file comment --> + + <!-- LOCALIZATION NOTE: Comment for first. --> + <!-- LOCALIZATION NOTE: Comment 2 for first. --> + <!ENTITY string.1 "First"> + + <!-- Second + - file + - comment --> + + <!ENTITY string.2 "Second"> + """, + """\ + <!-- First file comment --> + + <!-- LOCALIZATION NOTE: Comment for first. --> + <!ENTITY string.1 "First"> + <!ENTITY removed.1 "First removed"> + <!-- LOCALIZATION NOTE: Comment for second removed. --> + <!ENTITY removed.2 "Second removed"> + + <!-- Removed file comment --> + + <!-- LOCALIZATION NOTE: Comment for third removed. --> + <!-- LOCALIZATION NOTE: Comment 2 for + third removed. --> + <!ENTITY removed.3 "Third removed"> + + <!-- Second + - file + - comment --> + + <!ENTITY removed.4 "Fourth removed"> + <!ENTITY string.2 "Second"> + """, + """\ + <!-- First file comment --> + + <!-- LOCALIZATION NOTE: Comment for first. --> + <!-- LOCALIZATION NOTE: Comment 2 for first. --> + <!ENTITY string.1 "First"> + + <!-- Second + - file + - comment --> + + <!ENTITY string.2 "Second"> + + <!-- LOCALIZATION NOTE: REMOVED STRING --> + <!ENTITY removed.1 "First removed"> + <!-- LOCALIZATION NOTE: REMOVED STRING --> + <!-- LOCALIZATION NOTE: Comment for second removed. --> + <!ENTITY removed.2 "Second removed"> + <!-- LOCALIZATION NOTE: REMOVED STRING --> + <!-- LOCALIZATION NOTE: Comment for third removed. --> + <!-- LOCALIZATION NOTE: Comment 2 for + third removed. --> + <!ENTITY removed.3 "Third removed"> + <!-- LOCALIZATION NOTE: REMOVED STRING --> + <!ENTITY removed.4 "Fourth removed"> + """, + ) ===================================== tools/base-browser/l10n/combine/tests/test_fluent.py ===================================== @@ -0,0 +1,344 @@ +import textwrap + +from combine import combine_files + + +def assert_result(new_content, old_content, expect): + # Allow for indents to make the tests more readable. + if new_content is not None: + new_content = textwrap.dedent(new_content) + if old_content is not None: + old_content = textwrap.dedent(old_content) + if expect is not None: + expect = textwrap.dedent(expect) + assert expect == combine_files( + "test.ftl", new_content, old_content, "REMOVED STRING" + ) + + +def test_combine_empty(): + assert_result(None, None, None) + + +def test_combine_new_file(): + # New file with no old content. + assert_result( + """\ + string-1 = First + string-2 = Second + """, + None, + """\ + string-1 = First + string-2 = Second + """, + ) + + +def test_combine_removed_file(): + # Entire file was removed. + assert_result( + None, + """\ + string-1 = First + string-2 = Second + """, + """\ + + + ## REMOVED STRING + + string-1 = First + string-2 = Second + """, + ) + + +def test_no_change(): + content = """\ + string-1 = First + string-2 = Second + """ + assert_result(content, content, content) + + +def test_added_string(): + assert_result( + """\ + string-1 = First + string-new = NEW + string-2 = Second + """, + """\ + string-1 = First + string-2 = Second + """, + """\ + string-1 = First + string-new = NEW + string-2 = Second + """, + ) + + +def test_removed_string(): + assert_result( + """\ + string-1 = First + string-2 = Second + """, + """\ + string-1 = First + removed = REMOVED + string-2 = Second + """, + """\ + string-1 = First + string-2 = Second + + + ## REMOVED STRING + + removed = REMOVED + """, + ) + + +def test_removed_and_added(): + assert_result( + """\ + new-1 = New string + string-1 = + .attr = First + string-2 = Second + new-2 = + .title = New string 2 + """, + """\ + string-1 = + .attr = First + removed-1 = First removed + removed-2 = + .attr = Second removed + string-2 = Second + removed-3 = Third removed + """, + """\ + new-1 = New string + string-1 = + .attr = First + string-2 = Second + new-2 = + .title = New string 2 + + + ## REMOVED STRING + + removed-1 = First removed + removed-2 = + .attr = Second removed + removed-3 = Third removed + """, + ) + + +def test_updated(): + # String content was updated. + assert_result( + """\ + changed-string = NEW + """, + """\ + changed-string = OLD + """, + """\ + changed-string = NEW + """, + ) + + +def test_updated_comment(): + # String comment was updated. + assert_result( + """\ + # NEW + changed-string = string + """, + """\ + # OLD + changed-string = string + """, + """\ + # NEW + changed-string = string + """, + ) + # Comment added. + assert_result( + """\ + # NEW + changed-string = string + """, + """\ + changed-string = string + """, + """\ + # NEW + changed-string = string + """, + ) + # Comment removed. + assert_result( + """\ + changed-string = string + """, + """\ + # OLD + changed-string = string + """, + """\ + changed-string = string + """, + ) + + # With group comments. + assert_result( + """\ + ## GROUP NEW + + # NEW + changed-string = string + """, + """\ + ## GROUP OLD + + # OLD + changed-string = string + """, + """\ + ## GROUP NEW + + # NEW + changed-string = string + """, + ) + + +def test_reordered(): + # String was re-ordered. + assert_result( + """\ + string-1 = value + moved-string = move + """, + """\ + moved-string = move + string-1 = value + """, + """\ + string-1 = value + moved-string = move + """, + ) + + +def test_removed_string_with_comment(): + assert_result( + """\ + # Comment for first. + string-1 = First + string-2 = Second + """, + """\ + # Comment for first. + string-1 = First + # Comment for removed. + removed = REMOVED + string-2 = Second + """, + """\ + # Comment for first. + string-1 = First + string-2 = Second + + + ## REMOVED STRING + + # Comment for removed. + removed = REMOVED + """, + ) + + # Group comments are combined with the "REMOVED STRING" comments. + # If strings have no group comment, then a single "REMOVED STRING" is + # included for them. + assert_result( + """\ + ## First Group comment + + # Comment for first. + string-1 = First + + ## + + no-group = No group comment + + ## Second + ## Group comment + + string-2 = Second + """, + """\ + ## First Group comment + + # Comment for first. + string-1 = First + removed-1 = First removed + # Comment for second removed. + removed-2 = Second removed + + ## + + no-group = No group comment + removed-3 = Third removed + + ## Second + ## Group comment + + removed-4 = Fourth removed + string-2 = Second + """, + """\ + ## First Group comment + + # Comment for first. + string-1 = First + + ## + + no-group = No group comment + + ## Second + ## Group comment + + string-2 = Second + + + ## REMOVED STRING + ## First Group comment + + removed-1 = First removed + # Comment for second removed. + removed-2 = Second removed + + ## REMOVED STRING + + removed-3 = Third removed + + ## REMOVED STRING + ## Second + ## Group comment + + removed-4 = Fourth removed + """, + ) ===================================== tools/base-browser/l10n/combine/tests/test_properties.py ===================================== @@ -0,0 +1,322 @@ +import textwrap + +from combine import combine_files + + +def assert_result(new_content, old_content, expect): + # Allow for indents to make the tests more readable. + if new_content is not None: + new_content = textwrap.dedent(new_content) + if old_content is not None: + old_content = textwrap.dedent(old_content) + if expect is not None: + expect = textwrap.dedent(expect) + assert expect == combine_files( + "test.properties", new_content, old_content, "REMOVED STRING" + ) + + +def test_combine_empty(): + assert_result(None, None, None) + + +def test_combine_new_file(): + # New file with no old content. + assert_result( + """\ + string.1 = First + string.2 = Second + """, + None, + """\ + string.1 = First + string.2 = Second + """, + ) + + +def test_combine_removed_file(): + # Entire file was removed. + assert_result( + None, + """\ + string.1 = First + string.2 = Second + """, + """\ + + # REMOVED STRING + string.1 = First + # REMOVED STRING + string.2 = Second + """, + ) + + +def test_no_change(): + content = """\ + string.1 = First + string.2 = Second + """ + assert_result(content, content, content) + + +def test_added_string(): + assert_result( + """\ + string.1 = First + string.new = NEW + string.2 = Second + """, + """\ + string.1 = First + string.2 = Second + """, + """\ + string.1 = First + string.new = NEW + string.2 = Second + """, + ) + + +def test_removed_string(): + assert_result( + """\ + string.1 = First + string.2 = Second + """, + """\ + string.1 = First + removed = REMOVED + string.2 = Second + """, + """\ + string.1 = First + string.2 = Second + + # REMOVED STRING + removed = REMOVED + """, + ) + + +def test_removed_and_added(): + assert_result( + """\ + new.1 = New string + string.1 = First + string.2 = Second + new.2 = New string 2 + """, + """\ + string.1 = First + removed.1 = First removed + removed.2 = Second removed + string.2 = Second + removed.3 = Third removed + """, + """\ + new.1 = New string + string.1 = First + string.2 = Second + new.2 = New string 2 + + # REMOVED STRING + removed.1 = First removed + # REMOVED STRING + removed.2 = Second removed + # REMOVED STRING + removed.3 = Third removed + """, + ) + + +def test_updated(): + # String content was updated. + assert_result( + """\ + changed.string = NEW + """, + """\ + changed.string = OLD + """, + """\ + changed.string = NEW + """, + ) + + +def test_updated_comment(): + # String comment was updated. + assert_result( + """\ + # NEW + changed.string = string + """, + """\ + # OLD + changed.string = string + """, + """\ + # NEW + changed.string = string + """, + ) + # Comment added. + assert_result( + """\ + # NEW + changed.string = string + """, + """\ + changed.string = string + """, + """\ + # NEW + changed.string = string + """, + ) + # Comment removed. + assert_result( + """\ + changed.string = string + """, + """\ + # OLD + changed.string = string + """, + """\ + changed.string = string + """, + ) + + # With file comments + assert_result( + """\ + # NEW file comment + + # NEW + changed.string = string + """, + """\ + # OLD file comment + + # OLD + changed.string = string + """, + """\ + # NEW file comment + + # NEW + changed.string = string + """, + ) + + +def test_reordered(): + # String was re.ordered. + assert_result( + """\ + string.1 = value + moved.string = move + """, + """\ + moved.string = move + string.1 = value + """, + """\ + string.1 = value + moved.string = move + """, + ) + + +def test_removed_string_with_comment(): + assert_result( + """\ + # Comment for first. + string.1 = First + string.2 = Second + """, + """\ + # Comment for first. + string.1 = First + # Comment for removed. + removed = REMOVED + string.2 = Second + """, + """\ + # Comment for first. + string.1 = First + string.2 = Second + + # REMOVED STRING + # Comment for removed. + removed = REMOVED + """, + ) + + # With file comments and multi-line. + # All comments prior to a removed string are moved with it, until another + # entity or blank line is reached. + assert_result( + """\ + # First File comment + + # Comment for first. + # Comment 2 for first. + string.1 = First + + # Second + # File comment + + string.2 = Second + """, + """\ + # First File comment + + # Comment for first. + # Comment 2 for first. + string.1 = First + removed.1 = First removed + # Comment for second removed. + removed.2 = Second removed + + # Removed file comment + + # Comment 1 for third removed + # Comment 2 for third removed + removed.3 = Third removed + + # Second + # File comment + + removed.4 = Fourth removed + string.2 = Second + """, + """\ + # First File comment + + # Comment for first. + # Comment 2 for first. + string.1 = First + + # Second + # File comment + + string.2 = Second + + # REMOVED STRING + removed.1 = First removed + # REMOVED STRING + # Comment for second removed. + removed.2 = Second removed + # REMOVED STRING + # Comment 1 for third removed + # Comment 2 for third removed + removed.3 = Third removed + # REMOVED STRING + removed.4 = Fourth removed + """, + ) View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/186910… -- View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/186910… You're receiving this email because of your account on gitlab.torproject.org.
1 0
0 0
[Git][tpo/applications/tor-browser][tor-browser-128.6.0esr-14.5-1] 5 commits: fixup! Add CI for Tor Browser
by Pier Angelo Vendrame (@pierov) 22 Jan '25

22 Jan '25
Pier Angelo Vendrame pushed to branch tor-browser-128.6.0esr-14.5-1 at The Tor Project / Applications / Tor Browser Commits: 4fd00231 by Henry Wilkes at 2025-01-22T11:06:59+00:00 fixup! Add CI for Tor Browser MB 324: Revert tor-browser changes that add update-translations CI. - - - - - f467154f by Henry Wilkes at 2025-01-22T11:06:59+00:00 Revert "TB 42305: Add script to combine translation files across versions." This reverts commit 3247633d3f6bf60be7feaf2e3515d9b7c2b1dad0. - - - - - 675287aa by Henry Wilkes at 2025-01-22T11:06:59+00:00 fixup! Add CI for Base Browser MB 324: Move update-translations CI to base-browser. - - - - - 4c57d159 by Henry Wilkes at 2025-01-22T11:06:59+00:00 BB 42305: Add script to combine translation files across versions. - - - - - e0847a5c by Henry Wilkes at 2025-01-22T11:06:59+00:00 fixup! Add CI for Tor Browser MB 324: Re-introduce tor-browser changes to update-translations - - - - - 10 changed files: - .gitlab/ci/jobs/update-translations.yml - tools/torbrowser/l10n/combine-translation-versions.py → tools/base-browser/l10n/combine-translation-versions.py - tools/torbrowser/l10n/combine/__init__.py → tools/base-browser/l10n/combine/__init__.py - tools/torbrowser/l10n/combine/combine.py → tools/base-browser/l10n/combine/combine.py - tools/torbrowser/l10n/combine/tests/README → tools/base-browser/l10n/combine/tests/README - tools/torbrowser/l10n/combine/tests/__init__.py → tools/base-browser/l10n/combine/tests/__init__.py - tools/torbrowser/l10n/combine/tests/test_android.py → tools/base-browser/l10n/combine/tests/test_android.py - tools/torbrowser/l10n/combine/tests/test_dtd.py → tools/base-browser/l10n/combine/tests/test_dtd.py - tools/torbrowser/l10n/combine/tests/test_fluent.py → tools/base-browser/l10n/combine/tests/test_fluent.py - tools/torbrowser/l10n/combine/tests/test_properties.py → tools/base-browser/l10n/combine/tests/test_properties.py Changes: ===================================== .gitlab/ci/jobs/update-translations.yml ===================================== @@ -1,7 +1,7 @@ .update-translation-base: stage: update-translations rules: - - if: ($CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE == "push") + - if: ($TRANSLATION_FILES != "" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE == "push") changes: - "**/*.ftl" - "**/*.properties" @@ -10,17 +10,9 @@ - "**/update-translations.yml" - "**/l10n/combine/combine.py" - "**/l10n/combine-translation-versions.py" - - if: $FORCE_UPDATE_TRANSLATIONS == "true" + - if: ($TRANSLATION_FILES != "" && $FORCE_UPDATE_TRANSLATIONS == "true") variables: - TOR_BROWSER_COMBINED_FILES_JSON: "combined-translation-files.json" - - -combine-en-US-translations: - extends: .update-translation-base - needs: [] - image: python - variables: - PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip" + COMBINED_FILES_JSON: "combined-translation-files.json" TRANSLATION_FILES: '[ { "name": "brand.ftl", @@ -49,13 +41,21 @@ combine-en-US-translations: } ]' TRANSLATION_INCLUDE_LEGACY: "true" + + +combine-en-US-translations: + extends: .update-translation-base + needs: [] + image: python + variables: + PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip" cache: paths: - .cache/pip # Artifact is for translation project job artifacts: paths: - - "$TOR_BROWSER_COMBINED_FILES_JSON" + - "$COMBINED_FILES_JSON" expire_in: "60 min" reports: dotenv: job_id.env @@ -66,14 +66,14 @@ combine-en-US-translations: # push-en-US-translations job. - echo 'COMBINE_TRANSLATIONS_JOB_ID='"$CI_JOB_ID" >job_id.env - pip install compare_locales - - python ./tools/torbrowser/l10n/combine-translation-versions.py "$CI_COMMIT_BRANCH" "$TRANSLATION_FILES" "$TOR_BROWSER_COMBINED_FILES_JSON" + - python ./tools/base-browser/l10n/combine-translation-versions.py "$CI_COMMIT_BRANCH" "$TRANSLATION_FILES" "$COMBINED_FILES_JSON" push-en-US-translations: extends: .update-translation-base needs: - job: combine-en-US-translations variables: - TOR_BROWSER_COMBINED_FILES_JSON_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/jobs/${COMBINE_TRANSLATIONS_JOB_ID}/artifacts/${TOR_BROWSER_COMBINED_FILES_JSON}" + COMBINED_FILES_JSON_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/jobs/${COMBINE_TRANSLATIONS_JOB_ID}/artifacts/${COMBINED_FILES_JSON}" trigger: strategy: depend project: tor-browser-translation-bot/translation ===================================== tools/torbrowser/l10n/combine-translation-versions.py → tools/base-browser/l10n/combine-translation-versions.py ===================================== ===================================== tools/torbrowser/l10n/combine/__init__.py → tools/base-browser/l10n/combine/__init__.py ===================================== ===================================== tools/torbrowser/l10n/combine/combine.py → tools/base-browser/l10n/combine/combine.py ===================================== ===================================== tools/torbrowser/l10n/combine/tests/README → tools/base-browser/l10n/combine/tests/README ===================================== ===================================== tools/torbrowser/l10n/combine/tests/__init__.py → tools/base-browser/l10n/combine/tests/__init__.py ===================================== ===================================== tools/torbrowser/l10n/combine/tests/test_android.py → tools/base-browser/l10n/combine/tests/test_android.py ===================================== ===================================== tools/torbrowser/l10n/combine/tests/test_dtd.py → tools/base-browser/l10n/combine/tests/test_dtd.py ===================================== ===================================== tools/torbrowser/l10n/combine/tests/test_fluent.py → tools/base-browser/l10n/combine/tests/test_fluent.py ===================================== ===================================== tools/torbrowser/l10n/combine/tests/test_properties.py → tools/base-browser/l10n/combine/tests/test_properties.py ===================================== View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/ecdccd… -- View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/ecdccd… You're receiving this email because of your account on gitlab.torproject.org.
1 0
0 0
[Git][tpo/applications/tor-browser][tor-browser-128.6.0esr-14.5-1] 2 commits: fixup! TB 40597: Implement TorSettings module
by Pier Angelo Vendrame (@pierov) 21 Jan '25

21 Jan '25
Pier Angelo Vendrame pushed to branch tor-browser-128.6.0esr-14.5-1 at The Tor Project / Applications / Tor Browser Commits: 266cf821 by Henry Wilkes at 2025-01-21T17:10:38+00:00 fixup! TB 40597: Implement TorSettings module TB 41921: Reset bootstrap stage when bridge settings change. In particular, this will cancel an autobootstrap when the user manually changes the bridge settings. However we apply this to all bootstrap attempts for consistency. By resetting to the Start stage, we also ensure that about:torconnect UI no longer shows the "Try bridges" pages when the user manually changes their bridges themselves. - - - - - ecdccd3f by Henry Wilkes at 2025-01-21T17:10:38+00:00 fixup! TB 31286: Implementation of bridge, proxy, and firewall settings in about:preferences#connection TB 41921: Also show the "Connect" button for bridge dialogs when we have an ongoing bootstrap attempt. With the new behaviour, changing the settings while not bootstrapped will cancel any ongoing bootstrap. Therefore, we can start a new bootstrap using the new settings. - - - - - 6 changed files: - browser/components/torpreferences/content/builtinBridgeDialog.js - browser/components/torpreferences/content/connectionPane.js - browser/components/torpreferences/content/provideBridgeDialog.js - browser/components/torpreferences/content/requestBridgeDialog.js - toolkit/modules/TorConnect.sys.mjs - toolkit/modules/TorSettings.sys.mjs Changes: ===================================== browser/components/torpreferences/content/builtinBridgeDialog.js ===================================== @@ -4,9 +4,8 @@ const { TorSettings, TorBridgeSource } = ChromeUtils.importESModule( "resource://gre/modules/TorSettings.sys.mjs" ); -const { TorConnect, TorConnectTopics } = ChromeUtils.importESModule( - "resource://gre/modules/TorConnect.sys.mjs" -); +const { TorConnect, TorConnectStage, TorConnectTopics } = + ChromeUtils.importESModule("resource://gre/modules/TorConnect.sys.mjs"); const gBuiltinBridgeDialog = { init() { @@ -96,7 +95,7 @@ const gBuiltinBridgeDialog = { }, onAcceptStateChange() { - const connect = TorConnect.canBeginBootstrap; + const connect = TorConnect.stageName !== TorConnectStage.Bootstrapped; this._result.connect = connect; this._acceptButton.setAttribute( "data-l10n-id", ===================================== browser/components/torpreferences/content/connectionPane.js ===================================== @@ -2257,6 +2257,8 @@ const gBridgeSettings = { } // Wait until the settings are applied before bootstrapping. + // NOTE: Saving the settings should also cancel any existing bootstrap + // attempt first. See tor-browser#41921. savedSettings.then(() => { // The bridge dialog button is "connect" when Tor is not // bootstrapped, so do the connect. ===================================== browser/components/torpreferences/content/provideBridgeDialog.js ===================================== @@ -3,9 +3,8 @@ const { TorSettings, TorBridgeSource, validateBridgeLines } = ChromeUtils.importESModule("resource://gre/modules/TorSettings.sys.mjs"); -const { TorConnect, TorConnectTopics } = ChromeUtils.importESModule( - "resource://gre/modules/TorConnect.sys.mjs" -); +const { TorConnect, TorConnectStage, TorConnectTopics } = + ChromeUtils.importESModule("resource://gre/modules/TorConnect.sys.mjs"); const { TorParsers } = ChromeUtils.importESModule( "resource://gre/modules/TorParsers.sys.mjs" @@ -190,7 +189,7 @@ const gProvideBridgeDialog = { "user-provide-bridge-dialog-next-button" ); } else { - connect = TorConnect.canBeginBootstrap; + connect = TorConnect.stageName !== TorConnectStage.Bootstrapped; this._acceptButton.setAttribute( "data-l10n-id", connect ? "bridge-dialog-button-connect" : "bridge-dialog-button-accept" ===================================== browser/components/torpreferences/content/requestBridgeDialog.js ===================================== @@ -4,9 +4,8 @@ const { BridgeDB } = ChromeUtils.importESModule( "resource://gre/modules/BridgeDB.sys.mjs" ); -const { TorConnect, TorConnectTopics } = ChromeUtils.importESModule( - "resource://gre/modules/TorConnect.sys.mjs" -); +const { TorConnect, TorConnectStage, TorConnectTopics } = + ChromeUtils.importESModule("resource://gre/modules/TorConnect.sys.mjs"); const log = console.createInstance({ maxLogLevel: "Warn", @@ -102,7 +101,7 @@ const gRequestBridgeDialog = { }, onAcceptStateChange() { - const connect = TorConnect.canBeginBootstrap; + const connect = TorConnect.stageName !== TorConnectStage.Bootstrapped; this._result.connect = connect; this._submitButton.setAttribute( "data-l10n-id", ===================================== toolkit/modules/TorConnect.sys.mjs ===================================== @@ -13,6 +13,7 @@ ChromeUtils.defineESModuleGetters(lazy, { TorProviderTopics: "resource://gre/modules/TorProviderBuilder.sys.mjs", TorLauncherUtil: "resource://gre/modules/TorLauncherUtil.sys.mjs", TorSettings: "resource://gre/modules/TorSettings.sys.mjs", + TorSettingsTopics: "resource://gre/modules/TorSettings.sys.mjs", }); const TorConnectPrefs = Object.freeze({ @@ -629,16 +630,6 @@ class AutoBootstrapAttempt { // Send the new settings directly to the provider. We will save them only // if the bootstrap succeeds. - // FIXME: We should somehow signal TorSettings users that we have set - // custom settings, and they should not apply theirs until we are done - // with trying ours. - // Otherwise, the new settings provided by the user while we were - // bootstrapping could be the ones that cause the bootstrap to succeed, - // but we overwrite them (unless we backup the original settings, and then - // save our new settings only if they have not changed). - // Another idea (maybe easier to implement) is to disable the settings - // UI while *any* bootstrap is going on. - // This is also documented in tor-browser#41921. await lazy.TorSettings.applyTemporaryBridges(bridges); if (this.#cancelled || this.#resolved) { @@ -1036,6 +1027,7 @@ export const TorConnect = { // register the Tor topics we always care about observeTopic(lazy.TorProviderTopics.ProcessExited); observeTopic(lazy.TorProviderTopics.HasWarnOrErr); + observeTopic(lazy.TorSettingsTopics.SettingsChanged); // NOTE: At this point, _requestedStage should still be `null`. this._setStage(TorConnectStage.Start); @@ -1070,8 +1062,32 @@ export const TorConnect = { Services.prefs.setBoolPref(TorConnectPrefs.prompt_at_startup, true); this._makeStageRequest(TorConnectStage.Start, true); break; - default: - // ignore + case lazy.TorSettingsTopics.SettingsChanged: + if ( + this._stageName !== TorConnectStage.Bootstrapped && + this._stageName !== TorConnectStage.Loading && + this._stageName !== TorConnectStage.Start && + subject.wrappedJSObject.changes.some(propertyName => + propertyName.startsWith("bridges.") + ) + ) { + // A change in bridge settings before we are bootstrapped, we reset + // the stage to Start to: + // + Cancel any ongoing bootstrap attempt. In particular, we + // definitely do not want to continue with an auto-bootstrap's + // temporary bridges if the settings have changed. + // + Reset the UI to be ready for normal bootstrapping in case the + // user returns to about:torconnect. + // See tor-browser#41921. + // NOTE: We do not reset in response to a change in the quickstart, + // firewall or proxy settings. + lazy.logger.warn( + "Resetting to Start stage since bridge settings changed" + ); + // Rather than cancel and return to the pre-bootstrap stage, we + // explicitly cancel and return to the start stage. + this._makeStageRequest(TorConnectStage.Start); + } break; } }, ===================================== toolkit/modules/TorSettings.sys.mjs ===================================== @@ -953,6 +953,7 @@ class TorSettingsImpl { }; if ("bridges" in newValues) { + const changesLength = changes.length; if ("source" in newValues.bridges) { this.#fixupBridgeSettings(newValues.bridges); changeSetting("bridges", "source", newValues.bridges.source); @@ -982,6 +983,19 @@ class TorSettingsImpl { if ("enabled" in newValues.bridges) { changeSetting("bridges", "enabled", newValues.bridges.enabled); } + + if (this.#temporaryBridgeSettings && changes.length !== changesLength) { + // A change in the bridges settings. + // We want to clear the temporary bridge settings to ensure that they + // cannot be used to overwrite these user-provided settings. + // See tor-browser#41921. + // NOTE: This should also trigger TorConnect to cancel any ongoing + // AutoBootstrap that would have otherwise used these settings. + this.#temporaryBridgeSettings = null; + lazy.logger.warn( + "Cleared temporary bridges since bridge settings were changed" + ); + } } if ("proxy" in newValues) { View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/0bb78c… -- View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/0bb78c… You're receiving this email because of your account on gitlab.torproject.org.
1 0
0 0
[Git][tpo/applications/tor-browser][tor-browser-128.6.0esr-14.5-1] fixup! [android] Add standalone Tor Bootstrap
by Pier Angelo Vendrame (@pierov) 21 Jan '25

21 Jan '25
Pier Angelo Vendrame pushed to branch tor-browser-128.6.0esr-14.5-1 at The Tor Project / Applications / Tor Browser Commits: 0bb78caa by clairehurst at 2025-01-21T16:51:39+00:00 fixup! [android] Add standalone Tor Bootstrap Bug 43368: Add @Suppress for linting error "Overriding method should call super. onNewIntent" - - - - - 1 changed file: - mobile/android/fenix/app/src/main/java/org/mozilla/fenix/HomeActivity.kt Changes: ===================================== mobile/android/fenix/app/src/main/java/org/mozilla/fenix/HomeActivity.kt ===================================== @@ -4,6 +4,7 @@ package org.mozilla.fenix +import android.annotation.SuppressLint import android.app.assist.AssistContent import android.app.PendingIntent import android.content.Context @@ -710,6 +711,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity, TorIn /** * Handles intents received when the activity is open. */ + @SuppressLint("MissingSuperCall") // super.onNewIntent is called in [onNewIntentInternal(intent)] final override fun onNewIntent(intent: Intent?) { if (intent?.action == ACTION_MAIN || components.torController.isConnected) { onNewIntentInternal(intent) View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/0bb78ca… -- View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/0bb78ca… You're receiving this email because of your account on gitlab.torproject.org.
1 0
0 0
[Git][tpo/applications/tor-browser][tor-browser-128.6.0esr-14.5-1] fixup! [android] Add standalone Tor Bootstrap
by Pier Angelo Vendrame (@pierov) 21 Jan '25

21 Jan '25
Pier Angelo Vendrame pushed to branch tor-browser-128.6.0esr-14.5-1 at The Tor Project / Applications / Tor Browser Commits: eabeaa5b by clairehurst at 2025-01-21T16:50:59+00:00 fixup! [android] Add standalone Tor Bootstrap Bug 43360: Replace custom variable isBeingRecreated with built-in isFinishing function - - - - - 1 changed file: - mobile/android/fenix/app/src/main/java/org/mozilla/fenix/HomeActivity.kt Changes: ===================================== mobile/android/fenix/app/src/main/java/org/mozilla/fenix/HomeActivity.kt ===================================== @@ -176,8 +176,6 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity, TorIn private var isToolbarInflated = false - private var isBeingRecreated = false - private val webExtensionPopupObserver by lazy { WebExtensionPopupObserver(components.core.store, ::openPopup) } @@ -652,7 +650,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity, TorIn stopMediaSession() } - if (!isBeingRecreated && !(application as FenixApplication).isTerminating()) { + if (isFinishing && !(application as FenixApplication).isTerminating()) { // We assume the Activity is being destroyed because the user // swiped away the app on the Recent screen. When this happens, // we assume the user expects the entire Application is destroyed @@ -686,8 +684,6 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity, TorIn message = "recreate()", ) - isBeingRecreated = true - super.recreate() } View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/eabeaa5… -- View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/eabeaa5… You're receiving this email because of your account on gitlab.torproject.org.
1 0
0 0
[Git][tpo/applications/tor-browser][tor-browser-128.6.0esr-14.5-1] fixup! [android] Implement Android-native Connection Assist UI
by Pier Angelo Vendrame (@pierov) 21 Jan '25

21 Jan '25
Pier Angelo Vendrame pushed to branch tor-browser-128.6.0esr-14.5-1 at The Tor Project / Applications / Tor Browser Commits: 8e5e2d5c by clairehurst at 2025-01-21T16:49:29+00:00 fixup! [android] Implement Android-native Connection Assist UI Bug 43359: Improper handling of TorBootstrapChangeListener with respect to system onDestroy() calls for HomeActivity - - - - - 1 changed file: - mobile/android/fenix/app/src/main/java/org/mozilla/fenix/HomeActivity.kt Changes: ===================================== mobile/android/fenix/app/src/main/java/org/mozilla/fenix/HomeActivity.kt ===================================== @@ -659,12 +659,13 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity, TorIn // and not only the top Activity/Task. Therefore we kill the // underlying Application, as well. (application as FenixApplication).terminate() - } - - val engine = components.core.engine - if (engine is GeckoEngine) { - val torIntegration = engine.getTorIntegrationController() - torIntegration.unregisterBootstrapStateChangeListener(this) + if (settings().useHtmlConnectionUi) { + val engine = components.core.engine + if (engine is GeckoEngine) { + val torIntegration = engine.getTorIntegrationController() + torIntegration.unregisterBootstrapStateChangeListener(this) + } + } } } View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/8e5e2d5… -- View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/8e5e2d5… You're receiving this email because of your account on gitlab.torproject.org.
1 0
0 0
[Git][tpo/applications/tor-browser][tor-browser-128.6.0esr-14.5-1] 4 commits: fixup! TB 40597: Implement TorSettings module
by Pier Angelo Vendrame (@pierov) 21 Jan '25

21 Jan '25
Pier Angelo Vendrame pushed to branch tor-browser-128.6.0esr-14.5-1 at The Tor Project / Applications / Tor Browser Commits: 4b7dc6cc by Henry Wilkes at 2025-01-21T15:54:08+00:00 fixup! TB 40597: Implement TorSettings module TB 41921: Do not wait for TorSettings to initialise before allowing a bootstrap. Instead, we wait for TorSettings as required: for preparing AutoBootstrap attempts, and TorBootstrapRequest should already wait for TorSettings before attempting to connect. - - - - - 34cfa54a by Henry Wilkes at 2025-01-21T15:54:13+00:00 fixup! TB 40933: Add tor-launcher functionality TB 41921: Ensure TorProviderBuilder.build can be called immediately after TorProviderBuilder.init returns (without await). We make sure that the `#provider` instance is created before any break in execution caused by an `await`. - - - - - 1dc47dd9 by Henry Wilkes at 2025-01-21T15:54:14+00:00 fixup! TB 42247: Android helpers for the TorProvider TB 41921: Do not wait for TorProviderBuilder.init since it is no longer async. - - - - - fff7daea by Henry Wilkes at 2025-01-21T15:54:14+00:00 fixup! TB 40933: Add tor-launcher functionality TB 41921: Add a note to TorBootstrapRequest explaining the expectation that the TorProvider has already read from TorSettings before it connects. - - - - - 4 changed files: - toolkit/components/tor-launcher/TorBootstrapRequest.sys.mjs - toolkit/components/tor-launcher/TorProviderBuilder.sys.mjs - toolkit/modules/TorAndroidIntegration.sys.mjs - toolkit/modules/TorConnect.sys.mjs Changes: ===================================== toolkit/components/tor-launcher/TorBootstrapRequest.sys.mjs ===================================== @@ -90,6 +90,11 @@ export class TorBootstrapRequest { // Wait for bootstrapping to begin and maybe handle error. // Notice that we do not resolve the promise here in case of success, but // we do it from the BootstrapStatus observer. + // NOTE: After TorProviderBuilder.build resolves, TorProvider.init will + // have completed. In particular, assuming no errors, the TorSettings will + // have been initialised and passed on to the provider via + // TorProvider.writeSettings. Therefore we should be safe to immediately + // call `connect` using the latest user settings. lazy.TorProviderBuilder.build() .then(provider => provider.connect()) .catch(err => { ===================================== toolkit/components/tor-launcher/TorProviderBuilder.sys.mjs ===================================== @@ -54,14 +54,15 @@ export class TorProviderBuilder { /** * Initialize the provider of choice. - * Even though initialization is asynchronous, we do not expect the caller to - * await this method. The reason is that any call to build() will wait the - * initialization anyway (and re-throw any initialization error). */ - static async init() { + static init() { switch (this.providerType) { case TorProviders.tor: - await this.#initTorProvider(); + // Even though initialization of the initial TorProvider is + // asynchronous, we do not expect the caller to await it. The reason is + // that any call to build() will wait the initialization anyway (and + // re-throw any initialization error). + this.#initTorProvider(); break; case TorProviders.none: lazy.TorLauncherUtil.setProxyConfiguration( @@ -74,7 +75,12 @@ export class TorProviderBuilder { } } - static async #initTorProvider() { + /** + * Replace #provider with a new instance. + * + * @returns {Promise<TorProvider>} The new instance. + */ + static #initTorProvider() { if (!this.#exitObserver) { this.#exitObserver = this.#torExited.bind(this); Services.obs.addObserver( @@ -83,18 +89,39 @@ export class TorProviderBuilder { ); } + // NOTE: We need to ensure that the #provider is set as soon + // TorProviderBuilder.init is called. + // I.e. it should be safe to call + // TorProviderBuilder.init(); + // TorProviderBuilder.build(); + // without any await. + // + // Therefore, we await the oldProvider within the Promise rather than make + // #initTorProvider async. + // + // In particular, this is needed by TorConnect when the user has selected + // quickstart, in which case `TorConnect.init` will immediately request the + // provider. See tor-browser#41921. + this.#provider = this.#replaceTorProvider(this.#provider); + return this.#provider; + } + + /** + * Replace a TorProvider instance. Resolves once the TorProvider is + * initialised. + * + * @param {Promise<TorProvider>?} oldProvider - The previous's provider's + * promise, if any. + * @returns {TorProvider} The new TorProvider instance. + */ + static async #replaceTorProvider(oldProvider) { try { - const old = await this.#provider; - old?.uninit(); + // Uninitialise the old TorProvider, if there is any. + (await oldProvider)?.uninit(); } catch {} - this.#provider = new Promise((resolve, reject) => { - const provider = new lazy.TorProvider(); - provider - .init() - .then(() => resolve(provider)) - .catch(reject); - }); - await this.#provider; + const provider = new lazy.TorProvider(); + await provider.init(); + return provider; } static uninit() { ===================================== toolkit/modules/TorAndroidIntegration.sys.mjs ===================================== @@ -68,9 +68,12 @@ class TorAndroidIntegrationImpl { Services.obs.addObserver(this, lazy.TorSettingsTopics[topic]); } - lazy.TorProviderBuilder.init().finally(() => { - lazy.TorProviderBuilder.firstWindowLoaded(); - }); + lazy.TorProviderBuilder.init(); + // On Android immediately call firstWindowLoaded. This should be safe to + // call since it will await the initialisation of the TorProvider set up + // by TorProviderBuilder.init. + lazy.TorProviderBuilder.firstWindowLoaded(); + try { await lazy.TorSettings.init(); await lazy.TorConnect.init(); ===================================== toolkit/modules/TorConnect.sys.mjs ===================================== @@ -10,7 +10,6 @@ ChromeUtils.defineESModuleGetters(lazy, { BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.sys.mjs", MoatRPC: "resource://gre/modules/Moat.sys.mjs", TorBootstrapRequest: "resource://gre/modules/TorBootstrapRequest.sys.mjs", - TorProviderBuilder: "resource://gre/modules/TorProviderBuilder.sys.mjs", TorProviderTopics: "resource://gre/modules/TorProviderBuilder.sys.mjs", TorLauncherUtil: "resource://gre/modules/TorLauncherUtil.sys.mjs", TorSettings: "resource://gre/modules/TorSettings.sys.mjs", @@ -436,15 +435,23 @@ class AutoBootstrapAttempt { return; } this.#resolved = true; - try { - // Run cleanup before we resolve the promise to ensure two instances - // of AutoBootstrapAttempt are not trying to change the settings at - // the same time. - if (arg.result !== "complete") { - await lazy.TorSettings.clearTemporaryBridges(); + + if (lazy.TorSettings.initialized) { + // If not initialized, then we won't have applied any settings. + try { + // Run cleanup before we resolve the promise to ensure two instances + // of AutoBootstrapAttempt are not trying to change the settings at + // the same time. + if (arg.result !== "complete") { + // Should do nothing if we never called applyTemporaryBridges. + await lazy.TorSettings.clearTemporaryBridges(); + } + } catch (error) { + lazy.logger.error( + "Unexpected error in auto-bootstrap cleanup", + error + ); } - } catch (error) { - lazy.logger.error("Unexpected error in auto-bootstrap cleanup", error); } if (arg.error) { reject(arg.error); @@ -483,6 +490,16 @@ class AutoBootstrapAttempt { * @param {BootstrapOptions} options - Options to apply to the bootstrap. */ async #runInternal(progressCallback, options) { + // Wait for TorSettings to be initialised, which is used for the + // AutoBootstrapping set up. + await Promise.race([ + lazy.TorSettings.initializedPromise, + this.#cancelledPromise, + ]); + if (this.#cancelled || this.#resolved) { + return; + } + await this.#fetchBridges(options); if (this.#cancelled || this.#resolved) { return; @@ -1016,19 +1033,20 @@ export const TorConnect = { lazy.logger.debug(`Observing topic '${addTopic}'`); }; - // Wait for TorSettings, as we will need it. - // We will wait for a TorProvider only after TorSettings is ready, - // because the TorProviderBuilder initialization might not have finished - // at this point, and TorSettings initialization is a prerequisite for - // having a provider. - // So, we prefer initializing TorConnect as soon as possible, so that - // the UI will be able to detect it is in the Initializing state and act - // consequently. - lazy.TorSettings.initializedPromise.then(() => this._settingsInitialized()); - // register the Tor topics we always care about observeTopic(lazy.TorProviderTopics.ProcessExited); observeTopic(lazy.TorProviderTopics.HasWarnOrErr); + + // NOTE: At this point, _requestedStage should still be `null`. + this._setStage(TorConnectStage.Start); + if ( + // Quickstart setting is enabled. + this.quickstart && + // And the previous bootstrap attempt must have succeeded. + !Services.prefs.getBoolPref(TorConnectPrefs.prompt_at_startup, true) + ) { + this.beginBootstrapping(); + } }, async observe(subject, topic) { @@ -1058,26 +1076,6 @@ export const TorConnect = { } }, - async _settingsInitialized() { - // TODO: Handle failures here, instead of the prompt to restart the - // daemon when it exits (tor-browser#21053, tor-browser#41921). - await lazy.TorProviderBuilder.build(); - - lazy.logger.debug("The TorProvider is ready, changing state."); - // NOTE: If the tor process exits before this point, then - // shouldQuickStart would be `false`. - // NOTE: At this point, _requestedStage should still be `null`. - this._setStage(TorConnectStage.Start); - if ( - // Quickstart setting is enabled. - this.quickstart && - // And the previous bootstrap attempt must have succeeded. - !Services.prefs.getBoolPref(TorConnectPrefs.prompt_at_startup, true) - ) { - this.beginBootstrapping(); - } - }, - /** * Set the user stage. * View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/b5cd60… -- View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/b5cd60… You're receiving this email because of your account on gitlab.torproject.org.
1 0
0 0
[Git][tpo/applications/tor-browser][tor-browser-128.6.0esr-14.5-1] 4 commits: fixup! TB 40597: Implement TorSettings module
by Pier Angelo Vendrame (@pierov) 21 Jan '25

21 Jan '25
Pier Angelo Vendrame pushed to branch tor-browser-128.6.0esr-14.5-1 at The Tor Project / Applications / Tor Browser Commits: 21b2be4c by Henry Wilkes at 2025-01-21T15:25:28+00:00 fixup! TB 40597: Implement TorSettings module TB 41921: Move quickstart setting from TorSettings to TorConnect. - - - - - cfd39fb0 by Henry Wilkes at 2025-01-21T15:25:29+00:00 fixup! TB 31286: Implementation of bridge, proxy, and firewall settings in about:preferences#connection TB 41921: Move quickstart setting from TorSettings to TorConnect. - - - - - 62e7a81f by Henry Wilkes at 2025-01-21T15:25:30+00:00 fixup! TB 27476: Implement about:torconnect captive portal within Tor Browser TB 41921: Move quickstart setting from TorSettings to TorConnect. This also means we no longer need to listen for TorSettingsTopics.Ready for the initial value. Also fix typo in signal name: "quickstart-changed" to "quickstart-change". - - - - - b5cd602f by Henry Wilkes at 2025-01-21T15:25:31+00:00 fixup! TB 42247: Android helpers for the TorProvider TB 41921: Move quickstart setting from TorSettings to TorConnect. - - - - - 5 changed files: - browser/components/torpreferences/content/connectionPane.js - toolkit/components/torconnect/TorConnectParent.sys.mjs - toolkit/modules/TorAndroidIntegration.sys.mjs - toolkit/modules/TorConnect.sys.mjs - toolkit/modules/TorSettings.sys.mjs Changes: ===================================== browser/components/torpreferences/content/connectionPane.js ===================================== @@ -2550,12 +2550,10 @@ const gConnectionPane = (function () { "torPreferences-quickstart-toggle" ); this._enableQuickstartCheckbox.addEventListener("command", () => { - TorSettings.changeSettings({ - quickstart: { enabled: this._enableQuickstartCheckbox.checked }, - }); + TorConnect.quickstart = this._enableQuickstartCheckbox.checked; }); - this._enableQuickstartCheckbox.checked = TorSettings.quickstart.enabled; - Services.obs.addObserver(this, TorSettingsTopics.SettingsChanged); + this._enableQuickstartCheckbox.checked = TorConnect.quickstart; + Services.obs.addObserver(this, TorConnectTopics.QuickstartChange); // Location { @@ -2667,7 +2665,7 @@ const gConnectionPane = (function () { gBridgeSettings.init(); gNetworkStatus.init(); - TorSettings.initializedPromise.then(() => this._populateXUL()); + this._populateXUL(); const onUnload = () => { window.removeEventListener("unload", onUnload); @@ -2681,7 +2679,7 @@ const gConnectionPane = (function () { gNetworkStatus.uninit(); // unregister our observer topics - Services.obs.removeObserver(this, TorSettingsTopics.SettingsChanged); + Services.obs.removeObserver(this, TorConnectTopics.QuickstartChange); Services.obs.removeObserver(this, TorConnectTopics.StageChange); }, @@ -2696,12 +2694,8 @@ const gConnectionPane = (function () { observe(subject, topic) { switch (topic) { - // triggered when a TorSettings param has changed - case TorSettingsTopics.SettingsChanged: { - if (subject.wrappedJSObject.changes.includes("quickstart.enabled")) { - this._enableQuickstartCheckbox.checked = - TorSettings.quickstart.enabled; - } + case TorConnectTopics.QuickstartChange: { + this._enableQuickstartCheckbox.checked = TorConnect.quickstart; break; } // triggered when tor connect state changes and we may @@ -2713,7 +2707,10 @@ const gConnectionPane = (function () { } }, - onAdvancedSettings() { + async onAdvancedSettings() { + // Ensure TorSettings is complete before loading the dialog, which reads + // from TorSettings. + await TorSettings.initializedPromise; gSubDialog.open( "chrome://browser/content/torpreferences/connectionSettingsDialog.xhtml", { features: "resizable=yes" } ===================================== toolkit/components/torconnect/TorConnectParent.sys.mjs ===================================== @@ -5,10 +5,6 @@ import { TorConnect, TorConnectTopics, } from "resource://gre/modules/TorConnect.sys.mjs"; -import { - TorSettings, - TorSettingsTopics, -} from "resource://gre/modules/TorSettings.sys.mjs"; const lazy = {}; @@ -47,15 +43,10 @@ export class TorConnectParent extends JSWindowActorParent { case TorConnectTopics.BootstrapProgress: self.sendAsyncMessage("torconnect:bootstrap-progress", obj); break; - case TorSettingsTopics.SettingsChanged: - if (!obj.changes.includes("quickstart.enabled")) { - break; - } - // eslint-disable-next-lined no-fallthrough - case TorSettingsTopics.Ready: + case TorConnectTopics.QuickstartChange: self.sendAsyncMessage( - "torconnect:quickstart-changed", - TorSettings.quickstart.enabled + "torconnect:quickstart-change", + TorConnect.quickstart ); break; } @@ -70,10 +61,9 @@ export class TorConnectParent extends JSWindowActorParent { this.torConnectObserver, TorConnectTopics.BootstrapProgress ); - Services.obs.addObserver(this.torConnectObserver, TorSettingsTopics.Ready); Services.obs.addObserver( this.torConnectObserver, - TorSettingsTopics.SettingsChanged + TorConnectTopics.QuickstartChange ); } @@ -88,11 +78,7 @@ export class TorConnectParent extends JSWindowActorParent { ); Services.obs.removeObserver( this.torConnectObserver, - TorSettingsTopics.Ready - ); - Services.obs.removeObserver( - this.torConnectObserver, - TorSettingsTopics.SettingsChanged + TorConnectTopics.QuickstartChange ); } @@ -104,7 +90,7 @@ export class TorConnectParent extends JSWindowActorParent { // If there are multiple home pages, just load the first one. return Promise.resolve(TorConnect.fixupURIs(lazy.HomePage.get())[0]); case "torconnect:set-quickstart": - TorSettings.changeSettings({ quickstart: { enabled: message.data } }); + TorConnect.quickstart = message.data; break; case "torconnect:open-tor-preferences": this.browsingContext.top.embedderElement.ownerGlobal.openPreferences( @@ -133,31 +119,16 @@ export class TorConnectParent extends JSWindowActorParent { case "torconnect:cancel-bootstrapping": TorConnect.cancelBootstrapping(); break; - case "torconnect:get-init-args": { + case "torconnect:get-init-args": // Called on AboutTorConnect.init(), pass down all state data it needs // to init. - - let quickstartEnabled = false; - - // Workaround for a race condition, but we should fix it asap. - // about:torconnect is loaded before TorSettings is actually initialized. - // The getter might throw and the page not loaded correctly as a result. - // Silence any warning for now, but we should really fix it. - // See also tor-browser#41921. - try { - quickstartEnabled = TorSettings.quickstart.enabled; - } catch (e) { - // Do not throw. - } - return { TorStrings, Direction: Services.locale.isAppLocaleRTL ? "rtl" : "ltr", CountryNames: TorConnect.countryNames, stage: TorConnect.stage, - quickstartEnabled, + quickstartEnabled: TorConnect.quickstart, }; - } case "torconnect:get-country-codes": return TorConnect.getCountryCodes(); } ===================================== toolkit/modules/TorAndroidIntegration.sys.mjs ===================================== @@ -79,6 +79,23 @@ class TorAndroidIntegrationImpl { } } + /** + * Combine the current TorSettings settings with the TorConnect settings. + * + * @returns {object} The TorSettings in an object, which also has a + * `quickstart.enabled` property. + */ + // This is added for backward compatibility with TorSettings.getSettings prior + // to tor-browser#41921, when it used to control the quickstart setting. + // TODO: Have android separate out the request for TorConnect.quickstart. In + // principle, this would allow android tor connect UI to be loaded before + // TorSettings has initialized (the SettingsReady signal), similar to desktop. + // See tor-browser#43408. + #getAllSettings() { + const settings = lazy.TorSettings.getSettings(); + settings.quickstart = { enabled: lazy.TorConnect.quickstart }; + } + observe(subj, topic) { switch (topic) { // TODO: Replace with StageChange. @@ -120,7 +137,7 @@ class TorAndroidIntegrationImpl { case lazy.TorSettingsTopics.Ready: lazy.EventDispatcher.instance.sendRequest({ type: EmittedEvents.settingsReady, - settings: lazy.TorSettings.getSettings(), + settings: this.#getAllSettings(), }); break; case lazy.TorSettingsTopics.SettingsChanged: @@ -129,7 +146,20 @@ class TorAndroidIntegrationImpl { lazy.EventDispatcher.instance.sendRequest({ type: EmittedEvents.settingsChanged, changes: subj.wrappedJSObject.changes ?? [], - settings: lazy.TorSettings.getSettings(), + settings: this.#getAllSettings(), + }); + break; + case lazy.TorConnectTopics.QuickstartChange: + // We also include the TorSettings, and a `changes` Array similar to + // SettingsChanged signal. This is for backward compatibility with + // TorSettings.getSettings prior to tor-browser#41921, when it used to + // control the quickstart setting. + // TODO: Have android separate out the request for TorConnect.quickstart. + // See tor-browser#43408. + lazy.EventDispatcher.instance.sendRequest({ + type: EmittedEvents.settingsChanged, + changes: ["quickstart.enabled"], + settings: this.#getAllSettings(), }); break; } @@ -140,9 +170,19 @@ class TorAndroidIntegrationImpl { try { switch (event) { case ListenedEvents.settingsGet: - callback?.onSuccess(lazy.TorSettings.getSettings()); + callback?.onSuccess(this.#getAllSettings()); return; case ListenedEvents.settingsSet: + // TODO: Set quickstart via a separate event. See tor-browser#43408. + // NOTE: Currently this may trigger GeckoView:Tor:SettingsChanged + // twice: once for quickstart.enabled, and again for the other + // settings. + if ( + "quickstart" in data.settings && + "enabled" in data.settings.quickstart + ) { + lazy.TorConnect.quickstart = data.settings.quickstart.enabled; + } // TODO: Handle setting throw? This can throw if data.settings is // incorrectly formatted, but more like it can throw when the settings // fail to be passed onto the TorProvider. tor-browser#43405. ===================================== toolkit/modules/TorConnect.sys.mjs ===================================== @@ -22,6 +22,7 @@ const TorConnectPrefs = Object.freeze({ log_level: "torbrowser.bootstrap.log_level", /* prompt_at_startup now controls whether the quickstart can trigger. */ prompt_at_startup: "extensions.torlauncher.prompt_at_startup", + quickstart: "torbrowser.settings.quickstart.enabled", }); export const TorConnectState = Object.freeze({ @@ -80,6 +81,7 @@ export const TorConnectTopics = Object.freeze({ StageChange: "torconnect:stage-change", // TODO: Remove torconnect:state-change when pages have switched to stage. StateChange: "torconnect:state-change", + QuickstartChange: "torconnect:quickstart-change", BootstrapProgress: "torconnect:bootstrap-progress", BootstrapComplete: "torconnect:bootstrap-complete", // TODO: Remove torconnect:error when pages have switched to stage. @@ -1066,8 +1068,12 @@ export const TorConnect = { // shouldQuickStart would be `false`. // NOTE: At this point, _requestedStage should still be `null`. this._setStage(TorConnectStage.Start); - if (this.shouldQuickStart) { - // Quickstart + if ( + // Quickstart setting is enabled. + this.quickstart && + // And the previous bootstrap attempt must have succeeded. + !Services.prefs.getBoolPref(TorConnectPrefs.prompt_at_startup, true) + ) { this.beginBootstrapping(); } }, @@ -1120,6 +1126,25 @@ export const TorConnect = { return lazy.TorLauncherUtil.shouldStartAndOwnTor; }, + /** + * Whether bootstrapping can begin immediately once Tor Browser has been + * opened. + * + * @type {boolean} + */ + get quickstart() { + return Services.prefs.getBoolPref(TorConnectPrefs.quickstart, false); + }, + + set quickstart(enabled) { + enabled = Boolean(enabled); + if (enabled === this.quickstart) { + return; + } + Services.prefs.setBoolPref(TorConnectPrefs.quickstart, enabled); + Services.obs.notifyObservers(null, TorConnectTopics.QuickstartChange); + }, + get shouldShowTorConnect() { // TorBrowser must control the daemon return ( @@ -1163,15 +1188,6 @@ export const TorConnect = { ); }, - get shouldQuickStart() { - // quickstart must be enabled - return ( - lazy.TorSettings.quickstart.enabled && - // and the previous bootstrap attempt must have succeeded - !Services.prefs.getBoolPref(TorConnectPrefs.prompt_at_startup, true) - ); - }, - // TODO: Remove when all pages have switched to "stage". get state() { // There is no "Error" stage, but about:torconnect relies on receiving the ===================================== toolkit/modules/TorSettings.sys.mjs ===================================== @@ -27,10 +27,8 @@ export const TorSettingsTopics = Object.freeze({ /* Prefs used to store settings in TorBrowser prefs */ const TorSettingsPrefs = Object.freeze({ - quickstart: { - /* bool: does tor connect automatically on launch */ - enabled: "torbrowser.settings.quickstart.enabled", - }, + // NOTE: torbrowser.settings.quickstart.enabled used to be managed by + // TorSettings but was moved to TorConnect.quickstart in tor-browser#41921. bridges: { /* bool: does tor use bridges */ enabled: "torbrowser.settings.bridges.enabled", @@ -173,9 +171,6 @@ class TorSettingsImpl { * @type {object} */ #settings = { - quickstart: { - enabled: false, - }, bridges: { /** * Whether the bridges are enabled or not. @@ -579,11 +574,6 @@ class TorSettingsImpl { #loadFromPrefs() { lazy.logger.debug("loadFromPrefs()"); - /* Quickstart */ - this.#settings.quickstart.enabled = Services.prefs.getBoolPref( - TorSettingsPrefs.quickstart.enabled, - false - ); /* Bridges */ const bridges = {}; bridges.enabled = Services.prefs.getBoolPref( @@ -691,11 +681,6 @@ class TorSettingsImpl { this.#checkIfInitialized(); - /* Quickstart */ - Services.prefs.setBoolPref( - TorSettingsPrefs.quickstart.enabled, - this.#settings.quickstart.enabled - ); /* Bridges */ Services.prefs.setBoolPref( TorSettingsPrefs.bridges.enabled, @@ -928,7 +913,6 @@ class TorSettingsImpl { * * It is possible to set all settings, or only some sections: * - * + quickstart.enabled can be set individually. * + bridges.enabled can be set individually. * + bridges.source can be set with a corresponding bridge specification for * the source (bridge_strings, lox_id, builtin_type). @@ -968,14 +952,6 @@ class TorSettingsImpl { changes.push(`${group}.${prop}`); }; - if ("quickstart" in newValues && "enabled" in newValues.quickstart) { - changeSetting( - "quickstart", - "enabled", - Boolean(newValues.quickstart.enabled) - ); - } - if ("bridges" in newValues) { if ("source" in newValues.bridges) { this.#fixupBridgeSettings(newValues.bridges); @@ -1048,11 +1024,7 @@ class TorSettingsImpl { // saved the preferences we send the new settings to TorProvider. // Some properties are unread by TorProvider. So if only these values change // there is no need to re-apply the settings. - const unreadProps = [ - "quickstart.enabled", - "bridges.builtin_type", - "bridges.lox_id", - ]; + const unreadProps = ["bridges.builtin_type", "bridges.lox_id"]; const shouldApply = changes.some(prop => !unreadProps.includes(prop)); if (shouldApply) { await this.#applySettings(true); View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/7a9894… -- View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/7a9894… You're receiving this email because of your account on gitlab.torproject.org.
1 0
0 0
[Git][tpo/applications/tor-browser][tor-browser-128.6.0esr-14.5-1] 4 commits: fixup! TB 40933: Add tor-launcher functionality
by Pier Angelo Vendrame (@pierov) 21 Jan '25

21 Jan '25
Pier Angelo Vendrame pushed to branch tor-browser-128.6.0esr-14.5-1 at The Tor Project / Applications / Tor Browser Commits: 1ad717fe by Henry Wilkes at 2025-01-21T14:56:40+00:00 fixup! TB 40933: Add tor-launcher functionality TB 41921: Ensure shouldStartAndOwnTor is constant per-session. TorConnect and TorSettings `enabled` properties depend on this value, and shouldn't change per session. - - - - - 8ae53510 by Henry Wilkes at 2025-01-21T14:56:41+00:00 fixup! TB 40597: Implement TorSettings module TB 41921: Tighten up TorSettings. We ensure TorSettings is enabled before certain operations. Also tidy up uninit to account for early calls (before init completes) or repeat calls. Also stop using "torbrowser.settings.enabled" preference, and read from the preferences for the first run. Also make TorSettings.initailizedPromise read-only. - - - - - a0c13700 by Henry Wilkes at 2025-01-21T14:56:41+00:00 fixup! TB 40562: Added Tor Browser preferences to 000-tor-browser.js TB 41921: Set default TorSetting setting values in 000-tor-browser.js. - - - - - 7a98943f by Henry Wilkes at 2025-01-21T15:00:22+00:00 fixup! TB 41435: Add a Tor Browser migration function TB 41921: Clear out unused "torbrowser.settings.enabled" preference. - - - - - 4 changed files: - browser/app/profile/000-tor-browser.js - browser/components/BrowserGlue.sys.mjs - toolkit/components/tor-launcher/TorLauncherUtil.sys.mjs - toolkit/modules/TorSettings.sys.mjs Changes: ===================================== browser/app/profile/000-tor-browser.js ===================================== @@ -61,6 +61,31 @@ pref("browser.startup.homepage", "about:tor"); // tor-browser#40701: Add new download warning pref("browser.download.showTorWarning", true); + +// Tor connection setting preferences. + +pref("torbrowser.settings.quickstart.enabled", false); +pref("torbrowser.settings.bridges.enabled", false); +// TorBridgeSource. Initially TorBridgeSource.Invalid = -1. +pref("torbrowser.settings.bridges.source", -1); +pref("torbrowser.settings.bridges.lox_id", ""); +// obfs4|meek-azure|snowflake|etc. +pref("torbrowser.settings.bridges.builtin_type", ""); +// torbrowser.settings.bridges.bridge_strings.0 +// torbrowser.settings.bridges.bridge_strings.1 +// etc hold the bridge lines. +pref("torbrowser.settings.proxy.enabled", false); +// TorProxyType. Initially TorProxyType.Invalid = -1. +pref("torbrowser.settings.proxy.type", -1); +pref("torbrowser.settings.proxy.address", ""); +pref("torbrowser.settings.proxy.port", 0); +pref("torbrowser.settings.proxy.username", ""); +pref("torbrowser.settings.proxy.password", ""); +pref("torbrowser.settings.firewall.enabled", false); +// comma-delimited list of port numbers. +pref("torbrowser.settings.firewall.allowed_ports", ""); + + // This pref specifies an ad-hoc "version" for various pref update hacks we need to do pref("extensions.torbutton.pref_fixup_version", 0); ===================================== browser/components/BrowserGlue.sys.mjs ===================================== @@ -4822,7 +4822,9 @@ BrowserGlue.prototype = { // YouTube search engines (tor-browser#41835). // Version 5: Tor Browser 14.0a5: Clear user preference for CFR settings // since we hid the UI (tor-browser#43118). - const TBB_MIGRATION_VERSION = 5; + // Version 6: Tor Browser 14.5a3: Clear preference for TorSettings that is + // no longer used (tor-browser#41921). + const TBB_MIGRATION_VERSION = 6; const MIGRATION_PREF = "torbrowser.migration.version"; // If we decide to force updating users to pass through any version @@ -4904,6 +4906,10 @@ BrowserGlue.prototype = { } } + if (currentVersion < 6) { + Services.prefs.clearUserPref("torbrowser.settings.enabled"); + } + Services.prefs.setIntPref(MIGRATION_PREF, TBB_MIGRATION_VERSION); }, ===================================== toolkit/components/tor-launcher/TorLauncherUtil.sys.mjs ===================================== @@ -17,8 +17,6 @@ const kPropBundleURI = "chrome://torbutton/locale/torlauncher.properties"; const kPropNamePrefix = "torlauncher."; const kIPCDirPrefName = "extensions.torlauncher.tmp_ipc_dir"; -let gStringBundle = null; - /** * This class allows to lookup for the paths of the various files that are * needed or can be used with the tor daemon, such as its configuration, the @@ -332,7 +330,7 @@ class TorFile { } } -export const TorLauncherUtil = Object.freeze({ +export const TorLauncherUtil = { get isAndroid() { return Services.appinfo.OS === "Android"; }, @@ -417,6 +415,8 @@ export const TorLauncherUtil = Object.freeze({ return this.showConfirm(null, s, defaultBtnLabel, cancelBtnLabel); }, + _stringBundle: null, + // Localized Strings // TODO: Switch to fluent also these ones. @@ -425,6 +425,9 @@ export const TorLauncherUtil = Object.freeze({ if (!aStringName) { return aStringName; } + if (!this._stringBundle) { + this._stringBundle = Services.strings.createBundle(kPropBundleURI); + } try { const key = kPropNamePrefix + aStringName; return this._stringBundle.GetStringFromName(key); @@ -587,7 +590,12 @@ export const TorLauncherUtil = Object.freeze({ Services.prefs.savePrefFile(null); }, - get shouldStartAndOwnTor() { + /** + * Determine the current value for whether we should start and own Tor. + * + * @returns {boolean} Whether we should start and own Tor. + */ + _getShouldStartAndOwnTor() { const kPrefStartTor = "extensions.torlauncher.start_tor"; try { const kBrowserToolboxPort = "MOZ_BROWSER_TOOLBOX_PORT"; @@ -610,6 +618,29 @@ export const TorLauncherUtil = Object.freeze({ return Services.prefs.getBoolPref(kPrefStartTor, true); }, + /** + * Cached value for shouldStartAndOwnTor, or `null` if not yet initialised. + * + * @type {boolean} + */ + _shouldStartAndOwnTor: null, + + /** + * Whether we should start and own Tor. + * + * The value should be constant per-session. + * + * @type {boolean} + */ + get shouldStartAndOwnTor() { + // Do not want this value to change within the same session, so always used + // the cached valued if it is available. + if (this._shouldStartAndOwnTor === null) { + this._shouldStartAndOwnTor = this._getShouldStartAndOwnTor(); + } + return this._shouldStartAndOwnTor; + }, + get shouldShowNetworkSettings() { try { const kEnvForceShowNetConfig = "TOR_FORCE_NET_CONFIG"; @@ -668,11 +699,4 @@ export const TorLauncherUtil = Object.freeze({ console.warn("Could not remove the IPC directory", e); } }, - - get _stringBundle() { - if (!gStringBundle) { - gStringBundle = Services.strings.createBundle(kPropBundleURI); - } - return gStringBundle; - }, -}); +}; ===================================== toolkit/modules/TorSettings.sys.mjs ===================================== @@ -27,8 +27,6 @@ export const TorSettingsTopics = Object.freeze({ /* Prefs used to store settings in TorBrowser prefs */ const TorSettingsPrefs = Object.freeze({ - /* bool: are we pulling tor settings from the preferences */ - enabled: "torbrowser.settings.enabled", quickstart: { /* bool: does tor connect automatically on launch */ enabled: "torbrowser.settings.quickstart.enabled", @@ -245,6 +243,13 @@ class TorSettingsImpl { */ #builtinBridges = {}; + /** + * A promise that resolves once we are initialized, or throws if there was an + * initialization error. + * + * @type {Promise} + */ + #initializedPromise; /** * Resolve callback of the initializedPromise. */ @@ -261,8 +266,29 @@ class TorSettingsImpl { */ #initialized = false; + /** + * Whether uninit cleanup has been called. + * + * @type {boolean} + */ + #uninitCalled = false; + + /** + * Whether Lox was initialized. + * + * @type {boolean} + */ + #initializedLox = false; + + /** + * Whether observers were initialized. + * + * @type {boolean} + */ + #initializedObservers = false; + constructor() { - this.initializedPromise = new Promise((resolve, reject) => { + this.#initializedPromise = new Promise((resolve, reject) => { this.#initComplete = resolve; this.#initFailed = reject; }); @@ -378,12 +404,22 @@ class TorSettingsImpl { return this.#builtinBridges[pt] ?? []; } + /** + * Whether this module is enabled. + * + * @type {boolean} + */ + get enabled() { + return lazy.TorLauncherUtil.shouldStartAndOwnTor; + } + /** * Load or init our settings. */ async init() { if (this.#initialized) { lazy.logger.warn("Called init twice."); + await this.#initializedPromise; return; } try { @@ -402,6 +438,11 @@ class TorSettingsImpl { * it easier to update initializatedPromise. */ async #initInternal() { + if (!this.enabled || this.#uninitCalled) { + // Nothing to do. + return; + } + try { const req = await fetch("chrome://global/content/pt_config.json"); const config = await req.json(); @@ -419,26 +460,37 @@ class TorSettingsImpl { lazy.logger.error("Could not load the built-in PT config.", e); } + // `uninit` may have been called whilst we awaited pt_config. + if (this.#uninitCalled) { + lazy.logger.warn("unint was called before init completed."); + return; + } + // Initialize this before loading from prefs because we need Lox initialized // before any calls to Lox.getBridges(). if (!lazy.TorLauncherUtil.isAndroid) { try { + // Set as initialized before calling to ensure it is cleaned up by our + // `uninit` method. + this.#initializedLox = true; await lazy.Lox.init(); } catch (e) { lazy.logger.error("Could not initialize Lox.", e); } } - if ( - lazy.TorLauncherUtil.shouldStartAndOwnTor && - Services.prefs.getBoolPref(TorSettingsPrefs.enabled, false) - ) { - this.#loadFromPrefs(); - // We do not pass on the loaded settings to the TorProvider yet. Instead - // TorProvider will ask for these once it has initialised. + // `uninit` may have been called whilst we awaited Lox.init. + if (this.#uninitCalled) { + lazy.logger.warn("unint was called before init completed."); + return; } + this.#loadFromPrefs(); + // We do not pass on the loaded settings to the TorProvider yet. Instead + // TorProvider will ask for these once it has initialised. + Services.obs.addObserver(this, lazy.LoxTopics.UpdateBridges); + this.#initializedObservers = true; lazy.logger.info("Ready"); } @@ -447,8 +499,22 @@ class TorSettingsImpl { * Unload or uninit our settings. */ async uninit() { - Services.obs.removeObserver(this, lazy.LoxTopics.UpdateBridges); - await lazy.Lox.uninit(); + if (this.#uninitCalled) { + lazy.logger.warn("Called uninit twice"); + return; + } + + this.#uninitCalled = true; + // NOTE: We do not reset #initialized to false because we want it to remain + // in place for external callers, and we do not want `#initInternal` to be + // re-entered. + + if (this.#initializedObservers) { + Services.obs.removeObserver(this, lazy.LoxTopics.UpdateBridges); + } + if (this.#initializedLox) { + await lazy.Lox.uninit(); + } } observe(subject, topic) { @@ -473,10 +539,13 @@ class TorSettingsImpl { } /** - * Check whether the object has been successfully initialized, and throw if - * it has not. + * Check whether the module is enabled and successfully initialized, and throw + * if it is not. */ #checkIfInitialized() { + if (!this.enabled) { + throw new Error("TorSettings is not enabled"); + } if (!this.#initialized) { lazy.logger.trace("Not initialized code path."); throw new Error( @@ -494,6 +563,16 @@ class TorSettingsImpl { return this.#initialized; } + /** + * A promise that resolves once we are initialized, or throws if there was an + * initialization error. + * + * @type {Promise} + */ + get initializedPromise() { + return this.#initializedPromise; + } + /** * Load our settings from prefs. */ @@ -701,9 +780,6 @@ class TorSettingsImpl { } else { Services.prefs.clearUserPref(TorSettingsPrefs.firewall.allowed_ports); } - - // all tor settings now stored in prefs :) - Services.prefs.setBoolPref(TorSettingsPrefs.enabled, true); } /** View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/06cbcd… -- View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/06cbcd… You're receiving this email because of your account on gitlab.torproject.org.
1 0
0 0
  • ← Newer
  • 1
  • ...
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • ...
  • 765
  • Older →

HyperKitty Powered by HyperKitty version 1.3.12.