While creating build system that works across the platforms, one can find issues in the most basic things. And that's even when shell is the same. For example, while Bash on Linux and Windows works out the same, a lot of supporting tools differ - a lot. And there's no better example than creating a zip archive.
Under Linux you can count on zip
command being available. Even if one doesn't have it, it's easy to install without messing with their desktop. On Windows story gets more complicated. Git Bash for example doesn't have it even compiled and there's no really good way to add it. Yes, you can use any application but different one is installed on every system. To create more "fun", supporting multiple applications also means dealing with their command-line arguments. And yes, 7-Zip has completely different syntax as compared to WinRAR.
However, when it comes to making zip archive, there's actually a solution that works for both Windows (via Git Bash) and Linux. Surprisingly, the answer is perl
.
If one is careful to use Perl's older IO::Compress::Zip
library, creating an archive becomes a simple task:
Codeperl -e '
use strict;
use warnings;
use autodie;
use IO::Compress::Zip qw(:all);
zip [
"src/mimetype",
<"src/META-INF/*.*">,
<"src/OEBPS/*.*">,
<"src/OEBPS/chapters/*.*">
] => "bin/book.epub",
FilterName => sub { s[^src/][] },
Zip64 => 0,
or die "Zip failed: $ZipError\n";
'
Yeah, might not be ideal when it comes to beauty but it definitely works across platforms.
One thought to “Zip in Git Bash”