git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
* [PATCH 1/1] do not add common-main to lib
@ 2016-08-15  7:52 Christian Hesse
  2016-08-15 12:02 ` Jeff King
  2016-08-15 12:20 ` Johannes Schindelin
  0 siblings, 2 replies; 5+ messages in thread
From: Christian Hesse @ 2016-08-15  7:52 UTC (permalink / raw)
  To: git; +Cc: Christian Hesse

From: Christian Hesse <mail@eworm.de>

Commit 08aade70 (mingw: declare main()'s argv as const) changed
declaration of main function. This breaks linking external projects
(e.g. cgit) to libgit.a with:

error: Multiple definition of `main'

So do not add common-main to lib and let projects have their own
main function.

Signed-off-by: Christian Hesse <mail@eworm.de>
---
 Makefile | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/Makefile b/Makefile
index d96ecb7..1aea768 100644
--- a/Makefile
+++ b/Makefile
@@ -953,7 +953,8 @@ BUILTIN_OBJS += builtin/verify-tag.o
 BUILTIN_OBJS += builtin/worktree.o
 BUILTIN_OBJS += builtin/write-tree.o
 
-GITLIBS = common-main.o $(LIB_FILE) $(XDIFF_LIB)
+GITLIBS = $(LIB_FILE) $(XDIFF_LIB)
+GITCOMMON = common-main.o $(GITLIBS)
 EXTLIBS =
 
 GIT_USER_AGENT = git/$(GIT_VERSION)
@@ -1593,15 +1594,15 @@ TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH))
 DIFF_SQ = $(subst ','\'',$(DIFF))
 PERLLIB_EXTRA_SQ = $(subst ','\'',$(PERLLIB_EXTRA))
 
-# We must filter out any object files from $(GITLIBS),
+# We must filter out any object files from $(GITCOMMON),
 # as it is typically used like:
 #
-#   foo: foo.o $(GITLIBS)
+#   foo: foo.o $(GITCOMMON)
 #	$(CC) $(filter %.o,$^) $(LIBS)
 #
 # where we use it as a dependency. Since we also pull object files
 # from the dependency list, that would make each entry appear twice.
-LIBS = $(filter-out %.o, $(GITLIBS)) $(EXTLIBS)
+LIBS = $(filter-out %.o, $(GITCOMMON)) $(EXTLIBS)
 
 BASIC_CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER_SQ)' \
 	$(COMPAT_CFLAGS)
@@ -1741,7 +1742,7 @@ git.sp git.s git.o: EXTRA_CPPFLAGS = \
 	'-DGIT_MAN_PATH="$(mandir_relative_SQ)"' \
 	'-DGIT_INFO_PATH="$(infodir_relative_SQ)"'
 
-git$X: git.o GIT-LDFLAGS $(BUILTIN_OBJS) $(GITLIBS)
+git$X: git.o GIT-LDFLAGS $(BUILTIN_OBJS) $(GITCOMMON)
 	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) \
 		$(filter %.o,$^) $(LIBS)
 
@@ -2033,21 +2034,21 @@ compat/nedmalloc/nedmalloc.sp compat/nedmalloc/nedmalloc.o: EXTRA_CPPFLAGS = \
 compat/nedmalloc/nedmalloc.sp: SPARSE_FLAGS += -Wno-non-pointer-null
 endif
 
-git-%$X: %.o GIT-LDFLAGS $(GITLIBS)
+git-%$X: %.o GIT-LDFLAGS $(GITCOMMON)
 	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
 
-git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
+git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITCOMMON)
 	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
 		$(LIBS) $(IMAP_SEND_LDFLAGS)
 
-git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
+git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITCOMMON)
 	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
 		$(CURL_LIBCURL) $(LIBS)
-git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
+git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITCOMMON)
 	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
 		$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
 
-git-remote-testsvn$X: remote-testsvn.o GIT-LDFLAGS $(GITLIBS) $(VCSSVN_LIB)
+git-remote-testsvn$X: remote-testsvn.o GIT-LDFLAGS $(GITCOMMON) $(VCSSVN_LIB)
 	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) \
 	$(VCSSVN_LIB)
 
@@ -2057,7 +2058,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
 	ln -s $< $@ 2>/dev/null || \
 	cp $< $@
 
-$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
+$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITCOMMON)
 	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
 		$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
 
@@ -2271,7 +2272,7 @@ t/helper/test-svn-fe$X: $(VCSSVN_LIB)
 
 .PRECIOUS: $(TEST_OBJS)
 
-t/helper/test-%$X: t/helper/test-%.o GIT-LDFLAGS $(GITLIBS)
+t/helper/test-%$X: t/helper/test-%.o GIT-LDFLAGS $(GITCOMMON)
 	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(filter %.a,$^) $(LIBS)
 
 check-sha1:: t/helper/test-sha1$X
-- 
2.9.3


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

* Re: [PATCH 1/1] do not add common-main to lib
  2016-08-15  7:52 [PATCH 1/1] do not add common-main to lib Christian Hesse
@ 2016-08-15 12:02 ` Jeff King
  2016-08-15 12:21   ` Christian Hesse
  2016-08-15 12:20 ` Johannes Schindelin
  1 sibling, 1 reply; 5+ messages in thread
From: Jeff King @ 2016-08-15 12:02 UTC (permalink / raw)
  To: Christian Hesse; +Cc: git, Christian Hesse

On Mon, Aug 15, 2016 at 09:52:07AM +0200, Christian Hesse wrote:

> From: Christian Hesse <mail@eworm.de>
> 
> Commit 08aade70 (mingw: declare main()'s argv as const) changed
> declaration of main function. This breaks linking external projects
> (e.g. cgit) to libgit.a with:
> 
> error: Multiple definition of `main'

I'd expect the culprit is actually 3f2e229 (add an extra level of
indirection to main(), 2016-07-01).

> So do not add common-main to lib and let projects have their own
> main function.

That is certainly an option, but I think it means that those projects
are potentially buggy in the same way that some git commands were prior
to the common-main series. Namely, the common main() may do some
run-time setup that parts of libgit.a assume has been done.

I would not be surprised if cgit crashes on Windows, for instance, for
the reasons detailed in 650c449 (common-main: call
git_extract_argv0_path(), 2016-07-01). I would also not be surprised if
nobody actually builds cgit on Windows. :)

The "right" way to do it (according to the way libgit.a views the world)
is for cgit's main to become cmd_main(), and let libgit.a do its
run-time startup before getting there.

-Peff

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

* Re: [PATCH 1/1] do not add common-main to lib
  2016-08-15  7:52 [PATCH 1/1] do not add common-main to lib Christian Hesse
  2016-08-15 12:02 ` Jeff King
@ 2016-08-15 12:20 ` Johannes Schindelin
  2016-08-15 12:30   ` Christian Hesse
  1 sibling, 1 reply; 5+ messages in thread
From: Johannes Schindelin @ 2016-08-15 12:20 UTC (permalink / raw)
  To: Christian Hesse; +Cc: git, Christian Hesse

Hi Christian,

On Mon, 15 Aug 2016, Christian Hesse wrote:

> From: Christian Hesse <mail@eworm.de>
> 
> Commit 08aade70 (mingw: declare main()'s argv as const) changed
> declaration of main function. This breaks linking external projects
> (e.g. cgit) to libgit.a with:
> 
> error: Multiple definition of `main'
> 
> So do not add common-main to lib and let projects have their own
> main function.

I am opposed to this change.

For one, libgit.a is *not* a library with an API, for a good reason:
nothing in Git's development guarantees any kind of stable API. For that
reason, libgit.a is not installed, either, and neither are any headers.

And even more importantly: *iff* you *insist* on using libgit.a in your
project *despite* having been told not to, it is your responsibility to
stay up-to-date with the requirements of it.

One such requirement is that you now implement cmd_main() instead of
main().

So if you want to continue to have an out-of-tree project that links
against the (private) libgit.a, it is your out-of-tree project that needs
changing, not libgit.a.

Ciao,
Johannes

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

* Re: [PATCH 1/1] do not add common-main to lib
  2016-08-15 12:02 ` Jeff King
@ 2016-08-15 12:21   ` Christian Hesse
  0 siblings, 0 replies; 5+ messages in thread
From: Christian Hesse @ 2016-08-15 12:21 UTC (permalink / raw)
  To: Jeff King; +Cc: git, Christian Hesse

[-- Attachment #1: Type: text/plain, Size: 1778 bytes --]

Jeff King <peff@peff.net> on Mon, 2016/08/15 08:02:
> On Mon, Aug 15, 2016 at 09:52:07AM +0200, Christian Hesse wrote:
> 
> > From: Christian Hesse <mail@eworm.de>
> > 
> > Commit 08aade70 (mingw: declare main()'s argv as const) changed
> > declaration of main function. This breaks linking external projects
> > (e.g. cgit) to libgit.a with:
> > 
> > error: Multiple definition of `main'  
> 
> I'd expect the culprit is actually 3f2e229 (add an extra level of
> indirection to main(), 2016-07-01).

Ah, probably you are right...

> > So do not add common-main to lib and let projects have their own
> > main function.  
> 
> That is certainly an option, but I think it means that those projects
> are potentially buggy in the same way that some git commands were prior
> to the common-main series. Namely, the common main() may do some
> run-time setup that parts of libgit.a assume has been done.

Ok, got it.

> I would not be surprised if cgit crashes on Windows, for instance, for
> the reasons detailed in 650c449 (common-main: call
> git_extract_argv0_path(), 2016-07-01). I would also not be surprised if
> nobody actually builds cgit on Windows. :)

I never tried and probably nobody else did. :-p

> The "right" way to do it (according to the way libgit.a views the world)
> is for cgit's main to become cmd_main(), and let libgit.a do its
> run-time startup before getting there.

Looks like that does the job. I will give it some more testing.

Please ignore my patch... ;)
Thanks a lot!
-- 
main(a){char*c=/*    Schoene Gruesse                         */"B?IJj;MEH"
"CX:;",b;for(a/*    Best regards             my address:    */=0;b=c[a++];)
putchar(b-1/(/*    Chris            cc -ox -xc - && ./x    */b/42*2-3)*42);}

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

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

* Re: [PATCH 1/1] do not add common-main to lib
  2016-08-15 12:20 ` Johannes Schindelin
@ 2016-08-15 12:30   ` Christian Hesse
  0 siblings, 0 replies; 5+ messages in thread
From: Christian Hesse @ 2016-08-15 12:30 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: git, Christian Hesse

[-- Attachment #1: Type: text/plain, Size: 1737 bytes --]

Johannes Schindelin <Johannes.Schindelin@gmx.de> on Mon, 2016/08/15 14:20:
> Hi Christian,
> 
> On Mon, 15 Aug 2016, Christian Hesse wrote:
> 
> > From: Christian Hesse <mail@eworm.de>
> > 
> > Commit 08aade70 (mingw: declare main()'s argv as const) changed
> > declaration of main function. This breaks linking external projects
> > (e.g. cgit) to libgit.a with:
> > 
> > error: Multiple definition of `main'
> > 
> > So do not add common-main to lib and let projects have their own
> > main function.  
> 
> I am opposed to this change.

Me too. :-p

> For one, libgit.a is *not* a library with an API, for a good reason:
> nothing in Git's development guarantees any kind of stable API. For that
> reason, libgit.a is not installed, either, and neither are any headers.
> 
> And even more importantly: *iff* you *insist* on using libgit.a in your
> project *despite* having been told not to, it is your responsibility to
> stay up-to-date with the requirements of it.

cgit pulls in the git tree as a subproject. We are aware that the API changes
all the time and that's fine. Usually we just fix it, this time I missed the
background information of the change.

> One such requirement is that you now implement cmd_main() instead of
> main().
> 
> So if you want to continue to have an out-of-tree project that links
> against the (private) libgit.a, it is your out-of-tree project that needs
> changing, not libgit.a.

Already updated my code. ;)
Thanks!
-- 
main(a){char*c=/*    Schoene Gruesse                         */"B?IJj;MEH"
"CX:;",b;for(a/*    Best regards             my address:    */=0;b=c[a++];)
putchar(b-1/(/*    Chris            cc -ox -xc - && ./x    */b/42*2-3)*42);}

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

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

end of thread, other threads:[~2016-08-15 12:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-15  7:52 [PATCH 1/1] do not add common-main to lib Christian Hesse
2016-08-15 12:02 ` Jeff King
2016-08-15 12:21   ` Christian Hesse
2016-08-15 12:20 ` Johannes Schindelin
2016-08-15 12:30   ` Christian Hesse

Code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).