Skip to content

Commit b90d41d

Browse files
author
epriestley
committedApr 8, 2012
Add an "--ignore-duplicates" flag to import_project_symbols.php
Summary: People are hella lazy and don't want to do this themselves. Test Plan: Generated a symbol file with duplicates and piped it in, got an import under --ignore-duplicates. Reviewers: kdeggelman, btrahan, vrana, jungejason Reviewed By: jungejason CC: aran Differential Revision: https://secure.phabricator.com/D2145
1 parent dd21f7e commit b90d41d

File tree

1 file changed

+43
-18
lines changed

1 file changed

+43
-18
lines changed
 

‎scripts/symbols/import_project_symbols.php

+43-18
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<?php
33

44
/*
5-
* Copyright 2011 Facebook, Inc.
5+
* Copyright 2012 Facebook, Inc.
66
*
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
@@ -20,15 +20,35 @@
2020
$root = dirname(dirname(dirname(__FILE__)));
2121
require_once $root.'/scripts/__init_script__.php';
2222

23-
phutil_require_module('phutil', 'console');
23+
$args = new PhutilArgumentParser($argv);
24+
$args->setSynopsis(<<<EOSYNOPSIS
25+
**import_project_symbols.php** [__options__] __project_name__ < symbols
2426
25-
if ($argc !== 2) {
26-
echo phutil_console_format(
27-
"usage: import_project_symbols.php __project_name__ < __symbol_file__\n");
28-
exit(1);
27+
Import project symbols (symbols are read from stdin).
28+
EOSYNOPSIS
29+
);
30+
$args->parseStandardArguments();
31+
$args->parse(
32+
array(
33+
array(
34+
'name' => 'ignore-duplicates',
35+
'help' => 'Ignore duplicate symbols, choosing one at random. By '.
36+
'default, this script throws if given duplicate '.
37+
'symbols.',
38+
),
39+
array(
40+
'name' => 'more',
41+
'wildcard' => true,
42+
),
43+
));
44+
45+
$ignore_duplicates = $args->getArg('ignore-duplicates');
46+
$more = $args->getArg('more');
47+
if (count($more) !== 1) {
48+
$args->printHelpAndExit();
2949
}
3050

31-
$project_name = $argv[1];
51+
$project_name = head($more);
3252
$project = id(new PhabricatorRepositoryArcanistProject())->loadOneWhere(
3353
'name = %s',
3454
$project_name);
@@ -64,17 +84,22 @@
6484
list($all, $name, $type, $lang, $line_number, $path) = $matches;
6585

6686
if (isset($map[$name][$type][$lang])) {
67-
$previous = $map[$name][$type][$lang] + 1;
68-
throw new Exception(
69-
"Line #{$line_no} of input is invalid. It specifies a duplicate symbol ".
70-
"(same name, language, and type) which has already been defined ".
71-
"elsewhere. You must preprocess the symbol list to remove duplicates ".
72-
"and choose exactly one master definition for each symbol. This symbol ".
73-
"was previously defined on line #{$previous}.\n\n".
74-
"Line #{$line_no}:\n".
75-
$line."\n\n".
76-
"Line #{$previous}:\n".
77-
$input[$previous - 1]);
87+
if ($ignore_duplicates) {
88+
echo "Ignoring duplicate definition of '{$name}' on line {$line_no}.\n";
89+
} else {
90+
$previous = $map[$name][$type][$lang] + 1;
91+
throw new Exception(
92+
"Line #{$line_no} of input is invalid. It specifies a duplicate ".
93+
"symbol (same name, language, and type) which has already been ".
94+
"defined elsewhere. You must preprocess the symbol list to remove ".
95+
"duplicates and choose exactly one master definition for each ".
96+
"symbol, or specify --ignore-duplicates. This symbol was previously ".
97+
"defined on line #{$previous}.\n\n".
98+
"Line #{$line_no}:\n".
99+
$line."\n\n".
100+
"Line #{$previous}:\n".
101+
$input[$previous - 1]);
102+
}
78103
} else {
79104
$map[$name][$type][$lang] = $key;
80105
}

0 commit comments

Comments
 (0)
Failed to load comments.