perl/clearcase programming with an emphasis on unix/windows interoperation david boyce bmrccug...

23
Perl/ClearCase Programming With an emphasis on UNIX/Windows interoperation David Boyce BMRCCUG 9/25/2001

Upload: kasey-risby

Post on 14-Dec-2015

227 views

Category:

Documents


2 download

TRANSCRIPT

Perl/ClearCase Programming

With an emphasis on UNIX/Windows interoperation

David Boyce

BMRCCUG 9/25/2001

General Notes

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

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

A Co-Operating Win32 Perl

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

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.

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

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 My triggers are at http://www.cleartool.com

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

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

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”);

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

My Perl Modules

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

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 #?”);

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)

ClearCase::SyncTree

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

ClearCase::CRDB

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

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’);

IPC::ClearTool

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

ClearCase::Argv Features

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

Prog, opts, args Attributes:

Verbosity (debug, quiet) Execution exceptions (autofail)

– Can exit or call exception handler

ClearCase::Argv for Interop

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

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);

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);

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

Question Time

At http://www.cleartool.com: This presentation Code samples Detailed documents