esp_err_to_name.py: guess IDF_PATH if not set in environement

Fixes the issue that esp_err_to_name.py would fail when called in
documentation build process, when there was no IDF_PATH set.
pull/2104/head
Ivan Grokhotkov 2018-06-21 15:21:45 +08:00
rodzic 8c87df538e
commit 858cfc2950
1 zmienionych plików z 11 dodań i 6 usunięć

Wyświetl plik

@ -277,24 +277,29 @@ def generate_rst_output(fout):
fout.write('\n\n') fout.write('\n\n')
def main(): def main():
if 'IDF_PATH' in os.environ:
idf_path = os.environ['IDF_PATH']
else:
idf_path = os.path.realpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))
parser = argparse.ArgumentParser(description='ESP32 esp_err_to_name lookup generator for esp_err_t') parser = argparse.ArgumentParser(description='ESP32 esp_err_to_name lookup generator for esp_err_t')
parser.add_argument('--c_input', help='Path to the esp_err_to_name.c.in template input.', default=os.environ['IDF_PATH'] + '/components/esp32/esp_err_to_name.c.in') parser.add_argument('--c_input', help='Path to the esp_err_to_name.c.in template input.', default=idf_path + '/components/esp32/esp_err_to_name.c.in')
parser.add_argument('--c_output', help='Path to the esp_err_to_name.c output.', default=os.environ['IDF_PATH'] + '/components/esp32/esp_err_to_name.c') parser.add_argument('--c_output', help='Path to the esp_err_to_name.c output.', default=idf_path + '/components/esp32/esp_err_to_name.c')
parser.add_argument('--rst_output', help='Generate .rst output and save it into this file') parser.add_argument('--rst_output', help='Generate .rst output and save it into this file')
args = parser.parse_args() args = parser.parse_args()
for root, dirnames, filenames in os.walk(os.environ['IDF_PATH']): for root, dirnames, filenames in os.walk(idf_path):
for filename in fnmatch.filter(filenames, '*.[ch]'): for filename in fnmatch.filter(filenames, '*.[ch]'):
full_path = os.path.join(root, filename) full_path = os.path.join(root, filename)
idf_path = os.path.relpath(full_path, os.environ['IDF_PATH']) path_in_idf = os.path.relpath(full_path, idf_path)
if idf_path in ignore_files: if path_in_idf in ignore_files:
continue continue
with open(full_path, "r+") as f: with open(full_path, "r+") as f:
for line in f: for line in f:
# match also ESP_OK and ESP_FAIL because some of ESP_ERRs are referencing them # match also ESP_OK and ESP_FAIL because some of ESP_ERRs are referencing them
if re.match(r"\s*#define\s+(ESP_ERR_|ESP_OK|ESP_FAIL)", line): if re.match(r"\s*#define\s+(ESP_ERR_|ESP_OK|ESP_FAIL)", line):
try: try:
process(str.strip(line), idf_path) process(str.strip(line), path_in_idf)
except InputError as e: except InputError as e:
print (e) print (e)