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

Adding support to creating custom schemes #225

Closed
wants to merge 1 commit into from
Closed

Adding support to creating custom schemes #225

wants to merge 1 commit into from

Conversation

marcelofabri
Copy link
Contributor

This adds basic support to creation of custom schemes on .liftoffrc:

schemes:
    - name: <%= project_name %>-CI
      actions:
          test:
              build_configuration: Debug-CI
          launch:
              build_configuration: Debug-CI
          profile:
              build_configuration: Release-CI
          archive:
              build_configuration: Release-CI
          analyze:
              build_configuration: Release-CI

actions can be test, launch, profile, archive or analyze and the only supported customization so far is build_configuration, but this can be extended to other options (such as "Launch due to background fetch").

I've done specifically for build_configuration but maybe we should support automatically (i.e. without having references in liftoff) all supported options in a scheme.

As my other PR, this still needs tests and documentation.

I'm also not particularly happy with the chain of ifs in create_schemes, but I couldn't figure a better way in Ruby (geez, I miss Objective-C nil behavior).

@gfontenot
Copy link
Member

Hey, sorry, I didn't forget about this. Promise. I'm going to look over these ASAP.

@marcelofabri
Copy link
Contributor Author

No problem!

@marcelofabri
Copy link
Contributor Author

@gfontenot Have you gotten a chance to look at this?

@bitcrumb
Copy link
Contributor

Would be awesome of this could get integrated anytime soon! 👍🏻

@jakecraige
Copy link
Contributor

Thanks for implementing this @marcelofabri ! I have a few things I'd like to see addressed if you're up for it.

First, Follow the thoughtbot Ruby style guide. I plan on enabling houndci.com soon once I have time to update the config, but until then we have to manually confirm we're following it.

A few violations I see here are:

  1. Avoid conditional modifiers (lines that end with conditionals).
  2. Prefer double quotes for strings.
  3. Use a trailing comma after each item in a multi-line list, including the last item.

Second, that large nested if structure. I see you aren't too happy with it either, one thing I'd suggest to clean it up is to extract methods out. If you take the content of each if and put it in it's own method that would be a great start. Another idea would be for the arrays to do variable || [] which would prevent checks before iterating over it. After those is likely you may spot some other optimizations to do.

Lastly, Docs and tests. You said this still needs them, are you waiting for us to approve the implementation before doing those tasks?

What do you think?

@marcelofabri
Copy link
Contributor Author

Thanks for the feedback, @jakecraige.

About the violations:

  1. OK
  2. This file already was using single quotes for strings. Is there a reason for using them where it's currently being used?
  3. Where have you seen this? I couldn't find it on this PR.

About the ifs: will do.

About docs and tests: I'd like an OK on the feature itself before spending too much time on them. Also, is there a easy way to edit the man help file?

I also would like some help to start the tests. I haven't found any tests on project_builder.rb.

@@ -20,7 +20,8 @@ class ProjectConfiguration
:xcode_command,
:extra_config,
:extra_test_config,
:deployment_target
:deployment_target,
:schemes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where the trailing comma is needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But isn't the rule only for lists? Is this any different than https://github.com/thoughtbot/guides/blob/master/style/ruby/sample.rb#L19? (I'm not a Ruby developer, so forgive me if I'm writing something dumb)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, what you linked to is a method definition. It's actually a syntax error there so we can't do it. The example that shows this case is here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I get an error if I try to add a comma:

liftoff/lib/liftoff/project_configuration.rb:26: syntax error, unexpected tSYMBEG, expecting keyword_do or '{' or '(' (SyntaxError)
    attr_writer :author,
                 ^

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops! I didn't see this was an attr_accessor list here. You're correct!

@jakecraige
Copy link
Contributor

For 2, it's something we'd like to change going forward so we can retro-actively change them over when we touch that part of the code. For this one, use double-quotes in your new code since you didn't alter any existing code that uses single ones. That make sense?

I'm not familiar with editing the man file actually, I'll defer to @gfontenot on that one to see if he has any tricks for that.

For the tests, You can look to the project_configuration_spec.rb for an example of how to set up the base spec.

From there I see 2 possibilities. the latter being my preferred approach:

  1. Set up a test forProjectBuilder#create_project method and run / assert that it creates the custom schemes. Since we don't have any test infrastructure to set up actual xcode projects, you'll probably have to do a bit of stubbing to get it all working properly.
  2. Extract a class like SchemeBuilder and move all your new code to there and test that. It'll be much easier to test that class in isolation than testing it through this ProjectBuilder.

What do you think?

@marcelofabri
Copy link
Contributor Author

@jakecraige I think I covered all the style violations and have dealt with the nested ifs. Could you please take a look if something is missing?

About the tests, I like the 2nd approach. However, to fully testing, I'd still need a project for creating a scheme, wouldn't I?

@jakecraige
Copy link
Contributor

My bad on the trailing comma stuff. I didn't notice that was an attr_reader and not an array.

It's looking much better now. Great work!

With the new class/testing, you'll probably need to stub out the Xcode project so that we don't need an actual one to work with. The new class would probably take the project as a param in the initializer do you could pass it a fake one and make assertions off of that.

xcode_project.generate_scheme

if @config.schemes
@config.schemes.each do |scheme_config|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are your thoughts on making a method called schemes that returns this config or an empty array to remove this conditional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@gfontenot
Copy link
Member

Also, is there a easy way to edit the man help file?

The man pages can be found here: https://github.com/thoughtbot/liftoff/tree/master/man

Editing them shouldn't be too difficult, but it's an intimidating format. Try looking at some similar examples (like the extra_config setting) and see if you can figure it out. If it's confusing, ping me and I'll help out.

@marcelofabri
Copy link
Contributor Author

@gfontenot: thanks!

@jakecraige: I've extracted the changes to another class. Could you please take a look? I'll try to get the tests and docs figured out later today.

@@ -0,0 +1,50 @@
module Liftoff
class SchemeBuilder

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this extra newline?

@jakecraige
Copy link
Contributor

Thanks for the great work!

@borwahs
Copy link

borwahs commented Aug 11, 2015

This feature looks awesome. Was thinking about working on this but glad someone beat me to it!

@marcelofabri - does this have the ability to define custom configuration (xcconfig) files with the custom schemes baked in?

@marcelofabri
Copy link
Contributor Author

@borwahs currently, no. My idea was to use this with #224, so you could have something like this in your .liftoffrc:

build_configurations:
    - name: Debug-CI
      type: debug
    - name: Release-CI
      type: release

extra_config:
    Debug-CI:
        GCC_PREPROCESSOR_DEFINITIONS:
           - $(inherited)
           - APP_CI=1
    Release-CI:
        GCC_PREPROCESSOR_DEFINITIONS:
           - $(inherited)
           - APP_CI=1

schemes:
    - name: <%= project_name %>-CI
      actions:
          test:
              build_configuration: Debug-CI
          launch:
              build_configuration: Debug-CI
          profile:
              build_configuration: Release-CI
          archive:
              build_configuration: Release-CI
          analyze:
              build_configuration: Release-CI

@borwahs
Copy link

borwahs commented Aug 12, 2015

@marcelofabri - that looks awesome. I'll be looking forward to it when it gets merged in!

@marcelofabri
Copy link
Contributor Author

@jakecraige Sorry for the delay, but I was able to play with this only today. I have done 2 tests around this, but I wasn't able to test an important part (the setup of buildConfigurations).

Do you have any ideas?

@marcelofabri
Copy link
Contributor Author

I was able to create a test by using a plain XCScheme (instead of mocking it).

I also updated Xcodeproj so I could use test_action & friends, avoiding digging into the scheme XML.

Unless I missed something, I think this is ready to merge! 😄

@marcelofabri marcelofabri changed the title [WIP] Adding support to creating custom schemes Adding support to creating custom schemes Aug 29, 2015
@jakecraige
Copy link
Contributor

Thanks! I'm traveling this weekend and beginning a new project next week so
I may not be able to take a look till late next week.
On Fri, Aug 28, 2015 at 11:32 PM Marcelo Fabri notifications@github.com
wrote:

I was able to create a test by using a plain XCScheme (instead of mocking
it).

I also updated Xcodeproj so I could use test_action & friends, avoiding
digging into the scheme XML.

Unless I missed something, I think this is ready to merge! [image:
😄]


Reply to this email directly or view it on GitHub
#225 (comment).

end

def create_schemes
@xcode_project.generate_default_scheme
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about making @xcode_project and @config private attr_readers and using that throughout this class to access them?

We have an open PR for our guides that recommends this that looks like it's probably going to be merged. thoughtbot/guides#331

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I keep using @xcode_project and @config Inside initialize?

@marcelofabri
Copy link
Contributor Author

@jakecraige Thanks for taking a look at this! I've just pushed 6ad5994, which fixes most of the comments you've made.

(test, launch, profile, archive or analyze). In order to create additional
schemes, you should add the
.Ic schemes
key in your
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this missing a word after "your"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because .Nm in the next line will be replaced by liftoffrc

@jakecraige
Copy link
Contributor

Code wise, this is looking great and I think it's ready to go! Thanks for being patient and working through this with me @marcelofabri

Could you squash the commits down?

@marcelofabri
Copy link
Contributor Author

@jakecraige Thanks for the help and all suggestions. It's definitely better now!

@jakecraige
Copy link
Contributor

Merged in 4c99412 Thanks again.

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

Successfully merging this pull request may close these issues.

5 participants