Marcel Telka
2023-07-13 372e47b02fb373b300ccdd31bd290c085edad8c9
makemaker.mk: use MYMETA.json instead of META.json for metadata

3 files modified
96 ■■■■■ changed files
make-rules/ips.mk 2 ●●● patch | view | raw | blame | history
make-rules/makemaker.mk 72 ●●●●● patch | view | raw | blame | history
tools/perl-meta-deps 22 ●●●● patch | view | raw | blame | history
make-rules/ips.mk
@@ -553,7 +553,7 @@
# truly lazy among us.  This is only a piece of the REQUIRED_PACKAGES puzzle.
# You must still include packages for tools you build and test with.
#
REQUIRED_PACKAGES::     $(RESOLVED) $(REQUIRED_PACKAGES_RESOLVED) $(BUILD_DIR)/filter-own-pkgs
REQUIRED_PACKAGES::     $(RESOLVED) $(REQUIRED_PACKAGES_RESOLVED) $(BUILD_DIR)/filter-own-pkgs $(REQUIRED_PACKAGES_EXTRA_DEPS)
    $(GMAKE) RESOLVE_DEPS= $(BUILD_DIR)/.resolved-$(MACH)
    @$(GSED) -i -e '/^# Auto-generated dependencies$$/,$$d' Makefile
    @echo "# Auto-generated dependencies" >>Makefile
make-rules/makemaker.mk
@@ -41,6 +41,10 @@
$(BUILD_DIR)/%-$(1)/.installed:            PERL_VERSION=$(1)
$(BUILD_DIR)/%-$(1)/.tested:            PERL_VERSION=$(1)
$(BUILD_DIR)/%-$(1)/.tested-and-compared:    PERL_VERSION=$(1)
$(BUILD_DIR)/%-$(1)/.depend-build:        PERL_VERSION=$(1)
$(BUILD_DIR)/%-$(1)/.depend-runtime:        PERL_VERSION=$(1)
$(BUILD_DIR)/%-$(1)/.depend-test:        PERL_VERSION=$(1)
endef
$(foreach perlver,$(PERL_VERSIONS),$(eval $(call perl-version-rule,$(perlver))))
@@ -170,8 +174,8 @@
    $(TOUCH) $@
# We need to add -$(PLV) to package fmri and generate runtime dependencies based on META.json
GENERATE_EXTRA_DEPS += $(BUILD_DIR)/META.json
# We need to add -$(PLV) to package fmri and add runtime dependencies from metadata to generated manifest
GENERATE_EXTRA_DEPS += $(BUILD_DIR)/META.depend-runtime.res
GENERATE_EXTRA_CMD += | \
    $(GSED) -e 's/^\(set name=pkg.fmri [^@]*\)\(.*\)$$/\1-$$(PLV)\2/' | \
    $(CAT) - <( \
@@ -179,42 +183,56 @@
        echo "\# perl modules are unusable without perl runtime binary" ; \
        echo "depend type=require fmri=__TBD pkg.debug.depend.file=perl \\" ; \
        echo "    pkg.debug.depend.path=usr/perl5/\$$(PERLVER)/bin" ; \
        $(CAT) $(BUILD_DIR)/META.json \
            | $(WS_TOOLS)/perl-meta-deps $(WS_MACH) $(BUILD_DIR) runtime $(PERL_VERSION) \
            | $(GSED) -e 's|^\(depend.*pkg:/runtime/perl-\$$(PLV).*\)$$|\#\1|g' \
        echo "" ; \
        echo "\# Automatically generated dependencies based on distribution metadata" ; \
        $(CAT) $(BUILD_DIR)/META.depend-runtime.res | $(PKGFMT) \
    )
# Add build dependencies from META.json to REQUIRED_PACKAGES.  The dependency
# on META.depend-test.required here is purely to get the file created as a side
# effect of this target.
# Add build dependencies from metadata to REQUIRED_PACKAGES.
REQUIRED_PACKAGES_RESOLVED += $(BUILD_DIR)/META.depend-build.res
$(BUILD_DIR)/META.depend-build.res: $(BUILD_DIR)/META.json $(BUILD_DIR)/META.depend-test.required
    $(CAT) $(BUILD_DIR)/META.json | $(WS_TOOLS)/perl-meta-deps $(WS_MACH) $(BUILD_DIR) build $(PERL_VERSION) > $@
# Generate list of TEST_REQUIRED_PACKAGES entries
$(BUILD_DIR)/META.depend-test.required: $(BUILD_DIR)/META.json
    $(CAT) $(BUILD_DIR)/META.json \
        | $(WS_TOOLS)/perl-meta-deps $(WS_MACH) $(BUILD_DIR) test $(PERL_VERSION) \
        | $(GNU_GREP) '^depend.*pkg:/library/perl-5/.*\$$(PLV)' \
        | $(GSED) -e 's|^depend.*pkg:/\(library/perl-5/.*\)-\$$(PLV).*$$|TEST_REQUIRED_PACKAGES.perl += \1|' > $@
REQUIRED_PACKAGES_EXTRA_DEPS += $(BUILD_DIR)/META.depend-test.required
$(BUILD_DIR)/META.depend-test.required: $(BUILD_DIR)/META.depend-test.res
    $(GSED) -e 's|^depend.*pkg:/\(library/perl-5/.*\)-\$$(PLV).*$$|TEST_REQUIRED_PACKAGES.perl += \1|' < $< > $@
# Add META.depend-test.required to the generated list of REQUIRED_PACKAGES
REQUIRED_PACKAGES_TRANSFORM += -e '$$r $(BUILD_DIR)/META.depend-test.required'
# Create META.json
$(BUILD_DIR)/META.json: $(SOURCE_DIR)/.prep
    $(MKDIR) $(BUILD_DIR)
    if [ -f $(SOURCE_DIR)/META.json ] ; then \
        $(CAT) $(SOURCE_DIR)/META.json ; \
    elif [ -f $(SOURCE_DIR)/META.yml ] ; then \
        $(CAT) $(SOURCE_DIR)/META.yml \
            | $(PYTHON) -c 'import sys, yaml, json; y=yaml.safe_load(sys.stdin.read()); print(json.dumps(y))' \
            | $(JQ) '{prereqs:{configure:{requires:.configure_requires},build:{requires:.build_requires},runtime:{requires}}}' ; \
    fi > $@
# perl-meta-deps requires jq
# The configure target should create the MYMETA.json file.  If it does not we
# need a fallback to use either META.json or META.yml.  We probably (and
# hopefully) currently have no component requiring such fallback.
$(BUILD_DIR)/%/MYMETA.json:    $(BUILD_DIR)/%/.configured
    if [ ! -f $@ ] ; then \
        if [ -e $(@D)/META.json ] ; then \
            $(CAT) $(@D)/META.json ; \
        elif [ -e $(@D)/META.yml ] ; then \
            $(CAT) $(@D)/META.yml \
                | $(PYTHON) -c 'import sys, yaml, json; y=yaml.safe_load(sys.stdin.read()); print(json.dumps(y))' \
                | $(JQ) '{prereqs:{configure:{requires:.configure_requires},build:{requires:.build_requires},runtime:{requires}}}' ; \
        fi > $@ ; \
    else \
        $(TOUCH) $@ ; \
    fi
$(BUILD_DIR)/%/.depend-build:    $(BUILD_DIR)/%/MYMETA.json
    $(WS_TOOLS)/perl-meta-deps $(WS_MACH) $(BUILD_DIR) build $(PERL_VERSION) < $< > $@
$(BUILD_DIR)/%/.depend-runtime:    $(BUILD_DIR)/%/MYMETA.json
    $(WS_TOOLS)/perl-meta-deps $(WS_MACH) $(BUILD_DIR) runtime $(PERL_VERSION) < $< > $@
$(BUILD_DIR)/%/.depend-test:    $(BUILD_DIR)/%/MYMETA.json
    $(WS_TOOLS)/perl-meta-deps $(WS_MACH) $(BUILD_DIR) test $(PERL_VERSION) < $< > $@
$(BUILD_DIR)/META.depend-build.res:    $(BUILD_$(MK_BITS):%.built=%.depend-build)
    $(CAT) $^ | $(SORT) -u > $@
$(BUILD_DIR)/META.depend-runtime.res:    $(BUILD_$(MK_BITS):%.built=%.depend-runtime)
    $(CAT) $^ | $(SORT) -u > $@
$(BUILD_DIR)/META.depend-test.res:    $(BUILD_$(MK_BITS):%.built=%.depend-test)
    $(CAT) $^ | $(SORT) -u > $@
# jq is needed for perl-meta-deps and to convert META.yml to MYMETA.json
USERLAND_REQUIRED_PACKAGES += text/jq
# pyyaml is needed to convert META.yml to META.json
# pyyaml is needed to convert META.yml to MYMETA.json
USERLAND_REQUIRED_PACKAGES += library/python/pyyaml
tools/perl-meta-deps
@@ -57,17 +57,17 @@
find "$CACHEDIR" -type f -mtime +7 -exec rm -f {} \;
printf "\n# Automatically generated dependencies based on distribution metadata\n"
/usr/bin/jq -r '.prereqs|'"$PHASES"'|.requires,.recommends|to_entries?|.[]|.key+" "+(.value|tostring)' | while read PREREQ VERSION ; do
    # Convert perl version number to pkg(5) compatible form
    VER=$("$PERL_VERSION_CONVERT" "$PREREQ" "$VERSION")
    [[ "$VER" != "0" ]] && VER="@$VER" || VER=
    CACHEFILE="$CACHEDIR/$PREREQ-$PERLVER"
    # Resolve the dependency if not in cache already
    if [[ ! -s "$CACHEDIR/$PREREQ" ]] ; then
    if [[ ! -s "$CACHEFILE" ]] ; then
        # We must replace '::' by '-' otherwise 'pkgdepend resolve' fails
        MANIFEST="$BUILD_DIR/META-${PREREQ//::/-}"
        MANIFEST="$BUILD_DIR/META-${PREREQ//::/-}-$PERLVER"
        # Prepare manifest
        if [[ "$PREREQ" == "perl" ]] ; then
@@ -89,15 +89,15 @@
        # Resolve dependency
        if /usr/bin/pkgdepend resolve "$MANIFEST" ; then
            # Remove version number and cache the result
            cat "$MANIFEST.res" | sed -e 's/@[^ ]*//g' -e 's/-'$PLV'/-$(PLV)/g' > "$CACHEDIR/$PREREQ"
            cat "$MANIFEST.res" | sed -e 's/@[^ ]*//g' -e 's/-'$PLV'/-$(PLV)/g' > "$CACHEFILE"
        else
            printf "ERROR: Prerequisite %s not found\n" "$PREREQ" >&2
            cat "$MANIFEST"
        fi
    fi
    # Use cached result (if any) and add required version number
    [[ -f "$CACHEDIR/$PREREQ" ]] && cat "$CACHEDIR/$PREREQ" | sed  -e 's/\(fmri=[^ ]*\)/\1'$VER'/g'
    # Use cached result (if any), add required version number and drop runtime/perl
    [[ -f "$CACHEFILE" ]] && cat "$CACHEFILE" | sed -e 's/\(fmri=[^ ]*\)/\1'$VER'/g' -e '/fmri=pkg:\/runtime\/perl-\$(PLV)/d'
done | /usr/bin/pkgfmt -u | uniq | (
    PREV_LINE_H=
    PREV_FMRI=
@@ -117,10 +117,6 @@
        [[ "$FMRI" == "$VER" ]] && VER=
        [[ -n "$VER" ]] && VER="@$VER"
        FMRI="fmri=$FMRI"
        # There is no connection between module version and
        # runtime/perl version for modules bundled with runtime/perl
        [[ "$FMRI" == 'fmri=pkg:/runtime/perl-$(PLV)' ]] && VER=
        if [[ "$PREV_LINE_H" != "$LINE_H" || "$PREV_FMRI" != "$FMRI" || "$PREV_LINE_T" != "$LINE_T" ]] ; then
            [[ -n "$PREV_LINE_H$PREV_FMRI$PREV_VER$PREV_LINE_T" ]] && printf "%s%s%s%s\n" "$PREV_LINE_H" "$PREV_FMRI" "$PREV_VER" "$PREV_LINE_T"
@@ -149,4 +145,6 @@
        done
    done
    [[ -n "$PREV_LINE_H$PREV_FMRI$PREV_VER$PREV_LINE_T" ]] && printf "%s%s%s%s\n" "$PREV_LINE_H" "$PREV_FMRI" "$PREV_VER" "$PREV_LINE_T"
)| /usr/bin/pkgfmt
)
exit 0