Skip to content

Commit

Permalink
Merge branch 'master' into codescan
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrajz authored Jan 4, 2025
2 parents fab9847 + fb6b442 commit 43c020e
Show file tree
Hide file tree
Showing 16 changed files with 467 additions and 278 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These are supported funding model platforms

patreon: ofabry
patreon: ondrajz
open_collective: go-callvis

# github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: CI

on:
push:
pull_request:
branches: [ master ]
schedule:
- cron: '0 3 * * *'

jobs:
build-test:
name: "Build & Test"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
go: [ 'stable', 'oldstable', '1.21' ]

steps:
- name: "Checkout"
uses: actions/checkout@v4

- name: "Setup Go ${{ matrix.go }}"
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}

- name: "Download Deps"
run: go mod download -x

- name: "Check go.mod"
run: |
go mod tidy -v
git diff --name-only --exit-code go.mod || ( git diff && echo "Run go tidy to update go.mod" && false )
- name: "Build"
run: make build

- name: "Test"
run: make test
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@ _testmain.go
*.out

# Builds
build/
/.build/
go-callvis

# IDE
/.idea/
12 changes: 0 additions & 12 deletions .travis.yml

This file was deleted.

63 changes: 41 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,34 +1,56 @@
SHELL = /bin/bash
SHELL := /usr/bin/env bash -o pipefail

GIT_VERSION ?= $(shell git describe --always --tags --always --dirty)
GIT_VERSION ?= $(shell git describe --always --tags --match 'v*' --dirty)
COMMIT ?= $(shell git rev-parse HEAD)
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
BUILD_DATE ?= $(shell date +%s)
BUILD_HOST ?= $(shell hostname)
BUILD_USER ?= $(shell id -un)

PROJECT := go-callvis
BUILD_DIR ?= .build

GOOS ?= $(shell go env GOOS)
GOARCH = amd64
PLATFORMS := linux-$(GOARCH) darwin-$(GOARCH)

BUILD_DIR ?= ./build
ORG := github.com/ofabry
PROJECT := go-callvis
REPOPATH ?= $(ORG)/$(PROJECT)
BUILD_PACKAGE = $(REPOPATH)

GO_BUILD_TAGS ?= ""
GO_LDFLAGS := "-X main.commit=$(GIT_VERSION)"
GO_FILES := $(shell go list -f '{{join .Deps "\n"}}' $(BUILD_PACKAGE) | grep $(ORG) | xargs go list -f '{{ range $$file := .GoFiles }} {{$$.Dir}}/{{$$file}}{{"\n"}}{{end}}')
GO_LDFLAGS := \
-X main.commit=$(GIT_VERSION)
GO_FILES := $(shell go list ./... | xargs go list -f '{{ range $$file := .GoFiles }} {{$$.Dir}}/{{$$file}}{{"\n"}}{{end}}')

ifeq ($(NOSTRIP),)
GO_LDFLAGS += -w -s
endif

ifeq ($(NOTRIM),)
GO_BUILD_ARGS += -trimpath
endif

ifeq ($(V),1)
GO_BUILD_ARGS += -v
endif

export GO111MODULE=on
export DOCKER_BUILDKIT=1

help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

install:
go install -tags $(GO_BUILD_TAGS) -ldflags $(GO_LDFLAGS)
build: ## Build go-callvis
go build -v -tags $(GO_BUILD_TAGS) -ldflags "$(GO_LDFLAGS)" $(GO_BUILD_ARGS)

all:
go build -tags $(GO_BUILD_TAGS) -ldflags $(GO_LDFLAGS)
test: ## Run unit tests
go test -tags $(GO_BUILD_TAGS) -ldflags "$(GO_LDFLAGS)" $(GO_BUILD_ARGS) -short -race ./...

install: ## Install go-callvis
go install -tags $(GO_BUILD_TAGS) -ldflags "$(GO_LDFLAGS)" $(GO_BUILD_ARGS)

$(BUILD_DIR)/$(PROJECT): $(BUILD_DIR)/$(PROJECT)-$(GOOS)-$(GOARCH)
cp $(BUILD_DIR)/$(PROJECT)-$(GOOS)-$(GOARCH) $@

$(BUILD_DIR)/$(PROJECT)-%-$(GOARCH): $(GO_FILES) $(BUILD_DIR)
GOOS=$* GOARCH=$(GOARCH) go build -tags $(GO_BUILD_TAGS) -ldflags $(GO_LDFLAGS) -o $@ $(BUILD_PACKAGE)
GOOS=$* GOARCH=$(GOARCH) go build -tags $(GO_BUILD_TAGS) -ldflags "$(GO_LDFLAGS)" -o $@ $(GO_BUILD_ARGS)

%.sha256: %
shasum -a 256 $< &> $@
Expand All @@ -40,13 +62,10 @@ $(BUILD_DIR):

cross: $(foreach platform, $(PLATFORMS), $(BUILD_DIR)/$(PROJECT)-$(platform).sha256)

release: cross
release: cross ## Release go-callvis
ls -hl $(BUILD_DIR)

test: $(BUILD_DIR)/$(PROJECT)
go test -v $(REPOPATH)

clean:
rm -rf $(BUILD_DIR)
clean: ## Clean build directory
rm -vrf $(BUILD_DIR)

.PHONY: cross release install test clean
.PHONY: help build test install cross release clean
111 changes: 64 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
<h1 align="center">go-callvis</h1>

<p align="center">
<a href="https://github.com/ofabry/go-callvis/releases"><img src="https://img.shields.io/github/release/ofabry/go-callvis.svg" alt="Github release"></a>
<a href="https://travis-ci.org/ofabry/go-callvis"><img src="https://travis-ci.org/ofabry/go-callvis.svg?branch=master" alt="Build status"></a>
<a href="https://github.com/ondrajz/go-callvis/releases"><img src="https://img.shields.io/github/release/ondrajz/go-callvis.svg?label=latest%20release&logo=github&sort=semver&color=blue" alt="Github release"></a>
<a href="https://github.com/ondrajz/go-callvis/actions"><img src="https://github.com/ondrajz/go-callvis/actions/workflows/ci.yml/badge.svg" alt="Build status"></a>
<a href="https://github.com/nikolaydubina/go-recipes"><img src="https://raw.githubusercontent.com/nikolaydubina/go-recipes/main/badge.svg?raw=true" alt="go-recipes"></a>
<a href="https://gophers.slack.com/archives/go-callvis"><img src="https://img.shields.io/badge/gophers%20slack-%23go--callvis-ff69b4.svg" alt="Slack channel"></a>
</p>

Expand All @@ -20,17 +21,17 @@ the code much higher or when you are just simply trying to understand code of so

### Features

- 🆕 **support for Go modules!** :boom:
- focus specific package in the program
- click on package to quickly switch the focus using [interactive viewer](#interactive-viewer)
- group functions by package and/or methods by type
- focus specific package in the program
- group functions by package
- group methods by their receiver type
- filter packages to specific import path prefixes
- ignore funcs from standard library
- ignore calls to/from standard library
- omit various types of function calls

### Output preview

[![main](images/main.png)](https://raw.githubusercontent.com/ofabry/go-callvis/master/images/main.png)
[![main](images/main.png)](images/main.png)

> Check out the [source code](examples/main) for the above image.
Expand All @@ -39,52 +40,34 @@ the code much higher or when you are just simply trying to understand code of so
It runs [pointer analysis](https://godoc.org/golang.org/x/tools/go/pointer) to construct the call graph of the program and
uses the data to generate output in [dot format](http://www.graphviz.org/content/dot-language), which can be rendered with Graphviz tools.

## Reference guide

Here you can find descriptions for various types of output.

### Packages / Types

|Represents | Style|
|----------: | :-------------|
|`focused` | **blue** color|
|`stdlib` | **green** color|
|`other` | **yellow** color|

### Functions / Methods
## Quick start

|Represents | Style|
|-----------: | :--------------|
|`exported` | **bold** border|
|`unexported` | **normal** border|
|`anonymous` | **dotted** border|
### Installation

### Calls
#### Requirements

|Represents | Style|
|-----------: | :-------------|
|`internal` | **black** color|
|`external` | **brown** color|
|`static` | **solid** line|
|`dynamic` | **dashed** line|
|`regular` | **simple** arrow|
|`concurrent` | arrow with **circle**|
|`deferred` | arrow with **diamond**|
- [Go](https://golang.org/dl/) 1.19+
- [Graphviz](http://www.graphviz.org/download/) (optional, required only with `-graphviz` flag)

## Quick start
To install go-callvis, run:

#### Requirements
```sh
# Latest release
go install github.com/ofabry/go-callvis@latest

- [Go](https://golang.org/dl/) 1.13+
- [Graphviz](http://www.graphviz.org/download/) (optional, required only with `-graphviz` flag)
# Development version
go install github.com/ofabry/go-callvis@master
```

### Installation
Alternatively, clone the repository and compile the source code:

```sh
go get -u github.com/ofabry/go-callvis
# or
# Clone repository
git clone https://github.com/ofabry/go-callvis.git
cd go-callvis && make install
cd go-callvis

# Compile and install
make install
```

### Usage
Expand Down Expand Up @@ -145,17 +128,51 @@ Usage of go-callvis:
a list of build tags to consider satisfied during the build. For more information about build tags, see the description of build constraints in the documentation for the go/build package
-tests
Include test code.
-algo string
Use specific algorithm for package analyzer: static, cha or rta (default "static")
-version
Show version and exit.
```

Run `go-callvis -h` to list all supported options.

## Reference guide

Here you can find descriptions for various types of output.

### Packages / Types

|Represents | Style|
|----------: | :-------------|
|`focused` | **blue** color|
|`stdlib` | **green** color|
|`other` | **yellow** color|

### Functions / Methods

|Represents | Style|
|-----------: | :--------------|
|`exported` | **bold** border|
|`unexported` | **normal** border|
|`anonymous` | **dotted** border|

### Calls

|Represents | Style|
|-----------: | :-------------|
|`internal` | **black** color|
|`external` | **brown** color|
|`static` | **solid** line|
|`dynamic` | **dashed** line|
|`regular` | **simple** arrow|
|`concurrent` | arrow with **circle**|
|`deferred` | arrow with **diamond**|

## Examples

Here is an example for the project [syncthing](https://github.com/syncthing/syncthing).

[![syncthing example](images/syncthing.png)](https://raw.githubusercontent.com/ofabry/go-callvis/master/images/syncthing.png)
[![syncthing example](images/syncthing.png)](https://raw.githubusercontent.com/ondrajz/go-callvis/master/images/syncthing.png)

> Check out [more examples](examples) and used command options.
Expand All @@ -166,15 +183,15 @@ Join [#go-callvis](https://gophers.slack.com/archives/go-callvis) channel at [go
### How to help

Did you find any bugs or have some suggestions?
- Feel free to open [new issue](https://github.com/ofabry/go-callvis/issues/new) or start discussion in the slack channel.
- Feel free to open [new issue](https://github.com/ondrajz/go-callvis/issues/new) or start discussion in the slack channel.

Do you want to contribute to the project?
- Fork the repository and open a pull request. [Here](https://github.com/ofabry/go-callvis/projects/1) you can find TODO features.
- Fork the repository and open a pull request. [Here](https://github.com/ondrajz/go-callvis/projects/1) you can find TODO features.

---

#### Roadmap

##### The *interactive tool* described below has been published as a *separate project* called [goexplorer](https://github.com/ofabry/goexplorer)!
##### The *interactive tool* described below has been published as a *separate project* called [goexplorer](https://github.com/ondrajz/goexplorer)!

> Ideal goal of this project is to make web app that would locally store the call graph data and then provide quick access of the call graphs for any package of your dependency tree. At first it would show an interactive map of overall dependencies between packages and then by selecting particular package it would show the call graph and provide various options to alter the output dynamically.
Loading

0 comments on commit 43c020e

Please sign in to comment.