2021-12-08 21:39:39 +00:00
|
|
|
# Copyright 2016-2021, Pulumi Corporation. All rights reserved.
|
2017-11-12 00:20:56 +00:00
|
|
|
|
|
|
|
# common.mk provides most of the scalfholding for our build system. It
|
|
|
|
# provides default targets for each project we want to build.
|
|
|
|
#
|
|
|
|
# The default targets we use are:
|
|
|
|
#
|
2019-05-02 17:18:02 +00:00
|
|
|
# - ensure: restores any dependencies needed for the build from
|
2017-11-12 00:20:56 +00:00
|
|
|
# remote sources (e.g dep ensure or yarn install)
|
|
|
|
#
|
|
|
|
# - build: builds a project but does not install it. In the case of
|
|
|
|
# go code, this usually means running go install (which
|
|
|
|
# would place them in `GOBIN`, but not `PULUMI_ROOT`
|
|
|
|
#
|
|
|
|
# - install: copies the bits we plan to ship into a layout in
|
|
|
|
# `PULUMI_ROOT` that looks like what a customer would get
|
|
|
|
# when they download and install Pulumi. For JavaScript
|
|
|
|
# projects, installing also runs yarn link to register
|
|
|
|
# this package, so that other projects can depend on it.
|
|
|
|
#
|
2017-12-04 02:12:20 +00:00
|
|
|
# - lint: runs relevent linters for the project
|
|
|
|
#
|
2017-11-12 00:20:56 +00:00
|
|
|
# - test_fast: runs the fast tests for a project. These are often
|
|
|
|
# go unit tests or javascript unit tests, they should
|
|
|
|
# complete quickly, as we expect developers to run them
|
|
|
|
# fequently as part of their "inner loop" development.
|
|
|
|
#
|
|
|
|
# - test_all: runs all of test_fast and then runs additional testing,
|
|
|
|
# which may take longer (some times a lot longer!). These
|
|
|
|
# are often integration tests which will use `pulumi` to
|
|
|
|
# deploy example Pulumi projects, creating cloud
|
|
|
|
# resources along the way.
|
|
|
|
#
|
|
|
|
# In addition, we have a few higher level targets that just depend on
|
|
|
|
# these targets:
|
|
|
|
#
|
2017-12-04 02:12:20 +00:00
|
|
|
# - only_build: this target runs build and install targets
|
|
|
|
#
|
|
|
|
# - only_test: this target runs the list and test_all targets
|
|
|
|
# (test_all itself runs test_fast)
|
|
|
|
#
|
2017-11-12 00:20:56 +00:00
|
|
|
# - default: this is the target that is run by default when no
|
|
|
|
# arguments are passed to make, it runs the build, lint,
|
|
|
|
# install and test_fast targets
|
|
|
|
#
|
|
|
|
# - core: this target behaves like `default` except for the case
|
|
|
|
# where a project declares SUB_PROJECTS (see a discussion on
|
|
|
|
# that later). In that case, building `core` target does not
|
|
|
|
# build sub projects.
|
|
|
|
#
|
|
|
|
# - all: this target runs build, lint, install and test_all (which
|
|
|
|
# itself runs test_fast).
|
|
|
|
#
|
|
|
|
# Before including this makefile, a project may define some values
|
|
|
|
# that this makefile understands:
|
|
|
|
#
|
|
|
|
# - PROJECT_NAME: If set, make default and make all will print a banner
|
|
|
|
# with the project name when they are built.
|
|
|
|
#
|
|
|
|
# - SUB_PROJECTS: If set, each item in the list is treated as a path
|
|
|
|
# to another project (relative to the directory of the
|
|
|
|
# main Makefile) which should be built as well. When
|
|
|
|
# this happens, the default and all targets first
|
|
|
|
# build the default or all target of each child
|
|
|
|
# project. For each subproject we also create targets
|
|
|
|
# with our standard names, prepended by the target
|
|
|
|
# name and an underscore, which just calls Make for
|
|
|
|
# that specific target. These can be handy targets to
|
|
|
|
# build explicitly on the command line from time to
|
|
|
|
# time.
|
|
|
|
#
|
|
|
|
# - NODE_MODULE_NAME: If set, an install target will be auto-generated
|
|
|
|
# that installs the module to
|
|
|
|
# $(PULUMI_ROOT)/node_modules/$(NODE_MODULE_NAME)
|
|
|
|
#
|
|
|
|
# This Makefile also provides some convience methods:
|
|
|
|
#
|
|
|
|
# STEP_MESSAGE is a macro that can be invoked with `$(call
|
|
|
|
# STEP_MESSAGE)` and it will print the name of the current target (in
|
|
|
|
# green text) to the console. All the targets provided by this makefile
|
|
|
|
# do that by default.
|
|
|
|
#
|
|
|
|
# Importing common.mk should be the first thing your Makefile does, after
|
|
|
|
# optionally setting SUB_PROJECTS, PROJECT_NAME and NODE_MODULE_NAME.
|
2022-03-25 21:56:11 +00:00
|
|
|
SHELL ?= /bin/bash
|
2017-11-12 00:20:56 +00:00
|
|
|
.SHELLFLAGS := -ec
|
|
|
|
|
2022-05-16 23:47:04 +00:00
|
|
|
STEP_MESSAGE = @printf "\033[0;32m$(shell echo '$@' | tr a-z A-Z | tr '_' ' '):\033[0m\n"
|
2017-11-12 00:20:56 +00:00
|
|
|
|
2021-12-15 20:32:41 +00:00
|
|
|
# Our install targets place items item into $PULUMI_ROOT.
|
2022-03-15 16:01:41 +00:00
|
|
|
PULUMI_ROOT ?= $$HOME/.pulumi-dev
|
2017-11-12 00:20:56 +00:00
|
|
|
|
2019-06-07 00:58:57 +00:00
|
|
|
# Use Python 3 explicitly vs expecting that `python` will resolve to a python 3
|
|
|
|
# runtime.
|
|
|
|
PYTHON ?= python3
|
|
|
|
PIP ?= pip3
|
|
|
|
|
2023-05-26 09:59:45 +00:00
|
|
|
ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
|
|
|
|
|
2017-11-12 00:20:56 +00:00
|
|
|
PULUMI_BIN := $(PULUMI_ROOT)/bin
|
|
|
|
PULUMI_NODE_MODULES := $(PULUMI_ROOT)/node_modules
|
|
|
|
|
2022-06-24 14:04:40 +00:00
|
|
|
# Extra options to pass to `go test` command, for example:
|
|
|
|
#
|
|
|
|
# make GO_TEST_OPTIONS="-short -test.v" test_fast
|
|
|
|
GO_TEST_OPTIONS :=
|
|
|
|
|
2022-09-14 06:20:01 +00:00
|
|
|
GO_TEST_PARALLELISM ?= 10 # -parallel, number of parallel tests to run within a package
|
|
|
|
GO_TEST_PKG_PARALLELISM ?= 2 # -p flag, number of parallel packages to test
|
|
|
|
GO_TEST_SHUFFLE ?= off # -shuffle flag, randomizes order of tests within a package
|
2022-09-16 22:04:05 +00:00
|
|
|
GO_TEST_TAGS ?= all
|
2024-05-09 16:15:41 +00:00
|
|
|
GO_TEST_RACE ?= true
|
2022-09-14 06:20:01 +00:00
|
|
|
|
2022-09-16 22:04:05 +00:00
|
|
|
GO_TEST_FLAGS = -count=1 -cover -tags="${GO_TEST_TAGS}" -timeout 1h \
|
|
|
|
-parallel=${GO_TEST_PARALLELISM} \
|
|
|
|
-shuffle=${GO_TEST_SHUFFLE} \
|
|
|
|
-p=${GO_TEST_PKG_PARALLELISM} \
|
2023-01-18 23:32:45 +00:00
|
|
|
-race=${GO_TEST_RACE} \
|
2022-09-14 06:20:01 +00:00
|
|
|
${GO_TEST_OPTIONS}
|
2022-06-24 14:04:40 +00:00
|
|
|
GO_TEST_FAST_FLAGS = -short ${GO_TEST_FLAGS}
|
2023-05-26 09:59:45 +00:00
|
|
|
|
|
|
|
GO_TEST = $(PYTHON) $(ROOT_DIR)/../scripts/go-test.py $(GO_TEST_FLAGS)
|
|
|
|
GO_TEST_FAST = $(PYTHON) $(ROOT_DIR)/../scripts/go-test.py $(GO_TEST_FAST_FLAGS)
|
|
|
|
|
fix goproxy environment variable in makefile (#14870)
# Description
~sourcegraph.com/sourcegraph/appdash-data disappeared from
proxy.golang.org. As a very temporary workaround we can use goproxy.io,
which still has it in its cache. However we should still try to get rid
of the dependency as a high priority.~
While trying to fix the sourcegraph.com/sourcegraph/appdash-data
dependency disappearing issue, one idea that came to mind was trying to
use a different goproxy. We already have a `GOPROXY` variable set in our
Makefiles, so just changing that should have worked. However that
variable had two problems:
- It was quoted in single quotes, which because this is a Makefile and
not shell were added to the environment, confusing Go.
- The variable was not exported, so it would never actually be used.
Fix these two problems, in case we need to use this in the future.
## Checklist
- [ ] I have run `make tidy` to update any new dependencies
- [ ] I have run `make lint` to verify my code passes the lint check
- [ ] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2023-12-19 14:05:01 +00:00
|
|
|
GOPROXY = https://proxy.golang.org
|
|
|
|
export GOPROXY
|
2019-02-26 21:39:33 +00:00
|
|
|
|
2022-05-16 23:47:04 +00:00
|
|
|
.PHONY: default all only_build only_test lint install test_all core build
|
2017-11-12 00:20:56 +00:00
|
|
|
|
2017-12-28 02:39:08 +00:00
|
|
|
# ensure that `default` is the target that is run when no arguments are passed to make
|
|
|
|
default::
|
|
|
|
|
2017-11-12 00:20:56 +00:00
|
|
|
# If there are sub projects, our default, all, and ensure targets will
|
|
|
|
# recurse into them.
|
|
|
|
ifneq ($(SUB_PROJECTS),)
|
2017-12-04 02:12:20 +00:00
|
|
|
only_build:: $(SUB_PROJECTS:%=%_only_build)
|
|
|
|
only_test:: $(SUB_PROJECTS:%=%_only_test)
|
2019-02-26 21:39:33 +00:00
|
|
|
only_test_fast:: $(SUB_PROJECTS:%=%_only_test_fast)
|
2017-11-12 00:20:56 +00:00
|
|
|
default:: $(SUB_PROJECTS:%=%_default)
|
|
|
|
all:: $(SUB_PROJECTS:%=%_all)
|
2020-09-09 20:37:03 +00:00
|
|
|
install_all:: $(SUB_PROJECTS:%=%_install_all)
|
|
|
|
test_all:: $(SUB_PROJECTS:%=%_test_all)
|
2018-08-08 20:00:42 +00:00
|
|
|
dist:: $(SUB_PROJECTS:%=%_dist)
|
2020-05-14 03:38:27 +00:00
|
|
|
brew:: $(SUB_PROJECTS:%=%_brew)
|
2017-11-12 00:20:56 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
# `core` is like `default` except it does not build sub projects.
|
|
|
|
core:: build lint install test_fast
|
|
|
|
|
|
|
|
# If $(PROJECT_NAME) has been set, have our default and all targets
|
|
|
|
# print a nice banner.
|
|
|
|
ifneq ($(PROJECT_NAME),)
|
|
|
|
default::
|
2022-05-16 23:47:04 +00:00
|
|
|
@printf "\033[1;37m$(shell echo '$(PROJECT_NAME)' | sed -e 's/./=/g')\033[1;37m\n"
|
|
|
|
@printf "\033[1;37m$(PROJECT_NAME)\033[1;37m\n"
|
|
|
|
@printf "\033[1;37m$(shell echo '$(PROJECT_NAME)' | sed -e 's/./=/g')\033[1;37m\n"
|
2017-11-12 00:20:56 +00:00
|
|
|
all::
|
2022-05-16 23:47:04 +00:00
|
|
|
@printf "\033[1;37m$(shell echo '$(PROJECT_NAME)' | sed -e 's/./=/g')\033[1;37m\n"
|
|
|
|
@printf "\033[1;37m$(PROJECT_NAME)\033[1;37m\n"
|
|
|
|
@printf "\033[1;37m$(shell echo '$(PROJECT_NAME)' | sed -e 's/./=/g')\033[1;37m\n"
|
2017-11-12 00:20:56 +00:00
|
|
|
endif
|
|
|
|
|
2017-12-04 02:12:20 +00:00
|
|
|
default:: build install lint test_fast
|
|
|
|
all:: build install lint test_all
|
2017-11-12 00:20:56 +00:00
|
|
|
|
2021-12-08 21:39:39 +00:00
|
|
|
|
2017-11-12 00:20:56 +00:00
|
|
|
build::
|
|
|
|
$(call STEP_MESSAGE)
|
|
|
|
|
|
|
|
lint::
|
|
|
|
$(call STEP_MESSAGE)
|
|
|
|
|
|
|
|
test_fast::
|
|
|
|
$(call STEP_MESSAGE)
|
|
|
|
|
|
|
|
install::
|
|
|
|
$(call STEP_MESSAGE)
|
2021-12-08 21:39:39 +00:00
|
|
|
@# Implicitly creates PULUMI_ROOT.
|
2017-11-12 00:20:56 +00:00
|
|
|
@mkdir -p $(PULUMI_BIN)
|
|
|
|
@mkdir -p $(PULUMI_NODE_MODULES)
|
|
|
|
|
2018-08-08 20:00:42 +00:00
|
|
|
dist::
|
|
|
|
$(call STEP_MESSAGE)
|
|
|
|
|
2020-05-14 03:38:27 +00:00
|
|
|
brew::
|
|
|
|
$(call STEP_MESSAGE)
|
|
|
|
|
2019-02-25 21:01:52 +00:00
|
|
|
test_all::
|
2017-11-12 00:20:56 +00:00
|
|
|
$(call STEP_MESSAGE)
|
|
|
|
|
|
|
|
ifneq ($(NODE_MODULE_NAME),)
|
|
|
|
install::
|
|
|
|
[ ! -e "$(PULUMI_NODE_MODULES)/$(NODE_MODULE_NAME)" ] || rm -rf "$(PULUMI_NODE_MODULES)/$(NODE_MODULE_NAME)"
|
|
|
|
mkdir -p "$(PULUMI_NODE_MODULES)/$(NODE_MODULE_NAME)"
|
|
|
|
cp -r bin/. "$(PULUMI_NODE_MODULES)/$(NODE_MODULE_NAME)"
|
2017-11-21 19:44:35 +00:00
|
|
|
cp yarn.lock "$(PULUMI_NODE_MODULES)/$(NODE_MODULE_NAME)"
|
2017-11-12 00:20:56 +00:00
|
|
|
rm -rf "$(PULUMI_NODE_MODULES)/$(NODE_MODULE_NAME)/node_modules"
|
|
|
|
cd "$(PULUMI_NODE_MODULES)/$(NODE_MODULE_NAME)" && \
|
2018-08-08 20:13:38 +00:00
|
|
|
yarn install --prefer-offline --production && \
|
2017-11-12 00:20:56 +00:00
|
|
|
(yarn unlink > /dev/null 2>&1 || true) && \
|
|
|
|
yarn link
|
|
|
|
endif
|
|
|
|
|
2017-12-04 02:12:20 +00:00
|
|
|
only_build:: build install
|
|
|
|
only_test:: lint test_all
|
2019-02-26 21:39:33 +00:00
|
|
|
only_test_fast:: lint test_fast
|
2017-12-04 02:12:20 +00:00
|
|
|
|
2017-11-12 00:20:56 +00:00
|
|
|
# Generate targets for each sub project. This project's default and
|
|
|
|
# all targets will depend on the sub project's targets, and the
|
2021-12-08 21:39:39 +00:00
|
|
|
# individual targets for sub projects are added as a convenience when
|
2017-11-12 00:20:56 +00:00
|
|
|
# invoking make from the command line
|
|
|
|
ifneq ($(SUB_PROJECTS),)
|
|
|
|
$(SUB_PROJECTS:%=%_default):
|
|
|
|
@$(MAKE) -C ./$(@:%_default=%) default
|
|
|
|
$(SUB_PROJECTS:%=%_all):
|
|
|
|
@$(MAKE) -C ./$(@:%_all=%) all
|
|
|
|
$(SUB_PROJECTS:%=%_ensure):
|
|
|
|
@$(MAKE) -C ./$(@:%_ensure=%) ensure
|
|
|
|
$(SUB_PROJECTS:%=%_build):
|
|
|
|
@$(MAKE) -C ./$(@:%_build=%) build
|
2020-09-09 20:37:03 +00:00
|
|
|
$(SUB_PROJECTS:%=%_install_all):
|
|
|
|
@$(MAKE) -C ./$(@:%_install_all=%) install
|
2017-11-12 00:20:56 +00:00
|
|
|
$(SUB_PROJECTS:%=%_lint):
|
|
|
|
@$(MAKE) -C ./$(@:%_lint=%) lint
|
|
|
|
$(SUB_PROJECTS:%=%_test_fast):
|
|
|
|
@$(MAKE) -C ./$(@:%_test_fast=%) test_fast
|
2020-09-09 20:37:03 +00:00
|
|
|
$(SUB_PROJECTS:%=%_test_all):
|
|
|
|
@$(MAKE) -C ./$(@:%_test_all=%) test_all
|
2017-11-12 00:20:56 +00:00
|
|
|
$(SUB_PROJECTS:%=%_install):
|
|
|
|
@$(MAKE) -C ./$(@:%_install=%) install
|
2017-12-04 02:12:20 +00:00
|
|
|
$(SUB_PROJECTS:%=%_only_build):
|
|
|
|
@$(MAKE) -C ./$(@:%_only_build=%) only_build
|
|
|
|
$(SUB_PROJECTS:%=%_only_test):
|
|
|
|
@$(MAKE) -C ./$(@:%_only_test=%) only_test
|
2019-02-26 21:39:33 +00:00
|
|
|
$(SUB_PROJECTS:%=%_only_test_fast):
|
|
|
|
@$(MAKE) -C ./$(@:%_only_test_fast=%) only_test_fast
|
2018-08-08 20:00:42 +00:00
|
|
|
$(SUB_PROJECTS:%=%_dist):
|
|
|
|
@$(MAKE) -C ./$(@:%_dist=%) dist
|
2020-05-14 03:38:27 +00:00
|
|
|
$(SUB_PROJECTS:%=%_brew):
|
|
|
|
@$(MAKE) -C ./$(@:%_brew=%) brew
|
2017-11-12 00:20:56 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
# As a convinece, we provide a format target that folks can build to
|
|
|
|
# run go fmt over all the go code in their tree.
|
|
|
|
.PHONY: format
|
2022-02-04 00:16:16 +00:00
|
|
|
format::
|
|
|
|
$(call STEP_MESSAGE)
|
|
|
|
find . -iname "*.go" -not \( \
|
|
|
|
-path "./vendor/*" -or \
|
|
|
|
-path "./*/compilation_error/*" -or \
|
|
|
|
-path "./*/testdata/*" \
|
2023-10-09 04:51:21 +00:00
|
|
|
\) | xargs gofumpt -w
|
2022-05-16 23:47:04 +00:00
|
|
|
|
|
|
|
# Defines the target `%.ensure` where `%` is an executable to check for. For
|
|
|
|
# example, the target `ensure.foo` will check that `foo` is available on the
|
|
|
|
# user's path.
|
|
|
|
%.ensure:
|
|
|
|
@pad=$$(printf '%0.1s' "."{1..20}); \
|
|
|
|
exec=$$(echo $@ | sed 's/\.ensure//'); \
|
|
|
|
printf "Checking for %s %*.*s " "$${exec}" 0 $$((20 - $${#exec})) "$$pad"; \
|
|
|
|
if command -v $${exec} > /dev/null ; then \
|
2022-06-22 16:08:07 +00:00
|
|
|
echo "\033[0;32m✓\033[0m"; \
|
2022-05-16 23:47:04 +00:00
|
|
|
else \
|
2022-06-22 16:08:07 +00:00
|
|
|
echo "\033[0;31mX\033[0m"; \
|
2022-05-16 23:47:04 +00:00
|
|
|
exit 1; \
|
|
|
|
fi \
|