This repository has been archived by the owner on Aug 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
/
build.py
executable file
·88 lines (71 loc) · 2.69 KB
/
build.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
#!/usr/bin/python
# Copyright 2016 Google LLC
#
# 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
#
# https://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.
"""Compiles the library, demo, and tests.
"""
from __future__ import print_function
import argparse
import os
import shutil
import subprocess
import sys
ROOT_DIR = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(ROOT_DIR, 'shaka', 'tools'))
import utils
def CopyDataFiles(dest, link=False):
"""Copies the data files to the given destination."""
def CopyFile(*path, **kwargs):
abs_src = os.path.join(ROOT_DIR, *path)
abs_dest = os.path.join(dest, kwargs.get('name', path[-1]))
if link and hasattr(os, 'symlink'):
try:
os.remove(abs_dest)
except IOError:
pass
os.symlink(abs_src, abs_dest)
else:
shutil.copy(abs_src, abs_dest)
if utils.GetGnArg('is_debug', is_string=False) == 'true':
CopyFile('shaka', 'js', 'shaka-player.compiled.debug.js',
name='shaka-player.compiled.js')
else:
CopyFile('shaka', 'js', 'shaka-player.compiled.js')
def Build(clean=False):
"""Builds the library."""
if clean:
return subprocess.call(['ninja', '-t', 'clean'])
else:
return subprocess.call(['ninja', 'player'])
def main(args):
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--clean', dest='clean', action='store_true',
help='Delete all temporary object files for this config.')
parser.add_argument('--data-dir', dest='data_dir',
help='The directory to copy program data to.')
parser.add_argument('--symlink-data', dest='symlink', action='store_true',
help='Don\'t copy program data, create symlinks instead.')
ns = parser.parse_args(args)
if not os.path.exists('build.ninja') and os.path.exists('args.gn'):
print('Ninja files missing, trying to recover them...', file=sys.stderr)
configure = os.path.join(ROOT_DIR, 'configure')
if subprocess.call([sys.executable or 'python', configure,
'--recover']) != 0:
return 1
if Build(ns.clean) != 0:
return 1
if not ns.clean:
CopyDataFiles(ns.data_dir or '.', ns.symlink)
return 0
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))