Skip to content

Commit 2a8c994

Browse files
committed
tooling: Improve handling of editable files
1. When running `make help` or `make status` the output regarding editable packages has been improved. Now the following states are possible: ok: Package is built and up-to-date. outdated: Package is not available or source is newer. editable: Package is editable. editable-other-name: Package path is editable, but by another name. This can happen when you set editable and then change the version of the package by either setting VERSION or by checking out another state of the code. editable-elsewhere: Package is editable, but from a different location. This can happen when you have multiple clones of the repository at different locations. These last two issues have come up multiple times for users. 2. Running `make export` checks that a package is not "editable" or "editable-elsewhere" before trying to run `conan export`.
1 parent 771a7f5 commit 2a8c994

File tree

1 file changed

+37
-11
lines changed

1 file changed

+37
-11
lines changed

Makefile.package

+37-11
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,29 @@ PACKAGE_VERSION := $(or \
5555
PACKAGE_CHANNEL := cloe/develop
5656
PACKAGE_FQN := ${PACKAGE_NAME}/${PACKAGE_VERSION}@${PACKAGE_CHANNEL}
5757

58+
# It is an order of magnitude faster to parse ~/.conan/editable_packages.json
59+
# ourselves than to get conan to do it for us. This should only take us 20ms,
60+
# while conan needs 250ms. Also, this will tell us if the package is editable,
61+
# or the path to the current conanfile.py is marked as editable. This helps
62+
# inform the user when they make a package editable, but then check out another
63+
# state of the tree with a different version.
64+
SOURCE_CONANFILE_REALPATH := $(realpath ${SOURCE_CONANFILE})
65+
define JQ_PACKAGE_EDITABLE
66+
if has(\"${PACKAGE_FQN}\") then
67+
if .[\"${PACKAGE_FQN}\"].path == \"${SOURCE_CONANFILE_REALPATH}\" then
68+
\"editable\"
69+
else
70+
\"editable-elsewhere\"
71+
end
72+
else
73+
if ([.[].path] | any(. == \"${SOURCE_CONANFILE_REALPATH}\")) then
74+
\"editable-other-name\"
75+
else
76+
\"not-editable\"
77+
end
78+
end
79+
endef
80+
5881
# Normally, you should set this in your profile, but if you just want to build
5982
# the package in debug mode once, you can do it this way, although it will
6083
# only apply to local builds.
@@ -92,9 +115,9 @@ endif
92115

93116
# INFORMATIONAL TARGETS -------------------------------------------------------
94117
.DEFAULT: help
95-
.SILENT: help status parse-info info-name info-version info-channel info-fqn info
96-
.PHONY: help status parse-info info-name info-version info-channel info-fqn info
97-
help:: parse-info
118+
.SILENT: help status parse-info parse-editable info-name info-version info-channel info-fqn info
119+
.PHONY: help status parse-info parse-editable info-name info-version info-channel info-fqn info
120+
help:: parse-info parse-editable
98121
echo "Usage: make <target>"
99122
echo
100123
echo "The following targets define common operations with this package in"
@@ -136,6 +159,7 @@ help:: parse-info
136159
echo " PACKAGE_VERSION: ${PACKAGE_VERSION}"
137160
echo " PACKAGE_CHANNEL: ${PACKAGE_CHANNEL}"
138161
echo " PACKAGE_FQN: ${PACKAGE_FQN}"
162+
echo " PACKAGE_EDITABLE:${PACKAGE_EDITABLE}"
139163
echo " PACKAGE_ID: ${PACKAGE_ID}"
140164
echo " PACKAGE_DIR: ${PACKAGE_DIR}"
141165
echo " PACKAGE_DATE: ${PACKAGE_DATE}"
@@ -149,28 +173,30 @@ parse-info: ${BUILD_LOCKFILE}
149173
# target needs one of these variables, they should depend on this target
150174
# to ensure that these variables are set.
151175
#
152-
$(eval PACKAGE_INFO := $(shell conan info ${ALL_OPTIONS} "${PACKAGE_FQN}" --package-filter "${PACKAGE_FQN}" --paths | sed -r 's/$$/\\n/'))
176+
$(eval PACKAGE_INFO := $(shell conan info ${ALL_OPTIONS} "${PACKAGE_FQN}" --package-filter "${PACKAGE_FQN}" --paths 2>/dev/null | sed -r 's/$$/\\n/'))
153177
$(eval PACKAGE_ID := $(shell echo -e "${PACKAGE_INFO}" | sed -rn 's/^ *ID: *(.*)$$/\1/p'))
154178
$(eval PACKAGE_DIR := $(shell echo -e "${PACKAGE_INFO}" | sed -rn 's/^ *package_folder: *(.*)$$/\1/p'))
155179
$(eval PACKAGE_DATE := $(shell echo -e "${PACKAGE_INFO}" | sed -rn 's/^ *Creation date: *(.*)$$/\1/p'))
156180

157-
status: parse-info
181+
parse-editable:
182+
$(eval PACKAGE_EDITABLE := $(shell [ -e ~/.conan/editable_packages.json ] && jq -r "${JQ_PACKAGE_EDITABLE}" ~/.conan/editable_packages.json || echo "not-editable"))
183+
184+
status: parse-info parse-editable
158185
# Show the *approximate* status of each package in the cloe workspace.
159186
#
160187
# This lets you know whether a package is in editable mode or not,
161188
# and will also let you know if any of the files in the package
162189
# directory has been modified more recently than the package in the
163190
# Conan cache.
164191
#
165-
_editable=$$(conan editable list | grep "${PACKAGE_FQN}"); \
166-
if [ -z "$${_editable}" ]; then \
192+
if [ "${PACKAGE_EDITABLE}" != "not-editable" ] ; then \
193+
echo "${PACKAGE_EDITABLE} : ${PACKAGE_FQN}"; \
194+
else \
167195
if [ -n "${PACKAGE_DATE}" ] && [ -z "$$(find -type f -newermt "${PACKAGE_DATE}")" ]; then \
168196
echo "ok : ${PACKAGE_FQN}"; \
169197
else \
170198
echo "outdated : ${PACKAGE_FQN}"; \
171199
fi \
172-
else \
173-
echo "editable : ${PACKAGE_FQN}"; \
174200
fi
175201

176202
info-name:
@@ -218,13 +244,13 @@ uneditable:
218244
# CONAN TARGETS ---------------------------------------------------------------
219245
.PHONY: export package package-all package-missing package-outdated purge list
220246

221-
export:
247+
export: parse-editable
222248
# Export sources to Conan cache.
223249
#
224250
# This does not build this package but provides the sources and the
225251
# build recipe to Conan for on-demand building.
226252
#
227-
conan export . ${PACKAGE_FQN}
253+
if [ "${PACKAGE_EDITABLE}" = "not-editable" ] || [ "${PACKAGE_EDITABLE}" = "editable-other-name" ]; then conan export . ${PACKAGE_FQN}; fi
228254

229255
download:
230256
# Try to download the package to Conan cache.

0 commit comments

Comments
 (0)