diff --git a/tools/buildgen/build-cleaner.py b/tools/buildgen/build-cleaner.py
index f9307360c328d5173a59009ff35513565730bfdb..4992beb89707c8c06084e7681db3ada3b548d460 100755
--- a/tools/buildgen/build-cleaner.py
+++ b/tools/buildgen/build-cleaner.py
@@ -33,9 +33,9 @@ def clean_elem(indict):
   for name in ['public_headers', 'headers', 'src']:
     if name not in indict: continue
     inlist = indict[name]
-    protos = set(x for x in inlist if os.path.splitext(x)[1] == '.proto')
+    protos = list(x for x in inlist if os.path.splitext(x)[1] == '.proto')
     others = set(x for x in inlist if x not in protos)
-    indict[name] = sorted(protos) + sorted(others)
+    indict[name] = protos + sorted(others)
   return rebuild_as_ordered_dict(indict, _ELEM_KEYS)
 
 for filename in sys.argv[1:]: