Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Validate new keywords possibilities and add a deprecated entry
Baptiste Daroussin committed 5 years ago
commit f6bd336a53f8ec4bcb68aff01914ea55a2d01eea
parent 256b8b1
2 files changed +48 -1
modified libpkg/pkg_ports.c
@@ -107,6 +107,10 @@ keyword_open_schema(void)
		"      items = { type = string }; "
		"      uniqueItems: true "
		"    }; "
+
		"    actions_script = { type = string }; "
+
		"    validation = { type = string }; "
+
		"    deprecated = { type = boolean }; "
+
		"    deprecation_message = { type = string }; "
		"    attributes = { "
		"      type = object; "
		"      properties { "
@@ -1082,6 +1086,7 @@ external_keyword(struct plist *plist, char *keyword, char *line, struct file_att
	char keyfile_path[MAXPATHLEN];
	int ret = EPKG_UNKNOWN, fd;
	ucl_object_t *o, *schema;
+
	const ucl_object_t *obj;
	struct ucl_schema_error err;

	keyword_dir = pkg_object_string(pkg_config_get("PLIST_KEYWORDS_DIR"));
@@ -1124,6 +1129,17 @@ external_keyword(struct plist *plist, char *keyword, char *line, struct file_att
		}
	}

+
	if ((obj = ucl_object_find_key(o, "deprecated")) &&
+
	    ucl_object_toboolean(obj)) {
+
		obj = ucl_object_find_key(o, "deprecation_message");
+
		pkg_emit_error("Use of '@%s' is deprecated%s%s", keyword,
+
		   obj != NULL ? ": " : "",
+
		   obj != NULL ? ucl_object_tostring(obj) : "");
+
		if (ctx.developer_mode) {
+
			ucl_object_unref(o);
+
			return (EPKG_FATAL);
+
		}
+
	}
	ret = apply_keyword_file(o, plist, line, attr);

	return (ret);
modified tests/frontend/create.sh
@@ -23,7 +23,8 @@ tests_init \
	time \
	create_from_plist_keyword_validation \
	create_from_plist_keyword_real_args \
-
	create_from_plist_keyword_lua_actions
+
	create_from_plist_keyword_lua_actions \
+
	create_from_plist_keyword_deprecated

genmanifest() {
	cat << EOF >> +MANIFEST
@@ -702,3 +703,33 @@ touch A B
		-o match:"-rw-r--r-- .*plop[ /]+wheel.* /A$" \
		tar tvf test-1.txz
}
+

+
create_from_plist_keyword_deprecated_body()
+
{
+
	genmanifest
+
	genplist "@test A B C D"
+

+
cat << EOF > test.ucl
+
arguments: true
+
deprecated: true
+
EOF
+

+
	atf_check \
+
		-e inline:"${PROGNAME}: Use of '@test' is deprecated\n" \
+
		-s exit:0 \
+
		pkg -o PLIST_KEYWORDS_DIR=. create -o ${TMPDIR} -m . -p test.plist -r .
+

+
cat << EOF > test.ucl
+
arguments: true
+
deprecated: true
+
deprecation_message: <<EOM
+
we don't like it anymore
+
EOM
+
EOF
+

+
	atf_check \
+
		-e inline:"${PROGNAME}: Use of '@test' is deprecated: we don't like it anymore\n" \
+
		-s exit:0 \
+
		pkg -o PLIST_KEYWORDS_DIR=. create -o ${TMPDIR} -m . -p test.plist -r .
+

+
}