Repository: ESMCI/cime

Issue:
driver build files get put in esp directory
I'm not sure if this causes any problems, but it seems wrong: I noticed that the driver's build files (*.o, *.mod) get put in the esp component directory within the bld directory:

```
$ ls -lrt /glade/scratch/sacks/ERS_Ld7.f19_g16.B1850.yellowstone_intel.allactive-defaultio.20161102_130827_ew9xpb/bld/esp/obj
total 12800
-rw-r--r-- 1 sacks ncar    150 Nov  2 13:08 CASEROOT
-rw-r--r-- 1 sacks ncar  72844 Nov  2 13:16 esp_comp_mct.mod
-rw-r--r-- 1 sacks ncar   9192 Nov  2 13:16 esp_comp_mct.o
-rw-r--r-- 1 sacks ncar    246 Nov  2 13:28 Filepath
-rw-r--r-- 1 sacks ncar    366 Nov  2 13:28 Deppath
-rw-r--r-- 1 sacks ncar    619 Nov  2 13:28 Srcfiles
-rw-r--r-- 1 sacks ncar   5274 Nov  2 13:28 Depends
-rw-r--r-- 1 sacks ncar   5108 Nov  2 13:28 t_drv_timers_mod.mod
-rw-r--r-- 1 sacks ncar  51036 Nov  2 13:28 seq_map_type_mod.mod
-rw-r--r-- 1 sacks ncar  11504 Nov  2 13:28 t_driver_timers_mod.o
-rw-r--r-- 1 sacks ncar   4707 Nov  2 13:28 vertical_gradient_calculator_base.mod
-rw-r--r-- 1 sacks ncar  85748 Nov  2 13:28 mrg_mod.mod
-rw-r--r-- 1 sacks ncar  10416 Nov  2 13:28 vertical_gradient_calculator_base.o
-rw-r--r-- 1 sacks ncar  14432 Nov  2 13:28 seq_map_type_mod.o
-rw-r--r-- 1 sacks ncar  31608 Nov  2 13:28 vertical_gradient_calculator_2nd_order.mod
-rw-r--r-- 1 sacks ncar 314432 Nov  2 13:28 component_type_mod.mod
-rw-r--r-- 1 sacks ncar  18840 Nov  2 13:28 component_type_mod.o
-rw-r--r-- 1 sacks ncar  25216 Nov  2 13:28 vertical_gradient_calculator_2nd_order.o
-rw-r--r-- 1 sacks ncar 114424 Nov  2 13:28 mrg_mod.o
-rw-r--r-- 1 sacks ncar  88323 Nov  2 13:28 seq_map_mod.mod
-rw-r--r-- 1 sacks ncar  39276 Nov  2 13:28 vertical_gradient_calculator_factory.mod
-rw-r--r-- 1 sacks ncar 225286 Nov  2 13:28 seq_io_mod.mod
-rw-r--r-- 1 sacks ncar 178918 Nov  2 13:28 seq_diag_mct.mod
-rw-r--r-- 1 sacks ncar 107018 Nov  2 13:28 seq_flux_mct.mod
-rw-r--r-- 1 sacks ncar  22056 Nov  2 13:28 vertical_gradient_calculator_factory.o
-rw-r--r-- 1 sacks ncar  82424 Nov  2 13:28 seq_map_mod.o
-rw-r--r-- 1 sacks ncar 150088 Nov  2 13:28 seq_io_mod.o
-rw-r--r-- 1 sacks ncar 285099 Nov  2 13:28 map_lnd2glc_mod.mod
-rw-r--r-- 1 sacks ncar 131080 Nov  2 13:28 prep_ice_mod.mod
-rw-r--r-- 1 sacks ncar 284464 Nov  2 13:28 map_glc2lnd_mod.mod
-rw-r--r-- 1 sacks ncar 131294 Nov  2 13:28 prep_atm_mod.mod
-rw-r--r-- 1 sacks ncar 142540 Nov  2 13:28 prep_ocn_mod.mod
-rw-r--r-- 1 sacks ncar  25824 Nov  2 13:28 map_glc2lnd_mod.o
-rw-r--r-- 1 sacks ncar  30344 Nov  2 13:28 map_lnd2glc_mod.o
-rw-r--r-- 1 sacks ncar 278145 Nov  2 13:28 map_lnd2rof_irrig_mod.mod
-rw-r--r-- 1 sacks ncar  16608 Nov  2 13:28 map_lnd2rof_irrig_mod.o
-rw-r--r-- 1 sacks ncar  70384 Nov  2 13:28 prep_ice_mod.o
-rw-r--r-- 1 sacks ncar 128013 Nov  2 13:28 prep_wav_mod.mod
-rw-r--r-- 1 sacks ncar 128962 Nov  2 13:28 prep_glc_mod.mod
-rw-r--r-- 1 sacks ncar 132456 Nov  2 13:28 prep_lnd_mod.mod
-rw-r--r-- 1 sacks ncar  34472 Nov  2 13:28 prep_wav_mod.o
-rw-r--r-- 1 sacks ncar  86784 Nov  2 13:28 prep_atm_mod.o
-rw-r--r-- 1 sacks ncar  43336 Nov  2 13:28 prep_lnd_mod.o
-rw-r--r-- 1 sacks ncar  51288 Nov  2 13:28 prep_glc_mod.o
-rw-r--r-- 1 sacks ncar 131176 Nov  2 13:28 prep_ocn_mod.o
-rw-r--r-- 1 sacks ncar 133522 Nov  2 13:28 prep_rof_mod.mod
-rw-r--r-- 1 sacks ncar  54864 Nov  2 13:28 prep_rof_mod.o
-rw-r--r-- 1 sacks ncar  99869 Nov  2 13:28 prep_aoflux_mod.mod
-rw-r--r-- 1 sacks ncar 335309 Nov  2 13:28 seq_domain_mct.mod
-rw-r--r-- 1 sacks ncar  18248 Nov  2 13:28 prep_aoflux_mod.o
-rw-r--r-- 1 sacks ncar 223320 Nov  2 13:28 seq_flux_mct.o
-rw-r--r-- 1 sacks ncar 340659 Nov  2 13:28 seq_frac_mct.mod
-rw-r--r-- 1 sacks ncar 135485 Nov  2 13:28 seq_hist_mod.mod
-rw-r--r-- 1 sacks ncar  94312 Nov  2 13:28 seq_domain_mct.o
-rw-r--r-- 1 sacks ncar 285912 Nov  2 13:28 seq_diag_mct.o
-rw-r--r-- 1 sacks ncar 152323 Nov  2 13:28 seq_rest_mod.mod
-rw-r--r-- 1 sacks ncar 112305 Nov  2 13:28 cplcomp_exchange_mod.mod
-rw-r--r-- 1 sacks ncar  49432 Nov  2 13:28 seq_rest_mod.o
-rw-r--r-- 1 sacks ncar  64600 Nov  2 13:28 cplcomp_exchange_mod.o
-rw-r--r-- 1 sacks ncar 405339 Nov  2 13:28 component_mod.mod
-rw-r--r-- 1 sacks ncar  48200 Nov  2 13:28 component_mod.o
-rw-r--r-- 1 sacks ncar 281936 Nov  2 13:28 seq_frac_mct.o
-rw-r--r-- 1 sacks ncar 186520 Nov  2 13:28 seq_hist_mod.o
-rw-r--r-- 1 sacks ncar 476903 Nov  2 13:28 cesm_comp_mod.mod
-rw-r--r-- 1 sacks ncar 356512 Nov  2 13:28 cesm_comp_mod.o
-rw-r--r-- 1 sacks ncar  10168 Nov  2 13:28 cesm_driver.o
```


Discussion:
thanks - i'll have a look


Resolving patch:
diff --git a/utils/python/CIME/build.py b/utils/python/CIME/build.py
--- a/utils/python/CIME/build.py
+++ b/utils/python/CIME/build.py
@@ -59,7 +59,7 @@ def build_model(build_threaded, exeroot, clm_config_opts, incroot, complist,
         # thread_bad_results captures error output from thread (expected to be empty)
         # logs is a list of log files to be compressed and added to the case logs/bld directory
         t = threading.Thread(target=_build_model_thread,
-            args=(config_dir, model, caseroot, bldroot, libroot, incroot, file_build,
+            args=(config_dir, model, caseroot, libroot, bldroot, incroot, file_build,
                   thread_bad_results, smp, compiler))
         t.start()
 
@@ -80,7 +80,7 @@ def build_model(build_threaded, exeroot, clm_config_opts, incroot, complist,
             logger.debug("Now build aquap ocn component")
             # thread_bad_results captures error output from thread (expected to be empty)
             # logs is a list of log files to be compressed and added to the case logs/bld directory
-            _build_model_thread(config_dir, comp, caseroot, bldroot, libroot, incroot, file_build,
+            _build_model_thread(config_dir, comp, caseroot, libroot, bldroot, incroot, file_build,
                                 thread_bad_results, smp, compiler)
             logs.append(file_build)
     expect(not thread_bad_results, "\n".join(thread_bad_results))
@@ -94,8 +94,9 @@ def build_model(build_threaded, exeroot, clm_config_opts, incroot, complist,
 
     config_dir = os.path.join(cimeroot, "driver_cpl", "cime_config")
     f = open(file_build, "w")
+    bldroot = os.path.join(exeroot, "cpl", "obj")
     stat = run_cmd("%s/buildexe %s %s %s" %
-                   (config_dir, caseroot, bldroot, libroot),
+                   (config_dir, caseroot, libroot, bldroot),
                    from_dir=bldroot, verbose=True, arg_stdout=f,
                    arg_stderr=subprocess.STDOUT)[0]
     f.close()
@@ -473,7 +474,7 @@ def build_libraries(case, exeroot, sharedpath, caseroot, cimeroot, libroot, lid,
         # thread_bad_results captures error output from thread (expected to be empty)
         # logs is a list of log files to be compressed and added to the case logs/bld directory
         thread_bad_results = []
-        _build_model_thread(config_lnd_dir, "lnd", caseroot, bldroot, libroot, incroot,
+        _build_model_thread(config_lnd_dir, "lnd", caseroot, libroot, bldroot, incroot,
                             file_build, thread_bad_results, smp, compiler)
         logs.append(file_build)
         expect(not thread_bad_results, "\n".join(thread_bad_results))
@@ -481,12 +482,12 @@ def build_libraries(case, exeroot, sharedpath, caseroot, cimeroot, libroot, lid,
     return logs
 
 ###############################################################################
-def _build_model_thread(config_dir, compclass, caseroot, bldroot, libroot, incroot, file_build,
+def _build_model_thread(config_dir, compclass, caseroot, libroot, bldroot, incroot, file_build,
                         thread_bad_results, smp, compiler):
 ###############################################################################
     with open(file_build, "w") as fd:
         stat = run_cmd("MODEL=%s SMP=%s %s/buildlib %s %s %s " %
-                       (compclass, stringify_bool(smp), config_dir, caseroot, bldroot, libroot),
+                       (compclass, stringify_bool(smp), config_dir, caseroot, libroot, bldroot),
                        from_dir=bldroot, verbose=True, arg_stdout=fd,
                        arg_stderr=subprocess.STDOUT)[0]
     analyze_build_log(compclass, file_build, compiler)
diff --git a/utils/python/CIME/buildlib.py b/utils/python/CIME/buildlib.py
--- a/utils/python/CIME/buildlib.py
+++ b/utils/python/CIME/buildlib.py
@@ -24,13 +24,12 @@ def parse_input(argv):
     parser.add_argument("caseroot", default=os.getcwd(),
                         help="Case directory")
 
-    # JGF: This doesn't appear to be used anywhere
-    parser.add_argument("bldroot",
-                        help="root for building library")
-
     parser.add_argument("libroot",
                         help="root for creating the library")
 
+    parser.add_argument("bldroot",
+                        help="root for building library")
+
     args = parser.parse_args()
 
     handle_standard_logging_options(args)


Test patch: