()
| 59 | |
| 60 | |
| 61 | def main(): |
| 62 | if len(sys.argv) < 4: |
| 63 | print( |
| 64 | "Usage: closure_make_deps.py <files_list> <output> <closure_path>", |
| 65 | file=sys.stderr, |
| 66 | ) |
| 67 | sys.exit(1) |
| 68 | |
| 69 | files_list_path = sys.argv[1] |
| 70 | output_path = sys.argv[2] |
| 71 | closure_path = sys.argv[3] |
| 72 | |
| 73 | with open(files_list_path, encoding="utf-8") as f: |
| 74 | files = [line.strip() for line in f if line.strip()] |
| 75 | |
| 76 | lines = [] |
| 77 | for filepath in files: |
| 78 | provides, requires, is_module = parse_js_file(filepath) |
| 79 | |
| 80 | rel_path = os.path.relpath(filepath, closure_path) |
| 81 | # deps.js is consumed in the browser, so always use forward slashes |
| 82 | rel_path = rel_path.replace(os.sep, "/") |
| 83 | |
| 84 | provides_str = ", ".join(f"'{p}'" for p in provides) |
| 85 | requires_str = ", ".join(f"'{r}'" for r in requires) |
| 86 | |
| 87 | if is_module: |
| 88 | line = f"goog.addDependency('{rel_path}', [{provides_str}], [{requires_str}], {{'module': 'goog'}});" |
| 89 | else: |
| 90 | line = f"goog.addDependency('{rel_path}', [{provides_str}], [{requires_str}]);" |
| 91 | |
| 92 | lines.append((rel_path, line)) |
| 93 | |
| 94 | # Sort by relative path for deterministic output |
| 95 | lines.sort(key=lambda x: x[0]) |
| 96 | |
| 97 | with open(output_path, "w", encoding="utf-8") as f: |
| 98 | for _, line in lines: |
| 99 | f.write(line + "\n") |
| 100 | |
| 101 | |
| 102 | if __name__ == "__main__": |
no test coverage detected