New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(capture_webrender): write webrender revision into text #20320
Merged
+69
−2
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6b16e71
build(mach): generate webrender revision via cargo lockfile
kwonoj 0671fcb
feat(capture_webrender): write webrender revision into text
kwonoj f923097
refactor(build): generate revision via build.rs
kwonoj b957f6a
refactor(build): generate revision into out_dir
kwonoj 5f69773
style(capture_webrender): use eprintln for error output
kwonoj File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.
refactor(build): generate revision via build.rs
- Loading branch information
kwonoj
committed
Mar 23, 2018
kwonoj
OJ Kwon
commit f9230975f54c3777219ba09d784557b3841f7acc
Verified
This commit was signed with a verified signature.
GPG key ID: 2E469434030C7F09
Learn about signing commits
Some generated files are not rendered by default. Learn more.
Oops, something went wrong.
| @@ -0,0 +1,65 @@ | ||
| /* This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
|
||
| extern crate toml; | ||
|
|
||
| use std::env; | ||
| use std::fs::File; | ||
| use std::io::{Read, Write}; | ||
|
|
||
| const WEBRENDER_REVISION_TEMPLATE: &'static str = | ||
| "/* This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
| /// auto-generated by cargo. do not manually modify. | ||
| pub const REVISION: &'static str = "; | ||
|
|
||
| fn main() { | ||
| let current_path = env::current_dir().expect("Failed to access path to lockfile"); | ||
| let lockfile_path = current_path.join("..").join("..").join("Cargo.lock"); | ||
| let revision_file_path = current_path.join("webrender_revision.rs"); | ||
|
||
|
|
||
| let mut existing_revision_exported = String::new(); | ||
| match File::open(&revision_file_path) { | ||
| Ok(mut f) => { | ||
| f.read_to_string(&mut existing_revision_exported).unwrap_or_default(); | ||
| }, | ||
| Err(_) => () | ||
| } | ||
|
|
||
| let mut lockfile = String::new(); | ||
| File::open(lockfile_path).expect("Cannot open lockfile") | ||
| .read_to_string(&mut lockfile) | ||
| .expect("Failed to read lockfile"); | ||
|
|
||
| match toml::from_str::<toml::value::Table>(&lockfile) { | ||
| Ok(result) => { | ||
| let packages = result.get("package").expect("Cargo lockfile should contain package list"); | ||
|
|
||
| match *packages { | ||
| toml::Value::Array(ref arr) => { | ||
| let source = arr | ||
| .iter() | ||
| .find(|pkg| pkg.get("name").and_then(|name| name.as_str()).unwrap_or("") == "webrender") | ||
| .and_then(|pkg| pkg.get("source").and_then(|source| source.as_str())) | ||
| .unwrap_or("unknown"); | ||
|
|
||
| let parsed: Vec<&str> = source.split("#").collect(); | ||
| let revision = if parsed.len() > 1 { parsed[1] } else { source }; | ||
|
|
||
| if let Some(_) = existing_revision_exported.find(revision) { | ||
| return | ||
| } | ||
|
|
||
| let revision_contents = format!("{}\"{}\";", WEBRENDER_REVISION_TEMPLATE, revision); | ||
| let mut revision_module_file = File::create(&revision_file_path).unwrap(); | ||
| write!(&mut revision_module_file, "{}", revision_contents).unwrap(); | ||
| }, | ||
| _ => panic!("Cannot find package definitions in lockfile") | ||
| } | ||
| }, | ||
| Err(e) => panic!(e) | ||
| } | ||
| } | ||
ProTip!
Use n and p to navigate between commits in a pull request.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Rather than creating a file in the source directory, we should use the OUT_DIR environment variable and then include the file like this.