golang dependency analysis - s²erc...ball state university go program structure •a package is 1:1...
TRANSCRIPT
![Page 1: GoLang Dependency Analysis - S²ERC...Ball State University Go Program Structure •A Package is 1:1 with a source directory •An executable is 1:1 with a package named main _ •Other](https://reader034.vdocuments.us/reader034/viewer/2022042302/5ecd4de0bdf3a53aec2fabfc/html5/thumbnails/1.jpg)
Ball State University
GoLang Dependency AnalysisPaul Buis
![Page 2: GoLang Dependency Analysis - S²ERC...Ball State University Go Program Structure •A Package is 1:1 with a source directory •An executable is 1:1 with a package named main _ •Other](https://reader034.vdocuments.us/reader034/viewer/2022042302/5ecd4de0bdf3a53aec2fabfc/html5/thumbnails/2.jpg)
Ball State University
Go Programming Language
•Being developed by Google as a systems language
•Open Source
•Rapidly rising in popularity
•DevOps features to prevent• Linker errors• Deployment errors
![Page 3: GoLang Dependency Analysis - S²ERC...Ball State University Go Program Structure •A Package is 1:1 with a source directory •An executable is 1:1 with a package named main _ •Other](https://reader034.vdocuments.us/reader034/viewer/2022042302/5ecd4de0bdf3a53aec2fabfc/html5/thumbnails/3.jpg)
Ball State University
Go Program Structure
•A Package is 1:1 with a source directory
•An executable is 1:1 with a package named “main”
•Other packages are 1:1 with a compiled object library
•Object library contains• Type declarations needed by importing packages• Compiled object code
![Page 4: GoLang Dependency Analysis - S²ERC...Ball State University Go Program Structure •A Package is 1:1 with a source directory •An executable is 1:1 with a package named main _ •Other](https://reader034.vdocuments.us/reader034/viewer/2022042302/5ecd4de0bdf3a53aec2fabfc/html5/thumbnails/4.jpg)
Ball State University
Dependency Implications
•Package must be compiled after the packages in it imports packages are compiled.
•No importing of source-level “header” files.
•No possible mismatch between header and library
•Dependency graph is directed acyclic graph (DAG)
•DAG rooted at main
![Page 5: GoLang Dependency Analysis - S²ERC...Ball State University Go Program Structure •A Package is 1:1 with a source directory •An executable is 1:1 with a package named main _ •Other](https://reader034.vdocuments.us/reader034/viewer/2022042302/5ecd4de0bdf3a53aec2fabfc/html5/thumbnails/5.jpg)
Ball State University
Why this is interesting
• Go is not like C / C++, where• Namespaces not required to align with libraries
• Compilation order is arbitrary
• Dependencies may be cyclic
• Go is like many other “new” languages• Guarantee of acyclic dependency
• Enables use of special algorithms
• Go standard library includes parts of compiler/linker• No high-effort, low-reliability reproduction of parser, type checker, …
• Can concentrate on analysis of code rather than reproduction of standard
![Page 6: GoLang Dependency Analysis - S²ERC...Ball State University Go Program Structure •A Package is 1:1 with a source directory •An executable is 1:1 with a package named main _ •Other](https://reader034.vdocuments.us/reader034/viewer/2022042302/5ecd4de0bdf3a53aec2fabfc/html5/thumbnails/6.jpg)
Ball State University
Godepgraph
200-line open source tool
•Generates graph represented in GraphViz dot notatation
• Expects GraphViz dot to be used to do layout & static rendering
• Example renderings look like spaghetti & meatballs
![Page 7: GoLang Dependency Analysis - S²ERC...Ball State University Go Program Structure •A Package is 1:1 with a source directory •An executable is 1:1 with a package named main _ •Other](https://reader034.vdocuments.us/reader034/viewer/2022042302/5ecd4de0bdf3a53aec2fabfc/html5/thumbnails/7.jpg)
Ball State University
Standard godepgraph example
• Static GraphViz Graph
• Nodes lack details
• Poor layout• not the fault of godepgraph
Could be improved by interactivity
• Manual node positioning
• Experiment with alternative layouts
• Hiding “uninteresting” nodes
• Adding detail to crucial nodes• File names
• Last modified dates
![Page 8: GoLang Dependency Analysis - S²ERC...Ball State University Go Program Structure •A Package is 1:1 with a source directory •An executable is 1:1 with a package named main _ •Other](https://reader034.vdocuments.us/reader034/viewer/2022042302/5ecd4de0bdf3a53aec2fabfc/html5/thumbnails/8.jpg)
Ball State University
goviz
• Like godepgraph• Generates GraphViz graph
• Expects “dot” to generate static rendering
• Unlike godepgraph• Provides more detailed information about package
• Detail useful, but can overwhelm• User picking out important information & relationships
• Output device size and resolution
![Page 9: GoLang Dependency Analysis - S²ERC...Ball State University Go Program Structure •A Package is 1:1 with a source directory •An executable is 1:1 with a package named main _ •Other](https://reader034.vdocuments.us/reader034/viewer/2022042302/5ecd4de0bdf3a53aec2fabfc/html5/thumbnails/9.jpg)
Ball State University
Goviz output rendered by GraphViz “dot”
![Page 10: GoLang Dependency Analysis - S²ERC...Ball State University Go Program Structure •A Package is 1:1 with a source directory •An executable is 1:1 with a package named main _ •Other](https://reader034.vdocuments.us/reader034/viewer/2022042302/5ecd4de0bdf3a53aec2fabfc/html5/thumbnails/10.jpg)
Ball State University
Alternative Design
Backend – replacing godepgraph / goviz
•HTTP server written in Go
•Generates graph data as JSON
Frontend – replacing GraphViz “dot”
• Interactive webpage with JavaScript
•Graph rendered as interactive SVG
![Page 11: GoLang Dependency Analysis - S²ERC...Ball State University Go Program Structure •A Package is 1:1 with a source directory •An executable is 1:1 with a package named main _ •Other](https://reader034.vdocuments.us/reader034/viewer/2022042302/5ecd4de0bdf3a53aec2fabfc/html5/thumbnails/11.jpg)
Ball State University
Backend
• Initial version based on source of godepgraph & goviz• JSON output to include lots of detail
• Use Go standard library packages• go/build
• Encoding/json
• Use GoLang.org/x/tools packages• go/loader
• Use Go standard net/http package for server framework
![Page 12: GoLang Dependency Analysis - S²ERC...Ball State University Go Program Structure •A Package is 1:1 with a source directory •An executable is 1:1 with a package named main _ •Other](https://reader034.vdocuments.us/reader034/viewer/2022042302/5ecd4de0bdf3a53aec2fabfc/html5/thumbnails/12.jpg)
Ball State University
Front End
Interactive graph rendering to control:
• level of detail displayed for each node
• layout of graph
• which nodes are displayed
Needs to be able to save graph rendering as static image for import into team engineering documents.
Use one of many existing JavaScript graph rendering packages
![Page 13: GoLang Dependency Analysis - S²ERC...Ball State University Go Program Structure •A Package is 1:1 with a source directory •An executable is 1:1 with a package named main _ •Other](https://reader034.vdocuments.us/reader034/viewer/2022042302/5ecd4de0bdf3a53aec2fabfc/html5/thumbnails/13.jpg)
Ball State University
Deliverables/Milestones
•By Spring 2017 Showcase:• Completed Backend• Prototype Frontend
•By November 2017 Showcase• Delivery of completed initial version of tool
![Page 14: GoLang Dependency Analysis - S²ERC...Ball State University Go Program Structure •A Package is 1:1 with a source directory •An executable is 1:1 with a package named main _ •Other](https://reader034.vdocuments.us/reader034/viewer/2022042302/5ecd4de0bdf3a53aec2fabfc/html5/thumbnails/14.jpg)
Ball State University
Benefits
Immediate:
• Only if you are doing Go projects
Later Projects:
• Graph Generators for other languages
• More features: e.g., versioning