scala-js / scala-js-env-phantomjs

PhantomJS environment for Scala.js
BSD 3-Clause "New" or "Revised" License
2 stars 3 forks source link

Import the PhantomJS env from the Scala.js core repository. #1

Closed sjrd closed 7 years ago

sjrd commented 7 years ago

This is the initial import of the PhantomJS env and its sbt plugin from the Scala.js core repository. The history of this commit reflects the entire history of relevant files from the core repo, filter-branch'ed to appear as if they had always been in this repo. This commit adds the specific setup of the build and tests.

The history was obtained as follows, starting from commit https://github.com/scala-js/scala-js/commit/f21e7f5ea652fe4a186f1ecd8c0070fbb80edc80 of the core repo.

First, we identified all the paths where relevant files have lived in the past, through renamings along their history. This is the list:

js-envs/src/test/scala/org/scalajs/jsenv/test/RetryingComJSEnvTest.scala
js-envs-test-suite/src/test/scala/org/scalajs/jsenv/test/RetryingComJSEnvTest.scala
phantomjs-env/src/test/scala/org/scalajs/jsenv/phantomjs/RetryingComJSEnvTest.scala

js-envs/src/main/scala/org/scalajs/jsenv/RetryingComJSEnv.scala
phantomjs-env/src/main/scala/org/scalajs/jsenv/phantomjs/RetryingComJSEnv.scala

sbt-plugin/src/test/scala/scala/scalajs/sbtplugin/test/env/PhantomJSTest.scala
js-envs/src/test/scala/org/scalajs/jsenv/test/PhantomJSTest.scala
js-envs-test-suite/src/test/scala/org/scalajs/jsenv/test/PhantomJSTest.scala
phantomjs-env/src/test/scala/org/scalajs/jsenv/phantomjs/PhantomJSTest.scala

js-envs-test-suite/src/test/scala/org/scalajs/jsenv/test/PhantomJSWithCustomInitFilesTest.scala
phantomjs-env/src/test/scala/org/scalajs/jsenv/phantomjs/PhantomJSWithCustomInitFilesTest.scala

sbt-plugin/src/main/scala/scala/scalajs/sbtplugin/env/phantomjs/*
js-envs/src/main/scala/org/scalajs/jsenv/phantomjs/*
phantomjs-env/src/main/scala/org/scalajs/jsenv/phantomjs/*

phantomjs-sbt-plugin/src/main/scala/org/scalajs/jsenv/phantomjs/sbtplugin/PhantomJSEnvPlugin.scala

sbt-plugin-test/build.sbt
sbt-plugin-test/jetty9/src/main/resources/test.txt
sbt-plugin-test/project/Jetty9Test.scala
sbt-plugin-test/project/build.sbt

Based on that, we filter-branch'ed to keep only those files, using the following incantation, inspired by http://stackoverflow.com/a/6006679/1829647:

git filter-branch \
    --prune-empty \
    --index-filter '
  git ls-tree -z -r --name-only --full-tree $GIT_COMMIT \
    | grep -z -v "^js-envs/src/test/scala/org/scalajs/jsenv/test/RetryingComJSEnvTest.scala$" \
    | grep -z -v "^js-envs-test-suite/src/test/scala/org/scalajs/jsenv/test/RetryingComJSEnvTest.scala$" \
    | grep -z -v "^phantomjs-env/src/test/scala/org/scalajs/jsenv/phantomjs/RetryingComJSEnvTest.scala$" \
    | grep -z -v "^js-envs/src/main/scala/org/scalajs/jsenv/RetryingComJSEnv.scala$" \
    | grep -z -v "^phantomjs-env/src/main/scala/org/scalajs/jsenv/phantomjs/RetryingComJSEnv.scala$" \
    | grep -z -v "^sbt-plugin/src/test/scala/scala/scalajs/sbtplugin/test/env/PhantomJSTest.scala$" \
    | grep -z -v "^js-envs/src/test/scala/org/scalajs/jsenv/test/PhantomJSTest.scala$" \
    | grep -z -v "^js-envs-test-suite/src/test/scala/org/scalajs/jsenv/test/PhantomJSTest.scala$" \
    | grep -z -v "^phantomjs-env/src/test/scala/org/scalajs/jsenv/phantomjs/PhantomJSTest.scala$" \
    | grep -z -v "^js-envs-test-suite/src/test/scala/org/scalajs/jsenv/test/PhantomJSWithCustomInitFilesTest.scala$" \
    | grep -z -v "^phantomjs-env/src/test/scala/org/scalajs/jsenv/phantomjs/PhantomJSWithCustomInitFilesTest.scala$" \
    | grep -z -v "^sbt-plugin/src/main/scala/scala/scalajs/sbtplugin/env/phantomjs/" \
    | grep -z -v "^js-envs/src/main/scala/org/scalajs/jsenv/phantomjs/" \
    | grep -z -v "^phantomjs-env/src/main/scala/org/scalajs/jsenv/phantomjs/" \
    | grep -z -v "^phantomjs-sbt-plugin/src/main/scala/org/scalajs/jsenv/phantomjs/sbtplugin/PhantomJSEnvPlugin.scala$" \
    | grep -z -v "^sbt-plugin-test/build.sbt$" \
    | grep -z -v "^sbt-plugin-test/jetty9/src/main/resources/test.txt$" \
    | grep -z -v "^sbt-plugin-test/project/Jetty9Test.scala$" \
    | grep -z -v "^sbt-plugin-test/project/build.sbt$" \
    | xargs -0 -r git rm -r --cached
  ' HEAD

That gave the result visible in https://github.com/sjrd/scala-js-env-phantomjs/tree/import-from-core-step1. Unfortunately, --prune-empty does not prune empty merge commits. We fixed that using the solution found in http://stackoverflow.com/a/38420284/1829647:

git filter-branch --prune-empty --parent-filter 'sed "s/-p //g" | xargs -r git show-branch --independent | sed "s/\</-p /g"'

giving https://github.com/sjrd/scala-js-env-phantomjs/tree/import-from-core-step2

Now, we had a clean history, except that it was orphaned wrt. the Initial commit of this repository, which is 51c45de4e5079a999abe964bc0e06dadcac8e789. To have a nice PR with a history that appears to have come from the Initial commit, we reattached the first meaningful commit to the Initial commit using:

git filter-branch --parent-filter 'sed "s/ca1d58a31e27756c0d07fd65fbfdb1a3e0c6642e/51c45de4e5079a999abe964bc0e06dadcac8e789/"'

which yielded https://github.com/sjrd/scala-js-env-phantomjs/tree/import-from-core-step3.

Almost there, except that now the files from the Initial commit have been removed in the first meaningful commit of the filter-branch. We restored them using:

git filter-branch --index-filter 'git reset 51c45de4e5079a999abe964bc0e06dadcac8e789 -- .gitignore LICENSE README.md'

giving the history in https://github.com/sjrd/scala-js-env-phantomjs/tree/import-from-core-step4.

As a final polish, we rewrite, in commit messages, references to tickets of the form #123 to scala-js/scala-js#123, so that they point to issues in the scala-js/scala-js repository. This is done using the following incantation:

git filter-branch --msg-filter 'sed -r -e "s/(#[0-9]+)/scala-js\/scala-js\1/g"'

and gives the result in https://github.com/sjrd/scala-js-env-phantomjs/tree/import-from-core-step5.

This PR is one commit on top of that final step.

sjrd commented 7 years ago

Phew ... managed to get it green. I had to resort to using coursier on Travis, because the normal ivy resolution was simply killing all the time allocated to jobs on Travis!

Ping @gzm0. Since it's a new repo, I'm not sure you received earlier notifications.

gzm0 commented 7 years ago

Will the references to issues "in the future" (e.g. fix #2883) make our life harder in the future?

If yes, consider s/(#[0-9]+)/sjs\1/g

I'm still reviewing the rest.

gzm0 commented 7 years ago

The longer I think of it, the more unsure I get about importing the history. I do not understand what it buys us. IIUC, those commits won't build anyways, so we will not have bisecting capabilities or something.

Have you considered just replacing everything with a commit saying "copied from scala/scala@..."? Yes, that would make us lose the history if we lose Scala.js, but then again, this would make this repo quite useless.

Ok, I now understand that it gives us blame capabilities. So maybe we should retain it.

I'll proceed with reviewing the filter branch procedure and the last commit.

sjrd commented 7 years ago

Ok, I now understand that it gives us blame capabilities. So maybe we should retain it.

Yes, it's essentially for the blames.

sjrd commented 7 years ago

Will the references to issues "in the future" (e.g. fix #2883) make our life harder in the future?

Hum, good point. Yes, I think you're right and we should rewrite those.

gzm0 commented 7 years ago

Yes, I think you're right and we should rewrite those.

If you are doing this and you need to repeat step 3 and step 4, note that I think they are just a convoluted way to do a rebase --onto.

sjrd commented 7 years ago

Nah I'll do that as a step 5.

A rebase --onto flattens out all merges, so not good to import a history. (plus, it reassigns the "committer" field--different from "author"--, not a big deal but still annoying for an entire history)

gzm0 commented 7 years ago

A rebase --onto flattens out all merges, so not good to import a history

Ah, ah, indeed.

sjrd commented 7 years ago

Updated: