Closed Bug 1748762 Opened 2 years ago Closed 2 years ago

Support Windows Terminal's -d parameter and other "starting folder" behaviors

Categories

(Firefox Build System :: MozillaBuild, defect)

Desktop
Windows
defect

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: aminomancer, Assigned: mhentges)

References

Details

Attachments

(2 files)

Windows Terminal has a command line parameter -d whereby the user can open a shell to a chosen folder, e.g., wt -d C:\mozilla-source\mozilla-central. This works for other unix shells integrated within Windows Terminal, but not for MozillaBuild shell.

Windows Terminal has a settings GUI that lets you create a profile for a shell. If you choose MozillaBuild's start-shell.bat as the shell, it works great. But within this GUI there's 1) an option to set the starting directory to some absolute path or environment path variable, and 2) an option to "Use parent process directory," meaning the shell will open in the working directory from which Windows Terminal was invoked.

Neither of these behaviors works with MozillaBuild shell, I think because the shell is jumping to the $HOME directory after the fact. It's possible to add your own static "starting directory" by making a file $HOME/.profile with contents like cd C:\mozilla-source\mozilla-central but I'm not aware of any straightforward way to make this dynamic such that it supports the -d parameter or the WT starting directory settings.

msys2_shell.cmd provides a -here option, so there's ways to work around the cwd-resetting.
I'll play with this a bit, we should be able to include this for 4.0.

Assignee: nobody → mhentges
Blocks: 1739443

For developers who prefer the Command Prompt instead of MinTTY as their
terminal, or those who don't want their $PATH reset, pass through
options to msys2_shell.cmd.

Users can enumerate MSYS2's options with start-shell.bat -help.

Note that this breaks the start-shell.bat <bash commands> use case,
which will need to be ported to start-shell.bat -c <bash commands>
(or, more correctly,
start-shell.bat -no-start -defterm -c <bash commands>).
Fortunately, that case was rare, so impact should be minor.

Depends on D135186

Explicit docs around Windows Terminal support are in the pipeline, but this change should work for ya.
A couple things:

  1. You'll need to wait for the release of MozillaBuild 4.0 to be able to leverage this improvement
  2. In your Windows Terminal profile for MozillaBuild, set "commandline": "C:/mozilla-build/start-shell.bat -no-start -defterm -here".

Awesome!

Attachment #9257767 - Attachment description: Bug 1748762: Expose `msys2_shell.cmd` to callers → WIP: Bug 1748762: Expose `msys2_shell.cmd` to callers
Attachment #9257767 - Attachment description: WIP: Bug 1748762: Expose `msys2_shell.cmd` to callers → Bug 1748762: Expose `msys2_shell.cmd` to callers

For a little bit, compatibility with MACH_PS1_USE_MOZILLABUILD will be
maintained, though the recent work in bug 1740123 should entirely
obsolete it. It's staying around //for now// so that regressions in
1740123 don't unnecessarily impede workflows.

However, MACH_PS1_USE_MOZILLABUILD has some serious drawbacks already
(can't have whitespace in arguments, can't pass braces to Mach, etc).
This patch still has these drawbacks, because they're tricky to solve.

In a couple months, once bug 1740123 has settled nicely, we'll remove
support for MACH_PS1_USE_MOZILLABUILD.

Depends on D136286

Pushed by mhentges@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/8aa3c3bbd075
Update mach.ps1 to always support MozillaBuild 4.0 r=saschanaz
Status: UNCONFIRMED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Pushed by mhentges@mozilla.com:
https://hg.mozilla.org/mozilla-build/rev/674d46ce8355
Expose `msys2_shell.cmd` to callers r=glandium
See Also: → 1753063

I just tried 4.0 and followed the windows terminal instructions but it doesn't seem to work for me. Always opens in mozilla-central.

{
    "name": "MozillaBuild",
    "commandline": "C:/mozilla-build/start-shell.bat -here",
    "startingDirectory": "C:\\",
}

Same thing with wt -d C:\, with or without the startingDirectory parameter. I also tried C:/mozilla-build/start-shell.bat -no-start -defterm -here with the same results.

Edit: Ignore the above, this is my own fault. Before 4.0, I added cd C:/mozilla-source/mozilla-central; to my .bash_profile to serve the same purpose as the startingDirectory parameter, and forgot I did so.

Btw idk if this is due to something I did, but I used to be able to run mach build (like without the ./) but now it returns bash: mach: command not found unless I use ./mach build.

Edit: If anyone else is missing the same ^ try adding this line to your .bashrc/.bash_profile file: alias mach="./mach";

Btw idk if this is due to something I did, but I used to be able to run mach build (like without the ./) but now it returns bash: mach: command not found unless I use ./mach build.

FWIW, I'd recommend running ./mach with the explicit relative path (./), to avoid issues where the wrong mach is implicitly called (such as if you have multiple checkouts, and one of them is added the $PATH for unrelated reasons). There's a little more discussion around this in this patch.

Product: mozilla.org → Firefox Build System
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: