Skip to content

Commit 8e2ebbe

Browse files
cgo option build
With this patch, we've made the external C parser optional for generateOutput. As cgo can be problematic for some users, we've added an option to bypass it and test generateOutput against a sample dot file instead. This change should make the tool more accessible and user-friendly. Signed-off-by: Alessandro Carminati <[email protected]> Suggested-by: Maurizio Papini <[email protected]>
1 parent 7f3f2b9 commit 8e2ebbe

File tree

8 files changed

+387
-43
lines changed

8 files changed

+387
-43
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.swp
22
nav
33
conf.json
4+
libdotparser.so

Makefile

+14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
12
all: nav.go
23
go build -ldflags="-r ."
34

5+
cgo: nav.go dot_parser/libdotparser.so libdotparser.so
6+
go build -ldflags="-r ." -tags CGO
7+
48
upx: nav
59
upx nav
610

@@ -13,3 +17,13 @@ code/check:
1317

1418
code/fmt:
1519
@gofmt -w `find . -type f -name '*.go' -not -path "./vendor/*"`
20+
21+
dot_parser/libdotparser.so: dot_parser/dot.l dot_parser/dot.y
22+
$(MAKE) -C dot_parser/ libdotparser.so
23+
24+
libdotparser.so: dot_parser/libdotparser.so
25+
ln -s dot_parser/libdotparser.so libdotparser.so
26+
27+
clean:
28+
$(MAKE) -C dot_parser/ clean
29+
rm -f nav libdotparser.so

dot_parser/samples/xx.dot

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
digraph G {
2+
rankdir="LR"
3+
"__x64_sys_getpid"->"__task_pid_nr_ns"
4+
"__task_pid_nr_ns"->"__rcu_read_lock"
5+
"__task_pid_nr_ns"->"__rcu_read_unlock"
6+
}

libdotparser.so

-1
This file was deleted.

nav.go

+1-15
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,11 @@
1+
// +build !CGO
12
/*
23
* Copyright (c) 2022 Red Hat, Inc.
34
* SPDX-License-Identifier: GPL-2.0-or-later
45
*/
56

67
package main
78

8-
/*
9-
#cgo LDFLAGS: -ldotparser -Ldot_parser/
10-
#include <stdio.h>
11-
#include "dot_parser/dot.tab.h"
12-
extern int dotparse(void);
13-
extern void set_input_string(const char* in);
14-
extern void end_lexical_scan(void);
15-
int parse_string(const char* in) {
16-
set_input_string(in);
17-
int rv = dotparse();
18-
end_lexical_scan();
19-
return rv;
20-
}
21-
*/
22-
import "C"
239
import (
2410
"encoding/binary"
2511
"bytes"

nav_cgo.go

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// +build CGO
2+
package main
3+
4+
/*
5+
#cgo LDFLAGS: -ldotparser -Ldot_parser/
6+
#include <stdio.h>
7+
#include "dot_parser/dot.tab.h"
8+
extern int dotparse(void);
9+
extern void set_input_string(const char* in);
10+
extern void end_lexical_scan(void);
11+
int parse_string(const char* in) {
12+
set_input_string(in);
13+
int rv = dotparse();
14+
end_lexical_scan();
15+
return rv;
16+
}
17+
*/
18+
import "C"
19+
20+
func valid_dot(dot string) bool{
21+
if C.parse_string(C.CString(dot))==0 {
22+
return true
23+
}
24+
return false
25+
}

0 commit comments

Comments
 (0)