Closed peterzhu1992 closed 2 years ago
@eliben opened a PR, please review, please raise comments if you want me to improve anything. It is my 1st time contribute to this repo so things can be messy. 😄
Thanks.
Sorry, I was meaning to comment this on the issue - let's separate the renaming into its own PR first. Once that one lands, this PR can be rebased and reviewed.
Hi @eliben,
Sure, I have put this PR back to WIP. Please approve and merge this renaming 1st.
I will rebase this PR once that one is merge.
Thanks.
Hi @eliben,
Thanks for merging #424 and I have also resolved the conflict of this one.
Please review, thanks.
@eliben there are some issues with using example_folder
.
The reason being that //go:embed
requires the files to be presented when compiling.
And the existing measure.go/generate.go will panic if sourcePath
is a dir when readline.
If I dont include the example_folder
and its files, error out:
Running tests...
examples/embed-directive/embed-directive.go:25:12: pattern example_folder/*.hash: no matching files found
If I include the example_folder
and its files, error out:
Measuring line lengths...
measure: examples/embed-directive/embed-directive.go:38
panic: read examples/embed-directive/example_folder: is a directory
goroutine 1 [running]: main.check(...) /Users/zhujiaxi/amazonworks/sourcecodes/peterzhuamazon/gobyexample_peterzhu1992/tools/measure.go:14 main.readLines({0xc0001507e0?, 0x0?}) /Users/zhujiaxi/amazonworks/sourcecodes/peterzhuamazon/gobyexample_peterzhu1992/tools/measure.go:20 +0x67 main.main() /Users/zhujiaxi/amazonworks/sourcecodes/peterzhuamazon/gobyexample_peterzhu1992/tools/measure.go:32 +0xa8 exit status 2
panic: read examples/embed-directive/example_folder: is a directory goroutine 1 [running]: main.check(...) /Users/zhujiaxi/amazonworks/sourcecodes/peterzhuamazon/gobyexample_peterzhu1992/tools/generate.go:35 main.mustReadFile(...) /Users/zhujiaxi/amazonworks/sourcecodes/peterzhuamazon/gobyexample_peterzhu1992/tools/generate.go:79 main.readLines({0xc000840bd0?, 0x12f4e7e?}) /Users/zhujiaxi/amazonworks/sourcecodes/peterzhuamazon/gobyexample_peterzhu1992/tools/generate.go:88 +0x67 main.parseSegs({0xc000840bd0?, 0x35?}) /Users/zhujiaxi/amazonworks/sourcecodes/peterzhuamazon/gobyexample_peterzhu1992/tools/generate.go:159 +0x36 main.parseAndRenderSegs({0xc000840bd0, 0x27}) /Users/zhujiaxi/amazonworks/sourcecodes/peterzhuamazon/gobyexample_peterzhu1992/tools/generate.go:234 +0x2d main.parseExamples() /Users/zhujiaxi/amazonworks/sourcecodes/peterzhuamazon/gobyexample_peterzhu1992/tools/generate.go:281 +0x6de main.main() /Users/zhujiaxi/amazonworks/sourcecodes/peterzhuamazon/gobyexample_peterzhu1992/tools/generate.go:348 +0x1d2 exit status 2
It seems like we need to add a check in `measure.go` and `generate.go` to ensure readline does not happen on directories, like:
fileInfo, _ := os.Stat(sourcePath) if !fileInfo.IsDir() {}
Let me know how you think about this, I cannot think of any better solutions now.
PS: I now remember this is the reason I used `embad-directive.hash` as sample file to start with.
Thanks.
Yes, I think it should be fine to skip directories in measure/build.
Sure @eliben I am a bit busy these few days, will find a time slot to correct the scripts and push again. Thanks.
It is actually easier than I thought, so complete the changes right now. Please review @eliben . Thanks.
Hi @eliben I read your follow up tweaks they are truly better. Happy to see it shows up on the main website now.
Thanks.
Signed-off-by: peterzhu1992 peterzhu1992@gmail.com
Description
Add embed-directive example and rename embedding to struct-embedding.
Resolved Issue
422