Commit 3bd7a1ef authored by Jérémie Boulic's avatar Jérémie Boulic Committed by Chromium LUCI CQ

[Files app] Fix duplicate dependencies and improve class exports

Update modules generation script:
- Fix detection of duplicate dependencies
- Update class export condition: export class if the class is used in
another JS file
- Fix clang-format off/on

Bug: 1133186
Change-Id: Icb5b38f8d57ca69912397b489b8e49dd23e1b8b2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2575303Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Commit-Queue: Jeremie Boulic <jboulic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#834627}
parent 5acfc24e
...@@ -175,7 +175,7 @@ def add_import_line(file_lines, variable, relative_path, is_unittest): ...@@ -175,7 +175,7 @@ def add_import_line(file_lines, variable, relative_path, is_unittest):
index = last_import_line_index index = last_import_line_index
else: else:
file_lines.insert(index + 1, '') file_lines.insert(index + 1, '')
file_lines.insert(index + 1, '// clang-format off') file_lines.insert(index + 1, '// clang-format on')
elif 'import ' not in file_lines[index + 1]: elif 'import ' not in file_lines[index + 1]:
file_lines.insert(index, '') file_lines.insert(index, '')
...@@ -241,10 +241,6 @@ def add_dependency(file_lines, section_first_line, list_name, dependency_line): ...@@ -241,10 +241,6 @@ def add_dependency(file_lines, section_first_line, list_name, dependency_line):
print 'Unable to find ' + section_first_line print 'Unable to find ' + section_first_line
return False return False
# Return False if dependency already found.
if dependency_line in file_lines:
return False
# Find index of `list_name`. Get index of 'sources = [' in case `list_name` # Find index of `list_name`. Get index of 'sources = [' in case `list_name`
# is not defined. # is not defined.
rule_index = file_lines.index(section_first_line) rule_index = file_lines.index(section_first_line)
...@@ -263,8 +259,11 @@ def add_dependency(file_lines, section_first_line, list_name, dependency_line): ...@@ -263,8 +259,11 @@ def add_dependency(file_lines, section_first_line, list_name, dependency_line):
if file_lines[i].endswith(']'): if file_lines[i].endswith(']'):
single_line_dependency_list = True single_line_dependency_list = True
# Jump to the end of the dependency list. # Go to the end of the dependency list.
while not ']' in file_lines[i]: while not ']' in file_lines[i]:
if dependency_line == file_lines[i]:
# Dependency already found.
return False
i += 1 i += 1
insertion_index = i insertion_index = i
break break
...@@ -650,13 +649,16 @@ def convert_js_file(js_file_path): ...@@ -650,13 +649,16 @@ def convert_js_file(js_file_path):
if line.startswith('class '): if line.startswith('class '):
# Extract class name. # Extract class name.
class_name = line.split(' ')[1] class_name = line.split(' ')[1]
# Make sure this class is not used locally. # Export class if this class is used or referred to in another js
if get_index_substr(file_lines, 'new ' + class_name) >= 0: # file.
# Export only if the class name is the name of the file. out, _ = subprocess.Popen([
snake_case_name = ''.join([ 'egrep', '-R', '\W{}\W'.format(class_name), '-l',
'_' + c.lower() if c.isupper() else c for c in class_name './ui/file_manager/'
]).lstrip('_') ],
if not snake_case_name + '.js' == js_file_path.split('/')[-1]: stdout=subprocess.PIPE).communicate()
path = out.rstrip()
if not '\n' in path:
print 'Not exporting ' + class_name + ': local class'
continue continue
file_lines[i] = '/* #export */ ' + line file_lines[i] = '/* #export */ ' + line
# Export variable in global namespace. # Export variable in global namespace.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment