[Pkg-ocaml-maint-commits] [SCM] dh-ocaml packaging branch, master, updated. debian/0.5.0-7-g2c80f72

Sylvain Le Gall gildor at debian.org
Sun Jul 19 18:04:46 UTC 2009


The following commit has been merged in the master branch:
commit 1a9b4d0b7516452ef78b284294d5f50856954d6e
Author: Sylvain Le Gall <gildor at debian.org>
Date:   Sun Jul 19 16:17:40 2009 +0200

    Install perl version ocaml-md5sums.
    
    The perl version of this util is now compatible with former ocaml
    version. Use checksum and unit name to determine exported module and
    allow to use several directories to store md5sums files.

diff --git a/debian/changelog b/debian/changelog
index 222a383..65bbcf0 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -4,6 +4,9 @@ dh-ocaml (0.5.1) UNRELEASED; urgency=low
   * dom-git-checkout manpage: clarify that the tool is d-o-m specific
   * dom-new-git-repo manpage: clarify what pkg-ocaml-maint is
 
+  [ Sylvain Le Gall ]
+  * Rewrite ocaml-md5sums in perl and install it
+
  -- Stefano Zacchiroli <zack at debian.org>  Sun, 19 Jul 2009 11:01:11 +0200
 
 dh-ocaml (0.5.0) unstable; urgency=low
diff --git a/debian/install b/debian/install
index f0fd90b..79afef5 100644
--- a/debian/install
+++ b/debian/install
@@ -1,4 +1,5 @@
-cdbs/1                  usr/share/cdbs
-share/*                 usr/share/ocaml
-debhelper/dh_ocaml      usr/bin
-tools/*                 usr/bin
+cdbs/1                      usr/share/cdbs
+share/*                     usr/share/ocaml
+debhelper/dh_ocaml          usr/bin
+tools/*                     usr/bin
+ocaml-md5sums/ocaml-md5sums usr/bin
diff --git a/ocaml-md5sums/Makefile b/ocaml-md5sums/Makefile
deleted file mode 100644
index 3749c18..0000000
--- a/ocaml-md5sums/Makefile
+++ /dev/null
@@ -1,30 +0,0 @@
-
-DESTDIR = /usr/local/bin
-OFLAGS = -nostdlib -I ../../stdlib -I ../../otherlibs/unix -I ../../otherlibs/str
-OCAMLC = ../../boot/ocamlrun ../../ocamlc $(OFLAGS)
-OCAMLOPT = ../../boot/ocamlrun ../../ocamlopt $(OFLAGS)
-OCAML_LIBS = unix str
-NAME = ocaml-md5sums
-BYTE = $(NAME)
-OPT = $(NAME).opt
-
-all: $(BYTE)
-opt: $(OPT)
-install:
-	if [ -x "$(OPT)" ]; then				\
-		cp -a "$(OPT)" $(DESTDIR)/$(NAME);		\
-	elif [ -x "$(BYTE)" ]; then				\
-		cp -a "$(BYTE)" $(DESTDIR)/$(NAME);		\
-	else							\
-		echo "Nothing to be installed, aborting.";	\
-		exit 2;						\
-	fi
-
-$(BYTE): $(NAME).ml
-	$(OCAMLC) $(patsubst %,%.cma,$(OCAML_LIBS)) -o $@ $<
-$(OPT): $(NAME).ml
-	$(OCAMLOPT) $(patsubst %,%.cmxa,$(OCAML_LIBS)) -o $@ $<
-
-clean:
-	rm -f ocaml-md5sums ocaml-md5sums.opt *.cm[aiox] *.cmxa *.[ao]
-
diff --git a/ocaml-md5sums/configure.in b/ocaml-md5sums/configure.in
deleted file mode 100644
index bf760c8..0000000
--- a/ocaml-md5sums/configure.in
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/bin/sh
-VERSION="#OcamlABI#"
-DEFAULT="/var/lib/ocaml/#OcamlABI#/md5sums"
-if [ -z "$1" ]; then
-  echo "No dir provided, using default: $DEFAULT"
-  echo "You can override it with: ./configure [ md5sums_dir ]"
-  MD5SUMS_DIR="$DEFAULT"
-else
-  MD5SUMS_DIR="$1"
-fi
-echo -n "Creating ocaml-md5sums.ml ... "
-sed -e "s:@MD5SUMS_DIR@:$MD5SUMS_DIR:" \
-  -e "s:@VERSION@:$VERSION:" \
-  < ocaml-md5sums.ml.in > ocaml-md5sums.ml
-echo "done."
diff --git a/ocaml-md5sums/ocaml-md5sums.pl b/ocaml-md5sums/ocaml-md5sums
similarity index 68%
rename from ocaml-md5sums/ocaml-md5sums.pl
rename to ocaml-md5sums/ocaml-md5sums
index e110229..955fff7 100755
--- a/ocaml-md5sums/ocaml-md5sums.pl
+++ b/ocaml-md5sums/ocaml-md5sums
@@ -9,7 +9,12 @@ use constant VERSION => "0.1";
 
 sub info 
 {
-  print STDERR (@_, "\n") if $verbose;
+  print STDERR (@_, "\n") if $verbose >= 1;
+};
+
+sub debug
+{
+  print STDERR (@_, "\n") if $verbose >= 2;
 };
 
 package OCamlMD5Sums::File;
@@ -17,9 +22,6 @@ package OCamlMD5Sums::File;
 use warnings;
 use strict;
 
-use Carp::Assert;
-use File::Find;
-
 sub new 
 {
   my ($class, 
@@ -31,18 +33,33 @@ sub new
   $self->{dev} = defined $dev ? $dev : "-";
   $self->{runtime} = defined $runtime ? $runtime : "-";
   $self->{version} = defined $version ? $version : "-";
-  $self->{exported} = ();
+  $self->{"defined"} = ();
   $self->{imported} = ();
 
   bless $self, $class;
   return $self;
 };
 
+sub add_unit 
+{
+  my ($self, $symbol_table, $unit_name, $md5) = @_;
+  main::debug "Adding unit $unit_name";
+  $self->{$symbol_table}{"$md5+$unit_name"} = 1;
+};
+
+sub get_unit
+{
+  my ($self, $symbol_table, $key) = @_;
+  return ($2, $1) if /([^+]*)\+(.*)/;
+  die "$key doesn't have the right format";
+};
+
 sub squeeze_imported 
 {
   my ($self) = @_;
 
-  foreach (keys(%{$self->{exported}}))
+  main::debug "Squeezing imported symbol";
+  foreach (keys(%{$self->{"defined"}}))
   {
     delete($self->{imported}{$_}) 
       if exists($self->{imported}{$_});
@@ -56,34 +73,21 @@ sub add_object
   my $interface = undef;
   my $symbol_table = undef;
 
+  main::info "Execute ocamlobjinfo $obj_file";
   foreach (`ocamlobjinfo $obj_file`)
   {
+    chomp $_;
+    main::debug "Input line: $_";
     if (/^\s*(Unit|Module) name: (\S+)$/)
     {
       $interface = $2;
-      main::info "Interface: $interface";
+      main::debug "Interface: $interface";
     };
     if (/^\s*([a-fA-F0-9]+)\s+(\S+)$/)
     {
       $symbol_table = "imported";
-      $symbol_table = "exported" if defined($interface) && ($interface eq $2);
-
-      warn "Already defined $interface is redefined with a different signatures" 
-      if defined($interface) 
-      && exists($self->{$symbol_table}{$2}) 
-      && $self->{$symbol_table}{$2} ne $1;
-
-      $self->{$symbol_table}{$2} = $1;
-      if ($symbol_table eq "exported")
-      {
-        if (exists($self->{imported}{$2}))
-        {
-          warn "Already required $interface is defined with a different signatures"
-          if defined($interface) 
-          && $self->{imported}{$2} ne $self->{exported}{$2};
-          delete($self->{imported}{$2});
-        };
-      };
+      $symbol_table = "defined" if defined($interface) && ($interface eq $2);
+      $self->add_unit($symbol_table, $2, $1);
     };
   };
 
@@ -94,16 +98,16 @@ sub read_dump
 {
   my ($self, $file) = @_;
   
-  my $section = undef;
+  my $symbol_table = undef;
 
   open(FH, $file) || die "Cannot open file $file";
   foreach (<FH>)
   {
-    my ($section,$md5,$unit_name) = split /\s+/;
-    $section = "exported" if $section eq "defined";
-    $self->{$section}{$unit_name} = $md5;
+    my ($symbol_table,$md5,$unit_name) = split /\s+/;
+    $self->add_unit($symbol_table, $unit_name, $md5);
   };
   close(FH) || die "Cannot close file $file";
+  $self->squeeze_imported();
 };
 
 sub write_dump
@@ -111,26 +115,37 @@ sub write_dump
   my ($self, $file) = @_;
 
   open(FH,">", $file) || die "Cannot open file $file";
-  print FH "imported $self->{imported}{$_} $_\n"
-   foreach (keys(%{$self->{imported}}));
-  print FH "defined  $self->{exported}{$_} $_\n"
-    foreach (keys(%{$self->{exported}}));
+  
+  foreach my $symbol_table ("imported", "defined")
+  {
+    my $symbol_table_print = $symbol_table;
+    $symbol_table_print = "defined " if $symbol_table eq "defined";
+    foreach (keys(%{$self->{$symbol_table}}))
+    {
+      my ($unit_name, $md5) = $self->get_unit($symbol_table, $_);
+      print FH "$symbol_table_print $md5 $unit_name\n";
+    }
+  }
+
   close(FH);
 };
 
 sub print
 {
   my ($self) = @_;
-  print  
-    (join 
-      (" ",
-       $self->{exported}{$_}, 
-       $_, 
-       $self->{dev}, 
-       $self->{runtime}, 
-       $self->{version}),
-       "\n")
-    foreach (keys(%{$self->{exported}}));
+  foreach (keys(%{$self->{"defined"}}))
+  {
+    my ($unit_name, $md5) = $self->get_unit("defined", $_);
+    print
+      (join 
+        (" ",
+         $md5, 
+         $unit_name, 
+         $self->{dev}, 
+         $self->{runtime}, 
+         $self->{version}),
+         "\n");
+  };
 };
 
 sub load_assign 
@@ -166,9 +181,10 @@ sub load
     $self->load_assign("dev", $dev);
     $self->load_assign("runtime", $runtime);
     $self->load_assign("version", $version);
-    $self->{exported}{$unit_name} = $md5;
+    $self->add_unit("defined", $unit_name, $md5);
   };
   close(FH);
+  $self->squeeze_imported();
 };
 
 # Check that self depends on another package
@@ -178,11 +194,7 @@ sub depends_on
 
   foreach (keys(%{$self->{imported}}))
   {
-    if (defined $other->{exported}{$_} &&
-        $self->{imported}{$_} eq $other->{exported}{$_})
-    {
-      return 1;
-    };
+    return 1 if (exists $other->{"defined"}{$_});
   };
 
   return 0;
@@ -199,7 +211,6 @@ sub print_dep
 
 package main;
 
-use File::Spec;
 use Getopt::Long;
 use Pod::Usage;
 use File::Glob;;
@@ -214,7 +225,7 @@ my $package_version;
 my $dump_info_fn;
 my $load_info_fn;
 my $print_version;
-my $md5sums_dir="/var/lib/ocaml/md5sums";
+my @md5sums_dirs=("/var/lib/ocaml/md5sums");
 
 sub process_not_option
 {
@@ -241,9 +252,9 @@ GetOptions(
   "version=s"     => \$package_version,
   "dump-info=s"   => \$dump_info_fn,
   "load-info=s"   => \$load_info_fn,
-  "md5sums-dir=s" => \$md5sums_dir,
+  "md5sums-dir=s" => \@md5sums_dirs,
   "my-version"    => \$print_version,
-  "v"             => \$verbose,
+  "v+"            => \$verbose,
   "<>"            => \&process_not_option, 
   "help|?"        => \$help, 
   "man"           => \$man) or pod2usage(2);
@@ -260,7 +271,6 @@ die "No action\n" unless defined($action);
 
 if ($action eq "compute" || $action eq "dep") 
 {
-
   my $md5sums = 
     OCamlMD5Sums::File->new 
       ($package_dev, 
@@ -281,15 +291,18 @@ if ($action eq "compute" || $action eq "dep")
   }
   else # dep
   {
-    my @files = <$md5sums_dir/*.md5sums>;
-    foreach (@files)
+    foreach my $md5sums_dir (@md5sums_dirs)
     {
-      my $other_md5sums = OCamlMD5Sums::File->new();
-      $other_md5sums->load($_);
-      if ($md5sums->depends_on($other_md5sums))
+      my @files = <$md5sums_dir/*.md5sums>;
+      foreach (@files)
       {
-        info "Depends on $_";
-        $other_md5sums->print_dep ();
+        my $other_md5sums = OCamlMD5Sums::File->new();
+        $other_md5sums->load($_);
+        if ($md5sums->depends_on($other_md5sums))
+        {
+          info "Depends on $_";
+          $other_md5sums->print_dep ();
+        };
       };
     };
   }
diff --git a/ocaml-md5sums/ocaml-md5sums.1 b/ocaml-md5sums/ocaml-md5sums.1
deleted file mode 100644
index 3174eb5..0000000
--- a/ocaml-md5sums/ocaml-md5sums.1
+++ /dev/null
@@ -1,48 +0,0 @@
-.TH OCAML-MD5SUMS "1" "June 2007" "ocaml-md5sums 3.10.0" "User Commands"
-.SH NAME
-ocaml-md5sums \- use and maintain system-wide OCaml md5sums registry
-.SH SYNOPSIS
-.B ocaml-md5sums compute
-\fB\-\-package\fR <name>
-[\fIoption\ ...\fR] \fIfile ...\fR
-.br
-.B ocaml-md5sums dep
-[\fIoption\ ...\fR] \fIfile ...\fR
-.br
-.B ocaml-md5sums update
-[\fIoption\ ...\fR]
-.SH DESCRIPTION
-ocaml-md5sums is an administrative tool for maintaining the system-wide
-registry of md5sums of OCaml modules. For each OCaml object registered, the
-registry contains information about which modules (compilation unit) are
-contained and their md5sums.
-.SH OPTIONS
-.HP
-\fB\-\-package\fR set package name for development dependency
-.HP
-\fB\-\-runtime\fR set package name for runtime dependency
-.HP
-\fB\-\-version\fR set package version for dependencies
-.HP
-\fB\-\-dump\-info\fR dump ocamlobjinfo to file
-.HP
-\fB\-\-load\-info\fR restore ocamlobjinfo from file
-.HP
-\fB\-v\fR increase verbosity
-.HP
-\fB\-\-my\-version\fR print ocaml\-md5sum version and exit
-.TP
-\fB\-help\fR
-Display this list of options
-.TP
-\fB\-\-help\fR
-Display this list of options
-.SH "SEE ALSO"
-.BR ocamlc(1),
-.BR ocaml(1).
-.SH AUTHOR
-ocaml-md5sums is Copyright Stefano Zacchiroli and is distributed under the
-terms of the GNU General Public License.
-.PP
-This manual page was written by Stefano Zacchiroli <zack at debian.org>,
-for the Debian project (but may be used by others).
diff --git a/ocaml-md5sums/ocaml-md5sums.ml.in b/ocaml-md5sums/ocaml-md5sums.ml.in
deleted file mode 100644
index b10a7ca..0000000
--- a/ocaml-md5sums/ocaml-md5sums.ml.in
+++ /dev/null
@@ -1,317 +0,0 @@
-(*
- * ocaml-md5sums - use and maintain debian registry of ocaml md5sums
- *
- * Copyright (C) 2005, Stefano Zacchiroli <zack at debian.org>
- *
- * Created:        Wed, 06 Apr 2005 16:55:39 +0200 zack
- * Last-Modified:  Fri, 12 Aug 2005 10:28:10 +0200 zack
- *
- * This is free software, you can redistribute it and/or modify it under the
- * terms of the GNU General Public License version 2 as published by the Free
- * Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA  02111-1307  USA
- *)
-
-open Printf
-
-(** {2 Constants} *)
-
-let my_version = "@VERSION@"
-let md5sums_dir = "@MD5SUMS_DIR@"
-let md5sums_index = "MD5SUMS"
-let md5sums_ext = ".md5sums"
-let registry_file = sprintf "%s/%s" md5sums_dir md5sums_index
-
-(** {2 System requirements} *)
-
-let ocamlobjinfo =
-  try                           (* needed at ocaml package build time, when *)
-    Sys.getenv "OCAMLOBJINFO"   (* ocamlobjinfo is not yet installed        *)
-  with Not_found -> "/usr/bin/ocamlobjinfo"
-
-(** {2 Regular expressions, for parsing purposes} *)
-
-let unit_name_line_RE =
-  Str.regexp "^[ \t]*Unit[ \t]+name[ \t]*:[ \t]*\\([a-zA-Z0-9_]+\\)[ \t]*$"
-let md5sum_line_RE =
-  Str.regexp "^[ \t]*\\([a-f0-9]+\\)[ \t]+\\([a-zA-Z0-9_]+\\)[ \t]*$"
-let blanks_RE = Str.regexp "[ \t]+"
-let ignorable_line_RE = Str.regexp "^[ \t]*\\(#.*\\)?"
-let md5sums_ext_RE = Str.regexp (sprintf "^.*%s$" (Str.quote md5sums_ext))
-
-(** {2 Argument parsing} *)
-
-let objects = ref []
-let dev_dep = ref ""
-let runtime_dep = ref "-"
-let dep_version = ref "-"
-let verbosity = ref 0
-let dump_info_to = ref ""
-let load_info_from = ref ""
-let action = ref None
-
-let usage_msg =
-  "Use and maintain system-wide ocaml md5sums registry\n"
-  ^ "Usage:\n"
-  ^ " ocaml-md5sum compute --package <name> [option ...] file ...\n"
-  ^ " ocaml-md5sum dep     [option ...] file ...\n"
-  ^ " ocaml-md5sum update  [option ...]\n"
-  ^ "Options:"
-let cmdline_spec = [
-  "--package", Arg.Set_string dev_dep,
-    "set package name for development dependency";
-  "--runtime", Arg.Set_string runtime_dep,
-    "set package name for runtime dependency";
-  "--version", Arg.Set_string dep_version,
-    "set package version for dependencies";
-  "--dump-info", Arg.Set_string dump_info_to,
-    "dump ocamlobjinfo to file";
-  "--load-info", Arg.Set_string load_info_from,
-    "restore ocamlobjinfo from file";
-  "-v", Arg.Unit (fun () -> incr verbosity), "increase verbosity";
-  "--my-version", Arg.Unit (fun () -> print_endline my_version ; exit 0),
-    "print ocaml-md5sum version and exit";
-]
-let die_usage () =
-  Arg.usage cmdline_spec usage_msg;
-  exit 1
-
-(** {2 Helpers} *)
-
-let error   msg = prerr_endline ("Error: " ^ msg); exit 2
-let warning msg = prerr_endline ("Warning: " ^ msg)
-let info ?(level = 1) msg =
-  if !verbosity >= level then prerr_endline ("Info: " ^ msg)
-let iter_in f ic =
-  try while true do f (input_line ic) done with End_of_file -> ()
-let iter_file f fname =
-  let ic = open_in fname in
-  iter_in f ic;
-  close_in ic
-let iter_table f = iter_file (fun line -> f (Str.split blanks_RE line))
-
-module Strings = Set.Make (String)
-
-(** read until the end of standard input
- * @return the list of lines read from stdin, without trailing "\n" *)
-let read_stdin () =
-  let lines = ref [] in
-  iter_in (fun s -> lines := s :: !lines) stdin;
-  List.rev !lines
-
-let is_empty fname = (Unix.stat fname).Unix.st_size = 0
-let is_regular fname = (Unix.stat fname).Unix.st_kind = Unix.S_REG
-let is_dir fname = (Unix.stat fname).Unix.st_kind = Unix.S_DIR
-
-(** {2 Auxiliary functions} *)
-
-(** loads info previously stored in a file using --dump-info and stores them in
- * two hashtables
- * @param defined hashtable for md5sums of defined units
- * @param imported hashtable for md5sums of imported units
- * @param fname file where the dump has been saved *)
-let load_info ~defined ~imported fname =
-  info ("loading ocamlobjinfo information from " ^ fname);
-  let lineno = ref 0 in
-  iter_table
-    (fun fields ->
-      incr lineno;
-      match fields with
-      | [ "defined"; md5; unit_name ] ->
-          info ~level:2 (String.concat " " fields);
-          Hashtbl.replace defined unit_name md5
-      | [ "imported"; md5; unit_name ] ->
-          info ~level:2 (String.concat " " fields);
-          Hashtbl.replace imported unit_name md5
-      | _ ->
-          warning (sprintf "ignoring dump entry (%s, line %d)" fname !lineno))
-    fname
-
-(** dumps ocamlobjinfo to file
- * @param defined hashtable containing md5sums of defined units
- * @param imported hashtable containing md5sums of imported units
- * @param fname file where to dump ocamlobjinfo *)
-let dump_info ~defined ~imported fname =
-  info ("dumping ocamlobjinfo information to " ^ fname);
-  let oc = open_out fname in
-  Hashtbl.iter
-    (fun unit_name md5sum -> fprintf oc "defined  %s %s\n" md5sum unit_name)
-    defined;
-  Hashtbl.iter
-    (fun unit_name md5sum -> fprintf oc "imported %s %s\n" md5sum unit_name)
-    imported;
-  close_out oc
-
-(** @param fnames list of *.cm[ao] file names
- * @return a pair of hash tables <defined_units, imported_units>. Both tables
- * contains mappings <unit_name, md5sum>. defined_units lists units defined in
- * given files while imported_units imported ones *)
-let unit_info fnames =
-  let (defined, imported) = (Hashtbl.create 1024, Hashtbl.create 1024) in
-  if !load_info_from <> "" then
-    load_info ~defined ~imported !load_info_from;
-  List.iter
-    (fun fname ->
-      info ("getting unit info from " ^ fname);
-      let current_unit = ref "" in
-      let ic = Unix.open_process_in (sprintf "%s %s" ocamlobjinfo fname) in
-      iter_in
-        (fun line ->
-          if Str.string_match unit_name_line_RE line 0 then
-            current_unit := Str.matched_group 1 line
-          else if Str.string_match md5sum_line_RE line 0 then
-            let md5sum = Str.matched_group 1 line in
-            let unit_name = Str.matched_group 2 line in
-            if unit_name = !current_unit then begin (* defined unit *)
-              let dump_entry = sprintf "defined %s %s" md5sum unit_name in
-              info ~level:2 dump_entry;
-              Hashtbl.replace defined unit_name md5sum
-            end else begin  (* imported unit *)
-              let dump_entry = sprintf "imported %s %s" md5sum unit_name in
-              info ~level:2 dump_entry;
-              Hashtbl.replace imported unit_name md5sum
-            end)
-        ic;
-      close_in ic)
-    fnames;
-  Hashtbl.iter  (* imported := imported - defined *)
-    (fun unit_name _ -> Hashtbl.remove imported unit_name)
-    defined;
-  if !dump_info_to <> "" then
-    dump_info ~defined ~imported !dump_info_to;
-  (defined, imported)
-
-(** pretty print a registry entry sending output to an output channel *)
-let pp_entry outchan ~md5sum ~unit_name ~dev_dep ~runtime_dep ~dep_version =
-  fprintf outchan "%s %s %s %s %s\n"
-    md5sum unit_name dev_dep runtime_dep dep_version
-
-(** iter a function over the entries of a registry file
- * @param f function to be executed for each entries, it takes 4 labeled
- * arguments: ~md5sum ~unit_name ~package ?version
- * @param fname file containining the registry *)
-let iter_registry f fname =
-  info ("processing registry " ^ fname);
-  let lineno = ref 0 in
-  iter_file
-    (fun line ->
-      incr lineno;
-      (match Str.split blanks_RE line with
-      | [ md5sum; unit_name; dev_dep; runtime_dep; dep_version ] ->
-          f ~md5sum ~unit_name ~dev_dep ~runtime_dep ~dep_version
-      | _ when Str.string_match ignorable_line_RE line 0 -> ()
-      | _ ->
-          warning (sprintf "ignoring registry entry (%s, line %d)"
-            fname !lineno)))
-    fname
-
-(** @param fname file name of the registry file, if fname does not exists an
- * empty registry will be returned
- * @return an hashtbl mapping pairs <unit_name, md5sum> to pairs <package_name,
- * version_info>. E.g. ("Foo_bar", "74be7fa4320ebd9415f1c7cfc04c2d7b") ->
- * ("libfoo-ocaml-dev", ">= 1.2.3-4") *)
-let parse_registry fname =
-  let registry = Hashtbl.create 1024 in
-  if Sys.file_exists fname then
-    iter_registry
-      (fun ~md5sum ~unit_name ~dev_dep ~runtime_dep ~dep_version ->
-        Hashtbl.replace registry (unit_name, md5sum)
-          (dev_dep, runtime_dep, dep_version))
-      fname;
-  registry
-
-(** {2 Main functions, one for each command line action} *)
-
-(** compute registry entry for a set of ocaml objects *)
-let compute dev_dep runtime_dep dep_version objects () =
-  let defined, _ = unit_info objects in
-  Hashtbl.iter
-    (fun unit_name md5sum ->
-       pp_entry stdout ~md5sum ~unit_name ~dev_dep ~runtime_dep ~dep_version)
-    defined
-
-(** compute package dependencies for a set of ocaml objects *)
-let dep objects () =
-  let _, imported = unit_info objects in
-  let registry = parse_registry registry_file in
-  let deps =
-    Hashtbl.fold
-      (fun unit_name md5sum deps ->
-        try
-          let (dev_dep, runtime_dep, dep_version) =
-            Hashtbl.find registry (unit_name, md5sum)
-          in
-          Strings.add (sprintf "%s %s %s" dev_dep runtime_dep dep_version) deps
-        with Not_found -> deps)
-      imported
-      Strings.empty
-  in
-  Strings.iter print_endline deps
-
-(** update debian registry of ocaml md5sums *)
-let update () =
-  info (sprintf "updating registry %s using info from %s/"
-    registry_file md5sums_dir);
-  let keys = Hashtbl.create 1024 in (* history of seen registry keys *)
-  if Sys.file_exists md5sums_dir && is_dir md5sums_dir then begin
-    let dir = Unix.opendir md5sums_dir in
-    let registry = open_out registry_file in
-    try
-      while true do
-        let fname = sprintf "%s/%s" md5sums_dir (Unix.readdir dir) in
-        if (Str.string_match md5sums_ext_RE fname 0) && is_regular fname then
-          iter_registry
-            (fun ~md5sum ~unit_name ~dev_dep ~runtime_dep ~dep_version ->
-               if Hashtbl.mem keys (unit_name, md5sum) then
-                 error (sprintf "duplicate entry %s %s in registry" unit_name
-                            md5sum);
-               Hashtbl.replace keys (unit_name, md5sum) ();
-               pp_entry registry ~md5sum ~unit_name ~dev_dep ~runtime_dep
-                 ~dep_version)
-            fname
-      done
-    with End_of_file ->
-      Unix.closedir dir;
-      close_out registry;
-      if is_empty registry_file then Sys.remove registry_file
-  end else
-    warning (sprintf "%s/ does not exist or is not a directory, not updating"
-      md5sums_dir)
-
-(** {2 Main} *)
-
-(** main *)
-let main () =
-  Arg.parse cmdline_spec
-    (fun s ->
-      if !action = None then
-        action := Some s
-      else
-        objects := s :: !objects)
-    usage_msg;
-  match !action with
-  | Some "update" -> update ()
-  | Some action ->
-      let objects =
-        match !objects with
-        | [] when !load_info_from = "" -> read_stdin ()
-        | objects -> List.rev objects
-      in
-      (match action with
-      | "compute" ->
-          if !dev_dep = "" then die_usage ();
-          compute !dev_dep !runtime_dep !dep_version objects ()
-      | "dep" -> dep objects ()
-      | _ -> die_usage ())
-  | None -> die_usage ()
-
-let _ = Unix.handle_unix_error main ()
-

-- 
dh-ocaml packaging



More information about the Pkg-ocaml-maint-commits mailing list