説明

Perforce Helix Core 2019.1ではHelix Core Extension(p4 extensionコマンド)が追加されました。
Helix Core Extensionは、管理者がワークフローをカスタマイズするための機能です。

Perfore Helix Coreは、ユーザが記述するプログラムまたは特定の操作が実行されると呼び出されるスクリプトであるトリガを使用した機能の拡張・カスタマイズをサポートしてきました。
Helix Core Extensionを使用することにより、Helix Coreサーバーランタイムとカスタムロジックを密接に統合して、製品の動作を拡張できます。

Helix Core Extensionとトリガを比較した場合の利点は以下の通りです。

Helix Core ExtensionWindows Serverでは使用できません。

Helix Core Extensions Developer Guide

利用手順

■ 前提

例として、【クライアントワークスペースのビュー定義でディポパスの階層数が3より少ない場合をチェックする】というサーバエクステンションを作成、サーバへのインストール、動作確認をするまでの手順を説明しています。

Perforce Workshopで公開されている"narrow_workspace_mappings"というサンプルを使用します。
スクリプトの記述については含めていません。

その他の設定は以下の通りです。
  ・ルートディレクトリ:/master
  ・サーバエクステンション用ディレクトリ:/master/narrow_workspace_mappings
  ・自動ログインユーザ:super

.サーバエクステンションのスケルトン作成

"/master/narrow_workspace_mappings" ディレクトリに移動し、スケルトンを作成します。

  p4 extension --sample server-extension-name
例:p4 extension --sample narrow_workspace_mappings

Extension template created in the 'narrow_workspace_mappings' directory.
※"main.lua"、"manifest.json"の2ファイルが作成されます。

2.main.luaの編集
main.luaファイルを編集してロジックを追加します。

今回の作業ではファイルの編集ではなく、"narrow_workspace_mappings"の"main.lua"をダウンロードサイトより入手し、"/master/narrow_workspace_mappings"ディレクトリ内のファイルを置き換えます。

narrow_workspace_mappings

3.".p4-extension"ファイルの作成
クライアントで"narrow_workspace_mappings.p4-extension"ファイルを作成します。
".p4-extension"ファイルは、サーバエクステンションをサーバにインストールする際に必要です。

  p4 extension --package server-extension-name
例:p4 extension --package narrow_workspace_mappings

Extension packaged successfully.
※"narrow_workspace_mappings.p4-extension"ファイルが作成されます

4.サーバエクステンションのインストール(確認)
作成したサーバエクステンションを、Helixサーバに実際にインストールする前に、レポートモードで確認します。

  p4 extension --install server-extension-name.p4-extension
例:p4 extension --install narrow_workspace_mappings.p4-extension

Would install Extension 'ExampleInc::narrow_workspace_mappings'
   ⋮
Version: '2019.1'
UUID: 22BB3349-4AD5-8617-203B-575747XXXXXX
Developer: Perforce Software Inc.
Description: [Example Extension, sample code] Restrict client views to have a configurable minimum
directory depth. This is to prevent user from
having a wide open workspace leading to getting unecessary files.
E.g. reject a mapping of //depot/... and allow //depot/some/more/narrow/path/...
License: BSD
Homepage URL: https://swarm.workshop.perforce.com/files/guest/perforce_software/extensions/2019-1
Compatible products: p4d
   ⋮
This was report mode. Use -y to perform the operation.

5.サーバエクステンションのインストール(実行)
 実行結果が確認できたら"-y"オプションを追加し、インストールを実行します。

  p4 extension --install server-extension-name.p4-extension -y
例:p4 extension --install narrow_workspace_mappings.p4-extension -y

Extension 'ExampleInc::narrow_workspace_mappings' version '2019.1' installed successfully.

6.インストールされているサーバエクステンションの確認
サーバエクステンションがインストールされていることを確認します

p4 extension --list –type=extensions

... extension ExampleInc::narrow_workspace_mappings
... rev 1
... developer Perforce Software Inc.
... description-snippet [Example Extension,
... UUID 22BB3349-4AD5-8617-203B-575747XXXXXX
... version 2019.1
... enabled false
... arch-dir server.extensions.dir/22BB3349-4AD5-8617-203B-575747XXXXXX/1-arch
... data-dir server.extensions.dir/22BB3349-4AD5-8617-203B-575747XXXXXX/1-data

7.サーバエクステンション構成のグローバル設定
インストールしたサーバエクステンションが、自動ログインに使用するユーザをsuperにするため、グローバル設定を変更します。
※コマンドで使用するネームスペース名は"manifest.json"ファイル内で定義されています。ここでは"ExampleInc"がネームスペース名となっています。

  p4 extension --configure name-space-name::server-extension-name
例:p4 extension --configure ExampleInc::narrow_workspace_mappings

   ⋮
ExtP4USER:   super    ●"sampleExtensionsUser"から変更
   ⋮

「Helix Core Extensions Developer Guide (2019.1)」- Server extension configuration (global and instance specs)

8.サーバエクステンション構成のインスタンス設定
インストールしたサーバエクステンションのインスタンス設定を変更します。
本手順では、「ワークスペースのビュー定義でディポパスの階層数を3より少ない」をチェックするサーバエクステションとするため、下記の変更を行います

  p4 extension --configure name-space-name::server-extension-name --name extCfg
例:p4 extension --configure ExampleInc::narrow_workspace_mappings --name extCfg

   ⋮
ExtConfig:
        exempt_users:
                super  ●"Space-separated list of which users do NOT have this restriction"を修正
        num_level:
                3               ●"insert minimum number of level across all"を修正
   ⋮

9.インストールしたサーバエクステンションの動作確認
P4Vを起動し、クライアントワークスペースのビューの定義を表示します
① [ 接続(C) ] → [ 現在のワークスペースを編集(W) ]を選択します。

  

② ディポパスの階層を[ 3 ] よりも少ない数で指定します。
  指定後[ OK ]をクリックします。

  

③ ディポパスの階層が確認され、下記メッセージが表示されます。

  

作業は以上です