epoger@google.com | 1e8e056 | 2011-06-07 14:48:41 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | # |
| 3 | # Copyright (C) 2011 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | # This script is a wrapper which invokes gyp with the correct --depth argument, |
| 18 | # and supports the automatic regeneration of build files if all.gyp is |
| 19 | # changed (Linux-only). |
| 20 | |
| 21 | import glob |
| 22 | import os |
| 23 | import shlex |
| 24 | import sys |
| 25 | |
| 26 | script_dir = os.path.dirname(__file__) |
| 27 | |
| 28 | # Directory within which we can find the gyp source. |
epoger@google.com | 0ae27e0 | 2011-06-14 16:01:04 +0000 | [diff] [blame] | 29 | gyp_source_dir = os.path.join(script_dir, 'third_party', 'externals', 'gyp') |
epoger@google.com | 1e8e056 | 2011-06-07 14:48:41 +0000 | [diff] [blame] | 30 | |
| 31 | # Directory within which we can find most of Skia's gyp configuration files. |
| 32 | gyp_config_dir = os.path.join(script_dir, 'gyp') |
| 33 | |
| 34 | # Directory within which we want all generated files (including Makefiles) |
| 35 | # to be written. |
| 36 | output_dir = os.path.join(os.path.abspath(script_dir), 'out') |
| 37 | |
| 38 | sys.path.append(os.path.join(gyp_source_dir, 'pylib')) |
| 39 | import gyp |
| 40 | |
| 41 | def additional_include_files(args=[]): |
| 42 | # Determine the include files specified on the command line. |
| 43 | # This doesn't cover all the different option formats you can use, |
| 44 | # but it's mainly intended to avoid duplicating flags on the automatic |
| 45 | # makefile regeneration which only uses this format. |
| 46 | specified_includes = set() |
| 47 | for arg in args: |
| 48 | if arg.startswith('-I') and len(arg) > 2: |
| 49 | specified_includes.add(os.path.realpath(arg[2:])) |
| 50 | |
| 51 | result = [] |
| 52 | def AddInclude(path): |
| 53 | if os.path.realpath(path) not in specified_includes: |
| 54 | result.append(path) |
| 55 | |
epoger@google.com | 1e8e056 | 2011-06-07 14:48:41 +0000 | [diff] [blame] | 56 | return result |
| 57 | |
| 58 | if __name__ == '__main__': |
| 59 | args = sys.argv[1:] |
| 60 | |
epoger@google.com | 2d75cc0 | 2011-07-14 17:31:33 +0000 | [diff] [blame] | 61 | # Set CWD to the directory containing this script. |
| 62 | # This allows us to launch it from other directories, in spite of gyp's |
| 63 | # finickyness about the current working directory. |
| 64 | # See http://b.corp.google.com/issue?id=5019517 ('Linux make build |
| 65 | # (from out dir) no longer runs skia_gyp correctly') |
epoger@google.com | 7fd589c | 2011-07-14 18:55:12 +0000 | [diff] [blame] | 66 | os.chdir(os.path.abspath(script_dir)) |
epoger@google.com | 2d75cc0 | 2011-07-14 17:31:33 +0000 | [diff] [blame] | 67 | |
epoger@google.com | 1e8e056 | 2011-06-07 14:48:41 +0000 | [diff] [blame] | 68 | # This could give false positives since it doesn't actually do real option |
| 69 | # parsing. Oh well. |
| 70 | gyp_file_specified = False |
| 71 | for arg in args: |
| 72 | if arg.endswith('.gyp'): |
| 73 | gyp_file_specified = True |
| 74 | break |
| 75 | |
| 76 | # If we didn't get a file, then fall back to assuming 'skia.gyp' from the |
| 77 | # same directory as the script. |
epoger@google.com | 2d75cc0 | 2011-07-14 17:31:33 +0000 | [diff] [blame] | 78 | # The gypfile must be passed as a relative path, not an absolute path, |
| 79 | # or else the gyp code doesn't write into the proper output dir. |
epoger@google.com | 1e8e056 | 2011-06-07 14:48:41 +0000 | [diff] [blame] | 80 | if not gyp_file_specified: |
epoger@google.com | 2d75cc0 | 2011-07-14 17:31:33 +0000 | [diff] [blame] | 81 | args.append('skia.gyp') |
epoger@google.com | 1e8e056 | 2011-06-07 14:48:41 +0000 | [diff] [blame] | 82 | |
| 83 | args.extend(['-I' + i for i in additional_include_files(args)]) |
| 84 | args.extend(['--depth', '.']) |
| 85 | |
| 86 | # Tell gyp to write the Makefiles into output_dir |
| 87 | args.extend(['--generator-output', os.path.abspath(output_dir)]) |
| 88 | |
| 89 | # Tell make to write its output into the same dir |
| 90 | args.extend(['-Goutput_dir=.']) |
| 91 | |
epoger@google.com | 0fb2125 | 2011-07-13 21:30:14 +0000 | [diff] [blame] | 92 | # Special arguments for generating Visual Studio projects: |
| 93 | # - msvs_version forces generation of Visual Studio 2010 project so that we |
| 94 | # can use msbuild.exe |
| 95 | # - msvs_abspath_output is a workaround for |
| 96 | # http://code.google.com/p/gyp/issues/detail?id=201 |
| 97 | args.extend(['-Gmsvs_version=2010']) |
| 98 | args.extend(['-Gmsvs_abspath_output']) |
| 99 | |
epoger@google.com | 1e8e056 | 2011-06-07 14:48:41 +0000 | [diff] [blame] | 100 | print 'Updating projects from gyp files...' |
| 101 | sys.stdout.flush() |
| 102 | |
| 103 | # Off we go... |
| 104 | sys.exit(gyp.main(args)) |