Skip to content

Commit 605a39d

Browse files
committed
modify DoWritePubFile
1 parent a2b4610 commit 605a39d

File tree

2 files changed

+18
-43
lines changed

2 files changed

+18
-43
lines changed

chore/genpub/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ func main() {
9494
genpub := func(do bool, args ...string) {
9595
fs := flagsetMap[genpubCommand]
9696
pR := fs.Bool("r", false, "true if generate .pub recursively")
97-
pDirs := fs.String("dirs", "c,math,net,os,pthread,time,", "list of subdirectories where llcppg.pub needs to be generated")
97+
//deflib := "c,math,net,os,pthread,time,"
98+
pDirs := fs.String("dirs", "", "list of subdirectories where llcppg.pub needs to be generated")
9899
if err := fs.Parse(args); err != nil {
99100
log.Printf("error: %s", err)
100101
return

chore/genpub/pub/handle.go

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -260,33 +260,6 @@ func GenAstFiles(quit chan int, dir string, fset *token.FileSet) <-chan *ast.Fil
260260
return output
261261
}
262262

263-
func writeAstFiles(quit chan int, fset *token.FileSet, files <-chan *ast.File) <-chan string {
264-
output := make(chan string)
265-
go func() {
266-
defer close(output)
267-
for file := range files {
268-
temp, err := os.CreateTemp(os.TempDir(), "file*.pub")
269-
if err != nil {
270-
fmt.Println(err)
271-
return
272-
}
273-
defer temp.Close()
274-
w := bufio.NewWriter(temp)
275-
defer func() {
276-
if w.Buffered() > 0 {
277-
w.Flush()
278-
output <- temp.Name()
279-
} else {
280-
os.Remove(temp.Name())
281-
}
282-
}()
283-
pubWriter := NewPubWriter(w, fset)
284-
pubWriter.WriteFile(file)
285-
}
286-
}()
287-
return output
288-
}
289-
290263
func DoWritePubFile(w io.Writer, pubFile string) {
291264
quit := make(chan int)
292265
defer func() {
@@ -295,21 +268,22 @@ func DoWritePubFile(w io.Writer, pubFile string) {
295268
fset := token.NewFileSet()
296269
dir := filepath.Dir(pubFile)
297270
astFiles := GenAstFiles(quit, dir, fset)
298-
files := writeAstFiles(quit, fset, astFiles)
299-
wg := sync.WaitGroup{}
300-
for file := range files {
301-
wg.Add(1)
302-
go func(fileName string) {
303-
defer func() {
304-
os.Remove(fileName)
305-
wg.Done()
306-
}()
307-
b, err := os.ReadFile(fileName)
308-
if err != nil {
309-
panic(err)
271+
var prev, next chan int
272+
for astFile := range astFiles {
273+
next = make(chan int)
274+
go func(wr io.Writer, file *ast.File, prev, next chan int) {
275+
if prev != nil {
276+
<-prev
310277
}
311-
w.Write(b)
312-
}(file)
278+
pubWriter := NewPubWriter(wr, fset)
279+
pubWriter.WriteFile(file)
280+
if next != nil {
281+
next <- 0
282+
}
283+
}(w, astFile, prev, next)
284+
prev = next
285+
}
286+
if next != nil {
287+
<-next
313288
}
314-
wg.Wait()
315289
}

0 commit comments

Comments
 (0)