Building your Perforce backed workspace

Once you've checked in your files to Perforce the next step is to check out a workspace. This requires a properly configured p4 client, to bring the right files into your workspace, and a target user workspace location. 

Project Template Client

An example template client is shown below:

Client: versic.tutorial.template
Update: 2015/11/14 13:56:15
Access: 2015/11/14 13:56:15
Owner:  mdx
Description:
        Created by mdx.
Root:   /home/mdx/workspaces/tutorial/versic_libs
Options:        noallwrite noclobber nocompress unlocked nomodtime rmdir
SubmitOptions:  submitunchanged
LineEnd:        local
View:
        //depot/mdx/tutorial/... //versic.tutorial.template/...

In this example we can see that the project files live in the //depot/mdx/tutorial of the Perforce depot. The root location is arbitrary at this time, the important information is the left hand side part of the View definition in line 12

Creating the Workspace

To create the workspace Perforce provides a simple script that reads the template client into the users environment, creates some target directories and syncs over the contents of the project depot location (defined in the template client

#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
# VersIC/P4 workspace creation script
#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
MDX_ROOT=/mdx

if [ $# -ne 2 ]; then
    echo "Expected PROJECT and PROJECT_HOME arguments"    return 1
else
    PROJECT=$1
    PROJECT_HOME=$2
fi


USERDIR=$PROJECT_HOME/$USER/$PROJECT
echo
echo "#######################################################"echo "#"echo "# Creating a methodics workspace for project $PROJECT"echo "# Located in $USERDIR"echo "#"echo "#######################################################"echo

#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
# VersIC setup
#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#
echo "Configuring VersIC ..."echo ""#
export MDX_LICENSE_FILE=$MDX_ROOT/license/license.dat
export VSC_INSTALL_DIR=$MDX_ROOT/tools/methodics/versic/current
export VSC_CONFIG_DIR=$MDX_ROOT/config/versic

#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
# VersIC GDM setup
#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#
echo "Configuring VersIC GDM ..."echo ""#
# export CDS_GDM_SHLIB_LOCATION=${VSC_INSTALL_DIR}/tools/lib:${VSC_INSTALL_DIR}/tools/lib/64bit
# export LD_LIBRARY_PATH=${VSC_INSTALL_DIR}/tools/lib:${VSC_INSTALL_DIR}/tools/lib/64bit
export PATH=${PATH}:${VSC_INSTALL_DIR}/tools/bin
export GDM_USE_SHLIB_ENVVAR=yes
unset GDMNOTLOADLIB

#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
# P4 setup
#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#
echo "Configuring P4 ..."echo ""#
export PATH=${PATH}:$MDX_ROOT/tools/p4/current
export P4PORT=localhost:1666
export P4CLIENT=versic.$PROJECT.$USER

#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
# Setup the p4 client
#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#
# NOTE: this assumes versic.$PROJECT.template client pre-exists with the correct viewspec
#

# Check we can create $USERDIR/versic_libs
if [ ! -w "$PROJECT_HOME" ]; then
    echo ERROR: Project home dir $PROJECT_HOME was not accessible. Please check your permissions. 1>&2
    return 1 # terminate and indicate error
else
    mkdir -p $USERDIR/versic_libs; cd $USERDIR/versic_libs
fi
p4 client -o -t versic.$PROJECT.template | grep -v Host > /tmp/template_client
p4 client -i < /tmp/template_client > /dev/null
/bin/rm -f /tmp/template_client

#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
# Create symbolic links to the cadence config files
#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#
echo "Creating user dir ..."echo ""#

#
cd $USERDIR
if [ ! -e cds.lib ]; then
  echo "INCLUDE $MDX_ROOT/tools/cds/IC616/share/cdssetup/dfII/cds.lib" > cds.lib
  echo "INCLUDE $USERDIR/versic_libs/cds.lib" >> cds.lib
fi
if [ ! -e .cdsinit ]; then
  ln -s $MDX_ROOT/tools/methodics/versic/current/config/cadence/dot_cdsinit .cdsinit
fi
ln -s -f $MDX_ROOT/tools/methodics/versic/current/config/cadence/cdsLibMgr.il

#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
# Populate your workspace
#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#
echo "Syncing the user files ..."echo ""#
p4 sync

#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
# One-time manual step to create managed cds.lib
#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#
# cd $USERDIR/versic_libs
# ls > cds.lib
# [edit and add DEFINE <library> ./<library> statements]
# p4 add cds.lib; p4 submit cds.lib -d 'added managed cds.lib'

and a wrapper script to pass in the project name and project root dir

source /mdx/tools/scripts/workspace/create_versic_p4_ws.sh ez /cache3/home