Skip to content

Commit

Permalink
ref: move pbxproj to top level
Browse files Browse the repository at this point in the history
  • Loading branch information
kkharji committed Jun 7, 2022
1 parent fbd07f9 commit a4c4b26
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
#![deny(rustdoc::broken_intra_doc_links)]
#![doc = include_str!("../README.md")]

mod parser;
pub use parser::pbxproj;
pub mod pbxproj;
1 change: 0 additions & 1 deletion src/parser/mod.rs

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
191 changes: 191 additions & 0 deletions src/pbxproj/object/product_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
use tap::Pipe;

/// Target Product Type
#[derive(Default, Debug, Hash, PartialEq, Eq)]
pub enum PBXProductType {
/// Application
Application,
/// Framework
Framework,
/// StaticFramework
StaticFramework,
/// XcFramework
XcFramework,
/// DynamicLibrary
DynamicLibrary,
/// StaticLibrary
StaticLibrary,
/// Bundle
Bundle,
/// UnitTestBundle
UnitTestBundle,
/// UiTestBundle
UiTestBundle,
/// AppExtension
AppExtension,
/// CommandLineTool
CommandLineTool,
/// WatchApp
WatchApp,
/// Watch2App
Watch2App,
/// Watch2AppContainer
Watch2AppContainer,
/// WatchExtension
WatchExtension,
/// Watch2Extension
Watch2Extension,
/// TvExtension
TvExtension,
/// MessagesApplication
MessagesApplication,
/// MessagesExtension
MessagesExtension,
/// StickerPack
StickerPack,
/// XpcService
XpcService,
/// OcUnitTestBundle
OcUnitTestBundle,
/// XcodeExtension
XcodeExtension,
/// InstrumentsPackage
InstrumentsPackage,
/// IntentsServiceExtension
IntentsServiceExtension,
/// OnDemandInstallCapableApplication
OnDemandInstallCapableApplication,
/// MetalLibrary
MetalLibrary,
/// DriverExtension
DriverExtension,
/// SystemExtension
SystemExtension,
/// None Identified
#[default]
None,
}

impl PBXProductType {
/// Return file extension for product type
pub fn file_extension(&self) -> Option<&str> {
use PBXProductType::*;
match self {
Application
| WatchApp
| Watch2App
| Watch2AppContainer
| MessagesApplication
| OnDemandInstallCapableApplication => "app",
AppExtension
| TvExtension
| WatchExtension
| Watch2Extension
| MessagesExtension
| StickerPack
| XcodeExtension
| IntentsServiceExtension => "appex",
Framework | StaticFramework => "framework",
UnitTestBundle | UiTestBundle => "xctest",
DynamicLibrary => "dylib",
StaticLibrary => "a",
Bundle => "bundle",
XpcService => "xpc",
OcUnitTestBundle => "octest",
InstrumentsPackage => "instrpkg",
XcFramework => "xcframework",
MetalLibrary => "metallib",
SystemExtension => "systemextension",
DriverExtension => "dext",
_ => return Option::None,
}
.pipe(Some)
}
}

impl std::fmt::Display for PBXProductType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
use PBXProductType::*;
let value = match self {
Application => "com.apple.product-type.application",
Framework => "com.apple.product-type.framework",
StaticFramework => "com.apple.product-type.framework.static",
XcFramework => "com.apple.product-type.xcframework",
DynamicLibrary => "com.apple.product-type.library.dynamic",
StaticLibrary => "com.apple.product-type.library.static",
Bundle => "com.apple.product-type.bundle",
UnitTestBundle => "com.apple.product-type.bundle.unit-test",
UiTestBundle => "com.apple.product-type.bundle.ui-testing",
AppExtension => "com.apple.product-type.app-extension",
CommandLineTool => "com.apple.product-type.tool",
WatchApp => "com.apple.product-type.application.watchapp",
Watch2App => "com.apple.product-type.application.watchapp2",
Watch2AppContainer => "com.apple.product-type.application.watchapp2-container",
WatchExtension => "com.apple.product-type.watchkit-extension",
Watch2Extension => "com.apple.product-type.watchkit2-extension",
TvExtension => "com.apple.product-type.tv-app-extension",
MessagesApplication => "com.apple.product-type.application.messages",
MessagesExtension => "com.apple.product-type.app-extension.messages",
StickerPack => "com.apple.product-type.app-extension.messages-sticker-pack",
XpcService => "com.apple.product-type.xpc-service",
OcUnitTestBundle => "com.apple.product-type.bundle.ocunit-test",
XcodeExtension => "com.apple.product-type.xcode-extension",
InstrumentsPackage => "com.apple.product-type.instruments-package",
IntentsServiceExtension => "com.apple.product-type.app-extension.intents-service",
OnDemandInstallCapableApplication => {
"com.apple.product-type.application.on-demand-install-capable"
}
MetalLibrary => "com.apple.product-type.metal-library",
DriverExtension => "com.apple.product-type.driver-extension",
SystemExtension => "com.apple.product-type.system-extension",
None => return Ok(()),
};
write!(f, "{value}")
}
}

impl From<&str> for PBXProductType {
fn from(value: &str) -> Self {
use PBXProductType::*;
match value {
"com.apple.product-type.application" => Application,
"com.apple.product-type.framework" => Framework,
"com.apple.product-type.framework.static" => StaticFramework,
"com.apple.product-type.xcframework" => XcFramework,
"com.apple.product-type.library.dynamic" => DynamicLibrary,
"com.apple.product-type.library.static" => StaticLibrary,
"com.apple.product-type.bundle" => Bundle,
"com.apple.product-type.bundle.unit-test" => UnitTestBundle,
"com.apple.product-type.bundle.ui-testing" => UiTestBundle,
"com.apple.product-type.app-extension" => AppExtension,
"com.apple.product-type.tool" => CommandLineTool,
"com.apple.product-type.application.watchapp" => WatchApp,
"com.apple.product-type.application.watchapp2" => Watch2App,
"com.apple.product-type.application.watchapp2-container" => Watch2AppContainer,
"com.apple.product-type.watchkit-extension" => WatchExtension,
"com.apple.product-type.watchkit2-extension" => Watch2Extension,
"com.apple.product-type.tv-app-extension" => TvExtension,
"com.apple.product-type.application.messages" => MessagesApplication,
"com.apple.product-type.app-extension.messages" => MessagesExtension,
"com.apple.product-type.app-extension.messages-sticker-pack" => StickerPack,
"com.apple.product-type.xpc-service" => XpcService,
"com.apple.product-type.bundle.ocunit-test" => OcUnitTestBundle,
"com.apple.product-type.xcode-extension" => XcodeExtension,
"com.apple.product-type.instruments-package" => InstrumentsPackage,
"com.apple.product-type.app-extension.intents-service" => IntentsServiceExtension,
"com.apple.product-type.application.on-demand-install-capable" => {
OnDemandInstallCapableApplication
}
"com.apple.product-type.metal-library" => MetalLibrary,
"com.apple.product-type.driver-extension" => DriverExtension,
"com.apple.product-type.system-extension" => SystemExtension,
_ => None,
}
}
}

impl From<String> for PBXProductType {
fn from(s: String) -> Self {
PBXProductType::from(s.as_str())
}
}
File renamed without changes.
2 changes: 1 addition & 1 deletion src/parser/pbxproj/pest/mod.rs → src/pbxproj/pest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use tap::Pipe;

/// Pest Parser to parse into [`XProj`]
#[derive(Parser)]
#[grammar = "parser/pbxproj/pest/grammar.pest"]
#[grammar = "pbxproj/pest/grammar.pest"]
pub(crate) struct PBXProjectParser;

pub(crate) type NodeResult<T> = std::result::Result<T, Error<Rule>>;
Expand Down
6 changes: 3 additions & 3 deletions src/parser/pbxproj/rep.rs → src/pbxproj/rep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,21 @@ impl PBXProjectData {
#[test]
#[ignore = "check_output"]
fn test_parse() {
let test_content = include_str!("../../../tests/samples/demo1.pbxproj");
let test_content = include_str!("../../tests/samples/demo1.pbxproj");
let project = PBXProjectData::try_from(test_content).unwrap();
println!("{project:#?}");
}

#[test]
fn test_extract_string() {
let test_content = include_str!("../../../tests/samples/demo1.pbxproj");
let test_content = include_str!("../../tests/samples/demo1.pbxproj");
let project = PBXProjectData::try_from(test_content).unwrap();
// let development_region = project.extract_string("development_region");
// assert_eq!(Some(&String::from("en")), development_region);
}
#[test]
fn test_extract_value() {
let test_content = include_str!("../../../tests/samples/demo2.pbxproj");
let test_content = include_str!("../../tests/samples/demo2.pbxproj");
let project = PBXProjectData::try_from(test_content).unwrap();
// let has_scanned_for_encodings = project.extract_value("has_scanned_for_encodings");
// let targets = project.extract_value("targets");
Expand Down
File renamed without changes.

0 comments on commit a4c4b26

Please sign in to comment.