1#!/usr/bin/env python
2# Copyright (c) 2012 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6import parse_deps
7import os
8
9srcdir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../src"))
10
11def generate_deps_js():
12  all_filenames = []
13
14  for dirpath, dirnames, filenames in os.walk(srcdir):
15    for f in filenames:
16      all_filenames.append(os.path.join(dirpath, f))
17
18  filenames = [x for x in all_filenames if
19               os.path.splitext(x)[1] == ".js"]
20  filenames = [os.path.relpath(x) for x in filenames]
21
22  def ignored(x):
23    if os.path.basename(x).startswith('.'):
24      return True
25    return False
26  filenames = [x for x in filenames if not ignored(x)]
27
28  load_sequence = parse_deps.calc_load_sequence(filenames, srcdir)
29
30  chunks = []
31  for module in load_sequence:
32    for dependent_module_name in module.dependent_module_names:
33      chunks.append("base.addModuleDependency('%s','%s');\n" % (
34          module.name, dependent_module_name));
35
36    for dependent_raw_script_name in module.dependent_raw_script_names:
37      chunks.append(
38          "base.addModuleRawScriptDependency('%s','%s');\n" % (
39          module.name, dependent_raw_script_name));
40
41    for style_sheet in module.style_sheets:
42      chunks.append("base.addModuleStylesheet('%s','%s');\n" % (
43          module.name, style_sheet.name));
44  return "".join(chunks)
45
46