зеркало из https://github.com/github/codeql-go.git
Add a go-gen-dbscheme for generating dbschemes
This commit is contained in:
Родитель
f599a502fc
Коммит
aef7524f35
6
Makefile
6
Makefile
|
@ -18,7 +18,7 @@ CODEQL_TOOLS = $(addprefix codeql-tools/,autobuild.cmd autobuild.sh index.cmd in
|
|||
|
||||
EXTRACTOR_PACK_OUT = build/codeql-extractor-go
|
||||
|
||||
BINARIES = go-extractor go-tokenizer go-autobuilder go-bootstrap
|
||||
BINARIES = go-extractor go-tokenizer go-autobuilder go-bootstrap go-gen-dbscheme
|
||||
|
||||
.PHONY: tools tools-codeql tools-codeql-full clean \
|
||||
tools-linux64 tools-osx64 tools-win64
|
||||
|
@ -81,8 +81,8 @@ tools/net/sourceforge/pmd/cpd/GoLanguage.class: extractor/net/sourceforge/pmd/cp
|
|||
rm tools/net/sourceforge/pmd/cpd/TokenEntry.class
|
||||
rm tools/net/sourceforge/pmd/cpd/Tokenizer.class
|
||||
|
||||
ql/src/go.dbscheme: tools/$(CODEQL_PLATFORM)/go-extractor$(EXE)
|
||||
env TRAP_FOLDER=/tmp $< --dbscheme $@
|
||||
ql/src/go.dbscheme: tools/$(CODEQL_PLATFORM)/go-gen-dbscheme$(EXE)
|
||||
$< $@
|
||||
|
||||
build/stats/src.stamp:
|
||||
mkdir -p $(@D)/src
|
||||
|
|
|
@ -8,8 +8,6 @@ import (
|
|||
"runtime/pprof"
|
||||
"strings"
|
||||
|
||||
"github.com/github/codeql-go/extractor/dbscheme"
|
||||
|
||||
"github.com/github/codeql-go/extractor"
|
||||
)
|
||||
|
||||
|
@ -20,12 +18,10 @@ func usage() {
|
|||
fmt.Fprintf(os.Stderr, "Usage:\n\n %s [<flag>...] [<buildflag>...] [--] <file>...\n\n", os.Args[0])
|
||||
fmt.Fprintf(os.Stderr, "Flags:\n\n")
|
||||
fmt.Fprintf(os.Stderr, "--help Print this help.\n")
|
||||
fmt.Fprintf(os.Stderr, "--dbscheme string Write dbscheme to this file.\n")
|
||||
}
|
||||
|
||||
func parseFlags(args []string) ([]string, []string, string) {
|
||||
func parseFlags(args []string) ([]string, []string) {
|
||||
i := 0
|
||||
var dumpDbscheme string
|
||||
buildFlags := []string{}
|
||||
for i < len(args) && strings.HasPrefix(args[i], "-") {
|
||||
if args[i] == "--" {
|
||||
|
@ -33,12 +29,7 @@ func parseFlags(args []string) ([]string, []string, string) {
|
|||
break
|
||||
}
|
||||
|
||||
if strings.HasPrefix(args[i], "--dbscheme=") {
|
||||
dumpDbscheme = strings.TrimPrefix(args[i], "--dbscheme=")
|
||||
} else if args[i] == "--dbscheme" {
|
||||
i++
|
||||
dumpDbscheme = args[i]
|
||||
} else if args[i] == "--help" {
|
||||
if args[i] == "--help" {
|
||||
usage()
|
||||
os.Exit(0)
|
||||
} else {
|
||||
|
@ -51,21 +42,11 @@ func parseFlags(args []string) ([]string, []string, string) {
|
|||
cpuprofile = os.Getenv("CODEQL_EXTRACTOR_GO_CPU_PROFILE")
|
||||
memprofile = os.Getenv("CODEQL_EXTRACTOR_GO_MEM_PROFILE")
|
||||
|
||||
return buildFlags, args[i:], dumpDbscheme
|
||||
return buildFlags, args[i:]
|
||||
}
|
||||
|
||||
func main() {
|
||||
buildFlags, patterns, dumpDbscheme := parseFlags(os.Args[1:])
|
||||
|
||||
if dumpDbscheme != "" {
|
||||
f, err := os.Create(dumpDbscheme)
|
||||
if err != nil {
|
||||
log.Fatalf("Unable to open file %s for writing.", dumpDbscheme)
|
||||
}
|
||||
dbscheme.PrintDbScheme(f)
|
||||
f.Close()
|
||||
log.Printf("Dbscheme written to file %s.", dumpDbscheme)
|
||||
}
|
||||
buildFlags, patterns := parseFlags(os.Args[1:])
|
||||
|
||||
if cpuprofile != "" {
|
||||
f, err := os.Create(cpuprofile)
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/github/codeql-go/extractor/dbscheme"
|
||||
)
|
||||
|
||||
func usage() {
|
||||
fmt.Fprintf(os.Stderr, "%s is a program for generating the dbscheme for CodeQL Go databases.\n\n", os.Args[0])
|
||||
fmt.Fprintf(os.Stderr, "Usage:\n\n %s <output file>\n\n", os.Args[0])
|
||||
}
|
||||
|
||||
func main() {
|
||||
if len(os.Args) != 2 {
|
||||
usage()
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
out := os.Args[1]
|
||||
|
||||
f, err := os.Create(out)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Unable to open file %s for writing.", out)
|
||||
os.Exit(1)
|
||||
}
|
||||
dbscheme.PrintDbScheme(f)
|
||||
f.Close()
|
||||
fmt.Printf("Dbscheme written to file %s.", out)
|
||||
}
|
Загрузка…
Ссылка в новой задаче