This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gcjx] Patch: FYI: handle dependency tracking


I'm checking this in on the gcjx branch.

This has been sitting in my local tree for quite a while.  I'm not
sure it is really finished, but I wanted to get it checked in.

This is a first cut at dependency tracking for gcjx.

Tom

Index: gcjx/ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	* factory.cc (find_source_file): Updated.
	(find_derived_file): Likewise.
	(process_zip_entry): Updated.
	* reader/fdreader.cc (read_all): Call note_read.
	* reader/fdreader.hh (fd_reader): Added filename argument.
	* reader/zereader.cc (read_all): Call note_read.
	* reader/zereader.hh (zip_entry_reader): Added filename argument.
	* reader/reader.hh (reader::note_read): New method.
	(reader): Added argument.
	* compiler.hh (compiler::all_files_read): New field.
	(compiler::note_file_read): New method.
	(compiler::get_all_files_read): Likewise.

Index: gcjx/compiler.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/Attic/compiler.hh,v
retrieving revision 1.1.2.4
diff -u -r1.1.2.4 compiler.hh
--- gcjx/compiler.hh 13 Feb 2005 03:39:44 -0000 1.1.2.4
+++ gcjx/compiler.hh 12 Sep 2005 01:45:48 -0000
@@ -224,6 +224,9 @@
   // True if this compiler will accept resource files.
   bool can_accept_resources;
 
+  // All the files read during this compilation.
+  std::set<std::string> all_files_read;
+
   void do_load_source_file (const std::string &);
   void do_generate_code (model_unit *);
   void do_analyze_unit (model_unit *);
@@ -471,6 +474,19 @@
 
   /// Compile a resource file given its file name and its contents.
   void compile_resource (const std::string &, reader *);
+
+  /// Indicate that a given file has been read during the course of
+  /// this compilation.
+  void note_file_read (const std::string &fn)
+  {
+    all_files_read.insert (fn);
+  }
+
+  /// Return a set of all files read.
+  std::set<std::string> get_all_files_read ()
+  {
+    return all_files_read;
+  }
 };
 
 #endif // GCJX_COMPILER_HH
Index: gcjx/factory.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/Attic/factory.cc,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 factory.cc
--- gcjx/factory.cc 13 Feb 2005 03:39:44 -0000 1.1.2.2
+++ gcjx/factory.cc 12 Sep 2005 01:45:48 -0000
@@ -116,7 +116,7 @@
   if (fd < 0)
     return NULL;
 
-  return new source_file_creator (file, new fd_reader (fd));
+  return new source_file_creator (file, new fd_reader (file, fd));
 }
 
 class_instance_creator *
@@ -133,7 +133,7 @@
   int fd = open (file.c_str (), O_RDONLY | O_BINARY);
   if (fd < 0)
     return NULL;
-  return new class_byte_creator (file, new fd_reader (fd));
+  return new class_byte_creator (file, new fd_reader (file, fd));
 }
 
 class_instance_creator *
@@ -315,8 +315,10 @@
 
   std::string filename ((char *)(&dir_ptr[CREC_SIZE + 4]), filename_length);
 
+  // Note that we use the name of the zip file for dependency tracking
+  // here.
   zip_entry_reader *ze_reader
-    = new zip_entry_reader (archive->get () + file_start,
+    = new zip_entry_reader (file, archive->get () + file_start,
                             compression_method,
                             compressed_size,
                             uncompressed_size,
Index: gcjx/reader/fdreader.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/reader/Attic/fdreader.cc,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 fdreader.cc
--- gcjx/reader/fdreader.cc 13 Jan 2005 03:18:36 -0000 1.1.2.1
+++ gcjx/reader/fdreader.cc 12 Sep 2005 01:45:48 -0000
@@ -1,6 +1,6 @@
 // Read from a file descriptor.
 
-// Copyright (C) 2004 Free Software Foundation, Inc.
+// Copyright (C) 2004, 2005 Free Software Foundation, Inc.
 //
 // This file is part of GCC.
 //
@@ -38,6 +38,7 @@
 fd_reader::read_all ()
 {
   // FIXME: configury.
+  note_read ();
   return new mmap_byte_buffer (fd);
 }
 
Index: gcjx/reader/fdreader.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/reader/Attic/fdreader.hh,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 fdreader.hh
--- gcjx/reader/fdreader.hh 13 Jan 2005 03:18:36 -0000 1.1.2.1
+++ gcjx/reader/fdreader.hh 12 Sep 2005 01:45:48 -0000
@@ -1,6 +1,6 @@
 // Reader that uses the file system.
 
-// Copyright (C) 2004 Free Software Foundation, Inc.
+// Copyright (C) 2004, 2005 Free Software Foundation, Inc.
 //
 // This file is part of GCC.
 //
@@ -33,8 +33,9 @@
 
 public:
 
-  fd_reader (int f)
-    : fd (f)
+  fd_reader (const std::string &fn, int f)
+    : reader (fn),
+      fd (f)
   {
   }
 
Index: gcjx/reader/reader.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/reader/Attic/reader.hh,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 reader.hh
--- gcjx/reader/reader.hh 13 Jan 2005 03:18:36 -0000 1.1.2.1
+++ gcjx/reader/reader.hh 12 Sep 2005 01:45:48 -0000
@@ -1,6 +1,6 @@
 // Base class for plain-byte input streams.
 
-// Copyright (C) 2004 Free Software Foundation, Inc.
+// Copyright (C) 2004, 2005 Free Software Foundation, Inc.
 //
 // This file is part of GCC.
 //
@@ -28,10 +28,21 @@
 
 class reader
 {
+private:
+
+  // Name of underlying file.
+  std::string filename;
+
 protected:
 
-  reader ()
+  reader (const std::string &fn)
+    : filename (fn)
+  {
+  }
+
+  void note_read ()
   {
+    global->get_compiler ()->note_file_read (filename);
   }
 
 public:
Index: gcjx/reader/zereader.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/reader/Attic/zereader.cc,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 zereader.cc
--- gcjx/reader/zereader.cc 13 Jan 2005 03:18:36 -0000 1.1.2.1
+++ gcjx/reader/zereader.cc 12 Sep 2005 01:45:48 -0000
@@ -1,6 +1,6 @@
 // Read a compressed file from a ZIP/JAR archive.
 
-// Copyright (C) 2004 Free Software Foundation, Inc.
+// Copyright (C) 2004, 2005 Free Software Foundation, Inc.
 //
 // This file is part of GCC.
 //
@@ -36,6 +36,7 @@
 byte_buffer *
 zip_entry_reader::read_all ()
 {
+  note_read ();
   uint8 *out_buffer = new uint8[uncompressed_size];
   if (compression_method == Z_NO_COMPRESSION)
     {
Index: gcjx/reader/zereader.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/reader/Attic/zereader.hh,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 zereader.hh
--- gcjx/reader/zereader.hh 13 Jan 2005 03:18:36 -0000 1.1.2.1
+++ gcjx/reader/zereader.hh 12 Sep 2005 01:45:48 -0000
@@ -1,6 +1,6 @@
 // Reader that uncompresses and reads a ZIP/JAR file entry.
 
-// Copyright (C) 2004 Free Software Foundation, Inc.
+// Copyright (C) 2004, 2005 Free Software Foundation, Inc.
 //
 // This file is part of GCC.
 //
@@ -31,7 +31,7 @@
 private:
 
   /// The compressed data.
-  const uint8* compressed_data;
+  const uint8 *compressed_data;
 
   /// The compression method used for the file.
   int compression_method;
@@ -49,9 +49,10 @@
 
 public:
 
-  zip_entry_reader (const uint8* data, int cmethod, uint32 csize, uint32 ucsize,
-                    uint32 dos_mtime)
-    : compressed_data (data),
+  zip_entry_reader (const std::string &fn, const uint8 *data, int cmethod,
+		    uint32 csize, uint32 ucsize, uint32 dos_mtime)
+    : reader (fn),
+      compressed_data (data),
       compression_method (cmethod),
       compressed_size (csize),
       uncompressed_size (ucsize),
Index: gcc/java/ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	* driver.cc (arg_info::dependencies): New field.
	(arg_info::print_phonies): Likewise.
	(arg_info::include_system_files): Likewise.
	(arg_info::dependency_file): Likewise.
	(arg_info::target): Likewise.
	(arg_info::deps_to_file): Likewise.
	(arg_info): Initialize it.
	(~arg_info): New destructor.
	(arg_info::init_dependencies): New method.
	(finish): Write out dependencies.
	(handle_option): Handle -M family of options.
	* glue.hh: Include mkdeps.h.

Index: gcc/java/driver.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/driver.cc,v
retrieving revision 1.1.2.7
diff -u -r1.1.2.7 driver.cc
--- gcc/java/driver.cc 11 Sep 2005 01:03:51 -0000 1.1.2.7
+++ gcc/java/driver.cc 12 Sep 2005 01:45:54 -0000
@@ -26,6 +26,10 @@
 #include "header/cni.hh"
 #include "source/ucs2.hh"
 
+#ifndef TARGET_OBJECT_SUFFIX
+# define TARGET_OBJECT_SUFFIX ".o"
+#endif
+
 // An object of this type is used to hold command line argument
 // information.
 struct arg_info
@@ -44,13 +48,47 @@
   // Input file name.
   const char *filename;
 
+  // Dependency tracking structure.
+  struct deps *dependencies;
+  // True if we should print phony targets.
+  bool print_phonies;
+  // True if we should include system files in dependency output.
+  bool include_system_files;
+  // True if we should write dependencies to a file (instead of to
+  // stdout).
+  bool deps_to_file;
+  // Name of output file.  If not specified, and DEPS_TO_FILE is true,
+  // then we compute the name of the file.
+  const char *dependency_file;
+  // Name of target to use, or NULL for the default.
+  const char *target;
+
   arg_info ()
     : bootclasspath (NULL),
       classpath (NULL),
       encoding (NULL),
       output (NULL),
-      filename (NULL)
+      filename (NULL),
+      dependencies (NULL),
+      print_phonies (false),
+      include_system_files (false),
+      deps_to_file (false),
+      dependency_file (NULL),
+      target (NULL)
+  {
+  }
+
+  ~arg_info ()
+  {
+    if (dependencies)
+      deps_free (dependencies);
+  }
+
+  void init_dependencies (bool system)
   {
+    if (! dependencies)
+      dependencies = deps_init ();
+    include_system_files = system;
   }
 };
 
@@ -79,13 +117,33 @@
       break;
 
     case OPT_M:
+      arguments->init_dependencies (true);
+      break;
+
     case OPT_MD_:
+      arguments->init_dependencies (true);
+      arguments->deps_to_file = true;
+      break;
+
     case OPT_MF:
+      arguments->dependency_file = arg;
+      break;
+
     case OPT_MM:
+      arguments->init_dependencies (false);
+      break;
+
     case OPT_MMD_:
+      arguments->init_dependencies (false);
+      arguments->deps_to_file = true;
+      break;
+
     case OPT_MP:
+      arguments->print_phonies = true;
+      break;
+
     case OPT_MT:
-      // fixme
+      arguments->target = arg;
       break;
 
     case OPT_Wall:
@@ -439,6 +497,67 @@
 void
 gcjx::finish ()
 {
+  // Write out the dependencies.
+  if (arguments->dependencies)
+    {
+      FILE *dep_file;
+      if (! arguments->deps_to_file)
+	dep_file = stdout;
+      else
+	{
+	  std::string dep_filename;
+	  if (arguments->dependency_file)
+	    dep_filename = arguments->dependency_file;
+	  else
+	    {
+	      const char *filename = arguments->filename;
+	      const char *dot = strrchr (filename, '.');
+	      if (dot == NULL)
+		error ("couldn't determine target name for "
+		       "dependency tracking");
+	      else
+		{
+		  char *buf
+		    = (char *) xmalloc (dot - filename
+					+ 3 + sizeof (TARGET_OBJECT_SUFFIX));
+		  strncpy (buf, filename, dot - filename);
+		  // FIXME: special handling when generating .class.
+		  // FIXME: blah blah
+		  if (arguments->target == NULL)
+		    {
+		      strcpy (buf + (dot - filename), TARGET_OBJECT_SUFFIX);
+		      deps_add_default_target (arguments->dependencies, buf);
+		    }
+
+		  buf[dot - filename] = '\0';
+		  dep_filename = buf + std::string (".d");
+		}
+	    }
+
+	  dep_file = fopen (dep_filename.c_str (), "w");
+	  // FIXME: error handling.
+	}
+
+      // Add the dependencies.
+      std::set<std::string> files = our_compiler->get_all_files_read ();
+      for (std::set<std::string>::const_iterator i = files.begin ();
+	   i != files.end ();
+	   ++i)
+	deps_add_dep (arguments->dependencies, (*i).c_str ());
+
+      // Set the target.
+      if (arguments->target != NULL)
+	deps_add_target (arguments->dependencies, arguments->target, 1);
+
+      // Write out the results.
+      deps_write (arguments->dependencies, dep_file, 72);
+      if (arguments->print_phonies)
+	deps_phony_targets (arguments->dependencies, dep_file);
+
+      if (dep_file != stdout)
+	fclose (dep_file);
+    }
+
   // We're done with the command-line arguments.
   delete arguments;
   arguments = NULL;
Index: gcc/java/glue.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/glue.hh,v
retrieving revision 1.1.2.13
diff -u -r1.1.2.13 glue.hh
--- gcc/java/glue.hh 29 Apr 2005 02:58:51 -0000 1.1.2.13
+++ gcc/java/glue.hh 12 Sep 2005 01:45:54 -0000
@@ -72,6 +72,7 @@
 #include "version.h"
 #include "target.h"
 #include "rtl.h"
+#include "mkdeps.h"
 
 // This gets us alloc_stmt_list().  Shouldn't that be in
 // tree-iterator.h?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]