Friday, September 27, 2013

Patching and Using Core Dart Packages (the Wrong? Way)

My daughter is having difficulty doing cartwheels. She is much aggrieved by this for two reasons. First, I can do a cartwheel (quite gracefully I might add), which leads to the but-even-daddy-can-do-it objection. The second reason that this bothers her so much is that it is “embarrassing” that she is incapable of doing what so many of her friends can do. I consoled her by telling her that very few people can pull off cartwheels as well as I can. That did not seem to have quite the soothing effect that I anticipated, so I let her know that I embarrass myself publicly on a daily basis.

That seemed to do the trick. So now all that's left is to figure out how I will embarrass myself tonight. Trying to figure out how to apply and use the latest patch to Polymer.dart for attribute binding seems a fine candidate for the job.

Last night, I manually downloaded and applied a diff for a single file in a single Polymer.dart dependency. The patch for today spans several packages, so that trick, although it would work, would be a tad time-consuming. Instead I am going to apply the patch directly to the Dart source code.

Many packages that are only available from Dart Pub are, in fact maintained by the core Dart team alongside the core Dart libraries.

So I clone the repository from GitHub:
➜  repos  git clone dart              
Cloning into 'dart'...
remote: Counting objects: 413160, done.
remote: Compressing objects: 100% (88516/88516), done.
remote: Total 413160 (delta 294342), reused 395016 (delta 276211)
Receiving objects: 100% (413160/413160), 577.79 MiB | 3.46 MiB/s, done.
Resolving deltas: 100% (294342/294342), done.
Next, I download the patch:
➜  dart git:(master) wget
The patch is in git-am format, so I will give it a go with git-apply:
➜  dart git:(master) ✗ git apply --directory dart --check issue24149003_42001.diff
error: patch failed: dart/pkg/custom_element/lib/custom_element.dart:178
error: dart/pkg/custom_element/lib/custom_element.dart: patch does not apply
error: patch failed: dart/samples/third_party/todomvc/web/editable_label.html:3
error: dart/samples/third_party/todomvc/web/editable_label.html: patch does not apply

Well, hopefully the 3-way fallback option will get me close enough:
➜  dart git:(master) ✗ git apply --directory dart -3 issue24149003_42001.diff      
error: patch failed: dart/pkg/custom_element/lib/custom_element.dart:178
Falling back to three-way merge...
Applied patch to 'dart/pkg/custom_element/lib/custom_element.dart' cleanly.
error: patch failed: dart/samples/third_party/todomvc/web/editable_label.html:3
Falling back to three-way merge...
Applied patch to 'dart/samples/third_party/todomvc/web/editable_label.html' with conflicts.
U dart/samples/third_party/todomvc/web/editable_label.html
Yay! That is close enough. The only conflict is in the “todo” app, which I do not care about anyway.

So I modify pubspec.yaml from the project in which I am trying to use Polymer:
name: ice_code_editor
# ...
  # ...
    path: /home/chris/repos/dart/dart/pkg/polymer
    path: /home/chris/repos/dart/dart/pkg/custom_element
    path: /home/chris/repos/dart/dart/pkg/observe
And then a quick pub install to get all of my dependencies:
➜  ice-code-editor git:(polymer) ✗ pub install
Resolving dependencies.................................
Incompatible dependencies on 'custom_element':
- 'ice_code_editor' depends on it from source path
- 'polymer' depends on it from source hosted

So, maybe it will not be a quick pub install. Not knowing what else to try, I modify the pubspec.yaml file in the dart repository to also use local paths:
name: polymer
  # ...
  csslib: any
    path: /home/chris/repos/dart/dart/pkg/custom_element
  html5lib: any
  html_import: any
  logging: any
  mdv: any
  meta: any
    path: /home/chris/repos/dart/dart/pkg/observe
  path: any
  polymer_expressions: any
  # ...
And that drags me down into dependency hell. Several of the other packages depend on observe so I have to edit the pubspec.yaml of each in turn. Eventually, I get far enough down that I have a successful pub install, but… yuck.

So I must be doing this wrong. Which means that I can definitely report back to my daughter that I have successfully embarrassed myself tonight. Yay!

I do have the patch and enough of the paths updated, so I may just go ahead and explore the changes in the proposed patch tomorrow. But hopefully someone will be kind enough to explain a better approach to linking such a large dependency fingerprint into a project.

Day #887

No comments:

Post a Comment