Skip to content

Commit

Permalink
Move CIME.macros to CIME.XML.build.
Browse files Browse the repository at this point in the history
  • Loading branch information
quantheory committed Aug 25, 2016
1 parent 329ab29 commit 23dd5af
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 31 deletions.
4 changes: 2 additions & 2 deletions tools/configure
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ _LIBDIR = os.path.join(_CIMEROOT, "scripts", "Tools")
sys.path.append(_LIBDIR)

from standard_script_setup import *
from CIME.macros import MacroMaker
from CIME.utils import expect
from CIME.XML.build import Build
from CIME.XML.env_mach_specific import EnvMachSpecific
from CIME.XML.machines import Machines

Expand Down Expand Up @@ -126,7 +126,7 @@ def _main():

# Macros generation.
suffixes = {'Makefile': '.make', 'CMake': '.cmake'}
macro_maker = MacroMaker(machobj)
macro_maker = Build(machobj)
build_file_name = os.path.join(machobj.machines_dir, "config_build.xml")
for form in opts['macros_format']:
out_file_name = os.path.join(output_dir,
Expand Down
32 changes: 16 additions & 16 deletions utils/python/CIME/macros.py → utils/python/CIME/XML/build.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""
Classes used to build the CIME Macros file.
The main "public" class here is MacroMaker. It is initialized with machine-
specific information, and its write_macros method is the driver for translating
the config_build.xml file into a Makefile or CMake-format Macros file.
The main "public" class here is Build. It is initialized with machine-specific
information, and its write_macros method is the driver for translating the
config_build.xml file into a Makefile or CMake-format Macros file.
For developers, here's the role of the other classes in the process:
Expand All @@ -20,14 +20,14 @@
In more detail:
- MacroMaker.write_macros immediately creates a MakeMacroWriter or
CMakeMacroWriter to translate strings for the build system.
- Build.write_macros immediately creates a MakeMacroWriter or CMakeMacroWriter
to translate strings for the build system.
- It also creates value_lists, a dictionary of PossibleValues objects, with
variable names as the keys. Each variable has a single PossibleValues object
associated with it.
- For each <compiler> element, MacroMaker.write_macros creates a CompilerBlock
- For each <compiler> element, Build.write_macros creates a CompilerBlock
instance. This object is responsible for translating the XML in its block, in
order to populate the PossibleValues instances. This includes handling the
<var>/<env>/<shell> tags, and keeping track of dependencies induced by one
Expand All @@ -47,11 +47,11 @@
translated to. The lists in the PossibleValues class contain these objects.
- Once the XML has all been read in and the PossibleValues objects are
populated, the dependencies among variables are checked in
MacroMaker.write_macros. For each variable, if all its dependencies have been
handled, it is converted to a MacroConditionTree merged with all other trees
for variables that are ready, and written out. Then we loop through the
variable list again to check for variables whose dependencies are all handled.
populated, the dependencies among variables are checked in Build.write_macros.
For each variable, if all its dependencies have been handled, it is converted
to a MacroConditionTree merged with all other trees for variables that are
ready, and written out. Then we loop through the variable list again to check
for variables whose dependencies are all handled.
- The MacroConditionTree acts as a primitive syntax tree. Its __init__ method
reorganizes the data into conditional blocks, and its write_out method writes
Expand All @@ -68,7 +68,7 @@
from CIME.XML.machines import Machines # pylint: disable=unused-import
from CIME.XML.standard_module_setup import *

__all__ = ["MacroMaker"]
__all__ = ["Build"]

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -648,7 +648,7 @@ def matches_machine(self):
return True


class MacroMaker(object):
class Build(object):

"""Class to convert config_build.xml input into a macros file.
Expand All @@ -663,7 +663,7 @@ class MacroMaker(object):
"""

def __init__(self, machobj, schema_path=None):
"""Construct a MacroMaker given machine-specific information.
"""Construct a Build given machine-specific information.
In the process some information about possible variables is read in
from the schema file.
Expand All @@ -672,9 +672,9 @@ def __init__(self, machobj, schema_path=None):
machobj - A Machines object for this machine.
schema_path (optional) - Path to config_build.xsd within CIME.
>>> "CFLAGS" in MacroMaker('MyMach').flag_vars
>>> "CFLAGS" in Build('MyMach').flag_vars
True
>>> "MPICC" in MacroMaker('MyMach').flag_vars
>>> "MPICC" in Build('MyMach').flag_vars
False
"""
self.machobj = machobj
Expand Down
4 changes: 2 additions & 2 deletions utils/python/CIME/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +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.XML.build import Build
from CIME.XML.machines import Machines
from CIME.XML.pes import Pes
from CIME.XML.files import Files
Expand All @@ -30,7 +31,6 @@

from CIME.user_mod_support import apply_user_mods
from CIME.case_setup import case_setup
from CIME.macros import MacroMaker

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -714,7 +714,7 @@ def _create_caseroot_tools(self):
files = Files()
build_file = files.get_value("BUILD_SPEC_FILE")
machobj = Machines(machine=machine, files=files)
macro_maker = MacroMaker(machobj)
macro_maker = Build(machobj)
macros_path = os.path.join(self._caseroot, "Macros")
with open(macros_path, "w") as macros_file:
macro_maker.write_macros('Makefile', build_file, macros_file)
Expand Down
21 changes: 10 additions & 11 deletions utils/python/tests/scripts_regression_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
import update_acme_tests
import CIME.test_scheduler, CIME.wait_for_tests
from CIME.test_scheduler import TestScheduler
from CIME.XML.build import Build
from CIME.XML.machines import Machines
from CIME.XML.files import Files
from CIME.case import Case
from CIME.macros import MacroMaker
from CIME.test_status import *

SCRIPT_DIR = CIME.utils.get_scripts_root()
Expand Down Expand Up @@ -1118,7 +1118,7 @@ def get_machine_name(self):

def get_value(self, var_name):
"""Allow the operating system to be queried."""
assert var_name == "OS", "MacrosMaker asked for a value not " \
assert var_name == "OS", "Build asked for a value not " \
"implemented in the testing infrastructure."
return self.os

Expand All @@ -1135,13 +1135,13 @@ def get_macros(macro_maker, build_xml, build_system):
"""Generate build system ("Macros" file) output from config_build XML.
Arguments:
macro_maker - The underlying MacroMaker object.
macro_maker - The underlying Build object.
build_xml - A string containing the XML to operate on.
build_system - Either "Makefile" or "CMake", depending on desired output.
The return value is a string containing the build system output.
"""
# MacroMaker.write_macros expects file-like objects as input, so
# Build.write_macros expects file-like objects as input, so
# we need to wrap the strings in StringIO objects.
xml = io.StringIO(unicode(build_xml))
output = io.StringIO()
Expand Down Expand Up @@ -1358,19 +1358,19 @@ class G_TestMacrosBasic(unittest.TestCase):
def test_script_is_callable(self):
"""The test script can be called on valid output without dying."""
# This is really more a smoke test of this script than anything else.
maker = MacroMaker(MockMachines("mymachine", "SomeOS"))
maker = Build(MockMachines("mymachine", "SomeOS"))
test_xml = _wrap_config_build_xml("<compiler><SUPPORTS_CXX>FALSE</SUPPORTS_CXX></compiler>")
get_macros(maker, test_xml, "Makefile")

def test_script_rejects_bad_xml(self):
"""The macro writer rejects input that's not valid XML."""
maker = MacroMaker(MockMachines("mymachine", "SomeOS"))
maker = Build(MockMachines("mymachine", "SomeOS"))
with self.assertRaises(ParseError):
get_macros(maker, "This is not valid XML.", "Makefile")

def test_script_rejects_bad_build_system(self):
"""The macro writer rejects a bad build system string."""
maker = MacroMaker(MockMachines("mymachine", "SomeOS"))
maker = Build(MockMachines("mymachine", "SomeOS"))
bad_string = "argle-bargle."
with self.assertRaisesRegexp(
SystemExit,
Expand All @@ -1384,7 +1384,7 @@ class H_TestMakeMacros(unittest.TestCase):

"""Makefile macros tests.
This class contains tests of the Makefile output of MacrosMaker.
This class contains tests of the Makefile output of Build.
Aside from the usual setUp and test methods, this class has a utility method
(xml_to_tester) that converts XML input directly to a MakefileTester object.
Expand All @@ -1394,7 +1394,7 @@ class H_TestMakeMacros(unittest.TestCase):
test_machine = "mymachine"

def setUp(self):
self._maker = MacroMaker(MockMachines(self.test_machine, self.test_os))
self._maker = Build(MockMachines(self.test_machine, self.test_os))

def xml_to_tester(self, xml_string):
"""Helper that directly converts an XML string to a MakefileTester."""
Expand Down Expand Up @@ -1653,13 +1653,12 @@ def test_variable_insertion_with_machine_specific_setting(self):


###############################################################################
@unittest.skipIf(FAST_ONLY, "Skipping slow CMake tests.")
class I_TestCMakeMacros(H_TestMakeMacros):
###############################################################################

"""CMake macros tests.
This class contains tests of the CMake output of MacrosMaker.
This class contains tests of the CMake output of Build.
This class simply inherits all of the methods of TestMakeOutput, but changes
the definition of xml_to_tester to create a CMakeTester instead.
Expand Down

0 comments on commit 23dd5af

Please sign in to comment.