| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import posixpath | 6 import posixpath |
| 7 import sys | 7 import sys |
| 8 import os.path | 8 import os.path |
| 9 | 9 |
| 10 output_filename = 'samples_gen.gyp' | 10 output_filename = 'samples_gen.gyp' |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 | 74 |
| 75 { | 75 { |
| 76 'variables': { | 76 'variables': { |
| 77 'chromium_code': 1, | 77 'chromium_code': 1, |
| 78 }, | 78 }, |
| 79 'includes': [ | 79 'includes': [ |
| 80 '../build/common.gypi', | 80 '../build/common.gypi', |
| 81 ], | 81 ], |
| 82 'targets': [ | 82 'targets': [ |
| 83 { | 83 { |
| 84 'target_name': 'build_samples', | 84 'target_name': 'convert_samples', |
| 85 'type': 'none', | 85 'type': 'none', |
| 86 'dependencies': [ | 86 'dependencies': [ |
| 87 '../converter/converter.gyp:o3dConverter', | 87 '../converter/converter.gyp:o3dConverter', |
| 88 ], | 88 ], |
| 89 'actions': [\n""") | 89 'actions': [\n""") |
| 90 | 90 |
| 91 def write_action(asset, webgl_mode): | 91 def write_action(asset, webgl_mode): |
| 92 filename = posixpath.splitext(posixpath.basename(asset['path']))[0] | 92 filename = posixpath.splitext(posixpath.basename(asset['path']))[0] |
| 93 filename = filename.replace('.','_') | 93 filename = filename.replace('.','_') |
| 94 filename = filename.replace('-','_') | 94 filename = filename.replace('-','_') |
| 95 filename = filename.lower() | 95 filename = filename.lower() |
| 96 name = "convert_" + filename | 96 name = "convert_" + filename |
| 97 if webgl_mode: | 97 if webgl_mode: |
| 98 name = name + "_webgl" | 98 name = name + "_webgl" |
| 99 output = asset['path'].replace('convert_', '') | 99 output = asset['path'].replace('convert_', '') |
| 100 output_base = posixpath.splitext(output)[0] | 100 output_base = posixpath.splitext(output)[0] |
| 101 output_tgz = output_base + ".o3dtgz" | 101 output_tgz = output_base + ".o3dtgz" |
| 102 output_json = output_base + "/scene.json" | 102 output_json = output_base + "/scene.json" |
| 103 output = output_tgz | 103 output = output_tgz |
| 104 if webgl_mode: | 104 if webgl_mode: |
| 105 output = output_json | 105 output = output_json |
| 106 output_dir = posixpath.dirname(output) | 106 output_dir = posixpath.dirname(output) |
| 107 output_file.write(" {\n") | 107 output_file.write(" {\n") |
| 108 output_file.write(" 'action_name': '%s',\n" % name) | 108 output_file.write(" 'action_name': '%s',\n" % name) |
| 109 output_file.write(" 'inputs': [\n") | 109 output_file.write(" 'inputs': [\n") |
| 110 output_file.write(" '<(PRODUCT_DIR)/o3dConverter',\n") | 110 output_file.write(" '<(PRODUCT_DIR)/o3dConverter',\n") |
| 111 output_file.write(" '../o3d_assets/samples/%s',\n" % asset['path']) | 111 # TODO(kbr): there are a couple of problems with gyp's MSVC |
| 112 # generator which require this workaround right now. First, if two |
| 113 # actions have the same inputs then gyp will arbitrarily hang the |
| 114 # custom build rule off the second input, and the collision will |
| 115 # currently cause one or the other rule to be dropped. Second, if we |
| 116 # just insert a fake second input, without removing the .zip, then |
| 117 # for some reason the .zip ends up in an "_excluded_files" folder in |
| 118 # the project and the non-WebGL version of the asset won't be built. |
| 119 # Here we use a different input for the WebGL version of the assets. |
| 120 if webgl_mode: |
| 121 output_file.write(" '../o3d_assets/samples/%s.fake_webgl_input.tx
t',\n" % asset['path']) |
| 122 else: |
| 123 output_file.write(" '../o3d_assets/samples/%s',\n" % asset['path'
]) |
| 112 output_file.write(" ],\n") | 124 output_file.write(" ],\n") |
| 113 output_file.write(" 'outputs': [\n") | 125 output_file.write(" 'outputs': [\n") |
| 114 if sys.platform[:5] == 'linux': | 126 if sys.platform[:5] == 'linux': |
| 115 # TODO(gspencer): This is a HACK! We shouldn't need to put the | 127 # TODO(gspencer): This is a HACK! We shouldn't need to put the |
| 116 # absolute path here, but currently on Linux (scons), it is unable | 128 # absolute path here, but currently on Linux (scons), it is unable |
| 117 # to copy generated items out of the source tree (because the | 129 # to copy generated items out of the source tree (because the |
| 118 # repository mojo fails to find it and puts in the wrong path). | 130 # repository mojo fails to find it and puts in the wrong path). |
| 119 output_file.write(" '%s',\n" % posixpath.abspath(output)) | 131 output_file.write(" '%s',\n" % posixpath.abspath(output)) |
| 120 else: | 132 else: |
| 121 output_file.write(" '../samples/%s',\n" % output) | 133 output_file.write(" '../samples/%s',\n" % output) |
| 122 output_file.write(" ],\n") | 134 output_file.write(" ],\n") |
| 123 output_file.write(" 'action': [\n") | 135 output_file.write(" 'action': [\n") |
| 124 output_file.write(" '<(PRODUCT_DIR)/o3dConverter',\n") | 136 output_file.write(" '<(PRODUCT_DIR)/o3dConverter',\n") |
| 125 output_file.write(" '--no-condition',\n") | 137 output_file.write(" '--no-condition',\n") |
| 126 output_file.write(" '--up-axis=%s',\n" % asset['up']) | 138 output_file.write(" '--up-axis=%s',\n" % asset['up']) |
| 127 if webgl_mode: | 139 if webgl_mode: |
| 128 output_file.write(" '--no-binary',\n") | 140 output_file.write(" '--no-binary',\n") |
| 129 output_file.write(" '--no-archive',\n") | 141 output_file.write(" '--no-archive',\n") |
| 130 output_file.write(" '--convert-dds-to-png',\n") | 142 output_file.write(" '--convert-dds-to-png',\n") |
| 131 output_file.write(" '--convert-cg-to-glsl',\n") | 143 output_file.write(" '--convert-cg-to-glsl',\n") |
| 132 output_file.write(" '../o3d_assets/samples/%s',\n" % asset['path']) | 144 output_file.write(" '../o3d_assets/samples/%s',\n" % asset['path']) |
| 133 if webgl_mode: | 145 if webgl_mode: |
| 134 output_file.write(" '../samples/%s',\n" % output_tgz) | 146 output_file.write(" '../samples/%s',\n" % output_tgz) |
| 135 else: | 147 else: |
| 136 output_file.write(" '<(_outputs)',\n") | 148 output_file.write(" '<(_outputs)',\n") |
| 137 output_file.write(" ],\n") | 149 output_file.write(" ],\n") |
| 138 output_file.write(" },\n") | 150 output_file.write(" },\n") |
| 139 | 151 |
| 140 for asset in assets: | 152 for asset in assets: |
| 141 write_action(asset, False); | 153 write_action(asset, False) |
| 142 if asset.has_key('webgl'): | 154 if asset.has_key('webgl'): |
| 143 write_action(asset, True); | 155 write_action(asset, True) |
| 144 | 156 |
| 145 output_file.write(" ],\n") | 157 output_file.write(""" ], |
| 158 }, |
| 159 { |
| 160 'target_name': 'copy_samples', |
| 161 'type': 'none', |
| 162 'dependencies': [ |
| 163 'convert_samples', |
| 164 ], |
| 165 'copies': [\n""") |
| 146 | 166 |
| 147 # Coalesce copies by directory so we don't have tons of copies rules | 167 # Coalesce copies by directory so we don't have tons of copies rules |
| 148 # to parse. | 168 # to parse. |
| 149 copies = {} | 169 copies = {} |
| 150 for asset in assets: | 170 for asset in assets: |
| 151 output = asset['path'].replace('convert_', '') | 171 output = asset['path'].replace('convert_', '') |
| 152 output = posixpath.splitext(output)[0] + ".o3dtgz" | 172 output = posixpath.splitext(output)[0] + ".o3dtgz" |
| 153 output_dir = posixpath.dirname(output) | 173 output_dir = posixpath.dirname(output) |
| 154 if output_dir in copies: | 174 if output_dir in copies: |
| 155 # Make sure we don't add any twice. | 175 # Make sure we don't add any twice. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 167 js_files = ["o3djs/" + f for f in js_files] | 187 js_files = ["o3djs/" + f for f in js_files] |
| 168 items = items + js_files | 188 items = items + js_files |
| 169 for item in items: | 189 for item in items: |
| 170 item_dir = posixpath.dirname(item) | 190 item_dir = posixpath.dirname(item) |
| 171 if item_dir in copies: | 191 if item_dir in copies: |
| 172 if not item in copies[item_dir]: | 192 if not item in copies[item_dir]: |
| 173 copies[item_dir] += [item] | 193 copies[item_dir] += [item] |
| 174 else: | 194 else: |
| 175 copies[item_dir] = [item] | 195 copies[item_dir] = [item] |
| 176 | 196 |
| 177 output_file.write(" 'copies': [\n") | |
| 178 for (dir, paths) in copies.items(): | 197 for (dir, paths) in copies.items(): |
| 179 output_file.write(" {\n") | 198 output_file.write(" {\n") |
| 180 output_file.write(" 'destination': " \ | 199 output_file.write(" 'destination': " \ |
| 181 "'<(PRODUCT_DIR)/samples/%s',\n" % dir) | 200 "'<(PRODUCT_DIR)/samples/%s',\n" % dir) |
| 182 output_file.write(" 'files': [\n") | 201 output_file.write(" 'files': [\n") |
| 183 for path in paths: | 202 for path in paths: |
| 184 if sys.platform[:5] == 'linux': | 203 if sys.platform[:5] == 'linux': |
| 185 # TODO(gspencer): This is a HACK! We shouldn't need to put the | 204 # TODO(gspencer): This is a HACK! We shouldn't need to put the |
| 186 # absolute path here, but currently on Linux (scons), it is unable | 205 # absolute path here, but currently on Linux (scons), it is unable |
| 187 # to copy generated items out of the source tree (because the | 206 # to copy generated items out of the source tree (because the |
| 188 # repository mojo fails to find it and puts in the wrong path). | 207 # repository mojo fails to find it and puts in the wrong path). |
| 189 output_file.write(" '%s',\n" % posixpath.abspath(path)) | 208 output_file.write(" '%s',\n" % posixpath.abspath(path)) |
| 190 else: | 209 else: |
| 191 output_file.write(" '../samples/%s',\n" % path) | 210 output_file.write(" '../samples/%s',\n" % path) |
| 192 output_file.write(" ],\n") | 211 output_file.write(" ],\n") |
| 193 output_file.write(" },\n") | 212 output_file.write(" },\n") |
| 194 | 213 |
| 195 output_file.write(" ],\n") | 214 output_file.write(" ],\n") |
| 196 output_file.write(" },\n") | 215 output_file.write(" },\n") |
| 216 output_file.write(""" { |
| 217 'target_name': 'build_samples', |
| 218 'type': 'none', |
| 219 'dependencies': [ |
| 220 'copy_samples', |
| 221 ], |
| 222 },\n""") |
| 197 output_file.write(" ],\n") | 223 output_file.write(" ],\n") |
| 198 output_file.write("}\n") | 224 output_file.write("}\n") |
| 199 | 225 |
| 200 print output_filename | 226 print output_filename |
| 201 sys.exit(0) | 227 sys.exit(0) |
| OLD | NEW |