-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: infer library name from Cargo.toml
- Loading branch information
Showing
14 changed files
with
123 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:path/path.dart' as path; | ||
import 'package:toml/toml.dart'; | ||
|
||
class ManifestException { | ||
ManifestException(this.message, {required this.fileName}); | ||
|
||
final String? fileName; | ||
final String message; | ||
|
||
@override | ||
String toString() { | ||
if (fileName != null) { | ||
return 'Failed to parse package manifest at $fileName: $message'; | ||
} else { | ||
return 'Failed to parse package manifest: $message'; | ||
} | ||
} | ||
} | ||
|
||
class CrateInfo { | ||
CrateInfo({required this.packageName}); | ||
|
||
final String packageName; | ||
|
||
static CrateInfo parseManifest(String manifest, {final String? fileName}) { | ||
final toml = TomlDocument.parse(manifest); | ||
final package = toml.toMap()['package']; | ||
if (package == null) { | ||
throw ManifestException('Missing package section', fileName: fileName); | ||
} | ||
final name = package['name']; | ||
if (name == null) { | ||
throw ManifestException('Missing package name', fileName: fileName); | ||
} | ||
return CrateInfo(packageName: name); | ||
} | ||
|
||
static CrateInfo load(String manifestDir) { | ||
final manifestFile = File(path.join(manifestDir, 'Cargo.toml')); | ||
final manifest = manifestFile.readAsStringSync(); | ||
return parseManifest(manifest, fileName: manifestFile.path); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.