Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/update git bash string resource editor #118

Conversation

fourpastmidnight
Copy link
Contributor

@fourpastmidnight fourpastmidnight commented May 30, 2016

@dscho: Could you please look this over?

  • Move Makefile and edit-git-bash.c to build-extra since both InnoSetup and MSI installers require this to edit git-bash.exe string resources.
  • Ensure that edit-git-bash.{dll,exe} update string resources using the original git-bash.exe locale of LCID 1033 (0x0409, a/k/a en-US).

@fourpastmidnight
Copy link
Contributor Author

It appears some commit messages could use a bit of "fine tuning" to be a bit more accurate.

@dscho
Copy link
Member

dscho commented May 30, 2016

Would you mind signing off on the patches?

I am not quite sure we would want to specify an output directory, but rather move the .dll as well, adjusting installer/install.iss and .gitignore for the new path.

Other than that, I really like this PR!

@fourpastmidnight
Copy link
Contributor Author

Thanks! I'll make the suggested changes and sign off on everything.

@fourpastmidnight
Copy link
Contributor Author

@dscho: Since you want me to change .gitignore, are you implying that edit-git-bash.{dll,exe} should be compiled as part of the release process when creating the installers?

@dscho
Copy link
Member

dscho commented Jun 1, 2016

Since you want me to change .gitignore, are you implying that edit-git-bash.{dll,exe} should be compiled as part of the release process when creating the installers?

I think we can keep the .dll precompiled (it must be 32-bit because InnoSetup itself is 32-bit and could not load a 64-bit .dll in-process if it wanted to). If you use the .exe in the MSI-based installer, I would like to compile it on the fly (via the Makefile, i.e. avoiding unnecessary recompiles).

But now that I come to think of it: it is really dirty to use a precompiled .dll. Since we already require the cross-compilation toolchain to build MINGW packages (both 32-bit and 64-bit packages are built in the 64-bit SDK if you use the please.sh helper), we could easily (cross-)compile the .dll. Or just go ahead and use the .exe in the InnoSetup-based installer, too...

What do you think?

@fourpastmidnight
Copy link
Contributor Author

I think I agree that both the DLL and EXE should be compiled as part of the release process. When changes were made to edit-git-bash.c in the past, the DLL has forgotten to be recompiled (it's an easy enough thing to forget!). Having it compiled as part of the release process makes this much less likely.

I was having trouble making it cross-compile. The Makefile isn't set up for that (it doesn't work on my machine, anyway), and I'm even having trouble trying to do it manually. I didn't check the please.sh script; I'll take a look at that script. That may solve the problem.

I don't think it makes much of a difference whether we use the EXE or the DLL in the InnoSetup installer. If we use the EXE, could we retain the DontCopy flag and still be able to execute it? Something tells me no; it doesn't work that way in the MSI either. The EXE will need to be copied to the disk, executed, and optionally deleted, much like we do with post-install.bat. For MSI, I don't have much choice; for InnoSetup, if the EXE would work the way I think it would, I'd rather keep using the DLL.

@fourpastmidnight
Copy link
Contributor Author

The please.sh script won't solve my problem of being able to cross-compile edit-git-bash.c as a 32-bit DLL for the InnoSetup installer from the 64-bit SDK. I must not have something setup correctly in my SDK environment (though, I see a lot of people online having trouble with MinGW and cross-compiling--but they're all on Linux boxes and I'm on a Windows box in a specialized MinGW environment for building Git, so I'm having trouble relating the solutions to my environment).

@dscho
Copy link
Member

dscho commented Jun 3, 2016

I was having trouble making it cross-compile. The Makefile isn't set up for tha

This seems to work for me:

diff --git a/installer/Makefile b/installer/Makefile
index 73737e1..89de752 100644
--- a/installer/Makefile
+++ b/installer/Makefile
@@ -4,7 +4,8 @@ DLLINKFLAGS=-Wl,--kill-at -static-libgcc -shared
 all: edit-git-bash.dll

 edit-git-bash.dll: edit-git-bash.c
-   gcc $(CFLAGS) $(DLLINKFLAGS) -o $@ $^
+   PATH=/mingw32/bin:$$PATH \
+   i686-w64-mingw32-gcc -march=i686 $(CFLAGS) $(DLLINKFLAGS) -o $@ $^

 edit-git-bash.exe: edit-git-bash.c
    gcc -DSTANDALONE_EXE $(CFLAGS) -o $@ $^

(I have not tested the .dll in an installer, though)

If we use the EXE, could we retain the DontCopy flag and still be able to execute it?

I think we should be able to use it; We use the .dll, after all, so why not the .exe (with an absolute path)?

@fourpastmidnight
Copy link
Contributor Author

fourpastmidnight commented Jun 3, 2016

Thanks, I'll check it out.

...why not the .exe (with an absolute path)?

The DLL is never copied to disk, it's loaded into memory by the installer process and the method within is exported. To my knowledge, there's nothing preventing a EXE from exporting functions, so it might work.

I'll give it a try. The worst that could happen is it doesn't work.


Well, my knowledge was (mostly) wrong. I think I'm going to go with the path of least resistance: keep using edit-git-bash.dll in InnoSetup and use the EXE in the MSI.

@fourpastmidnight
Copy link
Contributor Author

fourpastmidnight commented Jun 4, 2016

Thanks @dscho, it compiled. I should've known it was that simple. I'll do a few tests to make sure everything works ok.

The InnoSetup installer requires `edit-git-bash.c` to be compiled to a
DLL, though currently, this is not compiled as part of the overall release
process. This DLL is used by the installer to modify the `git-bash.exe`
string resources responsible for starting the terminal emulator for hosting
the BASH. It comes into play when the installing user chooses to use the
standard Windows Command Console over the default mintty terminal emulator.

The new MSI installer also needs a way to modify `git-bash.exe` string
resources to achieve the same effect. The easiest way to accomplish this
is to compile `edit-git-bash.c` as an EXE and use a custom action to call
the `edit-git-bash.exe` to modify `git-bash.exe`.

Therefore, this commit moves the make file and `edit-git-bash.c` to the
top-level `build-extra` directory since it's a resource now required by
more than one installer.

Likewise, the .gitignore has been updated to ignore `edit-git-bash.dll`
and `edit-git-bash.exe`.

Signed-off-by: Craig E. Shea <[email protected]>
Signed-off-by: Craig E. Shea <[email protected]>
When this developer compiled `edit-git-bash.c` to an EXE,
`edit-git-bash.exe` did not behave as expected. Two string tables appeared
in the resources section of the resulting `git-bash.exe` executable.

Furthermore, this did _not_ occur when installing Git for Windows 2.7.2
using the InnoSetup installer on a test VM. However, this developer did
confirm a problem with this program.

When installing Git for Windows 2.7.2 and choosing the Windows Command
Console as the terminal emulator, the string resources for `git-bash.exe`
were updated. In fact, all resources were wiped out of `git-bash.exe` and
a new STRINGTABLE resource was created containing the command to execute
to start the BASH shell in a Windows Command Console. Resources that were
wiped out included the Git for Windows icons that are embedded in the
`git-bash.dll` (the file size went from 137KB to 28KB). This appears to be
due to the fact that
1. This DLL is not recompiled from source whenever an installer is
generated
2. The existing `edit-git-bash.dll` was compiled from an earlier version
of the source which replaced resources instead of just updating them

When this developer compiled the current source of `edit-git-bash.c` and
proceeded to run the resulting EXE on `git-bash.exe`, `git-bash.exe` now
contained two string tables in its resources section of the executable,
both with ID 1. How can this be? It turns out the original `git-bash.exe`
string table resources were added using LCID 1033 (0x0409 a/k/a en-US
locale). The EXE produced by the current `edit-git-bash.c` updated
`git-bash.exe` resources using the LCID 1024 (0x0400, language-neutral,
default sub-language). Since the source code is now _updating_ the
resources, and not replacing them, the net effect was to add a second
string table. Apparently, then, string table are uniquely identified by
their ID and (at least) their locale.

Why does this matter? Because my computer is set to LCID 1033 (en-US),
so when `git-bash.exe` was executed, it used the original string resources
(the one matching my current computer's Locale) and started the BASH in
mintty, not the Windows Command Console.

Furthermore, when looking at the embedded resources for the installation
of Git for Windows 2.7.2 set to use the Windows Command Console for the
BASH, it worked correctly even though the string resources were for LCID
1024 (the neutral locale). That's because there was only one STRINGTABLE,
(since the resources in that version of the DLL were being completely
replaced) and the neutral locale is the fallback locale. Since a string
table resource for LCID 1033 could not be found, the neutral resources were
used, resulting in correct behavior.

This commit, then, changes the updating of the string resources in
`git-bash.exe` such that the new string resources are written in LCID
1033, just as the original resources of `git-bash.exe` are. This will
prevent additional string table resources (in different locales) from
being created and ensure that the proper resources are updated, resulting
in correct behavior.

Signed-off-by: Craig E. Shea <[email protected]>
@fourpastmidnight fourpastmidnight force-pushed the feature/UpdateGitBashStringResourceEditor branch from 33f8d98 to e22d6b2 Compare June 4, 2016 03:16
@fourpastmidnight
Copy link
Contributor Author

@dscho: Could I borrow your eyes once more? 😄

Just a note: I plan on making more changes to Makefile, but since that's MSI-related for the TERMINAL option, I'm going to do that on another branch I have for implementing that option in the MSI to keep the set of changes for that MSI option all together.

edit-git-bash.dll: edit-git-bash.c
gcc $(CFLAGS) $(DLLINKFLAGS) -o $@ $^
PATH=/mingw32/bin:$$PATH \
i686-w64-mingw32-gcc -march=i686 $(CFLAGS) $(DLLINKFLAGS) -o $@ $^

This comment was marked as off-topic.

This comment was marked as off-topic.

@fourpastmidnight fourpastmidnight force-pushed the feature/UpdateGitBashStringResourceEditor branch from e22d6b2 to fcb1446 Compare June 4, 2016 04:49
@dscho
Copy link
Member

dscho commented Jun 4, 2016

InnoSetup in only 32-bit "aware"

s/in/is/

CC = PATH=/mingw32/bin:$$PATH i686-w64-mingw32-gcc -march=i686
endif
endif

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

@dscho
Copy link
Member

dscho commented Jun 4, 2016

Good work!

As I said in the comments, I'd prefer to hardcode the (cross-)compiler in the .dll rule, as it makes things obvious, and it works in the intended setup (which is really all I care about).

After that, I think this PR is ready to go!

The Makefile was modified to ensure that `edit-git-bash.c` is always
compiled as a 32-bit DLL when the `edit-git-bash.dll` target is invoked.
InnoSetup is only 32-bit "aware", so even for the 64-bit distribution, a
32-bit DLL needs to be used.

The InnoSetup `release.sh` script was updated to include building
`edit-git-bash.dll`. The rendering of release notes was moved until after
all argument processing; this also had the advantage of placing the call
to `make` directly after it--these activities are sort of "pre-processing"
before the actual generation of the installer and made logical sense to
this developer.

Lastly, the `install.iss` file was updated to source the DLL from it's new
location in `build-extra`; the old edit-git-bash.dll in the `installer`
directory was deleted.

Signed-off-by: Craig E. Shea <[email protected]>
@fourpastmidnight fourpastmidnight force-pushed the feature/UpdateGitBashStringResourceEditor branch from fcb1446 to 8710041 Compare June 4, 2016 14:54
@fourpastmidnight
Copy link
Contributor Author

@dscho: OK, fixed that commit message typo and reverted to the last Makefile implementation with the hard-coded 32-bit gcc.

@dscho dscho merged commit 0a2fe06 into git-for-windows:master Jun 5, 2016
@dscho
Copy link
Member

dscho commented Jun 5, 2016

Excellent! Thank you so much!

dscho added a commit that referenced this pull request Jun 5, 2016
When configuring Git Bash with Windows'
default console, it [no longer loses its
icon](#118).

Signed-off-by: Johannes Schindelin <[email protected]>
@fourpastmidnight fourpastmidnight deleted the feature/UpdateGitBashStringResourceEditor branch June 5, 2016 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants