Skip to content

Commit

Permalink
Fix #135358
Browse files Browse the repository at this point in the history
  • Loading branch information
tanvincible committed Jan 13, 2025
1 parent 047bc17 commit 850eb05
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 5 deletions.
19 changes: 16 additions & 3 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ def verify(path, expected, verbose):
verified = found == expected
if not verified:
eprint(
"invalid checksum:\n" " found: {}\n" " expected: {}".format(
found, expected
)
"invalid checksum:\n"
" found: {}\n"
" expected: {}".format(found, expected)
)
return verified

Expand Down Expand Up @@ -1264,6 +1264,12 @@ def bootstrap(args):
config_toml = ""

profile = RustBuild.get_toml_static(config_toml, "profile")
is_non_git_source = not os.path.exists(os.path.join(rust_root, ".git"))

if profile is None:
if is_non_git_source:
profile = "dist"

if profile is not None:
# Allows creating alias for profile names, allowing
# profiles to be renamed while maintaining back compatibility
Expand All @@ -1284,6 +1290,13 @@ def bootstrap(args):
with open(include_path) as included_toml:
config_toml += os.linesep + included_toml.read()

if is_non_git_source:
for option in ["download-ci-llvm", "download-rustc"]:
if RustBuild.get_toml_static(config_toml, option):
raise Exception(
"Option '{}' cannot be used with non-git sources.".format(option)
)

# Configure initial bootstrap
build = RustBuild(config_toml, args)
build.check_vendored_status()
Expand Down
102 changes: 101 additions & 1 deletion src/bootstrap/bootstrap_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from __future__ import absolute_import, division, print_function
import os
import unittest
from unittest.mock import patch
from unittest.mock import patch, mock_open
import tempfile
import hashlib
import sys
Expand Down Expand Up @@ -249,3 +249,103 @@ def test_warnings(self):

_, env = self.build_args(configure_args, args=["--warnings=deny"])
self.assertTrue("-Dwarnings" in env["RUSTFLAGS"])


class TestRustBuild(unittest.TestCase):

@patch("os.path.exists")
@patch("bootstrap.RustBuild.get_toml_static")
def test_profile_none_with_non_git_source(self, mock_get_toml_static, mock_exists):
mock_exists.return_value = False
mock_get_toml_static.return_value = None

rust_root = "/mock/rust_root"
config_toml = ""

profile = bootstrap.RustBuild.get_toml_static(config_toml, "profile")

is_non_git_source = not os.path.exists(os.path.join(rust_root, ".git"))
if profile is None and is_non_git_source:
profile = "dist"

self.assertEqual(profile, "dist")

@patch("os.path.exists")
@patch("bootstrap.RustBuild.get_toml_static")
def test_include_path_exists(self, mock_get_toml_static, mock_exists):
mock_exists.return_value = True
mock_get_toml_static.return_value = "dist"

rust_root = "/mock/rust_root"
config_toml = "mock_config"

profile = bootstrap.RustBuild.get_toml_static(config_toml, "profile")

profile_aliases = {"user": "dist"}
include_file = f"config.{profile_aliases.get(profile) or profile}.toml"
include_dir = os.path.join(rust_root, "src", "bootstrap", "defaults")
include_path = os.path.join(include_dir, include_file)

# Assert the include_path is correctly formed
self.assertEqual(
include_path, "/mock/rust_root/src/bootstrap/defaults/config.dist.toml"
)

@patch("os.path.exists")
@patch("bootstrap.RustBuild.get_toml_static")
@patch("builtins.open", new_callable=mock_open)
def test_config_toml_inclusion(self, mock_open, mock_get_toml_static, mock_exists):
mock_exists.side_effect = (
lambda path: path
== "/mock/rust_root/src/bootstrap/defaults/config.dist.toml"
)
mock_get_toml_static.return_value = "dist"
mock_open.return_value.read.return_value = "included_toml_content"

rust_root = "/mock/rust_root"
config_toml = "initial_config"

profile = bootstrap.RustBuild.get_toml_static(config_toml, "profile")

profile_aliases = {"user": "dist"}
include_file = f"config.{profile_aliases.get(profile) or profile}.toml"
include_dir = os.path.join(rust_root, "src", "bootstrap", "defaults")
include_path = os.path.join(include_dir, include_file)

with open(include_path) as included_toml:
config_toml += os.linesep + included_toml.read()

self.assertIn("initial_config\nincluded_toml_content", config_toml)

@patch("os.path.exists")
@patch("bootstrap.RustBuild.get_toml_static")
def test_invalid_profile_for_non_git_source(
self, mock_get_toml_static, mock_exists
):
mock_exists.return_value = False

def mock_get_toml_static_side_effect(config_toml, option):
if option in ["download-ci-llvm", "download-rustc"]:
return "true"
return None

mock_get_toml_static.side_effect = mock_get_toml_static_side_effect

rust_root = "/mock/rust_root"
config_toml = ""

profile = bootstrap.RustBuild.get_toml_static(config_toml, "profile")
is_non_git_source = not os.path.exists(os.path.join(rust_root, ".git"))
if profile is None and is_non_git_source:
profile = "dist"

for option in ["download-ci-llvm", "download-rustc"]:
if bootstrap.RustBuild.get_toml_static(config_toml, option):
with self.assertRaises(Exception) as context:
raise Exception(
f"Option '{option}' cannot be used with non-git sources."
)
self.assertTrue(
f"Option '{option}' cannot be used with non-git sources."
in str(context.exception)
)
21 changes: 20 additions & 1 deletion src/librustdoc/passes/propagate_stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,26 @@ impl DocFolder for StabilityPropagator<'_, '_> {

let stability = match item.item_id {
ItemId::DefId(def_id) => {
let own_stability = self.cx.tcx.lookup_stability(def_id);
let item_stability = self.cx.tcx.lookup_stability(def_id);
let inline_stability =
item.inline_stmt_id.and_then(|did| self.cx.tcx.lookup_stability(did));
let own_stability = if let Some(item_stab) = item_stability
&& let StabilityLevel::Stable { since: _, allowed_through_unstable_modules } =
item_stab.level
&& let Some(mut inline_stab) = inline_stability
&& let StabilityLevel::Stable {
since: inline_since,
allowed_through_unstable_modules: _,
} = inline_stab.level
{
inline_stab.level = StabilityLevel::Stable {
since: inline_since,
allowed_through_unstable_modules,
};
Some(inline_stab)
} else {
item_stability
};

let (ItemKind::StrippedItem(box kind) | kind) = &item.kind;
match kind {
Expand Down
18 changes: 18 additions & 0 deletions tests/rustdoc/inline_local/staged-inline.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// https://github.com/rust-lang/rust/issues/135078
#![crate_name = "foo"]
#![feature(staged_api)]
#![stable(feature = "v1", since="1.0.0")]

#[stable(feature = "v1", since="1.0.0")]
pub mod ffi {
#[stable(feature = "core_ffi", since="1.99.0")]
//@ has "foo/ffi/struct.CStr.html" "//span[@class='sub-heading']/span[@class='since']" "1.99.0"
//@ !has - "//span[@class='sub-heading']/span[@class='since']" "1.0.0"
pub struct CStr;
}

#[stable(feature = "v1", since = "1.0.0")]
#[doc(inline)]
//@ has "foo/struct.CStr.html" "//span[@class='sub-heading']/span[@class='since']" "1.0.0"
//@ !has - "//span[@class='sub-heading']/span[@class='since']" "1.99.0"
pub use ffi::CStr;

0 comments on commit 850eb05

Please sign in to comment.