MCPcopy Create free account
hub / github.com/bytecodealliance/wstd / read_crate

Function read_crate

ci/publish.rs:127–184  ·  view source on GitHub ↗
(ws: Option<&Workspace>, manifest: &Path)

Source from the content-addressed store, hash-verified

125}
126
127fn read_crate(ws: Option<&Workspace>, manifest: &Path) -> Crate {
128 let mut name = None;
129 let mut version = None;
130 let mut workspace_version = None;
131 let mut publish = true;
132 let mut in_workspace = false;
133 for line in fs::read_to_string(manifest).unwrap().lines() {
134 if line.starts_with("[") {
135 in_workspace = line.starts_with("[workspace");
136 continue;
137 }
138
139 if name.is_none() && line.starts_with("name = \"") {
140 name = Some(
141 line.replace("name = \"", "")
142 .replace("\"", "")
143 .trim()
144 .to_string(),
145 );
146 }
147 if line.starts_with("version = \"") {
148 let dst = if in_workspace {
149 &mut workspace_version
150 } else {
151 &mut version
152 };
153 assert!(dst.is_none());
154 *dst = Some(
155 line.replace("version = \"", "")
156 .replace("\"", "")
157 .trim()
158 .to_string(),
159 );
160 }
161 if let Some(ws) = ws {
162 if version.is_none() && line.starts_with("version") && line.contains("workspace = true")
163 {
164 version = Some(ws.version.clone());
165 }
166 }
167 if line.starts_with("publish = false") {
168 publish = false;
169 }
170 }
171 let name = name.unwrap();
172 let version = if !publish {
173 "0.0.0".to_string()
174 } else {
175 version.or(workspace_version.clone()).unwrap()
176 };
177 Crate {
178 manifest: manifest.to_path_buf(),
179 name,
180 version,
181 workspace_version,
182 publish,
183 }
184}

Callers 2

mainFunction · 0.85
find_cratesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected