#2293 Viewing Source Code of 3rd Party Libraries in F4

SlimerDude Wed 4 Jun 2014

Below is a short composition on how to view the source code of 3rd party libraries in F4. It's something I've automated in my own build system, but I figured it may be handy to others also.


When writing code it can be huge boost to the view source code of libraries you're using. It clarifies what's going, shows you the developers intent, and the comments can be helpful.

When using F4 by Xored, not only is the source code a single mouse click (or F3 key press) away, but you can also step through it when debugging! Awesome!

But by default it only works with system pods and any projects F4 has open.

- sadness -

Until now!

- happiness! -

All Alien-Factory pods are compiled with debug information and bundled with source code. To let F4 gain access to this, all you need to do is copy the source files from the pod into your Fantom home directory. Or more specifically, to the pod's src dir in the Fantom home directory.

Taking the afIoc.pod as an example, if you open it up as a .zip file:

Inspecting afIoc.pod as a .zip file

You will see the usual pod directories. If you copy the contents of src/ to %FAN_HOME%\src\afIoc\ then F4 will be able to pick it up.

Source Code Install Script

If all this file copying seems like too much manual effort, then try this handy Fantom script instead:

using util

class InstallSrc : AbstractMain {

    @Arg Str? pod
    @Opt Bool uninstall

    override Int run() {
        pod     := Pod.find(pod)
        podDir  := Env.cur.homeDir.plus(`src/${pod.name}/`).normalize
        echo("Found ${pod.name} v${pod.version}")

        if (uninstall) {
            echo("Deleting '${podDir.osPath}'")
            podDir.delete
            echo("Done.")
            return 0
        }

        // copy src to %FAN_HOME% for F4 debugging
        echo("Copying ${pod.name} src to '${podDir.osPath}'")
        podDir.delete    // delete old stuff
        podDir.create

        fileCnt := 0
        podFile := Env.cur.findPodFile(pod.name)
        zip     := Zip.open(podFile)
        zip.contents.each |file| {
            if (file.pathStr.startsWith("/src/")) {
                file.copyInto(podDir)
                fileCnt++
            }
        }
        zip.close
        echo("Copied ${fileCnt} files")

        echo("Done.")
        return 0
    }
}

Assuming you've saved it as a file named InstallSrc.fan, you can use it like this:

C:\>fan InstallSrc.fan afIoc

Found afIoc v1.6.0
Copying afIoc src to 'C:\Apps\fantom-1.0.66\src\afIoc'
Copied 69 files
Done.

And to remove the source code:

C:\>fan InstallSrc.fan afIoc -uninstall

Found afIoc v1.6.0
Deleting 'C:\Apps\fantom-1.0.66\src\afIoc'
Done.

Have fun!

:)

See also:

Login or Signup to reply.