From 765487390f48e03c5e118e86cc389a737693d1cc Mon Sep 17 00:00:00 2001 From: Jesse Wattenbarger Date: Thu, 20 Apr 2023 15:43:31 -0400 Subject: [PATCH] Fallback on PYTHON path in Makefile - Change default PYTHON in Makefile to be ranked choice - Fix `PYTHON_VERSION` target that expects just a word - Use native GNU Make `$(subst ,,)` instead of `sed` - Add 'version-for-buildyml' target to simplify ci If I understand correctly, this change should make '$(PYTHON)' work how we want it to everywhere. Before this change, on develpers' machines that don't have a 'python3.9' in their path, make would fail. With this change, we will prefer python3.9 if it's available, but we'll take python3 otherwise. --- Makefile | 16 ++++++++++++++-- tools/ansible/build.yml | 3 +-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 8ec6251f8318..e654a1e44595 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ -include awx/ui_next/Makefile -PYTHON ?= python3.9 +PYTHON := $(notdir $(shell for i in python3.9 python3; do command -v $$i; done|sed 1q)) DOCKER_COMPOSE ?= docker-compose OFFICIAL ?= no NODE ?= node @@ -606,7 +606,18 @@ VERSION: @echo "awx: $(VERSION)" PYTHON_VERSION: - @echo "$(PYTHON)" | sed 's:python::' + @echo "$(subst python,,$(PYTHON))" + +.PHONY: version-for-buildyml +version-for-buildyml: + @echo $(firstword $(subst +, ,$(VERSION))) +# version-for-buildyml prints a special version string for build.yml, +# chopping off the sha after the '+' sign. +# tools/ansible/build.yml was doing this: make print-VERSION | cut -d + -f -1 +# This does the same thing in native make without +# the pipe or the extra processes, and now the pb does `make version-for-buildyml` +# Example: +# 22.1.1.dev38+g523c0d9781 becomes 22.1.1.dev38 .PHONY: Dockerfile ## Generate Dockerfile for awx image @@ -658,6 +669,7 @@ messages: fi; \ $(PYTHON) manage.py makemessages -l en_us --keep-pot +.PHONY: print-% print-%: @echo $($*) diff --git a/tools/ansible/build.yml b/tools/ansible/build.yml index 3ac900494417..9270d69f58ab 100644 --- a/tools/ansible/build.yml +++ b/tools/ansible/build.yml @@ -4,8 +4,7 @@ gather_facts: true tasks: - name: Get version from SCM if not explicitly provided - shell: | - make print-VERSION | cut -d + -f -1 + command: make version-for-buildyml args: chdir: '../../' register: scm_version