Added support for single file builds
This commit is contained in:
parent
d04c216dc2
commit
423526e567
4 changed files with 57 additions and 24 deletions
|
@ -11,12 +11,12 @@ import (
|
|||
)
|
||||
|
||||
// Scan scans the directory.
|
||||
func Scan(path string) (<-chan *Function, <-chan error) {
|
||||
func Scan(files []string) (<-chan *Function, <-chan error) {
|
||||
functions := make(chan *Function)
|
||||
errors := make(chan error)
|
||||
|
||||
go func() {
|
||||
scan(path, functions, errors)
|
||||
scan(files, functions, errors)
|
||||
close(functions)
|
||||
close(errors)
|
||||
}()
|
||||
|
@ -25,29 +25,51 @@ func Scan(path string) (<-chan *Function, <-chan error) {
|
|||
}
|
||||
|
||||
// scan scans the directory without channel allocations.
|
||||
func scan(path string, functions chan<- *Function, errors chan<- error) {
|
||||
func scan(files []string, functions chan<- *Function, errors chan<- error) {
|
||||
wg := sync.WaitGroup{}
|
||||
|
||||
err := directory.Walk(path, func(name string) {
|
||||
if !strings.HasSuffix(name, ".q") {
|
||||
for _, file := range files {
|
||||
stat, err := os.Stat(file)
|
||||
|
||||
if err != nil {
|
||||
errors <- err
|
||||
return
|
||||
}
|
||||
|
||||
fullPath := filepath.Join(path, name)
|
||||
wg.Add(1)
|
||||
if stat.IsDir() {
|
||||
err = directory.Walk(file, func(name string) {
|
||||
if !strings.HasSuffix(name, ".q") {
|
||||
return
|
||||
}
|
||||
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
err := scanFile(fullPath, functions)
|
||||
fullPath := filepath.Join(file, name)
|
||||
wg.Add(1)
|
||||
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
err := scanFile(fullPath, functions)
|
||||
|
||||
if err != nil {
|
||||
errors <- err
|
||||
}
|
||||
}()
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
errors <- err
|
||||
}
|
||||
}()
|
||||
})
|
||||
} else {
|
||||
wg.Add(1)
|
||||
|
||||
if err != nil {
|
||||
errors <- err
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
err := scanFile(file, functions)
|
||||
|
||||
if err != nil {
|
||||
errors <- err
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue