VTK/Git/Develop/Data: Difference between revisions

From KitwarePublic
< VTK‎ | Git‎ | Develop
Jump to navigationJump to search
Line 283: Line 283:
push it to gerrit for review (more magic makes sure the original file gets uploaded where it needs to)
push it to gerrit for review (more magic makes sure the original file gets uploaded where it needs to)
  $ git gerrit-push
  $ git gerrit-push
== Publishing Data for an External Branch ==
The above [[#Workflow|workflow]] works well for developers working on a single machine to contribute changes directly to upstream VTK.
When working in an external branch of VTK, perhaps during a long-term topic development effort, data objects need to be published separately.
The workflow for adding data to an external branch of VTK is the same as the above through the [[#Commit|commit]] step, but diverges at the [[#Push|push]] step because one will push to a separate repository.
Our ExternalData infrastructure intentionally hides the real data files from Git so only the content links (<code>.md5</code> files) will be pushed.
The real data objects will still be left in the <code>.ExternalData/MD5</code> directory at the top of the VTK source tree by the [[#pre-commit|pre-commit]] hook.

Revision as of 13:57, 3 July 2014

This page documents how to add test data while developing VTK. See our table of contents for more information.

Setup

The workflow below depends on local hooks to function properly. Follow the main developer setup instructions before proceeding. In particular, run SetupForDevelopment.sh:

$ ./Utilities/SetupForDevelopment.sh

Workflow

Our workflow for adding data integrates with our standard Git development process. Start by creating a topic. Return here when you reach the "edit files" step.

These instructions follow a typical use case of adding a new test with a baseline image.

Add Data

Copy the data file into your local source tree.

$ mkdir -p Some/Module/Testing/Data/Baseline
$ cp ~/MyTest.png Some/Module/Testing/Data/Baseline/MyTest.png

How do you generate baseline images in the first place?

Add Test

Edit the test CMakeLists.txt file and add the test using a vtk_add_test_... call (which references baselines automatically). For tests not using such a call, reference the data file in an ExternalData_add_test call. Specify the file inside DATA{...} using a path relative to the test directory:

$ edit Some/Module/Testing/Cxx/CMakeLists.txt
ExternalData_add_test(VTKData
  NAME ${vtk-module}Cxx-MyTest
  COMMAND ${vtk-module}CxxTests MyTest
          ... -V DATA{../Data/Baseline/MyTest.png,:} ...
  )
  • If the data file references other data files, e.g. .mhd -> .raw, follow the link to the ExternalData module on the right and read the documentation on "associated" files.
  • Multiple baseline images and other series are handled automatically when the reference ends in the ",:" option; follow the link to the ExternalData module on the right for details.

ExternalData.cmake

Run CMake

CMake will move the original file. Keep your own copy if necessary.

Run cmake on the build tree:

$ cd ../VTK-build
$ cmake .
(Or just run "make" to do a full configuration and build.)
$ cd ../VTK

Need to recover the original file?

During configuration CMake will display a message such as:

Linked Some/Module/Testing/Data/Baseline/MyTest.png.md5 to ExternalData MD5/...

This means that CMake converted the file into a data object referenced by a "content link".

ExternalData.cmake

Commit

Continue to create the topic and edit other files as necessary. Add the content link and commit it along with the other changes:

$ git add Some/Module/Testing/Data/Baseline/MyTest.png.md5
$ git add Some/Module/Testing/Data/CMakeLists.txt
$ git commit

git help add
git help commit

The local pre-commit hook will display a message such as:

Some/Module/Testing/Data/Baseline/MyTest.png.md5: Added content to Git at refs/data/MD5/...
Some/Module/Testing/Data/Baseline/MyTest.png.md5: Added content to local store at .ExternalData/MD5/...
Content link Some/Module/Testing/Data/Baseline/MyTest.png.md5 -> .ExternalData/MD5/...

This means that the pre-commit hook recognized that the content link references a new data object and prepared it for upload.

pre-commit

Push

Follow the instructions to share the topic. When you push it to Gerrit for review using

$ git gerrit-push

git-gerrit-push

part of the output will be of the form

*       ...:refs/data/commits/...      [new branch]
*       HEAD:refs/for/master/my-topic  [new branch]
Pushed refs/data and removed local copy:
  MD5/...

This means that the git-gerrit-push script pushed the topic and uploaded the data it references.

Options for gerrit-push:

  • --dry-run: Report push that would occur without actually doing it
  • --no-topic: Push the data referenced by the topic but not the topic itself

Note: One must git gerrit-push from the same work tree as was used to create the commit. Do not git push to another computer first and try to push to Gerrit from there. The data will not follow.

Building

Download

For the test data to be downloaded and made available to the tests in your build tree the VTKData target must be built. One may build the target directly, e.g. make VTKData, to obtain the data without a complete build. The output will be something like

-- Fetching ".../ExternalData/MD5/..."
-- [download 100% complete]
-- Downloaded object: "VTK-build/ExternalData/Objects/MD5/..."

The downloaded files appear in VTK-build/ExternalData by default.

Local Store

It is possible to configure one or more local ExternalData object stores shared among multiple builds. Configure for each build the advanced cache entry ExternalData_OBJECT_STORES to a directory on your local disk outside all build trees, e.g. "/home/user/.ExternalData":

$ cmake -DExternalData_OBJECT_STORES=/home/user/.ExternalData ../VTK

The ExternalData module will store downloaded objects in the local store instead of the build tree. Once an object has been downloaded by one build it will persist in the local store for re-use by other builds without downloading again.

ExternalData.cmake

Discussion

A VTK test data file is not stored in the main source tree under version control. Instead the source tree contains a "content link" that refers to a data object by a hash of its content. At build time the ExternalData.cmake module fetches data needed by enabled tests. This allows arbitrarily large data to be added and removed without bloating the version control history.

The above workflow allows developers to add a new data file almost as if committing it to the source tree. The following subsections discuss details of the workflow implementation.

ExternalData

While CMake runs the ExternalData module evaluates DATA{} references. VTK sets the ExternalData_LINK_CONTENT option to MD5 to enable automatic conversion of raw data files into content links. When the module detects a real data file in the source tree it performs the following transformation as specified in the module documentation:

  • Compute the MD5 hash of the file
  • Store the ${hash} in a file with the original name plus .md5
  • Rename the original file to .ExternalData_MD5_${hash}

The real data now sit in a file that we tell Git to ignore. For example:

$ cat Some/Module/Testing/Data/Baseline/.ExternalData_MD5_477e602800c18624d9bc7a32fa706b97 |md5sum
477e602800c18624d9bc7a32fa706b97  -
$ cat Some/Module/Testing/Data/Baseline/MyTest.png.md5
477e602800c18624d9bc7a32fa706b97

Recover Data File

To recover the original file after running CMake but before committing, undo the operation:

$ cd Some/Module/Testing/Data/Baseline
$ mv .ExternalData_MD5_$(cat MyTest.png.md5) MyTest.png

pre-commit

While committing a new or modified content link the pre-commit hook moves the real data object from the .ExternalData_MD5_${hash} file left by the ExternalData module to a local object repository stored in a .ExternalData directory at the top of the source tree.

The hook also uses Git plumbing commands to store the data object as a blob in the local Git repository. The blob is not referenced by the new commit but instead by refs/data/MD5/${hash}. This keeps the blob alive in the local repository but does not add it to the project history. For example:

$ git for-each-ref --format="%(refname)" refs/data
refs/data/MD5/477e602800c18624d9bc7a32fa706b97
$ git cat-file blob refs/data/MD5/477e602800c18624d9bc7a32fa706b97 | md5sum
477e602800c18624d9bc7a32fa706b97  -

git gerrit-push

The "git gerrit-push" command is actually an alias for the Utilities/Scripts/git-gerrit-push script. In addition to pushing the topic branch to Gerrit the script also detects content links added or modified by the commits in the topic. It reads the data object hashes from the content links and looks for matching refs/data/ entries in the local Git repository.

The script pushes the matching data objects to Gerrit inside a temporary commit object disjoint from the rest of history. For example:

$ git gerrit-push --dry-run --no-topic
*       f59717cfb68a7093010d18b84e8a9a90b6b42c11:refs/data/commits/f59717cfb68a7093010d18b84e8a9a90b6b42c11     [new branch]
Pushed refs/data and removed local copy:
  MD5/477e602800c18624d9bc7a32fa706b97
$ git ls-tree -r --name-only f59717cf
MD5/477e602800c18624d9bc7a32fa706b97
$ git log --oneline f59717cf
f59717c data

A robot runs every few minutes to fetch the objects from Gerrit and upload them to a location that we tell ExternalData to search at build time.

Putting it all together

How do you generate baseline images in the first place? If a baseline image is missing, CMake will warn you about it, but you can still configure, build and run the test. When you run the test the first time, it will fail but place a new test image into the build tree. Move that image into the appropriate place in the source tree, then configure and run again and the test should then pass. In summary:

Write some new test in:

$ $VTKSRC/some/module /Testing/whateverlang/sometest.langext

Tell cmake about it by editing:

$ $VTKSRC/some/module/Testing/whateverlang/CMakeLists.txt

Configure and make, cmake will warn at some point that there is no such regression test file.

Run the test, it will fail and dump the new image to

$ $VTKBUILD/Testing/Temporary

Copy that dat file into the source tree

$ cp $VTKBUILD/Testing/Temporary/sometest.png $VTKSRC/some/module/Testing/Data/Baseline

Configure and make, cmake will magically move $VTKSRC/some/module/Testing/Data/Baseline/sometest.png into a hidden place in the guts of your source tree AND create and place a new file containing the md5 of the original into $VTKSRC/some/module/Testing/Data/Baseline/sometest.png.md5

run ctest again, it should pass this time

commit the new test and data files

$ git add $VTKSRC/some/module/Testing/whateverlang/sometest.langext
$ git add $VTKSRC/some/module/Testing/whateverlang/CMakeLists.txt
$ git add $VTKSRC/some/module/Testing/Data/Baseline/sometest.png.md5
$ git commit

push it to gerrit for review (more magic makes sure the original file gets uploaded where it needs to)

$ git gerrit-push

Publishing Data for an External Branch

The above workflow works well for developers working on a single machine to contribute changes directly to upstream VTK. When working in an external branch of VTK, perhaps during a long-term topic development effort, data objects need to be published separately.

The workflow for adding data to an external branch of VTK is the same as the above through the commit step, but diverges at the push step because one will push to a separate repository. Our ExternalData infrastructure intentionally hides the real data files from Git so only the content links (.md5 files) will be pushed. The real data objects will still be left in the .ExternalData/MD5 directory at the top of the VTK source tree by the pre-commit hook.