Fixed SWIG go for cases when SWIG %import-s another package which is located in a subdirectory.

This commit is contained in:
Misha Seltzer 2015-02-09 18:34:04 +02:00 committed by Misha Seltzer
commit 8da4d20308
9 changed files with 135 additions and 7 deletions

View file

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

View file

@ -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); \

View file

@ -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

View file

@ -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)
}
}

View file

@ -0,0 +1,3 @@
testdir/go_subdir_import/go_subdir_import_c
go_subdir_import_b
go_subdir_import_a

View file

@ -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;
}
%}

View file

@ -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;
}
};
%}

View file

@ -0,0 +1,12 @@
/* File : go_subdir_import_c.i */
%module go_subdir_import_c
%inline %{
class ObjC {
public:
int getInt() const {
return 18;
}
};
%}

View file

@ -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 */
/* -----------------------------------------------------------------------------