@@ -109,7 +109,7 @@ struct GeneratorCommand: CommandPlugin {
109109
110110 // keep for now as a reminder to check if args are processed, or not
111111 let tool = try context. tool ( named: " objectbox-generator " )
112- print ( " Processing arguments:: \( arguments) " )
112+ print ( " Processing arguments: \( arguments) " )
113113 if arguments. count == 1 {
114114 if arguments [ 0 ] == " context " {
115115 dump ( context)
@@ -131,7 +131,7 @@ struct GeneratorCommand: CommandPlugin {
131131 if targets. count > 1 {
132132 let availableTargetNames = targets. map { $0. name } . joined ( separator: " , " )
133133 Diagnostics . error (
134- " Multiple targets found \n Please select specify one target by using the `--target name` option \n Available target names: \( availableTargetNames) "
134+ " Multiple targets found \n Please select specify one target by using the `--target < name> ` option \n Available target names: \( availableTargetNames) "
135135 )
136136 return
137137 } else if targets. isEmpty {
@@ -170,37 +170,40 @@ struct GeneratorCommand: CommandPlugin {
170170 Diagnostics . error (
171171 """
172172 \( targetNames. count) target names given: \( targetNames)
173- Please select exact 1 target
173+ Please select exactly 1 target
174174 """ )
175+ return
175176 }
176177
177178 let targetName = targetNames [ 0 ]
178179
179180 var inputFiles : PackagePlugin . FileList ?
180181 for target in context. xcodeProject. targets {
181182 if target. product? . name == targetName {
182- Diagnostics . remark ( " Found target \( targetName) " )
183+ Diagnostics . remark ( " Found target \( targetName) \n " )
183184 inputFiles = target. inputFiles
184185 }
185186 }
186187
188+ // This is some additional validation that the Xcode target has Swift source files.
189+ // However, this appears to not work for all Xcode targets, so just print warnings
190+ // and continue anyhow as the generator might still find source files (it looks based on the directory).
187191 if inputFiles == nil {
188- Diagnostics . warning ( " Target \( targetName) has no files " )
189- return
190- }
191-
192- var sourcesArgs : [ String ] = [ ]
193- for inputFile in inputFiles! {
194- if inputFile. path. string. hasSuffix ( " .swift " ) {
195- sourcesArgs. append ( " --sources " )
196- sourcesArgs. append ( inputFile. path. string)
192+ // File list can be empty, but should never be nil
193+ Diagnostics . warning ( " Target \( targetName) has no files, generator might fail \n " )
194+ } else {
195+ var swiftSourceFiles : [ String ] = [ ]
196+ for inputFile in inputFiles! {
197+ if inputFile. path. string. hasSuffix ( " .swift " ) {
198+ swiftSourceFiles. append ( inputFile. path. string)
199+ }
197200 }
198- }
199201
200- if sourcesArgs. isEmpty {
201- // TODO probably error
202- Diagnostics . warning ( " No Swift files found in Target \( targetName) " )
203- return
202+ if swiftSourceFiles. isEmpty {
203+ // Just warn instead of error in case this is run on a target that has no Swift files
204+ Diagnostics . warning (
205+ " No Swift files found in Target \( targetName) , model might be empty \n " )
206+ }
204207 }
205208
206209 let targetPath = context. xcodeProject. directory
@@ -213,10 +216,10 @@ struct GeneratorCommand: CommandPlugin {
213216
214217 // TODO Add the generated files to the Xcode project
215218 Diagnostics . remark (
216- " ! Add the generated source file in ' \( codeFilePath) ' to the project and version control "
219+ " ! Add the generated source file in ' \( codeFilePath) ' to the project and version control \n "
217220 )
218221 Diagnostics . remark (
219- " ! Add the generated model file in ' \( modelFilePath) ' to version control, this is important for ObjectBox model generation "
222+ " ! Add the generated model file in ' \( modelFilePath) ' to version control, this is important for ObjectBox model generation \n "
220223 )
221224
222225 }
0 commit comments