blob: bb932add65791c690352fd712ba196119d8a3dfc [file] [log] [blame]
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "gn/rust_project_writer_helpers.h"
#include "base/strings/string_util.h"
#include "gn/string_output_buffer.h"
#include "gn/test_with_scheduler.h"
#include "gn/test_with_scope.h"
#include "util/build_config.h"
#include "util/test/test.h"
using RustProjectWriterHelper = TestWithScheduler;
TEST_F(RustProjectWriterHelper, SysrootDepsAreCorrect) {
TestWithScope setup;
SysrootIdxMap sysroot_lookup;
uint32_t current_crate_count = 2;
std::ostringstream stream;
AddSysroot("path", &current_crate_count, sysroot_lookup, stream, setup.build_settings(),
false);
std::string out = stream.str();
#if defined(OS_WIN)
base::ReplaceSubstringsAfterOffset(&out, 0, "\r\n", "\n");
#endif
const char expected_json[] = ",\n"
" {\n"
" \"crate_id\": 2,\n"
" \"root_module\": \"out/Debug/path/lib/rustlib/src/rust/src/libcore/lib.rs\",\n"
" \"edition\": \"2018\",\n"
" \"deps\": [\n"
" ],\n"
" \"cfg\": []\n"
" },\n"
" {\n"
" \"crate_id\": 3,\n"
" \"root_module\": \"out/Debug/path/lib/rustlib/src/rust/src/liballoc/lib.rs\",\n"
" \"edition\": \"2018\",\n"
" \"deps\": [\n"
" {\n"
" \"crate\": 2,\n"
" \"name\": \"core\"\n"
" }\n"
" ],\n"
" \"cfg\": []\n"
" },\n"
" {\n"
" \"crate_id\": 4,\n"
" \"root_module\": \"out/Debug/path/lib/rustlib/src/rust/src/libpanic_abort/lib.rs\",\n"
" \"edition\": \"2018\",\n"
" \"deps\": [\n"
" ],\n"
" \"cfg\": []\n"
" },\n"
" {\n"
" \"crate_id\": 5,\n"
" \"root_module\": \"out/Debug/path/lib/rustlib/src/rust/src/libunwind/lib.rs\",\n"
" \"edition\": \"2018\",\n"
" \"deps\": [\n"
" ],\n"
" \"cfg\": []\n"
" },\n"
" {\n"
" \"crate_id\": 6,\n"
" \"root_module\": \"out/Debug/path/lib/rustlib/src/rust/src/libstd/lib.rs\",\n"
" \"edition\": \"2018\",\n"
" \"deps\": [\n"
" {\n"
" \"crate\": 3,\n"
" \"name\": \"alloc\"\n"
" },\n"
" {\n"
" \"crate\": 2,\n"
" \"name\": \"core\"\n"
" },\n"
" {\n"
" \"crate\": 4,\n"
" \"name\": \"panic_abort\"\n"
" },\n"
" {\n"
" \"crate\": 5,\n"
" \"name\": \"unwind\"\n"
" }\n"
" ],\n"
" \"cfg\": []\n"
" },\n"
" {\n"
" \"crate_id\": 7,\n"
" \"root_module\": \"out/Debug/path/lib/rustlib/src/rust/src/libcollections/lib.rs\",\n"
" \"edition\": \"2018\",\n"
" \"deps\": [\n"
" ],\n"
" \"cfg\": []\n"
" },\n"
" {\n"
" \"crate_id\": 8,\n"
" \"root_module\": \"out/Debug/path/lib/rustlib/src/rust/src/liblibc/lib.rs\",\n"
" \"edition\": \"2018\",\n"
" \"deps\": [\n"
" ],\n"
" \"cfg\": []\n"
" },\n"
" {\n"
" \"crate_id\": 9,\n"
" \"root_module\": \"out/Debug/path/lib/rustlib/src/rust/src/libpanic_unwind/lib.rs\",\n"
" \"edition\": \"2018\",\n"
" \"deps\": [\n"
" ],\n"
" \"cfg\": []\n"
" },\n"
" {\n"
" \"crate_id\": 10,\n"
" \"root_module\": \"out/Debug/path/lib/rustlib/src/rust/src/libproc_macro/lib.rs\",\n"
" \"edition\": \"2018\",\n"
" \"deps\": [\n"
" ],\n"
" \"cfg\": []\n"
" },\n"
" {\n"
" \"crate_id\": 11,\n"
" \"root_module\": \"out/Debug/path/lib/rustlib/src/rust/src/librustc_unicode/lib.rs\",\n"
" \"edition\": \"2018\",\n"
" \"deps\": [\n"
" ],\n"
" \"cfg\": []\n"
" },\n"
" {\n"
" \"crate_id\": 12,\n"
" \"root_module\": \"out/Debug/path/lib/rustlib/src/rust/src/libstd_unicode/lib.rs\",\n"
" \"edition\": \"2018\",\n"
" \"deps\": [\n"
" ],\n"
" \"cfg\": []\n"
" },\n"
" {\n"
" \"crate_id\": 13,\n"
" \"root_module\": \"out/Debug/path/lib/rustlib/src/rust/src/libtest/lib.rs\",\n"
" \"edition\": \"2018\",\n"
" \"deps\": [\n"
" ],\n"
" \"cfg\": []\n"
" },\n"
" {\n"
" \"crate_id\": 14,\n"
" \"root_module\": \"out/Debug/path/lib/rustlib/src/rust/src/liballoc_jemalloc/lib.rs\",\n"
" \"edition\": \"2018\",\n"
" \"deps\": [\n"
" ],\n"
" \"cfg\": []\n"
" },\n"
" {\n"
" \"crate_id\": 15,\n"
" \"root_module\": \"out/Debug/path/lib/rustlib/src/rust/src/liballoc_system/lib.rs\",\n"
" \"edition\": \"2018\",\n"
" \"deps\": [\n"
" ],\n"
" \"cfg\": []\n"
" },\n"
" {\n"
" \"crate_id\": 16,\n"
" \"root_module\": \"out/Debug/path/lib/rustlib/src/rust/src/libcompiler_builtins/lib.rs\",\n"
" \"edition\": \"2018\",\n"
" \"deps\": [\n"
" ],\n"
" \"cfg\": []\n"
" },\n"
" {\n"
" \"crate_id\": 17,\n"
" \"root_module\": \"out/Debug/path/lib/rustlib/src/rust/src/libgetopts/lib.rs\",\n"
" \"edition\": \"2018\",\n"
" \"deps\": [\n"
" ],\n"
" \"cfg\": []\n"
" },\n"
" {\n"
" \"crate_id\": 18,\n"
" \"root_module\": \"out/Debug/path/lib/rustlib/src/rust/src/libbuild_helper/lib.rs\",\n"
" \"edition\": \"2018\",\n"
" \"deps\": [\n"
" ],\n"
" \"cfg\": []\n"
" },\n"
" {\n"
" \"crate_id\": 19,\n"
" \"root_module\": \"out/Debug/path/lib/rustlib/src/rust/src/librustc_asan/lib.rs\",\n"
" \"edition\": \"2018\",\n"
" \"deps\": [\n"
" ],\n"
" \"cfg\": []\n"
" },\n"
" {\n"
" \"crate_id\": 20,\n"
" \"root_module\": \"out/Debug/path/lib/rustlib/src/rust/src/librustc_lsan/lib.rs\",\n"
" \"edition\": \"2018\",\n"
" \"deps\": [\n"
" ],\n"
" \"cfg\": []\n"
" },\n"
" {\n"
" \"crate_id\": 21,\n"
" \"root_module\": \"out/Debug/path/lib/rustlib/src/rust/src/librustc_msan/lib.rs\",\n"
" \"edition\": \"2018\",\n"
" \"deps\": [\n"
" ],\n"
" \"cfg\": []\n"
" },\n"
" {\n"
" \"crate_id\": 22,\n"
" \"root_module\": \"out/Debug/path/lib/rustlib/src/rust/src/librustc_tsan/lib.rs\",\n"
" \"edition\": \"2018\",\n"
" \"deps\": [\n"
" ],\n"
" \"cfg\": []\n"
" },\n"
" {\n"
" \"crate_id\": 23,\n"
" \"root_module\": \"out/Debug/path/lib/rustlib/src/rust/src/libsyntax/lib.rs\",\n"
" \"edition\": \"2018\",\n"
" \"deps\": [\n"
" ],\n"
" \"cfg\": []\n"
" }"
;
EXPECT_EQ(expected_json, out);
}