Skip to content

Commit f308868

Browse files
committed
Move srcsrv URL parsing to MappedPath::from_url.
1 parent 1da9b15 commit f308868

File tree

4 files changed

+76
-39
lines changed

4 files changed

+76
-39
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samply-symbols/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ debugid = "0.8.0"
5151
flate2 = "1"
5252
yoke = { version = "0.6.2", features = ["derive"] }
5353
nom = "7.1.1"
54+
lazy_static = "1.4.0"
5455

5556
[dev-dependencies]
5657
memmap2 = "0.5.0"

samply-symbols/src/mapped_path.rs

+69
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
use lazy_static::lazy_static;
12
use nom::branch::alt;
23
use nom::bytes::complete::{tag, take_until1};
34
use nom::combinator::{eof, map};
45
use nom::error::ErrorKind;
56
use nom::sequence::terminated;
67
use nom::{Err, IResult};
8+
use regex::Regex;
79

810
/// A special source file path for source files which are hosted online.
911
///
@@ -68,6 +70,43 @@ impl MappedPath {
6870
}
6971
}
7072

73+
/// Detect some URLs of plain text files and convert them to a `MappedPath`.
74+
pub fn from_url(url: &str) -> Option<Self> {
75+
lazy_static! {
76+
static ref GITHUB_REGEX: Regex = Regex::new(r"^https://raw\.githubusercontent\.com/(?P<repo>[^/]+/[^/]+)/(?P<rev>[^/]+)/(?P<path>.*)$").unwrap();
77+
static ref HG_REGEX: Regex = Regex::new(r"^https://(?P<repo>hg\..+)/raw-file/(?P<rev>[0-9a-f]+)/(?P<path>.*)$").unwrap();
78+
static ref S3_REGEX: Regex = Regex::new(r"^https://(?P<bucket>[^/]+).s3.amazonaws.com/(?P<digest>[^/]+)/(?P<path>.*)$").unwrap();
79+
}
80+
if let Some(captures) = GITHUB_REGEX.captures(url) {
81+
// https://raw.githubusercontent.com/baldurk/renderdoc/v1.15/renderdoc/data/glsl/gl_texsample.h
82+
// -> "git:github.com/baldurk/renderdoc:renderdoc/data/glsl/gl_texsample.h:v1.15"
83+
let repo = format!("github.com/{}", captures.name("repo").unwrap().as_str());
84+
let path = captures.name("path").unwrap().as_str().to_owned();
85+
let rev = captures.name("rev").unwrap().as_str().to_owned();
86+
Some(MappedPath::Git { repo, path, rev })
87+
} else if let Some(captures) = HG_REGEX.captures(url) {
88+
// "https://hg.mozilla.org/mozilla-central/raw-file/1706d4d54ec68fae1280305b70a02cb24c16ff68/mozglue/baseprofiler/core/ProfilerBacktrace.cpp"
89+
// -> "hg:hg.mozilla.org/mozilla-central:mozglue/baseprofiler/core/ProfilerBacktrace.cpp:1706d4d54ec68fae1280305b70a02cb24c16ff68"
90+
let repo = captures.name("repo").unwrap().as_str().to_owned();
91+
let path = captures.name("path").unwrap().as_str().to_owned();
92+
let rev = captures.name("rev").unwrap().as_str().to_owned();
93+
Some(MappedPath::Hg { repo, path, rev })
94+
} else if let Some(captures) = S3_REGEX.captures(url) {
95+
// "https://gecko-generated-sources.s3.amazonaws.com/7a1db5dfd0061d0e0bcca227effb419a20439aef4f6c4e9cd391a9f136c6283e89043d62e63e7edbd63ad81c339c401092bcfeff80f74f9cae8217e072f0c6f3/x86_64-pc-windows-msvc/release/build/swgl-59e3a0e09f56f4ea/out/brush_solid_DEBUG_OVERDRAW.h"
96+
// -> "s3:gecko-generated-sources:7a1db5dfd0061d0e0bcca227effb419a20439aef4f6c4e9cd391a9f136c6283e89043d62e63e7edbd63ad81c339c401092bcfeff80f74f9cae8217e072f0c6f3/x86_64-pc-windows-msvc/release/build/swgl-59e3a0e09f56f4ea/out/brush_solid_DEBUG_OVERDRAW.h:"
97+
let bucket = captures.name("bucket").unwrap().as_str().to_owned();
98+
let digest = captures.name("digest").unwrap().as_str().to_owned();
99+
let path = captures.name("path").unwrap().as_str().to_owned();
100+
Some(MappedPath::S3 {
101+
bucket,
102+
digest,
103+
path,
104+
})
105+
} else {
106+
None
107+
}
108+
}
109+
71110
/// Serialize this mapped path to a string, using the "special path" syntax.
72111
pub fn to_special_path_str(&self) -> String {
73112
match self {
@@ -197,6 +236,16 @@ mod test {
197236
rev: "997f00815e6bc28806b75448c8829f0259d2cb28".to_string(),
198237
})
199238
);
239+
assert_eq!(
240+
MappedPath::from_url(
241+
"https://hg.mozilla.org/mozilla-central/raw-file/1706d4d54ec68fae1280305b70a02cb24c16ff68/mozglue/baseprofiler/core/ProfilerBacktrace.cpp"
242+
),
243+
Some(MappedPath::Hg {
244+
repo: "hg.mozilla.org/mozilla-central".to_string(),
245+
path: "mozglue/baseprofiler/core/ProfilerBacktrace.cpp".to_string(),
246+
rev: "1706d4d54ec68fae1280305b70a02cb24c16ff68".to_string(),
247+
})
248+
);
200249
}
201250

202251
#[test]
@@ -231,6 +280,16 @@ mod test {
231280
rev: "dab1161c861cc239e48a17e1a5d729aa12785a53".to_string(),
232281
})
233282
);
283+
assert_eq!(
284+
MappedPath::from_url(
285+
"https://raw.githubusercontent.com/baldurk/renderdoc/v1.15/renderdoc/data/glsl/gl_texsample.h"
286+
),
287+
Some(MappedPath::Git {
288+
repo: "github.com/baldurk/renderdoc".to_string(),
289+
path: "renderdoc/data/glsl/gl_texsample.h".to_string(),
290+
rev: "v1.15".to_string(),
291+
})
292+
);
234293
}
235294

236295
#[test]
@@ -256,6 +315,16 @@ mod test {
256315
digest: "4fd754dd7ca7565035aaa3357b8cd99959a2dddceba0fc2f7018ef99fd78ea63d03f9bf928afdc29873089ee15431956791130b97f66ab8fcb88ec75f4ba6b04".to_string(),
257316
})
258317
);
318+
assert_eq!(
319+
MappedPath::from_url(
320+
"https://gecko-generated-sources.s3.amazonaws.com/7a1db5dfd0061d0e0bcca227effb419a20439aef4f6c4e9cd391a9f136c6283e89043d62e63e7edbd63ad81c339c401092bcfeff80f74f9cae8217e072f0c6f3/x86_64-pc-windows-msvc/release/build/swgl-59e3a0e09f56f4ea/out/brush_solid_DEBUG_OVERDRAW.h"
321+
),
322+
Some(MappedPath::S3 {
323+
bucket: "gecko-generated-sources".to_string(),
324+
path: "x86_64-pc-windows-msvc/release/build/swgl-59e3a0e09f56f4ea/out/brush_solid_DEBUG_OVERDRAW.h".to_string(),
325+
digest: "7a1db5dfd0061d0e0bcca227effb419a20439aef4f6c4e9cd391a9f136c6283e89043d62e63e7edbd63ad81c339c401092bcfeff80f74f9cae8217e072f0c6f3".to_string(),
326+
})
327+
);
259328
}
260329

261330
#[test]

samply-symbols/src/windows.rs

+5-39
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,6 @@ where
324324
struct SrcSrvPathMapper<'a> {
325325
srcsrv_stream: srcsrv::SrcSrvStream<'a>,
326326
cache: HashMap<String, Option<MappedPath>>,
327-
github_regex: Regex,
328-
hg_regex: Regex,
329-
s3_regex: Regex,
330327
gitiles_regex: Regex,
331328
command_is_file_download_with_url_in_var4_and_uncompress_function_in_var5: bool,
332329
}
@@ -342,7 +339,7 @@ impl<'a> ExtraPathMapper for SrcSrvPathMapper<'a> {
342339
.source_and_raw_var_values_for_path(path, "C:\\Dummy")
343340
{
344341
Ok(Some((srcsrv::SourceRetrievalMethod::Download { url }, _map))) => {
345-
self.url_to_mapped_path(&url)
342+
MappedPath::from_url(&url)
346343
}
347344
Ok(Some((srcsrv::SourceRetrievalMethod::ExecuteCommand { .. }, map))) => {
348345
// We're not going to execute a command here.
@@ -364,10 +361,10 @@ impl<'a> SrcSrvPathMapper<'a> {
364361
SrcSrvPathMapper {
365362
srcsrv_stream,
366363
cache: HashMap::new(),
367-
github_regex: Regex::new(r"^https://raw\.githubusercontent\.com/(?P<repo>[^/]+/[^/]+)/(?P<rev>[^/]+)/(?P<path>.*)$").unwrap(),
368-
hg_regex: Regex::new(r"^https://(?P<repo>hg\..+)/raw-file/(?P<rev>[0-9a-f]+)/(?P<path>.*)$").unwrap(),
369-
s3_regex: Regex::new(r"^https://(?P<bucket>[^/]+).s3.amazonaws.com/(?P<digest>[^/]+)/(?P<path>.*)$").unwrap(),
370-
gitiles_regex: Regex::new(r"^https://(?P<repo>.+)\.git/\+/(?P<rev>[^/]+)/(?P<path>.*)\?format=TEXT$").unwrap(),
364+
gitiles_regex: Regex::new(
365+
r"^https://(?P<repo>.+)\.git/\+/(?P<rev>[^/]+)/(?P<path>.*)\?format=TEXT$",
366+
)
367+
.unwrap(),
371368
command_is_file_download_with_url_in_var4_and_uncompress_function_in_var5,
372369
}
373370
}
@@ -434,37 +431,6 @@ impl<'a> SrcSrvPathMapper<'a> {
434431
let rev = captures.name("rev").unwrap().as_str().to_owned();
435432
Some(MappedPath::Git { repo, path, rev })
436433
}
437-
438-
fn url_to_mapped_path(&self, url: &str) -> Option<MappedPath> {
439-
if let Some(captures) = self.github_regex.captures(url) {
440-
// https://raw.githubusercontent.com/baldurk/renderdoc/v1.15/renderdoc/data/glsl/gl_texsample.h
441-
// -> "git:github.com/baldurk/renderdoc:renderdoc/data/glsl/gl_texsample.h:v1.15"
442-
let repo = captures.name("repo").unwrap().as_str().to_owned();
443-
let path = captures.name("path").unwrap().as_str().to_owned();
444-
let rev = captures.name("rev").unwrap().as_str().to_owned();
445-
Some(MappedPath::Git { repo, path, rev })
446-
} else if let Some(captures) = self.hg_regex.captures(url) {
447-
// "https://hg.mozilla.org/mozilla-central/raw-file/1706d4d54ec68fae1280305b70a02cb24c16ff68/mozglue/baseprofiler/core/ProfilerBacktrace.cpp"
448-
// -> "hg:hg.mozilla.org/mozilla-central:mozglue/baseprofiler/core/ProfilerBacktrace.cpp:1706d4d54ec68fae1280305b70a02cb24c16ff68"
449-
let repo = captures.name("repo").unwrap().as_str().to_owned();
450-
let path = captures.name("path").unwrap().as_str().to_owned();
451-
let rev = captures.name("rev").unwrap().as_str().to_owned();
452-
Some(MappedPath::Hg { repo, path, rev })
453-
} else if let Some(captures) = self.s3_regex.captures(url) {
454-
// "https://gecko-generated-sources.s3.amazonaws.com/7a1db5dfd0061d0e0bcca227effb419a20439aef4f6c4e9cd391a9f136c6283e89043d62e63e7edbd63ad81c339c401092bcfeff80f74f9cae8217e072f0c6f3/x86_64-pc-windows-msvc/release/build/swgl-59e3a0e09f56f4ea/out/brush_solid_DEBUG_OVERDRAW.h"
455-
// -> "s3:gecko-generated-sources:7a1db5dfd0061d0e0bcca227effb419a20439aef4f6c4e9cd391a9f136c6283e89043d62e63e7edbd63ad81c339c401092bcfeff80f74f9cae8217e072f0c6f3/x86_64-pc-windows-msvc/release/build/swgl-59e3a0e09f56f4ea/out/brush_solid_DEBUG_OVERDRAW.h:"
456-
let bucket = captures.name("bucket").unwrap().as_str().to_owned();
457-
let digest = captures.name("digest").unwrap().as_str().to_owned();
458-
let path = captures.name("path").unwrap().as_str().to_owned();
459-
Some(MappedPath::S3 {
460-
bucket,
461-
digest,
462-
path,
463-
})
464-
} else {
465-
None
466-
}
467-
}
468434
}
469435

470436
fn has_debug_info(func: &pdb_addr2line::FunctionFrames) -> bool {

0 commit comments

Comments
 (0)