Norman Ramsey
Norman Ramsey

Reputation: 202675

How to discover (possibly approximate) dependencies between SML source files?

I have software written in Standard ML (henceforth SML) which I'd like to make portable across three compilers.

What I'd like to do is take a list of SML source files and discover dependencies between files. Here are the ways I've tried and failed:

I'm looking for ideas along the lines of simple tools that would give approximate answers. My code has two special properties:

It seems to me that in this situation, a simple syntactic tool might be able to find external dependencies of a file. But I don't quite know how to write one.

Ideas?

Upvotes: 3

Views: 156

Answers (2)

Ionuț G. Stan
Ionuț G. Stan

Reputation: 179189

Based on this thread, which is asking a similar question, I was able to write a small program that worked for me (I copied the produced list of file names, pasted it inside an .mlb file, and MLton was able to compile my little project). So, I can't guarantee anything, but it's probably a good start. Hope it helps.

sources.cm

group
  structure Deps
is
  $/basis.cm
  $/pgraph.cm
  $smlnj/cm.cm

  deps.sml

deps.sml

structure Deps =
struct
  structure PG = PortableGraph

  fun list () =
    let
      fun println s = print (s ^ "\n")

      fun extractFiles def =
        case def of
          PG.DEF { rhs = PG.COMPILE { src, ... }, ... } => SOME (#1 src)
        | _ => NONE

      val PG.GRAPH { defs, ... } =
        (* Replace "sources.cm" with your project's .cm file path. *)
        #graph (valOf (CM.Graph.graph "sources.cm"))

      val files = List.mapPartial extractFiles defs
    in
      List.app println files
    end
end

Upvotes: 1

Matt
Matt

Reputation: 4049

In the MLton repository, there is a cm2mlb tool that will convert a .cm file into an MLB file (util/cm2mlb of the git repo). If you put all of your files into a .cm file you should be able to use this to generate an MLB file that will be in dependency order.

Upvotes: 1

Related Questions