本文整理汇总了Golang中sourcegraph/com/sourcegraph/srclib/plan.SourceUnitDataFilename函数的典型用法代码示例。如果您正苦于以下问题:Golang SourceUnitDataFilename函数的具体用法?Golang SourceUnitDataFilename怎么用?Golang SourceUnitDataFilename使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SourceUnitDataFilename函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Targets
func (r *GraphMultiUnitsRule) Targets() map[string]*unit.SourceUnit {
targets := make(map[string]*unit.SourceUnit)
for _, u := range r.Units {
targets[filepath.ToSlash(filepath.Join(r.dataDir, plan.SourceUnitDataFilename(&graph.Output{}, u)))] = u
}
return targets
}
示例2: Target
func (r *GraphMultiUnitsRule) Target() string {
// This is a dummy target, which is only used for ensuring a stable ordering of
// the makefile rules (see plan/util.go). Both import command and coverage command
// call the Targets() method to get the *.graph.json filepaths for all units graphed
// by this rule.
return filepath.ToSlash(filepath.Join(r.dataDir, plan.SourceUnitDataFilename(&graph.Output{}, &unit.SourceUnit{Key: unit.Key{Type: r.UnitsType}})))
}
示例3: Prereqs
func (r *GraphUnitRule) Prereqs() []string {
ps := []string{filepath.ToSlash(filepath.Join(r.dataDir, plan.SourceUnitDataFilename(unit.SourceUnit{}, r.Unit)))}
for _, file := range r.Unit.Files {
if _, err := os.Stat(file); err != nil && os.IsNotExist(err) {
// skip not-existent files listed in source unit
continue
}
ps = append(ps, file)
}
return ps
}
示例4: Recipes
func (r *GraphMultiUnitsRule) Recipes() []string {
if r.Tool == nil {
return nil
}
safeCommand := util.SafeCommandName(srclib.CommandName)
unitFiles := []string{}
for _, u := range r.Units {
unitFiles = append(unitFiles, filepath.ToSlash(filepath.Join(r.dataDir, plan.SourceUnitDataFilename(unit.SourceUnit{}, u))))
}
// Use `find` command + `xargs` because otherwise the arguments list can become too long.
var findCmd = "find -L"
if runtime.GOOS == "windows" {
findCmd = "/usr/bin/find"
}
return []string{
fmt.Sprintf(`%s %s -name "*%s.unit.json" | xargs %s internal emit-unit-data | %s tool %q %q | %s internal normalize-graph-data --unit-type %q --dir . --multi --data-dir %s`, findCmd, filepath.ToSlash(r.dataDir), r.UnitsType, safeCommand, safeCommand, r.Tool.Toolchain, r.Tool.Subcmd, safeCommand, r.UnitsType, filepath.ToSlash(r.dataDir)),
}
}
示例5: Execute
func (c *ConfigCmd) Execute(args []string) error {
if c.w == nil {
c.w = os.Stdout
}
if c.Quiet {
c.w = nopWriteCloser{}
}
cfg, err := getInitialConfig(c.Options, c.Args.Dir.String())
if err != nil {
return err
}
if len(cfg.PreConfigCommands) > 0 {
if err := runPreConfigCommands(c.Args.Dir.String(), cfg.PreConfigCommands, c.ToolchainExecOpt, c.Quiet); err != nil {
return fmt.Errorf("PreConfigCommands: %s", err)
}
}
if err := scanUnitsIntoConfig(cfg, c.Options, c.ToolchainExecOpt, c.Quiet); err != nil {
return fmt.Errorf("failed to scan for source units: %s", err)
}
localRepo, err := OpenRepo(c.Args.Dir.String())
if err != nil {
return fmt.Errorf("failed to open repo: %s", err)
}
buildStore, err := buildstore.LocalRepo(localRepo.RootDir)
if err != nil {
return err
}
commitFS := buildStore.Commit(localRepo.CommitID)
// Write source units to build cache.
if err := rwvfs.MkdirAll(commitFS, "."); err != nil {
return err
}
for _, u := range cfg.SourceUnits {
unitFile := plan.SourceUnitDataFilename(unit.SourceUnit{}, u)
if err := rwvfs.MkdirAll(commitFS, filepath.Dir(unitFile)); err != nil {
return err
}
f, err := commitFS.Create(unitFile)
if err != nil {
return err
}
defer f.Close()
if err := json.NewEncoder(f).Encode(u); err != nil {
return err
}
if err := f.Close(); err != nil {
log.Fatal(err)
}
}
if c.Output.Output == "json" {
PrintJSON(cfg, "")
} else {
fmt.Fprintf(c.w, "SCANNERS (%d)\n", len(cfg.Scanners))
for _, s := range cfg.Scanners {
fmt.Fprintf(c.w, " - %s\n", s)
}
fmt.Fprintln(c.w)
fmt.Fprintf(c.w, "SOURCE UNITS (%d)\n", len(cfg.SourceUnits))
for _, u := range cfg.SourceUnits {
fmt.Fprintf(c.w, " - %s: %s\n", u.Type, u.Name)
}
fmt.Fprintln(c.w)
fmt.Fprintf(c.w, "CONFIG PROPERTIES (%d)\n", len(cfg.Config))
for _, kv := range sortedMap(cfg.Config) {
fmt.Fprintf(c.w, " - %s: %s\n", kv[0], kv[1])
}
}
return nil
}
示例6: Execute
func (c *APIDescribeCmd) Execute(args []string) error {
context, err := prepareCommandContext(c.File)
if err != nil {
return err
}
file := context.relativeFile
units, err := getSourceUnitsWithFile(context.buildStore, context.repo, file)
if err != nil {
return err
}
if GlobalOpt.Verbose {
if len(units) > 0 {
ids := make([]string, len(units))
for i, u := range units {
ids[i] = string(u.ID())
}
log.Printf("Position %s:%d is in %d source units %v.", file, c.StartByte, len(units), ids)
} else {
log.Printf("Position %s:%d is not in any source units.", file, c.StartByte)
}
}
// Find the ref(s) at the character position.
var ref *graph.Ref
var nearbyRefs []*graph.Ref // Find nearby refs to help with debugging.
OuterLoop:
for _, u := range units {
var g graph.Output
graphFile := plan.SourceUnitDataFilename("graph", u)
f, err := context.commitFS.Open(graphFile)
if err != nil {
return err
}
defer f.Close()
if err := json.NewDecoder(f).Decode(&g); err != nil {
return fmt.Errorf("%s: %s", graphFile, err)
}
for _, ref2 := range g.Refs {
if file == ref2.File {
if c.StartByte >= ref2.Start && c.StartByte <= ref2.End {
ref = ref2
if ref.DefUnit == "" {
ref.DefUnit = u.Name
}
if ref.DefUnitType == "" {
ref.DefUnitType = u.Type
}
break OuterLoop
} else if GlobalOpt.Verbose && abs(int(ref2.Start)-int(c.StartByte)) < 25 {
nearbyRefs = append(nearbyRefs, ref2)
}
}
}
}
if ref == nil {
if GlobalOpt.Verbose {
log.Printf("No ref found at %s:%d.", file, c.StartByte)
if len(nearbyRefs) > 0 {
log.Printf("However, nearby refs were found in the same file:")
for _, nref := range nearbyRefs {
log.Printf("Ref at bytes %d-%d to %v", nref.Start, nref.End, nref.DefKey())
}
}
f, err := os.Open(file)
if err == nil {
defer f.Close()
b, err := ioutil.ReadAll(f)
if err != nil {
log.Fatalf("Error reading source file: %s.", err)
}
start := c.StartByte
if start < 0 || int(start) > len(b)-1 {
log.Fatalf("Start byte %d is out of file bounds.", c.StartByte)
}
end := c.StartByte + 50
if int(end) > len(b)-1 {
end = uint32(len(b) - 1)
}
log.Printf("Surrounding source is:\n\n%s", b[start:end])
} else {
log.Printf("Error opening source file to show surrounding source: %s.", err)
}
}
fmt.Println(`{}`)
return nil
}
// ref.DefRepo is *not* guaranteed to be non-empty, as
// repo.URI() will return the empty string if the repo's
// CloneURL is empty or malformed.
if ref.DefRepo == "" {
ref.DefRepo = context.repo.URI()
}
var resp apiDescribeCmdOutput
// Now find the def for this ref.
//.........这里部分代码省略.........
示例7: Prereqs
func (r *GraphUnitRule) Prereqs() []string {
ps := []string{filepath.ToSlash(filepath.Join(r.dataDir, plan.SourceUnitDataFilename(unit.SourceUnit{}, r.Unit)))}
ps = append(ps, r.Unit.Files...)
return ps
}
示例8: Target
func (r *GraphUnitRule) Target() string {
return filepath.ToSlash(filepath.Join(r.dataDir, plan.SourceUnitDataFilename(&graph.Output{}, r.Unit)))
}
示例9: Prereqs
func (r *ResolveDepsRule) Prereqs() []string {
return []string{filepath.Join(r.dataDir, plan.SourceUnitDataFilename(unit.SourceUnit{}, r.Unit))}
}
示例10: Target
func (r *ResolveDepsRule) Target() string {
return filepath.Join(r.dataDir, plan.SourceUnitDataFilename([]*ResolvedDep{}, r.Unit))
}
示例11: Execute
func (c *NormalizeGraphDataCmd) Execute(args []string) error {
in := os.Stdin
var o *graph.Output
if err := json.NewDecoder(in).Decode(&o); err != nil {
return err
}
if !c.Multi {
if err := grapher.NormalizeData(c.UnitType, c.Dir, o); err != nil {
return err
}
data, err := json.MarshalIndent(o, "", " ")
if err != nil {
return err
}
if _, err := os.Stdout.Write(data); err != nil {
return err
}
return nil
}
// If `graph` emits multiple source units, in this case, don't
// write to stdout (the rule will not direct it to a file), but
// instead write to multiple .graph.json files (one for each
// source unit). This is a HACK.
// graphPerUnit maps source unit names to the graph data of
// that unit.
graphPerUnit := make(map[string]*graph.Output)
initUnitGraph := func(unitName string) {
if _, ok := graphPerUnit[unitName]; !ok {
graphPerUnit[unitName] = &graph.Output{}
}
}
// Split the graph data per source unit.
for _, d := range o.Defs {
if d.Unit == "" {
log.Printf("skip def with empty unit: %v", d)
continue
}
initUnitGraph(d.Unit)
graphPerUnit[d.Unit].Defs = append(graphPerUnit[d.Unit].Defs, d)
}
for _, r := range o.Refs {
if r.Unit == "" {
log.Printf("skip ref with empty unit: %v", r)
continue
}
initUnitGraph(r.Unit)
graphPerUnit[r.Unit].Refs = append(graphPerUnit[r.Unit].Refs, r)
}
for _, d := range o.Docs {
if d.DocUnit == "" {
log.Printf("skip doc with empty unit: %v", d)
continue
}
initUnitGraph(d.DocUnit)
graphPerUnit[d.DocUnit].Docs = append(graphPerUnit[d.DocUnit].Docs, d)
}
for _, a := range o.Anns {
if a.Unit == "" {
log.Printf("skip ann with empty unit: %v", a)
continue
}
initUnitGraph(a.Unit)
graphPerUnit[a.Unit].Anns = append(graphPerUnit[a.Unit].Anns, a)
}
// Write the graph data to a separate file for each source unit.
for unitName, graphData := range graphPerUnit {
if err := grapher.NormalizeData(c.UnitType, c.Dir, graphData); err != nil {
log.Printf("skipping unit %s because failed to normalize data: %s", unitName, err)
continue
}
path := filepath.ToSlash(filepath.Join(c.DataDir, plan.SourceUnitDataFilename(&graph.Output{}, &unit.SourceUnit{Key: unit.Key{Name: unitName, Type: c.UnitType}})))
graphFile, err := os.Create(path)
if err != nil {
return err
}
data, err := json.MarshalIndent(graphData, "", " ")
if err != nil {
return err
}
if _, err := graphFile.Write(data); err != nil {
return err
}
}
return nil
}
示例12: Execute
func (c *APIDescribeCmd) Execute(args []string) error {
context, err := prepareCommandContext(c.File)
if err != nil {
return err
}
file := context.relativeFile
units, err := getSourceUnitsWithFile(context.buildStore, context.repo, file)
if err != nil {
return err
}
if GlobalOpt.Verbose {
if len(units) > 0 {
ids := make([]string, len(units))
for i, u := range units {
ids[i] = string(u.ID())
}
log.Printf("Position %s:%d is in %d source units %v.", file, c.StartByte, len(units), ids)
} else {
log.Printf("Position %s:%d is not in any source units.", file, c.StartByte)
}
}
// Find the ref(s) at the character position.
var ref *graph.Ref
var nearbyRefs []*graph.Ref // Find nearby refs to help with debugging.
OuterLoop:
for _, u := range units {
var g graph.Output
graphFile := plan.SourceUnitDataFilename("graph", u)
f, err := context.commitFS.Open(graphFile)
if err != nil {
return err
}
defer f.Close()
if err := json.NewDecoder(f).Decode(&g); err != nil {
return fmt.Errorf("%s: %s", graphFile, err)
}
for _, ref2 := range g.Refs {
if file == ref2.File {
if c.StartByte >= ref2.Start && c.StartByte <= ref2.End {
ref = ref2
if ref.DefUnit == "" {
ref.DefUnit = u.Name
}
if ref.DefUnitType == "" {
ref.DefUnitType = u.Type
}
break OuterLoop
} else if GlobalOpt.Verbose && abs(int(ref2.Start)-int(c.StartByte)) < 25 {
nearbyRefs = append(nearbyRefs, ref2)
}
}
}
}
if ref == nil {
if GlobalOpt.Verbose {
log.Printf("No ref found at %s:%d.", file, c.StartByte)
if len(nearbyRefs) > 0 {
log.Printf("However, nearby refs were found in the same file:")
for _, nref := range nearbyRefs {
log.Printf("Ref at bytes %d-%d to %v", nref.Start, nref.End, nref.DefKey())
}
}
f, err := os.Open(file)
if err == nil {
defer f.Close()
b, err := ioutil.ReadAll(f)
if err != nil {
log.Fatalf("Error reading source file: %s.", err)
}
start := c.StartByte
if start < 0 || int(start) > len(b)-1 {
log.Fatalf("Start byte %d is out of file bounds.", c.StartByte)
}
end := c.StartByte + 50
if int(end) > len(b)-1 {
end = uint32(len(b) - 1)
}
log.Printf("Surrounding source is:\n\n%s", b[start:end])
} else {
log.Printf("Error opening source file to show surrounding source: %s.", err)
}
}
colorable.Println(`{}`)
return nil
}
var resp apiDescribeCmdOutput
// Now find the def for this ref.
defInCurrentRepo := ref.DefRepo == ""
if defInCurrentRepo {
// Def is in the current repo.
var g graph.Output
graphFile := plan.SourceUnitDataFilename("graph", &unit.SourceUnit{Name: ref.DefUnit, Type: ref.DefUnitType})
f, err := context.commitFS.Open(graphFile)
//.........这里部分代码省略.........