github.com/tigera/api@v0.0.0-20240320170621-278e89a8c5fb/Makefile (about)

     1  # If ../metadata.mk exists, we're running this logic from within the calico repository.
     2  # If it does not, then we're in the api repo and we should use the local metadata.mk.
     3  ifneq ("$(wildcard ../metadata.mk)", "")
     4  include ../metadata.mk
     5  else
     6  include ./metadata.mk
     7  endif
     8  
     9  PACKAGE_NAME    ?= github.com/tigera/api
    10  LOCAL_CHECKS     = lint-cache-dir goimports check-copyright
    11  
    12  BINDIR ?= bin
    13  BUILD_DIR ?= build
    14  TOP_SRC_DIRS = pkg
    15  
    16  ##############################################################################
    17  # Download and include ../lib.Makefile before anything else
    18  #   Additions to EXTRA_DOCKER_ARGS need to happen before the include since
    19  #   that variable is evaluated when we declare DOCKER_RUN and siblings.
    20  ##############################################################################
    21  # If ../lib.Makefile exists, we're running this logic from within the calico repository.
    22  # If it does not, then we're in the api repo and should use the local lib.Makefile.
    23  ifneq ("$(wildcard ../lib.Makefile)", "")
    24  include ../lib.Makefile
    25  else
    26  include ./lib.Makefile
    27  endif
    28  
    29  CGO_ENABLED=0
    30  
    31  # Override DOCKER_RUN from lib.Makefile. We need to trick this particular directory to think
    32  # that its package is github.com/tigera/api for easier mirroring.
    33  DOCKER_RUN := mkdir -p ../.go-pkg-cache bin $(GOMOD_CACHE) && \
    34  	docker run --rm \
    35  		--net=host \
    36  		--init \
    37  		$(EXTRA_DOCKER_ARGS) \
    38  		-e LOCAL_USER_ID=$(LOCAL_USER_ID) \
    39  		-e GOCACHE=/go-cache \
    40  		$(GOARCH_FLAGS) \
    41  		-e GOPATH=/go \
    42  		-e OS=$(BUILDOS) \
    43  		-e GOOS=$(BUILDOS) \
    44  		-e GOFLAGS=$(GOFLAGS) \
    45  		-v $(CURDIR):/go/src/$(PACKAGE_NAME):rw \
    46  		-v $(CURDIR)/../.go-pkg-cache:/go-cache:rw \
    47  		-w /go/src/$(PACKAGE_NAME)
    48  
    49  build: gen-files examples
    50  
    51  ###############################################################################
    52  # This section contains the code generation stuff
    53  ###############################################################################
    54  # Regenerate all files if the gen exes changed or any "types.go" files changed
    55  .PHONY: gen-files
    56  gen-files .generate_files: lint-cache-dir clean-generated
    57  	# Generate defaults
    58  	$(DOCKER_RUN) $(CALICO_BUILD) \
    59  	   sh -c '$(GIT_CONFIG_SSH) defaulter-gen \
    60  		--v 1 --logtostderr \
    61  		--go-header-file "/go/src/$(PACKAGE_NAME)/hack/boilerplate/boilerplate.go.txt" \
    62  		--input-dirs "$(PACKAGE_NAME)/pkg/apis/projectcalico/v3" \
    63  		--extra-peer-dirs "$(PACKAGE_NAME)/pkg/apis/projectcalico/v3" \
    64  		--output-file-base "zz_generated.defaults"'
    65  	# Generate deep copies
    66  	$(DOCKER_RUN) $(CALICO_BUILD) \
    67  	   sh -c '$(GIT_CONFIG_SSH) deepcopy-gen \
    68  		--v 1 --logtostderr \
    69  		--go-header-file "/go/src/$(PACKAGE_NAME)/hack/boilerplate/boilerplate.go.txt" \
    70  		--input-dirs "$(PACKAGE_NAME)/pkg/apis/projectcalico/v3" \
    71  		--bounding-dirs $(PACKAGE_NAME) \
    72  		--output-file-base zz_generated.deepcopy'
    73  
    74  	# generate all pkg/client contents
    75  	$(DOCKER_RUN) $(CALICO_BUILD) \
    76  	   sh -c '$(GIT_CONFIG_SSH) $(BUILD_DIR)/update-client-gen.sh'
    77  
    78  	# generate openapi
    79  	$(DOCKER_RUN) $(CALICO_BUILD) \
    80  	   sh -c '$(GIT_CONFIG_SSH) openapi-gen \
    81  		--v 1 --logtostderr \
    82  		--go-header-file "/go/src/$(PACKAGE_NAME)/hack/boilerplate/boilerplate.go.txt" \
    83  		--input-dirs "$(PACKAGE_NAME)/pkg/apis/projectcalico/v3,k8s.io/api/core/v1,k8s.io/api/networking/v1,k8s.io/apimachinery/pkg/apis/meta/v1,k8s.io/apimachinery/pkg/version,k8s.io/apimachinery/pkg/runtime,k8s.io/apimachinery/pkg/util/intstr,$(PACKAGE_NAME)/pkg/lib/numorstring" \
    84  		--output-package "$(PACKAGE_NAME)/pkg/openapi"'
    85  
    86  	touch .generate_files
    87  	$(MAKE) fix
    88  
    89  .PHONY: lint-cache-dir
    90  lint-cache-dir:
    91  	mkdir -p $(CURDIR)/.lint-cache
    92  
    93  .PHONY: check-copyright
    94  check-copyright:
    95  	@hack/check-copyright.sh
    96  
    97  .PHONY: clean
    98  clean: clean-bin
    99  	rm -rf .lint-cache
   100  
   101  clean-generated:
   102  	rm -f .generate_files
   103  	find $(TOP_SRC_DIRS) -name zz_generated* -exec rm {} \;
   104  	# rollback changes to the generated clientset directories
   105  	# find $(TOP_SRC_DIRS) -type d -name *_generated -exec rm -rf {} \;
   106  	rm -rf pkg/client/clientset_generated pkg/client/informers_generated pkg/client/listers_generated pkg/openapi pkg/lib/numorstring/openapi_generated.go
   107  
   108  clean-bin:
   109  	rm -rf $(BINDIR) \
   110  	    .generate_execs \
   111  
   112  .PHONY: examples
   113  examples: bin/list-gnp
   114  
   115  bin/list-gnp: examples/list-gnp/main.go
   116  	@echo Building list-gnp example binary...
   117  	$(call build_binary, examples/list-gnp/main.go, $@)
   118  
   119  WHAT?=.
   120  GINKGO_FOCUS?=.*
   121  
   122  .PHONY:ut
   123  ut:
   124  	$(DOCKER_RUN) --privileged $(CALICO_BUILD) \
   125  		sh -c 'cd /go/src/$(PACKAGE_NAME) && ginkgo -r -focus="$(GINKGO_FOCUS)" $(WHAT)'
   126  
   127  ## Check if generated files are out of date
   128  .PHONY: check-generated-files
   129  check-generated-files: .generate_files
   130  	if (git describe --tags --dirty | grep -c dirty >/dev/null); then \
   131  	  echo "Generated files are out of date."; \
   132  	  false; \
   133  	else \
   134  	  echo "Generated files are up to date."; \
   135  	fi
   136  
   137  ###############################################################################
   138  # CI
   139  ###############################################################################
   140  .PHONY: ci
   141  ## Run what CI runs
   142  ci: clean check-generated-files static-checks build ut