{"thread":{"id":"27374","subject":"[PATCH] add Android support","startedAt":"2011-05-16T20:08:23Z","lastAt":"2011-05-19T17:30:41Z","messageCount":5,"participants":["Rafael Gieschke","Junio C Hamano","Daniel Stenberg"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"168011","messageId":"D2F37FDB-20C2-401A-AA90-DB4A50C27123@gieschke.de","threadId":"27374","inReplyTo":null,"subject":"[PATCH] add Android support","fromName":"Rafael Gieschke","fromEmail":"rafael@gieschke.de","sentAt":"2011-05-16T20:08:23Z","receivedAt":"2011-05-16T20:08:23Z","isPatch":true,"sender":{"key":"rafael@gieschke.de","avatar":"https://avatars.githubusercontent.com/u/6069565?v=4"},"body":"\nCurrently, it is not possible to compile git for Android as the C library (Bionic)\nis neither providing getpass nor pw_gecos in struct passwd. Therefore,\nNO_GETPASS and NO_PW_GECOS are defined in Makefile. As code for Android can only\nbe cross-compiled, ANDROID is defined.\n\nSigned-off-by: Rafael Gieschke <rafael@gieschke.de>\n---\n Makefile  |   27 +++++++++++++++++++++++++++\n connect.c |    4 ++++\n ident.c   |    7 ++++++-\n 3 files changed, 37 insertions(+), 1 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex c4db5af..e010efb 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -71,6 +71,11 @@ all::\n #\n # Define NO_STRTOK_R if you don't have strtok_r in the C library.\n #\n+# Define NO_GETPASS if you don't have getpass in the C library.\n+#\n+# Define NO_PW_GECOS if you don't have pw_gecos in struct passwd\n+# in the C library.\n+#\n # Define NO_FNMATCH if you don't have fnmatch in the C library.\n #\n # Define NO_FNMATCH_CASEFOLD if your fnmatch function doesn't have the\n@@ -248,6 +253,8 @@ all::\n # dependency rules.\n #\n # Define NATIVE_CRLF if your platform uses CRLF for line endings.\n+#\n+# Define ANDROID if you are cross-compiling for Android.\n \n GIT-VERSION-FILE: FORCE\n \t@$(SHELL_PATH) ./GIT-VERSION-GEN\n@@ -789,6 +796,20 @@ ifeq ($(uname_S),OSF1)\n \tNO_STRTOULL = YesPlease\n \tNO_NSEC = YesPlease\n endif\n+ifdef ANDROID\n+\tuname_S := Linux\n+\tNO_GETPASS = YesPlease\n+\tNO_PW_GECOS = YesPlease\n+\tNO_NSEC = YesPlease\n+\tNO_MKDTEMP = YesPlease\n+\tNO_PTHREADS = YesPlease\n+\tNO_PERL = YesPlease\n+\tNO_OPENSSL = YesPlease\n+\tNO_CURL = YesPlease\n+\tNO_EXPAT = YesPlease\n+\tNO_TCLTK = YesPlease\n+\tNO_ICONV = YesPlease\n+endif\n ifeq ($(uname_S),Linux)\n \tNO_STRLCPY = YesPlease\n \tNO_MKSTEMPS = YesPlease\n@@ -1404,6 +1425,12 @@ ifdef NO_STRTOK_R\n \tCOMPAT_CFLAGS += -DNO_STRTOK_R\n \tCOMPAT_OBJS += compat/strtok_r.o\n endif\n+ifdef NO_GETPASS\n+\tCOMPAT_CFLAGS += -DNO_GETPASS\n+endif\n+ifdef NO_PW_GECOS\n+\tCOMPAT_CFLAGS += -DNO_PW_GECOS\n+endif\n ifdef NO_FNMATCH\n \tCOMPAT_CFLAGS += -Icompat/fnmatch\n \tCOMPAT_CFLAGS += -DNO_FNMATCH\ndiff --git a/connect.c b/connect.c\nindex 57dc20c..15b285e 100644\n--- a/connect.c\n+++ b/connect.c\n@@ -632,7 +632,11 @@ char *git_getpass(const char *prompt)\n \tif (!askpass)\n \t\taskpass = getenv(\"SSH_ASKPASS\");\n \tif (!askpass || !(*askpass)) {\n+\t\t#ifndef NO_GETPASS\n \t\tchar *result = getpass(prompt);\n+\t\t#else\n+\t\tchar *result = NULL;\n+\t\t#endif\n \t\tif (!result)\n \t\t\tdie_errno(\"Could not read password\");\n \t\treturn result;\ndiff --git a/ident.c b/ident.c\nindex 1c4adb0..76fa786 100644\n--- a/ident.c\n+++ b/ident.c\n@@ -20,7 +20,12 @@ static void copy_gecos(const struct passwd *w, char *name, size_t sz)\n \t * with commas.  Also & stands for capitalized form of the login name.\n \t */\n \n-\tfor (len = 0, dst = name, src = w->pw_gecos; len < sz; src++) {\n+\t#ifndef NO_PW_GECOS\n+\tsrc = w->pw_gecos;\n+\t#else\n+\tsrc = \"&\";\n+\t#endif\n+\tfor (len = 0, dst = name; len < sz; src++) {\n \t\tint ch = *src;\n \t\tif (ch != '&') {\n \t\t\t*dst++ = ch;\n-- \n1.7.4\n"},{"id":"168018","messageId":"7vzkmmjqpx.fsf@alter.siamese.dyndns.org","threadId":"27374","inReplyTo":"D2F37FDB-20C2-401A-AA90-DB4A50C27123@gieschke.de","subject":"Re: [PATCH] add Android support","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-05-16T21:11:22Z","receivedAt":"2011-05-16T21:11:22Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Rafael Gieschke <rafael@gieschke.de> writes:\n\n> diff --git a/connect.c b/connect.c\n> index 57dc20c..15b285e 100644\n> --- a/connect.c\n> +++ b/connect.c\n> @@ -632,7 +632,11 @@ char *git_getpass(const char *prompt)\n>  \tif (!askpass)\n>  \t\taskpass = getenv(\"SSH_ASKPASS\");\n>  \tif (!askpass || !(*askpass)) {\n> +\t\t#ifndef NO_GETPASS\n>  \t\tchar *result = getpass(prompt);\n> +\t\t#else\n> +\t\tchar *result = NULL;\n> +\t\t#endif\n>  \t\tif (!result)\n>  \t\t\tdie_errno(\"Could not read password\");\n>  \t\treturn result;\n> diff --git a/ident.c b/ident.c\n> index 1c4adb0..76fa786 100644\n> --- a/ident.c\n> +++ b/ident.c\n> @@ -20,7 +20,12 @@ static void copy_gecos(const struct passwd *w, char *name, size_t sz)\n>  \t * with commas.  Also & stands for capitalized form of the login name.\n>  \t */\n>  \n> -\tfor (len = 0, dst = name, src = w->pw_gecos; len < sz; src++) {\n> +\t#ifndef NO_PW_GECOS\n> +\tsrc = w->pw_gecos;\n> +\t#else\n> +\tsrc = \"&\";\n> +\t#endif\n> +\tfor (len = 0, dst = name; len < sz; src++) {\n>  \t\tint ch = *src;\n>  \t\tif (ch != '&') {\n>  \t\t\t*dst++ = ch;\n\nPlease do not throw in conditional compilation in a codepath that is\notherwise generic.\n\nDo something like this near the beginning of the file (or if they are\ncommon, in an appropriate header):\n\n        #ifdef NO_GETPASS\n        #define getpass(ignored) NULL\n        #endif\n\n        #ifdef NO_PW_GECOS\n        #define get_gecos(ignored) \"&\"\n        #else\n        #define get_gecos(struct_passwd) (struct_passwd->pw_gecos)\n        #endif\n\nThat way, you do not have to change connect.c at all, and the code that\naccesses gecos field would get a slight abstraction, i.e.\n\n\tfor (len = 0, dst = name, src = get_gecos(w); len < sz; src++) {\n\t\t...\n\nI however suspect that NO_GETPASS would be a useless thing in the longer\nterm. Wouldn't you rather wish to have a native Android UI that asks a\npassword and plug that implementation as a replacement for git_getpass()?\n\nIt might be worthwhile to study how mingw folks do this part before you\ndive in and butcher this codepath in a way you may regret later.\n"},{"id":"168031","messageId":"D01E807D-C82C-4A8F-9678-9CEA92C413DA@gieschke.de","threadId":"27374","inReplyTo":"7vzkmmjqpx.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] add Android support","fromName":"Rafael Gieschke","fromEmail":"rafael@gieschke.de","sentAt":"2011-05-16T23:23:22Z","receivedAt":"2011-05-16T23:23:22Z","isPatch":true,"sender":{"key":"rafael@gieschke.de","avatar":"https://avatars.githubusercontent.com/u/6069565?v=4"},"body":"\nAm 16.05.2011 um 23:11 schrieb Junio C Hamano:\n\n> Please do not throw in conditional compilation in a codepath that is\n> otherwise generic.\n> \n> Do something like this near the beginning of the file (or if they are\n> common, in an appropriate header):\n> \n>        #ifdef NO_GETPASS\n>        #define getpass(ignored) NULL\n>        #endif\n> \n>        #ifdef NO_PW_GECOS\n>        #define get_gecos(ignored) \"&\"\n>        #else\n>        #define get_gecos(struct_passwd) (struct_passwd->pw_gecos)\n>        #endif\n> \n> That way, you do not have to change connect.c at all, and the code that\n> accesses gecos field would get a slight abstraction, i.e.\n> \n> \tfor (len = 0, dst = name, src = get_gecos(w); len < sz; src++) {\n> \t\t...\n> \n\nThanks. Great idea, didn't think about that. See new patch.\n\n> I however suspect that NO_GETPASS would be a useless thing in the longer\n> term. Wouldn't you rather wish to have a native Android UI that asks a\n> password and plug that implementation as a replacement for git_getpass()?\n> \n> It might be worthwhile to study how mingw folks do this part before you\n> dive in and butcher this codepath in a way you may regret later.\n> \n\n\nI don't think that it is a lot of fun to call Android UI code from C as it is normally only done from Java.\n\nThe same problem occurs in dropbear on Android. There, it is solved by including a NetBSD version of getpass.c: https://github.com/CyanogenMod/android_external_dropbear/blob/master/netbsd_getpass.c .\n\nIf including NetBSD code is okay, the new patch will work. There currently is very limited use for this on Android, however, as there is no libcurl by default on Android. So, the only usage is git-imap-send, which works fine with this patch.\n\nCompiling libcurl for Android should be possible with some work, though. So compat/getpass.c would be used for libcurl/HTTP access, too.\n"},{"id":"168049","messageId":"alpine.DEB.2.00.1105170842490.30333@tvnag.unkk.fr","threadId":"27374","inReplyTo":"D01E807D-C82C-4A8F-9678-9CEA92C413DA@gieschke.de","subject":"Re: [PATCH] add Android support","fromName":"Daniel Stenberg","fromEmail":"daniel@haxx.se","sentAt":"2011-05-17T06:44:11Z","receivedAt":"2011-05-17T06:44:11Z","isPatch":true,"sender":{"key":"daniel@haxx.se","avatar":"https://gravatar.com/avatar/69fdca87edd17cee21ca2e79fc2ff671d644603c3dc27167430f3cd3dbab7ba8?d=mp&s=160"},"body":"On Tue, 17 May 2011, Rafael Gieschke wrote:\n\n> Compiling libcurl for Android should be possible with some work, though. So \n> compat/getpass.c would be used for libcurl/HTTP access, too.\n\n(lib)curl already has a dedicated makefile in the release tarball crafted for \nbuilding it for Android. It should not be a major obstacle.\n\n-- \n\n  / daniel.haxx.se\n"},{"id":"168231","messageId":"CB6373AF-1F26-4E4B-843B-B02C4FE60F96@gieschke.de","threadId":"27374","inReplyTo":"alpine.DEB.2.00.1105170842490.30333@tvnag.unkk.fr","subject":"Re: [PATCH] add Android support","fromName":"Rafael Gieschke","fromEmail":"rafael@gieschke.de","sentAt":"2011-05-19T17:30:41Z","receivedAt":"2011-05-19T17:30:41Z","isPatch":true,"sender":{"key":"rafael@gieschke.de","avatar":"https://avatars.githubusercontent.com/u/6069565?v=4"},"body":"Am 17.05.2011 um 08:44 schrieb Daniel Stenberg:\n\n> (lib)curl already has a dedicated makefile in the release tarball crafted for building it for Android. It should not be a major obstacle.\n\nThanks, I'll have a try but the instructions in Android.mk look kind of scary :-).\n"}]}