Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions nml/grfstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def com_parse_string(val, lang_id):
]


def read_extra_commands(custom_tags_file):
def read_extra_commands(custom_tags_file, dependencies: list[str]):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

: list[str] annotation included out of habit to make autocomplete work. Can trash it if it's too against the grain here.

"""
@param custom_tags_file: Filename of the custom tags file.
@type custom_tags_file: C{str}
Expand All @@ -298,6 +298,7 @@ def read_extra_commands(custom_tags_file):
# Failed to open custom_tags.txt, ignore this
return
line_no = 0
dependencies.append(custom_tags_file)
with open(generic.find_file(custom_tags_file), "r", encoding="utf-8") as fh:
for line in fh:
line_no += 1
Expand Down Expand Up @@ -1267,7 +1268,7 @@ def parse_file(filename, default):
langs.append((lang.langid, lang))


def read_lang_files(lang_dir, default_lang_file):
def read_lang_files(lang_dir, default_lang_file, dependencies: list[str]):
"""
Read the language files containing the translations for string constants
used in the NML specification.
Expand All @@ -1289,10 +1290,13 @@ def read_lang_files(lang_dir, default_lang_file):
'Default language file "{}" doesn\'t exist'.format(os.path.join(lang_dir, default_lang_file)),
)
return
dependencies.append(lang_dir + os.sep + default_lang_file)
parse_file(lang_dir + os.sep + default_lang_file, True)
dependencies.append(lang_dir)
for filename in glob.glob(lang_dir + os.sep + "*.lng"):
if filename.endswith(default_lang_file):
continue
dependencies.append(filename)
parse_file(filename, False)
langs.sort()

Expand Down
18 changes: 15 additions & 3 deletions nml/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def parse_cli(argv):
dest="dep_check",
help=(
"output a rule suitable for make describing"
" the graphics dependencies of the main grf file (requires input file or --grf)"
" the dependencies of the main grf file (requires input file or --grf)"
),
)
opt_parser.add_option(
Expand Down Expand Up @@ -265,11 +265,13 @@ def main(argv):
if opts.stack:
developmode = True

grfstrings.read_extra_commands(opts.custom_tags)
dependencies = []

grfstrings.read_extra_commands(opts.custom_tags, dependencies)

generic.print_progress("Reading lang ...")

grfstrings.read_lang_files(opts.lang_dir, opts.default_lang)
grfstrings.read_lang_files(opts.lang_dir, opts.default_lang, dependencies)

generic.clear_progress()

Expand Down Expand Up @@ -307,6 +309,7 @@ def main(argv):
if input_filename is None:
input = sys.stdin
else:
dependencies.append(input_filename)
input = codecs.open(generic.find_file(input_filename), "r", "utf-8")
# Only append an output grf name, if no output is given, also not implicitly via -M
if not opts.outputfile_given and not outputs:
Expand Down Expand Up @@ -352,6 +355,7 @@ def main(argv):
opts.md5_filename,
opts.debug_parser,
opts.disable_palette_validation,
dependencies,
)

input.close()
Expand All @@ -377,6 +381,7 @@ def nml(
md5_filename,
debug_parser,
disable_palette_validation,
dependencies,
):
"""
Compile an NML file.
Expand Down Expand Up @@ -405,6 +410,9 @@ def nml(
@param md5_filename: Filename to use for writing the md5 sum of the grf file.
C{None} if the file should not be written.
@type md5_filename: C{str} or C{None}

@param dependencies: List of lang/config file dependencies.
@type dependencies: C{List}
"""
generic.OnlyOnce.clear()

Expand Down Expand Up @@ -510,6 +518,10 @@ def nml(
for outputfile in outputfiles:
if isinstance(outputfile, output_dep.OutputDEP):
with outputfile:
# Dependencies from outside world
for dep in dependencies:
outputfile.write(dep)
# Sprite dependencies discovered during build
for f in sprite_files:
if f[0] is not None:
outputfile.write(f[0])
Expand Down