forked from Autodesk/Aurora
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployHdAurora.py
146 lines (129 loc) · 7.28 KB
/
deployHdAurora.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# Copyright 2022 Autodesk, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.'
import os
import shutil
import sys
import pathlib
import glob
import argparse
import pathlib
import subprocess
programDescription = """
Deploy HdAurora to the provided USD folder (will build a new USD install if build argument provided)
"""
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description=programDescription)
parser.add_argument("usd_root", type=str,
help="The USD root to deploy hdAurora into.")
parser.add_argument("-a", "--aurora_root", type=str, dest="aurora_root", action="store", default=".",
help="The root of the Aurora Git repo.")
parser.add_argument("-c", "--config", type=str,dest="config", action="store", default="Release",
help="The Aurora configuration to deploy.")
parser.add_argument("-f", "--build_folder", dest="aurora_cmake_build_folder", action="store", default="Build",
help="The Aurora CMake build folder to deploy from.")
parser.add_argument("-e", "--externals_folder", dest="externals_folder", action="store", default="~/ADSK/AuroraExternals",
help="Externals folder used to build Aurora and USD (if --build specified).")
parser.add_argument("-b", "--build", dest="build", action="store_true", default=0,
help="Build Aurora and USD before deploying.")
args = parser.parse_args()
# Paths can be specified as relate path to the root of Aurora. We convert them to absolute
# path to avoid build issues after changing working directory.
args.aurora_root = os.path.abspath(args.aurora_root)
args.usd_root = os.path.abspath(args.usd_root)
args.aurora_cmake_build_folder = os.path.abspath(args.aurora_cmake_build_folder)
args.externals_folder = os.path.abspath(args.externals_folder)
# Get the USD target folders.
usd_bin_folder = os.path.join(args.usd_root,"bin")
usd_lib_folder = os.path.join(args.usd_root,"lib")
usd_plugin_folder = os.path.join(args.usd_root,"plugin","usd")
usd_hdaurora_resource_folder = os.path.join(usd_plugin_folder,"hdAurora","resources")
usd_mtlx_folder = os.path.join(usd_lib_folder,"MaterialX")
# Get the Aurora source folders.
aurora_build_folder = os.path.join(args.aurora_root, args.aurora_cmake_build_folder)
aurora_build_bin_folder = os.path.join(aurora_build_folder ,"bin",args.config)
aurora_resource_folder = os.path.join(args.aurora_root, "Libraries", "hdAurora", "resources")
aurora_mtlx_folder = os.path.join(aurora_build_bin_folder, "MaterialX")
# If the build arg is set, then build Aurora and USD before deploying.
if(args.build):
externals_path = pathlib.Path(args.externals_folder)
externals_folder = str(externals_path.expanduser())
externals_src = os.path.join(externals_folder, "src")
# USD dir has the format of 'USD-git-tag' where 'git-tag' is the git commit tag (for example '22.08')
# There is only one USD dir so we can just take the first directory that matches the format
usd_dir = [dir for dir in os.listdir(externals_src) if dir.startswith('USD')][0]
usd_repo_root = os.path.join(externals_src, usd_dir)
print("Build flag is set, building Aurora in "+aurora_build_folder+" and building+installing USD from "+usd_repo_root+" into "+args.usd_root+" (With externals from "+externals_folder+")")
print("- Installing externals.")
if(subprocess.run(["python","Scripts/installExternals.py",externals_folder],cwd=args.aurora_root).returncode!=0):
sys.exit("Failed to install externals")
print("- Running Cmake.")
if(subprocess.run(["cmake","-S",args.aurora_root,"-B",aurora_build_folder,"-D","EXTERNALS_DIR="+externals_folder,"-D","CMAKE_BUILD_TYPE="+args.config],cwd=args.aurora_root).returncode!=0):
sys.exit("Failed to run Cmake")
print("- Building Aurora.")
if(subprocess.run(["cmake","--build",aurora_build_folder,"--config",args.config],cwd=args.aurora_root).returncode!=0):
sys.exit("Failed to build Aurora")
print("- Building USD.")
if(subprocess.run(["python","build_scripts/build_usd.py","--python",args.usd_root],cwd=usd_repo_root).returncode!=0):
sys.exit("Failed to build USD")
# Copy a file if it has changed.
def copy_if_changed(src, dst):
if(not os.path.exists(src)):
print("File not found "+src)
return
if (not os.path.exists(dst)) or (os.stat(src).st_mtime != os.stat(dst).st_mtime):
print("Copying "+src+" to "+dst)
shutil.copy2 (src, dst)
# Copy a file from src_folder to dst_folder if it has changed.
def copy_file(src_folder,dst_folder,name):
copy_if_changed(os.path.join(src_folder,name), os.path.join(dst_folder,name))
# Create target folders if they don't exist.
os.makedirs(usd_bin_folder, exist_ok=True)
os.makedirs(usd_lib_folder, exist_ok=True)
os.makedirs(usd_plugin_folder, exist_ok=True)
os.makedirs(usd_hdaurora_resource_folder, exist_ok=True)
# Copy plugin JSON.
copy_file(aurora_resource_folder,usd_hdaurora_resource_folder,"plugInfo.json")
# Copy hdAurora and PDB (if it exists)
copy_file(aurora_build_bin_folder,usd_plugin_folder,"hdAurora.dll")
copy_file(aurora_build_bin_folder,usd_plugin_folder,"hdAurora.pdb")
# Copy aurora and PDB (if it exists)
copy_file(aurora_build_bin_folder,usd_lib_folder,"Aurora.dll")
copy_file(aurora_build_bin_folder,usd_lib_folder,"Aurora.pdb")
# Copy compiler DLLs.
copy_file(aurora_build_bin_folder,usd_lib_folder,"dxcompiler.dll")
copy_file(aurora_build_bin_folder,usd_lib_folder,"dxil.dll")
copy_file(aurora_build_bin_folder,usd_lib_folder,"slang.dll")
copy_file(aurora_build_bin_folder,usd_lib_folder,"msvcp140.dll")
copy_file(aurora_build_bin_folder,usd_lib_folder,"glew32.dll")
# Copy MtlX libraries and library folders.
copy_file(aurora_build_bin_folder,usd_lib_folder,"MaterialXCore.dll")
copy_file(aurora_build_bin_folder,usd_lib_folder,"MaterialXFormat.dll")
copy_file(aurora_build_bin_folder,usd_lib_folder,"MaterialXGenGlsl.dll")
copy_file(aurora_build_bin_folder,usd_lib_folder,"MaterialXGenMdl.dll")
copy_file(aurora_build_bin_folder,usd_lib_folder,"MaterialXGenOsl.dll")
copy_file(aurora_build_bin_folder,usd_lib_folder,"MaterialXGenShader.dll")
copy_file(aurora_build_bin_folder,usd_lib_folder,"MaterialXRender.dll")
copy_file(aurora_build_bin_folder,usd_lib_folder,"MaterialXRenderGlsl.dll")
copy_file(aurora_build_bin_folder,usd_lib_folder,"MaterialXRenderHw.dll")
copy_file(aurora_build_bin_folder,usd_lib_folder,"MaterialXRenderOsl.dll")
if(not os.path.exists(usd_mtlx_folder)):
os.makedirs(aurora_mtlx_folder, exist_ok=True)
mtlx_files = glob.glob(os.path.join(aurora_mtlx_folder, "**"), recursive=True)
for mtlx_file in mtlx_files:
usd_mtlx_file = mtlx_file.replace(aurora_mtlx_folder,usd_mtlx_folder)
if(os.path.isfile(mtlx_file)):
copy_if_changed(mtlx_file,usd_mtlx_file)
else:
os.makedirs(usd_mtlx_file, exist_ok=True)