From 5a9f15cd47f438210b56cd9389257ed5320f2ad7 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Fri, 10 Jul 2020 15:05:28 -0500 Subject: hscript: Use curr_name; work around Alpine bug On some Alpine systems, '/dev/stdin' cannot be canonicalised. We work around this by hardcoding "" as the internal name for scripts read from stdin, similar to Python. This change also ensures messages generated from the parser itself use curr_name (the canonicalised name) instead of the name passed to the Script object. --- hscript/script.cc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/hscript/script.cc b/hscript/script.cc index 20ccbe5..6e436b7 100644 --- a/hscript/script.cc +++ b/hscript/script.cc @@ -225,7 +225,12 @@ Script *Script::load(std::istream &sstream, const ScriptOptions &opts, char nextline[SCRIPT_LINE_MAX]; const std::string delim(" \t"); int errors = 0, warnings = 0; - std::string curr_name = fs::canonical(fs::path(name)); + std::string curr_name; + if(name == "/dev/stdin") { + curr_name = ""; + } else { + curr_name = fs::canonical(fs::path(name)); + } std::set seen = {curr_name}; bool inherit = false; std::istream *my_stream = &sstream; @@ -311,7 +316,7 @@ Script *Script::load(std::istream &sstream, const ScriptOptions &opts, } if(my_stream->fail() && !my_stream->eof()) { - output_error("installfile:" + std::to_string(lineno + 1), + output_error(curr_name + ":" + std::to_string(lineno + 1), "line exceeds maximum length", "Maximum line length is " + std::to_string(SCRIPT_LINE_MAX)); @@ -319,14 +324,14 @@ Script *Script::load(std::istream &sstream, const ScriptOptions &opts, } if(my_stream->bad() && !my_stream->eof()) { - output_error("installfile:" + std::to_string(lineno), + output_error(curr_name + ":" + std::to_string(lineno), "I/O error while reading installfile", ""); errors++; } /* Ensure all required keys are present. */ #define MISSING_ERROR(key) \ - output_error(name, "expected value for key '" + std::string(key) + "'",\ + output_error(curr_name, "expected value for key '" + std::string(key) + "'",\ "this key is required");\ errors++; @@ -349,7 +354,7 @@ Script *Script::load(std::istream &sstream, const ScriptOptions &opts, } #undef MISSING_ERROR - output_log("parser", "0", name, + output_log("parser", "0", curr_name, std::to_string(errors) + " error(s), " + std::to_string(warnings) + " warning(s).", ""); -- cgit v1.2.3-60-g2f50