Skip to content

Commit

Permalink
Fix querying P4PORT from env
Browse files Browse the repository at this point in the history
'env' is controlled by AYON, os.getenv might not
Stream is required
  • Loading branch information
kalisp committed Jul 24, 2024
1 parent 6d2fa50 commit 0fc1dcd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def __main__( deadlinePlugin ):
stream = deadlinePlugin.GetPluginInfoEntry("PerforceStream")
if not stream:
print("Perforce info not collected, skipping!")
return
changelist = int(deadlinePlugin.GetPluginInfoEntryWithDefault("PerforceChangelist", "0"))
gamePath = deadlinePlugin.GetPluginInfoEntry("PerforceGamePath")
projectFile = deadlinePlugin.GetPluginInfoEntry("ProjectFile")
Expand All @@ -26,14 +27,10 @@ def __main__( deadlinePlugin ):
bForceFullSync = deadlinePlugin.GetPluginInfoEntryWithDefault("ForceFullSync", "false").lower() == "true"
bSyncProject = deadlinePlugin.GetPluginInfoEntryWithDefault("SyncProject", "true" ).lower() == "true"
bSyncEntireStream = deadlinePlugin.GetPluginInfoEntryWithDefault("SyncEntireStream", "false").lower() == "true"
bBuildProject = True

print("bSyncProject::: " + str(bSyncProject))
print("bSyncEntireStream: " + str(bSyncEntireStream))

bBuildProject = True

#
# Set up PerforceUtil
# Set up PerforceUtil
#

try:
Expand Down Expand Up @@ -62,7 +59,7 @@ def __main__( deadlinePlugin ):
deadlinePlugin.FailRender(argError.message)
except UnrealSyncUtil.PerforceMultipleWorkspaceError as argError:
deadlinePlugin.LogWarning(argError.message)
deadlinePlugin.FailRender(argError.message)
deadlinePlugin.FailRender(argError.message)

# Set project root
# This resolves gamePath in case it contains "...""
Expand All @@ -74,7 +71,7 @@ def __main__( deadlinePlugin ):
except UnrealSyncUtil.PerforceError as argError:
deadlinePlugin.LogWarning(argError.message)
deadlinePlugin.FailRender(argError.message)

projectRoot = perforceTools.projectRoot.replace('\\','/')
deadlinePlugin.LogInfo( "Storing UnrealProjectRoot (\"%s\") in environment variable..." % projectRoot )
deadlinePlugin.SetProcessEnvironmentVariable( "UnrealProjectRoot", projectRoot )
Expand All @@ -85,7 +82,7 @@ def __main__( deadlinePlugin ):


# Set the option if it's syncing entire stream or just game path
perforceTools.SetSyncEntireStream( bSyncEntireStream )
perforceTools.SetSyncEntireStream( bSyncEntireStream )

#
# Clean workspace
Expand All @@ -97,9 +94,9 @@ def __main__( deadlinePlugin ):
deadlinePlugin.LogInfo("Performing a perforce clean to bring local files in sync with depot.")
perforceTools.CleanWorkspace()
deadlinePlugin.LogInfo("Finished p4 clean.")

deadlinePlugin.LogInfo("Perforce Command Prefix: " + " ".join(perforceTools.GetP4CommandPrefix()))

# Determine the latest changelist to sync to if unspecified.
try:
if changelist == 0:
Expand All @@ -116,7 +113,7 @@ def __main__( deadlinePlugin ):

#
# Sync project
#
#
if bSyncProject:

# Estimate how much work there is to do for a sync operation.
Expand All @@ -127,7 +124,7 @@ def __main__( deadlinePlugin ):
except UnrealSyncUtil.PerforceResponseError as argError:
deadlinePlugin.LogWarning(str(argError))
deadlinePlugin.LogWarning("No sync estimates will be available.")

# If there's no files to sync, let's skip running the sync. It takes a lot of time as it's a double-estimate.
if perforceTools.syncEstimates[0] == 0 and perforceTools.syncEstimates[1] == 0 and perforceTools.syncEstimates[2] == 0:
deadlinePlugin.LogInfo("Skipping sync command as estimated says there's no work to sync!")
Expand All @@ -138,13 +135,13 @@ def __main__( deadlinePlugin ):
deadlinePlugin.LogInfo("Syncing to CL %d" % perforceTools.changelist)
deadlinePlugin.SetProgress(0)
deadlinePlugin.LogInfo("Estimated Files %s (added/updated/deleted)" % ("/".join(map(str, perforceTools.syncEstimates))))

logCallback = lambda tools: deadlinePlugin.SetProgress(perforceTools.GetSyncProgress() * 100)


# Perform the sync. This could take a while.
perforceTools.Sync(logCallback, bForceFullSync)

# The estimates are only estimates, so when the command is complete we'll ensure it looks complete.
deadlinePlugin.SetStatusMessage("Synced Workspace to CL " + str(perforceTools.changelist))
deadlinePlugin.LogInfo("Synced Workspace to CL " + str(perforceTools.changelist))
Expand All @@ -154,10 +151,10 @@ def __main__( deadlinePlugin ):
deadlinePlugin.FailRender("Suspected Out of Disk Error while syncing: \"%s\"" % str(ioError))
else:
deadlinePlugin.LogInfo("Skipping Project Sync due to job settings.")



#

#
# Build project
#
if bBuildProject:
Expand All @@ -181,15 +178,15 @@ def __main__( deadlinePlugin ):
engine_root = unreal_executable.split('/Engine/Binaries/')[0]

uproject_path = perforceTools.uprojectPath

buildtool = UnrealSyncUtil.BuildUtils( engine_root, uproject_path, editorName )

if not buildtool.IsCppProject():
deadlinePlugin.LogInfo("Skip building process -- no need to build for BP project")
else:
deadlinePlugin.LogInfo("Starting a local build")

try:
try:
deadlinePlugin.LogInfo("Generating project files...")
deadlinePlugin.SetStatusMessage("Generating project files")
buildtool.GenerateProjectFiles()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def run(self):
class PerforceUtils(object):
def __init__(self, stream, gamePath, env):
# The hostname of the perforce server. Defaults to the "P4PORT" Environment Var.
self._serverName = self._FindServerHostName()
self._serverName = self._FindServerHostName(env)
if not self._serverName:
raise PerforceError('"P4PORT" has not been set in the Slave environment!')

Expand Down Expand Up @@ -175,10 +175,13 @@ def uprojectPath(self):
def setChangelist(self, value):
self._changelist = value

def _FindServerHostName(self):
def _FindServerHostName(self, env):
# The hostname of the perforce server. Defaults to the "P4PORT" Environment Var.
# If it's not set, try to find it from 'p4 set' command
name = os.getenv("P4PORT")
if env:
name = env.get("P4PORT")
else:
name = os.getenv("P4PORT")
if name:
return name
output = subprocess.check_output(["p4", "set"])
Expand Down

0 comments on commit 0fc1dcd

Please sign in to comment.