gen_config.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import os
  2. abspath = os.path.abspath(__file__)
  3. dname = os.path.dirname(abspath)
  4. os.chdir(dname)
  5. features = []
  6. def feature(name, default, min, max, pow2=None):
  7. vals = set()
  8. val = min
  9. while val <= max:
  10. vals.add(val)
  11. if pow2 == True or (isinstance(pow2, int) and val >= pow2):
  12. val *= 2
  13. else:
  14. val += 1
  15. vals.add(default)
  16. features.append(
  17. {
  18. "name": name,
  19. "default": default,
  20. "vals": sorted(list(vals)),
  21. }
  22. )
  23. feature("iface_max_addr_count", default=2, min=1, max=8)
  24. feature("iface_max_multicast_group_count", default=4, min=1, max=1024, pow2=8)
  25. feature("iface_max_sixlowpan_address_context_count", default=4, min=1, max=1024, pow2=8)
  26. feature("iface_neighbor_cache_count", default=4, min=1, max=1024, pow2=8)
  27. feature("iface_max_route_count", default=2, min=1, max=1024, pow2=8)
  28. feature("fragmentation_buffer_size", default=1500, min=256, max=65536, pow2=True)
  29. feature("assembler_max_segment_count", default=4, min=1, max=32, pow2=4)
  30. feature("reassembly_buffer_size", default=1500, min=256, max=65536, pow2=True)
  31. feature("reassembly_buffer_count", default=1, min=1, max=32, pow2=4)
  32. feature("dns_max_result_count", default=1, min=1, max=32, pow2=4)
  33. feature("dns_max_server_count", default=1, min=1, max=32, pow2=4)
  34. feature("dns_max_name_size", default=255, min=64, max=255, pow2=True)
  35. # ========= Update Cargo.toml
  36. things = ""
  37. for f in features:
  38. name = f["name"].replace("_", "-")
  39. for val in f["vals"]:
  40. things += f"{name}-{val} = []"
  41. if val == f["default"]:
  42. things += " # Default"
  43. things += "\n"
  44. things += "\n"
  45. SEPARATOR_START = "# BEGIN AUTOGENERATED CONFIG FEATURES\n"
  46. SEPARATOR_END = "# END AUTOGENERATED CONFIG FEATURES\n"
  47. HELP = "# Generated by gen_config.py. DO NOT EDIT.\n"
  48. with open("Cargo.toml", "r") as f:
  49. data = f.read()
  50. before, data = data.split(SEPARATOR_START, maxsplit=1)
  51. _, after = data.split(SEPARATOR_END, maxsplit=1)
  52. data = before + SEPARATOR_START + HELP + things + SEPARATOR_END + after
  53. with open("Cargo.toml", "w") as f:
  54. f.write(data)
  55. # ========= Update build.rs
  56. things = ""
  57. for f in features:
  58. name = f["name"].upper()
  59. things += f' ("{name}", {f["default"]}),\n'
  60. SEPARATOR_START = "// BEGIN AUTOGENERATED CONFIG FEATURES\n"
  61. SEPARATOR_END = "// END AUTOGENERATED CONFIG FEATURES\n"
  62. HELP = " // Generated by gen_config.py. DO NOT EDIT.\n"
  63. with open("build.rs", "r") as f:
  64. data = f.read()
  65. before, data = data.split(SEPARATOR_START, maxsplit=1)
  66. _, after = data.split(SEPARATOR_END, maxsplit=1)
  67. data = before + SEPARATOR_START + HELP + things + " " + SEPARATOR_END + after
  68. with open("build.rs", "w") as f:
  69. f.write(data)