Skip to content

Commit ce7c4f6

Browse files
committed
feat(pbxproj): add file
1 parent c3cc42a commit ce7c4f6

File tree

8 files changed

+435
-8
lines changed

8 files changed

+435
-8
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ enum_variant_macros = "0.2.0"
3030
md-5 = "0.10.1"
3131
rand = "0.8.5"
3232
base16ct = "0.1.1"
33+
phf = "0.10.1"
3334

3435
[dev-dependencies]
3536
tracing-test = "0.2.1"
@@ -38,3 +39,6 @@ once_cell = "1.12.0"
3839
[features]
3940
default = [ "tracing" ]
4041
tracing = [ "dep:tracing", "tracing-appender", "tracing-subscriber" ]
42+
43+
[build-dependencies]
44+
phf_codegen = "0.10.0"

build.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use std::env;
2+
use std::fs::File;
3+
use std::io::Write;
4+
use std::path::Path;
5+
6+
use phf_codegen::Map;
7+
8+
fn main() {
9+
let out_dir = env::var("OUT_DIR").unwrap();
10+
let ref mut f = File::create(Path::new(&out_dir).join("file_types.rs")).unwrap();
11+
let mut map: Map<&str> = phf_codegen::Map::new();
12+
let txt = include_str!("./res/file_type.txt");
13+
14+
txt.lines().for_each(|line| {
15+
let (key, value) = line.split_once(": ").unwrap();
16+
map.entry(key, &format!("\"{value}\""));
17+
});
18+
19+
let map = map.build();
20+
let base = "static XCODE_FILE_TYPES: phf::Map<&'static str, &'static str>";
21+
22+
write!(f, "{base} = \n{map};\n",).unwrap();
23+
}

res/file_type.txt

Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
1: text.man
2+
C: sourcecode.cpp.cpp
3+
H: sourcecode.cpp.h
4+
M: sourcecode.cpp.objcpp
5+
a: archive.ar
6+
ada: sourcecode.ada
7+
adb: sourcecode.ada
8+
ads: sourcecode.ada
9+
aiff: audio.aiff
10+
air: compiled.air
11+
apinotes: text.apinotes
12+
apns: text
13+
app: wrapper.application
14+
appex: wrapper.app-extension
15+
applescript: sourcecode.applescript
16+
archivingdescription: text.xml.ibArchivingDescription
17+
asdictionary: archive.asdictionary
18+
asm: sourcecode.asm.asm
19+
atlas: folder.skatlas
20+
au: audio.au
21+
avi: video.avi
22+
bin: archive.macbinary
23+
bmp: image.bmp
24+
bundle: wrapper.cfbundle
25+
c: sourcecode.c.c
26+
c++: sourcecode.cpp.cpp
27+
cc: sourcecode.cpp.cpp
28+
cdda: audio.aiff
29+
cl: sourcecode.opencl
30+
class: compiled.javaclass
31+
classdescription: text.plist.ibClassDescription
32+
classdescriptions: text.plist.ibClassDescription
33+
clp: sourcecode.clips
34+
cp: sourcecode.cpp.cpp
35+
cpp: sourcecode.cpp.cpp
36+
csh: text.script.csh
37+
css: text.css
38+
ctrl: sourcecode.glsl
39+
cxx: sourcecode.cpp.cpp
40+
d: sourcecode.dtrace
41+
dSYM: wrapper.dsym
42+
dae: text.xml.dae
43+
defs: sourcecode.mig
44+
dext: wrapper.driver-extension
45+
dict: text.plist
46+
docc: folder.documentationcatalog
47+
dsym: wrapper.dsym
48+
dtd: text.xml
49+
dylan: sourcecode.dylan
50+
dylib: compiled.mach-o.dylib
51+
ear: archive.ear
52+
entitlements: text.plist.entitlements
53+
eval: sourcecode.glsl
54+
exp: sourcecode.exports
55+
f: sourcecode.fortran
56+
f77: sourcecode.fortran.f77
57+
f90: sourcecode.fortran.f90
58+
f95: sourcecode.fortran.f90
59+
for: sourcecode.fortran
60+
frag: sourcecode.glsl
61+
fragment: sourcecode.glsl
62+
framework: wrapper.framework
63+
fs: sourcecode.glsl
64+
fsh: sourcecode.glsl
65+
geom: sourcecode.glsl
66+
geometry: sourcecode.glsl
67+
gif: image.gif
68+
gmk: sourcecode.make
69+
gpx: text.xml
70+
gs: sourcecode.glsl
71+
gsh: sourcecode.glsl
72+
gz: archive.gzip
73+
h: sourcecode.c.h
74+
h++: sourcecode.cpp.h
75+
hh: sourcecode.cpp.h
76+
hp: sourcecode.cpp.h
77+
hpp: sourcecode.cpp.h
78+
hqx: archive.binhex
79+
htm: text.html
80+
html: text.html
81+
htmld: wrapper.htmld
82+
hxx: sourcecode.cpp.h
83+
i: sourcecode.c.c.preprocessed
84+
icns: image.icns
85+
ico: image.ico
86+
iconset: folder.iconset
87+
ii: sourcecode.cpp.cpp.preprocessed
88+
iig: sourcecode.iig
89+
imagecatalog: folder.imagecatalog
90+
inc: sourcecode.pascal
91+
instrdst: com.apple.instruments.instrdst
92+
instrpkg: com.apple.instruments.package-definition
93+
intentdefinition: file.intentdefinition
94+
ipp: sourcecode.cpp.h
95+
jam: sourcecode.jam
96+
jar: archive.jar
97+
java: sourcecode.java
98+
javascript: sourcecode.javascript
99+
jpeg: image.jpeg
100+
jpg: image.jpeg
101+
js: sourcecode.javascript
102+
jscript: sourcecode.javascript
103+
json: text.json
104+
jsp: text.html.other
105+
kext: wrapper.kernel-extension
106+
l: sourcecode.lex
107+
lid: sourcecode.dylan
108+
ll: sourcecode.asm.llvm
109+
llx: sourcecode.asm.llvm
110+
lm: sourcecode.lex
111+
lmm: sourcecode.lex
112+
lp: sourcecode.lex
113+
lpp: sourcecode.lex
114+
lxx: sourcecode.lex
115+
m: sourcecode.c.objc
116+
mak: sourcecode.make
117+
make: sourcecode.make
118+
map: sourcecode.module-map
119+
markdown: net.daringfireball.markdown
120+
md: net.daringfireball.markdown
121+
mdimporter: wrapper.spotlight-importer
122+
mdown: net.daringfireball.markdown
123+
metal: sourcecode.metal
124+
metallib: archive.metal-library
125+
mi: sourcecode.c.objc.preprocessed
126+
mid: audio.midi
127+
midi: audio.midi
128+
mig: sourcecode.mig
129+
mii: sourcecode.cpp.objcpp.preprocessed
130+
mlkitmodel: file.mlmodel
131+
mlmodel: file.mlmodel
132+
mm: sourcecode.cpp.objcpp
133+
modulemap: sourcecode.module-map
134+
moov: video.quicktime
135+
mov: video.quicktime
136+
mp3: audio.mp3
137+
mpeg: video.mpeg
138+
mpg: video.mpeg
139+
mpkg: wrapper.installer-mpkg
140+
nasm: sourcecode.nasm
141+
nib: wrapper.nib
142+
nib~: wrapper.nib
143+
nqc: sourcecode.nqc
144+
o: compiled.mach-o.objfile
145+
octest: wrapper.cfbundle
146+
p: sourcecode.pascal
147+
pas: sourcecode.pascal
148+
pbfilespec: text.plist.pbfilespec
149+
pblangspec: text.plist.pblangspec
150+
pbxproj: text.pbxproject
151+
pch: sourcecode.c.h
152+
pch++: sourcecode.cpp.h
153+
pct: image.pict
154+
pdf: image.pdf
155+
perl: text.script.perl
156+
php: text.script.php
157+
php3: text.script.php
158+
php4: text.script.php
159+
phtml: text.script.php
160+
pict: image.pict
161+
pkg: wrapper.installer-pkg
162+
pl: text.script.perl
163+
playground: file.playground
164+
plist: text.plist
165+
pluginkit: wrapper.app-extension
166+
pm: text.script.perl
167+
png: image.png
168+
pp: sourcecode.pascal
169+
ppob: archive.ppob
170+
proto: sourcecode.protobuf
171+
py: text.script.python
172+
qtz: video.quartz-composer
173+
r: sourcecode.rez
174+
rb: text.script.ruby
175+
rbw: text.script.ruby
176+
rcproject: file.rcproject
177+
rcx: compiled.rcx
178+
rez: sourcecode.rez
179+
rhtml: text.html.other
180+
rsrc: archive.rsrc
181+
rtf: text.rtf
182+
rtfd: wrapper.rtfd
183+
s: sourcecode.asm
184+
scnassets: wrapper.scnassets
185+
scncache: wrapper.scncache
186+
scnp: file.scp
187+
scriptSuite: text.plist.scriptSuite
188+
scriptTerminology: text.plist.scriptTerminology
189+
sh: text.script.sh
190+
shtml: text.html.other
191+
sit: archive.stuffit
192+
sks: file.sks
193+
skybox: file.skybox
194+
sqlite: file
195+
storyboard: file.storyboard
196+
storyboardc: wrapper.storyboardc
197+
strings: text.plist.strings
198+
stringsdict: text.plist.stringsdict
199+
swift: sourcecode.swift
200+
systemextension: wrapper.system-extension
201+
tar: archive.tar
202+
tbd: sourcecode.text-based-dylib-definition
203+
tcc: sourcecode.cpp.cpp
204+
text: net.daringfireball.markdown
205+
tif: image.tiff
206+
tiff: image.tiff
207+
ttf: file
208+
txt: text
209+
uicatalog: file.uicatalog
210+
usdz: file.usdz
211+
vert: sourcecode.glsl
212+
vertex: sourcecode.glsl
213+
view: archive.rsrc
214+
vs: sourcecode.glsl
215+
vsh: sourcecode.glsl
216+
war: archive.war
217+
wav: audio.wav
218+
worksheet: text.script.worksheet
219+
xcassets: folder.assetcatalog
220+
xcbuildrules: text.plist.xcbuildrules
221+
xcclassmodel: wrapper.xcclassmodel
222+
xcconfig: text.xcconfig
223+
xcdatamodel: wrapper.xcdatamodel
224+
xcdatamodeld: wrapper.xcdatamodeld
225+
xcfilelist: text.xcfilelist
226+
xcframework: wrapper.xcframework
227+
xclangspec: text.plist.xclangspec
228+
xcmappingmodel: wrapper.xcmappingmodel
229+
xcode: wrapper.pb-project
230+
xcodeproj: wrapper.pb-project
231+
xconf: text.xml
232+
xcplaygroundpage: file.xcplaygroundpage
233+
xcspec: text.plist.xcspec
234+
xcstickers: folder.stickers
235+
xcsynspec: text.plist.xcsynspec
236+
xctarget: wrapper.pb-target
237+
xctest: wrapper.cfbundle
238+
xctxtmacro: text.plist.xctxtmacro
239+
xcworkspace: wrapper.workspace
240+
xhtml: text.xml
241+
xib: file.xib
242+
xmap: text.xml
243+
xml: text.xml
244+
xpc: wrapper.xpc-service
245+
xsl: text.xml
246+
xslt: text.xml
247+
xsp: text.xml
248+
y: sourcecode.yacc
249+
yaml: text.yaml
250+
ym: sourcecode.yacc
251+
yml: text.yaml
252+
ymm: sourcecode.yacc
253+
yp: sourcecode.yacc
254+
ypp: sourcecode.yacc
255+
yxx: sourcecode.yacc
256+
zip: archive.zip

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77

88
mod macros;
99
pub mod pbxproj;
10+
pub mod xcode;

src/pbxproj/object/collection.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,16 @@ impl PBXObjectCollection {
6161
pub(crate) fn get_fs_references<'a>(
6262
&'a self,
6363
predict: fn(Ref<PBXFSReference>) -> bool,
64-
) -> Vec<(String, Rc<RefCell<PBXFSReference>>)> {
64+
) -> impl Iterator<Item = (String, Rc<RefCell<PBXFSReference>>)> + 'a {
6565
self.iter()
66-
.filter(|o| {
66+
.filter(move |o| {
6767
if let Some(fs_reference) = o.1.as_pbxfs_reference() {
6868
predict(fs_reference.borrow())
6969
} else {
7070
false
7171
}
7272
})
7373
.map(|(k, o)| (k.clone(), o.as_pbxfs_reference().unwrap().clone()))
74-
.collect()
7574
}
7675

7776
pub(crate) fn fs_references<'a>(&'a self) -> Vec<(String, Rc<RefCell<PBXFSReference>>)> {
@@ -84,6 +83,7 @@ impl PBXObjectCollection {
8483
/// Get all PBXGroup
8584
pub fn groups<'a>(&'a self) -> Vec<(String, Rc<RefCell<PBXFSReference>>)> {
8685
self.get_fs_references(|fs_reference| fs_reference.is_group())
86+
.collect()
8787
}
8888

8989
/// Get PBXGroup with by name or path
@@ -115,6 +115,7 @@ impl PBXObjectCollection {
115115
/// Get all files
116116
pub fn files<'a>(&'a self) -> Vec<(String, Rc<RefCell<PBXFSReference>>)> {
117117
self.get_fs_references(|fs_reference| fs_reference.is_file())
118+
.collect()
118119
}
119120

120121
/// Get all PBXBuildFile

src/pbxproj/object/fs/full_path.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ impl PBXFSReference {
2929
let mut group_path: PathBuf;
3030

3131
if let Some(parent) = self.parent() {
32-
println!("Using parent path");
3332
group_path = parent.borrow().full_path(&source_root)?;
3433
if let Some(path) = self.path() {
3534
group_path.extend(get_parts(path))
@@ -51,16 +50,12 @@ impl PBXFSReference {
5150
if let Some(path) = self.path() {
5251
let mut root = source_root.to_path_buf();
5352
root.extend(get_parts(path));
54-
println!("Joining {source_root:?} with {path:?}");
5553
return Ok(root);
5654
} else {
57-
println!("Self is main group and return source_root as is!");
5855
return Ok(source_root.to_path_buf());
5956
}
6057
}
6158

62-
println!("Falling back to search through all groups");
63-
6459
// Fallback if parent is nil and it's not root element
6560
let group = objects
6661
.groups()
@@ -147,6 +142,7 @@ mod tests {
147142
.map(|name| name == "GuessView.swift")
148143
.unwrap_or_default()
149144
})
145+
.collect::<Vec<_>>()
150146
.first()
151147
.map(|(_, o)| o.clone())
152148
.unwrap();

0 commit comments

Comments
 (0)