diff --git a/modules/libpref/init/generate_static_pref_list.py b/modules/libpref/init/generate_static_pref_list.py index 4fe11150c011b..8e96be5842d26 100644 --- a/modules/libpref/init/generate_static_pref_list.py +++ b/modules/libpref/init/generate_static_pref_list.py @@ -57,7 +57,10 @@ "float": "f32", } -FIRST_LINE = "// This file was generated by generate_static_pref_list.py. DO NOT EDIT." +HEADER_LINE = ( + "// This file was generated by generate_static_pref_list.py from {input_filename}." + " DO NOT EDIT." +) MIRROR_TEMPLATES = { "never": """\ @@ -222,19 +225,21 @@ def check_pref_list(pref_list): prev_pref = pref -def generate_code(pref_list): +def generate_code(pref_list, input_filename): check_pref_list(pref_list) + first_line = HEADER_LINE.format(input_filename=input_filename) + # The required includes for StaticPrefs_.h. includes = defaultdict(set) # StaticPrefList_.h contains all the pref definitions for this # group. - static_pref_list_group_h = defaultdict(lambda: [FIRST_LINE, ""]) + static_pref_list_group_h = defaultdict(lambda: [first_line, ""]) # StaticPrefsCGetters.cpp contains C getters for all the mirrored prefs, # for use by Rust code. - static_prefs_c_getters_cpp = [FIRST_LINE, ""] + static_prefs_c_getters_cpp = [first_line, ""] # static_prefs.rs contains C getter declarations and a macro. static_prefs_rs_decls = [] @@ -310,7 +315,7 @@ def generate_code(pref_list): # StaticPrefListAll.h contains one `#include "mozilla/StaticPrefList_X.h` # line per pref group. - static_pref_list_all_h = [FIRST_LINE, ""] + static_pref_list_all_h = [first_line, ""] static_pref_list_all_h.extend( '#include "mozilla/StaticPrefList_{}.h"'.format(group) for group in sorted(static_pref_list_group_h) @@ -319,7 +324,7 @@ def generate_code(pref_list): # StaticPrefsAll.h contains one `#include "mozilla/StaticPrefs_X.h` line per # pref group. - static_prefs_all_h = [FIRST_LINE, ""] + static_prefs_all_h = [first_line, ""] static_prefs_all_h.extend( '#include "mozilla/StaticPrefs_{}.h"'.format(group) for group in sorted(static_pref_list_group_h) @@ -330,7 +335,7 @@ def generate_code(pref_list): # used directly by application code. static_prefs_group_h = defaultdict(list) for group in sorted(static_pref_list_group_h): - static_prefs_group_h[group] = [FIRST_LINE] + static_prefs_group_h[group] = [first_line] static_prefs_group_h[group].append( STATIC_PREFS_GROUP_H_TEMPLATE1.format(group=group) ) @@ -344,7 +349,7 @@ def generate_code(pref_list): ) # static_prefs.rs contains the Rust macro getters. - static_prefs_rs = [FIRST_LINE, "", 'extern "C" {'] + static_prefs_rs = [first_line, "", 'extern "C" {'] static_prefs_rs.extend(static_prefs_rs_decls) static_prefs_rs.extend(["}", "", "#[macro_export]", "macro_rules! pref {"]) static_prefs_rs.extend(static_prefs_rs_macro) @@ -382,7 +387,11 @@ def emit_code(fd, pref_list_filename): try: pref_list = yaml.safe_load(pp.out.getvalue()) - code = generate_code(pref_list) + input_file = os.path.relpath( + pref_list_filename, + os.environ.get("GECKO_PATH", os.environ.get("TOPSRCDIR")), + ) + code = generate_code(pref_list, input_file) except (IOError, ValueError) as e: print("{}: error:\n {}\n".format(pref_list_filename, e)) sys.exit(1) diff --git a/modules/libpref/test/test_generate_static_pref_list.py b/modules/libpref/test/test_generate_static_pref_list.py index 86d4d1248f926..ab8e6492b7f2b 100644 --- a/modules/libpref/test/test_generate_static_pref_list.py +++ b/modules/libpref/test/test_generate_static_pref_list.py @@ -99,7 +99,7 @@ good[ "static_pref_list_all_h" ] = """\ -// This file was generated by generate_static_pref_list.py. DO NOT EDIT. +// This file was generated by generate_static_pref_list.py from (string input). DO NOT EDIT. #include "mozilla/StaticPrefList_my.h" #include "mozilla/StaticPrefList_my_dashed.h" @@ -108,7 +108,7 @@ good[ "static_prefs_all_h" ] = """\ -// This file was generated by generate_static_pref_list.py. DO NOT EDIT. +// This file was generated by generate_static_pref_list.py from (string input). DO NOT EDIT. #include "mozilla/StaticPrefs_my.h" #include "mozilla/StaticPrefs_my_dashed.h" @@ -116,7 +116,7 @@ good["static_pref_list_group_h"] = { "my": """\ -// This file was generated by generate_static_pref_list.py. DO NOT EDIT. +// This file was generated by generate_static_pref_list.py from (string input). DO NOT EDIT. NEVER_PREF("my.bool", bool, false) @@ -167,7 +167,7 @@ ) """, "my_dashed": """\ -// This file was generated by generate_static_pref_list.py. DO NOT EDIT. +// This file was generated by generate_static_pref_list.py from (string input). DO NOT EDIT. NEVER_PREF("my-dashed.atomic.float", AtomicFloat, 0.4455667) """, @@ -175,7 +175,7 @@ good["static_prefs_group_h"] = { "my": """\ -// This file was generated by generate_static_pref_list.py. DO NOT EDIT. +// This file was generated by generate_static_pref_list.py from (string input). DO NOT EDIT. // Include it to gain access to StaticPrefs::my_*. #ifndef mozilla_StaticPrefs_my_h @@ -194,7 +194,7 @@ good[ "static_prefs_c_getters_cpp" ] = """\ -// This file was generated by generate_static_pref_list.py. DO NOT EDIT. +// This file was generated by generate_static_pref_list.py from (string input). DO NOT EDIT. extern "C" uint32_t StaticPrefs_my_uint() { return mozilla::StaticPrefs::my_uint(); @@ -212,7 +212,7 @@ good[ "static_prefs_rs" ] = """\ -// This file was generated by generate_static_pref_list.py. DO NOT EDIT. +// This file was generated by generate_static_pref_list.py from (string input). DO NOT EDIT. extern "C" { pub fn StaticPrefs_my_uint() -> u32; @@ -417,7 +417,7 @@ def test_good(self): "Test various pieces of good input." inp = StringIO(good_input) pref_list = yaml.safe_load(inp) - code = generate_code(pref_list) + code = generate_code(pref_list, "(string input)") self.assertEqual(good["static_pref_list_all_h"], code["static_pref_list_all_h"]) @@ -449,7 +449,7 @@ def test_bad(self): inp = StringIO(input_string) try: pref_list = yaml.safe_load(inp) - generate_code(pref_list) + generate_code(pref_list, "(string input") self.assertEqual(0, 1) except ValueError as e: self.assertEqual(str(e), expected)