From 8da4d20308c015e679eaba6b1d312af45cccbe48 Mon Sep 17 00:00:00 2001 From: Misha Seltzer Date: Mon, 9 Feb 2015 18:34:04 +0200 Subject: [PATCH 1/4] Fixed SWIG go for cases when SWIG %import-s another package which is located in a subdirectory. --- CHANGES.current | 3 ++ Examples/Makefile.in | 13 +++++-- Examples/test-suite/go/Makefile.in | 23 ++++++++++++ .../test-suite/go/go_subdir_import_runme.go | 16 ++++++++ Examples/test-suite/go_subdir_import.list | 3 ++ Examples/test-suite/go_subdir_import_a.i | 37 +++++++++++++++++++ Examples/test-suite/go_subdir_import_b.i | 12 ++++++ .../go_subdir_import/go_subdir_import_c.i | 12 ++++++ Source/Modules/go.cxx | 23 ++++++++++-- 9 files changed, 135 insertions(+), 7 deletions(-) create mode 100644 Examples/test-suite/go/go_subdir_import_runme.go create mode 100644 Examples/test-suite/go_subdir_import.list create mode 100644 Examples/test-suite/go_subdir_import_a.i create mode 100644 Examples/test-suite/go_subdir_import_b.i create mode 100644 Examples/test-suite/testdir/go_subdir_import/go_subdir_import_c.i diff --git a/CHANGES.current b/CHANGES.current index 4679e8d63..a8fa0ca46 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -9,6 +9,9 @@ Version 3.0.6 (in progress) [Guile] Fix generated code for static const char member variables when defined and declared inline. +2015-02-09: mishas + [Go] Fix %import of files in sub directories. + 2015-02-05: ianlancetaylor [Go] Ignore Go specific type maps (goin, goout, etc.) if they are empty. diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 6fccda22e..9a414af08 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -1818,14 +1818,21 @@ go: $(SRCDIR_SRCS) go_cpp: $(SRCDIR_SRCS) $(SWIG) -go -c++ $(GOOPT) $(GOSWIGARG) $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) if $(GO12) || $(GO13) || $(GOGCC); then \ - $(CXX) -g -c $(CPPFLAGS) $(CXXFLAGS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(ICXXSRCS) $(INCLUDES); \ + ${foreach f,$(SRCDIR_CXXSRCS) $(SRCDIR_SRCS) $(ICXXSRCS), \ + $(CXX) -g -c $(CPPFLAGS) $(CXXFLAGS) -o ${addsuffix .o,${basename $f}} $f $(INCLUDES); \ + } \ else \ $(CXX) -g -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(ICXXSRCS) $(INCLUDES); \ $(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO); \ fi - $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(GOSRCS) + ${foreach f,$(GOSRCS), \ + $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . -o ${addsuffix .$(GOOBJEXT),${basename $f}} $f \ + } if ! $(GOGCC) ; then \ - $(COMPILETOOL) $(GOTOOL) $(GOC) -I $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`} $(GOCSRCS); \ + ${foreach f,$(GOCSRCS), \ + $(COMPILETOOL) $(GOTOOL) $(GOC) -I $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`} \ + -o ${addsuffix .$(GOOBJEXT),${basename $f}} $f; \ + } \ rm -f $(GOPACKAGE); \ if $(GO13); then \ cp $(GOGCOBJS) $(GOPACKAGE); \ diff --git a/Examples/test-suite/go/Makefile.in b/Examples/test-suite/go/Makefile.in index 4480ecf1f..7eb12d2f8 100644 --- a/Examples/test-suite/go/Makefile.in +++ b/Examples/test-suite/go/Makefile.in @@ -28,6 +28,9 @@ CPP_TEST_CASES = \ go_inout \ go_director_inout +MULTI_CPP_TEST_CASES = \ + go_subdir_import + include $(srcdir)/../common.mk .SUFFIXES: .cpptest .ctest .multicpptest @@ -59,6 +62,25 @@ multi_import.multicpptest: done $(run_multi_testcase) +go_subdir_import.multicpptest: + $(setup) + mkdir -p testdir/go_subdir_import/ + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR="$(SRCDIR)" CXXSRCS="$(CXXSRCS)" \ + SWIG_LIB="$(SWIG_LIB)" SWIG="$(SWIG)" LIBS='$(LIBS)' \ + INTERFACEPATH="go_subdir_import_b.i" \ + INCLUDES="$(INCLUDES)" SWIGOPT="$(SWIGOPT) -outdir ." NOLINK=true \ + TARGET="$(TARGETPREFIX)go_subdir_import_b$(TARGETSUFFIX)" INTERFACEDIR="$(INTERFACEDIR)" \ + INTERFACE="testdir/go_subdir_import/go_subdir_import_b.i" \ + $(LANGUAGE)$(VARIANT)_cpp; + for f in testdir/go_subdir_import/go_subdir_import_c go_subdir_import_a ; do \ + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR="$(SRCDIR)" CXXSRCS="$(CXXSRCS)" \ + SWIG_LIB="$(SWIG_LIB)" SWIG="$(SWIG)" LIBS='$(LIBS)' \ + INCLUDES="$(INCLUDES)" SWIGOPT="$(SWIGOPT)" NOLINK=true \ + TARGET="$(TARGETPREFIX)$${f}$(TARGETSUFFIX)" INTERFACEDIR="$(INTERFACEDIR)" INTERFACE="$$f.i" \ + $(LANGUAGE)$(VARIANT)_cpp; \ + done + $(run_multi_testcase) + # Runs the testcase. run_testcase = \ if test -f $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); then \ @@ -108,6 +130,7 @@ clean: rm -f mod_a.go mod_b.go imports_a.go imports_b.go rm -f clientdata_prop_a.go clientdata_prop_b.go rm -f multi_import_a.go multi_import_b.go + rm -rf go_subdir_import_a.go testdir rm -f packageoption_a.go packageoption_b.go packageoption_c.go rm -f import_stl_a.go import_stl_b.go diff --git a/Examples/test-suite/go/go_subdir_import_runme.go b/Examples/test-suite/go/go_subdir_import_runme.go new file mode 100644 index 000000000..f90a6eb54 --- /dev/null +++ b/Examples/test-suite/go/go_subdir_import_runme.go @@ -0,0 +1,16 @@ +package main + +import ( + "go_subdir_import_a" + "testdir/go_subdir_import/go_subdir_import_b" + "testdir/go_subdir_import/go_subdir_import_c" +) + +func main() { + b := go_subdir_import_b.NewObjB(); + c := go_subdir_import_c.NewObjC(); + v := go_subdir_import_a.AddFive(b, c) + if v != 50 { + panic(0) + } +} diff --git a/Examples/test-suite/go_subdir_import.list b/Examples/test-suite/go_subdir_import.list new file mode 100644 index 000000000..e117d32fa --- /dev/null +++ b/Examples/test-suite/go_subdir_import.list @@ -0,0 +1,3 @@ +testdir/go_subdir_import/go_subdir_import_c +go_subdir_import_b +go_subdir_import_a diff --git a/Examples/test-suite/go_subdir_import_a.i b/Examples/test-suite/go_subdir_import_a.i new file mode 100644 index 000000000..72b28786e --- /dev/null +++ b/Examples/test-suite/go_subdir_import_a.i @@ -0,0 +1,37 @@ +/* File : go_subdir_import_a.i */ + +/* + * This files helps check the case where the SWIG-generated .go file needs to + * import another, SWIG-generated, module that is in a relative subdirectory. + * This case might happen for two different reasons: + * 1) Importing a module for which the .i file is in a subdirectory relatively + * to this file (this is tested here with go_subdir_import_c). + * 2) Importing a module whos module name is a path (this is tested here with + * go_subdir_import_b). + * + * This file is the "root" file that imports the two modules which will be + * generated (by swig) in a relative subdirectory. + */ +%module go_subdir_import_a + +%import(module="testdir/go_subdir_import/go_subdir_import_c") "testdir/go_subdir_import/go_subdir_import_c.i" +%import "go_subdir_import_b.i" + +%{ +class ObjC { + public: + int getInt() const; +}; + +class ObjB { + public: + int getInt() const; +}; +%} + +%inline %{ +int AddFive(const ObjB& b, const ObjC& c) { + return b.getInt() + c.getInt() + 5; +} +%} + diff --git a/Examples/test-suite/go_subdir_import_b.i b/Examples/test-suite/go_subdir_import_b.i new file mode 100644 index 000000000..b87f7cf3c --- /dev/null +++ b/Examples/test-suite/go_subdir_import_b.i @@ -0,0 +1,12 @@ +/* File : go_subdir_import_b.i */ +%module "testdir/go_subdir_import/go_subdir_import_b" + +%inline %{ +class ObjB { + public: + int getInt() const { + return 27; + } +}; +%} + diff --git a/Examples/test-suite/testdir/go_subdir_import/go_subdir_import_c.i b/Examples/test-suite/testdir/go_subdir_import/go_subdir_import_c.i new file mode 100644 index 000000000..2c2c2e1fe --- /dev/null +++ b/Examples/test-suite/testdir/go_subdir_import/go_subdir_import_c.i @@ -0,0 +1,12 @@ +/* File : go_subdir_import_c.i */ +%module go_subdir_import_c + +%inline %{ +class ObjC { + public: + int getInt() const { + return 18; + } +}; +%} + diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index 9a3960ce0..f910da629 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -554,7 +554,7 @@ private: // Output module initialization code. - Printf(f_go_begin, "\npackage %s\n\n", package); + Printf(f_go_begin, "\npackage %s\n\n", getModuleName(package)); if (gccgo_flag) { Printf(f_go_runtime, "func SwigCgocall()\n"); @@ -2058,7 +2058,7 @@ private: Printv(f_go_wrappers, "type ", name, " int\n", NULL); } else { String *nw = NewString(""); - Printv(nw, imported_package, ".", name, NULL); + Printv(nw, getModuleName(imported_package), ".", name, NULL); Setattr(n, "go:enumname", nw); } } @@ -5096,7 +5096,7 @@ private: Setattr(undefined_types, t, t); } else { String *nw = NewString(""); - Printv(nw, Getattr(cnmod, "name"), ".", ret, NULL); + Printv(nw, getModuleName(Getattr(cnmod, "name")), ".", ret, NULL); Delete(ret); ret = nw; } @@ -5282,7 +5282,7 @@ private: Append(ret, ex); } else { ret = NewString(""); - Printv(ret, Getattr(cnmod, "name"), ".Swigcptr", ex, NULL); + Printv(ret, getModuleName(Getattr(cnmod, "name")), ".Swigcptr", ex, NULL); } } Delete(ty); @@ -5603,6 +5603,21 @@ private: return ret; } + /* ---------------------------------------------------------------------- + * getModuleName + * + * Return the name of a module. This is different from module path: + * "some/path/to/module" -> "module". + * ---------------------------------------------------------------------- */ + + String *getModuleName(String *module_path) { + char *suffix = strrchr(Char(module_path), '/'); + if (suffix == NULL) { + return module_path; + } + return Str(suffix + 1); + } + }; /* class GO */ /* ----------------------------------------------------------------------------- From fcf2b68e841d3055379b4c10ebc00cc7e6e53c86 Mon Sep 17 00:00:00 2001 From: Misha Seltzer Date: Tue, 10 Feb 2015 11:02:59 +0200 Subject: [PATCH 2/4] Fixed errors due to last sync. --- Examples/test-suite/go/Makefile.in | 2 +- Source/Modules/go.cxx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Examples/test-suite/go/Makefile.in b/Examples/test-suite/go/Makefile.in index 7eb12d2f8..294f4c335 100644 --- a/Examples/test-suite/go/Makefile.in +++ b/Examples/test-suite/go/Makefile.in @@ -67,7 +67,7 @@ go_subdir_import.multicpptest: mkdir -p testdir/go_subdir_import/ $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR="$(SRCDIR)" CXXSRCS="$(CXXSRCS)" \ SWIG_LIB="$(SWIG_LIB)" SWIG="$(SWIG)" LIBS='$(LIBS)' \ - INTERFACEPATH="go_subdir_import_b.i" \ + INTERFACEPATH="$(SRCDIR)$(INTERFACEDIR)go_subdir_import_b.i" \ INCLUDES="$(INCLUDES)" SWIGOPT="$(SWIGOPT) -outdir ." NOLINK=true \ TARGET="$(TARGETPREFIX)go_subdir_import_b$(TARGETSUFFIX)" INTERFACEDIR="$(INTERFACEDIR)" \ INTERFACE="testdir/go_subdir_import/go_subdir_import_b.i" \ diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index f910da629..f0b1d5ac2 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -444,7 +444,7 @@ private: Delete(swig_input_content); fclose(swig_input); unique_id = NewString(""); - Printf(unique_id, "_%s_%08x%08x", package, hash.hi, hash.lo); + Printf(unique_id, "_%s_%08x%08x", getModuleName(package), hash.hi, hash.lo); // Open files. From 9e2c75c2a88df0feef55f8abe803923cd47139cf Mon Sep 17 00:00:00 2001 From: Misha Seltzer Date: Tue, 10 Feb 2015 14:31:27 +0200 Subject: [PATCH 3/4] Fix running tests when the test build outputs are generated in a different folder. (Fixes Travis' test runs). --- Examples/Makefile.in | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 9a414af08..6bc391cf1 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -1818,7 +1818,10 @@ go: $(SRCDIR_SRCS) go_cpp: $(SRCDIR_SRCS) $(SWIG) -go -c++ $(GOOPT) $(GOSWIGARG) $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) if $(GO12) || $(GO13) || $(GOGCC); then \ - ${foreach f,$(SRCDIR_CXXSRCS) $(SRCDIR_SRCS) $(ICXXSRCS), \ + if test -n "$(SRCDIR_CXXSRCS)$(SRCDIR_SRCS)"; then \ + $(CXX) -g -c $(CPPFLAGS) $(CXXFLAGS) $(SRCDIR_CXXSRCS) $(SRCDIR_SRCS) $(INCLUDES); \ + fi; \ + ${foreach f,$(ICXXSRCS), \ $(CXX) -g -c $(CPPFLAGS) $(CXXFLAGS) -o ${addsuffix .o,${basename $f}} $f $(INCLUDES); \ } \ else \ From beed5f3479182987e90069fea4b17b2d7cc31f4a Mon Sep 17 00:00:00 2001 From: Misha Seltzer Date: Sat, 14 Feb 2015 12:02:57 +0200 Subject: [PATCH 4/4] Changed to using $() instead of ${} in the makefile for consistancy --- Examples/Makefile.in | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 6bc391cf1..6fa45e3ec 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -1821,21 +1821,21 @@ go_cpp: $(SRCDIR_SRCS) if test -n "$(SRCDIR_CXXSRCS)$(SRCDIR_SRCS)"; then \ $(CXX) -g -c $(CPPFLAGS) $(CXXFLAGS) $(SRCDIR_CXXSRCS) $(SRCDIR_SRCS) $(INCLUDES); \ fi; \ - ${foreach f,$(ICXXSRCS), \ - $(CXX) -g -c $(CPPFLAGS) $(CXXFLAGS) -o ${addsuffix .o,${basename $f}} $f $(INCLUDES); \ - } \ + $(foreach f,$(ICXXSRCS), \ + $(CXX) -g -c $(CPPFLAGS) $(CXXFLAGS) -o $(addsuffix .o,$(basename $f)) $f $(INCLUDES); \ + ) \ else \ $(CXX) -g -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(ICXXSRCS) $(INCLUDES); \ $(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO); \ fi - ${foreach f,$(GOSRCS), \ - $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . -o ${addsuffix .$(GOOBJEXT),${basename $f}} $f \ - } + $(foreach f,$(GOSRCS), \ + $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . -o $(addsuffix .$(GOOBJEXT),$(basename $f)) $f \ + ) if ! $(GOGCC) ; then \ - ${foreach f,$(GOCSRCS), \ + $(foreach f,$(GOCSRCS), \ $(COMPILETOOL) $(GOTOOL) $(GOC) -I $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`} \ - -o ${addsuffix .$(GOOBJEXT),${basename $f}} $f; \ - } \ + -o $(addsuffix .$(GOOBJEXT),$(basename $f)) $f; \ + ) \ rm -f $(GOPACKAGE); \ if $(GO13); then \ cp $(GOGCOBJS) $(GOPACKAGE); \