github.com/buildpacks/pack@v0.33.3-0.20240516162812-884dd1837311/Makefile (about)

     1  ifeq ($(OS),Windows_NT)
     2  SHELL:=cmd.exe
     3  
     4  # Need BLANK due to makefile parsing of `\`
     5  # (see: https://stackoverflow.com/questions/54733231/how-to-escape-a-backslash-in-the-end-to-mean-literal-backslash-in-makefile/54733416#54733416)
     6  BLANK:=
     7  
     8  # Define variable named `/` to represent OS path separator (usable as `$/` in this file)
     9  /:=\$(BLANK)
    10  CAT=type
    11  RMRF=rmdir /q /s
    12  SRC=$(shell dir /q /s /b *.go | findstr /v $/out$/)
    13  GOIMPORTS_DIFF_OPTION="-l" # Windows can't do diff-mode because it's missing the "diff" binary
    14  PACK_BIN?=pack.exe
    15  else
    16  /:=/
    17  CAT=cat
    18  RMRF=rm -rf
    19  SRC=$(shell find . -type f -name '*.go' -not -path "*/out/*")
    20  GOIMPORTS_DIFF_OPTION:="-d"
    21  PACK_BIN?=pack
    22  endif
    23  
    24  ACCEPTANCE_TIMEOUT?=$(TEST_TIMEOUT)
    25  ARCHIVE_NAME=pack-$(PACK_VERSION)
    26  GOCMD?=go
    27  GOFLAGS?=
    28  GOTESTFLAGS?=-v -count=1 -parallel=1
    29  PACKAGE_BASE=github.com/buildpacks/pack
    30  PACK_GITSHA1=$(shell git rev-parse --short=7 HEAD)
    31  PACK_VERSION?=0.0.0
    32  TEST_TIMEOUT?=1200s
    33  UNIT_TIMEOUT?=$(TEST_TIMEOUT)
    34  NO_DOCKER?=
    35  
    36  # Clean build flags
    37  clean_build := $(strip ${PACK_BUILD})
    38  clean_sha := $(strip ${PACK_GITSHA1})
    39  
    40  # Append build number and git sha to version, if not-empty
    41  ifneq ($(and $(clean_build),$(clean_sha)),)
    42  PACK_VERSION:=${PACK_VERSION}+git-${clean_sha}.build-${clean_build}
    43  else ifneq ($(clean_build),)
    44  PACK_VERSION:=${PACK_VERSION}+build-${clean_build}
    45  else ifneq ($(clean_sha),)
    46  PACK_VERSION:=${PACK_VERSION}+git-${clean_sha}
    47  endif
    48  
    49  export GOFLAGS:=$(GOFLAGS)
    50  export CGO_ENABLED=0
    51  
    52  BINDIR:=/usr/bin/
    53  
    54  .DEFAULT_GOAL := build
    55  
    56  # this target must be listed first in order for it to be a default target,
    57  # so that ubuntu_ppa's may be constructed using default build tools.
    58  ## build: Build the program
    59  build: out
    60  	@echo "=====> Building..."
    61  	$(GOCMD) build -ldflags "-s -w -X 'github.com/buildpacks/pack.Version=${PACK_VERSION}' -extldflags '${LDFLAGS}'" -trimpath -o ./out/$(PACK_BIN) -a ./cmd/pack
    62  
    63  ## all: Run clean, verify, test, and build operations
    64  all: clean verify test build
    65  
    66  ## clean: Clean the workspace
    67  clean:
    68  	@echo "=====> Cleaning workspace..."
    69  	@$(RMRF) .$/out benchmarks.test || (exit 0)
    70  
    71  ## format: Format the code
    72  format: install-goimports
    73  	@echo "=====> Formatting code..."
    74  	@goimports -l -w -local ${PACKAGE_BASE} ${SRC}
    75  	@go run tools/pedantic_imports/main.go ${PACKAGE_BASE} ${SRC}
    76  
    77  ## generate: Generate mocks
    78  generate: install-mockgen
    79  	@echo "=====> Generating mocks..."
    80  	$(GOCMD) generate ./...
    81  
    82  ## lint: Check the code
    83  lint: install-golangci-lint
    84  	@echo "=====> Linting code..."
    85  	@golangci-lint run -c golangci.yaml
    86  
    87  ## test: Run unit and acceptance tests
    88  test: unit acceptance
    89  
    90  ## unit: Append coverage arguments
    91  ifeq ($(TEST_COVERAGE), 1)
    92  unit: GOTESTFLAGS:=$(GOTESTFLAGS) -coverprofile=./out/tests/coverage-unit.txt -covermode=atomic
    93  endif
    94  ifeq ($(NO_DOCKER),)
    95  unit: GOTESTFLAGS:=$(GOTESTFLAGS) --tags=example
    96  endif
    97  unit: out
    98  	@echo "> Running unit/integration tests..."
    99  	$(GOCMD) test $(GOTESTFLAGS) -timeout=$(UNIT_TIMEOUT) ./...
   100  
   101  ## acceptance: Run acceptance tests
   102  acceptance: out
   103  	@echo "=====> Running acceptance tests..."
   104  	$(GOCMD) test $(GOTESTFLAGS) -timeout=$(ACCEPTANCE_TIMEOUT) -tags=acceptance ./acceptance
   105  
   106  ## acceptance-all: Run all acceptance tests
   107  acceptance-all: export ACCEPTANCE_SUITE_CONFIG:=$(shell $(CAT) .$/acceptance$/testconfig$/all.json)
   108  acceptance-all:
   109  	@echo "=====> Running acceptance tests..."
   110  	$(GOCMD) test $(GOTESTFLAGS) -timeout=$(ACCEPTANCE_TIMEOUT) -tags=acceptance ./acceptance
   111  
   112  ## prepare-for-pr: Run clean, verify, and test operations and check for uncommitted changes
   113  prepare-for-pr: tidy verify test
   114  	@git diff-index --quiet HEAD -- ||\
   115  	(echo "-----------------" &&\
   116  	echo "NOTICE: There are some files that have not been committed." &&\
   117  	echo "-----------------\n" &&\
   118  	git status &&\
   119  	echo "\n-----------------" &&\
   120  	echo "NOTICE: There are some files that have not been committed." &&\
   121  	echo "-----------------\n"  &&\
   122  	exit 0)
   123  
   124  ## verify: Run format and lint checks
   125  verify: verify-format lint
   126  
   127  ## verify-format: Verify the format
   128  verify-format: install-goimports
   129  	@echo "=====> Verifying format..."
   130  	$(if $(shell goimports -l -local ${PACKAGE_BASE} ${SRC}), @echo ERROR: Format verification failed! && goimports ${GOIMPORTS_DIFF_OPTION} -local ${PACKAGE_BASE} ${SRC} && exit 1)
   131  
   132  ## benchmark: Run benchmark tests
   133  benchmark: out
   134  	@echo "=====> Running benchmarks"
   135  	$(GOCMD) test -run=^$  -bench=. -benchtime=1s -benchmem -memprofile=./out/bench_mem.out -cpuprofile=./out/bench_cpu.out -tags=benchmarks ./benchmarks/ -v
   136  # NOTE: You can analyze the results, using go tool pprof. For instance, you can start a server to see a graph of the cpu usage by running
   137  # go tool pprof -http=":8082" out/bench_cpu.out. Alternatively, you can run go tool pprof, and in the ensuing cli, run
   138  # commands like top10 or web to dig down into the cpu and memory usage
   139  # For more, see https://blog.golang.org/pprof
   140  
   141  ## package: Package the program
   142  package: out
   143  	tar czf .$/out$/$(ARCHIVE_NAME).tgz -C .$/out$/ $(PACK_BIN)
   144  
   145  ## install: Install the program to the system
   146  install:
   147  	mkdir -p ${DESTDIR}${BINDIR}
   148  	cp ./out/$(PACK_BIN) ${DESTDIR}${BINDIR}/
   149  
   150  ## install-mockgen: Used only by apt-get install when installing ubuntu ppa
   151  install-mockgen:
   152  	@echo "=====> Installing mockgen..."
   153  	cd tools && $(GOCMD) install github.com/golang/mock/mockgen
   154  
   155  ## install-goimports: Install goimports dependency
   156  install-goimports:
   157  	@echo "=====> Installing goimports..."
   158  	cd tools && $(GOCMD) install golang.org/x/tools/cmd/goimports
   159  
   160  ## install-golangci-lint: Install golangci-lint dependency
   161  install-golangci-lint:
   162  	@echo "=====> Installing golangci-lint..."
   163  	cd tools && $(GOCMD) install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.1
   164  
   165  ## mod-tidy: Tidy Go modules
   166  mod-tidy:
   167  	$(GOCMD) mod tidy  -compat=1.22
   168  	cd tools && $(GOCMD) mod tidy -compat=1.22
   169  
   170  ## tidy: Tidy modules and format the code
   171  tidy: mod-tidy format
   172  
   173  # NOTE: Windows doesn't support `-p`
   174  ## out: Make a directory for output
   175  out:
   176  	@mkdir out || (exit 0)
   177  	mkdir out$/tests || (exit 0)
   178  
   179  ## help: Display help information
   180  help: Makefile
   181  	@echo ""
   182  	@echo "Usage:"
   183  	@echo ""
   184  	@echo "  make [target]"
   185  	@echo ""
   186  	@echo "Targets:"
   187  	@echo ""
   188  	@awk -F ':|##' '/^[^\.%\t][^\t]*:.*##/{printf "  \033[36m%-20s\033[0m %s\n", $$1, $$NF}' $(MAKEFILE_LIST) | sort
   189  	@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' |  sed -e 's/^/ /'
   190  
   191  .PHONY: clean build format imports lint test unit acceptance prepare-for-pr verify verify-format benchmark