diff options
author | Swaroop Sridhar <Swaroop.Sridhar@microsoft.com> | 2020-05-01 19:24:13 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-01 19:24:13 +0300 |
commit | 47ec733ba79b196e4e09d0c89bad245155002353 (patch) | |
tree | 98fc7124abbcb678abe9687e757a77e638560f05 /src/installer/corehost/cli/json_parser.cpp | |
parent | 6d1f7e01d3429054ec3dcb7c75b3450b9fe1429e (diff) |
[release/5.0-preview4] Revert processing bundles in framework (#35679)v5.0.0-preview.4.20251.6
This commit reverts:
Revert "Single-File: Process bundles in the framework (#34274)"
This reverts commit 78b303df8fbb242985d049a277d0d199cafd51b5.
Revert "Single-File Bundler: Add a FileSize test (#35149)"
This reverts commit 779588a509b81d909ac5d496c172949ec1f1ddcc.
*Customer Scenario*
Publishing apps as a self-contained single-file doesn't work as expected.
* Publish needs to generate hostpolicy and hostfxr separate from the single file bundle
* Cross-platform publishing is incorrect
*Problem*
Since Static-apphost is not yet ready, processing bundle content in hostpolicy means that hostpolicy and hostfxr DLLs need to be separate from the bundle. This causes self-contained single-file apps to not be a "single file" temporarily.
The change also requires supporting changes from the SDK, to publish hostfxr and hostpolicy as separate files, and to invoke HostModel library with arguments that facilitate cross-platform publishing.
*Solution*
To solve these, problem, this change reverts:
Revert "Single-File: Process bundles in the framework (#34274)" commit 78b303df8fbb242985d049a277d0d199cafd51b5.
and a dependent test-only change:
Revert "Single-File Bundler: Add a FileSize test (#35149)" commit 779588a509b81d909ac5d496c172949ec1f1ddcc.
*Risk*
Medium
The change is contained to only host components: apphost, hostpolicy, and hostfxr.
However, the change is big, and needs testing in runtime and SDK repos.
*Testing*
Manually tested the SDK by inserting apphost, hostfxr, hostpolicy, and hostmodel library from this build into the `dotnet/packs` preview-4 SDK from https://github.com/dotnet/sdk/pull/11518 build.
Verified that:
* Singlefile apps can be published and run OK for { Windows, Linux, Osx } x {netcoreapp3.0, netcoreapp3.1, netcoreapp5.0}
* Cross-targeting builds of single-file apps build and run OK (ex: built on Windos, run on Mac).
Diffstat (limited to 'src/installer/corehost/cli/json_parser.cpp')
-rw-r--r-- | src/installer/corehost/cli/json_parser.cpp | 62 |
1 files changed, 16 insertions, 46 deletions
diff --git a/src/installer/corehost/cli/json_parser.cpp b/src/installer/corehost/cli/json_parser.cpp index c6f0cbbf0c9..9814f3215d6 100644 --- a/src/installer/corehost/cli/json_parser.cpp +++ b/src/installer/corehost/cli/json_parser.cpp @@ -42,9 +42,9 @@ std::streampos get_utf8_bom_length(pal::istream_t& stream) return 3; } -void get_line_column_from_offset(const char* data, uint64_t size, size_t offset, int *line, int *column) +void get_line_column_from_offset(const std::vector<char>& json, size_t offset, int *line, int *column) { - assert(offset < size); + assert(offset < json.size()); *line = *column = 1; @@ -52,12 +52,12 @@ void get_line_column_from_offset(const char* data, uint64_t size, size_t offset, { (*column)++; - if (data[i] == '\n') + if (json[i] == '\n') { (*line)++; *column = 1; } - else if (data[i] == '\r' && data[i + 1] == '\n') + else if (json[i] == '\r' && json[i + 1] == '\n') { (*line)++; *column = 1; @@ -75,30 +75,32 @@ void json_parser_t::realloc_buffer(size_t size) m_json[size] = '\0'; } -bool json_parser_t::parse_json(char* data, int64_t size, const pal::string_t& context) +bool json_parser_t::parse_json(const pal::string_t& context) { + assert(!m_json.empty()); + #ifdef _WIN32 // Can't use in-situ parsing on Windows, as JSON data is encoded in // UTF-8 and the host expects wide strings. m_document will store // data in UTF-16 (with pal::char_t as the character type), but it // has to know that data is encoded in UTF-8 to convert during parsing. constexpr auto flags = rapidjson::ParseFlag::kParseStopWhenDoneFlag - | rapidjson::ParseFlag::kParseCommentsFlag; - m_document.Parse<flags, rapidjson::UTF8<>>(data); -#else // _WIN32 - m_document.ParseInsitu<rapidjson::ParseFlag::kParseCommentsFlag>(data); -#endif // _WIN32 + | rapidjson::ParseFlag::kParseCommentsFlag; + m_document.Parse<flags, rapidjson::UTF8<>>(m_json.data()); +#else + m_document.ParseInsitu<rapidjson::ParseFlag::kParseCommentsFlag>(m_json.data()); +#endif if (m_document.HasParseError()) { int line, column; size_t offset = m_document.GetErrorOffset(); - get_line_column_from_offset(data, size, offset, &line, &column); + get_line_column_from_offset(m_json, offset, &line, &column); trace::error(_X("A JSON parsing exception occurred in [%s], offset %zu (line %d, column %d): %s"), - context.c_str(), offset, line, column, - rapidjson::GetParseError_En(m_document.GetParseError())); + context.c_str(), offset, line, column, + rapidjson::GetParseError_En(m_document.GetParseError())); return false; } @@ -128,37 +130,5 @@ bool json_parser_t::parse_stream(pal::istream_t& stream, realloc_buffer(stream_size - current_pos); stream.read(m_json.data(), stream_size - current_pos); - return parse_json(m_json.data(), m_json.size(), context); -} - -bool json_parser_t::parse_file(const pal::string_t& path) -{ - // This code assumes that the caller has checked that the file `path` exists - // either within the bundle, or as a real file on disk. - assert(m_bundle_data == nullptr); - assert(m_bundle_location == nullptr); - - if (bundle::info_t::is_single_file_bundle()) - { - m_bundle_data = bundle::info_t::config_t::map(path, m_bundle_location); - // The mapping will be unmapped by the json_parser destructor. - // The mapping cannot be immediately released due to in-situ parsing on Linux. - - if (m_bundle_data != nullptr) - { - bool result = parse_json(m_bundle_data, m_bundle_location->size, path); - return result; - } - } - - pal::ifstream_t file{ path }; - return parse_stream(file, path); -} - -json_parser_t::~json_parser_t() -{ - if (m_bundle_data != nullptr) - { - bundle::info_t::config_t::unmap(m_bundle_data, m_bundle_location); - } + return parse_json(context); } |