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

bottle: add bottle stanza by traversing AST #9095

Merged
merged 2 commits into from
Dec 11, 2020

Conversation

SeekingMeaning
Copy link
Contributor

@SeekingMeaning SeekingMeaning commented Nov 9, 2020

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew tests with your changes locally?
  • Have you successfully run brew man locally and committed any changes?

This should improve brew bottle and make it 💥 less often by traversing the abstract syntax tree of a new formula and not using regex

Related: #9081 (comment)

@reitermarkus
Copy link
Member

Very nice.

Would be good to also have some tests with examples where the non-AST version broke before. Also, maybe move this into bottles.rb.

@SeekingMeaning SeekingMeaning added the in progress Maintainers are working on this label Nov 11, 2020
@MikeMcQuaid
Copy link
Member

I ❤️ this a LOT, thanks so much @SeekingMeaning! bump-revision would be another good candidate after this is merged. Agreed with @reitermarkus that some very basic tests and extracting it into another file would be great.

@SeekingMeaning
Copy link
Contributor Author

I'm not sure if this is too long for testing one example:

  context "when `license` is simple" do
    let(:formula_contents) do
      <<~RUBY.chomp
        class Foobar < Formula
          desc "Foobar"
          license "GPL-3.0"
        end
      RUBY
    end

    let(:new_contents) do
      <<~RUBY.chomp
        class Foobar < Formula
          desc "Foobar"
          license "GPL-3.0"

          bottle do
            sha256 "123" => :cat
          end
        end
      RUBY
    end

    it "adds `bottle` after `license`" do
      described_class.add_bottle_stanza! formula_contents, bottle_output
      expect(formula_contents).to eq(new_contents)
    end
  end

Context:

describe "#add_bottle_stanza!" do
  let(:bottle_output) do
    require "active_support/core_ext/string/indent"

    <<~RUBY.chomp.indent(2)
      bottle do
        sha256 "123" => :cat
      end
    RUBY
  end

  # above code block example goes here

  # more examples
end

@MikeMcQuaid
Copy link
Member

@SeekingMeaning Doesn't seem too long to me!

Library/Homebrew/dev-cmd/bottle.rb Outdated Show resolved Hide resolved
Library/Homebrew/dev-cmd/bottle.rb Outdated Show resolved Hide resolved
@MikeMcQuaid
Copy link
Member

This is looking great @SeekingMeaning! A few nits but I'm 👍🏻 to merge this whenever.

@SeekingMeaning
Copy link
Contributor Author

As COMPONENTS_BEFORE_BOTTLE comes directly from components_order.rb, is it okay to have this "duplicate" list in bottles.rb, or should I extract out component_precedence_list into a static constant? And if so, where would be a good place for this constant?

@MikeMcQuaid
Copy link
Member

As COMPONENTS_BEFORE_BOTTLE comes directly from components_order.rb, is it okay to have this "duplicate" list in bottles.rb, or should I extract out component_precedence_list into a static constant? And if so, where would be a good place for this constant?

Maybe something like Library/Homebrew/tap_constants.rb: Library/Homebrew/bottle_constants.rb?

@SeekingMeaning
Copy link
Contributor Author

@MikeMcQuaid
Copy link
Member

@SeekingMeaning Yeh, I'm suggesting it might be good to extract a constant from both places. Alternatively, just require the rubocop module in the bottle code (can't do the other way around as RuboCop needs to be independent of the Homebrew code).

@iMichka iMichka mentioned this pull request Dec 9, 2020
7 tasks
@BrewTestBot
Copy link
Member

Review period ended.

@SeekingMeaning SeekingMeaning marked this pull request as ready for review December 10, 2020 21:25
@SeekingMeaning SeekingMeaning marked this pull request as draft December 10, 2020 21:27
@SeekingMeaning
Copy link
Contributor Author

Linux gives this error:

Error: cannot load such file -- rubocop-ast

@SeekingMeaning SeekingMeaning marked this pull request as ready for review December 10, 2020 21:47
@iMichka
Copy link
Member

iMichka commented Dec 11, 2020

Looks similar to: Homebrew/discussions#265

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

👍🏻 to merge once CI is 💚.

Library/Homebrew/utils/bottles.rb Show resolved Hide resolved
@MikeMcQuaid
Copy link
Member

Yup, that suggested change fixed CI 🎉. Not merging yet because this has the potential to cause homebrew-core issues so I want to wait until @SeekingMeaning is around to respond quickly to any if needed. Nice work here 👏🏻

Copy link
Member

@iMichka iMichka left a comment

Choose a reason for hiding this comment

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

Same here, really cool work. I'll let @SeekingMeaning merge and monitor stuff in case there is any issue.

@SeekingMeaning
Copy link
Contributor Author

Thanks guys! This should only affect new formulae added to homebrew-core but I'll try to keep an eye on everything just in case.

@SeekingMeaning SeekingMeaning merged commit 85373df into Homebrew:master Dec 11, 2020
@BrewTestBot BrewTestBot added the outdated PR was locked due to age label Jan 11, 2021
@Homebrew Homebrew locked as resolved and limited conversation to collaborators Jan 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
in progress Maintainers are working on this outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants