2016-05-30 15:10:57 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
2016-09-13 11:09:44 +08:00
|
|
|
import re, os, platform, sys, getopt, shutil
|
2016-05-30 15:10:57 +02:00
|
|
|
|
|
|
|
def usage():
|
2016-09-07 12:42:44 +08:00
|
|
|
print "Usage: build.py [options]"
|
|
|
|
|
|
|
|
def grep_dep(reg, repo, dir):
|
|
|
|
pat = re.compile(reg)
|
|
|
|
found = re.search(pat, deps_str)
|
|
|
|
if found is None:
|
|
|
|
return None
|
|
|
|
head = found.group(1)
|
|
|
|
return '''
|
|
|
|
'%s':
|
|
|
|
(Var(\"chromium_git\")) + '%s@%s',
|
|
|
|
''' % (dir, repo, head)
|
2016-05-30 15:10:57 +02:00
|
|
|
|
|
|
|
try:
|
2016-09-07 12:42:44 +08:00
|
|
|
opts, args = getopt.getopt(sys.argv[1:], "hc", ["clean", "help", "target_arch=", "nw_version="])
|
2016-05-30 15:10:57 +02:00
|
|
|
except getopt.GetoptError:
|
2016-09-07 12:42:44 +08:00
|
|
|
usage()
|
|
|
|
sys.exit(2)
|
2016-05-30 15:10:57 +02:00
|
|
|
|
|
|
|
if re.match(r'i.86', platform.machine()):
|
2016-09-07 12:42:44 +08:00
|
|
|
host_arch = 'ia32'
|
2016-05-30 15:10:57 +02:00
|
|
|
elif platform.machine() == 'x86_64' or platform.machine() == 'AMD64':
|
2016-09-07 12:42:44 +08:00
|
|
|
host_arch = 'x64'
|
2016-05-30 15:10:57 +02:00
|
|
|
elif platform.machine() == 'aarch64':
|
2016-09-07 12:42:44 +08:00
|
|
|
host_arch = 'arm64'
|
2016-05-30 15:10:57 +02:00
|
|
|
elif platform.machine().startswith('arm'):
|
2016-09-07 12:42:44 +08:00
|
|
|
host_arch = 'arm'
|
2016-05-30 15:10:57 +02:00
|
|
|
else:
|
2016-09-07 12:42:44 +08:00
|
|
|
sys.exit(1)
|
2016-05-30 15:10:57 +02:00
|
|
|
|
2016-09-07 12:42:44 +08:00
|
|
|
nw_version='0.17.0'
|
2016-05-30 15:10:57 +02:00
|
|
|
target_arch=host_arch
|
|
|
|
|
|
|
|
for opt, arg in opts:
|
2016-09-07 12:42:44 +08:00
|
|
|
if opt in ("-h", "--help"):
|
|
|
|
usage()
|
|
|
|
sys.exit(0)
|
|
|
|
elif opt in ("--target_arch"):
|
|
|
|
target_arch = arg
|
|
|
|
elif opt in ("--nw_version"):
|
|
|
|
nw_version = arg
|
|
|
|
elif opt in ("-c", "--clean"):
|
|
|
|
shutil.rmtree("build", ignore_errors=True)
|
|
|
|
|
|
|
|
if target_arch == "ia32":
|
|
|
|
target_cpu = "x86"
|
|
|
|
else:
|
|
|
|
target_cpu = target_arch
|
|
|
|
|
|
|
|
try:
|
|
|
|
os.mkdir("build")
|
|
|
|
except OSError:
|
|
|
|
print "build is already created"
|
|
|
|
|
|
|
|
os.chdir("build")
|
|
|
|
|
|
|
|
shutil.rmtree("src/out", ignore_errors=True)
|
2016-05-30 15:10:57 +02:00
|
|
|
|
|
|
|
chromium_git = 'https://chromium.googlesource.com'
|
|
|
|
#clone depot_tools
|
|
|
|
os.system("git clone --depth=1 https://chromium.googlesource.com/chromium/tools/depot_tools.git")
|
|
|
|
os.environ["PATH"] = os.environ["PATH"] + ":" + os.getcwd() + "/depot_tools"
|
|
|
|
|
2016-09-07 12:42:44 +08:00
|
|
|
#create .gclient file
|
|
|
|
os.system("gclient config --unmanaged --name=src https://github.com/nwjs/chromium.src.git@tags/nw-v" + nw_version)
|
|
|
|
|
2016-05-30 15:10:57 +02:00
|
|
|
#clone chromium.src
|
2016-09-07 12:42:44 +08:00
|
|
|
os.system("git clone --depth=1 -b nw-v" + nw_version + " --single-branch https://github.com/nwjs/chromium.src.git src")
|
|
|
|
|
|
|
|
#overwrite DEPS file
|
|
|
|
os.chdir("src")
|
|
|
|
os.system("git reset --hard tags/nw-v" + nw_version)
|
|
|
|
|
|
|
|
shutil.rmtree("DPES.bak", ignore_errors=True)
|
|
|
|
shutil.rmtree("BUILD.gn.bak", ignore_errors=True)
|
|
|
|
|
|
|
|
with open('DEPS', 'r') as f:
|
|
|
|
deps_str = f.read()
|
|
|
|
|
|
|
|
#vars
|
2016-09-13 11:09:44 +08:00
|
|
|
#copied from DEPS
|
2016-09-07 12:42:44 +08:00
|
|
|
min_vars = '''
|
|
|
|
vars = {
|
|
|
|
'chromium_git':
|
|
|
|
'https://chromium.googlesource.com',
|
|
|
|
}
|
|
|
|
'''
|
|
|
|
|
|
|
|
#deps
|
2016-09-13 11:09:44 +08:00
|
|
|
deps_list = {
|
|
|
|
'buildtools' : {
|
|
|
|
'reg' : ur'buildtools\.git@(.+)\'',
|
|
|
|
'repo': '/chromium/buildtools.git',
|
|
|
|
'path': 'src/buildtools'
|
|
|
|
},
|
|
|
|
'gyp' : {
|
|
|
|
'reg' : ur'gyp\.git@(.+)\'',
|
|
|
|
'repo': '/external/gyp.git',
|
|
|
|
'path': 'src/tools/gyp'
|
|
|
|
},
|
|
|
|
'patched-yasm' : {
|
|
|
|
'reg' : ur'patched-yasm\.git@(.+)\'',
|
|
|
|
'repo': '/chromium/deps/yasm/patched-yasm.git',
|
|
|
|
'path': 'src/third_party/yasm/source/patched-yasm'
|
|
|
|
},
|
|
|
|
'ffmpeg' : {
|
|
|
|
'reg' : ur'ffmpeg\.git@(.+)\'',
|
|
|
|
'repo': '/chromium/third_party/ffmpeg',
|
|
|
|
'path': 'src/third_party/ffmpeg'
|
|
|
|
},
|
|
|
|
}
|
2016-09-07 12:42:44 +08:00
|
|
|
min_deps = []
|
2016-09-13 11:09:44 +08:00
|
|
|
for k, v in deps_list.items():
|
|
|
|
dep = grep_dep(v['reg'], v['repo'], v['path'])
|
|
|
|
if dep is None:
|
|
|
|
raise Exception("`%s` is not found in DEPS" % k)
|
|
|
|
min_deps.append(dep)
|
|
|
|
|
2016-09-07 12:42:44 +08:00
|
|
|
min_deps = '''
|
|
|
|
deps = {
|
|
|
|
%s
|
|
|
|
}
|
|
|
|
''' % "\n".join(min_deps)
|
|
|
|
|
|
|
|
#hooks
|
2016-09-13 11:09:44 +08:00
|
|
|
#copied from DEPS
|
2016-09-07 12:42:44 +08:00
|
|
|
min_hooks = '''
|
|
|
|
hooks = [
|
|
|
|
{
|
|
|
|
'action': [
|
|
|
|
'python',
|
|
|
|
'src/build/linux/sysroot_scripts/install-sysroot.py',
|
|
|
|
'--running-as-hook'
|
|
|
|
],
|
|
|
|
'pattern':
|
|
|
|
'.',
|
|
|
|
'name':
|
|
|
|
'sysroot'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'action': [
|
|
|
|
'python',
|
|
|
|
'src/build/mac_toolchain.py'
|
|
|
|
],
|
|
|
|
'pattern':
|
|
|
|
'.',
|
|
|
|
'name':
|
|
|
|
'mac_toolchain'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'action': [
|
|
|
|
'python',
|
|
|
|
'src/tools/clang/scripts/update.py',
|
|
|
|
'--if-needed'
|
|
|
|
],
|
|
|
|
'pattern':
|
|
|
|
'.',
|
|
|
|
'name':
|
|
|
|
'clang'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'action': [
|
|
|
|
'download_from_google_storage',
|
|
|
|
'--no_resume',
|
|
|
|
'--platform=win32',
|
|
|
|
'--no_auth',
|
|
|
|
'--bucket',
|
|
|
|
'chromium-gn',
|
|
|
|
'-s',
|
|
|
|
'src/buildtools/win/gn.exe.sha1'
|
|
|
|
],
|
|
|
|
'pattern':
|
|
|
|
'.',
|
|
|
|
'name':
|
|
|
|
'gn_win'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'action': [
|
|
|
|
'download_from_google_storage',
|
|
|
|
'--no_resume',
|
|
|
|
'--platform=darwin',
|
|
|
|
'--no_auth',
|
|
|
|
'--bucket',
|
|
|
|
'chromium-gn',
|
|
|
|
'-s',
|
|
|
|
'src/buildtools/mac/gn.sha1'
|
|
|
|
],
|
|
|
|
'pattern':
|
|
|
|
'.',
|
|
|
|
'name':
|
|
|
|
'gn_mac'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'action': [
|
|
|
|
'download_from_google_storage',
|
|
|
|
'--no_resume',
|
|
|
|
'--platform=linux*',
|
|
|
|
'--no_auth',
|
|
|
|
'--bucket',
|
|
|
|
'chromium-gn',
|
|
|
|
'-s',
|
|
|
|
'src/buildtools/linux64/gn.sha1'
|
|
|
|
],
|
|
|
|
'pattern':
|
|
|
|
'.',
|
|
|
|
'name':
|
|
|
|
'gn_linux64'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'action': [
|
|
|
|
'download_from_google_storage',
|
|
|
|
'--no_resume',
|
|
|
|
'--platform=darwin',
|
|
|
|
'--no_auth',
|
|
|
|
'--bucket',
|
|
|
|
'chromium-libcpp',
|
|
|
|
'-s',
|
|
|
|
'src/third_party/libc++-static/libc++.a.sha1'
|
|
|
|
],
|
|
|
|
'pattern':
|
|
|
|
'.',
|
|
|
|
'name':
|
|
|
|
'libcpp_mac'
|
|
|
|
},
|
|
|
|
]
|
|
|
|
'''
|
|
|
|
|
|
|
|
#overwrite DEPS
|
|
|
|
shutil.move('DEPS', 'DEPS.bak')
|
|
|
|
with open('DEPS', 'w') as f:
|
|
|
|
f.write("%s\n%s\n%s" % (min_vars, min_deps, min_hooks))
|
|
|
|
|
|
|
|
#overwrite BUILD.gn
|
|
|
|
BUILD_gn = '''
|
2016-09-13 11:09:44 +08:00
|
|
|
group("dummy") {
|
2016-09-07 12:42:44 +08:00
|
|
|
deps = [
|
|
|
|
"//third_party/ffmpeg"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
'''
|
|
|
|
shutil.move('BUILD.gn', 'BUILD.gn.bak')
|
|
|
|
with open('BUILD.gn', 'w') as f:
|
|
|
|
f.write(BUILD_gn)
|
2016-05-30 15:10:57 +02:00
|
|
|
|
|
|
|
#install linux dependencies
|
|
|
|
if platform.system() == 'Linux':
|
2016-09-07 12:42:44 +08:00
|
|
|
os.system('./build/install-build-deps.sh --no-prompt --no-nacl --no-chromeos-fonts --no-syms')
|
2016-05-30 15:10:57 +02:00
|
|
|
|
2016-09-07 12:42:44 +08:00
|
|
|
#gclient sync
|
|
|
|
os.system('gclient sync --no-history')
|
2016-05-30 15:10:57 +02:00
|
|
|
|
2016-09-07 12:42:44 +08:00
|
|
|
#generate ninja files
|
2016-09-13 11:09:44 +08:00
|
|
|
os.system('gn gen //out/nw "--args=is_debug=false is_component_ffmpeg=true target_cpu=\\\"%s\\\" is_official_build=true ffmpeg_branding=\\\"Chrome\\\""' % target_cpu)
|
2016-05-30 15:10:57 +02:00
|
|
|
|
|
|
|
#build ffmpeg
|
2016-09-07 12:42:44 +08:00
|
|
|
os.system("ninja -C out/nw ffmpeg")
|