The tune is in the Skene Manuscript of 1625 (tunes for the mandour, a sort of ukulele), under the present name, and the words are referred to in a witch trial record of a few decades earlier. The pipes don't come into it.
I hadn't thought of the connection with "London Bridge is Falling Down". Anybody know how old that is?