Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

Commit

Permalink
swc-windows-installer.py: Install GNU Make from gnuwin32
Browse files Browse the repository at this point in the history
The Make binary in msysGit doesn't work with the MSys2-based Git for
Windows, raising [1]:

  The program can't start because msys-1.0.dll is missing from your
  computer.

The gnuwin32 [2] binaries are built from GNU Make v3.81 (2006-04-01 [3]),
but they run without crashing [4].

We need the dependencies to avoid [5]:

   The program can't start because libintl3.dll is missing from your
   computer.

Somewhat suspicously, the MD5 digest of the dependencies I got from
SourceForge (2edb5b27ab0818b727fb43494dc40a5f) doesn't match the MD5
digest listed on [2] (d370415aa924fa023411c4099ef84563).  The size is
the same though (708206 bytes), so I'm guessing the gnuwin32 listing
is just stale.  I downloaded the dependency zip from several
SourceForge mirrors using several hosts, and always got the same
digests, so if the hash-mismatch is malicious, the attacker is doing a
good job ;).

I also updated zip_install to take an optional 'path' argument, so we
can unpack several zips to the same directory (without it, we'd get
the "existing installation" message for the second zip).

_MakeDirsError works around the change in makedirs errors between
Python 2 [6] and Python 3 [7].

[1]: #34 (comment)
[2]: http://gnuwin32.sourceforge.net/packages/make.htm
[3]: http://git.savannah.gnu.org/cgit/make.git/tag/?id=3.81
[4]: #34 (comment)
[5]: #35 (comment)
[6]: https://docs.python.org/2/library/os.html#os.makedirs
[7]: https://docs.python.org/3/library/os.html#os.makedirs
  • Loading branch information
wking committed Nov 20, 2015
1 parent dd2a712 commit 8107c0d
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions swc-windows-installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@


if sys.version_info >= (3, 0): # Python 3
_MakeDirsError = OSError
open3 = open
else:
_MakeDirsError = os.error
def open3(file, mode='r', newline=None):
if newline:
if newline != '\n':
Expand Down Expand Up @@ -131,29 +133,36 @@ def tar_install(url, sha1, install_directory, compression='*',
LOG.info('existing installation at {}'.format(install_directory))


def zip_install(url, sha1, install_directory):
def zip_install(url, sha1, install_directory, path=None):
"""Download and install a zipped bundle"""
if not os.path.isdir(install_directory):
if path is None:
path = install_directory
if not os.path.exists(path):
zip_bytes = download(url=url, sha1=sha1)
zip_io = _BytesIO(zip_bytes)
zip_file = zipfile.ZipFile(zip_io)
LOG.info('installing {} into {}'.format(url, install_directory))
os.makedirs(install_directory)
try:
os.makedirs(install_directory)
except _MakeDirsError:
pass
zip_file.extractall(install_directory)
else:
LOG.info('existing installation at {}'.format(install_directory))


def install_msysgit_binary(name, sha1, install_directory,
tag='Git-1.9.4-preview20140815'):
"""Download and install a binary from msysGit's bin directory"""
bytes = download(
url='https://github.com/msysgit/msysgit/raw/{}/bin/{}'.format(
tag, name),
sha1=sha1)
LOG.info('installing {} into {}'.format(name, install_directory))
with open(os.path.join(install_directory, name), 'wb') as f:
f.write(bytes)
def install_make(install_directory):
"""Download and install GNU Make"""
zip_install(
url='http://downloads.sourceforge.net/project/gnuwin32/make/3.81/make-3.81-bin.zip',
sha1='7c1e23a93e6cb78975f36efd22d598241b1f0e8b',
install_directory=install_directory,
path=os.path.join(install_directory, 'bin', 'make.exe'))
zip_install(
url='http://downloads.sourceforge.net/project/gnuwin32/make/3.81/make-3.81-dep.zip',
sha1='ee90e45c1bacc24a0c3852a95fc6dcfbcabe802b',
install_directory=install_directory,
path=os.path.join(install_directory, 'bin', 'libiconv2.dll'))


def install_nano(install_directory):
Expand Down Expand Up @@ -274,17 +283,17 @@ def make_posix_path(windows_path):
def main():
swc_dir = os.path.join(os.path.expanduser('~'), '.swc')
bin_dir = os.path.join(swc_dir, 'bin')
make_dir = os.path.join(swc_dir, 'lib', 'make')
make_bin = os.path.join(make_dir, 'bin')
nano_dir = os.path.join(swc_dir, 'lib', 'nano')
nanorc_dir = os.path.join(swc_dir, 'share', 'nanorc')
sqlite_dir = os.path.join(swc_dir, 'lib', 'sqlite')
create_nosetests_entry_point(python_scripts_directory=bin_dir)
install_msysgit_binary(
name='make.exe', sha1='ad11047985c33ff57074f8e09d347fe122e047a4',
install_directory=bin_dir)
install_make(install_directory=make_dir)
install_nano(install_directory=nano_dir)
install_nanorc(install_directory=nanorc_dir)
install_sqlite(install_directory=sqlite_dir)
paths = [nano_dir, sqlite_dir, bin_dir]
paths = [make_bin, nano_dir, sqlite_dir, bin_dir]
r_dir = get_r_bin_directory()
if r_dir:
paths.append(r_dir)
Expand Down

0 comments on commit 8107c0d

Please sign in to comment.