code-intelligence.com/cifuzz@v0.40.0/Makefile (about)

     1  current_os :=
     2  label_os :=
     3  bin_ext :=
     4  
     5  # Force PowerShell on Windows. sh.exe on Windows GH Actions runners is using a different PATH with incompatible tools.
     6  ifeq ($(OS),Windows_NT)
     7  	SHELL := pwsh.exe
     8  	.SHELLFLAGS := -NoProfile -Command
     9  endif
    10  
    11  ifeq ($(OS),Windows_NT)
    12  	current_os = windows
    13  	label_os = windows
    14  	bin_ext = .exe
    15  	RM = rm -r -force
    16  else
    17  	UNAME_S := $(shell uname -s)
    18  	ifeq ($(UNAME_S),Linux)
    19  		current_os = linux
    20  		label_os = linux
    21  	endif
    22  	ifeq ($(UNAME_S),Darwin)
    23  		current_os = darwin
    24  		label_os = macOS
    25  		UNAME_P := $(shell uname -p)
    26  	endif
    27  	RM = rm -r -f
    28  endif
    29  
    30  bin_dir = build/bin
    31  binary_base_path = $(bin_dir)/cifuzz
    32  installer_base_path = $(bin_dir)/cifuzz_installer
    33  
    34  project := "code-intelligence.com/cifuzz"
    35  
    36  # default version can be overriden by
    37  # make version=1.0.0-dev [target]
    38  version = dev
    39  
    40  # Set IMAGE_ID to ghcr.io/codeintelligencetesting/cifuzz if it's not set
    41  image_id ?= ghcr.io/codeintelligencetesting/cifuzz
    42  
    43  # Set IMAGE_TAG to IMAGE_ID:version
    44  image_tag ?= $(image_id):$(version)
    45  
    46  # Export environment variables from the .env file if it exists
    47  ifneq ("$(wildcard .env)","")
    48  	include .env
    49  	export
    50  endif
    51  
    52  
    53  default:
    54  	@echo cifuzz
    55  
    56  .PHONY: clean
    57  clean: clean/examples/cmake clean/third-party/minijail
    58  	$(RM) build/
    59  
    60  .PHONY: clean/examples/cmake
    61  clean/examples/cmake:
    62  	-$(RM) examples/cmake/.cifuzz-*
    63  	-$(RM) examples/cmake/build/
    64  	-$(RM) examples/cmake/crash-*
    65  	-$(RM) examples/cmake/*_inputs
    66  
    67  .PHONY: clean/third-party/minijail
    68  clean/third-party/minijail:
    69  	PWD=${PWD}/third-party/minijail make -C third-party/minijail clean
    70  
    71  .PHONY: deps
    72  deps:
    73  	go mod download
    74  
    75  .PHONY: deps/integration-tests
    76  deps/integration-tests:
    77  	./tools/test-bucket-generator/check-buckets.sh
    78  	go install github.com/bazelbuild/buildtools/buildozer@latest
    79  
    80  .PHONY: deps/dev
    81  deps/dev: deps
    82  	go install github.com/incu6us/goimports-reviser/v2@latest
    83  	go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.2
    84  	yarn install --silent
    85  
    86  
    87  .PHONY: deps/test
    88  # TODO: use a version of gotestfmt ^2.4.2 when it's released
    89  deps/test:
    90  	go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@b870aff77ad39547466e58f79725ca4d1bd92881
    91  
    92  .PHONY: install
    93  install:
    94  	go run tools/builder/builder.go --version $(version)
    95  	go run -tags installer cmd/installer/installer.go --verbose
    96  	$(RM) cmd/installer/build
    97  
    98  .PHONY: install/coverage
    99  install/coverage:
   100  	go run tools/builder/builder.go --version $(version) --coverage
   101  	go run -tags installer cmd/installer/installer.go --verbose
   102  	$(RM) cmd/installer/build
   103  
   104  .PHONY: installer
   105  installer:
   106  	go run tools/builder/builder.go --version $(version)
   107  	go build -tags installer -o $(installer_base_path)_$(label_os)_amd64$(bin_ext) cmd/installer/installer.go
   108  	$(RM) cmd/installer/build
   109  
   110  .PHONY: installer/darwin-arm64
   111  installer/darwin-arm64:
   112  	go run tools/builder/builder.go --version $(version) --goos darwin --goarch arm64
   113  	GOOS=darwin GOARCH=arm64 go build -tags installer -o $(installer_base_path)_macOS_arm64 cmd/installer/installer.go
   114  	$(RM) cmd/installer/build
   115  
   116  .PHONY: build
   117  build: build/$(current_os)
   118  
   119  .PHONY: build/all
   120  build/all: build/linux build/windows build/darwin ;
   121  
   122  .PHONY: build/linux
   123  build/linux: deps
   124  	env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(binary_base_path)_linux cmd/cifuzz/main.go
   125  
   126  .PHONY: build/windows
   127  build/windows: deps
   128  	env GOOS=windows GOARCH=amd64 go build -o $(binary_base_path)_windows.exe cmd/cifuzz/main.go
   129  
   130  .PHONY: build/darwin
   131  build/darwin: deps
   132  ifeq ($(UNAME_P), arm)
   133  	env GOOS=darwin GOARCH=arm64 go build -o $(binary_base_path)_macOS cmd/cifuzz/main.go
   134  else
   135  	env GOOS=darwin GOARCH=amd64 go build -o $(binary_base_path)_macOS cmd/cifuzz/main.go
   136  endif
   137  
   138  .PHONY: lint
   139  lint: deps/dev
   140  	golangci-lint run
   141  
   142  .PHONY: fmt
   143  fmt: deps/dev
   144  	find . -type f -name "*.go" -not -path "./.git/*" -print0 | xargs -0 -n1 goimports-reviser -project-name $(project) -file-path
   145  	npx prettier --loglevel=warn --write .
   146  
   147  .PHONY: fmt/check
   148  fmt/check: deps/dev
   149  	@DIFF=$$(find . -type f -name "*.go" -not -path "./.git/*" -print0 | xargs -0 -n1 goimports-reviser -project-name $(project) -list-diff -file-path); \
   150  	# Exit if the find command failed \
   151  	if [ "$$?" -ne 0 ]; then \
   152  	  exit "$$1"; \
   153  	fi; \
   154  	# Exit after printing unformatted files (if any) \
   155  	if [ -n "$${DIFF}" ]; then \
   156  		echo -e >&2 "Unformatted files:\n$${DIFF}"; \
   157  		exit 1; \
   158  	fi;
   159  	npx prettier --loglevel=warn --check .
   160  
   161  .PHONY: tidy
   162  tidy:
   163  	go mod tidy
   164  
   165  .PHONY: tidy/check
   166  tidy/check:
   167  	# Replace with `go mod tidy -check` once that's available, see
   168  	# https://github.com/golang/go/issues/27005
   169  	if [ -n "$$(git status --porcelain go.mod go.sum)" ]; then       \
   170  		echo >&2 "Error: The working tree has uncommitted changes."; \
   171  		exit 1;                                                      \
   172  	fi
   173  	go mod tidy
   174  	if [ -n "$$(git status --porcelain go.mod go.sum)" ]; then \
   175  		echo >&2 "Error: Files were modified by go mod tidy";  \
   176  		git checkout go.mod go.sum;                            \
   177  		exit 1;                                                \
   178  	fi
   179  
   180  .PHONY: test
   181  test: deps build/$(current_os)
   182  	go test -v ./...
   183  
   184  .PHONY: test/unit
   185  test/unit: deps deps/test
   186  	go test -json -v ./... -short 2>&1 | tee gotest.log | gotestfmt -hide all
   187  
   188  INTEGRATION_TEST_PLATFORM := $(word 3, $(subst /, ,$(MAKECMDGOALS)))
   189  INTEGRATION_TEST_BUCKET := $(word 4, $(subst /, ,$(MAKECMDGOALS)))
   190  .PHONY: test/integration/%
   191  test/integration/%: deps deps/test deps/integration-tests
   192  	@echo $(INTEGRATION_TEST_PLATFORM)
   193  	go test -json -v -timeout=20m -run 'TestIntegration.*' $(shell cat ./tools/test-bucket-generator/$(INTEGRATION_TEST_PLATFORM)/bucket-$(INTEGRATION_TEST_BUCKET).txt) 2>&1 | tee gotest.log | gotestfmt -hide all
   194  
   195  .PHONY: test/integration
   196  test/integration: deps deps/test deps/integration-tests
   197  	go test -json -v -timeout=20m ./... -run 'TestIntegration.*' 2>&1 | tee gotest.log | gotestfmt -hide all
   198  
   199  .PHONY: test/e2e
   200  test/e2e: deps deps/test install
   201  test/e2e: export E2E_TESTS_MATRIX = 1
   202  test/e2e:
   203  	go test -json -v ./e2e-tests/... | tee gotest.log | gotestfmt
   204  
   205  # For Release E2E testing, we want to use the installed cifuzz, instead of installing from source.
   206  .PHONY: test/e2e-use-installed-cifuzz
   207  test/e2e-use-installed-cifuzz: deps/test
   208  test/e2e-use-installed-cifuzz: export E2E_TESTS_MATRIX = 1
   209  test/e2e-use-installed-cifuzz:
   210  	go test -json -v ./e2e-tests/... | tee gotest.log | gotestfmt
   211  
   212  .PHONY: test/race
   213  test/race: deps build/$(current_os)
   214  	go test -v ./... -race
   215  
   216  .PHONY: coverage
   217  coverage: export E2E_TESTS_MATRIX = V
   218  coverage: deps install/coverage
   219  coverage:
   220  	-$(RM) coverage
   221  	mkdir -p coverage/e2e coverage/unit coverage/integration
   222  	-go test ./... -cover -args -test.gocoverdir="${PWD}/coverage/unit"
   223  	go tool covdata func -i=./coverage/unit,./coverage/e2e,./coverage/integration
   224  
   225  .PHONY: coverage/merge
   226  coverage/merge:
   227  	go tool covdata func -i=./coverage/unit,./coverage/e2e,./coverage/integration
   228  	go tool covdata textfmt -i=./coverage/unit,./coverage/e2e,./coverage/integration -o coverage/profile
   229  	go tool cover -html coverage/profile -o coverage/report.html
   230  
   231  .PHONY: coverage/e2e
   232  coverage/e2e: export E2E_TESTS_MATRIX = V
   233  coverage/e2e: deps install/coverage
   234  	-$(RM) coverage/e2e
   235  	mkdir -p coverage/e2e
   236  	-go test ./e2e-tests/...
   237  	go tool covdata func -i=./coverage/e2e
   238  
   239  .PHONY: coverage/integration
   240  coverage/integration: deps
   241  	-$(RM) coverage/integration
   242  	mkdir -p coverage/integration
   243  	-go test ./... -run 'TestIntegration.*'
   244  	go tool covdata func -i=./coverage/integration
   245  
   246  .PHONY: coverage/unit
   247  coverage/unit: deps
   248  	-$(RM) coverage/unit
   249  	mkdir -p coverage/unit
   250  	-go test ./... -short -cover -args -test.gocoverdir="${PWD}/coverage/unit"
   251  	go tool covdata func -i=./coverage/unit
   252  
   253  .PHONY: site/setup
   254  site/setup:
   255  	-$(RM) site
   256  	git clone git@github.com:CodeIntelligenceTesting/cifuzz.wiki.git site
   257  
   258  .PHONY: site/generate
   259  site/generate: deps
   260  	$(RM) ./site/*.md
   261  	go run ./cmd/gen-docs/main.go --dir ./site/
   262  	cp -R ./docs/*.md ./site
   263  
   264  .PHONY: site/update
   265  site/update:
   266  	git -C site add -A
   267  	git -C site commit -m "update docs" || true
   268  	git -C site push
   269  
   270  build-container-image: build/linux
   271  	DOCKER_BUILDKIT=1 docker build --platform linux/amd64 -f docker/cifuzz-base/Dockerfile -t $(image_tag) .
   272  
   273  push-container-image: build-container-image
   274  	# Exit if GITHUB_TOKEN or GITHUB_USER are not set
   275  	if [ -z "${GITHUB_TOKEN}" ] || [ -z "${GITHUB_USER}" ]; then \
   276  		echo "GITHUB_TOKEN or GITHUB_USER not set"; \
   277  		exit 1; \
   278  	fi
   279  	echo "${GITHUB_TOKEN}" | docker login ghcr.io -u "${GITHUB_USER}" --password-stdin
   280  	docker push "$(image_tag)"
   281  
   282  .PHONY: installer-via-docker
   283  installer-via-docker:
   284  	@echo "Building a cifuzz Linux installer"
   285  	mkdir -p build/bin
   286  	DOCKER_BUILDKIT=1 docker build --platform linux/amd64 -f docker/cifuzz-builder/Dockerfile . --target bin --output build/bin