|
1 # Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 # All rights reserved. |
|
3 # This component and the accompanying materials are made available |
|
4 # under the terms of the License "Eclipse Public License v1.0" |
|
5 # which accompanies this distribution, and is available |
|
6 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 # |
|
8 # Initial Contributors: |
|
9 # Nokia Corporation - initial contribution. |
|
10 # |
|
11 # Contributors: |
|
12 # |
|
13 # Description: |
|
14 # |
|
15 |
|
16 package SetP4Client; |
|
17 |
|
18 use strict; |
|
19 use Carp; |
|
20 use Sys::Hostname; |
|
21 |
|
22 # Start |
|
23 # |
|
24 # Inputs |
|
25 # $iClientName (Name of the client to create) |
|
26 # $iCodeline (Codeline root) |
|
27 # $iUser |
|
28 # $iDrive |
|
29 # $iHost |
|
30 # $iType |
|
31 # |
|
32 # Outputs |
|
33 # |
|
34 # Description |
|
35 # |
|
36 |
|
37 sub Start |
|
38 { |
|
39 my ( $iCodeline, $iDrive, $iType) = @_; |
|
40 my ($iUser, $iHost, $iClientname); |
|
41 |
|
42 $iUser = &get_user(); |
|
43 ($iHost) = &hostname() =~ /(\S+?)\./; |
|
44 if ($iHost eq "") |
|
45 { |
|
46 # Not a fully qualified Hostname, use use raw name |
|
47 $iHost = &hostname(); |
|
48 } |
|
49 print "Hostname is $iHost\n"; |
|
50 $iClientname = $iHost."_source_".$iType; |
|
51 |
|
52 #processing codeline |
|
53 $iCodeline =~ s?//CLIENTNAME/?//$iClientname/?g; |
|
54 my (@iSplit_codeline) = split /\+/, $iCodeline; |
|
55 for (my ($n)=1; $n <= $#iSplit_codeline; $n=$n+2) |
|
56 { |
|
57 $iSplit_codeline[$n] .= "\n"; |
|
58 } |
|
59 |
|
60 #Flushes and deletes old client, then creates new client and sets it as a default |
|
61 &set_view($iClientname); |
|
62 #Sets up client specification |
|
63 &set_client($iHost, $iClientname, $iUser, $iDrive, @iSplit_codeline); |
|
64 |
|
65 |
|
66 } |
|
67 |
|
68 # Start |
|
69 # |
|
70 # Inputs |
|
71 # |
|
72 # Outputs |
|
73 # $iUser |
|
74 # |
|
75 # Description |
|
76 # This Gets the user name |
|
77 sub get_user |
|
78 { |
|
79 my ($iLine, $iUser); |
|
80 |
|
81 open USER, "p4 user -o |" or die "Can't read user"; |
|
82 while ($iLine=<USER>) |
|
83 { |
|
84 if ($iLine =~ /^User:\s+(\S+)/) |
|
85 { |
|
86 $iUser = $1; |
|
87 } |
|
88 } |
|
89 close USER; |
|
90 return ($iUser); |
|
91 } |
|
92 |
|
93 sub set_client |
|
94 { |
|
95 my ($iHost, $iClientname, $iUser, $iDrive, @iSplit_codeline) = @_; |
|
96 |
|
97 open CLIENT, "| p4 client -i" or die "Can't create Perforce client"; |
|
98 |
|
99 print CLIENT<<CLIENTSPEC_EOF; |
|
100 # A Perforce Client Specification. |
|
101 # |
|
102 # Client: The client name. |
|
103 # Update: The date this specification was last modified. |
|
104 # Access: The date this client was last used in any way. |
|
105 # Owner: The user who created this client. |
|
106 # Host: If set, restricts access to the named host. |
|
107 # Description: A short description of the client (optional). |
|
108 # Root: The base directory of the client workspace. |
|
109 # Options: Client options: |
|
110 # [no]allwrite [no]clobber [no]compress |
|
111 # [un]locked [no]modtime [no]rmdir |
|
112 # LineEnd: Text file line endings on client: local/unix/mac/win/share. |
|
113 # View: Lines to map depot files into the client workspace. |
|
114 # |
|
115 # Use 'p4 help client' to see more about client views and options. |
|
116 |
|
117 Client: $iClientname |
|
118 |
|
119 Owner: $iUser |
|
120 |
|
121 Host: $iHost |
|
122 |
|
123 Description: |
|
124 DO NOT USE THIS CLIENT UNLESS YOU ARE PART OF THE "BUILD" TEAM. |
|
125 This client is generated automatically when GetSource.pl is |
|
126 called as a part of the build process. If client spec |
|
127 is changed manually it will not take any effect as the |
|
128 client will be deleted and then regenerated during |
|
129 build. |
|
130 |
|
131 Root: $iDrive |
|
132 |
|
133 Options: noallwrite noclobber nocompress crlf unlocked nomodtime normdir |
|
134 |
|
135 View: |
|
136 @iSplit_codeline |
|
137 |
|
138 CLIENTSPEC_EOF |
|
139 |
|
140 close CLIENT; # Terminate input, and wait for command to finish.. |
|
141 } |
|
142 |
|
143 |
|
144 sub set_view() |
|
145 { |
|
146 my ($iClientname) = @_; |
|
147 print `p4 client -d $iClientname 2>&1`; |
|
148 print `p4 set p4client=$iClientname 2>&1`; |
|
149 } |
|
150 1; |