@@ -81,6 +81,53 @@ def scan_for_bad_import(file_path, all_pat, good_pats):
8181 print("%s: bad import version in multiple lines" % file_path)
8282 return bool(errors)
8383
84+# Flickable matches
85+flickable_pat = re.compile(r'.*\s*Flickable\s*{')
86+listview_pat = re.compile(r'.*\s*ListView\s*{')
87+gridview_pat = re.compile(r'.*\s*GridView\s*{')
88+flickable_pats = [flickable_pat, listview_pat, gridview_pat]
89+unity_components_pat = re.compile(r'.*import ".*Components"')
90+components_import_pat = re.compile(r'.*import "."')
91+components_path = re.compile(r'.*qml/Components.*')
92+skip_components_flickable_path = re.compile(r'.*qml/Components/Flickable.qml')
93+skip_components_listview_path = re.compile(r'.*qml/Components/ListView.qml')
94+skip_components_gridview_path = re.compile(r'.*qml/Components/GridView.qml')
95+skip_mocks_path = re.compile(r'.*tests/mocks.*')
96+
97+def scan_for_flickable_imports(file_path, component_pats, qtquick_pat, unitycomponents_pat):
98+ errors = []
99+ with open(file_path, 'rt', encoding='utf-8') as ifile, open(file_path, 'rt', encoding='utf-8') as i2file:
100+ flickable_found = False
101+ for lino, line in enumerate(ifile, start=1):
102+ for component_pat in component_pats:
103+ if component_pat.match(line):
104+ flickable_found = True
105+ if flickable_found:
106+ qtquick_found = False
107+ unitycomponents_found = False
108+ for lino, line in enumerate(i2file, start=1):
109+ if not qtquick_found and qtquick_pat.match(line):
110+ qtquick_found = True
111+ if unitycomponents_pat.match(line):
112+ unitycomponents_found = True
113+ if not qtquick_found:
114+ errors.append(lino)
115+ else:
116+ return
117+ if not unitycomponents_found:
118+ errors.append(lino)
119+ if 0 < len(errors) <= 10:
120+ if len(errors) > 1:
121+ plural = 's'
122+ else:
123+ plural = ''
124+ print(
125+ "%s: missing/wrong order of Components import in line%s %s" % (
126+ file_path, plural, ", ".join((str(i) for i in errors))))
127+ elif errors:
128+ print("%s: missing/wrong order of Components imports in multiple lines" % file_path)
129+ return bool(errors)
130+
84131# Parse args
85132
86133parser = argparse.ArgumentParser(
@@ -116,6 +163,17 @@ try:
116163 found_bad_import = True
117164 if scan_for_bad_import(path, ubuntu_components_pat, [ubuntu_good_components_pat]):
118165 found_bad_import = True
166+ if skip_mocks_path.match(path) or \
167+ skip_components_flickable_path.match(path) or \
168+ skip_components_listview_path.match(path) or \
169+ skip_components_gridview_path.match(path):
170+ break
171+ if not components_path.match(path):
172+ if scan_for_flickable_imports(path, flickable_pats, quick_good_pat, unity_components_pat):
173+ found_bad_import = True
174+ else:
175+ if scan_for_flickable_imports(path, flickable_pats, quick_good_pat, components_import_pat):
176+ found_bad_import = True
119177
120178except OSError as e:
121179 error("cannot create file list for \"" + dir + "\": " + e.strerror)