author | Mike Sullivan <Mike.Sullivan@Oracle.COM> |
Fri, 12 Aug 2016 17:23:26 -0700 | |
changeset 6610 | 88360f57667e |
parent 5682 | 94c0ca64c022 |
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 |
# |
|
5682
94c0ca64c022
15558602 TCL_LD_SEARCH_FLAGS is wrongly defined in tclConfig.sh
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
3770
diff
changeset
|
22 |
|
94c0ca64c022
15558602 TCL_LD_SEARCH_FLAGS is wrongly defined in tclConfig.sh
Shawn Walker-Salas <shawn.walker@oracle.com>
parents:
3770
diff
changeset
|
23 |
# |
3770
ca450a806cc1
20440888 Userland python tools should migrate to 2.7
John Beck <John.Beck@Oracle.COM>
parents:
32
diff
changeset
|
24 |
# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
10 | 25 |
# |
26 |
# |
|
27 |
# build-watch.pl - a simple utility to watch a process and it's children under |
|
28 |
# dtrace and process the results for dependency information. |
|
29 |
# |
|
30 |
# Ex: |
|
31 |
# $ export WS_TOP=/top/of/your/workspace |
|
32 |
# $ cd $(WS_TOP)/components/{component} |
|
33 |
# $ $(WS_TOP)/tools/build-watch.pl -c "gmake install" |
|
34 |
# |
|
35 |
||
36 |
use File::Temp qw/tempfile/; |
|
37 |
use Getopt::Long; |
|
38 |
||
39 |
my $verbose = 0; |
|
40 |
||
41 |
my @ignore = ( |
|
42 |
'^[^/\.].*', # ignore paths that don't begin with / or . |
|
43 |
'^/dev/', # ignore devices |
|
44 |
'^/etc/', # ignore config files |
|
45 |
'^/proc/', # ignore /proc |
|
46 |
'^/tmp/', # ignore temp files |
|
47 |
'^/var/', # ignore more temp/volatile files |
|
48 |
'^/usr/lib/locale/', # ignore locale support |
|
49 |
'^/usr/share/lib/make/', # ignore make bits |
|
50 |
'^/usr/share/lib/zoneinfo/', # ignore timezone info |
|
51 |
'/SUNWspro/', # ignore compiler bits |
|
52 |
'/sunstudio12.1/', # ignore more compiler bits |
|
53 |
'^/ws/', # nothing in /ws can be interesting |
|
54 |
'^\.[/\.]{0,1}$' # ignore ., .., and ./ |
|
55 |
); |
|
56 |
||
57 |
sub match |
|
58 |
{ |
|
59 |
local($string, @expressions) = @_; |
|
60 |
||
61 |
foreach (@expressions) { |
|
62 |
($string =~ m{$_}) && return (1); |
|
63 |
} |
|
64 |
return (0); |
|
65 |
} |
|
66 |
||
67 |
sub process_dtrace_results |
|
68 |
{ |
|
69 |
local ($filename) = @_; |
|
70 |
my (%tools, %files, $fh) = (); |
|
71 |
||
72 |
open($fh, "<$filename") || die "open($filename): $!\n"; |
|
73 |
while (<$fh>) { |
|
74 |
if (/^TOOL:\s+(\S+) = (\S+)$/) { |
|
75 |
$tools{$2} = $1; |
|
76 |
} elsif ((/^FILE:\s+(\S+)\s*$/) && (match($1, @ignore) == 0) && |
|
77 |
(-e $1)) { |
|
78 |
$files{$1} = $1; |
|
79 |
} |
|
80 |
} |
|
81 |
close($fh); |
|
82 |
||
83 |
return (\%tools, \%files); |
|
84 |
} |
|
85 |
||
86 |
sub generate_package_requirements |
|
87 |
{ |
|
88 |
local (*tools, *files) = @_; |
|
89 |
my ($count, %pkgs, @search_strings, $search_string) = (0); |
|
90 |
||
91 |
# create a set of search strings to query the package DB |
|
92 |
foreach (sort (keys %tools, keys %files)) { |
|
93 |
if ($count++ % 100 == 0) { |
|
94 |
defined($search_string) && \ |
|
95 |
push(@search_strings, $search_string); |
|
96 |
$search_string = $_; |
|
97 |
} else { |
|
98 |
$search_string .= " OR $_"; |
|
99 |
} |
|
100 |
} |
|
101 |
push(@search_strings, $search_string); |
|
102 |
||
103 |
# walk through the search strings and query the package DB |
|
104 |
foreach (@search_strings) { |
|
105 |
my $IFH; |
|
106 |
||
107 |
open($IFH, "pkg search -l -H -o path,pkg.name '$_'|"); |
|
108 |
while (<$IFH>) { |
|
109 |
(/^(\S+)\s+(\S+)$/) && ($pkgs{$1} = $2); |
|
110 |
} |
|
111 |
close($IFH); |
|
112 |
} |
|
113 |
||
114 |
return (\%pkgs); |
|
115 |
} |
|
116 |
||
117 |
# |
|
118 |
# Main execution begins here |
|
119 |
# |
|
120 |
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
|
121 |
"p|pkg" => \$pkg_flag, "v|verbose" => \$verbose); |
10 | 122 |
|
123 |
if (defined($cmd)) { |
|
124 |
$file = (tempfile(UNLINK => 1))[1]; |
|
125 |
||
126 |
if (!defined($ENV{'WS_TOP'})) { |
|
127 |
print("WS_TOP must be set in the calling environment\n"); |
|
128 |
exit(1); |
|
129 |
} |
|
130 |
($verbose == 1) && print("*** Executing '$cmd' under dtrace...\n"); |
|
131 |
system($ENV{'WS_TOP'}."/tools/build-watch.d", "-o", $file, "-c", $cmd); |
|
132 |
} |
|
133 |
||
134 |
($verbose == 1) && printf("*** Processing results...\n"); |
|
135 |
my ($tools, $files) = process_dtrace_results($file); |
|
136 |
||
32
280a7444e782
automatically generate intercomponent dependencies for build ordering
Norm Jacobs <Norm.Jacobs@Sun.COM>
parents:
17
diff
changeset
|
137 |
if (defined($pkg_flag)) { |
280a7444e782
automatically generate intercomponent dependencies for build ordering
Norm Jacobs <Norm.Jacobs@Sun.COM>
parents:
17
diff
changeset
|
138 |
($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
|
139 |
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
|
140 |
} |
10 | 141 |
|
142 |
if (defined($tools)) { |
|
17
56b936d4786f
Change dependency output to construct Makefile macros
Norm Jacobs <Norm.Jacobs@Sun.COM>
parents:
10
diff
changeset
|
143 |
print "\n"; |
56b936d4786f
Change dependency output to construct Makefile macros
Norm Jacobs <Norm.Jacobs@Sun.COM>
parents:
10
diff
changeset
|
144 |
print "REQUIRED_TOOL +=\t$_\n" for (sort keys %$tools); |
10 | 145 |
} |
146 |
||
147 |
if (defined($files)) { |
|
17
56b936d4786f
Change dependency output to construct Makefile macros
Norm Jacobs <Norm.Jacobs@Sun.COM>
parents:
10
diff
changeset
|
148 |
print "\n"; |
56b936d4786f
Change dependency output to construct Makefile macros
Norm Jacobs <Norm.Jacobs@Sun.COM>
parents:
10
diff
changeset
|
149 |
print "REQUIRED_FILE +=\t$_\n" for (sort keys %$files); |
10 | 150 |
} |
151 |
||
152 |
if (defined($pkgs)) { |
|
153 |
@unique{values %$pkgs} = (); |
|
17
56b936d4786f
Change dependency output to construct Makefile macros
Norm Jacobs <Norm.Jacobs@Sun.COM>
parents:
10
diff
changeset
|
154 |
print "\n"; |
56b936d4786f
Change dependency output to construct Makefile macros
Norm Jacobs <Norm.Jacobs@Sun.COM>
parents:
10
diff
changeset
|
155 |
print "REQUIRED_PKG +=\t$_\n" for (sort keys %unique); |
10 | 156 |
} |
157 |
||
158 |
exit(0); |