| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::processrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/::Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#; |
| 2 | |
| 3 | use craterust-analyzer cargo glibc_musl_version 0.1.0 crate/::typesrust-analyzer cargo glibc_musl_version 0.1.0 types/::{LibcVersionsrust-analyzer cargo glibc_musl_version 0.1.0 types/LibcVersions#, Versionrust-analyzer cargo glibc_musl_version 0.1.0 types/Version#}; |
| 4 | |
| 5 | pub fn get_libc_version_outputrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/get_libc_version_output().(app: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> { |
| 6 | let output = Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]new().(app) |
| 7 | .argsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]args().(["--version"]) |
| 8 | .outputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]output().() |
| 9 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("failed to execute ldd: {e}"))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 10 | |
| 11 | let output_str = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 12 | "{}\n{}", |
| 13 | Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8_lossyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8_lossy().(&output.stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Output#stdout.), |
| 14 | Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8_lossyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8_lossy().(&output.stderrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Output#stderr.) |
| 15 | ) |
| 16 | .trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().() |
| 17 | .to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 18 | |
| 19 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(output_str) |
| 20 | } |
| 21 | |
| 22 | pub fn get_os_libc_versionsrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/get_os_libc_versions().() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<LibcVersionsrust-analyzer cargo glibc_musl_version 0.1.0 types/LibcVersions#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> { |
| 23 | let ldd_output = get_libc_version_outputrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/get_libc_version_output().("ldd")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 24 | |
| 25 | let glibc = if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(version_str) = ldd_output_to_glibc_version_strrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/ldd_output_to_glibc_version_str().(&ldd_output) { |
| 26 | parse_glibc_versionrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/parse_glibc_version().(version_str) |
| 27 | } else { |
| 28 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 29 | }; |
| 30 | |
| 31 | let musl_output = get_libc_version_outputrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/get_libc_version_output().("musl-ldd").unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or().(ldd_output); |
| 32 | |
| 33 | let musl = parse_musl_versionrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/parse_musl_version().(&musl_output); |
| 34 | |
| 35 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(LibcVersionsrust-analyzer cargo glibc_musl_version 0.1.0 types/LibcVersions# { glibcrust-analyzer cargo glibc_musl_version 0.1.0 types/LibcVersions#glibc., muslrust-analyzer cargo glibc_musl_version 0.1.0 types/LibcVersions#musl. }) |
| 36 | } |
| 37 | |
| 38 | fn ldd_output_to_glibc_version_strrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/ldd_output_to_glibc_version_str().(output_str: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&str, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> { |
| 39 | for line in output_str.linesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]lines().() { |
| 40 | if line.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("ldd (") { |
| 41 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(idx) = line.findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().(')') { |
| 42 | let after = &line[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 43 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(tok) = find_version_tokenrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/find_version_token().(after) { |
| 44 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(tok); |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#("no glibc version in ldd output".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()) |
| 50 | } |
| 51 | |
| 52 | fn parse_glibc_versionrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/parse_glibc_version().(version: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Versionrust-analyzer cargo glibc_musl_version 0.1.0 types/Version#> { |
| 53 | let mut parts = version.splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().('.').maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|s| s.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<usize>()); |
| 54 | match (parts.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/map/impl#[`Map<I, F>`][Iterator]next().(), parts.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/map/impl#[`Map<I, F>`][Iterator]next().()) { |
| 55 | (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(major)), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(minor))) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Versionrust-analyzer cargo glibc_musl_version 0.1.0 types/Version# { majorrust-analyzer cargo glibc_musl_version 0.1.0 types/Version#major., minorrust-analyzer cargo glibc_musl_version 0.1.0 types/Version#minor. }), |
| 56 | _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | fn parse_musl_versionrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/parse_musl_version().(output: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Versionrust-analyzer cargo glibc_musl_version 0.1.0 types/Version#> { |
| 61 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(pos) = output.findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().("musl libc") { |
| 62 | let rest = &output[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().pos..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 63 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(tok) = find_version_tokenrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/find_version_token().(rest) { |
| 64 | return parse_glibc_versionrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/parse_glibc_version().(tok); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | for line in output.linesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]lines().() { |
| 69 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(rest) = line.strip_prefixrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]strip_prefix().("Version ") { |
| 70 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(tok) = find_version_tokenrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/find_version_token().(rest) { |
| 71 | return parse_glibc_versionrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/parse_glibc_version().(tok); |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 77 | } |
| 78 | |
| 79 | fn find_version_tokenrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/find_version_token().(s: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str> { |
| 80 | for token in s.splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().(|c: char| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().(c.is_ascii_digitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_ascii_digit().() || c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'.')) { |
| 81 | if token.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() { |
| 82 | continue; |
| 83 | } |
| 84 | if token.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().('.') { |
| 85 | let mut parts = token.splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().('.'); |
| 86 | if let (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(a), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(b)) = (parts.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Split<'a, P>`][Iterator]next().(), parts.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Split<'a, P>`][Iterator]next().()) { |
| 87 | if a.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().().allrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#all().(|c| c.is_ascii_digitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_ascii_digit().()) && b.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().().allrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#all().(|c| c.is_ascii_digitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_ascii_digit().()) { |
| 88 | return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token); |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 94 | } |
| 95 | |
| 96 | #[cfg(test)] |
| 97 | mod testsrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/tests/ { |
| 98 | use superrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/::*; |
| 99 | use craterust-analyzer cargo glibc_musl_version 0.1.0 crate/::typesrust-analyzer cargo glibc_musl_version 0.1.0 types/::{LibcVersionsrust-analyzer cargo glibc_musl_version 0.1.0 types/LibcVersions#, Versionrust-analyzer cargo glibc_musl_version 0.1.0 types/Version#}; |
| 100 | |
| 101 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 102 | fn parse_glibc_ldd_outputrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/tests/parse_glibc_ldd_output().() { |
| 103 | let out = r#"ldd (GNU libc) 2.12 |
| 104 | Copyright (C) 2010 Free Software Foundation, Inc."#; |
| 105 | let ver_res = ldd_output_to_glibc_version_strrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/ldd_output_to_glibc_version_str().(out); |
| 106 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ver_res.is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 107 | let ver_str = ver_res.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 108 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ver_str, "2.12"); |
| 109 | let parsed = parse_glibc_versionrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/parse_glibc_version().(ver_str); |
| 110 | let parsed = parsed.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 111 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parsed.majorrust-analyzer cargo glibc_musl_version 0.1.0 types/Version#major., 2); |
| 112 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parsed.minorrust-analyzer cargo glibc_musl_version 0.1.0 types/Version#minor., 12); |
| 113 | |
| 114 | let out2 = r#"ldd (Ubuntu GLIBC 2.41-6ubuntu1.1) 2.41 |
| 115 | Copyright (C) 2024 Free Software Foundation, Inc. |
| 116 | This is free software; see the source for copying conditions. There is NO |
| 117 | warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 118 | Written by Roland McGrath and Ulrich Drepper. |
| 119 | "#; |
| 120 | let ver_res2 = ldd_output_to_glibc_version_strrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/ldd_output_to_glibc_version_str().(out2); |
| 121 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ver_res2.is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 122 | let ver_str2 = ver_res2.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 123 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ver_str2, "2.41"); |
| 124 | let parsed2 = parse_glibc_versionrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/parse_glibc_version().(ver_str2); |
| 125 | let parsed2 = parsed2.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 126 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parsed2.majorrust-analyzer cargo glibc_musl_version 0.1.0 types/Version#major., 2); |
| 127 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parsed2.minorrust-analyzer cargo glibc_musl_version 0.1.0 types/Version#minor., 41); |
| 128 | } |
| 129 | |
| 130 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 131 | fn parse_musl_from_ldd_outputrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/tests/parse_musl_from_ldd_output().() { |
| 132 | let out = "musl libc (x86_64)\nVersion 1.2.3\n"; |
| 133 | let parsed = parse_musl_versionrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/parse_musl_version().(out); |
| 134 | let parsed = parsed.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 135 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parsed.majorrust-analyzer cargo glibc_musl_version 0.1.0 types/Version#major., 1); |
| 136 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parsed.minorrust-analyzer cargo glibc_musl_version 0.1.0 types/Version#minor., 2); |
| 137 | |
| 138 | let out2 = "musl libc (x86_64) 1.3.0\n"; |
| 139 | let parsed2 = parse_musl_versionrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/parse_musl_version().(out2); |
| 140 | let parsed2 = parsed2.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 141 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parsed2.majorrust-analyzer cargo glibc_musl_version 0.1.0 types/Version#major., 1); |
| 142 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parsed2.minorrust-analyzer cargo glibc_musl_version 0.1.0 types/Version#minor., 3); |
| 143 | } |
| 144 | |
| 145 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 146 | fn get_version_fallbacksrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/tests/get_version_fallbacks().() { |
| 147 | let out = "some random output not containing versions"; |
| 148 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ldd_output_to_glibc_version_strrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/ldd_output_to_glibc_version_str().(out).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 149 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parse_musl_versionrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/parse_musl_version().(out).is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().()); |
| 150 | } |
| 151 | |
| 152 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 153 | fn get_os_libc_versions_both_nonerust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/tests/get_os_libc_versions_both_none().() { |
| 154 | // Simulate output with neither glibc nor musl present |
| 155 | let out = "random output without libc info"; |
| 156 | let glibc = parse_glibc_versionrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/parse_glibc_version().(out); |
| 157 | let musl = parse_musl_versionrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/parse_musl_version().(out); |
| 158 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(glibc.is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().()); |
| 159 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(musl.is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().()); |
| 160 | } |
| 161 | |
| 162 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 163 | fn get_os_libc_versions_glibc_onlyrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/tests/get_os_libc_versions_glibc_only().() { |
| 164 | // Simulate glibc output |
| 165 | let out = r#"ldd (GNU libc) 2.17\nCopyright (C) 2013 Free Software Foundation, Inc."#; |
| 166 | let glibc = parse_glibc_versionrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/parse_glibc_version().("2.17"); |
| 167 | let musl = parse_musl_versionrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/parse_musl_version().(out); |
| 168 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(glibc.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().()); |
| 169 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(musl.is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().()); |
| 170 | let v = glibc.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 171 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(v.majorrust-analyzer cargo glibc_musl_version 0.1.0 types/Version#major., 2); |
| 172 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(v.minorrust-analyzer cargo glibc_musl_version 0.1.0 types/Version#minor., 17); |
| 173 | } |
| 174 | |
| 175 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 176 | fn get_os_libc_versions_musl_onlyrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/tests/get_os_libc_versions_musl_only().() { |
| 177 | // Simulate musl output |
| 178 | let out = "musl libc (x86_64)\nVersion 1.1.24\n"; |
| 179 | let glibc = parse_glibc_versionrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/parse_glibc_version().(out); |
| 180 | let musl = parse_musl_versionrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/parse_musl_version().(out); |
| 181 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(glibc.is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().()); |
| 182 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(musl.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().()); |
| 183 | let v = musl.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 184 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(v.majorrust-analyzer cargo glibc_musl_version 0.1.0 types/Version#major., 1); |
| 185 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(v.minorrust-analyzer cargo glibc_musl_version 0.1.0 types/Version#minor., 1); |
| 186 | } |
| 187 | |
| 188 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 189 | fn libc_versions_displayrust-analyzer cargo glibc_musl_version 0.1.0 detect/detect_impl/tests/libc_versions_display().() { |
| 190 | let both = LibcVersionsrust-analyzer cargo glibc_musl_version 0.1.0 types/LibcVersions# { |
| 191 | glibcrust-analyzer cargo glibc_musl_version 0.1.0 types/LibcVersions#glibc.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Versionrust-analyzer cargo glibc_musl_version 0.1.0 types/Version# { majorrust-analyzer cargo glibc_musl_version 0.1.0 types/Version#major.: 2, minorrust-analyzer cargo glibc_musl_version 0.1.0 types/Version#minor.: 31 }), |
| 192 | muslrust-analyzer cargo glibc_musl_version 0.1.0 types/LibcVersions#musl.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Versionrust-analyzer cargo glibc_musl_version 0.1.0 types/Version# { majorrust-analyzer cargo glibc_musl_version 0.1.0 types/Version#major.: 1, minorrust-analyzer cargo glibc_musl_version 0.1.0 types/Version#minor.: 2 }), |
| 193 | }; |
| 194 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(both.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "glibc 2.31 | musl 1.2"); |
| 195 | let only_glibc = LibcVersionsrust-analyzer cargo glibc_musl_version 0.1.0 types/LibcVersions# { |
| 196 | glibcrust-analyzer cargo glibc_musl_version 0.1.0 types/LibcVersions#glibc.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Versionrust-analyzer cargo glibc_musl_version 0.1.0 types/Version# { majorrust-analyzer cargo glibc_musl_version 0.1.0 types/Version#major.: 2, minorrust-analyzer cargo glibc_musl_version 0.1.0 types/Version#minor.: 17 }), |
| 197 | muslrust-analyzer cargo glibc_musl_version 0.1.0 types/LibcVersions#musl.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 198 | }; |
| 199 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(only_glibc.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "glibc 2.17 | musl <not detected>"); |
| 200 | let only_musl = LibcVersionsrust-analyzer cargo glibc_musl_version 0.1.0 types/LibcVersions# { |
| 201 | glibcrust-analyzer cargo glibc_musl_version 0.1.0 types/LibcVersions#glibc.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 202 | muslrust-analyzer cargo glibc_musl_version 0.1.0 types/LibcVersions#musl.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Versionrust-analyzer cargo glibc_musl_version 0.1.0 types/Version# { majorrust-analyzer cargo glibc_musl_version 0.1.0 types/Version#major.: 1, minorrust-analyzer cargo glibc_musl_version 0.1.0 types/Version#minor.: 1 }), |
| 203 | }; |
| 204 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(only_musl.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "glibc <not detected> | musl 1.1"); |
| 205 | let none = LibcVersionsrust-analyzer cargo glibc_musl_version 0.1.0 types/LibcVersions# { |
| 206 | glibcrust-analyzer cargo glibc_musl_version 0.1.0 types/LibcVersions#glibc.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 207 | muslrust-analyzer cargo glibc_musl_version 0.1.0 types/LibcVersions#musl.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 208 | }; |
| 209 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(none.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "glibc <not detected> | musl <not detected>"); |
| 210 | } |
| 211 | } |