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

Test generation for Servo_* bindings in `components/style/gecko_bindings/bindings.rs` #13603

Closed
wants to merge 141 commits into from

Conversation

@Rafagd
Copy link
Contributor

Rafagd commented Oct 5, 2016

Added a python script that takes all Servo_* bindings generated in components/style/gecko_bindings/bindings.rs and generates a new test file that checks if they all have the same signature as the bindings on ports/geckolib/glue.rs.

Issue asks for both files to be created at the same folder components/style/gecko_bindings/bindings.rs is located.

#13598

  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #13598 (github issue number if applicable).
  • There are tests for these changes OR
  • These changes do not require tests because they are tests.

This change is Reviewable

@highfive
Copy link

highfive commented Oct 5, 2016

Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @SimonSapin (or someone else) soon.

@highfive
Copy link

highfive commented Oct 5, 2016

Heads up! This PR modifies the following files:

  • @bholley: components/style/gecko_bindings/test_bindings.rs, components/style/gecko_bindings/check_bindings.py
@highfive
Copy link

highfive commented Oct 5, 2016

warning Warning warning

  • These commits modify style code, but no tests are modified. Please consider adding a test!
@emilio
Copy link
Member

emilio commented Oct 5, 2016

r? @wafflespeanut for the python bits.

@highfive highfive assigned wafflespeanut and unassigned SimonSapin Oct 5, 2016
tests.write("}\n")

bindings.close()
tests.close()

This comment has been minimized.

@aneeshusa

aneeshusa Oct 5, 2016

Member

Please use with instead of manually calling close().

This comment has been minimized.

@Rafagd

Rafagd Oct 6, 2016

Author Contributor

Done.

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

This comment has been minimized.

@emilio

emilio Oct 5, 2016

Member

You'll need to include this module somewhere, otherwise it wont be compiled. And you'll need to generate the relevant use statements too.

A line like:

mod test_bindings;

in gecko_bindings/lib.rs would suffice for the first part.

This comment has been minimized.

@emilio

emilio Oct 5, 2016

Member

(Sorry, I meant gecko_bindings/mod.rs, my fault).

This comment has been minimized.

@Manishearth

Manishearth Oct 6, 2016

Member

We don't want to include it in gecko_bindings, we want to include (include!(), not pub mod) it in tests/unit/stylo. The glue functions don't get defined till later. I plan on doing this myself later.

This comment has been minimized.

@Rafagd

Rafagd Oct 6, 2016

Author Contributor

Should I move the script back to the same folder as 'bindings.rs`?

This comment has been minimized.


tests.write("/* This Source Code Form is subject to the terms of the Mozilla Public\n")
tests.write(" * License, v. 2.0. If a copy of the MPL was not distributed with this\n")
tests.write(" * file, You can obtain one at http://mozilla.org/MPL/2.0/. */\n\n")

This comment has been minimized.

@emilio

emilio Oct 5, 2016

Member

A warning about the file being an autogenerated file would be nice as well :)

This comment has been minimized.

@emilio

emilio Oct 5, 2016

Member

Probably also maybe making the destination file components/style/generated/check_bindings.rs would be helpful, in addition to that.

In that case, you'll need to do something like:

#[path = "path/to/generated/check_bindings.rs"]
mod check_bindings;

Also, please hook this to the components/style/binding_tools/regen.py script, the same way that regen_atoms.py is hooked in, and ideally put this script in that directory too :)

Thanks for doing this!

This comment has been minimized.

@Rafagd

Rafagd Oct 5, 2016

Author Contributor

Did I do the last part correctly?

This comment has been minimized.

@Manishearth

Manishearth Oct 6, 2016

Member

You did the hooking up to regen correctly 😄

As I said elsewhere, don't worry about including it as a mod just yet.


def build(objdir, verbose=False):
with open(objdir + "/bindings.rs", "r") as bindings:
with open(objdir + "/check_bindings.rs", "w+") as tests:

This comment has been minimized.

@aneeshusa

aneeshusa Oct 5, 2016

Member

Please use os.path.join instead of string concatenation.

import re

def build(objdir, verbose=False):
with open(objdir+"/bindings.rs", "r") as bindings:

This comment has been minimized.

@emilio

emilio Oct 5, 2016

Member

You don't need the objdir here. you should be able to get the current script directory (with os.path.dirname(os.path.abspath(__file__)), or passing TOOLS_DIR as an argument), and arrive into the bindings.rs file.

I think you can test that with ./regen.py --target check_bindings /dummy/path/since/it/wont/be/used

This comment has been minimized.

@Manishearth

Manishearth Oct 6, 2016

Member

regen_atoms.py just uses the local dir it seems.

@@ -2,24 +2,5 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

This comment has been minimized.

@Manishearth

Manishearth Oct 6, 2016

Member

This file should be unchanged. check_bindings.rs is not actually going to be used in this crate, so you don't need a mod for it

This comment has been minimized.

@Manishearth

Manishearth Oct 6, 2016

Member

Also, could you commit the generated file?

This comment has been minimized.

@Rafagd

Rafagd Oct 6, 2016

Author Contributor

Moved the script back to the same folder bindings.rs is, added the generated file there, and removed the changes to files that should not have been changed.



def build(objdir, verbose=False):
with open(objdir + "/bindings.rs", "r") as bindings:

This comment has been minimized.

@Manishearth

Manishearth Oct 6, 2016

Member

You shouldn't be using the objdir here, you should be using local paths. The objdir is pointed to where gecko headers live.

This comment has been minimized.

@Rafagd

Rafagd Oct 6, 2016

Author Contributor

When you say local paths, do you mean just open("bindings.rs", "r") as if they were in the same folder, or open("components/style/gecko_bindings/bindings.rs", "r")?

This comment has been minimized.

@Manishearth

Manishearth Oct 6, 2016

Member

Yes. Assume it's being run from the same dir.

This comment has been minimized.

@Manishearth

Manishearth Oct 6, 2016

Member

I think this should be ../gecko_bindings/bindings.rs?

I meant "Assume it is being run from the same dir that contains the script"

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

This comment has been minimized.

@Manishearth

Manishearth Oct 6, 2016

Member

We don't want to include it in gecko_bindings, we want to include (include!(), not pub mod) it in tests/unit/stylo. The glue functions don't get defined till later. I plan on doing this myself later.

Copy link
Member

Manishearth left a comment

Sorry about the confusion wrt including the mod.

@Manishearth
Copy link
Member

Manishearth commented Oct 6, 2016

As far as using this file, it should be used via a new module in tests/unit/stylo, which contains:

// license header

use geckolib::glue::*;
use style::gecko_bindings::bindings;

include!("../../../components/style/gecko_bindings/check_bindings.rs")

I didn't ask for this to be done in this PR because I suspect there will be some errors that need fixing and I didn't want to extend the scope of the issue to that. The changes I requested right now should be enough.

tests.write("/* This Source Code Form is subject to the terms of the Mozilla Public\n")
tests.write(" * License, v. 2.0. If a copy of the MPL was not distributed with this\n")
tests.write(" * file, You can obtain one at http://mozilla.org/MPL/2.0/. */\n\n")
tests.write("/* automatically generated by check_bindings.py. */\n\n")

This comment has been minimized.

@wafflespeanut

wafflespeanut Oct 6, 2016

Member

This should be put into a global name (like, LICENSE) on the top of the file.


def build(objdir, verbose=False):
with open(objdir + "/bindings.rs", "r") as bindings:
with open(objdir + "/check_bindings.rs", "w+") as tests:

This comment has been minimized.

@wafflespeanut

wafflespeanut Oct 6, 2016

Member

Instead of nesting inside, this could be joined as

with open(...) as bindings, open(...) as tests:

Also, as @aneeshusa said, it's a better idea to join the paths instead of hardcoding them, and put the paths in the top of the file, like BINDINGS_FILE, BINDINGS_CHECK_FILE, etc.

This comment has been minimized.

@Rafagd

Rafagd Oct 6, 2016

Author Contributor

Oh, I didn't knew you could do that. Fixed.

if match:
tests.write(" [ Servo_" + match.group(1) + ", bindings::Servo_" + match.group(1) + " ];\n")

tests.write("}\n")

This comment has been minimized.

@wafflespeanut

wafflespeanut Oct 6, 2016

Member

Instead, we could have a template for this above, like

TEMPLATE = '''
    [ Servo_{name}, bindings::Servo_{name} ];
'''

and format it every time we find a match.


import re

LICENSE = """/* This Source Code Form is subject to the terms of the Mozilla Public

This comment has been minimized.

@aneeshusa

aneeshusa Oct 6, 2016

Member

Do

LICENSE = """\
/* This Source Code
...
"""

at the beginning instead, as it keeps the license block formatted as usual.

This comment has been minimized.

@Rafagd

Rafagd Oct 6, 2016

Author Contributor

Wouldn't that add a \n at the start of the generated file? Or the \ removes the \n from the resulting string?

This comment has been minimized.

@aneeshusa

aneeshusa Oct 6, 2016

Member

Yes, \ followed by a newline is an escape sequence that is ignored/skipped by Python, so the resulting string won't have a leading newline.

Try it out in a small test file!

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

This comment has been minimized.

@Manishearth

Manishearth Oct 6, 2016

Member

Uh, sorry for the confusion again.

To be clear: check_bindings.py belongs in binding_tools. The generated file belongs in gecko_bindings.

This comment has been minimized.

@Manishearth

Manishearth Oct 6, 2016

Member

Aside from this everything else looks good! r=me once this file is moved.

This comment has been minimized.

@Rafagd

Rafagd Oct 6, 2016

Author Contributor

Oh, I see. I'm preparing a new commit soon anyway.

@Manishearth
Copy link
Member

Manishearth commented Oct 6, 2016

Once done, please squash your commits together.

emilio and others added 18 commits Sep 26, 2016
… to that fragment.

Otherwise we might mix writing modes. Not totally sure this change is correct in
the case we're mixing them, we might need to just not checking that operation.
It can be retrieved through its init field.
This uses a (very simple) Win32 API call to enumerate font
families available, and load them as byte buffers.

The font rasterization itself is done by freetype.

This gets Servo + WR + Windows working, but should be improved
by adding a proper implementation that matches fonts correctly
and also uses DirectWrite (or GDI) to handle font rasterization.
fragment position assignment.

Improves Rust documentation.

Closes #13471.
@Rafagd
Copy link
Contributor Author

Rafagd commented Oct 6, 2016

I'm closing this request and making a new one.

@Rafagd Rafagd closed this Oct 6, 2016
@Rafagd Rafagd mentioned this pull request Oct 6, 2016
4 of 5 tasks complete
@Manishearth
Copy link
Member

Manishearth commented Oct 6, 2016

You can just squash the commits via rebase and force-push to the same branch, no need to close the PR 😄

@Rafagd
Copy link
Contributor Author

Rafagd commented Oct 6, 2016

I did something wrong during the rebase and merged a bunch of unrelated stuff to this PR.
I felt it was easier to start from a clean fork instead of trying to fix the one I had.

bors-servo added a commit that referenced this pull request Oct 6, 2016
Script-generated tests for Servo_* gecko bindings

All changes done in #13603, but this time I understand why I should have created a branch instead of doing everything on master.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #13598 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because `they are tests`.

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13617)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this pull request Oct 7, 2016
Script-generated tests for Servo_* gecko bindings

All changes done in #13603, but this time I understand why I should have created a branch instead of doing everything on master.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #13598 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because `they are tests`.

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13617)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this pull request Oct 7, 2016
Script-generated tests for Servo_* gecko bindings

All changes done in #13603, but this time I understand why I should have created a branch instead of doing everything on master.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #13598 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because `they are tests`.

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13617)
<!-- Reviewable:end -->
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Feb 4, 2017
…gs (from Rafagd:my_changes); r=Manishearth

All changes done in servo/servo#13603, but this time I understand why I should have created a branch instead of doing everything on master.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #13598 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because `they are tests`.

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

Source-Repo: https://github.com/servo/servo
Source-Revision: 03cd936639905e4c980ee706f4ee8f0f35de5180
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request Oct 1, 2019
…gs (from Rafagd:my_changes); r=Manishearth

All changes done in servo/servo#13603, but this time I understand why I should have created a branch instead of doing everything on master.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #13598 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because `they are tests`.

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

Source-Repo: https://github.com/servo/servo
Source-Revision: 03cd936639905e4c980ee706f4ee8f0f35de5180

UltraBlame original commit: 1cf764acd99a05d75440bfa73b1a32b12c1cf4ee
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this pull request Oct 1, 2019
…gs (from Rafagd:my_changes); r=Manishearth

All changes done in servo/servo#13603, but this time I understand why I should have created a branch instead of doing everything on master.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #13598 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because `they are tests`.

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

Source-Repo: https://github.com/servo/servo
Source-Revision: 03cd936639905e4c980ee706f4ee8f0f35de5180

UltraBlame original commit: 1cf764acd99a05d75440bfa73b1a32b12c1cf4ee
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request Oct 1, 2019
…gs (from Rafagd:my_changes); r=Manishearth

All changes done in servo/servo#13603, but this time I understand why I should have created a branch instead of doing everything on master.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #13598 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because `they are tests`.

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

Source-Repo: https://github.com/servo/servo
Source-Revision: 03cd936639905e4c980ee706f4ee8f0f35de5180

UltraBlame original commit: 1cf764acd99a05d75440bfa73b1a32b12c1cf4ee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

You can’t perform that action at this time.