dart_xcodeproj 0.4.0
dart_xcodeproj: ^0.4.0 copied to clipboard
Dart library for parsing and working with Xcode projects. Manipulates .xcodeproj, .xcworkspace, .xcscheme, and .xcconfig files. Pure Dart, cross-platform (macOS, Windows, Linux), zero native code.
Changelog #
0.4.0 #
Breaking Changes #
- The minimum Dart SDK is now 3.11 (was 3.9 in
pubspec.yaml). It was already the effective floor, since thexml^7 dependency requires Dart 3.11, so on Dart 3.9 and 3.10 the package could not be resolved XCScheme.buildAction,testAction,launchAction,profileAction,analyzeActionandarchiveActionno longer add an element to the document when the scheme lacks it. Like Ruby'sXCScheme#launch_actionand friends they return a default action that is not saved until it is assigned, and the same instance on every call, so reading a getter never changes whatsavewrites. Code that relied on the getter attaching the missing element must now assign it (scheme.testAction = scheme.testAction)ObjectGraph.newObjecttakes a new optionaluuidparameter (see Features): classes implementingObjectGraphmust accept itAbstractObject.asciiPlistAnnotationis nowString?:null(no annotation) for the main group.AsciiPlistWriter.writegiven a plain map no longer annotates anything, only the annotated nodes ofAbstractObject.toAsciiPlist()are printedXCConfigurationList.getSettingreturnsMap<String, dynamic>(wasMap<String, String?>),AbstractTarget.resolvedBuildSettingreturnsMap<String, dynamic>andcommonResolvedBuildSettingreturnsdynamic, because array settings such asLD_RUNPATH_SEARCH_PATHSare returned as lists instead of throwing aTypeError. Code that assigned the result to aString?map or value needs a castAbstractObject.removeReferenceis no longer a no-op: it is generic, driven by the newtoOneAttributes,toManyAttributesandreferencesByKeysAttributeshooks. A subclass ofAbstractObjectthat holds references and overroderemoveReferenceshould declare its attributes through these hooks (subclasses append tosuper's lists) instead- The saved output of a project can change: pbxproj annotations now come only from the object model, objects are registered in Ruby's load order, and removing a file reference, group or reference proxy removes its build files too (see Bug Fixes)
Bug Fixes #
XCSchemeoutput is well-formed XML:SchemeXmlFormatterescapes& < > "in attribute values (and\n,\r,\tas , ,	) and keeps comments and non-blank text nodes, so opening and saving a pristine FlutterRunner.xcscheme(whose PreActionscriptTexthas"/ ) round-trips byte-identically. Entities beyond those, such as', are decoded by the XML parser instead of preserved verbatim, which is equivalent- Saving a project no longer guesses
/* ... */annotations from the shape of strings: the pbxproj writer prints only the annotations carried by the object model, like Ruby'sProject#to_ascii_plist. String attributes that hold a UUID (remoteGlobalIDString,TestTargetID) are no longer annotated, and an open + save of a pristine Flutter iOS/macOS project now matches what Ruby writes PBXReferenceProxyannotatespathby its basename,XCConfigurationListreadsBuild configuration list for <isa> "<name>"from its owner, andXCBuildConfiguration.displayNameis itsnamePBXTargetDependency.displayNamefalls back to the proxy'sremoteInfo(a dependency on a target of another project), andPBXBuildRule.displayNameis itsname, like Ruby'sdisplay_nameUuidGenerator.isValidaccepts the 32-char uppercase hex UUIDs thatpredictabilizeUuidsand CocoaPods write (andgenerateDeterministicreturns), next to the 24-char ones, so such projects keep their annotations. RFC4122, lowercase, non-hex and other lengths are still rejected- Batches of random UUIDs exclude the ones already in
objectsByUuid(and the ones already generated), like Ruby'sgenerate_available_uuid_list, so a collision can no longer replace an existing object.UuidGenerator.generatetakes an optionalrandomandXcodeProject.uuidRandomlets tests inject one AbstractObject.removeReferenceremoves the object from the to-one, to-many and dictionary attributes that point to it, like Ruby'sremove_reference.buildFile.removeFromProject()no longer leaves its UUID in thefilesof the build phase (it was written to disk), and removing an object held inPBXProject.projectReferencesno longer leaves the project among its referrersPBXFileReference.removeFromProjectandPBXReferenceProxy.removeFromProjectremove their build files first (and so their entry in the build phases) instead of leaving an empty{isa = PBXBuildFile; }behind; the container proxy of a reference proxy goes with it once nothing else refers to it.PBXGroup.removeFromProject(alsoPBXVariantGroupandXCVersionGroup) clears the group, so its descendants go too, and removes the build files that point to the group or to them. Unlike Ruby, which only removes the group's own build files, the build files of the descendants are removed as wellXCConfigurationList.getSetting(and soresolvedBuildSettingandcommonResolvedBuildSetting) no longer throws aTypeErroron array-valued settings such asLD_RUNPATH_SEARCH_PATHSorOTHER_LDFLAGS;$(inherited)is spliced into array values and values are de-duplicated with deep equality, like RubyGroupableHelper.realPathresolves the leading.and..of a path against its source tree like Ruby'sPathname#+(<DIR>/Runner+../Flutter/xis<DIR>/Flutter/x, not<DIR>/Runner/../Flutter/x)AbstractTarget.resolvedBuildSetting(and socommonResolvedBuildSetting) includes the configurations only the project has, with the project value, like Ruby'sHash#merge: a target withDebugandReleasein a project that also hasProfilenow sees the three, and the consistency check ofcommonResolvedBuildSettingcounts the project'sProfilevalue tooXcodeProject.openregisters the objects in the order Ruby loads them (depth first from the root object, plain attributes before to-one before to-many references), soobjectsByUuid,filesandgroupslist them in that order. Objects the root does not reach come last- A new
PBXShellScriptBuildPhasehas Ruby's placeholder script (# Type a script or drag a script file from your workspace to insert its path.) instead of# Type a script...
Features #
- Annotated plist output:
AbstractObject.toAsciiPlist()/toAsciiPlistHash()and theAnnotatedString/AnnotatedDictionaryplist nodes, whichAsciiPlistWriterprints annotations from PBXProject.name,PBXContainerItemProxy.isRemoteandPBXGroup.isMainGroupXcodeProject.newObject(andObjectGraph.newObject) takes an optionaluuidso tools that create objects idempotently can pin stable UUIDs. A UUID that is invalid perUuidGenerator.isValidor already present inobjectsByUuidthrows anArgumentErrorand never replaces the registered object; withoutuuida generated one is used as before. This is new API: Ruby only offers the privateKlass.new(project, uuid)UuidGenerator.deterministic(seed, {length = 24})returns the first 24 or 32 uppercase hex characters of the MD5 ofseed, so tools can create stable, Xcode-looking 24-char UUIDs. Withlength: 32it equalsgenerateDeterministic(Ruby'suuid_for_path); any other length throws anArgumentError. Truncation raises the collision odds, so namespace seeds, e.g.tool/<target>/<thing>XcodeProject.predictabilizeUuids()replaces every UUID of the project with the MD5 of the structural path of its object, ported from Ruby'sProject#predictabilize_uuids(the saved file is byte-identical to xcodeproj's on the Flutter iOS and macOS projects). Object references,containerPortal,remoteGlobalIDStringand theTargetAttributeskeys andTestTargetIDs are rewritten together, so no UUID is left dangling. Files outside the project that refer to its UUIDs, such as theBlueprintIdentifierof a scheme, are not rewritten. Objects with the same path share a UUID (a warning is logged), and objects the root cannot reach keep theirs (aStateErroris thrown, and the project left as it was, if one of them already has the UUID a reachable object would get). The paths include the build settings as they are in the model (a space separated string stays one, like Ruby) and the UUIDs held as strings by the proxies of target dependencies, so the output is reproducible only if those areUuidGenerator.structuralPathsreturns the structural path of every object of a project, andAbstractObject.toManyAttributeKeys/referencesByKeysAttributeKeysexpose the plist keys those paths are made ofPBXNativeTarget.sourceBuildPhase,frameworksBuildPhase,resourcesBuildPhaseandheadersBuildPhasereturn the build phase of that class, creating and appending it tobuildPhaseswhen the target has none, like Ruby'sfind_or_create_build_phase_by_class. Unlike Ruby they do not memoize it, so a phase removed from the target is created againPBXNativeTarget.addFileReferences(refs, {compilerFlags, onBuildFile})adds a build file per reference to the sources phase, or to the headers phase for a header extension (any case), reusing the build file a reference already has. A non-emptycompilerFlagsis appended, after a space, to theCOMPILER_FLAGSof the build file of a source file (even when they repeat, like Ruby) andonBuildFilestands for Ruby's block. A reference without apaththrows anArgumentErrorbefore anything is added, where Ruby raises aTypeErrormidway.PBXNativeTarget.addResources(refs)does the same for the resources phase, skipping references it already has. Neither creates a phase when given no referenceAbstractTarget.shellScriptBuildPhasesandcopyFilesBuildPhaseslist the phases of that class,newShellScriptBuildPhase([name])andnewCopyFilesBuildPhase([name])append a new one tobuildPhases(a new phase every time) andbuildConfigurationsreturns the configurations of the target's configuration list (aStateErrorwhen it has none). The output on the Flutter iOS and macOS projects is byte-identical to xcodeproj'sPBXGroup.findSubpath(path, {create}),findFileByPath(path),recursiveChildren,clear/removeChildrenRecursivelyandbuildFiles(also onPBXFileReferenceandPBXReferenceProxy), ported from xcodeproj.findSubpathwalks/separated names matched against Ruby'sdisplay_name(a group without name and path has none, so only''or'/'find it), the first match wins, andcreate: trueadds aPBXGroupfor each missing name. It returns anAbstractObject?, as Ruby returns files too, and throws aStateErrorwhere Ruby raisesNoMethodError(a file in the middle of the path)XcodeProject.nativeTargets(thePBXNativeTargets oftargets, without aggregate and legacy ones) andXcodeProject.referenceForPath(absolutePath), which returns the firstPBXFileReferencewhose real path isabsolutePath(anArgumentErrorfor a relative one; it is not normalized, like Ruby'sPathname#==).GroupableHelper.realPathhas a newprojectDirparameter, for projects opened from a relative path.referenceForPathanchorsSOURCE_ROOTpaths at the absolute project directory the project had when it was opened or created, so changingDirectory.currentafterwards does not move it (Ruby'sproject_diris absolute fromProject.newon)XCConfigurationList.setSetting(key, value)sets one build setting in every configuration of the list and leaves the other keys alone,XCConfigurationList.buildSettings(name)andAbstractTarget.buildSettings(name)return the live settings map of the named configuration (nullfor an unknown name), so a key level edit no longer needs to replacebuildSettingswholesale. The same instance of an array value is stored in each configuration, like RubyAbstractTarget.addBuildConfiguration(name, type)adds a configuration with the default settings of Ruby for the platform, deployment target and product type of the target, appends it tobuildConfigurationsand returns the existing configuration, untouched, when the name is taken. It usesAbstractTarget.sdk,platformNameanddeploymentTarget, also new. Like Ruby, deployment targets compare as strings ('13.0' < '5', so a new iOS 13 configuration getsCLANG_ENABLE_OBJC_WEAK = NO). A target without configuration list throws aStateErrorwhere Ruby raises aNoMethodError. The output on the Flutter iOS and macOS projects is byte-identical to xcodeproj'sProjectHelper.commonBuildSettingsaccepts anullplatform and adeploymentTarget, and returns copies of the constantsXCScheme.buildAction,testAction,launchAction,profileAction,analyzeActionandarchiveActionnow have setters, like Ruby'sXCScheme#launch_action=and friends: the first existing element is removed and the action is appended to<Scheme>(a copy, if it already belongs to a document). The getters return the typed actions, soscheme.launchAction.buildConfiguration = 'Debug-dev'changes only that attribute and keeps every other attribute,PreActions/PostActionsand unknown child element as they were
0.3.0 #
Bug Fixes #
EnvironmentVariables.assignVariableandCommandLineArguments.assignArgumentnow replace any existing entry with the same key/argument instead of appending a duplicate, matching xcodeproj's update-by-key semantics
Features #
TestActionnow exposesmacroExpansionsandaddMacroExpansion, matching CocoaPods xcodeproj'sTestAction#add_macro_expansion(inserted beforeTestableswhen present)ShellScriptActionContentnow exposesbuildableReference(get/set), matching xcodeproj'sShellScriptActionContent#buildable_reference, so a pre/post-build shell script can run within a specific target's build environmentTestActionnow exposescodeCoverageTargets/addCodeCoverageTarget, matching xcodeproj's per-target code coverage filtering (flipsonlyGenerateCoverageForSpecifiedTargets)TestableReferencenow exposesparallelizable,testExecutionOrdering/randomized,skippedTests/addSkippedTest,selectedTests/addSelectedTest,useTestSelectionWhitelist, andremoveBuildableReference, matching xcodeproj's test-selection and execution controls
0.2.0 #
- Updated
propertylistserializationandxmldependencies to latest versions
0.1.1 #
Bug Fixes #
- Export all scheme types from public barrel (
BuildableProductRunnable,BuildableReference,BuildAction,LaunchAction,TestAction,AnalyzeAction,ArchiveAction,ProfileAction, and related types)
0.1.0 #
Initial release. Dart library for parsing and working with Xcode projects, heavily inspired by CocoaPods XcodeProj and xcode.
Features #
- ASCII plist read/write with byte-identical round-trip
- Full PBX object model (25+ ISA types) with reference counting
XcodeProjectopen / create / mutate / saveXCWorkspace,XCScheme,XcConfigread/write- UUID-agnostic
Differfor project comparison - CLI:
show,sort,project-diff,config-dump - Zero native code; runs on macOS, Linux, Windows