OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/python2.4 |
| 2 # Copyright 2009 Google Inc. |
| 3 # |
| 4 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 # you may not use this file except in compliance with the License. |
| 6 # You may obtain a copy of the License at |
| 7 # |
| 8 # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 # |
| 10 # Unless required by applicable law or agreed to in writing, software |
| 11 # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 # See the License for the specific language governing permissions and |
| 14 # limitations under the License. |
| 15 |
| 16 # This file is just here so that we can modify the python path before |
| 17 # invoking nixysa. |
| 18 |
| 19 import os |
| 20 import os.path |
| 21 import shutil |
| 22 import subprocess |
| 23 import sys |
| 24 |
| 25 third_party = os.path.join('..', '..', 'third_party') |
| 26 gflags_dir = os.path.join(third_party, 'gflags', 'python') |
| 27 sys.path.append(gflags_dir) |
| 28 |
| 29 import gflags |
| 30 |
| 31 FLAGS = gflags.FLAGS |
| 32 gflags.DEFINE_string('configuration', 'Debug', |
| 33 'Specify which configuration to build.') |
| 34 |
| 35 gflags.DEFINE_string('platform', 'win', |
| 36 'Specify which platform to build.') |
| 37 |
| 38 gflags.DEFINE_boolean('debug', False, |
| 39 'Whether or not to turn on debug output ' |
| 40 'when running scons.') |
| 41 |
| 42 gflags.DEFINE_string('output', '.', 'Sets the output directory.') |
| 43 |
| 44 |
| 45 def CopyIfNewer(inputs, output_dir): |
| 46 '''Copy the inputs to the output directory, but only if the files are |
| 47 newer than the destination files.''' |
| 48 for input in inputs: |
| 49 output = os.path.join(output_dir, os.path.basename(input)) |
| 50 if os.path.exists(input): |
| 51 if (not os.path.exists(output) or |
| 52 os.path.getmtime(input) > os.path.getmtime(output)): |
| 53 try: |
| 54 print 'Copying from %s to %s' % (input, output) |
| 55 shutil.copy2(input, output) |
| 56 except: |
| 57 return False |
| 58 else: |
| 59 print '%s is up to date.' % output |
| 60 return True |
| 61 |
| 62 def PrependToPath(path, item): |
| 63 '''Prepend an item to an environment variable path.''' |
| 64 orig_path = os.environ.get(path) |
| 65 if orig_path: |
| 66 new_path = os.pathsep.join([item, orig_path]) |
| 67 else: |
| 68 new_path = item |
| 69 |
| 70 os.environ[path] = new_path |
| 71 |
| 72 def AppendToPath(path, item): |
| 73 '''Append an item to an environment variable path.''' |
| 74 orig_path = os.environ.get(path) |
| 75 if orig_path: |
| 76 new_path = os.pathsep.join([orig_path, item]) |
| 77 else: |
| 78 new_path = item |
| 79 |
| 80 os.environ[path] = new_path |
| 81 |
| 82 def FindPlatformSDK(): |
| 83 '''On Windows, find the installed location of the Platform SDK.''' |
| 84 import _winreg |
| 85 try: |
| 86 winsdk_key = _winreg.OpenKey( |
| 87 _winreg.HKEY_LOCAL_MACHINE, |
| 88 'SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v6.1\\WinSDKBuild') |
| 89 except WindowsError: |
| 90 try: |
| 91 winsdk_key = _winreg.OpenKey( |
| 92 _winreg.HKEY_LOCAL_MACHINE, |
| 93 'SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v6.0A\\WinSDKBuild') |
| 94 except WindowsError: |
| 95 print 'The Windows SDK version 6.0 or later needs to be installed' |
| 96 sys.exit(1) |
| 97 try: |
| 98 winsdk_dir, value_type = _winreg.QueryValueEx(winsdk_key, |
| 99 'InstallationFolder') |
| 100 except WindowsError: |
| 101 print 'The Windows SDK version 6.0 or later needs to be installed' |
| 102 sys.exit(1) |
| 103 _winreg.CloseKey(winsdk_key) |
| 104 |
| 105 # Strip off trailing slashes |
| 106 winsdk_dir = winsdk_dir.rstrip('\\/') |
| 107 AppendToPath('PATH', os.path.join(winsdk_dir, 'Bin')) |
| 108 AppendToPath('INCLUDE', os.path.join(winsdk_dir, 'Include')) |
| 109 AppendToPath('LIB', os.path.join(winsdk_dir, 'Lib')) |
| 110 |
| 111 def main(args): |
| 112 extra_args = FLAGS(args) |
| 113 # strip off argv[0] |
| 114 extra_args = extra_args[1:] |
| 115 |
| 116 pythonpath = os.path.join(third_party, 'scons', 'scons-local') |
| 117 PrependToPath('PYTHONPATH', pythonpath) |
| 118 |
| 119 binutils_path = os.path.join(third_party, 'gnu_binutils', 'files') |
| 120 AppendToPath('PATH', binutils_path) |
| 121 |
| 122 config = 'opt' |
| 123 if FLAGS.configuration == 'Debug': |
| 124 config = 'dbg' |
| 125 elif FLAGS.configuration == 'Release': |
| 126 config = 'opt' |
| 127 |
| 128 mode = '%s-%s' % (config, FLAGS.platform) |
| 129 |
| 130 native_client_dir = os.path.join(third_party, 'native_client', |
| 131 'googleclient', 'native_client') |
| 132 |
| 133 args = [ |
| 134 'MODE=%s' % mode, |
| 135 'naclsdk_validate=0', |
| 136 'sdl=none', |
| 137 '--verbose', |
| 138 '--file=SConstruct', |
| 139 '-C', |
| 140 native_client_dir, |
| 141 ] |
| 142 scons = os.path.join(third_party, 'scons', 'scons.py') |
| 143 args = [sys.executable, scons] + args + extra_args |
| 144 |
| 145 # Add the platform SDK to INCLUDE and LIB |
| 146 if FLAGS.platform == 'win': |
| 147 FindPlatformSDK() |
| 148 |
| 149 print 'Executing %s' % ' '.join(args) |
| 150 status = subprocess.call(args) |
| 151 |
| 152 # Calculate what the output files should be. |
| 153 outputs = [] |
| 154 for arg in extra_args: |
| 155 file_path = os.path.join(native_client_dir, |
| 156 'scons-out', mode, 'lib', arg) |
| 157 if FLAGS.platform == 'win': |
| 158 file_path = file_path + '.lib' |
| 159 else: |
| 160 file_path = file_path + '.a' |
| 161 outputs.append(file_path) |
| 162 |
| 163 if status == 0 and not CopyIfNewer(outputs, FLAGS.output): |
| 164 sys.exit(-1) |
| 165 else: |
| 166 sys.exit(status) |
| 167 |
| 168 if __name__ == '__main__': |
| 169 main(sys.argv) |
OLD | NEW |