perl/clearcase programming

23
Perl/ClearCase Programming With an emphasis on UNIX/Windows interoperation David Boyce

Upload: jeneil

Post on 23-Jan-2016

71 views

Category:

Documents


0 download

DESCRIPTION

Perl/ClearCase Programming. With an emphasis on UNIX/Windows interoperation David Boyce. General Notes. Me [email protected] http://www.cleartool.com Focus: Scripting vs Programming Portability vs Interoperability Perl vs Java (philosophy). Sharing modules. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Perl/ClearCase Programming

Perl/ClearCase Programming

With an emphasis on UNIX/Windows interoperation

David Boyce

Page 2: Perl/ClearCase Programming

General Notes

Me [email protected] http://www.cleartool.com

Focus: Scripting vs Programming Portability vs Interoperability Perl vs Java (philosophy)

Page 3: Perl/ClearCase Programming

Sharing modules

Make use of SMB symlink translation Must be on UNIX/Samba/TAS/NAS Some SMB’s require symlink switch

Even WIN32 binary modules work Share /usr/local/bin (\\server\ulb)

or /usr/local (\\server\local).All maintenance from UNIX.

Page 4: Perl/ClearCase Programming

A Co-Operating Win32 Perl

ClearCase bundled perl (ccperl) Local-only WIN32 build Local with network modules Networked standard build Networked ActiveState build

Page 5: Perl/ClearCase Programming

Sharing and executing scripts

Choices: executing scripts on Windows Register the .pl/.plx extension Use pl2bat Use a redirector:

@echo off

\\server\perl\bin\perl \\server\ulb\whence %*

Local .bat, remote/shared perl script (ulb) Use perl’s bin directory UNC path entries must be user and at end

Page 6: Perl/ClearCase Programming

Trigger Definition

% ct lstype -l trtype:mkelem_post

trigger type "mkelem_post"

02-Aug-99.18:35:01 by [VOB Admin] (vobadm.ccusers@sparc5)

owner: vobadm

group: ccusers

all element trigger

post-operation mkelem

action: -execunix /usr/local/bin/perl /data/ccase/triggers/mkelem_post.tgr

action: -execwin perl //ultra10/triggers/mkelem_post.tgr

excluded users: vobadm

Page 7: Perl/ClearCase Programming

Interop Tips and Tricks

use constant MSWIN => $^O =~ /MSWin32|Windows_NT/i;

Quoting: make use of qq() and q() Especially in –e scripts No single quote (‘) in cmd.exe

Remember: 2>&1 works on Windows -e “foo@@/main/0”

Useful for testing dynamic-vs-snapshot Follow with ct desc for snapshot support

Page 8: Perl/ClearCase Programming

Interop Tips and Tricks (cont)

Make a DNS alias “usr” for the fileserver Enables e.g. “//usr/local/bin” anywhere Useful for includes in cspecs etc.

Use the notify command for email (4.0) Beware of PERL5LIB et al (CC bug) Use binmode on all binary files Cleartool returns native version paths

Page 9: Perl/ClearCase Programming

Interop Tips and Tricks (cont)

Use s%\\%/%g if MSWIN; File::Spec 0.82 (abstract pathnames)

File::Spec->rel2abs($path); # native fmt

File::Spec::Unix->rel2abs($path); # force Unix fmt

my $nul = MSWIN ? ‘NUL’ : ‘/dev/null’; system(“cmd >$nul 2>&1”);

Page 10: Perl/ClearCase Programming

Interop: system() and exec()

The documentation lies! system() always uses a shell exec() always exits

Perl 5.6.0 emulates fork but not exec emulation: exit(system(“cmd”)!=0));

Best: use ClearCase::Argv for complex/long-running programs

Page 11: Perl/ClearCase Programming

My Perl Modules

ClearCase::ClearPrompt ClearCase::Wrapper ClearCase::SyncTree ClearCase::CRDB Env::Path IPC::ClearTool ClearCase::Argv

Page 12: Perl/ClearCase Programming

ClearCase::ClearPrompt

Handles temp files automatically Capable of asynchronous operation Handles trigger series automatically Captures/emails error msgs (*CC 4.2)

use ClearCase::ClearPrompt qw(clearprompt +TRIGGERSERIES +CAPTURE=vobadm);

clearprompt(‘proceed’, ‘-prompt’, ‘Hi!’));

$bug = clearprompt(qw(text -def 0 –prompt), “Bug #?”);

Page 13: Perl/ClearCase Programming

ClearCase::Wrapper

Not an API, a program in module form Potentially wraps all cleartool access Cannot affect Windows GUI Many cmdline features (-rec/-all/-dir)

Page 14: Perl/ClearCase Programming

ClearCase::SyncTree

Analogous to citree, clearfsimport Preserves CR’s Maps filenames Takes or derives file lists Regular expression filtering Comes with synctree program

Page 15: Perl/ClearCase Programming

ClearCase::CRDB

Unreleased CR analysis (impact analysis) Comes with whouses program Forward or backward analysis

Page 16: Perl/ClearCase Programming

Env::Path

Simply adds methods to existing EV’s Prepend, Append, Remove InsertBefore, InsertAfter Uniqify, DeleteNonexistent Replace, Whence (take RE’s)

Comes with envpath program Comes with whence program for Windows

use Env::Path ‘PATH’;PATH->Remove(‘/usr/ucb’);

Page 17: Perl/ClearCase Programming

IPC::ClearTool

Interop Speedup: order of magnitude, or none. Significant constant overhead CAL on Windows, coprocess on UNIX Preferred interface via ClearCase::Argv

Page 18: Perl/ClearCase Programming

ClearCase::Argv Features

Command line as object Advance Option Parsing (option sets) Interoperability

Prog, opts, args Attributes:

Verbosity (debug, quiet) Execution exceptions (autofail)

– Can exit or call exception handler

Page 19: Perl/ClearCase Programming

ClearCase::Argv for Interop

Quoting (->autoquote) Path normalization (->ccpathnorm) Output (->stdout, ->stderr) Globbing (->autoglob) Xargs behavior (->qxargs, ->syxargs)

Page 20: Perl/ClearCase Programming

ClearCase::Argv examples

my $ct = ClearCase::Argv->new;

$ct->autochomp(1);

my @co = $ct->lsco([‘-s’, ‘-all’], ‘.’)->qx;

$ct->ci([‘-c’, “comment”], @co)->system;

my @co = ctqx(“lsco –s –all .”);

ctsystem(qw(mkelem –c comment), @co);

Page 21: Perl/ClearCase Programming

Special-purpose Objects

my $ct = ClearCase::Argv->new;

$ct->autofail(1);

$ct->autochomp(1);

my $ctq = ClearCase::Argv->new;

$ct->stdout(0);

$ct->stderr(0);

Page 22: Perl/ClearCase Programming

Setting attributes

Per-object: $ct->stderr(1); Globally: ClearCase::Argv->stderr(1); export ARGV_STDERR=1 ClearCase::Argv->attropts;

-/dbg=1 -/quiet=1 -/ipc=1

Page 23: Perl/ClearCase Programming

Question Time