MCPcopy Create free account
hub / github.com/GraphiteEditor/Graphite / run

Function run

tools/third-party-licenses/src/main.rs:69–132  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

67}
68
69fn run() -> Result<(), Error> {
70 let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
71 let workspace_dir = PathBuf::from(env!("CARGO_WORKSPACE_DIR"));
72
73 #[cfg(feature = "desktop")]
74 let output_path = workspace_dir.join("desktop/third-party-licenses.txt.xz");
75 #[cfg(not(feature = "desktop"))]
76 let output_path = workspace_dir.join("frontend/third-party-licenses.txt");
77
78 #[cfg(feature = "desktop")]
79 let current_hash_path = manifest_dir.join("desktop.hash");
80 #[cfg(not(feature = "desktop"))]
81 let current_hash_path = manifest_dir.join("web.hash");
82
83 let cargo_source = CargoLicenseSource::new();
84 let npm_source = NpmLicenseSource::new(workspace_dir.join("frontend"));
85 #[cfg(feature = "desktop")]
86 let cef_source = CefLicenseSource::new();
87
88 let mut run = Run {
89 cargo: &cargo_source,
90 npm: &npm_source,
91 #[cfg(feature = "desktop")]
92 cef: &cef_source,
93 output: &fs::read(&output_path).unwrap_or_default(),
94 };
95
96 let mut hasher = DefaultHasher::new();
97 run.hash(&mut hasher);
98 let current_hash = format!("{:016x}", hasher.finish());
99
100 if current_hash == fs::read_to_string(&current_hash_path).unwrap_or_default() {
101 return Ok(());
102 }
103 eprintln!("Changes in licenses detected, generating new license file...");
104
105 let licenses = merge_filter_dedup_and_sort(vec![
106 cargo_source.licenses()?,
107 npm_source.licenses()?,
108 #[cfg(feature = "desktop")]
109 cef_source.licenses()?,
110 ]);
111 let formatted = format_credits(&licenses);
112
113 #[cfg(feature = "desktop")]
114 let output = compress(&formatted)?;
115 #[cfg(not(feature = "desktop"))]
116 let output = formatted.as_bytes().to_vec();
117 if let Some(parent) = output_path.parent() {
118 fs::create_dir_all(parent).map_err(|e| Error::Io(e, format!("Failed to create directory {}", parent.display())))?;
119 }
120 fs::write(&output_path, &output).map_err(|e| Error::Io(e, format!("Failed to write {}", output_path.display())))?;
121 run.output = &output;
122
123 let hash = {
124 let mut hasher = DefaultHasher::new();
125 run.hash(&mut hasher);
126 format!("{:016x}", hasher.finish())

Callers 1

mainFunction · 0.70

Calls 7

format_creditsFunction · 0.85
compressFunction · 0.85
writeFunction · 0.85
parentMethod · 0.80
readFunction · 0.70
hashMethod · 0.45

Tested by

no test coverage detected