Repository: ESMCI/cime

Issue:
Add CESM tag to the caseroot env_case.xml file
The CESM tag name is needed for the archive_metadata script and other post-processing tools.
Proposed XML would be as follows:

In group id=case_der:

```
<entry id="CESM_TAG" value="[SVN tag name]">
  <type>char</type>
  <desc>CESM SVN Tag name</desc>
</entry>
```



Discussion:

Resolving patch:
diff --git a/utils/python/CIME/case.py b/utils/python/CIME/case.py
--- a/utils/python/CIME/case.py
+++ b/utils/python/CIME/case.py
@@ -10,7 +10,7 @@
 
 from CIME.utils                     import expect, get_cime_root, append_status
 from CIME.utils                     import convert_to_type, get_model, get_project
-from CIME.utils                     import get_build_threaded
+from CIME.utils                     import get_build_threaded, get_current_commit
 from CIME.XML.build                 import Build
 from CIME.XML.machines              import Machines
 from CIME.XML.pes                   import Pes
@@ -688,6 +688,7 @@ def configure(self, compset_name, grid_name, machine_name=None,
 
         # Turn on short term archiving as cesm default setting
         model = get_model()
+        self.set_model_version(model)
         if model == "cesm" and not test:
             self.set_value("DOUT_S",True)
         if test:
@@ -979,3 +980,29 @@ def get_mpirun_cmd(self, job="case.run"):
             mpi_arg_string += " : "
 
         return "%s %s %s" % (executable if executable is not None else "", mpi_arg_string, run_suffix)
+
+
+    def set_model_version(self, model):
+        version = "unknown"
+        if model == "cesm":
+            srcroot = self.get_value("SRCROOT")
+            changelog = os.path.join(srcroot,"ChangeLog")
+            expect(os.path.isfile(changelog), " No CESM ChangeLog file found")
+            for line in open(changelog, "r"):
+                m = re.search("Tag name: (cesm.*)$", line)
+                if m is not None:
+                    version = m.group(1)
+                    break
+        elif model == "acme":
+            cimeroot = self.get_value("CIMEROOT")
+            version = get_current_commit(True, cimeroot)
+        self.set_value("MODEL_VERSION", version)
+
+
+
+
+
+
+
+
+
diff --git a/utils/python/CIME/provenance.py b/utils/python/CIME/provenance.py
--- a/utils/python/CIME/provenance.py
+++ b/utils/python/CIME/provenance.py
@@ -30,7 +30,6 @@ def save_build_provenance_acme(case, lid=None):
     exeroot = case.get_value("EXEROOT")
     caseroot = case.get_value("CASEROOT")
     lid = os.environ["LID"] if lid is None else lid
-
     # Save git describe
     describe_prov = os.path.join(exeroot, "GIT_DESCRIBE.%s" % lid)
     if os.path.exists(describe_prov):
@@ -73,8 +72,13 @@ def save_build_provenance_acme(case, lid=None):
                 os.remove(generic_name)
             os.symlink(the_match, generic_name)
 
+
 def save_build_provenance_cesm(case, lid=None): # pylint: disable=unused-argument
-    pass
+    version = case.get_value("MODEL_VERSION")
+    # version has already been recorded
+    caseroot = case.get_value("CASEROOT")
+    with open(os.path.join(caseroot, "README.case"), "a") as fd:
+        fd.write("CESM version is %s\n"%version)
 
 def save_build_provenance(case, lid=None):
     model = case.get_value("MODEL")


Test patch: