Skip to content

Commit 57f4eba

Browse files
jcortell68John Cortell
andauthored
Make pre-build.py re-runnable on Windows (#66)
* Make pre-build.py re-runnable on Windows pre-build.py couldn't be run twice. On the second run, the git pull failed with Directory /git/gpu_performance_api/external/Lib/AMD/ADL exists. Using 'git pull' to get latest You are not currently on a branch. Please specify which branch you want to merge with. See git-pull(1) for details. git pull <remote> <branch> 'git pull' failed with returncode: This happens because the previous run intentionally checks out a specific commit, leaving the workspace in a detached state. The subsequent run tries to do a 'git pull origin' and that can't be done while the workspace is detached. I've changed the 'git pull' to a 'git fetch --tags -f', which is then followed by 'git checkout <requested change>'. That fixes that issue. However, there is a lot of waste in the likely scenario that the workspace is already checked out to the commit the script wants it at. So I've added a check for that and we now no-op the git workspace update in that case. That reduces a many-seconds phase of the script to almost no time. Co-authored-by: John Cortell <j.cortell@sarc.samsung.com>
1 parent 63f2ffc commit 57f4eba

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

scripts/fetch_dependencies.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,24 @@ def UpdateGitHubRepo(repoRootUrl, location, commit):
8989
# Add script directory to targetPath.
9090
targetPath = os.path.join(gpaRoot, location)
9191

92-
reqdCommit = commit
92+
# 'location' has forward slashes even on Windows. Clean up the final path
93+
# for purely aesthetical reasons (script output)
94+
targetPath = os.path.realpath(targetPath)
9395

94-
print("\nChecking out commit: %s for %s\n"%(reqdCommit, targetPath))
96+
reqdCommit = commit
9597

9698
if os.path.isdir(targetPath):
9799
# Directory exists - get latest from git using pull.
98-
print("Directory " + targetPath + " exists. \n\tUsing 'git pull' to get latest")
99-
sys.stdout.flush()
100100
try:
101-
subprocess.check_call(["git", "-C", targetPath, "pull", "origin"], shell=SHELLARG)
101+
if reqdCommit is not None:
102+
currentCommit = subprocess.check_output(["git", "-C", targetPath, "rev-parse", "HEAD"], shell=SHELLARG).decode().strip()
103+
if currentCommit == reqdCommit:
104+
print("Directory " + targetPath + " exists and is at expected commit. Nothing to do.")
105+
sys.stdout.flush()
106+
return
107+
print("Directory " + targetPath + " exists but is not at the required commit. \n\tUsing 'git fetch' and 'git checkout' to move the workspace to " + reqdCommit[0:7])
108+
sys.stdout.flush()
109+
subprocess.check_call(["git", "-C", targetPath, "fetch", "--tags", "-f", "origin"], shell=SHELLARG)
102110
except subprocess.CalledProcessError as e:
103111
print ("'git pull' failed with returncode: %d\n" % e.returncode)
104112
sys.exit(1)

0 commit comments

Comments
 (0)