Skip to content

Commit c3eec3e

Browse files
dschoGit for Windows Build Agent
authored andcommitted
Merge branch 'busybox-w32'
Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 700ee9d + 37f9b11 commit c3eec3e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+481
-212
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*.perl eol=lf diff=perl
55
*.pl eof=lf diff=perl
66
*.pm eol=lf diff=perl
7+
*.png binary
78
*.py eol=lf diff=python
89
*.bat eol=crlf
910
/Documentation/**/*.txt eol=lf

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,7 @@ PROGRAMS += $(patsubst %.o,git-%$X,$(PROGRAM_OBJS))
698698
TEST_BUILTINS_OBJS += test-bloom.o
699699
TEST_BUILTINS_OBJS += test-advise.o
700700
TEST_BUILTINS_OBJS += test-chmtime.o
701+
TEST_BUILTINS_OBJS += test-cmp.o
701702
TEST_BUILTINS_OBJS += test-config.o
702703
TEST_BUILTINS_OBJS += test-ctype.o
703704
TEST_BUILTINS_OBJS += test-date.o
@@ -714,6 +715,7 @@ TEST_BUILTINS_OBJS += test-genzeros.o
714715
TEST_BUILTINS_OBJS += test-hash-speed.o
715716
TEST_BUILTINS_OBJS += test-hash.o
716717
TEST_BUILTINS_OBJS += test-hashmap.o
718+
TEST_BUILTINS_OBJS += test-iconv.o
717719
TEST_BUILTINS_OBJS += test-index-version.o
718720
TEST_BUILTINS_OBJS += test-json-writer.o
719721
TEST_BUILTINS_OBJS += test-lazy-init-name-hash.o

compat/mingw.c

Lines changed: 73 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "dir.h"
1212
#include "win32/fscache.h"
1313
#include "../attr.h"
14+
#include "../string-list.h"
1415

1516
#define HCAST(type, handle) ((type)(intptr_t)handle)
1617

@@ -1485,6 +1486,65 @@ static char *lookup_prog(const char *dir, int dirlen, const char *cmd,
14851486
return NULL;
14861487
}
14871488

1489+
static char *path_lookup(const char *cmd, int exe_only);
1490+
1491+
static char *is_busybox_applet(const char *cmd)
1492+
{
1493+
static struct string_list applets = STRING_LIST_INIT_DUP;
1494+
static char *busybox_path;
1495+
static int busybox_path_initialized;
1496+
1497+
/* Avoid infinite loop */
1498+
if (!strncasecmp(cmd, "busybox", 7) &&
1499+
(!cmd[7] || !strcasecmp(cmd + 7, ".exe")))
1500+
return NULL;
1501+
1502+
if (!busybox_path_initialized) {
1503+
busybox_path = path_lookup("busybox.exe", 1);
1504+
busybox_path_initialized = 1;
1505+
}
1506+
1507+
/* Assume that sh is compiled in... */
1508+
if (!busybox_path || !strcasecmp(cmd, "sh"))
1509+
return xstrdup_or_null(busybox_path);
1510+
1511+
if (!applets.nr) {
1512+
struct child_process cp = CHILD_PROCESS_INIT;
1513+
struct strbuf buf = STRBUF_INIT;
1514+
char *p;
1515+
1516+
argv_array_pushl(&cp.args, busybox_path, "--help", NULL);
1517+
1518+
if (capture_command(&cp, &buf, 2048)) {
1519+
string_list_append(&applets, "");
1520+
return NULL;
1521+
}
1522+
1523+
/* parse output */
1524+
p = strstr(buf.buf, "Currently defined functions:\n");
1525+
if (!p) {
1526+
warning("Could not parse output of busybox --help");
1527+
string_list_append(&applets, "");
1528+
return NULL;
1529+
}
1530+
p = strchrnul(p, '\n');
1531+
for (;;) {
1532+
size_t len;
1533+
1534+
p += strspn(p, "\n\t ,");
1535+
len = strcspn(p, "\n\t ,");
1536+
if (!len)
1537+
break;
1538+
p[len] = '\0';
1539+
string_list_insert(&applets, p);
1540+
p = p + len + 1;
1541+
}
1542+
}
1543+
1544+
return string_list_has_string(&applets, cmd) ?
1545+
xstrdup(busybox_path) : NULL;
1546+
}
1547+
14881548
/*
14891549
* Determines the absolute path of cmd using the split path in path.
14901550
* If cmd contains a slash or backslash, no lookup is performed.
@@ -1513,6 +1573,9 @@ static char *path_lookup(const char *cmd, int exe_only)
15131573
path = sep + 1;
15141574
}
15151575

1576+
if (!prog && !isexe)
1577+
prog = is_busybox_applet(cmd);
1578+
15161579
return prog;
15171580
}
15181581

@@ -1712,8 +1775,8 @@ static int is_msys2_sh(const char *cmd)
17121775
}
17131776

17141777
static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaenv,
1715-
const char *dir,
1716-
int prepend_cmd, int fhin, int fhout, int fherr)
1778+
const char *dir, const char *prepend_cmd,
1779+
int fhin, int fhout, int fherr)
17171780
{
17181781
static int restrict_handle_inheritance = -1;
17191782
STARTUPINFOEXW si;
@@ -1804,9 +1867,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
18041867
/* concatenate argv, quoting args as we go */
18051868
strbuf_init(&args, 0);
18061869
if (prepend_cmd) {
1807-
char *quoted = (char *)quote_arg(cmd);
1870+
char *quoted = (char *)quote_arg(prepend_cmd);
18081871
strbuf_addstr(&args, quoted);
1809-
if (quoted != cmd)
1872+
if (quoted != prepend_cmd)
18101873
free(quoted);
18111874
}
18121875
for (; *argv; argv++) {
@@ -1965,7 +2028,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
19652028
return (pid_t)pi.dwProcessId;
19662029
}
19672030

1968-
static pid_t mingw_spawnv(const char *cmd, const char **argv, int prepend_cmd)
2031+
static pid_t mingw_spawnv(const char *cmd, const char **argv,
2032+
const char *prepend_cmd)
19692033
{
19702034
return mingw_spawnve_fd(cmd, argv, NULL, NULL, prepend_cmd, 0, 1, 2);
19712035
}
@@ -1993,14 +2057,14 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **deltaenv,
19932057
pid = -1;
19942058
}
19952059
else {
1996-
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, 1,
2060+
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, interpr,
19972061
fhin, fhout, fherr);
19982062
free(iprog);
19992063
}
20002064
argv[0] = argv0;
20012065
}
20022066
else
2003-
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, 0,
2067+
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, NULL,
20042068
fhin, fhout, fherr);
20052069
free(prog);
20062070
}
@@ -2028,7 +2092,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
20282092
argv2[0] = (char *)cmd; /* full path to the script file */
20292093
COPY_ARRAY(&argv2[1], &argv[1], argc);
20302094
exec_id = trace2_exec(prog, argv2);
2031-
pid = mingw_spawnv(prog, argv2, 1);
2095+
pid = mingw_spawnv(prog, argv2, interpr);
20322096
if (pid >= 0) {
20332097
int status;
20342098
if (waitpid(pid, &status, 0) < 0)
@@ -2052,7 +2116,7 @@ int mingw_execv(const char *cmd, char *const *argv)
20522116
int exec_id;
20532117

20542118
exec_id = trace2_exec(cmd, (const char **)argv);
2055-
pid = mingw_spawnv(cmd, (const char **)argv, 0);
2119+
pid = mingw_spawnv(cmd, (const char **)argv, NULL);
20562120
if (pid < 0) {
20572121
trace2_exec_result(exec_id, -1);
20582122
return -1;

config.mak.uname

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,62 @@ else
684684
NO_CURL = YesPlease
685685
endif
686686
endif
687+
ifeq (i686,$(uname_M))
688+
MINGW_PREFIX := mingw32
689+
endif
690+
ifeq (x86_64,$(uname_M))
691+
MINGW_PREFIX := mingw64
692+
endif
693+
694+
DESTDIR_WINDOWS = $(shell cygpath -aw '$(DESTDIR_SQ)')
695+
DESTDIR_MIXED = $(shell cygpath -am '$(DESTDIR_SQ)')
696+
install-mingit-test-artifacts:
697+
install -m755 -d '$(DESTDIR_SQ)/usr/bin'
698+
printf '%s\n%s\n' >'$(DESTDIR_SQ)/usr/bin/perl' \
699+
"#!/mingw64/bin/busybox sh" \
700+
"exec \"$(shell cygpath -am /usr/bin/perl.exe)\" \"\$$@\""
701+
702+
install -m755 -d '$(DESTDIR_SQ)'
703+
printf '%s%s\n%s\n%s\n%s\n%s\n' >'$(DESTDIR_SQ)/init.bat' \
704+
"PATH=$(DESTDIR_WINDOWS)\\$(MINGW_PREFIX)\\bin;" \
705+
"C:\\WINDOWS;C:\\WINDOWS\\system32" \
706+
"@set GIT_TEST_INSTALLED=$(DESTDIR_MIXED)/$(MINGW_PREFIX)/bin" \
707+
"@`echo "$(DESTDIR_WINDOWS)" | sed 's/:.*/:/'`" \
708+
"@cd `echo "$(DESTDIR_WINDOWS)" | sed 's/^.://'`\\test-git\\t" \
709+
"@echo Now, run 'helper\\test-run-command testsuite'"
710+
711+
install -m755 -d '$(DESTDIR_SQ)/test-git'
712+
sed 's/^\(NO_PERL\|NO_PYTHON\)=.*/\1=YesPlease/' \
713+
<GIT-BUILD-OPTIONS >'$(DESTDIR_SQ)/test-git/GIT-BUILD-OPTIONS'
714+
715+
install -m755 -d '$(DESTDIR_SQ)/test-git/t/helper'
716+
install -m755 $(TEST_PROGRAMS) '$(DESTDIR_SQ)/test-git/t/helper'
717+
(cd t && $(TAR) cf - t[0-9][0-9][0-9][0-9] diff-lib) | \
718+
(cd '$(DESTDIR_SQ)/test-git/t' && $(TAR) xf -)
719+
install -m755 t/t556x_common t/*.sh '$(DESTDIR_SQ)/test-git/t'
720+
721+
install -m755 -d '$(DESTDIR_SQ)/test-git/templates'
722+
(cd templates && $(TAR) cf - blt) | \
723+
(cd '$(DESTDIR_SQ)/test-git/templates' && $(TAR) xf -)
724+
725+
# po/build/locale for t0200
726+
install -m755 -d '$(DESTDIR_SQ)/test-git/po/build/locale'
727+
(cd po/build/locale && $(TAR) cf - .) | \
728+
(cd '$(DESTDIR_SQ)/test-git/po/build/locale' && $(TAR) xf -)
729+
730+
# git-daemon.exe for t5802, git-http-backend.exe for t5560
731+
install -m755 -d '$(DESTDIR_SQ)/$(MINGW_PREFIX)/bin'
732+
install -m755 git-daemon.exe git-http-backend.exe \
733+
'$(DESTDIR_SQ)/$(MINGW_PREFIX)/bin'
734+
735+
# git-upload-archive (dashed) for t5000
736+
install -m755 -d '$(DESTDIR_SQ)/$(MINGW_PREFIX)/bin'
737+
install -m755 git-upload-archive.exe '$(DESTDIR_SQ)/$(MINGW_PREFIX)/bin'
738+
739+
# git-difftool--helper for t7800
740+
install -m755 -d '$(DESTDIR_SQ)/$(MINGW_PREFIX)/libexec/git-core'
741+
install -m755 git-difftool--helper \
742+
'$(DESTDIR_SQ)/$(MINGW_PREFIX)/libexec/git-core'
687743
endif
688744
ifeq ($(uname_S),QNX)
689745
COMPAT_CFLAGS += -DSA_RESTART=0

git-sh-setup.sh

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -333,17 +333,30 @@ create_virtual_base() {
333333
# Platform specific tweaks to work around some commands
334334
case $(uname -s) in
335335
*MINGW*)
336-
# Windows has its own (incompatible) sort and find
337-
sort () {
338-
/usr/bin/sort "$@"
339-
}
340-
find () {
341-
/usr/bin/find "$@"
342-
}
343-
# git sees Windows-style pwd
344-
pwd () {
345-
builtin pwd -W
346-
}
336+
if test -x /usr/bin/sort
337+
then
338+
# Windows has its own (incompatible) sort; override
339+
sort () {
340+
/usr/bin/sort "$@"
341+
}
342+
fi
343+
if test -x /usr/bin/find
344+
then
345+
# Windows has its own (incompatible) find; override
346+
find () {
347+
/usr/bin/find "$@"
348+
}
349+
fi
350+
# On Windows, Git wants Windows paths. But /usr/bin/pwd spits out
351+
# Unix-style paths. At least in Bash, we have a builtin pwd that
352+
# understands the -W option to force "mixed" paths, i.e. with drive
353+
# prefix but still with forward slashes. Let's use that, if available.
354+
if type builtin >/dev/null 2>&1
355+
then
356+
pwd () {
357+
builtin pwd -W
358+
}
359+
fi
347360
is_absolute_path () {
348361
case "$1" in
349362
[/\\]* | [A-Za-z]:*)
File renamed without changes.
File renamed without changes.

t/helper/test-cmp.c

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#include "test-tool.h"
2+
#include "git-compat-util.h"
3+
#include "strbuf.h"
4+
#include "gettext.h"
5+
#include "parse-options.h"
6+
#include "run-command.h"
7+
8+
#ifdef WIN32
9+
#define NO_SUCH_DIR "\\\\.\\GLOBALROOT\\invalid"
10+
#else
11+
#define NO_SUCH_DIR "/dev/null"
12+
#endif
13+
14+
static int run_diff(const char *path1, const char *path2)
15+
{
16+
const char *argv[] = {
17+
"diff", "--no-index", NULL, NULL, NULL
18+
};
19+
const char *env[] = {
20+
"GIT_PAGER=cat",
21+
"GIT_DIR=" NO_SUCH_DIR,
22+
"HOME=" NO_SUCH_DIR,
23+
NULL
24+
};
25+
26+
argv[2] = path1;
27+
argv[3] = path2;
28+
return run_command_v_opt_cd_env(argv,
29+
RUN_COMMAND_NO_STDIN | RUN_GIT_CMD,
30+
NULL, env);
31+
}
32+
33+
int cmd__cmp(int argc, const char **argv)
34+
{
35+
FILE *f0, *f1;
36+
struct strbuf b0 = STRBUF_INIT, b1 = STRBUF_INIT;
37+
38+
if (argc != 3)
39+
die("Require exactly 2 arguments, got %d", argc);
40+
41+
if (!(f0 = !strcmp(argv[1], "-") ? stdin : fopen(argv[1], "r")))
42+
return error_errno("could not open '%s'", argv[1]);
43+
if (!(f1 = !strcmp(argv[2], "-") ? stdin : fopen(argv[2], "r"))) {
44+
fclose(f0);
45+
return error_errno("could not open '%s'", argv[2]);
46+
}
47+
48+
for (;;) {
49+
int r0 = strbuf_getline(&b0, f0);
50+
int r1 = strbuf_getline(&b1, f1);
51+
52+
if (r0 == EOF) {
53+
fclose(f0);
54+
fclose(f1);
55+
strbuf_release(&b0);
56+
strbuf_release(&b1);
57+
if (r1 == EOF)
58+
return 0;
59+
cmp_failed:
60+
if (!run_diff(argv[1], argv[2]))
61+
die("Huh? 'diff --no-index %s %s' succeeded",
62+
argv[1], argv[2]);
63+
return 1;
64+
}
65+
if (r1 == EOF || strbuf_cmp(&b0, &b1)) {
66+
fclose(f0);
67+
fclose(f1);
68+
strbuf_release(&b0);
69+
strbuf_release(&b1);
70+
goto cmp_failed;
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)