Skip to content

Commit

Permalink
Solve comments on PR
Browse files Browse the repository at this point in the history
  • Loading branch information
Villaquiranm committed Sep 29, 2024
1 parent 9f63d7f commit eaf6a87
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 22 deletions.
4 changes: 2 additions & 2 deletions misc/stdlib_diff/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ Stdlibs_diff is a tool that generates an html report indicating differences betw
Compare the `go` standard libraries the `gno` standard libraries

```shell
./stdlibs_diff --src <path to go standard libraries> --dst <path to gno standard libraries> --out <output directory>
./stdlibs_diff -src <path to go standard libraries> -dst <path to gno standard libraries> -out <output directory>
```

Compare the `gno` standard libraries the `go` standard libraries

```shell
./stdlibs_diff --src <path to gno standard libraries> --dst <path to go standard libraries> --out <output directory> --src_is_gno
./stdlibs_diff -src <path to gno standard libraries> -dst <path to go standard libraries> -out <output directory> -src_is_gno
```


Expand Down
3 changes: 3 additions & 0 deletions misc/stdlib_diff/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/gnolang/gno/misc/stdlib_diff

go 1.21.0
40 changes: 22 additions & 18 deletions misc/stdlib_diff/packagediff.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package main

import (
"fmt"
"errors"
"io/fs"
"os"
"path/filepath"
"slices"
"strings"
)
Expand Down Expand Up @@ -155,26 +157,28 @@ func (p *PackageDiffChecker) hasSameNumberOfFiles() bool {

// listDirFiles returns a list of file names in the specified directory.
func listDirFiles(dirPath string) ([]string, error) {
f, err := os.Open(dirPath)
if err != nil {
return []string{}, nil
}
fileNames := make([]string, 0)
err := filepath.WalkDir(dirPath, func(path string, dirEntry fs.DirEntry, err error) error {
if err != nil {
// Avoid returning an error if the file does not exists on source or destination.
if errors.Is(err, os.ErrNotExist) {
return nil
}
return err
}

defer func() {
if err := f.Close(); err != nil {
fmt.Fprintln(os.Stderr, "can't close "+dirPath)
// Only list .go and .gno files
if !strings.Contains(path, ".go") && !strings.Contains(path, ".gno") {
return nil
}
}()

filesInfo, err := f.Readdir(0)
if err != nil {
return nil, fmt.Errorf("can't list file in directory :%w", err)
}
if dirEntry != nil && !dirEntry.IsDir() {
filenameWithSubfolder := strings.TrimPrefix(path, dirPath+"/")
fileNames = append(fileNames, filenameWithSubfolder)
}

fileNames := make([]string, 0)
for _, info := range filesInfo {
fileNames = append(fileNames, info.Name())
}
return nil
})

return fileNames, nil
return fileNames, err
}
3 changes: 2 additions & 1 deletion misc/stdlib_diff/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"html/template"
"os"
"slices"
)

var (
Expand Down Expand Up @@ -133,7 +134,7 @@ func (builder *ReportBuilder) listSrcDirectories() ([]string, error) {

directories := make([]string, 0)
for _, dirEntry := range dirEntries {
if dirEntry.IsDir() {
if dirEntry.IsDir() && !slices.Contains([]string{"cmd", "vendor"}, dirEntry.Name()) {
directories = append(directories, dirEntry.Name())
}
}
Expand Down
2 changes: 1 addition & 1 deletion misc/stdlib_diff/templates/package_diff_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{{- else if eq .Line ""}}
<br />
{{- else}}
<p style="opacity: 0.65;">{{.Line}}</p>
<p style="opacity: 0.75;">{{.Line}}</p>
{{- end}}
{{- end}}
</div>
Expand Down

0 comments on commit eaf6a87

Please sign in to comment.