xref: /illumos-gate/usr/src/pkg/scripts/pkglist.awk (revision 2bd79b08)
1*2bd79b08SAndy Fiddaman# This file and its contents are supplied under the terms of the
2*2bd79b08SAndy Fiddaman# Common Development and Distribution License ("CDDL"), version 1.0.
3*2bd79b08SAndy Fiddaman# You may only use this file in accordance with the terms of version
4*2bd79b08SAndy Fiddaman# 1.0 of the CDDL.
5*2bd79b08SAndy Fiddaman#
6*2bd79b08SAndy Fiddaman# A full copy of the text of the CDDL should have accompanied this
7*2bd79b08SAndy Fiddaman# source. A copy of the CDDL is also available via the Internet at
8*2bd79b08SAndy Fiddaman# http://www.illumos.org/license/CDDL.
9*2bd79b08SAndy Fiddaman
10*2bd79b08SAndy Fiddaman# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
11*2bd79b08SAndy Fiddaman# Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
12*2bd79b08SAndy Fiddaman
13*2bd79b08SAndy Fiddaman#
14*2bd79b08SAndy Fiddaman# We do the work in the BEGIN action instead of using pattern matching because
15*2bd79b08SAndy Fiddaman# we expect the fmri to be at or near the first line of each input file, and
16*2bd79b08SAndy Fiddaman# this way lets us avoid reading the rest of the file after we find what we
17*2bd79b08SAndy Fiddaman# need.
18*2bd79b08SAndy Fiddaman#
19*2bd79b08SAndy Fiddaman# We keep track of a failure to locate an fmri, so we can exit with an error
20*2bd79b08SAndy Fiddaman# code which will cause the make run to fail, but we still attempt to process
21*2bd79b08SAndy Fiddaman# each package on the command line, in hope of maybe giving some additional
22*2bd79b08SAndy Fiddaman# useful info.
23*2bd79b08SAndy Fiddaman#
24*2bd79b08SAndy Fiddaman
25*2bd79b08SAndy FiddamanBEGIN {
26*2bd79b08SAndy Fiddaman	if (ARGC < 2) {
27*2bd79b08SAndy Fiddaman		exit
28*2bd79b08SAndy Fiddaman	}
29*2bd79b08SAndy Fiddaman	retcode = 0
30*2bd79b08SAndy Fiddaman	for (i = 1; i < ARGC; i++) {
31*2bd79b08SAndy Fiddaman		do {
32*2bd79b08SAndy Fiddaman			e = getline f < ARGV[i]
33*2bd79b08SAndy Fiddaman		} while ((e == 1) && (f !~ /name=pkg.fmri/))
34*2bd79b08SAndy Fiddaman		if (e == 1) {
35*2bd79b08SAndy Fiddaman			l = split(f, a, "=")
36*2bd79b08SAndy Fiddaman			fmri = a[l]
37*2bd79b08SAndy Fiddaman			facet = 0
38*2bd79b08SAndy Fiddaman			do {
39*2bd79b08SAndy Fiddaman				e = getline f < ARGV[i]
40*2bd79b08SAndy Fiddaman				if (e == 1 &&
41*2bd79b08SAndy Fiddaman				    f ~ /org.opensolaris.incorp-facet.*=true/)
42*2bd79b08SAndy Fiddaman					facet = 1
43*2bd79b08SAndy Fiddaman			} while ((e == 1) && (f ~ /^set name=/))
44*2bd79b08SAndy Fiddaman			close(ARGV[i])
45*2bd79b08SAndy Fiddaman			printf("depend fmri=%s type=$(PKGDEP_TYPE)", fmri)
46*2bd79b08SAndy Fiddaman			if (facet)
47*2bd79b08SAndy Fiddaman				printf(" vlfacet=true")
48*2bd79b08SAndy Fiddaman			print ""
49*2bd79b08SAndy Fiddaman		} else {
50*2bd79b08SAndy Fiddaman			print "no fmri in " ARGV[i] >> "/dev/stderr"
51*2bd79b08SAndy Fiddaman			retcode = 2
52*2bd79b08SAndy Fiddaman		}
53*2bd79b08SAndy Fiddaman	}
54*2bd79b08SAndy Fiddaman	exit retcode
55*2bd79b08SAndy Fiddaman}
56