Skip to content

Commit

Permalink
gogensig:third file temp to libname_autogen.go
Browse files Browse the repository at this point in the history
  • Loading branch information
luoliwoshang committed Feb 26, 2025
1 parent 18f2b80 commit e732508
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
"mangle": "third_depfn",
"c++": "third_depfn",
"go": "ThirdDepfn"
},
{
"mangle": "third_type",
"c++": "thirdType",
"go": "ThirdType"
}
]

6 changes: 6 additions & 0 deletions cmd/gogensig/convert/_testdata/_depcjson/gogensig.expect
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import (

type X_depcjsonType c.Int

type ThirdDep3 struct {
B c.Long
}

===== temp.go =====
package _depcjson

Expand All @@ -27,6 +31,8 @@ func ParseClientRequest(json_string *int8, error_buffer *int8, buffer_size uintp
func SerializeResponse(response *cjson.CJSON, buffer *int8, length c.Int, pretty_print cjson.CJSONBool) cjson.CJSONBool
//go:linkname ThirdDepfn C.third_depfn
func ThirdDepfn(a *thirddep.ThirdDep, b *thirddep2.ThirdDep2, c X_depcjsonType, d basicdep.BasicDep) thirddep.ThirdDep
//go:linkname ThirdType C.third_type
func ThirdType(a *ThirdDep3) ThirdDep3

===== llcppg.pub =====
_depcjson_type X_depcjsonType
11 changes: 7 additions & 4 deletions cmd/gogensig/convert/_testdata/_depcjson/hfile/temp.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
#include "type.h"
#include <cJSON.h>
#include <stddef.h>
#include <thirddep.h>
#include <thirddep2.h>
#include "type.h"
#include <thirddep3.h>
// This file is supposed to depend on cjson in its cflags, but for testing,
// we will simulate its API using libcjson instead.
// "cflags" :"$(pkg-config --cflags libcjson)"
cJSON* create_response(int status_code, const char* message);
cJSON *create_response(int status_code, const char *message);

cJSON_bool parse_client_request(const char* json_string, char* error_buffer, size_t buffer_size);
cJSON_bool parse_client_request(const char *json_string, char *error_buffer, size_t buffer_size);

cJSON_bool serialize_response(cJSON *response, char *buffer, const int length, const cJSON_bool pretty_print);

third_dep third_depfn(third_dep *a, third_dep2 *b,_depcjson_type c,basic_dep d);
third_dep third_depfn(third_dep *a, third_dep2 *b, _depcjson_type c, basic_dep d);

third_dep3 third_type(third_dep3 *a);
4 changes: 3 additions & 1 deletion cmd/gogensig/convert/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,16 @@ func TestDepPkg(t *testing.T) {

thirdDepPath := buildTestPath(dir, testDataDir, "thirddep")
thirdDep2Path := buildTestPath(dir, testDataDir, "thirddep2")
thirdDep3Path := buildTestPath(dir, testDataDir, "thirddep3")
basicDepPath := buildTestPath(dir, testDataDir, "basicdep")

thirdDepHFile := buildTestPath(thirdDepPath, hfileDir)
thirdDep2HFile := buildTestPath(thirdDep2Path, hfileDir)
thirdDep3HFile := buildTestPath(thirdDep3Path, hfileDir)
basicDepHFile := buildTestPath(basicDepPath, hfileDir)

cleanups := []func(){
inc(depcjsonConf, fmt.Sprintf(" -I%s -I%s -I%s", thirdDepHFile, thirdDep2HFile, basicDepHFile)),
inc(depcjsonConf, fmt.Sprintf(" -I%s -I%s -I%s -I%s", thirdDepHFile, thirdDep2HFile, thirdDep3HFile, basicDepHFile)),
inc(buildTestPath(thirdDepPath, "llcppg.cfg"), fmt.Sprintf(" -I%s -I%s", thirdDepHFile, basicDepHFile)),
inc(buildTestPath(thirdDep2Path, "llcppg.cfg"), fmt.Sprintf(" -I%s -I%s -I%s", thirdDep2HFile, thirdDepHFile, basicDepHFile)),
inc(buildTestPath(basicDepPath, "llcppg.cfg"), fmt.Sprintf(" -I%s", basicDepHFile)),
Expand Down
9 changes: 7 additions & 2 deletions cmd/gogensig/convert/headerfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ func (p *HeaderFile) ToGoFileName(pkgName string) string {
case llcppg.Impl:
return pkgName + "_autogen.go"
case llcppg.Third:
// todo(zzy):ignore third file
return names.HeaderFileToGo(p.File)
// todo(zzy):ignore third file when dependency refactored
if p.IsSys {
return names.HeaderFileToGo(p.File)
} else {
// todo(zzy):temp gen third type to libname_autogen.go
return pkgName + "_autogen.go"
}
default:
panic("unkown FileType")
}
Expand Down
9 changes: 9 additions & 0 deletions cmd/gogensig/convert/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2172,3 +2172,12 @@ func TestImport(t *testing.T) {
})
})
}

func TestUnkownHfile(t *testing.T) {
defer func() {
if err := recover(); err == nil {
t.Fatal("Expect Error")
}
}()
convert.NewHeaderFile("/path/to/foo.h", "foo.h", true, 0, false).ToGoFileName("Pkg")
}
3 changes: 3 additions & 0 deletions cmd/gogensig/convert/testdata/thirddep3/hfile/thirddep3.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
struct third_dep3 {
long b;
};
7 changes: 7 additions & 0 deletions cmd/gogensig/convert/testdata/thirddep3/llcppg.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "thirddep3",
"include": [
"thirddep3.h"
],
"cplusplus": false
}
1 change: 1 addition & 0 deletions cmd/gogensig/convert/testdata/thirddep3/llcppg.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
third_dep3 ThirdDep3
11 changes: 11 additions & 0 deletions cmd/gogensig/convert/testdata/thirddep3/thirddep3.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package thirddep2

import (
_ "unsafe"

"github.com/goplus/llgo/c"
)

type ThirdDep3 struct {
C c.Long
}

0 comments on commit e732508

Please sign in to comment.