github.com/replit/upm@v0.0.0-20240423230255-9ce4fc3ea24c/Makefile (about)

     1  SOURCES := $(shell find cmd internal -type d -o -name "*.go")
     2  RESOURCES := $(shell find resources)
     3  GENERATED := internal/backends/python/pypi_map.sqlite
     4  LD_FLAGS := "-X 'github.com/replit/upm/internal/cli.version=$${VERSION:-development version}'"
     5  
     6  export GO111MODULE=on
     7  
     8  .PHONY: upm
     9  upm: cmd/upm/upm ## Build the UPM binary
    10  
    11  install: cmd/upm/upm
    12  	go install ./cmd/upm
    13  
    14  internal/backends/python/pypi_map.sqlite: internal/backends/python/download_stats.json
    15  	cd internal/backends/python; go run ./gen_pypi_map gen
    16  
    17  generated: $(GENERATED)
    18  
    19  cmd/upm/upm: $(SOURCES) $(RESOURCES) generated
    20  	cd cmd/upm && go build -ldflags $(LD_FLAGS)
    21  
    22  build-release: $(SOURCES) $(RESOURCES) generated
    23  	goreleaser build
    24  
    25  clean-gen:
    26  	rm -f $(GENERATED)
    27  
    28  .PHONY: dev
    29  dev: ## Run a shell with UPM source code and all package managers inside Docker
    30  	docker build . -f Dockerfile.dev -t upm:dev
    31  	docker run -it --rm -v "$$PWD:/upm" upm:dev
    32  
    33  .PHONY: light
    34  light: ## Build a Docker image with just the UPM binary
    35  	docker build . -f Dockerfile.light -t upm:light --build-arg VERSION
    36  
    37  .PHONY: full
    38  full: ## Build a Docker image with the UPM binary and all package managers
    39  	docker build . -f Dockerfile.full -t upm:full --build-arg VERSION
    40  
    41  .PHONY: doc
    42  doc: ## Open Godoc in web browser
    43  	docker build . -f Dockerfile.godoc -t upm:godoc
    44  	@echo
    45  	@echo "starting godoc; your browser will be opened once it is ready" >&2
    46  	@scripts/browse-godoc.bash &
    47  	@docker run -it --rm -p 6060:6060 \
    48  		-v "$$PWD:/tmp/go/src/github.com/replit/upm" \
    49  		upm:godoc
    50  
    51  .PHONY: deploy
    52  deploy: light full ## Publish UPM snapshot Docker images to Docker Hub
    53  	docker tag upm:light replco/upm:light
    54  	docker tag upm:full replco/upm:full
    55  	docker tag upm:full replco/upm:latest
    56  	docker push replco/upm:light
    57  	docker push replco/upm:full
    58  	docker push replco/upm:latest
    59  
    60  .PHONY: pkgbuild
    61  pkgbuild: ## Update and test PKGBUILD
    62  	git clean -fdX packaging/aur
    63  	docker build . -f Dockerfile.arch -t upm:arch
    64  	docker run -it --rm -v "$$PWD/packaging/aur:/upm" upm:arch \
    65  		/tmp/update-pkgbuild.bash
    66  
    67  .PHONY: clean
    68  clean: clean-gen ## Remove build artifacts
    69  	rm -rf cmd/upm/upm dist
    70  
    71  .PHONY: help
    72  help: ## Show this message
    73  	@echo "usage:" >&2
    74  	@grep -h "[#]# " $(MAKEFILE_LIST)	| \
    75  		sed 's/^/  make /'		| \
    76  		sed 's/:[^#]*[#]# /|/'		| \
    77  		sed 's/%/LANG/'			| \
    78  		column -t -s'|' >&2
    79  
    80  .PHONY: test
    81  test:
    82  	go test ./... -v
    83  
    84  ifdef TEST_SUITE
    85  GO_TEST_RUN_OPTS=$(TEST_SUITE)
    86  else
    87  GO_TEST_RUN_OPTS=.
    88  endif
    89  
    90  .PHONY: test-suite
    91  ifdef UPM_CI
    92  test-suite:
    93  	go get gotest.tools/gotestsum
    94  	# TODO: Move the following setup out into before/after or a separate
    95  	# environment-specific runner
    96  	venv="$$(mktemp -d)"; \
    97  	python -m venv "$$venv"; \
    98  	source "$$venv/bin/activate"; \
    99  	go run gotest.tools/gotestsum --junitfile ./junit.xml ./test-suite
   100  else
   101  test-suite:
   102  	nix develop -c nix shell -c go test -run $(GO_TEST_RUN_OPTS) ./test-suite
   103  
   104  # I don't have a great name for these. The cases are as follows:
   105  #   make test-python3            # This runs inside nix develop and gates test suite
   106  #                                # execution on any backend starting with python3
   107  #   make unwrapped-test-python3  # This sets the requisite envvars to run the filtered
   108  #                                # test suite execution, but letting you run
   109  #                                # _outside of nix_, should you need a virtualenv or
   110  #                                # something special.
   111  #   make wrapped-test-python3    # This is the underlying command that powers the above
   112  #                                # two modes. It isn't very useful when run directly,
   113  #                                # since it doesn't know where upm or the PYPI_MAP_DB are.
   114  test-%:
   115  	nix develop -c nix shell -c make wrapped-$@
   116  
   117  unwrapped-test-%:
   118  	label="$@"; \
   119  	label="$${label#unwrapped-}"; \
   120  	PATH=$$PWD/cmd/upm/:"$$PATH" \
   121  	PYPI_MAP_DB=$$PWD/internal/backends/python/pypi_map.sqlite \
   122  			 make wrapped-$$label
   123  
   124  wrapped-test-%:
   125  	suite_prefix="$$(echo "$@" | cut -d- -f 3-)"; \
   126  	echo "Running $$suite_prefix"; \
   127  	cd test-suite; \
   128  	UPM_SUITE_PREFIX="$$suite_prefix" go test
   129  endif
   130  
   131  fmt:
   132  	go fmt github.com/replit/upm/...