author | Mohana Rao Gorai <mohana.gorai@oracle.com> |
Mon, 24 Mar 2014 09:57:22 -0700 | |
branch | s11u1-sru |
changeset 3001 | b96508535208 |
parent 32 | 280a7444e782 |
child 3770 | ca450a806cc1 |
permissions | -rwxr-xr-x |
10 | 1 |
#!/usr/perl5/bin/perl |
2 |
# |
|
3 |
# CDDL HEADER START |
|
4 |
# |
|
5 |
# The contents of this file are subject to the terms of the |
|
6 |
# Common Development and Distribution License (the "License"). |
|
7 |
# You may not use this file except in compliance with the License. |
|
8 |
# |
|
9 |
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
10 |
# or http://www.opensolaris.org/os/licensing. |
|
11 |
# See the License for the specific language governing permissions |
|
12 |
# and limitations under the License. |
|
13 |
# |
|
14 |
# When distributing Covered Code, include this CDDL HEADER in each |
|
15 |
# file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
16 |
# If applicable, add the following below this CDDL HEADER, with the |
|
17 |
# fields enclosed by brackets "[]" replaced with your own identifying |
|
18 |
# information: Portions Copyright [yyyy] [name of copyright owner] |
|
19 |
# |
|
20 |
# CDDL HEADER END |
|
21 |
# |
|
22 |
# Copyright (c) 2010, Oracle and/or it's affiliates. All rights reserved. |
|
23 |
# |
|
24 |
# |
|
25 |
# build-watch.pl - a simple utility to watch a process and it's children under |
|
26 |
# dtrace and process the results for dependency information. |
|
27 |
# |
|
28 |
# Ex: |
|
29 |
# $ export WS_TOP=/top/of/your/workspace |
|
30 |
# $ cd $(WS_TOP)/components/{component} |
|
31 |
# $ $(WS_TOP)/tools/build-watch.pl -c "gmake install" |
|
32 |
# |
|
33 |
||
34 |
use File::Temp qw/tempfile/; |
|
35 |
use Getopt::Long; |
|
36 |
||
37 |
my $verbose = 0; |
|
38 |
||
39 |
my @ignore = ( |
|
40 |
'^[^/\.].*', # ignore paths that don't begin with / or . |
|
41 |
'^/dev/', # ignore devices |
|
42 |
'^/etc/', # ignore config files |
|
43 |
'^/proc/', # ignore /proc |
|
44 |
'^/tmp/', # ignore temp files |
|
45 |
'^/var/', # ignore more temp/volatile files |
|
46 |
'^/usr/lib/locale/', # ignore locale support |
|
47 |
'^/usr/share/lib/make/', # ignore make bits |
|
48 |
'^/usr/share/lib/zoneinfo/', # ignore timezone info |
|
49 |
'/SUNWspro/', # ignore compiler bits |
|
50 |
'/sunstudio12.1/', # ignore more compiler bits |
|
51 |
'^/ws/', # nothing in /ws can be interesting |
|
52 |
'^\.[/\.]{0,1}$' # ignore ., .., and ./ |
|
53 |
); |
|
54 |
||
55 |
sub match |
|
56 |
{ |
|
57 |
local($string, @expressions) = @_; |
|
58 |
||
59 |
foreach (@expressions) { |
|
60 |
($string =~ m{$_}) && return (1); |
|
61 |
} |
|
62 |
return (0); |
|
63 |
} |
|
64 |
||
65 |
sub process_dtrace_results |
|
66 |
{ |
|
67 |
local ($filename) = @_; |
|
68 |
my (%tools, %files, $fh) = (); |
|
69 |
||
70 |
open($fh, "<$filename") || die "open($filename): $!\n"; |
|
71 |
while (<$fh>) { |
|
72 |
if (/^TOOL:\s+(\S+) = (\S+)$/) { |
|
73 |
$tools{$2} = $1; |
|
74 |
} elsif ((/^FILE:\s+(\S+)\s*$/) && (match($1, @ignore) == 0) && |
|
75 |
(-e $1)) { |
|
76 |
$files{$1} = $1; |
|
77 |
} |
|
78 |
} |
|
79 |
close($fh); |
|
80 |
||
81 |
return (\%tools, \%files); |
|
82 |
} |
|
83 |
||
84 |
sub generate_package_requirements |
|
85 |
{ |
|
86 |
local (*tools, *files) = @_; |
|
87 |
my ($count, %pkgs, @search_strings, $search_string) = (0); |
|
88 |
||
89 |
# create a set of search strings to query the package DB |
|
90 |
foreach (sort (keys %tools, keys %files)) { |
|
91 |
if ($count++ % 100 == 0) { |
|
92 |
defined($search_string) && \ |
|
93 |
push(@search_strings, $search_string); |
|
94 |
$search_string = $_; |
|
95 |
} else { |
|
96 |
$search_string .= " OR $_"; |
|
97 |
} |
|
98 |
} |
|
99 |
push(@search_strings, $search_string); |
|
100 |
||
101 |
# walk through the search strings and query the package DB |
|
102 |
foreach (@search_strings) { |
|
103 |
my $IFH; |
|
104 |
||
105 |
open($IFH, "pkg search -l -H -o path,pkg.name '$_'|"); |
|
106 |
while (<$IFH>) { |
|
107 |
(/^(\S+)\s+(\S+)$/) && ($pkgs{$1} = $2); |
|
108 |
} |
|
109 |
close($IFH); |
|
110 |
} |
|
111 |
||
112 |
return (\%pkgs); |
|
113 |
} |
|
114 |
||
115 |
# |
|
116 |
# Main execution begins here |
|
117 |
# |
|
118 |
GetOptions("c|command=s" => \$cmd, "i|input-file=s" => \@file, |
|
32
280a7444e782
automatically generate intercomponent dependencies for build ordering
Norm Jacobs <Norm.Jacobs@Sun.COM>
parents:
17
diff
changeset
|
119 |
"p|pkg" => \$pkg_flag, "v|verbose" => \$verbose); |
10 | 120 |
|
121 |
if (defined($cmd)) { |
|
122 |
$file = (tempfile(UNLINK => 1))[1]; |
|
123 |
||
124 |
if (!defined($ENV{'WS_TOP'})) { |
|
125 |
print("WS_TOP must be set in the calling environment\n"); |
|
126 |
exit(1); |
|
127 |
} |
|
128 |
($verbose == 1) && print("*** Executing '$cmd' under dtrace...\n"); |
|
129 |
system($ENV{'WS_TOP'}."/tools/build-watch.d", "-o", $file, "-c", $cmd); |
|
130 |
} |
|
131 |
||
132 |
($verbose == 1) && printf("*** Processing results...\n"); |
|
133 |
my ($tools, $files) = process_dtrace_results($file); |
|
134 |
||
32
280a7444e782
automatically generate intercomponent dependencies for build ordering
Norm Jacobs <Norm.Jacobs@Sun.COM>
parents:
17
diff
changeset
|
135 |
if (defined($pkg_flag)) { |
280a7444e782
automatically generate intercomponent dependencies for build ordering
Norm Jacobs <Norm.Jacobs@Sun.COM>
parents:
17
diff
changeset
|
136 |
($verbose == 1) && printf("*** Generating package requirements...\n"); |
280a7444e782
automatically generate intercomponent dependencies for build ordering
Norm Jacobs <Norm.Jacobs@Sun.COM>
parents:
17
diff
changeset
|
137 |
my ($pkgs) = generate_package_requirements($tools, $files); |
280a7444e782
automatically generate intercomponent dependencies for build ordering
Norm Jacobs <Norm.Jacobs@Sun.COM>
parents:
17
diff
changeset
|
138 |
} |
10 | 139 |
|
140 |
if (defined($tools)) { |
|
17
56b936d4786f
Change dependency output to construct Makefile macros
Norm Jacobs <Norm.Jacobs@Sun.COM>
parents:
10
diff
changeset
|
141 |
print "\n"; |
56b936d4786f
Change dependency output to construct Makefile macros
Norm Jacobs <Norm.Jacobs@Sun.COM>
parents:
10
diff
changeset
|
142 |
print "REQUIRED_TOOL +=\t$_\n" for (sort keys %$tools); |
10 | 143 |
} |
144 |
||
145 |
if (defined($files)) { |
|
17
56b936d4786f
Change dependency output to construct Makefile macros
Norm Jacobs <Norm.Jacobs@Sun.COM>
parents:
10
diff
changeset
|
146 |
print "\n"; |
56b936d4786f
Change dependency output to construct Makefile macros
Norm Jacobs <Norm.Jacobs@Sun.COM>
parents:
10
diff
changeset
|
147 |
print "REQUIRED_FILE +=\t$_\n" for (sort keys %$files); |
10 | 148 |
} |
149 |
||
150 |
if (defined($pkgs)) { |
|
151 |
@unique{values %$pkgs} = (); |
|
17
56b936d4786f
Change dependency output to construct Makefile macros
Norm Jacobs <Norm.Jacobs@Sun.COM>
parents:
10
diff
changeset
|
152 |
print "\n"; |
56b936d4786f
Change dependency output to construct Makefile macros
Norm Jacobs <Norm.Jacobs@Sun.COM>
parents:
10
diff
changeset
|
153 |
print "REQUIRED_PKG +=\t$_\n" for (sort keys %unique); |
10 | 154 |
} |
155 |
||
156 |
exit(0); |