diff --git a/generate-encoding-data.py b/generate-encoding-data.py index ddcefd6..ce0d286 100644 --- a/generate-encoding-data.py +++ b/generate-encoding-data.py @@ -109,18 +109,29 @@ def is_single_byte(name): return True return False -label_file = open("src/labels.rs", "w") +label_file = open("src/lib.rs", "r") +lib_rs_full = label_file.read() +label_file.close() -label_file.write("""// Copyright 2015-2016 Mozilla Foundation. See the COPYRIGHT -// file at the top-level directory of this distribution. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. +generated_begin = "// BEGIN GENERATED CODE. PLEASE DO NOT EDIT." +generated_end = "// END GENERATED CODE" -// BEGIN GENERATED CODE. PLEASE DO NOT EDIT. +generated_begin_index = lib_rs_full.find(generated_begin) +if generated_begin_index < 0: + print "Can't find generated code start marker in lib.rs. Exiting." + sys.exit(-1) +generated_end_index = lib_rs_full.find(generated_end) +if generated_end_index < 0: + print "Can't find generated code end marker in lib.rs. Exiting." + sys.exit(-1) + +lib_rs_begin = lib_rs_full[0:generated_begin_index + len(generated_begin)] +lib_rs_end = lib_rs_full[generated_end_index:] + +label_file = open("src/lib.rs", "w") + +label_file.write(lib_rs_begin) +label_file.write(""" // Instead, please regenerate using generate-encoding-data.py const LONGEST_LABEL_LENGTH: usize = %d; // %s @@ -167,9 +178,8 @@ for label in labels: label_file.write(''']; -// END GENERATED CODE ''') - +label_file.write(lib_rs_end) label_file.close() def null_to_zero(code_point):