Monorepo for Aesthetic.Computer
aesthetic.computer
1# Create a new Perforce workspace for local Windows builds
2
3$ErrorActionPreference = "Stop"
4
5Write-Host "=========================================" -ForegroundColor Cyan
6Write-Host "Create Perforce Workspace for SpiderLily" -ForegroundColor Cyan
7Write-Host "=========================================" -ForegroundColor Cyan
8Write-Host ""
9
10# Set Perforce environment
11$env:P4PORT = "ssl:falsework.helixcore.io:1666"
12$env:P4USER = "machine"
13
14# Get computer name for unique workspace
15$hostname = $env:COMPUTERNAME.ToLower()
16$workspaceName = "spiderlily_windows_$hostname"
17$workspaceRoot = "C:\Perforce\SpiderLily"
18
19Write-Host "Server: $env:P4PORT" -ForegroundColor Cyan
20Write-Host "User: $env:P4USER" -ForegroundColor Cyan
21Write-Host "New Workspace: $workspaceName" -ForegroundColor Cyan
22Write-Host "Root Directory: $workspaceRoot" -ForegroundColor Cyan
23Write-Host ""
24
25# Create workspace directory
26if (!(Test-Path $workspaceRoot)) {
27 Write-Host "Creating directory: $workspaceRoot" -ForegroundColor Yellow
28 New-Item -ItemType Directory -Path $workspaceRoot -Force | Out-Null
29}
30
31# Check if workspace already exists
32$existingClient = p4 clients -e $workspaceName 2>$null
33if ($existingClient) {
34 Write-Host "[WARNING] Workspace '$workspaceName' already exists" -ForegroundColor Yellow
35 $response = Read-Host "Delete and recreate? (y/N)"
36 if ($response -eq "y" -or $response -eq "Y") {
37 Write-Host "Deleting existing workspace..." -ForegroundColor Yellow
38 p4 client -d $workspaceName
39 } else {
40 Write-Host "Using existing workspace." -ForegroundColor Yellow
41 $env:P4CLIENT = $workspaceName
42 Write-Host ""
43 Write-Host "Run sync-project.ps1 to sync files" -ForegroundColor Cyan
44 exit 0
45 }
46}
47
48# Get the view mapping from the existing workspace
49Write-Host "Getting depot view from existing workspace..." -ForegroundColor Yellow
50$viewMapping = p4 client -o spiderlily_build_workspace | Select-String "^\s*//SL_main/" | ForEach-Object {
51 $line = $_.ToString().Trim()
52 # Replace the client name in the mapping
53 $line -replace '//spiderlily_build_workspace/', "//$workspaceName/"
54}
55
56if (!$viewMapping) {
57 Write-Host "[ERROR] Could not get view mapping from existing workspace!" -ForegroundColor Red
58 Write-Host "Manually create the workspace using P4V" -ForegroundColor Yellow
59 exit 1
60}
61
62Write-Host "Creating new workspace..." -ForegroundColor Yellow
63Write-Host ""
64
65# Create workspace spec
66$clientSpec = @"
67Client: $workspaceName
68
69Owner: $env:P4USER
70
71Host: $hostname
72
73Description:
74 Local Windows build workspace for SpiderLily
75
76Root: $workspaceRoot
77
78Options: noallwrite noclobber nocompress unlocked nomodtime normdir
79
80SubmitOptions: submitunchanged
81
82LineEnd: local
83
84View:
85$($viewMapping -join "`n")
86"@
87
88# Write spec to temp file and create client
89$tempSpec = "$env:TEMP\p4client_$workspaceName.txt"
90$clientSpec | Out-File -FilePath $tempSpec -Encoding ASCII
91
92Get-Content $tempSpec | p4 client -i
93
94if ($LASTEXITCODE -ne 0) {
95 Write-Host ""
96 Write-Host "[ERROR] Failed to create workspace!" -ForegroundColor Red
97 Remove-Item $tempSpec -ErrorAction SilentlyContinue
98 exit 1
99}
100
101Remove-Item $tempSpec -ErrorAction SilentlyContinue
102
103Write-Host ""
104Write-Host "[OK] Workspace created successfully!" -ForegroundColor Green
105Write-Host ""
106Write-Host "Workspace name: $workspaceName" -ForegroundColor Cyan
107Write-Host "Root directory: $workspaceRoot" -ForegroundColor Cyan
108Write-Host ""
109Write-Host "Next step: Run sync-project.ps1 to sync the files" -ForegroundColor Yellow
110Write-Host " (Update it to use P4CLIENT = '$workspaceName')" -ForegroundColor Gray
111Write-Host ""
112
113# Update the environment for this session
114$env:P4CLIENT = $workspaceName
115Write-Host "Environment updated for this session." -ForegroundColor Green
116Write-Host ""