100 likes | 384 Views
Scripting with Perforce Prakash Ranade. The P4 Command-Line Client. P4 CLI offers access to all Perforce features. It can used in scripts and is the ideal interface for automated processes such as backups and nightly builds.
E N D
The P4 Command-Line Client • P4 CLI offers access to all Perforce features. It can used in scripts and is the ideal interface for automated processes such as backups and nightly builds. • Custom automation of your development and administrative processes can be accomplished by embedding the appropriate commands in Perl, Python, or any other scripting language.
The P4 Command-Line Client • P4 CLI uses the same commands and syntax on more than 50 platforms, and automatically translates line ending conventions between operating systems. • Generate custom reports from the Perforce metadata
The Perforce Perl Scripting • The Perforce Perl API allows you to write Perl scripts that directly execute Perforce commands. • P4Perl is the product name for a Perl module that allows you to execute Perforce commands without leaving Perl space and to get the results in Perl Arrays and Hashes.
P4Perl- Perl Extensions • #!/usr/bin/perl • use P4; • # Initialisation • my $p4 = new P4; • $p4->Init() or die( "Failed to connect to Perforce" ); • # Running "p4 info" and getting the results in array form • my @info; • @info = $p4->Info(); • # Submitting changes. Use "p4 change -o" to grab the change spec • # and "p4 submit -i" to do the submit. • # • # Commented out by default to make the example non-invasive • my $change = $p4->FetchChange(); • $change =~ s/<enter description here>/Some description/; • $p4->SetInput( $change ); • $p4->Submit( "-i" ) );
NetApp environment • We are into development of storage and networking products. • Number of users: Approximately 800. • Number of development sites: 5 (main development center in Sunnyvale, California; remote US-based development sites in Pittsburgh, RTP, NANE, and Bangalore, India) • Perforce Proxy: Used in India, Pittsburgh offices • Status: In production; All development files are on our NetApp storage systems (for main server only).
Scripting Advantages • Using scripting one can force the company specific rules. Examples… • Access control on depots • Branching strategy (cold, frozen, open) • Submit message check and integration with bug tracking system
Scripting at Bangalore site • P4P PROXY site • P4PORT defined based on site • Simple checks for P4CLIENT definitions • Enforce rule based on site.
How we did it!!! • /usr/local/bin/p4 wrapper perl script will manage p4 interactions on heterogeneous systems using platform dependant p4 binaries. • All Perforce users will use wrapper script. • Wrapper script does the argument processing, Access control, branching checks and executes p4 binary.
Checks at remote sites tight views • //depot/prod/XXX/YYY/… checks using tight views. • XXX is product • YYY is code-line • Define client views (and branch and label views) so users access only the files they require. For example, the following "tight" client view is restricted to specific depot areas: • //depot/main/svr/devA/... //ws/main/svr/devA/... //depot/main/dvr/lport/... //ws/main/dvr/lport/... //depot/rel2.0/svr/devA/bin/... //ws/rel2.0/svr/devA/bin/... //depot/qa/s6test/dvr/... //ws/qa/s6test/dvr/... • By contrast, the following unrestricted view is easier to set up but invites trouble when depots are very large: //depot/... //ws/... • Client views, branch views, and label views are defined using the p4 client, p4 branch, and p4 label commands, respectively, by the users who created them.