#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
#

#
# This set of transforms is intended to be used to convert a set of actions
# generated by "pkgsend generate ..." into a more generic set of actions with
# most attributes removed and paths converted to use strategically placed
# macros to remove plartform or version specifics.
#

# convert the "pkgsend generate" file "hash" to a common value
<transform file -> set action.hash 'NOHASH'>

# drop extra attribute data that "pkgsend generate" might have added
<transform dir file link hardlink license -> delete timestamp .*>
<transform dir file link hardlink license -> delete pkg.size .*>
<transform dir file link hardlink license -> delete owner .*>
<transform dir file link hardlink license -> delete group .*>
<transform dir link hardlink license -> delete mode .*>
# preserve mode for illumos-closed files
<transform file path=(?!opt/onbld/closed/root_i386) -> delete mode .*>

#<transform set name=pkg.fmri -> edit value "@[^ \t\n\r\f\v]*" "@$!(IPS_COMPONENT_VERSION),$!(BUILD_VERSION)">

<transform dir file link hardlink -> \
	edit path "/(sparcv9|amd64)$" "/$!(MACH64)">
<transform dir file link hardlink -> \
	edit path "/(sparcv9|amd64)/" "/$!(MACH64)/">
<transform dir file link hardlink -> \
	edit path "/(sparcv7|i86)$" "/$!(MACH32)">
<transform dir file link hardlink -> \
	edit path "/(sparcv7|i86)/" "/$!(MACH32)/">
<transform dir file link hardlink -> \
	edit path "/(sparc|i386)$" "/$!(MACH)">
<transform dir file link hardlink -> \
	edit path "/(sparc|i386)/" "/$!(MACH)/">

# perl support
<transform dir file link hardlink -> \
	edit path "^(usr/perl5/.*/)i86pc-solaris-(64int|thread-multi-64)/" "\1$!(PERL_ARCH)/">
<transform dir file link hardlink -> \
	edit path "^(usr/perl5/(vendor_perl/)?)5\.[^/]*" "\1$!(PERLVER)">
<transform dir file link hardlink \
	path=usr/perl5/.*/perllocal\.pod$ -> drop>
<transform dir file link hardlink \
	path=usr/perl5/.*/\.packlist$ -> drop>

# Python support
<transform dir file link hardlink path=usr\/lib\/python2\.7\/.*\.pyc$ -> drop>
<transform dir file link hardlink path=usr\/lib\/python2\.7\/.*\.pyo$ -> drop>
<transform dir file link hardlink path=usr\/lib\/python3\.\d+\/(.*\/)?__pycache__\/ -> drop>
# Drop backports/__init__.py because all supported Python versions are PEP 420
# compliant so this file is no longer needed.
# See https://github.com/jaraco/backports.entry_points_selectable/issues/5
<transform dir file link hardlink path=usr\/lib\/python3\.\d+\/vendor-packages\/backports\/__init__\.py$ -> drop>
# PEP 627 made the RECORD file optional.  Since we do not need the file and it
# could contain inaccurate info we simply drop it.
<transform dir file link hardlink path=usr\/lib\/python3\.\d+\/vendor-packages\/[^/]+\.dist-info/RECORD$ -> drop>
# Replace Python version by $(PYV)
<transform file -> \
	edit path "^(usr/lib/python3\.\d+/vendor-packages/(.*/)?[^/]+\.cpython-)3\d+\.so$" "\1$!(PYV).so">
# Replace Python version by $(PYVER)
<transform file path=usr/bin/[^/]+-3\.\d+$ -> default tmp.fmri "$(COMPONENT_FMRI)">
<transform file tmp.fmri=.*runtime/python -> edit path "^(usr/bin/[^/]+-)3\.\d+$" "\1$!(PYVER)">
<transform file tmp.fmri=.*library/python/ -> edit path "^(usr/bin/[^/]+-)3\.\d+$" "\1$!(PYVER)">
<transform file tmp.fmri=.* -> delete tmp.fmri .*>
<transform dir file link hardlink -> \
	edit path "^(usr/lib/python3\.\d+/vendor-packages/[^/]+-py)3\.\d+(\.egg-info(/.*)?)$" "\1$!(PYVER)\2">
<transform dir file link hardlink -> \
	edit path "^(usr/lib/python3\.\d+/vendor-packages/[^/]+-py)3\.\d+(-nspkg\.pth)$" "\1$!(PYVER)\2">
<transform dir file link hardlink -> \
	edit path "^(usr/lib/python)3\.\d+(/.*)?$" "\1$!(PYVER)\2">
<transform dir file link hardlink -> \
	edit path "^(usr/include/python)3\.\d+(/.*)?$" "\1$!(PYVER)\2">

# GCC support
<transform dir file link hardlink -> \
	edit path "^(usr\/gcc\/)\d+\/" "\1$!(GCCVER)/">

<transform link hardlink -> \
	edit target "(^|/)(sparcv9|amd64)(/|$)" "\1$!(MACH64)\3">
<transform link hardlink -> \
	edit target "(^|/)(sparcv7|i86)(/|$)" "\1$!(MACH32)\3">
<transform link hardlink -> \
	edit target "(^|/)(sparc|i386)(/|$)" "\1$!(MACH)\3">

# <transform dir file link hardlink -> \
# 	edit path "$(COMPONENT_NAME)" "$!(COMPONENT_NAME)">
# <transform dir file link hardlink -> \
# 	edit target "$(COMPONENT_NAME)" "$!(COMPONENT_NAME)">

<transform dir file link hardlink -> \
	edit path "$(HUMAN_VERSION_RE)" "$!(HUMAN_VERSION)">
<transform dir file link hardlink -> \
	edit target "$(HUMAN_VERSION_RE)" "$!(HUMAN_VERSION)">

<transform dir file link hardlink -> \
	edit path "$(COMPONENT_RE_VERSION)" "$!(COMPONENT_VERSION)">
<transform dir file link hardlink -> \
	edit target "$(COMPONENT_RE_VERSION)" "$!(COMPONENT_VERSION)">

<transform dir file link hardlink -> \
	edit path "$(IPS_COMPONENT_RE_VERSION)" "$!(IPS_COMPONENT_VERSION)">
<transform dir file link hardlink -> \
	edit target "$(IPS_COMPONENT_RE_VERSION)" "$!(IPS_COMPONENT_VERSION)">

# Clang support (must be after HUMAN_VERSION transforms)
<transform dir file link hardlink path="usr/clang/[^/]+/lib/lib.*\.so" -> \
	edit path "(lib[^/]+\.so\.)\d+" "\1$!(CLANGVER)">
<transform link hardlink path="usr/clang/[^/]+/lib/lib.*\.so" -> \
	edit target "(lib[^/]+\.so\.)\d+" "\1$!(CLANGVER)">
<transform dir file link hardlink -> \
	edit path "^(usr/clang/[^/]+/lib/clang/)\d+/" "\1$!(CLANGVER)/">
<transform dir file link hardlink -> \
	edit path "^(usr/clang/)\d+/" "\1$!(CLANGVER)/">

# convert temporary macro names to their real name
<transform set -> \
	edit value "\$!\((.*)\)" "$(\1)">
<transform dir file link hardlink -> \
	edit path "\$!\((.*)\)" "$(\1)">
<transform dir file link hardlink -> \
	edit target "\$!\((.*)\)" "$(\1)">
<transform dir file link hardlink -> \
	edit path "\$!\((.*)\)" "$(\1)">
<transform dir file link hardlink -> \
	edit target "\$!\((.*)\)" "$(\1)">
<transform dir file link hardlink -> \
	edit path "\$!\((.*)\)" "$(\1)">
<transform dir file link hardlink -> \
	edit target "\$!\((.*)\)" "$(\1)">
<transform dir file link hardlink -> \
	edit path "\$!\((.*)\)" "$(\1)">
<transform dir file link hardlink -> \
	edit target "\$!\((.*)\)" "$(\1)">
<transform dir file link hardlink -> \
	edit path "\$!\((.*)\)" "$(\1)">
<transform dir file link hardlink -> \
	edit target "\$!\((.*)\)" "$(\1)">

<transform file link hardlink path=mangled/(.*) -> drop>
# drop all dirs except for illumos-closed
<transform dir path=(?!(opt/onbld/closed/root_i386(-nd)?/)) -> drop>