git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] add Android support
@ 2011-05-16 20:08 Rafael Gieschke
  2011-05-16 21:11 ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Rafael Gieschke @ 2011-05-16 20:08 UTC (permalink / raw)
  To: git, gitster


Currently, it is not possible to compile git for Android as the C library (Bionic)
is neither providing getpass nor pw_gecos in struct passwd. Therefore,
NO_GETPASS and NO_PW_GECOS are defined in Makefile. As code for Android can only
be cross-compiled, ANDROID is defined.

Signed-off-by: Rafael Gieschke <rafael@gieschke.de>
---
 Makefile  |   27 +++++++++++++++++++++++++++
 connect.c |    4 ++++
 ident.c   |    7 ++++++-
 3 files changed, 37 insertions(+), 1 deletions(-)

diff --git a/Makefile b/Makefile
index c4db5af..e010efb 100644
--- a/Makefile
+++ b/Makefile
@@ -71,6 +71,11 @@ all::
 #
 # Define NO_STRTOK_R if you don't have strtok_r in the C library.
 #
+# Define NO_GETPASS if you don't have getpass in the C library.
+#
+# Define NO_PW_GECOS if you don't have pw_gecos in struct passwd
+# in the C library.
+#
 # Define NO_FNMATCH if you don't have fnmatch in the C library.
 #
 # Define NO_FNMATCH_CASEFOLD if your fnmatch function doesn't have the
@@ -248,6 +253,8 @@ all::
 # dependency rules.
 #
 # Define NATIVE_CRLF if your platform uses CRLF for line endings.
+#
+# Define ANDROID if you are cross-compiling for Android.
 
 GIT-VERSION-FILE: FORCE
 	@$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -789,6 +796,20 @@ ifeq ($(uname_S),OSF1)
 	NO_STRTOULL = YesPlease
 	NO_NSEC = YesPlease
 endif
+ifdef ANDROID
+	uname_S := Linux
+	NO_GETPASS = YesPlease
+	NO_PW_GECOS = YesPlease
+	NO_NSEC = YesPlease
+	NO_MKDTEMP = YesPlease
+	NO_PTHREADS = YesPlease
+	NO_PERL = YesPlease
+	NO_OPENSSL = YesPlease
+	NO_CURL = YesPlease
+	NO_EXPAT = YesPlease
+	NO_TCLTK = YesPlease
+	NO_ICONV = YesPlease
+endif
 ifeq ($(uname_S),Linux)
 	NO_STRLCPY = YesPlease
 	NO_MKSTEMPS = YesPlease
@@ -1404,6 +1425,12 @@ ifdef NO_STRTOK_R
 	COMPAT_CFLAGS += -DNO_STRTOK_R
 	COMPAT_OBJS += compat/strtok_r.o
 endif
+ifdef NO_GETPASS
+	COMPAT_CFLAGS += -DNO_GETPASS
+endif
+ifdef NO_PW_GECOS
+	COMPAT_CFLAGS += -DNO_PW_GECOS
+endif
 ifdef NO_FNMATCH
 	COMPAT_CFLAGS += -Icompat/fnmatch
 	COMPAT_CFLAGS += -DNO_FNMATCH
diff --git a/connect.c b/connect.c
index 57dc20c..15b285e 100644
--- a/connect.c
+++ b/connect.c
@@ -632,7 +632,11 @@ char *git_getpass(const char *prompt)
 	if (!askpass)
 		askpass = getenv("SSH_ASKPASS");
 	if (!askpass || !(*askpass)) {
+		#ifndef NO_GETPASS
 		char *result = getpass(prompt);
+		#else
+		char *result = NULL;
+		#endif
 		if (!result)
 			die_errno("Could not read password");
 		return result;
diff --git a/ident.c b/ident.c
index 1c4adb0..76fa786 100644
--- a/ident.c
+++ b/ident.c
@@ -20,7 +20,12 @@ static void copy_gecos(const struct passwd *w, char *name, size_t sz)
 	 * with commas.  Also & stands for capitalized form of the login name.
 	 */
 
-	for (len = 0, dst = name, src = w->pw_gecos; len < sz; src++) {
+	#ifndef NO_PW_GECOS
+	src = w->pw_gecos;
+	#else
+	src = "&";
+	#endif
+	for (len = 0, dst = name; len < sz; src++) {
 		int ch = *src;
 		if (ch != '&') {
 			*dst++ = ch;
-- 
1.7.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] add Android support
  2011-05-16 20:08 [PATCH] add Android support Rafael Gieschke
@ 2011-05-16 21:11 ` Junio C Hamano
  2011-05-16 23:23   ` Rafael Gieschke
  0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2011-05-16 21:11 UTC (permalink / raw)
  To: Rafael Gieschke; +Cc: git

Rafael Gieschke <rafael@gieschke.de> writes:

> diff --git a/connect.c b/connect.c
> index 57dc20c..15b285e 100644
> --- a/connect.c
> +++ b/connect.c
> @@ -632,7 +632,11 @@ char *git_getpass(const char *prompt)
>  	if (!askpass)
>  		askpass = getenv("SSH_ASKPASS");
>  	if (!askpass || !(*askpass)) {
> +		#ifndef NO_GETPASS
>  		char *result = getpass(prompt);
> +		#else
> +		char *result = NULL;
> +		#endif
>  		if (!result)
>  			die_errno("Could not read password");
>  		return result;
> diff --git a/ident.c b/ident.c
> index 1c4adb0..76fa786 100644
> --- a/ident.c
> +++ b/ident.c
> @@ -20,7 +20,12 @@ static void copy_gecos(const struct passwd *w, char *name, size_t sz)
>  	 * with commas.  Also & stands for capitalized form of the login name.
>  	 */
>  
> -	for (len = 0, dst = name, src = w->pw_gecos; len < sz; src++) {
> +	#ifndef NO_PW_GECOS
> +	src = w->pw_gecos;
> +	#else
> +	src = "&";
> +	#endif
> +	for (len = 0, dst = name; len < sz; src++) {
>  		int ch = *src;
>  		if (ch != '&') {
>  			*dst++ = ch;

Please do not throw in conditional compilation in a codepath that is
otherwise generic.

Do something like this near the beginning of the file (or if they are
common, in an appropriate header):

        #ifdef NO_GETPASS
        #define getpass(ignored) NULL
        #endif

        #ifdef NO_PW_GECOS
        #define get_gecos(ignored) "&"
        #else
        #define get_gecos(struct_passwd) (struct_passwd->pw_gecos)
        #endif

That way, you do not have to change connect.c at all, and the code that
accesses gecos field would get a slight abstraction, i.e.

	for (len = 0, dst = name, src = get_gecos(w); len < sz; src++) {
		...

I however suspect that NO_GETPASS would be a useless thing in the longer
term. Wouldn't you rather wish to have a native Android UI that asks a
password and plug that implementation as a replacement for git_getpass()?

It might be worthwhile to study how mingw folks do this part before you
dive in and butcher this codepath in a way you may regret later.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] add Android support
  2011-05-16 21:11 ` Junio C Hamano
@ 2011-05-16 23:23   ` Rafael Gieschke
  2011-05-17  6:44     ` Daniel Stenberg
  0 siblings, 1 reply; 5+ messages in thread
From: Rafael Gieschke @ 2011-05-16 23:23 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git


Am 16.05.2011 um 23:11 schrieb Junio C Hamano:

> Please do not throw in conditional compilation in a codepath that is
> otherwise generic.
> 
> Do something like this near the beginning of the file (or if they are
> common, in an appropriate header):
> 
>        #ifdef NO_GETPASS
>        #define getpass(ignored) NULL
>        #endif
> 
>        #ifdef NO_PW_GECOS
>        #define get_gecos(ignored) "&"
>        #else
>        #define get_gecos(struct_passwd) (struct_passwd->pw_gecos)
>        #endif
> 
> That way, you do not have to change connect.c at all, and the code that
> accesses gecos field would get a slight abstraction, i.e.
> 
> 	for (len = 0, dst = name, src = get_gecos(w); len < sz; src++) {
> 		...
> 

Thanks. Great idea, didn't think about that. See new patch.

> I however suspect that NO_GETPASS would be a useless thing in the longer
> term. Wouldn't you rather wish to have a native Android UI that asks a
> password and plug that implementation as a replacement for git_getpass()?
> 
> It might be worthwhile to study how mingw folks do this part before you
> dive in and butcher this codepath in a way you may regret later.
> 


I 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.

The 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 .

If 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.

Compiling libcurl for Android should be possible with some work, though. So compat/getpass.c would be used for libcurl/HTTP access, too.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] add Android support
  2011-05-16 23:23   ` Rafael Gieschke
@ 2011-05-17  6:44     ` Daniel Stenberg
  2011-05-19 17:30       ` Rafael Gieschke
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Stenberg @ 2011-05-17  6:44 UTC (permalink / raw)
  To: Rafael Gieschke; +Cc: Junio C Hamano, git

On Tue, 17 May 2011, Rafael Gieschke wrote:

> Compiling libcurl for Android should be possible with some work, though. So 
> compat/getpass.c would be used for libcurl/HTTP access, too.

(lib)curl already has a dedicated makefile in the release tarball crafted for 
building it for Android. It should not be a major obstacle.

-- 

  / daniel.haxx.se

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] add Android support
  2011-05-17  6:44     ` Daniel Stenberg
@ 2011-05-19 17:30       ` Rafael Gieschke
  0 siblings, 0 replies; 5+ messages in thread
From: Rafael Gieschke @ 2011-05-19 17:30 UTC (permalink / raw)
  To: Daniel Stenberg; +Cc: git

Am 17.05.2011 um 08:44 schrieb Daniel Stenberg:

> (lib)curl already has a dedicated makefile in the release tarball crafted for building it for Android. It should not be a major obstacle.

Thanks, I'll have a try but the instructions in Android.mk look kind of scary :-).

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-05-19 17:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-16 20:08 [PATCH] add Android support Rafael Gieschke
2011-05-16 21:11 ` Junio C Hamano
2011-05-16 23:23   ` Rafael Gieschke
2011-05-17  6:44     ` Daniel Stenberg
2011-05-19 17:30       ` Rafael Gieschke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).