github.com/projectcalico/api@v0.0.0-20231218190037-9183ab93f33e/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/projectcalico/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  # Override DOCKER_RUN from lib.Makefile. We need to trick this particular directory to think
    30  # that its package is github.com/projectcalico/api for easier mirroring.
    31  DOCKER_RUN := mkdir -p ../.go-pkg-cache bin $(GOMOD_CACHE) && \
    32  	docker run --rm \
    33  		--net=host \
    34  		--init \
    35  		$(EXTRA_DOCKER_ARGS) \
    36  		-e LOCAL_USER_ID=$(LOCAL_USER_ID) \
    37  		-e GOCACHE=/go-cache \
    38  		$(GOARCH_FLAGS) \
    39  		-e GOPATH=/go \
    40  		-e OS=$(BUILDOS) \
    41  		-e GOOS=$(BUILDOS) \
    42  		-e GOFLAGS=$(GOFLAGS) \
    43  		-v $(CURDIR):/go/src/$(PACKAGE_NAME):rw \
    44  		-v $(CURDIR)/../.go-pkg-cache:/go-cache:rw \
    45  		-w /go/src/$(PACKAGE_NAME)
    46  
    47  build: gen-files examples
    48  
    49  ###############################################################################
    50  # This section contains the code generation stuff
    51  ###############################################################################
    52  # Regenerate all files if the gen exes changed or any "types.go" files changed
    53  .PHONY: gen-files
    54  gen-files .generate_files: lint-cache-dir clean-generated
    55  	# Generate defaults
    56  	$(DOCKER_RUN) $(CALICO_BUILD) \
    57  	   sh -c '$(GIT_CONFIG_SSH) defaulter-gen \
    58  		--v 1 --logtostderr \
    59  		--go-header-file "/go/src/$(PACKAGE_NAME)/hack/boilerplate/boilerplate.go.txt" \
    60  		--input-dirs "$(PACKAGE_NAME)/pkg/apis/projectcalico/v3" \
    61  		--extra-peer-dirs "$(PACKAGE_NAME)/pkg/apis/projectcalico/v3" \
    62  		--output-file-base "zz_generated.defaults"'
    63  	# Generate deep copies
    64  	$(DOCKER_RUN) $(CALICO_BUILD) \
    65  	   sh -c '$(GIT_CONFIG_SSH) deepcopy-gen \
    66  		--v 1 --logtostderr \
    67  		--go-header-file "/go/src/$(PACKAGE_NAME)/hack/boilerplate/boilerplate.go.txt" \
    68  		--input-dirs "$(PACKAGE_NAME)/pkg/apis/projectcalico/v3" \
    69  		--bounding-dirs $(PACKAGE_NAME) \
    70  		--output-file-base zz_generated.deepcopy'
    71  
    72  	# generate all pkg/client contents
    73  	$(DOCKER_RUN) $(CALICO_BUILD) \
    74  	   sh -c '$(GIT_CONFIG_SSH) $(BUILD_DIR)/update-client-gen.sh'
    75  
    76  	# generate openapi
    77  	$(DOCKER_RUN) $(CALICO_BUILD) \
    78  	   sh -c '$(GIT_CONFIG_SSH) openapi-gen \
    79  		--v 1 --logtostderr \
    80  		--go-header-file "/go/src/$(PACKAGE_NAME)/hack/boilerplate/boilerplate.go.txt" \
    81  		--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" \
    82  		--output-package "$(PACKAGE_NAME)/pkg/openapi"'
    83  
    84  	touch .generate_files
    85  	$(MAKE) fix
    86  
    87  .PHONY: lint-cache-dir
    88  lint-cache-dir:
    89  	mkdir -p $(CURDIR)/.lint-cache
    90  
    91  .PHONY: check-copyright
    92  check-copyright:
    93  	@hack/check-copyright.sh
    94  
    95  .PHONY: clean
    96  clean: clean-bin
    97  	rm -rf .lint-cache
    98  
    99  clean-generated:
   100  	rm -f .generate_files
   101  	find $(TOP_SRC_DIRS) -name zz_generated* -exec rm {} \;
   102  	# rollback changes to the generated clientset directories
   103  	# find $(TOP_SRC_DIRS) -type d -name *_generated -exec rm -rf {} \;
   104  	rm -rf pkg/client/clientset_generated pkg/client/informers_generated pkg/client/listers_generated pkg/openapi pkg/lib/numorstring/openapi_generated.go
   105  
   106  clean-bin:
   107  	rm -rf $(BINDIR) \
   108  	    .generate_execs \
   109  
   110  .PHONY: examples
   111  examples: bin/list-gnp
   112  
   113  bin/list-gnp: examples/list-gnp/main.go
   114  	@echo Building list-gnp example binary...
   115  	$(call build_binary, examples/list-gnp/main.go, $@)
   116  
   117  WHAT?=.
   118  GINKGO_FOCUS?=.*
   119  
   120  .PHONY:ut
   121  ut:
   122  	$(DOCKER_RUN) --privileged $(CALICO_BUILD) \
   123  		sh -c 'cd /go/src/$(PACKAGE_NAME) && ginkgo -r -focus="$(GINKGO_FOCUS)" $(WHAT)'
   124  
   125  ## Check if generated files are out of date
   126  .PHONY: check-generated-files
   127  check-generated-files: .generate_files
   128  	if (git describe --tags --dirty | grep -c dirty >/dev/null); then \
   129  	  echo "Generated files are out of date."; \
   130  	  false; \
   131  	else \
   132  	  echo "Generated files are up to date."; \
   133  	fi
   134  
   135  ###############################################################################
   136  # CI
   137  ###############################################################################
   138  .PHONY: ci
   139  ## Run what CI runs
   140  ci: clean check-generated-files build static-checks ut