Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Objc mode bad handling of -x and --framework-root together #900

Closed
awgeorge opened this issue Nov 2, 2017 · 3 comments
Closed

Objc mode bad handling of -x and --framework-root together #900

awgeorge opened this issue Nov 2, 2017 · 3 comments
Labels

Comments

@awgeorge
Copy link

awgeorge commented Nov 2, 2017

It looks like the #603 #518 added the ability to recursively add subdirs, by added -I parameters.

However, if you also specify xcodebuild-arguments then the additional arguments are prepended to the command creating:

['doc', '-I', 'FolderPath', '-I', 'FolderPath/Subdir1', '-I', 'FolderPath/Subdir2', '--objc', 'Module/Module.h', '--', '-x', 'objective-c', '-isysroot', '*.sdk', '-fmodules']

Which fails with the following error:

Unrecognized arguments: -I, -I, -I
	from /Library/Ruby/Gems/2.3.0/gems/jazzy-0.9.0/lib/jazzy/sourcekitten.rb:221:in `run_sourcekitten'
	from /Library/Ruby/Gems/2.3.0/gems/jazzy-0.9.0/lib/jazzy/doc_builder.rb:66:in `block in build'
	from /Library/Ruby/Gems/2.3.0/gems/jazzy-0.9.0/lib/jazzy/doc_builder.rb:64:in `chdir'
	from /Library/Ruby/Gems/2.3.0/gems/jazzy-0.9.0/lib/jazzy/doc_builder.rb:64:in `build'
	from /Library/Ruby/Gems/2.3.0/gems/jazzy-0.9.0/bin/jazzy:15:in `<top (required)>'
	from /usr/local/bin/jazzy:22:in `load'
	from /usr/local/bin/jazzy:22:in `<main>'

The -I flags are required to go at the end so a valid command is:

['doc', '--objc', 'Module/Module.h', '--', '-x', 'objective-c', '-isysroot', '*.sdk', '-I', 'FolderPath', '-I', 'FolderPath/Subdir1', '-I', 'FolderPath/Subdir2', '-fmodules']

I've highlighted where I think the problem lies:

    # Builds SourceKitten arguments based on Jazzy options
    def self.arguments_from_options(options)
      arguments = ['doc']
      arguments += if options.objc_mode
                     objc_arguments_from_options(options) ### <---------- 1) This is called
                   elsif !options.module_name.empty?
                     ['--module-name', options.module_name, '--']
                   else
                     ['--']
                   end
      arguments + options.xcodebuild_arguments ### <---------- 3) Before this
    end

    def self.objc_arguments_from_options(options)
      arguments = []
      if options.xcodebuild_arguments.empty?
        arguments += ['--objc', options.umbrella_header.to_s, '--', '-x',
                      'objective-c', '-isysroot',
                      `xcrun --show-sdk-path --sdk #{options.sdk}`.chomp,
                      '-I', options.framework_root.to_s,
                      '-fmodules']
      end
      # add additional -I arguments for each subdirectory of framework_root
      unless options.framework_root.nil?
        rec_path(Pathname.new(options.framework_root.to_s)).collect do |child|
          if child.directory?
            arguments += ['-I', child.to_s]   ### <---------- 2) Which adds these
          end
        end
      end
      arguments
    end

Meaning that you could probably do:

    # Builds SourceKitten arguments based on Jazzy options
    def self.arguments_from_options(options)
      arguments = ['doc']
      arguments += if options.objc_mode
                     objc_arguments_from_options(options)
                   elsif !options.module_name.empty?
                     ['--module-name', options.module_name, '--']
                   else
                     ['--']
                   end
      arguments + options.xcodebuild_arguments

      # add additional -I arguments for each subdirectory of framework_root
      unless options.framework_root.nil?
        rec_path(Pathname.new(options.framework_root.to_s)).collect do |child|
          if child.directory?
            arguments += ['-I', child.to_s]  
          end
        end
      end
    end

    def self.objc_arguments_from_options(options)
      arguments = []
      if options.xcodebuild_arguments.empty?
        arguments += ['--objc', options.umbrella_header.to_s, '--', '-x',
                      'objective-c', '-isysroot',
                      `xcrun --show-sdk-path --sdk #{options.sdk}`.chomp,
                      '-I', options.framework_root.to_s,
                      '-fmodules']
      end
      arguments
    end
@johnfairh
Copy link
Collaborator

johnfairh commented Nov 5, 2017

Thanks for the report. Jazzy doesn't expect the user to do both --xcodebuild-arguments and --framework-root. We definitely need to improve the documentation of Objective-C mode and make the code more robust.

@johnfairh johnfairh changed the title objc_arguments_from_options is prepending -I which causes Unrecognized arguments: -I error Objc mode bad handling of -x and --framework-root together Nov 10, 2017
@johnfairh johnfairh added the bug label Nov 10, 2017
@bitomaxsp
Copy link

Three years later i am googling exactly the same issue. Docs are still where they were :)

@johnfairh
Copy link
Collaborator

Added warning and objective-c docs in master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants